/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/wireless

  • Committer: teddy at recompile
  • Date: 2011-12-31 13:25:58 UTC
  • mto: This revision was merged to the branch mainline in revision 541.
  • Revision ID: teddy@recompile.se-20111231132558-z0dh7qgofgctmgri
* network-hooks.s/bridge: Don't use interface names directly; search
                          for interface names using their address.
  (addrtoif): New function.
* network-hooks.s/bridge.conf (PORTS): Removed.
  (PORT_ADDRESSES): New.
* network-hooks.s/wireless: Don't use interface names directly; search
                            for interface names using their address.
  (addrtoif): New function.
* network-hooks.s/wireless.conf: Specify address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
CONFIG="$MANDOSNETHOOKDIR/wireless.conf"
22
22
 
 
23
addrtoif(){
 
24
    grep -liFe "$1" /sys/class/net/*/address | sed -e 's,.*/\([^/]*\)/[^/]*,\1,'
 
25
}
 
26
 
23
27
# Read config file
24
28
if [ -e "$CONFIG" ]; then
25
29
    . "$CONFIG"
27
31
    exit
28
32
fi
29
33
 
30
 
interfaces="`env|sed -n -e 's/^\(MODULE\|IPADDRS\|ROUTES\|WPA_DRIVER\)_\([^=]*\)=.*/\2/p' \"$CONFIG\" |sort -u`"
 
34
ifkeys="`env | sed -n -e 's/^ADDRESS_\([^=]*\)=.*/\1/p' \"$CONFIG\" | sort -u`"
31
35
 
32
36
# Exit if DEVICE is set and is not any of the wireless interfaces
33
37
if [ -n "$DEVICE" ]; then
34
38
    while :; do
35
 
        for IF in $interfaces; do
36
 
            if [ "$IF" = "$DEVICE" ]; then
 
39
        for KEY in $ifkeys; do
 
40
            ADDRESS=`eval 'echo "$ADDRESS_'"$KEY"\"`
 
41
            INTERFACE=`addrtoif "$ADDRESS"`
 
42
            if [ "$INTERFACE" = "$DEVICE" ]; then
37
43
                break 2
38
44
            fi
39
45
        done
66
72
    start)
67
73
        mkdir -m u=rwx,go= -p "$CTRLDIR"
68
74
        "$wpa_supplicant" -B -g "$CTRL" -p "$CTRLDIR" $WPAS_OPTIONS
69
 
        for INTERFACE in $interfaces; do
70
 
            DRIVER=`eval 'echo "$WPA_DRIVER_'"$INTERFACE"\"`
71
 
            IFDELAY=`eval 'echo "$DELAY_'"$INTERFACE"\"`
 
75
        for KEY in $ifkeys; do
 
76
            ADDRESS=`eval 'echo "$ADDRESS_'"$KEY"\"`
 
77
            INTERFACE=`addrtoif "$ADDRESS"`
 
78
            DRIVER=`eval 'echo "$WPA_DRIVER_'"$KEY"\"`
 
79
            IFDELAY=`eval 'echo "$DELAY_'"$KEY"\"`
72
80
            "$wpa_cli" -g "$CTRL" interface_add "$INTERFACE" "" \
73
81
                "${DRIVER:-wext}" "$CTRLDIR" > /dev/null \
74
82
                | sed -e '/^OK$/d'
75
83
            NETWORK=`"$wpa_cli" -p "$CTRLDIR" -i "$INTERFACE" add_network`
76
 
            eval wpa_interface_"$INTERFACE"
 
84
            eval wpa_interface_"$KEY"
77
85
            "$wpa_cli" -p "$CTRLDIR" -i "$INTERFACE" enable_network \
78
86
                "$NETWORK" | sed -e '/^OK$/d'
79
87
            sleep "${IFDELAY:-$DELAY}" &
95
103
                sleep 1
96
104
            done &
97
105
            wait $sleep || :
98
 
            IPADDRS=`eval 'echo "$IPADDRS_'"$INTERFACE"\"`
 
106
            IPADDRS=`eval 'echo "$IPADDRS_'"$KEY"\"`
99
107
            if [ -n "$IPADDRS" ]; then
100
108
                if [ "$IPADDRS" = dhcp ]; then
101
109
                    ipconfig -c dhcp -d "$INTERFACE" || :
106
114
                    done
107
115
                fi
108
116
            fi
109
 
            ROUTES=`eval 'echo "$ROUTES_'"$INTERFACE"\"`
 
117
            ROUTES=`eval 'echo "$ROUTES_'"$KEY"\"`
110
118
            if [ -n "$ROUTES" ]; then
111
119
                for route in $ROUTES; do
112
120
                    "$ip" route add "$route" dev "$BRIDGE"
116
124
        ;;
117
125
    stop)
118
126
        "$wpa_cli" -g "$CTRL" terminate 2>&1 | sed -e '/^OK$/d'
119
 
        for INTERFACE in $interfaces; do
 
127
        for KEY in $ifkeys; do
 
128
            ADDRESS=`eval 'echo "$ADDRESS_'"$KEY"\"`
 
129
            INTERFACE=`addrtoif "$ADDRESS"`
120
130
            "$ip" addr show scope global permanent dev "$INTERFACE" \
121
131
                | while read type addr rest; do
122
132
                case "$type" in