From 03e665dbc27247766cb6934601888fc04e18ad51 Mon Sep 17 00:00:00 2001 From: Peter van Dijk Date: Fri, 6 Sep 2024 13:23:07 +0200 Subject: [PATCH 1/2] bit of tidy --- pdns/lua-record.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pdns/lua-record.cc b/pdns/lua-record.cc index 6c33cf3d515e..6b90e60a2617 100644 --- a/pdns/lua-record.cc +++ b/pdns/lua-record.cc @@ -969,18 +969,19 @@ static void setupLuaRecords(LuaContext& lua) // NOLINT(readability-function-cogn if(parts.size()==8) { string tot; for(int i=0; i<8; ++i) { - if(i) + if(i != 0) { tot.append(1,':'); + } tot+=parts[i]; } - ComboAddress ca(tot); - return ca.toString(); + ComboAddress address(tot); + return address.toString(); } else if(parts.size()==1) { if (parts[0].find('-') != std::string::npos) { boost::replace_all(parts[0],"-",":"); - ComboAddress ca(parts[0]); - return ca.toString(); + ComboAddress address(parts[0]); + return address.toString(); } else { if (parts[0].size() >= 32) { auto ippart = parts[0].substr(parts[0].size()-32); @@ -994,8 +995,8 @@ static void setupLuaRecords(LuaContext& lua) // NOLINT(readability-function-cogn ippart.substr(24, 4) + ":" + ippart.substr(28, 4); - ComboAddress ca(fulladdress); - return ca.toString(); + ComboAddress address(fulladdress); + return address.toString(); } } } From d3c63f8ef84c1f17dd674eaaebcf63095916e9f4 Mon Sep 17 00:00:00 2001 From: Peter van Dijk Date: Fri, 6 Sep 2024 13:59:45 +0200 Subject: [PATCH 2/2] createForward6: on parse problem, return :: instead of SERVFAIL this mirrors how we handle the v4 case closes #14629 --- pdns/lua-record.cc | 21 ++++++++++++++------- regression-tests.auth-py/test_LuaRecords.py | 12 +++++++++++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/pdns/lua-record.cc b/pdns/lua-record.cc index 6b90e60a2617..10a2d5fd286a 100644 --- a/pdns/lua-record.cc +++ b/pdns/lua-record.cc @@ -966,6 +966,8 @@ static void setupLuaRecords(LuaContext& lua) // NOLINT(readability-function-cogn lua.writeFunction("createForward6", []() { DNSName rel=s_lua_record_ctx->qname.makeRelative(s_lua_record_ctx->zone); auto parts = rel.getRawLabels(); + string address = "::"; + if(parts.size()==8) { string tot; for(int i=0; i<8; ++i) { @@ -974,14 +976,12 @@ static void setupLuaRecords(LuaContext& lua) // NOLINT(readability-function-cogn } tot+=parts[i]; } - ComboAddress address(tot); - return address.toString(); + address = tot; } else if(parts.size()==1) { if (parts[0].find('-') != std::string::npos) { boost::replace_all(parts[0],"-",":"); - ComboAddress address(parts[0]); - return address.toString(); + address = parts[0]; } else { if (parts[0].size() >= 32) { auto ippart = parts[0].substr(parts[0].size()-32); @@ -995,13 +995,20 @@ static void setupLuaRecords(LuaContext& lua) // NOLINT(readability-function-cogn ippart.substr(24, 4) + ":" + ippart.substr(28, 4); - ComboAddress address(fulladdress); - return address.toString(); + address = fulladdress; } } } - return std::string("::"); + try { + ComboAddress caddress(address); + address = caddress.toString(); + } + catch (PDNSException &error) { + address = "::"; + } + + return address; }); lua.writeFunction("createReverse6", [](string format, boost::optional> e){ vector candidates; diff --git a/regression-tests.auth-py/test_LuaRecords.py b/regression-tests.auth-py/test_LuaRecords.py index 973d98568c87..f631c6062495 100644 --- a/regression-tests.auth-py/test_LuaRecords.py +++ b/regression-tests.auth-py/test_LuaRecords.py @@ -166,8 +166,14 @@ class TestLuaRecords(AuthTest): createforward6.example.org. 3600 IN NS ns1.example.org. createforward6.example.org. 3600 IN NS ns2.example.org. * IN LUA AAAA "filterForward(createForward6(), newNMG{{'2000::/3'}}, 'fe80::1')" + """, + 'createforward6-nofilter.example.org': """ +createforward6-nofilter.example.org. 3600 IN SOA {soa} +createforward6-nofilter.example.org. 3600 IN NS ns1.example.org. +createforward6-nofilter.example.org. 3600 IN NS ns2.example.org. +* IN LUA AAAA "createForward6(), newNMG{{'2000::/3'}}" """ -# the separate createforward6 zone is because some of the code in lua-record.cc insists on working relatively to the zone apex +# the separate createforward6 zones are because some of the code in lua-record.cc insists on working relatively to the zone apex } _web_rrsets = [] @@ -1027,6 +1033,10 @@ def testCreateForwardAndReverse(self): "blabla20010002000300040005000600070db8" : "2001:2:3:4:5:6:7:db8", "4000-db8--1" : "fe80::1" # filtered, with fallback address override }), + ".createforward6-nofilter.example.org." : (dns.rdatatype.AAAA, { + "foo" : "::", + "averylongstringthatismorethan32chars" : "::" + }), ".createreverse6.example.org." : (dns.rdatatype.PTR, { "8.b.d.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.1.0.0.2" : "2001--db8.example.com.", "1.0.0.0.0.0.0.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" : "example.example.com." # exception