summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBertrand Jacquin <beber@meleeweb.net>2009-05-01 22:04:19 +0200
committerBertrand Jacquin <beber@meleeweb.net>2009-05-01 22:04:19 +0200
commit7c1c859cdbb3565e62923beaab94958e93d6d0ba (patch)
treef6e0cc87e6a1a7465e74e7c1dc70b728767ca57a
parent* functions: small performance improvements (~5-10%) (diff)
downloadinit-scripts-7c1c859cdbb3565e62923beaab94958e93d6d0ba.tar.gz
network: Handle unreacheable/prohibit/local/etc iproute2 options.
For example, this can be implemented like ; service network ... ip route 10.0.0.0/8 unreachable ip route 169.254.0.0/16 unreachable Could be usefull to manage at low-level RFC 1918
-rwxr-xr-xsbin/init.d/network86
1 files changed, 66 insertions, 20 deletions
diff --git a/sbin/init.d/network b/sbin/init.d/network
index 01002a2..6457d56 100755
--- a/sbin/init.d/network
+++ b/sbin/init.d/network
@@ -209,13 +209,30 @@ function do_start {
arg=0
while [ $arg -lt $route_idx ]; do
local dest gw
+
+ if [ ${#route_list[$arg]} -lt 2 ] ; then
+ echo " ==> start $svcname : route ${route_list[$arg]} failed. Missing args."
+ arg=$[$arg+1]
+ continue
+ fi
+
dest=${route_list[$arg]%%[ ]*}
gw=${route_list[$arg]#*[ ]} # gw and potentially other ip args
- if [ -n "${gw##connected*}" ]; then
- ip route add $dest via $gw
- else
- ip route add $dest ${gw#connected}
- fi
+
+ case ${gw% *} in
+ unreachable|blackhole|prohibit|local)
+ ip route add ${gw% *} $dest
+ ;;
+ multicast|broadcast|throw)
+ echo " ==> start $svcname : route ${route_list[$arg]} failed. Not applicable."
+ ;;
+ connected|-)
+ ip route add $dest ${gw#connected}
+ ;;
+ *)
+ ip route add $dest via ${gw}
+ ;;
+ esac
arg=$[$arg+1]
done
echo " ==> start $svcname : Done."
@@ -424,13 +441,30 @@ function do_start {
arg=0
while [ $arg -lt $route_idx ]; do
local dest gw
+
+ if [ ${#route_list[$arg]} -lt 2 ] ; then
+ echo " ==> start $svcname : route ${route_list[$arg]} failed. Missing args."
+ arg=$[$arg+1]
+ continue
+ fi
+
dest=${route_list[$arg]%%[ ]*}
gw=${route_list[$arg]#*[ ]} # gw and potentially other ip args
- if [ -n "${gw##connected*}" ]; then
- ip route add $dest dev $instname via $gw
- else
- ip route add $dest dev $instname ${gw#connected}
- fi
+
+ case ${gw% *} in
+ multicast|broadcast|throw)
+ ip route add ${gw% *} $dest
+ ;;
+ unreachable|blackhole|prohibit|local)
+ echo " ==> start $svcname : route ${route_list[$arg]} failed. Not applicable."
+ ;;
+ connected|-)
+ ip route add $dest dev $instname ${gw#connected}
+ ;;
+ *)
+ ip route add $dest dev $instname via ${gw}
+ ;;
+ esac
arg=$[$arg+1]
done
echo " ==> start $svcname${instname:+[$instname]} : Done."
@@ -446,20 +480,11 @@ function do_status {
echo "Interface $instname is down."
return 1
fi
- #else
- # if ip route list | grep -q dev; then
- # echo "Network is up."
- # return 0
- # else
- # echo "Network is down."
- # return 1
- # fi
fi
REPLY=
return 0
}
-
function do_stop {
local svcname=$1
local instname=$2
@@ -488,7 +513,28 @@ function do_stop {
arg=0
while [ $arg -lt $route_idx ]; do
- ip route del ${route_list[$arg]} >/dev/null 2>&1
+ local dest gw
+
+ if [ ${#route_list[$arg]} -lt 2 ] ; then
+ echo " ==> start $svcname : route ${route_list[$arg]} failed. Missing args."
+ arg=$[$arg+1]
+ continue
+ fi
+
+ dest=${route_list[$arg]%%[ ]*}
+ gw=${route_list[$arg]#*[ ]} # gw and potentially other ip args
+
+ case ${gw% *} in
+ unreachable|blackhole|prohibit|local)
+ ip route del ${gw% *} $dest
+ ;;
+ multicast|broadcast|throw)
+ echo " ==> start $svcname : route ${route_list[$arg]} failed. Not applicable."
+ ;;
+ *)
+ ip route del ${route_list[$arg]}
+ ;;
+ esac
arg=$[$arg+1]
done
return $?