1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Fri, 2 Dec 2022 13:54:15 +0100
3 Subject: [PATCH] wifi: cfg80211: factor out bridge tunnel / RFC1042 header
6 The same check is done in multiple places, unify it.
8 Signed-off-by: Felix Fietkau <nbd@nbd.name>
11 --- a/net/wireless/util.c
12 +++ b/net/wireless/util.c
13 @@ -542,6 +542,21 @@ unsigned int ieee80211_get_mesh_hdrlen(s
15 EXPORT_SYMBOL(ieee80211_get_mesh_hdrlen);
17 +static bool ieee80211_get_8023_tunnel_proto(const void *hdr, __be16 *proto)
19 + const __be16 *hdr_proto = hdr + ETH_ALEN;
21 + if (!(ether_addr_equal(hdr, rfc1042_header) &&
22 + *hdr_proto != htons(ETH_P_AARP) &&
23 + *hdr_proto != htons(ETH_P_IPX)) &&
24 + !ether_addr_equal(hdr, bridge_tunnel_header))
27 + *proto = *hdr_proto;
32 int ieee80211_data_to_8023_exthdr(struct sk_buff *skb, struct ethhdr *ehdr,
33 const u8 *addr, enum nl80211_iftype iftype,
34 u8 data_offset, bool is_amsdu)
35 @@ -633,14 +648,9 @@ int ieee80211_data_to_8023_exthdr(struct
37 if (likely(!is_amsdu &&
38 skb_copy_bits(skb, hdrlen, &payload, sizeof(payload)) == 0 &&
39 - ((ether_addr_equal(payload.hdr, rfc1042_header) &&
40 - payload.proto != htons(ETH_P_AARP) &&
41 - payload.proto != htons(ETH_P_IPX)) ||
42 - ether_addr_equal(payload.hdr, bridge_tunnel_header)))) {
43 - /* remove RFC1042 or Bridge-Tunnel encapsulation and
44 - * replace EtherType */
45 + ieee80211_get_8023_tunnel_proto(&payload, &tmp.h_proto))) {
46 + /* remove RFC1042 or Bridge-Tunnel encapsulation */
47 hdrlen += ETH_ALEN + 2;
48 - tmp.h_proto = payload.proto;
49 skb_postpull_rcsum(skb, &payload, ETH_ALEN + 2);
51 tmp.h_proto = htons(skb->len - hdrlen);
52 @@ -756,8 +766,6 @@ void ieee80211_amsdu_to_8023s(struct sk_
54 unsigned int hlen = ALIGN(extra_headroom, 4);
55 struct sk_buff *frame = NULL;
58 int offset = 0, remaining;
60 bool reuse_frag = skb->head_frag && !skb_has_frag_list(skb);
61 @@ -811,14 +819,8 @@ void ieee80211_amsdu_to_8023s(struct sk_
62 frame->dev = skb->dev;
63 frame->priority = skb->priority;
65 - payload = frame->data;
66 - ethertype = (payload[6] << 8) | payload[7];
67 - if (likely((ether_addr_equal(payload, rfc1042_header) &&
68 - ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
69 - ether_addr_equal(payload, bridge_tunnel_header))) {
70 - eth.h_proto = htons(ethertype);
71 + if (likely(ieee80211_get_8023_tunnel_proto(frame->data, ð.h_proto)))
72 skb_pull(frame, ETH_ALEN + 2);
75 memcpy(skb_push(frame, sizeof(eth)), ð, sizeof(eth));
76 __skb_queue_tail(list, frame);