2021-08-12 14:33:53 +00:00
|
|
|
//go:build openbsd
|
|
|
|
// +build openbsd
|
|
|
|
|
|
|
|
package aghnet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/aghos"
|
|
|
|
)
|
|
|
|
|
|
|
|
func canBindPrivilegedPorts() (can bool, err error) {
|
|
|
|
return aghos.HaveAdminRights()
|
|
|
|
}
|
|
|
|
|
|
|
|
func ifaceHasStaticIP(ifaceName string) (ok bool, err error) {
|
2021-10-14 16:39:21 +00:00
|
|
|
filename := fmt.Sprintf("etc/hostname.%s", ifaceName)
|
2021-08-12 14:33:53 +00:00
|
|
|
|
2021-10-14 16:39:21 +00:00
|
|
|
return aghos.FileWalker(hostnameIfStaticConfig).Walk(aghos.RootDirFS(), filename)
|
2021-08-12 14:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// hostnameIfStaticConfig checks if the interface is configured by
|
|
|
|
// /etc/hostname.* to have a static IP.
|
2021-08-13 16:20:17 +00:00
|
|
|
func hostnameIfStaticConfig(r io.Reader) (_ []string, ok bool, err error) {
|
2021-08-12 14:33:53 +00:00
|
|
|
s := bufio.NewScanner(r)
|
|
|
|
for s.Scan() {
|
|
|
|
line := strings.TrimSpace(s.Text())
|
|
|
|
fields := strings.Fields(line)
|
|
|
|
if len(fields) >= 2 && fields[0] == "inet" && net.ParseIP(fields[1]) != nil {
|
2021-08-16 12:53:33 +00:00
|
|
|
return nil, false, s.Err()
|
2021-08-12 14:33:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-16 12:53:33 +00:00
|
|
|
return nil, true, s.Err()
|
2021-08-12 14:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ifaceSetStaticIP(string) (err error) {
|
|
|
|
return aghos.Unsupported("setting static ip")
|
|
|
|
}
|