From patchwork Tue Nov 5 19:17:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Pedersen X-Patchwork-Id: 3143471 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5BDD69F432 for ; Tue, 5 Nov 2013 19:23:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4A1BF205BB for ; Tue, 5 Nov 2013 19:23:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8CA2E205B3 for ; Tue, 5 Nov 2013 19:23:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755486Ab3KETXO (ORCPT ); Tue, 5 Nov 2013 14:23:14 -0500 Received: from mail-pd0-f169.google.com ([209.85.192.169]:65140 "EHLO mail-pd0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755392Ab3KETXM (ORCPT ); Tue, 5 Nov 2013 14:23:12 -0500 Received: by mail-pd0-f169.google.com with SMTP id q10so9113400pdj.0 for ; Tue, 05 Nov 2013 11:23:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uPEEJNN/pKoHO7000vc1zk1B5F0DevxzSbhMVvkBWlU=; b=QSaYlciXSBy0sWKhVpTD1boroMG9lgshaltlpjRy399d2qjbk8HZQZ2Eoi6YOk+7jh mB5QJENhdd5rSYM1knqb8iDyFbZWZE/i21ceoY5J5pBUiqXc9r8V4dP0RFV7vmIgRvFk kfe+MBar0dqn7C3Wl0j6ui89rSVdxk0zxk+DZIqoKQCzz38X5Ly9Mqgk/f6PcZ8Sha8j lhO8kxDcKA+nDyr/ZXqLuoQNAp+fhO5ctxYX/53/n2rtueClOzlIn8PPT6idwnN9W3+j w4EUcxAYmhVUpBEaWVs/lTJPKCo4vjpbf6+2vVXpHX+ANUDqEroM77VPkT3m+dUi7jba rm+w== X-Gm-Message-State: ALoCoQlf/ExFZsoOp0RTK6HWUGanGFajDGp4ZiWucbZFOdUkZWUKuWjRYIoC0rwF/sE8XyvkMo9L X-Received: by 10.68.161.2 with SMTP id xo2mr2790080pbb.179.1383679391363; Tue, 05 Nov 2013 11:23:11 -0800 (PST) Received: from cable.cozybit (70-35-43-50.static.wiline.com. [70.35.43.50]) by mx.google.com with ESMTPSA id de1sm36237294pbc.7.2013.11.05.11.23.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Nov 2013 11:23:10 -0800 (PST) From: Thomas Pedersen To: Johannes Berg Cc: Bob Copeland , linux-wireless , open80211s , Thomas Pedersen Subject: [PATCH 17/17] mac80211: clean up mesh local link ID generation Date: Tue, 5 Nov 2013 11:17:05 -0800 Message-Id: <1383679025-7150-17-git-send-email-thomas@cozybit.com> X-Mailer: git-send-email 1.8.4.rc3 In-Reply-To: <1383679025-7150-1-git-send-email-thomas@cozybit.com> References: <1383679025-7150-1-git-send-email-thomas@cozybit.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 802.11-2012 13.3.1 implicitly limits the mesh local link ID range to that of AID, since for mesh PS the local link ID must be indicated in the TIM IE, which only holds IEEE80211_MAX_AID bits. Also the code was allowing a local link ID of 0, but this is not correct since that TIM bit is used for indicating buffered mcast frames. Generate a random, unique, link ID from 1 - 2007, and drop a modulo conversion for the local link ID, but keep it for the peer link ID in case he chose something > MAX_AID. Signed-off-by: Thomas Pedersen --- net/mac80211/mesh_plink.c | 40 +++++++++++++++++++++++++++++++++++----- net/mac80211/mesh_ps.c | 3 +-- net/mac80211/sta_info.c | 4 ++-- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/net/mac80211/mesh_plink.c b/net/mac80211/mesh_plink.c index e0528b9..4ea2f21 100644 --- a/net/mac80211/mesh_plink.c +++ b/net/mac80211/mesh_plink.c @@ -615,9 +615,40 @@ static inline void mesh_plink_timer_set(struct sta_info *sta, int timeout) add_timer(&sta->plink_timer); } +static bool llid_in_use(struct ieee80211_sub_if_data *sdata, + __le16 llid) +{ + struct ieee80211_local *local = sdata->local; + bool in_use = false; + struct sta_info *sta; + + rcu_read_lock(); + list_for_each_entry_rcu(sta, &local->sta_list, list) { + if (!memcmp(&sta->llid, &llid, sizeof(llid))) { + in_use = true; + break; + } + } + rcu_read_unlock(); + + return in_use; +} + +static __le16 mesh_get_new_llid(struct ieee80211_sub_if_data *sdata) +{ + u16 llid; + + do { + get_random_bytes(&llid, sizeof(llid)); + /* for mesh PS we still only have the AID range for TIM bits */ + llid = (llid % IEEE80211_MAX_AID) + 1; + } while (llid_in_use(sdata, cpu_to_le16(llid))); + + return cpu_to_le16(llid); +} + u32 mesh_plink_open(struct sta_info *sta) { - __le16 llid; struct ieee80211_sub_if_data *sdata = sta->sdata; u32 changed; @@ -625,8 +656,7 @@ u32 mesh_plink_open(struct sta_info *sta) return 0; spin_lock_bh(&sta->lock); - get_random_bytes(&llid, 2); - sta->llid = llid; + sta->llid = mesh_get_new_llid(sdata); if (sta->plink_state != NL80211_PLINK_LISTEN && sta->plink_state != NL80211_PLINK_BLOCKED) { spin_unlock_bh(&sta->lock); @@ -643,7 +673,7 @@ u32 mesh_plink_open(struct sta_info *sta) changed = ieee80211_mps_local_status_update(sdata); mesh_plink_frame_tx(sdata, WLAN_SP_MESH_PEERING_OPEN, - sta->sta.addr, llid, 0, 0); + sta->sta.addr, sta->llid, 0, 0); return changed; } @@ -719,7 +749,7 @@ static u32 mesh_plink_fsm(struct ieee80211_sub_if_data *sdata, break; case OPN_ACPT: sta->plink_state = NL80211_PLINK_OPN_RCVD; - get_random_bytes(&sta->llid, 2); + sta->llid = mesh_get_new_llid(sdata); mesh_plink_timer_set(sta, mshcfg->dot11MeshRetryTimeout); diff --git a/net/mac80211/mesh_ps.c b/net/mac80211/mesh_ps.c index 0f79b78..9493868 100644 --- a/net/mac80211/mesh_ps.c +++ b/net/mac80211/mesh_ps.c @@ -576,10 +576,9 @@ void ieee80211_mps_frame_release(struct sta_info *sta, int ac, buffer_local = 0; bool has_buffered = false; - /* TIM map only for LLID <= IEEE80211_MAX_AID */ if (sta->plink_state == NL80211_PLINK_ESTAB) has_buffered = ieee80211_check_tim(elems->tim, elems->tim_len, - le16_to_cpu(sta->llid) % IEEE80211_MAX_AID); + le16_to_cpu(sta->llid)); if (has_buffered) mps_dbg(sta->sdata, "%pM indicates buffered frames\n", diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c index 1eb66e2..7a91515 100644 --- a/net/mac80211/sta_info.c +++ b/net/mac80211/sta_info.c @@ -630,8 +630,8 @@ void sta_info_recalc_tim(struct sta_info *sta) #ifdef CONFIG_MAC80211_MESH } else if (ieee80211_vif_is_mesh(&sta->sdata->vif)) { ps = &sta->sdata->u.mesh.ps; - /* TIM map only for PLID <= IEEE80211_MAX_AID */ - id = le16_to_cpu(sta->plid) % IEEE80211_MAX_AID; + /* TIM map only for 1 <= PLID <= IEEE80211_MAX_AID */ + id = le16_to_cpu(sta->plid) % (IEEE80211_MAX_AID + 1); #endif } else { return;