Skip to content

Commit

Permalink
portlist: reduce log spam on macOS
Browse files Browse the repository at this point in the history
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 <josh@tailscale.com>
  • Loading branch information
josharian committed Sep 2, 2020
1 parent 3b05cba commit a570c27
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 6 additions & 2 deletions portlist/netstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
7 changes: 5 additions & 2 deletions portlist/portlist_macos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit a570c27

Please sign in to comment.