mirror of
https://github.com/tailscale/tailscale.git
synced 2025-05-02 13:41:03 +00:00
Unadvertise routes when turning an appConnector down, and also only unadvertise routes for a domain when the domain actually have a datedRoutes structure
This commit is contained in:
parent
75ba1c4d45
commit
aeff360f77
@ -144,6 +144,15 @@ func (e *AppConnector) UpdateRouteInfo(ri *routeinfo.RouteInfo) {
|
|||||||
e.routeInfo = ri
|
e.routeInfo = ri
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *AppConnector) UnadvertiseRemoteRoutes() {
|
||||||
|
e.queue.Add(func() {
|
||||||
|
toRemove := e.RouteInfo().Routes(false, true, true)
|
||||||
|
if err := e.routeAdvertiser.UnadvertiseRoute(toRemove...); err != nil {
|
||||||
|
e.logf("failed to unadvertise routes %v: %v", toRemove, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// UpdateDomains asynchronously replaces the current set of configured domains
|
// UpdateDomains asynchronously replaces the current set of configured domains
|
||||||
// with the supplied set of domains. Domains must not contain a trailing dot,
|
// with the supplied set of domains. Domains must not contain a trailing dot,
|
||||||
// and should be lower case. If the domain contains a leading '*' label it
|
// and should be lower case. If the domain contains a leading '*' label it
|
||||||
@ -216,9 +225,11 @@ func (e *AppConnector) updateDomains(domains []string) {
|
|||||||
e.UpdateRouteInfo(routeInfo)
|
e.UpdateRouteInfo(routeInfo)
|
||||||
// everything left in oldDiscovered a) won't be in e.domains and b) can be unadvertised if it's not in local or control
|
// everything left in oldDiscovered a) won't be in e.domains and b) can be unadvertised if it's not in local or control
|
||||||
for domainName, domainsRoutes := range oldDiscovered {
|
for domainName, domainsRoutes := range oldDiscovered {
|
||||||
toRemove := domainsRoutes.RoutesSlice()
|
if domainsRoutes != nil {
|
||||||
e.logf("unadvertising %d routes for domain: %s", len(toRemove), domainName)
|
toRemove := domainsRoutes.RoutesSlice()
|
||||||
e.scheduleUnadvertisement(domainName, toRemove...)
|
e.logf("unadvertising %d routes for domain: %s", len(toRemove), domainName)
|
||||||
|
e.scheduleUnadvertisement(domainName, toRemove...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
e.logf("handling domains: %v and wildcards: %v", xmaps.Keys(e.domains), e.wildcards)
|
e.logf("handling domains: %v and wildcards: %v", xmaps.Keys(e.domains), e.wildcards)
|
||||||
|
@ -22,6 +22,8 @@ func TestUpdateDomains(t *testing.T) {
|
|||||||
for _, shouldStore := range []bool{true, false} {
|
for _, shouldStore := range []bool{true, false} {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
a := NewAppConnector(t.Logf, nil, shouldStore)
|
a := NewAppConnector(t.Logf, nil, shouldStore)
|
||||||
|
a.routeAdvertiser = &appctest.RouteCollector{}
|
||||||
|
a.UpdateRouteInfo(routeinfo.NewRouteInfo())
|
||||||
a.UpdateDomains([]string{"example.com"})
|
a.UpdateDomains([]string{"example.com"})
|
||||||
|
|
||||||
a.Wait(ctx)
|
a.Wait(ctx)
|
||||||
|
@ -3585,7 +3585,7 @@ func (b *LocalBackend) reconfigAppConnectorLocked(nm *netmap.NetworkMap, prefs i
|
|||||||
|
|
||||||
if !prefs.AppConnector().Advertise {
|
if !prefs.AppConnector().Advertise {
|
||||||
if b.appConnector != nil && shouldAppCStoreRoutes {
|
if b.appConnector != nil && shouldAppCStoreRoutes {
|
||||||
b.appConnector.UpdateDomainsAndRoutes([]string{}, []netip.Prefix{})
|
b.appConnector.UnadvertiseRemoteRoutes()
|
||||||
}
|
}
|
||||||
b.appConnector = nil
|
b.appConnector = nil
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user