From e39f75f404ccea2b47f9d742c3fa4da29fdc6cc0 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 23 May 2023 09:03:32 +0200 Subject: network: fix ip rule to also work in the global section When no instance is specified we still want the ip rules to work. Unfortunately they were placed only in the section specific to instances. Let's move them and add some comments to avoid this mistake in the future. --- sbin/init.d/network | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/sbin/init.d/network b/sbin/init.d/network index ecf5937..5edfc21 100755 --- a/sbin/init.d/network +++ b/sbin/init.d/network @@ -410,6 +410,7 @@ function do_start { local arg if [ -z "$instname" ]; then + # here we have no instance, it's the generic section echo "# Starting $svcname ..." arg=0 while [ $arg -lt ${#opt_modprobe[*]} ]; do @@ -456,6 +457,14 @@ function do_start { fi arg=$[$arg+1] done + + arg=0 + while [ $arg -lt $rule_idx ]; do + local args=${rule_list[$arg]} + ip rule add ${args[*]} + arg=$[$arg+1] + done + arg=0 while [ $arg -lt $route_idx ]; do local dest gw @@ -468,6 +477,14 @@ function do_start { fi arg=$[$arg+1] done + + arg=0 + while [ $arg -lt $rule6_idx ]; do + local args=${rule6_list[$arg]} + ip -6 rule add ${args[*]} + arg=$[$arg+1] + done + arg=0 while [ $arg -lt $route6_idx ]; do local dest gw @@ -484,6 +501,10 @@ function do_start { return $? fi + # + # below we necessarily have an instance + # + if [ "$opt_shutdown" = 1 ]; then return 0 fi @@ -842,7 +863,7 @@ function do_start { arg=0 while [ $arg -lt $rule_idx ]; do local args=${rule_list[$arg]} - ip rule add ${instname:+iif $instname} ${args[*]} + ip rule add iif $instname ${args[*]} arg=$[$arg+1] done @@ -891,7 +912,7 @@ function do_start { arg=0 while [ $arg -lt $rule6_idx ]; do local args=${rule6_list[$arg]} - ip -6 rule add ${instname:+iif $instname} ${args[*]} + ip -6 rule add iif $instname ${args[*]} arg=$[$arg+1] done -- 2.35.3