From c1b1cad633ae28b6c28bb9d7d3b97d6c5fae144d Mon Sep 17 00:00:00 2001 From: Jonathan Nobels Date: Fri, 21 Nov 2025 08:40:20 -0500 Subject: [PATCH] libtailscale: use b.netmon and sys.Bus consistently fixes tailscale/android#17747 There was a mismatch between the netmon into which we were injecting network change events, and the netmon that the eventBus registered with in the userspace engine. The switch from directly registering callbacks with netmon to using the eventBus caused a regression where the injected events would no longer trigger interface rebinds based on feedback from the Android network monitoring APIs. Signed-off-by: Jonathan Nobels --- libtailscale/backend.go | 7 ++++++- libtailscale/net.go | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/libtailscale/backend.go b/libtailscale/backend.go index 864136c..16fa0c6 100644 --- a/libtailscale/backend.go +++ b/libtailscale/backend.go @@ -249,6 +249,11 @@ func (a *App) runBackend(ctx context.Context, hardwareAttestation bool) error { vpnService.service = nil } case i := <-onDNSConfigChanged: + // TODO (barnstar): Consider using [dns.Manager.RecompileDNSConfig] here. + // NetworkChanged injects a netmon event that has the side effect + // regenerating the DNS config but have the means to do + // that independently of userspace engine network changes which may + // eliminate some unnecessary work. go b.NetworkChanged(i) } } @@ -265,7 +270,7 @@ func (a *App) newBackend(dataDir string, appCtx AppContext, store *stateStore, devices: newTUNDevices(), settings: settings, appCtx: appCtx, - bus: eventbus.New(), + bus: sys.Bus.Get(), } var logID logid.PrivateID diff --git a/libtailscale/net.go b/libtailscale/net.go index 86becab..0a12e19 100644 --- a/libtailscale/net.go +++ b/libtailscale/net.go @@ -275,10 +275,10 @@ func (b *backend) NetworkChanged(ifname string) { // Set the interface name and alert the monitor. netmon.UpdateLastKnownDefaultRouteInterface(ifname) - if b.sys != nil { - if nm, ok := b.sys.NetMon.GetOK(); ok { - nm.InjectEvent() - } + if b.netMon != nil { + b.netMon.InjectEvent() + } else { + log.Printf("NetworkChanged: netMon is nil") } }