]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/rec_channel.hh
updated KSK and ZSK Rollover procedures, small fixes in Algorithm Rollover procedure
[thirdparty/pdns.git] / pdns / rec_channel.hh
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 */
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
38extern GlobalStateHolder<SuffixMatchNode> g_dontThrottleNames;
39extern GlobalStateHolder<NetmaskGroup> g_dontThrottleNetmasks;
40
f6f016d1
BH
41/** this class is used both to send and answer channel commands to the PowerDNS Recursor */
42class RecursorControlChannel
43{
44public:
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
74private:
75 struct sockaddr_un d_local;
f6f016d1
BH
76};
77
1d5b3ce6
BH
78class RecursorControlParser
79{
80public:
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
90enum class StatComponent
91{
92 API,
93 Carbon,
94 RecControl,
95 SNMP
96};
adf0f368 97
a7f98e34
O
98struct StatsMapEntry
99{
308cd14c
OM
100 std::string d_prometheusName;
101 std::string d_value;
102};
b4448848 103
a74ad857 104class PrefixDashNumberCompare
b4448848
O
105{
106private:
107 static std::pair<std::string, std::string> prefixAndTrailingNum(const std::string& a);
a7f98e34 108
b4448848
O
109public:
110 bool operator()(const std::string& a, const std::string& b) const;
111};
112
a74ad857 113typedef std::map<std::string, StatsMapEntry, PrefixDashNumberCompare> StatsMap;
b4448848 114
308cd14c
OM
115StatsMap getAllStatsMap(StatComponent component);
116
58d7ad6b
RG
117struct CarbonConfig
118{
119 std::string hostname;
120 std::string instance_name;
121 std::string namespace_name;
122 std::vector<std::string> servers;
123};
124
125extern GlobalStateHolder<CarbonConfig> g_carbonConfig;
126
a7f98e34
O
127std::vector<std::pair<DNSName, uint16_t>>* pleaseGetQueryRing();
128std::vector<std::pair<DNSName, uint16_t>>* pleaseGetServfailQueryRing();
129std::vector<std::pair<DNSName, uint16_t>>* pleaseGetBogusQueryRing();
509196af 130std::vector<ComboAddress>* pleaseGetRemotes();
131std::vector<ComboAddress>* pleaseGetServfailRemotes();
66f2e6ad 132std::vector<ComboAddress>* pleaseGetBogusRemotes();
509196af 133std::vector<ComboAddress>* pleaseGetLargeAnswerRemotes();
621ccf89 134std::vector<ComboAddress>* pleaseGetTimeouts();
c5c066bf 135DNSName getRegisteredName(const DNSName& dom);
57c5fefb 136std::atomic<unsigned long>* getDynMetric(const std::string& str, const std::string& prometheusName);
1a09e47b 137std::optional<uint64_t> getStatByName(const std::string& name);
3d324e00
O
138bool isStatDisabled(StatComponent component, const std::string& name);
139void disableStat(StatComponent component, const string& name);
140void disableStats(StatComponent component, const string& stats);
72259676 141
b0b37121 142void registerAllStats();
5e08df89 143
9f374187
FL
144void doExitGeneric(bool nicely);
145void doExit();
146void doExitNicely();
adf0f368 147RecursorControlChannel::Answer doQueueReloadLuaScript(vector<string>::const_iterator begin, vector<string>::const_iterator end);