portlist: add Poller.IncludeLocalhost option

This PR parameterizes receiving loopback updates from the portlist package.
Callers can now include services bound to localhost if they want.
Note that this option is off by default still.

Fixes #8171

Signed-off-by: Marwan Sulaiman <marwan@tailscale.com>
This commit is contained in:
Marwan Sulaiman
2023-05-24 12:52:45 -04:00
committed by Marwan Sulaiman
parent 3d180a16c3
commit e32e5c0d0c
9 changed files with 88 additions and 64 deletions

View File

@@ -18,6 +18,7 @@ type Port struct {
Proto string // "tcp" or "udp"
Port uint16 // port number
Process string // optional process name, if found
Pid int // process id, if known
}
// List is a list of Ports.
@@ -69,12 +70,11 @@ func sortAndDedup(ps List) List {
out := ps[:0]
var last Port
for _, p := range ps {
protoPort := Port{Proto: p.Proto, Port: p.Port}
if last == protoPort {
if last.Proto == p.Proto && last.Port == p.Port {
continue
}
out = append(out, p)
last = protoPort
last = p
}
return out
}