From 8a3d5f046c8b54017c55f0f35fdfa9f44a05794b Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Wed, 3 Aug 2022 20:36:20 +0300 Subject: [PATCH] Pull request: 4670-invalid-arg-cap-check Updates #4670. Squashed commit of the following: commit 9c32739eb92ef57c78a4dc3ec3c0f280aebf7182 Author: Ainar Garipov Date: Wed Aug 3 20:04:54 2022 +0300 aghnet: imp port check for older linuxes --- CHANGELOG.md | 6 ++++++ internal/aghnet/net_linux.go | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cc43b12..8183fd68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,13 @@ and this project adheres to - Go 1.18 support. v0.109.0 will require at least Go 1.19 to build. +### Fixed + +- `invalid argument` errors during update checks on older Linux kernels + ([#4670]). + [#2993]: https://github.com/AdguardTeam/AdGuardHome/issues/2993 +[#4670]: https://github.com/AdguardTeam/AdGuardHome/issues/4670 [ddr-draft]: https://datatracker.ietf.org/doc/html/draft-ietf-add-ddr-08 diff --git a/internal/aghnet/net_linux.go b/internal/aghnet/net_linux.go index 148abe1f..4be8835c 100644 --- a/internal/aghnet/net_linux.go +++ b/internal/aghnet/net_linux.go @@ -13,6 +13,7 @@ import ( "github.com/AdguardTeam/AdGuardHome/internal/aghos" "github.com/AdguardTeam/golibs/errors" + "github.com/AdguardTeam/golibs/log" "github.com/AdguardTeam/golibs/stringutil" "github.com/google/renameio/maybe" "golang.org/x/sys/unix" @@ -22,17 +23,27 @@ import ( const dhcpcdConf = "etc/dhcpcd.conf" func canBindPrivilegedPorts() (can bool, err error) { - cnbs, err := unix.PrctlRetInt( + res, err := unix.PrctlRetInt( unix.PR_CAP_AMBIENT, unix.PR_CAP_AMBIENT_IS_SET, unix.CAP_NET_BIND_SERVICE, 0, 0, ) + if err != nil { + if errors.Is(err, unix.EINVAL) { + // Older versions of Linux kernel do not support this. Print a + // warning and check admin rights. + log.Info("warning: cannot check capability cap_net_bind_service: %s", err) + } else { + return false, err + } + } + // Don't check the error because it's always nil on Linux. adm, _ := aghos.HaveAdminRights() - return cnbs == 1 || adm, err + return res == 1 || adm, nil } // dhcpcdStaticConfig checks if interface is configured by /etc/dhcpcd.conf to