]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/doh.hh
dnsdist: Add regression tests for DoH HTTP bindings and actions
[thirdparty/pdns.git] / pdns / doh.hh
1 #pragma once
2 #include "iputils.hh"
3
4 struct DOHServerConfig;
5
6 struct DOHFrontend
7 {
8 std::shared_ptr<DOHServerConfig> d_dsc{nullptr};
9 std::vector<std::pair<std::string, std::string>> d_certKeyPairs;
10 std::string d_ciphers;
11 std::string d_ciphers13;
12 std::string d_serverTokens{"h2o/dnsdist"};
13 std::vector<std::pair<std::string, std::string>> d_customResponseHeaders;
14 ComboAddress d_local;
15
16 uint32_t d_idleTimeout{30}; // HTTP idle timeout in seconds
17 std::vector<std::string> d_urls;
18
19 std::atomic<uint64_t> d_httpconnects; // number of TCP/IP connections established
20 std::atomic<uint64_t> d_tls10queries; // valid DNS queries received via TLSv1.0
21 std::atomic<uint64_t> d_tls11queries; // valid DNS queries received via TLSv1.1
22 std::atomic<uint64_t> d_tls12queries; // valid DNS queries received via TLSv1.2
23 std::atomic<uint64_t> d_tls13queries; // valid DNS queries received via TLSv1.3
24 std::atomic<uint64_t> d_tlsUnknownqueries; // valid DNS queries received via unknown TLS version
25
26 std::atomic<uint64_t> d_getqueries; // valid DNS queries received via GET
27 std::atomic<uint64_t> d_postqueries; // valid DNS queries received via POST
28 std::atomic<uint64_t> d_badrequests; // request could not be converted to dns query
29 std::atomic<uint64_t> d_errorresponses; // dnsdist set 'error' on response
30 std::atomic<uint64_t> d_redirectresponses; // dnsdist set 'redirect' on response
31 std::atomic<uint64_t> d_validresponses; // valid responses sent out
32
33 struct HTTPVersionStats
34 {
35 std::atomic<uint64_t> d_nbQueries{0}; // valid DNS queries received
36 std::atomic<uint64_t> d_nb200Responses{0};
37 std::atomic<uint64_t> d_nb400Responses{0};
38 std::atomic<uint64_t> d_nb403Responses{0};
39 std::atomic<uint64_t> d_nb500Responses{0};
40 std::atomic<uint64_t> d_nb502Responses{0};
41 std::atomic<uint64_t> d_nbOtherResponses{0};
42 };
43
44 HTTPVersionStats d_http1Stats;
45 HTTPVersionStats d_http2Stats;
46
47 #ifndef HAVE_DNS_OVER_HTTPS
48 void setup()
49 {
50 }
51
52 void reloadCertificates()
53 {
54 }
55 #else
56 void setup();
57 void reloadCertificates();
58 #endif /* HAVE_DNS_OVER_HTTPS */
59 };
60
61 #ifndef HAVE_DNS_OVER_HTTPS
62 struct DOHUnit
63 {
64 };
65
66 #else /* HAVE_DNS_OVER_HTTPS */
67 #include <unordered_map>
68
69 struct st_h2o_req_t;
70
71 struct DOHUnit
72 {
73 std::string query;
74 std::string response;
75 ComboAddress remote;
76 ComboAddress dest;
77 st_h2o_req_t* req{nullptr};
78 DOHUnit** self{nullptr};
79 std::string contentType;
80 int rsock;
81 uint16_t qtype;
82 /* the status_code is set from
83 processDOHQuery() (which is executed in
84 the DOH client thread) so that the correct
85 response can be sent in on_dnsdist(),
86 after the DOHUnit has been passed back to
87 the main DoH thread.
88 */
89 uint16_t status_code{200};
90 bool ednsAdded{false};
91
92 std::string getHTTPPath() const;
93 std::string getHTTPHost() const;
94 std::string getHTTPScheme() const;
95 std::string getHTTPQueryString() const;
96 std::unordered_map<std::string, std::string> getHTTPHeaders() const;
97 void setHTTPResponse(uint16_t statusCode, const std::string& body, const std::string& contentType="");
98 };
99
100 #endif /* HAVE_DNS_OVER_HTTPS */
101
102 void handleDOHTimeout(DOHUnit* oldDU);