From 69dc5784ab8eeaccac82e440c7d219e1a95d5589 Mon Sep 17 00:00:00 2001 From: Daniel Fojt Date: Fri, 29 May 2020 19:34:24 +0200 Subject: [PATCH] etc/network.subr: enhance wlan initialization Introduce new functions wlan_get_unused() and wlan_is_parent(), and extend wlan_up() to utilize them. With this change, devices configured the traditional way in rc.conf(5) are created first, and then all other wireless interfaces are assigned to next available wlan devices automatically. This allows either to have wlan configured manually in rc.conf(5) via "wlans_" or to remove the static assignment and let devices be auto-created. With dhcpcd_enable and wpa_supplicant_enable in rc.conf, no further configuration is then needed to get network connectivity. Furthermore, this will allow to enhance devd(8) default configuration, so that also hot-pluggable wireless interfaces are automatically detected and brought up (ie. assigned to wlan devices). Reviewed by: Aaron LI --- etc/network.subr | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/etc/network.subr b/etc/network.subr index e382e2bcdd..b8b663a411 100644 --- a/etc/network.subr +++ b/etc/network.subr @@ -414,6 +414,32 @@ ifscript_down() return 1 } +# wlan_get_unused +# walk through net.wlan and find unused device that can be created +# +wlan_get_unused() +{ + local idx + + idx=0 + + while : ; do + if ! ${SYSCTL_N} -q net.wlan.${idx}.%parent >/dev/null; then + echo "wlan${idx}" + break + fi + idx=$((${idx} + 1)) + done +} + +# wlan_is_parent +# check if given interface is parent for any existing wlan device +# +wlan_is_parent() +{ + sysctl -q net.wlan | grep -q "%parent: ${1}" +} + # wlan_up # Create IEEE 802.11 interfaces. # @@ -423,9 +449,31 @@ wlan_up() _prefix= _list= + local _rcconf _auto + _rcconf="" + _auto="" + + # Order detected devices so that interfaces configured via rc.conf are + # created first, and then all other devices are automatically assigned for parent in `${SYSCTL_N} -q net.wlan.devices`; do + child_wlans=`get_if_var $parent wlans_IF` + if [ -n "${child_wlans}" ]; then + _rcconf="${_rcconf} ${parent}" + else + _auto="${_auto} ${parent}" + fi + done + + for parent in ${_rcconf} ${_auto}; do + if wlan_is_parent $parent; then + continue + fi # Parse wlans_$parent="$child ..." child_wlans=`get_if_var $parent wlans_IF` + # Or find first unused wlan device to create + if [ -z "${child_wlans}" ]; then + child_wlans=`wlan_get_unused` + fi for child in ${child_wlans}; do if ifexists $child; then continue -- 2.41.0