From ec9998007777f02c90999c36dfd9cf4cd8079e90 Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Tue, 9 Feb 2021 17:06:31 +0100 Subject: [PATCH] SVCB: support "auto" hints in the record --- pdns/dnsrecords.cc | 35 +++++++++++++++++++++++++++++++++++ pdns/dnsrecords.hh | 4 ++++ pdns/packethandler.cc | 24 ++++-------------------- pdns/svc-records.hh | 7 +++++++ 4 files changed, 50 insertions(+), 20 deletions(-) diff --git a/pdns/dnsrecords.cc b/pdns/dnsrecords.cc index 6bb5d7e14f..fa267e4b33 100644 --- a/pdns/dnsrecords.cc +++ b/pdns/dnsrecords.cc @@ -716,6 +716,41 @@ string APLRecordContent::getZoneRepresentation(bool noDot) const { /* APL end */ +/* SVCB start */ +bool SVCBBaseRecordContent::autoHint(const SvcParam::SvcParamKey &key) const { + auto p = std::find_if(d_params.begin(), d_params.end(), + [&key](const SvcParam ¶m) { + return param.getKey() == key; + }); + if (p == d_params.end()) { + return false; + } + return p->getAutoHint(); +} + +void SVCBBaseRecordContent::setHints(const SvcParam::SvcParamKey &key, const std::vector &addresses) { + auto p = std::find_if(d_params.begin(), d_params.end(), + [&key](const SvcParam ¶m) { + return param.getKey() == key; + }); + if (p == d_params.end()) { + return; + } + std::vector h; + h.reserve(h.size() + addresses.size()); + h.insert(h.end(), addresses.begin(), addresses.end()); + try { + auto newParam = SvcParam(key, std::move(h)); + d_params.erase(p); + d_params.insert(newParam); + } catch(...) { + // XXX maybe we should SERVFAIL instead? + return; + } +} + +/* SVCB end */ + boilerplate_conv(TKEY, conv.xfrName(d_algo); conv.xfr32BitInt(d_inception); diff --git a/pdns/dnsrecords.hh b/pdns/dnsrecords.hh index d694f879f6..bafe372989 100644 --- a/pdns/dnsrecords.hh +++ b/pdns/dnsrecords.hh @@ -502,6 +502,10 @@ class SVCBBaseRecordContent : public DNSRecordContent public: const DNSName& getTarget() const {return d_target;} uint16_t getPriority() const {return d_priority;} + // Returns true if a value for |key| was set to 'auto' + bool autoHint(const SvcParam::SvcParamKey &key) const; + // Sets the |addresses| to the existing hints for |key| + void setHints(const SvcParam::SvcParamKey &key, const std::vector &addresses); protected: uint16_t d_priority; diff --git a/pdns/packethandler.cc b/pdns/packethandler.cc index fb3ed7a883..ee45ff65be 100644 --- a/pdns/packethandler.cc +++ b/pdns/packethandler.cc @@ -463,17 +463,9 @@ DNSName PacketHandler::doAdditionalServiceProcessing(const DNSName &firstTarget, while (B.get(rr)) { rr.dr.d_place = DNSResourceRecord::ADDITIONAL; switch (qtype) { - case QType::SVCB: { - auto rrc = getRR(rr.dr); - r->addRecord(std::move(rr)); - ret = rrc->getTarget().isRoot() ? ret : rrc->getTarget(); - if (rrc->getPriority() == 0) { - done = false; - } - break; - } + case QType::SVCB: /* fall-through */ case QType::HTTPS: { - auto rrc = getRR(rr.dr); + auto rrc = getRR(rr.dr); r->addRecord(std::move(rr)); ret = rrc->getTarget().isRoot() ? ret : rrc->getTarget(); if (rrc->getPriority() == 0) { @@ -512,17 +504,9 @@ void PacketHandler::doAdditionalProcessing(DNSPacket& p, std::unique_ptr(rr.dr)->d_target; break; - case QType::SVCB: { - auto rrc = getRR(rr.dr); - content = rrc->getTarget(); - if (content.isRoot()) { - content = rr.dr.d_name; - } - content = doAdditionalServiceProcessing(content, rr.dr.d_type, r); - break; - } + case QType::SVCB: /* fall-through */ case QType::HTTPS: { - auto rrc = getRR(rr.dr); + auto rrc = getRR(rr.dr); content = rrc->getTarget(); if (content.isRoot()) { content = rr.dr.d_name; diff --git a/pdns/svc-records.hh b/pdns/svc-records.hh index d2d4b2b779..1ac4eedb43 100644 --- a/pdns/svc-records.hh +++ b/pdns/svc-records.hh @@ -84,6 +84,9 @@ class SvcParam { const std::string& getEchConfig() const; const std::string& getValue() const; + bool getAutoHint() const { return d_autohint; }; + void setAutoHint(const bool value) { d_autohint = value; }; + private: SvcParamKey d_key; std::string d_value; // For keyNNNNN vals @@ -94,5 +97,9 @@ class SvcParam { std::string d_echconfig; // For echconfig uint16_t d_port{0}; // For port + // Set to true if we encountered an "auto" field in hints + // Can only be true when we read SVCParams from text + bool d_autohint{false}; + static const std::map SvcParams; }; -- 2.47.2