Skip to content

Commit

Permalink
createForward6: on parse problem, return :: instead of SERVFAIL
Browse files Browse the repository at this point in the history
this mirrors how we handle the v4 case

closes PowerDNS#14629
  • Loading branch information
Habbie committed Sep 6, 2024
1 parent 03e665d commit d3c63f8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
21 changes: 14 additions & 7 deletions pdns/lua-record.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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<std::unordered_map<string,string>> e){
vector<ComboAddress> candidates;
Expand Down
12 changes: 11 additions & 1 deletion regression-tests.auth-py/test_LuaRecords.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d3c63f8

Please sign in to comment.