Skip to content

Log all changes to magicSock best addr #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 5 additions & 19 deletions wgengine/magicsock/magicsock.go
Original file line number Diff line number Diff line change
Expand Up @@ -1663,8 +1663,6 @@ func (c *Conn) derpWriteChanOfAddr(addr netip.AddrPort, peer key.NodePublic) cha
// the provided DERP regionID, and that the peer advertises a DERP
// home region ID of homeID.
//
// If there's any change, it logs.
//
// c.mu must be held.
func (c *Conn) setPeerLastDerpLocked(peer key.NodePublic, regionID, homeID int) {
if peer.IsZero() {
Expand All @@ -1675,23 +1673,6 @@ func (c *Conn) setPeerLastDerpLocked(peer key.NodePublic, regionID, homeID int)
return
}
c.peerLastDerp[peer] = regionID

var newDesc string
switch {
case regionID == homeID && regionID == c.myDerp:
newDesc = "shared home"
case regionID == homeID:
newDesc = "their home"
case regionID == c.myDerp:
newDesc = "our home"
case regionID != homeID:
newDesc = "alt"
}
if old == 0 {
c.logf("[v1] magicsock: derp route for %s set to derp-%d (%s)", peer.ShortString(), regionID, newDesc)
} else {
c.logf("[v1] magicsock: derp route for %s changed from derp-%d => derp-%d (%s)", peer.ShortString(), old, regionID, newDesc)
}
}

// derpReadResult is the type sent by runDerpClient to ReceiveIPv4
Expand Down Expand Up @@ -4298,6 +4279,8 @@ func (de *endpoint) deleteEndpointLocked(why string, ep netip.AddrPort) {
})
delete(de.endpointState, ep)
if de.bestAddr.AddrPort == ep {
de.c.logf("magicsock: disco: node %v %v now using DERP only (endpoint %s deleted)",
de.publicKey.ShortString(), de.discoShort(), ep)
de.debugUpdates.Add(EndpointChange{
When: time.Now(),
What: "deleteEndpointLocked-bestAddr-" + why,
Expand Down Expand Up @@ -4703,6 +4686,8 @@ func (de *endpoint) updateFromNode(n *tailcfg.Node, heartbeatDisabled bool) {
de.c.logf("magicsock: invalid endpoint: %s %s", ep, err)
continue
}
de.c.logf("magicsock: disco: node %v %v now using %s (WireGuard Only)",
de.publicKey.ShortString(), de.discoShort(), ipp)
de.bestAddr = addrLatency{
AddrPort: ipp,
}
Expand Down Expand Up @@ -5109,6 +5094,7 @@ func (de *endpoint) stopAndReset() {
func (de *endpoint) resetLocked() {
de.lastSend = 0
de.lastFullPing = 0
de.c.logf("magicsock: disco: node %v %v now using DERP only (reset)", de.publicKey.ShortString(), de.discoShort())
de.bestAddr = addrLatency{}
de.bestAddrAt = 0
de.trustBestAddrUntil = 0
Expand Down