Pull request: create aghnet package
Merge in DNS/adguard-home from mk-aghnet to master
Updates #2829.
Squashed commit of the following:
commit 519806c04b8d0517aacce9c31f2d06ab56631937
Merge: 92376c86 97361234
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Mar 16 19:13:56 2021 +0300
Merge branch 'master' into mk-aghnet
commit 92376c8665e529191aa482432f9d5e3e2e3afdc8
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Mar 16 18:37:22 2021 +0300
aghnet: fix linux
commit 7f36d19b0e650d4e4fc5cf9ea4b501a7f636abeb
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Mar 16 18:08:30 2021 +0300
aghnet: mv network utils from util
commit aa68c70c1146b8c32303c6e037953a41aa7d72f9
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Mar 16 17:30:06 2021 +0300
aghnet: mv ipDetector here
commit b033657f5c5ee91f869c36508a5eb15976a174a0
Author: Eugene Burkov <e.burkov@adguard.com>
Date: Tue Mar 16 17:24:07 2021 +0300
all: mk aghnet package, rename sysutil package
This commit is contained in:
@@ -10,8 +10,7 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/sysutil"
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/util"
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
||||
"github.com/AdguardTeam/golibs/log"
|
||||
)
|
||||
|
||||
@@ -93,7 +92,7 @@ func (s *Server) handleDHCPStatus(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func (s *Server) enableDHCP(ifaceName string) (code int, err error) {
|
||||
var hasStaticIP bool
|
||||
hasStaticIP, err = sysutil.IfaceHasStaticIP(ifaceName)
|
||||
hasStaticIP, err = aghnet.IfaceHasStaticIP(ifaceName)
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrPermission) {
|
||||
// ErrPermission may happen here on Linux systems where
|
||||
@@ -110,7 +109,7 @@ func (s *Server) enableDHCP(ifaceName string) (code int, err error) {
|
||||
log.Info("error while checking static ip: %s; "+
|
||||
"assuming machine has static ip and going on", err)
|
||||
hasStaticIP = true
|
||||
} else if errors.Is(err, sysutil.ErrNoStaticIPInfo) {
|
||||
} else if errors.Is(err, aghnet.ErrNoStaticIPInfo) {
|
||||
// Couldn't obtain a definitive answer. Assume static
|
||||
// IP an go on.
|
||||
log.Info("can't check for static ip; " +
|
||||
@@ -124,7 +123,7 @@ func (s *Server) enableDHCP(ifaceName string) (code int, err error) {
|
||||
}
|
||||
|
||||
if !hasStaticIP {
|
||||
err = sysutil.IfaceSetStaticIP(ifaceName)
|
||||
err = aghnet.IfaceSetStaticIP(ifaceName)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("setting static ip: %w", err)
|
||||
|
||||
@@ -267,7 +266,7 @@ type netInterfaceJSON struct {
|
||||
func (s *Server) handleDHCPInterfaces(w http.ResponseWriter, r *http.Request) {
|
||||
response := map[string]netInterfaceJSON{}
|
||||
|
||||
ifaces, err := util.GetValidNetInterfaces()
|
||||
ifaces, err := aghnet.GetValidNetInterfaces()
|
||||
if err != nil {
|
||||
httpError(r, w, http.StatusInternalServerError, "Couldn't get interfaces: %s", err)
|
||||
return
|
||||
@@ -317,7 +316,7 @@ func (s *Server) handleDHCPInterfaces(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
if len(jsonIface.Addrs4)+len(jsonIface.Addrs6) != 0 {
|
||||
jsonIface.GatewayIP = sysutil.GatewayIP(iface.Name)
|
||||
jsonIface.GatewayIP = aghnet.GatewayIP(iface.Name)
|
||||
response[iface.Name] = jsonIface
|
||||
}
|
||||
}
|
||||
@@ -397,13 +396,13 @@ func (s *Server) handleDHCPFindActiveServer(w http.ResponseWriter, r *http.Reque
|
||||
|
||||
found4, err4 := CheckIfOtherDHCPServersPresentV4(interfaceName)
|
||||
|
||||
isStaticIP, err := sysutil.IfaceHasStaticIP(interfaceName)
|
||||
isStaticIP, err := aghnet.IfaceHasStaticIP(interfaceName)
|
||||
if err != nil {
|
||||
result.V4.StaticIP.Static = "error"
|
||||
result.V4.StaticIP.Error = err.Error()
|
||||
} else if !isStaticIP {
|
||||
result.V4.StaticIP.Static = "no"
|
||||
result.V4.StaticIP.IP = util.GetSubnet(interfaceName).String()
|
||||
result.V4.StaticIP.IP = aghnet.GetSubnet(interfaceName).String()
|
||||
}
|
||||
|
||||
if found4 {
|
||||
|
||||
Reference in New Issue
Block a user