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 #include <set>
24 
25 #include "sholder.hh"
26 #include "sortlist.hh"
27 #include "filterpo.hh"
28 #include "validate.hh"
29 
30 struct ProtobufExportConfig
31 {
32   std::set<uint16_t> exportTypes = { QType::A, QType::AAAA, QType::CNAME };
33   std::vector<ComboAddress> servers;
34   uint64_t maxQueuedEntries{100};
35   uint16_t timeout{2};
36   uint16_t reconnectWaitTime{1};
37   bool asyncConnect{false};
38   bool enabled{false};
39   bool logQueries{true};
40   bool logResponses{true};
41   bool taggedOnly{false};
42 };
43 
44 struct FrameStreamExportConfig
45 {
46   std::vector<string> servers;
47   bool enabled{false};
48   bool logQueries{true};
49   bool logResponses{true};
50   unsigned bufferHint{0};
51   unsigned flushTimeout{0};
52   unsigned inputQueueSize{0};
53   unsigned outputQueueSize{0};
54   unsigned queueNotifyThreshold{0};
55   unsigned reopenInterval{0};
56 };
57 
58 struct TrustAnchorFileInfo {
59   uint32_t interval{24};
60   std::string fname;
61 };
62 
63 class LuaConfigItems
64 {
65 public:
66   LuaConfigItems();
67   SortList sortlist;
68   DNSFilterEngine dfe;
69   TrustAnchorFileInfo trustAnchorFileInfo; // Used to update the Trust Anchors from file periodically
70   map<DNSName,dsmap_t> dsAnchors;
71   map<DNSName,std::string> negAnchors;
72   ProtobufExportConfig protobufExportConfig;
73   ProtobufExportConfig outgoingProtobufExportConfig;
74   FrameStreamExportConfig frameStreamExportConfig;
75 
76   /* we need to increment this every time the configuration
77      is reloaded, so we know if we need to reload the protobuf
78      remote loggers */
79   uint64_t generation{0};
80   uint8_t protobufMaskV4{32};
81   uint8_t protobufMaskV6{128};
82 };
83 
84 extern GlobalStateHolder<LuaConfigItems> g_luaconfs;
85 
86 struct luaConfigDelayedThreads
87 {
88   std::vector<std::tuple<std::vector<ComboAddress>, boost::optional<DNSFilterEngine::Policy>, bool, uint32_t, size_t, TSIGTriplet, size_t, ComboAddress, uint16_t, uint32_t, std::shared_ptr<SOARecordContent>, std::string> > rpzPrimaryThreads;
89 };
90 
91 void loadRecursorLuaConfig(const std::string& fname, luaConfigDelayedThreads& delayedThreads);
92 void startLuaConfigDelayedThreads(const luaConfigDelayedThreads& delayedThreads, uint64_t generation);
93 
94