Coverage Report

Created: 2024-04-25 06:25

/src/pdns/pdns/dnsdistdist/doh3.hh
Line
Count
Source (jump to first uncovered line)
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
26
#include "config.h"
27
#include "channel.hh"
28
#include "iputils.hh"
29
#include "libssl.hh"
30
#include "noinitvector.hh"
31
#include "stat_t.hh"
32
#include "dnsdist-idstate.hh"
33
34
struct DOH3ServerConfig;
35
struct DownstreamState;
36
37
#ifdef HAVE_DNS_OVER_HTTP3
38
39
#include "doq-common.hh"
40
41
struct DOH3Frontend
42
{
43
  DOH3Frontend();
44
  DOH3Frontend(const DOH3Frontend&) = delete;
45
  DOH3Frontend(DOH3Frontend&&) = delete;
46
  DOH3Frontend& operator=(const DOH3Frontend&) = delete;
47
  DOH3Frontend& operator=(DOH3Frontend&&) = delete;
48
  ~DOH3Frontend();
49
50
  void setup();
51
  void reloadCertificates();
52
53
  std::unique_ptr<DOH3ServerConfig> d_server_config;
54
  ComboAddress d_local;
55
56
#ifdef __linux__
57
  // On Linux this gives us 128k pending queries (default is 8192 queries),
58
  // which should be enough to deal with huge spikes
59
  uint32_t d_internalPipeBufferSize{1024 * 1024};
60
#else
61
  uint32_t d_internalPipeBufferSize{0};
62
#endif
63
64
  dnsdist::doq::QuicheParams d_quicheParams;
65
  pdns::stat_t d_doh3UnsupportedVersionErrors{0}; // Unsupported protocol version errors
66
  pdns::stat_t d_doh3InvalidTokensReceived{0}; // Discarded received tokens
67
  pdns::stat_t d_validResponses{0}; // Valid responses sent
68
  pdns::stat_t d_errorResponses{0}; // Empty responses (no backend, drops, invalid queries, etc.)
69
};
70
71
struct DOH3Unit
72
{
73
  DOH3Unit(PacketBuffer&& query_) :
74
    query(std::move(query_))
75
  {
76
  }
77
78
  DOH3Unit(const DOH3Unit&) = delete;
79
  DOH3Unit& operator=(const DOH3Unit&) = delete;
80
81
  InternalQueryState ids;
82
  PacketBuffer query;
83
  PacketBuffer response;
84
  PacketBuffer serverConnID;
85
  std::shared_ptr<DownstreamState> downstream{nullptr};
86
  DOH3ServerConfig* dsc{nullptr};
87
  uint64_t streamID{0};
88
  size_t proxyProtocolPayloadSize{0};
89
  uint16_t status_code{200};
90
  /* whether the query was re-sent to the backend over
91
     TCP after receiving a truncated answer over UDP */
92
  bool tcp{false};
93
};
94
95
using DOH3UnitUniquePtr = std::unique_ptr<DOH3Unit>;
96
97
struct CrossProtocolQuery;
98
struct DNSQuestion;
99
std::unique_ptr<CrossProtocolQuery> getDOH3CrossProtocolQueryFromDQ(DNSQuestion& dnsQuestion, bool isResponse);
100
101
void doh3Thread(ClientState* clientState);
102
103
#else
104
105
struct DOH3Unit
106
{
107
};
108
109
struct DOH3Frontend
110
{
111
  DOH3Frontend()
112
0
  {
113
0
  }
114
  void setup()
115
0
  {
116
0
  }
117
};
118
119
#endif