From c55d26967b1b4646e80a7c1c11700373dc044868 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 21 Jan 2021 08:05:07 -0800 Subject: [PATCH] wgengine/magicsock: log more details of endpoints learned over disco Also, don't try to use IPv6 LinkLocalUnicast addresses for now. Like endpoints exchanged with control, we share them but don't yet use them. Updates #1172 --- wgengine/magicsock/magicsock.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index 9cead1c61..06cf1e0d5 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -1850,7 +1850,10 @@ func (c *Conn) handleDiscoMessage(msg []byte, src netaddr.IPPort) bool { return true } if de != nil { - c.logf("magicsock: disco: %v<-%v (%v, %v) got call-me-maybe", c.discoShort, de.discoShort, de.publicKey.ShortString(), derpStr(src.String())) + c.logf("magicsock: disco: %v<-%v (%v, %v) got call-me-maybe, %d endpoints", + c.discoShort, de.discoShort, + de.publicKey.ShortString(), derpStr(src.String()), + len(dm.MyNumber)) go de.handleCallMeMaybe(dm) } } @@ -3464,14 +3467,35 @@ func (de *discoEndpoint) handleCallMeMaybe(m *disco.CallMeMaybe) { if de.isCallMeMaybeEP == nil { de.isCallMeMaybeEP = map[netaddr.IPPort]bool{} } + var newEPs []netaddr.IPPort for _, ep := range m.MyNumber { + if ep.IP.Is6() && ep.IP.IsLinkLocalUnicast() { + // We send these out, but ignore them for now. + // TODO: teach the ping code to ping on all interfaces + // for these. + continue + } de.isCallMeMaybeEP[ep] = true if es, ok := de.endpointState[ep]; ok { es.callMeMaybeTime = now } else { de.endpointState[ep] = &endpointState{callMeMaybeTime: now} - } + newEPs = append(newEPs, ep) + } + } + if len(newEPs) > 0 { + de.c.logf("magicsock: disco: call-me-maybe from %v %v added new endpoints: %v", + de.publicKey.ShortString(), de.discoShort, + logger.ArgWriter(func(w *bufio.Writer) { + for i, ep := range newEPs { + if i > 0 { + w.WriteString(", ") + } + w.WriteString(ep.String()) + } + })) } + // Delete any prior CalllMeMaybe endpoints that weren't included // in this message. for ep, want := range de.isCallMeMaybeEP {