Skip to content

Commit

Permalink
try both ip and interface in client_up and client_down
Browse files Browse the repository at this point in the history
  • Loading branch information
clowwindy committed Oct 6, 2014
1 parent 7b4d273 commit 15c7855
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
14 changes: 8 additions & 6 deletions samples/client_down.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ iptables -D FORWARD -i $intf -o eth0 -m state --state RELATED,ESTABLISHED -j ACC
iptables -D FORWARD -i eth0 -o $intf -j ACCEPT

# get old gateway
echo reading old gateway from /tmp/old_gw
old_gw=`cat /tmp/old_gw` || ( echo "can not read gateway, check up.sh" && exit 1 )
rm /tmp/old_gw
echo reading old gateway from /tmp/old_gw_intf
old_gw_intf=`cat /tmp/old_gw_intf` || ( echo "can not read gateway, check up.sh" && exit 1 )
old_gw_ip=`cat /tmp/old_gw_ip` || ( echo "can not read gateway, check up.sh" && exit 1 )
rm /tmp/old_gw_intf
rm /tmp/old_gw_ip

# change routing table
echo changing default route
route del $server $old_gw
route del $server $old_gw_intf
route del default
route add default $old_gw
echo default route changed to $old_gw
route add default gw $old_gw_ip || route add default $old_gw_$intf
echo default route changed to $old_gw_intf

echo $0 done
16 changes: 9 additions & 7 deletions samples/client_up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,23 @@ iptables -A FORWARD -i eth0 -o $intf -j ACCEPT

# get current gateway
echo reading old gateway from route table
old_gw=`ip route show | grep '^default' | sed -e 's/.* dev \([^ ]*\).*/\1/'`
old_gw_intf=`ip route show | grep '^default' | sed -e 's/.* dev \([^ ]*\).*/\1/'`
old_gw_ip=`ip route show | grep '^default' | sed -e 's/.* via \([^ ]*\).*/\1/'`

# if current gateway is tun, it indicates that our gateway is already changed
# read from saved file
if [ $old_gw == "$intf" ]; then
echo reading old gateway from /tmp/old_gw
old_gw=`cat /tmp/old_gw` || ( echo "can not read gateway, check up.sh" && exit 1 )
if [ $old_gw_intf == "$intf" ]; then
echo reading old gateway from /tmp/old_gw_intf
old_gw_intf=`cat /tmp/old_gw_intf` || ( echo "can not read gateway, check up.sh" && exit 1 )
fi

echo saving old gateway to /tmp/old_gw
echo $old_gw > /tmp/old_gw
echo saving old gateway to /tmp/old_gw_intf
echo $old_gw_intf > /tmp/old_gw_intf
echo $old_gw_ip > /tmp/old_gw_ip

# change routing table
echo changing default route
route add $server $old_gw
route add $server gw $old_gw_ip || route add $server $old_gw_intf
route del default
route add default gw 10.7.0.1
echo default route changed to 10.7.0.1
Expand Down

0 comments on commit 15c7855

Please sign in to comment.