315-mac80211-avoid-duplicate-TX-path-station-lookup.patch 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. From: Johannes Berg <[email protected]>
  2. Date: Fri, 20 Mar 2015 14:18:27 +0100
  3. Subject: [PATCH] mac80211: avoid duplicate TX path station lookup
  4. Instead of looking up the destination station twice in the TX path
  5. (first to build the header, and then for control processing), save
  6. it when building the header and use it later in the TX path.
  7. To avoid having to look up the station in the many callers, allow
  8. those to pass %NULL which keeps the existing lookup.
  9. Signed-off-by: Johannes Berg <[email protected]>
  10. ---
  11. --- a/net/mac80211/cfg.c
  12. +++ b/net/mac80211/cfg.c
  13. @@ -3565,7 +3565,7 @@ static int ieee80211_probe_client(struct
  14. nullfunc->qos_ctrl = cpu_to_le16(7);
  15. local_bh_disable();
  16. - ieee80211_xmit(sdata, skb);
  17. + ieee80211_xmit(sdata, sta, skb);
  18. local_bh_enable();
  19. rcu_read_unlock();
  20. --- a/net/mac80211/ieee80211_i.h
  21. +++ b/net/mac80211/ieee80211_i.h
  22. @@ -1775,7 +1775,8 @@ void mac80211_ev_michael_mic_failure(str
  23. gfp_t gfp);
  24. void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata,
  25. bool bss_notify);
  26. -void ieee80211_xmit(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb);
  27. +void ieee80211_xmit(struct ieee80211_sub_if_data *sdata,
  28. + struct sta_info *sta, struct sk_buff *skb);
  29. void __ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata,
  30. struct sk_buff *skb, int tid,
  31. --- a/net/mac80211/sta_info.c
  32. +++ b/net/mac80211/sta_info.c
  33. @@ -1279,7 +1279,7 @@ static void ieee80211_send_null_response
  34. }
  35. info->band = chanctx_conf->def.chan->band;
  36. - ieee80211_xmit(sdata, skb);
  37. + ieee80211_xmit(sdata, sta, skb);
  38. rcu_read_unlock();
  39. }
  40. --- a/net/mac80211/tx.c
  41. +++ b/net/mac80211/tx.c
  42. @@ -1110,11 +1110,13 @@ static bool ieee80211_tx_prep_agg(struct
  43. /*
  44. * initialises @tx
  45. + * pass %NULL for the station if unknown, a valid pointer if known
  46. + * or an ERR_PTR() if the station is known not to exist
  47. */
  48. static ieee80211_tx_result
  49. ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata,
  50. struct ieee80211_tx_data *tx,
  51. - struct sk_buff *skb)
  52. + struct sta_info *sta, struct sk_buff *skb)
  53. {
  54. struct ieee80211_local *local = sdata->local;
  55. struct ieee80211_hdr *hdr;
  56. @@ -1137,17 +1139,22 @@ ieee80211_tx_prepare(struct ieee80211_su
  57. hdr = (struct ieee80211_hdr *) skb->data;
  58. - if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
  59. - tx->sta = rcu_dereference(sdata->u.vlan.sta);
  60. - if (!tx->sta && sdata->dev->ieee80211_ptr->use_4addr)
  61. - return TX_DROP;
  62. - } else if (info->flags & (IEEE80211_TX_CTL_INJECTED |
  63. - IEEE80211_TX_INTFL_NL80211_FRAME_TX) ||
  64. - tx->sdata->control_port_protocol == tx->skb->protocol) {
  65. - tx->sta = sta_info_get_bss(sdata, hdr->addr1);
  66. + if (likely(sta)) {
  67. + if (!IS_ERR(sta))
  68. + tx->sta = sta;
  69. + } else {
  70. + if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
  71. + tx->sta = rcu_dereference(sdata->u.vlan.sta);
  72. + if (!tx->sta && sdata->wdev.use_4addr)
  73. + return TX_DROP;
  74. + } else if (info->flags & (IEEE80211_TX_INTFL_NL80211_FRAME_TX |
  75. + IEEE80211_TX_CTL_INJECTED) ||
  76. + tx->sdata->control_port_protocol == tx->skb->protocol) {
  77. + tx->sta = sta_info_get_bss(sdata, hdr->addr1);
  78. + }
  79. + if (!tx->sta && !is_multicast_ether_addr(hdr->addr1))
  80. + tx->sta = sta_info_get(sdata, hdr->addr1);
  81. }
  82. - if (!tx->sta && !is_multicast_ether_addr(hdr->addr1))
  83. - tx->sta = sta_info_get(sdata, hdr->addr1);
  84. if (tx->sta && ieee80211_is_data_qos(hdr->frame_control) &&
  85. !ieee80211_is_qos_nullfunc(hdr->frame_control) &&
  86. @@ -1485,7 +1492,7 @@ bool ieee80211_tx_prepare_skb(struct iee
  87. struct ieee80211_tx_data tx;
  88. struct sk_buff *skb2;
  89. - if (ieee80211_tx_prepare(sdata, &tx, skb) == TX_DROP)
  90. + if (ieee80211_tx_prepare(sdata, &tx, NULL, skb) == TX_DROP)
  91. return false;
  92. info->band = band;
  93. @@ -1518,7 +1525,8 @@ EXPORT_SYMBOL(ieee80211_tx_prepare_skb);
  94. * Returns false if the frame couldn't be transmitted but was queued instead.
  95. */
  96. static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata,
  97. - struct sk_buff *skb, bool txpending)
  98. + struct sta_info *sta, struct sk_buff *skb,
  99. + bool txpending)
  100. {
  101. struct ieee80211_local *local = sdata->local;
  102. struct ieee80211_tx_data tx;
  103. @@ -1534,7 +1542,7 @@ static bool ieee80211_tx(struct ieee8021
  104. /* initialises tx */
  105. led_len = skb->len;
  106. - res_prepare = ieee80211_tx_prepare(sdata, &tx, skb);
  107. + res_prepare = ieee80211_tx_prepare(sdata, &tx, sta, skb);
  108. if (unlikely(res_prepare == TX_DROP)) {
  109. ieee80211_free_txskb(&local->hw, skb);
  110. @@ -1590,7 +1598,8 @@ static int ieee80211_skb_resize(struct i
  111. return 0;
  112. }
  113. -void ieee80211_xmit(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
  114. +void ieee80211_xmit(struct ieee80211_sub_if_data *sdata,
  115. + struct sta_info *sta, struct sk_buff *skb)
  116. {
  117. struct ieee80211_local *local = sdata->local;
  118. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  119. @@ -1625,7 +1634,7 @@ void ieee80211_xmit(struct ieee80211_sub
  120. }
  121. ieee80211_set_qos_hdr(sdata, skb);
  122. - ieee80211_tx(sdata, skb, false);
  123. + ieee80211_tx(sdata, sta, skb, false);
  124. }
  125. static bool ieee80211_parse_tx_radiotap(struct sk_buff *skb)
  126. @@ -1846,7 +1855,7 @@ netdev_tx_t ieee80211_monitor_start_xmit
  127. goto fail_rcu;
  128. info->band = chandef->chan->band;
  129. - ieee80211_xmit(sdata, skb);
  130. + ieee80211_xmit(sdata, NULL, skb);
  131. rcu_read_unlock();
  132. return NETDEV_TX_OK;
  133. @@ -1877,7 +1886,8 @@ fail:
  134. * Returns: the (possibly reallocated) skb or an ERR_PTR() code
  135. */
  136. static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata,
  137. - struct sk_buff *skb, u32 info_flags)
  138. + struct sk_buff *skb, u32 info_flags,
  139. + struct sta_info **sta_out)
  140. {
  141. struct ieee80211_local *local = sdata->local;
  142. struct ieee80211_tx_info *info;
  143. @@ -1920,6 +1930,7 @@ static struct sk_buff *ieee80211_build_h
  144. authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
  145. wme_sta = sta->sta.wme;
  146. have_station = true;
  147. + *sta_out = sta;
  148. } else if (sdata->wdev.use_4addr) {
  149. ret = -ENOLINK;
  150. goto free;
  151. @@ -2073,6 +2084,7 @@ static struct sk_buff *ieee80211_build_h
  152. have_station = true;
  153. authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
  154. wme_sta = sta->sta.wme;
  155. + *sta_out = sta;
  156. } else if (sdata->u.mgd.use_4addr &&
  157. cpu_to_be16(ethertype) != sdata->control_port_protocol) {
  158. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
  159. @@ -2136,13 +2148,18 @@ static struct sk_buff *ieee80211_build_h
  160. * and mesh mode checks authorization later.
  161. */
  162. multicast = is_multicast_ether_addr(hdr.addr1);
  163. - if (!multicast && !have_station &&
  164. - !ieee80211_vif_is_mesh(&sdata->vif)) {
  165. - sta = sta_info_get(sdata, hdr.addr1);
  166. + if (multicast) {
  167. + *sta_out = ERR_PTR(-ENOENT);
  168. + } else if (!have_station && !ieee80211_vif_is_mesh(&sdata->vif)) {
  169. + if (sdata->control_port_protocol == skb->protocol)
  170. + sta = sta_info_get_bss(sdata, hdr.addr1);
  171. + else
  172. + sta = sta_info_get(sdata, hdr.addr1);
  173. if (sta) {
  174. authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
  175. wme_sta = sta->sta.wme;
  176. }
  177. + *sta_out = sta ?: ERR_PTR(-ENOENT);
  178. }
  179. /* For mesh, the use of the QoS header is mandatory */
  180. @@ -2320,6 +2337,7 @@ void __ieee80211_subif_start_xmit(struct
  181. u32 info_flags)
  182. {
  183. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  184. + struct sta_info *sta = NULL;
  185. if (unlikely(skb->len < ETH_HLEN)) {
  186. kfree_skb(skb);
  187. @@ -2328,7 +2346,7 @@ void __ieee80211_subif_start_xmit(struct
  188. rcu_read_lock();
  189. - skb = ieee80211_build_hdr(sdata, skb, info_flags);
  190. + skb = ieee80211_build_hdr(sdata, skb, info_flags, &sta);
  191. if (IS_ERR(skb))
  192. goto out;
  193. @@ -2336,7 +2354,7 @@ void __ieee80211_subif_start_xmit(struct
  194. dev->stats.tx_bytes += skb->len;
  195. dev->trans_start = jiffies;
  196. - ieee80211_xmit(sdata, skb);
  197. + ieee80211_xmit(sdata, sta, skb);
  198. out:
  199. rcu_read_unlock();
  200. }
  201. @@ -2364,10 +2382,11 @@ ieee80211_build_data_template(struct iee
  202. .local = sdata->local,
  203. .sdata = sdata,
  204. };
  205. + struct sta_info *sta_ignore;
  206. rcu_read_lock();
  207. - skb = ieee80211_build_hdr(sdata, skb, info_flags);
  208. + skb = ieee80211_build_hdr(sdata, skb, info_flags, &sta_ignore);
  209. if (IS_ERR(skb))
  210. goto out;
  211. @@ -2425,7 +2444,7 @@ static bool ieee80211_tx_pending_skb(str
  212. return true;
  213. }
  214. info->band = chanctx_conf->def.chan->band;
  215. - result = ieee80211_tx(sdata, skb, true);
  216. + result = ieee80211_tx(sdata, NULL, skb, true);
  217. } else {
  218. struct sk_buff_head skbs;
  219. @@ -3163,7 +3182,7 @@ ieee80211_get_buffered_bc(struct ieee802
  220. if (sdata->vif.type == NL80211_IFTYPE_AP)
  221. sdata = IEEE80211_DEV_TO_SUB_IF(skb->dev);
  222. - if (!ieee80211_tx_prepare(sdata, &tx, skb))
  223. + if (!ieee80211_tx_prepare(sdata, &tx, NULL, skb))
  224. break;
  225. dev_kfree_skb_any(skb);
  226. }
  227. @@ -3295,6 +3314,6 @@ void __ieee80211_tx_skb_tid_band(struct
  228. */
  229. local_bh_disable();
  230. IEEE80211_SKB_CB(skb)->band = band;
  231. - ieee80211_xmit(sdata, skb);
  232. + ieee80211_xmit(sdata, NULL, skb);
  233. local_bh_enable();
  234. }