From patchwork Mon Apr 8 16:18: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: 234831 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 355C22C0097 for ; Tue, 9 Apr 2013 02:20:16 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id A13889C1E6; Mon, 8 Apr 2013 12:19:40 -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 uroXt49-+IZD; Mon, 8 Apr 2013 12:19:39 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 92BBF9C1E7; Mon, 8 Apr 2013 12:19:10 -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 AC2F99C133 for ; Mon, 8 Apr 2013 12:19:06 -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 X9k82u5HzZCw for ; Mon, 8 Apr 2013 12:19:06 -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 B911A9C19B for ; Mon, 8 Apr 2013 12:18:42 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.fem.tu-ilmenau.de (Postfix) with ESMTP id 3E4EF683A; Mon, 8 Apr 2013 18:18:42 +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 I6on0RNGNw6U; Mon, 8 Apr 2013 18:18:42 +0200 (CEST) Received: from a234.fem.tu-ilmenau.de (unknown [10.42.51.234]) by mail.fem.tu-ilmenau.de (Postfix) with ESMTP; Mon, 8 Apr 2013 18:18:42 +0200 (CEST) Received: by a234.fem.tu-ilmenau.de (Postfix, from userid 1001) id 0155FCF05F; Mon, 8 Apr 2013 18:18:41 +0200 (CEST) From: michael-dev@fami-braun.de To: hostap@lists.shmoo.com Subject: [PATCH 2/6] vlan: transform untagged/tagged vlan description into vlan_id Date: Mon, 8 Apr 2013 18:18:37 +0200 Message-Id: <1365437921-11715-3-git-send-email-michael-dev@fami-braun.de> X-Mailer: git-send-email 1.8.1.5 In-Reply-To: <1365437921-11715-1-git-send-email-michael-dev@fami-braun.de> References: <1365437921-11715-1-git-send-email-michael-dev@fami-braun.de> 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: , MIME-Version: 1.0 Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com From: Michael Braun Signed-hostap: Michael Braun --- src/ap/vlan_init.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ap/vlan_init.h | 16 ++++++++++ 2 files changed, 107 insertions(+) diff --git a/src/ap/vlan_init.c b/src/ap/vlan_init.c index c25381d..27afbc8 100644 --- a/src/ap/vlan_init.c +++ b/src/ap/vlan_init.c @@ -35,6 +35,18 @@ #include "drivers/priv_netlink.h" #include "utils/eloop.h" +#endif /* CONFIG_FULL_DYNAMIC_VLAN */ + +#ifdef CONFIG_VLAN_TAGGED +struct vlan_info_list { + unsigned int counter; + unsigned int size; + struct vlan_info *vlan; +}; +static struct vlan_info_list vlan_mapping; +#endif /* CONFIG_VLAN_TAGGED */ + +#ifdef CONFIG_FULL_DYNAMIC_VLAN struct full_dynamic_vlan { int s; /* socket on which to listen for new/removed interfaces. */ @@ -952,3 +964,82 @@ int vlan_remove_dynamic(struct hostapd_data *hapd, int vlan_id) return 0; } + +#ifdef CONFIG_VLAN_TAGGED +static int cmp_vlan(const void *a, const void *b) +{ + const int *ia = (const int *) a; + const int *ib = (const int *) b; + return (*ia > *ib) - (*ia < *ib); +} + +/* make tagged vlans unique and sorted */ +void vlan_cleanup(struct vlan_info *a) { + int i, offset=0; + qsort(a->tagged, a->num_tagged, sizeof(int), cmp_vlan); + for (i=1; i < a->num_tagged; i++) { + if (a->tagged[i-1-offset] == a->tagged[i]) + offset++; + else if (offset > 0) + a->tagged[i-offset] = a->tagged[i]; + } + a->num_tagged -= offset; +} + +int vlan_equals(struct vlan_info *a, struct vlan_info *b) { + int i; + if (!a && !b) return 1; + if (!a || !b) return 0; + if (a->untagged != b->untagged) return 0; + if (a->num_tagged != b->num_tagged) return 0; + for (i=0; i < a->num_tagged; i++) + if (a->tagged[i] != b->tagged[i]) return 0; + return 1; +} + +int vlan_get_id(struct vlan_info* a) { + int i; + + /* no tagged/untagged vlan => vlan_id = 0 */ + if (!a) return 0; + if (!a->untagged && !a->num_tagged) return 0; + + /* all other untagged/tagged configurations get vlan_id > 0 */ + if(vlan_mapping.counter > vlan_mapping.size) { + wpa_printf(MSG_ERROR, "VLAN: internal mapping data structure is corrupt."); + return -1; + } + for (i=0; i < vlan_mapping.counter; i++) + if (vlan_equals(a, &vlan_mapping.vlan[i])) + return i + 1; + /* resize cache, amortized O(1) */ + if (vlan_mapping.size == vlan_mapping.counter) { + unsigned int newsize = 2 * vlan_mapping.size; + if (newsize == 0) + newsize = 1; + if (newsize < vlan_mapping.size) /* overflow */ + return -1; + struct vlan_info *new_vlan = os_malloc(sizeof(struct vlan_info) * newsize); + if (!new_vlan) + return -1; + if (vlan_mapping.size > 0) + os_memcpy(new_vlan, vlan_mapping.vlan, sizeof(struct vlan_info) * vlan_mapping.size); + os_free(vlan_mapping.vlan); + vlan_mapping.vlan = new_vlan; new_vlan = NULL; + vlan_mapping.size = newsize; + } + /* add new entry */ + vlan_mapping.vlan[vlan_mapping.counter] = *a; + vlan_mapping.counter++; + + char buf[IFNAMSIZ], *pos; + pos = buf; + pos += os_snprintf(pos, sizeof(buf) + buf - pos, "%d", a->untagged); + for (i=0; i < a->num_tagged; i++) { + pos += os_snprintf(pos, sizeof(buf) + buf - pos, "t%d", a->tagged[i]); + } + + wpa_printf(MSG_DEBUG, "VLAN: assign %s to %d", buf, vlan_mapping.counter); + return vlan_mapping.counter; +} +#endif diff --git a/src/ap/vlan_init.h b/src/ap/vlan_init.h index 382d5de..75fda69 100644 --- a/src/ap/vlan_init.h +++ b/src/ap/vlan_init.h @@ -17,6 +17,12 @@ #define VLAN_INIT_H #ifndef CONFIG_NO_VLAN +struct vlan_info { + int untagged; + unsigned int num_tagged; + int* tagged; +}; + int vlan_init(struct hostapd_data *hapd); void vlan_deinit(struct hostapd_data *hapd); struct hostapd_vlan * vlan_add_dynamic(struct hostapd_data *hapd, @@ -26,6 +32,16 @@ int vlan_remove_dynamic(struct hostapd_data *hapd, int vlan_id); int vlan_setup_encryption_dyn(struct hostapd_data *hapd, struct hostapd_ssid *mssid, const char *dyn_vlan); +#ifdef CONFIG_VLAN_TAGGED +int vlan_get_id(struct vlan_info *a); +void vlan_cleanup(struct vlan_info *a); +#else +static inline int vlan_get_id(struct vlan_info *a) { + if (!a) return 0; + return a->untagged; +} +#endif /* VLAN_CONFIG_TAGGED */ + #else /* CONFIG_NO_VLAN */ static inline int vlan_init(struct hostapd_data *hapd) {