[PATCH v3 08/25] VLAN: Use new VLAN data type in src_ap_ieee802_11

Michael Braun michael-dev
Sat Jul 27 09:11:31 PDT 2013


Signed-hostap: Michael Braun <michael-dev at fami-braun.de>
---
 src/ap/ieee802_11.c      |   18 ++++++++++--------
 src/ap/ieee802_11_auth.c |   13 +++++++------
 src/ap/ieee802_11_auth.h |    2 +-
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/src/ap/ieee802_11.c b/src/ap/ieee802_11.c
index 35282af..88f24ec 100644
--- a/src/ap/ieee802_11.c
+++ b/src/ap/ieee802_11.c
@@ -544,7 +544,7 @@ static void handle_auth(struct hostapd_data *hapd,
 	u16 fc;
 	const u8 *challenge = NULL;
 	u32 session_timeout, acct_interim_interval;
-	int vlan_id = 0;
+	vlan_t vlan_id = VLAN_NULL;
 	struct hostapd_sta_wpa_psk_short *psk = NULL;
 	u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
 	size_t resp_ies_len = 0;
@@ -649,19 +649,21 @@ static void handle_auth(struct hostapd_data *hapd,
 		goto fail;
 	}
 
-	if (vlan_id > 0) {
+	if (vlan_notempty(&vlan_id) && vlan_untagged(&vlan_id) >= 0) {
 		if (!hostapd_vlan_id_valid(hapd->conf->vlan, vlan_id)) {
 			hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
 				       HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
 				       "%d received from RADIUS server",
-				       vlan_id);
+				       vlan_untagged(&vlan_id));
 			resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
 			goto fail;
 		}
-		sta->vlan_id = vlan_id;
+		vlan_alloc_copy(&sta->vlan_id, &vlan_id);
 		hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
-			       HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
+			       HOSTAPD_LEVEL_INFO, "VLAN ID %d",
+			       vlan_untagged(&sta->vlan_id));
 	}
+	vlan_free(&vlan_id);
 
 	hostapd_free_psk_list(sta->psk);
 	if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
@@ -1960,11 +1962,11 @@ static void handle_assoc_cb(struct hostapd_data *hapd,
 		 * so bind it to the selected VLAN interface now, since the
 		 * interface selection is not going to change anymore.
 		 */
-		if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
+		if (ap_sta_bind_vlan(hapd, sta, VLAN_NULL) < 0)
 			goto fail;
-	} else if (sta->vlan_id) {
+	} else if (vlan_notempty(&sta->vlan_id)) {
 		/* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
-		if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
+		if (ap_sta_bind_vlan(hapd, sta, VLAN_NULL) < 0)
 			goto fail;
 	}
 
diff --git a/src/ap/ieee802_11_auth.c b/src/ap/ieee802_11_auth.c
index c311e55..604b54a 100644
--- a/src/ap/ieee802_11_auth.c
+++ b/src/ap/ieee802_11_auth.c
@@ -35,7 +35,7 @@ struct hostapd_cached_radius_acl {
 	struct hostapd_cached_radius_acl *next;
 	u32 session_timeout;
 	u32 acct_interim_interval;
-	int vlan_id;
+	vlan_t vlan_id;
 	struct hostapd_sta_wpa_psk_short *psk;
 	char *identity;
 	char *radius_cui;
@@ -58,6 +58,7 @@ static void hostapd_acl_cache_free_entry(struct hostapd_cached_radius_acl *e)
 	os_free(e->identity);
 	os_free(e->radius_cui);
 	hostapd_free_psk_list(e->psk);
+	vlan_free(&e->vlan_id);
 	os_free(e);
 }
 
@@ -99,7 +100,7 @@ static void copy_psk_list(struct hostapd_sta_wpa_psk_short **psk,
 
 static int hostapd_acl_cache_get(struct hostapd_data *hapd, const u8 *addr,
 				 u32 *session_timeout,
-				 u32 *acct_interim_interval, int *vlan_id,
+				 u32 *acct_interim_interval, vlan_t *vlan_id,
 				 struct hostapd_sta_wpa_psk_short **psk,
 				 char **identity, char **radius_cui)
 {
@@ -121,7 +122,7 @@ static int hostapd_acl_cache_get(struct hostapd_data *hapd, const u8 *addr,
 			*acct_interim_interval =
 				entry->acct_interim_interval;
 		if (vlan_id)
-			*vlan_id = entry->vlan_id;
+			vlan_alloc_copy(vlan_id, &entry->vlan_id);
 		copy_psk_list(psk, entry->psk);
 		if (identity) {
 			if (entry->identity)
@@ -230,7 +231,7 @@ static int hostapd_radius_acl_query(struct hostapd_data *hapd, const u8 *addr,
  */
 int hostapd_allowed_address(struct hostapd_data *hapd, const u8 *addr,
 			    const u8 *msg, size_t len, u32 *session_timeout,
-			    u32 *acct_interim_interval, int *vlan_id,
+			    u32 *acct_interim_interval, vlan_t *vlan_id,
 			    struct hostapd_sta_wpa_psk_short **psk,
 			    char **identity, char **radius_cui)
 {
@@ -239,7 +240,7 @@ int hostapd_allowed_address(struct hostapd_data *hapd, const u8 *addr,
 	if (acct_interim_interval)
 		*acct_interim_interval = 0;
 	if (vlan_id)
-		*vlan_id = 0;
+		vlan_free(vlan_id);
 	if (psk)
 		*psk = NULL;
 	if (identity)
@@ -539,7 +540,7 @@ hostapd_acl_recv_radius(struct radius_msg *msg, struct radius_msg *req,
 			cache->acct_interim_interval = 0;
 		}
 
-		cache->vlan_id = radius_msg_get_vlanid(msg);
+		vlan_alloc(&cache->vlan_id, radius_msg_get_vlanid(msg));
 
 		decode_tunnel_passwords(hapd, shared_secret, shared_secret_len,
 					msg, req, cache);
diff --git a/src/ap/ieee802_11_auth.h b/src/ap/ieee802_11_auth.h
index 2bc1065..69bde7e 100644
--- a/src/ap/ieee802_11_auth.h
+++ b/src/ap/ieee802_11_auth.h
@@ -18,7 +18,7 @@ enum {
 
 int hostapd_allowed_address(struct hostapd_data *hapd, const u8 *addr,
 			    const u8 *msg, size_t len, u32 *session_timeout,
-			    u32 *acct_interim_interval, int *vlan_id,
+			    u32 *acct_interim_interval, vlan_t *vlan_id,
 			    struct hostapd_sta_wpa_psk_short **psk,
 			    char **identity, char **radius_cui);
 int hostapd_acl_init(struct hostapd_data *hapd);




More information about the Hostap mailing list