Compare commits

...

1 Commits

Author SHA1 Message Date
Fran Bull
1c8e060628 appc: fix writing route info
Before the fix in 7eb8a77ac8 we were
writing route info on every DNS request. Since that fix we have only
been writing when we advertise new routes. This means we haven't been
writing domain->IP Address associations if the IP Address is covered by
a control route. We do want to persist the info associating the domain
and IP Address so make sure we also store routes in that case.

Fixes #12673

Signed-off-by: Fran Bull <fran@tailscale.com>
2024-07-01 08:53:59 -07:00
2 changed files with 33 additions and 0 deletions

View File

@@ -493,6 +493,7 @@ func (e *AppConnector) isAddrKnownLocked(domain string, addr netip.Addr) bool {
// record the new address associated with the domain for faster matching in subsequent
// requests and for diagnostic records.
e.addDomainAddrLocked(domain, addr)
e.storeRoutesLocked()
return true
}
}

View File

@@ -569,3 +569,35 @@ func TestRateLogger(t *testing.T) {
t.Fatalf("wasCalled: got false, want true")
}
}
func TestWriteRoutesCoveredByControlRoutes(t *testing.T) {
var writeCount int
write := func(*RouteInfo) error {
writeCount++
return nil
}
// even if there are routes that cover a domain's ip, if we haven't see the domain before we should write
ctx := context.Background()
rc := &appctest.RouteCollector{}
a := NewAppConnector(t.Logf, rc, &RouteInfo{}, write)
a.UpdateDomainsAndRoutes([]string{"*.example.com"}, []netip.Prefix{netip.MustParsePrefix("192.1.1.0/31")})
a.Wait(ctx)
// now we have an app connector that is wanting to learn routes for *.example.com, and is preconfigured with
// a route range, when it observes a dns response within the route range it should not publish a new route, but
// it should write it's RouteInfo, so that it remembers the domain<->ip addr association.
writeCount = 0
a.ObserveDNSResponse(dnsResponse("a.example.com.", "192.1.1.1"))
a.Wait(ctx)
want := 1
if writeCount != want {
t.Fatalf("writeCount new ip: got %d, want %d", writeCount, want)
}
// we should NOT write, if we are observing the same ip address again
writeCount = 0
a.ObserveDNSResponse(dnsResponse("a.example.com.", "192.1.1.1"))
a.Wait(ctx)
want = 0
if writeCount != want {
t.Fatalf("writeCount old ip: got %d, want %d", writeCount, want)
}
}