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

@@ -25,7 +25,8 @@ type famPort struct {
}
type windowsImpl struct {
known map[famPort]*portMeta // inode string => metadata
known map[famPort]*portMeta // inode string => metadata
includeLocalhost bool
}
type portMeta struct {
@@ -33,9 +34,10 @@ type portMeta struct {
keep bool
}
func newWindowsImpl() osImpl {
func newWindowsImpl(includeLocalhost bool) osImpl {
return &windowsImpl{
known: map[famPort]*portMeta{},
known: map[famPort]*portMeta{},
includeLocalhost: includeLocalhost,
}
}
@@ -58,7 +60,7 @@ func (im *windowsImpl) AppendListeningPorts(base []Port) ([]Port, error) {
if e.State != "LISTEN" {
continue
}
if !e.Local.Addr().IsUnspecified() {
if !im.includeLocalhost && !e.Local.Addr().IsUnspecified() {
continue
}
fp := famPort{
@@ -83,6 +85,7 @@ func (im *windowsImpl) AppendListeningPorts(base []Port) ([]Port, error) {
Proto: "tcp",
Port: e.Local.Port(),
Process: process,
Pid: e.Pid,
},
}
im.known[fp] = pm