Commit 1a49b46
Antonio Mika
·
2026-10-25 11:57:11 -0400 EDT
parent e635d41
fix(router): look up custom domain records as fully qualified names
3 files changed,
+11,
-5
+2,
-2
| ... | ... | @@ -112,11 +112,11 @@ func checkTunsRecords(c *Cmd, records []string) string { | |
| 112 | 112 | // lookupHost resolves host and returns its canonical name, or "" when it has | |
| 113 | 113 | // no CNAME. | |
| 114 | 114 | func lookupHost(host string) (string, []string, error) { | |
| 115 | - | addrs, err := net.LookupHost(host) | |
| 115 | + | addrs, err := net.LookupHost(router.FQDN(host)) | |
| 116 | 116 | if err != nil { | |
| 117 | 117 | return "", nil, err | |
| 118 | 118 | } | |
| 119 | - | cname, err := net.LookupCNAME(host) | |
| 119 | + | cname, err := net.LookupCNAME(router.FQDN(host)) | |
| 120 | 120 | if err != nil { | |
| 121 | 121 | return "", addrs, nil | |
| 122 | 122 | } |
| ... | ... | @@ -105,10 +105,16 @@ func TXTRecordName(host, space string) string { | |
| 105 | 105 | return fmt.Sprintf("_%s.%s", space, host) | |
| 106 | 106 | } | |
| 107 | 107 | ||
| 108 | + | // FQDN returns name with a trailing dot, so the resolver won't retry a name | |
| 109 | + | // that doesn't exist under its own search domains. | |
| 110 | + | func FQDN(name string) string { | |
| 111 | + | return strings.TrimSuffix(name, ".") + "." | |
| 112 | + | } | |
| 113 | + | ||
| 108 | 114 | // LookupTXTRecords asks DNS for host's records on space, bypassing the | |
| 109 | 115 | // cache. No records returns ErrNoTXTRecord. | |
| 110 | 116 | func LookupTXTRecords(host, space string) ([]string, error) { | |
| 111 | - | records, err := lookupTXT(TXTRecordName(host, space)) | |
| 117 | + | records, err := lookupTXT(FQDN(TXTRecordName(host, space))) | |
| 112 | 118 | var dnsErr *net.DNSError | |
| 113 | 119 | if errors.As(err, &dnsErr) && dnsErr.IsNotFound { | |
| 114 | 120 | return nil, ErrNoTXTRecord |
| ... | ... | @@ -36,7 +36,7 @@ func TestGetCustomDomainCachesMisses(t *testing.T) { | |
| 36 | 36 | } | |
| 37 | 37 | ||
| 38 | 38 | // The uncached lookup sees a record as soon as it exists. | |
| 39 | - | records["_pgs.example.com"] = []string{" antonio-blog "} | |
| 39 | + | records["_pgs.example.com."] = []string{" antonio-blog "} | |
| 40 | 40 | if got, err := LookupCustomDomain("example.com", "pgs"); got != "antonio-blog" || err != nil { | |
| 41 | 41 | t.Fatalf("LookupCustomDomain = %q, %v", got, err) | |
| 42 | 42 | } |
| ... | ... | @@ -47,7 +47,7 @@ func TestGetCustomDomainCachesMisses(t *testing.T) { | |
| 47 | 47 | t.Fatalf("got %q", got) | |
| 48 | 48 | } | |
| 49 | 49 | fail = nil | |
| 50 | - | records["_pgs.other.com"] = []string{"antonio-other"} | |
| 50 | + | records["_pgs.other.com."] = []string{"antonio-other"} | |
| 51 | 51 | if got := GetCustomDomain("other.com", "pgs"); got != "antonio-other" { | |
| 52 | 52 | t.Fatalf("lookup after a transient failure got %q", got) | |
| 53 | 53 | } |