fix(install.sh): check the live sysctl value, not sysctl.conf text

Same fix as the upstream PR (#6105) review round: grepping
/etc/sysctl.conf for the setting name is unreliable -- many distros
split sysctl config across /etc/sysctl.d/*.conf, and /etc/sysctl.conf
can be a symlink into that directory, so the check can miss an
already-active setting or match a disabled/commented line, leaving
forwarding silently off either way. Query the live value via
`sysctl -n` instead. Applied to both the IPv6 and IPv4 checks.
This commit is contained in:
Kuzz007
2026-07-29 23:18:41 +03:00
parent d3da7abdf0
commit 1b07dadfb9
+9 -2
View File
@@ -188,10 +188,17 @@ install_ndppd() {
# internal/amneziawg/manager.go's defaultPostUpDown), so this is a belt-and-
# suspenders persistence step, not the only place it's set.
enable_ipv6_forwarding() {
if ! grep -q "net.ipv6.conf.all.forwarding" /etc/sysctl.conf 2>/dev/null; then
# Checking /etc/sysctl.conf by name is not reliable: many distros split
# sysctl settings across /etc/sysctl.d/*.conf, and /etc/sysctl.conf is
# sometimes just a symlink into that directory, so grep can miss an
# already-active setting (false negative -> harmless duplicate line) or
# match a disabled/commented one (false positive -> forwarding silently
# stays off). Querying the live value directly is accurate regardless of
# which file actually set it.
if [ "$(sysctl -n net.ipv6.conf.all.forwarding 2>/dev/null)" != "1" ]; then
echo "net.ipv6.conf.all.forwarding = 1" >> /etc/sysctl.conf
fi
if ! grep -q "net.ipv4.ip_forward" /etc/sysctl.conf 2>/dev/null; then
if [ "$(sysctl -n net.ipv4.ip_forward 2>/dev/null)" != "1" ]; then
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
fi
sysctl -p >/dev/null 2>&1 || true