]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dnsdist-dynbpf.cc
dnsdist: Add eBPF source address v4/v6 and qname filtering
[thirdparty/pdns.git] / pdns / dnsdist-dynbpf.cc
1 #include "dnsdist-dynbpf.hh"
2
3 #ifdef HAVE_EBPF
4
5 void DynBPFFilter::block(const ComboAddress& addr, const struct timespec& until)
6 {
7 std::unique_lock<std::mutex> lock(d_mutex);
8
9 const container_t::iterator it = d_entries.find(addr);
10 if (it != d_entries.end()) {
11 if (it->d_until < until) {
12 d_entries.replace(it, BlockEntry(addr, until));
13 }
14 }
15 else {
16 d_bpf->block(addr);
17 d_entries.insert(BlockEntry(addr, until));
18 }
19 }
20
21 void DynBPFFilter::purgeExpired(const struct timespec& now)
22 {
23 std::unique_lock<std::mutex> lock(d_mutex);
24
25 typedef nth_index<container_t,1>::type ordered_until;
26 ordered_until& ou = get<1>(d_entries);
27
28 for (ordered_until::iterator it=ou.begin(); it != ou.end(); ) {
29 if (it->d_until < now) {
30 ComboAddress addr = it->d_addr;
31 it = ou.erase(it);
32 d_bpf->unblock(addr);
33 }
34 else {
35 break;
36 }
37 }
38 }
39
40 #endif /* HAVE_EBPF */