From: Thomas Pedersen <thomas@cozybit.com>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: Bob Copeland <me@bobcopeland.com>,
linux-wireless <linux-wireless@vger.kernel.org>,
open80211s <devel@lists.open80211s.org>,
Thomas Pedersen <thomas@cozybit.com>
Subject: [PATCH 17/17] mac80211: clean up mesh local link ID generation
Date: Tue, 5 Nov 2013 11:17:05 -0800 [thread overview]
Message-ID: <1383679025-7150-17-git-send-email-thomas@cozybit.com> (raw)
In-Reply-To: <1383679025-7150-1-git-send-email-thomas@cozybit.com>
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 <thomas@cozybit.com>
---
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;
--
1.8.4.rc3
next prev parent reply other threads:[~2013-11-05 19:23 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-05 19:16 [PATCH 01/17] mac80211: fix off-by-one in llid check Thomas Pedersen
2013-11-05 19:16 ` [PATCH 02/17] mac80211: consolidate calls to plink_frame_tx Thomas Pedersen
2013-11-05 19:16 ` [PATCH 03/17] mac80211: hold sta->lock across plink switch statements Thomas Pedersen
2013-11-05 19:16 ` [PATCH 04/17] mac80211: mesh: factor out common plink close/estab code Thomas Pedersen
2013-11-05 19:16 ` [PATCH 05/17] mac80211: mesh_plink: group basic fitness checks Thomas Pedersen
2013-11-05 19:16 ` [PATCH 06/17] mac80211: mesh: rewrite rssi_threshold_check in C Thomas Pedersen
2013-11-05 19:16 ` [PATCH 07/17] mac80211: mesh_plink: collapse the two switch statements together Thomas Pedersen
2013-11-05 19:16 ` [PATCH 08/17] mac80211: mesh_plink: don't ignore holding timer Thomas Pedersen
2013-11-05 19:16 ` [PATCH 09/17] mac80211: return -ENOMEM in mesh_plink_frame_tx Thomas Pedersen
2013-11-05 19:16 ` [PATCH 10/17] mac80211: remove unused mesh_mgmt_ies_add() prototype Thomas Pedersen
2013-11-05 19:16 ` [PATCH 11/17] mac80211: factor peering frame processing into own function Thomas Pedersen
2013-11-05 19:17 ` [PATCH 12/17] mac80211: consolidate rcu unlocks in plink frame rx Thomas Pedersen
2013-11-05 19:17 ` [PATCH 13/17] mac80211: assign sta plid early Thomas Pedersen
2013-11-05 19:17 ` [PATCH 14/17] mac80211: factor out peering FSM Thomas Pedersen
2013-11-05 19:17 ` [PATCH 15/17] mac80211: factor out plink event gathering Thomas Pedersen
2013-11-05 19:17 ` [PATCH 16/17] mac80211: initialize llid Thomas Pedersen
2013-11-05 19:17 ` Thomas Pedersen [this message]
2013-11-06 10:35 ` [PATCH 01/17] mac80211: fix off-by-one in llid check Johannes Berg
2013-11-06 15:14 ` Thomas Pedersen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1383679025-7150-17-git-send-email-thomas@cozybit.com \
--to=thomas@cozybit.com \
--cc=devel@lists.open80211s.org \
--cc=johannes@sipsolutions.net \
--cc=linux-wireless@vger.kernel.org \
--cc=me@bobcopeland.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox