From 34859f8e7ddb39ea54433af4e164069f789a57fb Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Tue, 3 Mar 2020 10:39:02 -0500 Subject: [PATCH] wgengine, magicsock: add a CreateBind method Signed-off-by: David Crawshaw --- wgengine/magicsock/magicsock.go | 5 +++++ wgengine/userspace.go | 5 +---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index dc511b213..52f42b301 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -1094,6 +1094,11 @@ func (a *AddrSet) Addrs() []wgcfg.Endpoint { return eps } +// CreateBind is called by WireGuard to create a UDP binding. +func (c *Conn) CreateBind(uint16) (conn.Bind, uint16, error) { + return c, c.LocalPort(), nil +} + // CreateEndpoint is called by WireGuard to connect to an endpoint. // The key is the public key of the peer and addrs is a // comma-separated list of UDP ip:ports. diff --git a/wgengine/userspace.go b/wgengine/userspace.go index 32cfb3d34..66daabcd1 100644 --- a/wgengine/userspace.go +++ b/wgengine/userspace.go @@ -15,7 +15,6 @@ import ( "sync" "time" - "github.com/tailscale/wireguard-go/conn" "github.com/tailscale/wireguard-go/device" "github.com/tailscale/wireguard-go/tun" "github.com/tailscale/wireguard-go/wgcfg" @@ -173,9 +172,7 @@ func newUserspaceEngineAdvanced(logf logger.Logf, tundev tun.Device, routerGen R } logf("ERROR: peer %s has unexpected AllowedIPs: %v", peerKey.ShortString(), allowedIPs) }, - CreateBind: func(uint16) (conn.Bind, uint16, error) { - return e.magicConn, e.magicConn.LocalPort(), nil - }, + CreateBind: e.magicConn.CreateBind, CreateEndpoint: e.magicConn.CreateEndpoint, SkipBindUpdate: true, }