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
6 Use skb_copy_bits in preparation for allowing fragmented skbs
8 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
9 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
12 --- a/net/wireless/util.c
13 +++ b/net/wireless/util.c
14 @@ -393,9 +393,9 @@ unsigned int ieee80211_get_hdrlen_from_s
16 EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
18 -unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
19 +static unsigned int __ieee80211_get_mesh_hdrlen(u8 flags)
21 - int ae = meshhdr->flags & MESH_FLAGS_AE;
22 + int ae = flags & MESH_FLAGS_AE;
23 /* 802.11-2012, 8.2.4.7.3 */
26 @@ -407,21 +407,31 @@ unsigned int ieee80211_get_mesh_hdrlen(s
31 +unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
33 + return __ieee80211_get_mesh_hdrlen(meshhdr->flags);
35 EXPORT_SYMBOL(ieee80211_get_mesh_hdrlen);
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)
42 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
43 - u16 hdrlen, ethertype;
46 - u8 src[ETH_ALEN] __aligned(2);
48 + u8 hdr[ETH_ALEN] __aligned(2);
55 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
58 hdrlen = ieee80211_hdrlen(hdr->frame_control);
59 + if (skb->len < hdrlen + 8)
62 /* convert IEEE 802.11 header + possible LLC headers into Ethernet
64 @@ -432,8 +442,11 @@ int ieee80211_data_to_8023(struct sk_buf
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);
73 + if (iftype == NL80211_IFTYPE_MESH_POINT)
74 + skb_copy_bits(skb, hdrlen, &mesh_flags, 1);
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))
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))
87 - if (meshdr->flags & MESH_FLAGS_AE_A4)
88 + if (mesh_flags & MESH_FLAGS_AE_A4)
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),
95 - skb_copy_bits(skb, hdrlen +
96 - offsetof(struct ieee80211s_hdr, eaddr2),
98 + tmp.h_dest, 2 * ETH_ALEN);
100 - hdrlen += ieee80211_get_mesh_hdrlen(meshdr);
101 + hdrlen += __ieee80211_get_mesh_hdrlen(mesh_flags);
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)))
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))
119 - if (meshdr->flags & MESH_FLAGS_AE_A5_A6)
120 + if (mesh_flags & MESH_FLAGS_AE_A5_A6)
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),
127 - hdrlen += ieee80211_get_mesh_hdrlen(meshdr);
128 + tmp.h_source, ETH_ALEN);
129 + hdrlen += __ieee80211_get_mesh_hdrlen(mesh_flags);
133 @@ -498,33 +498,33 @@ int ieee80211_data_to_8023(struct sk_buf
137 - if (!pskb_may_pull(skb, hdrlen + 8))
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;
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);
158 - struct ethhdr *ehdr;
160 + hdrlen += ETH_ALEN + 2;
162 + tmp.h_proto = htons(skb->len);
164 - skb_pull(skb, hdrlen);
165 - len = htons(skb->len);
166 + pskb_pull(skb, hdrlen);
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;
174 + memcpy(ehdr, &tmp, sizeof(tmp));
179 +int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr,
180 + enum nl80211_iftype iftype)
182 + return __ieee80211_data_to_8023(skb, NULL, addr, iftype);
184 EXPORT_SYMBOL(ieee80211_data_to_8023);
186 int ieee80211_data_from_8023(struct sk_buff *skb, const u8 *addr,