b0b2823cc9ef3acb1e17299ae5f33d33250fe638
[openwrt/staging/chunkeey.git] / target / linux / generic / backport-4.14 / 274-flow_dissector-Parse-batman-adv-unicast-headers.patch
1 From: Sven Eckelmann <sven.eckelmann@openmesh.com>
2 Date: Thu, 21 Dec 2017 10:17:42 +0100
3 Subject: [PATCH] flow_dissector: Parse batman-adv unicast headers
4
5 The batman-adv unicast packets contain a full layer 2 frame in encapsulated
6 form. The flow dissector must therefore be able to parse the batman-adv
7 unicast header to reach the layer 2+3 information.
8
9 +--------------------+
10 | ip(v6)hdr |
11 +--------------------+
12 | inner ethhdr |
13 +--------------------+
14 | batadv unicast hdr |
15 +--------------------+
16 | outer ethhdr |
17 +--------------------+
18
19 The obtained information from the upper layer can then be used by RPS to
20 schedule the processing on separate cores. This allows better distribution
21 of multiple flows from the same neighbor to different cores.
22
23 Signed-off-by: Sven Eckelmann <sven.eckelmann@openmesh.com>
24 Reviewed-by: Jiri Pirko <jiri@mellanox.com>
25 Acked-by: Willem de Bruijn <willemb@google.com>
26 Signed-off-by: David S. Miller <davem@davemloft.net>
27 ---
28
29 --- a/net/core/flow_dissector.c
30 +++ b/net/core/flow_dissector.c
31 @@ -22,6 +22,7 @@
32 #include <linux/tcp.h>
33 #include <net/flow_dissector.h>
34 #include <scsi/fc/fc_fcoe.h>
35 +#include <uapi/linux/batadv_packet.h>
36
37 static void dissector_set_key(struct flow_dissector *flow_dissector,
38 enum flow_dissector_key_id key_id)
39 @@ -338,6 +339,57 @@ __skb_flow_dissect_gre(const struct sk_b
40 return FLOW_DISSECT_RET_PROTO_AGAIN;
41 }
42
43 +/**
44 + * __skb_flow_dissect_batadv() - dissect batman-adv header
45 + * @skb: sk_buff to with the batman-adv header
46 + * @key_control: flow dissectors control key
47 + * @data: raw buffer pointer to the packet, if NULL use skb->data
48 + * @p_proto: pointer used to update the protocol to process next
49 + * @p_nhoff: pointer used to update inner network header offset
50 + * @hlen: packet header length
51 + * @flags: any combination of FLOW_DISSECTOR_F_*
52 + *
53 + * ETH_P_BATMAN packets are tried to be dissected. Only
54 + * &struct batadv_unicast packets are actually processed because they contain an
55 + * inner ethernet header and are usually followed by actual network header. This
56 + * allows the flow dissector to continue processing the packet.
57 + *
58 + * Return: FLOW_DISSECT_RET_PROTO_AGAIN when &struct batadv_unicast was found,
59 + * FLOW_DISSECT_RET_OUT_GOOD when dissector should stop after encapsulation,
60 + * otherwise FLOW_DISSECT_RET_OUT_BAD
61 + */
62 +static enum flow_dissect_ret
63 +__skb_flow_dissect_batadv(const struct sk_buff *skb,
64 + struct flow_dissector_key_control *key_control,
65 + void *data, __be16 *p_proto, int *p_nhoff, int hlen,
66 + unsigned int flags)
67 +{
68 + struct {
69 + struct batadv_unicast_packet batadv_unicast;
70 + struct ethhdr eth;
71 + } *hdr, _hdr;
72 +
73 + hdr = __skb_header_pointer(skb, *p_nhoff, sizeof(_hdr), data, hlen,
74 + &_hdr);
75 + if (!hdr)
76 + return FLOW_DISSECT_RET_OUT_BAD;
77 +
78 + if (hdr->batadv_unicast.version != BATADV_COMPAT_VERSION)
79 + return FLOW_DISSECT_RET_OUT_BAD;
80 +
81 + if (hdr->batadv_unicast.packet_type != BATADV_UNICAST)
82 + return FLOW_DISSECT_RET_OUT_BAD;
83 +
84 + *p_proto = hdr->eth.h_proto;
85 + *p_nhoff += sizeof(*hdr);
86 +
87 + key_control->flags |= FLOW_DIS_ENCAPSULATION;
88 + if (flags & FLOW_DISSECTOR_F_STOP_AT_ENCAP)
89 + return FLOW_DISSECT_RET_OUT_GOOD;
90 +
91 + return FLOW_DISSECT_RET_PROTO_AGAIN;
92 +}
93 +
94 static void
95 __skb_flow_dissect_tcp(const struct sk_buff *skb,
96 struct flow_dissector *flow_dissector,
97 @@ -717,6 +769,11 @@ proto_again:
98 nhoff, hlen);
99 break;
100
101 + case htons(ETH_P_BATMAN):
102 + fdret = __skb_flow_dissect_batadv(skb, key_control, data,
103 + &proto, &nhoff, hlen, flags);
104 + break;
105 +
106 default:
107 fdret = FLOW_DISSECT_RET_OUT_BAD;
108 break;