diff options
author | Jouke Witteveen <j.witteveen@gmail.com> | 2015-01-06 18:21:54 +0100 |
---|---|---|
committer | Jouke Witteveen <j.witteveen@gmail.com> | 2015-01-12 22:08:33 +0100 |
commit | 9c5c435f6240c0293ad01c34e1e4c4b224fffea2 (patch) | |
tree | 53be8a89d408ff168d6ad0bf907bfbcf748640ea | |
parent | d2cf9ae99834de3b8338008cae6273b967c353cd (diff) | |
download | netctl-9c5c435f6240c0293ad01c34e1e4c4b224fffea2.tar.gz netctl-9c5c435f6240c0293ad01c34e1e4c4b224fffea2.tar.xz |
Unify wired and wireless automatic profile selection (FS#35252)
The previous wired automatic profile selection procedure was not
properly documented.
Now both wired and wireless automatic profile selection use
ExcludeAuto= and Priority=
-rw-r--r-- | docs/netctl.profile.5.txt | 15 | ||||
-rwxr-xr-x | src/ifplugd.action | 46 | ||||
-rwxr-xr-x | src/netctl-auto | 11 |
3 files changed, 33 insertions, 39 deletions
diff --git a/docs/netctl.profile.5.txt b/docs/netctl.profile.5.txt index c4982fc..82946da 100644 --- a/docs/netctl.profile.5.txt +++ b/docs/netctl.profile.5.txt @@ -103,6 +103,11 @@ GENERAL OPTIONS Set to `++yes++' to force connecting even if the interface is up. Do not use this unless you know what you are doing. +'ExcludeAuto=':: + Whether or not to exclude this profile from automatic profile + selection. Defaults to `++no++' for wireless and DHCP enabled + connections and to `++yes++' otherwise. + IP OPTIONS ---------- @@ -223,6 +228,12 @@ of the `ethernet' type: Whether or not the absence of a carrier (plugged-in cable) is acceptable. Defaults to `++no++'. +'Priority=':: + Priority level of the profile. In case of automatic profile + selection, profiles are tried in decreasing order of priority. + Defaults to `++1++' in DHCP enabled profiles and to `++0++' + otherwise. + OPTIONS FOR `wireless' CONNECTIONS ---------------------------------- @@ -295,10 +306,6 @@ of the `wireless' type: variable to `++auto++'. In that case an *rfkill* device that is associated with the network interface is used. -'ExcludeAuto=':: - Whether or not to exclude this profile from automatic profile - selection. Defaults to `++no++'. - OPTIONS FOR `bond' CONNECTIONS ------------------------------ diff --git a/src/ifplugd.action b/src/ifplugd.action index c87ac0c..42d1c5a 100755 --- a/src/ifplugd.action +++ b/src/ifplugd.action @@ -1,4 +1,4 @@ -#!/bin/bash +#! /bin/bash # # ifplugd.action script for netctl @@ -8,39 +8,29 @@ PROFILE_FILE="$STATE_DIR/ifplugd_$1.profile" case "$2" in up) - # Look for a dhcp based profile to try first - # dhcp can actually outright fail, whereas - # it's difficult to tell if static succeeded - # Also check profile is same iface and is right connection - echo "up" - declare -a preferred_profiles - declare -a dhcp_profiles - declare -a static_profiles while read -r profile; do - ( - echo "Reading profile '$profile'" - source "$PROFILE_DIR/$profile" - [[ "$Interface" == "$1" && "$Connection" == "ethernet" ]] || continue - is_yes "${AutoWired:-no}" && exit 1 # user preferred AUTO profile - [[ "$IP" == "dhcp" ]] && exit 2 # dhcp profile - exit 3 # static profile - ) - case $? in - 1) preferred_profiles+=("$profile");; - 2) dhcp_profiles+=("$profile");; - 3) static_profiles+=("$profile");; - esac - done < <(list_profiles) - if [[ ${#preferred_profiles[@]} > 1 ]]; then - echo "AutoWired flag for '$1' set in more than one profile (${preferred_profiles[*]})" - fi - for profile in "${preferred_profiles[@]}" "${dhcp_profiles[@]}" "${static_profiles[@]}"; do if ForceConnect=yes "$SUBR_DIR/network" start "$profile"; then mkdir -p "$(dirname "$PROFILE_FILE")" printf "%s" "$profile" > "$PROFILE_FILE" exit 0 fi - done + done < <(list_profiles | while read -r profile; do + report_debug "Examining profile '$profile'" + ( + source "$PROFILE_DIR/$profile" > /dev/null + [[ $Interface == "$1" && $Connection == "ethernet" ]] || exit + # Prioritize dhcp based profiles as they can outright fail, whereas + # it is difficult to tell if a profile with a static address fails + if [[ $IP == "dhcp" || $IP6 == dhcp* ]]; then + : ${ExcludeAuto:=no} + : ${Priority:=1} + fi + is_yes "${ExcludeAuto:-yes}" && exit + printf "%i\t%s\n" "${Priority:-0}" "$profile" + report_debug "Included profile '$profile'" + ) + done | sort -nrs -k 1,1 | cut -f 2-) + report_error "Could not start any suitable profile" ;; down) if [[ -e "$PROFILE_FILE" ]]; then diff --git a/src/netctl-auto b/src/netctl-auto index d9fac3a..b84c0de 100755 --- a/src/netctl-auto +++ b/src/netctl-auto @@ -192,13 +192,10 @@ start() { report_debug "Examining profile '$profile'" ( source "$PROFILE_DIR/$profile" - [[ $Interface == "$interface" ]] || continue - is_yes "${ExcludeAuto:-no}" && exit 1 - [[ $Connection != "wireless" ]] && exit 1 - : ${Security:=none} - # Exclude wpa-config, the wpa_conf is 'complete' and doesn't fit in this scheme - [[ $Security == "wpa-config" ]] && exit 1 - + [[ $Interface == "$interface" && $Connection == "wireless" ]] || exit + is_yes "${ExcludeAuto:-no}" && exit + # Set default and exclude wpa-config as it does not fit this scheme + [[ ${Security:=none} != "wpa-config" ]] || exit printf "%s\n" "network={" "$(wpa_make_config_block)" "id_str=\"$profile\"" "}" >> "$wpa_conf" report_notice "Included profile '$profile'" ) |