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