From db2a2165611936e3fe0b4fad85a50dd9f290654e Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 29 May 2020 12:40:51 -0700 Subject: [PATCH] wgengine/magicsock: don't log on UDP send errors if address family known missing Fixes #376 --- wgengine/magicsock/magicsock.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index e820b4c3a..08e0f7df0 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -123,6 +123,13 @@ type Conn struct { // peerLastDerp tracks which DERP node we last used to speak with a // peer. It's only used to quiet logging, so we only log on change. peerLastDerp map[key.Public]int + + // noV4 and noV6 are whether IPv4 and IPv6 are known to be + // missing. They're only used to suppress log spam. The name + // is named negatively because in early start-up, we don't yet + // necessarily have a netcheck.Report and don't want to skip + // logging. + noV4, noV6 syncs.AtomicBool } // derpRoute is a route entry for a public key, saying that a certain @@ -347,6 +354,9 @@ func (c *Conn) updateNetInfo(ctx context.Context) (*netcheck.Report, error) { return nil, err } + c.noV4.Set(!report.IPv4) + c.noV6.Set(!report.IPv6) + ni := &tailcfg.NetInfo{ DERPLatency: map[string]float64{}, MappingVariesByDestIP: report.MappingVariesByDestIP, @@ -746,10 +756,16 @@ var errDropDerpPacket = errors.New("too many DERP packets queued; dropping") func (c *Conn) sendUDP(addr *net.UDPAddr, b []byte) error { if addr.IP.To4() != nil { _, err := c.pconn4.WriteTo(b, addr) + if err != nil && c.noV4.Get() { + return nil + } return err } if c.pconn6 != nil { _, err := c.pconn6.WriteTo(b, addr) + if err != nil && c.noV6.Get() { + return nil + } return err } return nil // ignore IPv6 dest if we don't have an IPv6 address.