From patchwork Mon Apr 8 16:11:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: michael-dev X-Patchwork-Id: 234824 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 92AE22C0168 for ; Tue, 9 Apr 2013 02:18:03 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 399119C175; Mon, 8 Apr 2013 12:17:44 -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 BzeucbN5rYP6; Mon, 8 Apr 2013 12:17:43 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 40F099C134; Mon, 8 Apr 2013 12:17:00 -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 76E609C133 for ; Mon, 8 Apr 2013 12:16:59 -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 yJg-u1ptGzk8 for ; Mon, 8 Apr 2013 12:16:55 -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 5CF6A9C11C for ; Mon, 8 Apr 2013 12:16:48 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.fem.tu-ilmenau.de (Postfix) with ESMTP id E34FC68E2; Mon, 8 Apr 2013 18:16:47 +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 cpjdlVGq-Kc0; Mon, 8 Apr 2013 18:16:46 +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:16:44 +0200 (CEST) Received: by a234.fem.tu-ilmenau.de (Postfix, from userid 1001) id 7BAF1D0A88; Mon, 8 Apr 2013 18:11:29 +0200 (CEST) From: michael-dev@fami-braun.de To: hostap@lists.shmoo.com Subject: [PATCH 4/6] parse untagged/tagged VLANs from config files Date: Mon, 8 Apr 2013 18:11:13 +0200 Message-Id: <1365437475-9295-5-git-send-email-michael-dev@fami-braun.de> X-Mailer: git-send-email 1.8.1.5 In-Reply-To: <1365437475-9295-1-git-send-email-michael-dev@fami-braun.de> References: <1365437475-9295-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 --- hostapd/config_file.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 115 insertions(+), 9 deletions(-) diff --git a/hostapd/config_file.c b/hostapd/config_file.c index 12d627a..a6ba770 100644 --- a/hostapd/config_file.c +++ b/hostapd/config_file.c @@ -19,6 +19,7 @@ #include "radius/radius_client.h" #include "ap/wpa_auth.h" #include "ap/ap_config.h" +#include "ap/vlan_init.h" #include "config_file.h" @@ -33,6 +34,10 @@ static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss, char buf[128], *pos, *pos2; int line = 0, vlan_id; struct hostapd_vlan *vlan; + struct vlan_info vlan_desc; + #ifdef CONFIG_VLAN_TAGGED + int i; + #endif f = fopen(fname, "r"); if (!f) { @@ -60,14 +65,65 @@ static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss, 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) { - wpa_printf(MSG_ERROR, "Invalid VLAN ID at " + os_memset(&vlan_desc, 0, sizeof(vlan_desc)); + pos = buf; + #ifdef CONFIG_VLAN_TAGGED + /* count number of tagged vlans, separated by minus */ + pos2 = pos; + while (*pos2 != '\0' && *pos2 != ' ' && *pos2 != '\t') { + if (*pos2 == 't') + vlan_desc.num_tagged++; + pos2++; + } + /* replace first minus with \0 for atoi */ + pos2 = pos; + while (*pos2 != '\0' && *pos2 != ' ' && *pos2 != '\t' && *pos2 != 't') + pos2++; + *pos2 = '\0'; pos2++; + #endif + vlan_desc.untagged = atoi(pos); + if (vlan_desc.untagged < 0 && vlan_desc.untagged > MAX_VLAN_ID) { + wpa_printf(MSG_ERROR, "Invalid VLAN ID %d at " + "line %d in '%s'", vlan_desc.untagged, line, fname); + fclose(f); + } + #ifndef CONFIG_VLAN_TAGGED + while (*pos != '\0' && *pos != ' ' && *pos != '\t') + pos++; + #else + pos = pos2; + if (vlan_desc.num_tagged > 0) { + vlan_desc.tagged = os_zalloc(sizeof(*vlan_desc.tagged) * vlan_desc.num_tagged); + if (!vlan_desc.tagged) { + wpa_printf(MSG_ERROR, "Out of memory parsing '%s' at " + "line %d in '%s'", buf, line, fname); + fclose(f); + return -1; + } + for (i=0; i < vlan_desc.num_tagged; i++) { + while (*pos2 != '\0' && *pos2 != ' ' && *pos2 != '\t' && *pos2 != 't') + pos2++; + *pos2 = '\0'; pos2++; + vlan_desc.tagged[i] = atoi(pos); + if (vlan_desc.tagged[i] < 1 && vlan_desc.tagged[i] > MAX_VLAN_ID) { + wpa_printf(MSG_ERROR, "Invalid tagged VLAN ID %d at " + "line %d in '%s'", vlan_desc.tagged[i], line, fname); + fclose(f); + } + pos = pos2; + } + vlan_cleanup(&vlan_desc); + } + #endif + if (!vlan_desc.untagged && !vlan_desc.num_tagged) { + wpa_printf(MSG_ERROR, "No VLAN ID at " "line %d in '%s'", line, fname); fclose(f); return -1; } + vlan_id = vlan_get_id(&vlan_desc); + os_free(vlan_desc.tagged); + os_memset(&vlan_desc, 0, sizeof(vlan_desc)); } while (*pos == ' ' || *pos == '\t') @@ -124,7 +180,11 @@ 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_info vlan_desc; + #ifdef CONFIG_VLAN_TAGGED + char *pos2; + int i; + #endif if (!fname) return 0; @@ -158,14 +218,58 @@ static int hostapd_config_read_maclist(const char *fname, return -1; } - vlan_id = 0; + os_memset(&vlan_desc, 0, sizeof(vlan_desc)); pos = buf; while (*pos != '\0' && *pos != ' ' && *pos != '\t') pos++; while (*pos == ' ' || *pos == '\t') pos++; - if (*pos != '\0') - vlan_id = atoi(pos); + if (*pos != '\0') { + #ifdef CONFIG_VLAN_TAGGED + /* count number of tagged vlans, separated by minus */ + pos2 = pos; + while (*pos2 != '\0' && *pos2 != ' ' && *pos2 != '\t') { + if (*pos2 == 't') + vlan_desc.num_tagged++; + pos2++; + } + /* replace first minus with \0 for atoi */ + pos2 = pos; + while (*pos2 != '\0' && *pos2 != ' ' && *pos2 != '\t' && *pos2 != 't') + pos2++; + *pos2 = '\0'; pos2++; + #endif + vlan_desc.untagged = atoi(pos); + if (vlan_desc.untagged < 0 && vlan_desc.untagged > MAX_VLAN_ID) { + wpa_printf(MSG_ERROR, "Invalid VLAN ID %d at " + "line %d in '%s'", vlan_desc.untagged, line, fname); + fclose(f); + } + #ifdef CONFIG_VLAN_TAGGED + if (vlan_desc.num_tagged > 0) { + vlan_desc.tagged = os_zalloc(sizeof(*vlan_desc.tagged) * vlan_desc.num_tagged); + if (!vlan_desc.tagged) { + wpa_printf(MSG_ERROR, "Out of memory parsing '%s' at " + "line %d in '%s'", buf, line, fname); + fclose(f); + return -1; + } + for (i=0; i < vlan_desc.num_tagged; i++) { + pos = pos2; + while (*pos2 != '\0' && *pos2 != ' ' && *pos2 != '\t' && *pos2 != 't') + pos2++; + *pos2 = '\0'; pos2++; + vlan_desc.tagged[i] = atoi(pos); + if (vlan_desc.tagged[i] < 1 && vlan_desc.tagged[i] > MAX_VLAN_ID) { + wpa_printf(MSG_ERROR, "Invalid tagged VLAN ID %d at " + "line %d in '%s'", vlan_desc.tagged[i], line, fname); + fclose(f); + } + } + vlan_cleanup(&vlan_desc); + } + #endif + } newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl)); if (newacl == NULL) { @@ -176,8 +280,10 @@ 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; + (*acl)[*num].vlan_id = vlan_get_id(&vlan_desc); (*num)++; + os_free(vlan_desc.tagged); + os_memset(&vlan_desc, 0, sizeof(vlan_desc)); } fclose(f);