From patchwork Sat Jul 27 16:10:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: michael-dev X-Patchwork-Id: 262467 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "maxx.shmoo.com", Issuer "CA Cert Signing Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 265712C00C1 for ; Sun, 28 Jul 2013 02:11:14 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 249BF9D34F; Sat, 27 Jul 2013 12:11:12 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AoqlzvGS1DF7; Sat, 27 Jul 2013 12:11:11 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 616DD9D36C; Sat, 27 Jul 2013 12:10:58 -0400 (EDT) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 816A39D34F for ; Sat, 27 Jul 2013 12:10:56 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KmUK9HFIEDyY for ; Sat, 27 Jul 2013 12:10:51 -0400 (EDT) Received: from mail.fem.tu-ilmenau.de (mail.fem.tu-ilmenau.de [141.24.101.79]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id CF76D9D38B for ; Sat, 27 Jul 2013 12:10:38 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.fem.tu-ilmenau.de (Postfix) with ESMTP id 5C2F9656D for ; Sat, 27 Jul 2013 18:10:38 +0200 (CEST) X-Virus-Scanned: amavisd-new at fem.tu-ilmenau.de Received: from mail.fem.tu-ilmenau.de ([127.0.0.1]) by localhost (mail.fem.tu-ilmenau.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6e9LKJWEWQOq; Sat, 27 Jul 2013 18:10:37 +0200 (CEST) Received: from a234.fem.tu-ilmenau.de (unknown [10.42.51.234]) by mail.fem.tu-ilmenau.de (Postfix) with ESMTP; Sat, 27 Jul 2013 18:10:37 +0200 (CEST) Received: from [10.42.51.234] (localhost [127.0.0.1]) by a234.fem.tu-ilmenau.de (Postfix) with ESMTP id 83F14BD0; Sat, 27 Jul 2013 18:10:37 +0200 (CEST) Subject: [PATCH v3 06/25] VLAN: Use new VLAN data type in config To: hostap@lists.shmoo.com From: Michael Braun Date: Sat, 27 Jul 2013 18:10:37 +0200 Message-ID: <20130727161032.1152.55649.stgit@ray-controller> In-Reply-To: <20130727160024.1152.46147.stgit@ray-controller> References: <20130727160024.1152.46147.stgit@ray-controller> User-Agent: StGit/0.16 MIME-Version: 1.0 Cc: projekt-wlan@fem.tu-ilmenau.de X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.11 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com Signed-hostap: Michael Braun --- hostapd/config_file.c | 24 ++++++++++++++---------- src/ap/ap_config.c | 14 ++++++++------ src/ap/ap_config.h | 12 +++++++----- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/hostapd/config_file.c b/hostapd/config_file.c index e9d324f..45a2cb9 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; + vlan_t 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; + vlan_t 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 54a2e75..03da6a0 100644 --- a/src/ap/ap_config.c +++ b/src/ap/ap_config.c @@ -556,7 +556,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, vlan_t *vlan_id) { int start, end, middle, res; @@ -568,7 +568,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) @@ -596,11 +596,12 @@ 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, vlan_t 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; } @@ -608,11 +609,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, + vlan_t 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 9b87686..1e46f69 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; + vlan_t vlan_id; }; struct hostapd_radius_servers; @@ -81,7 +82,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 */ + vlan_t vlan_id; char ifname[IFNAMSIZ + 1]; int dynamic_vlan; #ifdef CONFIG_FULL_DYNAMIC_VLAN @@ -541,16 +543,16 @@ struct hostapd_config * hostapd_config_defaults(void); void hostapd_config_defaults_bss(struct hostapd_bss_config *bss); 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, vlan_t *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); const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf, const u8 *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, vlan_t vlan_id); const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, - int vlan_id); + vlan_t vlan_id); struct hostapd_radius_attr * hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type);