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