-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaws_routemon.sh
More file actions
executable file
·65 lines (54 loc) · 1.92 KB
/
aws_routemon.sh
File metadata and controls
executable file
·65 lines (54 loc) · 1.92 KB
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
64
65
#!/bin/bash
# Monitors route changes and sets the correct SA via setkey
us-east-1-via-41() {
#service setkey restart
setkey -c << EOF
spddelete 10.142.25.0/24 10.142.32.0/21 any -P out;
spddelete 10.142.32.0/21 10.142.25.0/24 any -P in ;
spdupdate 10.142.25.0/24 10.142.32.0/21 any -P out ipsec esp/tunnel/10.142.31.191-54.240.217.162/require;
spdupdate 10.142.32.0/21 10.142.25.0/24 any -P in ipsec esp/tunnel/54.240.217.162-10.142.31.191/require;
EOF
logger "aws-routemon: ran us-east-1-via-41"
}
us-east-1-via-45() {
#service setkey restart
setkey -c << EOF
spddelete 10.142.25.0/24 10.142.32.0/21 any -P out;
spddelete 10.142.32.0/21 10.142.25.0/24 any -P in ;
spdupdate 10.142.25.0/24 10.142.32.0/21 any -P out ipsec esp/tunnel/10.142.31.191-54.240.217.164/require;
spdupdate 10.142.32.0/21 10.142.25.0/24 any -P in ipsec esp/tunnel/54.240.217.164-10.142.31.191/require;
EOF
logger "aws-routemon: ran us-east-1-via-45"
}
declare -a actions
actions[0]="10.142.32.0/21 169.254.255.45 169.254.255.41 us-east-1-via-45 us-east-1-via-41"
#actions[1]="10.142.88.0/21 169.254.88.45 169.254.88.41 foo bar"
while :; do
ip monitor | \
while read net via gw rest; do
if [ "$via" != "via" ]; then
continue
fi
for action in "${actions[@]}"; do
data=($action)
network=${data[0]}
gw1=${data[1]}
gw2=${data[2]}
cmd1=${data[3]}
cmd2=${data[4]}
if [ "$net" = "$network" ]; then
logger "aws-routemon: route change, new gw: $gw for $network"
if [ "$gw" = "$gw1" ]; then
$cmd1
logger "aws-routemon: calling $cmd1"
elif [ "$gw" = "$gw2" ]; then
$cmd2
logger "aws-routemon: calling $cmd2"
else
echo "unknown gw"
fi
fi
done
done
sleep 1
done