2021-08-12 15:33:53 +01:00
|
|
|
//go:build openbsd
|
|
|
|
|
|
|
|
package aghnet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/aghos"
|
2024-08-05 15:12:33 +01:00
|
|
|
"github.com/AdguardTeam/golibs/netutil"
|
2021-08-12 15:33:53 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
2022-03-30 13:11:57 +01:00
|
|
|
return aghos.FileWalker(hostnameIfStaticConfig).Walk(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)
|
2024-08-05 15:12:33 +01:00
|
|
|
switch {
|
|
|
|
case
|
|
|
|
len(fields) < 2,
|
|
|
|
fields[0] != "inet",
|
|
|
|
!netutil.IsValidIPString(fields[1]):
|
|
|
|
continue
|
|
|
|
default:
|
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")
|
|
|
|
}
|