ext1_if=eth0
ext2_if=eth1
int1_if=eth2

ext1_ip=`/usr/local/bin/get_ip_by_eth $ext1_if`
ext2_ip=`/usr/local/bin/get_ip_by_eth $ext2_if`
ext1_net=`/usr/local/bin/get_net_by_eth $ext1_if`
ext2_net=`/usr/local/bin/get_net_by_eth $est2_if`

ext1_table=ext1
ext2_table=ext2

# setup our two basic tables
echo basic tables
ip route add $ext1_net dev $ext1_if src $ext1_ip table $ext1_table
ip route add default via $ext1_ip table $ext1_table
ip route add $ext2_net dev $ext2_if src $ext2_ip table $ext2_table
ip route add default via $ext2_ip table $ext2_table

# some crossrouting stuff
echo crossrouting stuff
ip route add $int1_net dev $int1_if table $ext1_table
ip route add $ext2_net dev $ext2_if table $ext1_table
ip route add 127.0.0.0/8 dev lo table $ext1_table
ip route add $int1_net dev $int1_if table $ext2_table
ip route add $ext1_net dev $ext1_if table $ext2_table
ip route add 127.0.0.0/8 dev lo table $ext2_table

# send packets in each subnet directly there
echo subnet
ip route add $ext1_net dev $ext1_if src $ext1_ip
ip route add $ext2_net dev $ext2_if src $ext2_ip

# alright, now the actual routing rules, which table to use
echo routing rules
ip rule add from $ext1_ip table $ext1_table
ip rule add from $ext2_ip table $ext2_table

# set the MTU, and set us up to multiroute
# ext1 is our wired link, so use that if you can:
#ip route add default scope global \
#    nexthop via $ext1_ip dev $ext1_if weight 1\
#    nexthop via $ext2_ip dev $ext2_if weight 0

echo set default
ip route add default via $ext1_ip metric 1

ip route flush cache
