cmd/tailscale: fix netstack init, call SetLocalBackend

The netstack code on Android was never told about the LocalBackend,
so the peerapi interception wasn't working.

Fixes tailscale/tailscale#4449
Fixes tailscale/tailscale#4293

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
release-branch/1.24
Brad Fitzpatrick 3 years ago committed by Brad Fitzpatrick
parent 8550365e52
commit cff9e2a772

@ -121,16 +121,27 @@ func newBackend(dataDir string, jvm *jni.JVM, appCtx jni.Object, store *stateSto
return nil, fmt.Errorf("runBackend: NewUserspaceEngine: %v", err)
}
b.logIDPublic = logID.Public().String()
if err := startNetstack(log.Printf, dialer, engine); err != nil {
return nil, fmt.Errorf("startNetstack: %w", err)
tunDev, magicConn, ok := engine.(wgengine.InternalsGetter).GetInternals()
if !ok {
return nil, fmt.Errorf("%T is not a wgengine.InternalsGetter", engine)
}
ns, err := netstack.Create(logf, tunDev, engine, magicConn, dialer)
if err != nil {
return nil, fmt.Errorf("netstack.Create: %w", err)
}
local, err := ipnlocal.NewLocalBackend(logf, b.logIDPublic, store, dialer, engine, 0)
ns.ProcessLocalIPs = false // let Android kernel handle it; VpnBuilder sets this up
ns.ProcessSubnets = true // for Android-being-an-exit-node support
lb, err := ipnlocal.NewLocalBackend(logf, b.logIDPublic, store, dialer, engine, 0)
if err != nil {
engine.Close()
return nil, fmt.Errorf("runBackend: NewLocalBackend: %v", err)
}
ns.SetLocalBackend(lb)
if err := ns.Start(); err != nil {
return nil, fmt.Errorf("startNetstack: %w", err)
}
b.engine = engine
b.backend = local
b.backend = lb
return b, nil
}
@ -432,17 +443,3 @@ func (b *backend) getDNSBaseConfig() (dns.OSConfig, error) {
return config, nil
}
func startNetstack(logf logger.Logf, dialer *tsdial.Dialer, e wgengine.Engine) error {
tunDev, magicConn, ok := e.(wgengine.InternalsGetter).GetInternals()
if !ok {
return fmt.Errorf("%T is not a wgengine.InternalsGetter", e)
}
ns, err := netstack.Create(logf, tunDev, e, magicConn, dialer)
if err != nil {
return fmt.Errorf("netstack.Create: %w", err)
}
ns.ProcessLocalIPs = false
ns.ProcessSubnets = true
return ns.Start()
}

Loading…
Cancel
Save