1 #include <linux/kernel.h>
2 #include <linux/skbuff.h>
3 #include <linux/export.h>
5 #include <linux/ipv6.h>
6 #include <linux/if_vlan.h>
8 #include <net/dst_metadata.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>
27 #include <uapi/linux/batadv_packet.h>
29 static void dissector_set_key(struct flow_dissector
*flow_dissector
,
30 enum flow_dissector_key_id key_id
)
32 flow_dissector
->used_keys
|= (1 << key_id
);
35 void skb_flow_dissector_init(struct flow_dissector
*flow_dissector
,
36 const struct flow_dissector_key
*key
,
37 unsigned int key_count
)
41 memset(flow_dissector
, 0, sizeof(*flow_dissector
));
43 for (i
= 0; i
< key_count
; i
++, key
++) {
44 /* User should make sure that every key target offset is withing
45 * boundaries of unsigned short.
47 BUG_ON(key
->offset
> USHRT_MAX
);
48 BUG_ON(dissector_uses_key(flow_dissector
,
51 dissector_set_key(flow_dissector
, key
->key_id
);
52 flow_dissector
->offset
[key
->key_id
] = key
->offset
;
55 /* Ensure that the dissector always includes control and basic key.
56 * That way we are able to avoid handling lack of these in fast path.
58 BUG_ON(!dissector_uses_key(flow_dissector
,
59 FLOW_DISSECTOR_KEY_CONTROL
));
60 BUG_ON(!dissector_uses_key(flow_dissector
,
61 FLOW_DISSECTOR_KEY_BASIC
));
63 EXPORT_SYMBOL(skb_flow_dissector_init
);
66 * skb_flow_get_be16 - extract be16 entity
67 * @skb: sk_buff to extract from
68 * @poff: offset to extract at
69 * @data: raw buffer pointer to the packet
70 * @hlen: packet header length
72 * The function will try to retrieve a be32 entity at
75 static __be16
skb_flow_get_be16(const struct sk_buff
*skb
, int poff
,
80 u
= __skb_header_pointer(skb
, poff
, sizeof(_u
), data
, hlen
, &_u
);
88 * __skb_flow_get_ports - extract the upper layer ports and return them
89 * @skb: sk_buff to extract the ports from
90 * @thoff: transport header offset
91 * @ip_proto: protocol for which to get port offset
92 * @data: raw buffer pointer to the packet, if NULL use skb->data
93 * @hlen: packet header length, if @data is NULL use skb_headlen(skb)
95 * The function will try to retrieve the ports at offset thoff + poff where poff
96 * is the protocol port offset returned from proto_ports_offset
98 __be32
__skb_flow_get_ports(const struct sk_buff
*skb
, int thoff
, u8 ip_proto
,
101 int poff
= proto_ports_offset(ip_proto
);
105 hlen
= skb_headlen(skb
);
109 __be32
*ports
, _ports
;
111 ports
= __skb_header_pointer(skb
, thoff
+ poff
,
112 sizeof(_ports
), data
, hlen
, &_ports
);
119 EXPORT_SYMBOL(__skb_flow_get_ports
);
122 skb_flow_dissect_set_enc_addr_type(enum flow_dissector_key_id type
,
123 struct flow_dissector
*flow_dissector
,
124 void *target_container
)
126 struct flow_dissector_key_control
*ctrl
;
128 if (!dissector_uses_key(flow_dissector
, FLOW_DISSECTOR_KEY_ENC_CONTROL
))
131 ctrl
= skb_flow_dissector_target(flow_dissector
,
132 FLOW_DISSECTOR_KEY_ENC_CONTROL
,
134 ctrl
->addr_type
= type
;
138 skb_flow_dissect_tunnel_info(const struct sk_buff
*skb
,
139 struct flow_dissector
*flow_dissector
,
140 void *target_container
)
142 struct ip_tunnel_info
*info
;
143 struct ip_tunnel_key
*key
;
145 /* A quick check to see if there might be something to do. */
146 if (!dissector_uses_key(flow_dissector
,
147 FLOW_DISSECTOR_KEY_ENC_KEYID
) &&
148 !dissector_uses_key(flow_dissector
,
149 FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS
) &&
150 !dissector_uses_key(flow_dissector
,
151 FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS
) &&
152 !dissector_uses_key(flow_dissector
,
153 FLOW_DISSECTOR_KEY_ENC_CONTROL
) &&
154 !dissector_uses_key(flow_dissector
,
155 FLOW_DISSECTOR_KEY_ENC_PORTS
))
158 info
= skb_tunnel_info(skb
);
164 switch (ip_tunnel_info_af(info
)) {
166 skb_flow_dissect_set_enc_addr_type(FLOW_DISSECTOR_KEY_IPV4_ADDRS
,
169 if (dissector_uses_key(flow_dissector
,
170 FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS
)) {
171 struct flow_dissector_key_ipv4_addrs
*ipv4
;
173 ipv4
= skb_flow_dissector_target(flow_dissector
,
174 FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS
,
176 ipv4
->src
= key
->u
.ipv4
.src
;
177 ipv4
->dst
= key
->u
.ipv4
.dst
;
181 skb_flow_dissect_set_enc_addr_type(FLOW_DISSECTOR_KEY_IPV6_ADDRS
,
184 if (dissector_uses_key(flow_dissector
,
185 FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS
)) {
186 struct flow_dissector_key_ipv6_addrs
*ipv6
;
188 ipv6
= skb_flow_dissector_target(flow_dissector
,
189 FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS
,
191 ipv6
->src
= key
->u
.ipv6
.src
;
192 ipv6
->dst
= key
->u
.ipv6
.dst
;
197 if (dissector_uses_key(flow_dissector
, FLOW_DISSECTOR_KEY_ENC_KEYID
)) {
198 struct flow_dissector_key_keyid
*keyid
;
200 keyid
= skb_flow_dissector_target(flow_dissector
,
201 FLOW_DISSECTOR_KEY_ENC_KEYID
,
203 keyid
->keyid
= tunnel_id_to_key32(key
->tun_id
);
206 if (dissector_uses_key(flow_dissector
, FLOW_DISSECTOR_KEY_ENC_PORTS
)) {
207 struct flow_dissector_key_ports
*tp
;
209 tp
= skb_flow_dissector_target(flow_dissector
,
210 FLOW_DISSECTOR_KEY_ENC_PORTS
,
212 tp
->src
= key
->tp_src
;
213 tp
->dst
= key
->tp_dst
;
216 EXPORT_SYMBOL(skb_flow_dissect_tunnel_info
);
218 static enum flow_dissect_ret
219 __skb_flow_dissect_mpls(const struct sk_buff
*skb
,
220 struct flow_dissector
*flow_dissector
,
221 void *target_container
, void *data
, int nhoff
, int hlen
)
223 struct flow_dissector_key_keyid
*key_keyid
;
224 struct mpls_label
*hdr
, _hdr
[2];
227 if (!dissector_uses_key(flow_dissector
,
228 FLOW_DISSECTOR_KEY_MPLS_ENTROPY
) &&
229 !dissector_uses_key(flow_dissector
, FLOW_DISSECTOR_KEY_MPLS
))
230 return FLOW_DISSECT_RET_OUT_GOOD
;
232 hdr
= __skb_header_pointer(skb
, nhoff
, sizeof(_hdr
), data
,
235 return FLOW_DISSECT_RET_OUT_BAD
;
237 entry
= ntohl(hdr
[0].entry
);
238 label
= (entry
& MPLS_LS_LABEL_MASK
) >> MPLS_LS_LABEL_SHIFT
;
240 if (dissector_uses_key(flow_dissector
, FLOW_DISSECTOR_KEY_MPLS
)) {
241 struct flow_dissector_key_mpls
*key_mpls
;
243 key_mpls
= skb_flow_dissector_target(flow_dissector
,
244 FLOW_DISSECTOR_KEY_MPLS
,
246 key_mpls
->mpls_label
= label
;
247 key_mpls
->mpls_ttl
= (entry
& MPLS_LS_TTL_MASK
)
248 >> MPLS_LS_TTL_SHIFT
;
249 key_mpls
->mpls_tc
= (entry
& MPLS_LS_TC_MASK
)
251 key_mpls
->mpls_bos
= (entry
& MPLS_LS_S_MASK
)
255 if (label
== MPLS_LABEL_ENTROPY
) {
256 key_keyid
= skb_flow_dissector_target(flow_dissector
,
257 FLOW_DISSECTOR_KEY_MPLS_ENTROPY
,
259 key_keyid
->keyid
= hdr
[1].entry
& htonl(MPLS_LS_LABEL_MASK
);
261 return FLOW_DISSECT_RET_OUT_GOOD
;
264 static enum flow_dissect_ret
265 __skb_flow_dissect_arp(const struct sk_buff
*skb
,
266 struct flow_dissector
*flow_dissector
,
267 void *target_container
, void *data
, int nhoff
, int hlen
)
269 struct flow_dissector_key_arp
*key_arp
;
271 unsigned char ar_sha
[ETH_ALEN
];
272 unsigned char ar_sip
[4];
273 unsigned char ar_tha
[ETH_ALEN
];
274 unsigned char ar_tip
[4];
275 } *arp_eth
, _arp_eth
;
276 const struct arphdr
*arp
;
279 if (!dissector_uses_key(flow_dissector
, FLOW_DISSECTOR_KEY_ARP
))
280 return FLOW_DISSECT_RET_OUT_GOOD
;
282 arp
= __skb_header_pointer(skb
, nhoff
, sizeof(_arp
), data
,
285 return FLOW_DISSECT_RET_OUT_BAD
;
287 if (arp
->ar_hrd
!= htons(ARPHRD_ETHER
) ||
288 arp
->ar_pro
!= htons(ETH_P_IP
) ||
289 arp
->ar_hln
!= ETH_ALEN
||
291 (arp
->ar_op
!= htons(ARPOP_REPLY
) &&
292 arp
->ar_op
!= htons(ARPOP_REQUEST
)))
293 return FLOW_DISSECT_RET_OUT_BAD
;
295 arp_eth
= __skb_header_pointer(skb
, nhoff
+ sizeof(_arp
),
296 sizeof(_arp_eth
), data
,
299 return FLOW_DISSECT_RET_OUT_BAD
;
301 key_arp
= skb_flow_dissector_target(flow_dissector
,
302 FLOW_DISSECTOR_KEY_ARP
,
305 memcpy(&key_arp
->sip
, arp_eth
->ar_sip
, sizeof(key_arp
->sip
));
306 memcpy(&key_arp
->tip
, arp_eth
->ar_tip
, sizeof(key_arp
->tip
));
308 /* Only store the lower byte of the opcode;
309 * this covers ARPOP_REPLY and ARPOP_REQUEST.
311 key_arp
->op
= ntohs(arp
->ar_op
) & 0xff;
313 ether_addr_copy(key_arp
->sha
, arp_eth
->ar_sha
);
314 ether_addr_copy(key_arp
->tha
, arp_eth
->ar_tha
);
316 return FLOW_DISSECT_RET_OUT_GOOD
;
319 static enum flow_dissect_ret
320 __skb_flow_dissect_gre(const struct sk_buff
*skb
,
321 struct flow_dissector_key_control
*key_control
,
322 struct flow_dissector
*flow_dissector
,
323 void *target_container
, void *data
,
324 __be16
*p_proto
, int *p_nhoff
, int *p_hlen
,
327 struct flow_dissector_key_keyid
*key_keyid
;
328 struct gre_base_hdr
*hdr
, _hdr
;
332 hdr
= __skb_header_pointer(skb
, *p_nhoff
, sizeof(_hdr
),
333 data
, *p_hlen
, &_hdr
);
335 return FLOW_DISSECT_RET_OUT_BAD
;
337 /* Only look inside GRE without routing */
338 if (hdr
->flags
& GRE_ROUTING
)
339 return FLOW_DISSECT_RET_OUT_GOOD
;
341 /* Only look inside GRE for version 0 and 1 */
342 gre_ver
= ntohs(hdr
->flags
& GRE_VERSION
);
344 return FLOW_DISSECT_RET_OUT_GOOD
;
346 *p_proto
= hdr
->protocol
;
348 /* Version1 must be PPTP, and check the flags */
349 if (!(*p_proto
== GRE_PROTO_PPP
&& (hdr
->flags
& GRE_KEY
)))
350 return FLOW_DISSECT_RET_OUT_GOOD
;
353 offset
+= sizeof(struct gre_base_hdr
);
355 if (hdr
->flags
& GRE_CSUM
)
356 offset
+= sizeof(((struct gre_full_hdr
*) 0)->csum
) +
357 sizeof(((struct gre_full_hdr
*) 0)->reserved1
);
359 if (hdr
->flags
& GRE_KEY
) {
363 keyid
= __skb_header_pointer(skb
, *p_nhoff
+ offset
,
365 data
, *p_hlen
, &_keyid
);
367 return FLOW_DISSECT_RET_OUT_BAD
;
369 if (dissector_uses_key(flow_dissector
,
370 FLOW_DISSECTOR_KEY_GRE_KEYID
)) {
371 key_keyid
= skb_flow_dissector_target(flow_dissector
,
372 FLOW_DISSECTOR_KEY_GRE_KEYID
,
375 key_keyid
->keyid
= *keyid
;
377 key_keyid
->keyid
= *keyid
& GRE_PPTP_KEY_MASK
;
379 offset
+= sizeof(((struct gre_full_hdr
*) 0)->key
);
382 if (hdr
->flags
& GRE_SEQ
)
383 offset
+= sizeof(((struct pptp_gre_header
*) 0)->seq
);
386 if (*p_proto
== htons(ETH_P_TEB
)) {
387 const struct ethhdr
*eth
;
390 eth
= __skb_header_pointer(skb
, *p_nhoff
+ offset
,
392 data
, *p_hlen
, &_eth
);
394 return FLOW_DISSECT_RET_OUT_BAD
;
395 *p_proto
= eth
->h_proto
;
396 offset
+= sizeof(*eth
);
398 /* Cap headers that we access via pointers at the
399 * end of the Ethernet header as our maximum alignment
400 * at that point is only 2 bytes.
403 *p_hlen
= *p_nhoff
+ offset
;
405 } else { /* version 1, must be PPTP */
406 u8 _ppp_hdr
[PPP_HDRLEN
];
409 if (hdr
->flags
& GRE_ACK
)
410 offset
+= sizeof(((struct pptp_gre_header
*) 0)->ack
);
412 ppp_hdr
= __skb_header_pointer(skb
, *p_nhoff
+ offset
,
414 data
, *p_hlen
, _ppp_hdr
);
416 return FLOW_DISSECT_RET_OUT_BAD
;
418 switch (PPP_PROTOCOL(ppp_hdr
)) {
420 *p_proto
= htons(ETH_P_IP
);
423 *p_proto
= htons(ETH_P_IPV6
);
426 /* Could probably catch some more like MPLS */
430 offset
+= PPP_HDRLEN
;
434 key_control
->flags
|= FLOW_DIS_ENCAPSULATION
;
435 if (flags
& FLOW_DISSECTOR_F_STOP_AT_ENCAP
)
436 return FLOW_DISSECT_RET_OUT_GOOD
;
438 return FLOW_DISSECT_RET_PROTO_AGAIN
;
442 * __skb_flow_dissect_batadv() - dissect batman-adv header
443 * @skb: sk_buff to with the batman-adv header
444 * @key_control: flow dissectors control key
445 * @data: raw buffer pointer to the packet, if NULL use skb->data
446 * @p_proto: pointer used to update the protocol to process next
447 * @p_nhoff: pointer used to update inner network header offset
448 * @hlen: packet header length
449 * @flags: any combination of FLOW_DISSECTOR_F_*
451 * ETH_P_BATMAN packets are tried to be dissected. Only
452 * &struct batadv_unicast packets are actually processed because they contain an
453 * inner ethernet header and are usually followed by actual network header. This
454 * allows the flow dissector to continue processing the packet.
456 * Return: FLOW_DISSECT_RET_PROTO_AGAIN when &struct batadv_unicast was found,
457 * FLOW_DISSECT_RET_OUT_GOOD when dissector should stop after encapsulation,
458 * otherwise FLOW_DISSECT_RET_OUT_BAD
460 static enum flow_dissect_ret
461 __skb_flow_dissect_batadv(const struct sk_buff
*skb
,
462 struct flow_dissector_key_control
*key_control
,
463 void *data
, __be16
*p_proto
, int *p_nhoff
, int hlen
,
467 struct batadv_unicast_packet batadv_unicast
;
471 hdr
= __skb_header_pointer(skb
, *p_nhoff
, sizeof(_hdr
), data
, hlen
,
474 return FLOW_DISSECT_RET_OUT_BAD
;
476 if (hdr
->batadv_unicast
.version
!= BATADV_COMPAT_VERSION
)
477 return FLOW_DISSECT_RET_OUT_BAD
;
479 if (hdr
->batadv_unicast
.packet_type
!= BATADV_UNICAST
)
480 return FLOW_DISSECT_RET_OUT_BAD
;
482 *p_proto
= hdr
->eth
.h_proto
;
483 *p_nhoff
+= sizeof(*hdr
);
485 key_control
->flags
|= FLOW_DIS_ENCAPSULATION
;
486 if (flags
& FLOW_DISSECTOR_F_STOP_AT_ENCAP
)
487 return FLOW_DISSECT_RET_OUT_GOOD
;
489 return FLOW_DISSECT_RET_PROTO_AGAIN
;
493 __skb_flow_dissect_tcp(const struct sk_buff
*skb
,
494 struct flow_dissector
*flow_dissector
,
495 void *target_container
, void *data
, int thoff
, int hlen
)
497 struct flow_dissector_key_tcp
*key_tcp
;
498 struct tcphdr
*th
, _th
;
500 if (!dissector_uses_key(flow_dissector
, FLOW_DISSECTOR_KEY_TCP
))
503 th
= __skb_header_pointer(skb
, thoff
, sizeof(_th
), data
, hlen
, &_th
);
507 if (unlikely(__tcp_hdrlen(th
) < sizeof(_th
)))
510 key_tcp
= skb_flow_dissector_target(flow_dissector
,
511 FLOW_DISSECTOR_KEY_TCP
,
513 key_tcp
->flags
= (*(__be16
*) &tcp_flag_word(th
) & htons(0x0FFF));
517 __skb_flow_dissect_ipv4(const struct sk_buff
*skb
,
518 struct flow_dissector
*flow_dissector
,
519 void *target_container
, void *data
, const struct iphdr
*iph
)
521 struct flow_dissector_key_ip
*key_ip
;
523 if (!dissector_uses_key(flow_dissector
, FLOW_DISSECTOR_KEY_IP
))
526 key_ip
= skb_flow_dissector_target(flow_dissector
,
527 FLOW_DISSECTOR_KEY_IP
,
529 key_ip
->tos
= iph
->tos
;
530 key_ip
->ttl
= iph
->ttl
;
534 __skb_flow_dissect_ipv6(const struct sk_buff
*skb
,
535 struct flow_dissector
*flow_dissector
,
536 void *target_container
, void *data
, const struct ipv6hdr
*iph
)
538 struct flow_dissector_key_ip
*key_ip
;
540 if (!dissector_uses_key(flow_dissector
, FLOW_DISSECTOR_KEY_IP
))
543 key_ip
= skb_flow_dissector_target(flow_dissector
,
544 FLOW_DISSECTOR_KEY_IP
,
546 key_ip
->tos
= ipv6_get_dsfield(iph
);
547 key_ip
->ttl
= iph
->hop_limit
;
550 /* Maximum number of protocol headers that can be parsed in
553 #define MAX_FLOW_DISSECT_HDRS 15
555 static bool skb_flow_dissect_allowed(int *num_hdrs
)
559 return (*num_hdrs
<= MAX_FLOW_DISSECT_HDRS
);
563 * __skb_flow_dissect - extract the flow_keys struct and return it
564 * @skb: sk_buff to extract the flow from, can be NULL if the rest are specified
565 * @flow_dissector: list of keys to dissect
566 * @target_container: target structure to put dissected values into
567 * @data: raw buffer pointer to the packet, if NULL use skb->data
568 * @proto: protocol for which to get the flow, if @data is NULL use skb->protocol
569 * @nhoff: network header offset, if @data is NULL use skb_network_offset(skb)
570 * @hlen: packet header length, if @data is NULL use skb_headlen(skb)
572 * The function will try to retrieve individual keys into target specified
573 * by flow_dissector from either the skbuff or a raw buffer specified by the
576 * Caller must take care of zeroing target container memory.
578 bool __skb_flow_dissect(const struct sk_buff
*skb
,
579 struct flow_dissector
*flow_dissector
,
580 void *target_container
,
581 void *data
, __be16 proto
, int nhoff
, int hlen
,
584 struct flow_dissector_key_control
*key_control
;
585 struct flow_dissector_key_basic
*key_basic
;
586 struct flow_dissector_key_addrs
*key_addrs
;
587 struct flow_dissector_key_ports
*key_ports
;
588 struct flow_dissector_key_icmp
*key_icmp
;
589 struct flow_dissector_key_tags
*key_tags
;
590 struct flow_dissector_key_vlan
*key_vlan
;
591 enum flow_dissect_ret fdret
;
592 bool skip_vlan
= false;
599 proto
= skb_vlan_tag_present(skb
) ?
600 skb
->vlan_proto
: skb
->protocol
;
601 nhoff
= skb_network_offset(skb
);
602 hlen
= skb_headlen(skb
);
603 #if IS_ENABLED(CONFIG_NET_DSA)
604 if (unlikely(skb
->dev
&& netdev_uses_dsa(skb
->dev
))) {
605 const struct dsa_device_ops
*ops
;
608 ops
= skb
->dev
->dsa_ptr
->tag_ops
;
609 if (ops
->flow_dissect
&&
610 !ops
->flow_dissect(skb
, &proto
, &offset
)) {
618 /* It is ensured by skb_flow_dissector_init() that control key will
621 key_control
= skb_flow_dissector_target(flow_dissector
,
622 FLOW_DISSECTOR_KEY_CONTROL
,
625 /* It is ensured by skb_flow_dissector_init() that basic key will
628 key_basic
= skb_flow_dissector_target(flow_dissector
,
629 FLOW_DISSECTOR_KEY_BASIC
,
632 if (dissector_uses_key(flow_dissector
,
633 FLOW_DISSECTOR_KEY_ETH_ADDRS
)) {
634 struct ethhdr
*eth
= eth_hdr(skb
);
635 struct flow_dissector_key_eth_addrs
*key_eth_addrs
;
637 key_eth_addrs
= skb_flow_dissector_target(flow_dissector
,
638 FLOW_DISSECTOR_KEY_ETH_ADDRS
,
640 memcpy(key_eth_addrs
, ð
->h_dest
, sizeof(*key_eth_addrs
));
644 fdret
= FLOW_DISSECT_RET_CONTINUE
;
647 case htons(ETH_P_IP
): {
648 const struct iphdr
*iph
;
651 iph
= __skb_header_pointer(skb
, nhoff
, sizeof(_iph
), data
, hlen
, &_iph
);
652 if (!iph
|| iph
->ihl
< 5) {
653 fdret
= FLOW_DISSECT_RET_OUT_BAD
;
657 nhoff
+= iph
->ihl
* 4;
659 ip_proto
= iph
->protocol
;
661 if (dissector_uses_key(flow_dissector
,
662 FLOW_DISSECTOR_KEY_IPV4_ADDRS
)) {
663 key_addrs
= skb_flow_dissector_target(flow_dissector
,
664 FLOW_DISSECTOR_KEY_IPV4_ADDRS
,
667 memcpy(&key_addrs
->v4addrs
, &iph
->saddr
,
668 sizeof(key_addrs
->v4addrs
));
669 key_control
->addr_type
= FLOW_DISSECTOR_KEY_IPV4_ADDRS
;
672 if (ip_is_fragment(iph
)) {
673 key_control
->flags
|= FLOW_DIS_IS_FRAGMENT
;
675 if (iph
->frag_off
& htons(IP_OFFSET
)) {
676 fdret
= FLOW_DISSECT_RET_OUT_GOOD
;
679 key_control
->flags
|= FLOW_DIS_FIRST_FRAG
;
681 FLOW_DISSECTOR_F_PARSE_1ST_FRAG
)) {
682 fdret
= FLOW_DISSECT_RET_OUT_GOOD
;
688 __skb_flow_dissect_ipv4(skb
, flow_dissector
,
689 target_container
, data
, iph
);
691 if (flags
& FLOW_DISSECTOR_F_STOP_AT_L3
) {
692 fdret
= FLOW_DISSECT_RET_OUT_GOOD
;
698 case htons(ETH_P_IPV6
): {
699 const struct ipv6hdr
*iph
;
702 iph
= __skb_header_pointer(skb
, nhoff
, sizeof(_iph
), data
, hlen
, &_iph
);
704 fdret
= FLOW_DISSECT_RET_OUT_BAD
;
708 ip_proto
= iph
->nexthdr
;
709 nhoff
+= sizeof(struct ipv6hdr
);
711 if (dissector_uses_key(flow_dissector
,
712 FLOW_DISSECTOR_KEY_IPV6_ADDRS
)) {
713 key_addrs
= skb_flow_dissector_target(flow_dissector
,
714 FLOW_DISSECTOR_KEY_IPV6_ADDRS
,
717 memcpy(&key_addrs
->v6addrs
, &iph
->saddr
,
718 sizeof(key_addrs
->v6addrs
));
719 key_control
->addr_type
= FLOW_DISSECTOR_KEY_IPV6_ADDRS
;
722 if ((dissector_uses_key(flow_dissector
,
723 FLOW_DISSECTOR_KEY_FLOW_LABEL
) ||
724 (flags
& FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL
)) &&
725 ip6_flowlabel(iph
)) {
726 __be32 flow_label
= ip6_flowlabel(iph
);
728 if (dissector_uses_key(flow_dissector
,
729 FLOW_DISSECTOR_KEY_FLOW_LABEL
)) {
730 key_tags
= skb_flow_dissector_target(flow_dissector
,
731 FLOW_DISSECTOR_KEY_FLOW_LABEL
,
733 key_tags
->flow_label
= ntohl(flow_label
);
735 if (flags
& FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL
) {
736 fdret
= FLOW_DISSECT_RET_OUT_GOOD
;
741 __skb_flow_dissect_ipv6(skb
, flow_dissector
,
742 target_container
, data
, iph
);
744 if (flags
& FLOW_DISSECTOR_F_STOP_AT_L3
)
745 fdret
= FLOW_DISSECT_RET_OUT_GOOD
;
749 case htons(ETH_P_8021AD
):
750 case htons(ETH_P_8021Q
): {
751 const struct vlan_hdr
*vlan
;
752 struct vlan_hdr _vlan
;
753 bool vlan_tag_present
= skb
&& skb_vlan_tag_present(skb
);
755 if (vlan_tag_present
)
756 proto
= skb
->protocol
;
758 if (!vlan_tag_present
|| eth_type_vlan(skb
->protocol
)) {
759 vlan
= __skb_header_pointer(skb
, nhoff
, sizeof(_vlan
),
762 fdret
= FLOW_DISSECT_RET_OUT_BAD
;
766 proto
= vlan
->h_vlan_encapsulated_proto
;
767 nhoff
+= sizeof(*vlan
);
769 fdret
= FLOW_DISSECT_RET_PROTO_AGAIN
;
775 if (dissector_uses_key(flow_dissector
,
776 FLOW_DISSECTOR_KEY_VLAN
)) {
777 key_vlan
= skb_flow_dissector_target(flow_dissector
,
778 FLOW_DISSECTOR_KEY_VLAN
,
781 if (vlan_tag_present
) {
782 key_vlan
->vlan_id
= skb_vlan_tag_get_id(skb
);
783 key_vlan
->vlan_priority
=
784 (skb_vlan_tag_get_prio(skb
) >> VLAN_PRIO_SHIFT
);
786 key_vlan
->vlan_id
= ntohs(vlan
->h_vlan_TCI
) &
788 key_vlan
->vlan_priority
=
789 (ntohs(vlan
->h_vlan_TCI
) &
790 VLAN_PRIO_MASK
) >> VLAN_PRIO_SHIFT
;
794 fdret
= FLOW_DISSECT_RET_PROTO_AGAIN
;
797 case htons(ETH_P_PPP_SES
): {
799 struct pppoe_hdr hdr
;
802 hdr
= __skb_header_pointer(skb
, nhoff
, sizeof(_hdr
), data
, hlen
, &_hdr
);
804 fdret
= FLOW_DISSECT_RET_OUT_BAD
;
809 nhoff
+= PPPOE_SES_HLEN
;
812 proto
= htons(ETH_P_IP
);
813 fdret
= FLOW_DISSECT_RET_PROTO_AGAIN
;
815 case htons(PPP_IPV6
):
816 proto
= htons(ETH_P_IPV6
);
817 fdret
= FLOW_DISSECT_RET_PROTO_AGAIN
;
820 fdret
= FLOW_DISSECT_RET_OUT_BAD
;
825 case htons(ETH_P_TIPC
): {
826 struct tipc_basic_hdr
*hdr
, _hdr
;
828 hdr
= __skb_header_pointer(skb
, nhoff
, sizeof(_hdr
),
831 fdret
= FLOW_DISSECT_RET_OUT_BAD
;
835 if (dissector_uses_key(flow_dissector
,
836 FLOW_DISSECTOR_KEY_TIPC
)) {
837 key_addrs
= skb_flow_dissector_target(flow_dissector
,
838 FLOW_DISSECTOR_KEY_TIPC
,
840 key_addrs
->tipckey
.key
= tipc_hdr_rps_key(hdr
);
841 key_control
->addr_type
= FLOW_DISSECTOR_KEY_TIPC
;
843 fdret
= FLOW_DISSECT_RET_OUT_GOOD
;
847 case htons(ETH_P_MPLS_UC
):
848 case htons(ETH_P_MPLS_MC
):
849 fdret
= __skb_flow_dissect_mpls(skb
, flow_dissector
,
850 target_container
, data
,
853 case htons(ETH_P_FCOE
):
854 if ((hlen
- nhoff
) < FCOE_HEADER_LEN
) {
855 fdret
= FLOW_DISSECT_RET_OUT_BAD
;
859 nhoff
+= FCOE_HEADER_LEN
;
860 fdret
= FLOW_DISSECT_RET_OUT_GOOD
;
863 case htons(ETH_P_ARP
):
864 case htons(ETH_P_RARP
):
865 fdret
= __skb_flow_dissect_arp(skb
, flow_dissector
,
866 target_container
, data
,
870 case htons(ETH_P_BATMAN
):
871 fdret
= __skb_flow_dissect_batadv(skb
, key_control
, data
,
872 &proto
, &nhoff
, hlen
, flags
);
876 fdret
= FLOW_DISSECT_RET_OUT_BAD
;
880 /* Process result of proto processing */
882 case FLOW_DISSECT_RET_OUT_GOOD
:
884 case FLOW_DISSECT_RET_PROTO_AGAIN
:
885 if (skb_flow_dissect_allowed(&num_hdrs
))
888 case FLOW_DISSECT_RET_CONTINUE
:
889 case FLOW_DISSECT_RET_IPPROTO_AGAIN
:
891 case FLOW_DISSECT_RET_OUT_BAD
:
897 fdret
= FLOW_DISSECT_RET_CONTINUE
;
901 fdret
= __skb_flow_dissect_gre(skb
, key_control
, flow_dissector
,
902 target_container
, data
,
903 &proto
, &nhoff
, &hlen
, flags
);
907 case NEXTHDR_ROUTING
:
909 u8 _opthdr
[2], *opthdr
;
911 if (proto
!= htons(ETH_P_IPV6
))
914 opthdr
= __skb_header_pointer(skb
, nhoff
, sizeof(_opthdr
),
915 data
, hlen
, &_opthdr
);
917 fdret
= FLOW_DISSECT_RET_OUT_BAD
;
921 ip_proto
= opthdr
[0];
922 nhoff
+= (opthdr
[1] + 1) << 3;
924 fdret
= FLOW_DISSECT_RET_IPPROTO_AGAIN
;
927 case NEXTHDR_FRAGMENT
: {
928 struct frag_hdr _fh
, *fh
;
930 if (proto
!= htons(ETH_P_IPV6
))
933 fh
= __skb_header_pointer(skb
, nhoff
, sizeof(_fh
),
937 fdret
= FLOW_DISSECT_RET_OUT_BAD
;
941 key_control
->flags
|= FLOW_DIS_IS_FRAGMENT
;
943 nhoff
+= sizeof(_fh
);
944 ip_proto
= fh
->nexthdr
;
946 if (!(fh
->frag_off
& htons(IP6_OFFSET
))) {
947 key_control
->flags
|= FLOW_DIS_FIRST_FRAG
;
948 if (flags
& FLOW_DISSECTOR_F_PARSE_1ST_FRAG
) {
949 fdret
= FLOW_DISSECT_RET_IPPROTO_AGAIN
;
954 fdret
= FLOW_DISSECT_RET_OUT_GOOD
;
958 proto
= htons(ETH_P_IP
);
960 key_control
->flags
|= FLOW_DIS_ENCAPSULATION
;
961 if (flags
& FLOW_DISSECTOR_F_STOP_AT_ENCAP
) {
962 fdret
= FLOW_DISSECT_RET_OUT_GOOD
;
966 fdret
= FLOW_DISSECT_RET_PROTO_AGAIN
;
970 proto
= htons(ETH_P_IPV6
);
972 key_control
->flags
|= FLOW_DIS_ENCAPSULATION
;
973 if (flags
& FLOW_DISSECTOR_F_STOP_AT_ENCAP
) {
974 fdret
= FLOW_DISSECT_RET_OUT_GOOD
;
978 fdret
= FLOW_DISSECT_RET_PROTO_AGAIN
;
983 proto
= htons(ETH_P_MPLS_UC
);
984 fdret
= FLOW_DISSECT_RET_PROTO_AGAIN
;
988 __skb_flow_dissect_tcp(skb
, flow_dissector
, target_container
,
996 if (dissector_uses_key(flow_dissector
,
997 FLOW_DISSECTOR_KEY_PORTS
)) {
998 key_ports
= skb_flow_dissector_target(flow_dissector
,
999 FLOW_DISSECTOR_KEY_PORTS
,
1001 key_ports
->ports
= __skb_flow_get_ports(skb
, nhoff
, ip_proto
,
1005 if (dissector_uses_key(flow_dissector
,
1006 FLOW_DISSECTOR_KEY_ICMP
)) {
1007 key_icmp
= skb_flow_dissector_target(flow_dissector
,
1008 FLOW_DISSECTOR_KEY_ICMP
,
1010 key_icmp
->icmp
= skb_flow_get_be16(skb
, nhoff
, data
, hlen
);
1013 /* Process result of IP proto processing */
1015 case FLOW_DISSECT_RET_PROTO_AGAIN
:
1016 if (skb_flow_dissect_allowed(&num_hdrs
))
1019 case FLOW_DISSECT_RET_IPPROTO_AGAIN
:
1020 if (skb_flow_dissect_allowed(&num_hdrs
))
1021 goto ip_proto_again
;
1023 case FLOW_DISSECT_RET_OUT_GOOD
:
1024 case FLOW_DISSECT_RET_CONTINUE
:
1026 case FLOW_DISSECT_RET_OUT_BAD
:
1035 key_control
->thoff
= min_t(u16
, nhoff
, skb
? skb
->len
: hlen
);
1036 key_basic
->n_proto
= proto
;
1037 key_basic
->ip_proto
= ip_proto
;
1045 EXPORT_SYMBOL(__skb_flow_dissect
);
1047 static u32 hashrnd __read_mostly
;
1048 static __always_inline
void __flow_hash_secret_init(void)
1050 net_get_random_once(&hashrnd
, sizeof(hashrnd
));
1053 static __always_inline u32
__flow_hash_words(const u32
*words
, u32 length
,
1056 return jhash2(words
, length
, keyval
);
1059 static inline const u32
*flow_keys_hash_start(const struct flow_keys
*flow
)
1061 const void *p
= flow
;
1063 BUILD_BUG_ON(FLOW_KEYS_HASH_OFFSET
% sizeof(u32
));
1064 return (const u32
*)(p
+ FLOW_KEYS_HASH_OFFSET
);
1067 static inline size_t flow_keys_hash_length(const struct flow_keys
*flow
)
1069 size_t diff
= FLOW_KEYS_HASH_OFFSET
+ sizeof(flow
->addrs
);
1070 BUILD_BUG_ON((sizeof(*flow
) - FLOW_KEYS_HASH_OFFSET
) % sizeof(u32
));
1071 BUILD_BUG_ON(offsetof(typeof(*flow
), addrs
) !=
1072 sizeof(*flow
) - sizeof(flow
->addrs
));
1074 switch (flow
->control
.addr_type
) {
1075 case FLOW_DISSECTOR_KEY_IPV4_ADDRS
:
1076 diff
-= sizeof(flow
->addrs
.v4addrs
);
1078 case FLOW_DISSECTOR_KEY_IPV6_ADDRS
:
1079 diff
-= sizeof(flow
->addrs
.v6addrs
);
1081 case FLOW_DISSECTOR_KEY_TIPC
:
1082 diff
-= sizeof(flow
->addrs
.tipckey
);
1085 return (sizeof(*flow
) - diff
) / sizeof(u32
);
1088 __be32
flow_get_u32_src(const struct flow_keys
*flow
)
1090 switch (flow
->control
.addr_type
) {
1091 case FLOW_DISSECTOR_KEY_IPV4_ADDRS
:
1092 return flow
->addrs
.v4addrs
.src
;
1093 case FLOW_DISSECTOR_KEY_IPV6_ADDRS
:
1094 return (__force __be32
)ipv6_addr_hash(
1095 &flow
->addrs
.v6addrs
.src
);
1096 case FLOW_DISSECTOR_KEY_TIPC
:
1097 return flow
->addrs
.tipckey
.key
;
1102 EXPORT_SYMBOL(flow_get_u32_src
);
1104 __be32
flow_get_u32_dst(const struct flow_keys
*flow
)
1106 switch (flow
->control
.addr_type
) {
1107 case FLOW_DISSECTOR_KEY_IPV4_ADDRS
:
1108 return flow
->addrs
.v4addrs
.dst
;
1109 case FLOW_DISSECTOR_KEY_IPV6_ADDRS
:
1110 return (__force __be32
)ipv6_addr_hash(
1111 &flow
->addrs
.v6addrs
.dst
);
1116 EXPORT_SYMBOL(flow_get_u32_dst
);
1118 static inline void __flow_hash_consistentify(struct flow_keys
*keys
)
1122 switch (keys
->control
.addr_type
) {
1123 case FLOW_DISSECTOR_KEY_IPV4_ADDRS
:
1124 addr_diff
= (__force u32
)keys
->addrs
.v4addrs
.dst
-
1125 (__force u32
)keys
->addrs
.v4addrs
.src
;
1126 if ((addr_diff
< 0) ||
1128 ((__force u16
)keys
->ports
.dst
<
1129 (__force u16
)keys
->ports
.src
))) {
1130 swap(keys
->addrs
.v4addrs
.src
, keys
->addrs
.v4addrs
.dst
);
1131 swap(keys
->ports
.src
, keys
->ports
.dst
);
1134 case FLOW_DISSECTOR_KEY_IPV6_ADDRS
:
1135 addr_diff
= memcmp(&keys
->addrs
.v6addrs
.dst
,
1136 &keys
->addrs
.v6addrs
.src
,
1137 sizeof(keys
->addrs
.v6addrs
.dst
));
1138 if ((addr_diff
< 0) ||
1140 ((__force u16
)keys
->ports
.dst
<
1141 (__force u16
)keys
->ports
.src
))) {
1142 for (i
= 0; i
< 4; i
++)
1143 swap(keys
->addrs
.v6addrs
.src
.s6_addr32
[i
],
1144 keys
->addrs
.v6addrs
.dst
.s6_addr32
[i
]);
1145 swap(keys
->ports
.src
, keys
->ports
.dst
);
1151 static inline u32
__flow_hash_from_keys(struct flow_keys
*keys
, u32 keyval
)
1155 __flow_hash_consistentify(keys
);
1157 hash
= __flow_hash_words(flow_keys_hash_start(keys
),
1158 flow_keys_hash_length(keys
), keyval
);
1165 u32
flow_hash_from_keys(struct flow_keys
*keys
)
1167 __flow_hash_secret_init();
1168 return __flow_hash_from_keys(keys
, hashrnd
);
1170 EXPORT_SYMBOL(flow_hash_from_keys
);
1172 static inline u32
___skb_get_hash(const struct sk_buff
*skb
,
1173 struct flow_keys
*keys
, u32 keyval
)
1175 skb_flow_dissect_flow_keys(skb
, keys
,
1176 FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL
);
1178 return __flow_hash_from_keys(keys
, keyval
);
1181 struct _flow_keys_digest_data
{
1190 void make_flow_keys_digest(struct flow_keys_digest
*digest
,
1191 const struct flow_keys
*flow
)
1193 struct _flow_keys_digest_data
*data
=
1194 (struct _flow_keys_digest_data
*)digest
;
1196 BUILD_BUG_ON(sizeof(*data
) > sizeof(*digest
));
1198 memset(digest
, 0, sizeof(*digest
));
1200 data
->n_proto
= flow
->basic
.n_proto
;
1201 data
->ip_proto
= flow
->basic
.ip_proto
;
1202 data
->ports
= flow
->ports
.ports
;
1203 data
->src
= flow
->addrs
.v4addrs
.src
;
1204 data
->dst
= flow
->addrs
.v4addrs
.dst
;
1206 EXPORT_SYMBOL(make_flow_keys_digest
);
1208 static struct flow_dissector flow_keys_dissector_symmetric __read_mostly
;
1210 u32
__skb_get_hash_symmetric(const struct sk_buff
*skb
)
1212 struct flow_keys keys
;
1214 __flow_hash_secret_init();
1216 memset(&keys
, 0, sizeof(keys
));
1217 __skb_flow_dissect(skb
, &flow_keys_dissector_symmetric
, &keys
,
1219 FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL
);
1221 return __flow_hash_from_keys(&keys
, hashrnd
);
1223 EXPORT_SYMBOL_GPL(__skb_get_hash_symmetric
);
1226 * __skb_get_hash: calculate a flow hash
1227 * @skb: sk_buff to calculate flow hash from
1229 * This function calculates a flow hash based on src/dst addresses
1230 * and src/dst port numbers. Sets hash in skb to non-zero hash value
1231 * on success, zero indicates no valid hash. Also, sets l4_hash in skb
1232 * if hash is a canonical 4-tuple hash over transport ports.
1234 void __skb_get_hash(struct sk_buff
*skb
)
1236 struct flow_keys keys
;
1239 __flow_hash_secret_init();
1241 hash
= ___skb_get_hash(skb
, &keys
, hashrnd
);
1243 __skb_set_sw_hash(skb
, hash
, flow_keys_have_l4(&keys
));
1245 EXPORT_SYMBOL(__skb_get_hash
);
1247 __u32
skb_get_hash_perturb(const struct sk_buff
*skb
, u32 perturb
)
1249 struct flow_keys keys
;
1251 return ___skb_get_hash(skb
, &keys
, perturb
);
1253 EXPORT_SYMBOL(skb_get_hash_perturb
);
1255 u32
__skb_get_poff(const struct sk_buff
*skb
, void *data
,
1256 const struct flow_keys_basic
*keys
, int hlen
)
1258 u32 poff
= keys
->control
.thoff
;
1260 /* skip L4 headers for fragments after the first */
1261 if ((keys
->control
.flags
& FLOW_DIS_IS_FRAGMENT
) &&
1262 !(keys
->control
.flags
& FLOW_DIS_FIRST_FRAG
))
1265 switch (keys
->basic
.ip_proto
) {
1267 /* access doff as u8 to avoid unaligned access */
1271 doff
= __skb_header_pointer(skb
, poff
+ 12, sizeof(_doff
),
1272 data
, hlen
, &_doff
);
1276 poff
+= max_t(u32
, sizeof(struct tcphdr
), (*doff
& 0xF0) >> 2);
1280 case IPPROTO_UDPLITE
:
1281 poff
+= sizeof(struct udphdr
);
1283 /* For the rest, we do not really care about header
1284 * extensions at this point for now.
1287 poff
+= sizeof(struct icmphdr
);
1289 case IPPROTO_ICMPV6
:
1290 poff
+= sizeof(struct icmp6hdr
);
1293 poff
+= sizeof(struct igmphdr
);
1296 poff
+= sizeof(struct dccp_hdr
);
1299 poff
+= sizeof(struct sctphdr
);
1307 * skb_get_poff - get the offset to the payload
1308 * @skb: sk_buff to get the payload offset from
1310 * The function will get the offset to the payload as far as it could
1311 * be dissected. The main user is currently BPF, so that we can dynamically
1312 * truncate packets without needing to push actual payload to the user
1313 * space and can analyze headers only, instead.
1315 u32
skb_get_poff(const struct sk_buff
*skb
)
1317 struct flow_keys_basic keys
;
1319 if (!skb_flow_dissect_flow_keys_basic(skb
, &keys
, NULL
, 0, 0, 0, 0))
1322 return __skb_get_poff(skb
, skb
->data
, &keys
, skb_headlen(skb
));
1325 __u32
__get_hash_from_flowi6(const struct flowi6
*fl6
, struct flow_keys
*keys
)
1327 memset(keys
, 0, sizeof(*keys
));
1329 memcpy(&keys
->addrs
.v6addrs
.src
, &fl6
->saddr
,
1330 sizeof(keys
->addrs
.v6addrs
.src
));
1331 memcpy(&keys
->addrs
.v6addrs
.dst
, &fl6
->daddr
,
1332 sizeof(keys
->addrs
.v6addrs
.dst
));
1333 keys
->control
.addr_type
= FLOW_DISSECTOR_KEY_IPV6_ADDRS
;
1334 keys
->ports
.src
= fl6
->fl6_sport
;
1335 keys
->ports
.dst
= fl6
->fl6_dport
;
1336 keys
->keyid
.keyid
= fl6
->fl6_gre_key
;
1337 keys
->tags
.flow_label
= (__force u32
)flowi6_get_flowlabel(fl6
);
1338 keys
->basic
.ip_proto
= fl6
->flowi6_proto
;
1340 return flow_hash_from_keys(keys
);
1342 EXPORT_SYMBOL(__get_hash_from_flowi6
);
1344 static const struct flow_dissector_key flow_keys_dissector_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_TIPC
,
1363 .offset
= offsetof(struct flow_keys
, addrs
.tipckey
),
1366 .key_id
= FLOW_DISSECTOR_KEY_PORTS
,
1367 .offset
= offsetof(struct flow_keys
, ports
),
1370 .key_id
= FLOW_DISSECTOR_KEY_VLAN
,
1371 .offset
= offsetof(struct flow_keys
, vlan
),
1374 .key_id
= FLOW_DISSECTOR_KEY_FLOW_LABEL
,
1375 .offset
= offsetof(struct flow_keys
, tags
),
1378 .key_id
= FLOW_DISSECTOR_KEY_GRE_KEYID
,
1379 .offset
= offsetof(struct flow_keys
, keyid
),
1383 static const struct flow_dissector_key flow_keys_dissector_symmetric_keys
[] = {
1385 .key_id
= FLOW_DISSECTOR_KEY_CONTROL
,
1386 .offset
= offsetof(struct flow_keys
, control
),
1389 .key_id
= FLOW_DISSECTOR_KEY_BASIC
,
1390 .offset
= offsetof(struct flow_keys
, basic
),
1393 .key_id
= FLOW_DISSECTOR_KEY_IPV4_ADDRS
,
1394 .offset
= offsetof(struct flow_keys
, addrs
.v4addrs
),
1397 .key_id
= FLOW_DISSECTOR_KEY_IPV6_ADDRS
,
1398 .offset
= offsetof(struct flow_keys
, addrs
.v6addrs
),
1401 .key_id
= FLOW_DISSECTOR_KEY_PORTS
,
1402 .offset
= offsetof(struct flow_keys
, ports
),
1406 static const struct flow_dissector_key flow_keys_basic_dissector_keys
[] = {
1408 .key_id
= FLOW_DISSECTOR_KEY_CONTROL
,
1409 .offset
= offsetof(struct flow_keys
, control
),
1412 .key_id
= FLOW_DISSECTOR_KEY_BASIC
,
1413 .offset
= offsetof(struct flow_keys
, basic
),
1417 struct flow_dissector flow_keys_dissector __read_mostly
;
1418 EXPORT_SYMBOL(flow_keys_dissector
);
1420 struct flow_dissector flow_keys_basic_dissector __read_mostly
;
1421 EXPORT_SYMBOL(flow_keys_basic_dissector
);
1423 static int __init
init_default_flow_dissectors(void)
1425 skb_flow_dissector_init(&flow_keys_dissector
,
1426 flow_keys_dissector_keys
,
1427 ARRAY_SIZE(flow_keys_dissector_keys
));
1428 skb_flow_dissector_init(&flow_keys_dissector_symmetric
,
1429 flow_keys_dissector_symmetric_keys
,
1430 ARRAY_SIZE(flow_keys_dissector_symmetric_keys
));
1431 skb_flow_dissector_init(&flow_keys_basic_dissector
,
1432 flow_keys_basic_dissector_keys
,
1433 ARRAY_SIZE(flow_keys_basic_dissector_keys
));
1437 core_initcall(init_default_flow_dissectors
);