Patchwork [v3,11/25] VLAN: Use new VLAN data type in src_ap_sta_info

login
register
mail settings
Submitter michael-dev@fami-braun.de
Date July 27, 2013, 4:13 p.m.
Message ID <20130727161349.1152.34790.stgit@ray-controller>
Download mbox | patch
Permalink /patch/262472/
State Superseded
Headers show

Comments

michael-dev@fami-braun.de - July 27, 2013, 4:13 p.m.
Signed-hostap: Michael Braun <michael-dev@fami-braun.de>
---
 src/ap/sta_info.c |   40 ++++++++++++++++++++++++----------------
 src/ap/sta_info.h |    6 ++++--
 2 files changed, 28 insertions(+), 18 deletions(-)

Patch

diff --git a/src/ap/sta_info.c b/src/ap/sta_info.c
index 39c9eb8..1082a3a 100644
--- a/src/ap/sta_info.c
+++ b/src/ap/sta_info.c
@@ -246,6 +246,8 @@  void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
 	os_free(sta->sae);
 #endif /* CONFIG_SAE */
 
+	vlan_free(&sta->vlan_id);
+
 	os_free(sta);
 }
 
@@ -661,7 +663,7 @@  int ap_sta_wps_cancel(struct hostapd_data *hapd,
 
 
 int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
-		     int old_vlanid)
+		     vlan_t old_vlanid)
 {
 #ifndef CONFIG_NO_VLAN
 	const char *iface;
@@ -672,14 +674,14 @@  int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
 	 * Do not proceed furthur if the vlan id remains same. We do not want
 	 * duplicate dynamic vlan entries.
 	 */
-	if (sta->vlan_id == old_vlanid)
+	if (vlan_cmp(&sta->vlan_id, &old_vlanid))
 		return 0;
 
 	/*
 	 * During 1x reauth, if the vlan id changes, then remove the old id and
 	 * proceed furthur to add the new one.
 	 */
-	if (old_vlanid > 0)
+	if (vlan_notempty(&old_vlanid) && vlan_untagged(&old_vlanid) >= 0)
 		vlan_remove_dynamic(hapd, old_vlanid);
 
 	iface = hapd->conf->iface;
@@ -687,14 +689,15 @@  int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
 		iface = sta->ssid->vlan;
 
 	if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
-		sta->vlan_id = 0;
-	else if (sta->vlan_id > 0) {
+		vlan_free(&sta->vlan_id);
+	else if (vlan_notempty(&sta->vlan_id) &&
+	         vlan_untagged(&sta->vlan_id) >= 0) {
 		vlan = hapd->conf->vlan;
 		struct hostapd_vlan *wildcard_vlan = NULL;
 		while (vlan) {
-			if (vlan->vlan_id == sta->vlan_id)
+			if (vlan_cmp(&vlan->vlan_id, &sta->vlan_id))
 				break;
-			if (vlan->vlan_id == VLAN_ID_WILDCARD)
+			if (vlan_untagged(&vlan->vlan_id) == VLAN_ID_WILDCARD)
 				wildcard_vlan = vlan;
 			vlan = vlan->next;
 		}
@@ -704,20 +707,23 @@  int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
 			iface = vlan->ifname;
 	}
 
-	if (sta->vlan_id > 0 && vlan == NULL) {
+	if (vlan_notempty(&sta->vlan_id) &&
+	    vlan_untagged(&sta->vlan_id) >= 0 && vlan == NULL) {
 		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
 			       HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
 			       "binding station to (vlan_id=%d)",
-			       sta->vlan_id);
+			       vlan_untagged(&sta->vlan_id));
 		return -1;
-	} else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) {
+	} else if (vlan_notempty(&sta->vlan_id) &&
+	           vlan_untagged(&sta->vlan_id) >= 0 &&
+		   vlan_untagged(&vlan->vlan_id) == VLAN_ID_WILDCARD) {
 		vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id);
 		if (vlan == NULL) {
 			hostapd_logger(hapd, sta->addr,
 				       HOSTAPD_MODULE_IEEE80211,
 				       HOSTAPD_LEVEL_DEBUG, "could not add "
 				       "dynamic VLAN interface for vlan_id=%d",
-				       sta->vlan_id);
+				       vlan_untagged(&sta->vlan_id));
 			return -1;
 		}
 
@@ -728,14 +734,15 @@  int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
 				       HOSTAPD_LEVEL_DEBUG, "could not "
 				       "configure encryption for dynamic VLAN "
 				       "interface for vlan_id=%d",
-				       sta->vlan_id);
+				       vlan_untagged(&sta->vlan_id));
 		}
 
 		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
 			       HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN "
 			       "interface '%s'", iface);
-	} else if (vlan && vlan->vlan_id == sta->vlan_id) {
-		if (sta->vlan_id > 0) {
+	} else if (vlan && vlan_cmp(&vlan->vlan_id, &sta->vlan_id)) {
+		if (vlan_notempty(&sta->vlan_id) &&
+		    vlan_untagged(&sta->vlan_id) >= 0) {
 			vlan->dynamic_vlan++;
 			hostapd_logger(hapd, sta->addr,
 				       HOSTAPD_MODULE_IEEE80211,
@@ -755,7 +762,7 @@  int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
 				       HOSTAPD_LEVEL_DEBUG, "could not "
 				       "configure encryption for VLAN "
 				       "interface for vlan_id=%d",
-				       sta->vlan_id);
+				       vlan_untagged(&sta->vlan_id));
 		}
 	}
 
@@ -770,7 +777,8 @@  int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
 	if (ret < 0) {
 		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
 			       HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
-			       "entry to vlan_id=%d", sta->vlan_id);
+			       "entry to vlan_id=%d",
+			       vlan_untagged(&sta->vlan_id));
 	}
 	return ret;
 #else /* CONFIG_NO_VLAN */
diff --git a/src/ap/sta_info.h b/src/ap/sta_info.h
index f8f5a83..c2d1525 100644
--- a/src/ap/sta_info.h
+++ b/src/ap/sta_info.h
@@ -9,6 +9,8 @@ 
 #ifndef STA_INFO_H
 #define STA_INFO_H
 
+#include "common/vlan.h"
+
 /* STA flags */
 #define WLAN_STA_AUTH BIT(0)
 #define WLAN_STA_ASSOC BIT(1)
@@ -95,7 +97,7 @@  struct sta_info {
 	struct hostapd_ssid *ssid; /* SSID selection based on (Re)AssocReq */
 	struct hostapd_ssid *ssid_probe; /* SSID selection based on ProbeReq */
 
-	int vlan_id;
+	vlan_t vlan_id;
 	 /* PSKs from RADIUS authentication server */
 	struct hostapd_sta_wpa_psk_short *psk;
 
@@ -174,7 +176,7 @@  int ap_sta_wps_cancel(struct hostapd_data *hapd,
 		      struct sta_info *sta, void *ctx);
 #endif /* CONFIG_WPS */
 int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
-		     int old_vlanid);
+		     vlan_t old_vlanid);
 void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta);
 void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta);
 int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta);