2021-08-12 15:33:53 +01: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 17:39:21 +01:00
|
|
|
filename := fmt.Sprintf("etc/hostname.%s", ifaceName)
|
2021-08-12 15:33:53 +01:00
|
|
|
|
2021-10-14 17:39:21 +01:00
|
|
|
return aghos.FileWalker(hostnameIfStaticConfig).Walk(aghos.RootDirFS(), filename)
|
2021-08-12 15:33:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// hostnameIfStaticConfig checks if the interface is configured by
|
|
|
|
// /etc/hostname.* to have a static IP.
|
2021-08-13 17:20:17 +01:00
|
|
|
func hostnameIfStaticConfig(r io.Reader) (_ []string, ok bool, err error) {
|
2021-08-12 15:33:53 +01: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 13:53:33 +01:00
|
|
|
return nil, false, s.Err()
|
2021-08-12 15:33:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-16 13:53:33 +01:00
|
|
|
return nil, true, s.Err()
|
2021-08-12 15:33:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func ifaceSetStaticIP(string) (err error) {
|
|
|
|
return aghos.Unsupported("setting static ip")
|
|
|
|
}
|