From a2c330c4961aea883a674aa530cc40bf74047bac Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 20 Apr 2022 13:22:42 -0700 Subject: [PATCH] ipn/ipnlocal: use the fake peerapi listener as fallback if netstack available The previous commit (1b89662eff) this for Android, but we can also use this on any platform if we we would otherwise fail. Change-Id: I4cd78b40e9e77fca5cc8e717dd48ac173101bed4 Signed-off-by: Brad Fitzpatrick --- ipn/ipnlocal/peerapi.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ipn/ipnlocal/peerapi.go b/ipn/ipnlocal/peerapi.go index f0c9143c6..73393f2b6 100644 --- a/ipn/ipnlocal/peerapi.go +++ b/ipn/ipnlocal/peerapi.go @@ -436,8 +436,15 @@ func (s *peerAPIServer) listen(ip netaddr.IP, ifState *interfaces.State) (ln net return ln, nil } } - // Fall back to random ephemeral port. - return lc.Listen(context.Background(), tcp4or6, net.JoinHostPort(ipStr, "0")) + // Fall back to some random ephemeral port. + ln, err = lc.Listen(context.Background(), tcp4or6, net.JoinHostPort(ipStr, "0")) + + // And if we're on a platform with netstack (anything but iOS), then just fallback to netstack. + if err != nil && runtime.GOOS != "ios" { + s.b.logf("peerapi: failed to do peerAPI listen, harmless (netstack available) but error was: %v", err) + return newFakePeerAPIListener(ip), nil + } + return ln, err } type peerAPIListener struct {