diff mbox

make vlan_file optional

Message ID 0f8e5db2aa9bc2708f8affed3df0bc35@fami-braun.de
State Accepted
Commit 7ca902b53ed69d2dc047c83fc1e396de2f6e9429
Headers show

Commit Message

michael-dev April 7, 2013, 9:02 p.m. UTC
Hi,

currently hostapd depends on vlan_file even if all vlan interfaces get 
generated by full_dynamic_vlan.
This makes it a little bit complicated to generate a hostapd 
configuration files on the ap on-the-fly as needed, as one will always 
need to generate bss-specific vlan_files too.
The attached patch makes life easier by using the "<device>.<vlan-id>" 
scheme if no vlan_file entries are provided and dynamic vlans are 
enabled.

Regards,
  M. Braun
commit 73c078616a713b9e83b91fa879cb4d7a8f91b888
Author: Michael Braun <michael-dev@fami-braun.de>
Date:   Sun Apr 7 22:28:09 2013 +0200

    Make vlan_file optional if dynamic_vlan is used
    
    My APs generate their configuration on their own using a different number of
    (vlan-enabled) bss. Currently, all my vlan_file files consist of a single
    line:  the wildcard line. Configuration file generation would be easier, if
    the hostapd configuration file would not depend on those simple vlan_file files.
    
    This patch removes the need for those one-line files by using the <device>.<vlan>
    naming scheme if no vlan_file is given (or that file is empty).
    This should not break any existing setup, as using dynamic_vlan with no vlan
    configured does not make sense anyway.
    
    Signed-hostap: Michael Braun <michael-dev@fami-braun.de>

Comments

Jouni Malinen April 27, 2013, 8:10 p.m. UTC | #1
On Sun, Apr 07, 2013 at 11:02:03PM +0200, michael-dev wrote:
> currently hostapd depends on vlan_file even if all vlan interfaces
> get generated by full_dynamic_vlan.
> This makes it a little bit complicated to generate a hostapd
> configuration files on the ap on-the-fly as needed, as one will
> always need to generate bss-specific vlan_files too.
> The attached patch makes life easier by using the
> "<device>.<vlan-id>" scheme if no vlan_file entries are provided and
> dynamic vlans are enabled.

Thanks, applied.
diff mbox

Patch

diff --git a/hostapd/hostapd.conf b/hostapd/hostapd.conf
index 17bb7ed..49b60bd 100644
--- a/hostapd/hostapd.conf
+++ b/hostapd/hostapd.conf
@@ -814,9 +814,8 @@  own_ip_addr=127.0.0.1
 # is used for the stations. This information is parsed from following RADIUS
 # attributes based on RFC 3580 and RFC 2868: Tunnel-Type (value 13 = VLAN),
 # Tunnel-Medium-Type (value 6 = IEEE 802), Tunnel-Private-Group-ID (value
-# VLANID as a string). vlan_file option below must be configured if dynamic
-# VLANs are used. Optionally, the local MAC ACL list (accept_mac_file) can be
-# used to set static client MAC address to VLAN ID mapping.
+# VLANID as a string). Optionally, the local MAC ACL list (accept_mac_file) can
+# be used to set static client MAC address to VLAN ID mapping.
 # 0 = disabled (default)
 # 1 = option; use default interface if RADIUS server does not include VLAN ID
 # 2 = required; reject authentication if RADIUS server does not include VLAN ID
@@ -828,6 +827,8 @@  own_ip_addr=127.0.0.1
 # multiple BSSIDs or SSIDs. Each line in this text file is defining a new
 # interface and the line must include VLAN ID and interface name separated by
 # white space (space or tab).
+# If no entries are provided by this file, the station is statically mapped
+# to <bss-iface>.<vlan-id> interfaces.
 #vlan_file=/etc/hostapd.vlan
 
 # Interface where 802.1q tagged packets should appear when a RADIUS server is
diff --git a/src/ap/vlan_init.c b/src/ap/vlan_init.c
index 7b1a9e6..c25381d 100644
--- a/src/ap/vlan_init.c
+++ b/src/ap/vlan_init.c
@@ -837,6 +837,26 @@  int vlan_init(struct hostapd_data *hapd)
 	hapd->full_dynamic_vlan = full_dynamic_vlan_init(hapd);
 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
 
+	if (hapd->conf->ssid.dynamic_vlan != DYNAMIC_VLAN_DISABLED && !hapd->conf->vlan) {
+		/* dynamic vlans enabled but no (or empty) vlan_file given */
+		struct hostapd_vlan *vlan;
+		vlan = os_malloc(sizeof(*vlan));
+		if (vlan == NULL) {
+			wpa_printf(MSG_ERROR, "Out of memory while assinging "
+				   "VLAN interfaces");
+			return -1;
+		}
+
+		os_memset(vlan, 0, sizeof(*vlan));
+		vlan->vlan_id = VLAN_ID_WILDCARD;
+		snprintf(vlan->ifname, sizeof(vlan->ifname), "%s.#", hapd->conf->iface);
+		if (hapd->conf->vlan_tail)
+			hapd->conf->vlan_tail->next = vlan;
+		else
+			hapd->conf->vlan = vlan;
+		hapd->conf->vlan_tail = vlan;
+	}
+
 	if (vlan_dynamic_add(hapd, hapd->conf->vlan))
 		return -1;