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