github.com/sagernet/netlink@v0.0.0-20240612041022-b9a21c07ac6a/nl/tc_linux.go (about) 1 package nl 2 3 import ( 4 "encoding/binary" 5 "unsafe" 6 ) 7 8 // LinkLayer 9 const ( 10 LINKLAYER_UNSPEC = iota 11 LINKLAYER_ETHERNET 12 LINKLAYER_ATM 13 ) 14 15 // ATM 16 const ( 17 ATM_CELL_PAYLOAD = 48 18 ATM_CELL_SIZE = 53 19 ) 20 21 const TC_LINKLAYER_MASK = 0x0F 22 23 // Police 24 const ( 25 TCA_POLICE_UNSPEC = iota 26 TCA_POLICE_TBF 27 TCA_POLICE_RATE 28 TCA_POLICE_PEAKRATE 29 TCA_POLICE_AVRATE 30 TCA_POLICE_RESULT 31 TCA_POLICE_MAX = TCA_POLICE_RESULT 32 ) 33 34 // Message types 35 const ( 36 TCA_UNSPEC = iota 37 TCA_KIND 38 TCA_OPTIONS 39 TCA_STATS 40 TCA_XSTATS 41 TCA_RATE 42 TCA_FCNT 43 TCA_STATS2 44 TCA_STAB 45 TCA_MAX = TCA_STAB 46 ) 47 48 const ( 49 TCA_ACT_TAB = 1 50 TCAA_MAX = 1 51 ) 52 53 const ( 54 TCA_ACT_UNSPEC = iota 55 TCA_ACT_KIND 56 TCA_ACT_OPTIONS 57 TCA_ACT_INDEX 58 TCA_ACT_STATS 59 TCA_ACT_MAX 60 ) 61 62 const ( 63 TCA_PRIO_UNSPEC = iota 64 TCA_PRIO_MQ 65 TCA_PRIO_MAX = TCA_PRIO_MQ 66 ) 67 68 const ( 69 TCA_STATS_UNSPEC = iota 70 TCA_STATS_BASIC 71 TCA_STATS_RATE_EST 72 TCA_STATS_QUEUE 73 TCA_STATS_APP 74 TCA_STATS_MAX = TCA_STATS_APP 75 ) 76 77 const ( 78 SizeofTcMsg = 0x14 79 SizeofTcActionMsg = 0x04 80 SizeofTcPrioMap = 0x14 81 SizeofTcRateSpec = 0x0c 82 SizeofTcNetemQopt = 0x18 83 SizeofTcNetemCorr = 0x0c 84 SizeofTcNetemReorder = 0x08 85 SizeofTcNetemCorrupt = 0x08 86 SizeofTcTbfQopt = 2*SizeofTcRateSpec + 0x0c 87 SizeofTcHtbCopt = 2*SizeofTcRateSpec + 0x14 88 SizeofTcHtbGlob = 0x14 89 SizeofTcU32Key = 0x10 90 SizeofTcU32Sel = 0x10 // without keys 91 SizeofTcGen = 0x14 92 SizeofTcConnmark = SizeofTcGen + 0x04 93 SizeofTcCsum = SizeofTcGen + 0x04 94 SizeofTcMirred = SizeofTcGen + 0x08 95 SizeofTcTunnelKey = SizeofTcGen + 0x04 96 SizeofTcSkbEdit = SizeofTcGen 97 SizeofTcPolice = 2*SizeofTcRateSpec + 0x20 98 SizeofTcSfqQopt = 0x0b 99 SizeofTcSfqRedStats = 0x18 100 SizeofTcSfqQoptV1 = SizeofTcSfqQopt + SizeofTcSfqRedStats + 0x1c 101 ) 102 103 // struct tcmsg { 104 // unsigned char tcm_family; 105 // unsigned char tcm__pad1; 106 // unsigned short tcm__pad2; 107 // int tcm_ifindex; 108 // __u32 tcm_handle; 109 // __u32 tcm_parent; 110 // __u32 tcm_info; 111 // }; 112 113 type TcMsg struct { 114 Family uint8 115 Pad [3]byte 116 Ifindex int32 117 Handle uint32 118 Parent uint32 119 Info uint32 120 } 121 122 func (msg *TcMsg) Len() int { 123 return SizeofTcMsg 124 } 125 126 func DeserializeTcMsg(b []byte) *TcMsg { 127 return (*TcMsg)(unsafe.Pointer(&b[0:SizeofTcMsg][0])) 128 } 129 130 func (x *TcMsg) Serialize() []byte { 131 return (*(*[SizeofTcMsg]byte)(unsafe.Pointer(x)))[:] 132 } 133 134 // struct tcamsg { 135 // unsigned char tca_family; 136 // unsigned char tca__pad1; 137 // unsigned short tca__pad2; 138 // }; 139 140 type TcActionMsg struct { 141 Family uint8 142 Pad [3]byte 143 } 144 145 func (msg *TcActionMsg) Len() int { 146 return SizeofTcActionMsg 147 } 148 149 func DeserializeTcActionMsg(b []byte) *TcActionMsg { 150 return (*TcActionMsg)(unsafe.Pointer(&b[0:SizeofTcActionMsg][0])) 151 } 152 153 func (x *TcActionMsg) Serialize() []byte { 154 return (*(*[SizeofTcActionMsg]byte)(unsafe.Pointer(x)))[:] 155 } 156 157 const ( 158 TC_PRIO_MAX = 15 159 ) 160 161 // struct tc_prio_qopt { 162 // int bands; /* Number of bands */ 163 // __u8 priomap[TC_PRIO_MAX+1]; /* Map: logical priority -> PRIO band */ 164 // }; 165 166 type TcPrioMap struct { 167 Bands int32 168 Priomap [TC_PRIO_MAX + 1]uint8 169 } 170 171 func (msg *TcPrioMap) Len() int { 172 return SizeofTcPrioMap 173 } 174 175 func DeserializeTcPrioMap(b []byte) *TcPrioMap { 176 return (*TcPrioMap)(unsafe.Pointer(&b[0:SizeofTcPrioMap][0])) 177 } 178 179 func (x *TcPrioMap) Serialize() []byte { 180 return (*(*[SizeofTcPrioMap]byte)(unsafe.Pointer(x)))[:] 181 } 182 183 const ( 184 TCA_TBF_UNSPEC = iota 185 TCA_TBF_PARMS 186 TCA_TBF_RTAB 187 TCA_TBF_PTAB 188 TCA_TBF_RATE64 189 TCA_TBF_PRATE64 190 TCA_TBF_BURST 191 TCA_TBF_PBURST 192 TCA_TBF_MAX = TCA_TBF_PBURST 193 ) 194 195 // struct tc_ratespec { 196 // unsigned char cell_log; 197 // __u8 linklayer; /* lower 4 bits */ 198 // unsigned short overhead; 199 // short cell_align; 200 // unsigned short mpu; 201 // __u32 rate; 202 // }; 203 204 type TcRateSpec struct { 205 CellLog uint8 206 Linklayer uint8 207 Overhead uint16 208 CellAlign int16 209 Mpu uint16 210 Rate uint32 211 } 212 213 func (msg *TcRateSpec) Len() int { 214 return SizeofTcRateSpec 215 } 216 217 func DeserializeTcRateSpec(b []byte) *TcRateSpec { 218 return (*TcRateSpec)(unsafe.Pointer(&b[0:SizeofTcRateSpec][0])) 219 } 220 221 func (x *TcRateSpec) Serialize() []byte { 222 return (*(*[SizeofTcRateSpec]byte)(unsafe.Pointer(x)))[:] 223 } 224 225 /** 226 * NETEM 227 */ 228 229 const ( 230 TCA_NETEM_UNSPEC = iota 231 TCA_NETEM_CORR 232 TCA_NETEM_DELAY_DIST 233 TCA_NETEM_REORDER 234 TCA_NETEM_CORRUPT 235 TCA_NETEM_LOSS 236 TCA_NETEM_RATE 237 TCA_NETEM_ECN 238 TCA_NETEM_RATE64 239 TCA_NETEM_MAX = TCA_NETEM_RATE64 240 ) 241 242 // struct tc_netem_qopt { 243 // __u32 latency; /* added delay (us) */ 244 // __u32 limit; /* fifo limit (packets) */ 245 // __u32 loss; /* random packet loss (0=none ~0=100%) */ 246 // __u32 gap; /* re-ordering gap (0 for none) */ 247 // __u32 duplicate; /* random packet dup (0=none ~0=100%) */ 248 // __u32 jitter; /* random jitter in latency (us) */ 249 // }; 250 251 type TcNetemQopt struct { 252 Latency uint32 253 Limit uint32 254 Loss uint32 255 Gap uint32 256 Duplicate uint32 257 Jitter uint32 258 } 259 260 func (msg *TcNetemQopt) Len() int { 261 return SizeofTcNetemQopt 262 } 263 264 func DeserializeTcNetemQopt(b []byte) *TcNetemQopt { 265 return (*TcNetemQopt)(unsafe.Pointer(&b[0:SizeofTcNetemQopt][0])) 266 } 267 268 func (x *TcNetemQopt) Serialize() []byte { 269 return (*(*[SizeofTcNetemQopt]byte)(unsafe.Pointer(x)))[:] 270 } 271 272 // struct tc_netem_corr { 273 // __u32 delay_corr; /* delay correlation */ 274 // __u32 loss_corr; /* packet loss correlation */ 275 // __u32 dup_corr; /* duplicate correlation */ 276 // }; 277 278 type TcNetemCorr struct { 279 DelayCorr uint32 280 LossCorr uint32 281 DupCorr uint32 282 } 283 284 func (msg *TcNetemCorr) Len() int { 285 return SizeofTcNetemCorr 286 } 287 288 func DeserializeTcNetemCorr(b []byte) *TcNetemCorr { 289 return (*TcNetemCorr)(unsafe.Pointer(&b[0:SizeofTcNetemCorr][0])) 290 } 291 292 func (x *TcNetemCorr) Serialize() []byte { 293 return (*(*[SizeofTcNetemCorr]byte)(unsafe.Pointer(x)))[:] 294 } 295 296 // struct tc_netem_reorder { 297 // __u32 probability; 298 // __u32 correlation; 299 // }; 300 301 type TcNetemReorder struct { 302 Probability uint32 303 Correlation uint32 304 } 305 306 func (msg *TcNetemReorder) Len() int { 307 return SizeofTcNetemReorder 308 } 309 310 func DeserializeTcNetemReorder(b []byte) *TcNetemReorder { 311 return (*TcNetemReorder)(unsafe.Pointer(&b[0:SizeofTcNetemReorder][0])) 312 } 313 314 func (x *TcNetemReorder) Serialize() []byte { 315 return (*(*[SizeofTcNetemReorder]byte)(unsafe.Pointer(x)))[:] 316 } 317 318 // struct tc_netem_corrupt { 319 // __u32 probability; 320 // __u32 correlation; 321 // }; 322 323 type TcNetemCorrupt struct { 324 Probability uint32 325 Correlation uint32 326 } 327 328 func (msg *TcNetemCorrupt) Len() int { 329 return SizeofTcNetemCorrupt 330 } 331 332 func DeserializeTcNetemCorrupt(b []byte) *TcNetemCorrupt { 333 return (*TcNetemCorrupt)(unsafe.Pointer(&b[0:SizeofTcNetemCorrupt][0])) 334 } 335 336 func (x *TcNetemCorrupt) Serialize() []byte { 337 return (*(*[SizeofTcNetemCorrupt]byte)(unsafe.Pointer(x)))[:] 338 } 339 340 // struct tc_tbf_qopt { 341 // struct tc_ratespec rate; 342 // struct tc_ratespec peakrate; 343 // __u32 limit; 344 // __u32 buffer; 345 // __u32 mtu; 346 // }; 347 348 type TcTbfQopt struct { 349 Rate TcRateSpec 350 Peakrate TcRateSpec 351 Limit uint32 352 Buffer uint32 353 Mtu uint32 354 } 355 356 func (msg *TcTbfQopt) Len() int { 357 return SizeofTcTbfQopt 358 } 359 360 func DeserializeTcTbfQopt(b []byte) *TcTbfQopt { 361 return (*TcTbfQopt)(unsafe.Pointer(&b[0:SizeofTcTbfQopt][0])) 362 } 363 364 func (x *TcTbfQopt) Serialize() []byte { 365 return (*(*[SizeofTcTbfQopt]byte)(unsafe.Pointer(x)))[:] 366 } 367 368 const ( 369 TCA_HTB_UNSPEC = iota 370 TCA_HTB_PARMS 371 TCA_HTB_INIT 372 TCA_HTB_CTAB 373 TCA_HTB_RTAB 374 TCA_HTB_DIRECT_QLEN 375 TCA_HTB_RATE64 376 TCA_HTB_CEIL64 377 TCA_HTB_MAX = TCA_HTB_CEIL64 378 ) 379 380 //struct tc_htb_opt { 381 // struct tc_ratespec rate; 382 // struct tc_ratespec ceil; 383 // __u32 buffer; 384 // __u32 cbuffer; 385 // __u32 quantum; 386 // __u32 level; /* out only */ 387 // __u32 prio; 388 //}; 389 390 type TcHtbCopt struct { 391 Rate TcRateSpec 392 Ceil TcRateSpec 393 Buffer uint32 394 Cbuffer uint32 395 Quantum uint32 396 Level uint32 397 Prio uint32 398 } 399 400 func (msg *TcHtbCopt) Len() int { 401 return SizeofTcHtbCopt 402 } 403 404 func DeserializeTcHtbCopt(b []byte) *TcHtbCopt { 405 return (*TcHtbCopt)(unsafe.Pointer(&b[0:SizeofTcHtbCopt][0])) 406 } 407 408 func (x *TcHtbCopt) Serialize() []byte { 409 return (*(*[SizeofTcHtbCopt]byte)(unsafe.Pointer(x)))[:] 410 } 411 412 type TcHtbGlob struct { 413 Version uint32 414 Rate2Quantum uint32 415 Defcls uint32 416 Debug uint32 417 DirectPkts uint32 418 } 419 420 func (msg *TcHtbGlob) Len() int { 421 return SizeofTcHtbGlob 422 } 423 424 func DeserializeTcHtbGlob(b []byte) *TcHtbGlob { 425 return (*TcHtbGlob)(unsafe.Pointer(&b[0:SizeofTcHtbGlob][0])) 426 } 427 428 func (x *TcHtbGlob) Serialize() []byte { 429 return (*(*[SizeofTcHtbGlob]byte)(unsafe.Pointer(x)))[:] 430 } 431 432 // HFSC 433 434 type Curve struct { 435 m1 uint32 436 d uint32 437 m2 uint32 438 } 439 440 type HfscCopt struct { 441 Rsc Curve 442 Fsc Curve 443 Usc Curve 444 } 445 446 func (c *Curve) Attrs() (uint32, uint32, uint32) { 447 return c.m1, c.d, c.m2 448 } 449 450 func (c *Curve) Set(m1 uint32, d uint32, m2 uint32) { 451 c.m1 = m1 452 c.d = d 453 c.m2 = m2 454 } 455 456 func DeserializeHfscCurve(b []byte) *Curve { 457 return &Curve{ 458 m1: binary.LittleEndian.Uint32(b[0:4]), 459 d: binary.LittleEndian.Uint32(b[4:8]), 460 m2: binary.LittleEndian.Uint32(b[8:12]), 461 } 462 } 463 464 func SerializeHfscCurve(c *Curve) (b []byte) { 465 t := make([]byte, binary.MaxVarintLen32) 466 binary.LittleEndian.PutUint32(t, c.m1) 467 b = append(b, t[:4]...) 468 binary.LittleEndian.PutUint32(t, c.d) 469 b = append(b, t[:4]...) 470 binary.LittleEndian.PutUint32(t, c.m2) 471 b = append(b, t[:4]...) 472 return b 473 } 474 475 type TcHfscOpt struct { 476 Defcls uint16 477 } 478 479 func (x *TcHfscOpt) Serialize() []byte { 480 return (*(*[2]byte)(unsafe.Pointer(x)))[:] 481 } 482 483 const ( 484 TCA_U32_UNSPEC = iota 485 TCA_U32_CLASSID 486 TCA_U32_HASH 487 TCA_U32_LINK 488 TCA_U32_DIVISOR 489 TCA_U32_SEL 490 TCA_U32_POLICE 491 TCA_U32_ACT 492 TCA_U32_INDEV 493 TCA_U32_PCNT 494 TCA_U32_MARK 495 TCA_U32_MAX = TCA_U32_MARK 496 ) 497 498 // struct tc_u32_key { 499 // __be32 mask; 500 // __be32 val; 501 // int off; 502 // int offmask; 503 // }; 504 505 type TcU32Key struct { 506 Mask uint32 // big endian 507 Val uint32 // big endian 508 Off int32 509 OffMask int32 510 } 511 512 func (msg *TcU32Key) Len() int { 513 return SizeofTcU32Key 514 } 515 516 func DeserializeTcU32Key(b []byte) *TcU32Key { 517 return (*TcU32Key)(unsafe.Pointer(&b[0:SizeofTcU32Key][0])) 518 } 519 520 func (x *TcU32Key) Serialize() []byte { 521 return (*(*[SizeofTcU32Key]byte)(unsafe.Pointer(x)))[:] 522 } 523 524 // struct tc_u32_sel { 525 // unsigned char flags; 526 // unsigned char offshift; 527 // unsigned char nkeys; 528 // 529 // __be16 offmask; 530 // __u16 off; 531 // short offoff; 532 // 533 // short hoff; 534 // __be32 hmask; 535 // struct tc_u32_key keys[0]; 536 // }; 537 538 const ( 539 TC_U32_TERMINAL = 1 << iota 540 TC_U32_OFFSET = 1 << iota 541 TC_U32_VAROFFSET = 1 << iota 542 TC_U32_EAT = 1 << iota 543 ) 544 545 type TcU32Sel struct { 546 Flags uint8 547 Offshift uint8 548 Nkeys uint8 549 Pad uint8 550 Offmask uint16 // big endian 551 Off uint16 552 Offoff int16 553 Hoff int16 554 Hmask uint32 // big endian 555 Keys []TcU32Key 556 } 557 558 func (msg *TcU32Sel) Len() int { 559 return SizeofTcU32Sel + int(msg.Nkeys)*SizeofTcU32Key 560 } 561 562 func DeserializeTcU32Sel(b []byte) *TcU32Sel { 563 x := &TcU32Sel{} 564 copy((*(*[SizeofTcU32Sel]byte)(unsafe.Pointer(x)))[:], b) 565 next := SizeofTcU32Sel 566 var i uint8 567 for i = 0; i < x.Nkeys; i++ { 568 x.Keys = append(x.Keys, *DeserializeTcU32Key(b[next:])) 569 next += SizeofTcU32Key 570 } 571 return x 572 } 573 574 func (x *TcU32Sel) Serialize() []byte { 575 // This can't just unsafe.cast because it must iterate through keys. 576 buf := make([]byte, x.Len()) 577 copy(buf, (*(*[SizeofTcU32Sel]byte)(unsafe.Pointer(x)))[:]) 578 next := SizeofTcU32Sel 579 for _, key := range x.Keys { 580 keyBuf := key.Serialize() 581 copy(buf[next:], keyBuf) 582 next += SizeofTcU32Key 583 } 584 return buf 585 } 586 587 type TcGen struct { 588 Index uint32 589 Capab uint32 590 Action int32 591 Refcnt int32 592 Bindcnt int32 593 } 594 595 func (msg *TcGen) Len() int { 596 return SizeofTcGen 597 } 598 599 func DeserializeTcGen(b []byte) *TcGen { 600 return (*TcGen)(unsafe.Pointer(&b[0:SizeofTcGen][0])) 601 } 602 603 func (x *TcGen) Serialize() []byte { 604 return (*(*[SizeofTcGen]byte)(unsafe.Pointer(x)))[:] 605 } 606 607 // #define tc_gen \ 608 // __u32 index; \ 609 // __u32 capab; \ 610 // int action; \ 611 // int refcnt; \ 612 // int bindcnt 613 614 const ( 615 TCA_ACT_GACT = 5 616 ) 617 618 const ( 619 TCA_GACT_UNSPEC = iota 620 TCA_GACT_TM 621 TCA_GACT_PARMS 622 TCA_GACT_PROB 623 TCA_GACT_MAX = TCA_GACT_PROB 624 ) 625 626 type TcGact TcGen 627 628 const ( 629 TCA_ACT_BPF = 13 630 ) 631 632 const ( 633 TCA_ACT_BPF_UNSPEC = iota 634 TCA_ACT_BPF_TM 635 TCA_ACT_BPF_PARMS 636 TCA_ACT_BPF_OPS_LEN 637 TCA_ACT_BPF_OPS 638 TCA_ACT_BPF_FD 639 TCA_ACT_BPF_NAME 640 TCA_ACT_BPF_MAX = TCA_ACT_BPF_NAME 641 ) 642 643 const ( 644 TCA_BPF_FLAG_ACT_DIRECT uint32 = 1 << iota 645 ) 646 647 const ( 648 TCA_BPF_UNSPEC = iota 649 TCA_BPF_ACT 650 TCA_BPF_POLICE 651 TCA_BPF_CLASSID 652 TCA_BPF_OPS_LEN 653 TCA_BPF_OPS 654 TCA_BPF_FD 655 TCA_BPF_NAME 656 TCA_BPF_FLAGS 657 TCA_BPF_FLAGS_GEN 658 TCA_BPF_TAG 659 TCA_BPF_ID 660 TCA_BPF_MAX = TCA_BPF_ID 661 ) 662 663 type TcBpf TcGen 664 665 const ( 666 TCA_ACT_CONNMARK = 14 667 ) 668 669 const ( 670 TCA_CONNMARK_UNSPEC = iota 671 TCA_CONNMARK_PARMS 672 TCA_CONNMARK_TM 673 TCA_CONNMARK_MAX = TCA_CONNMARK_TM 674 ) 675 676 // struct tc_connmark { 677 // tc_gen; 678 // __u16 zone; 679 // }; 680 681 type TcConnmark struct { 682 TcGen 683 Zone uint16 684 } 685 686 func (msg *TcConnmark) Len() int { 687 return SizeofTcConnmark 688 } 689 690 func DeserializeTcConnmark(b []byte) *TcConnmark { 691 return (*TcConnmark)(unsafe.Pointer(&b[0:SizeofTcConnmark][0])) 692 } 693 694 func (x *TcConnmark) Serialize() []byte { 695 return (*(*[SizeofTcConnmark]byte)(unsafe.Pointer(x)))[:] 696 } 697 698 const ( 699 TCA_CSUM_UNSPEC = iota 700 TCA_CSUM_PARMS 701 TCA_CSUM_TM 702 TCA_CSUM_PAD 703 TCA_CSUM_MAX = TCA_CSUM_PAD 704 ) 705 706 // struct tc_csum { 707 // tc_gen; 708 // __u32 update_flags; 709 // } 710 711 type TcCsum struct { 712 TcGen 713 UpdateFlags uint32 714 } 715 716 func (msg *TcCsum) Len() int { 717 return SizeofTcCsum 718 } 719 720 func DeserializeTcCsum(b []byte) *TcCsum { 721 return (*TcCsum)(unsafe.Pointer(&b[0:SizeofTcCsum][0])) 722 } 723 724 func (x *TcCsum) Serialize() []byte { 725 return (*(*[SizeofTcCsum]byte)(unsafe.Pointer(x)))[:] 726 } 727 728 const ( 729 TCA_ACT_MIRRED = 8 730 ) 731 732 const ( 733 TCA_MIRRED_UNSPEC = iota 734 TCA_MIRRED_TM 735 TCA_MIRRED_PARMS 736 TCA_MIRRED_MAX = TCA_MIRRED_PARMS 737 ) 738 739 // struct tc_mirred { 740 // tc_gen; 741 // int eaction; /* one of IN/EGRESS_MIRROR/REDIR */ 742 // __u32 ifindex; /* ifindex of egress port */ 743 // }; 744 745 type TcMirred struct { 746 TcGen 747 Eaction int32 748 Ifindex uint32 749 } 750 751 func (msg *TcMirred) Len() int { 752 return SizeofTcMirred 753 } 754 755 func DeserializeTcMirred(b []byte) *TcMirred { 756 return (*TcMirred)(unsafe.Pointer(&b[0:SizeofTcMirred][0])) 757 } 758 759 func (x *TcMirred) Serialize() []byte { 760 return (*(*[SizeofTcMirred]byte)(unsafe.Pointer(x)))[:] 761 } 762 763 const ( 764 TCA_TUNNEL_KEY_UNSPEC = iota 765 TCA_TUNNEL_KEY_TM 766 TCA_TUNNEL_KEY_PARMS 767 TCA_TUNNEL_KEY_ENC_IPV4_SRC 768 TCA_TUNNEL_KEY_ENC_IPV4_DST 769 TCA_TUNNEL_KEY_ENC_IPV6_SRC 770 TCA_TUNNEL_KEY_ENC_IPV6_DST 771 TCA_TUNNEL_KEY_ENC_KEY_ID 772 TCA_TUNNEL_KEY_PAD 773 TCA_TUNNEL_KEY_ENC_DST_PORT 774 TCA_TUNNEL_KEY_NO_CSUM 775 TCA_TUNNEL_KEY_ENC_OPTS 776 TCA_TUNNEL_KEY_ENC_TOS 777 TCA_TUNNEL_KEY_ENC_TTL 778 TCA_TUNNEL_KEY_MAX 779 ) 780 781 type TcTunnelKey struct { 782 TcGen 783 Action int32 784 } 785 786 func (x *TcTunnelKey) Len() int { 787 return SizeofTcTunnelKey 788 } 789 790 func DeserializeTunnelKey(b []byte) *TcTunnelKey { 791 return (*TcTunnelKey)(unsafe.Pointer(&b[0:SizeofTcTunnelKey][0])) 792 } 793 794 func (x *TcTunnelKey) Serialize() []byte { 795 return (*(*[SizeofTcTunnelKey]byte)(unsafe.Pointer(x)))[:] 796 } 797 798 const ( 799 TCA_SKBEDIT_UNSPEC = iota 800 TCA_SKBEDIT_TM 801 TCA_SKBEDIT_PARMS 802 TCA_SKBEDIT_PRIORITY 803 TCA_SKBEDIT_QUEUE_MAPPING 804 TCA_SKBEDIT_MARK 805 TCA_SKBEDIT_PAD 806 TCA_SKBEDIT_PTYPE 807 TCA_SKBEDIT_MAX = TCA_SKBEDIT_MARK 808 ) 809 810 type TcSkbEdit struct { 811 TcGen 812 } 813 814 func (x *TcSkbEdit) Len() int { 815 return SizeofTcSkbEdit 816 } 817 818 func DeserializeSkbEdit(b []byte) *TcSkbEdit { 819 return (*TcSkbEdit)(unsafe.Pointer(&b[0:SizeofTcSkbEdit][0])) 820 } 821 822 func (x *TcSkbEdit) Serialize() []byte { 823 return (*(*[SizeofTcSkbEdit]byte)(unsafe.Pointer(x)))[:] 824 } 825 826 // struct tc_police { 827 // __u32 index; 828 // int action; 829 // __u32 limit; 830 // __u32 burst; 831 // __u32 mtu; 832 // struct tc_ratespec rate; 833 // struct tc_ratespec peakrate; 834 // int refcnt; 835 // int bindcnt; 836 // __u32 capab; 837 // }; 838 839 type TcPolice struct { 840 Index uint32 841 Action int32 842 Limit uint32 843 Burst uint32 844 Mtu uint32 845 Rate TcRateSpec 846 PeakRate TcRateSpec 847 Refcnt int32 848 Bindcnt int32 849 Capab uint32 850 } 851 852 func (msg *TcPolice) Len() int { 853 return SizeofTcPolice 854 } 855 856 func DeserializeTcPolice(b []byte) *TcPolice { 857 return (*TcPolice)(unsafe.Pointer(&b[0:SizeofTcPolice][0])) 858 } 859 860 func (x *TcPolice) Serialize() []byte { 861 return (*(*[SizeofTcPolice]byte)(unsafe.Pointer(x)))[:] 862 } 863 864 const ( 865 TCA_FW_UNSPEC = iota 866 TCA_FW_CLASSID 867 TCA_FW_POLICE 868 TCA_FW_INDEV 869 TCA_FW_ACT 870 TCA_FW_MASK 871 TCA_FW_MAX = TCA_FW_MASK 872 ) 873 874 const ( 875 TCA_MATCHALL_UNSPEC = iota 876 TCA_MATCHALL_CLASSID 877 TCA_MATCHALL_ACT 878 TCA_MATCHALL_FLAGS 879 ) 880 881 const ( 882 TCA_FQ_UNSPEC = iota 883 TCA_FQ_PLIMIT // limit of total number of packets in queue 884 TCA_FQ_FLOW_PLIMIT // limit of packets per flow 885 TCA_FQ_QUANTUM // RR quantum 886 TCA_FQ_INITIAL_QUANTUM // RR quantum for new flow 887 TCA_FQ_RATE_ENABLE // enable/disable rate limiting 888 TCA_FQ_FLOW_DEFAULT_RATE // obsolete do not use 889 TCA_FQ_FLOW_MAX_RATE // per flow max rate 890 TCA_FQ_BUCKETS_LOG // log2(number of buckets) 891 TCA_FQ_FLOW_REFILL_DELAY // flow credit refill delay in usec 892 TCA_FQ_ORPHAN_MASK // mask applied to orphaned skb hashes 893 TCA_FQ_LOW_RATE_THRESHOLD // per packet delay under this rate 894 TCA_FQ_CE_THRESHOLD // DCTCP-like CE-marking threshold 895 TCA_FQ_TIMER_SLACK // timer slack 896 TCA_FQ_HORIZON // time horizon in us 897 TCA_FQ_HORIZON_DROP // drop packets beyond horizon, or cap their EDT 898 ) 899 900 const ( 901 TCA_FQ_CODEL_UNSPEC = iota 902 TCA_FQ_CODEL_TARGET 903 TCA_FQ_CODEL_LIMIT 904 TCA_FQ_CODEL_INTERVAL 905 TCA_FQ_CODEL_ECN 906 TCA_FQ_CODEL_FLOWS 907 TCA_FQ_CODEL_QUANTUM 908 TCA_FQ_CODEL_CE_THRESHOLD 909 TCA_FQ_CODEL_DROP_BATCH_SIZE 910 TCA_FQ_CODEL_MEMORY_LIMIT 911 ) 912 913 const ( 914 TCA_HFSC_UNSPEC = iota 915 TCA_HFSC_RSC 916 TCA_HFSC_FSC 917 TCA_HFSC_USC 918 ) 919 920 const ( 921 TCA_FLOWER_UNSPEC = iota 922 TCA_FLOWER_CLASSID 923 TCA_FLOWER_INDEV 924 TCA_FLOWER_ACT 925 TCA_FLOWER_KEY_ETH_DST /* ETH_ALEN */ 926 TCA_FLOWER_KEY_ETH_DST_MASK /* ETH_ALEN */ 927 TCA_FLOWER_KEY_ETH_SRC /* ETH_ALEN */ 928 TCA_FLOWER_KEY_ETH_SRC_MASK /* ETH_ALEN */ 929 TCA_FLOWER_KEY_ETH_TYPE /* be16 */ 930 TCA_FLOWER_KEY_IP_PROTO /* u8 */ 931 TCA_FLOWER_KEY_IPV4_SRC /* be32 */ 932 TCA_FLOWER_KEY_IPV4_SRC_MASK /* be32 */ 933 TCA_FLOWER_KEY_IPV4_DST /* be32 */ 934 TCA_FLOWER_KEY_IPV4_DST_MASK /* be32 */ 935 TCA_FLOWER_KEY_IPV6_SRC /* struct in6_addr */ 936 TCA_FLOWER_KEY_IPV6_SRC_MASK /* struct in6_addr */ 937 TCA_FLOWER_KEY_IPV6_DST /* struct in6_addr */ 938 TCA_FLOWER_KEY_IPV6_DST_MASK /* struct in6_addr */ 939 TCA_FLOWER_KEY_TCP_SRC /* be16 */ 940 TCA_FLOWER_KEY_TCP_DST /* be16 */ 941 TCA_FLOWER_KEY_UDP_SRC /* be16 */ 942 TCA_FLOWER_KEY_UDP_DST /* be16 */ 943 944 TCA_FLOWER_FLAGS 945 TCA_FLOWER_KEY_VLAN_ID /* be16 */ 946 TCA_FLOWER_KEY_VLAN_PRIO /* u8 */ 947 TCA_FLOWER_KEY_VLAN_ETH_TYPE /* be16 */ 948 949 TCA_FLOWER_KEY_ENC_KEY_ID /* be32 */ 950 TCA_FLOWER_KEY_ENC_IPV4_SRC /* be32 */ 951 TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK /* be32 */ 952 TCA_FLOWER_KEY_ENC_IPV4_DST /* be32 */ 953 TCA_FLOWER_KEY_ENC_IPV4_DST_MASK /* be32 */ 954 TCA_FLOWER_KEY_ENC_IPV6_SRC /* struct in6_addr */ 955 TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK /* struct in6_addr */ 956 TCA_FLOWER_KEY_ENC_IPV6_DST /* struct in6_addr */ 957 TCA_FLOWER_KEY_ENC_IPV6_DST_MASK /* struct in6_addr */ 958 959 TCA_FLOWER_KEY_TCP_SRC_MASK /* be16 */ 960 TCA_FLOWER_KEY_TCP_DST_MASK /* be16 */ 961 TCA_FLOWER_KEY_UDP_SRC_MASK /* be16 */ 962 TCA_FLOWER_KEY_UDP_DST_MASK /* be16 */ 963 TCA_FLOWER_KEY_SCTP_SRC_MASK /* be16 */ 964 TCA_FLOWER_KEY_SCTP_DST_MASK /* be16 */ 965 966 TCA_FLOWER_KEY_SCTP_SRC /* be16 */ 967 TCA_FLOWER_KEY_SCTP_DST /* be16 */ 968 969 TCA_FLOWER_KEY_ENC_UDP_SRC_PORT /* be16 */ 970 TCA_FLOWER_KEY_ENC_UDP_SRC_PORT_MASK /* be16 */ 971 TCA_FLOWER_KEY_ENC_UDP_DST_PORT /* be16 */ 972 TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK /* be16 */ 973 974 TCA_FLOWER_KEY_FLAGS /* be32 */ 975 TCA_FLOWER_KEY_FLAGS_MASK /* be32 */ 976 977 TCA_FLOWER_KEY_ICMPV4_CODE /* u8 */ 978 TCA_FLOWER_KEY_ICMPV4_CODE_MASK /* u8 */ 979 TCA_FLOWER_KEY_ICMPV4_TYPE /* u8 */ 980 TCA_FLOWER_KEY_ICMPV4_TYPE_MASK /* u8 */ 981 TCA_FLOWER_KEY_ICMPV6_CODE /* u8 */ 982 TCA_FLOWER_KEY_ICMPV6_CODE_MASK /* u8 */ 983 TCA_FLOWER_KEY_ICMPV6_TYPE /* u8 */ 984 TCA_FLOWER_KEY_ICMPV6_TYPE_MASK /* u8 */ 985 986 TCA_FLOWER_KEY_ARP_SIP /* be32 */ 987 TCA_FLOWER_KEY_ARP_SIP_MASK /* be32 */ 988 TCA_FLOWER_KEY_ARP_TIP /* be32 */ 989 TCA_FLOWER_KEY_ARP_TIP_MASK /* be32 */ 990 TCA_FLOWER_KEY_ARP_OP /* u8 */ 991 TCA_FLOWER_KEY_ARP_OP_MASK /* u8 */ 992 TCA_FLOWER_KEY_ARP_SHA /* ETH_ALEN */ 993 TCA_FLOWER_KEY_ARP_SHA_MASK /* ETH_ALEN */ 994 TCA_FLOWER_KEY_ARP_THA /* ETH_ALEN */ 995 TCA_FLOWER_KEY_ARP_THA_MASK /* ETH_ALEN */ 996 997 TCA_FLOWER_KEY_MPLS_TTL /* u8 - 8 bits */ 998 TCA_FLOWER_KEY_MPLS_BOS /* u8 - 1 bit */ 999 TCA_FLOWER_KEY_MPLS_TC /* u8 - 3 bits */ 1000 TCA_FLOWER_KEY_MPLS_LABEL /* be32 - 20 bits */ 1001 1002 TCA_FLOWER_KEY_TCP_FLAGS /* be16 */ 1003 TCA_FLOWER_KEY_TCP_FLAGS_MASK /* be16 */ 1004 1005 TCA_FLOWER_KEY_IP_TOS /* u8 */ 1006 TCA_FLOWER_KEY_IP_TOS_MASK /* u8 */ 1007 TCA_FLOWER_KEY_IP_TTL /* u8 */ 1008 TCA_FLOWER_KEY_IP_TTL_MASK /* u8 */ 1009 1010 TCA_FLOWER_KEY_CVLAN_ID /* be16 */ 1011 TCA_FLOWER_KEY_CVLAN_PRIO /* u8 */ 1012 TCA_FLOWER_KEY_CVLAN_ETH_TYPE /* be16 */ 1013 1014 TCA_FLOWER_KEY_ENC_IP_TOS /* u8 */ 1015 TCA_FLOWER_KEY_ENC_IP_TOS_MASK /* u8 */ 1016 TCA_FLOWER_KEY_ENC_IP_TTL /* u8 */ 1017 TCA_FLOWER_KEY_ENC_IP_TTL_MASK /* u8 */ 1018 1019 TCA_FLOWER_KEY_ENC_OPTS 1020 TCA_FLOWER_KEY_ENC_OPTS_MASK 1021 1022 __TCA_FLOWER_MAX 1023 ) 1024 1025 // struct tc_sfq_qopt { 1026 // unsigned quantum; /* Bytes per round allocated to flow */ 1027 // int perturb_period; /* Period of hash perturbation */ 1028 // __u32 limit; /* Maximal packets in queue */ 1029 // unsigned divisor; /* Hash divisor */ 1030 // unsigned flows; /* Maximal number of flows */ 1031 // }; 1032 1033 type TcSfqQopt struct { 1034 Quantum uint8 1035 Perturb int32 1036 Limit uint32 1037 Divisor uint8 1038 Flows uint8 1039 } 1040 1041 func (x *TcSfqQopt) Len() int { 1042 return SizeofTcSfqQopt 1043 } 1044 1045 func DeserializeTcSfqQopt(b []byte) *TcSfqQopt { 1046 return (*TcSfqQopt)(unsafe.Pointer(&b[0:SizeofTcSfqQopt][0])) 1047 } 1048 1049 func (x *TcSfqQopt) Serialize() []byte { 1050 return (*(*[SizeofTcSfqQopt]byte)(unsafe.Pointer(x)))[:] 1051 } 1052 1053 // struct tc_sfqred_stats { 1054 // __u32 prob_drop; /* Early drops, below max threshold */ 1055 // __u32 forced_drop; /* Early drops, after max threshold */ 1056 // __u32 prob_mark; /* Marked packets, below max threshold */ 1057 // __u32 forced_mark; /* Marked packets, after max threshold */ 1058 // __u32 prob_mark_head; /* Marked packets, below max threshold */ 1059 // __u32 forced_mark_head;/* Marked packets, after max threshold */ 1060 // }; 1061 type TcSfqRedStats struct { 1062 ProbDrop uint32 1063 ForcedDrop uint32 1064 ProbMark uint32 1065 ForcedMark uint32 1066 ProbMarkHead uint32 1067 ForcedMarkHead uint32 1068 } 1069 1070 func (x *TcSfqRedStats) Len() int { 1071 return SizeofTcSfqRedStats 1072 } 1073 1074 func DeserializeTcSfqRedStats(b []byte) *TcSfqRedStats { 1075 return (*TcSfqRedStats)(unsafe.Pointer(&b[0:SizeofTcSfqRedStats][0])) 1076 } 1077 1078 func (x *TcSfqRedStats) Serialize() []byte { 1079 return (*(*[SizeofTcSfqRedStats]byte)(unsafe.Pointer(x)))[:] 1080 } 1081 1082 // struct tc_sfq_qopt_v1 { 1083 // struct tc_sfq_qopt v0; 1084 // unsigned int depth; /* max number of packets per flow */ 1085 // unsigned int headdrop; 1086 // 1087 // /* SFQRED parameters */ 1088 // 1089 // __u32 limit; /* HARD maximal flow queue length (bytes) */ 1090 // __u32 qth_min; /* Min average length threshold (bytes) */ 1091 // __u32 qth_max; /* Max average length threshold (bytes) */ 1092 // unsigned char Wlog; /* log(W) */ 1093 // unsigned char Plog; /* log(P_max/(qth_max-qth_min)) */ 1094 // unsigned char Scell_log; /* cell size for idle damping */ 1095 // unsigned char flags; 1096 // __u32 max_P; /* probability, high resolution */ 1097 // 1098 // /* SFQRED stats */ 1099 // 1100 // struct tc_sfqred_stats stats; 1101 // }; 1102 type TcSfqQoptV1 struct { 1103 TcSfqQopt 1104 Depth uint32 1105 HeadDrop uint32 1106 Limit uint32 1107 QthMin uint32 1108 QthMax uint32 1109 Wlog byte 1110 Plog byte 1111 ScellLog byte 1112 Flags byte 1113 MaxP uint32 1114 TcSfqRedStats 1115 } 1116 1117 func (x *TcSfqQoptV1) Len() int { 1118 return SizeofTcSfqQoptV1 1119 } 1120 1121 func DeserializeTcSfqQoptV1(b []byte) *TcSfqQoptV1 { 1122 return (*TcSfqQoptV1)(unsafe.Pointer(&b[0:SizeofTcSfqQoptV1][0])) 1123 } 1124 1125 func (x *TcSfqQoptV1) Serialize() []byte { 1126 return (*(*[SizeofTcSfqQoptV1]byte)(unsafe.Pointer(x)))[:] 1127 }