Pull request: all: fix statip ip ck
Merge in DNS/adguard-home from fix-static-ip-check to master
Squashed commit of the following:
commit af365c106f3d620afc77492a06f5368611328f5f
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Mon Feb 15 18:55:35 2021 +0300
all: doc changes
commit 922afb262458fc488e03cad232430d90c504f2f3
Merge: 43fec5fb dbcc55f5
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Mon Feb 15 18:53:31 2021 +0300
Merge branch 'master' into fix-static-ip-check
commit 43fec5fb79f5c67b375da00aa73d11b3ed9ba3a4
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Mon Feb 15 18:37:16 2021 +0300
all: fix statip ip ck
This commit is contained in:
@@ -21,7 +21,11 @@ import (
|
||||
const maxConfigFileSize = 1024 * 1024
|
||||
|
||||
func ifaceHasStaticIP(ifaceName string) (has bool, err error) {
|
||||
var f *os.File
|
||||
// TODO(a.garipov): Currently, this function returns the first
|
||||
// definitive result. So if /etc/dhcpcd.conf has a static IP while
|
||||
// /etc/network/interfaces doesn't, it will return true. Perhaps this
|
||||
// is not the most desirable behavior.
|
||||
|
||||
for _, check := range []struct {
|
||||
checker func(io.Reader, string) (bool, error)
|
||||
filePath string
|
||||
@@ -32,8 +36,11 @@ func ifaceHasStaticIP(ifaceName string) (has bool, err error) {
|
||||
checker: ifacesStaticConfig,
|
||||
filePath: "/etc/network/interfaces",
|
||||
}} {
|
||||
var f *os.File
|
||||
f, err = os.Open(check.filePath)
|
||||
if err != nil {
|
||||
// ErrNotExist can happen here if there is no such file.
|
||||
// This is normal, as not every system uses those files.
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
err = nil
|
||||
|
||||
@@ -52,12 +59,14 @@ func ifaceHasStaticIP(ifaceName string) (has bool, err error) {
|
||||
defer fileReadCloser.Close()
|
||||
|
||||
has, err = check.checker(fileReadCloser, ifaceName)
|
||||
if has || err != nil {
|
||||
break
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return has, nil
|
||||
}
|
||||
|
||||
return has, err
|
||||
return false, ErrNoStaticIPInfo
|
||||
}
|
||||
|
||||
// dhcpcdStaticConfig checks if interface is configured by /etc/dhcpcd.conf to
|
||||
|
||||
Reference in New Issue
Block a user