summaryrefslogtreecommitdiffstats
path: root/ctdb/config/events.d/11.routing
blob: 2fe560f73f1a14996470465056b45eb184503b60 (plain)
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
#!/bin/sh

# Attempt to add a set of static routes.
#
# Do this in "ipreallocated" rather than just "startup" because some
# of the routes might be missing because the corresponding interface
# has not previously had any IPs assigned or IPs were previously
# released and corresponding routes were dropped.
#
# Addition of some routes might fail, errors go to /dev/null.
#
# Routes to add are defined in $CTDB_BASE/static-routes. Syntax is:
#
# IFACE NET/MASK GATEWAY
#
# Example:
#
# bond1 10.3.3.0/24 10.0.0.1

[ -n "$CTDB_BASE" ] || \
    export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD")

. $CTDB_BASE/functions
loadconfig

[ -f $CTDB_BASE/static-routes ] || {
    exit 0
}

case "$1" in
    ipreallocated)
        while read iface dest gw; do
            ip route add "$dest" via "$gw" dev "$iface" >/dev/null 2>&1
        done <"${CTDB_BASE}/static-routes"
        ;;

    updateip)
	oiface=$2
	niface=$3
	while read iface dest gw; do
	    if [ "$niface" = "$iface" -o "$oiface" = "$iface" ] ; then
		ip route add "$dest" via "$gw" dev "$iface" >/dev/null 2>&1
	    fi
	done <"${CTDB_BASE}/static-routes"
	;;

    *)
	ctdb_standard_event_handler "$@"
	;;
esac

exit 0