xref: /openbmc/linux/include/uapi/linux/pkt_cls.h (revision a72594ca)
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 
133 /* U32 filters */
134 
135 #define TC_U32_HTID(h) ((h)&0xFFF00000)
136 #define TC_U32_USERHTID(h) (TC_U32_HTID(h)>>20)
137 #define TC_U32_HASH(h) (((h)>>12)&0xFF)
138 #define TC_U32_NODE(h) ((h)&0xFFF)
139 #define TC_U32_KEY(h) ((h)&0xFFFFF)
140 #define TC_U32_UNSPEC	0
141 #define TC_U32_ROOT	(0xFFF00000)
142 
143 enum {
144 	TCA_U32_UNSPEC,
145 	TCA_U32_CLASSID,
146 	TCA_U32_HASH,
147 	TCA_U32_LINK,
148 	TCA_U32_DIVISOR,
149 	TCA_U32_SEL,
150 	TCA_U32_POLICE,
151 	TCA_U32_ACT,
152 	TCA_U32_INDEV,
153 	TCA_U32_PCNT,
154 	TCA_U32_MARK,
155 	TCA_U32_FLAGS,
156 	TCA_U32_PAD,
157 	__TCA_U32_MAX
158 };
159 
160 #define TCA_U32_MAX (__TCA_U32_MAX - 1)
161 
162 struct tc_u32_key {
163 	__be32		mask;
164 	__be32		val;
165 	int		off;
166 	int		offmask;
167 };
168 
169 struct tc_u32_sel {
170 	unsigned char		flags;
171 	unsigned char		offshift;
172 	unsigned char		nkeys;
173 
174 	__be16			offmask;
175 	__u16			off;
176 	short			offoff;
177 
178 	short			hoff;
179 	__be32			hmask;
180 	struct tc_u32_key	keys[0];
181 };
182 
183 struct tc_u32_mark {
184 	__u32		val;
185 	__u32		mask;
186 	__u32		success;
187 };
188 
189 struct tc_u32_pcnt {
190 	__u64 rcnt;
191 	__u64 rhit;
192 	__u64 kcnts[0];
193 };
194 
195 /* Flags */
196 
197 #define TC_U32_TERMINAL		1
198 #define TC_U32_OFFSET		2
199 #define TC_U32_VAROFFSET	4
200 #define TC_U32_EAT		8
201 
202 #define TC_U32_MAXDEPTH 8
203 
204 
205 /* RSVP filter */
206 
207 enum {
208 	TCA_RSVP_UNSPEC,
209 	TCA_RSVP_CLASSID,
210 	TCA_RSVP_DST,
211 	TCA_RSVP_SRC,
212 	TCA_RSVP_PINFO,
213 	TCA_RSVP_POLICE,
214 	TCA_RSVP_ACT,
215 	__TCA_RSVP_MAX
216 };
217 
218 #define TCA_RSVP_MAX (__TCA_RSVP_MAX - 1 )
219 
220 struct tc_rsvp_gpi {
221 	__u32	key;
222 	__u32	mask;
223 	int	offset;
224 };
225 
226 struct tc_rsvp_pinfo {
227 	struct tc_rsvp_gpi dpi;
228 	struct tc_rsvp_gpi spi;
229 	__u8	protocol;
230 	__u8	tunnelid;
231 	__u8	tunnelhdr;
232 	__u8	pad;
233 };
234 
235 /* ROUTE filter */
236 
237 enum {
238 	TCA_ROUTE4_UNSPEC,
239 	TCA_ROUTE4_CLASSID,
240 	TCA_ROUTE4_TO,
241 	TCA_ROUTE4_FROM,
242 	TCA_ROUTE4_IIF,
243 	TCA_ROUTE4_POLICE,
244 	TCA_ROUTE4_ACT,
245 	__TCA_ROUTE4_MAX
246 };
247 
248 #define TCA_ROUTE4_MAX (__TCA_ROUTE4_MAX - 1)
249 
250 
251 /* FW filter */
252 
253 enum {
254 	TCA_FW_UNSPEC,
255 	TCA_FW_CLASSID,
256 	TCA_FW_POLICE,
257 	TCA_FW_INDEV, /*  used by CONFIG_NET_CLS_IND */
258 	TCA_FW_ACT, /* used by CONFIG_NET_CLS_ACT */
259 	TCA_FW_MASK,
260 	__TCA_FW_MAX
261 };
262 
263 #define TCA_FW_MAX (__TCA_FW_MAX - 1)
264 
265 /* TC index filter */
266 
267 enum {
268 	TCA_TCINDEX_UNSPEC,
269 	TCA_TCINDEX_HASH,
270 	TCA_TCINDEX_MASK,
271 	TCA_TCINDEX_SHIFT,
272 	TCA_TCINDEX_FALL_THROUGH,
273 	TCA_TCINDEX_CLASSID,
274 	TCA_TCINDEX_POLICE,
275 	TCA_TCINDEX_ACT,
276 	__TCA_TCINDEX_MAX
277 };
278 
279 #define TCA_TCINDEX_MAX     (__TCA_TCINDEX_MAX - 1)
280 
281 /* Flow filter */
282 
283 enum {
284 	FLOW_KEY_SRC,
285 	FLOW_KEY_DST,
286 	FLOW_KEY_PROTO,
287 	FLOW_KEY_PROTO_SRC,
288 	FLOW_KEY_PROTO_DST,
289 	FLOW_KEY_IIF,
290 	FLOW_KEY_PRIORITY,
291 	FLOW_KEY_MARK,
292 	FLOW_KEY_NFCT,
293 	FLOW_KEY_NFCT_SRC,
294 	FLOW_KEY_NFCT_DST,
295 	FLOW_KEY_NFCT_PROTO_SRC,
296 	FLOW_KEY_NFCT_PROTO_DST,
297 	FLOW_KEY_RTCLASSID,
298 	FLOW_KEY_SKUID,
299 	FLOW_KEY_SKGID,
300 	FLOW_KEY_VLAN_TAG,
301 	FLOW_KEY_RXHASH,
302 	__FLOW_KEY_MAX,
303 };
304 
305 #define FLOW_KEY_MAX	(__FLOW_KEY_MAX - 1)
306 
307 enum {
308 	FLOW_MODE_MAP,
309 	FLOW_MODE_HASH,
310 };
311 
312 enum {
313 	TCA_FLOW_UNSPEC,
314 	TCA_FLOW_KEYS,
315 	TCA_FLOW_MODE,
316 	TCA_FLOW_BASECLASS,
317 	TCA_FLOW_RSHIFT,
318 	TCA_FLOW_ADDEND,
319 	TCA_FLOW_MASK,
320 	TCA_FLOW_XOR,
321 	TCA_FLOW_DIVISOR,
322 	TCA_FLOW_ACT,
323 	TCA_FLOW_POLICE,
324 	TCA_FLOW_EMATCHES,
325 	TCA_FLOW_PERTURB,
326 	__TCA_FLOW_MAX
327 };
328 
329 #define TCA_FLOW_MAX	(__TCA_FLOW_MAX - 1)
330 
331 /* Basic filter */
332 
333 enum {
334 	TCA_BASIC_UNSPEC,
335 	TCA_BASIC_CLASSID,
336 	TCA_BASIC_EMATCHES,
337 	TCA_BASIC_ACT,
338 	TCA_BASIC_POLICE,
339 	__TCA_BASIC_MAX
340 };
341 
342 #define TCA_BASIC_MAX (__TCA_BASIC_MAX - 1)
343 
344 
345 /* Cgroup classifier */
346 
347 enum {
348 	TCA_CGROUP_UNSPEC,
349 	TCA_CGROUP_ACT,
350 	TCA_CGROUP_POLICE,
351 	TCA_CGROUP_EMATCHES,
352 	__TCA_CGROUP_MAX,
353 };
354 
355 #define TCA_CGROUP_MAX (__TCA_CGROUP_MAX - 1)
356 
357 /* BPF classifier */
358 
359 #define TCA_BPF_FLAG_ACT_DIRECT		(1 << 0)
360 
361 enum {
362 	TCA_BPF_UNSPEC,
363 	TCA_BPF_ACT,
364 	TCA_BPF_POLICE,
365 	TCA_BPF_CLASSID,
366 	TCA_BPF_OPS_LEN,
367 	TCA_BPF_OPS,
368 	TCA_BPF_FD,
369 	TCA_BPF_NAME,
370 	TCA_BPF_FLAGS,
371 	TCA_BPF_FLAGS_GEN,
372 	TCA_BPF_TAG,
373 	TCA_BPF_ID,
374 	__TCA_BPF_MAX,
375 };
376 
377 #define TCA_BPF_MAX (__TCA_BPF_MAX - 1)
378 
379 /* Flower classifier */
380 
381 enum {
382 	TCA_FLOWER_UNSPEC,
383 	TCA_FLOWER_CLASSID,
384 	TCA_FLOWER_INDEV,
385 	TCA_FLOWER_ACT,
386 	TCA_FLOWER_KEY_ETH_DST,		/* ETH_ALEN */
387 	TCA_FLOWER_KEY_ETH_DST_MASK,	/* ETH_ALEN */
388 	TCA_FLOWER_KEY_ETH_SRC,		/* ETH_ALEN */
389 	TCA_FLOWER_KEY_ETH_SRC_MASK,	/* ETH_ALEN */
390 	TCA_FLOWER_KEY_ETH_TYPE,	/* be16 */
391 	TCA_FLOWER_KEY_IP_PROTO,	/* u8 */
392 	TCA_FLOWER_KEY_IPV4_SRC,	/* be32 */
393 	TCA_FLOWER_KEY_IPV4_SRC_MASK,	/* be32 */
394 	TCA_FLOWER_KEY_IPV4_DST,	/* be32 */
395 	TCA_FLOWER_KEY_IPV4_DST_MASK,	/* be32 */
396 	TCA_FLOWER_KEY_IPV6_SRC,	/* struct in6_addr */
397 	TCA_FLOWER_KEY_IPV6_SRC_MASK,	/* struct in6_addr */
398 	TCA_FLOWER_KEY_IPV6_DST,	/* struct in6_addr */
399 	TCA_FLOWER_KEY_IPV6_DST_MASK,	/* struct in6_addr */
400 	TCA_FLOWER_KEY_TCP_SRC,		/* be16 */
401 	TCA_FLOWER_KEY_TCP_DST,		/* be16 */
402 	TCA_FLOWER_KEY_UDP_SRC,		/* be16 */
403 	TCA_FLOWER_KEY_UDP_DST,		/* be16 */
404 
405 	TCA_FLOWER_FLAGS,
406 	TCA_FLOWER_KEY_VLAN_ID,		/* be16 */
407 	TCA_FLOWER_KEY_VLAN_PRIO,	/* u8   */
408 	TCA_FLOWER_KEY_VLAN_ETH_TYPE,	/* be16 */
409 
410 	TCA_FLOWER_KEY_ENC_KEY_ID,	/* be32 */
411 	TCA_FLOWER_KEY_ENC_IPV4_SRC,	/* be32 */
412 	TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK,/* be32 */
413 	TCA_FLOWER_KEY_ENC_IPV4_DST,	/* be32 */
414 	TCA_FLOWER_KEY_ENC_IPV4_DST_MASK,/* be32 */
415 	TCA_FLOWER_KEY_ENC_IPV6_SRC,	/* struct in6_addr */
416 	TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK,/* struct in6_addr */
417 	TCA_FLOWER_KEY_ENC_IPV6_DST,	/* struct in6_addr */
418 	TCA_FLOWER_KEY_ENC_IPV6_DST_MASK,/* struct in6_addr */
419 
420 	TCA_FLOWER_KEY_TCP_SRC_MASK,	/* be16 */
421 	TCA_FLOWER_KEY_TCP_DST_MASK,	/* be16 */
422 	TCA_FLOWER_KEY_UDP_SRC_MASK,	/* be16 */
423 	TCA_FLOWER_KEY_UDP_DST_MASK,	/* be16 */
424 	TCA_FLOWER_KEY_SCTP_SRC_MASK,	/* be16 */
425 	TCA_FLOWER_KEY_SCTP_DST_MASK,	/* be16 */
426 
427 	TCA_FLOWER_KEY_SCTP_SRC,	/* be16 */
428 	TCA_FLOWER_KEY_SCTP_DST,	/* be16 */
429 
430 	TCA_FLOWER_KEY_ENC_UDP_SRC_PORT,	/* be16 */
431 	TCA_FLOWER_KEY_ENC_UDP_SRC_PORT_MASK,	/* be16 */
432 	TCA_FLOWER_KEY_ENC_UDP_DST_PORT,	/* be16 */
433 	TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK,	/* be16 */
434 
435 	TCA_FLOWER_KEY_FLAGS,		/* be32 */
436 	TCA_FLOWER_KEY_FLAGS_MASK,	/* be32 */
437 
438 	TCA_FLOWER_KEY_ICMPV4_CODE,	/* u8 */
439 	TCA_FLOWER_KEY_ICMPV4_CODE_MASK,/* u8 */
440 	TCA_FLOWER_KEY_ICMPV4_TYPE,	/* u8 */
441 	TCA_FLOWER_KEY_ICMPV4_TYPE_MASK,/* u8 */
442 	TCA_FLOWER_KEY_ICMPV6_CODE,	/* u8 */
443 	TCA_FLOWER_KEY_ICMPV6_CODE_MASK,/* u8 */
444 	TCA_FLOWER_KEY_ICMPV6_TYPE,	/* u8 */
445 	TCA_FLOWER_KEY_ICMPV6_TYPE_MASK,/* u8 */
446 
447 	TCA_FLOWER_KEY_ARP_SIP,		/* be32 */
448 	TCA_FLOWER_KEY_ARP_SIP_MASK,	/* be32 */
449 	TCA_FLOWER_KEY_ARP_TIP,		/* be32 */
450 	TCA_FLOWER_KEY_ARP_TIP_MASK,	/* be32 */
451 	TCA_FLOWER_KEY_ARP_OP,		/* u8 */
452 	TCA_FLOWER_KEY_ARP_OP_MASK,	/* u8 */
453 	TCA_FLOWER_KEY_ARP_SHA,		/* ETH_ALEN */
454 	TCA_FLOWER_KEY_ARP_SHA_MASK,	/* ETH_ALEN */
455 	TCA_FLOWER_KEY_ARP_THA,		/* ETH_ALEN */
456 	TCA_FLOWER_KEY_ARP_THA_MASK,	/* ETH_ALEN */
457 
458 	TCA_FLOWER_KEY_MPLS_TTL,	/* u8 - 8 bits */
459 	TCA_FLOWER_KEY_MPLS_BOS,	/* u8 - 1 bit */
460 	TCA_FLOWER_KEY_MPLS_TC,		/* u8 - 3 bits */
461 	TCA_FLOWER_KEY_MPLS_LABEL,	/* be32 - 20 bits */
462 
463 	TCA_FLOWER_KEY_TCP_FLAGS,	/* be16 */
464 	TCA_FLOWER_KEY_TCP_FLAGS_MASK,	/* be16 */
465 
466 	TCA_FLOWER_KEY_IP_TOS,		/* u8 */
467 	TCA_FLOWER_KEY_IP_TOS_MASK,	/* u8 */
468 	TCA_FLOWER_KEY_IP_TTL,		/* u8 */
469 	TCA_FLOWER_KEY_IP_TTL_MASK,	/* u8 */
470 
471 	__TCA_FLOWER_MAX,
472 };
473 
474 #define TCA_FLOWER_MAX (__TCA_FLOWER_MAX - 1)
475 
476 enum {
477 	TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT = (1 << 0),
478 };
479 
480 /* Match-all classifier */
481 
482 enum {
483 	TCA_MATCHALL_UNSPEC,
484 	TCA_MATCHALL_CLASSID,
485 	TCA_MATCHALL_ACT,
486 	TCA_MATCHALL_FLAGS,
487 	__TCA_MATCHALL_MAX,
488 };
489 
490 #define TCA_MATCHALL_MAX (__TCA_MATCHALL_MAX - 1)
491 
492 /* Extended Matches */
493 
494 struct tcf_ematch_tree_hdr {
495 	__u16		nmatches;
496 	__u16		progid;
497 };
498 
499 enum {
500 	TCA_EMATCH_TREE_UNSPEC,
501 	TCA_EMATCH_TREE_HDR,
502 	TCA_EMATCH_TREE_LIST,
503 	__TCA_EMATCH_TREE_MAX
504 };
505 #define TCA_EMATCH_TREE_MAX (__TCA_EMATCH_TREE_MAX - 1)
506 
507 struct tcf_ematch_hdr {
508 	__u16		matchid;
509 	__u16		kind;
510 	__u16		flags;
511 	__u16		pad; /* currently unused */
512 };
513 
514 /*  0                   1
515  *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
516  * +-----------------------+-+-+---+
517  * |         Unused        |S|I| R |
518  * +-----------------------+-+-+---+
519  *
520  * R(2) ::= relation to next ematch
521  *          where: 0 0 END (last ematch)
522  *                 0 1 AND
523  *                 1 0 OR
524  *                 1 1 Unused (invalid)
525  * I(1) ::= invert result
526  * S(1) ::= simple payload
527  */
528 #define TCF_EM_REL_END	0
529 #define TCF_EM_REL_AND	(1<<0)
530 #define TCF_EM_REL_OR	(1<<1)
531 #define TCF_EM_INVERT	(1<<2)
532 #define TCF_EM_SIMPLE	(1<<3)
533 
534 #define TCF_EM_REL_MASK	3
535 #define TCF_EM_REL_VALID(v) (((v) & TCF_EM_REL_MASK) != TCF_EM_REL_MASK)
536 
537 enum {
538 	TCF_LAYER_LINK,
539 	TCF_LAYER_NETWORK,
540 	TCF_LAYER_TRANSPORT,
541 	__TCF_LAYER_MAX
542 };
543 #define TCF_LAYER_MAX (__TCF_LAYER_MAX - 1)
544 
545 /* Ematch type assignments
546  *   1..32767		Reserved for ematches inside kernel tree
547  *   32768..65535	Free to use, not reliable
548  */
549 #define	TCF_EM_CONTAINER	0
550 #define	TCF_EM_CMP		1
551 #define	TCF_EM_NBYTE		2
552 #define	TCF_EM_U32		3
553 #define	TCF_EM_META		4
554 #define	TCF_EM_TEXT		5
555 #define	TCF_EM_VLAN		6
556 #define	TCF_EM_CANID		7
557 #define	TCF_EM_IPSET		8
558 #define	TCF_EM_MAX		8
559 
560 enum {
561 	TCF_EM_PROG_TC
562 };
563 
564 enum {
565 	TCF_EM_OPND_EQ,
566 	TCF_EM_OPND_GT,
567 	TCF_EM_OPND_LT
568 };
569 
570 #endif
571