]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Represent scope as a prefix length and not a full Netmask (ip + prefix) object
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 14 Jan 2025 16:03:39 +0000 (17:03 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 15 Jan 2025 10:20:44 +0000 (11:20 +0100)
25 files changed:
pdns/calidns.cc
pdns/dnsdistdist/dnsdist-cache.cc
pdns/dnsdistdist/dnsdist-ecs.cc
pdns/dnsdistdist/test-dnsdist_cc.cc
pdns/dnsdistdist/test-dnsdistedns.cc
pdns/dnsdistdist/test-dnsdistpacketcache_cc.cc
pdns/dnspacket.cc
pdns/dnsproxy.cc
pdns/dnsreplay.cc
pdns/ednssubnet.cc
pdns/ednssubnet.hh
pdns/recursordist/lua-recursor4.cc
pdns/recursordist/lwres.cc
pdns/recursordist/pdns_recursor.cc
pdns/recursordist/rec-main.cc
pdns/recursordist/rec-tcp.cc
pdns/recursordist/syncres.cc
pdns/recursordist/syncres.hh
pdns/recursordist/test-ednsoptions_cc.cc
pdns/recursordist/test-syncres_cc1.cc
pdns/recursordist/test-syncres_cc2.cc
pdns/sdig.cc
pdns/stubresolver.cc
pdns/test-packetcache_cc.cc
pdns/test-packetcache_hh.cc

index 920a4df88c551b560d46e0440a76443e03db2ed5..8c5d218740ee44ee9873b41064d8fcb3ba0fd492 100644 (file)
@@ -243,8 +243,8 @@ void parseQueryFile(const std::string& queryFile, vector<std::shared_ptr<vector<
 
     if (!subnet.empty() || addECS) {
       EDNSSubnetOpts opt;
-      opt.source = Netmask(subnet.empty() ? "0.0.0.0/32" : subnet);
-      ednsOptions.emplace_back(EDNSOptionCode::ECS, makeEDNSSubnetOptsString(opt));
+      opt.setSource(Netmask(subnet.empty() ? "0.0.0.0/32" : subnet));
+      ednsOptions.emplace_back(EDNSOptionCode::ECS, opt.makeOptString());
     }
 
     if (!ednsOptions.empty() || (packetWriter.getHeader()->id % 2) != 0) {
index e3522a38e8077bf0e648e4ed5cb87cdce74b0ed9..020825306be5303e6609c79cb117f699fdec57b3 100644 (file)
@@ -65,8 +65,8 @@ bool DNSDistPacketCache::getClientSubnet(const PacketBuffer& packet, size_t qnam
 
       EDNSSubnetOpts eso;
       // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
-      if (getEDNSSubnetOptsFromString(reinterpret_cast<const char*>(&packet.at(optRDPosition + ecsOptionStartPosition + (EDNS_OPTION_CODE_SIZE + EDNS_OPTION_LENGTH_SIZE))), ecsOptionSize - (EDNS_OPTION_CODE_SIZE + EDNS_OPTION_LENGTH_SIZE), &eso)) {
-        subnet = eso.source;
+      if (EDNSSubnetOpts::getFromString(reinterpret_cast<const char*>(&packet.at(optRDPosition + ecsOptionStartPosition + (EDNS_OPTION_CODE_SIZE + EDNS_OPTION_LENGTH_SIZE))), ecsOptionSize - (EDNS_OPTION_CODE_SIZE + EDNS_OPTION_LENGTH_SIZE), &eso)) {
+        subnet = eso.getSource();
         return true;
       }
     }
index 782be6b75a65d80b7538778030486ba8610d1e81..dc6b31cb88dec18710ff5790fb4bb8984562b619 100644 (file)
@@ -436,8 +436,8 @@ void generateECSOption(const ComboAddress& source, string& res, uint16_t ECSPref
 {
   Netmask sourceNetmask(source, ECSPrefixLength);
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = sourceNetmask;
-  string payload = makeEDNSSubnetOptsString(ecsOpts);
+  ecsOpts.setSource(sourceNetmask);
+  string payload = ecsOpts.makeOptString();
   generateEDNSOption(EDNSOptionCode::ECS, payload, res);
 }
 
index 1cca05f66c40ae82e7a953f4eef4c152cb247902..38dbd916d3978539f936485d8c1f366e1be2e4eb 100644 (file)
@@ -478,8 +478,8 @@ BOOST_AUTO_TEST_CASE(replaceECSWithSameSize)
   GenericDNSPacketWriter<PacketBuffer> packetWriter(query, name, QType::A, QClass::IN, 0);
   packetWriter.getHeader()->rd = 1;
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = Netmask(origRemote, ECSSourcePrefixV4);
-  string origECSOption = makeEDNSSubnetOptsString(ecsOpts);
+  ecsOpts.setSource(Netmask(origRemote, ECSSourcePrefixV4));
+  string origECSOption = ecsOpts.makeOptString();
   GenericDNSPacketWriter<PacketBuffer>::optvect_t opts;
   opts.emplace_back(EDNSOptionCode::ECS, origECSOption);
   packetWriter.addOpt(512, 0, 0, opts);
@@ -518,8 +518,8 @@ BOOST_AUTO_TEST_CASE(replaceECSWithSameSizeAlreadyParsed)
   GenericDNSPacketWriter<PacketBuffer> packetWriter(query, ids.qname, QType::A, QClass::IN, 0);
   packetWriter.getHeader()->rd = 1;
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = Netmask(origRemote, ECSSourcePrefixV4);
-  string origECSOption = makeEDNSSubnetOptsString(ecsOpts);
+  ecsOpts.setSource(Netmask(origRemote, ECSSourcePrefixV4));
+  string origECSOption = ecsOpts.makeOptString();
   GenericDNSPacketWriter<PacketBuffer>::optvect_t opts;
   opts.emplace_back(EDNSOptionCode::ECS, origECSOption);
   packetWriter.addOpt(512, 0, 0, opts);
@@ -565,8 +565,8 @@ BOOST_AUTO_TEST_CASE(replaceECSWithSmaller)
   GenericDNSPacketWriter<PacketBuffer> packetWriter(query, name, QType::A, QClass::IN, 0);
   packetWriter.getHeader()->rd = 1;
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = Netmask(origRemote, 32);
-  string origECSOption = makeEDNSSubnetOptsString(ecsOpts);
+  ecsOpts.setSource(Netmask(origRemote, 32));
+  string origECSOption = ecsOpts.makeOptString();
   GenericDNSPacketWriter<PacketBuffer>::optvect_t opts;
   opts.emplace_back(EDNSOptionCode::ECS, origECSOption);
   packetWriter.addOpt(512, 0, 0, opts);
@@ -605,8 +605,8 @@ BOOST_AUTO_TEST_CASE(replaceECSWithLarger)
   EDNSSubnetOpts ecsOpts;
   // smaller (less specific so less bits) option
   static_assert(8 < ECSSourcePrefixV4, "The ECS scope should be smaller");
-  ecsOpts.source = Netmask(origRemote, 8);
-  string origECSOption = makeEDNSSubnetOptsString(ecsOpts);
+  ecsOpts.setSource(Netmask(origRemote, 8));
+  string origECSOption = ecsOpts.makeOptString();
   GenericDNSPacketWriter<PacketBuffer>::optvect_t opts;
   opts.emplace_back(EDNSOptionCode::ECS, origECSOption);
   packetWriter.addOpt(512, 0, 0, opts);
@@ -661,8 +661,8 @@ BOOST_AUTO_TEST_CASE(replaceECSFollowedByTSIG)
   GenericDNSPacketWriter<PacketBuffer> packetWriter(query, name, QType::A, QClass::IN, 0);
   packetWriter.getHeader()->rd = 1;
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = Netmask(origRemote, 8);
-  string origECSOption = makeEDNSSubnetOptsString(ecsOpts);
+  ecsOpts.setSource(Netmask(origRemote, 8));
+  string origECSOption = ecsOpts.makeOptString();
   GenericDNSPacketWriter<PacketBuffer>::optvect_t opts;
   opts.emplace_back(EDNSOptionCode::ECS, origECSOption);
   packetWriter.addOpt(512, 0, 0, opts);
@@ -720,8 +720,8 @@ BOOST_AUTO_TEST_CASE(replaceECSAfterAN)
   packetWriter.startRecord(DNSName("powerdns.com."), QType::A, 0, QClass::IN, DNSResourceRecord::ANSWER, true);
   packetWriter.commit();
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = Netmask(origRemote, 8);
-  string origECSOption = makeEDNSSubnetOptsString(ecsOpts);
+  ecsOpts.setSource(Netmask(origRemote, 8));
+  string origECSOption = ecsOpts.makeOptString();
   GenericDNSPacketWriter<PacketBuffer>::optvect_t opts;
   opts.emplace_back(EDNSOptionCode::ECS, origECSOption);
   packetWriter.addOpt(512, 0, 0, opts);
@@ -778,8 +778,8 @@ BOOST_AUTO_TEST_CASE(replaceECSAfterAuth)
   packetWriter.startRecord(DNSName("powerdns.com."), QType::A, 0, QClass::IN, DNSResourceRecord::AUTHORITY, true);
   packetWriter.commit();
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = Netmask(origRemote, 8);
-  string origECSOption = makeEDNSSubnetOptsString(ecsOpts);
+  ecsOpts.setSource(Netmask(origRemote, 8));
+  string origECSOption = ecsOpts.makeOptString();
   GenericDNSPacketWriter<PacketBuffer>::optvect_t opts;
   opts.emplace_back(EDNSOptionCode::ECS, origECSOption);
   packetWriter.addOpt(512, 0, 0, opts);
@@ -834,8 +834,8 @@ BOOST_AUTO_TEST_CASE(replaceECSBetweenTwoRecords)
   GenericDNSPacketWriter<PacketBuffer> packetWriter(query, name, QType::A, QClass::IN, 0);
   packetWriter.getHeader()->rd = 1;
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = Netmask(origRemote, 8);
-  string origECSOption = makeEDNSSubnetOptsString(ecsOpts);
+  ecsOpts.setSource(Netmask(origRemote, 8));
+  string origECSOption = ecsOpts.makeOptString();
   GenericDNSPacketWriter<PacketBuffer>::optvect_t opts;
   opts.emplace_back(EDNSOptionCode::ECS, origECSOption);
   packetWriter.startRecord(DNSName("additional"), QType::A, 0, QClass::IN, DNSResourceRecord::ADDITIONAL, false);
@@ -1099,8 +1099,8 @@ BOOST_AUTO_TEST_CASE(removeECSWhenOnlyOption)
   packetWriter.commit();
 
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = Netmask(origRemote, ECSSourcePrefixV4);
-  string origECSOptionStr = makeEDNSSubnetOptsString(ecsOpts);
+  ecsOpts.setSource(Netmask(origRemote, ECSSourcePrefixV4));
+  string origECSOptionStr = ecsOpts.makeOptString();
   GenericDNSPacketWriter<PacketBuffer>::optvect_t opts;
   opts.emplace_back(EDNSOptionCode::ECS, origECSOptionStr);
   packetWriter.addOpt(512, 0, 0, opts);
@@ -1149,8 +1149,8 @@ BOOST_AUTO_TEST_CASE(removeECSWhenFirstOption)
   packetWriter.commit();
 
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = Netmask(origRemote, ECSSourcePrefixV6);
-  string origECSOptionStr = makeEDNSSubnetOptsString(ecsOpts);
+  ecsOpts.setSource(Netmask(origRemote, ECSSourcePrefixV6));
+  string origECSOptionStr = ecsOpts.makeOptString();
   EDNSCookiesOpt cookiesOpt("deadbeefdeadbeef");
   string cookiesOptionStr = cookiesOpt.makeOptString();
   GenericDNSPacketWriter<PacketBuffer>::optvect_t opts;
@@ -1202,9 +1202,8 @@ BOOST_AUTO_TEST_CASE(removeECSWhenIntermediaryOption)
   packetWriter.commit();
 
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = Netmask(origRemote, ECSSourcePrefixV4);
-  string origECSOptionStr = makeEDNSSubnetOptsString(ecsOpts);
-
+  ecsOpts.setSource(Netmask(origRemote, ECSSourcePrefixV4));
+  string origECSOptionStr = ecsOpts.makeOptString();
   EDNSCookiesOpt cookiesOpt("deadbeefdeadbeef");
   string cookiesOptionStr1 = cookiesOpt.makeOptString();
   string cookiesOptionStr2 = cookiesOpt.makeOptString();
@@ -1261,8 +1260,8 @@ BOOST_AUTO_TEST_CASE(removeECSWhenLastOption)
   EDNSCookiesOpt cookiesOpt("deadbeefdeadbeef");
   string cookiesOptionStr = cookiesOpt.makeOptString();
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = Netmask(origRemote, ECSSourcePrefixV4);
-  string origECSOptionStr = makeEDNSSubnetOptsString(ecsOpts);
+  ecsOpts.setSource(Netmask(origRemote, ECSSourcePrefixV4));
+  string origECSOptionStr = ecsOpts.makeOptString();
   GenericDNSPacketWriter<PacketBuffer>::optvect_t opts;
   opts.emplace_back(EDNSOptionCode::COOKIE, cookiesOptionStr);
   opts.emplace_back(EDNSOptionCode::ECS, origECSOptionStr);
@@ -1308,8 +1307,8 @@ BOOST_AUTO_TEST_CASE(rewritingWithoutECSWhenOnlyOption)
   packetWriter.xfr32BitInt(0x01020304);
 
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = Netmask(origRemote, ECSSourcePrefixV4);
-  string origECSOptionStr = makeEDNSSubnetOptsString(ecsOpts);
+  ecsOpts.setSource(Netmask(origRemote, ECSSourcePrefixV4));
+  string origECSOptionStr = ecsOpts.makeOptString();
   GenericDNSPacketWriter<PacketBuffer>::optvect_t opts;
   opts.emplace_back(EDNSOptionCode::ECS, origECSOptionStr);
   packetWriter.addOpt(512, 0, 0, opts);
@@ -1347,8 +1346,8 @@ BOOST_AUTO_TEST_CASE(rewritingWithoutECSWhenFirstOption)
   packetWriter.xfr32BitInt(0x01020304);
 
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = Netmask(origRemote, ECSSourcePrefixV4);
-  string origECSOptionStr = makeEDNSSubnetOptsString(ecsOpts);
+  ecsOpts.setSource(Netmask(origRemote, ECSSourcePrefixV4));
+  string origECSOptionStr = ecsOpts.makeOptString();
   EDNSCookiesOpt cookiesOpt("deadbeefdeadbeef");
   string cookiesOptionStr = cookiesOpt.makeOptString();
   GenericDNSPacketWriter<PacketBuffer>::optvect_t opts;
@@ -1389,8 +1388,8 @@ BOOST_AUTO_TEST_CASE(rewritingWithoutECSWhenIntermediaryOption)
   packetWriter.xfr32BitInt(0x01020304);
 
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = Netmask(origRemote, ECSSourcePrefixV4);
-  string origECSOptionStr = makeEDNSSubnetOptsString(ecsOpts);
+  ecsOpts.setSource(Netmask(origRemote, ECSSourcePrefixV4));
+  string origECSOptionStr = ecsOpts.makeOptString();
   EDNSCookiesOpt cookiesOpt("deadbeefdeadbeef");
   string cookiesOptionStr1 = cookiesOpt.makeOptString();
   string cookiesOptionStr2 = cookiesOpt.makeOptString();
@@ -1433,8 +1432,8 @@ BOOST_AUTO_TEST_CASE(rewritingWithoutECSWhenLastOption)
   packetWriter.xfr32BitInt(0x01020304);
 
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = Netmask(origRemote, ECSSourcePrefixV4);
-  string origECSOptionStr = makeEDNSSubnetOptsString(ecsOpts);
+  ecsOpts.setSource(Netmask(origRemote, ECSSourcePrefixV4));
+  string origECSOptionStr = ecsOpts.makeOptString();
   EDNSCookiesOpt cookiesOpt("deadbeefdeadbeef");
   string cookiesOptionStr = cookiesOpt.makeOptString();
   GenericDNSPacketWriter<PacketBuffer>::optvect_t opts;
@@ -1500,8 +1499,8 @@ BOOST_AUTO_TEST_CASE(test_getEDNSZ)
   uint16_t qtype = QType::A;
   uint16_t qclass = QClass::IN;
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = Netmask(ComboAddress("127.0.0.1"), ECSSourcePrefixV4);
-  string origECSOptionStr = makeEDNSSubnetOptsString(ecsOpts);
+  ecsOpts.setSource(Netmask(ComboAddress("127.0.0.1"), ECSSourcePrefixV4));
+  string origECSOptionStr = ecsOpts.makeOptString();
   EDNSCookiesOpt cookiesOpt("deadbeefdeadbeef");
   string cookiesOptionStr = cookiesOpt.makeOptString();
   GenericDNSPacketWriter<PacketBuffer>::optvect_t opts;
@@ -1730,8 +1729,8 @@ BOOST_AUTO_TEST_CASE(test_addEDNSToQueryTurnedResponse)
   uint16_t zValue = 0;
   uint16_t udpPayloadSize = 0;
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = Netmask(ComboAddress("127.0.0.1"), ECSSourcePrefixV4);
-  string origECSOptionStr = makeEDNSSubnetOptsString(ecsOpts);
+  ecsOpts.setSource(Netmask(ComboAddress("127.0.0.1"), ECSSourcePrefixV4));
+  string origECSOptionStr = ecsOpts.makeOptString();
   EDNSCookiesOpt cookiesOpt("deadbeefdeadbeef");
   string cookiesOptionStr = cookiesOpt.makeOptString();
   GenericDNSPacketWriter<PacketBuffer>::optvect_t opts;
@@ -1849,8 +1848,8 @@ BOOST_AUTO_TEST_CASE(test_getEDNSOptionsStart)
   const uint16_t qtype = QType::A;
   const uint16_t qclass = QClass::IN;
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = Netmask(ComboAddress("127.0.0.1"), ECSSourcePrefixV4);
-  const string ecsOptionStr = makeEDNSSubnetOptsString(ecsOpts);
+  ecsOpts.setSource(Netmask(ComboAddress("127.0.0.1"), ECSSourcePrefixV4));
+  const string ecsOptionStr = ecsOpts.makeOptString();
   GenericDNSPacketWriter<PacketBuffer>::optvect_t opts;
   opts.emplace_back(EDNSOptionCode::ECS, ecsOptionStr);
   const ComboAddress rem("127.0.0.1");
@@ -1949,8 +1948,8 @@ BOOST_AUTO_TEST_CASE(test_isEDNSOptionInOpt)
   const uint16_t qtype = QType::A;
   const uint16_t qclass = QClass::IN;
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = Netmask(ComboAddress("127.0.0.1"), ECSSourcePrefixV4);
-  const string ecsOptionStr = makeEDNSSubnetOptsString(ecsOpts);
+  ecsOpts.setSource(Netmask(ComboAddress("127.0.0.1"), ECSSourcePrefixV4));
+  const string ecsOptionStr = ecsOpts.makeOptString();
   const size_t sizeOfECSContent = ecsOptionStr.size();
   const size_t sizeOfECSOption = /* option code */ 2 + /* option length */ 2 + sizeOfECSContent;
   EDNSCookiesOpt cookiesOpt("deadbeefdeadbeef");
index 603bc3eca6944d85130ed6af34f231270bddd677..da2306ca2a7a22a957e1d4f18af2c53d958c25a6 100644 (file)
@@ -135,8 +135,8 @@ BOOST_AUTO_TEST_CASE(getExtendedDNSError)
       .extraText = "Synthesized from aggressive NSEC cache"};
     opts.emplace_back(EDNSOptionCode::EXTENDEDERROR, makeEDNSExtendedErrorOptString(ede));
     EDNSSubnetOpts ecsOpt;
-    ecsOpt.source = Netmask(ComboAddress("192.0.2.1"), 24U);
-    const auto ecsOptStr = makeEDNSSubnetOptsString(ecsOpt);
+    ecsOpt.setSource(Netmask(ComboAddress("192.0.2.1"), 24U));
+    const auto ecsOptStr = ecsOpt.makeOptString();
     opts.emplace_back(EDNSOptionCode::ECS, ecsOptStr);
     pw.addOpt(512, 0, 0, opts);
     pw.commit();
@@ -155,8 +155,8 @@ BOOST_AUTO_TEST_CASE(getExtendedDNSError)
     pw.getHeader()->rd = 1;
     GenericDNSPacketWriter<PacketBuffer>::optvect_t opts;
     EDNSSubnetOpts ecsOpt;
-    ecsOpt.source = Netmask(ComboAddress("192.0.2.1"), 24U);
-    const auto ecsOptStr = makeEDNSSubnetOptsString(ecsOpt);
+    ecsOpt.setSource(Netmask(ComboAddress("192.0.2.1"), 24U));
+    const auto ecsOptStr = ecsOpt.makeOptString();
     opts.emplace_back(EDNSOptionCode::ECS, ecsOptStr);
     const EDNSExtendedError ede{
       .infoCode = static_cast<uint16_t>(EDNSExtendedError::code::Synthesized),
index 08794b320a893f08331a6ab9a2f783d00c1d6a8e..6915233caecb823d606c34e661c1664f5faa4086 100644 (file)
@@ -801,8 +801,8 @@ BOOST_AUTO_TEST_CASE(test_PCCollision)
     pwQ.getHeader()->id = qid;
     GenericDNSPacketWriter<PacketBuffer>::optvect_t ednsOptions;
     EDNSSubnetOpts opt;
-    opt.source = Netmask("10.0.59.220/32");
-    ednsOptions.emplace_back(EDNSOptionCode::ECS, makeEDNSSubnetOptsString(opt));
+    opt.setSource(Netmask("10.0.59.220/32"));
+    ednsOptions.emplace_back(EDNSOptionCode::ECS, opt.makeOptString());
     pwQ.addOpt(512, 0, 0, ednsOptions);
     pwQ.commit();
 
@@ -812,7 +812,7 @@ BOOST_AUTO_TEST_CASE(test_PCCollision)
     bool found = localCache.get(dnsQuestion, 0, &key, subnetOut, dnssecOK, receivedOverUDP);
     BOOST_CHECK_EQUAL(found, false);
     BOOST_REQUIRE(subnetOut);
-    BOOST_CHECK_EQUAL(subnetOut->toString(), opt.source.toString());
+    BOOST_CHECK_EQUAL(subnetOut->toString(), opt.getSource().toString());
 
     PacketBuffer response;
     GenericDNSPacketWriter<PacketBuffer> pwR(response, ids.qname, ids.qtype, QClass::IN, 0);
@@ -831,7 +831,7 @@ BOOST_AUTO_TEST_CASE(test_PCCollision)
     found = localCache.get(dnsQuestion, 0, &key, subnetOut, dnssecOK, receivedOverUDP);
     BOOST_CHECK_EQUAL(found, true);
     BOOST_REQUIRE(subnetOut);
-    BOOST_CHECK_EQUAL(subnetOut->toString(), opt.source.toString());
+    BOOST_CHECK_EQUAL(subnetOut->toString(), opt.getSource().toString());
   }
 
   /* now lookup for the same query with a different ECS value,
@@ -843,8 +843,8 @@ BOOST_AUTO_TEST_CASE(test_PCCollision)
     pwQ.getHeader()->id = qid;
     GenericDNSPacketWriter<PacketBuffer>::optvect_t ednsOptions;
     EDNSSubnetOpts opt;
-    opt.source = Netmask("10.0.167.48/32");
-    ednsOptions.emplace_back(EDNSOptionCode::ECS, makeEDNSSubnetOptsString(opt));
+    opt.setSource(Netmask("10.0.167.48/32"));
+    ednsOptions.emplace_back(EDNSOptionCode::ECS, opt.makeOptString());
     pwQ.addOpt(512, 0, 0, ednsOptions);
     pwQ.commit();
 
@@ -855,7 +855,7 @@ BOOST_AUTO_TEST_CASE(test_PCCollision)
     BOOST_CHECK_EQUAL(found, false);
     BOOST_CHECK_EQUAL(secondKey, key);
     BOOST_REQUIRE(subnetOut);
-    BOOST_CHECK_EQUAL(subnetOut->toString(), opt.source.toString());
+    BOOST_CHECK_EQUAL(subnetOut->toString(), opt.getSource().toString());
     BOOST_CHECK_EQUAL(localCache.getLookupCollisions(), 1U);
   }
 
index 8588f2c21a151990792e98d6d195e0dedbd553d3..6c12370505a7f92aa6a290f296fd652b8a0f3433 100644 (file)
@@ -325,7 +325,7 @@ void DNSPacket::wrapup(bool throwsOnTruncation)
   {
     // this is an upper bound
     optsize += EDNS_OPTION_CODE_SIZE + EDNS_OPTION_LENGTH_SIZE + 2 + 1 + 1; // code+len+family+src len+scope len
-    optsize += d_eso.source.isIPv4() ? 4 : 16;
+    optsize += d_eso.getSource().isIPv4() ? 4 : 16;
   }
 
   if (d_haveednscookie) {
@@ -371,10 +371,10 @@ void DNSPacket::wrapup(bool throwsOnTruncation)
       if(d_haveednssubnet) {
         EDNSSubnetOpts eso = d_eso;
         // use the scopeMask from the resolver, if it is greater - issue #5469
-        maxScopeMask = max(maxScopeMask, eso.scope.getBits());
-        eso.scope = Netmask(eso.source.getNetwork(), maxScopeMask);
+        maxScopeMask = max(maxScopeMask, eso.getScopePrefixLength());
+        eso.setScopePrefixLength(maxScopeMask);
 
-        string opt = makeEDNSSubnetOptsString(eso);
+        string opt = eso.makeOptString();
         opts.emplace_back(8, opt); // 'EDNS SUBNET'
       }
 
@@ -617,7 +617,7 @@ try
         d_wantsnsid=true;
       }
       else if(s_doEDNSSubnetProcessing && (option.first == EDNSOptionCode::ECS)) { // 'EDNS SUBNET'
-        if(getEDNSSubnetOptsFromString(option.second, &d_eso)) {
+        if (EDNSSubnetOpts::getFromString(option.second, &d_eso)) {
           //cerr<<"Parsed, source: "<<d_eso.source.toString()<<", scope: "<<d_eso.scope.toString()<<", family = "<<d_eso.scope.getNetwork().sin4.sin_family<<endl;
           d_haveednssubnet=true;
         }
@@ -716,13 +716,13 @@ bool DNSPacket::hasValidEDNSCookie() const
 }
 
 void DNSPacket::setRealRemote(const Netmask& netmask) {
-  d_eso.source = netmask;
+  d_eso.setSource(netmask);
   d_haveednssubnet = true;
 }
 
 Netmask DNSPacket::getRealRemote() const
 {
-  return d_haveednssubnet ? d_eso.source : Netmask{getInnerRemote()};
+  return d_haveednssubnet ? d_eso.getSource() : Netmask{getInnerRemote()};
 }
 
 void DNSPacket::setSocket(Utility::sock_t sock)
index 8c14559c92ecaf46c3377c9655180b1c880309d2..ec3827037bd8e7e38b0195c2fe2f5a9334218846 100644 (file)
@@ -114,8 +114,8 @@ bool DNSProxy::completePacket(std::unique_ptr<DNSPacket>& reply, const DNSName&
   string ECSOptionStr;
 
   if (reply->hasEDNSSubnet()) {
-    DLOG(g_log << "dnsproxy::completePacket: Parsed edns source: " << reply->d_eso.source.toString() << ", scope: " << reply->d_eso.scope.toString() << ", family = " << reply->d_eso.scope.getNetwork().sin4.sin_family << endl);
-    ECSOptionStr = makeEDNSSubnetOptsString(reply->d_eso);
+    DLOG(g_log << "dnsproxy::completePacket: Parsed edns source: " << reply->d_eso.getSource().toString() << ", scope: " << Netmask(reply->d_eso.getSource().getNetwork(), reply->d_eso.getScopePrefixLength()).toString() << ", family = " << std::to_string(reply->d_eso.getFamily()) << endl);
+    ECSOptionStr = reply->d_eso.makeOptString();
     DLOG(g_log << "from dnsproxy::completePacket: Creating ECS option string " << makeHexDump(ECSOptionStr) << endl);
   }
 
@@ -288,8 +288,8 @@ void DNSProxy::mainloop()
         MOADNSParser mdp(false, packet.getString());
         // update the EDNS options with info from the resolver - issue #5469
         // note that this relies on the ECS string encoder to use the source network, and only take the prefix length from scope
-        iter->second.complete->d_eso.scope = packet.d_eso.scope;
-        DLOG(g_log << "from dnsproxy::mainLoop: updated EDNS options from resolver EDNS source: " << iter->second.complete->d_eso.source.toString() << " EDNS scope: " << iter->second.complete->d_eso.scope.toString() << endl);
+        iter->second.complete->d_eso.setScopePrefixLength(packet.d_eso.getScopePrefixLength());
+        DLOG(g_log << "from dnsproxy::mainLoop: updated EDNS options from resolver EDNS source: " << iter->second.complete->d_eso.getSource().toString() << " EDNS scope: " << Netmask(iter->second.complete->d_eso.getSource().getNetwork(), iter->second.complete->d_eso.getScopePrefixLength()).toString() << endl);
 
         if (mdp.d_header.rcode == RCode::NoError) {
           for (const auto& answer : mdp.d_answers) {
index d7a87d1c1856df94430551fb9b9c1c5b30d3178a..f7290fa93ddd43e8ac2983fec2c2b5d0eaae82f7 100644 (file)
@@ -558,14 +558,15 @@ static void addECSOption(char* packet, const size_t packetSize, uint16_t* len, c
   struct dnsheader* dh = (struct dnsheader*) packet;
 
   EDNSSubnetOpts eso;
-  if(stamp < 0)
-    eso.source = Netmask(remote);
+  if(stamp < 0) {
+    eso.setSource(Netmask(remote));
+  }
   else {
     ComboAddress stamped(remote);
     *((char*)&stamped.sin4.sin_addr.s_addr)=stamp;
-    eso.source = Netmask(stamped);
+    eso.setSource(Netmask(stamped));
   }
-  string optRData=makeEDNSSubnetOptsString(eso);
+  string optRData = eso.makeOptString();
   string record;
   generateEDNSOption(EDNSOptionCode::ECS, optRData, record);
   generateOptRR(record, EDNSRR);
index 279274cd9f37f5853eab6101b3898e8bde1746fd..76c445a13a567eaa089da9bf147f1d9248f73f30 100644 (file)
@@ -29,18 +29,18 @@ namespace
 struct EDNSSubnetOptsWire
 {
   uint16_t family;
-  uint8_t sourceMask;
-  uint8_t scopeMask;
+  uint8_t sourcePrefixLength;
+  uint8_t scopePrefixLength;
 } GCCPACKATTRIBUTE; // BRRRRR
 
 }
 
-bool getEDNSSubnetOptsFromString(const std::string& options, EDNSSubnetOpts* eso)
+bool EDNSSubnetOpts::getFromString(const std::string& options, EDNSSubnetOpts* eso)
 {
-  return getEDNSSubnetOptsFromString(options.c_str(), options.length(), eso);
+  return getFromString(options.c_str(), options.length(), eso);
 }
 
-bool getEDNSSubnetOptsFromString(const char* options, unsigned int len, EDNSSubnetOpts* eso)
+bool EDNSSubnetOpts::getFromString(const char* options, unsigned int len, EDNSSubnetOpts* eso)
 {
   EDNSSubnetOptsWire esow{};
   static_assert(sizeof(esow) == 4, "sizeof(EDNSSubnetOptsWire) must be 4 bytes");
@@ -51,7 +51,7 @@ bool getEDNSSubnetOptsFromString(const char* options, unsigned int len, EDNSSubn
   esow.family = ntohs(esow.family);
 
   ComboAddress address;
-  unsigned int octetsin = esow.sourceMask > 0 ? (((esow.sourceMask - 1) >> 3) + 1) : 0;
+  unsigned int octetsin = esow.sourcePrefixLength > 0 ? (((esow.sourcePrefixLength - 1) >> 3) + 1) : 0;
 
   if (esow.family == 1) {
     if (len != sizeof(esow) + octetsin) {
@@ -83,30 +83,30 @@ bool getEDNSSubnetOptsFromString(const char* options, unsigned int len, EDNSSubn
   else {
     return false;
   }
-  eso->source = Netmask(address, esow.sourceMask);
-  /* 'address' has more bits set (potentially) than scopeMask. This leads to odd looking netmasks that promise
-     more precision than they have. For this reason we truncate the address to scopeMask bits */
+  eso->source = Netmask(address, esow.sourcePrefixLength);
+  /* 'address' has more bits set (potentially) than scopePrefixLength. This leads to odd looking netmasks that promise
+     more precision than they have. For this reason we truncate the address to scopePrefixLength bits */
 
-  address.truncate(esow.scopeMask); // truncate will not throw for odd scopeMasks
-  eso->scope = Netmask(address, esow.scopeMask);
+  address.truncate(esow.scopePrefixLength); // truncate will not throw for odd scopePrefixLengths
+  eso->scopeBits = esow.scopePrefixLength;
 
   return true;
 }
 
-std::string makeEDNSSubnetOptsString(const EDNSSubnetOpts& eso)
+std::string EDNSSubnetOpts::makeOptString() const
 {
   std::string ret;
   EDNSSubnetOptsWire esow{};
-  uint16_t family = htons(eso.source.getNetwork().sin4.sin_family == AF_INET ? 1 : 2);
+  uint16_t family = htons(source.getNetwork().sin4.sin_family == AF_INET ? 1 : 2);
   esow.family = family;
-  esow.sourceMask = eso.source.getBits();
-  esow.scopeMask = eso.scope.getBits();
+  esow.sourcePrefixLength = source.getBits();
+  esow.scopePrefixLength = scopeBits;
   // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast)
   ret.assign(reinterpret_cast<const char*>(&esow), sizeof(esow));
-  int octetsout = ((esow.sourceMask - 1) >> 3) + 1;
+  int octetsout = ((esow.sourcePrefixLength - 1) >> 3) + 1;
 
-  ComboAddress src = eso.source.getNetwork();
-  src.truncate(esow.sourceMask);
+  ComboAddress src = source.getNetwork();
+  src.truncate(esow.sourcePrefixLength);
 
   if (family == htons(1)) {
     ret.append(reinterpret_cast<const char*>(&src.sin4.sin_addr.s_addr), octetsout);
index 7b85d302b20a2c02486baf92dc3c5607fe502c75..cc671d0346787cdeb16e0b1eb1036d68b225df86 100644 (file)
 
 #include "iputils.hh"
 
-struct EDNSSubnetOpts
+class EDNSSubnetOpts
 {
+public:
+  void setSource(const Netmask& netmask)
+  {
+    source = netmask;
+  }
+  [[nodiscard]] const Netmask& getSource() const
+  {
+    return source;
+  }
+  [[nodiscard]] uint8_t getFamily() const
+  {
+    return source.getNetwork().sin4.sin_family;
+  }
+  [[nodiscard]] uint8_t getSourcePrefixLength() const
+  {
+    return source.getBits();
+  }
+  void setScopePrefixLength(uint8_t scope)
+  {
+    scopeBits = scope;
+  }
+  [[nodiscard]] uint8_t getScopePrefixLength() const
+  {
+    return scopeBits;
+  }
+  [[nodiscard]] std::string makeOptString() const;
+  static bool getFromString(const std::string& options, EDNSSubnetOpts* eso);
+  static bool getFromString(const char* options, unsigned int len, EDNSSubnetOpts* eso);
+
+private:
   Netmask source;
-  Netmask scope;
+  uint8_t scopeBits{};
 };
-
-bool getEDNSSubnetOptsFromString(const std::string& options, EDNSSubnetOpts* eso);
-bool getEDNSSubnetOptsFromString(const char* options, unsigned int len, EDNSSubnetOpts* eso);
-std::string makeEDNSSubnetOptsString(const EDNSSubnetOpts& eso);
index 2a31ec8b0c040a2342e037022f6ec4378186c6ed..435c7797296c8b1238a01902d747952007097dd3 100644 (file)
@@ -89,8 +89,8 @@ boost::optional<Netmask> RecursorLua4::DNSQuestion::getEDNSSubnet() const
     for (const auto& option : *ednsOptions) {
       if (option.first == EDNSOptionCode::ECS) {
         EDNSSubnetOpts eso;
-        if (getEDNSSubnetOptsFromString(option.second, &eso)) {
-          return eso.source;
+        if (EDNSSubnetOpts::getFromString(option.second, &eso)) {
+          return eso.getSource();
         }
         break;
       }
index 95bdb00f527806a687d740c65509806186b3ec07..80368a31063149f171f47586a4c374115f0b3623 100644 (file)
@@ -428,11 +428,11 @@ static LWResult::Result asyncresolve(const ComboAddress& address, const DNSName&
   if (EDNS0Level > 0) {
     DNSPacketWriter::optvect_t opts;
     if (srcmask) {
-      EDNSSubnetOpts eo;
-      eo.source = *srcmask;
+      EDNSSubnetOpts subnetOpts;
+      subnetOpts.setSource(*srcmask);
       outgoingECSBits = srcmask->getBits();
       outgoingECSAddr = srcmask->getNetwork();
-      opts.emplace_back(EDNSOptionCode::ECS, makeEDNSSubnetOptsString(eo));
+      opts.emplace_back(EDNSOptionCode::ECS, subnetOpts.makeOptString());
       weWantEDNSSubnet = true;
     }
 
@@ -607,13 +607,13 @@ static LWResult::Result asyncresolve(const ComboAddress& address, const DNSName&
         for (const auto& opt : edo.d_options) {
           if (opt.first == EDNSOptionCode::ECS) {
             EDNSSubnetOpts reso;
-            if (getEDNSSubnetOptsFromString(opt.second, &reso)) {
+            if (EDNSSubnetOpts::getFromString(opt.second, &reso)) {
               /* rfc7871 states that 0 "indicate[s] that the answer is suitable for all addresses in FAMILY",
                  so we might want to still pass the information along to be able to differentiate between
                  IPv4 and IPv6. Still I'm pretty sure it doesn't matter in real life, so let's not duplicate
                  entries in our cache. */
-              if (reso.scope.getBits()) {
-                uint8_t bits = std::min(reso.scope.getBits(), outgoingECSBits);
+              if (reso.getScopePrefixLength() != 0) {
+                uint8_t bits = std::min(reso.getScopePrefixLength(), outgoingECSBits);
                 outgoingECSAddr.truncate(bits);
                 srcmask = Netmask(outgoingECSAddr, bits);
               }
index 180cb8d246b5937cde0510a453554331fecfd4eb..da7faf5e519805789b630b0d90e667ac27277b7b 100644 (file)
@@ -1005,7 +1005,7 @@ void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexi
 
       for (const auto& option : edo.d_options) {
         if (option.first == EDNSOptionCode::ECS && g_useIncomingECS && !comboWriter->d_ecsParsed) {
-          comboWriter->d_ecsFound = getEDNSSubnetOptsFromString(option.second, &comboWriter->d_ednssubnet);
+          comboWriter->d_ecsFound = EDNSSubnetOpts::getFromString(option.second, &comboWriter->d_ednssubnet);
         }
         else if (option.first == EDNSOptionCode::NSID) {
           const static string mode_server_id = ::arg()["server-id"];
@@ -1129,7 +1129,7 @@ void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexi
       }
       // lookup failing cannot happen as dc->d_source != dc->d_mappedSource
     }
-    resolver.setQuerySource(useMapped ? comboWriter->d_mappedSource : comboWriter->d_source, g_useIncomingECS && !comboWriter->d_ednssubnet.source.empty() ? boost::optional<const EDNSSubnetOpts&>(comboWriter->d_ednssubnet) : boost::none);
+    resolver.setQuerySource(useMapped ? comboWriter->d_mappedSource : comboWriter->d_source, g_useIncomingECS && !comboWriter->d_ednssubnet.getSource().empty() ? boost::optional<const EDNSSubnetOpts&>(comboWriter->d_ednssubnet) : boost::none);
 
     resolver.setQueryReceivedOverTCP(comboWriter->d_tcp);
 
@@ -1163,7 +1163,7 @@ void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexi
                                                   "qtype", Logging::Loggable(QType(comboWriter->d_mdp.d_qtype)),
                                                   "remote", Logging::Loggable(comboWriter->getRemote()),
                                                   "proto", Logging::Loggable(comboWriter->d_tcp ? "tcp" : "udp"),
-                                                  "ecs", Logging::Loggable(comboWriter->d_ednssubnet.source.empty() ? "" : comboWriter->d_ednssubnet.source.toString()),
+                                                  "ecs", Logging::Loggable(comboWriter->d_ednssubnet.getSource().empty() ? "" : comboWriter->d_ednssubnet.getSource().toString()),
                                                   "mtid", Logging::Loggable(g_multiTasker->getTid()));
     RunningResolveGuard tcpGuard(comboWriter);
 
@@ -1187,8 +1187,8 @@ void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexi
       if (!g_slogStructured) {
         g_log << Logger::Warning << RecThreadInfo::id() << " [" << g_multiTasker->getTid() << "/" << g_multiTasker->numProcesses() << "] " << (comboWriter->d_tcp ? "TCP " : "") << "question for '" << comboWriter->d_mdp.d_qname << "|"
               << QType(comboWriter->d_mdp.d_qtype) << "' from " << comboWriter->getRemote();
-        if (!comboWriter->d_ednssubnet.source.empty()) {
-          g_log << " (ecs " << comboWriter->d_ednssubnet.source.toString() << ")";
+        if (!comboWriter->d_ednssubnet.getSource().empty()) {
+          g_log << " (ecs " << comboWriter->d_ednssubnet.getSource().toString() << ")";
         }
         g_log << endl;
       }
@@ -1589,12 +1589,12 @@ void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexi
 
     if (g_useIncomingECS && comboWriter->d_ecsFound && !resolver.wasVariable() && !variableAnswer) {
       EDNSSubnetOpts ednsOptions;
-      ednsOptions.source = comboWriter->d_ednssubnet.source;
+      ednsOptions.setSource(comboWriter->d_ednssubnet.getSource());
       ComboAddress sourceAddr;
       sourceAddr.reset();
-      sourceAddr.sin4.sin_family = ednsOptions.source.getNetwork().sin4.sin_family;
-      ednsOptions.scope = Netmask(sourceAddr, 0);
-      auto ecsPayload = makeEDNSSubnetOptsString(ednsOptions);
+      sourceAddr.sin4.sin_family = ednsOptions.getFamily();
+      ednsOptions.setScopePrefixLength(0);
+      auto ecsPayload = ednsOptions.makeOptString();
 
       // if we don't have enough space available let's just not set that scope of zero,
       // it will prevent some caching, mostly from dnsdist, but that's fine
@@ -1852,7 +1852,7 @@ void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexi
       pbMessage.setId(comboWriter->d_mdp.d_header.id);
 
       pbMessage.setTime();
-      pbMessage.setEDNSSubnet(comboWriter->d_ednssubnet.source, comboWriter->d_ednssubnet.source.isIPv4() ? luaconfsLocal->protobufMaskV4 : luaconfsLocal->protobufMaskV6);
+      pbMessage.setEDNSSubnet(comboWriter->d_ednssubnet.getSource(), comboWriter->d_ednssubnet.getSource().isIPv4() ? luaconfsLocal->protobufMaskV4 : luaconfsLocal->protobufMaskV6);
       pbMessage.setRequestorId(dnsQuestion.requestorId);
       pbMessage.setDeviceId(dnsQuestion.deviceId);
       pbMessage.setDeviceName(dnsQuestion.deviceName);
@@ -2045,7 +2045,7 @@ void getQNameAndSubnet(const std::string& question, DNSName* dnsname, uint16_t*
         int res = getEDNSOption(reinterpret_cast<const char*>(&question.at(pos - sizeof(drh->d_clen))), questionLen - pos + sizeof(drh->d_clen), EDNSOptionCode::ECS, &ecsStartPosition, &ecsLen); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
         if (res == 0 && ecsLen > 4) {
           EDNSSubnetOpts eso;
-          if (getEDNSSubnetOptsFromString(&question.at(pos - sizeof(drh->d_clen) + ecsStartPosition + 4), ecsLen - 4, &eso)) {
+          if (EDNSSubnetOpts::getFromString(&question.at(pos - sizeof(drh->d_clen) + ecsStartPosition + 4), ecsLen - 4, &eso)) {
             *ednssubnet = eso;
             foundECS = true;
           }
@@ -2058,7 +2058,7 @@ void getQNameAndSubnet(const std::string& question, DNSName* dnsname, uint16_t*
           const auto& iter = options->find(EDNSOptionCode::ECS);
           if (iter != options->end() && !iter->second.values.empty() && iter->second.values.at(0).content != nullptr && iter->second.values.at(0).size > 0) {
             EDNSSubnetOpts eso;
-            if (getEDNSSubnetOptsFromString(iter->second.values.at(0).content, iter->second.values.at(0).size, &eso)) {
+            if (EDNSSubnetOpts::getFromString(iter->second.values.at(0).content, iter->second.values.at(0).size, &eso)) {
               *ednssubnet = eso;
               foundECS = true;
             }
@@ -2261,7 +2261,7 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr
         if (t_pdl) {
           try {
             if (t_pdl->hasGettagFFIFunc()) {
-              RecursorLua4::FFIParams params(qname, qtype, destaddr, fromaddr, destination, source, ednssubnet.source, data, policyTags, records, ednsOptions, proxyProtocolValues, requestorId, deviceId, deviceName, routingTag, rcode, ttlCap, variable, false, logQuery, logResponse, followCNAMEs, extendedErrorCode, extendedErrorExtra, responsePaddingDisabled, meta);
+              RecursorLua4::FFIParams params(qname, qtype, destaddr, fromaddr, destination, source, ednssubnet.getSource(), data, policyTags, records, ednsOptions, proxyProtocolValues, requestorId, deviceId, deviceName, routingTag, rcode, ttlCap, variable, false, logQuery, logResponse, followCNAMEs, extendedErrorCode, extendedErrorExtra, responsePaddingDisabled, meta);
 
               eventTrace.add(RecEventTrace::LuaGetTagFFI);
               ctag = t_pdl->gettag_ffi(params);
@@ -2269,7 +2269,7 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr
             }
             else if (t_pdl->hasGettagFunc()) {
               eventTrace.add(RecEventTrace::LuaGetTag);
-              ctag = t_pdl->gettag(source, ednssubnet.source, destination, qname, qtype, &policyTags, data, ednsOptions, false, requestorId, deviceId, deviceName, routingTag, proxyProtocolValues);
+              ctag = t_pdl->gettag(source, ednssubnet.getSource(), destination, qname, qtype, &policyTags, data, ednsOptions, false, requestorId, deviceId, deviceName, routingTag, proxyProtocolValues);
               eventTrace.add(RecEventTrace::LuaGetTag, ctag, false);
             }
           }
@@ -2291,7 +2291,7 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr
     RecursorPacketCache::OptPBData pbData{boost::none};
     if (t_protobufServers.servers) {
       if (logQuery && !(luaconfsLocal->protobufExportConfig.taggedOnly && policyTags.empty())) {
-        protobufLogQuery(luaconfsLocal, uniqueId, source, destination, mappedSource, ednssubnet.source, false, question.size(), qname, qtype, qclass, policyTags, requestorId, deviceId, deviceName, meta, ednsVersion, *dnsheader);
+        protobufLogQuery(luaconfsLocal, uniqueId, source, destination, mappedSource, ednssubnet.getSource(), false, question.size(), qname, qtype, qclass, policyTags, requestorId, deviceId, deviceName, meta, ednsVersion, *dnsheader);
       }
     }
 
index 68746a53f62fb5bfdb6a6e13003cda0fea6dde95..03ee74ce2605a7f12353817e32f29acb4b044008 100644 (file)
@@ -631,7 +631,7 @@ void protobufLogResponse(const struct dnsheader* header, LocalStateHolder<LuaCon
   pbMessage.setId(header->id);
 
   pbMessage.setTime();
-  pbMessage.setEDNSSubnet(ednssubnet.source, ednssubnet.source.isIPv4() ? luaconfsLocal->protobufMaskV4 : luaconfsLocal->protobufMaskV6);
+  pbMessage.setEDNSSubnet(ednssubnet.getSource(), ednssubnet.getSource().isIPv4() ? luaconfsLocal->protobufMaskV4 : luaconfsLocal->protobufMaskV6);
   pbMessage.setRequestorId(requestorId);
   pbMessage.setDeviceId(deviceId);
   pbMessage.setDeviceName(deviceName);
index 4ef2bb182b8c50856fdbd685a79c98de7d942532..21af9a44d4e626b31e5a51425cfe258c3b458e0c 100644 (file)
@@ -277,7 +277,7 @@ static void doProtobufLogQuery(bool logQuery, LocalStateHolder<LuaConfigItems>&
 {
   try {
     if (logQuery && !(luaconfsLocal->protobufExportConfig.taggedOnly && comboWriter->d_policyTags.empty())) {
-      protobufLogQuery(luaconfsLocal, comboWriter->d_uuid, comboWriter->d_source, comboWriter->d_destination, comboWriter->d_mappedSource, comboWriter->d_ednssubnet.source, true, conn->qlen, qname, qtype, qclass, comboWriter->d_policyTags, comboWriter->d_requestorId, comboWriter->d_deviceId, comboWriter->d_deviceName, comboWriter->d_meta, ednsVersion, *dnsheader);
+      protobufLogQuery(luaconfsLocal, comboWriter->d_uuid, comboWriter->d_source, comboWriter->d_destination, comboWriter->d_mappedSource, comboWriter->d_ednssubnet.getSource(), true, conn->qlen, qname, qtype, qclass, comboWriter->d_policyTags, comboWriter->d_requestorId, comboWriter->d_deviceId, comboWriter->d_deviceName, comboWriter->d_meta, ednsVersion, *dnsheader);
     }
   }
   catch (const std::exception& e) {
@@ -329,14 +329,14 @@ static void doProcessTCPQuestion(std::unique_ptr<DNSComboWriter>& comboWriter, s
       if (t_pdl) {
         try {
           if (t_pdl->hasGettagFFIFunc()) {
-            RecursorLua4::FFIParams params(qname, qtype, comboWriter->d_local, comboWriter->d_remote, comboWriter->d_destination, comboWriter->d_source, comboWriter->d_ednssubnet.source, comboWriter->d_data, comboWriter->d_gettagPolicyTags, comboWriter->d_records, ednsOptions, comboWriter->d_proxyProtocolValues, requestorId, deviceId, deviceName, comboWriter->d_routingTag, comboWriter->d_rcode, comboWriter->d_ttlCap, comboWriter->d_variable, true, logQuery, comboWriter->d_logResponse, comboWriter->d_followCNAMERecords, comboWriter->d_extendedErrorCode, comboWriter->d_extendedErrorExtra, comboWriter->d_responsePaddingDisabled, comboWriter->d_meta);
+            RecursorLua4::FFIParams params(qname, qtype, comboWriter->d_local, comboWriter->d_remote, comboWriter->d_destination, comboWriter->d_source, comboWriter->d_ednssubnet.getSource(), comboWriter->d_data, comboWriter->d_gettagPolicyTags, comboWriter->d_records, ednsOptions, comboWriter->d_proxyProtocolValues, requestorId, deviceId, deviceName, comboWriter->d_routingTag, comboWriter->d_rcode, comboWriter->d_ttlCap, comboWriter->d_variable, true, logQuery, comboWriter->d_logResponse, comboWriter->d_followCNAMERecords, comboWriter->d_extendedErrorCode, comboWriter->d_extendedErrorExtra, comboWriter->d_responsePaddingDisabled, comboWriter->d_meta);
             comboWriter->d_eventTrace.add(RecEventTrace::LuaGetTagFFI);
             comboWriter->d_tag = t_pdl->gettag_ffi(params);
             comboWriter->d_eventTrace.add(RecEventTrace::LuaGetTagFFI, comboWriter->d_tag, false);
           }
           else if (t_pdl->hasGettagFunc()) {
             comboWriter->d_eventTrace.add(RecEventTrace::LuaGetTag);
-            comboWriter->d_tag = t_pdl->gettag(comboWriter->d_source, comboWriter->d_ednssubnet.source, comboWriter->d_destination, qname, qtype, &comboWriter->d_gettagPolicyTags, comboWriter->d_data, ednsOptions, true, requestorId, deviceId, deviceName, comboWriter->d_routingTag, comboWriter->d_proxyProtocolValues);
+            comboWriter->d_tag = t_pdl->gettag(comboWriter->d_source, comboWriter->d_ednssubnet.getSource(), comboWriter->d_destination, qname, qtype, &comboWriter->d_gettagPolicyTags, comboWriter->d_data, ednsOptions, true, requestorId, deviceId, deviceName, comboWriter->d_routingTag, comboWriter->d_proxyProtocolValues);
             comboWriter->d_eventTrace.add(RecEventTrace::LuaGetTag, comboWriter->d_tag, false);
           }
           // Copy d_gettagPolicyTags to d_policyTags, so other Lua hooks see them and can add their
index 41de087bbed5859b7fc303471bac90b67fc952cf..5bfc4d6740135a86d6d452fe1512f0da54762139 100644 (file)
@@ -6114,10 +6114,10 @@ void SyncRes::setQuerySource(const ComboAddress& requestor, const boost::optiona
 {
   d_requestor = requestor;
 
-  if (incomingECS && incomingECS->source.getBits() > 0) {
-    d_cacheRemote = incomingECS->source.getMaskedNetwork();
-    uint8_t bits = std::min(incomingECS->source.getBits(), (incomingECS->source.isIPv4() ? s_ecsipv4limit : s_ecsipv6limit));
-    ComboAddress trunc = incomingECS->source.getNetwork();
+  if (incomingECS && incomingECS->getSourcePrefixLength() > 0) {
+    d_cacheRemote = incomingECS->getSource().getMaskedNetwork();
+    uint8_t bits = std::min(incomingECS->getSourcePrefixLength(), (incomingECS->getSource().isIPv4() ? s_ecsipv4limit : s_ecsipv6limit));
+    ComboAddress trunc = incomingECS->getSource().getNetwork();
     trunc.truncate(bits);
     d_outgoingECSNetwork = boost::optional<Netmask>(Netmask(trunc, bits));
   }
@@ -6130,7 +6130,7 @@ void SyncRes::setQuerySource(const ComboAddress& requestor, const boost::optiona
       trunc.truncate(bits);
       d_outgoingECSNetwork = boost::optional<Netmask>(Netmask(trunc, bits));
     }
-    else if (s_ecsScopeZero.source.getBits() > 0) {
+    else if (s_ecsScopeZero.getSourcePrefixLength() > 0) {
       /* RFC7871 says we MUST NOT send any ECS if the source scope is 0.
          But using an empty ECS in that case would mean inserting
          a non ECS-specific entry into the cache, preventing any further
@@ -6145,8 +6145,8 @@ void SyncRes::setQuerySource(const ComboAddress& requestor, const boost::optiona
          indicator of the applicable scope.  Subsequent Stub Resolver queries
          for /0 can then be answered from this cached response.
       */
-      d_outgoingECSNetwork = boost::optional<Netmask>(s_ecsScopeZero.source.getMaskedNetwork());
-      d_cacheRemote = s_ecsScopeZero.source.getNetwork();
+      d_outgoingECSNetwork = boost::optional<Netmask>(s_ecsScopeZero.getSource().getMaskedNetwork());
+      d_cacheRemote = s_ecsScopeZero.getSource().getNetwork();
     }
     else {
       // ECS disabled because no scope-zero address could be derived.
index 6b3366e13d7e2605830bc6ff917a0d9b46b1a07b..45151b5ce7ddaa28fd86c5c429c96768a3f0dfcb 100644 (file)
@@ -299,7 +299,7 @@ public:
 
   static void setECSScopeZeroAddress(const Netmask& scopeZeroMask)
   {
-    s_ecsScopeZero.source = scopeZeroMask;
+    s_ecsScopeZero.setSource(scopeZeroMask);
   }
 
   static void clearECSStats()
index 7c99d5af7b32204e4870b7eb6425c673acf08383..eff82307f7fb77ee39e4f9d28f8efb3a5cf56e54 100644 (file)
@@ -28,8 +28,8 @@ static void getRawQueryWithECSAndCookie(const DNSName& name, const Netmask& ecs,
   EDNSCookiesOpt cookiesOpt(clientCookie + serverCookie);
   string cookiesOptionStr = cookiesOpt.makeOptString();
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = ecs;
-  string origECSOptionStr = makeEDNSSubnetOptsString(ecsOpts);
+  ecsOpts.setSource(ecs);
+  string origECSOptionStr = ecsOpts.makeOptString();
   DNSPacketWriter::optvect_t opts;
   opts.emplace_back(EDNSOptionCode::COOKIE, cookiesOptionStr);
   opts.emplace_back(EDNSOptionCode::ECS, origECSOptionStr);
@@ -65,9 +65,9 @@ BOOST_AUTO_TEST_CASE(test_getEDNSOption)
   BOOST_CHECK_EQUAL(res, 0);
 
   EDNSSubnetOpts eso;
-  BOOST_REQUIRE(getEDNSSubnetOptsFromString(reinterpret_cast<const char*>(&query.at(pos + 9 + ecsStartPosition + 4)), ecsLen - 4, &eso));
+  BOOST_REQUIRE(EDNSSubnetOpts::getFromString(reinterpret_cast<const char*>(&query.at(pos + 9 + ecsStartPosition + 4)), ecsLen - 4, &eso));
 
-  BOOST_CHECK(eso.source == ecs);
+  BOOST_CHECK(eso.getSource() == ecs);
 }
 
 BOOST_AUTO_TEST_CASE(test_getEDNSOptions)
@@ -105,8 +105,8 @@ BOOST_AUTO_TEST_CASE(test_getEDNSOptions)
   BOOST_REQUIRE_GT(it->second.values.at(0).size, 0U);
 
   EDNSSubnetOpts eso;
-  BOOST_REQUIRE(getEDNSSubnetOptsFromString(it->second.values.at(0).content, it->second.values.at(0).size, &eso));
-  BOOST_CHECK(eso.source == ecs);
+  BOOST_REQUIRE(EDNSSubnetOpts::getFromString(it->second.values.at(0).content, it->second.values.at(0).size, &eso));
+  BOOST_CHECK(eso.getSource() == ecs);
 
   it = options.find(EDNSOptionCode::COOKIE);
   BOOST_REQUIRE(it != options.end());
@@ -121,9 +121,9 @@ static void checkECSOptionValidity(const std::string& sourceStr, uint8_t sourceM
 {
   ComboAddress source(sourceStr);
   EDNSSubnetOpts ecsOpts;
-  ecsOpts.source = Netmask(source, sourceMask);
+  ecsOpts.setSource(Netmask(source, sourceMask));
 
-  string ecsOptionStr = makeEDNSSubnetOptsString(ecsOpts);
+  string ecsOptionStr = ecsOpts.makeOptString();
 
   /* 2 bytes for family, one for source mask and one for scope mask */
   const size_t ecsHeaderSize = 4;
@@ -157,9 +157,9 @@ static void checkECSOptionValidity(const std::string& sourceStr, uint8_t sourceM
   }
 
   EDNSSubnetOpts parsed;
-  BOOST_REQUIRE(getEDNSSubnetOptsFromString(ecsOptionStr, &parsed));
-  BOOST_REQUIRE(parsed.source == Netmask(truncated, sourceMask));
-  BOOST_REQUIRE_EQUAL(ecsOpts.scope.getBits(), parsed.scope.getBits());
+  BOOST_REQUIRE(EDNSSubnetOpts::getFromString(ecsOptionStr, &parsed));
+  BOOST_REQUIRE(parsed.getSource() == Netmask(truncated, sourceMask));
+  BOOST_REQUIRE_EQUAL(ecsOpts.getScopePrefixLength(), parsed.getScopePrefixLength());
 }
 
 BOOST_AUTO_TEST_CASE(test_makeEDNSSubnetOptsString)
index af5fccaa28c5992f67ba11114dba589a53f570d0..42e5bc54d3a27c55c8a0c853b8245ed2272d5f02 100644 (file)
@@ -1138,7 +1138,7 @@ BOOST_AUTO_TEST_CASE(test_edns_subnet_by_domain)
   SyncRes::addEDNSDomain(target);
 
   EDNSSubnetOpts incomingECS;
-  incomingECS.source = Netmask("192.0.2.128/32");
+  incomingECS.setSource(Netmask("192.0.2.128/32"));
   sr->setQuerySource(ComboAddress(), boost::optional<const EDNSSubnetOpts&>(incomingECS));
 
   sr->setAsyncCallback([&](const ComboAddress& address, const DNSName& domain, int /* type */, bool /* doTCP */, bool /* sendRDQuery */, int /* EDNS0Level */, struct timeval* /* now */, boost::optional<Netmask>& srcmask, const ResolveContext& /* context */, LWResult* res, bool* /* chained */) {
@@ -1198,7 +1198,7 @@ BOOST_AUTO_TEST_CASE(test_edns_subnet_by_addr)
   SyncRes::addEDNSRemoteSubnet("192.0.2.1/32");
 
   EDNSSubnetOpts incomingECS;
-  incomingECS.source = Netmask("2001:DB8::FF/128");
+  incomingECS.setSource(Netmask("2001:DB8::FF/128"));
   sr->setQuerySource(ComboAddress(), boost::optional<const EDNSSubnetOpts&>(incomingECS));
 
   sr->setAsyncCallback([&](const ComboAddress& address, const DNSName& domain, int /* type */, bool /* doTCP */, bool /* sendRDQuery */, int /* EDNS0Level */, struct timeval* /* now */, boost::optional<Netmask>& srcmask, const ResolveContext& /* context */, LWResult* res, bool* /* chained */) {
@@ -1339,7 +1339,7 @@ BOOST_AUTO_TEST_CASE(test_ecs_honor_incoming_mask)
   SyncRes::clearEDNSLocalSubnets();
   SyncRes::addEDNSLocalSubnet("192.0.2.254/32");
   EDNSSubnetOpts incomingECS;
-  incomingECS.source = Netmask("192.0.0.0/16");
+  incomingECS.setSource(Netmask("192.0.0.0/16"));
   sr->setQuerySource(ComboAddress("192.0.2.127"), boost::optional<const EDNSSubnetOpts&>(incomingECS));
 
   sr->setAsyncCallback([&](const ComboAddress& address, const DNSName& domain, int /* type */, bool /* doTCP */, bool /* sendRDQuery */, int /* EDNS0Level */, struct timeval* /* now */, boost::optional<Netmask>& srcmask, const ResolveContext& /* context */, LWResult* res, bool* /* chained */) {
@@ -1384,7 +1384,7 @@ BOOST_AUTO_TEST_CASE(test_ecs_honor_incoming_mask_zero)
   SyncRes::clearEDNSLocalSubnets();
   SyncRes::addEDNSLocalSubnet("192.0.2.254/32");
   EDNSSubnetOpts incomingECS;
-  incomingECS.source = Netmask("0.0.0.0/0");
+  incomingECS.setSource(Netmask("0.0.0.0/0"));
   sr->setQuerySource(ComboAddress("192.0.2.127"), boost::optional<const EDNSSubnetOpts&>(incomingECS));
 
   sr->setAsyncCallback([&](const ComboAddress& address, const DNSName& domain, int /* type */, bool /* doTCP */, bool /* sendRDQuery */, int /* EDNS0Level */, struct timeval* /* now */, boost::optional<Netmask>& srcmask, const ResolveContext& /* context */, LWResult* res, bool* /* chained */) {
index 1a2d30a700ca6205e2fc1496755cdbd40ac4bd16..c478b758d9bfc30eff1d350375cf9b0e54c72dca 100644 (file)
@@ -1121,7 +1121,7 @@ BOOST_AUTO_TEST_CASE(test_dont_skip_negcache_for_variable_response)
   SyncRes::addEDNSDomain(DNSName("powerdns.com."));
 
   EDNSSubnetOpts incomingECS;
-  incomingECS.source = Netmask("192.0.2.128/32");
+  incomingECS.setSource(Netmask("192.0.2.128/32"));
   sr->setQuerySource(ComboAddress(), boost::optional<const EDNSSubnetOpts&>(incomingECS));
 
   sr->setAsyncCallback([&](const ComboAddress& address, const DNSName& domain, int /* type */, bool /* doTCP */, bool /* sendRDQuery */, int /* EDNS0Level */, struct timeval* /* now */, boost::optional<Netmask>& srcmask, const ResolveContext& /* context */, LWResult* res, bool* /* chained */) {
@@ -1176,7 +1176,7 @@ BOOST_AUTO_TEST_CASE(test_ecs_cache_limit_allowed)
   SyncRes::addEDNSDomain(DNSName("powerdns.com."));
 
   EDNSSubnetOpts incomingECS;
-  incomingECS.source = Netmask("192.0.2.128/32");
+  incomingECS.setSource(Netmask("192.0.2.128/32"));
   sr->setQuerySource(ComboAddress(), boost::optional<const EDNSSubnetOpts&>(incomingECS));
   SyncRes::s_ecsipv4cachelimit = 24;
 
@@ -1215,7 +1215,7 @@ BOOST_AUTO_TEST_CASE(test_ecs_cache_limit_no_ttl_limit_allowed)
   SyncRes::addEDNSDomain(DNSName("powerdns.com."));
 
   EDNSSubnetOpts incomingECS;
-  incomingECS.source = Netmask("192.0.2.128/32");
+  incomingECS.setSource(Netmask("192.0.2.128/32"));
   sr->setQuerySource(ComboAddress(), boost::optional<const EDNSSubnetOpts&>(incomingECS));
   SyncRes::s_ecsipv4cachelimit = 16;
 
@@ -1254,7 +1254,7 @@ BOOST_AUTO_TEST_CASE(test_ecs_cache_ttllimit_allowed)
   SyncRes::addEDNSDomain(DNSName("powerdns.com."));
 
   EDNSSubnetOpts incomingECS;
-  incomingECS.source = Netmask("192.0.2.128/32");
+  incomingECS.setSource(Netmask("192.0.2.128/32"));
   sr->setQuerySource(ComboAddress(), boost::optional<const EDNSSubnetOpts&>(incomingECS));
   SyncRes::s_ecscachelimitttl = 30;
 
@@ -1293,7 +1293,7 @@ BOOST_AUTO_TEST_CASE(test_ecs_cache_ttllimit_and_scope_allowed)
   SyncRes::addEDNSDomain(DNSName("powerdns.com."));
 
   EDNSSubnetOpts incomingECS;
-  incomingECS.source = Netmask("192.0.2.128/32");
+  incomingECS.setSource(Netmask("192.0.2.128/32"));
   sr->setQuerySource(ComboAddress(), boost::optional<const EDNSSubnetOpts&>(incomingECS));
   SyncRes::s_ecscachelimitttl = 100;
   SyncRes::s_ecsipv4cachelimit = 24;
@@ -1333,7 +1333,7 @@ BOOST_AUTO_TEST_CASE(test_ecs_cache_ttllimit_notallowed)
   SyncRes::addEDNSDomain(DNSName("powerdns.com."));
 
   EDNSSubnetOpts incomingECS;
-  incomingECS.source = Netmask("192.0.2.128/32");
+  incomingECS.setSource(Netmask("192.0.2.128/32"));
   sr->setQuerySource(ComboAddress(), boost::optional<const EDNSSubnetOpts&>(incomingECS));
   SyncRes::s_ecscachelimitttl = 100;
   SyncRes::s_ecsipv4cachelimit = 16;
@@ -1667,7 +1667,7 @@ BOOST_AUTO_TEST_CASE(test_cache_min_max_ecs_ttl)
   const ComboAddress ns("192.0.2.1:53");
 
   EDNSSubnetOpts incomingECS;
-  incomingECS.source = Netmask("192.0.2.128/32");
+  incomingECS.setSource(Netmask("192.0.2.128/32"));
   sr->setQuerySource(ComboAddress(), boost::optional<const EDNSSubnetOpts&>(incomingECS));
   SyncRes::addEDNSDomain(target);
 
index 39e8f08d50484913313f9f233f77955366f5e481..0a7dec1eeb19eb8090c0ea85150db89eed988cfc 100644 (file)
@@ -71,8 +71,8 @@ static void fillPacket(vector<uint8_t>& packet, const string& q, const string& t
     DNSPacketWriter::optvect_t opts;
     if (ednsnm) {
       EDNSSubnetOpts eo;
-      eo.source = *ednsnm;
-      opts.emplace_back(EDNSOptionCode::ECS, makeEDNSSubnetOptsString(eo));
+      eo.setSource(*ednsnm);
+      opts.emplace_back(EDNSOptionCode::ECS, eo.makeOptString());
     }
 
     pw.addOpt(bufsize, 0, dnssec ? EDNSOpts::DNSSECOK : 0, opts);
@@ -169,10 +169,10 @@ static void printReply(const string& reply, bool showflags, bool hidesoadetails,
          iter != edo.d_options.end(); ++iter) {
       if (iter->first == EDNSOptionCode::ECS) { // 'EDNS subnet'
         EDNSSubnetOpts reso;
-        if (getEDNSSubnetOptsFromString(iter->second, &reso)) {
-          cerr << "EDNS Subnet response: " << reso.source.toString()
-               << ", scope: " << reso.scope.toString()
-               << ", family = " << reso.scope.getNetwork().sin4.sin_family
+        if (EDNSSubnetOpts::getFromString(iter->second, &reso)) {
+          cerr << "EDNS Subnet response: " << reso.getSource().toString()
+               << ", scope: " << Netmask(reso.getSource().getNetwork(), reso.getScopePrefixLength()).toString()
+               << ", family = " << std::to_string(reso.getFamily())
                << endl;
         }
       } else if (iter->first == EDNSOptionCode::PADDING) {
index 5c8df331111497d7177208b3ab23029035192f80..47b3d9854dbe56d78043693de61f8c9cb2b6bc03 100644 (file)
@@ -131,7 +131,7 @@ int stubDoResolve(const DNSName& qname, uint16_t qtype, vector<DNSZoneRecord>& r
 
   if (d_eso != nullptr) {
     // pass along EDNS subnet from client if given - issue #5469
-    string origECSOptionStr = makeEDNSSubnetOptsString(*d_eso);
+    string origECSOptionStr = d_eso->makeOptString();
     DNSPacketWriter::optvect_t opts;
     opts.emplace_back(EDNSOptionCode::ECS, origECSOptionStr);
     packetWriter.addOpt(512, 0, 0, opts);
index 166a11dab4a77472f783b7206d3db98390158964..4cba7e8b8474fea7db7b3af89af1a10daf159352 100644 (file)
@@ -349,8 +349,8 @@ BOOST_AUTO_TEST_CASE(test_AuthPacketCache) {
     }
 
     {
-      ecsOpts.source = Netmask(ComboAddress("192.0.2.1"), 32);
-      opts.emplace_back(EDNSOptionCode::ECS, makeEDNSSubnetOptsString(ecsOpts));
+      ecsOpts.setSource(Netmask(ComboAddress("192.0.2.1"), 32));
+      opts.emplace_back(EDNSOptionCode::ECS, ecsOpts.makeOptString());
       DNSPacketWriter pw(pak, DNSName("www.powerdns.com"), QType::A);
       pw.addOpt(512, 0, 0, opts);
       pw.commit();
@@ -361,8 +361,8 @@ BOOST_AUTO_TEST_CASE(test_AuthPacketCache) {
 
     {
       DNSPacketWriter pw(pak, DNSName("www.powerdns.com"), QType::A);
-      ecsOpts.source = Netmask(ComboAddress("192.0.2.2"), 32);
-      opts.emplace_back(EDNSOptionCode::ECS, makeEDNSSubnetOptsString(ecsOpts));
+      ecsOpts.setSource(Netmask(ComboAddress("192.0.2.2"), 32));
+      opts.emplace_back(EDNSOptionCode::ECS, ecsOpts.makeOptString());
       pw.addOpt(512, 0, 0, opts);
       pw.commit();
       ecs2.parse((char*)&pak[0], pak.size());
@@ -372,8 +372,8 @@ BOOST_AUTO_TEST_CASE(test_AuthPacketCache) {
 
     {
       DNSPacketWriter pw(pak, DNSName("www.powerdns.com"), QType::A);
-      ecsOpts.source = Netmask(ComboAddress("192.0.2.3"), 16);
-      opts.emplace_back(EDNSOptionCode::ECS, makeEDNSSubnetOptsString(ecsOpts));
+      ecsOpts.setSource(Netmask(ComboAddress("192.0.2.3"), 16));
+      opts.emplace_back(EDNSOptionCode::ECS, ecsOpts.makeOptString());
       pw.addOpt(512, 0, 0, opts);
       pw.commit();
       ecs3.parse((char*)&pak[0], pak.size());
index 8d1bc24dfe3e21bdec352b08725acf9800f610ed..89c7e8cead8bad19f0173ae6ef6877900e091af1 100644 (file)
@@ -56,9 +56,9 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheAuthCollision) {
     pw1.getHeader()->rd = true;
     pw1.getHeader()->qr = false;
     pw1.getHeader()->id = 0x42;
-    opt.source = Netmask("10.0.59.220/32");
+    opt.setSource(Netmask("10.0.59.220/32"));
     ednsOptions.clear();
-    ednsOptions.emplace_back(EDNSOptionCode::ECS, makeEDNSSubnetOptsString(opt));
+    ednsOptions.emplace_back(EDNSOptionCode::ECS, opt.makeOptString());
     pw1.addOpt(512, 0, 0, ednsOptions);
     pw1.commit();
 
@@ -70,9 +70,9 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheAuthCollision) {
     pw2.getHeader()->rd = true;
     pw2.getHeader()->qr = false;
     pw2.getHeader()->id = 0x84;
-    opt.source = Netmask("10.0.167.48/32");
+    opt.setSource(Netmask("10.0.167.48/32"));
     ednsOptions.clear();
-    ednsOptions.emplace_back(EDNSOptionCode::ECS, makeEDNSSubnetOptsString(opt));
+    ednsOptions.emplace_back(EDNSOptionCode::ECS, opt.makeOptString());
     pw2.addOpt(512, 0, 0, ednsOptions);
     pw2.commit();
 
@@ -128,9 +128,9 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheAuthCollision) {
     pw1.getHeader()->rd = true;
     pw1.getHeader()->qr = false;
     pw1.getHeader()->id = 0x42;
-    opt.source = Netmask("10.0.41.6/32");
+    opt.setSource(Netmask("10.0.41.6/32"));
     ednsOptions.clear();
-    ednsOptions.emplace_back(EDNSOptionCode::ECS, makeEDNSSubnetOptsString(opt));
+    ednsOptions.emplace_back(EDNSOptionCode::ECS, opt.makeOptString());
     pw1.addOpt(512, 0, EDNSOpts::DNSSECOK, ednsOptions);
     pw1.commit();
 
@@ -142,9 +142,9 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheAuthCollision) {
     pw2.getHeader()->rd = true;
     pw2.getHeader()->qr = false;
     pw2.getHeader()->id = 0x84;
-    opt.source = Netmask("10.0.119.79/32");
+    opt.setSource(Netmask("10.0.119.79/32"));
     ednsOptions.clear();
-    ednsOptions.emplace_back(EDNSOptionCode::ECS, makeEDNSSubnetOptsString(opt));
+    ednsOptions.emplace_back(EDNSOptionCode::ECS, opt.makeOptString());
     /* no EDNSOpts::DNSSECOK !! */
     pw2.addOpt(512, 0, 0, ednsOptions);
     pw2.commit();
@@ -164,9 +164,9 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheAuthCollision) {
     pw1.getHeader()->rd = true;
     pw1.getHeader()->qr = false;
     pw1.getHeader()->id = 0x42;
-    opt.source = Netmask("192.0.2.1/32");
+    opt.setSource(Netmask("192.0.2.1/32"));
     ednsOptions.clear();
-    ednsOptions.emplace_back(EDNSOptionCode::ECS, makeEDNSSubnetOptsString(opt));
+    ednsOptions.emplace_back(EDNSOptionCode::ECS, opt.makeOptString());
     EDNSCookiesOpt cookiesOpt(string("deadbeefdeadbeef"));
     ednsOptions.emplace_back(EDNSOptionCode::COOKIE, cookiesOpt.makeOptString());
     pw1.addOpt(512, 0, EDNSOpts::DNSSECOK, ednsOptions);
@@ -180,9 +180,9 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheAuthCollision) {
     pw2.getHeader()->rd = true;
     pw2.getHeader()->qr = false;
     pw2.getHeader()->id = 0x84;
-    opt.source = Netmask("192.0.2.1/32");
+    opt.setSource(Netmask("192.0.2.1/32"));
     ednsOptions.clear();
-    ednsOptions.emplace_back(EDNSOptionCode::ECS, makeEDNSSubnetOptsString(opt));
+    ednsOptions.emplace_back(EDNSOptionCode::ECS, opt.makeOptString());
     cookiesOpt.makeFromString(string("deadbeefbadc0fee"));
     ednsOptions.emplace_back(EDNSOptionCode::COOKIE, cookiesOpt.makeOptString());
     pw2.addOpt(512, 0, EDNSOpts::DNSSECOK, ednsOptions);
@@ -315,9 +315,9 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheRecCollision) {
     pw1.getHeader()->rd = true;
     pw1.getHeader()->qr = false;
     pw1.getHeader()->id = 0x42;
-    opt.source = Netmask("10.0.18.199/32");
+    opt.setSource(Netmask("10.0.18.199/32"));
     ednsOptions.clear();
-    ednsOptions.emplace_back(EDNSOptionCode::ECS, makeEDNSSubnetOptsString(opt));
+    ednsOptions.emplace_back(EDNSOptionCode::ECS, opt.makeOptString());
     pw1.addOpt(512, 0, 0, ednsOptions);
     pw1.commit();
 
@@ -329,9 +329,9 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheRecCollision) {
     pw2.getHeader()->rd = true;
     pw2.getHeader()->qr = false;
     pw2.getHeader()->id = 0x84;
-    opt.source = Netmask("10.0.131.66/32");
+    opt.setSource(Netmask("10.0.131.66/32"));
     ednsOptions.clear();
-    ednsOptions.emplace_back(EDNSOptionCode::ECS, makeEDNSSubnetOptsString(opt));
+    ednsOptions.emplace_back(EDNSOptionCode::ECS, opt.makeOptString());
     pw2.addOpt(512, 0, 0, ednsOptions);
     pw2.commit();
 
@@ -350,9 +350,9 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheRecCollision) {
     pw1.getHeader()->rd = true;
     pw1.getHeader()->qr = false;
     pw1.getHeader()->id = 0x42;
-    opt.source = Netmask("192.0.2.1/32");
+    opt.setSource(Netmask("192.0.2.1/32"));
     ednsOptions.clear();
-    ednsOptions.emplace_back(EDNSOptionCode::ECS, makeEDNSSubnetOptsString(opt));
+    ednsOptions.emplace_back(EDNSOptionCode::ECS, opt.makeOptString());
     EDNSCookiesOpt cookiesOpt(string("deadbeefdead\x11\xee\x00\x00").c_str(), 16);
     ednsOptions.emplace_back(EDNSOptionCode::COOKIE, cookiesOpt.makeOptString());
     pw1.addOpt(512, 0, EDNSOpts::DNSSECOK, ednsOptions);
@@ -366,9 +366,9 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheRecCollision) {
     pw2.getHeader()->rd = true;
     pw2.getHeader()->qr = false;
     pw2.getHeader()->id = 0x84;
-    opt.source = Netmask("192.0.2.1/32");
+    opt.setSource(Netmask("192.0.2.1/32"));
     ednsOptions.clear();
-    ednsOptions.emplace_back(EDNSOptionCode::ECS, makeEDNSSubnetOptsString(opt));
+    ednsOptions.emplace_back(EDNSOptionCode::ECS, opt.makeOptString());
     cookiesOpt.makeFromString(string("deadbeefdead\x67\x44\x00\x00").c_str(), 16);
     ednsOptions.emplace_back(EDNSOptionCode::COOKIE, cookiesOpt.makeOptString());
     pw2.addOpt(512, 0, EDNSOpts::DNSSECOK, ednsOptions);