net/interfaces: reduce & cleanup logs on iOS

We don't need a log line every time defaultRoute is read in the good
case, and we now only log default interface updates that are actually
changes.

Updates #3363

Signed-off-by: James Tucker <james@tailscale.com>
This commit is contained in:
James Tucker 2024-02-23 16:05:57 -08:00 committed by James Tucker
parent c8c999d7a9
commit 651c4899ac

View File

@ -21,8 +21,9 @@ func UpdateLastKnownDefaultRouteInterface(ifName string) {
if ifName == "" {
return
}
lastKnownDefaultRouteIfName.Store(ifName)
log.Printf("defaultroute_ios: update from Swift, ifName = %s", ifName)
if old := lastKnownDefaultRouteIfName.Swap(ifName); old != ifName {
log.Printf("defaultroute_ios: update from Swift, ifName = %s (was %s)", ifName, old)
}
}
func defaultRoute() (d DefaultRouteDetails, err error) {
@ -56,13 +57,13 @@ func defaultRoute() (d DefaultRouteDetails, err error) {
}
if !ifc.IsUp() {
log.Println("defaultroute_ios: %s is down", name)
log.Printf("defaultroute_ios: %s is down", name)
return nil
}
addrs, _ := ifc.Addrs()
if len(addrs) == 0 {
log.Println("defaultroute_ios: %s has no addresses", name)
log.Printf("defaultroute_ios: %s has no addresses", name)
return nil
}
return &ifc
@ -76,7 +77,6 @@ func defaultRoute() (d DefaultRouteDetails, err error) {
if swiftIfName := lastKnownDefaultRouteIfName.Load(); swiftIfName != "" {
ifc := getInterfaceByName(swiftIfName)
if ifc != nil {
log.Printf("defaultroute_ios: using %s (provided by Swift)", ifc.Name)
d.InterfaceName = ifc.Name
d.InterfaceIndex = ifc.Index
return d, nil