Skip to content

Commit 72f15d5

Browse files
michael-devjmberg-intel
authored andcommitted
mac80211: filter multicast data packets on AP / AP_VLAN
This patch adds filtering for multicast data packets on AP_VLAN interfaces that have no authorized station connected and changes filtering on AP interfaces to not count stations assigned to AP_VLAN interfaces. This saves airtime and avoids waking up other stations currently authorized in this BSS. When using WPA, the packets dropped could not be decrypted by any station. The behaviour when there are no AP_VLAN interfaces is left unchanged. When there are AP_VLAN interfaces, this patch 1. adds filtering multicast data packets sent on AP_VLAN interfaces that have no authorized station connected. No filtering happens on 4addr AP_VLAN interfaces. 2. makes filtering of multicast data packets sent on AP interfaces depend on the number of authorized stations in this bss not assigned to an AP_VLAN interface. Therefore, a new num_mcast_sta counter is added for AP_VLAN interfaces. The existing one for AP interfaces is altered to not track stations assigned to an AP_VLAN interface. The new counter is exposed in debugfs. Signed-off-by: Michael Braun <michael-dev@fami-braun.de> [reformat commit message a bit, unline ieee80211_vif_{inc,dec}_num_mcast] Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent 5f9994b commit 72f15d5

7 files changed

Lines changed: 58 additions & 27 deletions

File tree

‎net/mac80211/cfg.c‎

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,9 +1520,6 @@ static int ieee80211_change_station(struct wiphy *wiphy,
15201520
goto out_err;
15211521

15221522
if (params->vlan && params->vlan != sta->sdata->dev) {
1523-
bool prev_4addr = false;
1524-
bool new_4addr = false;
1525-
15261523
vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
15271524

15281525
if (params->vlan->ieee80211_ptr->use_4addr) {
@@ -1532,26 +1529,21 @@ static int ieee80211_change_station(struct wiphy *wiphy,
15321529
}
15331530

15341531
rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
1535-
new_4addr = true;
15361532
__ieee80211_check_fast_rx_iface(vlansdata);
15371533
}
15381534

15391535
if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1540-
sta->sdata->u.vlan.sta) {
1536+
sta->sdata->u.vlan.sta)
15411537
RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
1542-
prev_4addr = true;
1543-
}
1538+
1539+
if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1540+
ieee80211_vif_dec_num_mcast(sta->sdata);
15441541

15451542
sta->sdata = vlansdata;
15461543
ieee80211_check_fast_xmit(sta);
15471544

1548-
if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1549-
prev_4addr != new_4addr) {
1550-
if (new_4addr)
1551-
atomic_dec(&sta->sdata->bss->num_mcast_sta);
1552-
else
1553-
atomic_inc(&sta->sdata->bss->num_mcast_sta);
1554-
}
1545+
if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1546+
ieee80211_vif_inc_num_mcast(sta->sdata);
15551547

15561548
ieee80211_send_layer2_update(sta);
15571549
}

‎net/mac80211/debugfs_netdev.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ IEEE80211_IF_FILE_RW(tdls_wider_bw);
477477
IEEE80211_IF_FILE(num_mcast_sta, u.ap.num_mcast_sta, ATOMIC);
478478
IEEE80211_IF_FILE(num_sta_ps, u.ap.ps.num_sta_ps, ATOMIC);
479479
IEEE80211_IF_FILE(dtim_count, u.ap.ps.dtim_count, DEC);
480+
IEEE80211_IF_FILE(num_mcast_sta_vlan, u.vlan.num_mcast_sta, ATOMIC);
480481

481482
static ssize_t ieee80211_if_fmt_num_buffered_multicast(
482483
const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
@@ -684,6 +685,13 @@ static void add_ap_files(struct ieee80211_sub_if_data *sdata)
684685
DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
685686
}
686687

