[PATCH v5 10/22] VLAN: Use new VLAN data type in src_ap_vlan_init

Michael Braun michael-dev
Tue Nov 19 11:47:30 PST 2013


Signed-hostap: Michael Braun <michael-dev at fami-braun.de>
---
 src/ap/vlan_init.c |   72 ++++++++++++++++++++++++++++++++--------------------
 src/ap/vlan_init.h |   14 ++++++----
 2 files changed, 52 insertions(+), 34 deletions(-)

diff --git a/src/ap/vlan_init.c b/src/ap/vlan_init.c
index 1afbb8e..2fd1c50 100644
--- a/src/ap/vlan_init.c
+++ b/src/ap/vlan_init.c
@@ -614,14 +614,15 @@ static void vlan_newlink(char *ifname, struct hostapd_data *hapd)
 			if (hapd->conf->vlan_bridge[0]) {
 				os_snprintf(br_name, sizeof(br_name), "%s%d",
 					    hapd->conf->vlan_bridge,
-					    vlan->vlan_id);
+					    vlan_untagged(&vlan->vlan_id));
 			} else if (tagged_interface) {
 				os_snprintf(br_name, sizeof(br_name),
 				            "br%s.%d", tagged_interface,
-					    vlan->vlan_id);
+					    vlan_untagged(&vlan->vlan_id));
 			} else {
 				os_snprintf(br_name, sizeof(br_name),
-				            "brvlan%d", vlan->vlan_id);
+				            "brvlan%d",
+					    vlan_untagged(&vlan->vlan_id));
 			}
 
 			ret = br_addbr(br_name);
@@ -637,15 +638,19 @@ static void vlan_newlink(char *ifname, struct hostapd_data *hapd)
 					os_snprintf(vlan_ifname,
 						    sizeof(vlan_ifname),
 						    "%s.%d", tagged_interface,
-						    vlan->vlan_id);
+						    vlan_untagged(
+						      &vlan->vlan_id));
 				else
 					os_snprintf(vlan_ifname,
 						    sizeof(vlan_ifname),
-						    "vlan%d", vlan->vlan_id);
+						    "vlan%d",
+						    vlan_untagged(
+						      &vlan->vlan_id));
 
 				ifconfig_up(tagged_interface);
-				ret = vlan_add(tagged_interface, vlan->vlan_id,
-					      vlan_ifname);
+				ret = vlan_add(tagged_interface,
+				               vlan_untagged(&vlan->vlan_id),
+					       vlan_ifname);
 				if (hapd_get_dynamic_iface(NULL, vlan_ifname,
 				                           ret == 0, hapd))
 					vlan->clean |= DVLAN_CLEAN_VLAN;
@@ -690,14 +695,15 @@ static void vlan_dellink(char *ifname, struct hostapd_data *hapd)
 			if (hapd->conf->vlan_bridge[0]) {
 				os_snprintf(br_name, sizeof(br_name), "%s%d",
 					    hapd->conf->vlan_bridge,
-					    vlan->vlan_id);
+					    vlan_untagged(&vlan->vlan_id));
 			} else if (tagged_interface) {
-				os_snprintf(br_name, sizeof(br_name),
-				            "br%s.%d", tagged_interface,
-					    vlan->vlan_id);
+				os_snprintf(br_name, sizeof(br_name), "br%s.%d",
+					    tagged_interface,
+					    vlan_untagged(&vlan->vlan_id));
 			} else {
 				os_snprintf(br_name, sizeof(br_name),
-				            "brvlan%d", vlan->vlan_id);
+				            "brvlan%d",
+					    vlan_untagged(&vlan->vlan_id));
 			}
 
 			if ((vlan->clean & DVLAN_CLEAN_WLAN_PORT) &&
@@ -710,11 +716,14 @@ static void vlan_dellink(char *ifname, struct hostapd_data *hapd)
 					os_snprintf(vlan_ifname,
 						    sizeof(vlan_ifname),
 						    "%s.%d", tagged_interface,
-						    vlan->vlan_id);
+						    vlan_untagged(
+						      &vlan->vlan_id));
 				else
 					os_snprintf(vlan_ifname,
 						    sizeof(vlan_ifname),
-						    "vlan%d", vlan->vlan_id);
+						    "vlan%d",
+						    vlan_untagged(
+						      &vlan->vlan_id));
 				if ((vlan->clean & DVLAN_CLEAN_VLAN_PORT) &&
 				    hapd_put_dynamic_iface(br_name, vlan_ifname,
 							   hapd))
@@ -739,6 +748,8 @@ static void vlan_dellink(char *ifname, struct hostapd_data *hapd)
 			} else {
 				prev->next = vlan->next;
 			}
+
+			vlan_free(&vlan->vlan_id);
 			os_free(vlan);
 
 			break;
