{ipn,net,tsnet}: use tsaddr helpers

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
pull/13598/head
Kristoffer Dalby 2 months ago committed by Kristoffer Dalby
parent f03e82a97c
commit 7d1160ddaa

@ -4593,11 +4593,6 @@ func magicDNSRootDomains(nm *netmap.NetworkMap) []dnsname.FQDN {
return nil
}
var (
ipv4Default = netip.MustParsePrefix("0.0.0.0/0")
ipv6Default = netip.MustParsePrefix("::/0")
)
// peerRoutes returns the routerConfig.Routes to access peers.
// If there are over cgnatThreshold CGNAT routes, one big CGNAT route
// is used instead.
@ -4698,9 +4693,9 @@ func (b *LocalBackend) routerConfig(cfg *wgcfg.Config, prefs ipn.PrefsView, oneC
var default4, default6 bool
for _, route := range rs.Routes {
switch route {
case ipv4Default:
case tsaddr.AllIPv4():
default4 = true
case ipv6Default:
case tsaddr.AllIPv6():
default6 = true
}
if default4 && default6 {
@ -4708,10 +4703,10 @@ func (b *LocalBackend) routerConfig(cfg *wgcfg.Config, prefs ipn.PrefsView, oneC
}
}
if !default4 {
rs.Routes = append(rs.Routes, ipv4Default)
rs.Routes = append(rs.Routes, tsaddr.AllIPv4())
}
if !default6 {
rs.Routes = append(rs.Routes, ipv6Default)
rs.Routes = append(rs.Routes, tsaddr.AllIPv6())
}
internalIPs, externalIPs, err := internalAndExternalInterfaces()
if err != nil {
@ -4768,14 +4763,7 @@ func (b *LocalBackend) applyPrefsToHostinfoLocked(hi *tailcfg.Hostinfo, prefs ip
hi.ShieldsUp = prefs.ShieldsUp()
hi.AllowsUpdate = envknob.AllowsRemoteUpdate() || prefs.AutoUpdate().Apply.EqualBool(true)
// count routes without exit node routes
var routes int64
for _, route := range hi.RoutableIPs {
if route.Bits() != 0 {
routes++
}
}
b.metrics.advertisedRoutes.Set(float64(routes))
b.metrics.advertisedRoutes.Set(float64(tsaddr.WithoutExitRoute(prefs.AdvertiseRoutes()).Len()))
var sshHostKeys []string
if prefs.RunSSH() && envknob.CanSSHD() {

@ -13,11 +13,6 @@ import (
"tailscale.com/net/tsaddr"
)
var (
ipv4default = netip.MustParsePrefix("0.0.0.0/0")
ipv6default = netip.MustParsePrefix("::/0")
)
func validateViaPrefix(ipp netip.Prefix) error {
if !tsaddr.IsViaPrefix(ipp) {
return fmt.Errorf("%v is not a 4-in-6 prefix", ipp)
@ -60,22 +55,22 @@ func CalcAdvertiseRoutes(advertiseRoutes string, advertiseDefaultRoute bool) ([]
return nil, err
}
}
if ipp == ipv4default {
if ipp == tsaddr.AllIPv4() {
default4 = true
} else if ipp == ipv6default {
} else if ipp == tsaddr.AllIPv6() {
default6 = true
}
routeMap[ipp] = true
}
if default4 && !default6 {
return nil, fmt.Errorf("%s advertised without its IPv6 counterpart, please also advertise %s", ipv4default, ipv6default)
return nil, fmt.Errorf("%s advertised without its IPv6 counterpart, please also advertise %s", tsaddr.AllIPv4(), tsaddr.AllIPv6())
} else if default6 && !default4 {
return nil, fmt.Errorf("%s advertised without its IPv4 counterpart, please also advertise %s", ipv6default, ipv4default)
return nil, fmt.Errorf("%s advertised without its IPv4 counterpart, please also advertise %s", tsaddr.AllIPv6(), tsaddr.AllIPv4())
}
}
if advertiseDefaultRoute {
routeMap[netip.MustParsePrefix("0.0.0.0/0")] = true
routeMap[netip.MustParsePrefix("::/0")] = true
routeMap[tsaddr.AllIPv4()] = true
routeMap[tsaddr.AllIPv6()] = true
}
if len(routeMap) == 0 {
return nil, nil

Loading…
Cancel
Save