Skip to content

Commit e4f5b86

Browse files
authored
android: push default gateway IP from LinkProperties to go backend (#794)
likelyHomeRouterIPHelper was replaced with a cached gateway read in 86f9e7a9ea47e368e394a8e4e1866bbd40e6ed4a. This provides the value by retrieving the default gateway from LinkProperties.getRoute() in NetworkChangeCallback on every onLinkPropertiesChanged event. Updates tailscale/tailscale#18622 Updates tailscale/tailscale#13352 Signed-off-by: kari-ts <kari@tailscale.com>
1 parent 892082e commit e4f5b86

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

android/src/main/java/com/tailscale/ipn/NetworkChangeCallback.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ object NetworkChangeCallback {
197197

198198
if (dns.updateDNSFromNetwork(sb.toString())) {
199199
TSLog.d(TAG, "$why: updated DNS config for iface=${info.linkProps.interfaceName}")
200+
201+
val gatewayIP =
202+
info.linkProps.routes
203+
.filter { it.isDefaultRoute && it.gateway != null }
204+
.sortedBy { if (it.gateway is java.net.Inet4Address) 0 else 1 }
205+
.firstNotNullOfOrNull { it.gateway?.hostAddress } ?: ""
206+
207+
Libtailscale.onGatewayChanged(gatewayIP)
200208
Libtailscale.onDNSConfigChanged(info.linkProps.interfaceName)
201209
}
202210
}

libtailscale/callbacks.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package libtailscale
55

66
import (
77
"sync"
8+
9+
"tailscale.com/net/netmon"
810
)
911

1012
var (
@@ -36,6 +38,11 @@ func OnDNSConfigChanged(ifname string) {
3638
}
3739
}
3840

41+
// OnGatewayChanged is called when LinkProperties provides an updated default gateway IP.
42+
func OnGatewayChanged(gatewayIP string) {
43+
netmon.UpdateLastKnownDefaultGateway(gatewayIP)
44+
}
45+
3946
var android struct {
4047
// mu protects all fields of this structure. However, once a
4148
// non-nil jvm is returned from javaVM, all the other fields may

0 commit comments

Comments
 (0)