mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
Make RFC1918 listener spawning opt-in via --rfc1918 flag instead of automatic behavior. This allows users to explicitly control when ctrld listens on private network addresses to receive DNS queries from LAN clients, improving security and configurability. Refactor network interface detection to better distinguish between physical and virtual interfaces, ensuring only real hardware interfaces are used for RFC1918 address binding.
36 lines
825 B
Go
36 lines
825 B
Go
package ctrld
|
|
|
|
import (
|
|
"bufio"
|
|
"bytes"
|
|
"io"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
// validInterfaces returns a set of all valid hardware ports.
|
|
// TODO: deduplicated with cmd/cli/net_darwin.go in v2.
|
|
func validInterfaces() map[string]struct{} {
|
|
b, err := exec.Command("networksetup", "-listallhardwareports").Output()
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return parseListAllHardwarePorts(bytes.NewReader(b))
|
|
}
|
|
|
|
// parseListAllHardwarePorts parses output of "networksetup -listallhardwareports"
|
|
// and returns map presents all hardware ports.
|
|
func parseListAllHardwarePorts(r io.Reader) map[string]struct{} {
|
|
m := make(map[string]struct{})
|
|
scanner := bufio.NewScanner(r)
|
|
for scanner.Scan() {
|
|
line := scanner.Text()
|
|
after, ok := strings.CutPrefix(line, "Device: ")
|
|
if !ok {
|
|
continue
|
|
}
|
|
m[after] = struct{}{}
|
|
}
|
|
return m
|
|
}
|