mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-05 23:07:44 +00:00
appc: fix writing route info
Before the fix in 7eb8a77ac80b78a2917f0a78a6f4a9189d739797 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>
This commit is contained in:
parent
8965e87fa8
commit
1c8e060628
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user