#ifdef HAVE_EBPF
-void DynBPFFilter::block(const ComboAddress& addr, const struct timespec& until)
+bool DynBPFFilter::block(const ComboAddress& addr, const struct timespec& until)
{
+ bool inserted = false;
std::unique_lock<std::mutex> lock(d_mutex);
const container_t::iterator it = d_entries.find(addr);
else {
d_bpf->block(addr);
d_entries.insert(BlockEntry(addr, until));
+ inserted = true;
}
+ return inserted;
}
void DynBPFFilter::purgeExpired(const struct timespec& now)
~DynBPFFilter()
{
}
- void block(const ComboAddress& addr, const struct timespec& until);
+ /* returns true if the addr wasn't already blocked, false otherwise */
+ bool block(const ComboAddress& addr, const struct timespec& until);
void purgeExpired(const struct timespec& now);
std::vector<std::tuple<ComboAddress, uint64_t, struct timespec> > getAddrStats();
private:
}
});
- g_lua.writeFunction("addBPFFilterDynBlocks", [](const map<ComboAddress,int>& m, std::shared_ptr<DynBPFFilter> dynbpf, boost::optional<int> seconds) {
+ g_lua.writeFunction("addBPFFilterDynBlocks", [](const map<ComboAddress,int>& m, std::shared_ptr<DynBPFFilter> dynbpf, boost::optional<int> seconds, boost::optional<std::string> msg) {
setLuaSideEffect();
struct timespec until, now;
clock_gettime(CLOCK_MONOTONIC, &now);
int actualSeconds = seconds ? *seconds : 10;
until.tv_sec += actualSeconds;
for(const auto& capair : m) {
- dynbpf->block(capair.first, until);
+ if (dynbpf->block(capair.first, until)) {
+ warnlog("Inserting eBPF dynamic block for %s for %d seconds: %s", capair.first.toString(), actualSeconds, msg ? *msg : "");
+ }
}
});
These are all the functions, objects and methods related to the :doc:`../advanced/ebpf`.
-.. function:: addBPFFilterDynBlocks(addresses, dynbpf[, seconds=10])
+.. function:: addBPFFilterDynBlocks(addresses, dynbpf[[, seconds=10], msg])
+
+ .. versionchanged:: 1.3.0
+ ``msg`` optional parameter added.
This is the eBPF equivalent of :func:`addDynBlocks`, blocking a set of addresses for (optionally) a number of seconds, using an eBPF dynamic filter.
The default number of seconds to block for is 10.
:param addresses: set of Addresses as returned by an :ref:`exceed function <exceedfuncs>`
:param DynBPFFilter dynbpf: The dynamic eBPF filter to use
:param int seconds: The number of seconds this block to expire
+ :param str msg: A message to display while inserting the block
.. function:: newBPFFilter(maxV4, maxV6, maxQNames) -> BPFFilter