#!/bin/bash

local_if='eth1'
local_ip='192.168.1.1'
local_net='192.168.1.0/24'
ps3='192.168.1.36'

comcast_if='eth0'
comcast_ip=$(ip addr show dev $comcast_if | awk '/inet / { print $2 }')
comcast_net=$(ipcalc -n $comast_ip | awk '/Network:/ { print $2 }')
comcast_gw=$(echo $comcast_net | sed 's/0\/[0-9][0-9]$/1/')

att_if='eth2'
att_ip=$(ip addr show dev $att_if | awk '/inet / { print $2 }')
att_net=$(ipcalc -n $att_ip | awk '/Network:/ { print $2 }')
att_gw=$(echo $att_net | sed 's/0\/[0-9][0-9]$/1/')

# comcast table
ip route add $comcast_net dev $comcast_if src $comcast_ip table COMCAST
ip route add default via $comcast_gw table COMCAST
ip route add $local_net dev $local_if table COMCAST
ip route add $att_net dev $att_if table COMCAST
ip route add 172.0.0.0/8 dev lo table COMCAST

# att table
ip route add $att_net dev $att_if src $att_ip table ATT
ip route add default via $att_gw table ATT
ip route add $local_net dev $local_if table ATT
ip route add $comcast_net dev $comcast_if table ATT
ip route add 172.0.0.0/8 dev lo table ATT

# main routing table
ip route add $comcast_net dev $comcast_if src $comcast_ip
ip route add $att_net dev $att_if src $att_ip
ip route add default scope global nexthop via $att_gw dev $att_if weight 1 \
    nexthop via $comcast_gw dev $comcast_if weight 1

# rules
ip rule add from $ps3 table ATT # ps3 "netflix" to att
ip rule add to 74.125.0.0/16 table ATT # direct youtube (google) to att
ip rule add to 172.16.0.0/24 table ATT # allow access to 2wire modem


