From 10f03b7527e0974a085aba8aeb4192e24b8ea19b Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Fri, 12 Feb 2021 16:40:34 +0300 Subject: [PATCH] Pull request: dhcpd: assume static ip on eperm Merge in DNS/adguard-home from 2667-eperm-dhcp to master Updates #2667. Squashed commit of the following: commit 7fad607ae0ae75419005707ee58312bc64fe78c5 Author: Ainar Garipov Date: Fri Feb 12 16:27:59 2021 +0300 dhcpd: assume static ip on eperm --- CHANGELOG.md | 3 +++ internal/dhcpd/{dhcphttp.go => http.go} | 16 +++++++++++++++- .../dhcpd/{dhcphttp_test.go => http_test.go} | 0 3 files changed, 18 insertions(+), 1 deletion(-) rename internal/dhcpd/{dhcphttp.go => http.go} (95%) rename internal/dhcpd/{dhcphttp_test.go => http_test.go} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 097f5c46..23edf804 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ and this project adheres to ### Changed +- "Permission denied" errors when checking if the machine has a static IP no + longer prevent the DHCP server from starting ([#2667]). - The server name sent by clients of TLS APIs is not only checked when `strict_sni_check` is enabled ([#2664]). - HTTP API request body size limit for the `/control/access/set` API is @@ -40,6 +42,7 @@ and this project adheres to [#2663]: https://github.com/AdguardTeam/AdGuardHome/issues/2663 [#2664]: https://github.com/AdguardTeam/AdGuardHome/issues/2664 [#2666]: https://github.com/AdguardTeam/AdGuardHome/issues/2666 +[#2667]: https://github.com/AdguardTeam/AdGuardHome/issues/2667 diff --git a/internal/dhcpd/dhcphttp.go b/internal/dhcpd/http.go similarity index 95% rename from internal/dhcpd/dhcphttp.go rename to internal/dhcpd/http.go index 0a182cf0..de155c5c 100644 --- a/internal/dhcpd/dhcphttp.go +++ b/internal/dhcpd/http.go @@ -2,6 +2,7 @@ package dhcpd import ( "encoding/json" + "errors" "fmt" "io/ioutil" "net" @@ -94,7 +95,20 @@ func (s *Server) enableDHCP(ifaceName string) (code int, err error) { var hasStaticIP bool hasStaticIP, err = sysutil.IfaceHasStaticIP(ifaceName) if err != nil { - return http.StatusInternalServerError, fmt.Errorf("checking static ip: %w", err) + // ErrPermission may happen here on Linux systems where AdGuard + // Home is installed using Snap. That doesn't necessarily mean + // that the machine doesn't have a static IP, so we can assume + // that it has and go on. If the machine doesn't, we'll get an + // error later. + // + // See https://github.com/AdguardTeam/AdGuardHome/issues/2667. + if errors.Is(err, os.ErrPermission) { + log.Info("error while checking static ip: %s; "+ + "assuming machine has static ip and going on", err) + hasStaticIP = true + } else { + return http.StatusInternalServerError, fmt.Errorf("checking static ip: %w", err) + } } if !hasStaticIP { diff --git a/internal/dhcpd/dhcphttp_test.go b/internal/dhcpd/http_test.go similarity index 100% rename from internal/dhcpd/dhcphttp_test.go rename to internal/dhcpd/http_test.go