From patchwork Fri Apr 12 22:46:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alban X-Patchwork-Id: 236255 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 8A44B2C009F for ; Sat, 13 Apr 2013 08:47:02 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id DE3F09D21D; Fri, 12 Apr 2013 18:46:57 -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 uN1fVgKf7+YL; Fri, 12 Apr 2013 18:46:57 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id AB77E9D20B; Fri, 12 Apr 2013 18:46:53 -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 31E309D20B for ; Fri, 12 Apr 2013 18:46:52 -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 M+hYuQiYnbSD for ; Fri, 12 Apr 2013 18:46:48 -0400 (EDT) Received: from styx.dotsec.net (dotsec.net [62.75.224.215]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id DCF749D207 for ; Fri, 12 Apr 2013 18:46:47 -0400 (EDT) Received: from f054115244.adsl.alicedsl.de ([78.54.115.244] helo=tock.netz.gv) by styx.dotsec.net with esmtpa (Exim 4.71) (envelope-from ) id 1UQmjp-0006R8-PY for hostap@lists.shmoo.com; Sat, 13 Apr 2013 00:46:46 +0200 From: Alban Bedel To: hostap@lists.shmoo.com Subject: [PATCH] IAPP: Send layer 2 updates to the bridge, not the IAPP interface Date: Sat, 13 Apr 2013 00:46:33 +0200 Message-Id: <1365806793-18914-1-git-send-email-albeu@free.fr> X-Mailer: git-send-email 1.7.10.4 X-SA-Score: -1.0 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 Layer 2 updates only make sense if the wifi interface is bridged and should be sent to the bridge, not the IAPP interface. This is important in setups where the wifi clients are in a different layer 2 network than the one used for RADIUS, IAPP, etc. Signed-hostap: Alban Bedel --- src/ap/hostapd.c | 4 +++- src/ap/iapp.c | 54 +++++++++++++++++++++++++++++++++++++++--------------- src/ap/iapp.h | 6 ++++-- 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c index a0ac38c..f200156 100644 --- a/src/ap/hostapd.c +++ b/src/ap/hostapd.c @@ -781,7 +781,9 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first) } if (hapd->conf->ieee802_11f && - (hapd->iapp = iapp_init(hapd, hapd->conf->iapp_iface)) == NULL) { + (hapd->iapp = iapp_init(hapd, hapd->conf->iapp_iface, + hapd->conf->bridge[0] ? hapd->conf->bridge : + NULL)) == NULL) { wpa_printf(MSG_ERROR, "IEEE 802.11F (IAPP) initialization " "failed."); return -1; diff --git a/src/ap/iapp.c b/src/ap/iapp.c index be55c69..346e659 100644 --- a/src/ap/iapp.c +++ b/src/ap/iapp.c @@ -214,6 +214,8 @@ static void iapp_send_layer2_update(struct iapp_data *iapp, u8 *addr) /* Send Level 2 Update Frame to update forwarding tables in layer 2 * bridge devices */ + if (iapp->packet_sock < 0) + return; /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID) * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */ @@ -382,11 +384,46 @@ static void iapp_receive_udp(int sock, void *eloop_ctx, void *sock_ctx) } -struct iapp_data * iapp_init(struct hostapd_data *hapd, const char *iface) +static int iapp_init_layer2(struct iapp_data *iapp, const char *bridge) { struct ifreq ifr; struct sockaddr_ll addr; int ifindex; + + /* Layer 2 updates only make sense when the wifi interface is bridged */ + if (!bridge) + return 0; + + iapp->packet_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); + if (iapp->packet_sock < 0) { + perror("socket[PF_PACKET,SOCK_RAW]"); + return -1; + } + + os_memset(&ifr, 0, sizeof(ifr)); + os_strlcpy(ifr.ifr_name, bridge, sizeof(ifr.ifr_name)); + if (ioctl(iapp->packet_sock, SIOCGIFINDEX, &ifr) != 0) { + perror("ioctl(SIOCGIFINDEX)"); + return -1; + } + ifindex = ifr.ifr_ifindex; + + os_memset(&addr, 0, sizeof(addr)); + addr.sll_family = AF_PACKET; + addr.sll_ifindex = ifindex; + if (bind(iapp->packet_sock, (struct sockaddr *) &addr, + sizeof(addr)) < 0) { + perror("bind[PACKET]"); + return -1; + } + + return 0; +} + +struct iapp_data * iapp_init(struct hostapd_data *hapd, const char *iface, + const char *bridge) +{ + struct ifreq ifr; struct sockaddr_in *paddr, uaddr; struct iapp_data *iapp; struct ip_mreqn mreq; @@ -415,7 +452,6 @@ struct iapp_data * iapp_init(struct hostapd_data *hapd, const char *iface) iapp_deinit(iapp); return NULL; } - ifindex = ifr.ifr_ifindex; if (ioctl(iapp->udp_sock, SIOCGIFADDR, &ifr) != 0) { perror("ioctl(SIOCGIFADDR)"); @@ -466,19 +502,7 @@ struct iapp_data * iapp_init(struct hostapd_data *hapd, const char *iface) return NULL; } - iapp->packet_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); - if (iapp->packet_sock < 0) { - perror("socket[PF_PACKET,SOCK_RAW]"); - iapp_deinit(iapp); - return NULL; - } - - os_memset(&addr, 0, sizeof(addr)); - addr.sll_family = AF_PACKET; - addr.sll_ifindex = ifindex; - if (bind(iapp->packet_sock, (struct sockaddr *) &addr, - sizeof(addr)) < 0) { - perror("bind[PACKET]"); + if (iapp_init_layer2(iapp, bridge) < 0) { iapp_deinit(iapp); return NULL; } diff --git a/src/ap/iapp.h b/src/ap/iapp.h index c221183..fa47356 100644 --- a/src/ap/iapp.h +++ b/src/ap/iapp.h @@ -14,7 +14,8 @@ struct iapp_data; #ifdef CONFIG_IAPP void iapp_new_station(struct iapp_data *iapp, struct sta_info *sta); -struct iapp_data * iapp_init(struct hostapd_data *hapd, const char *iface); +struct iapp_data * iapp_init(struct hostapd_data *hapd, const char *iface, + const char *bridge); void iapp_deinit(struct iapp_data *iapp); #else /* CONFIG_IAPP */ @@ -25,7 +26,8 @@ static inline void iapp_new_station(struct iapp_data *iapp, } static inline struct iapp_data * iapp_init(struct hostapd_data *hapd, - const char *iface) + const char *iface, + const char *bridge) { return NULL; }