5 struct DOHServerConfig;
7 class DOHResponseMapEntry
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)
14 bool matches(const std::string& path) const
16 return d_regex.match(path);
19 uint16_t getStatusCode() const
24 const std::string& getContent() const
29 const boost::optional<std::vector<std::pair<std::string, std::string>>>& getHeaders() const
31 return d_customHeaders;
36 boost::optional<std::vector<std::pair<std::string, std::string>>> d_customHeaders;
37 std::string d_content;
45 d_rotatingTicketsKey.clear();
48 std::shared_ptr<DOHServerConfig> d_dsc{nullptr};
49 std::vector<std::shared_ptr<DOHResponseMapEntry>> d_responsesMap;
50 TLSConfig d_tlsConfig;
51 std::string d_serverTokens{"h2o/dnsdist"};
52 #ifdef HAVE_DNS_OVER_HTTPS
53 std::unique_ptr<OpenSSLTLSTicketKeysRing> d_ticketKeys{nullptr};
55 std::vector<std::pair<std::string, std::string>> d_customResponseHeaders;
58 uint32_t d_idleTimeout{30}; // HTTP idle timeout in seconds
59 std::vector<std::string> d_urls;
61 std::atomic<uint64_t> d_httpconnects{0}; // number of TCP/IP connections established
62 std::atomic<uint64_t> d_getqueries{0}; // valid DNS queries received via GET
63 std::atomic<uint64_t> d_postqueries{0}; // valid DNS queries received via POST
64 std::atomic<uint64_t> d_badrequests{0}; // request could not be converted to dns query
65 std::atomic<uint64_t> d_errorresponses{0}; // dnsdist set 'error' on response
66 std::atomic<uint64_t> d_redirectresponses{0}; // dnsdist set 'redirect' on response
67 std::atomic<uint64_t> d_validresponses{0}; // valid responses sent out
69 struct HTTPVersionStats
71 std::atomic<uint64_t> d_nbQueries{0}; // valid DNS queries received
72 std::atomic<uint64_t> d_nb200Responses{0};
73 std::atomic<uint64_t> d_nb400Responses{0};
74 std::atomic<uint64_t> d_nb403Responses{0};
75 std::atomic<uint64_t> d_nb500Responses{0};
76 std::atomic<uint64_t> d_nb502Responses{0};
77 std::atomic<uint64_t> d_nbOtherResponses{0};
80 HTTPVersionStats d_http1Stats;
81 HTTPVersionStats d_http2Stats;
84 #ifndef HAVE_DNS_OVER_HTTPS
89 void reloadCertificates()
93 void rotateTicketsKey(time_t now)
97 void loadTicketsKeys(const std::string& keyFile)
101 void handleTicketsKeyRotation()
107 void reloadCertificates();
109 void rotateTicketsKey(time_t now);
110 void loadTicketsKeys(const std::string& keyFile);
111 void handleTicketsKeyRotation();
113 #endif /* HAVE_DNS_OVER_HTTPS */
115 time_t getNextTicketsKeyRotation() const
117 return d_ticketsKeyNextRotation;
120 size_t getTicketsKeysCount() const
123 #ifdef HAVE_DNS_OVER_HTTPS
125 res = d_ticketKeys->getKeysCount();
127 #endif /* HAVE_DNS_OVER_HTTPS */
132 time_t d_ticketsKeyNextRotation{0};
133 std::atomic_flag d_rotatingTicketsKey;
136 #ifndef HAVE_DNS_OVER_HTTPS
141 #else /* HAVE_DNS_OVER_HTTPS */
142 #include <unordered_map>
149 std::string response;
152 st_h2o_req_t* req{nullptr};
153 DOHUnit** self{nullptr};
154 std::string contentType;
157 /* the status_code is set from
158 processDOHQuery() (which is executed in
159 the DOH client thread) so that the correct
160 response can be sent in on_dnsdist(),
161 after the DOHUnit has been passed back to
164 uint16_t status_code{200};
165 bool ednsAdded{false};
167 std::string getHTTPPath() const;
168 std::string getHTTPHost() const;
169 std::string getHTTPScheme() const;
170 std::string getHTTPQueryString() const;
171 std::unordered_map<std::string, std::string> getHTTPHeaders() const;
172 void setHTTPResponse(uint16_t statusCode, const std::string& body, const std::string& contentType="");
175 #endif /* HAVE_DNS_OVER_HTTPS */
177 void handleDOHTimeout(DOHUnit* oldDU);