From a570c2757790110ca1ac6af9a7d2e1a2b10a7af1 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Wed, 2 Sep 2020 15:42:33 -0700 Subject: [PATCH] portlist: reduce log spam on macOS Running tailscaled on my machine yields lots of entries like: weird: missing {tcp 6060} parsePortsNetstat is filtering out loopback addresses as uninteresting. Then addProcesses is surprised to discover these listening ports, which results in spurious logging. Teach addProcesses to also ignore loopback addresses. Signed-off-by: Josh Bleecher Snyder --- portlist/netstat.go | 8 ++++++-- portlist/portlist_macos.go | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/portlist/netstat.go b/portlist/netstat.go index d8a09492e..e0f9345be 100644 --- a/portlist/netstat.go +++ b/portlist/netstat.go @@ -41,6 +41,10 @@ func parsePort(s string) int { return int(port) } +func isLoopbackAddr(s string) bool { + return strings.HasPrefix(s, "127.0.0.1:") || strings.HasPrefix(s, "127.0.0.1.") +} + type nothing struct{} // Lowest common denominator parser for "netstat -na" format. @@ -74,7 +78,7 @@ func parsePortsNetstat(output string) List { // not interested in non-listener sockets continue } - if strings.HasPrefix(laddr, "127.0.0.1:") || strings.HasPrefix(laddr, "127.0.0.1.") { + if isLoopbackAddr(laddr) { // not interested in loopback-bound listeners continue } @@ -85,7 +89,7 @@ func parsePortsNetstat(output string) List { proto = "udp" laddr = cols[len(cols)-2] raddr = cols[len(cols)-1] - if strings.HasPrefix(laddr, "127.0.0.1:") || strings.HasPrefix(laddr, "127.0.0.1.") { + if isLoopbackAddr(laddr) { // not interested in loopback-bound listeners continue } diff --git a/portlist/portlist_macos.go b/portlist/portlist_macos.go index fc3f1d88a..c532a248d 100644 --- a/portlist/portlist_macos.go +++ b/portlist/portlist_macos.go @@ -95,9 +95,12 @@ func addProcesses(pl []Port) ([]Port, error) { if port > 0 { pp := ProtoPort{proto, uint16(port)} p := m[pp] - if p != nil { + switch { + case p != nil: p.Process = cmd - } else { + case isLoopbackAddr(val): + // ignore + default: fmt.Fprintf(os.Stderr, "weird: missing %v\n", pp) } }