mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-29 02:18:51 +03:00
2898a49d86
Merge in DNS/adguard-home from 4499-rm-unnecessary-locking to master Squashed commit of the following: commit 6d70472506dd0fd69225454c73d9f7f6a208b76b Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Mon Apr 25 17:26:54 2022 +0300 home: rm unnecessary locking in update; refactor
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
//go:build freebsd
|
|
// +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(aghos.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")
|
|
}
|