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 |
||
237.17.8
by teddy at recompile
* network-hooks.s/bridge: Don't use interface names directly; search |
18 |
addrtoif(){
|
19 |
grep -liFe "$1" /sys/class/net/*/address | sed -e 's,.*/\([^/]*\)/[^/]*,\1,' |
|
20 |
}
|
|
21 |
||
22 |
# Read config file, which must set "BRIDGE", "PORT_ADDRESSES", and
|
|
23 |
# optionally "IPADDRS" and "ROUTES".
|
|
237.16.10
by Teddy Hogeborn
* network-hooks.d: New directory. |
24 |
if [ -e "$CONFIG" ]; then |
25 |
. "$CONFIG" |
|
26 |
fi
|
|
27 |
||
237.17.8
by teddy at recompile
* network-hooks.s/bridge: Don't use interface names directly; search |
28 |
if [ -z "$BRIDGE" -o -z "$PORT_ADDRESSES" ]; then |
237.16.10
by Teddy Hogeborn
* network-hooks.d: New directory. |
29 |
exit |
30 |
fi
|
|
31 |
||
32 |
if [ -n "$DEVICE" -a "$DEVICE" != "$BRIDGE" ]; then |
|
33 |
exit |
|
34 |
fi
|
|
35 |
||
237.16.21
by Teddy Hogeborn
* network-hooks.d/bridge: Bug fix - really find brctl. |
36 |
for b in /sbin/brctl /usr/sbin/brctl; do |
37 |
if [ -e "$b" ]; then |
|
38 |
brctl="$b" |
|
237.16.20
by Teddy Hogeborn
* network-hooks.d/bridge: Look for both /sbin/brctl and /usr/sbin/brctl. |
39 |
break |
40 |
fi |
|
41 |
done
|
|
42 |
||
237.16.10
by Teddy Hogeborn
* network-hooks.d: New directory. |
43 |
case "$1" in |
44 |
start) |
|
237.16.22
by Teddy Hogeborn
* network-hooks.d/bridge: Bug fix - use the found brctl. |
45 |
"$brctl" addbr "$BRIDGE" |
237.17.8
by teddy at recompile
* network-hooks.s/bridge: Don't use interface names directly; search |
46 |
for address in $PORT_ADDRESSES; do |
47 |
interface=`addrtoif "$address"` |
|
48 |
"$brctl" addif "$BRIDGE" "$interface" |
|
49 |
ip link set dev "$interface" up |
|
237.16.10
by Teddy Hogeborn
* network-hooks.d: New directory. |
50 |
done |
237.17.1
by teddy at recompile
Add wireless network hook |
51 |
ip link set dev "$BRIDGE" up |
237.16.23
by Teddy Hogeborn
* network-hooks.d/bridge: Bug fix - take up (and down) the bound |
52 |
sleep "$DELAY" |
237.16.10
by Teddy Hogeborn
* network-hooks.d: New directory. |
53 |
if [ -n "$IPADDRS" ]; then |
54 |
for ipaddr in $IPADDRS; do |
|
55 |
ip addr add "$ipaddr" dev "$BRIDGE" |
|
56 |
done |
|
57 |
fi |
|
58 |
if [ -n "$ROUTES" ]; then |
|
59 |
for route in $ROUTES; do |
|
60 |
ip route add "$route" dev "$BRIDGE" |
|
61 |
done |
|
62 |
fi |
|
63 |
;; |
|
64 |
stop) |
|
237.17.1
by teddy at recompile
Add wireless network hook |
65 |
ip link set dev "$BRIDGE" down |
237.17.8
by teddy at recompile
* network-hooks.s/bridge: Don't use interface names directly; search |
66 |
for address in $PORT_ADDRESSES; do |
67 |
interface=`addrtoif "$address"` |
|
68 |
ip link set dev "$interface" down |
|
69 |
"$brctl" delif "$BRIDGE" "$interface" |
|
237.16.10
by Teddy Hogeborn
* network-hooks.d: New directory. |
70 |
done |
237.16.22
by Teddy Hogeborn
* network-hooks.d/bridge: Bug fix - use the found brctl. |
71 |
"$brctl" delbr "$BRIDGE" |
237.16.10
by Teddy Hogeborn
* network-hooks.d: New directory. |
72 |
;; |
73 |
files) |
|
74 |
echo /bin/ip |
|
237.16.20
by Teddy Hogeborn
* network-hooks.d/bridge: Look for both /sbin/brctl and /usr/sbin/brctl. |
75 |
echo "$brctl" |
237.16.14
by teddy at bsnet
Hooks take new "modules" argument, and hook names can contain periods. |
76 |
;; |
77 |
modules) |
|
78 |
echo bridge |
|
237.16.10
by Teddy Hogeborn
* network-hooks.d: New directory. |
79 |
;; |
80 |
esac
|