#!/bin/sh

DEV_GW=vlan1
DEV_TUN=tun0

if ! test -d /etc/iproute2; then mkdir /etc/iproute2; fi
echo -e "255     local\n254     main\n253     default\n21      T2\n20      T1\n0       unspec">/etc/iproute2/rt_tables
GW=`ip route show|grep default|cut -d ' ' -f3`
IP=`ifconfig $DEV_GW|grep inet|cut -d ':' -f2|cut -d ' ' -f1`
TUN_GW=`ifconfig $DEV_TUN|grep inet|cut -d ':' -f3|cut -d ' ' -f1`
TUN_IP=`ifconfig $DEV_TUN|grep inet|cut -d ':' -f2|cut -d ' ' -f1`
ip route add default via $GW table T1
ip route add default via $TUN_GW table T2
ip rule add from $IP table T1
ip rule add from $TUN_IP table T2


