]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
Update static routing script to actually add the routes.
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 5 Jul 2011 16:57:33 +0000 (18:57 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 5 Jul 2011 16:57:33 +0000 (18:57 +0200)
src/initscripts/init.d/static-routes

index 184f97d47e98609822d3174b344cb9dc01c7a781..970083c0d2d00177f1014f0dd5e95b4d51fbd2bd 100644 (file)
@@ -6,34 +6,62 @@
 
 function init_table() {
        # Check if table does already exist. If not we add it.
-       if (ip rule | grep -qeE static >/dev/null 2>&1); then
+       if (ip rule | grep -q "static" >/dev/null 2>&1); then
                return
        fi
 
        ip rule add table static
 }
 
+function create_all_routes() {
+       local file=${1}
+       shift
+
+       # Remote all routes.
+       ip route flush table static >/dev/null 2>&1
+
+       local status
+       local network
+       local gateway
+       local remark
+
+       # Read all routes from the configuration file and add the enabled ones
+       # immediately.
+       while IFS=, read status network gateway remark; do
+               [ "${status}" = "on" ] || continue
+
+               if [ -z "${network}" -o -z "${gateway}" ]; then
+                       # Silently skipping invalid routes.
+                       continue
+               fi
+
+               ip route add ${network} via ${gateway} table static
+       done < ${file}
+}
+
+CONFIGFILE="/var/ipfire/main/routing"
 
 case "${1}" in
        start)
-               boot_mesg "Adding static routes..."
+               boot_mesg "Adding static routes..."
 
                # First, initialize the table
-                init_table
+               init_table
 
-               ### ADD ALL ROUTES
+               # Add all routes
+               create_all_routes ${CONFIGFILE}
 
                evaluate_retval
-                ;;
+               ;;
 
-        stop)
-               boot_mesg "Removing static routes..."
-                ip route flush table static >/dev/null 2>&1
+       stop)
+               boot_mesg "Removing static routes..."
+               ip route flush table static >/dev/null 2>&1
                evaluate_retval
-                ;;
+               ;;
 
-        *)
-               echo "Usage: ${0} {start|stop}"
-                       exit 1
-                ;;
+       *)
+               echo "Usage: ${0} {start|stop}"
+               exit 1
+               ;;
 esac