From a1a819fdbdaee1268a94f17b392bede82e58c259 Mon Sep 17 00:00:00 2001 From: Charles-Henri Bruyand Date: Thu, 21 Sep 2023 11:32:18 +0200 Subject: [PATCH] doq: use dnsdist::getRandomValue and fix a few compilation warnings --- pdns/dnsdistdist/doq.cc | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/pdns/dnsdistdist/doq.cc b/pdns/dnsdistdist/doq.cc index 8d704a17dc..80c1c39359 100644 --- a/pdns/dnsdistdist/doq.cc +++ b/pdns/dnsdistdist/doq.cc @@ -23,6 +23,7 @@ #include "doq.hh" #include "dnsdist-tcp.hh" +#include "dnsdist-random.hh" #include "dolog.hh" #include "iputils.hh" #include "misc.hh" @@ -33,9 +34,8 @@ #include "dnsdist-proxy-protocol.hh" static void sendBackDOQUnit(DOQUnitUniquePtr&& du, const char* description); -class DOQServerConfig +struct DOQServerConfig { -public: DOQServerConfig(std::unique_ptr&& config_) : config(std::move(config_)) { @@ -264,16 +264,13 @@ void DOQFrontend::setup() static std::optional getCID() { - // FIXME replace it - int rng = open("/dev/urandom", O_RDONLY); - if (rng < 0) { - return std::nullopt; - } PacketBuffer buffer; + size_t idx = 0; + buffer.resize(LOCAL_CONN_ID_LEN); - auto got = read(rng, buffer.data(), LOCAL_CONN_ID_LEN); - if (got < 0) { - return std::nullopt; + while (idx < LOCAL_CONN_ID_LEN) { + buffer.at(idx) = dnsdist::getRandomValue(std::numeric_limits::max()); + ++idx; } return buffer; @@ -623,8 +620,6 @@ void doqThread(ClientState* cs) size_t scid_len = scid.size(); std::array dcid; size_t dcid_len = dcid.size(); - std::array odcid; - size_t odcid_len = odcid.size(); std::array token; size_t token_len = token.size(); -- 2.39.2