cfg80211: fix duplicated scan entries after channel switch
v4 cover cfg80211: fix duplicated scan entries after channel switch
Hi Johannes and all,
This is v4 patch fixing duplicated scan entries after channel switch.
Regards,
Sergey
v1 -> v2
- use IEs of new BSS entry to update known BSS entry
for this purpose extract BSS update code from cfg80211_bss_update into a separate function cfg80211_update_known_bss
v2 -> v3
- minor cleanup according to review comments
- split cfg80211_update_known_bss function into a separate patch
- update channel and location in rb-tree for nontransmit bss entries
v3 -> v4
- rebase on top of the latest mac80211-next tree
- drop RFC tag
Sergey Matyukevich (2):
cfg80211: refactor cfg80211_bss_update
cfg80211: fix duplicated scan entries after channel switch
net/wireless/core.h | 2 + net/wireless/nl80211.c | 2 +- net/wireless/scan.c | 250 +++++++++++++++++++++++++++++++++---------------- 3 files changed, 171 insertions(+), 83 deletions(-)
Signature · 1 line
2.11.0
PATCH v4 1/2 cfg80211: refactor cfg80211_bss_update
This patch implements minor refactoring for cfg80211_bss_update function. Code path for updating known BSS is extracted into dedicated cfg80211_update_known_bss function.
--- net/wireless/scan.c | 171 +++++++++++++++++++++++++++------------------------- 1 file changed, 89 insertions(+), 82 deletions(-)
net/wireless/scan.c +89 -82
@@ -1091,6 +1091,93 @@ struct cfg80211_non_tx_bss {u8 bssid_index; }; +static bool +cfg80211_update_known_bss (struct cfg80211_registered_device *rdev, +struct cfg80211_internal_bss *known, +struct cfg80211_internal_bss *new, +bool signal_valid) +{ +lockdep_assert_held (&rdev->bss_lock); + +/* Update IEs */ +if (rcu_access_pointer (new->pub.proberesp_ies)) { +const struct cfg80211_bss_ies *old; + + old =rcu_access_pointer (known->pub.proberesp_ies); + +rcu_assign_pointer (known->pub.proberesp_ies, + new->pub.proberesp_ies); +/* Override possible earlier Beacon frame IEs */ +rcu_assign_pointer (known->pub.ies, + new->pub.proberesp_ies); +if (old) +kfree_rcu ((struct cfg80211_bss_ies *)old, rcu_head); + }else if (rcu_access_pointer (new->pub.beacon_ies)) { +const struct cfg80211_bss_ies *old; +struct cfg80211_internal_bss *bss; + +if (known->pub.hidden_beacon_bss && + !list_empty (&known->hidden_list)) { +const struct cfg80211_bss_ies *f; + +/* The known BSS struct is one of the probe +* response members of a group, but we're +* receiving a beacon (beacon_ies in the new +* bss is used). This can only mean that the +* AP changed its beacon from not having an +* SSID to showing it, which is confusing so +* drop this information. +*/ + + f =rcu_access_pointer (new->pub.beacon_ies); +kfree_rcu ((struct cfg80211_bss_ies *)f, rcu_head); +return false; + } + + old =rcu_access_pointer (known->pub.beacon_ies); + +rcu_assign_pointer (known->pub.beacon_ies, new->pub.beacon_ies); + +/* Override IEs if they were from a beacon before */ +if (old ==rcu_access_pointer (known->pub.ies)) +rcu_assign_pointer (known->pub.ies, new->pub.beacon_ies); + +/* Assign beacon IEs to all sub entries */ +list_for_each_entry (bss, &known->hidden_list, hidden_list) { +const struct cfg80211_bss_ies *ies; + + ies =rcu_access_pointer (bss->pub.beacon_ies); +WARN_ON (ies != old); + +rcu_assign_pointer (bss->pub.beacon_ies, + new->pub.beacon_ies); + } + +if (old) +kfree_rcu ((struct cfg80211_bss_ies *)old, rcu_head); + } + + known->pub.beacon_interval = new->pub.beacon_interval; + +/* don't update the signal if beacon was heard on +* adjacent channel. +*/ +if (signal_valid) + known->pub.signal = new->pub.signal; + known->pub.capability = new->pub.capability; + known->ts = new->ts; + known->ts_boottime = new->ts_boottime; + known->parent_tsf = new->parent_tsf; + known->pub.chains = new->pub.chains; +memcpy (known->pub.chain_signal, new->pub.chain_signal, +IEEE80211_MAX_CHAINS ); +ether_addr_copy (known->parent_bssid, new->parent_bssid); + known->pub.max_bssid_indicator = new->pub.max_bssid_indicator; + known->pub.bssid_index = new->pub.bssid_index; + +return true; +} +/* Returned bss is reference counted and must be cleaned up appropriately. */ struct cfg80211_internal_bss * cfg80211_bss_update(struct cfg80211_registered_device *rdev,
@@ -1114,88 +1201,8 @@ cfg80211_bss_update(struct cfg80211_registered_device *rdev, found =rb_find_bss (rdev, tmp,BSS_CMP_REGULAR );if (found) { -/* Update IEs */ -if (rcu_access_pointer (tmp->pub.proberesp_ies)) { -const struct cfg80211_bss_ies *old; - - old =rcu_access_pointer (found->pub.proberesp_ies); - -rcu_assign_pointer (found->pub.proberesp_ies, - tmp->pub.proberesp_ies); -/* Override possible earlier Beacon frame IEs */ -rcu_assign_pointer (found->pub.ies, - tmp->pub.proberesp_ies); -if (old) -kfree_rcu ((struct cfg80211_bss_ies *)old, - rcu_head); - }else if (rcu_access_pointer (tmp->pub.beacon_ies)) { -const struct cfg80211_bss_ies *old; -struct cfg80211_internal_bss *bss; - -if (found->pub.hidden_beacon_bss && - !list_empty (&found->hidden_list)) { -const struct cfg80211_bss_ies *f; - -/* -* The found BSS struct is one of the probe -* response members of a group, but we're -* receiving a beacon (beacon_ies in the tmp -* bss is used). This can only mean that the -* AP changed its beacon from not having an -* SSID to showing it, which is confusing so -* drop this information. -*/ - - f =rcu_access_pointer (tmp->pub.beacon_ies); -kfree_rcu ((struct cfg80211_bss_ies *)f, - rcu_head); - goto drop; - } - - old =rcu_access_pointer (found->pub.beacon_ies); - -rcu_assign_pointer (found->pub.beacon_ies, - tmp->pub.beacon_ies); - -/* Override IEs if they were from a beacon before */ -if (old ==rcu_access_pointer (found->pub.ies)) -rcu_assign_pointer (found->pub.ies, - tmp->pub.beacon_ies); - -/* Assign beacon IEs to all sub entries */ -list_for_each_entry (bss, &found->hidden_list, - hidden_list) { -const struct cfg80211_bss_ies *ies; - - ies =rcu_access_pointer (bss->pub.beacon_ies); -WARN_ON (ies != old); - -rcu_assign_pointer (bss->pub.beacon_ies, - tmp->pub.beacon_ies); - } - -if (old) -kfree_rcu ((struct cfg80211_bss_ies *)old, - rcu_head); - } - - found->pub.beacon_interval = tmp->pub.beacon_interval; -/* -* don't update the signal if beacon was heard on -* adjacent channel. -*/ -if (signal_valid) - found->pub.signal = tmp->pub.signal; - found->pub.capability = tmp->pub.capability; - found->ts = tmp->ts; - found->ts_boottime = tmp->ts_boottime; - found->parent_tsf = tmp->parent_tsf; - found->pub.chains = tmp->pub.chains; -memcpy (found->pub.chain_signal, tmp->pub.chain_signal, -IEEE80211_MAX_CHAINS ); -ether_addr_copy (found->parent_bssid, tmp->parent_bssid); - found->pub.max_bssid_indicator = tmp->pub.max_bssid_indicator; - found->pub.bssid_index = tmp->pub.bssid_index; +if (!cfg80211_update_known_bss (rdev, found, tmp, signal_valid)) + goto drop; }else {struct cfg80211_internal_bss *new;struct cfg80211_internal_bss *hidden;
Signature · 1 line
2.11.0
PATCH v4 2/2 cfg80211: fix duplicated scan entries after channel switch
In reply to Sergey MatyukevichWhen associated BSS completes channel switch procedure, its channel record needs to be updated. The existing mac80211 solution was extended to cfg80211 in commit 5dc8cdce1d72 ("mac80211/cfg80211:
update bss channel on channel switch").
However that solution still appears to be incomplete as it may lead to duplicated scan entries for associated BSS after channel switch. The root cause of the problem is as follows. Each BSS entry is included into the following data structures:
- bss list rdev->bss_list
- bss search tree rdev->bss_tree
Updating BSS channel record without rebuilding bss_tree may break tree search since cmp_bss considers all of the following: channel, bssid, ssid. When BSS channel is updated, but its location in bss_tree is not updated, then subsequent search operations may fail to locate this BSS since they will be traversing bss_tree in wrong direction. As a result, for scan performed after associated BSS channel switch, cfg80211_bss_update may add the second entry for the same BSS to both bss_list and bss_tree, rather then update the existing one.
To summarize, if BSS channel needs to be updated, then bss_tree should be rebuilt in order to put updated BSS entry into a proper location.
This commit suggests the following straightforward solution:
- if new entry has been already created for BSS after channel switch, then use its IEs to update known BSS entry and then remove new entry completely
- use rb_erase/rb_insert_bss reinstall updated BSS in bss_tree
- for nontransmit BSS entry, the whole transmit BSS hierarchy is updated
--- net/wireless/core.h | 2 ++ net/wireless/nl80211.c | 2 +- net/wireless/scan.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-)
net/wireless/core.h +2 -0
@@ -306,6 +306,8 @@ void ieee80211_set_bitrate_flags(struct wiphy *wiphy);void cfg80211_bss_expire (struct cfg80211_registered_device *rdev);void cfg80211_bss_age (struct cfg80211_registered_device *rdev,unsigned long age_secs); +void cfg80211_update_assoc_bss_entry (struct wireless_dev *wdev, +struct ieee80211_channel *channel);/* IBSS */ int __cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
net/wireless/nl80211.c +1 -1
@@ -16116,7 +16116,7 @@ void cfg80211_ch_switch_notify(struct net_device *dev,if (wdev->iftype ==NL80211_IFTYPE_STATION && !WARN_ON (!wdev->current_bss)) - wdev->current_bss->pub.channel = chandef->chan; +cfg80211_update_assoc_bss_entry (wdev, chandef->chan);nl80211_ch_switch_notify (rdev, dev, chandef,GFP_KERNEL ,NL80211_CMD_CH_SWITCH_NOTIFY ,0 );
net/wireless/scan.c +79 -0
85 lines not on this page · raw message
Signature · 1 line
2.11.0