File: reroute

package info (click to toggle)
vtun 3.0.4-2
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,520 kB
  • sloc: ansic: 4,180; sh: 2,814; yacc: 536; lex: 195; makefile: 139
file content (63 lines) | stat: -rwxr-xr-x 1,276 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
#
# Maxim Krasnyansky <max_mk@yahoo.com>
# $Id: reroute,v 1.3.2.1 2007/06/29 05:27:18 mtbishop Exp $
#
IP=/sbin/ip

if [ $# -ne 3 ]; then
   echo "Usage: reroute option Source_IP Destination_IP"
   echo "Options:"
   echo "   -m - Move route Source_IP -> Destination_IP to table 100."
   echo "        Configure source based routing." 

   echo "   -r - Restore route Source_IP -> Destination_IP to default table."
   echo "        Delete source based routing."
   exit 1;
fi

MODE=$1
IP_S=$2
IP_D=$3

# Get original route
ROUTE=`$IP route get $IP_D from $IP_S | grep dev`

# Parse route 
set - $ROUTE
while [ "$1" != "" ]; do
    if [ "$1" = "src" ]; then
	shift
	O_SRC=$1
    fi
    if [ "$1" = "dev" ]; then
	shift
	O_DEV=$1
    fi
    if [ "$1" = "via" ]; then
	shift
	O_GW=$1
    fi
    shift
done

# Flush all routes, rules and cache for that IP 
$IP route flush $IP_D table all >/dev/null 2>&1
$IP rule del from $IP_S to $IP_D >/dev/null 2>&1

case $MODE in
   -m)
	# Add route via orig device to table 100
	$IP route add $ROUTE table 100 >/dev/null 2>&1

	# Add source based routing 
	$IP rule add from $IP_S to $IP_D table 100 >/dev/null 2>&1
	;;

   -r)
	# Add route via orig device to defaul table
	$IP route add $ROUTE >/dev/null 2>&1
	;;
esac

exit 0