From 551e1e99e9ef0a725939a6583bcdbfae60254277 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 13 Oct 2020 15:22:08 -0700 Subject: [PATCH] net/netns: don't bind to device for localhost connections Fixes derphttp test failures on Windows (for #50). --- net/netns/netns_windows.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/net/netns/netns_windows.go b/net/netns/netns_windows.go index d2441e7cd..a25b3f22d 100644 --- a/net/netns/netns_windows.go +++ b/net/netns/netns_windows.go @@ -6,6 +6,7 @@ import ( "encoding/binary" + "strings" "syscall" "unsafe" @@ -28,6 +29,13 @@ func interfaceIndex(iface *winipcfg.IPAdapterAddresses) uint32 { // control binds c to the Windows interface that holds a default // route, and is not the Tailscale WinTun interface. func control(network, address string, c syscall.RawConn) error { + if strings.HasPrefix(address, "127.") { + // Don't bind to an interface for localhost connections, + // otherwise we get: + // connectex: The requested address is not valid in its context + // (The derphttp tests were failing) + return nil + } canV4, canV6 := false, false switch network { case "tcp", "udp":