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