wgengine, magicsock: adjust for wireguard-go conn/device package split

Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
This commit is contained in:
David Crawshaw 2020-02-24 07:27:48 -05:00
parent 8994a59e20
commit 868cfae84f
3 changed files with 10 additions and 7 deletions

2
go.mod
View File

@ -17,7 +17,7 @@ require (
github.com/pborman/getopt v0.0.0-20190409184431-ee0cd42419d3 github.com/pborman/getopt v0.0.0-20190409184431-ee0cd42419d3
github.com/tailscale/hujson v0.0.0-20190930033718-5098e564d9b3 github.com/tailscale/hujson v0.0.0-20190930033718-5098e564d9b3
github.com/tailscale/winipcfg-go v0.0.0-20200213045944-185b07f8233f github.com/tailscale/winipcfg-go v0.0.0-20200213045944-185b07f8233f
github.com/tailscale/wireguard-go v0.0.0-20200223182756-33c04a0e6a73 github.com/tailscale/wireguard-go v0.0.0-20200224122332-ad79bbddc844
golang.org/x/crypto v0.0.0-20200210222208-86ce3cb69678 golang.org/x/crypto v0.0.0-20200210222208-86ce3cb69678
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/sys v0.0.0-20200217220822-9197077df867 golang.org/x/sys v0.0.0-20200217220822-9197077df867

View File

@ -21,6 +21,7 @@
"syscall" "syscall"
"time" "time"
"github.com/tailscale/wireguard-go/conn"
"github.com/tailscale/wireguard-go/device" "github.com/tailscale/wireguard-go/device"
"github.com/tailscale/wireguard-go/wgcfg" "github.com/tailscale/wireguard-go/wgcfg"
"tailscale.com/derp" "tailscale.com/derp"
@ -415,7 +416,7 @@ func appendDests(dsts []*net.UDPAddr, as *AddrSet, b []byte) (_ []*net.UDPAddr,
var errNoDestinations = errors.New("magicsock: no destinations") var errNoDestinations = errors.New("magicsock: no destinations")
func (c *Conn) Send(b []byte, ep device.Endpoint) error { func (c *Conn) Send(b []byte, ep conn.Endpoint) error {
as := ep.(*AddrSet) as := ep.(*AddrSet)
var addrBuf [8]*net.UDPAddr var addrBuf [8]*net.UDPAddr
@ -622,7 +623,7 @@ type udpReadResult struct {
// immediate cancellation of network operations. // immediate cancellation of network operations.
var aLongTimeAgo = time.Unix(233431200, 0) var aLongTimeAgo = time.Unix(233431200, 0)
func (c *Conn) ReceiveIPv4(b []byte) (n int, ep device.Endpoint, addr *net.UDPAddr, err error) { func (c *Conn) ReceiveIPv4(b []byte) (n int, ep conn.Endpoint, addr *net.UDPAddr, err error) {
go func() { go func() {
// Read a packet, and process any STUN packets before returning. // Read a packet, and process any STUN packets before returning.
for { for {
@ -694,7 +695,7 @@ func (c *Conn) ReceiveIPv4(b []byte) (n int, ep device.Endpoint, addr *net.UDPAd
return n, addrSet, addr, nil return n, addrSet, addr, nil
} }
func (c *Conn) ReceiveIPv6(buff []byte) (int, device.Endpoint, *net.UDPAddr, error) { func (c *Conn) ReceiveIPv6(buff []byte) (int, conn.Endpoint, *net.UDPAddr, error) {
// TODO(crawshaw): IPv6 support // TODO(crawshaw): IPv6 support
return 0, nil, nil, syscall.EAFNOSUPPORT return 0, nil, nil, syscall.EAFNOSUPPORT
} }
@ -705,6 +706,7 @@ func (c *Conn) SetPrivateKey(privateKey wgcfg.PrivateKey) error {
} }
func (c *Conn) SetMark(value uint32) error { return nil } func (c *Conn) SetMark(value uint32) error { return nil }
func (c *Conn) LastMark() uint32 { return 0 }
func (c *Conn) Close() error { func (c *Conn) Close() error {
select { select {
@ -755,7 +757,7 @@ func (c *Conn) LinkChange() {
c.pconn.Reset(packetConn.(*net.UDPConn)) c.pconn.Reset(packetConn.(*net.UDPConn))
} }
// AddrSet is a set of UDP addresses that implements wireguard/device.Endpoint. // AddrSet is a set of UDP addresses that implements wireguard/conn.Endpoint.
type AddrSet struct { type AddrSet struct {
publicKey key.Public // peer public key used for DERP communication publicKey key.Public // peer public key used for DERP communication
addrs []net.UDPAddr // ordered priority list (low to high) provided by wgengine addrs []net.UDPAddr // ordered priority list (low to high) provided by wgengine
@ -935,7 +937,7 @@ func (a *AddrSet) Addrs() []wgcfg.Endpoint {
// CreateEndpoint is called by WireGuard to connect to an endpoint. // CreateEndpoint is called by WireGuard to connect to an endpoint.
// The key is the public key of the peer and addrs is a // The key is the public key of the peer and addrs is a
// comma-separated list of UDP ip:ports. // comma-separated list of UDP ip:ports.
func (c *Conn) CreateEndpoint(key [32]byte, addrs string) (device.Endpoint, error) { func (c *Conn) CreateEndpoint(key [32]byte, addrs string) (conn.Endpoint, error) {
pk := wgcfg.Key(key) pk := wgcfg.Key(key)
log.Printf("magicsock: CreateEndpoint: key=%s: %s", pk.ShortString(), addrs) log.Printf("magicsock: CreateEndpoint: key=%s: %s", pk.ShortString(), addrs)
a := &AddrSet{ a := &AddrSet{

View File

@ -13,6 +13,7 @@
"sync" "sync"
"time" "time"
"github.com/tailscale/wireguard-go/conn"
"github.com/tailscale/wireguard-go/device" "github.com/tailscale/wireguard-go/device"
"github.com/tailscale/wireguard-go/tun" "github.com/tailscale/wireguard-go/tun"
"github.com/tailscale/wireguard-go/wgcfg" "github.com/tailscale/wireguard-go/wgcfg"
@ -151,7 +152,7 @@ func newUserspaceEngineAdvanced(logf logger.Logf, tundev tun.Device, routerGen R
// here. // here.
go e.RequestStatus() go e.RequestStatus()
}, },
CreateBind: func(uint16) (device.Bind, uint16, error) { CreateBind: func(uint16) (conn.Bind, uint16, error) {
return e.magicConn, e.magicConn.LocalPort(), nil return e.magicConn, e.magicConn.LocalPort(), nil
}, },
CreateEndpoint: e.magicConn.CreateEndpoint, CreateEndpoint: e.magicConn.CreateEndpoint,