#!/bin/sh # copyright 2003 Alexey Toptygin # # chkconfig: 2345 46 69 # description: prepares static policy routes # # customized for CHANGEME . /etc/init.d/functions # list of all custom tables you use (remember to update rt_tables) TABLES='' if [ ! -x /sbin/ip ]; then { echo "iproute: could not find /sbin/ip !!!"; exit 1; } fi # check that the needed tables are known by iproute for i in $TABLES; do { if [ " $i" != " main" ]; then { foo=`grep -v "^\w*#" /etc/iproute2/rt_tables | grep -c $i` if [ $foo != 1 ]; then { echo "iproute: could not find table $i, quitting" exit 1 } fi } fi } done if [ `id -u` -ne 0 ]; then { echo "iproute: must be superuser" exit 1 } fi start() { rules=`ip rule ls | egrep -v "^(0|32766|32767):" | cut -d ':' -f 1` echo -n "Removing user defined rules: " error= for i in $rules; do { ip rule del prio $i || error=1 } done [ $error ] && failure "Removing user defined rules: " || \ success "Removing user defined rules: " echo echo -n "Flushing user defined route tables: " error= for i in $TABLES; do { ip route flush table $i || error=1 } done [ $error ] && failure "Flushing user defined route tables: " || \ success "Flushing user defined route tables: " echo echo -n "Adding rules and routes: " # add rules and routes here like so: ip route add default via 10.0.0.1 dev eth0 && \ success "Adding rules and routes: " || \ failure "Adding rules and routes: " echo echo -n "Flushing route cache: " ip route flush cache && \ success "Flushing route cache: " || \ failure "Flushing route cache: " echo } stop() { rules=`ip rule ls | egrep -v "^(0|32766|32767):" | cut -d ':' -f 1` echo -n "Removing user defined rules: " error= for i in $rules; do { ip rule del prio $i || error=1 } done [ $error ] && failure "Removing user defined rules: " || \ success "Removing user defined rules: " echo echo -n "Flushing user defined route tables: " error= for i in $TABLES; do { ip route flush table $i || error=1 } done [ $error ] && failure "Flushing user defined route tables: " || \ success "Flushing user defined route tables: " echo echo -n "Flushing route cache: " ip route flush cache && \ success "Flushing route cache: " || \ failure "Flushing route cache: " echo } status() { echo " Rules:" ip rule ls echo echo " Table main:" ip route ls echo for i in $TABLES; do { echo " Table $i:" ip route ls table $i echo } done } case "$1" in start) start;; stop) stop;; restart) start;; status) status;; *) echo "Usage: $0 {start|stop|restart|status}";; esac exit 0