#!/bin/sh # # /etc/rc.d/rc.routing.table # Version: 20011021-1 # # Leest route tabel uit de files in $ROUTEDIR en stelt # stelt de routes vervolgens in. # # 20010227-1 First version # # 20010307-1 Commentaar in route-files is nu mogelijk. # Tekst na #-teken wordt genegeerd. # # 20010517-1 Verwijdering van bestaande routes zodat dit script periodiek # via cron kan worden uitgevoerd. # # 20010815-1 Gateway adress in combinatie met netwerk/mask is nu mogelijk. # # 20010815-2 improve debugging (write to log-file) # # 20010817-1 resolve bug in routing of host via GW via tunnel. # # 20011021-1 routering voor gebruikers van pi1shb toegevoegd. # ROUTEDIR=/etc/routes LOGDIR=/var/log/routes LOGFILE=$LOGDIR/`date +%y%m%d`.log GWLAP1k2="44.137.24.103" GWLAP1k2best="44.137.24.7" GWLAP4k8=$GWLAP1k2 GWLAP4k8best="44.137.24.7" GWLAP9k6=$GWLAP1k2 GWLAP19k2= GWLAP76k8=$GWLAP1k2 GWLAP23cm=$GWLAP1k2 GWLAP13cm="44.137.27.126" INTF1k2="scc0" INTF1k2best= INTF4k8="scc1" INTF4k8best= INTF9k6="scc2" INTF19k2="scc4" INTF76k8="scc1" INTF23cm="scc3" INTF13cm="dmascc0" LAPS="1k2 4k8 9k6 19k2 76k8 23cm 4k8best 13cm" # 1k2best, en nog toe voegen. TUNNEL=no # Alleen activeren als deze host zelf tunnelt ############################################################ # # # De regels hieronder hoeven niet te worden aangepast. # # # ############################################################ # Eerst kijken of de log directory en file bestaan, en indien nodig deze aanmaken. if [ ! -d $LOGDIR ] ; then /bin/mkdir -p $LOGDIR fi gunzip $LOGFILE 2>/dev/null echo "# # # # # # # # # # # # # # # # # # # # # # # # # # # # # #" >> $LOGFILE date >> $LOGFILE # Quick & Dirty manier om te kijken of de -v optie (verbose) is meegegeven # op de command-line. if [ ! -z $1 ] ; then if [ $1 = "-v" ] || [ $1 = "--verbose" ] ; then VERBOSE=1 fi else VERBOSE="" fi MYIPADDR=`/sbin/ifconfig eth0 | grep inet | cut -d : -f 2 | cut -d " " -f 1` # zet de Ethernet-variabele, maar filter mijzelf uit de lijst. Ethernet=`cat $ROUTEDIR/ethernet | cut -d "#" -f 1 | grep -vw $MYIPADDR` for HOST in $Ethernet do if ! /sbin/route add $HOST window 4096 eth0 2>/dev/null; then [ $VERBOSE ] && echo -n "Route for $HOST exists, removing old route first. " echo "/sbin/route del $HOST" >> $LOGFILE /sbin/route del $HOST 1>> $LOGFILE 2>> $LOGFILE [ $VERBOSE ] && echo "Adding route for $HOST window 4096 via eth0" echo "/sbin/route add $HOST window 4096 eth0" >> $LOGFILE /sbin/route add $HOST window 4096 eth0 1>> $LOGFILE 2>> $LOGFILE fi done ################################################## # HostViaGateway function # # # # inputs: $HOST $GW $VERBOSE $LOGFILE # # # ################################################## HostViaGateway () { if ! /sbin/route add $HOST gw $GW 2>/dev/null; then [ $VERBOSE ] && echo -n "Route for $HOST exists, removing old route first. " echo "/sbin/route del $HOST" >> $LOGFILE /sbin/route del $HOST 1>> $LOGFILE 2>> $LOGFILE # and again, just in case there were multiple routes set. /sbin/route del $HOST 1> /dev/null 2> /dev/null fi [ $VERBOSE ] && echo "Adding route for $HOST via $GW" echo "/sbin/route add $HOST gw $GW" >> $LOGFILE /sbin/route add $HOST gw $GW 1>> $LOGFILE 2>> $LOGFILE return 0 } ################################################## # NetViaGateway function # # # # inputs: $HOST $GW $VERBOSE $LOGFILE # # # ################################################## NetViaGateway () { if ! /sbin/route add -net $HOST gw $GW 2>/dev/null; then [ $VERBOSE ] && echo -n "Route for $HOST exists, removing old route first. " echo "/sbin/route del -net $HOST" >> $LOGFILE /sbin/route del -net $HOST 1>> $LOGFILE 2>> $LOGFILE # and again, just in case there were multiple routes set. /sbin/route del -net $HOST 1> /dev/null 2> /dev/null fi [ $VERBOSE ] && echo "Adding route for $HOST via $GW" echo "/sbin/route add -net $HOST gw $GW" >> $LOGFILE /sbin/route add -net $HOST gw $GW 1>> $LOGFILE 2>> $LOGFILE return 0 } ################################################## # SetRoute function # # # # inputs: $HOST $GW $INTF $MYIPADDR $VERBOSE # # # ################################################## SetRoute () { NETADDR=`echo $HOST | grep /` GWADDR=`echo $HOST | grep ">"` ### Routing of (sub-)network addres via a gateway ### if [ "$GWADDR" ] && [ "$NETADDR" ]; then [ $VERBOSE ] && echo -e "\nRouting of (sub-)network addres via a gateway..." if [ "$GW" = "$MYIPADDR" ]; then [ $VERBOSE ] && echo GW is MYIPADDR GW=`echo $HOST | cut -d ">" -f 2` # replace GW with the real gateway. HOST=`echo $HOST | cut -d ">" -f 1` NetViaGateway else HOST=`echo $HOST | cut -d ">" -f 1` NetViaGateway fi return 0 fi ### Routing of hosts via a gateway ### if [ $GWADDR ]; then [ $VERBOSE ] && echo -e "\nRouting of hosts via a gateway..." if [ "$GW" = "$MYIPADDR" ]; then [ $VERBOSE ] && echo GW is MYIPADDR GW=`echo $HOST | cut -d ">" -f 2` # replace GW with the real gateway. HOST=`echo $HOST | cut -d ">" -f 1` HostViaGateway else HOST=`echo $HOST | cut -d ">" -f 1` HostViaGateway fi return 0 fi if [ $NETADDR ]; then [ $VERBOSE ] && echo -e "\nRouting of (sub-)network..." if [ "$GW" = "$MYIPADDR" ]; then if ! /sbin/route add -net $HOST $INTF 2>/dev/null; then [ $VERBOSE ] && echo -n "Route for $HOST exists, removing old route first. " echo "/sbin/route del -net $HOST" >> $LOGFILE /sbin/route del -net $HOST 1>> $LOGFILE 2>> $LOGFILE [ $VERBOSE ] && echo "Adding route for $HOST via $GW" echo "/sbin/route add -net $HOST $INTF" >> $LOGFILE /sbin/route add -net $HOST $INTF 1>> $LOGFILE 2>> $LOGFILE fi else if ! /sbin/route add -net $HOST gw $GW 2>/dev/null; then [ $VERBOSE ] && echo -n "Route for $HOST exists, removing old route first. " echo "/sbin/route del -net $HOST" >> $LOGFILE /sbin/route del -net $HOST 1>> $LOGFILE 2>> $LOGFILE [ $VERBOSE ] && echo "Adding route for $HOST via $GW" echo "/sbin/route add -net $HOST gw $GW" >> $LOGFILE /sbin/route add -net $HOST gw $GW 1>> $LOGFILE 2>> $LOGFILE fi fi return 0 fi ### Routing of hosts ### [ $VERBOSE ] && echo -e "\nRouting of hosts..." if [ "$GW" = "$MYIPADDR" ]; then [ $VERBOSE ] && echo GW is MYIPADDR HOST=`echo $HOST | cut -d ">" -f 1` if ! /sbin/route add $HOST $INTF 2>/dev/null; then [ $VERBOSE ] && echo -n "Route for $HOST exists, removing old route first. " echo "/sbin/route del $HOST" >> $LOGFILE /sbin/route del $HOST 1>> $LOGFILE 2>> $LOGFILE fi [ $VERBOSE ] && echo "Adding route for $HOST via $INTF" echo "/sbin/route add $HOST $INTF" >> $LOGFILE /sbin/route add $HOST $INTF 1>> $LOGFILE 2>> $LOGFILE else HOST=`echo $HOST | cut -d ">" -f 1` HostViaGateway fi return 0 } # SetRoute procedure ################################################## for LAP in $LAPS do for HOST in `cat $ROUTEDIR/lap$LAP | cut -d "#" -f 1` do eval GW=\$GWLAP$LAP eval INTF=\$INTF$LAP SetRoute done done if [ $TUNNEL = "y" ] || [ $TUNNEL = "Y" ] || [ $TUNNEL = "yes" ]; then /sbin/route add -net 0.0.0.0 netmask 0.0.0.0 metric 128 tunl0 for HOST in `cat $ROUTEDIR/tunnel | cut -d "#" -f 1` do GW="$MYIPADDR" INTF=tunl0 SetRoute done fi ##################################### ### routes voor gebruikers pi1shb ### ##################################### if [ $MYIPADDR != "44.137.24.40" ]; then for HOST in `cat $ROUTEDIR/pi1shb | cut -d "#" -f 1` do GW="pi1ehv" HostViaGateway done fi sleep 1 gzip $LOGFILE