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