@@ -938,7 +949,7 @@ static int vlan_dynamic_add(struct hostapd_data *hapd,
 			    struct hostapd_vlan *vlan)
 {
 	while (vlan) {
-		if (vlan->vlan_id != VLAN_ID_WILDCARD) {
+		if (vlan_untagged(&vlan->vlan_id) != VLAN_ID_WILDCARD) {
 			if (hostapd_vlan_if_add(hapd, vlan->ifname)) {
 				if (errno != EEXIST) {
 					wpa_printf(MSG_ERROR, "VLAN: Could "
@@ -968,7 +979,7 @@ static void vlan_dynamic_remove(struct hostapd_data *hapd,
 	while (vlan) {
 		next = vlan->next;
 
-		if (vlan->vlan_id != VLAN_ID_WILDCARD &&
+		if (vlan_untagged(&vlan->vlan_id) != VLAN_ID_WILDCARD &&
 		    hostapd_vlan_if_remove(hapd, vlan->ifname)) {
 			wpa_printf(MSG_ERROR, "VLAN: Could not remove VLAN "
 				   "iface: %s: %s",
@@ -1001,7 +1012,7 @@ int vlan_init(struct hostapd_data *hapd)
 			return -1;
 		}
 
-		vlan->vlan_id = VLAN_ID_WILDCARD;
+		vlan_alloc(&vlan->vlan_id, VLAN_ID_WILDCARD);
 		os_snprintf(vlan->ifname, sizeof(vlan->ifname), "%s.#",
 			    hapd->conf->iface);
 		vlan->next = hapd->conf->vlan;
@@ -1028,17 +1039,18 @@ void vlan_deinit(struct hostapd_data *hapd)
 
 struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd,
 				       struct hostapd_vlan *vlan,
-				       int vlan_id)
+				       struct vlan_description vlan_id)
 {
 	struct hostapd_vlan *n;
 	char *ifname, *pos;
 
-	if (vlan == NULL || vlan_id <= 0 || vlan_id > MAX_VLAN_ID ||
-	    vlan->vlan_id != VLAN_ID_WILDCARD)
+	if (vlan == NULL || vlan_untagged(&vlan_id) <= 0 ||
+	    vlan_untagged(&vlan_id) > MAX_VLAN_ID ||
+	    vlan_untagged(&vlan->vlan_id) != VLAN_ID_WILDCARD)
 		return NULL;
 
 	wpa_printf(MSG_DEBUG, "VLAN: %s(vlan_id=%d ifname=%s)",
-		   __func__, vlan_id, vlan->ifname);
+		   __func__, vlan_untagged(&vlan_id), vlan->ifname);
 	ifname = os_strdup(vlan->ifname);
 	if (ifname == NULL)
 		return NULL;
@@ -1055,11 +1067,11 @@ struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd,
 		return NULL;
 	}
 
-	n->vlan_id = vlan_id;
+	vlan_alloc_copy(&n->vlan_id, &vlan_id);
 	n->dynamic_vlan = 1;
 
-	os_snprintf(n->ifname, sizeof(n->ifname), "%s%d%s", ifname, vlan_id,
-		    pos);
+	os_snprintf(n->ifname, sizeof(n->ifname), "%s%d%s", ifname,
+	            vlan_untagged(&vlan_id), pos);
 	os_free(ifname);
 
 	if (hostapd_vlan_if_add(hapd, n->ifname)) {
@@ -1078,18 +1090,22 @@ struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd,
 }
 
 
-int vlan_remove_dynamic(struct hostapd_data *hapd, int vlan_id)
+int vlan_remove_dynamic(struct hostapd_data *hapd,
+                        struct vlan_description vlan_id)
 {
 	struct hostapd_vlan *vlan;
 
-	if (vlan_id <= 0 || vlan_id > MAX_VLAN_ID)
+	if (vlan_untagged(&vlan_id) <= 0 ||
+	    vlan_untagged(&vlan_id) > MAX_VLAN_ID)
 		return 1;
 
-	wpa_printf(MSG_DEBUG, "VLAN: %s(vlan_id=%d)", __func__, vlan_id);
+	wpa_printf(MSG_DEBUG, "VLAN: %s(vlan_id=%d)", __func__,
+	           vlan_untagged(&vlan_id));
 
 	vlan = hapd->conf->vlan;
 	while (vlan) {
-		if (vlan->vlan_id == vlan_id && vlan->dynamic_vlan > 0) {
+		if (vlan_cmp(&vlan->vlan_id, &vlan_id) &&
+		    vlan->dynamic_vlan > 0) {
 			vlan->dynamic_vlan--;
 			break;
 		}
diff --git a/src/ap/vlan_init.h b/src/ap/vlan_init.h
index 382d5de..7237823 100644
--- a/src/ap/vlan_init.h
+++ b/src/ap/vlan_init.h
@@ -21,8 +21,9 @@ int vlan_init(struct hostapd_data *hapd);
 void vlan_deinit(struct hostapd_data *hapd);
 struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd,
 				       struct hostapd_vlan *vlan,
-				       int vlan_id);
-int vlan_remove_dynamic(struct hostapd_data *hapd, int vlan_id);
+				       struct vlan_description vlan_id);
+int vlan_remove_dynamic(struct hostapd_data *hapd,
+                        struct vlan_description vlan_id);
 int vlan_setup_encryption_dyn(struct hostapd_data *hapd,
 			      struct hostapd_ssid *mssid,
 			      const char *dyn_vlan);
@@ -36,14 +37,15 @@ static inline void vlan_deinit(struct hostapd_data *hapd)
 {
 }
 
-static inline struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd,
-						     struct hostapd_vlan *vlan,
-						     int vlan_id)
+static inline struct hostapd_vlan *
+vlan_add_dynamic(struct hostapd_data *hapd, struct hostapd_vlan *vlan,
+                 struct vlan_description vlan_id)
 {
 	return NULL;
 }
 
-static inline int vlan_remove_dynamic(struct hostapd_data *hapd, int vlan_id)
+static inline int vlan_remove_dynamic(struct hostapd_data *hapd,
+                                      struct vlan_description vlan_id)
 {
 	return -1;
 }




More information about the Hostap mailing list