From 3c7898728dd3c29b794a19e76f50569e3a62eabd Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Tue, 27 Apr 2021 13:20:58 -0700 Subject: [PATCH] wgengine/magicsock: remove DefaultPort const Assume it'll stay at 0 forever, so hard-code it and delete code conditional on it being non-0. Signed-off-by: Josh Bleecher Snyder --- cmd/tailscaled/depaware.txt | 2 +- cmd/tailscaled/tailscaled.go | 3 +-- wgengine/magicsock/magicsock.go | 16 +--------------- 3 files changed, 3 insertions(+), 18 deletions(-) diff --git a/cmd/tailscaled/depaware.txt b/cmd/tailscaled/depaware.txt index 4f00dcd20..b5bfe9496 100644 --- a/cmd/tailscaled/depaware.txt +++ b/cmd/tailscaled/depaware.txt @@ -144,7 +144,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de tailscale.com/version/distro from tailscale.com/control/controlclient+ tailscale.com/wgengine from tailscale.com/cmd/tailscaled+ tailscale.com/wgengine/filter from tailscale.com/control/controlclient+ - tailscale.com/wgengine/magicsock from tailscale.com/cmd/tailscaled+ + tailscale.com/wgengine/magicsock from tailscale.com/wgengine+ tailscale.com/wgengine/monitor from tailscale.com/wgengine+ tailscale.com/wgengine/netstack from tailscale.com/cmd/tailscaled tailscale.com/wgengine/router from tailscale.com/cmd/tailscaled+ diff --git a/cmd/tailscaled/tailscaled.go b/cmd/tailscaled/tailscaled.go index 12311c457..8b4e89a36 100644 --- a/cmd/tailscaled/tailscaled.go +++ b/cmd/tailscaled/tailscaled.go @@ -44,7 +44,6 @@ "tailscale.com/version" "tailscale.com/version/distro" "tailscale.com/wgengine" - "tailscale.com/wgengine/magicsock" "tailscale.com/wgengine/monitor" "tailscale.com/wgengine/netstack" "tailscale.com/wgengine/router" @@ -117,7 +116,7 @@ func main() { flag.StringVar(&args.debug, "debug", "", "listen address ([ip]:port) of optional debug server") flag.StringVar(&args.socksAddr, "socks5-server", "", `optional [ip]:port to run a SOCK5 server (e.g. "localhost:1080")`) flag.StringVar(&args.tunname, "tun", defaultTunName(), `tunnel interface name; use "userspace-networking" (beta) to not use TUN`) - flag.Var(flagtype.PortValue(&args.port, magicsock.DefaultPort), "port", "UDP port to listen on for WireGuard and peer-to-peer traffic; 0 means automatically select") + flag.Var(flagtype.PortValue(&args.port, 0), "port", "UDP port to listen on for WireGuard and peer-to-peer traffic; 0 means automatically select") flag.StringVar(&args.statepath, "state", paths.DefaultTailscaledStateFile(), "path of state file") flag.StringVar(&args.socketpath, "socket", paths.DefaultTailscaledSocket(), "path of the service unix socket") flag.BoolVar(&printVersion, "version", false, "print version information and exit") diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index 4e49d0531..e1eff1b24 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -365,10 +365,6 @@ type activeDerp struct { createTime time.Time } -// DefaultPort is the default port to listen on. -// The current default (zero) means to auto-select a random free port. -const DefaultPort = 0 - // Options contains options for Listen. type Options struct { // Logf optionally provides a log function to use. @@ -2617,17 +2613,7 @@ func (c *Conn) bind1(ruc **RebindingUDPConn, which string) error { host = "::1" } } - var pc net.PacketConn - var err error - if c.port == 0 && DefaultPort != 0 { - pc, err = c.listenPacket(which, host, DefaultPort) - if err != nil { - c.logf("magicsock: bind: default port %s/%v unavailable; picking random", which, DefaultPort) - } - } - if pc == nil { - pc, err = c.listenPacket(which, host, c.port) - } + pc, err := c.listenPacket(which, host, c.port) if err != nil { c.logf("magicsock: bind(%s/%v): %v", which, c.port, err) return fmt.Errorf("magicsock: bind: %s/%d: %v", which, c.port, err)