Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 5 Sep 2017 21:53:35 +0000
From:      Kamil Choudhury <Kamil.Choudhury@anserinae.net>
To:        "freebsd-wireless@freebsd.org" <freebsd-wireless@freebsd.org>
Subject:   Configure hostapd(8) to manage multiple interfaces

| raw e-mail | index | archive | help
I've had this change floating around for a while to allow hostapd(8)=20
to manage multiple wireless interfaces using rc.conf...=20

In rc.conf, we specify our wireless interfaces:=20

> hostapd_ifaces=3D"wlan0 wlan1"

...and enable our hostapd as before:=20

> hostapd_enable=3D"YES"

Behind the scene, we need to create /etc/hostapd-wlan0.conf and=20
/etc/hostapd-wlan1.conf

Here are the diffs:=20

diff --git a/etc/rc.d/hostapd b/etc/rc.d/hostapd
index d0c2d88f2ff..43c6cf4e480 100755
--- a/etc/rc.d/hostapd
+++ b/etc/rc.d/hostapd
@@ -13,15 +13,27 @@ name=3D"hostapd"
 desc=3D"Authenticator for IEEE 802.11 networks"
 command=3D"/usr/sbin/${name}"

-ifn=3D"$2"
-if [ -z "$ifn" ]; then
-       rcvar=3D"hostapd_enable"
-       conf_file=3D"/etc/${name}.conf"
-       pidfile=3D"/var/run/${name}.pid"
+load_rc_config ${name}
+
+
+if [ -n "$hostapd_ifaces" ]; then
+        nl_hostapd_ifaces=3D`(echo $hostapd_ifaces | tr '\s+' '\n')`
+        for iface in $nl_hostapd_ifaces
+        do
+                conf_file=3D"/etc/${name}-${iface}.conf $conf_file"
+        done
+        pidfile=3D"/var/run/${name}.pid"
 else
-       rcvar=3D
-       conf_file=3D"/etc/${name}-${ifn}.conf"
-       pidfile=3D"/var/run/${name}-${ifn}.pid"
+        ifn=3D"$2"
+        if [ -z "$ifn" ]; then
+                rcvar=3D"hostapd_enable"
+                conf_file=3D"/etc/${name}.conf"
+                pidfile=3D"/var/run/${name}.pid"
+        else
+                rcvar=3D
+                conf_file=3D"/etc/${name}-${ifn}.conf"
+                pidfile=3D"/var/run/${name}-${ifn}.pid"
+        fi
 fi

 command_args=3D"-P ${pidfile} -B ${conf_file}"
@@ -29,5 +41,4 @@ required_files=3D"${conf_file}"
 required_modules=3D"wlan_xauth wlan_wep wlan_tkip wlan_ccmp"
 extra_commands=3D"reload"

-load_rc_config ${name}
 run_rc_command "$1"
diff --git a/share/man/man5/rc.conf.5 b/share/man/man5/rc.conf.5
index a03f4de5cb9..7217cbc1f16 100644
--- a/share/man/man5/rc.conf.5
+++ b/share/man/man5/rc.conf.5
@@ -409,6 +409,10 @@ Set to
 to start
 .Xr hostapd 8
 at system boot time.
+.It Va hostapd_ifaces
+.Pq Vt str
+Space separated list of interfaces managed by
+.Xr hostapd 8
 .It Va hostname
 .Pq Vt str
 The fully qualified domain name (FQDN) of this host on the network.

My shell isn't great, but the above changes do seem to work. Let me know
if there is interest in merging this, and if so, what I can do to move=20
the process ahead.=20

Thanks!=20

Kamil



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?>