mirror of https://github.com/tailscale/tailscale/
portlist: add macOS osImpl, finish migration to new style
Previously: *pull/6202/merge036f70b7b4
for linux *35bee36549
for windows This does macOS. And removes all the compat code for the old style. (e.g. iOS, js are no longer mentioned; all platforms without implementations just default to not doing anything) One possible regression is that platforms without explicit implementations previously tried to do the "netstat -na" style to get open ports (but not process names). Maybe that worked on FreeBSD and OpenBSD previously, but nobody ever really tested it. And it was kinda useless without associated process names. So better off removing those for now until they get a good implementation. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
parent
da8def8e13
commit
21ef7e5c35
@ -1,31 +0,0 @@
|
|||||||
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
//go:build (windows || freebsd || openbsd || darwin) && !ios && !js
|
|
||||||
|
|
||||||
package portlist
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os/exec"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func appendListeningPortsNetstat(base []Port, arg string) ([]Port, error) {
|
|
||||||
exe, err := exec.LookPath("netstat")
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("netstat: lookup: %v", err)
|
|
||||||
}
|
|
||||||
output, err := exec.Command(exe, arg).Output()
|
|
||||||
if err != nil {
|
|
||||||
xe, ok := err.(*exec.ExitError)
|
|
||||||
stderr := ""
|
|
||||||
if ok {
|
|
||||||
stderr = strings.TrimSpace(string(xe.Stderr))
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("netstat: %v (%q)", err, stderr)
|
|
||||||
}
|
|
||||||
|
|
||||||
return appendParsePortsNetstat(base, string(output)), nil
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
//go:build ios
|
|
||||||
|
|
||||||
package portlist
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const pollInterval = 9999 * time.Hour
|
|
||||||
|
|
||||||
func appendListeningPorts(base []Port) ([]Port, error) {
|
|
||||||
return nil, errors.New("not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
func addProcesses(pl []Port) ([]Port, error) {
|
|
||||||
return nil, errors.New("not implemented")
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package portlist
|
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
const pollInterval = 365 * 24 * time.Hour
|
|
||||||
|
|
||||||
func appendListeningPorts(base []Port) ([]Port, error) {
|
|
||||||
return base, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func addProcesses(pl []Port) ([]Port, error) {
|
|
||||||
return pl, nil
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
//go:build !linux && !windows && !darwin && !js
|
|
||||||
|
|
||||||
package portlist
|
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
// We have to run netstat, which is a bit expensive, so don't do it too often.
|
|
||||||
const pollInterval = 5 * time.Second
|
|
||||||
|
|
||||||
func appendListeningPorts(base []Port) ([]Port, error) {
|
|
||||||
return appendListeningPortsNetstat(base, "-na")
|
|
||||||
}
|
|
||||||
|
|
||||||
func addProcesses(pl []Port) ([]Port, error) {
|
|
||||||
// Generic version has no way to get process mappings.
|
|
||||||
// This has to be OS-specific.
|
|
||||||
return pl, nil
|
|
||||||
}
|
|
Loading…
Reference in New Issue