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 __u64 firstuse; 128 }; 129 130 struct tc_cnt { 131 int refcnt; 132 int bindcnt; 133 }; 134 135 #define tc_gen \ 136 __u32 index; \ 137 __u32 capab; \ 138 int action; \ 139 int refcnt; \ 140 int bindcnt 141 142 enum { 143 TCA_POLICE_UNSPEC, 144 TCA_POLICE_TBF, 145 TCA_POLICE_RATE, 146 TCA_POLICE_PEAKRATE, 147 TCA_POLICE_AVRATE, 148 TCA_POLICE_RESULT, 149 TCA_POLICE_TM, 150 TCA_POLICE_PAD, 151 __TCA_POLICE_MAX 152 #define TCA_POLICE_RESULT TCA_POLICE_RESULT 153 }; 154 155 #define TCA_POLICE_MAX (__TCA_POLICE_MAX - 1) 156 157 /* tca flags definitions */ 158 #define TCA_CLS_FLAGS_SKIP_HW (1 << 0) 159 #define TCA_CLS_FLAGS_SKIP_SW (1 << 1) 160 161 /* U32 filters */ 162 163 #define TC_U32_HTID(h) ((h)&0xFFF00000) 164 #define TC_U32_USERHTID(h) (TC_U32_HTID(h)>>20) 165 #define TC_U32_HASH(h) (((h)>>12)&0xFF) 166 #define TC_U32_NODE(h) ((h)&0xFFF) 167 #define TC_U32_KEY(h) ((h)&0xFFFFF) 168 #define TC_U32_UNSPEC 0 169 #define TC_U32_ROOT (0xFFF00000) 170 171 enum { 172 TCA_U32_UNSPEC, 173 TCA_U32_CLASSID, 174 TCA_U32_HASH, 175 TCA_U32_LINK, 176 TCA_U32_DIVISOR, 177 TCA_U32_SEL, 178 TCA_U32_POLICE, 179 TCA_U32_ACT, 180 TCA_U32_INDEV, 181 TCA_U32_PCNT, 182 TCA_U32_MARK, 183 TCA_U32_FLAGS, 184 TCA_U32_PAD, 185 __TCA_U32_MAX 186 }; 187 188 #define TCA_U32_MAX (__TCA_U32_MAX - 1) 189 190 struct tc_u32_key { 191 __be32 mask; 192 __be32 val; 193 int off; 194 int offmask; 195 }; 196 197 struct tc_u32_sel { 198 unsigned char flags; 199 unsigned char offshift; 200 unsigned char nkeys; 201 202 __be16 offmask; 203 __u16 off; 204 short offoff; 205 206 short hoff; 207 __be32 hmask; 208 struct tc_u32_key keys[0]; 209 }; 210 211 struct tc_u32_mark { 212 __u32 val; 213 __u32 mask; 214 __u32 success; 215 }; 216 217 struct tc_u32_pcnt { 218 __u64 rcnt; 219 __u64 rhit; 220 __u64 kcnts[0]; 221 }; 222 223 /* Flags */ 224 225 #define TC_U32_TERMINAL 1 226 #define TC_U32_OFFSET 2 227 #define TC_U32_VAROFFSET 4 228 #define TC_U32_EAT 8 229 230 #define TC_U32_MAXDEPTH 8 231 232 233 /* RSVP filter */ 234 235 enum { 236 TCA_RSVP_UNSPEC, 237 TCA_RSVP_CLASSID, 238 TCA_RSVP_DST, 239 TCA_RSVP_SRC, 240 TCA_RSVP_PINFO, 241 TCA_RSVP_POLICE, 242 TCA_RSVP_ACT, 243 __TCA_RSVP_MAX 244 }; 245 246 #define TCA_RSVP_MAX (__TCA_RSVP_MAX - 1 ) 247 248 struct tc_rsvp_gpi { 249 __u32 key; 250 __u32 mask; 251 int offset; 252 }; 253 254 struct tc_rsvp_pinfo { 255 struct tc_rsvp_gpi dpi; 256 struct tc_rsvp_gpi spi; 257 __u8 protocol; 258 __u8 tunnelid; 259 __u8 tunnelhdr; 260 __u8 pad; 261 }; 262 263 /* ROUTE filter */ 264 265 enum { 266 TCA_ROUTE4_UNSPEC, 267 TCA_ROUTE4_CLASSID, 268 TCA_ROUTE4_TO, 269 TCA_ROUTE4_FROM, 270 TCA_ROUTE4_IIF, 271 TCA_ROUTE4_POLICE, 272 TCA_ROUTE4_ACT, 273 __TCA_ROUTE4_MAX 274 }; 275 276 #define TCA_ROUTE4_MAX (__TCA_ROUTE4_MAX - 1) 277 278 279 /* FW filter */ 280 281 enum { 282 TCA_FW_UNSPEC, 283 TCA_FW_CLASSID, 284 TCA_FW_POLICE, 285 TCA_FW_INDEV, /* used by CONFIG_NET_CLS_IND */ 286 TCA_FW_ACT, /* used by CONFIG_NET_CLS_ACT */ 287 TCA_FW_MASK, 288 __TCA_FW_MAX 289 }; 290 291 #define TCA_FW_MAX (__TCA_FW_MAX - 1) 292 293 /* TC index filter */ 294 295 enum { 296 TCA_TCINDEX_UNSPEC, 297 TCA_TCINDEX_HASH, 298 TCA_TCINDEX_MASK, 299 TCA_TCINDEX_SHIFT, 300 TCA_TCINDEX_FALL_THROUGH, 301 TCA_TCINDEX_CLASSID, 302 TCA_TCINDEX_POLICE, 303 TCA_TCINDEX_ACT, 304 __TCA_TCINDEX_MAX 305 }; 306 307 #define TCA_TCINDEX_MAX (__TCA_TCINDEX_MAX - 1) 308 309 /* Flow filter */ 310 311 enum { 312 FLOW_KEY_SRC, 313 FLOW_KEY_DST, 314 FLOW_KEY_PROTO, 315 FLOW_KEY_PROTO_SRC, 316 FLOW_KEY_PROTO_DST, 317 FLOW_KEY_IIF, 318 FLOW_KEY_PRIORITY, 319 FLOW_KEY_MARK, 320 FLOW_KEY_NFCT, 321 FLOW_KEY_NFCT_SRC, 322 FLOW_KEY_NFCT_DST, 323 FLOW_KEY_NFCT_PROTO_SRC, 324 FLOW_KEY_NFCT_PROTO_DST, 325 FLOW_KEY_RTCLASSID, 326 FLOW_KEY_SKUID, 327 FLOW_KEY_SKGID, 328 FLOW_KEY_VLAN_TAG, 329 FLOW_KEY_RXHASH, 330 __FLOW_KEY_MAX, 331 }; 332 333 #define FLOW_KEY_MAX (__FLOW_KEY_MAX - 1) 334 335 enum { 336 FLOW_MODE_MAP, 337 FLOW_MODE_HASH, 338 }; 339 340 enum { 341 TCA_FLOW_UNSPEC, 342 TCA_FLOW_KEYS, 343 TCA_FLOW_MODE, 344 TCA_FLOW_BASECLASS, 345 TCA_FLOW_RSHIFT, 346 TCA_FLOW_ADDEND, 347 TCA_FLOW_MASK, 348 TCA_FLOW_XOR, 349 TCA_FLOW_DIVISOR, 350 TCA_FLOW_ACT, 351 TCA_FLOW_POLICE, 352 TCA_FLOW_EMATCHES, 353 TCA_FLOW_PERTURB, 354 __TCA_FLOW_MAX 355 }; 356 357 #define TCA_FLOW_MAX (__TCA_FLOW_MAX - 1) 358 359 /* Basic filter */ 360 361 enum { 362 TCA_BASIC_UNSPEC, 363 TCA_BASIC_CLASSID, 364 TCA_BASIC_EMATCHES, 365 TCA_BASIC_ACT, 366 TCA_BASIC_POLICE, 367 __TCA_BASIC_MAX 368 }; 369 370 #define TCA_BASIC_MAX (__TCA_BASIC_MAX - 1) 371 372 373 /* Cgroup classifier */ 374 375 enum { 376 TCA_CGROUP_UNSPEC, 377 TCA_CGROUP_ACT, 378 TCA_CGROUP_POLICE, 379 TCA_CGROUP_EMATCHES, 380 __TCA_CGROUP_MAX, 381 }; 382 383 #define TCA_CGROUP_MAX (__TCA_CGROUP_MAX - 1) 384 385 /* BPF classifier */ 386 387 #define TCA_BPF_FLAG_ACT_DIRECT (1 << 0) 388 389 enum { 390 TCA_BPF_UNSPEC, 391 TCA_BPF_ACT, 392 TCA_BPF_POLICE, 393 TCA_BPF_CLASSID, 394 TCA_BPF_OPS_LEN, 395 TCA_BPF_OPS, 396 TCA_BPF_FD, 397 TCA_BPF_NAME, 398 TCA_BPF_FLAGS, 399 TCA_BPF_FLAGS_GEN, 400 TCA_BPF_DIGEST, 401 __TCA_BPF_MAX, 402 }; 403 404 #define TCA_BPF_MAX (__TCA_BPF_MAX - 1) 405 406 /* Flower classifier */ 407 408 enum { 409 TCA_FLOWER_UNSPEC, 410 TCA_FLOWER_CLASSID, 411 TCA_FLOWER_INDEV, 412 TCA_FLOWER_ACT, 413 TCA_FLOWER_KEY_ETH_DST, /* ETH_ALEN */ 414 TCA_FLOWER_KEY_ETH_DST_MASK, /* ETH_ALEN */ 415 TCA_FLOWER_KEY_ETH_SRC, /* ETH_ALEN */ 416 TCA_FLOWER_KEY_ETH_SRC_MASK, /* ETH_ALEN */ 417 TCA_FLOWER_KEY_ETH_TYPE, /* be16 */ 418 TCA_FLOWER_KEY_IP_PROTO, /* u8 */ 419 TCA_FLOWER_KEY_IPV4_SRC, /* be32 */ 420 TCA_FLOWER_KEY_IPV4_SRC_MASK, /* be32 */ 421 TCA_FLOWER_KEY_IPV4_DST, /* be32 */ 422 TCA_FLOWER_KEY_IPV4_DST_MASK, /* be32 */ 423 TCA_FLOWER_KEY_IPV6_SRC, /* struct in6_addr */ 424 TCA_FLOWER_KEY_IPV6_SRC_MASK, /* struct in6_addr */ 425 TCA_FLOWER_KEY_IPV6_DST, /* struct in6_addr */ 426 TCA_FLOWER_KEY_IPV6_DST_MASK, /* struct in6_addr */ 427 TCA_FLOWER_KEY_TCP_SRC, /* be16 */ 428 TCA_FLOWER_KEY_TCP_DST, /* be16 */ 429 TCA_FLOWER_KEY_UDP_SRC, /* be16 */ 430 TCA_FLOWER_KEY_UDP_DST, /* be16 */ 431 432 TCA_FLOWER_FLAGS, 433 TCA_FLOWER_KEY_VLAN_ID, /* be16 */ 434 TCA_FLOWER_KEY_VLAN_PRIO, /* u8 */ 435 TCA_FLOWER_KEY_VLAN_ETH_TYPE, /* be16 */ 436 437 TCA_FLOWER_KEY_ENC_KEY_ID, /* be32 */ 438 TCA_FLOWER_KEY_ENC_IPV4_SRC, /* be32 */ 439 TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK,/* be32 */ 440 TCA_FLOWER_KEY_ENC_IPV4_DST, /* be32 */ 441 TCA_FLOWER_KEY_ENC_IPV4_DST_MASK,/* be32 */ 442 TCA_FLOWER_KEY_ENC_IPV6_SRC, /* struct in6_addr */ 443 TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK,/* struct in6_addr */ 444 TCA_FLOWER_KEY_ENC_IPV6_DST, /* struct in6_addr */ 445 TCA_FLOWER_KEY_ENC_IPV6_DST_MASK,/* struct in6_addr */ 446 447 TCA_FLOWER_KEY_TCP_SRC_MASK, /* be16 */ 448 TCA_FLOWER_KEY_TCP_DST_MASK, /* be16 */ 449 TCA_FLOWER_KEY_UDP_SRC_MASK, /* be16 */ 450 TCA_FLOWER_KEY_UDP_DST_MASK, /* be16 */ 451 TCA_FLOWER_KEY_SCTP_SRC_MASK, /* be16 */ 452 TCA_FLOWER_KEY_SCTP_DST_MASK, /* be16 */ 453 454 TCA_FLOWER_KEY_SCTP_SRC, /* be16 */ 455 TCA_FLOWER_KEY_SCTP_DST, /* be16 */ 456 457 TCA_FLOWER_KEY_ENC_UDP_SRC_PORT, /* be16 */ 458 TCA_FLOWER_KEY_ENC_UDP_SRC_PORT_MASK, /* be16 */ 459 TCA_FLOWER_KEY_ENC_UDP_DST_PORT, /* be16 */ 460 TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK, /* be16 */ 461 462 TCA_FLOWER_KEY_FLAGS, /* be32 */ 463 TCA_FLOWER_KEY_FLAGS_MASK, /* be32 */ 464 465 TCA_FLOWER_KEY_ICMPV4_CODE, /* u8 */ 466 TCA_FLOWER_KEY_ICMPV4_CODE_MASK,/* u8 */ 467 TCA_FLOWER_KEY_ICMPV4_TYPE, /* u8 */ 468 TCA_FLOWER_KEY_ICMPV4_TYPE_MASK,/* u8 */ 469 TCA_FLOWER_KEY_ICMPV6_CODE, /* u8 */ 470 TCA_FLOWER_KEY_ICMPV6_CODE_MASK,/* u8 */ 471 TCA_FLOWER_KEY_ICMPV6_TYPE, /* u8 */ 472 TCA_FLOWER_KEY_ICMPV6_TYPE_MASK,/* u8 */ 473 474 __TCA_FLOWER_MAX, 475 }; 476 477 #define TCA_FLOWER_MAX (__TCA_FLOWER_MAX - 1) 478 479 enum { 480 TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT = (1 << 0), 481 }; 482 483 /* Match-all classifier */ 484 485 enum { 486 TCA_MATCHALL_UNSPEC, 487 TCA_MATCHALL_CLASSID, 488 TCA_MATCHALL_ACT, 489 TCA_MATCHALL_FLAGS, 490 __TCA_MATCHALL_MAX, 491 }; 492 493 #define TCA_MATCHALL_MAX (__TCA_MATCHALL_MAX - 1) 494 495 /* Extended Matches */ 496 497 struct tcf_ematch_tree_hdr { 498 __u16 nmatches; 499 __u16 progid; 500 }; 501 502 enum { 503 TCA_EMATCH_TREE_UNSPEC, 504 TCA_EMATCH_TREE_HDR, 505 TCA_EMATCH_TREE_LIST, 506 __TCA_EMATCH_TREE_MAX 507 }; 508 #define TCA_EMATCH_TREE_MAX (__TCA_EMATCH_TREE_MAX - 1) 509 510 struct tcf_ematch_hdr { 511 __u16 matchid; 512 __u16 kind; 513 __u16 flags; 514 __u16 pad; /* currently unused */ 515 }; 516 517 /* 0 1 518 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 519 * +-----------------------+-+-+---+ 520 * | Unused |S|I| R | 521 * +-----------------------+-+-+---+ 522 * 523 * R(2) ::= relation to next ematch 524 * where: 0 0 END (last ematch) 525 * 0 1 AND 526 * 1 0 OR 527 * 1 1 Unused (invalid) 528 * I(1) ::= invert result 529 * S(1) ::= simple payload 530 */ 531 #define TCF_EM_REL_END 0 532 #define TCF_EM_REL_AND (1<<0) 533 #define TCF_EM_REL_OR (1<<1) 534 #define TCF_EM_INVERT (1<<2) 535 #define TCF_EM_SIMPLE (1<<3) 536 537 #define TCF_EM_REL_MASK 3 538 #define TCF_EM_REL_VALID(v) (((v) & TCF_EM_REL_MASK) != TCF_EM_REL_MASK) 539 540 enum { 541 TCF_LAYER_LINK, 542 TCF_LAYER_NETWORK, 543 TCF_LAYER_TRANSPORT, 544 __TCF_LAYER_MAX 545 }; 546 #define TCF_LAYER_MAX (__TCF_LAYER_MAX - 1) 547 548 /* Ematch type assignments 549 * 1..32767 Reserved for ematches inside kernel tree 550 * 32768..65535 Free to use, not reliable 551 */ 552 #define TCF_EM_CONTAINER 0 553 #define TCF_EM_CMP 1 554 #define TCF_EM_NBYTE 2 555 #define TCF_EM_U32 3 556 #define TCF_EM_META 4 557 #define TCF_EM_TEXT 5 558 #define TCF_EM_VLAN 6 559 #define TCF_EM_CANID 7 560 #define TCF_EM_IPSET 8 561 #define TCF_EM_MAX 8 562 563 enum { 564 TCF_EM_PROG_TC 565 }; 566 567 enum { 568 TCF_EM_OPND_EQ, 569 TCF_EM_OPND_GT, 570 TCF_EM_OPND_LT 571 }; 572 573 #endif 574