From: Otto Moerbeek Date: Wed, 7 Dec 2022 09:51:04 +0000 (+0100) Subject: Take searchsuffix into acount when generating targets of PTR records. X-Git-Tag: dnsdist-1.8.0-rc1~178^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F12203%2Fhead;p=thirdparty%2Fpdns.git Take searchsuffix into acount when generating targets of PTR records. Fix tests for that and also add a testcode for boths v4 and v6 localhost --- diff --git a/pdns/recursordist/test-reczones-helpers.cc b/pdns/recursordist/test-reczones-helpers.cc index 4ea3cf7001..4a7aa30e78 100644 --- a/pdns/recursordist/test-reczones-helpers.cc +++ b/pdns/recursordist/test-reczones-helpers.cc @@ -1,14 +1,14 @@ #define BOOST_TEST_DYN_LINK #include -#include +#include #include "test-syncres_cc.hh" #include "reczones-helpers.hh" BOOST_AUTO_TEST_SUITE(reczones_helpers) -static const std::array hostLines = { +static const std::array hostLines = { "192.168.0.1 foo bar\n", "192.168.0.1 dupfoo\n", "192.168.0.2 baz\n", @@ -16,6 +16,7 @@ static const std::array hostLines = { "2.2.2.2 more.fancy\n", "2001:db8::567:89ab foo6 bar6\n", "2001:db8::567:89ab dupfoo6\n", + "127.0.0.1 localhost\n", "::1 localhost self\n", "2001:db8::567:89ac some.address.somewhere some some.address\n", }; @@ -80,7 +81,7 @@ struct Fixture { DNSRecord("1.0.168.192.in-addr.arpa", makeLocalhostDRC(), QType::NS), DNSRecord("1.0.168.192.in-addr.arpa", makeLocalhostRootDRC(), QType::SOA), - DNSRecord("1.0.168.192.in-addr.arpa", makePtrDRC("foo."), QType::PTR), + DNSRecord("1.0.168.192.in-addr.arpa", makePtrDRC("foo" + actualSearchSuffix), QType::PTR), }); addDomainMapFixtureEntry(domainMap, "baz" + actualSearchSuffix, QType::A, "192.168.0.2"); addDomainMapFixtureEntry( @@ -89,7 +90,7 @@ struct Fixture { DNSRecord("2.0.168.192.in-addr.arpa", makeLocalhostDRC(), QType::NS), DNSRecord("2.0.168.192.in-addr.arpa", makeLocalhostRootDRC(), QType::SOA), - DNSRecord("2.0.168.192.in-addr.arpa", makePtrDRC("baz."), QType::PTR), + DNSRecord("2.0.168.192.in-addr.arpa", makePtrDRC("baz" + actualSearchSuffix), QType::PTR), }); addDomainMapFixtureEntry(domainMap, "fancy" + actualSearchSuffix, QType::A, "1.1.1.1"); addDomainMapFixtureEntry( @@ -98,7 +99,7 @@ struct Fixture { DNSRecord("1.1.1.1.in-addr.arpa", makeLocalhostDRC(), QType::NS), DNSRecord("1.1.1.1.in-addr.arpa", makeLocalhostRootDRC(), QType::SOA), - DNSRecord("1.1.1.1.in-addr.arpa", makePtrDRC("fancy."), QType::PTR), + DNSRecord("1.1.1.1.in-addr.arpa", makePtrDRC("fancy" + actualSearchSuffix), QType::PTR), }); addDomainMapFixtureEntry(domainMap, "more.fancy", QType::A, "2.2.2.2"); addDomainMapFixtureEntry( @@ -119,10 +120,16 @@ struct Fixture { DNSRecord("b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa", makeLocalhostDRC(), QType::NS), DNSRecord("b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa", makeLocalhostRootDRC(), QType::SOA), - DNSRecord("b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa", makePtrDRC("foo6."), QType::PTR), + DNSRecord("b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa", makePtrDRC("foo6" + actualSearchSuffix), QType::PTR), }); - addDomainMapFixtureEntry(domainMap, "localhost" + actualSearchSuffix, QType::AAAA, "::1"); + addDomainMapFixtureEntry( + domainMap, + "localhost" + actualSearchSuffix, + {DNSRecord("localhost" + actualSearchSuffix, makeLocalhostDRC(), QType::NS), + DNSRecord("localhost" + actualSearchSuffix, makeLocalhostRootDRC(), QType::SOA), + DNSRecord("localhost" + actualSearchSuffix, DNSRecordContent::mastermake(QType::AAAA, QClass::IN, "::1"), QType::AAAA), + DNSRecord("localhost" + actualSearchSuffix, DNSRecordContent::mastermake(QType::A, QClass::IN, "127.0.0.1"), QType::A)}); addDomainMapFixtureEntry(domainMap, "self" + actualSearchSuffix, QType::AAAA, "::1"); addDomainMapFixtureEntry( domainMap, @@ -130,7 +137,15 @@ struct Fixture { DNSRecord("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa", makeLocalhostDRC(), QType::NS), DNSRecord("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa", makeLocalhostRootDRC(), QType::SOA), - DNSRecord("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa", makePtrDRC("localhost."), QType::PTR), + DNSRecord("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa", makePtrDRC("localhost" + actualSearchSuffix), QType::PTR), + }); + addDomainMapFixtureEntry( + domainMap, + "1.0.0.127.in-addr.arpa", + { + DNSRecord("1.0.0.127.in-addr.arpa", makeLocalhostDRC(), QType::NS), + DNSRecord("1.0.0.127.in-addr.arpa", makeLocalhostRootDRC(), QType::SOA), + DNSRecord("1.0.0.127.in-addr.arpa", makePtrDRC("localhost" + actualSearchSuffix), QType::PTR), }); addDomainMapFixtureEntry(domainMap, "some" + actualSearchSuffix, QType::AAAA, "2001:db8::567:89ac"); diff --git a/pdns/reczones-helpers.cc b/pdns/reczones-helpers.cc index f4a8fbbaa3..1d69a402bf 100644 --- a/pdns/reczones-helpers.cc +++ b/pdns/reczones-helpers.cc @@ -149,7 +149,13 @@ void addForwardAndReverseLookupEntries(SyncRes::domainmap_t& newMap, } // Add entries for the primary name for reverse lookups. - makeIPToNamesZone(newMap, address, parts[1], log); + if (searchSuffix.empty() || parts[1].find('.') != string::npos) { + makeIPToNamesZone(newMap, address, parts[1], log); + } + else { + DNSName canonical = toCanonic(DNSName(searchSuffix), parts[1]); + makeIPToNamesZone(newMap, address, canonical.toString(), log); + } } bool parseEtcHostsLine(std::vector& parts, std::string& line)