]>
Commit | Line | Data |
---|---|---|
12471842 PL |
1 | /* |
2 | * This file is part of PowerDNS or dnsdist. | |
3 | * Copyright -- PowerDNS.COM B.V. and its contributors | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of version 2 of the GNU General Public License as | |
7 | * published by the Free Software Foundation. | |
8 | * | |
9 | * In addition, for the avoidance of any doubt, permission is granted to | |
10 | * link this program with OpenSSL and to (re)distribute the binaries | |
11 | * produced as the result of such linking. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
21 | */ | |
87b515ed RG |
22 | #pragma once |
23 | #include "config.h" | |
24 | ||
25 | #include <mutex> | |
26 | ||
27 | #include "iputils.hh" | |
28 | ||
29 | #ifdef HAVE_EBPF | |
30 | ||
31 | class BPFFilter | |
32 | { | |
33 | public: | |
34 | BPFFilter(uint32_t maxV4Addresses, uint32_t maxV6Addresses, uint32_t maxQNames); | |
87b515ed RG |
35 | void addSocket(int sock); |
36 | void block(const ComboAddress& addr); | |
37 | void block(const DNSName& qname, uint16_t qtype=255); | |
38 | void unblock(const ComboAddress& addr); | |
39 | void unblock(const DNSName& qname, uint16_t qtype=255); | |
40 | std::vector<std::pair<ComboAddress, uint64_t> > getAddrStats(); | |
41 | std::vector<std::tuple<DNSName, uint16_t, uint64_t> > getQNameStats(); | |
42 | private: | |
d45189b7 RG |
43 | struct FDWrapper |
44 | { | |
45 | ~FDWrapper() | |
46 | { | |
47 | if (fd != -1) { | |
48 | close(fd); | |
49 | } | |
50 | } | |
51 | int fd{-1}; | |
52 | }; | |
87b515ed RG |
53 | std::mutex d_mutex; |
54 | uint32_t d_maxV4; | |
55 | uint32_t d_maxV6; | |
56 | uint32_t d_maxQNames; | |
57 | uint32_t d_v4Count{0}; | |
58 | uint32_t d_v6Count{0}; | |
59 | uint32_t d_qNamesCount{0}; | |
d45189b7 RG |
60 | FDWrapper d_v4map; |
61 | FDWrapper d_v6map; | |
62 | FDWrapper d_qnamemap; | |
63 | FDWrapper d_filtermap; | |
64 | FDWrapper d_mainfilter; | |
65 | FDWrapper d_qnamefilter; | |
87b515ed RG |
66 | }; |
67 | ||
68 | #endif /* HAVE_EBPF */ |