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