xref: /openbmc/linux/include/uapi/linux/pkt_cls.h (revision 42bc47b3)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef __LINUX_PKT_CLS_H
3 #define __LINUX_PKT_CLS_H
4 
5 #include <linux/types.h>
6 #include <linux/pkt_sched.h>
7 
8 #define TC_COOKIE_MAX_SIZE 16
9 
10 /* Action attributes */
11 enum {
12 	TCA_ACT_UNSPEC,
13 	TCA_ACT_KIND,
14 	TCA_ACT_OPTIONS,
15 	TCA_ACT_INDEX,
16 	TCA_ACT_STATS,
17 	TCA_ACT_PAD,
18 	TCA_ACT_COOKIE,
19 	__TCA_ACT_MAX
20 };
21 
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
31 
32 #define TC_ACT_UNSPEC	(-1)
33 #define TC_ACT_OK		0
34 #define TC_ACT_RECLASSIFY	1
35 #define TC_ACT_SHOT		2
36 #define TC_ACT_PIPE		3
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
46 				   * is alright.
47 				   */
48 
49 /* There is a special kind of actions called "extended actions",
50  * which need a value parameter. These have a local opcode located in
51  * the highest nibble, starting from 1. The rest of the bits
52  * are used to carry the value. These two parts together make
53  * a combined opcode.
54  */
55 #define __TC_ACT_EXT_SHIFT 28
56 #define __TC_ACT_EXT(local) ((local) << __TC_ACT_EXT_SHIFT)
57 #define TC_ACT_EXT_VAL_MASK ((1 << __TC_ACT_EXT_SHIFT) - 1)
58 #define TC_ACT_EXT_CMP(combined, opcode) \
59 	(((combined) & (~TC_ACT_EXT_VAL_MASK)) == opcode)
60 
61 #define TC_ACT_JUMP __TC_ACT_EXT(1)
62 #define TC_ACT_GOTO_CHAIN __TC_ACT_EXT(2)
63 
64 /* Action type identifiers*/
65 enum {
66 	TCA_ID_UNSPEC=0,
67 	TCA_ID_POLICE=1,
68 	/* other actions go here */
69 	__TCA_ID_MAX=255
70 };
71 
72 #define TCA_ID_MAX __TCA_ID_MAX
73 
74 struct tc_police {
75 	__u32			index;
76 	int			action;
77 #define TC_POLICE_UNSPEC	TC_ACT_UNSPEC
78 #define TC_POLICE_OK		TC_ACT_OK
79 #define TC_POLICE_RECLASSIFY	TC_ACT_RECLASSIFY
80 #define TC_POLICE_SHOT		TC_ACT_SHOT
81 #define TC_POLICE_PIPE		TC_ACT_PIPE
82 
83 	__u32			limit;
84 	__u32			burst;
85 	__u32			mtu;
86 	struct tc_ratespec	rate;
87 	struct tc_ratespec	peakrate;
88 	int			refcnt;
89 	int			bindcnt;
90 	__u32			capab;
91 };
92 
93 struct tcf_t {
94 	__u64   install;
95 	__u64   lastuse;
96 	__u64   expires;
97 	__u64   firstuse;
98 };
99 
100 struct tc_cnt {
101 	int                   refcnt;
102 	int                   bindcnt;
103 };
104 
105 #define tc_gen \
106 	__u32                 index; \
107 	__u32                 capab; \
108 	int                   action; \
109 	int                   refcnt; \
110 	int                   bindcnt
111 
112 enum {
113 	TCA_POLICE_UNSPEC,
114 	TCA_POLICE_TBF,
115 	TCA_POLICE_RATE,
116 	TCA_POLICE_PEAKRATE,
117 	TCA_POLICE_AVRATE,
118 	TCA_POLICE_RESULT,
119 	TCA_POLICE_TM,
120 	TCA_POLICE_PAD,
121 	__TCA_POLICE_MAX
122 #define TCA_POLICE_RESULT TCA_POLICE_RESULT
123 };
124 
125 #define TCA_POLICE_MAX (__TCA_POLICE_MAX - 1)
126 
127 /* tca flags definitions */
128 #define TCA_CLS_FLAGS_SKIP_HW	(1 << 0) /* don't offload filter to HW */
129 #define TCA_CLS_FLAGS_SKIP_SW	(1 << 1) /* don't use filter in SW */
130 #define TCA_CLS_FLAGS_IN_HW	(1 << 2) /* filter is offloaded to HW */
131 #define TCA_CLS_FLAGS_NOT_IN_HW (1 << 3) /* filter isn't offloaded to HW */
132 #define TCA_CLS_FLAGS_VERBOSE	(1 << 4) /* verbose logging */
133 
134 /* U32 filters */
135 
136 #define TC_U32_HTID(h) ((h)&0xFFF00000)
137 #define TC_U32_USERHTID(h) (TC_U32_HTID(h)>>20)
138 #define TC_U32_HASH(h) (((h)>>12)&0xFF)
139 #define TC_U32_NODE(h) ((h)&0xFFF)
140 #define TC_U32_KEY(h) ((h)&0xFFFFF)
141 #define TC_U32_UNSPEC	0
142 #define TC_U32_ROOT	(0xFFF00000)
143 
144 enum {
145 	TCA_U32_UNSPEC,
146 	TCA_U32_CLASSID,
147 	TCA_U32_HASH,
148 	TCA_U32_LINK,
149 	TCA_U32_DIVISOR,
150 	TCA_U32_SEL,
151 	TCA_U32_POLICE,
152 	TCA_U32_ACT,
153 	TCA_U32_INDEV,
154 	TCA_U32_PCNT,
155 	TCA_U32_MARK,
156 	TCA_U32_FLAGS,
157 	TCA_U32_PAD,
158 	__TCA_U32_MAX
159 };
160 
161 #define TCA_U32_MAX (__TCA_U32_MAX - 1)
162 
163 struct tc_u32_key {
164 	__be32		mask;
165 	__be32		val;
166 	int		off;
167 	int		offmask;
168 };
169 
170 struct tc_u32_sel {
171 	unsigned char		flags;
172 	unsigned char		offshift;
173 	unsigned char		nkeys;
174 
175 	__be16			offmask;
176 	__u16			off;
177 	short			offoff;
178 
179 	short			hoff;
180 	__be32			hmask;
181 	struct tc_u32_key	keys[0];
182 };
183 
184 struct tc_u32_mark {
185 	__u32		val;
186 	__u32		mask;
187 	__u32		success;
188 };
189 
190 struct tc_u32_pcnt {
191 	__u64 rcnt;
192 	__u64 rhit;
193 	__u64 kcnts[0];
194 };
195 
196 /* Flags */
197 
198 #define TC_U32_TERMINAL		1
199 #define TC_U32_OFFSET		2
200 #define TC_U32_VAROFFSET	4
201 #define TC_U32_EAT		8
202 
203 #define TC_U32_MAXDEPTH 8
204 
205 
206 /* RSVP filter */
207 
208 enum {
209 	TCA_RSVP_UNSPEC,
210 	TCA_RSVP_CLASSID,
211 	TCA_RSVP_DST,
212 	TCA_RSVP_SRC,
213 	TCA_RSVP_PINFO,
214 	TCA_RSVP_POLICE,
215 	TCA_RSVP_ACT,
216 	__TCA_RSVP_MAX
217 };
218 
219 #define TCA_RSVP_MAX (__TCA_RSVP_MAX - 1 )
220 
221 struct tc_rsvp_gpi {
222 	__u32	key;
223 	__u32	mask;
224 	int	offset;
225 };
226 
227 struct tc_rsvp_pinfo {
228 	struct tc_rsvp_gpi dpi;
229 	struct tc_rsvp_gpi spi;
230 	__u8	protocol;
231 	__u8	tunnelid;
232 	__u8	tunnelhdr;
233 	__u8	pad;
234 };
235 
236 /* ROUTE filter */
237 
238 enum {
239 	TCA_ROUTE4_UNSPEC,
240 	TCA_ROUTE4_CLASSID,
241 	TCA_ROUTE4_TO,
242 	TCA_ROUTE4_FROM,
243 	TCA_ROUTE4_IIF,
244 	TCA_ROUTE4_POLICE,
245 	TCA_ROUTE4_ACT,
246 	__TCA_ROUTE4_MAX
247 };
248 
249 #define TCA_ROUTE4_MAX (__TCA_ROUTE4_MAX - 1)
250 
251 
252 /* FW filter */
253 
254 enum {
255 	TCA_FW_UNSPEC,
256 	TCA_FW_CLASSID,
257 	TCA_FW_POLICE,
258 	TCA_FW_INDEV, /*  used by CONFIG_NET_CLS_IND */
259 	TCA_FW_ACT, /* used by CONFIG_NET_CLS_ACT */
260 	TCA_FW_MASK,
261 	__TCA_FW_MAX
262 };
263 
264 #define TCA_FW_MAX (__TCA_FW_MAX - 1)
265 
266 /* TC index filter */
267 
268 enum {
269 	TCA_TCINDEX_UNSPEC,
270 	TCA_TCINDEX_HASH,
271 	TCA_TCINDEX_MASK,
272 	TCA_TCINDEX_SHIFT,
273 	TCA_TCINDEX_FALL_THROUGH,
274 	TCA_TCINDEX_CLASSID,
275 	TCA_TCINDEX_POLICE,
276 	TCA_TCINDEX_ACT,
277 	__TCA_TCINDEX_MAX
278 };
279 
280 #define TCA_TCINDEX_MAX     (__TCA_TCINDEX_MAX - 1)
281 
282 /* Flow filter */
283 
284 enum {
285 	FLOW_KEY_SRC,
286 	FLOW_KEY_DST,
287 	FLOW_KEY_PROTO,
288 	FLOW_KEY_PROTO_SRC,
289 	FLOW_KEY_PROTO_DST,
290 	FLOW_KEY_IIF,
291 	FLOW_KEY_PRIORITY,
292 	FLOW_KEY_MARK,
293 	FLOW_KEY_NFCT,
294 	FLOW_KEY_NFCT_SRC,
295 	FLOW_KEY_NFCT_DST,
296 	FLOW_KEY_NFCT_PROTO_SRC,
297 	FLOW_KEY_NFCT_PROTO_DST,
298 	FLOW_KEY_RTCLASSID,
299 	FLOW_KEY_SKUID,
300 	FLOW_KEY_SKGID,
301 	FLOW_KEY_VLAN_TAG,
302 	FLOW_KEY_RXHASH,
303 	__FLOW_KEY_MAX,
304 };
305 
306 #define FLOW_KEY_MAX	(__FLOW_KEY_MAX - 1)
307 
308 enum {
309 	FLOW_MODE_MAP,
310 	FLOW_MODE_HASH,
311 };
312 
313 enum {
314 	TCA_FLOW_UNSPEC,
315 	TCA_FLOW_KEYS,
316 	TCA_FLOW_MODE,
317 	TCA_FLOW_BASECLASS,
318 	TCA_FLOW_RSHIFT,
319 	TCA_FLOW_ADDEND,
320 	TCA_FLOW_MASK,
321 	TCA_FLOW_XOR,
322 	TCA_FLOW_DIVISOR,
323 	TCA_FLOW_ACT,
324 	TCA_FLOW_POLICE,
325 	TCA_FLOW_EMATCHES,
326 	TCA_FLOW_PERTURB,
327 	__TCA_FLOW_MAX
328 };
329 
330 #define TCA_FLOW_MAX	(__TCA_FLOW_MAX - 1)
331 
332 /* Basic filter */
333 
334 enum {
335 	TCA_BASIC_UNSPEC,
336 	TCA_BASIC_CLASSID,
337 	TCA_BASIC_EMATCHES,
338 	TCA_BASIC_ACT,
339 	TCA_BASIC_POLICE,
340 	__TCA_BASIC_MAX
341 };
342 
343 #define TCA_BASIC_MAX (__TCA_BASIC_MAX - 1)
344 
345 
346 /* Cgroup classifier */
347 
348 enum {
349 	TCA_CGROUP_UNSPEC,
350 	TCA_CGROUP_ACT,
351 	TCA_CGROUP_POLICE,
352 	TCA_CGROUP_EMATCHES,
353 	__TCA_CGROUP_MAX,
354 };
355 
356 #define TCA_CGROUP_MAX (__TCA_CGROUP_MAX - 1)
357 
358 /* BPF classifier */
359 
360 #define TCA_BPF_FLAG_ACT_DIRECT		(1 << 0)
361 
362 enum {
363 	TCA_BPF_UNSPEC,
364 	TCA_BPF_ACT,
365 	TCA_BPF_POLICE,
366 	TCA_BPF_CLASSID,
367 	TCA_BPF_OPS_LEN,
368 	TCA_BPF_OPS,
369 	TCA_BPF_FD,
370 	TCA_BPF_NAME,
371 	TCA_BPF_FLAGS,
372 	TCA_BPF_FLAGS_GEN,
373 	TCA_BPF_TAG,
374 	TCA_BPF_ID,
375 	__TCA_BPF_MAX,
376 };
377 
378 #define TCA_BPF_MAX (__TCA_BPF_MAX - 1)
379 
380 /* Flower classifier */
381 
382 enum {
383 	TCA_FLOWER_UNSPEC,
384 	TCA_FLOWER_CLASSID,
385 	TCA_FLOWER_INDEV,
386 	TCA_FLOWER_ACT,
387 	TCA_FLOWER_KEY_ETH_DST,		/* ETH_ALEN */
388 	TCA_FLOWER_KEY_ETH_DST_MASK,	/* ETH_ALEN */
389 	TCA_FLOWER_KEY_ETH_SRC,		/* ETH_ALEN */
390 	TCA_FLOWER_KEY_ETH_SRC_MASK,	/* ETH_ALEN */
391 	TCA_FLOWER_KEY_ETH_TYPE,	/* be16 */
392 	TCA_FLOWER_KEY_IP_PROTO,	/* u8 */
393 	TCA_FLOWER_KEY_IPV4_SRC,	/* be32 */
394 	TCA_FLOWER_KEY_IPV4_SRC_MASK,	/* be32 */
395 	TCA_FLOWER_KEY_IPV4_DST,	/* be32 */
396 	TCA_FLOWER_KEY_IPV4_DST_MASK,	/* be32 */
397 	TCA_FLOWER_KEY_IPV6_SRC,	/* struct in6_addr */
398 	TCA_FLOWER_KEY_IPV6_SRC_MASK,	/* struct in6_addr */
399 	TCA_FLOWER_KEY_IPV6_DST,	/* struct in6_addr */
400 	TCA_FLOWER_KEY_IPV6_DST_MASK,	/* struct in6_addr */
401 	TCA_FLOWER_KEY_TCP_SRC,		/* be16 */
402 	TCA_FLOWER_KEY_TCP_DST,		/* be16 */
403 	TCA_FLOWER_KEY_UDP_SRC,		/* be16 */
404 	TCA_FLOWER_KEY_UDP_DST,		/* be16 */
405 
406 	TCA_FLOWER_FLAGS,
407 	TCA_FLOWER_KEY_VLAN_ID,		/* be16 */
408 	TCA_FLOWER_KEY_VLAN_PRIO,	/* u8   */
409 	TCA_FLOWER_KEY_VLAN_ETH_TYPE,	/* be16 */
410 
411 	TCA_FLOWER_KEY_ENC_KEY_ID,	/* be32 */
412 	TCA_FLOWER_KEY_ENC_IPV4_SRC,	/* be32 */
413 	TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK,/* be32 */
414 	TCA_FLOWER_KEY_ENC_IPV4_DST,	/* be32 */
415 	TCA_FLOWER_KEY_ENC_IPV4_DST_MASK,/* be32 */
416 	TCA_FLOWER_KEY_ENC_IPV6_SRC,	/* struct in6_addr */
417 	TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK,/* struct in6_addr */
418 	TCA_FLOWER_KEY_ENC_IPV6_DST,	/* struct in6_addr */
419 	TCA_FLOWER_KEY_ENC_IPV6_DST_MASK,/* struct in6_addr */
420 
421 	TCA_FLOWER_KEY_TCP_SRC_MASK,	/* be16 */
422 	TCA_FLOWER_KEY_TCP_DST_MASK,	/* be16 */
423 	TCA_FLOWER_KEY_UDP_SRC_MASK,	/* be16 */
424 	TCA_FLOWER_KEY_UDP_DST_MASK,	/* be16 */
425 	TCA_FLOWER_KEY_SCTP_SRC_MASK,	/* be16 */
426 	TCA_FLOWER_KEY_SCTP_DST_MASK,	/* be16 */
427 
428 	TCA_FLOWER_KEY_SCTP_SRC,	/* be16 */
429 	TCA_FLOWER_KEY_SCTP_DST,	/* be16 */
430 
431 	TCA_FLOWER_KEY_ENC_UDP_SRC_PORT,	/* be16 */
432 	TCA_FLOWER_KEY_ENC_UDP_SRC_PORT_MASK,	/* be16 */
433 	TCA_FLOWER_KEY_ENC_UDP_DST_PORT,	/* be16 */
434 	TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK,	/* be16 */
435 
436 	TCA_FLOWER_KEY_FLAGS,		/* be32 */
437 	TCA_FLOWER_KEY_FLAGS_MASK,	/* be32 */
438 
439 	TCA_FLOWER_KEY_ICMPV4_CODE,	/* u8 */
440 	TCA_FLOWER_KEY_ICMPV4_CODE_MASK,/* u8 */
441 	TCA_FLOWER_KEY_ICMPV4_TYPE,	/* u8 */
442 	TCA_FLOWER_KEY_ICMPV4_TYPE_MASK,/* u8 */
443 	TCA_FLOWER_KEY_ICMPV6_CODE,	/* u8 */
444 	TCA_FLOWER_KEY_ICMPV6_CODE_MASK,/* u8 */
445 	TCA_FLOWER_KEY_ICMPV6_TYPE,	/* u8 */
446 	TCA_FLOWER_KEY_ICMPV6_TYPE_MASK,/* u8 */
447 
448 	TCA_FLOWER_KEY_ARP_SIP,		/* be32 */
449 	TCA_FLOWER_KEY_ARP_SIP_MASK,	/* be32 */
450 	TCA_FLOWER_KEY_ARP_TIP,		/* be32 */
451 	TCA_FLOWER_KEY_ARP_TIP_MASK,	/* be32 */
452 	TCA_FLOWER_KEY_ARP_OP,		/* u8 */
453 	TCA_FLOWER_KEY_ARP_OP_MASK,	/* u8 */
454 	TCA_FLOWER_KEY_ARP_SHA,		/* ETH_ALEN */
455 	TCA_FLOWER_KEY_ARP_SHA_MASK,	/* ETH_ALEN */
456 	TCA_FLOWER_KEY_ARP_THA,		/* ETH_ALEN */
457 	TCA_FLOWER_KEY_ARP_THA_MASK,	/* ETH_ALEN */
458 
459 	TCA_FLOWER_KEY_MPLS_TTL,	/* u8 - 8 bits */
460 	TCA_FLOWER_KEY_MPLS_BOS,	/* u8 - 1 bit */
461 	TCA_FLOWER_KEY_MPLS_TC,		/* u8 - 3 bits */
462 	TCA_FLOWER_KEY_MPLS_LABEL,	/* be32 - 20 bits */
463 
464 	TCA_FLOWER_KEY_TCP_FLAGS,	/* be16 */
465 	TCA_FLOWER_KEY_TCP_FLAGS_MASK,	/* be16 */
466 
467 	TCA_FLOWER_KEY_IP_TOS,		/* u8 */
468 	TCA_FLOWER_KEY_IP_TOS_MASK,	/* u8 */
469 	TCA_FLOWER_KEY_IP_TTL,		/* u8 */
470 	TCA_FLOWER_KEY_IP_TTL_MASK,	/* u8 */
471 
472 	__TCA_FLOWER_MAX,
473 };
474 
475 #define TCA_FLOWER_MAX (__TCA_FLOWER_MAX - 1)
476 
477 enum {
478 	TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT = (1 << 0),
479 	TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST = (1 << 1),
480 };
481 
482 /* Match-all classifier */
483 
484 enum {
485 	TCA_MATCHALL_UNSPEC,
486 	TCA_MATCHALL_CLASSID,
487 	TCA_MATCHALL_ACT,
488 	TCA_MATCHALL_FLAGS,
489 	__TCA_MATCHALL_MAX,
490 };
491 
492 #define TCA_MATCHALL_MAX (__TCA_MATCHALL_MAX - 1)
493 
494 /* Extended Matches */
495 
496 struct tcf_ematch_tree_hdr {
497 	__u16		nmatches;
498 	__u16		progid;
499 };
500 
501 enum {
502 	TCA_EMATCH_TREE_UNSPEC,
503 	TCA_EMATCH_TREE_HDR,
504 	TCA_EMATCH_TREE_LIST,
505 	__TCA_EMATCH_TREE_MAX
506 };
507 #define TCA_EMATCH_TREE_MAX (__TCA_EMATCH_TREE_MAX - 1)
508 
509 struct tcf_ematch_hdr {
510 	__u16		matchid;
511 	__u16		kind;
512 	__u16		flags;
513 	__u16		pad; /* currently unused */
514 };
515 
516 /*  0                   1
517  *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
518  * +-----------------------+-+-+---+
519  * |         Unused        |S|I| R |
520  * +-----------------------+-+-+---+
521  *
522  * R(2) ::= relation to next ematch
523  *          where: 0 0 END (last ematch)
524  *                 0 1 AND
525  *                 1 0 OR
526  *                 1 1 Unused (invalid)
527  * I(1) ::= invert result
528  * S(1) ::= simple payload
529  */
530 #define TCF_EM_REL_END	0
531 #define TCF_EM_REL_AND	(1<<0)
532 #define TCF_EM_REL_OR	(1<<1)
533 #define TCF_EM_INVERT	(1<<2)
534 #define TCF_EM_SIMPLE	(1<<3)
535 
536 #define TCF_EM_REL_MASK	3
537 #define TCF_EM_REL_VALID(v) (((v) & TCF_EM_REL_MASK) != TCF_EM_REL_MASK)
538 
539 enum {
540 	TCF_LAYER_LINK,
541 	TCF_LAYER_NETWORK,
542 	TCF_LAYER_TRANSPORT,
543 	__TCF_LAYER_MAX
544 };
545 #define TCF_LAYER_MAX (__TCF_LAYER_MAX - 1)
546 
547 /* Ematch type assignments
548  *   1..32767		Reserved for ematches inside kernel tree
549  *   32768..65535	Free to use, not reliable
550  */
551 #define	TCF_EM_CONTAINER	0
552 #define	TCF_EM_CMP		1
553 #define	TCF_EM_NBYTE		2
554 #define	TCF_EM_U32		3
555 #define	TCF_EM_META		4
556 #define	TCF_EM_TEXT		5
557 #define	TCF_EM_VLAN		6
558 #define	TCF_EM_CANID		7
559 #define	TCF_EM_IPSET		8
560 #define	TCF_EM_IPT		9
561 #define	TCF_EM_MAX		9
562 
563 enum {
564 	TCF_EM_PROG_TC
565 };
566 
567 enum {
568 	TCF_EM_OPND_EQ,
569 	TCF_EM_OPND_GT,
570 	TCF_EM_OPND_LT
571 };
572 
573 #endif
574