mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-12 05:37:32 +00:00
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:
@@ -11,6 +11,7 @@ import (
|
||||
"net/netip"
|
||||
"sync"
|
||||
|
||||
"golang.org/x/exp/slices"
|
||||
"tailscale.com/net/netaddr"
|
||||
)
|
||||
|
||||
@@ -266,6 +267,16 @@ func AllIPv6() netip.Prefix { return allIPv6 }
|
||||
// ExitRoutes returns a slice containing AllIPv4 and AllIPv6.
|
||||
func ExitRoutes() []netip.Prefix { return []netip.Prefix{allIPv4, allIPv6} }
|
||||
|
||||
// SortPrefixes sorts the prefixes in place.
|
||||
func SortPrefixes(p []netip.Prefix) {
|
||||
slices.SortFunc(p, func(ri, rj netip.Prefix) bool {
|
||||
if ri.Addr() == rj.Addr() {
|
||||
return ri.Bits() < rj.Bits()
|
||||
}
|
||||
return ri.Addr().Less(rj.Addr())
|
||||
})
|
||||
}
|
||||
|
||||
// FilterPrefixes returns a new slice, not aliasing in, containing elements of
|
||||
// in that match f.
|
||||
func FilterPrefixesCopy(in []netip.Prefix, f func(netip.Prefix) bool) []netip.Prefix {
|
||||
|
Reference in New Issue
Block a user