-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathvrrp_switch.sh
executable file
·71 lines (55 loc) · 1.53 KB
/
vrrp_switch.sh
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
66
67
68
69
70
71
#!/bin/sh
state=$1
vrid=$2
ifname=$3
priority=$4
adv_int=$5
naddr=$6
family=$7
ips=$8
echo "state\t\t$state
vrid\t\t$vrid
ifname\t\t$ifname
priority\t$priority
adv_int\t\t$adv_int
naddr\t\t$naddr
ips\t\t$ips" > /tmp/state.vrrp_${vrid}_${ifname}
interface=${ifname}_${vrid}
echo $ips
case "$state" in
"init" )
# adjust sysctl
sysctl -w net.ipv4.conf.all.rp_filter=0
sysctl -w net.ipv4.conf.all.arp_ignore=1
sysctl -w net.ipv4.conf.all.arp_announce=2
sysctl -w net.ipv4.conf.default.rp_filter=0
sysctl -w net.ipv4.conf.default.arp_ignore=1
sysctl -w net.ipv4.conf.default.arp_announce=2
if [ -f /proc/net/if_inet6 ]; then
sysctl -w net.ipv6.conf.all.autoconf=0
sysctl -w net.ipv6.conf.all.accept_ra=0
sysctl -w net.ipv6.conf.all.forwarding=1
sysctl -w net.ipv6.conf.default.autoconf=0
sysctl -w net.ipv6.conf.default.accept_ra=0
sysctl -w net.ipv6.conf.default.forwarding=1
fi
;;
"master" )
# create macvlan interface
HEXA_VRID=$(printf %x $vrid)
ip link add link $ifname address 00:00:5E:00:01:$HEXA_VRID $interface type macvlan
# set virtual ips addresses
OIFS=$IFS
IFS=','
for ip in $ips; do
ip -$family addr add $ip dev $interface
done
ip link set dev $interface up
IFS=$OIFS
;;
"backup" )
# destroy macvlan interface
ip link del $interface
;;
esac
exit 0