From 213d696db0cd951311cc6e8535fc76f2dd508146 Mon Sep 17 00:00:00 2001 From: Claire Wang Date: Fri, 19 Jan 2024 20:04:22 -0500 Subject: [PATCH] magicsock: mute noisy expected peer mtu related error (#10870) --- wgengine/magicsock/magicsock.go | 2 +- wgengine/magicsock/peermtu.go | 20 +++++++++++++++++++- wgengine/magicsock/peermtu_stubs.go | 6 ++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index 0d1a15a22..edc812b48 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -1317,7 +1317,7 @@ func (c *Conn) sendDiscoMessage(dst netip.AddrPort, dstKey key.NodePublic, dstDi } else if err == nil { // Can't send. (e.g. no IPv6 locally) } else { - if !c.networkDown() { + if !c.networkDown() && pmtuShouldLogDiscoTxErr(m, err) { c.logf("magicsock: disco: failed to send %v to %v: %v", disco.MessageSummary(m), dst, err) } } diff --git a/wgengine/magicsock/peermtu.go b/wgengine/magicsock/peermtu.go index 199585323..b675bf409 100644 --- a/wgengine/magicsock/peermtu.go +++ b/wgengine/magicsock/peermtu.go @@ -5,7 +5,13 @@ package magicsock -import "tailscale.com/net/tstun" +import ( + "errors" + + "golang.org/x/sys/unix" + "tailscale.com/disco" + "tailscale.com/net/tstun" +) // Peer path MTU routines shared by platforms that implement it. @@ -110,3 +116,15 @@ func (c *Conn) UpdatePMTUD() { c.peerMTUEnabled.Store(newStatus) c.resetEndpointStates() } + +var errEMSGSIZE error = unix.EMSGSIZE + +func pmtuShouldLogDiscoTxErr(m disco.Message, err error) bool { + // Large disco.Ping packets used to probe path MTU may result in + // an EMSGSIZE error fairly regularly which can pollute logs. + p, ok := m.(*disco.Ping) + if !ok || p.Padding == 0 || !errors.Is(err, errEMSGSIZE) || debugPMTUD() { + return true + } + return false +} diff --git a/wgengine/magicsock/peermtu_stubs.go b/wgengine/magicsock/peermtu_stubs.go index 4675e2501..e4f8038a4 100644 --- a/wgengine/magicsock/peermtu_stubs.go +++ b/wgengine/magicsock/peermtu_stubs.go @@ -5,6 +5,8 @@ package magicsock +import "tailscale.com/disco" + func (c *Conn) DontFragSetting() (bool, error) { return false, nil } @@ -19,3 +21,7 @@ func (c *Conn) PeerMTUEnabled() bool { func (c *Conn) UpdatePMTUD() { } + +func pmtuShouldLogDiscoTxErr(m disco.Message, err error) bool { + return true +}