From patchwork Thu Apr 11 09:52:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: michael-dev X-Patchwork-Id: 235671 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]) by ozlabs.org (Postfix) with ESMTP id 61C302C00B1 for ; Thu, 11 Apr 2013 19:53:36 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 09F6B9D2EF; Thu, 11 Apr 2013 05:53: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 X9C4oOf9Lw0A; Thu, 11 Apr 2013 05:53:11 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id C9E119D28D; Thu, 11 Apr 2013 05:52:50 -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 A47E39D203 for ; Thu, 11 Apr 2013 05:52:47 -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 hjGI1AogOfBC for ; Thu, 11 Apr 2013 05:52:47 -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 4477E9D25D for ; Thu, 11 Apr 2013 05:52:47 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.fem.tu-ilmenau.de (Postfix) with ESMTP id B725B6675; Thu, 11 Apr 2013 11:52:46 +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 x8rGOot6jb-S; Thu, 11 Apr 2013 11:52:46 +0200 (CEST) Received: from a234.fem.tu-ilmenau.de (unknown [10.42.51.234]) by mail.fem.tu-ilmenau.de (Postfix) with ESMTP; Thu, 11 Apr 2013 11:52:46 +0200 (CEST) Received: by a234.fem.tu-ilmenau.de (Postfix, from userid 1001) id 62500CFA38; Thu, 11 Apr 2013 11:52:46 +0200 (CEST) From: michael-dev@fami-braun.de To: hostap@lists.shmoo.com Subject: [PATCHv3 5/6] radius: parse tagged vlan information Date: Thu, 11 Apr 2013 11:52:43 +0200 Message-Id: <1365673964-17831-6-git-send-email-michael-dev@fami-braun.de> X-Mailer: git-send-email 1.8.1.5 In-Reply-To: <1365673964-17831-1-git-send-email-michael-dev@fami-braun.de> References: <1365673964-17831-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/radius/radius.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- src/radius/radius.h | 1 + 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/radius/radius.c b/src/radius/radius.c index d1feec9..93b9541 100644 --- a/src/radius/radius.c +++ b/src/radius/radius.c @@ -12,6 +12,8 @@ #include "utils/wpabuf.h" #include "crypto/md5.h" #include "crypto/crypto.h" +#include "ap/hostapd.h" +#include "ap/vlan_init.h" #include "radius.h" @@ -214,6 +216,8 @@ static struct radius_attr_type radius_attrs[] = RADIUS_ATTR_INT32 }, { RADIUS_ATTR_EVENT_TIMESTAMP, "Event-Timestamp", RADIUS_ATTR_INT32 }, + { RADIUS_ATTR_EGRESS_VLANID, "Egress-VLANID", + RADIUS_ATTR_INT32 }, { RADIUS_ATTR_NAS_PORT_TYPE, "NAS-Port-Type", RADIUS_ATTR_INT32 }, { RADIUS_ATTR_TUNNEL_TYPE, "Tunnel-Type", RADIUS_ATTR_HEXDUMP }, { RADIUS_ATTR_TUNNEL_MEDIUM_TYPE, "Tunnel-Medium-Type", @@ -1342,8 +1346,10 @@ int radius_msg_get_vlanid(struct radius_msg *msg) const u8 *data; char buf[10]; size_t dlen; + struct vlan_info ret; os_memset(&tunnel, 0, sizeof(tunnel)); + os_memset(&ret, 0, sizeof(ret)); for (i = 0; i < msg->attr_used; i++) { attr = radius_get_attr_hdr(msg, i); @@ -1383,6 +1389,28 @@ int radius_msg_get_vlanid(struct radius_msg *msg) tun->tag_used++; tun->vlanid = atoi(buf); break; + case RADIUS_ATTR_EGRESS_VLANID: /* RFC 4675 */ + if (attr->length != 6) + break; + int vlan_id = WPA_GET_BE24(data + 1); + if (vlan_id <= 0 || vlan_id > MAX_VLAN_ID) + break; + if (data[0] == 0x31) { /* tagged vlan */ + #ifdef CONFIG_VLAN_TAGGED + int* new_tagged = os_zalloc(sizeof(int) * (ret.num_tagged + 1)); + if (!new_tagged) + break; + if (ret.num_tagged > 0) + os_memcpy(new_tagged, ret.tagged, sizeof(int) * ret.num_tagged); + new_tagged[ret.num_tagged] = vlan_id; + os_free(ret.tagged); + ret.tagged = new_tagged; + ret.num_tagged++; + #endif /* CONFIG_VLAN_TAGGED */ + } else if (data[0] == 0x32) { /* untagged vlan */ + ret.untagged = vlan_id; + } + break; } } @@ -1392,12 +1420,23 @@ int radius_msg_get_vlanid(struct radius_msg *msg) tun->type == RADIUS_TUNNEL_TYPE_VLAN && tun->medium_type == RADIUS_TUNNEL_MEDIUM_TYPE_802 && tun->vlanid > 0) - return tun->vlanid; + { + ret.untagged = tun->vlanid; + break; + } } - return -1; -} + if (ret.untagged < 0 || ret.untagged > MAX_VLAN_ID) + ret.untagged = 0; + #ifdef CONFIG_VLAN_TAGGED + vlan_cleanup(&ret); + #endif + if (!ret.untagged && !ret.tagged) + return -1; + + return vlan_get_id(&ret); +} /** * radius_msg_get_tunnel_password - Parse RADIUS attribute Tunnel-Password diff --git a/src/radius/radius.h b/src/radius/radius.h index 2031054..e0ebe6d 100644 --- a/src/radius/radius.h +++ b/src/radius/radius.h @@ -79,6 +79,7 @@ enum { RADIUS_ATTR_USER_NAME = 1, RADIUS_ATTR_ACCT_INPUT_GIGAWORDS = 52, RADIUS_ATTR_ACCT_OUTPUT_GIGAWORDS = 53, RADIUS_ATTR_EVENT_TIMESTAMP = 55, + RADIUS_ATTR_EGRESS_VLANID = 56, RADIUS_ATTR_NAS_PORT_TYPE = 61, RADIUS_ATTR_TUNNEL_TYPE = 64, RADIUS_ATTR_TUNNEL_MEDIUM_TYPE = 65,