/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
 
            DELAY=`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
 
            ( sleep "${DELAY:-$DELAY}" || : ) &
 
87
            sleep "${IFDELAY:-$DELAY}" &
80
88
            sleep=$!
81
89
            while :; do
82
 
                kill -0 $sleep || break
 
90
                kill -0 $sleep 2>/dev/null || break
83
91
                STATE=`"$wpa_cli" -p "$CTRLDIR" -i "$INTERFACE" status | sed -n -e 's/^wpa_state=//p'`
84
92
                if [ "$STATE" = COMPLETED ]; then
85
 
                    kill $sleep
86
 
                    break
 
93
                    while :; do
 
94
                        kill -0 $sleep 2>/dev/null || break 2
 
95
                        UP=`cat /sys/class/net/"$INTERFACE"/operstate`
 
96
                        if [ "$UP" = up ]; then
 
97
                            kill $sleep 2>/dev/null
 
98
                            break 2
 
99
                        fi
 
100
                        sleep 1
 
101
                    done
87
102
                fi
88
103
                sleep 1
89
104
            done &
90
105
            wait $sleep || :
91
 
            IPADDRS=`eval 'echo "$IPADDRS_'"$INTERFACE"\"`
 
106
            IPADDRS=`eval 'echo "$IPADDRS_'"$KEY"\"`
92
107
            if [ -n "$IPADDRS" ]; then
93
108
                if [ "$IPADDRS" = dhcp ]; then
94
109
                    ipconfig -c dhcp -d "$INTERFACE" || :
99
114
                    done
100
115
                fi
101
116
            fi
102
 
            ROUTES=`eval 'echo "$ROUTES_'"$INTERFACE"\"`
 
117
            ROUTES=`eval 'echo "$ROUTES_'"$KEY"\"`
103
118
            if [ -n "$ROUTES" ]; then
104
119
                for route in $ROUTES; do
105
120
                    "$ip" route add "$route" dev "$BRIDGE"
109
124
        ;;
110
125
    stop)
111
126
        "$wpa_cli" -g "$CTRL" terminate 2>&1 | sed -e '/^OK$/d'
112
 
        for INTERFACE in $interfaces; do
 
127
        for KEY in $ifkeys; do
 
128
            ADDRESS=`eval 'echo "$ADDRESS_'"$KEY"\"`
 
129
            INTERFACE=`addrtoif "$ADDRESS"`
113
130
            "$ip" addr show scope global permanent dev "$INTERFACE" \
114
131
                | while read type addr rest; do
115
132
                case "$type" in
130
147
        if [ "$IPADDRS" = dhcp ]; then
131
148
            echo af_packet
132
149
        fi
133
 
        sed -n -e 's/#.*$//' -e 's/[    ]*$//' -e 's/^MODULE=//p' \
134
 
            "$CONFIG"
 
150
        sed -n -e 's/#.*$//' -e 's/[    ]*$//' \
 
151
            -e 's/^MODULE_[^=]\+=//p' "$CONFIG"
135
152
        ;;
136
153
esac