blob: 28dfc61cf79e590d18c6ba62cbb8ee66b8101d89 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __LINUX_PKT_CLS_H
2#define __LINUX_PKT_CLS_H
3
4#include <linux/pkt_sched.h>
5
6/* I think i could have done better macros ; for now this is stolen from
7 * some arch/mips code - jhs
8*/
9#define _TC_MAKE32(x) ((x))
10
11#define _TC_MAKEMASK1(n) (_TC_MAKE32(1) << _TC_MAKE32(n))
12#define _TC_MAKEMASK(v,n) (_TC_MAKE32((_TC_MAKE32(1)<<(v))-1) << _TC_MAKE32(n))
13#define _TC_MAKEVALUE(v,n) (_TC_MAKE32(v) << _TC_MAKE32(n))
14#define _TC_GETVALUE(v,n,m) ((_TC_MAKE32(v) & _TC_MAKE32(m)) >> _TC_MAKE32(n))
15
16/* verdict bit breakdown
17 *
18bit 0: when set -> this packet has been munged already
19
20bit 1: when set -> It is ok to munge this packet
21
22bit 2,3,4,5: Reclassify counter - sort of reverse TTL - if exceeded
23assume loop
24
25bit 6,7: Where this packet was last seen
260: Above the transmit example at the socket level
271: on the Ingress
282: on the Egress
29
30bit 8: when set --> Request not to classify on ingress.
31
32bits 9,10,11: redirect counter - redirect TTL. Loop avoidance
33
34 *
35 * */
36
37#define TC_MUNGED _TC_MAKEMASK1(0)
38#define SET_TC_MUNGED(v) ( TC_MUNGED | (v & ~TC_MUNGED))
39#define CLR_TC_MUNGED(v) ( v & ~TC_MUNGED)
40
41#define TC_OK2MUNGE _TC_MAKEMASK1(1)
42#define SET_TC_OK2MUNGE(v) ( TC_OK2MUNGE | (v & ~TC_OK2MUNGE))
43#define CLR_TC_OK2MUNGE(v) ( v & ~TC_OK2MUNGE)
44
45#define S_TC_VERD _TC_MAKE32(2)
46#define M_TC_VERD _TC_MAKEMASK(4,S_TC_VERD)
47#define G_TC_VERD(x) _TC_GETVALUE(x,S_TC_VERD,M_TC_VERD)
48#define V_TC_VERD(x) _TC_MAKEVALUE(x,S_TC_VERD)
49#define SET_TC_VERD(v,n) ((V_TC_VERD(n)) | (v & ~M_TC_VERD))
50
51#define S_TC_FROM _TC_MAKE32(6)
52#define M_TC_FROM _TC_MAKEMASK(2,S_TC_FROM)
53#define G_TC_FROM(x) _TC_GETVALUE(x,S_TC_FROM,M_TC_FROM)
54#define V_TC_FROM(x) _TC_MAKEVALUE(x,S_TC_FROM)
55#define SET_TC_FROM(v,n) ((V_TC_FROM(n)) | (v & ~M_TC_FROM))
56#define AT_STACK 0x0
57#define AT_INGRESS 0x1
58#define AT_EGRESS 0x2
59
60#define TC_NCLS _TC_MAKEMASK1(8)
61#define SET_TC_NCLS(v) ( TC_NCLS | (v & ~TC_NCLS))
62#define CLR_TC_NCLS(v) ( v & ~TC_NCLS)
63
64#define S_TC_RTTL _TC_MAKE32(9)
65#define M_TC_RTTL _TC_MAKEMASK(3,S_TC_RTTL)
66#define G_TC_RTTL(x) _TC_GETVALUE(x,S_TC_RTTL,M_TC_RTTL)
67#define V_TC_RTTL(x) _TC_MAKEVALUE(x,S_TC_RTTL)
68#define SET_TC_RTTL(v,n) ((V_TC_RTTL(n)) | (v & ~M_TC_RTTL))
69
70#define S_TC_AT _TC_MAKE32(12)
71#define M_TC_AT _TC_MAKEMASK(2,S_TC_AT)
72#define G_TC_AT(x) _TC_GETVALUE(x,S_TC_AT,M_TC_AT)
73#define V_TC_AT(x) _TC_MAKEVALUE(x,S_TC_AT)
74#define SET_TC_AT(v,n) ((V_TC_AT(n)) | (v & ~M_TC_AT))
75
76/* Action attributes */
77enum
78{
79 TCA_ACT_UNSPEC,
80 TCA_ACT_KIND,
81 TCA_ACT_OPTIONS,
82 TCA_ACT_INDEX,
83 TCA_ACT_STATS,
84 __TCA_ACT_MAX
85};
86
87#define TCA_ACT_MAX __TCA_ACT_MAX
88#define TCA_OLD_COMPAT (TCA_ACT_MAX+1)
89#define TCA_ACT_MAX_PRIO 32
90#define TCA_ACT_BIND 1
91#define TCA_ACT_NOBIND 0
92#define TCA_ACT_UNBIND 1
93#define TCA_ACT_NOUNBIND 0
94#define TCA_ACT_REPLACE 1
95#define TCA_ACT_NOREPLACE 0
96#define MAX_REC_LOOP 4
97#define MAX_RED_LOOP 4
98
99#define TC_ACT_UNSPEC (-1)
100#define TC_ACT_OK 0
101#define TC_ACT_RECLASSIFY 1
102#define TC_ACT_SHOT 2
103#define TC_ACT_PIPE 3
104#define TC_ACT_STOLEN 4
105#define TC_ACT_QUEUED 5
106#define TC_ACT_REPEAT 6
107#define TC_ACT_JUMP 0x10000000
108
109/* Action type identifiers*/
110enum
111{
112 TCA_ID_UNSPEC=0,
113 TCA_ID_POLICE=1,
114 /* other actions go here */
115 __TCA_ID_MAX=255
116};
117
118#define TCA_ID_MAX __TCA_ID_MAX
119
120struct tc_police
121{
122 __u32 index;
123 int action;
124#define TC_POLICE_UNSPEC TC_ACT_UNSPEC
125#define TC_POLICE_OK TC_ACT_OK
126#define TC_POLICE_RECLASSIFY TC_ACT_RECLASSIFY
127#define TC_POLICE_SHOT TC_ACT_SHOT
128#define TC_POLICE_PIPE TC_ACT_PIPE
129
130 __u32 limit;
131 __u32 burst;
132 __u32 mtu;
133 struct tc_ratespec rate;
134 struct tc_ratespec peakrate;
135 int refcnt;
136 int bindcnt;
137 __u32 capab;
138};
139
140struct tcf_t
141{
142 __u64 install;
143 __u64 lastuse;
144 __u64 expires;
145};
146
147struct tc_cnt
148{
149 int refcnt;
150 int bindcnt;
151};
152
153#define tc_gen \
154 __u32 index; \
155 __u32 capab; \
156 int action; \
157 int refcnt; \
158 int bindcnt
159
160enum
161{
162 TCA_POLICE_UNSPEC,
163 TCA_POLICE_TBF,
164 TCA_POLICE_RATE,
165 TCA_POLICE_PEAKRATE,
166 TCA_POLICE_AVRATE,
167 TCA_POLICE_RESULT,
168 __TCA_POLICE_MAX
169#define TCA_POLICE_RESULT TCA_POLICE_RESULT
170};
171
172#define TCA_POLICE_MAX (__TCA_POLICE_MAX - 1)
173
174/* U32 filters */
175
176#define TC_U32_HTID(h) ((h)&0xFFF00000)
177#define TC_U32_USERHTID(h) (TC_U32_HTID(h)>>20)
178#define TC_U32_HASH(h) (((h)>>12)&0xFF)
179#define TC_U32_NODE(h) ((h)&0xFFF)
180#define TC_U32_KEY(h) ((h)&0xFFFFF)
181#define TC_U32_UNSPEC 0
182#define TC_U32_ROOT (0xFFF00000)
183
184enum
185{
186 TCA_U32_UNSPEC,
187 TCA_U32_CLASSID,
188 TCA_U32_HASH,
189 TCA_U32_LINK,
190 TCA_U32_DIVISOR,
191 TCA_U32_SEL,
192 TCA_U32_POLICE,
193 TCA_U32_ACT,
194 TCA_U32_INDEV,
195 TCA_U32_PCNT,
196 TCA_U32_MARK,
197 __TCA_U32_MAX
198};
199
200#define TCA_U32_MAX (__TCA_U32_MAX - 1)
201
202struct tc_u32_key
203{
204 __u32 mask;
205 __u32 val;
206 int off;
207 int offmask;
208};
209
210struct tc_u32_sel
211{
212 unsigned char flags;
213 unsigned char offshift;
214 unsigned char nkeys;
215
216 __u16 offmask;
217 __u16 off;
218 short offoff;
219
220 short hoff;
221 __u32 hmask;
222 struct tc_u32_key keys[0];
223};
224
225struct tc_u32_mark
226{
227 __u32 val;
228 __u32 mask;
229 __u32 success;
230};
231
232struct tc_u32_pcnt
233{
234 __u64 rcnt;
235 __u64 rhit;
236 __u64 kcnts[0];
237};
238
239/* Flags */
240
241#define TC_U32_TERMINAL 1
242#define TC_U32_OFFSET 2
243#define TC_U32_VAROFFSET 4
244#define TC_U32_EAT 8
245
246#define TC_U32_MAXDEPTH 8
247
248
249/* RSVP filter */
250
251enum
252{
253 TCA_RSVP_UNSPEC,
254 TCA_RSVP_CLASSID,
255 TCA_RSVP_DST,
256 TCA_RSVP_SRC,
257 TCA_RSVP_PINFO,
258 TCA_RSVP_POLICE,
259 TCA_RSVP_ACT,
260 __TCA_RSVP_MAX
261};
262
263#define TCA_RSVP_MAX (__TCA_RSVP_MAX - 1 )
264
265struct tc_rsvp_gpi
266{
267 __u32 key;
268 __u32 mask;
269 int offset;
270};
271
272struct tc_rsvp_pinfo
273{
274 struct tc_rsvp_gpi dpi;
275 struct tc_rsvp_gpi spi;
276 __u8 protocol;
277 __u8 tunnelid;
278 __u8 tunnelhdr;
Patrick McHardy8a470772005-06-28 12:56:45 -0700279 __u8 pad;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280};
281
282/* ROUTE filter */
283
284enum
285{
286 TCA_ROUTE4_UNSPEC,
287 TCA_ROUTE4_CLASSID,
288 TCA_ROUTE4_TO,
289 TCA_ROUTE4_FROM,
290 TCA_ROUTE4_IIF,
291 TCA_ROUTE4_POLICE,
292 TCA_ROUTE4_ACT,
293 __TCA_ROUTE4_MAX
294};
295
296#define TCA_ROUTE4_MAX (__TCA_ROUTE4_MAX - 1)
297
298
299/* FW filter */
300
301enum
302{
303 TCA_FW_UNSPEC,
304 TCA_FW_CLASSID,
305 TCA_FW_POLICE,
306 TCA_FW_INDEV, /* used by CONFIG_NET_CLS_IND */
307 TCA_FW_ACT, /* used by CONFIG_NET_CLS_ACT */
Patrick McHardyb4e9b522006-08-25 16:11:42 -0700308 TCA_FW_MASK,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 __TCA_FW_MAX
310};
311
312#define TCA_FW_MAX (__TCA_FW_MAX - 1)
313
314/* TC index filter */
315
316enum
317{
318 TCA_TCINDEX_UNSPEC,
319 TCA_TCINDEX_HASH,
320 TCA_TCINDEX_MASK,
321 TCA_TCINDEX_SHIFT,
322 TCA_TCINDEX_FALL_THROUGH,
323 TCA_TCINDEX_CLASSID,
324 TCA_TCINDEX_POLICE,
325 TCA_TCINDEX_ACT,
326 __TCA_TCINDEX_MAX
327};
328
329#define TCA_TCINDEX_MAX (__TCA_TCINDEX_MAX - 1)
330
Patrick McHardye5dfb812008-01-31 18:37:42 -0800331/* Flow filter */
332
333enum
334{
335 FLOW_KEY_SRC,
336 FLOW_KEY_DST,
337 FLOW_KEY_PROTO,
338 FLOW_KEY_PROTO_SRC,
339 FLOW_KEY_PROTO_DST,
340 FLOW_KEY_IIF,
341 FLOW_KEY_PRIORITY,
342 FLOW_KEY_MARK,
343 FLOW_KEY_NFCT,
344 FLOW_KEY_NFCT_SRC,
345 FLOW_KEY_NFCT_DST,
346 FLOW_KEY_NFCT_PROTO_SRC,
347 FLOW_KEY_NFCT_PROTO_DST,
348 FLOW_KEY_RTCLASSID,
349 FLOW_KEY_SKUID,
350 FLOW_KEY_SKGID,
Patrick McHardy9ec13812008-02-05 16:21:04 -0800351 FLOW_KEY_VLAN_TAG,
Patrick McHardye5dfb812008-01-31 18:37:42 -0800352 __FLOW_KEY_MAX,
353};
354
355#define FLOW_KEY_MAX (__FLOW_KEY_MAX - 1)
356
357enum
358{
359 FLOW_MODE_MAP,
360 FLOW_MODE_HASH,
361};
362
363enum
364{
365 TCA_FLOW_UNSPEC,
366 TCA_FLOW_KEYS,
367 TCA_FLOW_MODE,
368 TCA_FLOW_BASECLASS,
369 TCA_FLOW_RSHIFT,
370 TCA_FLOW_ADDEND,
371 TCA_FLOW_MASK,
372 TCA_FLOW_XOR,
373 TCA_FLOW_DIVISOR,
374 TCA_FLOW_ACT,
375 TCA_FLOW_POLICE,
376 TCA_FLOW_EMATCHES,
377 __TCA_FLOW_MAX
378};
379
380#define TCA_FLOW_MAX (__TCA_FLOW_MAX - 1)
381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382/* Basic filter */
383
384enum
385{
386 TCA_BASIC_UNSPEC,
387 TCA_BASIC_CLASSID,
388 TCA_BASIC_EMATCHES,
389 TCA_BASIC_ACT,
390 TCA_BASIC_POLICE,
391 __TCA_BASIC_MAX
392};
393
394#define TCA_BASIC_MAX (__TCA_BASIC_MAX - 1)
395
396/* Extended Matches */
397
398struct tcf_ematch_tree_hdr
399{
400 __u16 nmatches;
401 __u16 progid;
402};
403
404enum
405{
406 TCA_EMATCH_TREE_UNSPEC,
407 TCA_EMATCH_TREE_HDR,
408 TCA_EMATCH_TREE_LIST,
409 __TCA_EMATCH_TREE_MAX
410};
411#define TCA_EMATCH_TREE_MAX (__TCA_EMATCH_TREE_MAX - 1)
412
413struct tcf_ematch_hdr
414{
415 __u16 matchid;
416 __u16 kind;
417 __u16 flags;
418 __u16 pad; /* currently unused */
419};
420
421/* 0 1
422 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
423 * +-----------------------+-+-+---+
424 * | Unused |S|I| R |
425 * +-----------------------+-+-+---+
426 *
427 * R(2) ::= relation to next ematch
428 * where: 0 0 END (last ematch)
429 * 0 1 AND
430 * 1 0 OR
431 * 1 1 Unused (invalid)
432 * I(1) ::= invert result
433 * S(1) ::= simple payload
434 */
435#define TCF_EM_REL_END 0
436#define TCF_EM_REL_AND (1<<0)
437#define TCF_EM_REL_OR (1<<1)
438#define TCF_EM_INVERT (1<<2)
439#define TCF_EM_SIMPLE (1<<3)
440
441#define TCF_EM_REL_MASK 3
442#define TCF_EM_REL_VALID(v) (((v) & TCF_EM_REL_MASK) != TCF_EM_REL_MASK)
443
444enum
445{
446 TCF_LAYER_LINK,
447 TCF_LAYER_NETWORK,
448 TCF_LAYER_TRANSPORT,
449 __TCF_LAYER_MAX
450};
451#define TCF_LAYER_MAX (__TCF_LAYER_MAX - 1)
452
453/* Ematch type assignments
454 * 1..32767 Reserved for ematches inside kernel tree
455 * 32768..65535 Free to use, not reliable
456 */
Patrick McHardydb3d99c2007-07-11 19:46:26 -0700457#define TCF_EM_CONTAINER 0
458#define TCF_EM_CMP 1
459#define TCF_EM_NBYTE 2
460#define TCF_EM_U32 3
461#define TCF_EM_META 4
462#define TCF_EM_TEXT 5
Stephen Hemminger3113e882008-02-05 03:20:13 -0800463#define TCF_EM_VLAN 6
464#define TCF_EM_MAX 6
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
466enum
467{
468 TCF_EM_PROG_TC
469};
470
471enum
472{
473 TCF_EM_OPND_EQ,
474 TCF_EM_OPND_GT,
475 TCF_EM_OPND_LT
476};
477
478#endif