net/netns: remove some logspam by avoiding logging parse errors due to unspecified addresses

I updated the address parsing stuff to return a specific error for
unspecified hosts passed as empty strings, and look for that
when logging errors. I explicitly did not make parseAddress return a
netip.Addr containing an unspecified address because at this layer,
in the absence of any host, we don't necessarily know the address
family we're dealing with.

For the purposes of this code I think this is fine, at least until
we implement #12588.

Fixes #12979

Signed-off-by: Aaron Klotz <aaron@tailscale.com>
pull/12992/head
Aaron Klotz 4 months ago
parent 004dded0a8
commit 655b4f8fc5

@ -92,7 +92,9 @@ func getInterfaceIndex(logf logger.Logf, netMon *netmon.Monitor, address string)
// If the address doesn't parse, use the default index. // If the address doesn't parse, use the default index.
addr, err := parseAddress(address) addr, err := parseAddress(address)
if err != nil { if err != nil {
logf("[unexpected] netns: error parsing address %q: %v", address, err) if err != errUnspecifiedHost {
logf("[unexpected] netns: error parsing address %q: %v", address, err)
}
return defaultIdx() return defaultIdx()
} }

@ -6,16 +6,22 @@
package netns package netns
import ( import (
"errors"
"net" "net"
"net/netip" "net/netip"
) )
var errUnspecifiedHost = errors.New("unspecified host")
func parseAddress(address string) (addr netip.Addr, err error) { func parseAddress(address string) (addr netip.Addr, err error) {
host, _, err := net.SplitHostPort(address) host, _, err := net.SplitHostPort(address)
if err != nil { if err != nil {
// error means the string didn't contain a port number, so use the string directly // error means the string didn't contain a port number, so use the string directly
host = address host = address
} }
if host == "" {
return addr, errUnspecifiedHost
}
return netip.ParseAddr(host) return netip.ParseAddr(host)
} }

@ -102,7 +102,9 @@ func controlC(logf logger.Logf, network, address string, c syscall.RawConn) (err
} }
} }
} else { } else {
logf("[unexpected] netns: error parsing address %q: %v", address, err) if err != errUnspecifiedHost {
logf("[unexpected] netns: error parsing address %q: %v", address, err)
}
ifaceIdxV4, ifaceIdxV6 = defIfaceIdxV4, defIfaceIdxV6 ifaceIdxV4, ifaceIdxV6 = defIfaceIdxV4, defIfaceIdxV6
} }
} else { } else {

Loading…
Cancel
Save