cmd/tailscale/cli: [set] handle selectively modifying routes/exit node

Noticed this while debugging something else, we would reset all routes if
either `--advertise-exit-node` or `--advertise-routes` were set. This handles
correctly updating them.

Also added tests.

Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
Maisem Ali
2022-11-12 14:53:36 +05:00
committed by Maisem Ali
parent 26d1fc867e
commit 8e85227059
7 changed files with 199 additions and 19 deletions

View File

@@ -2930,19 +2930,10 @@ func peerRoutes(peers []wgcfg.Peer, cgnatThreshold int) (routes []netip.Prefix)
routes = append(routes, cgNATIPs...)
}
sort.Slice(routes, func(i, j int) bool {
return ipPrefixLess(routes[i], routes[j])
})
tsaddr.SortPrefixes(routes)
return routes
}
func ipPrefixLess(ri, rj netip.Prefix) bool {
if ri.Addr() == rj.Addr() {
return ri.Bits() < rj.Bits()
}
return ri.Addr().Less(rj.Addr())
}
// routerConfig produces a router.Config from a wireguard config and IPN prefs.
func (b *LocalBackend) routerConfig(cfg *wgcfg.Config, prefs ipn.PrefsView, oneCGNATRoute bool) *router.Config {
singleRouteThreshold := 10_000