image.mk: fix emitting profiles for targets that have no subtargets
[openwrt/staging/yousong.git] / package / kernel / mac80211 / patches / 319-cfg80211-add-function-for-802.3-conversion-with-sepa.patch
1 From: Felix Fietkau <nbd@openwrt.org>
2 Date: Tue, 2 Feb 2016 14:39:09 +0100
3 Subject: [PATCH] cfg80211: add function for 802.3 conversion with separate
4 output buffer
5
6 Use skb_copy_bits in preparation for allowing fragmented skbs
7
8 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
9 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
10 ---
11
12 --- a/net/wireless/util.c
13 +++ b/net/wireless/util.c
14 @@ -393,9 +393,9 @@ unsigned int ieee80211_get_hdrlen_from_s
15 }
16 EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
17
18 -unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
19 +static unsigned int __ieee80211_get_mesh_hdrlen(u8 flags)
20 {
21 - int ae = meshhdr->flags & MESH_FLAGS_AE;
22 + int ae = flags & MESH_FLAGS_AE;
23 /* 802.11-2012, 8.2.4.7.3 */
24 switch (ae) {
25 default:
26 @@ -407,21 +407,31 @@ unsigned int ieee80211_get_mesh_hdrlen(s
27 return 18;
28 }
29 }
30 +
31 +unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
32 +{
33 + return __ieee80211_get_mesh_hdrlen(meshhdr->flags);
34 +}
35 EXPORT_SYMBOL(ieee80211_get_mesh_hdrlen);
36
37 -int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr,
38 - enum nl80211_iftype iftype)
39 +static int __ieee80211_data_to_8023(struct sk_buff *skb, struct ethhdr *ehdr,
40 + const u8 *addr, enum nl80211_iftype iftype)
41 {
42 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
43 - u16 hdrlen, ethertype;
44 - u8 *payload;
45 - u8 dst[ETH_ALEN];
46 - u8 src[ETH_ALEN] __aligned(2);
47 + struct {
48 + u8 hdr[ETH_ALEN] __aligned(2);
49 + __be16 proto;
50 + } payload;
51 + struct ethhdr tmp;
52 + u16 hdrlen;
53 + u8 mesh_flags = 0;
54
55 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
56 return -1;
57
58 hdrlen = ieee80211_hdrlen(hdr->frame_control);
59 + if (skb->len < hdrlen + 8)
60 + return -1;
61
62 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
63 * header
64 @@ -432,8 +442,11 @@ int ieee80211_data_to_8023(struct sk_buf
65 * 1 0 BSSID SA DA n/a
66 * 1 1 RA TA DA SA
67 */
68 - memcpy(dst, ieee80211_get_DA(hdr), ETH_ALEN);
69 - memcpy(src, ieee80211_get_SA(hdr), ETH_ALEN);
70 + memcpy(tmp.h_dest, ieee80211_get_DA(hdr), ETH_ALEN);
71 + memcpy(tmp.h_source, ieee80211_get_SA(hdr), ETH_ALEN);
72 +
73 + if (iftype == NL80211_IFTYPE_MESH_POINT)
74 + skb_copy_bits(skb, hdrlen, &mesh_flags, 1);
75
76 switch (hdr->frame_control &
77 cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
78 @@ -450,44 +463,31 @@ int ieee80211_data_to_8023(struct sk_buf
79 iftype != NL80211_IFTYPE_STATION))
80 return -1;
81 if (iftype == NL80211_IFTYPE_MESH_POINT) {
82 - struct ieee80211s_hdr *meshdr =
83 - (struct ieee80211s_hdr *) (skb->data + hdrlen);
84 - /* make sure meshdr->flags is on the linear part */
85 - if (!pskb_may_pull(skb, hdrlen + 1))
86 - return -1;
87 - if (meshdr->flags & MESH_FLAGS_AE_A4)
88 + if (mesh_flags & MESH_FLAGS_AE_A4)
89 return -1;
90 - if (meshdr->flags & MESH_FLAGS_AE_A5_A6) {
91 + if (mesh_flags & MESH_FLAGS_AE_A5_A6) {
92 skb_copy_bits(skb, hdrlen +
93 offsetof(struct ieee80211s_hdr, eaddr1),
94 - dst, ETH_ALEN);
95 - skb_copy_bits(skb, hdrlen +
96 - offsetof(struct ieee80211s_hdr, eaddr2),
97 - src, ETH_ALEN);
98 + tmp.h_dest, 2 * ETH_ALEN);
99 }
100 - hdrlen += ieee80211_get_mesh_hdrlen(meshdr);
101 + hdrlen += __ieee80211_get_mesh_hdrlen(mesh_flags);
102 }
103 break;
104 case cpu_to_le16(IEEE80211_FCTL_FROMDS):
105 if ((iftype != NL80211_IFTYPE_STATION &&
106 iftype != NL80211_IFTYPE_P2P_CLIENT &&
107 iftype != NL80211_IFTYPE_MESH_POINT) ||
108 - (is_multicast_ether_addr(dst) &&
109 - ether_addr_equal(src, addr)))
110 + (is_multicast_ether_addr(tmp.h_dest) &&
111 + ether_addr_equal(tmp.h_source, addr)))
112 return -1;
113 if (iftype == NL80211_IFTYPE_MESH_POINT) {
114 - struct ieee80211s_hdr *meshdr =
115 - (struct ieee80211s_hdr *) (skb->data + hdrlen);
116 - /* make sure meshdr->flags is on the linear part */
117 - if (!pskb_may_pull(skb, hdrlen + 1))
118 - return -1;
119 - if (meshdr->flags & MESH_FLAGS_AE_A5_A6)
120 + if (mesh_flags & MESH_FLAGS_AE_A5_A6)
121 return -1;
122 - if (meshdr->flags & MESH_FLAGS_AE_A4)
123 + if (mesh_flags & MESH_FLAGS_AE_A4)
124 skb_copy_bits(skb, hdrlen +
125 offsetof(struct ieee80211s_hdr, eaddr1),
126 - src, ETH_ALEN);
127 - hdrlen += ieee80211_get_mesh_hdrlen(meshdr);
128 + tmp.h_source, ETH_ALEN);
129 + hdrlen += __ieee80211_get_mesh_hdrlen(mesh_flags);
130 }
131 break;
132 case cpu_to_le16(0):
133 @@ -498,33 +498,33 @@ int ieee80211_data_to_8023(struct sk_buf
134 break;
135 }
136
137 - if (!pskb_may_pull(skb, hdrlen + 8))
138 - return -1;
139 -
140 - payload = skb->data + hdrlen;
141 - ethertype = (payload[6] << 8) | payload[7];
142 + skb_copy_bits(skb, hdrlen, &payload, sizeof(payload));
143 + tmp.h_proto = payload.proto;
144
145 - if (likely((ether_addr_equal(payload, rfc1042_header) &&
146 - ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
147 - ether_addr_equal(payload, bridge_tunnel_header))) {
148 + if (likely((ether_addr_equal(payload.hdr, rfc1042_header) &&
149 + tmp.h_proto != htons(ETH_P_AARP) &&
150 + tmp.h_proto != htons(ETH_P_IPX)) ||
151 + ether_addr_equal(payload.hdr, bridge_tunnel_header)))
152 /* remove RFC1042 or Bridge-Tunnel encapsulation and
153 * replace EtherType */
154 - skb_pull(skb, hdrlen + 6);
155 - memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
156 - memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
157 - } else {
158 - struct ethhdr *ehdr;
159 - __be16 len;
160 + hdrlen += ETH_ALEN + 2;
161 + else
162 + tmp.h_proto = htons(skb->len);
163
164 - skb_pull(skb, hdrlen);
165 - len = htons(skb->len);
166 + pskb_pull(skb, hdrlen);
167 +
168 + if (!ehdr)
169 ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
170 - memcpy(ehdr->h_dest, dst, ETH_ALEN);
171 - memcpy(ehdr->h_source, src, ETH_ALEN);
172 - ehdr->h_proto = len;
173 - }
174 + memcpy(ehdr, &tmp, sizeof(tmp));
175 +
176 return 0;
177 }
178 +
179 +int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr,
180 + enum nl80211_iftype iftype)
181 +{
182 + return __ieee80211_data_to_8023(skb, NULL, addr, iftype);
183 +}
184 EXPORT_SYMBOL(ieee80211_data_to_8023);
185
186 int ieee80211_data_from_8023(struct sk_buff *skb, const u8 *addr,