/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to network-hooks.d/bridge

  • Committer: Teddy Hogeborn
  • Date: 2011-12-31 23:05:34 UTC
  • Revision ID: teddy@recompile.se-20111231230534-o5w0uhwx30gwhmk7
Updated year in copyright notices.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
CONFIG="$MANDOSNETHOOKDIR/bridge.conf"
17
17
 
18
 
# Read config file, which must set "BRIDGE", "PORTS", and optionally
19
 
# "IPADDRS" and "ROUTES".
 
18
addrtoif(){
 
19
    grep -liFe "$1" /sys/class/net/*/address \
 
20
        | sed -e 's,.*/\([^/]*\)/[^/]*,\1,'
 
21
}
 
22
 
 
23
# Read config file, which must set "BRIDGE", "PORT_ADDRESSES", and
 
24
# optionally "IPADDRS" and "ROUTES".
20
25
if [ -e "$CONFIG" ]; then
21
26
    . "$CONFIG"
22
27
fi
23
28
 
24
 
if [ -z "$BRIDGE" -o -z "$PORTS" ]; then
 
29
if [ -z "$BRIDGE" -o -z "$PORT_ADDRESSES" ]; then
25
30
    exit
26
31
fi
27
32
 
39
44
case "$1" in
40
45
    start)
41
46
        "$brctl" addbr "$BRIDGE"
42
 
        for port in $PORTS; do
43
 
            "$brctl" addif "$BRIDGE" "$port"
44
 
            ip link set up "$port"
 
47
        for address in $PORT_ADDRESSES; do
 
48
            interface=`addrtoif "$address"`
 
49
            "$brctl" addif "$BRIDGE" "$interface"
 
50
            ip link set dev "$interface" up
45
51
        done
46
 
        ip link set up "$BRIDGE"
 
52
        ip link set dev "$BRIDGE" up
47
53
        sleep "$DELAY"
48
54
        if [ -n "$IPADDRS" ]; then
49
55
            for ipaddr in $IPADDRS; do
57
63
        fi
58
64
        ;;
59
65
    stop)
60
 
        ip link set down "$BRIDGE"
61
 
        for port in $PORTS; do
62
 
            ip link set down "$port"
63
 
            "$brctl" delif "$BRIDGE" "$port"
 
66
        ip link set dev "$BRIDGE" down
 
67
        for address in $PORT_ADDRESSES; do
 
68
            interface=`addrtoif "$address"`
 
69
            ip link set dev "$interface" down
 
70
            "$brctl" delif "$BRIDGE" "$interface"
64
71
        done
65
72
        "$brctl" delbr "$BRIDGE"
66
73
        ;;