From: Remi Gacogne Date: Fri, 22 Sep 2023 13:53:00 +0000 (+0200) Subject: dnsdist: Small cleanup in doq.cc and doq.hh X-Git-Tag: rec-5.0.0-alpha2~6^2~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=acde66584880900c03679aba07126459f7f5c3b8;p=thirdparty%2Fpdns.git dnsdist: Small cleanup in doq.cc and doq.hh --- diff --git a/pdns/dnsdistdist/doq.cc b/pdns/dnsdistdist/doq.cc index e283a754b4..784c7c03ea 100644 --- a/pdns/dnsdistdist/doq.cc +++ b/pdns/dnsdistdist/doq.cc @@ -22,24 +22,24 @@ #include "doq.hh" -#include "dnsdist-tcp.hh" -#include "dnsdist-random.hh" +#ifdef HAVE_DNS_OVER_QUIC +#include + #include "dnsparser.hh" #include "dolog.hh" #include "iputils.hh" #include "misc.hh" +#include "sodcrypto.hh" #include "sstuff.hh" #include "threadname.hh" + #include "dnsdist-ecs.hh" #include "dnsdist-proxy-protocol.hh" -#include "sodcrypto.hh" +#include "dnsdist-tcp.hh" +#include "dnsdist-random.hh" static std::string s_quicRetryTokenKey = newKey(false); -#ifdef HAVE_DNS_OVER_QUIC - -#include - using QuicheConnection = std::unique_ptr; using QuicheConfig = std::unique_ptr; @@ -60,12 +60,10 @@ public: QuicheConnection d_conn; }; -#endif - static void sendBackDOQUnit(DOQUnitUniquePtr&& du, const char* description); struct DOQServerConfig { - DOQServerConfig(std::unique_ptr&& config_, uint32_t internalPipeBufferSize) : + DOQServerConfig(QuicheConfig&& config_, uint32_t internalPipeBufferSize) : config(std::move(config_)) { { @@ -88,6 +86,17 @@ struct DOQServerConfig pdns::channel::Receiver d_responseReceiver; }; +/* these might seem useless, but they are needed because + they need to be declared _after_ the definition of DOQServerConfig + so that we can use a unique_ptr in DOQFrontend */ +DOQFrontend::DOQFrontend() +{ +} + +DOQFrontend::~DOQFrontend() +{ +} + #if 0 #define DEBUGLOG_ENABLED #define DEBUGLOG(x) std::cerr << x << std::endl; @@ -95,7 +104,7 @@ struct DOQServerConfig #define DEBUGLOG(x) #endif -static constexpr size_t MAX_DATAGRAM_SIZE = 1350; +static constexpr size_t MAX_DATAGRAM_SIZE = 1200; static constexpr size_t LOCAL_CONN_ID_LEN = 16; static std::map s_connections; @@ -269,6 +278,7 @@ static void fillRandom(PacketBuffer& buffer, size_t size) --size; } } + void DOQFrontend::setup() { auto config = QuicheConfig(quiche_config_new(QUICHE_PROTOCOL_VERSION), quiche_config_free); @@ -286,7 +296,7 @@ void DOQFrontend::setup() } { - const std::array alpn{'\x03', 'd', 'o', 'q'}; + constexpr std::array alpn{'\x03', 'd', 'o', 'q'}; auto res = quiche_config_set_application_protos(config.get(), alpn.data(), alpn.size()); @@ -296,7 +306,7 @@ void DOQFrontend::setup() } quiche_config_set_max_idle_timeout(config.get(), d_idleTimeout * 1000); - quiche_config_set_max_recv_udp_payload_size(config.get(), MAX_DATAGRAM_SIZE); + /* maximum size of an outgoing packet, which means the buffer we pass to quiche_conn_send() should be at least that big */ quiche_config_set_max_send_udp_payload_size(config.get(), MAX_DATAGRAM_SIZE); // The number of concurrent remotely-initiated bidirectional streams to be open at any given time @@ -320,7 +330,7 @@ void DOQFrontend::setup() quiche_config_set_stateless_reset_token(config.get(), reinterpret_cast(resetToken.data())); } - d_server_config = std::make_shared(std::move(config), d_internalPipeBufferSize); + d_server_config = std::make_unique(std::move(config), d_internalPipeBufferSize); } static std::optional getCID() @@ -869,3 +879,5 @@ void doqThread(ClientState* cs) DEBUGLOG("Caught fatal error: " << e.what()); } } + +#endif /* HAVE_DNS_OVER_QUIC */ diff --git a/pdns/dnsdistdist/doq.hh b/pdns/dnsdistdist/doq.hh index 624af04d87..72d276892b 100644 --- a/pdns/dnsdistdist/doq.hh +++ b/pdns/dnsdistdist/doq.hh @@ -22,6 +22,8 @@ #pragma once #include + +#include "config.h" #include "channel.hh" #include "iputils.hh" #include "libssl.hh" @@ -36,11 +38,14 @@ struct DownstreamState; struct DOQFrontend { - DOQFrontend() - { - } + DOQFrontend(); + DOQFrontend(const DOQFrontend&) = delete; + DOQFrontend(DOQFrontend&&) = delete; + DOQFrontend& operator=(const DOQFrontend&) = delete; + DOQFrontend& operator=(DOQFrontend&&) = delete; + ~DOQFrontend(); - std::shared_ptr d_server_config{nullptr}; + std::unique_ptr d_server_config{nullptr}; TLSConfig d_tlsConfig; ComboAddress d_local; @@ -61,7 +66,6 @@ struct DOQUnit DOQUnit(PacketBuffer&& q) : query(std::move(q)) { - ids.ednsAdded = false; } DOQUnit(const DOQUnit&) = delete;