Pull request: 3435 openwrt detect
Merge in DNS/adguard-home from 3435-openwrt-detect to master Updates #3435. Squashed commit of the following: commit 04b10f407ced1c85ac8089f980d79e9bbfe14e95 Author: Eugene Burkov <e.burkov@adguard.com> Date: Fri Aug 13 19:02:55 2021 +0300 aghos: fix windows build commit d387cec5f9cae9256dccef8c666c02f2fb7449a2 Author: Eugene Burkov <e.burkov@adguard.com> Date: Fri Aug 13 18:22:12 2021 +0300 aghos: imp code, tests commit 2450b98522eb032ec8658f3ef2384fc77b627cc6 Author: Eugene Burkov <e.burkov@adguard.com> Date: Fri Aug 13 13:43:46 2021 +0300 all: imp code, docs commit 7fabba3a8dc70fe61dbaa8fd5445453816fe9ac7 Author: Eugene Burkov <e.burkov@adguard.com> Date: Fri Aug 13 04:04:09 2021 +0300 all: log changes commit 7cc1235308caf09eb4c80c05a4f328b8d6909ec7 Author: Eugene Burkov <e.burkov@adguard.com> Date: Fri Aug 13 03:33:13 2021 +0300 querylog: repl with golibs commit 84592087d3b2aca23613950bb203ff3c862624dc Author: Eugene Burkov <e.burkov@adguard.com> Date: Fri Aug 13 03:16:37 2021 +0300 aghos: use filewalker commit e4f2964b0e031c7a9a053e85c0ff7c792c772929 Author: Eugene Burkov <e.burkov@adguard.com> Date: Fri Aug 13 00:34:20 2021 +0300 aghos: mv recurrentchecker from aghnet
This commit is contained in:
@@ -8,61 +8,34 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/aghio"
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/aghos"
|
||||
"github.com/AdguardTeam/golibs/errors"
|
||||
)
|
||||
|
||||
func canBindPrivilegedPorts() (can bool, err error) {
|
||||
return aghos.HaveAdminRights()
|
||||
}
|
||||
|
||||
// maxCheckedFileSize is the maximum acceptable length of the /etc/hostname.*
|
||||
// files.
|
||||
const maxCheckedFileSize = 1024 * 1024
|
||||
|
||||
func ifaceHasStaticIP(ifaceName string) (ok bool, err error) {
|
||||
const filenameFmt = "/etc/hostname.%s"
|
||||
filename := fmt.Sprintf("/etc/hostname.%s", ifaceName)
|
||||
|
||||
filename := fmt.Sprintf(filenameFmt, ifaceName)
|
||||
var f *os.File
|
||||
if f, err = os.Open(filename); err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
err = nil
|
||||
}
|
||||
|
||||
return false, err
|
||||
}
|
||||
defer func() { err = errors.WithDeferred(err, f.Close()) }()
|
||||
|
||||
var r io.Reader
|
||||
r, err = aghio.LimitReader(f, maxCheckedFileSize)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return hostnameIfStaticConfig(r)
|
||||
return aghos.FileWalker(hostnameIfStaticConfig).Walk(filename)
|
||||
}
|
||||
|
||||
// hostnameIfStaticConfig checks if the interface is configured by
|
||||
// /etc/hostname.* to have a static IP.
|
||||
//
|
||||
// TODO(e.burkov): The platform-dependent functions to check the static IP
|
||||
// address configured are rather similar. Think about unifying common parts.
|
||||
func hostnameIfStaticConfig(r io.Reader) (has bool, err error) {
|
||||
func hostnameIfStaticConfig(r io.Reader) (_ []string, ok bool, err error) {
|
||||
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 {
|
||||
return true, s.Err()
|
||||
return nil, true, s.Err()
|
||||
}
|
||||
}
|
||||
|
||||
return false, s.Err()
|
||||
return nil, false, s.Err()
|
||||
}
|
||||
|
||||
func ifaceSetStaticIP(string) (err error) {
|
||||
|
||||
Reference in New Issue
Block a user