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
6 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
7 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
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
14 EXPORT_SYMBOL(ieee80211_data_from_8023);
16 +static struct sk_buff *
17 +__ieee80211_amsdu_copy(struct sk_buff *skb, unsigned int hlen,
18 + int offset, int len)
20 + struct sk_buff *frame;
22 + if (skb->len - offset < len)
26 + * Allocate and reserve two bytes more for payload
27 + * alignment since sizeof(struct ethhdr) is 14.
29 + frame = dev_alloc_skb(hlen + sizeof(struct ethhdr) + 2 + len);
31 + skb_reserve(frame, hlen + sizeof(struct ethhdr) + 2);
32 + skb_copy_bits(skb, offset, skb_put(frame, len), len);
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)
42 + unsigned int hlen = ALIGN(extra_headroom, 4);
43 struct sk_buff *frame = NULL;
46 - const struct ethhdr *eth;
48 - u8 dst[ETH_ALEN], src[ETH_ALEN];
50 - if (skb_linearize(skb))
52 + int offset = 0, remaining, err;
54 + bool reuse_skb = true;
57 if (has_80211_header) {
58 - err = ieee80211_data_to_8023(skb, addr, iftype);
59 + err = __ieee80211_data_to_8023(skb, ð, addr, iftype);
63 - /* skip the wrapping header */
64 - eth = (struct ethhdr *) skb_pull(skb, sizeof(struct ethhdr));
68 - eth = (struct ethhdr *) skb->data;
71 - while (skb != frame) {
73 + unsigned int subframe_len;
76 - __be16 len = eth->h_proto;
77 - unsigned int subframe_len = sizeof(struct ethhdr) + ntohs(len);
79 - remaining = skb->len;
80 - memcpy(dst, eth->h_dest, ETH_ALEN);
81 - memcpy(src, eth->h_source, ETH_ALEN);
83 + skb_copy_bits(skb, offset, ð, sizeof(eth));
84 + len = ntohs(eth.h_proto);
85 + subframe_len = sizeof(struct ethhdr) + len;
86 padding = (4 - subframe_len) & 0x3;
88 /* the last MSDU has no padding */
89 + remaining = skb->len - offset;
90 if (subframe_len > remaining)
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);
102 - unsigned int hlen = ALIGN(extra_headroom, 4);
104 - * Allocate and reserve two bytes more for payload
105 - * alignment since sizeof(struct ethhdr) is 14.
107 - frame = dev_alloc_skb(hlen + subframe_len + 2);
110 + frame = __ieee80211_amsdu_copy(skb, hlen, offset, len);
114 - skb_reserve(frame, hlen + sizeof(struct ethhdr) + 2);
115 - memcpy(skb_put(frame, ntohs(len)), skb->data,
118 - eth = (struct ethhdr *)skb_pull(skb, ntohs(len) +
121 - dev_kfree_skb(frame);
124 + offset += len + padding;
127 skb_reset_network_header(frame);
128 @@ -719,24 +721,20 @@ void ieee80211_amsdu_to_8023s(struct sk_
130 payload = frame->data;
131 ethertype = (payload[6] << 8) | payload[7];
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);
142 - memcpy(skb_push(frame, sizeof(__be16)), &len,
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);
150 + memcpy(skb_push(frame, sizeof(eth)), ð, sizeof(eth));
151 __skb_queue_tail(list, frame);
155 + dev_kfree_skb(skb);