320-cfg80211-add-support-for-non-linear-skbs-in-ieee8021.patch 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. From: Felix Fietkau <nbd@openwrt.org>
  2. Date: Tue, 2 Feb 2016 14:39:10 +0100
  3. Subject: [PATCH] cfg80211: add support for non-linear skbs in
  4. ieee80211_amsdu_to_8023s
  5. Signed-off-by: Felix Fietkau <nbd@openwrt.org>
  6. Signed-off-by: Johannes Berg <johannes.berg@intel.com>
  7. ---
  8. --- a/net/wireless/util.c
  9. +++ b/net/wireless/util.c
  10. @@ -644,73 +644,75 @@ int ieee80211_data_from_8023(struct sk_b
  11. }
  12. EXPORT_SYMBOL(ieee80211_data_from_8023);
  13. +static struct sk_buff *
  14. +__ieee80211_amsdu_copy(struct sk_buff *skb, unsigned int hlen,
  15. + int offset, int len)
  16. +{
  17. + struct sk_buff *frame;
  18. +
  19. + if (skb->len - offset < len)
  20. + return NULL;
  21. +
  22. + /*
  23. + * Allocate and reserve two bytes more for payload
  24. + * alignment since sizeof(struct ethhdr) is 14.
  25. + */
  26. + frame = dev_alloc_skb(hlen + sizeof(struct ethhdr) + 2 + len);
  27. +
  28. + skb_reserve(frame, hlen + sizeof(struct ethhdr) + 2);
  29. + skb_copy_bits(skb, offset, skb_put(frame, len), len);
  30. +
  31. + return frame;
  32. +}
  33. void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list,
  34. const u8 *addr, enum nl80211_iftype iftype,
  35. const unsigned int extra_headroom,
  36. bool has_80211_header)
  37. {
  38. + unsigned int hlen = ALIGN(extra_headroom, 4);
  39. struct sk_buff *frame = NULL;
  40. u16 ethertype;
  41. u8 *payload;
  42. - const struct ethhdr *eth;
  43. - int remaining, err;
  44. - u8 dst[ETH_ALEN], src[ETH_ALEN];
  45. -
  46. - if (skb_linearize(skb))
  47. - goto out;
  48. + int offset = 0, remaining, err;
  49. + struct ethhdr eth;
  50. + bool reuse_skb = true;
  51. + bool last = false;
  52. if (has_80211_header) {
  53. - err = ieee80211_data_to_8023(skb, addr, iftype);
  54. + err = __ieee80211_data_to_8023(skb, &eth, addr, iftype);
  55. if (err)
  56. goto out;
  57. -
  58. - /* skip the wrapping header */
  59. - eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr));
  60. - if (!eth)
  61. - goto out;
  62. - } else {
  63. - eth = (struct ethhdr *) skb->data;
  64. }
  65. - while (skb != frame) {
  66. + while (!last) {
  67. + unsigned int subframe_len;
  68. + int len;
  69. u8 padding;
  70. - __be16 len = eth->h_proto;
  71. - unsigned int subframe_len = sizeof(struct ethhdr) + ntohs(len);
  72. -
  73. - remaining = skb->len;
  74. - memcpy(dst, eth->h_dest, ETH_ALEN);
  75. - memcpy(src, eth->h_source, ETH_ALEN);
  76. + skb_copy_bits(skb, offset, &eth, sizeof(eth));
  77. + len = ntohs(eth.h_proto);
  78. + subframe_len = sizeof(struct ethhdr) + len;
  79. padding = (4 - subframe_len) & 0x3;
  80. +
  81. /* the last MSDU has no padding */
  82. + remaining = skb->len - offset;
  83. if (subframe_len > remaining)
  84. goto purge;
  85. - skb_pull(skb, sizeof(struct ethhdr));
  86. + offset += sizeof(struct ethhdr);
  87. /* reuse skb for the last subframe */
  88. - if (remaining <= subframe_len + padding)
  89. + last = remaining <= subframe_len + padding;
  90. + if (!skb_is_nonlinear(skb) && last) {
  91. + skb_pull(skb, offset);
  92. frame = skb;
  93. - else {
  94. - unsigned int hlen = ALIGN(extra_headroom, 4);
  95. - /*
  96. - * Allocate and reserve two bytes more for payload
  97. - * alignment since sizeof(struct ethhdr) is 14.
  98. - */
  99. - frame = dev_alloc_skb(hlen + subframe_len + 2);
  100. + reuse_skb = true;
  101. + } else {
  102. + frame = __ieee80211_amsdu_copy(skb, hlen, offset, len);
  103. if (!frame)
  104. goto purge;
  105. - skb_reserve(frame, hlen + sizeof(struct ethhdr) + 2);
  106. - memcpy(skb_put(frame, ntohs(len)), skb->data,
  107. - ntohs(len));
  108. -
  109. - eth = (struct ethhdr *)skb_pull(skb, ntohs(len) +
  110. - padding);
  111. - if (!eth) {
  112. - dev_kfree_skb(frame);
  113. - goto purge;
  114. - }
  115. + offset += len + padding;
  116. }
  117. skb_reset_network_header(frame);
  118. @@ -719,24 +721,20 @@ void ieee80211_amsdu_to_8023s(struct sk_
  119. payload = frame->data;
  120. ethertype = (payload[6] << 8) | payload[7];
  121. -
  122. if (likely((ether_addr_equal(payload, rfc1042_header) &&
  123. ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
  124. ether_addr_equal(payload, bridge_tunnel_header))) {
  125. - /* remove RFC1042 or Bridge-Tunnel
  126. - * encapsulation and replace EtherType */
  127. - skb_pull(frame, 6);
  128. - memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
  129. - memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
  130. - } else {
  131. - memcpy(skb_push(frame, sizeof(__be16)), &len,
  132. - sizeof(__be16));
  133. - memcpy(skb_push(frame, ETH_ALEN), src, ETH_ALEN);
  134. - memcpy(skb_push(frame, ETH_ALEN), dst, ETH_ALEN);
  135. + eth.h_proto = htons(ethertype);
  136. + skb_pull(frame, ETH_ALEN + 2);
  137. }
  138. +
  139. + memcpy(skb_push(frame, sizeof(eth)), &eth, sizeof(eth));
  140. __skb_queue_tail(list, frame);
  141. }
  142. + if (!reuse_skb)
  143. + dev_kfree_skb(skb);
  144. +
  145. return;
  146. purge: