1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef __LINUX_PKT_CLS_H
3 #define __LINUX_PKT_CLS_H
5 #include <linux/types.h>
6 #include <linux/pkt_sched.h>
8 #define TC_COOKIE_MAX_SIZE 16
10 /* Action attributes */
22 #define TCA_ACT_MAX __TCA_ACT_MAX
23 #define TCA_OLD_COMPAT (TCA_ACT_MAX+1)
24 #define TCA_ACT_MAX_PRIO 32
25 #define TCA_ACT_BIND 1
26 #define TCA_ACT_NOBIND 0
27 #define TCA_ACT_UNBIND 1
28 #define TCA_ACT_NOUNBIND 0
29 #define TCA_ACT_REPLACE 1
30 #define TCA_ACT_NOREPLACE 0
32 #define TC_ACT_UNSPEC (-1)
34 #define TC_ACT_RECLASSIFY 1
37 #define TC_ACT_STOLEN 4
38 #define TC_ACT_QUEUED 5
39 #define TC_ACT_REPEAT 6
40 #define TC_ACT_REDIRECT 7
41 #define TC_ACT_TRAP 8 /* For hw path, this means "trap to cpu"
42 * and don't further process the frame
43 * in hardware. For sw path, this is
44 * equivalent of TC_ACT_STOLEN - drop
45 * the skb and act like everything
48 #define TC_ACT_VALUE_MAX TC_ACT_TRAP
50 /* There is a special kind of actions called "extended actions",
51 * which need a value parameter. These have a local opcode located in
52 * the highest nibble, starting from 1. The rest of the bits
53 * are used to carry the value. These two parts together make
56 #define __TC_ACT_EXT_SHIFT 28
57 #define __TC_ACT_EXT(local) ((local) << __TC_ACT_EXT_SHIFT)
58 #define TC_ACT_EXT_VAL_MASK ((1 << __TC_ACT_EXT_SHIFT) - 1)
59 #define TC_ACT_EXT_OPCODE(combined) ((combined) & (~TC_ACT_EXT_VAL_MASK))
60 #define TC_ACT_EXT_CMP(combined, opcode) (TC_ACT_EXT_OPCODE(combined) == opcode)
62 #define TC_ACT_JUMP __TC_ACT_EXT(1)
63 #define TC_ACT_GOTO_CHAIN __TC_ACT_EXT(2)
64 #define TC_ACT_EXT_OPCODE_MAX TC_ACT_GOTO_CHAIN
66 /* These macros are put here for binary compatibility with userspace apps that
67 * make use of them. For kernel code and new userspace apps, use the TCA_ID_*
70 #define TCA_ACT_GACT 5
72 #define TCA_ACT_PEDIT 7
73 #define TCA_ACT_MIRRED 8
76 #define TCA_ACT_SKBEDIT 11
77 #define TCA_ACT_VLAN 12
78 #define TCA_ACT_BPF 13
79 #define TCA_ACT_CONNMARK 14
80 #define TCA_ACT_SKBMOD 15
81 #define TCA_ACT_CSUM 16
82 #define TCA_ACT_TUNNEL_KEY 17
83 #define TCA_ACT_SIMP 22
84 #define TCA_ACT_IFE 25
85 #define TCA_ACT_SAMPLE 26
87 /* Action type identifiers*/
91 TCA_ID_GACT = TCA_ACT_GACT,
92 TCA_ID_IPT = TCA_ACT_IPT,
93 TCA_ID_PEDIT = TCA_ACT_PEDIT,
94 TCA_ID_MIRRED = TCA_ACT_MIRRED,
95 TCA_ID_NAT = TCA_ACT_NAT,
96 TCA_ID_XT = TCA_ACT_XT,
97 TCA_ID_SKBEDIT = TCA_ACT_SKBEDIT,
98 TCA_ID_VLAN = TCA_ACT_VLAN,
99 TCA_ID_BPF = TCA_ACT_BPF,
100 TCA_ID_CONNMARK = TCA_ACT_CONNMARK,
101 TCA_ID_SKBMOD = TCA_ACT_SKBMOD,
102 TCA_ID_CSUM = TCA_ACT_CSUM,
103 TCA_ID_TUNNEL_KEY = TCA_ACT_TUNNEL_KEY,
104 TCA_ID_SIMP = TCA_ACT_SIMP,
105 TCA_ID_IFE = TCA_ACT_IFE,
106 TCA_ID_SAMPLE = TCA_ACT_SAMPLE,
107 /* other actions go here */
112 #define TCA_ID_MAX __TCA_ID_MAX
117 #define TC_POLICE_UNSPEC TC_ACT_UNSPEC
118 #define TC_POLICE_OK TC_ACT_OK
119 #define TC_POLICE_RECLASSIFY TC_ACT_RECLASSIFY
120 #define TC_POLICE_SHOT TC_ACT_SHOT
121 #define TC_POLICE_PIPE TC_ACT_PIPE
126 struct tc_ratespec rate;
127 struct tc_ratespec peakrate;
162 #define TCA_POLICE_RESULT TCA_POLICE_RESULT
165 #define TCA_POLICE_MAX (__TCA_POLICE_MAX - 1)
167 /* tca flags definitions */
168 #define TCA_CLS_FLAGS_SKIP_HW (1 << 0) /* don't offload filter to HW */
169 #define TCA_CLS_FLAGS_SKIP_SW (1 << 1) /* don't use filter in SW */
170 #define TCA_CLS_FLAGS_IN_HW (1 << 2) /* filter is offloaded to HW */
171 #define TCA_CLS_FLAGS_NOT_IN_HW (1 << 3) /* filter isn't offloaded to HW */
172 #define TCA_CLS_FLAGS_VERBOSE (1 << 4) /* verbose logging */
176 #define TC_U32_HTID(h) ((h)&0xFFF00000)
177 #define TC_U32_USERHTID(h) (TC_U32_HTID(h)>>20)
178 #define TC_U32_HASH(h) (((h)>>12)&0xFF)
179 #define TC_U32_NODE(h) ((h)&0xFFF)
180 #define TC_U32_KEY(h) ((h)&0xFFFFF)
181 #define TC_U32_UNSPEC 0
182 #define TC_U32_ROOT (0xFFF00000)
201 #define TCA_U32_MAX (__TCA_U32_MAX - 1)
212 unsigned char offshift;
221 struct tc_u32_key keys[0];
238 #define TC_U32_TERMINAL 1
239 #define TC_U32_OFFSET 2
240 #define TC_U32_VAROFFSET 4
243 #define TC_U32_MAXDEPTH 8
259 #define TCA_RSVP_MAX (__TCA_RSVP_MAX - 1 )
267 struct tc_rsvp_pinfo {
268 struct tc_rsvp_gpi dpi;
269 struct tc_rsvp_gpi spi;
289 #define TCA_ROUTE4_MAX (__TCA_ROUTE4_MAX - 1)
299 TCA_FW_ACT, /* used by CONFIG_NET_CLS_ACT */
304 #define TCA_FW_MAX (__TCA_FW_MAX - 1)
306 /* TC index filter */
313 TCA_TCINDEX_FALL_THROUGH,
320 #define TCA_TCINDEX_MAX (__TCA_TCINDEX_MAX - 1)
336 FLOW_KEY_NFCT_PROTO_SRC,
337 FLOW_KEY_NFCT_PROTO_DST,
346 #define FLOW_KEY_MAX (__FLOW_KEY_MAX - 1)
370 #define TCA_FLOW_MAX (__TCA_FLOW_MAX - 1)
374 struct tc_basic_pcnt {
390 #define TCA_BASIC_MAX (__TCA_BASIC_MAX - 1)
393 /* Cgroup classifier */
403 #define TCA_CGROUP_MAX (__TCA_CGROUP_MAX - 1)
407 #define TCA_BPF_FLAG_ACT_DIRECT (1 << 0)
425 #define TCA_BPF_MAX (__TCA_BPF_MAX - 1)
427 /* Flower classifier */
434 TCA_FLOWER_KEY_ETH_DST, /* ETH_ALEN */
435 TCA_FLOWER_KEY_ETH_DST_MASK, /* ETH_ALEN */
436 TCA_FLOWER_KEY_ETH_SRC, /* ETH_ALEN */
437 TCA_FLOWER_KEY_ETH_SRC_MASK, /* ETH_ALEN */
438 TCA_FLOWER_KEY_ETH_TYPE, /* be16 */
439 TCA_FLOWER_KEY_IP_PROTO, /* u8 */
440 TCA_FLOWER_KEY_IPV4_SRC, /* be32 */
441 TCA_FLOWER_KEY_IPV4_SRC_MASK, /* be32 */
442 TCA_FLOWER_KEY_IPV4_DST, /* be32 */
443 TCA_FLOWER_KEY_IPV4_DST_MASK, /* be32 */
444 TCA_FLOWER_KEY_IPV6_SRC, /* struct in6_addr */
445 TCA_FLOWER_KEY_IPV6_SRC_MASK, /* struct in6_addr */
446 TCA_FLOWER_KEY_IPV6_DST, /* struct in6_addr */
447 TCA_FLOWER_KEY_IPV6_DST_MASK, /* struct in6_addr */
448 TCA_FLOWER_KEY_TCP_SRC, /* be16 */
449 TCA_FLOWER_KEY_TCP_DST, /* be16 */
450 TCA_FLOWER_KEY_UDP_SRC, /* be16 */
451 TCA_FLOWER_KEY_UDP_DST, /* be16 */
454 TCA_FLOWER_KEY_VLAN_ID, /* be16 */
455 TCA_FLOWER_KEY_VLAN_PRIO, /* u8 */
456 TCA_FLOWER_KEY_VLAN_ETH_TYPE, /* be16 */
458 TCA_FLOWER_KEY_ENC_KEY_ID, /* be32 */
459 TCA_FLOWER_KEY_ENC_IPV4_SRC, /* be32 */
460 TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK,/* be32 */
461 TCA_FLOWER_KEY_ENC_IPV4_DST, /* be32 */
462 TCA_FLOWER_KEY_ENC_IPV4_DST_MASK,/* be32 */
463 TCA_FLOWER_KEY_ENC_IPV6_SRC, /* struct in6_addr */
464 TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK,/* struct in6_addr */
465 TCA_FLOWER_KEY_ENC_IPV6_DST, /* struct in6_addr */
466 TCA_FLOWER_KEY_ENC_IPV6_DST_MASK,/* struct in6_addr */
468 TCA_FLOWER_KEY_TCP_SRC_MASK, /* be16 */
469 TCA_FLOWER_KEY_TCP_DST_MASK, /* be16 */
470 TCA_FLOWER_KEY_UDP_SRC_MASK, /* be16 */
471 TCA_FLOWER_KEY_UDP_DST_MASK, /* be16 */
472 TCA_FLOWER_KEY_SCTP_SRC_MASK, /* be16 */
473 TCA_FLOWER_KEY_SCTP_DST_MASK, /* be16 */
475 TCA_FLOWER_KEY_SCTP_SRC, /* be16 */
476 TCA_FLOWER_KEY_SCTP_DST, /* be16 */
478 TCA_FLOWER_KEY_ENC_UDP_SRC_PORT, /* be16 */
479 TCA_FLOWER_KEY_ENC_UDP_SRC_PORT_MASK, /* be16 */
480 TCA_FLOWER_KEY_ENC_UDP_DST_PORT, /* be16 */
481 TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK, /* be16 */
483 TCA_FLOWER_KEY_FLAGS, /* be32 */
484 TCA_FLOWER_KEY_FLAGS_MASK, /* be32 */
486 TCA_FLOWER_KEY_ICMPV4_CODE, /* u8 */
487 TCA_FLOWER_KEY_ICMPV4_CODE_MASK,/* u8 */
488 TCA_FLOWER_KEY_ICMPV4_TYPE, /* u8 */
489 TCA_FLOWER_KEY_ICMPV4_TYPE_MASK,/* u8 */
490 TCA_FLOWER_KEY_ICMPV6_CODE, /* u8 */
491 TCA_FLOWER_KEY_ICMPV6_CODE_MASK,/* u8 */
492 TCA_FLOWER_KEY_ICMPV6_TYPE, /* u8 */
493 TCA_FLOWER_KEY_ICMPV6_TYPE_MASK,/* u8 */
495 TCA_FLOWER_KEY_ARP_SIP, /* be32 */
496 TCA_FLOWER_KEY_ARP_SIP_MASK, /* be32 */
497 TCA_FLOWER_KEY_ARP_TIP, /* be32 */
498 TCA_FLOWER_KEY_ARP_TIP_MASK, /* be32 */
499 TCA_FLOWER_KEY_ARP_OP, /* u8 */
500 TCA_FLOWER_KEY_ARP_OP_MASK, /* u8 */
501 TCA_FLOWER_KEY_ARP_SHA, /* ETH_ALEN */
502 TCA_FLOWER_KEY_ARP_SHA_MASK, /* ETH_ALEN */
503 TCA_FLOWER_KEY_ARP_THA, /* ETH_ALEN */
504 TCA_FLOWER_KEY_ARP_THA_MASK, /* ETH_ALEN */
506 TCA_FLOWER_KEY_MPLS_TTL, /* u8 - 8 bits */
507 TCA_FLOWER_KEY_MPLS_BOS, /* u8 - 1 bit */
508 TCA_FLOWER_KEY_MPLS_TC, /* u8 - 3 bits */
509 TCA_FLOWER_KEY_MPLS_LABEL, /* be32 - 20 bits */
511 TCA_FLOWER_KEY_TCP_FLAGS, /* be16 */
512 TCA_FLOWER_KEY_TCP_FLAGS_MASK, /* be16 */
514 TCA_FLOWER_KEY_IP_TOS, /* u8 */
515 TCA_FLOWER_KEY_IP_TOS_MASK, /* u8 */
516 TCA_FLOWER_KEY_IP_TTL, /* u8 */
517 TCA_FLOWER_KEY_IP_TTL_MASK, /* u8 */
519 TCA_FLOWER_KEY_CVLAN_ID, /* be16 */
520 TCA_FLOWER_KEY_CVLAN_PRIO, /* u8 */
521 TCA_FLOWER_KEY_CVLAN_ETH_TYPE, /* be16 */
523 TCA_FLOWER_KEY_ENC_IP_TOS, /* u8 */
524 TCA_FLOWER_KEY_ENC_IP_TOS_MASK, /* u8 */
525 TCA_FLOWER_KEY_ENC_IP_TTL, /* u8 */
526 TCA_FLOWER_KEY_ENC_IP_TTL_MASK, /* u8 */
528 TCA_FLOWER_KEY_ENC_OPTS,
529 TCA_FLOWER_KEY_ENC_OPTS_MASK,
531 TCA_FLOWER_IN_HW_COUNT,
533 TCA_FLOWER_KEY_PORT_SRC_MIN, /* be16 */
534 TCA_FLOWER_KEY_PORT_SRC_MAX, /* be16 */
535 TCA_FLOWER_KEY_PORT_DST_MIN, /* be16 */
536 TCA_FLOWER_KEY_PORT_DST_MAX, /* be16 */
541 #define TCA_FLOWER_MAX (__TCA_FLOWER_MAX - 1)
544 TCA_FLOWER_KEY_ENC_OPTS_UNSPEC,
545 TCA_FLOWER_KEY_ENC_OPTS_GENEVE, /* Nested
546 * TCA_FLOWER_KEY_ENC_OPT_GENEVE_
549 __TCA_FLOWER_KEY_ENC_OPTS_MAX,
552 #define TCA_FLOWER_KEY_ENC_OPTS_MAX (__TCA_FLOWER_KEY_ENC_OPTS_MAX - 1)
555 TCA_FLOWER_KEY_ENC_OPT_GENEVE_UNSPEC,
556 TCA_FLOWER_KEY_ENC_OPT_GENEVE_CLASS, /* u16 */
557 TCA_FLOWER_KEY_ENC_OPT_GENEVE_TYPE, /* u8 */
558 TCA_FLOWER_KEY_ENC_OPT_GENEVE_DATA, /* 4 to 128 bytes */
560 __TCA_FLOWER_KEY_ENC_OPT_GENEVE_MAX,
563 #define TCA_FLOWER_KEY_ENC_OPT_GENEVE_MAX \
564 (__TCA_FLOWER_KEY_ENC_OPT_GENEVE_MAX - 1)
567 TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT = (1 << 0),
568 TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST = (1 << 1),
571 #define TCA_FLOWER_MASK_FLAGS_RANGE (1 << 0) /* Range-based match */
573 /* Match-all classifier */
575 struct tc_matchall_pcnt {
581 TCA_MATCHALL_CLASSID,
589 #define TCA_MATCHALL_MAX (__TCA_MATCHALL_MAX - 1)
591 /* Extended Matches */
593 struct tcf_ematch_tree_hdr {
599 TCA_EMATCH_TREE_UNSPEC,
601 TCA_EMATCH_TREE_LIST,
602 __TCA_EMATCH_TREE_MAX
604 #define TCA_EMATCH_TREE_MAX (__TCA_EMATCH_TREE_MAX - 1)
606 struct tcf_ematch_hdr {
610 __u16 pad; /* currently unused */
614 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
615 * +-----------------------+-+-+---+
617 * +-----------------------+-+-+---+
619 * R(2) ::= relation to next ematch
620 * where: 0 0 END (last ematch)
623 * 1 1 Unused (invalid)
624 * I(1) ::= invert result
625 * S(1) ::= simple payload
627 #define TCF_EM_REL_END 0
628 #define TCF_EM_REL_AND (1<<0)
629 #define TCF_EM_REL_OR (1<<1)
630 #define TCF_EM_INVERT (1<<2)
631 #define TCF_EM_SIMPLE (1<<3)
633 #define TCF_EM_REL_MASK 3
634 #define TCF_EM_REL_VALID(v) (((v) & TCF_EM_REL_MASK) != TCF_EM_REL_MASK)
642 #define TCF_LAYER_MAX (__TCF_LAYER_MAX - 1)
644 /* Ematch type assignments
645 * 1..32767 Reserved for ematches inside kernel tree
646 * 32768..65535 Free to use, not reliable
648 #define TCF_EM_CONTAINER 0
650 #define TCF_EM_NBYTE 2
652 #define TCF_EM_META 4
653 #define TCF_EM_TEXT 5
654 #define TCF_EM_VLAN 6
655 #define TCF_EM_CANID 7
656 #define TCF_EM_IPSET 8