688+
static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
689+
{
690+
/* add num_mcast_sta_vlan using name num_mcast_sta */
691+
debugfs_create_file("num_mcast_sta", 0400, sdata->vif.debugfs_dir,
692+
sdata, &num_mcast_sta_vlan_ops);
693+
}
694+
687695
static void add_ibss_files(struct ieee80211_sub_if_data *sdata)
688696
{
689697
DEBUGFS_ADD_MODE(tsf, 0600);
@@ -787,6 +795,9 @@ static void add_files(struct ieee80211_sub_if_data *sdata)
787795
case NL80211_IFTYPE_AP:
788796
add_ap_files(sdata);
789797
break;
798+
case NL80211_IFTYPE_AP_VLAN:
799+
add_vlan_files(sdata);
800+
break;
790801
case NL80211_IFTYPE_WDS:
791802
add_wds_files(sdata);
792803
break;

‎net/mac80211/ieee80211_i.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ struct ieee80211_if_vlan {
307307

308308
/* used for all tx if the VLAN is configured to 4-addr mode */
309309
struct sta_info __rcu *sta;
310+
atomic_t num_mcast_sta; /* number of stations receiving multicast */
310311
};
311312

312313
struct mesh_stats {
@@ -1527,6 +1528,23 @@ ieee80211_have_rx_timestamp(struct ieee80211_rx_status *status)
15271528
return false;
15281529
}
15291530

1531+
void ieee80211_vif_inc_num_mcast(struct ieee80211_sub_if_data *sdata);
1532+
void ieee80211_vif_dec_num_mcast(struct ieee80211_sub_if_data *sdata);
1533+
1534+
/* This function returns the number of multicast stations connected to this
1535+
* interface. It returns -1 if that number is not tracked, that is for netdevs
1536+
* not in AP or AP_VLAN mode or when using 4addr.
1537+
*/
1538+
static inline int
1539+
ieee80211_vif_get_num_mcast_if(struct ieee80211_sub_if_data *sdata)
1540+
{
1541+
if (sdata->vif.type == NL80211_IFTYPE_AP)
1542+
return atomic_read(&sdata->u.ap.num_mcast_sta);
1543+
if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
1544+
return atomic_read(&sdata->u.vlan.num_mcast_sta);
1545+
return -1;
1546+
}
1547+
15301548
u64 ieee80211_calculate_rx_timestamp(struct ieee80211_local *local,
15311549
struct ieee80211_rx_status *status,
15321550
unsigned int mpdu_len,

‎net/mac80211/iface.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,3 +2005,19 @@ void ieee80211_iface_exit(void)
20052005
{
20062006
unregister_netdevice_notifier(&mac80211_netdev_notifier);
20072007
}
2008+
2009+
void ieee80211_vif_inc_num_mcast(struct ieee80211_sub_if_data *sdata)
2010+
{
2011+
if (sdata->vif.type == NL80211_IFTYPE_AP)
2012+
atomic_inc(&sdata->u.ap.num_mcast_sta);
2013+
else if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
2014+
atomic_inc(&sdata->u.vlan.num_mcast_sta);
2015+
}
2016+
2017+
void ieee80211_vif_dec_num_mcast(struct ieee80211_sub_if_data *sdata)
2018+
{
2019+
if (sdata->vif.type == NL80211_IFTYPE_AP)
2020+
atomic_dec(&sdata->u.ap.num_mcast_sta);
2021+
else if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
2022+
atomic_dec(&sdata->u.vlan.num_mcast_sta);
2023+
}

‎net/mac80211/rx.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,7 +2215,8 @@ ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
22152215
sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
22162216
!(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
22172217
(sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
2218-
if (is_multicast_ether_addr(ehdr->h_dest)) {
2218+
if (is_multicast_ether_addr(ehdr->h_dest) &&
2219+
ieee80211_vif_get_num_mcast_if(sdata) != 0) {
22192220
/*
22202221
* send multicast frames both to higher layers in
22212222
* local net stack and back to the wireless medium
@@ -2224,7 +2225,7 @@ ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
22242225
if (!xmit_skb)
22252226
net_info_ratelimited("%s: failed to clone multicast frame\n",
22262227
dev->name);
2227-
} else {
2228+
} else if (!is_multicast_ether_addr(ehdr->h_dest)) {
22282229
dsta = sta_info_get(sdata, skb->data);
22292230
if (dsta) {
22302231
/*

‎net/mac80211/sta_info.c‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,21 +1871,15 @@ int sta_info_move_state(struct sta_info *sta,
18711871
if (!sta->sta.support_p2p_ps)
18721872
ieee80211_recalc_p2p_go_ps_allowed(sta->sdata);
18731873
} else if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
1874-
if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1875-
(sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1876-
!sta->sdata->u.vlan.sta))
1877-
atomic_dec(&sta->sdata->bss->num_mcast_sta);
1874+
ieee80211_vif_dec_num_mcast(sta->sdata);
18781875
clear_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
18791876
ieee80211_clear_fast_xmit(sta);
18801877
ieee80211_clear_fast_rx(sta);
18811878
}
18821879
break;
18831880
case IEEE80211_STA_AUTHORIZED:
18841881
if (sta->sta_state == IEEE80211_STA_ASSOC) {
1885-
if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
1886-
(sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1887-
!sta->sdata->u.vlan.sta))
1888-
atomic_inc(&sta->sdata->bss->num_mcast_sta);
1882+
ieee80211_vif_inc_num_mcast(sta->sdata);
18891883
set_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
18901884
ieee80211_check_fast_xmit(sta);
18911885
ieee80211_check_fast_rx(sta);

‎net/mac80211/tx.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,8 @@ ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
331331
I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
332332
return TX_DROP;
333333
}
334-
} else if (unlikely(tx->sdata->vif.type == NL80211_IFTYPE_AP &&
335-
ieee80211_is_data(hdr->frame_control) &&
336-
!atomic_read(&tx->sdata->u.ap.num_mcast_sta))) {
334+
} else if (unlikely(ieee80211_is_data(hdr->frame_control) &&
335+
ieee80211_vif_get_num_mcast_if(tx->sdata) == 0)) {
337336
/*
338337
* No associated STAs - no need to send multicast
339338
* frames.

0 commit comments

Comments
 (0)