wgengine,ipn/ipnlocal,tsnet,cmd/tailscaled: remove PeerForIP from the Engine interface
Engine.PeerForIP was pure delegation to the callback that LocalBackend installs via SetPeerForIPFunc, so external callers going through the engine were taking a pointless round trip: LocalBackend called b.e.PeerForIP, which called right back into LocalBackend, and the netstack UseNetstackForIP hooks in tsnet and tailscaled did the same dance one layer removed. Export LocalBackend.PeerForIP and make those callers use it directly. The engine-internal cold paths (Ping, TSMP disco advertisements, pendopen diagnostics) still need the lookup and have no netmap of their own, so SetPeerForIPFunc stays on the interface, but the lookup method itself is now unexported and gone from the Engine interface. In tailscaled the UseNetstackForIP hook moves from netstack setup to just after the LocalBackend is created, since the backend doesn't exist yet when netstack is wired up. Updates #12542 Change-Id: Ib1e1a4fa5c84ee0dcb9ce5d1910047f2bab9453c Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
c436dec43c
commit
9cb1147805
@@ -44,11 +44,6 @@ func newNetstack(logf logger.Logf, sys *tsd.System, onlyNetstack bool) (tsd.Nets
|
||||
dialer := sys.Dialer.Get() // must be set by caller already
|
||||
|
||||
if onlyNetstack {
|
||||
e := sys.Engine.Get()
|
||||
dialer.UseNetstackForIP = func(ip netip.Addr) bool {
|
||||
_, ok := e.PeerForIP(ip)
|
||||
return ok
|
||||
}
|
||||
dialer.NetstackDialTCP = func(ctx context.Context, dst netip.AddrPort) (net.Conn, error) {
|
||||
// Note: don't just return ns.DialContextTCP or we'll return
|
||||
// *gonet.TCPConn(nil) instead of a nil interface which trips up
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
@@ -694,6 +695,12 @@ func getLocalBackend(ctx context.Context, logf logger.Logf, logID logid.PublicID
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ipnlocal.NewLocalBackend: %w", err)
|
||||
}
|
||||
if onlyNetstack {
|
||||
dialer.UseNetstackForIP = func(ip netip.Addr) bool {
|
||||
_, ok := lb.PeerForIP(ip)
|
||||
return ok
|
||||
}
|
||||
}
|
||||
lb.SetVarRoot(opts.VarRoot)
|
||||
if logPol != nil {
|
||||
lb.SetLogFlusher(logPol.Logtail.StartFlush)
|
||||
|
||||
Reference in New Issue
Block a user