mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-15 11:22:49 +03:00
b74b92fc27
Merge in DNS/adguard-home from imp-build-tags to master Squashed commit of the following: commit c15793e04c08097835692568a598b8a8d15f57f4 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 19:25:20 2022 +0300 home: imp build tags commit 2b9b68e9fe6942422951f50d90c70143a3509401 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 19:23:56 2022 +0300 version: imp build tags commit c0ade3d6ae8885c596fc31312360b25fe992d1e4 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 19:20:48 2022 +0300 dhcpd: imp build tags commit 0ca2a73b7c3b721400a0cc6383cc9e60f4961f22 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 19:17:22 2022 +0300 aghos: imp build tags commit 733a685b24b56153b96d59cb97c174ad322ff841 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 19:13:11 2022 +0300 aghnet: imp build tags
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
//go:build freebsd
|
|
|
|
package aghnet
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"io"
|
|
"net"
|
|
"strings"
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/aghos"
|
|
)
|
|
|
|
func ifaceHasStaticIP(ifaceName string) (ok bool, err error) {
|
|
const rcConfFilename = "etc/rc.conf"
|
|
|
|
walker := aghos.FileWalker(interfaceName(ifaceName).rcConfStaticConfig)
|
|
|
|
return walker.Walk(rootDirFS, rcConfFilename)
|
|
}
|
|
|
|
// rcConfStaticConfig checks if the interface is configured by /etc/rc.conf to
|
|
// have a static IP.
|
|
func (n interfaceName) rcConfStaticConfig(r io.Reader) (_ []string, cont bool, err error) {
|
|
s := bufio.NewScanner(r)
|
|
for pref := fmt.Sprintf("ifconfig_%s=", n); s.Scan(); {
|
|
line := strings.TrimSpace(s.Text())
|
|
if !strings.HasPrefix(line, pref) {
|
|
continue
|
|
}
|
|
|
|
cfgLeft, cfgRight := len(pref)+1, len(line)-1
|
|
if cfgLeft >= cfgRight {
|
|
continue
|
|
}
|
|
|
|
// TODO(e.burkov): Expand the check to cover possible
|
|
// configurations from man rc.conf(5).
|
|
fields := strings.Fields(line[cfgLeft:cfgRight])
|
|
if len(fields) >= 2 &&
|
|
strings.EqualFold(fields[0], "inet") &&
|
|
net.ParseIP(fields[1]) != nil {
|
|
return nil, false, s.Err()
|
|
}
|
|
}
|
|
|
|
return nil, true, s.Err()
|
|
}
|
|
|
|
func ifaceSetStaticIP(string) (err error) {
|
|
return aghos.Unsupported("setting static ip")
|
|
}
|