diff options
author | Jouke Witteveen <j.witteveen@gmail.com> | 2012-07-05 13:17:13 +0200 |
---|---|---|
committer | Jouke Witteveen <j.witteveen@gmail.com> | 2012-07-05 13:17:13 +0200 |
commit | 0f5eb3ef064c4a62a5ba3c8f4733f8e61556687b (patch) | |
tree | d3149db9fdc1a9513a169f8877291992e0581d78 | |
parent | c2036ac1ab643040d6cf98e682ed171114d87090 (diff) | |
download | netctl-0f5eb3ef064c4a62a5ba3c8f4733f8e61556687b.tar.gz netctl-0f5eb3ef064c4a62a5ba3c8f4733f8e61556687b.tar.xz |
Rethink management of socket location for wpa_supplicant
This may be set in a custom supplicant configuration file. All this is needed to cater for that.
The new name of the tracking variable is WPA_CTRL_DIR, conform the environment variable of wpa_cli -a.
-rwxr-xr-x | scripts/netcfg-wpa_actiond | 3 | ||||
-rwxr-xr-x | scripts/wifi-menu | 6 | ||||
-rw-r--r-- | src/8021x | 73 | ||||
-rw-r--r-- | src/connections/ethernet | 6 | ||||
-rw-r--r-- | src/connections/wireless | 12 |
5 files changed, 54 insertions, 46 deletions
diff --git a/scripts/netcfg-wpa_actiond b/scripts/netcfg-wpa_actiond index 744b7af..f2d2382 100755 --- a/scripts/netcfg-wpa_actiond +++ b/scripts/netcfg-wpa_actiond @@ -18,7 +18,6 @@ case $1 in interface=$2 [[ -f "$IFACE_DIR/$interface" ]] && source "$IFACE_DIR/$interface" netcfg -D "$interface" - stop_wpa "$interface" kill $(< "/run/wpa_actiond_${2}.pid") # only try to disable software rfkill switches (FS#25514) if [[ "$RFKILL" == "soft" ]]; then @@ -81,7 +80,7 @@ done WPA_OPTS="-W $WPA_OPTS" # Kill any existing wpa_supplicant on this interface -stop_wpa "$interface" +stop_wpa "$interface" &> /dev/null if start_wpa $interface $WPA_CONF $WPA_DRIVER $WPA_OPTS; then if $AUTOWIFI -i ${interface} -P ${PIDFILE} -a ${ACTION_SCRIPT} ${EXTRA_AUTOWIFI_OPTIONS}; then diff --git a/scripts/wifi-menu b/scripts/wifi-menu index 3d7ed57..bbc2bf5 100755 --- a/scripts/wifi-menu +++ b/scripts/wifi-menu @@ -4,9 +4,6 @@ . "$SUBR_DIR/8021x" . /etc/conf.d/netcfg -# The right value depends on the connected profile. -WPA_CTRL_PATH=/run/wpa_supplicant - usage() { cat << END @@ -211,8 +208,7 @@ if ! interface_is_up "$INTERFACE"; then fi report_try "Scanning for networks" -CONNECTION=$(wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" status 2> /dev/null \ - | grep -m 1 "^ssid=") +CONNECTION=$(wpa_call "$INTERFACE" status 2> /dev/null | grep -m 1 "^ssid=") CONNECTION=${CONNECTION#ssid=} NETWORKS=$(wpa_supplicant_scan_info "$INTERFACE" 3,4,5) if [[ $? -eq 0 ]]; then @@ -1,3 +1,23 @@ +# Usage: wpa_call $interface $call ... +# Wrapper around wpa_cli to deal with supplicant configurations that set a +# non-standard control path. +wpa_call() +{ + local args=("-i" "$1") + shift + + if [[ -n "$WPA_CTRL_DIR" ]]; then + args+=("-p" "$WPA_CTRL_DIR") + elif [[ -n "$WPA_CONF" ]] && grep -q "^[[:space:]]*ctrl_interface=" "$WPA_CONF"; then + WPA_CTRL_DIR=$(grep -m 1 "^[[:space:]]*ctrl_interface=" "$WPA_CONF" | cut -d= -f 2-) + WPA_CTRL_DIR=${WPA_CTRL_DIR#DIR=} + WPA_CTRL_DIR=${WPA_CTRL_DIR%% GROUP=.*} + args+=("-p" "$WPA_CTRL_DIR") + fi + report_debug wpa_cli "${args[@]}" "$@" + wpa_cli "${args[@]}" "$@" +} + # Uses wpa_supplicant to check for association to a network # wpa_check interface [timeout] wpa_check() @@ -5,13 +25,12 @@ wpa_check() local timeout=0 INTERFACE="$1" TIMEOUT="${2:-15}" CONDITION="${3:-COMPLETED}" # CONDITION is required as wired connections are ready at ASSOCIATED not COMPLETED FS#20150 - report_debug wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" status while (( timeout < TIMEOUT )); do ( # Sometimes wpa_supplicant isn't ready so silence errors for 2s only to avoid hiding real errors if (( timeout < 2 )); then - eval $(wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" status 2> /dev/null | fgrep "wpa_state=") + eval $(wpa_call "$INTERFACE" status 2> /dev/null | fgrep "wpa_state=") else - eval $(wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" status | fgrep "wpa_state=") + eval $(wpa_call "$INTERFACE" status | fgrep "wpa_state=") fi [[ "$wpa_state" = "$CONDITION" ]] ) && return 0 @@ -29,12 +48,13 @@ start_wpa() { local INTERFACE="$1" WPA_CONF="$2" WPA_DRIVER="$3" shift 3 - local WPA_OPTS="$*" + local WPA_OPTS="$@" if [[ -n "$WPA_CONF" ]]; then WPA_CONF="-c$WPA_CONF" else - WPA_CONF="-C$WPA_CTRL_PATH" + WPA_CTRL_DIR="/run/wpa_supplicant" + WPA_CONF="-C$WPA_CTRL_DIR" fi wpa_supplicant -B -P "/run/wpa_supplicant_${INTERFACE}.pid" -i "$INTERFACE" -D "$WPA_DRIVER" "$WPA_CONF" $WPA_OPTS @@ -46,16 +66,17 @@ start_wpa() stop_wpa() { - wpa_cli -p "$WPA_CTRL_PATH" -i "$1" terminate &> /dev/null + # we need this as long as wpa_cli has a different default than netcfg + [[ -z "$WPA_CTRL_DIR" && -z "$WPA_CONF" ]] && WPA_CTRL_DIR="/run/wpa_supplicant" + wpa_call "$1" terminate > /dev/null # wait up to one second for the pid file to be removed timeout_wait 1 '[[ ! -f "/run/wpa_supplicant_$1.pid" ]]' || \ - kill "$(< "/run/wpa_supplicant_$1.pid")" &>/dev/null & + kill "$(< "/run/wpa_supplicant_$1.pid")" &> /dev/null & } wpa_reconfigure() { - local INTERFACE=$1 - wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" reconfigure &> /dev/null + wpa_call "$1" reconfigure > /dev/null return $? } @@ -63,7 +84,7 @@ wpa_check_current_essid() { # usage: wpa_check_current_essid $interface $essid # check that wpa_supplicant is connected to the right essid local INTERFACE=$1 ESSID=$2 status - status=$(wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" status | grep "^ssid=") + status=$(wpa_call "$INTERFACE" status | grep "^ssid=") if (( $? == 0 )) && [[ "$status" == "ssid=$ESSID" ]]; then return 0 else @@ -100,12 +121,11 @@ wpa_supplicant_scan_and_find() { # item = string to lookup local INTERFACE="$1" FIELD="$2" ITEM="$3" RETRIES=5 try scan_ok scan_ok=0 - report_debug wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" scan - wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" scan &> /dev/null + wpa_call "$INTERFACE" scan > /dev/null for ((try=0; try < $RETRIES; try++)); do local found sleep 2 - found=$(wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" scan_results | tail -n+2 | cut -f ${FIELD} | fgrep -x -m 1 "${ITEM}") + found=$(wpa_call "$INTERFACE" scan_results | tail -n+2 | cut -f ${FIELD} | fgrep -x -m 1 "${ITEM}") (( $? == 0 )) && scan_ok=1 # ITEM has been found, echo it @@ -113,7 +133,7 @@ wpa_supplicant_scan_and_find() { echo "$found" return 0 fi - wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" scan &> /dev/null + wpa_call "$INTERFACE" scan > /dev/null done if (( $scan_ok != 1 )); then report_debug wpa_supplicant_scan_and_find "unable to retrieve scan results" @@ -135,17 +155,17 @@ wpa_supplicant_scan_info() { [[ -z "$INTERFACE" ]] && return 1 essids=$(mktemp --tmpdir essid.XXXXXXXX) - if [[ "$(wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" ping 2> /dev/null)" != "PONG" ]]; then + if [[ "$(wpa_call "$INTERFACE" ping 2> /dev/null)" != "PONG" ]]; then start_wpa "$INTERFACE" "" "${WPA_DRIVER:-nl80211,wext}" || return 1 spawned_wpa=1 fi - wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" scan &> /dev/null + wpa_call "$INTERFACE" scan > /dev/null # Wait at least 3 seconds for scan results sleep 3 # Sometimes, that is not enough (FS#29946) - timeout_wait 7 '! wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" status | fgrep -q "wpa_state=SCANNING"' - wpa_cli -p "$WPA_CTRL_PATH" -i "$INTERFACE" scan_results | + timeout_wait 7 '! wpa_call "$INTERFACE" status | fgrep -q "wpa_state=SCANNING"' + wpa_call "$INTERFACE" scan_results | grep -v "^Selected" | grep -v "^bssid" | sort -rn -k3 | @@ -174,19 +194,18 @@ wpa_supplicant_scan_info() { # Requires already loaded profile make_wpa_config_file() { - local interface=$1 - local WPA_CONF="$STATE_DIR/wpa.${interface}" # substitute spaces out + local WPA_CONFD="$STATE_DIR/wpa.$1" # make empty tmp dir with correct permissions, rename it check_make_state_dir mkdir -p /run/wpa_supplicant - rm -rf "$WPA_CONF" - mv -f "$(mktemp -d --tmpdir=$STATE_DIR)" "$WPA_CONF" || return 1 - echo "ctrl_interface=/run/wpa_supplicant" >> "$WPA_CONF/wpa.conf" # we know $WPA_CONF now has no spaces, but it may have other nasty chars, so still needs to be quoted - echo "ctrl_interface_group=${WPA_GROUP:-wheel}" >> "$WPA_CONF/wpa.conf" - [[ $WPA_COUNTRY ]] && echo "country=$WPA_COUNTRY" >> "$WPA_CONF/wpa.conf" - [[ -n "$ADHOC" ]] && echo "ap_scan=2" >> "$WPA_CONF/wpa.conf" - echo "$WPA_CONF/wpa.conf" + rm -rf "$WPA_CONFD" + mv -f "$(mktemp -d --tmpdir=$STATE_DIR)" "$WPA_CONFD" || return 1 + echo "ctrl_interface=/run/wpa_supplicant" >> "$WPA_CONFD/wpa.conf" + echo "ctrl_interface_group=${WPA_GROUP:-wheel}" >> "$WPA_CONFD/wpa.conf" + [[ $WPA_COUNTRY ]] && echo "country=$WPA_COUNTRY" >> "$WPA_CONFD/wpa.conf" + [[ -n "$ADHOC" ]] && echo "ap_scan=2" >> "$WPA_CONFD/wpa.conf" + echo "$WPA_CONFD/wpa.conf" } # Requires already loaded profile diff --git a/src/connections/ethernet b/src/connections/ethernet index b33dfbd..ba6c7be 100644 --- a/src/connections/ethernet +++ b/src/connections/ethernet @@ -43,11 +43,6 @@ ethernet_up() { . "$SUBR_DIR/8021x" [[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf" [[ -z "$WPA_DRIVER" ]] && WPA_DRIVER="wired" - # Set wpa_supplicant control path (FS#25473) - WPA_CTRL_PATH=/run/wpa_supplicant - if grep -q "^ *ctrl_interface=" "$WPA_CONF"; then - WPA_CTRL_PATH=$(grep -m 1 "^ *ctrl_interface=" "$WPA_CONF" | cut -d= -f 2- | sed -r 's/^DIR=(.*) GROUP=.*/\1/') - fi report_debug ethernet_up start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS" if ! start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS"; then @@ -276,6 +271,7 @@ ethernet_status() { stop_80211x() { if checkyesno "${AUTH8021X:-no}"; then . "$SUBR_DIR/8021x" + [[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf" report_debug ethernet_down stop_wpa "$INTERFACE" stop_wpa "$INTERFACE" fi diff --git a/src/connections/wireless b/src/connections/wireless index 0389ea6..e0321d4 100644 --- a/src/connections/wireless +++ b/src/connections/wireless @@ -8,7 +8,6 @@ wireless_up() { load_profile "$PROFILE" # Default settings - WPA_CTRL_PATH=/run/wpa_supplicant SECURITY=${SECURITY:-none} WPA_DRIVER=${WPA_DRIVER:-nl80211,wext} @@ -18,16 +17,11 @@ wireless_up() { is_interface "$INTERFACE" || { report_fail "interface $INTERFACE does not exist"; return 1; } # Kill any lingering wpa_supplicants. - report_debug wireless_up stop_wpa "$INTERFACE" - stop_wpa "$INTERFACE" + stop_wpa "$INTERFACE" &> /dev/null # Start wpa_supplicant if [[ "$SECURITY" = "wpa-config" ]]; then WPA_CONF="${WPA_CONF:-/etc/wpa_supplicant.conf}" - # Use defined control path (FS#24949) - if grep -q "^ *ctrl_interface=" "$WPA_CONF"; then - WPA_CTRL_PATH=$(grep -m 1 "^ *ctrl_interface=" "$WPA_CONF" | cut -d= -f 2- | sed -r 's/^DIR=(.*) GROUP=.*/\1/') - fi else WPA_CONF=$(make_wpa_config_file $INTERFACE) fi @@ -98,6 +92,10 @@ wireless_down() { "$CONN_DIR/ethernet" down "$PROFILE" + # The config file can contain a non-standard control socket path + if [[ "$SECURITY" = "wpa-config" ]]; then + WPA_CONF="${WPA_CONF:-/etc/wpa_supplicant.conf}" + fi report_debug wireless_down stop_wpa "$INTERFACE" stop_wpa "$INTERFACE" rm -rf "$STATE_DIR/wpa.$INTERFACE" |