Coverage Report

Created: 2026-07-16 06:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pdns/pdns/dnsdistdist/doh3.hh
Line
Count
Source
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
24
#include <memory>
25
#include <string>
26
#include <unordered_map>
27
28
#include "config.h"
29
#include "noinitvector.hh"
30
31
#ifdef HAVE_DNS_OVER_HTTP3
32
#include "channel.hh"
33
#include "dolog.hh"
34
#include "iputils.hh"
35
#include "libssl.hh"
36
#include "stat_t.hh"
37
38
struct DOH3ServerConfig;
39
struct DownstreamState;
40
#endif
41
42
namespace dnsdist::doh3
43
{
44
using h3_headers_t = std::unordered_map<std::string, std::string>;
45
}
46
47
#ifdef HAVE_DNS_OVER_HTTP3
48
49
#include "dnsdist-idstate.hh"
50
#include "doq-common.hh"
51
#include "dnsdist-doh-common.hh"
52
53
struct DOH3Frontend
54
{
55
  DOH3Frontend();
56
  DOH3Frontend(const DOH3Frontend&) = delete;
57
  DOH3Frontend(DOH3Frontend&&) = delete;
58
  DOH3Frontend& operator=(const DOH3Frontend&) = delete;
59
  DOH3Frontend& operator=(DOH3Frontend&&) = delete;
60
  ~DOH3Frontend();
61
62
  void setup();
63
  void reloadCertificates();
64
  const Logr::Logger& getLogger()
65
  {
66
    return *d_logger;
67
  }
68
69
  std::shared_ptr<const Logr::Logger> d_logger{nullptr};
70
  std::shared_ptr<std::vector<std::shared_ptr<DOHResponseMapEntry>>> d_responsesMap;
71
  std::unique_ptr<DOH3ServerConfig> d_server_config;
72
  ComboAddress d_local;
73
74
#ifdef __linux__
75
  // On Linux this gives us 128k pending queries (default is 8192 queries),
76
  // which should be enough to deal with huge spikes
77
  uint32_t d_internalPipeBufferSize{1024 * 1024};
78
#else
79
  uint32_t d_internalPipeBufferSize{0};
80
#endif
81
82
  dnsdist::doq::QuicheParams d_quicheParams;
83
  pdns::stat_t d_doh3UnsupportedVersionErrors{0}; // Unsupported protocol version errors
84
  pdns::stat_t d_doh3InvalidTokensReceived{0}; // Discarded received tokens
85
  pdns::stat_t d_validResponses{0}; // Valid responses sent
86
  pdns::stat_t d_errorResponses{0}; // Empty responses (no backend, drops, invalid queries, etc.)
87
};
88
89
struct DOH3Unit
90
{
91
  DOH3Unit(PacketBuffer&& query_) :
92
    query(std::move(query_))
93
  {
94
  }
95
96
  DOH3Unit(const DOH3Unit&) = delete;
97
  DOH3Unit& operator=(const DOH3Unit&) = delete;
98
99
  [[nodiscard]] std::string getHTTPPath() const;
100
  [[nodiscard]] std::string getHTTPQueryString() const;
101
  [[nodiscard]] std::string getHTTPHost() const;
102
  [[nodiscard]] std::string getHTTPScheme() const;
103
  [[nodiscard]] const dnsdist::doh3::h3_headers_t& getHTTPHeaders() const;
104
  void setHTTPResponse(uint16_t statusCode, PacketBuffer&& body, const std::string& contentType = "");
105
106
  InternalQueryState ids;
107
  PacketBuffer query;
108
  PacketBuffer response;
109
  PacketBuffer serverConnID;
110
  dnsdist::doh3::h3_headers_t headers;
111
  std::shared_ptr<DownstreamState> downstream{nullptr};
112
  std::shared_ptr<const std::string> sni{nullptr};
113
  std::string d_contentTypeOut;
114
  DOH3ServerConfig* dsc{nullptr};
115
  uint64_t streamID{0};
116
  size_t proxyProtocolPayloadSize{0};
117
  uint16_t status_code{200};
118
  /* whether the query was re-sent to the backend over
119
     TCP after receiving a truncated answer over UDP */
120
  bool tcp{false};
121
};
122
123
using DOH3UnitUniquePtr = std::unique_ptr<DOH3Unit>;
124
125
struct CrossProtocolQuery;
126
struct DNSQuestion;
127
std::unique_ptr<CrossProtocolQuery> getDOH3CrossProtocolQueryFromDQ(DNSQuestion& dnsQuestion, bool isResponse);
128
129
void doh3Thread(ClientState* clientState);
130
131
#else
132
133
struct DOH3Unit
134
{
135
  [[nodiscard]] std::string getHTTPPath() const;
136
  [[nodiscard]] std::string getHTTPQueryString() const;
137
  [[nodiscard]] std::string getHTTPHost() const;
138
  [[nodiscard]] std::string getHTTPScheme() const;
139
  [[nodiscard]] const dnsdist::doh3::h3_headers_t& getHTTPHeaders() const;
140
  void setHTTPResponse(uint16_t, PacketBuffer&&, const std::string&);
141
};
142
143
struct DOH3Frontend
144
{
145
  DOH3Frontend() = default;
146
  void setup()
147
0
  {
148
0
  }
149
};
150
151
#endif