#!/bin/sh

if [ $(cat /etc/iproute2/rt_tables | grep vpn | wc -l) -eq 0 ]; then
        echo "100     vpn" >> /etc/iproute2/rt_tables
fi

echo "------------------------------------------------------------------"
/sbin/ip route show
echo "------------------------------------------------------------------"

/sbin/ip rule | sed -n 's/.*\(from[ \t]*[0-9\.]*\).*vpn/\1/p' | while read RULE
do
	echo "remove old rule:  /sbin/ip rule del ${RULE}"
	/sbin/ip rule del ${RULE}
done

/sbin/ip route del 128.0.0.0/1 via ${route_vpn_gateway}
/sbin/ip route del 0.0.0.0/1 via ${route_vpn_gateway}

echo ip rule add from $ifconfig_local lookup vpn
/sbin/ip rule add from ${ifconfig_local} lookup vpn

# Add the route to direct all traffic using the the vpn routing table to the tunX interface
echo ip route add default dev ${dev} table vpn
/sbin/ip route add default dev ${dev} table vpn

/etc/rc.d/rc.transmission restart

exit 0
