diff --git a/checker/collect.go b/checker/collect.go index c239b35..a27796c 100644 --- a/checker/collect.go +++ b/checker/collect.go @@ -155,7 +155,7 @@ func extractPointers(sub, apex string, svc rawService) ([]Pointer, error) { if err := json.Unmarshal(svc.Service, &b); err != nil { return nil, fmt.Errorf("decode cname body: %w", err) } - target := normaliseTarget(b.Record.Target, owner, apex) + target := normaliseTarget(b.Record.Target, apex) if target == "" { return nil, nil } @@ -175,7 +175,7 @@ func extractPointers(sub, apex string, svc rawService) ([]Pointer, error) { } out := make([]Pointer, 0, len(b.MXs)) for _, r := range b.MXs { - target := normaliseTarget(r.Mx, owner, apex) + target := normaliseTarget(r.Mx, apex) if target == "" { continue } @@ -196,7 +196,7 @@ func extractPointers(sub, apex string, svc rawService) ([]Pointer, error) { } out := make([]Pointer, 0, len(b.Records)) for _, r := range b.Records { - target := normaliseTarget(r.Target, owner, apex) + target := normaliseTarget(r.Target, apex) if target == "" { continue } @@ -218,7 +218,7 @@ func extractPointers(sub, apex string, svc rawService) ([]Pointer, error) { ptOwner := preferRRName(b.Record.Hdr.Name, owner, apex) switch b.Record.Hdr.Rrtype { case dns.TypeNS: - target := normaliseTarget(b.Record.Ns, ptOwner, apex) + target := normaliseTarget(b.Record.Ns, apex) if target == "" { return nil, nil } @@ -230,7 +230,7 @@ func extractPointers(sub, apex string, svc rawService) ([]Pointer, error) { ServiceType: svc.Type, }}, nil case dns.TypeCNAME: - target := normaliseTarget(b.Record.Target, ptOwner, apex) + target := normaliseTarget(b.Record.Target, apex) if target == "" { return nil, nil } @@ -242,7 +242,7 @@ func extractPointers(sub, apex string, svc rawService) ([]Pointer, error) { ServiceType: svc.Type, }}, nil case dns.TypeMX: - target := normaliseTarget(b.Record.Mx, ptOwner, apex) + target := normaliseTarget(b.Record.Mx, apex) if target == "" { return nil, nil } @@ -349,20 +349,14 @@ func preferRRName(rrName, fallback, apex string) string { return rrName + "." + apex } -// normaliseTarget converts a target to FQDN form; happyDomain stores in-zone targets relative, external ones absolute. -func normaliseTarget(target, owner, apex string) string { - t := strings.TrimSpace(target) - if t == "" { - return "" +// normaliseTarget converts a target to FQDN form without trailing dot. +// Absolute FQDNs (trailing dot) are stripped; relative names and "@" are +// resolved against apex via sdk.JoinRelative. +func normaliseTarget(target, apex string) string { + if t, ok := strings.CutSuffix(strings.TrimSpace(target), "."); ok { + return t } - if trimmed, ok := strings.CutSuffix(t, "."); ok { - return trimmed - } - // Relative target: anchor under apex (empty apex only occurs in tests that omit domain_name). - if apex != "" { - return t + "." + apex - } - return t + "." + owner + return sdk.JoinRelative(target, apex) } func displaySubdomain(s string) string {