// Process auto hints
auto rrc = getRR<SVCBBaseRecordContent>(rec->dr);
DNSName target = rrc->getTarget().isRoot() ? rec->dr.d_name : rrc->getTarget();
- if (rrc->autoHint(SvcParam::ipv4hint) && s_SVCAutohints) {
- auto hints = getIPAddressFor(target, QType::A);
- if (hints.size() == 0) {
- rrc->removeParam(SvcParam::ipv4hint);
+
+ if (rrc->hasParam(SvcParam::ipv4hint) && rrc->autoHint(SvcParam::ipv4hint)) {
+ if (s_SVCAutohints) {
+ auto hints = getIPAddressFor(target, QType::A);
+ if (hints.size() == 0) {
+ rrc->removeParam(SvcParam::ipv4hint);
+ } else {
+ rrc->setHints(SvcParam::ipv4hint, hints);
+ }
} else {
- rrc->setHints(SvcParam::ipv4hint, hints);
+ rrc->removeParam(SvcParam::ipv4hint);
}
- } else {
- rrc->removeParam(SvcParam::ipv4hint);
}
- if (rrc->autoHint(SvcParam::ipv6hint) && s_SVCAutohints) {
- auto hints = getIPAddressFor(target, QType::AAAA);
- if (hints.size() == 0) {
- rrc->removeParam(SvcParam::ipv6hint);
+ if (rrc->hasParam(SvcParam::ipv6hint) && rrc->autoHint(SvcParam::ipv6hint)) {
+ if (s_SVCAutohints) {
+ auto hints = getIPAddressFor(target, QType::AAAA);
+ if (hints.size() == 0) {
+ rrc->removeParam(SvcParam::ipv6hint);
+ } else {
+ rrc->setHints(SvcParam::ipv6hint, hints);
+ }
} else {
- rrc->setHints(SvcParam::ipv6hint, hints);
+ rrc->removeParam(SvcParam::ipv6hint);
}
- } else {
- rrc->removeParam(SvcParam::ipv6hint);
}
}
no-aaaa.example.org. 3600 IN HTTPS 1 . ipv4hint=auto ipv6hint=auto
no-aaaa.example.org. 3600 IN A 192.0.2.81
+
+auto-a.example.org. 3600 IN HTTPS 1 . ipv4hint=auto ipv6hint=2001:db8::81
+auto-a.example.org. 3600 IN A 192.0.2.80
+auto-a.example.org. 3600 IN AAAA 2001:db8::80
+
+no-auto.example.org. 3600 IN HTTPS 1 . ipv4hint=192.0.2.81 ipv6hint=2001:db8::81
+no-auto.example.org. 3600 IN A 192.0.2.80
+no-auto.example.org. 3600 IN AAAA 2001:db8::80
+
+auto-aaaa.example.org. 3600 IN HTTPS 1 . ipv4hint=192.0.2.81 ipv6hint=auto
+auto-aaaa.example.org. 3600 IN A 192.0.2.80
+auto-aaaa.example.org. 3600 IN AAAA 2001:db8::80
""",
}
self.assertRcodeEqual(res, dns.rcode.NOERROR)
self.assertRRsetInAnswer(res, expected_ans)
self.assertEqual(len(res.additional), 1)
+
+ def testNoAuto(self):
+ """
+ Ensure we send the actual hints, not generated ones
+ """
+ query = dns.message.make_query('no-auto.example.org', 'HTTPS')
+ res = self.sendUDPQuery(query)
+ expected_ans = dns.rrset.from_text(
+ 'no-auto.example.org.', 3600, dns.rdataclass.IN, 'HTTPS',
+ '1 . ipv4hint="192.0.2.81" ipv6hint="2001:db8::81"'
+ )
+ self.assertRcodeEqual(res, dns.rcode.NOERROR)
+ print(res)
+ self.assertRRsetInAnswer(res, expected_ans)
+ self.assertEqual(len(res.additional), 2)
+
+ def testAutoA(self):
+ """
+ Ensure we send a generated A hint, but keep the existing AAAA hint
+ """
+ query = dns.message.make_query('auto-a.example.org', 'HTTPS')
+ res = self.sendUDPQuery(query)
+ expected_ans = dns.rrset.from_text(
+ 'auto-a.example.org.', 3600, dns.rdataclass.IN, 'HTTPS',
+ '1 . ipv4hint="192.0.2.80" ipv6hint="2001:db8::81"'
+ )
+ self.assertRcodeEqual(res, dns.rcode.NOERROR)
+ print(res)
+ self.assertRRsetInAnswer(res, expected_ans)
+ self.assertEqual(len(res.additional), 2)
+
+ def testAutoAAAA(self):
+ """
+ Ensure we send a generated AAAA hint, but keep the existing A hint
+ """
+ query = dns.message.make_query('auto-aaaa.example.org', 'HTTPS')
+ res = self.sendUDPQuery(query)
+ expected_ans = dns.rrset.from_text(
+ 'auto-aaaa.example.org.', 3600, dns.rdataclass.IN, 'HTTPS',
+ '1 . ipv4hint="192.0.2.81" ipv6hint="2001:db8::80"'
+ )
+ self.assertRcodeEqual(res, dns.rcode.NOERROR)
+ print(res)
+ self.assertRRsetInAnswer(res, expected_ans)
+ self.assertEqual(len(res.additional), 2)