]>
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 | */ | |
5e08df89 RG |
22 | |
23 | #pragma once | |
24 | ||
f6f016d1 | 25 | #include <string> |
1d5b3ce6 | 26 | #include <map> |
1a09e47b | 27 | #include <optional> |
3457a2a0 | 28 | #include <vector> |
2b808f13 | 29 | #include <inttypes.h> |
a254e9b6 | 30 | #include <sys/un.h> |
8657c2af | 31 | #include <signal.h> |
c684d7ad | 32 | #include <pthread.h> |
509196af | 33 | #include "iputils.hh" |
c5c066bf | 34 | #include "dnsname.hh" |
0c366a8e | 35 | #include "sholder.hh" |
27ae5181 | 36 | #include <atomic> |
f6f016d1 | 37 | |
0c366a8e PL |
38 | extern GlobalStateHolder<SuffixMatchNode> g_dontThrottleNames; |
39 | extern GlobalStateHolder<NetmaskGroup> g_dontThrottleNetmasks; | |
40 | ||
f6f016d1 BH |
41 | /** this class is used both to send and answer channel commands to the PowerDNS Recursor */ |
42 | class RecursorControlChannel | |
43 | { | |
44 | public: | |
a254e9b6 BH |
45 | RecursorControlChannel(); |
46 | ||
47 | ~RecursorControlChannel(); | |
a2bfc3ff | 48 | |
f6f016d1 | 49 | int listen(const std::string& filename); |
aaacf7f2 | 50 | void connect(const std::string& path, const std::string& filename); |
f6f016d1 BH |
51 | |
52 | uint64_t getStat(const std::string& name); | |
1d5b3ce6 | 53 | |
adf0f368 O |
54 | struct Answer |
55 | { | |
56 | Answer& operator+=(const Answer& rhs) | |
57 | { | |
58 | if (d_ret == 0 && rhs.d_ret != 0) { | |
59 | d_ret = rhs.d_ret; | |
60 | } | |
61 | d_str += rhs.d_str; | |
62 | return *this; | |
63 | } | |
64 | int d_ret{0}; | |
65 | std::string d_str; | |
66 | }; | |
67 | ||
6c593a38 O |
68 | void send(int remote, const Answer&, unsigned int timeout = 5, int fd_to_pass = -1); |
69 | RecursorControlChannel::Answer recv(int fd, unsigned int timeout = 5); | |
1d5b3ce6 | 70 | |
f6f016d1 | 71 | int d_fd; |
364a5491 | 72 | static std::atomic<bool> stop; |
adf0f368 | 73 | |
a2bfc3ff BH |
74 | private: |
75 | struct sockaddr_un d_local; | |
f6f016d1 BH |
76 | }; |
77 | ||
1d5b3ce6 BH |
78 | class RecursorControlParser |
79 | { | |
80 | public: | |
b0b37121 RG |
81 | RecursorControlParser() |
82 | { | |
83 | } | |
a7f98e34 | 84 | static void nop(void) {} |
aaacf7f2 | 85 | typedef void func_t(void); |
adf0f368 O |
86 | |
87 | RecursorControlChannel::Answer getAnswer(int s, const std::string& question, func_t** func); | |
1d5b3ce6 BH |
88 | }; |
89 | ||
a7f98e34 O |
90 | enum class StatComponent |
91 | { | |
92 | API, | |
93 | Carbon, | |
94 | RecControl, | |
95 | SNMP | |
96 | }; | |
adf0f368 | 97 | |
a7f98e34 O |
98 | struct StatsMapEntry |
99 | { | |
308cd14c OM |
100 | std::string d_prometheusName; |
101 | std::string d_value; | |
102 | }; | |
b4448848 | 103 | |
a74ad857 | 104 | class PrefixDashNumberCompare |
b4448848 O |
105 | { |
106 | private: | |
107 | static std::pair<std::string, std::string> prefixAndTrailingNum(const std::string& a); | |
a7f98e34 | 108 | |
b4448848 O |
109 | public: |
110 | bool operator()(const std::string& a, const std::string& b) const; | |
111 | }; | |
112 | ||
a74ad857 | 113 | typedef std::map<std::string, StatsMapEntry, PrefixDashNumberCompare> StatsMap; |
b4448848 | 114 | |
308cd14c OM |
115 | StatsMap getAllStatsMap(StatComponent component); |
116 | ||
58d7ad6b RG |
117 | struct CarbonConfig |
118 | { | |
119 | std::string hostname; | |
120 | std::string instance_name; | |
121 | std::string namespace_name; | |
122 | std::vector<std::string> servers; | |
123 | }; | |
124 | ||
125 | extern GlobalStateHolder<CarbonConfig> g_carbonConfig; | |
126 | ||
a7f98e34 O |
127 | std::vector<std::pair<DNSName, uint16_t>>* pleaseGetQueryRing(); |
128 | std::vector<std::pair<DNSName, uint16_t>>* pleaseGetServfailQueryRing(); | |
129 | std::vector<std::pair<DNSName, uint16_t>>* pleaseGetBogusQueryRing(); | |
509196af | 130 | std::vector<ComboAddress>* pleaseGetRemotes(); |
131 | std::vector<ComboAddress>* pleaseGetServfailRemotes(); | |
66f2e6ad | 132 | std::vector<ComboAddress>* pleaseGetBogusRemotes(); |
509196af | 133 | std::vector<ComboAddress>* pleaseGetLargeAnswerRemotes(); |
621ccf89 | 134 | std::vector<ComboAddress>* pleaseGetTimeouts(); |
c5c066bf | 135 | DNSName getRegisteredName(const DNSName& dom); |
57c5fefb | 136 | std::atomic<unsigned long>* getDynMetric(const std::string& str, const std::string& prometheusName); |
1a09e47b | 137 | std::optional<uint64_t> getStatByName(const std::string& name); |
3d324e00 O |
138 | bool isStatDisabled(StatComponent component, const std::string& name); |
139 | void disableStat(StatComponent component, const string& name); | |
140 | void disableStats(StatComponent component, const string& stats); | |
72259676 | 141 | |
b0b37121 | 142 | void registerAllStats(); |
5e08df89 | 143 | |
9f374187 FL |
144 | void doExitGeneric(bool nicely); |
145 | void doExit(); | |
146 | void doExitNicely(); | |
adf0f368 | 147 | RecursorControlChannel::Answer doQueueReloadLuaScript(vector<string>::const_iterator begin, vector<string>::const_iterator end); |