android: pass interface name to go (#340)

Use Android API to pass interface name to Tailscale on network updates

Fixes tailscale/corp#19215

Signed-off-by: kari-ts <kari@tailscale.com>
pull/353/head
kari-ts 7 months ago committed by GitHub
parent 24dd83090c
commit a6bc2244b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -168,14 +168,14 @@ class App : Application(), libtailscale.AppContext {
}
if (dns.updateDNSFromNetwork(sb.toString())) {
Libtailscale.onDnsConfigChanged()
Libtailscale.onDNSConfigChanged(linkProperties?.getInterfaceName())
}
}
override fun onLost(network: Network) {
super.onLost(network)
if (dns.updateDNSFromNetwork("")) {
Libtailscale.onDnsConfigChanged()
Libtailscale.onDNSConfigChanged("")
}
}
})

@ -222,9 +222,9 @@ func (a *App) runBackend(ctx context.Context) error {
netns.SetAndroidProtectFunc(nil)
service = nil
}
case <-onDNSConfigChanged:
case i := <-onDNSConfigChanged:
if b != nil {
go b.NetworkChanged()
go b.NetworkChanged(i)
}
}
}

@ -23,13 +23,14 @@ var (
// onGoogleToken receives google ID tokens.
onGoogleToken = make(chan string)
// onDNSConfigChanged is notified when the network changes and the DNS config needs to be updated.
onDNSConfigChanged = make(chan struct{}, 1)
// onDNSConfigChanged is notified when the network changes and the DNS config needs to be updated. It receives the updated interface name.
onDNSConfigChanged = make(chan string, 1)
)
func OnDnsConfigChanged() {
// ifname is the interface name retrieved from LinkProperties on network change. An empty string is used if there is no network available.
func OnDNSConfigChanged(ifname string) {
select {
case onDNSConfigChanged <- struct{}{}:
case onDNSConfigChanged <- ifname:
default:
}
}

@ -227,7 +227,8 @@ func (b *backend) CloseTUNs() {
b.devices.Shutdown()
}
func (b *backend) NetworkChanged() {
// ifname is the interface name retrieved from LinkProperties on network change. If a network is lost, an empty string is passed in.
func (b *backend) NetworkChanged(ifname string) {
defer func() {
if p := recover(); p != nil {
log.Printf("panic in NetworkChanged %s: %s", p, debug.Stack())
@ -235,6 +236,8 @@ func (b *backend) NetworkChanged() {
}
}()
// Set the interface name and alert the monitor.
interfaces.UpdateLastKnownDefaultRouteInterface(ifname)
if b.sys != nil {
if nm, ok := b.sys.NetMon.GetOK(); ok {
nm.InjectEvent()

Loading…
Cancel
Save