magicsock: keep DERP magic IPs out of the address map

Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
pull/119/head
David Crawshaw 5 years ago committed by David Crawshaw
parent c6550135d5
commit 0752c77dc2

@ -446,7 +446,12 @@ func (c *Conn) Send(b []byte, ep conn.Endpoint) error {
default: default:
panic(fmt.Sprintf("unexpected Endpoint type %T", v)) panic(fmt.Sprintf("unexpected Endpoint type %T", v))
case *singleEndpoint: case *singleEndpoint:
_, err := c.pconn.WriteTo(b, (*net.UDPAddr)(v)) addr := (*net.UDPAddr)(v)
if addr.IP.Equal(derpMagicIP) {
c.logf("DERP BUG: attempting to send packet to DERP address %v", addr)
return nil
}
_, err := c.pconn.WriteTo(b, addr)
return err return err
case *AddrSet: case *AddrSet:
as = v as = v
@ -1033,6 +1038,10 @@ func (c *Conn) CreateEndpoint(key [32]byte, addrs string) (conn.Endpoint, error)
c.addrsMu.Lock() c.addrsMu.Lock()
for _, addr := range a.addrs { for _, addr := range a.addrs {
if addr.IP.Equal(derpMagicIP) {
continue
}
var epAddr udpAddr var epAddr udpAddr
copy(epAddr.ip.Addr[:], addr.IP.To16()) copy(epAddr.ip.Addr[:], addr.IP.To16())
epAddr.port = uint16(addr.Port) epAddr.port = uint16(addr.Port)

Loading…
Cancel
Save