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