]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/bpf-filter.hh
eBPF: eBPF case-insensitive qname filtering
[thirdparty/pdns.git] / pdns / bpf-filter.hh
CommitLineData
87b515ed
RG
1#pragma once
2#include "config.h"
3
4#include <mutex>
5
6#include "iputils.hh"
7
8#ifdef HAVE_EBPF
9
10class BPFFilter
11{
12public:
13 BPFFilter(uint32_t maxV4Addresses, uint32_t maxV6Addresses, uint32_t maxQNames);
87b515ed
RG
14 void addSocket(int sock);
15 void block(const ComboAddress& addr);
16 void block(const DNSName& qname, uint16_t qtype=255);
17 void unblock(const ComboAddress& addr);
18 void unblock(const DNSName& qname, uint16_t qtype=255);
19 std::vector<std::pair<ComboAddress, uint64_t> > getAddrStats();
20 std::vector<std::tuple<DNSName, uint16_t, uint64_t> > getQNameStats();
21private:
d45189b7
RG
22 struct FDWrapper
23 {
24 ~FDWrapper()
25 {
26 if (fd != -1) {
27 close(fd);
28 }
29 }
30 int fd{-1};
31 };
87b515ed
RG
32 std::mutex d_mutex;
33 uint32_t d_maxV4;
34 uint32_t d_maxV6;
35 uint32_t d_maxQNames;
36 uint32_t d_v4Count{0};
37 uint32_t d_v6Count{0};
38 uint32_t d_qNamesCount{0};
d45189b7
RG
39 FDWrapper d_v4map;
40 FDWrapper d_v6map;
41 FDWrapper d_qnamemap;
42 FDWrapper d_filtermap;
43 FDWrapper d_mainfilter;
44 FDWrapper d_qnamefilter;
87b515ed
RG
45};
46
47#endif /* HAVE_EBPF */