c8d875cd732cefe630954cdc2e85223d92fc3fd7
[samba.git] / ctdb / config / events.d / 11.routing
1 #!/bin/sh
2
3 # Attempt to add a set of static routes.
4 #
5 # Do this in "ipreallocated" rather than just "startup" because some
6 # of the routes might be missing because the corresponding interface
7 # has not previously had any IPs assigned or IPs were previously
8 # released and corresponding routes were dropped.
9 #
10 # Addition of some routes might fail, errors go to /dev/null.
11 #
12 # Routes to add are defined in $CTDB_BASE/static-routes. Syntax is:
13 #
14 # IFACE NET/MASK GATEWAY
15 #
16 # Example:
17 #
18 # bond1 10.3.3.0/24 10.0.0.1
19
20 [ -n "$CTDB_BASE" ] || \
21     CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD")
22
23 . "${CTDB_BASE}/functions"
24
25 loadconfig
26
27 [ -f "${CTDB_BASE}/static-routes" ] || {
28     exit 0
29 }
30
31 case "$1" in
32 ipreallocated)
33         while read iface dest gw; do
34             ip route add "$dest" via "$gw" dev "$iface" >/dev/null 2>&1
35         done <"${CTDB_BASE}/static-routes"
36         ;;
37
38 updateip)
39         oiface=$2
40         niface=$3
41         while read iface dest gw; do
42             if [ "$niface" = "$iface" -o "$oiface" = "$iface" ] ; then
43                 ip route add "$dest" via "$gw" dev "$iface" >/dev/null 2>&1
44             fi
45         done <"${CTDB_BASE}/static-routes"
46         ;;
47 esac
48
49 exit 0