AdGuardHome/internal/aghnet/net_freebsd.go
Eugene Burkov edfa8c147f Pull request 2263: AGDNS-2280 Upd dnsproxy, golibs
Squashed commit of the following:

commit 8d83eebba851e8e09bb08b1c94a247cb049a1b75
Merge: c6574a33c b6ed76965
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Mon Aug 5 16:59:50 2024 +0300

    Merge branch 'master' into AGDNS-2280-upd-golibs

commit c6574a33c6
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Wed Jul 31 19:56:58 2024 +0300

    all: upd proxy, golibs
2024-08-05 17:12:33 +03:00

57 lines
1.3 KiB
Go

//go:build freebsd
package aghnet
import (
"bufio"
"fmt"
"io"
"strings"
"github.com/AdguardTeam/AdGuardHome/internal/aghos"
"github.com/AdguardTeam/golibs/netutil"
)
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])
switch {
case
len(fields) < 2,
!strings.EqualFold(fields[0], "inet"),
!netutil.IsValidIPString(fields[1]):
continue
default:
return nil, false, s.Err()
}
}
return nil, true, s.Err()
}
func ifaceSetStaticIP(string) (err error) {
return aghos.Unsupported("setting static ip")
}