[PATCH v5 04/22] VLAN: Use new VLAN data type in config
Michael Braun
michael-dev
Tue Nov 19 11:46:59 PST 2013
Signed-hostap: Michael Braun <michael-dev at fami-braun.de>
---
hostapd/config_file.c | 24 ++++++++++++++----------
src/ap/ap_config.c | 15 +++++++++------
src/ap/ap_config.h | 13 ++++++++-----
3 files changed, 31 insertions(+), 21 deletions(-)
diff --git a/hostapd/config_file.c b/hostapd/config_file.c
index ae05917..bff58d0 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;
+ struct vlan_description 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;
+ struct vlan_description 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 65a6f12..808d86f 100644
--- a/src/ap/ap_config.c
+++ b/src/ap/ap_config.c
@@ -570,7 +570,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, struct vlan_description *vlan_id)
{
int start, end, middle, res;
@@ -582,7 +582,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)
@@ -610,11 +610,13 @@ 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,
+ struct vlan_description 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;
}
@@ -622,11 +624,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,
+ struct vlan_description 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 09b2778..e67a8e4 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;
+ struct vlan_description vlan_id;
};
struct hostapd_radius_servers;
@@ -83,7 +84,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 */
+ struct vlan_description vlan_id;
char ifname[IFNAMSIZ + 1];
int dynamic_vlan;
#ifdef CONFIG_FULL_DYNAMIC_VLAN
@@ -559,7 +561,7 @@ void hostapd_config_defaults_bss(struct hostapd_bss_config *bss);
void hostapd_config_free_bss(struct hostapd_bss_config *conf);
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, struct vlan_description *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);
@@ -567,9 +569,10 @@ const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
const u8 *addr, const u8 *p2p_dev_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,
+ struct vlan_description vlan_id);
const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan,
- int vlan_id);
+ struct vlan_description vlan_id);
struct hostapd_radius_attr *
hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type);
int hostapd_config_check(struct hostapd_config *conf);
More information about the Hostap
mailing list