mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-21 09:11:18 -08:00
appc: detect cycles in CNAME chain
Fixes tailscale/corp#48296 Updates tailscale/corp#48187 Signed-off-by: Michael Ben-Ami <[email protected]>
This commit is contained in:
1 parent
044abcc9d2
commit
407d32ff42
2 files changed
+17
No files matched your search
@@ -26,6 +26,7 @@ import (
|
||||
"tailscale.com/util/dnsname"
|
||||
"tailscale.com/util/eventbus"
|
||||
"tailscale.com/util/execqueue"
|
||||
"tailscale.com/util/set"
|
||||
"tailscale.com/util/slicesx"
|
||||
)
|
||||
|
||||
@@ -425,6 +426,7 @@ func (e *AppConnector) DomainRoutes() map[string][]netip.Addr {
|
||||
// e.mu must be held.
|
||||
func (e *AppConnector) findRoutedDomainLocked(domain string, cnameChain map[string]string) (string, bool) {
|
||||
var isRouted bool
|
||||
var seen set.Set[string]
|
||||
for {
|
||||
_, isRouted = e.domains[domain]
|
||||
if isRouted {
|
||||
@@ -444,7 +446,12 @@ func (e *AppConnector) findRoutedDomainLocked(domain string, cnameChain map[stri
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
if seen.Contains(next) {
|
||||
break
|
||||
}
|
||||
domain = next
|
||||
seen.Make()
|
||||
seen.Add(domain)
|
||||
}
|
||||
return domain, isRouted
|
||||
}
|
||||
|
||||
@@ -255,6 +255,16 @@ func TestObserveDNSResponse(t *testing.T) {
|
||||
t.Errorf("got %v; want %v", got, want)
|
||||
}
|
||||
|
||||
// a CNAME record chain with a cycle terminates and does not
|
||||
// add any new routes.
|
||||
if err := a.ObserveDNSResponse(dnsCNAMEResponse("192.0.0.11", "a.example.org.", "b.example.org.", "a.example.org.")); err != nil {
|
||||
t.Errorf("ObserveDNSResponse: %v", err)
|
||||
}
|
||||
a.Wait(ctx)
|
||||
if got, want := rc.Routes(), wantRoutes; !slices.Equal(got, want) {
|
||||
t.Errorf("got %v; want %v", got, want)
|
||||
}
|
||||
|
||||
wantRoutes = append(wantRoutes, netip.MustParsePrefix("2001:db8::1/128"))
|
||||
|
||||
if err := a.ObserveDNSResponse(dnsResponse("example.com.", "2001:db8::1")); err != nil {
|
||||
|
||||
Reference in new issue
Block a user