]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
Merge branch 'static-routing' into next
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 6 Jul 2011 17:38:29 +0000 (19:38 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 6 Jul 2011 17:38:29 +0000 (19:38 +0200)
config/rootfiles/common/misc-progs
lfs/iproute2
src/initscripts/init.d/static-routes [new file with mode: 0644]
src/misc-progs/Makefile
src/misc-progs/rebuildroutes.c [new file with mode: 0644]

index 6e5d7caec192ef14668720b40f7fbf9f62ea7745..adab51bc1eea62f39c70c0e8101a43476534b5ed 100644 (file)
@@ -18,6 +18,7 @@ usr/local/bin/outgoingfwctrl
 usr/local/bin/pakfire
 usr/local/bin/qosctrl
 usr/local/bin/rebuildhosts
+usr/local/bin/rebuildroutes
 usr/local/bin/redctrl
 #usr/local/bin/sambactrl
 usr/local/bin/setaliases
index 3cc684483b711da7df627a2e4c4e90171e81cb56..50ccf40df3014209153c13f5460aaca6770595b6 100644 (file)
@@ -76,5 +76,9 @@ $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
        cd $(DIR_APP) && make $(MAKETUNING) SBINDIR=/sbin
        cd $(DIR_APP) && make SBINDIR=/sbin install
        cd $(DIR_APP) && mv -v /sbin/arpd /usr/sbin
+
+       # Add table for static routing
+       echo "200       static" >> /etc/iproute2/rt_tables
+
        @rm -rf $(DIR_APP)
        @$(POSTBUILD)
diff --git a/src/initscripts/init.d/static-routes b/src/initscripts/init.d/static-routes
new file mode 100644 (file)
index 0000000..970083c
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/bash
+
+. /etc/sysconfig/rc
+. ${rc_functions}
+
+
+function init_table() {
+       # Check if table does already exist. If not we add it.
+       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..."
+
+               # First, initialize the table
+               init_table
+
+               # Add all routes
+               create_all_routes ${CONFIGFILE}
+
+               evaluate_retval
+               ;;
+
+       stop)
+               boot_mesg "Removing static routes..."
+               ip route flush table static >/dev/null 2>&1
+               evaluate_retval
+               ;;
+
+       *)
+               echo "Usage: ${0} {start|stop}"
+               exit 1
+               ;;
+esac
index 348f91c7437111fe42b03edf77fd4bb3cf6248f5..9f1e3f0006d16b3dac3ac93e8bc95af8fbd2c191 100644 (file)
@@ -32,7 +32,7 @@ SUID_PROGS = setdmzholes setportfw setxtaccess \
        wirelessctrl getipstat getiptstate qosctrl launch-ether-wake \
        redctrl syslogdctrl extrahdctrl sambactrl upnpctrl tripwirectrl \
        smartctrl clamavctrl addonctrl pakfire mpfirectrl wlanapctrl \
-       setaliases urlfilterctrl updxlratorctrl fireinfoctrl
+       setaliases urlfilterctrl updxlratorctrl fireinfoctrl rebuildroutes
 SUID_UPDX = updxsetperms
 
 install : all
@@ -158,3 +158,5 @@ updxsetperms: updxsetperms.c setuid.o ../install+setup/libsmooth/varval.o
 fireinfoctrl: fireinfoctrl.c setuid.o ../install+setup/libsmooth/varval.o
        $(COMPILE) -I../install+setup/libsmooth/ fireinfoctrl.c setuid.o ../install+setup/libsmooth/varval.o -o $@
 
+rebuildroutes: rebuildroutes.c setuid.o ../install+setup/libsmooth/varval.o
+       $(COMPILE) -I../install+setup/libsmooth/ rebuildroutes.c setuid.o ../install+setup/libsmooth/varval.o -o $@
diff --git a/src/misc-progs/rebuildroutes.c b/src/misc-progs/rebuildroutes.c
new file mode 100644 (file)
index 0000000..3655692
--- /dev/null
@@ -0,0 +1,17 @@
+/* IPFire helper program - rebuildroutes
+ *
+ * This program is distributed under the terms of the GNU General Public
+ * Licence.  See the file COPYING for details.
+ */
+
+#include "libsmooth.h"
+#include "setuid.h"
+
+int main(int argc, char *argv[]) {
+       if (!(initsetuid()))
+               exit(1);
+
+       safe_system("/etc/init.d/static-routes start >/dev/null 2>&1");
+
+       return 0;
+}