mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-22 12:58:37 +00:00

1. Patch prefs handler doesn't add the remote routes to pref if the pref update is also turning appconnector off. 2. Unadvertise routes when StoreRoutes is on but appConnector is turning off. 3. When appConnector is turning on, add a task to recreate and reload routeInfo from store to the queue 3. When shouldStore is changed, remove the state saved for routeInfo (Set to nil)
66 lines
1.5 KiB
Go
66 lines
1.5 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package appctest
|
|
|
|
import (
|
|
"net/netip"
|
|
"slices"
|
|
|
|
"tailscale.com/appc/routeinfo"
|
|
"tailscale.com/ipn"
|
|
)
|
|
|
|
// RouteCollector is a test helper that collects the list of routes advertised
|
|
type RouteCollector struct {
|
|
routes []netip.Prefix
|
|
removedRoutes []netip.Prefix
|
|
routeInfo *routeinfo.RouteInfo
|
|
}
|
|
|
|
func (rc *RouteCollector) AdvertiseRoute(pfx ...netip.Prefix) error {
|
|
rc.routes = append(rc.routes, pfx...)
|
|
return nil
|
|
}
|
|
|
|
func (rc *RouteCollector) UnadvertiseRoute(toRemove ...netip.Prefix) error {
|
|
routes := rc.routes
|
|
rc.routes = rc.routes[:0]
|
|
for _, r := range routes {
|
|
if !slices.Contains(toRemove, r) {
|
|
rc.routes = append(rc.routes, r)
|
|
} else {
|
|
rc.removedRoutes = append(rc.removedRoutes, r)
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (rc *RouteCollector) StoreRouteInfo(ri *routeinfo.RouteInfo) error {
|
|
rc.routeInfo = ri
|
|
return nil
|
|
}
|
|
|
|
func (rc *RouteCollector) ReadRouteInfo() (*routeinfo.RouteInfo, error) {
|
|
if rc.routeInfo == nil {
|
|
return nil, ipn.ErrStateNotExist
|
|
}
|
|
return rc.routeInfo, nil
|
|
}
|
|
|
|
// RemovedRoutes returns the list of routes that were removed.
|
|
func (rc *RouteCollector) RemovedRoutes() []netip.Prefix {
|
|
return rc.removedRoutes
|
|
}
|
|
|
|
// Routes returns the ordered list of routes that were added, including
|
|
// possible duplicates.
|
|
func (rc *RouteCollector) Routes() []netip.Prefix {
|
|
return rc.routes
|
|
}
|
|
|
|
func (rc *RouteCollector) SetRoutes(routes []netip.Prefix) error {
|
|
rc.routes = routes
|
|
return nil
|
|
}
|