6dce21db1e2f4bb714af389534c16106efa5c6c0
[openwrt/staging/thess.git] / package / kernel / mac80211 / patches / subsys / 316-mac80211-skip-encap-offload-for-tx-multicast-control.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Fri, 21 Aug 2020 05:54:10 +0200
3 Subject: [PATCH] mac80211: skip encap offload for tx multicast/control
4 packets
5
6 This simplifies the checks in the encap offload tx handler and allows using
7 it in cases where software crypto is used for multicast packets, e.g. when
8 using an AP_VLAN.
9
10 Signed-off-by: Felix Fietkau <nbd@nbd.name>
11 ---
12
13 --- a/net/mac80211/tx.c
14 +++ b/net/mac80211/tx.c
15 @@ -4184,88 +4184,47 @@ static void ieee80211_8023_xmit(struct i
16 struct sk_buff *skb)
17 {
18 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
19 - struct ethhdr *ehdr = (struct ethhdr *)skb->data;
20 struct ieee80211_local *local = sdata->local;
21 - bool authorized = false;
22 - bool multicast;
23 - unsigned char *ra = ehdr->h_dest;
24 struct tid_ampdu_tx *tid_tx;
25 u8 tid;
26
27 - if (IS_ERR(sta) || (sta && !sta->uploaded))
28 - sta = NULL;
29 -
30 - if (sdata->vif.type == NL80211_IFTYPE_STATION &&
31 - (!sta || !test_sta_flag(sta, WLAN_STA_TDLS_PEER)))
32 - ra = sdata->u.mgd.bssid;
33 -
34 - if (is_zero_ether_addr(ra))
35 - goto out_free;
36 -
37 if (local->ops->wake_tx_queue) {
38 u16 queue = __ieee80211_select_queue(sdata, sta, skb);
39 skb_set_queue_mapping(skb, queue);
40 skb_get_hash(skb);
41 }
42
43 - multicast = is_multicast_ether_addr(ra);
44 -
45 - if (sta)
46 - authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
47 -
48 - if (!multicast && !authorized &&
49 - (ehdr->h_proto != sdata->control_port_protocol ||
50 - !ether_addr_equal(sdata->vif.addr, ehdr->h_source)))
51 - goto out_free;
52 -
53 - if (multicast && sdata->vif.type == NL80211_IFTYPE_AP &&
54 - !atomic_read(&sdata->u.ap.num_mcast_sta))
55 - goto out_free;
56 -
57 if (unlikely(test_bit(SCAN_SW_SCANNING, &local->scanning)) &&
58 test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))
59 goto out_free;
60
61 memset(info, 0, sizeof(*info));
62
63 - if (sta) {
64 - tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
65 - tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
66 - if (tid_tx) {
67 - if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
68 - /* fall back to non-offload slow path */
69 - __ieee80211_subif_start_xmit(skb, dev, 0, 0, NULL);
70 - return;
71 - }
72 -
73 - info->flags |= IEEE80211_TX_CTL_AMPDU;
74 - if (tid_tx->timeout)
75 - tid_tx->last_tx = jiffies;
76 + tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
77 + tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
78 + if (tid_tx) {
79 + if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
80 + /* fall back to non-offload slow path */
81 + __ieee80211_subif_start_xmit(skb, dev, 0, 0, NULL);
82 + return;
83 }
84 +
85 + info->flags |= IEEE80211_TX_CTL_AMPDU;
86 + if (tid_tx->timeout)
87 + tid_tx->last_tx = jiffies;
88 }
89
90 - if (unlikely(!multicast && skb->sk &&
91 + if (unlikely(skb->sk &&
92 skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS))
93 info->ack_frame_id = ieee80211_store_ack_skb(local, skb,
94 &info->flags, NULL);
95
96 - if (unlikely(sdata->control_port_protocol == ehdr->h_proto)) {
97 - if (sdata->control_port_no_encrypt)
98 - info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
99 - info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO;
100 - }
101 -
102 - if (multicast)
103 - info->flags |= IEEE80211_TX_CTL_NO_ACK;
104 -
105 info->hw_queue = sdata->vif.hw_queue[skb_get_queue_mapping(skb)];
106
107 ieee80211_tx_stats(dev, skb->len);
108
109 - if (sta) {
110 - sta->tx_stats.bytes[skb_get_queue_mapping(skb)] += skb->len;
111 - sta->tx_stats.packets[skb_get_queue_mapping(skb)]++;
112 - }
113 + sta->tx_stats.bytes[skb_get_queue_mapping(skb)] += skb->len;
114 + sta->tx_stats.packets[skb_get_queue_mapping(skb)]++;
115
116 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
117 sdata = container_of(sdata->bss,
118 @@ -4286,6 +4245,7 @@ netdev_tx_t ieee80211_subif_start_xmit_8
119 struct net_device *dev)
120 {
121 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
122 + struct ethhdr *ehdr = (struct ethhdr *)skb->data;
123 struct sta_info *sta;
124
125 if (WARN_ON(!sdata->hw_80211_encap)) {
126 @@ -4302,6 +4262,10 @@ netdev_tx_t ieee80211_subif_start_xmit_8
127
128 if (ieee80211_lookup_ra_sta(sdata, skb, &sta))
129 kfree_skb(skb);
130 + else if (unlikely(IS_ERR_OR_NULL(sta) || !sta->uploaded ||
131 + !test_sta_flag(sta, WLAN_STA_AUTHORIZED) ||
132 + sdata->control_port_protocol == ehdr->h_proto))
133 + ieee80211_subif_start_xmit(skb, dev);
134 else
135 ieee80211_8023_xmit(sdata, dev, sta, skb);
136