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 
8 /* Action attributes */
9 enum {
10 	TCA_ACT_UNSPEC,
11 	TCA_ACT_KIND,
12 	TCA_ACT_OPTIONS,
13 	TCA_ACT_INDEX,
14 	TCA_ACT_STATS,
15 	__TCA_ACT_MAX
16 };
17 
18 #define TCA_ACT_MAX __TCA_ACT_MAX
19 #define TCA_OLD_COMPAT (TCA_ACT_MAX+1)
20 #define TCA_ACT_MAX_PRIO 32
21 #define TCA_ACT_BIND	1
22 #define TCA_ACT_NOBIND	0
23 #define TCA_ACT_UNBIND	1
24 #define TCA_ACT_NOUNBIND	0
25 #define TCA_ACT_REPLACE		1
26 #define TCA_ACT_NOREPLACE	0
27 
28 #define TC_ACT_UNSPEC	(-1)
29 #define TC_ACT_OK		0
30 #define TC_ACT_RECLASSIFY	1
31 #define TC_ACT_SHOT		2
32 #define TC_ACT_PIPE		3
33 #define TC_ACT_STOLEN		4
34 #define TC_ACT_QUEUED		5
35 #define TC_ACT_REPEAT		6
36 #define TC_ACT_REDIRECT		7
37 #define TC_ACT_JUMP		0x10000000
38 
39 /* Action type identifiers*/
40 enum {
41 	TCA_ID_UNSPEC=0,
42 	TCA_ID_POLICE=1,
43 	/* other actions go here */
44 	__TCA_ID_MAX=255
45 };
46 
47 #define TCA_ID_MAX __TCA_ID_MAX
48 
49 struct tc_police {
50 	__u32			index;
51 	int			action;
52 #define TC_POLICE_UNSPEC	TC_ACT_UNSPEC
53 #define TC_POLICE_OK		TC_ACT_OK
54 #define TC_POLICE_RECLASSIFY	TC_ACT_RECLASSIFY
55 #define TC_POLICE_SHOT		TC_ACT_SHOT
56 #define TC_POLICE_PIPE		TC_ACT_PIPE
57 
58 	__u32			limit;
59 	__u32			burst;
60 	__u32			mtu;
61 	struct tc_ratespec	rate;
62 	struct tc_ratespec	peakrate;
63 	int 			refcnt;
64 	int 			bindcnt;
65 	__u32			capab;
66 };
67 
68 struct tcf_t {
69 	__u64   install;
70 	__u64   lastuse;
71 	__u64   expires;
72 };
73 
74 struct tc_cnt {
75 	int                   refcnt;
76 	int                   bindcnt;
77 };
78 
79 #define tc_gen \
80 	__u32                 index; \
81 	__u32                 capab; \
82 	int                   action; \
83 	int                   refcnt; \
84 	int                   bindcnt
85 
86 enum {
87 	TCA_POLICE_UNSPEC,
88 	TCA_POLICE_TBF,
89 	TCA_POLICE_RATE,
90 	TCA_POLICE_PEAKRATE,
91 	TCA_POLICE_AVRATE,
92 	TCA_POLICE_RESULT,
93 	__TCA_POLICE_MAX
94 #define TCA_POLICE_RESULT TCA_POLICE_RESULT
95 };
96 
97 #define TCA_POLICE_MAX (__TCA_POLICE_MAX - 1)
98 
99 /* U32 filters */
100 
101 #define TC_U32_HTID(h) ((h)&0xFFF00000)
102 #define TC_U32_USERHTID(h) (TC_U32_HTID(h)>>20)
103 #define TC_U32_HASH(h) (((h)>>12)&0xFF)
104 #define TC_U32_NODE(h) ((h)&0xFFF)
105 #define TC_U32_KEY(h) ((h)&0xFFFFF)
106 #define TC_U32_UNSPEC	0
107 #define TC_U32_ROOT	(0xFFF00000)
108 
109 enum {
110 	TCA_U32_UNSPEC,
111 	TCA_U32_CLASSID,
112 	TCA_U32_HASH,
113 	TCA_U32_LINK,
114 	TCA_U32_DIVISOR,
115 	TCA_U32_SEL,
116 	TCA_U32_POLICE,
117 	TCA_U32_ACT,
118 	TCA_U32_INDEV,
119 	TCA_U32_PCNT,
120 	TCA_U32_MARK,
121 	__TCA_U32_MAX
122 };
123 
124 #define TCA_U32_MAX (__TCA_U32_MAX - 1)
125 
126 struct tc_u32_key {
127 	__be32		mask;
128 	__be32		val;
129 	int		off;
130 	int		offmask;
131 };
132 
133 struct tc_u32_sel {
134 	unsigned char		flags;
135 	unsigned char		offshift;
136 	unsigned char		nkeys;
137 
138 	__be16			offmask;
139 	__u16			off;
140 	short			offoff;
141 
142 	short			hoff;
143 	__be32			hmask;
144 	struct tc_u32_key	keys[0];
145 };
146 
147 struct tc_u32_mark {
148 	__u32		val;
149 	__u32		mask;
150 	__u32		success;
151 };
152 
153 struct tc_u32_pcnt {
154 	__u64 rcnt;
155 	__u64 rhit;
156 	__u64 kcnts[0];
157 };
158 
159 /* Flags */
160 
161 #define TC_U32_TERMINAL		1
162 #define TC_U32_OFFSET		2
163 #define TC_U32_VAROFFSET	4
164 #define TC_U32_EAT		8
165 
166 #define TC_U32_MAXDEPTH 8
167 
168 
169 /* RSVP filter */
170 
171 enum {
172 	TCA_RSVP_UNSPEC,
173 	TCA_RSVP_CLASSID,
174 	TCA_RSVP_DST,
175 	TCA_RSVP_SRC,
176 	TCA_RSVP_PINFO,
177 	TCA_RSVP_POLICE,
178 	TCA_RSVP_ACT,
179 	__TCA_RSVP_MAX
180 };
181 
182 #define TCA_RSVP_MAX (__TCA_RSVP_MAX - 1 )
183 
184 struct tc_rsvp_gpi {
185 	__u32	key;
186 	__u32	mask;
187 	int	offset;
188 };
189 
190 struct tc_rsvp_pinfo {
191 	struct tc_rsvp_gpi dpi;
192 	struct tc_rsvp_gpi spi;
193 	__u8	protocol;
194 	__u8	tunnelid;
195 	__u8	tunnelhdr;
196 	__u8	pad;
197 };
198 
199 /* ROUTE filter */
200 
201 enum {
202 	TCA_ROUTE4_UNSPEC,
203 	TCA_ROUTE4_CLASSID,
204 	TCA_ROUTE4_TO,
205 	TCA_ROUTE4_FROM,
206 	TCA_ROUTE4_IIF,
207 	TCA_ROUTE4_POLICE,
208 	TCA_ROUTE4_ACT,
209 	__TCA_ROUTE4_MAX
210 };
211 
212 #define TCA_ROUTE4_MAX (__TCA_ROUTE4_MAX - 1)
213 
214 
215 /* FW filter */
216 
217 enum {
218 	TCA_FW_UNSPEC,
219 	TCA_FW_CLASSID,
220 	TCA_FW_POLICE,
221 	TCA_FW_INDEV, /*  used by CONFIG_NET_CLS_IND */
222 	TCA_FW_ACT, /* used by CONFIG_NET_CLS_ACT */
223 	TCA_FW_MASK,
224 	__TCA_FW_MAX
225 };
226 
227 #define TCA_FW_MAX (__TCA_FW_MAX - 1)
228 
229 /* TC index filter */
230 
231 enum {
232 	TCA_TCINDEX_UNSPEC,
233 	TCA_TCINDEX_HASH,
234 	TCA_TCINDEX_MASK,
235 	TCA_TCINDEX_SHIFT,
236 	TCA_TCINDEX_FALL_THROUGH,
237 	TCA_TCINDEX_CLASSID,
238 	TCA_TCINDEX_POLICE,
239 	TCA_TCINDEX_ACT,
240 	__TCA_TCINDEX_MAX
241 };
242 
243 #define TCA_TCINDEX_MAX     (__TCA_TCINDEX_MAX - 1)
244 
245 /* Flow filter */
246 
247 enum {
248 	FLOW_KEY_SRC,
249 	FLOW_KEY_DST,
250 	FLOW_KEY_PROTO,
251 	FLOW_KEY_PROTO_SRC,
252 	FLOW_KEY_PROTO_DST,
253 	FLOW_KEY_IIF,
254 	FLOW_KEY_PRIORITY,
255 	FLOW_KEY_MARK,
256 	FLOW_KEY_NFCT,
257 	FLOW_KEY_NFCT_SRC,
258 	FLOW_KEY_NFCT_DST,
259 	FLOW_KEY_NFCT_PROTO_SRC,
260 	FLOW_KEY_NFCT_PROTO_DST,
261 	FLOW_KEY_RTCLASSID,
262 	FLOW_KEY_SKUID,
263 	FLOW_KEY_SKGID,
264 	FLOW_KEY_VLAN_TAG,
265 	FLOW_KEY_RXHASH,
266 	__FLOW_KEY_MAX,
267 };
268 
269 #define FLOW_KEY_MAX	(__FLOW_KEY_MAX - 1)
270 
271 enum {
272 	FLOW_MODE_MAP,
273 	FLOW_MODE_HASH,
274 };
275 
276 enum {
277 	TCA_FLOW_UNSPEC,
278 	TCA_FLOW_KEYS,
279 	TCA_FLOW_MODE,
280 	TCA_FLOW_BASECLASS,
281 	TCA_FLOW_RSHIFT,
282 	TCA_FLOW_ADDEND,
283 	TCA_FLOW_MASK,
284 	TCA_FLOW_XOR,
285 	TCA_FLOW_DIVISOR,
286 	TCA_FLOW_ACT,
287 	TCA_FLOW_POLICE,
288 	TCA_FLOW_EMATCHES,
289 	TCA_FLOW_PERTURB,
290 	__TCA_FLOW_MAX
291 };
292 
293 #define TCA_FLOW_MAX	(__TCA_FLOW_MAX - 1)
294 
295 /* Basic filter */
296 
297 enum {
298 	TCA_BASIC_UNSPEC,
299 	TCA_BASIC_CLASSID,
300 	TCA_BASIC_EMATCHES,
301 	TCA_BASIC_ACT,
302 	TCA_BASIC_POLICE,
303 	__TCA_BASIC_MAX
304 };
305 
306 #define TCA_BASIC_MAX (__TCA_BASIC_MAX - 1)
307 
308 
309 /* Cgroup classifier */
310 
311 enum {
312 	TCA_CGROUP_UNSPEC,
313 	TCA_CGROUP_ACT,
314 	TCA_CGROUP_POLICE,
315 	TCA_CGROUP_EMATCHES,
316 	__TCA_CGROUP_MAX,
317 };
318 
319 #define TCA_CGROUP_MAX (__TCA_CGROUP_MAX - 1)
320 
321 /* BPF classifier */
322 
323 #define TCA_BPF_FLAG_ACT_DIRECT		(1 << 0)
324 
325 enum {
326 	TCA_BPF_UNSPEC,
327 	TCA_BPF_ACT,
328 	TCA_BPF_POLICE,
329 	TCA_BPF_CLASSID,
330 	TCA_BPF_OPS_LEN,
331 	TCA_BPF_OPS,
332 	TCA_BPF_FD,
333 	TCA_BPF_NAME,
334 	TCA_BPF_FLAGS,
335 	__TCA_BPF_MAX,
336 };
337 
338 #define TCA_BPF_MAX (__TCA_BPF_MAX - 1)
339 
340 /* Flower classifier */
341 
342 enum {
343 	TCA_FLOWER_UNSPEC,
344 	TCA_FLOWER_CLASSID,
345 	TCA_FLOWER_INDEV,
346 	TCA_FLOWER_ACT,
347 	TCA_FLOWER_KEY_ETH_DST,		/* ETH_ALEN */
348 	TCA_FLOWER_KEY_ETH_DST_MASK,	/* ETH_ALEN */
349 	TCA_FLOWER_KEY_ETH_SRC,		/* ETH_ALEN */
350 	TCA_FLOWER_KEY_ETH_SRC_MASK,	/* ETH_ALEN */
351 	TCA_FLOWER_KEY_ETH_TYPE,	/* be16 */
352 	TCA_FLOWER_KEY_IP_PROTO,	/* u8 */
353 	TCA_FLOWER_KEY_IPV4_SRC,	/* be32 */
354 	TCA_FLOWER_KEY_IPV4_SRC_MASK,	/* be32 */
355 	TCA_FLOWER_KEY_IPV4_DST,	/* be32 */
356 	TCA_FLOWER_KEY_IPV4_DST_MASK,	/* be32 */
357 	TCA_FLOWER_KEY_IPV6_SRC,	/* struct in6_addr */
358 	TCA_FLOWER_KEY_IPV6_SRC_MASK,	/* struct in6_addr */
359 	TCA_FLOWER_KEY_IPV6_DST,	/* struct in6_addr */
360 	TCA_FLOWER_KEY_IPV6_DST_MASK,	/* struct in6_addr */
361 	TCA_FLOWER_KEY_TCP_SRC,		/* be16 */
362 	TCA_FLOWER_KEY_TCP_DST,		/* be16 */
363 	TCA_FLOWER_KEY_UDP_SRC,		/* be16 */
364 	TCA_FLOWER_KEY_UDP_DST,		/* be16 */
365 	__TCA_FLOWER_MAX,
366 };
367 
368 #define TCA_FLOWER_MAX (__TCA_FLOWER_MAX - 1)
369 
370 /* Extended Matches */
371 
372 struct tcf_ematch_tree_hdr {
373 	__u16		nmatches;
374 	__u16		progid;
375 };
376 
377 enum {
378 	TCA_EMATCH_TREE_UNSPEC,
379 	TCA_EMATCH_TREE_HDR,
380 	TCA_EMATCH_TREE_LIST,
381 	__TCA_EMATCH_TREE_MAX
382 };
383 #define TCA_EMATCH_TREE_MAX (__TCA_EMATCH_TREE_MAX - 1)
384 
385 struct tcf_ematch_hdr {
386 	__u16		matchid;
387 	__u16		kind;
388 	__u16		flags;
389 	__u16		pad; /* currently unused */
390 };
391 
392 /*  0                   1
393  *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
394  * +-----------------------+-+-+---+
395  * |         Unused        |S|I| R |
396  * +-----------------------+-+-+---+
397  *
398  * R(2) ::= relation to next ematch
399  *          where: 0 0 END (last ematch)
400  *                 0 1 AND
401  *                 1 0 OR
402  *                 1 1 Unused (invalid)
403  * I(1) ::= invert result
404  * S(1) ::= simple payload
405  */
406 #define TCF_EM_REL_END	0
407 #define TCF_EM_REL_AND	(1<<0)
408 #define TCF_EM_REL_OR	(1<<1)
409 #define TCF_EM_INVERT	(1<<2)
410 #define TCF_EM_SIMPLE	(1<<3)
411 
412 #define TCF_EM_REL_MASK	3
413 #define TCF_EM_REL_VALID(v) (((v) & TCF_EM_REL_MASK) != TCF_EM_REL_MASK)
414 
415 enum {
416 	TCF_LAYER_LINK,
417 	TCF_LAYER_NETWORK,
418 	TCF_LAYER_TRANSPORT,
419 	__TCF_LAYER_MAX
420 };
421 #define TCF_LAYER_MAX (__TCF_LAYER_MAX - 1)
422 
423 /* Ematch type assignments
424  *   1..32767		Reserved for ematches inside kernel tree
425  *   32768..65535	Free to use, not reliable
426  */
427 #define	TCF_EM_CONTAINER	0
428 #define	TCF_EM_CMP		1
429 #define	TCF_EM_NBYTE		2
430 #define	TCF_EM_U32		3
431 #define	TCF_EM_META		4
432 #define	TCF_EM_TEXT		5
433 #define	TCF_EM_VLAN		6
434 #define	TCF_EM_CANID		7
435 #define	TCF_EM_IPSET		8
436 #define	TCF_EM_MAX		8
437 
438 enum {
439 	TCF_EM_PROG_TC
440 };
441 
442 enum {
443 	TCF_EM_OPND_EQ,
444 	TCF_EM_OPND_GT,
445 	TCF_EM_OPND_LT
446 };
447 
448 #endif
449