From a430e8e22b401c6a27e0e45cd6f84bb94741574e Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 14 Mar 2018 19:20:30 +0100 Subject: scripts/ipforward: better test for ipv4/ipv6 sysctls If ipv6 is disabled, the ipforward script may fail and/or show errors. Better test that entries exist before touching them. --- sbin/init.d/ipforward | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/sbin/init.d/ipforward b/sbin/init.d/ipforward index 478d0fb..7fed9a7 100644 --- a/sbin/init.d/ipforward +++ b/sbin/init.d/ipforward @@ -30,16 +30,26 @@ function is_loaded { # Enables ip forwarding. Returns 0 on success. function enable_forwarding { - echo 1 > /proc/sys/net/ipv4/ip_forward 2>/dev/null - [ $? -ne 0 ] && return $? - echo 1 > /proc/sys/net/ipv6/conf/all/forwarding 2>/dev/null + if [ -e /proc/sys/net/ipv4/ip_forward ]; then + echo 1 > /proc/sys/net/ipv4/ip_forward + [ $? -eq 0 ] || return $? + fi + if [ -e /proc/sys/net/ipv6/conf/all/forwarding ]; then + echo 1 > /proc/sys/net/ipv6/conf/all/forwarding + [ $? -eq 0 ] || return $? + fi } # Disables ip forwarding. Returns 0 on success. function disable_forwarding { - echo 0 > /proc/sys/net/ipv4/ip_forward 2>/dev/null - [ $? -ne 0 ] && return $? - echo 0 > /proc/sys/net/ipv6/conf/all/forwarding 2>/dev/null + if [ -e /proc/sys/net/ipv4/ip_forward ]; then + echo 0 > /proc/sys/net/ipv4/ip_forward + [ $? -eq 0 ] || return $? + fi + if [ -e /proc/sys/net/ipv6/conf/all/forwarding ]; then + echo 0 > /proc/sys/net/ipv6/conf/all/forwarding + [ $? -eq 0 ] || return $? + fi } # checks wether the firewall modules are loaded -- 2.28.0