[PATCH v4 06/25] VLAN: Use new VLAN data type in config

Michael Braun michael-dev
Sat Jul 27 12:54:56 PDT 2013


Signed-hostap: Michael Braun <michael-dev at fami-braun.de>
---
 hostapd/config_file.c |   24 ++++++++++++++----------
 src/ap/ap_config.c    |   14 ++++++++------
 src/ap/ap_config.h    |   12 +++++++-----
 3 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/hostapd/config_file.c b/hostapd/config_file.c
index e9d324f..45a2cb9 100644
--- a/hostapd/config_file.c
+++ b/hostapd/config_file.c
@@ -31,7 +31,8 @@ static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
 {
 	FILE *f;
 	char buf[128], *pos, *pos2;
-	int line = 0, vlan_id;
+	int line = 0;
+	vlan_t vlan_id = VLAN_NULL;
 	struct hostapd_vlan *vlan;
 
 	f = fopen(fname, "r");
@@ -57,17 +58,18 @@ static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
 			continue;
 
 		if (buf[0] == '*') {
-			vlan_id = VLAN_ID_WILDCARD;
+			vlan_alloc(&vlan_id, VLAN_ID_WILDCARD);
 			pos = buf + 1;
 		} else {
-			vlan_id = strtol(buf, &pos, 10);
-			if (buf == pos || vlan_id < 1 ||
-			    vlan_id > MAX_VLAN_ID) {
+			int untagged_vlan_id = strtol(buf, &pos, 10);
+			if (buf == pos || untagged_vlan_id < 1 ||
+			    untagged_vlan_id > MAX_VLAN_ID) {
 				wpa_printf(MSG_ERROR, "Invalid VLAN ID at "
 					   "line %d in '%s'", line, fname);
 				fclose(f);
 				return -1;
 			}
+			vlan_alloc(&vlan_id, untagged_vlan_id);
 		}
 
 		while (*pos == ' ' || *pos == '\t')
@@ -91,7 +93,8 @@ static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
 			return -1;
 		}
 
-		vlan->vlan_id = vlan_id;
+		vlan_alloc_copy(&vlan->vlan_id, &vlan_id);
+		vlan_free(&vlan_id);
 		os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
 		vlan->next = bss->vlan;
 		bss->vlan = vlan;
@@ -120,7 +123,7 @@ static int hostapd_config_read_maclist(const char *fname,
 	int line = 0;
 	u8 addr[ETH_ALEN];
 	struct mac_acl_entry *newacl;
-	int vlan_id;
+	vlan_t vlan_id = VLAN_NULL;
 
 	if (!fname)
 		return 0;
@@ -154,14 +157,14 @@ static int hostapd_config_read_maclist(const char *fname,
 			return -1;
 		}
 
-		vlan_id = 0;
+		vlan_id = VLAN_NULL;
 		pos = buf;
 		while (*pos != '\0' && *pos != ' ' && *pos != '\t')
 			pos++;
 		while (*pos == ' ' || *pos == '\t')
 			pos++;
 		if (*pos != '\0')
-			vlan_id = atoi(pos);
+			vlan_alloc(&vlan_id, atoi(pos));
 
 		newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
 		if (newacl == NULL) {
@@ -172,8 +175,9 @@ static int hostapd_config_read_maclist(const char *fname,
 
 		*acl = newacl;
 		os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
-		(*acl)[*num].vlan_id = vlan_id;
+		vlan_alloc_copy(&(*acl)[*num].vlan_id, &vlan_id);
 		(*num)++;
+		vlan_free(&vlan_id);
 	}
 
 	fclose(f);
diff --git a/src/ap/ap_config.c b/src/ap/ap_config.c
index 54a2e75..03da6a0 100644
--- a/src/ap/ap_config.c
+++ b/src/ap/ap_config.c
@@ -556,7 +556,7 @@ void hostapd_config_free(struct hostapd_config *conf)
  * Perform a binary search for given MAC address from a pre-sorted list.
  */
 int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
-			  const u8 *addr, int *vlan_id)
+			  const u8 *addr, vlan_t *vlan_id)
 {
 	int start, end, middle, res;
 
@@ -568,7 +568,7 @@ int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
 		res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
 		if (res == 0) {
 			if (vlan_id)
-				*vlan_id = list[middle].vlan_id;
+				vlan_alloc_copy(vlan_id, &list[middle].vlan_id);
 			return 1;
 		}
 		if (res < 0)
@@ -596,11 +596,12 @@ int hostapd_rate_found(int *list, int rate)
 }
 
 
-int hostapd_vlan_id_valid(struct hostapd_vlan *vlan, int vlan_id)
+int hostapd_vlan_id_valid(struct hostapd_vlan *vlan, vlan_t vlan_id)
 {
 	struct hostapd_vlan *v = vlan;
 	while (v) {
-		if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD)
+		if (vlan_cmp(&v->vlan_id, &vlan_id) ||
+		    vlan_untagged(&v->vlan_id) == VLAN_ID_WILDCARD)
 			return 1;
 		v = v->next;
 	}
@@ -608,11 +609,12 @@ int hostapd_vlan_id_valid(struct hostapd_vlan *vlan, int vlan_id)
 }
 
 
