/mandos/release

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/release
237.16.10 by Teddy Hogeborn
* network-hooks.d: New directory.
1
#!/bin/sh
2
#
3
# This is an example of a Mandos client network hook.  This hook
4
# brings up a bridge interface as specified in a separate
5
# configuration file.  To be used, this file and any needed
6
# configuration file(s) should be copied into the
7
# /etc/mandos/network-hooks.d directory.
8
# 
9
# Copying and distribution of this file, with or without modification,
10
# are permitted in any medium without royalty provided the copyright
11
# notice and this notice are preserved.  This file is offered as-is,
12
# without any warranty.
13
14
set -e
15
16
CONFIG="$MANDOSNETHOOKDIR/bridge.conf"
17
18
# Read config file, which must set "BRIDGE", "PORTS", and optionally
19
# "IPADDRS" and "ROUTES".
20
if [ -e "$CONFIG" ]; then
21
    . "$CONFIG"
22
fi
23
24
if [ -z "$BRIDGE" -o -z "$PORTS" ]; then
25
    exit
26
fi
27
28
if [ -n "$DEVICE" -a "$DEVICE" != "$BRIDGE" ]; then
29
    exit
30
fi
31
237.16.21 by Teddy Hogeborn
* network-hooks.d/bridge: Bug fix - really find brctl.
32
for b in /sbin/brctl /usr/sbin/brctl; do
33
    if [ -e "$b" ]; then
34
	brctl="$b"
237.16.20 by Teddy Hogeborn
* network-hooks.d/bridge: Look for both /sbin/brctl and /usr/sbin/brctl.
35
	break
36
    fi
37
done
38
237.16.10 by Teddy Hogeborn
* network-hooks.d: New directory.
39
case "$1" in
40
    start)
237.16.22 by Teddy Hogeborn
* network-hooks.d/bridge: Bug fix - use the found brctl.
41
	"$brctl" addbr "$BRIDGE"
237.16.10 by Teddy Hogeborn
* network-hooks.d: New directory.
42
	for port in $PORTS; do
237.16.22 by Teddy Hogeborn
* network-hooks.d/bridge: Bug fix - use the found brctl.
43
	    "$brctl" addif "$BRIDGE" "$port"
237.16.10 by Teddy Hogeborn
* network-hooks.d: New directory.
44
	done
45
	ip link set up "$BRIDGE"
46
	if [ -n "$IPADDRS" ]; then
47
            for ipaddr in $IPADDRS; do
48
		ip addr add "$ipaddr" dev "$BRIDGE"
49
	    done
50
	fi
51
	if [ -n "$ROUTES" ]; then
52
            for route in $ROUTES; do
53
		ip route add "$route" dev "$BRIDGE"
54
	    done
55
	fi
56
	;;
57
    stop)
58
	ip link set down "$BRIDGE"
59
	for port in $PORTS; do
237.16.22 by Teddy Hogeborn
* network-hooks.d/bridge: Bug fix - use the found brctl.
60
	    "$brctl" delif "$BRIDGE" "$port"
237.16.10 by Teddy Hogeborn
* network-hooks.d: New directory.
61
	done
237.16.22 by Teddy Hogeborn
* network-hooks.d/bridge: Bug fix - use the found brctl.
62
	"$brctl" delbr "$BRIDGE"
237.16.10 by Teddy Hogeborn
* network-hooks.d: New directory.
63
	;;
64
    files)
65
	echo /bin/ip
237.16.20 by Teddy Hogeborn
* network-hooks.d/bridge: Look for both /sbin/brctl and /usr/sbin/brctl.
66
	echo "$brctl"
237.16.14 by teddy at bsnet
Hooks take new "modules" argument, and hook names can contain periods.
67
	;;
68
    modules)
69
	echo bridge
237.16.10 by Teddy Hogeborn
* network-hooks.d: New directory.
70
	;;
71
esac