wgengine/magicsock: finish IPv6 transport support

DEBUG_INCLUDE_IPV6=1 is still required, but works now.

Updates #18 (fixes it, once env var gate is removed)
This commit is contained in:
Brad Fitzpatrick 2020-03-24 10:56:22 -07:00
parent 82ed7e527e
commit 3c3ea8bc8a

View File

@ -1170,8 +1170,8 @@ func (c *Conn) ReceiveIPv6(b []byte) (int, conn.Endpoint, *net.UDPAddr, error) {
c.stunReceiveFunc.Load().(func([]byte, *net.UDPAddr))(b[:n], addr) c.stunReceiveFunc.Load().(func([]byte, *net.UDPAddr))(b[:n], addr)
continue continue
} }
// TODO(bradfitz): finish. look up addrset, return etc. ep := c.findEndpoint(addr)
// For now we're only using this for STUN. return n, ep, addr, nil
} }
} }
@ -1687,13 +1687,7 @@ func (c *Conn) CreateEndpoint(key [32]byte, addrs string) (conn.Endpoint, error)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if ip4 := addr.IP.To4(); ip4 != nil { addr.IP = ip4or6(addr.IP)
addr.IP = ip4
} else {
// TODO(bradfitz): stop skipping IPv6 ones for now.
c.logf("magicsock: CreateEndpoint: ignoring IPv6 addr %v for now", addr)
continue
}
a.addrs = append(a.addrs, *addr) a.addrs = append(a.addrs, *addr)
} }
} }
@ -1844,3 +1838,10 @@ func peerShort(k key.Public) string {
k2 := wgcfg.Key(k) k2 := wgcfg.Key(k)
return k2.ShortString() return k2.ShortString()
} }
func ip4or6(ip net.IP) net.IP {
if ip4 := ip.To4(); ip4 != nil {
return ip4
}
return ip
}