Patchwork [v4,09/25] VLAN: Use new VLAN data type in src_ap_ieee802_1x.c

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

Comments

michael-dev@fami-braun.de - July 27, 2013, 7:55 p.m.
Signed-hostap: Michael Braun <michael-dev@fami-braun.de>
---
 src/ap/ieee802_1x.c |   32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

Patch

diff --git a/src/ap/ieee802_1x.c b/src/ap/ieee802_1x.c
index d9f6b38..38c5b08 100644
--- a/src/ap/ieee802_1x.c
+++ b/src/ap/ieee802_1x.c
@@ -191,7 +191,7 @@  void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
 	struct eapol_authenticator *eapol = hapd->eapol_auth;
 	struct eapol_state_machine *sm = sta->eapol_sm;
 #ifndef CONFIG_NO_VLAN
-	int vlan_id;
+	vlan_t *vlan_id = NULL;
 #endif /* CONFIG_NO_VLAN */
 
 	if (sm == NULL || !sm->eap_if->eapKeyData)
@@ -201,9 +201,10 @@  void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
 		   MAC2STR(sta->addr));
 
 #ifndef CONFIG_NO_VLAN
-	vlan_id = sta->vlan_id;
-	if (vlan_id < 0 || vlan_id > MAX_VLAN_ID)
-		vlan_id = 0;
+	vlan_id = &sta->vlan_id;
+	if (!vlan_notempty(vlan_id) || vlan_untagged(vlan_id) < 0 ||
+	    vlan_untagged(vlan_id) > MAX_VLAN_ID)
+		vlan_id = NULL;
 
 	if (vlan_id) {
 		wpa_printf(MSG_ERROR, "Using WEP with vlans is not supported.");
@@ -918,7 +919,7 @@  void ieee802_1x_new_station(struct hostapd_data *hapd, struct sta_info *sta)
 
 	pmksa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
 	if (pmksa) {
-		int old_vlanid;
+		vlan_t old_vlanid = VLAN_NULL;
 
 		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
 			       HOSTAPD_LEVEL_DEBUG,
@@ -933,11 +934,12 @@  void ieee802_1x_new_station(struct hostapd_data *hapd, struct sta_info *sta)
 		sta->eapol_sm->authFail = FALSE;
 		if (sta->eapol_sm->eap)
 			eap_sm_notify_cached(sta->eapol_sm->eap);
-		old_vlanid = sta->vlan_id;
+		vlan_alloc_copy(&old_vlanid, &sta->vlan_id);
 		pmksa_cache_to_eapol_data(pmksa, sta->eapol_sm);
 		if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
-			sta->vlan_id = 0;
+			vlan_free(&sta->vlan_id);
 		ap_sta_bind_vlan(hapd, sta, old_vlanid);
+		vlan_free(&old_vlanid);
 	} else {
 		if (reassoc) {
 			/*
@@ -1258,7 +1260,8 @@  ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
 	struct hostapd_data *hapd = data;
 	struct sta_info *sta;
 	u32 session_timeout = 0, termination_action, acct_interim_interval;
-	int session_timeout_set, old_vlanid = 0;
+	int session_timeout_set;
+	vlan_t old_vlanid = VLAN_NULL;
 	struct eapol_state_machine *sm;
 	int override_eapReq = 0;
 	struct radius_hdr *hdr = radius_msg_get_hdr(msg);
@@ -1327,18 +1330,20 @@  ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
 	switch (hdr->code) {
 	case RADIUS_CODE_ACCESS_ACCEPT:
 		if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
-			sta->vlan_id = 0;
+			vlan_free(&sta->vlan_id);
 #ifndef CONFIG_NO_VLAN
 		else {
-			old_vlanid = sta->vlan_id;
-			sta->vlan_id = radius_msg_get_vlanid(msg);
+			vlan_alloc_copy(&old_vlanid, &sta->vlan_id);
+			vlan_alloc(&sta->vlan_id, radius_msg_get_vlanid(msg));
 		}
-		if (sta->vlan_id > 0 &&
+		if (vlan_notempty(&sta->vlan_id) &&
+		    vlan_untagged(&sta->vlan_id) > 0 &&
 		    hostapd_vlan_id_valid(hapd->conf->vlan, sta->vlan_id)) {
 			hostapd_logger(hapd, sta->addr,
 				       HOSTAPD_MODULE_RADIUS,
 				       HOSTAPD_LEVEL_INFO,
-				       "VLAN ID %d", sta->vlan_id);
+				       "VLAN ID %d",
+				       vlan_untagged(&sta->vlan_id));
 		} else if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_REQUIRED) {
 			sta->eapol_sm->authFail = TRUE;
 			hostapd_logger(hapd, sta->addr,
@@ -1352,6 +1357,7 @@  ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
 
 		if (ap_sta_bind_vlan(hapd, sta, old_vlanid) < 0)
 			break;
+		vlan_free(&old_vlanid);
 
 		/* RFC 3580, Ch. 3.17 */
 		if (session_timeout_set && termination_action ==