Files
ctrld/cmd/cli/tunnel_owner.go
T
Anthony Wong 8ae09ac98e feat(cli): put the network state of the host in the log journal
The journal records the network state of the host and each change of
that state. The support team reads one file to see the interfaces, the
routes, the resolvers, and the recoveries around an incident. The same
file shows the health of the query path. A change that touches only
AirDrop or virtual interfaces runs no DNS work.
2026-09-28 16:49:05 +07:00

36 lines
915 B
Go

package cli
import (
"bufio"
"io"
"strings"
)
// agentDescriptionKey starts the quoted product name on an ifconfig agent line.
const agentDescriptionKey = `desc:"`
// parseIfconfigAgent returns the owner of a tunnel from "ifconfig -v utunN"
// output. The owner is the description of the first agent line, and a tunnel that
// no network extension owns has no agent line, so the result is "".
func parseIfconfigAgent(r io.Reader) string {
if r == nil {
return ""
}
scanner := bufio.NewScanner(r)
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
if !strings.HasPrefix(line, "agent ") {
continue
}
_, quoted, ok := strings.Cut(line, agentDescriptionKey)
if !ok {
continue
}
if description, _, ok := strings.Cut(quoted, `"`); ok && description != "" {
return description
}
}
// An owner that the read did not reach is not an owner that does not exist.
return ""
}