media: dvb_frontend: be sure to init dvb_frontend_handle_ioctl() return code
[linux/fpc-iii.git] / net / core / flow_dissector.c
blob544bddf08e13c7f6e47aadc737244c9ba5af56b2
1 #include <linux/kernel.h>
2 #include <linux/skbuff.h>
3 #include <linux/export.h>
4 #include <linux/ip.h>
5 #include <linux/ipv6.h>
6 #include <linux/if_vlan.h>
7 #include <net/dsa.h>
8 #include <net/dst_metadata.h>
9 #include <net/ip.h>
10 #include <net/ipv6.h>
11 #include <net/gre.h>
12 #include <net/pptp.h>
13 #include <net/tipc.h>
14 #include <linux/igmp.h>
15 #include <linux/icmp.h>
16 #include <linux/sctp.h>
17 #include <linux/dccp.h>
18 #include <linux/if_tunnel.h>
19 #include <linux/if_pppox.h>
20 #include <linux/ppp_defs.h>
21 #include <linux/stddef.h>
22 #include <linux/if_ether.h>
23 #include <linux/mpls.h>
24 #include <linux/tcp.h>
25 #include <net/flow_dissector.h>
26 #include <scsi/fc/fc_fcoe.h>
28 static void dissector_set_key(struct flow_dissector *flow_dissector,
29 enum flow_dissector_key_id key_id)
31 flow_dissector->used_keys |= (1 << key_id);
34 void skb_flow_dissector_init(struct flow_dissector *flow_dissector,
35 const struct flow_dissector_key *key,
36 unsigned int key_count)
38 unsigned int i;
40 memset(flow_dissector, 0, sizeof(*flow_dissector));
42 for (i = 0; i < key_count; i++, key++) {
43 /* User should make sure that every key target offset is withing
44 * boundaries of unsigned short.
46 BUG_ON(key->offset > USHRT_MAX);
47 BUG_ON(dissector_uses_key(flow_dissector,
48 key->key_id));
50 dissector_set_key(flow_dissector, key->key_id);
51 flow_dissector->offset[key->key_id] = key->offset;
54 /* Ensure that the dissector always includes control and basic key.
55 * That way we are able to avoid handling lack of these in fast path.
57 BUG_ON(!dissector_uses_key(flow_dissector,
58 FLOW_DISSECTOR_KEY_CONTROL));
59 BUG_ON(!dissector_uses_key(flow_dissector,
60 FLOW_DISSECTOR_KEY_BASIC));
62 EXPORT_SYMBOL(skb_flow_dissector_init);
64 /**
65 * skb_flow_get_be16 - extract be16 entity
66 * @skb: sk_buff to extract from
67 * @poff: offset to extract at
68 * @data: raw buffer pointer to the packet
69 * @hlen: packet header length
71 * The function will try to retrieve a be32 entity at
72 * offset poff
74 static __be16 skb_flow_get_be16(const struct sk_buff *skb, int poff,
75 void *data, int hlen)
77 __be16 *u, _u;
79 u = __skb_header_pointer(skb, poff, sizeof(_u), data, hlen, &_u);
80 if (u)
81 return *u;
83 return 0;
86 /**
87 * __skb_flow_get_ports - extract the upper layer ports and return them
88 * @skb: sk_buff to extract the ports from
89 * @thoff: transport header offset
90 * @ip_proto: protocol for which to get port offset
91 * @data: raw buffer pointer to the packet, if NULL use skb->data
92 * @hlen: packet header length, if @data is NULL use skb_headlen(skb)
94 * The function will try to retrieve the ports at offset thoff + poff where poff
95 * is the protocol port offset returned from proto_ports_offset
97 __be32 __skb_flow_get_ports(const struct sk_buff *skb, int thoff, u8 ip_proto,
98 void *data, int hlen)
100 int poff = proto_ports_offset(ip_proto);
102 if (!data) {
103 data = skb->data;
104 hlen = skb_headlen(skb);
107 if (poff >= 0) {
108 __be32 *ports, _ports;
110 ports = __skb_header_pointer(skb, thoff + poff,
111 sizeof(_ports), data, hlen, &_ports);
112 if (ports)
113 return *ports;
116 return 0;
118 EXPORT_SYMBOL(__skb_flow_get_ports);
120 static void
121 skb_flow_dissect_set_enc_addr_type(enum flow_dissector_key_id type,
122 struct flow_dissector *flow_dissector,
123 void *target_container)
125 struct flow_dissector_key_control *ctrl;
127 if (!dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_ENC_CONTROL))
128 return;
130 ctrl = skb_flow_dissector_target(flow_dissector,
131 FLOW_DISSECTOR_KEY_ENC_CONTROL,
132 target_container);
133 ctrl->addr_type = type;
136 static void
137 __skb_flow_dissect_tunnel_info(const struct sk_buff *skb,
138 struct flow_dissector *flow_dissector,
139 void *target_container)
141 struct ip_tunnel_info *info;
142 struct ip_tunnel_key *key;
144 /* A quick check to see if there might be something to do. */
145 if (!dissector_uses_key(flow_dissector,
146 FLOW_DISSECTOR_KEY_ENC_KEYID) &&
147 !dissector_uses_key(flow_dissector,
148 FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS) &&
149 !dissector_uses_key(flow_dissector,
150 FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS) &&
151 !dissector_uses_key(flow_dissector,
152 FLOW_DISSECTOR_KEY_ENC_CONTROL) &&
153 !dissector_uses_key(flow_dissector,
154 FLOW_DISSECTOR_KEY_ENC_PORTS))
155 return;
157 info = skb_tunnel_info(skb);
158 if (!info)
159 return;
161 key = &info->key;
163 switch (ip_tunnel_info_af(info)) {
164 case AF_INET:
165 skb_flow_dissect_set_enc_addr_type(FLOW_DISSECTOR_KEY_IPV4_ADDRS,
166 flow_dissector,
167 target_container);
168 if (dissector_uses_key(flow_dissector,
169 FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS)) {
170 struct flow_dissector_key_ipv4_addrs *ipv4;
172 ipv4 = skb_flow_dissector_target(flow_dissector,
173 FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS,
174 target_container);
175 ipv4->src = key->u.ipv4.src;
176 ipv4->dst = key->u.ipv4.dst;
178 break;
179 case AF_INET6:
180 skb_flow_dissect_set_enc_addr_type(FLOW_DISSECTOR_KEY_IPV6_ADDRS,
181 flow_dissector,
182 target_container);
183 if (dissector_uses_key(flow_dissector,
184 FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS)) {
185 struct flow_dissector_key_ipv6_addrs *ipv6;
187 ipv6 = skb_flow_dissector_target(flow_dissector,
188 FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS,
189 target_container);
190 ipv6->src = key->u.ipv6.src;
191 ipv6->dst = key->u.ipv6.dst;
193 break;
196 if (dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_ENC_KEYID)) {
197 struct flow_dissector_key_keyid *keyid;
199 keyid = skb_flow_dissector_target(flow_dissector,
200 FLOW_DISSECTOR_KEY_ENC_KEYID,
201 target_container);
202 keyid->keyid = tunnel_id_to_key32(key->tun_id);
205 if (dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_ENC_PORTS)) {
206 struct flow_dissector_key_ports *tp;
208 tp = skb_flow_dissector_target(flow_dissector,
209 FLOW_DISSECTOR_KEY_ENC_PORTS,
210 target_container);
211 tp->src = key->tp_src;
212 tp->dst = key->tp_dst;
216 static enum flow_dissect_ret
217 __skb_flow_dissect_mpls(const struct sk_buff *skb,
218 struct flow_dissector *flow_dissector,
219 void *target_container, void *data, int nhoff, int hlen)
221 struct flow_dissector_key_keyid *key_keyid;
222 struct mpls_label *hdr, _hdr[2];
223 u32 entry, label;
225 if (!dissector_uses_key(flow_dissector,
226 FLOW_DISSECTOR_KEY_MPLS_ENTROPY) &&
227 !dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_MPLS))
228 return FLOW_DISSECT_RET_OUT_GOOD;
230 hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data,
231 hlen, &_hdr);
232 if (!hdr)
233 return FLOW_DISSECT_RET_OUT_BAD;
235 entry = ntohl(hdr[0].entry);
236 label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT;
238 if (dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_MPLS)) {
239 struct flow_dissector_key_mpls *key_mpls;
241 key_mpls = skb_flow_dissector_target(flow_dissector,
242 FLOW_DISSECTOR_KEY_MPLS,
243 target_container);
244 key_mpls->mpls_label = label;
245 key_mpls->mpls_ttl = (entry & MPLS_LS_TTL_MASK)
246 >> MPLS_LS_TTL_SHIFT;
247 key_mpls->mpls_tc = (entry & MPLS_LS_TC_MASK)
248 >> MPLS_LS_TC_SHIFT;
249 key_mpls->mpls_bos = (entry & MPLS_LS_S_MASK)
250 >> MPLS_LS_S_SHIFT;
253 if (label == MPLS_LABEL_ENTROPY) {
254 key_keyid = skb_flow_dissector_target(flow_dissector,
255 FLOW_DISSECTOR_KEY_MPLS_ENTROPY,
256 target_container);
257 key_keyid->keyid = hdr[1].entry & htonl(MPLS_LS_LABEL_MASK);
259 return FLOW_DISSECT_RET_OUT_GOOD;
262 static enum flow_dissect_ret
263 __skb_flow_dissect_arp(const struct sk_buff *skb,
264 struct flow_dissector *flow_dissector,
265 void *target_container, void *data, int nhoff, int hlen)
267 struct flow_dissector_key_arp *key_arp;
268 struct {
269 unsigned char ar_sha[ETH_ALEN];
270 unsigned char ar_sip[4];
271 unsigned char ar_tha[ETH_ALEN];
272 unsigned char ar_tip[4];
273 } *arp_eth, _arp_eth;
274 const struct arphdr *arp;
275 struct arphdr _arp;
277 if (!dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_ARP))
278 return FLOW_DISSECT_RET_OUT_GOOD;
280 arp = __skb_header_pointer(skb, nhoff, sizeof(_arp), data,
281 hlen, &_arp);
282 if (!arp)
283 return FLOW_DISSECT_RET_OUT_BAD;
285 if (arp->ar_hrd != htons(ARPHRD_ETHER) ||
286 arp->ar_pro != htons(ETH_P_IP) ||
287 arp->ar_hln != ETH_ALEN ||
288 arp->ar_pln != 4 ||
289 (arp->ar_op != htons(ARPOP_REPLY) &&
290 arp->ar_op != htons(ARPOP_REQUEST)))
291 return FLOW_DISSECT_RET_OUT_BAD;
293 arp_eth = __skb_header_pointer(skb, nhoff + sizeof(_arp),
294 sizeof(_arp_eth), data,
295 hlen, &_arp_eth);
296 if (!arp_eth)
297 return FLOW_DISSECT_RET_OUT_BAD;
299 key_arp = skb_flow_dissector_target(flow_dissector,
300 FLOW_DISSECTOR_KEY_ARP,
301 target_container);
303 memcpy(&key_arp->sip, arp_eth->ar_sip, sizeof(key_arp->sip));
304 memcpy(&key_arp->tip, arp_eth->ar_tip, sizeof(key_arp->tip));
306 /* Only store the lower byte of the opcode;
307 * this covers ARPOP_REPLY and ARPOP_REQUEST.
309 key_arp->op = ntohs(arp->ar_op) & 0xff;
311 ether_addr_copy(key_arp->sha, arp_eth->ar_sha);
312 ether_addr_copy(key_arp->tha, arp_eth->ar_tha);
314 return FLOW_DISSECT_RET_OUT_GOOD;
317 static enum flow_dissect_ret
318 __skb_flow_dissect_gre(const struct sk_buff *skb,
319 struct flow_dissector_key_control *key_control,
320 struct flow_dissector *flow_dissector,
321 void *target_container, void *data,
322 __be16 *p_proto, int *p_nhoff, int *p_hlen,
323 unsigned int flags)
325 struct flow_dissector_key_keyid *key_keyid;
326 struct gre_base_hdr *hdr, _hdr;
327 int offset = 0;
328 u16 gre_ver;
330 hdr = __skb_header_pointer(skb, *p_nhoff, sizeof(_hdr),
331 data, *p_hlen, &_hdr);
332 if (!hdr)
333 return FLOW_DISSECT_RET_OUT_BAD;
335 /* Only look inside GRE without routing */
336 if (hdr->flags & GRE_ROUTING)
337 return FLOW_DISSECT_RET_OUT_GOOD;
339 /* Only look inside GRE for version 0 and 1 */
340 gre_ver = ntohs(hdr->flags & GRE_VERSION);
341 if (gre_ver > 1)
342 return FLOW_DISSECT_RET_OUT_GOOD;
344 *p_proto = hdr->protocol;
345 if (gre_ver) {
346 /* Version1 must be PPTP, and check the flags */
347 if (!(*p_proto == GRE_PROTO_PPP && (hdr->flags & GRE_KEY)))
348 return FLOW_DISSECT_RET_OUT_GOOD;
351 offset += sizeof(struct gre_base_hdr);
353 if (hdr->flags & GRE_CSUM)
354 offset += sizeof(((struct gre_full_hdr *) 0)->csum) +
355 sizeof(((struct gre_full_hdr *) 0)->reserved1);
357 if (hdr->flags & GRE_KEY) {
358 const __be32 *keyid;
359 __be32 _keyid;
361 keyid = __skb_header_pointer(skb, *p_nhoff + offset,
362 sizeof(_keyid),
363 data, *p_hlen, &_keyid);
364 if (!keyid)
365 return FLOW_DISSECT_RET_OUT_BAD;
367 if (dissector_uses_key(flow_dissector,
368 FLOW_DISSECTOR_KEY_GRE_KEYID)) {
369 key_keyid = skb_flow_dissector_target(flow_dissector,
370 FLOW_DISSECTOR_KEY_GRE_KEYID,
371 target_container);
372 if (gre_ver == 0)
373 key_keyid->keyid = *keyid;
374 else
375 key_keyid->keyid = *keyid & GRE_PPTP_KEY_MASK;
377 offset += sizeof(((struct gre_full_hdr *) 0)->key);
380 if (hdr->flags & GRE_SEQ)
381 offset += sizeof(((struct pptp_gre_header *) 0)->seq);
383 if (gre_ver == 0) {
384 if (*p_proto == htons(ETH_P_TEB)) {
385 const struct ethhdr *eth;
386 struct ethhdr _eth;
388 eth = __skb_header_pointer(skb, *p_nhoff + offset,
389 sizeof(_eth),
390 data, *p_hlen, &_eth);
391 if (!eth)
392 return FLOW_DISSECT_RET_OUT_BAD;
393 *p_proto = eth->h_proto;
394 offset += sizeof(*eth);
396 /* Cap headers that we access via pointers at the
397 * end of the Ethernet header as our maximum alignment
398 * at that point is only 2 bytes.
400 if (NET_IP_ALIGN)
401 *p_hlen = *p_nhoff + offset;
403 } else { /* version 1, must be PPTP */
404 u8 _ppp_hdr[PPP_HDRLEN];
405 u8 *ppp_hdr;
407 if (hdr->flags & GRE_ACK)
408 offset += sizeof(((struct pptp_gre_header *) 0)->ack);
410 ppp_hdr = __skb_header_pointer(skb, *p_nhoff + offset,
411 sizeof(_ppp_hdr),
412 data, *p_hlen, _ppp_hdr);
413 if (!ppp_hdr)
414 return FLOW_DISSECT_RET_OUT_BAD;
416 switch (PPP_PROTOCOL(ppp_hdr)) {
417 case PPP_IP:
418 *p_proto = htons(ETH_P_IP);
419 break;
420 case PPP_IPV6:
421 *p_proto = htons(ETH_P_IPV6);
422 break;
423 default:
424 /* Could probably catch some more like MPLS */
425 break;
428 offset += PPP_HDRLEN;
431 *p_nhoff += offset;
432 key_control->flags |= FLOW_DIS_ENCAPSULATION;
433 if (flags & FLOW_DISSECTOR_F_STOP_AT_ENCAP)
434 return FLOW_DISSECT_RET_OUT_GOOD;
436 return FLOW_DISSECT_RET_PROTO_AGAIN;
439 static void
440 __skb_flow_dissect_tcp(const struct sk_buff *skb,
441 struct flow_dissector *flow_dissector,
442 void *target_container, void *data, int thoff, int hlen)
444 struct flow_dissector_key_tcp *key_tcp;
445 struct tcphdr *th, _th;
447 if (!dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_TCP))
448 return;
450 th = __skb_header_pointer(skb, thoff, sizeof(_th), data, hlen, &_th);
451 if (!th)
452 return;
454 if (unlikely(__tcp_hdrlen(th) < sizeof(_th)))
455 return;
457 key_tcp = skb_flow_dissector_target(flow_dissector,
458 FLOW_DISSECTOR_KEY_TCP,
459 target_container);
460 key_tcp->flags = (*(__be16 *) &tcp_flag_word(th) & htons(0x0FFF));
463 static void
464 __skb_flow_dissect_ipv4(const struct sk_buff *skb,
465 struct flow_dissector *flow_dissector,
466 void *target_container, void *data, const struct iphdr *iph)
468 struct flow_dissector_key_ip *key_ip;
470 if (!dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_IP))
471 return;
473 key_ip = skb_flow_dissector_target(flow_dissector,
474 FLOW_DISSECTOR_KEY_IP,
475 target_container);
476 key_ip->tos = iph->tos;
477 key_ip->ttl = iph->ttl;
480 static void
481 __skb_flow_dissect_ipv6(const struct sk_buff *skb,
482 struct flow_dissector *flow_dissector,
483 void *target_container, void *data, const struct ipv6hdr *iph)
485 struct flow_dissector_key_ip *key_ip;
487 if (!dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_IP))
488 return;
490 key_ip = skb_flow_dissector_target(flow_dissector,
491 FLOW_DISSECTOR_KEY_IP,
492 target_container);
493 key_ip->tos = ipv6_get_dsfield(iph);
494 key_ip->ttl = iph->hop_limit;
497 /* Maximum number of protocol headers that can be parsed in
498 * __skb_flow_dissect
500 #define MAX_FLOW_DISSECT_HDRS 15
502 static bool skb_flow_dissect_allowed(int *num_hdrs)
504 ++*num_hdrs;
506 return (*num_hdrs <= MAX_FLOW_DISSECT_HDRS);
510 * __skb_flow_dissect - extract the flow_keys struct and return it
511 * @skb: sk_buff to extract the flow from, can be NULL if the rest are specified
512 * @flow_dissector: list of keys to dissect
513 * @target_container: target structure to put dissected values into
514 * @data: raw buffer pointer to the packet, if NULL use skb->data
515 * @proto: protocol for which to get the flow, if @data is NULL use skb->protocol
516 * @nhoff: network header offset, if @data is NULL use skb_network_offset(skb)
517 * @hlen: packet header length, if @data is NULL use skb_headlen(skb)
519 * The function will try to retrieve individual keys into target specified
520 * by flow_dissector from either the skbuff or a raw buffer specified by the
521 * rest parameters.
523 * Caller must take care of zeroing target container memory.
525 bool __skb_flow_dissect(const struct sk_buff *skb,
526 struct flow_dissector *flow_dissector,
527 void *target_container,
528 void *data, __be16 proto, int nhoff, int hlen,
529 unsigned int flags)
531 struct flow_dissector_key_control *key_control;
532 struct flow_dissector_key_basic *key_basic;
533 struct flow_dissector_key_addrs *key_addrs;
534 struct flow_dissector_key_ports *key_ports;
535 struct flow_dissector_key_icmp *key_icmp;
536 struct flow_dissector_key_tags *key_tags;
537 struct flow_dissector_key_vlan *key_vlan;
538 enum flow_dissect_ret fdret;
539 bool skip_vlan = false;
540 int num_hdrs = 0;
541 u8 ip_proto = 0;
542 bool ret;
544 if (!data) {
545 data = skb->data;
546 proto = skb_vlan_tag_present(skb) ?
547 skb->vlan_proto : skb->protocol;
548 nhoff = skb_network_offset(skb);
549 hlen = skb_headlen(skb);
550 #if IS_ENABLED(CONFIG_NET_DSA)
551 if (unlikely(skb->dev && netdev_uses_dsa(skb->dev))) {
552 const struct dsa_device_ops *ops;
553 int offset;
555 ops = skb->dev->dsa_ptr->tag_ops;
556 if (ops->flow_dissect &&
557 !ops->flow_dissect(skb, &proto, &offset)) {
558 hlen -= offset;
559 nhoff += offset;
562 #endif
565 /* It is ensured by skb_flow_dissector_init() that control key will
566 * be always present.
568 key_control = skb_flow_dissector_target(flow_dissector,
569 FLOW_DISSECTOR_KEY_CONTROL,
570 target_container);
572 /* It is ensured by skb_flow_dissector_init() that basic key will
573 * be always present.
575 key_basic = skb_flow_dissector_target(flow_dissector,
576 FLOW_DISSECTOR_KEY_BASIC,
577 target_container);
579 __skb_flow_dissect_tunnel_info(skb, flow_dissector,
580 target_container);
582 if (dissector_uses_key(flow_dissector,
583 FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
584 struct ethhdr *eth = eth_hdr(skb);
585 struct flow_dissector_key_eth_addrs *key_eth_addrs;
587 key_eth_addrs = skb_flow_dissector_target(flow_dissector,
588 FLOW_DISSECTOR_KEY_ETH_ADDRS,
589 target_container);
590 memcpy(key_eth_addrs, &eth->h_dest, sizeof(*key_eth_addrs));
593 proto_again:
594 fdret = FLOW_DISSECT_RET_CONTINUE;
596 switch (proto) {
597 case htons(ETH_P_IP): {
598 const struct iphdr *iph;
599 struct iphdr _iph;
601 iph = __skb_header_pointer(skb, nhoff, sizeof(_iph), data, hlen, &_iph);
602 if (!iph || iph->ihl < 5) {
603 fdret = FLOW_DISSECT_RET_OUT_BAD;
604 break;
607 nhoff += iph->ihl * 4;
609 ip_proto = iph->protocol;
611 if (dissector_uses_key(flow_dissector,
612 FLOW_DISSECTOR_KEY_IPV4_ADDRS)) {
613 key_addrs = skb_flow_dissector_target(flow_dissector,
614 FLOW_DISSECTOR_KEY_IPV4_ADDRS,
615 target_container);
617 memcpy(&key_addrs->v4addrs, &iph->saddr,
618 sizeof(key_addrs->v4addrs));
619 key_control->addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS;
622 if (ip_is_fragment(iph)) {
623 key_control->flags |= FLOW_DIS_IS_FRAGMENT;
625 if (iph->frag_off & htons(IP_OFFSET)) {
626 fdret = FLOW_DISSECT_RET_OUT_GOOD;
627 break;
628 } else {
629 key_control->flags |= FLOW_DIS_FIRST_FRAG;
630 if (!(flags &
631 FLOW_DISSECTOR_F_PARSE_1ST_FRAG)) {
632 fdret = FLOW_DISSECT_RET_OUT_GOOD;
633 break;
638 __skb_flow_dissect_ipv4(skb, flow_dissector,
639 target_container, data, iph);
641 if (flags & FLOW_DISSECTOR_F_STOP_AT_L3) {
642 fdret = FLOW_DISSECT_RET_OUT_GOOD;
643 break;
646 break;
648 case htons(ETH_P_IPV6): {
649 const struct ipv6hdr *iph;
650 struct ipv6hdr _iph;
652 iph = __skb_header_pointer(skb, nhoff, sizeof(_iph), data, hlen, &_iph);
653 if (!iph) {
654 fdret = FLOW_DISSECT_RET_OUT_BAD;
655 break;
658 ip_proto = iph->nexthdr;
659 nhoff += sizeof(struct ipv6hdr);
661 if (dissector_uses_key(flow_dissector,
662 FLOW_DISSECTOR_KEY_IPV6_ADDRS)) {
663 key_addrs = skb_flow_dissector_target(flow_dissector,
664 FLOW_DISSECTOR_KEY_IPV6_ADDRS,
665 target_container);
667 memcpy(&key_addrs->v6addrs, &iph->saddr,
668 sizeof(key_addrs->v6addrs));
669 key_control->addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
672 if ((dissector_uses_key(flow_dissector,
673 FLOW_DISSECTOR_KEY_FLOW_LABEL) ||
674 (flags & FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL)) &&
675 ip6_flowlabel(iph)) {
676 __be32 flow_label = ip6_flowlabel(iph);
678 if (dissector_uses_key(flow_dissector,
679 FLOW_DISSECTOR_KEY_FLOW_LABEL)) {
680 key_tags = skb_flow_dissector_target(flow_dissector,
681 FLOW_DISSECTOR_KEY_FLOW_LABEL,
682 target_container);
683 key_tags->flow_label = ntohl(flow_label);
685 if (flags & FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL) {
686 fdret = FLOW_DISSECT_RET_OUT_GOOD;
687 break;
691 __skb_flow_dissect_ipv6(skb, flow_dissector,
692 target_container, data, iph);
694 if (flags & FLOW_DISSECTOR_F_STOP_AT_L3)
695 fdret = FLOW_DISSECT_RET_OUT_GOOD;
697 break;
699 case htons(ETH_P_8021AD):
700 case htons(ETH_P_8021Q): {
701 const struct vlan_hdr *vlan;
702 struct vlan_hdr _vlan;
703 bool vlan_tag_present = skb && skb_vlan_tag_present(skb);
705 if (vlan_tag_present)
706 proto = skb->protocol;
708 if (!vlan_tag_present || eth_type_vlan(skb->protocol)) {
709 vlan = __skb_header_pointer(skb, nhoff, sizeof(_vlan),
710 data, hlen, &_vlan);
711 if (!vlan) {
712 fdret = FLOW_DISSECT_RET_OUT_BAD;
713 break;
716 proto = vlan->h_vlan_encapsulated_proto;
717 nhoff += sizeof(*vlan);
718 if (skip_vlan) {
719 fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
720 break;
724 skip_vlan = true;
725 if (dissector_uses_key(flow_dissector,
726 FLOW_DISSECTOR_KEY_VLAN)) {
727 key_vlan = skb_flow_dissector_target(flow_dissector,
728 FLOW_DISSECTOR_KEY_VLAN,
729 target_container);
731 if (vlan_tag_present) {
732 key_vlan->vlan_id = skb_vlan_tag_get_id(skb);
733 key_vlan->vlan_priority =
734 (skb_vlan_tag_get_prio(skb) >> VLAN_PRIO_SHIFT);
735 } else {
736 key_vlan->vlan_id = ntohs(vlan->h_vlan_TCI) &
737 VLAN_VID_MASK;
738 key_vlan->vlan_priority =
739 (ntohs(vlan->h_vlan_TCI) &
740 VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
744 fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
745 break;
747 case htons(ETH_P_PPP_SES): {
748 struct {
749 struct pppoe_hdr hdr;
750 __be16 proto;
751 } *hdr, _hdr;
752 hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr), data, hlen, &_hdr);
753 if (!hdr) {
754 fdret = FLOW_DISSECT_RET_OUT_BAD;
755 break;
758 proto = hdr->proto;
759 nhoff += PPPOE_SES_HLEN;
760 switch (proto) {
761 case htons(PPP_IP):
762 proto = htons(ETH_P_IP);
763 fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
764 break;
765 case htons(PPP_IPV6):
766 proto = htons(ETH_P_IPV6);
767 fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
768 break;
769 default:
770 fdret = FLOW_DISSECT_RET_OUT_BAD;
771 break;
773 break;
775 case htons(ETH_P_TIPC): {
776 struct tipc_basic_hdr *hdr, _hdr;
778 hdr = __skb_header_pointer(skb, nhoff, sizeof(_hdr),
779 data, hlen, &_hdr);
780 if (!hdr) {
781 fdret = FLOW_DISSECT_RET_OUT_BAD;
782 break;
785 if (dissector_uses_key(flow_dissector,
786 FLOW_DISSECTOR_KEY_TIPC)) {
787 key_addrs = skb_flow_dissector_target(flow_dissector,
788 FLOW_DISSECTOR_KEY_TIPC,
789 target_container);
790 key_addrs->tipckey.key = tipc_hdr_rps_key(hdr);
791 key_control->addr_type = FLOW_DISSECTOR_KEY_TIPC;
793 fdret = FLOW_DISSECT_RET_OUT_GOOD;
794 break;
797 case htons(ETH_P_MPLS_UC):
798 case htons(ETH_P_MPLS_MC):
799 fdret = __skb_flow_dissect_mpls(skb, flow_dissector,
800 target_container, data,
801 nhoff, hlen);
802 break;
803 case htons(ETH_P_FCOE):
804 if ((hlen - nhoff) < FCOE_HEADER_LEN) {
805 fdret = FLOW_DISSECT_RET_OUT_BAD;
806 break;
809 nhoff += FCOE_HEADER_LEN;
810 fdret = FLOW_DISSECT_RET_OUT_GOOD;
811 break;
813 case htons(ETH_P_ARP):
814 case htons(ETH_P_RARP):
815 fdret = __skb_flow_dissect_arp(skb, flow_dissector,
816 target_container, data,
817 nhoff, hlen);
818 break;
820 default:
821 fdret = FLOW_DISSECT_RET_OUT_BAD;
822 break;
825 /* Process result of proto processing */
826 switch (fdret) {
827 case FLOW_DISSECT_RET_OUT_GOOD:
828 goto out_good;
829 case FLOW_DISSECT_RET_PROTO_AGAIN:
830 if (skb_flow_dissect_allowed(&num_hdrs))
831 goto proto_again;
832 goto out_good;
833 case FLOW_DISSECT_RET_CONTINUE:
834 case FLOW_DISSECT_RET_IPPROTO_AGAIN:
835 break;
836 case FLOW_DISSECT_RET_OUT_BAD:
837 default:
838 goto out_bad;
841 ip_proto_again:
842 fdret = FLOW_DISSECT_RET_CONTINUE;
844 switch (ip_proto) {
845 case IPPROTO_GRE:
846 fdret = __skb_flow_dissect_gre(skb, key_control, flow_dissector,
847 target_container, data,
848 &proto, &nhoff, &hlen, flags);
849 break;
851 case NEXTHDR_HOP:
852 case NEXTHDR_ROUTING:
853 case NEXTHDR_DEST: {
854 u8 _opthdr[2], *opthdr;
856 if (proto != htons(ETH_P_IPV6))
857 break;
859 opthdr = __skb_header_pointer(skb, nhoff, sizeof(_opthdr),
860 data, hlen, &_opthdr);
861 if (!opthdr) {
862 fdret = FLOW_DISSECT_RET_OUT_BAD;
863 break;
866 ip_proto = opthdr[0];
867 nhoff += (opthdr[1] + 1) << 3;
869 fdret = FLOW_DISSECT_RET_IPPROTO_AGAIN;
870 break;
872 case NEXTHDR_FRAGMENT: {
873 struct frag_hdr _fh, *fh;
875 if (proto != htons(ETH_P_IPV6))
876 break;
878 fh = __skb_header_pointer(skb, nhoff, sizeof(_fh),
879 data, hlen, &_fh);
881 if (!fh) {
882 fdret = FLOW_DISSECT_RET_OUT_BAD;
883 break;
886 key_control->flags |= FLOW_DIS_IS_FRAGMENT;
888 nhoff += sizeof(_fh);
889 ip_proto = fh->nexthdr;
891 if (!(fh->frag_off & htons(IP6_OFFSET))) {
892 key_control->flags |= FLOW_DIS_FIRST_FRAG;
893 if (flags & FLOW_DISSECTOR_F_PARSE_1ST_FRAG) {
894 fdret = FLOW_DISSECT_RET_IPPROTO_AGAIN;
895 break;
899 fdret = FLOW_DISSECT_RET_OUT_GOOD;
900 break;
902 case IPPROTO_IPIP:
903 proto = htons(ETH_P_IP);
905 key_control->flags |= FLOW_DIS_ENCAPSULATION;
906 if (flags & FLOW_DISSECTOR_F_STOP_AT_ENCAP) {
907 fdret = FLOW_DISSECT_RET_OUT_GOOD;
908 break;
911 fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
912 break;
914 case IPPROTO_IPV6:
915 proto = htons(ETH_P_IPV6);
917 key_control->flags |= FLOW_DIS_ENCAPSULATION;
918 if (flags & FLOW_DISSECTOR_F_STOP_AT_ENCAP) {
919 fdret = FLOW_DISSECT_RET_OUT_GOOD;
920 break;
923 fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
924 break;
927 case IPPROTO_MPLS:
928 proto = htons(ETH_P_MPLS_UC);
929 fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
930 break;
932 case IPPROTO_TCP:
933 __skb_flow_dissect_tcp(skb, flow_dissector, target_container,
934 data, nhoff, hlen);
935 break;
937 default:
938 break;
941 if (dissector_uses_key(flow_dissector,
942 FLOW_DISSECTOR_KEY_PORTS)) {
943 key_ports = skb_flow_dissector_target(flow_dissector,
944 FLOW_DISSECTOR_KEY_PORTS,
945 target_container);
946 key_ports->ports = __skb_flow_get_ports(skb, nhoff, ip_proto,
947 data, hlen);
950 if (dissector_uses_key(flow_dissector,
951 FLOW_DISSECTOR_KEY_ICMP)) {
952 key_icmp = skb_flow_dissector_target(flow_dissector,
953 FLOW_DISSECTOR_KEY_ICMP,
954 target_container);
955 key_icmp->icmp = skb_flow_get_be16(skb, nhoff, data, hlen);
958 /* Process result of IP proto processing */
959 switch (fdret) {
960 case FLOW_DISSECT_RET_PROTO_AGAIN:
961 if (skb_flow_dissect_allowed(&num_hdrs))
962 goto proto_again;
963 break;
964 case FLOW_DISSECT_RET_IPPROTO_AGAIN:
965 if (skb_flow_dissect_allowed(&num_hdrs))
966 goto ip_proto_again;
967 break;
968 case FLOW_DISSECT_RET_OUT_GOOD:
969 case FLOW_DISSECT_RET_CONTINUE:
970 break;
971 case FLOW_DISSECT_RET_OUT_BAD:
972 default:
973 goto out_bad;
976 out_good:
977 ret = true;
979 out:
980 key_control->thoff = min_t(u16, nhoff, skb ? skb->len : hlen);
981 key_basic->n_proto = proto;
982 key_basic->ip_proto = ip_proto;
984 return ret;
986 out_bad:
987 ret = false;
988 goto out;
990 EXPORT_SYMBOL(__skb_flow_dissect);
992 static u32 hashrnd __read_mostly;
993 static __always_inline void __flow_hash_secret_init(void)
995 net_get_random_once(&hashrnd, sizeof(hashrnd));
998 static __always_inline u32 __flow_hash_words(const u32 *words, u32 length,
999 u32 keyval)
1001 return jhash2(words, length, keyval);
1004 static inline const u32 *flow_keys_hash_start(const struct flow_keys *flow)
1006 const void *p = flow;
1008 BUILD_BUG_ON(FLOW_KEYS_HASH_OFFSET % sizeof(u32));
1009 return (const u32 *)(p + FLOW_KEYS_HASH_OFFSET);
1012 static inline size_t flow_keys_hash_length(const struct flow_keys *flow)
1014 size_t diff = FLOW_KEYS_HASH_OFFSET + sizeof(flow->addrs);
1015 BUILD_BUG_ON((sizeof(*flow) - FLOW_KEYS_HASH_OFFSET) % sizeof(u32));
1016 BUILD_BUG_ON(offsetof(typeof(*flow), addrs) !=
1017 sizeof(*flow) - sizeof(flow->addrs));
1019 switch (flow->control.addr_type) {
1020 case FLOW_DISSECTOR_KEY_IPV4_ADDRS:
1021 diff -= sizeof(flow->addrs.v4addrs);
1022 break;
1023 case FLOW_DISSECTOR_KEY_IPV6_ADDRS:
1024 diff -= sizeof(flow->addrs.v6addrs);
1025 break;
1026 case FLOW_DISSECTOR_KEY_TIPC:
1027 diff -= sizeof(flow->addrs.tipckey);
1028 break;
1030 return (sizeof(*flow) - diff) / sizeof(u32);
1033 __be32 flow_get_u32_src(const struct flow_keys *flow)
1035 switch (flow->control.addr_type) {
1036 case FLOW_DISSECTOR_KEY_IPV4_ADDRS:
1037 return flow->addrs.v4addrs.src;
1038 case FLOW_DISSECTOR_KEY_IPV6_ADDRS:
1039 return (__force __be32)ipv6_addr_hash(
1040 &flow->addrs.v6addrs.src);
1041 case FLOW_DISSECTOR_KEY_TIPC:
1042 return flow->addrs.tipckey.key;
1043 default:
1044 return 0;
1047 EXPORT_SYMBOL(flow_get_u32_src);
1049 __be32 flow_get_u32_dst(const struct flow_keys *flow)
1051 switch (flow->control.addr_type) {
1052 case FLOW_DISSECTOR_KEY_IPV4_ADDRS:
1053 return flow->addrs.v4addrs.dst;
1054 case FLOW_DISSECTOR_KEY_IPV6_ADDRS:
1055 return (__force __be32)ipv6_addr_hash(
1056 &flow->addrs.v6addrs.dst);
1057 default:
1058 return 0;
1061 EXPORT_SYMBOL(flow_get_u32_dst);
1063 static inline void __flow_hash_consistentify(struct flow_keys *keys)
1065 int addr_diff, i;
1067 switch (keys->control.addr_type) {
1068 case FLOW_DISSECTOR_KEY_IPV4_ADDRS:
1069 addr_diff = (__force u32)keys->addrs.v4addrs.dst -
1070 (__force u32)keys->addrs.v4addrs.src;
1071 if ((addr_diff < 0) ||
1072 (addr_diff == 0 &&
1073 ((__force u16)keys->ports.dst <
1074 (__force u16)keys->ports.src))) {
1075 swap(keys->addrs.v4addrs.src, keys->addrs.v4addrs.dst);
1076 swap(keys->ports.src, keys->ports.dst);
1078 break;
1079 case FLOW_DISSECTOR_KEY_IPV6_ADDRS:
1080 addr_diff = memcmp(&keys->addrs.v6addrs.dst,
1081 &keys->addrs.v6addrs.src,
1082 sizeof(keys->addrs.v6addrs.dst));
1083 if ((addr_diff < 0) ||
1084 (addr_diff == 0 &&
1085 ((__force u16)keys->ports.dst <
1086 (__force u16)keys->ports.src))) {
1087 for (i = 0; i < 4; i++)
1088 swap(keys->addrs.v6addrs.src.s6_addr32[i],
1089 keys->addrs.v6addrs.dst.s6_addr32[i]);
1090 swap(keys->ports.src, keys->ports.dst);
1092 break;
1096 static inline u32 __flow_hash_from_keys(struct flow_keys *keys, u32 keyval)
1098 u32 hash;
1100 __flow_hash_consistentify(keys);
1102 hash = __flow_hash_words(flow_keys_hash_start(keys),
1103 flow_keys_hash_length(keys), keyval);
1104 if (!hash)
1105 hash = 1;
1107 return hash;
1110 u32 flow_hash_from_keys(struct flow_keys *keys)
1112 __flow_hash_secret_init();
1113 return __flow_hash_from_keys(keys, hashrnd);
1115 EXPORT_SYMBOL(flow_hash_from_keys);
1117 static inline u32 ___skb_get_hash(const struct sk_buff *skb,
1118 struct flow_keys *keys, u32 keyval)
1120 skb_flow_dissect_flow_keys(skb, keys,
1121 FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL);
1123 return __flow_hash_from_keys(keys, keyval);
1126 struct _flow_keys_digest_data {
1127 __be16 n_proto;
1128 u8 ip_proto;
1129 u8 padding;
1130 __be32 ports;
1131 __be32 src;
1132 __be32 dst;
1135 void make_flow_keys_digest(struct flow_keys_digest *digest,
1136 const struct flow_keys *flow)
1138 struct _flow_keys_digest_data *data =
1139 (struct _flow_keys_digest_data *)digest;
1141 BUILD_BUG_ON(sizeof(*data) > sizeof(*digest));
1143 memset(digest, 0, sizeof(*digest));
1145 data->n_proto = flow->basic.n_proto;
1146 data->ip_proto = flow->basic.ip_proto;
1147 data->ports = flow->ports.ports;
1148 data->src = flow->addrs.v4addrs.src;
1149 data->dst = flow->addrs.v4addrs.dst;
1151 EXPORT_SYMBOL(make_flow_keys_digest);
1153 static struct flow_dissector flow_keys_dissector_symmetric __read_mostly;
1155 u32 __skb_get_hash_symmetric(const struct sk_buff *skb)
1157 struct flow_keys keys;
1159 __flow_hash_secret_init();
1161 memset(&keys, 0, sizeof(keys));
1162 __skb_flow_dissect(skb, &flow_keys_dissector_symmetric, &keys,
1163 NULL, 0, 0, 0,
1164 FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL);
1166 return __flow_hash_from_keys(&keys, hashrnd);
1168 EXPORT_SYMBOL_GPL(__skb_get_hash_symmetric);
1171 * __skb_get_hash: calculate a flow hash
1172 * @skb: sk_buff to calculate flow hash from
1174 * This function calculates a flow hash based on src/dst addresses
1175 * and src/dst port numbers. Sets hash in skb to non-zero hash value
1176 * on success, zero indicates no valid hash. Also, sets l4_hash in skb
1177 * if hash is a canonical 4-tuple hash over transport ports.
1179 void __skb_get_hash(struct sk_buff *skb)
1181 struct flow_keys keys;
1182 u32 hash;
1184 __flow_hash_secret_init();
1186 hash = ___skb_get_hash(skb, &keys, hashrnd);
1188 __skb_set_sw_hash(skb, hash, flow_keys_have_l4(&keys));
1190 EXPORT_SYMBOL(__skb_get_hash);
1192 __u32 skb_get_hash_perturb(const struct sk_buff *skb, u32 perturb)
1194 struct flow_keys keys;
1196 return ___skb_get_hash(skb, &keys, perturb);
1198 EXPORT_SYMBOL(skb_get_hash_perturb);
1200 u32 __skb_get_poff(const struct sk_buff *skb, void *data,
1201 const struct flow_keys *keys, int hlen)
1203 u32 poff = keys->control.thoff;
1205 /* skip L4 headers for fragments after the first */
1206 if ((keys->control.flags & FLOW_DIS_IS_FRAGMENT) &&
1207 !(keys->control.flags & FLOW_DIS_FIRST_FRAG))
1208 return poff;
1210 switch (keys->basic.ip_proto) {
1211 case IPPROTO_TCP: {
1212 /* access doff as u8 to avoid unaligned access */
1213 const u8 *doff;
1214 u8 _doff;
1216 doff = __skb_header_pointer(skb, poff + 12, sizeof(_doff),
1217 data, hlen, &_doff);
1218 if (!doff)
1219 return poff;
1221 poff += max_t(u32, sizeof(struct tcphdr), (*doff & 0xF0) >> 2);
1222 break;
1224 case IPPROTO_UDP:
1225 case IPPROTO_UDPLITE:
1226 poff += sizeof(struct udphdr);
1227 break;
1228 /* For the rest, we do not really care about header
1229 * extensions at this point for now.
1231 case IPPROTO_ICMP:
1232 poff += sizeof(struct icmphdr);
1233 break;
1234 case IPPROTO_ICMPV6:
1235 poff += sizeof(struct icmp6hdr);
1236 break;
1237 case IPPROTO_IGMP:
1238 poff += sizeof(struct igmphdr);
1239 break;
1240 case IPPROTO_DCCP:
1241 poff += sizeof(struct dccp_hdr);
1242 break;
1243 case IPPROTO_SCTP:
1244 poff += sizeof(struct sctphdr);
1245 break;
1248 return poff;
1252 * skb_get_poff - get the offset to the payload
1253 * @skb: sk_buff to get the payload offset from
1255 * The function will get the offset to the payload as far as it could
1256 * be dissected. The main user is currently BPF, so that we can dynamically
1257 * truncate packets without needing to push actual payload to the user
1258 * space and can analyze headers only, instead.
1260 u32 skb_get_poff(const struct sk_buff *skb)
1262 struct flow_keys keys;
1264 if (!skb_flow_dissect_flow_keys(skb, &keys, 0))
1265 return 0;
1267 return __skb_get_poff(skb, skb->data, &keys, skb_headlen(skb));
1270 __u32 __get_hash_from_flowi6(const struct flowi6 *fl6, struct flow_keys *keys)
1272 memset(keys, 0, sizeof(*keys));
1274 memcpy(&keys->addrs.v6addrs.src, &fl6->saddr,
1275 sizeof(keys->addrs.v6addrs.src));
1276 memcpy(&keys->addrs.v6addrs.dst, &fl6->daddr,
1277 sizeof(keys->addrs.v6addrs.dst));
1278 keys->control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
1279 keys->ports.src = fl6->fl6_sport;
1280 keys->ports.dst = fl6->fl6_dport;
1281 keys->keyid.keyid = fl6->fl6_gre_key;
1282 keys->tags.flow_label = (__force u32)fl6->flowlabel;
1283 keys->basic.ip_proto = fl6->flowi6_proto;
1285 return flow_hash_from_keys(keys);
1287 EXPORT_SYMBOL(__get_hash_from_flowi6);
1289 __u32 __get_hash_from_flowi4(const struct flowi4 *fl4, struct flow_keys *keys)
1291 memset(keys, 0, sizeof(*keys));
1293 keys->addrs.v4addrs.src = fl4->saddr;
1294 keys->addrs.v4addrs.dst = fl4->daddr;
1295 keys->control.addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS;
1296 keys->ports.src = fl4->fl4_sport;
1297 keys->ports.dst = fl4->fl4_dport;
1298 keys->keyid.keyid = fl4->fl4_gre_key;
1299 keys->basic.ip_proto = fl4->flowi4_proto;
1301 return flow_hash_from_keys(keys);
1303 EXPORT_SYMBOL(__get_hash_from_flowi4);
1305 static const struct flow_dissector_key flow_keys_dissector_keys[] = {
1307 .key_id = FLOW_DISSECTOR_KEY_CONTROL,
1308 .offset = offsetof(struct flow_keys, control),
1311 .key_id = FLOW_DISSECTOR_KEY_BASIC,
1312 .offset = offsetof(struct flow_keys, basic),
1315 .key_id = FLOW_DISSECTOR_KEY_IPV4_ADDRS,
1316 .offset = offsetof(struct flow_keys, addrs.v4addrs),
1319 .key_id = FLOW_DISSECTOR_KEY_IPV6_ADDRS,
1320 .offset = offsetof(struct flow_keys, addrs.v6addrs),
1323 .key_id = FLOW_DISSECTOR_KEY_TIPC,
1324 .offset = offsetof(struct flow_keys, addrs.tipckey),
1327 .key_id = FLOW_DISSECTOR_KEY_PORTS,
1328 .offset = offsetof(struct flow_keys, ports),
1331 .key_id = FLOW_DISSECTOR_KEY_VLAN,
1332 .offset = offsetof(struct flow_keys, vlan),
1335 .key_id = FLOW_DISSECTOR_KEY_FLOW_LABEL,
1336 .offset = offsetof(struct flow_keys, tags),
1339 .key_id = FLOW_DISSECTOR_KEY_GRE_KEYID,
1340 .offset = offsetof(struct flow_keys, keyid),
1344 static const struct flow_dissector_key flow_keys_dissector_symmetric_keys[] = {
1346 .key_id = FLOW_DISSECTOR_KEY_CONTROL,
1347 .offset = offsetof(struct flow_keys, control),
1350 .key_id = FLOW_DISSECTOR_KEY_BASIC,
1351 .offset = offsetof(struct flow_keys, basic),
1354 .key_id = FLOW_DISSECTOR_KEY_IPV4_ADDRS,
1355 .offset = offsetof(struct flow_keys, addrs.v4addrs),
1358 .key_id = FLOW_DISSECTOR_KEY_IPV6_ADDRS,
1359 .offset = offsetof(struct flow_keys, addrs.v6addrs),
1362 .key_id = FLOW_DISSECTOR_KEY_PORTS,
1363 .offset = offsetof(struct flow_keys, ports),
1367 static const struct flow_dissector_key flow_keys_buf_dissector_keys[] = {
1369 .key_id = FLOW_DISSECTOR_KEY_CONTROL,
1370 .offset = offsetof(struct flow_keys, control),
1373 .key_id = FLOW_DISSECTOR_KEY_BASIC,
1374 .offset = offsetof(struct flow_keys, basic),
1378 struct flow_dissector flow_keys_dissector __read_mostly;
1379 EXPORT_SYMBOL(flow_keys_dissector);
1381 struct flow_dissector flow_keys_buf_dissector __read_mostly;
1383 static int __init init_default_flow_dissectors(void)
1385 skb_flow_dissector_init(&flow_keys_dissector,
1386 flow_keys_dissector_keys,
1387 ARRAY_SIZE(flow_keys_dissector_keys));
1388 skb_flow_dissector_init(&flow_keys_dissector_symmetric,
1389 flow_keys_dissector_symmetric_keys,
1390 ARRAY_SIZE(flow_keys_dissector_symmetric_keys));
1391 skb_flow_dissector_init(&flow_keys_buf_dissector,
1392 flow_keys_buf_dissector_keys,
1393 ARRAY_SIZE(flow_keys_buf_dissector_keys));
1394 return 0;
1397 core_initcall(init_default_flow_dissectors);