net/dns/publicdns: support NextDNS DoH URLs with path parameters

Updates #2452

Change-Id: I0f1c34cc1672e87e7efd0adfe4088724dd0de3ed
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/5589/head
Brad Fitzpatrick 2 years ago committed by Brad Fitzpatrick
parent b302742137
commit c14361e70e

@ -80,6 +80,10 @@ func DoHIPsOfBase(dohBase string) []netip.Addr {
return s return s
} }
if hexStr, ok := strs.CutPrefix(dohBase, "https://dns.nextdns.io/"); ok { if hexStr, ok := strs.CutPrefix(dohBase, "https://dns.nextdns.io/"); ok {
// The path is of the form /<profile-hex>[/<hostname>/<model>/<device id>...]
// but only the <profile-hex> is required. Ignore the rest:
hexStr, _, _ = strings.Cut(hexStr, "/") // discard any optional
// TODO(bradfitz): using the NextDNS anycast addresses works but is not // TODO(bradfitz): using the NextDNS anycast addresses works but is not
// ideal. Some of their regions have better latency via a non-anycast IP // ideal. Some of their regions have better latency via a non-anycast IP
// which we could get by first resolving A/AAAA "dns.nextdns.io" over // which we could get by first resolving A/AAAA "dns.nextdns.io" over

@ -86,6 +86,15 @@ func TestDoHIPsOfBase(t *testing.T) {
"2a07:a8c1::c3:a884", "2a07:a8c1::c3:a884",
), ),
}, },
{
base: "https://dns.nextdns.io/c3a884/with/more/stuff",
want: ips(
"45.90.28.0",
"45.90.30.0",
"2a07:a8c0::c3:a884",
"2a07:a8c1::c3:a884",
),
},
} }
for _, tt := range tests { for _, tt := range tests {
got := DoHIPsOfBase(tt.base) got := DoHIPsOfBase(tt.base)

Loading…
Cancel
Save