Coverage Report

Created: 2026-03-08 06:22

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