-const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
+const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan,
+                                        vlan_t vlan_id)
 {
 	struct hostapd_vlan *v = vlan;
 	while (v) {
-		if (v->vlan_id == vlan_id)
+		if (vlan_cmp(&v->vlan_id, &vlan_id))
 			return v->ifname;
 		v = v->next;
 	}
diff --git a/src/ap/ap_config.h b/src/ap/ap_config.h
index 9b87686..1e46f69 100644
--- a/src/ap/ap_config.h
+++ b/src/ap/ap_config.h
@@ -10,6 +10,7 @@
 #define HOSTAPD_CONFIG_H
 
 #include "common/defs.h"
+#include "common/vlan.h"
 #include "ip_addr.h"
 #include "common/wpa_common.h"
 #include "common/ieee802_11_common.h"
@@ -22,7 +23,7 @@ typedef u8 macaddr[ETH_ALEN];
 
 struct mac_acl_entry {
 	macaddr addr;
-	int vlan_id;
+	vlan_t vlan_id;
 };
 
 struct hostapd_radius_servers;
@@ -81,7 +82,8 @@ struct hostapd_ssid {
 
 struct hostapd_vlan {
 	struct hostapd_vlan *next;
-	int vlan_id; /* VLAN ID or -1 (VLAN_ID_WILDCARD) for wildcard entry */
+	/* untagged = VLAN ID or -1 (VLAN_ID_WILDCARD) for wildcard entry */
+	vlan_t vlan_id;
 	char ifname[IFNAMSIZ + 1];
 	int dynamic_vlan;
 #ifdef CONFIG_FULL_DYNAMIC_VLAN
@@ -541,16 +543,16 @@ struct hostapd_config * hostapd_config_defaults(void);
 void hostapd_config_defaults_bss(struct hostapd_bss_config *bss);
 void hostapd_config_free(struct hostapd_config *conf);
 int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
-			  const u8 *addr, int *vlan_id);
+			  const u8 *addr, vlan_t *vlan_id);
 int hostapd_rate_found(int *list, int rate);
 int hostapd_wep_key_cmp(struct hostapd_wep_keys *a,
 			struct hostapd_wep_keys *b);
 const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
 			   const u8 *addr, const u8 *prev_psk);
 int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf);
-int hostapd_vlan_id_valid(struct hostapd_vlan *vlan, int vlan_id);
+int hostapd_vlan_id_valid(struct hostapd_vlan *vlan, vlan_t vlan_id);
 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan,
-					int vlan_id);
+					vlan_t vlan_id);
 struct hostapd_radius_attr *
 hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type);
 




More information about the Hostap mailing list