/mandos/release

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

« back to all changes in this revision

Viewing changes to network-hooks.d/wireless

  • Committer: teddy at recompile
  • Date: 2011-12-31 12:08:11 UTC
  • mto: (237.7.89 trunk)
  • mto: This revision was merged to the branch mainline in revision 290.
  • Revision ID: teddy@recompile.se-20111231120811-pkvvjmqm53fx7w9x
* network-hooks.s/wireless (start): Wait until interface is up.

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