2021-08-12 17:33:53 +03:00
|
|
|
//go:build openbsd
|
|
|
|
// +build openbsd
|
|
|
|
|
|
|
|
package aghnet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/aghos"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ifaceHasStaticIP(ifaceName string) (ok bool, err error) {
|
2021-10-14 19:39:21 +03:00
|
|
|
filename := fmt.Sprintf("etc/hostname.%s", ifaceName)
|
2021-08-12 17:33:53 +03:00
|
|
|
|
2022-04-19 15:01:49 +03:00
|
|
|
return aghos.FileWalker(hostnameIfStaticConfig).Walk(rootDirFS, filename)
|
2021-08-12 17:33:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// hostnameIfStaticConfig checks if the interface is configured by
|
|
|
|
// /etc/hostname.* to have a static IP.
|
2021-08-13 19:20:17 +03:00
|
|
|
func hostnameIfStaticConfig(r io.Reader) (_ []string, ok bool, err error) {
|
2021-08-12 17:33:53 +03: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 15:53:33 +03:00
|
|
|
return nil, false, s.Err()
|
2021-08-12 17:33:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-16 15:53:33 +03:00
|
|
|
return nil, true, s.Err()
|
2021-08-12 17:33:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func ifaceSetStaticIP(string) (err error) {
|
|
|
|
return aghos.Unsupported("setting static ip")
|
|
|
|
}
|