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 {
112112 // lookupHost resolves host and returns its canonical name, or "" when it has
113113 // no CNAME.
114114 func lookupHost(host string) (string, []string, error) {
115- addrs, err := net.LookupHost(host)
115+ addrs, err := net.LookupHost(router.FQDN(host))
116116 if err != nil {
117117 return "", nil, err
118118 }
119- cname, err := net.LookupCNAME(host)
119+ cname, err := net.LookupCNAME(router.FQDN(host))
120120 if err != nil {
121121 return "", addrs, nil
122122 }
+7, -1
......@@ -105,10 +105,16 @@ func TXTRecordName(host, space string) string {
105105 return fmt.Sprintf("_%s.%s", space, host)
106106 }
107107
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+
108114 // LookupTXTRecords asks DNS for host's records on space, bypassing the
109115 // cache. No records returns ErrNoTXTRecord.
110116 func LookupTXTRecords(host, space string) ([]string, error) {
111- records, err := lookupTXT(TXTRecordName(host, space))
117+ records, err := lookupTXT(FQDN(TXTRecordName(host, space)))
112118 var dnsErr *net.DNSError
113119 if errors.As(err, &dnsErr) && dnsErr.IsNotFound {
114120 return nil, ErrNoTXTRecord
+2, -2
......@@ -36,7 +36,7 @@ func TestGetCustomDomainCachesMisses(t *testing.T) {
3636 }
3737
3838 // 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 "}
4040 if got, err := LookupCustomDomain("example.com", "pgs"); got != "antonio-blog" || err != nil {
4141 t.Fatalf("LookupCustomDomain = %q, %v", got, err)
4242 }
......@@ -47,7 +47,7 @@ func TestGetCustomDomainCachesMisses(t *testing.T) {
4747 t.Fatalf("got %q", got)
4848 }
4949 fail = nil
50- records["_pgs.other.com"] = []string{"antonio-other"}
50+ records["_pgs.other.com."] = []string{"antonio-other"}
5151 if got := GetCustomDomain("other.com", "pgs"); got != "antonio-other" {
5252 t.Fatalf("lookup after a transient failure got %q", got)
5353 }