From patchwork Mon Apr 8 16:11:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: michael-dev X-Patchwork-Id: 234826 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 704DC2C00A9 for ; Tue, 9 Apr 2013 02:18:40 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id E51299C16C; Mon, 8 Apr 2013 12:18: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 0vEAqJVY3qw3; Mon, 8 Apr 2013 12:18:12 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 57A729C13C; Mon, 8 Apr 2013 12:17:05 -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 587649C099 for ; Mon, 8 Apr 2013 12:17:03 -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 9vL7bjz8Q2Pl for ; Mon, 8 Apr 2013 12:16:59 -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 61D4D9C11F for ; Mon, 8 Apr 2013 12:16:49 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.fem.tu-ilmenau.de (Postfix) with ESMTP id E5AB068E2; Mon, 8 Apr 2013 18:16:48 +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 ha586Ai6Yqfv; 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 B3523D0A89; Mon, 8 Apr 2013 18:11:29 +0200 (CEST) From: michael-dev@fami-braun.de To: hostap@lists.shmoo.com Subject: [PATCH 5/6] radius: parse tagged vlan information Date: Mon, 8 Apr 2013 18:11:14 +0200 Message-Id: <1365437475-9295-6-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 --- 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,