]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/doh.hh
dnsdist: Add metrics about TLS versions with DNS over TLS
[thirdparty/pdns.git] / pdns / doh.hh
1 #pragma once
2 #include "iputils.hh"
3 #include "libssl.hh"
4
5 struct DOHServerConfig;
6
7 class DOHResponseMapEntry
8 {
9 public:
10 DOHResponseMapEntry(const std::string& regex, uint16_t status, const std::string& content, const boost::optional<std::vector<std::pair<std::string, std::string>>>& headers): d_regex(regex), d_customHeaders(headers), d_content(content), d_status(status)
11 {
12 }
13
14 bool matches(const std::string& path) const
15 {
16 return d_regex.match(path);
17 }
18
19 uint16_t getStatusCode() const
20 {
21 return d_status;
22 }
23
24 const std::string& getContent() const
25 {
26 return d_content;
27 }
28
29 const boost::optional<std::vector<std::pair<std::string, std::string>>>& getHeaders() const
30 {
31 return d_customHeaders;
32 }
33
34 private:
35 Regex d_regex;
36 boost::optional<std::vector<std::pair<std::string, std::string>>> d_customHeaders;
37 std::string d_content;
38 uint16_t d_status;
39 };
40
41 struct DOHFrontend
42 {
43 std::shared_ptr<DOHServerConfig> d_dsc{nullptr};
44 std::vector<std::pair<std::string, std::string>> d_certKeyPairs;
45 std::vector<std::string> d_ocspFiles;
46 std::vector<std::shared_ptr<DOHResponseMapEntry>> d_responsesMap;
47 std::string d_ciphers;
48 std::string d_ciphers13;
49 std::string d_serverTokens{"h2o/dnsdist"};
50 LibsslTLSVersion d_minTLSVersion{LibsslTLSVersion::TLS10};
51 #ifdef HAVE_DNS_OVER_HTTPS
52 std::unique_ptr<OpenSSLTLSTicketKeysRing> d_ticketKeys{nullptr};
53 #endif
54 std::vector<std::pair<std::string, std::string>> d_customResponseHeaders;
55 ComboAddress d_local;
56
57 uint32_t d_idleTimeout{30}; // HTTP idle timeout in seconds
58 std::vector<std::string> d_urls;
59 std::string d_ticketKeyFile;
60
61 std::atomic_flag d_rotatingTicketsKey;
62 time_t d_ticketsKeyRotationDelay{43200};
63 time_t d_ticketsKeyNextRotation{0};
64 size_t d_maxStoredSessions{20480};
65 uint8_t d_numberOfTicketsKeys{5};
66 bool d_enableTickets{true};
67
68 std::atomic<uint64_t> d_httpconnects{0}; // number of TCP/IP connections established
69 std::atomic<uint64_t> d_getqueries{0}; // valid DNS queries received via GET
70 std::atomic<uint64_t> d_postqueries{0}; // valid DNS queries received via POST
71 std::atomic<uint64_t> d_badrequests{0}; // request could not be converted to dns query
72 std::atomic<uint64_t> d_errorresponses{0}; // dnsdist set 'error' on response
73 std::atomic<uint64_t> d_redirectresponses{0}; // dnsdist set 'redirect' on response
74 std::atomic<uint64_t> d_validresponses{0}; // valid responses sent out
75
76 struct HTTPVersionStats
77 {
78 std::atomic<uint64_t> d_nbQueries{0}; // valid DNS queries received
79 std::atomic<uint64_t> d_nb200Responses{0};
80 std::atomic<uint64_t> d_nb400Responses{0};
81 std::atomic<uint64_t> d_nb403Responses{0};
82 std::atomic<uint64_t> d_nb500Responses{0};
83 std::atomic<uint64_t> d_nb502Responses{0};
84 std::atomic<uint64_t> d_nbOtherResponses{0};
85 };
86
87 HTTPVersionStats d_http1Stats;
88 HTTPVersionStats d_http2Stats;
89
90
91 #ifndef HAVE_DNS_OVER_HTTPS
92 void setup()
93 {
94 }
95
96 void reloadCertificates()
97 {
98 }
99
100 void rotateTicketsKey(time_t now)
101 {
102 }
103
104 void loadTicketsKeys(const std::string& keyFile)
105 {
106 }
107
108 void handleTicketsKeyRotation()
109 {
110 }
111
112 #else
113 void setup();
114 void reloadCertificates();
115
116 void rotateTicketsKey(time_t now);
117 void loadTicketsKeys(const std::string& keyFile);
118 void handleTicketsKeyRotation();
119
120 #endif /* HAVE_DNS_OVER_HTTPS */
121 };
122
123 #ifndef HAVE_DNS_OVER_HTTPS
124 struct DOHUnit
125 {
126 };
127
128 #else /* HAVE_DNS_OVER_HTTPS */
129 #include <unordered_map>
130
131 struct st_h2o_req_t;
132
133 struct DOHUnit
134 {
135 std::string query;
136 std::string response;
137 ComboAddress remote;
138 ComboAddress dest;
139 st_h2o_req_t* req{nullptr};
140 DOHUnit** self{nullptr};
141 std::string contentType;
142 int rsock;
143 uint16_t qtype;
144 /* the status_code is set from
145 processDOHQuery() (which is executed in
146 the DOH client thread) so that the correct
147 response can be sent in on_dnsdist(),
148 after the DOHUnit has been passed back to
149 the main DoH thread.
150 */
151 uint16_t status_code{200};
152 bool ednsAdded{false};
153
154 std::string getHTTPPath() const;
155 std::string getHTTPHost() const;
156 std::string getHTTPScheme() const;
157 std::string getHTTPQueryString() const;
158 std::unordered_map<std::string, std::string> getHTTPHeaders() const;
159 void setHTTPResponse(uint16_t statusCode, const std::string& body, const std::string& contentType="");
160 };
161
162 #endif /* HAVE_DNS_OVER_HTTPS */
163
164 void handleDOHTimeout(DOHUnit* oldDU);