#!/bin/sh -e # # /etc/ppp/ip-up.d/99tunnel v0.03 -- ip-up snippet for tunnels # Adjusts default route to use the tunnel when connection comes up. # Makes sure tunneled packets use the old default route. # # Copyright (c)2005 by Christoph Sommer # # # Feel free to use however you like as long as # you leave these comments intact. # IPROUTE=/sbin/ip # skip this script if pppd's ipparam is not set to "tunnel" if [ ! "$PPP_IPPARAM" = "tunnel" ]; then exit 0 fi # check for "iproute" utilities if [ ! -x $IPROUTE ]; then echo 'This script needs the "iproute" utility suite' >&2 exit 1 fi # get old default route DEFROUTE=$($IPROUTE route show | grep "^default" | cut -c9-) if [ ! -n "$DEFROUTE" ]; then echo 'Could not determine default route' >&2 exit 1 fi # set route to tunnel endpoint via old default route $IPROUTE route replace $PPP_REMOTE $DEFROUTE # set new default route to go through the tunnel route add default gw $PPP_LOCAL # done exit 0