提交 2d1c304c 编写于 作者: F Felix Fietkau 提交者: Johannes Berg

cfg80211: add function for 802.3 conversion with separate output buffer

Use skb_copy_bits in preparation for allowing fragmented skbs
Signed-off-by: NFelix Fietkau <nbd@openwrt.org>
Signed-off-by: NJohannes Berg <johannes.berg@intel.com>
上级 88665f5a
...@@ -393,9 +393,9 @@ unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb) ...@@ -393,9 +393,9 @@ unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
} }
EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb); EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr) static unsigned int __ieee80211_get_mesh_hdrlen(u8 flags)
{ {
int ae = meshhdr->flags & MESH_FLAGS_AE; int ae = flags & MESH_FLAGS_AE;
/* 802.11-2012, 8.2.4.7.3 */ /* 802.11-2012, 8.2.4.7.3 */
switch (ae) { switch (ae) {
default: default:
...@@ -407,21 +407,31 @@ unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr) ...@@ -407,21 +407,31 @@ unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
return 18; return 18;
} }
} }
unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
{
return __ieee80211_get_mesh_hdrlen(meshhdr->flags);
}
EXPORT_SYMBOL(ieee80211_get_mesh_hdrlen); EXPORT_SYMBOL(ieee80211_get_mesh_hdrlen);
int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr, static int __ieee80211_data_to_8023(struct sk_buff *skb, struct ethhdr *ehdr,
enum nl80211_iftype iftype) const u8 *addr, enum nl80211_iftype iftype)
{ {
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
u16 hdrlen, ethertype; struct {
u8 *payload; u8 hdr[ETH_ALEN] __aligned(2);
u8 dst[ETH_ALEN]; __be16 proto;
u8 src[ETH_ALEN] __aligned(2); } payload;
struct ethhdr tmp;
u16 hdrlen;
u8 mesh_flags = 0;
if (unlikely(!ieee80211_is_data_present(hdr->frame_control))) if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
return -1; return -1;
hdrlen = ieee80211_hdrlen(hdr->frame_control); hdrlen = ieee80211_hdrlen(hdr->frame_control);
if (skb->len < hdrlen + 8)
return -1;
/* convert IEEE 802.11 header + possible LLC headers into Ethernet /* convert IEEE 802.11 header + possible LLC headers into Ethernet
* header * header
...@@ -432,8 +442,11 @@ int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr, ...@@ -432,8 +442,11 @@ int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr,
* 1 0 BSSID SA DA n/a * 1 0 BSSID SA DA n/a
* 1 1 RA TA DA SA * 1 1 RA TA DA SA
*/ */
memcpy(dst, ieee80211_get_DA(hdr), ETH_ALEN); memcpy(tmp.h_dest, ieee80211_get_DA(hdr), ETH_ALEN);
memcpy(src, ieee80211_get_SA(hdr), ETH_ALEN); memcpy(tmp.h_source, ieee80211_get_SA(hdr), ETH_ALEN);
if (iftype == NL80211_IFTYPE_MESH_POINT)
skb_copy_bits(skb, hdrlen, &mesh_flags, 1);
switch (hdr->frame_control & switch (hdr->frame_control &
cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) { cpu_to_le16(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
...@@ -450,44 +463,31 @@ int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr, ...@@ -450,44 +463,31 @@ int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr,
iftype != NL80211_IFTYPE_STATION)) iftype != NL80211_IFTYPE_STATION))
return -1; return -1;
if (iftype == NL80211_IFTYPE_MESH_POINT) { if (iftype == NL80211_IFTYPE_MESH_POINT) {
struct ieee80211s_hdr *meshdr = if (mesh_flags & MESH_FLAGS_AE_A4)
(struct ieee80211s_hdr *) (skb->data + hdrlen);
/* make sure meshdr->flags is on the linear part */
if (!pskb_may_pull(skb, hdrlen + 1))
return -1;
if (meshdr->flags & MESH_FLAGS_AE_A4)
return -1; return -1;
if (meshdr->flags & MESH_FLAGS_AE_A5_A6) { if (mesh_flags & MESH_FLAGS_AE_A5_A6) {
skb_copy_bits(skb, hdrlen + skb_copy_bits(skb, hdrlen +
offsetof(struct ieee80211s_hdr, eaddr1), offsetof(struct ieee80211s_hdr, eaddr1),
dst, ETH_ALEN); tmp.h_dest, 2 * ETH_ALEN);
skb_copy_bits(skb, hdrlen +
offsetof(struct ieee80211s_hdr, eaddr2),
src, ETH_ALEN);
} }
hdrlen += ieee80211_get_mesh_hdrlen(meshdr); hdrlen += __ieee80211_get_mesh_hdrlen(mesh_flags);
} }
break; break;
case cpu_to_le16(IEEE80211_FCTL_FROMDS): case cpu_to_le16(IEEE80211_FCTL_FROMDS):
if ((iftype != NL80211_IFTYPE_STATION && if ((iftype != NL80211_IFTYPE_STATION &&
iftype != NL80211_IFTYPE_P2P_CLIENT && iftype != NL80211_IFTYPE_P2P_CLIENT &&
iftype != NL80211_IFTYPE_MESH_POINT) || iftype != NL80211_IFTYPE_MESH_POINT) ||
(is_multicast_ether_addr(dst) && (is_multicast_ether_addr(tmp.h_dest) &&
ether_addr_equal(src, addr))) ether_addr_equal(tmp.h_source, addr)))
return -1; return -1;
if (iftype == NL80211_IFTYPE_MESH_POINT) { if (iftype == NL80211_IFTYPE_MESH_POINT) {
struct ieee80211s_hdr *meshdr = if (mesh_flags & MESH_FLAGS_AE_A5_A6)
(struct ieee80211s_hdr *) (skb->data + hdrlen);
/* make sure meshdr->flags is on the linear part */
if (!pskb_may_pull(skb, hdrlen + 1))
return -1; return -1;
if (meshdr->flags & MESH_FLAGS_AE_A5_A6) if (mesh_flags & MESH_FLAGS_AE_A4)
return -1;
if (meshdr->flags & MESH_FLAGS_AE_A4)
skb_copy_bits(skb, hdrlen + skb_copy_bits(skb, hdrlen +
offsetof(struct ieee80211s_hdr, eaddr1), offsetof(struct ieee80211s_hdr, eaddr1),
src, ETH_ALEN); tmp.h_source, ETH_ALEN);
hdrlen += ieee80211_get_mesh_hdrlen(meshdr); hdrlen += __ieee80211_get_mesh_hdrlen(mesh_flags);
} }
break; break;
case cpu_to_le16(0): case cpu_to_le16(0):
...@@ -498,33 +498,33 @@ int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr, ...@@ -498,33 +498,33 @@ int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr,
break; break;
} }
if (!pskb_may_pull(skb, hdrlen + 8)) skb_copy_bits(skb, hdrlen, &payload, sizeof(payload));
return -1; tmp.h_proto = payload.proto;
payload = skb->data + hdrlen;
ethertype = (payload[6] << 8) | payload[7];
if (likely((ether_addr_equal(payload, rfc1042_header) && if (likely((ether_addr_equal(payload.hdr, rfc1042_header) &&
ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) || tmp.h_proto != htons(ETH_P_AARP) &&
ether_addr_equal(payload, bridge_tunnel_header))) { tmp.h_proto != htons(ETH_P_IPX)) ||
ether_addr_equal(payload.hdr, bridge_tunnel_header)))
/* remove RFC1042 or Bridge-Tunnel encapsulation and /* remove RFC1042 or Bridge-Tunnel encapsulation and
* replace EtherType */ * replace EtherType */
skb_pull(skb, hdrlen + 6); hdrlen += ETH_ALEN + 2;
memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN); else
memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN); tmp.h_proto = htons(skb->len);
} else {
struct ethhdr *ehdr; pskb_pull(skb, hdrlen);
__be16 len;
skb_pull(skb, hdrlen); if (!ehdr)
len = htons(skb->len);
ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr)); ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
memcpy(ehdr->h_dest, dst, ETH_ALEN); memcpy(ehdr, &tmp, sizeof(tmp));
memcpy(ehdr->h_source, src, ETH_ALEN);
ehdr->h_proto = len;
}
return 0; return 0;
} }
int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr,
enum nl80211_iftype iftype)
{
return __ieee80211_data_to_8023(skb, NULL, addr, iftype);
}
EXPORT_SYMBOL(ieee80211_data_to_8023); EXPORT_SYMBOL(ieee80211_data_to_8023);
int ieee80211_data_from_8023(struct sk_buff *skb, const u8 *addr, int ieee80211_data_from_8023(struct sk_buff *skb, const u8 *addr,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册