]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
SVCB: support "auto" hints in the record
authorPieter Lexis <pieter.lexis@powerdns.com>
Tue, 9 Feb 2021 16:06:31 +0000 (17:06 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Mon, 29 Mar 2021 17:10:31 +0000 (19:10 +0200)
pdns/dnsrecords.cc
pdns/dnsrecords.hh
pdns/packethandler.cc
pdns/svc-records.hh

index 6bb5d7e14f8f70c716aae35c4c373c077afaf92f..fa267e4b33f27d0ce051dd624138d74a3fb04ffc 100644 (file)
@@ -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 &param) {
+        return param.getKey() == key;
+      });
+  if (p == d_params.end()) {
+    return false;
+  }
+  return p->getAutoHint();
+}
+
+void SVCBBaseRecordContent::setHints(const SvcParam::SvcParamKey &key, const std::vector<ComboAddress> &addresses) {
+  auto p = std::find_if(d_params.begin(), d_params.end(),
+      [&key](const SvcParam &param) {
+        return param.getKey() == key;
+      });
+  if (p == d_params.end()) {
+    return;
+  }
+  std::vector<ComboAddress> 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);
index d694f879f6fd918264360a8639ce0a932a0d9a3d..bafe372989b6e0569c5b948e9631e5cad2c4d9b3 100644 (file)
@@ -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<ComboAddress> &addresses);
 
   protected:
     uint16_t d_priority;
index fb3ed7a8837cd001f18643efa0e972fd717887ae..ee45ff65be8800e2625d3107ca2825f662005496 100644 (file)
@@ -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<SVCBRecordContent>(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<HTTPSRecordContent>(rr.dr);
+          auto rrc = getRR<SVCBBaseRecordContent>(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<DNSPack
         case QType::SRV:
           content=getRR<SRVRecordContent>(rr.dr)->d_target;
           break;
-        case QType::SVCB: {
-          auto rrc = getRR<SVCBRecordContent>(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<HTTPSRecordContent>(rr.dr);
+          auto rrc = getRR<SVCBBaseRecordContent>(rr.dr);
           content = rrc->getTarget();
           if (content.isRoot()) {
             content = rr.dr.d_name;
index d2d4b2b7798ce76f9bc1007f9cb39f933b9823e0..1ac4eedb43abb673f7d6838a35025e0424b09c68 100644 (file)
@@ -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<std::string, SvcParamKey> SvcParams;
 };