From 5a62aa8047ec8f5c53d60235e573dd81d9fc82ec Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 25 Mar 2021 21:41:37 -0700 Subject: [PATCH] ipn/ipnlocal: pass down interface state to peerapi ListenConfig hook Signed-off-by: Brad Fitzpatrick --- ipn/ipnlocal/local.go | 3 ++- ipn/ipnlocal/peerapi.go | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index c2714afff..edebb356d 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -143,6 +143,7 @@ func NewLocalBackend(logf logger.Logf, logid string, store ipn.StateStore, e wge b.statusChanged = sync.NewCond(&b.statusLock) linkMon := e.GetLinkMonitor() + b.prevIfState = linkMon.InterfaceState() // Call our linkChange code once with the current state, and // then also whenever it changes: b.linkChange(false, linkMon.InterfaceState()) @@ -1446,7 +1447,7 @@ func (b *LocalBackend) initPeerAPIListener() { b.peerAPIListeners = nil for _, a := range b.netMap.Addresses { - ln, err := peerAPIListen(a.IP) + ln, err := peerAPIListen(a.IP, b.prevIfState) if err != nil { b.logf("[unexpected] peerAPI listen(%q) error: %v", a.IP, err) continue diff --git a/ipn/ipnlocal/peerapi.go b/ipn/ipnlocal/peerapi.go index 03e09896b..29bcd0abe 100644 --- a/ipn/ipnlocal/peerapi.go +++ b/ipn/ipnlocal/peerapi.go @@ -16,18 +16,19 @@ "strconv" "inet.af/netaddr" + "tailscale.com/net/interfaces" "tailscale.com/tailcfg" ) -var initListenConfig func(*net.ListenConfig, netaddr.IP) error +var initListenConfig func(*net.ListenConfig, netaddr.IP, *interfaces.State) error -func peerAPIListen(ip netaddr.IP) (ln net.Listener, err error) { +func peerAPIListen(ip netaddr.IP, ifState *interfaces.State) (ln net.Listener, err error) { var lc net.ListenConfig if initListenConfig != nil { // On iOS/macOS, this sets the lc.Control hook to // setsockopt the interface index to bind to, to get // out of the network sandbox. - if err := initListenConfig(&lc, ip); err != nil { + if err := initListenConfig(&lc, ip, ifState); err != nil { return nil, err } }