/src/pdns/pdns/dnsdistdist/ednssubnet.hh
Line | Count | Source |
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 "iputils.hh" |
25 | | |
26 | | class EDNSSubnetOpts |
27 | | { |
28 | | public: |
29 | | void setSource(const Netmask& netmask) |
30 | 0 | { |
31 | 0 | source = netmask; |
32 | 0 | } |
33 | | [[nodiscard]] const Netmask& getSource() const |
34 | 62 | { |
35 | 62 | return source; |
36 | 62 | } |
37 | | [[nodiscard]] uint8_t getFamily() const |
38 | 0 | { |
39 | 0 | return source.getNetwork().sin4.sin_family; |
40 | 0 | } |
41 | | [[nodiscard]] uint8_t getSourcePrefixLength() const |
42 | 0 | { |
43 | 0 | return source.getBits(); |
44 | 0 | } |
45 | | void setScopePrefixLength(uint8_t scope) |
46 | 0 | { |
47 | 0 | scopeBits = scope; |
48 | 0 | } |
49 | | [[nodiscard]] uint8_t getScopePrefixLength() const |
50 | 0 | { |
51 | 0 | return scopeBits; |
52 | 0 | } |
53 | | [[nodiscard]] Netmask getScope() const |
54 | 0 | { |
55 | 0 | return {source.getNetwork(), scopeBits}; |
56 | 0 | } |
57 | | [[nodiscard]] std::string makeOptString() const; |
58 | | static bool getFromString(const std::string& options, EDNSSubnetOpts* eso); |
59 | | static bool getFromString(const char* options, unsigned int len, EDNSSubnetOpts* eso); |
60 | | |
61 | | private: |
62 | | Netmask source; |
63 | | uint8_t scopeBits{}; |
64 | | }; |