When using mac80211 it is only possible to configure one macfile per phy
interface in hostapd. This patch enables the user to create one macfile for each
single AP Virtual Interface. In this way each interface has its own list of mac
addresses and its own rule (macaddr_acl).

At the same time, this patch enables the user to specify a custom filename
for the macfile (option macfile in config/wireless) instead of providing a list
of mac addresses in the config file directly

Signed-off-by: Antonio Quartulli <or...@autistici.org>
---
 package/hostapd/files/hostapd.sh            |   31 ++++++++++++++++++++++++++-
 package/mac80211/files/lib/wifi/mac80211.sh |   22 +------------------
 2 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/package/hostapd/files/hostapd.sh b/package/hostapd/files/hostapd.sh
index 1006230..04b0d3c 100644
--- a/package/hostapd/files/hostapd.sh
+++ b/package/hostapd/files/hostapd.sh
@@ -1,6 +1,8 @@
 hostapd_set_bss_options() {
        local var="$1"
        local vif="$2"
+       local ifname="$3"
+       local driver="$4"
        local enc wep_rekey wpa_group_rekey wpa_pair_rekey wpa_master_rekey 
wps_possible
 
        config_get enc "$vif" encryption
@@ -10,6 +12,33 @@ hostapd_set_bss_options() {
        config_get wpa_master_rekey "$vif" wpa_master_rekey # 640
        config_get_bool ap_isolate "$vif" isolate 0
 
+       [ "$driver" = "mac80211" ] && {
+               config_get macfile "$vif" macfile
+               [ -e "$macfile" ] || macfile=""
+               [ -n "$macfilter" -a -z "$macfile" ] && {
+                       macfile="/var/run/hostapd-$ifname.maclist"
+                       [ -e "$macfile" ] && rm -f "$macfile"
+                       config_get maclist "$vif" maclist
+                       [ -n "$maclist" ] && {
+                               for mac in $maclist; do
+                                       echo "$mac" >> $macfile
+                               done
+                       } || echo "No maclist specified"
+               }
+
+               config_get macfilter "$vif" macfilter
+               case "$macfilter" in
+                       allow)
+                               append "$var" "macaddr_acl=1" "$N"
+                               append "$var" "accept_mac_file=$macfile" "$N"
+                               ;;
+                       deny)
+                               append "$var" "macaddr_acl=0" "$N"
+                               append "$var" "deny_mac_file=$macfile" "$N"
+                               ;;
+               esac
+       }
+
        config_get device "$vif" device
        config_get hwmode "$device" hwmode
        config_get phy "$device" phy
@@ -243,7 +272,7 @@ hostapd_setup_vif() {
        config_get hwmode "$device" hwmode
 
        hostapd_set_log_options hostapd_cfg "$device"
-       hostapd_set_bss_options hostapd_cfg "$vif"
+       hostapd_set_bss_options hostapd_cfg "$vif" "$ifname" "$driver"
 
        case "$hwmode" in
                *bg|*gdt|*gst|*fh) hwmode=g;;
diff --git a/package/mac80211/files/lib/wifi/mac80211.sh 
b/package/mac80211/files/lib/wifi/mac80211.sh
index 1a4d7c1..b941d8e 100644
--- a/package/mac80211/files/lib/wifi/mac80211.sh
+++ b/package/mac80211/files/lib/wifi/mac80211.sh
@@ -6,8 +6,6 @@ mac80211_hostapd_setup_base() {
        local ifname="$2"
 
        cfgfile="/var/run/hostapd-$phy.conf"
-       macfile="/var/run/hostapd-$phy.maclist"
-       [ -e "$macfile" ] && rm -f "$macfile"
 
        config_get device "$vif" device
        config_get country "$device" country
@@ -51,24 +49,6 @@ mac80211_hostapd_setup_base() {
        config_get_bool country_ie "$device" country_ie "$country_ie"
        [ "$country_ie" -gt 0 ] && append base_cfg "ieee80211d=1" "$N"
 
-       config_get macfilter "$vif" macfilter
-       case "$macfilter" in
-               allow)
-                       append base_cfg "macaddr_acl=1" "$N"
-                       append base_cfg "accept_mac_file=$macfile" "$N"
-                       ;;
-               deny)
-                       append base_cfg "macaddr_acl=0" "$N"
-                       append base_cfg "deny_mac_file=$macfile" "$N"
-                       ;;
-       esac
-       config_get maclist "$vif" maclist
-       [ -n "$maclist" ] && {
-               for mac in $maclist; do
-                       echo "$mac" >> $macfile
-               done
-       }
-
        local br brval brstr
        [ -n "$basic_rate_list" ] && {
                for br in $basic_rate_list; do
@@ -150,7 +130,7 @@ mac80211_hostapd_setup_bss() {
        [ -z "$net_cfg" ] || bridge="$(bridge_interface "$net_cfg")"
        config_set "$vif" bridge "$bridge"
 
-       hostapd_set_bss_options hostapd_cfg "$vif"
+       hostapd_set_bss_options hostapd_cfg "$vif" "$ifname" mac80211
 
        config_get_bool wds "$vif" wds 0
        [ "$wds" -gt 0 ] && append hostapd_cfg "wds_sta=1" "$N"
-- 
1.7.9.4

_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to