]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/dnsdist-dynbpf.cc
Standardize license text in all PDNS files
[thirdparty/pdns.git] / pdns / dnsdist-dynbpf.cc
CommitLineData
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#include "dnsdist-dynbpf.hh"
23
24#ifdef HAVE_EBPF
25
26void DynBPFFilter::block(const ComboAddress& addr, const struct timespec& until)
27{
28 std::unique_lock<std::mutex> lock(d_mutex);
29
30 const container_t::iterator it = d_entries.find(addr);
31 if (it != d_entries.end()) {
32 if (it->d_until < until) {
33 d_entries.replace(it, BlockEntry(addr, until));
34 }
35 }
36 else {
37 d_bpf->block(addr);
38 d_entries.insert(BlockEntry(addr, until));
39 }
40}
41
42void DynBPFFilter::purgeExpired(const struct timespec& now)
43{
44 std::unique_lock<std::mutex> lock(d_mutex);
45
46 typedef nth_index<container_t,1>::type ordered_until;
47 ordered_until& ou = get<1>(d_entries);
48
49 for (ordered_until::iterator it=ou.begin(); it != ou.end(); ) {
50 if (it->d_until < now) {
51 ComboAddress addr = it->d_addr;
52 it = ou.erase(it);
53 d_bpf->unblock(addr);
54 }
55 else {
56 break;
57 }
58 }
59}
60
61#endif /* HAVE_EBPF */