/src/pdns/pdns/dnsdistdist/dnsdist-actions.hh
Line | Count | Source (jump to first uncovered line) |
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 | | */ |
22 | | #pragma once |
23 | | |
24 | | #include <cstdint> |
25 | | #include <map> |
26 | | #include <string> |
27 | | |
28 | | /* so what could you do: |
29 | | drop, |
30 | | fake up nxdomain, |
31 | | provide actual answer, |
32 | | allow & and stop processing, |
33 | | continue processing, |
34 | | modify header: (servfail|refused|notimp), set TC=1, |
35 | | send to pool */ |
36 | | |
37 | | struct DNSQuestion; |
38 | | struct DNSResponse; |
39 | | |
40 | | class DNSAction |
41 | | { |
42 | | public: |
43 | | enum class Action : uint8_t |
44 | | { |
45 | | Drop, |
46 | | Nxdomain, |
47 | | Refused, |
48 | | Spoof, |
49 | | Allow, |
50 | | HeaderModify, |
51 | | Pool, |
52 | | Delay, |
53 | | Truncate, |
54 | | ServFail, |
55 | | None, |
56 | | NoOp, |
57 | | NoRecurse, |
58 | | SpoofRaw, |
59 | | SpoofPacket, |
60 | | SetTag, |
61 | | }; |
62 | | static Action typeFromString(const std::string& str); |
63 | | static std::string typeToString(Action action); |
64 | | |
65 | | virtual Action operator()(DNSQuestion*, std::string* ruleresult) const = 0; |
66 | | virtual ~DNSAction() = default; |
67 | | virtual std::string toString() const = 0; |
68 | | virtual std::map<std::string, double> getStats() const |
69 | 0 | { |
70 | 0 | return {{}}; |
71 | 0 | } |
72 | | virtual void reload() |
73 | 0 | { |
74 | 0 | } |
75 | | }; |
76 | | |
77 | | class DNSResponseAction |
78 | | { |
79 | | public: |
80 | | enum class Action : uint8_t |
81 | | { |
82 | | Allow, |
83 | | Delay, |
84 | | Drop, |
85 | | HeaderModify, |
86 | | ServFail, |
87 | | Truncate, |
88 | | None |
89 | | }; |
90 | | virtual Action operator()(DNSResponse*, std::string* ruleresult) const = 0; |
91 | | virtual ~DNSResponseAction() = default; |
92 | | virtual std::string toString() const = 0; |
93 | | virtual void reload() |
94 | 0 | { |
95 | 0 | } |
96 | | }; |