tc_linux.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. package nl
  2. import (
  3. "encoding/binary"
  4. "unsafe"
  5. )
  6. // LinkLayer
  7. const (
  8. LINKLAYER_UNSPEC = iota
  9. LINKLAYER_ETHERNET
  10. LINKLAYER_ATM
  11. )
  12. // ATM
  13. const (
  14. ATM_CELL_PAYLOAD = 48
  15. ATM_CELL_SIZE = 53
  16. )
  17. const TC_LINKLAYER_MASK = 0x0F
  18. // Police
  19. const (
  20. TCA_POLICE_UNSPEC = iota
  21. TCA_POLICE_TBF
  22. TCA_POLICE_RATE
  23. TCA_POLICE_PEAKRATE
  24. TCA_POLICE_AVRATE
  25. TCA_POLICE_RESULT
  26. TCA_POLICE_MAX = TCA_POLICE_RESULT
  27. )
  28. // Message types
  29. const (
  30. TCA_UNSPEC = iota
  31. TCA_KIND
  32. TCA_OPTIONS
  33. TCA_STATS
  34. TCA_XSTATS
  35. TCA_RATE
  36. TCA_FCNT
  37. TCA_STATS2
  38. TCA_STAB
  39. TCA_MAX = TCA_STAB
  40. )
  41. const (
  42. TCA_ACT_TAB = 1
  43. TCAA_MAX = 1
  44. )
  45. const (
  46. TCA_ACT_UNSPEC = iota
  47. TCA_ACT_KIND
  48. TCA_ACT_OPTIONS
  49. TCA_ACT_INDEX
  50. TCA_ACT_STATS
  51. TCA_ACT_MAX
  52. )
  53. const (
  54. TCA_PRIO_UNSPEC = iota
  55. TCA_PRIO_MQ
  56. TCA_PRIO_MAX = TCA_PRIO_MQ
  57. )
  58. const (
  59. TCA_STATS_UNSPEC = iota
  60. TCA_STATS_BASIC
  61. TCA_STATS_RATE_EST
  62. TCA_STATS_QUEUE
  63. TCA_STATS_APP
  64. TCA_STATS_MAX = TCA_STATS_APP
  65. )
  66. const (
  67. SizeofTcMsg = 0x14
  68. SizeofTcActionMsg = 0x04
  69. SizeofTcPrioMap = 0x14
  70. SizeofTcRateSpec = 0x0c
  71. SizeofTcNetemQopt = 0x18
  72. SizeofTcNetemCorr = 0x0c
  73. SizeofTcNetemReorder = 0x08
  74. SizeofTcNetemCorrupt = 0x08
  75. SizeofTcTbfQopt = 2*SizeofTcRateSpec + 0x0c
  76. SizeofTcHtbCopt = 2*SizeofTcRateSpec + 0x14
  77. SizeofTcHtbGlob = 0x14
  78. SizeofTcU32Key = 0x10
  79. SizeofTcU32Sel = 0x10 // without keys
  80. SizeofTcGen = 0x14
  81. SizeofTcConnmark = SizeofTcGen + 0x04
  82. SizeofTcMirred = SizeofTcGen + 0x08
  83. SizeofTcTunnelKey = SizeofTcGen + 0x04
  84. SizeofTcSkbEdit = SizeofTcGen
  85. SizeofTcPolice = 2*SizeofTcRateSpec + 0x20
  86. SizeofTcSfqQopt = 0x0b
  87. SizeofTcSfqRedStats = 0x18
  88. SizeofTcSfqQoptV1 = SizeofTcSfqQopt + SizeofTcSfqRedStats + 0x1c
  89. )
  90. // struct tcmsg {
  91. // unsigned char tcm_family;
  92. // unsigned char tcm__pad1;
  93. // unsigned short tcm__pad2;
  94. // int tcm_ifindex;
  95. // __u32 tcm_handle;
  96. // __u32 tcm_parent;
  97. // __u32 tcm_info;
  98. // };
  99. type TcMsg struct {
  100. Family uint8
  101. Pad [3]byte
  102. Ifindex int32
  103. Handle uint32
  104. Parent uint32
  105. Info uint32
  106. }
  107. func (msg *TcMsg) Len() int {
  108. return SizeofTcMsg
  109. }
  110. func DeserializeTcMsg(b []byte) *TcMsg {
  111. return (*TcMsg)(unsafe.Pointer(&b[0:SizeofTcMsg][0]))
  112. }
  113. func (x *TcMsg) Serialize() []byte {
  114. return (*(*[SizeofTcMsg]byte)(unsafe.Pointer(x)))[:]
  115. }
  116. // struct tcamsg {
  117. // unsigned char tca_family;
  118. // unsigned char tca__pad1;
  119. // unsigned short tca__pad2;
  120. // };
  121. type TcActionMsg struct {
  122. Family uint8
  123. Pad [3]byte
  124. }
  125. func (msg *TcActionMsg) Len() int {
  126. return SizeofTcActionMsg
  127. }
  128. func DeserializeTcActionMsg(b []byte) *TcActionMsg {
  129. return (*TcActionMsg)(unsafe.Pointer(&b[0:SizeofTcActionMsg][0]))
  130. }
  131. func (x *TcActionMsg) Serialize() []byte {
  132. return (*(*[SizeofTcActionMsg]byte)(unsafe.Pointer(x)))[:]
  133. }
  134. const (
  135. TC_PRIO_MAX = 15
  136. )
  137. // struct tc_prio_qopt {
  138. // int bands; /* Number of bands */
  139. // __u8 priomap[TC_PRIO_MAX+1]; /* Map: logical priority -> PRIO band */
  140. // };
  141. type TcPrioMap struct {
  142. Bands int32
  143. Priomap [TC_PRIO_MAX + 1]uint8
  144. }
  145. func (msg *TcPrioMap) Len() int {
  146. return SizeofTcPrioMap
  147. }
  148. func DeserializeTcPrioMap(b []byte) *TcPrioMap {
  149. return (*TcPrioMap)(unsafe.Pointer(&b[0:SizeofTcPrioMap][0]))
  150. }
  151. func (x *TcPrioMap) Serialize() []byte {
  152. return (*(*[SizeofTcPrioMap]byte)(unsafe.Pointer(x)))[:]
  153. }
  154. const (
  155. TCA_TBF_UNSPEC = iota
  156. TCA_TBF_PARMS
  157. TCA_TBF_RTAB
  158. TCA_TBF_PTAB
  159. TCA_TBF_RATE64
  160. TCA_TBF_PRATE64
  161. TCA_TBF_BURST
  162. TCA_TBF_PBURST
  163. TCA_TBF_MAX = TCA_TBF_PBURST
  164. )
  165. // struct tc_ratespec {
  166. // unsigned char cell_log;
  167. // __u8 linklayer; /* lower 4 bits */
  168. // unsigned short overhead;
  169. // short cell_align;
  170. // unsigned short mpu;
  171. // __u32 rate;
  172. // };
  173. type TcRateSpec struct {
  174. CellLog uint8
  175. Linklayer uint8
  176. Overhead uint16
  177. CellAlign int16
  178. Mpu uint16
  179. Rate uint32
  180. }
  181. func (msg *TcRateSpec) Len() int {
  182. return SizeofTcRateSpec
  183. }
  184. func DeserializeTcRateSpec(b []byte) *TcRateSpec {
  185. return (*TcRateSpec)(unsafe.Pointer(&b[0:SizeofTcRateSpec][0]))
  186. }
  187. func (x *TcRateSpec) Serialize() []byte {
  188. return (*(*[SizeofTcRateSpec]byte)(unsafe.Pointer(x)))[:]
  189. }
  190. /**
  191. * NETEM
  192. */
  193. const (
  194. TCA_NETEM_UNSPEC = iota
  195. TCA_NETEM_CORR
  196. TCA_NETEM_DELAY_DIST
  197. TCA_NETEM_REORDER
  198. TCA_NETEM_CORRUPT
  199. TCA_NETEM_LOSS
  200. TCA_NETEM_RATE
  201. TCA_NETEM_ECN
  202. TCA_NETEM_RATE64
  203. TCA_NETEM_MAX = TCA_NETEM_RATE64
  204. )
  205. // struct tc_netem_qopt {
  206. // __u32 latency; /* added delay (us) */
  207. // __u32 limit; /* fifo limit (packets) */
  208. // __u32 loss; /* random packet loss (0=none ~0=100%) */
  209. // __u32 gap; /* re-ordering gap (0 for none) */
  210. // __u32 duplicate; /* random packet dup (0=none ~0=100%) */
  211. // __u32 jitter; /* random jitter in latency (us) */
  212. // };
  213. type TcNetemQopt struct {
  214. Latency uint32
  215. Limit uint32
  216. Loss uint32
  217. Gap uint32
  218. Duplicate uint32
  219. Jitter uint32
  220. }
  221. func (msg *TcNetemQopt) Len() int {
  222. return SizeofTcNetemQopt
  223. }
  224. func DeserializeTcNetemQopt(b []byte) *TcNetemQopt {
  225. return (*TcNetemQopt)(unsafe.Pointer(&b[0:SizeofTcNetemQopt][0]))
  226. }
  227. func (x *TcNetemQopt) Serialize() []byte {
  228. return (*(*[SizeofTcNetemQopt]byte)(unsafe.Pointer(x)))[:]
  229. }
  230. // struct tc_netem_corr {
  231. // __u32 delay_corr; /* delay correlation */
  232. // __u32 loss_corr; /* packet loss correlation */
  233. // __u32 dup_corr; /* duplicate correlation */
  234. // };
  235. type TcNetemCorr struct {
  236. DelayCorr uint32
  237. LossCorr uint32
  238. DupCorr uint32
  239. }
  240. func (msg *TcNetemCorr) Len() int {
  241. return SizeofTcNetemCorr
  242. }
  243. func DeserializeTcNetemCorr(b []byte) *TcNetemCorr {
  244. return (*TcNetemCorr)(unsafe.Pointer(&b[0:SizeofTcNetemCorr][0]))
  245. }
  246. func (x *TcNetemCorr) Serialize() []byte {
  247. return (*(*[SizeofTcNetemCorr]byte)(unsafe.Pointer(x)))[:]
  248. }
  249. // struct tc_netem_reorder {
  250. // __u32 probability;
  251. // __u32 correlation;
  252. // };
  253. type TcNetemReorder struct {
  254. Probability uint32
  255. Correlation uint32
  256. }
  257. func (msg *TcNetemReorder) Len() int {
  258. return SizeofTcNetemReorder
  259. }
  260. func DeserializeTcNetemReorder(b []byte) *TcNetemReorder {
  261. return (*TcNetemReorder)(unsafe.Pointer(&b[0:SizeofTcNetemReorder][0]))
  262. }
  263. func (x *TcNetemReorder) Serialize() []byte {
  264. return (*(*[SizeofTcNetemReorder]byte)(unsafe.Pointer(x)))[:]
  265. }
  266. // struct tc_netem_corrupt {
  267. // __u32 probability;
  268. // __u32 correlation;
  269. // };
  270. type TcNetemCorrupt struct {
  271. Probability uint32
  272. Correlation uint32
  273. }
  274. func (msg *TcNetemCorrupt) Len() int {
  275. return SizeofTcNetemCorrupt
  276. }
  277. func DeserializeTcNetemCorrupt(b []byte) *TcNetemCorrupt {
  278. return (*TcNetemCorrupt)(unsafe.Pointer(&b[0:SizeofTcNetemCorrupt][0]))
  279. }
  280. func (x *TcNetemCorrupt) Serialize() []byte {
  281. return (*(*[SizeofTcNetemCorrupt]byte)(unsafe.Pointer(x)))[:]
  282. }
  283. // struct tc_tbf_qopt {
  284. // struct tc_ratespec rate;
  285. // struct tc_ratespec peakrate;
  286. // __u32 limit;
  287. // __u32 buffer;
  288. // __u32 mtu;
  289. // };
  290. type TcTbfQopt struct {
  291. Rate TcRateSpec
  292. Peakrate TcRateSpec
  293. Limit uint32
  294. Buffer uint32
  295. Mtu uint32
  296. }
  297. func (msg *TcTbfQopt) Len() int {
  298. return SizeofTcTbfQopt
  299. }
  300. func DeserializeTcTbfQopt(b []byte) *TcTbfQopt {
  301. return (*TcTbfQopt)(unsafe.Pointer(&b[0:SizeofTcTbfQopt][0]))
  302. }
  303. func (x *TcTbfQopt) Serialize() []byte {
  304. return (*(*[SizeofTcTbfQopt]byte)(unsafe.Pointer(x)))[:]
  305. }
  306. const (
  307. TCA_HTB_UNSPEC = iota
  308. TCA_HTB_PARMS
  309. TCA_HTB_INIT
  310. TCA_HTB_CTAB
  311. TCA_HTB_RTAB
  312. TCA_HTB_DIRECT_QLEN
  313. TCA_HTB_RATE64
  314. TCA_HTB_CEIL64
  315. TCA_HTB_MAX = TCA_HTB_CEIL64
  316. )
  317. //struct tc_htb_opt {
  318. // struct tc_ratespec rate;
  319. // struct tc_ratespec ceil;
  320. // __u32 buffer;
  321. // __u32 cbuffer;
  322. // __u32 quantum;
  323. // __u32 level; /* out only */
  324. // __u32 prio;
  325. //};
  326. type TcHtbCopt struct {
  327. Rate TcRateSpec
  328. Ceil TcRateSpec
  329. Buffer uint32
  330. Cbuffer uint32
  331. Quantum uint32
  332. Level uint32
  333. Prio uint32
  334. }
  335. func (msg *TcHtbCopt) Len() int {
  336. return SizeofTcHtbCopt
  337. }
  338. func DeserializeTcHtbCopt(b []byte) *TcHtbCopt {
  339. return (*TcHtbCopt)(unsafe.Pointer(&b[0:SizeofTcHtbCopt][0]))
  340. }
  341. func (x *TcHtbCopt) Serialize() []byte {
  342. return (*(*[SizeofTcHtbCopt]byte)(unsafe.Pointer(x)))[:]
  343. }
  344. type TcHtbGlob struct {
  345. Version uint32
  346. Rate2Quantum uint32
  347. Defcls uint32
  348. Debug uint32
  349. DirectPkts uint32
  350. }
  351. func (msg *TcHtbGlob) Len() int {
  352. return SizeofTcHtbGlob
  353. }
  354. func DeserializeTcHtbGlob(b []byte) *TcHtbGlob {
  355. return (*TcHtbGlob)(unsafe.Pointer(&b[0:SizeofTcHtbGlob][0]))
  356. }
  357. func (x *TcHtbGlob) Serialize() []byte {
  358. return (*(*[SizeofTcHtbGlob]byte)(unsafe.Pointer(x)))[:]
  359. }
  360. // HFSC
  361. type Curve struct {
  362. m1 uint32
  363. d uint32
  364. m2 uint32
  365. }
  366. type HfscCopt struct {
  367. Rsc Curve
  368. Fsc Curve
  369. Usc Curve
  370. }
  371. func (c *Curve) Attrs() (uint32, uint32, uint32) {
  372. return c.m1, c.d, c.m2
  373. }
  374. func (c *Curve) Set(m1 uint32, d uint32, m2 uint32) {
  375. c.m1 = m1
  376. c.d = d
  377. c.m2 = m2
  378. }
  379. func DeserializeHfscCurve(b []byte) *Curve {
  380. return &Curve{
  381. m1: binary.LittleEndian.Uint32(b[0:4]),
  382. d: binary.LittleEndian.Uint32(b[4:8]),
  383. m2: binary.LittleEndian.Uint32(b[8:12]),
  384. }
  385. }
  386. func SerializeHfscCurve(c *Curve) (b []byte) {
  387. t := make([]byte, binary.MaxVarintLen32)
  388. binary.LittleEndian.PutUint32(t, c.m1)
  389. b = append(b, t[:4]...)
  390. binary.LittleEndian.PutUint32(t, c.d)
  391. b = append(b, t[:4]...)
  392. binary.LittleEndian.PutUint32(t, c.m2)
  393. b = append(b, t[:4]...)
  394. return b
  395. }
  396. type TcHfscOpt struct {
  397. Defcls uint16
  398. }
  399. func (x *TcHfscOpt) Serialize() []byte {
  400. return (*(*[2]byte)(unsafe.Pointer(x)))[:]
  401. }
  402. const (
  403. TCA_U32_UNSPEC = iota
  404. TCA_U32_CLASSID
  405. TCA_U32_HASH
  406. TCA_U32_LINK
  407. TCA_U32_DIVISOR
  408. TCA_U32_SEL
  409. TCA_U32_POLICE
  410. TCA_U32_ACT
  411. TCA_U32_INDEV
  412. TCA_U32_PCNT
  413. TCA_U32_MARK
  414. TCA_U32_MAX = TCA_U32_MARK
  415. )
  416. // struct tc_u32_key {
  417. // __be32 mask;
  418. // __be32 val;
  419. // int off;
  420. // int offmask;
  421. // };
  422. type TcU32Key struct {
  423. Mask uint32 // big endian
  424. Val uint32 // big endian
  425. Off int32
  426. OffMask int32
  427. }
  428. func (msg *TcU32Key) Len() int {
  429. return SizeofTcU32Key
  430. }
  431. func DeserializeTcU32Key(b []byte) *TcU32Key {
  432. return (*TcU32Key)(unsafe.Pointer(&b[0:SizeofTcU32Key][0]))
  433. }
  434. func (x *TcU32Key) Serialize() []byte {
  435. return (*(*[SizeofTcU32Key]byte)(unsafe.Pointer(x)))[:]
  436. }
  437. // struct tc_u32_sel {
  438. // unsigned char flags;
  439. // unsigned char offshift;
  440. // unsigned char nkeys;
  441. //
  442. // __be16 offmask;
  443. // __u16 off;
  444. // short offoff;
  445. //
  446. // short hoff;
  447. // __be32 hmask;
  448. // struct tc_u32_key keys[0];
  449. // };
  450. const (
  451. TC_U32_TERMINAL = 1 << iota
  452. TC_U32_OFFSET = 1 << iota
  453. TC_U32_VAROFFSET = 1 << iota
  454. TC_U32_EAT = 1 << iota
  455. )
  456. type TcU32Sel struct {
  457. Flags uint8
  458. Offshift uint8
  459. Nkeys uint8
  460. Pad uint8
  461. Offmask uint16 // big endian
  462. Off uint16
  463. Offoff int16
  464. Hoff int16
  465. Hmask uint32 // big endian
  466. Keys []TcU32Key
  467. }
  468. func (msg *TcU32Sel) Len() int {
  469. return SizeofTcU32Sel + int(msg.Nkeys)*SizeofTcU32Key
  470. }
  471. func DeserializeTcU32Sel(b []byte) *TcU32Sel {
  472. x := &TcU32Sel{}
  473. copy((*(*[SizeofTcU32Sel]byte)(unsafe.Pointer(x)))[:], b)
  474. next := SizeofTcU32Sel
  475. var i uint8
  476. for i = 0; i < x.Nkeys; i++ {
  477. x.Keys = append(x.Keys, *DeserializeTcU32Key(b[next:]))
  478. next += SizeofTcU32Key
  479. }
  480. return x
  481. }
  482. func (x *TcU32Sel) Serialize() []byte {
  483. // This can't just unsafe.cast because it must iterate through keys.
  484. buf := make([]byte, x.Len())
  485. copy(buf, (*(*[SizeofTcU32Sel]byte)(unsafe.Pointer(x)))[:])
  486. next := SizeofTcU32Sel
  487. for _, key := range x.Keys {
  488. keyBuf := key.Serialize()
  489. copy(buf[next:], keyBuf)
  490. next += SizeofTcU32Key
  491. }
  492. return buf
  493. }
  494. type TcGen struct {
  495. Index uint32
  496. Capab uint32
  497. Action int32
  498. Refcnt int32
  499. Bindcnt int32
  500. }
  501. func (msg *TcGen) Len() int {
  502. return SizeofTcGen
  503. }
  504. func DeserializeTcGen(b []byte) *TcGen {
  505. return (*TcGen)(unsafe.Pointer(&b[0:SizeofTcGen][0]))
  506. }
  507. func (x *TcGen) Serialize() []byte {
  508. return (*(*[SizeofTcGen]byte)(unsafe.Pointer(x)))[:]
  509. }
  510. // #define tc_gen \
  511. // __u32 index; \
  512. // __u32 capab; \
  513. // int action; \
  514. // int refcnt; \
  515. // int bindcnt
  516. const (
  517. TCA_ACT_GACT = 5
  518. )
  519. const (
  520. TCA_GACT_UNSPEC = iota
  521. TCA_GACT_TM
  522. TCA_GACT_PARMS
  523. TCA_GACT_PROB
  524. TCA_GACT_MAX = TCA_GACT_PROB
  525. )
  526. type TcGact TcGen
  527. const (
  528. TCA_ACT_BPF = 13
  529. )
  530. const (
  531. TCA_ACT_BPF_UNSPEC = iota
  532. TCA_ACT_BPF_TM
  533. TCA_ACT_BPF_PARMS
  534. TCA_ACT_BPF_OPS_LEN
  535. TCA_ACT_BPF_OPS
  536. TCA_ACT_BPF_FD
  537. TCA_ACT_BPF_NAME
  538. TCA_ACT_BPF_MAX = TCA_ACT_BPF_NAME
  539. )
  540. const (
  541. TCA_BPF_FLAG_ACT_DIRECT uint32 = 1 << iota
  542. )
  543. const (
  544. TCA_BPF_UNSPEC = iota
  545. TCA_BPF_ACT
  546. TCA_BPF_POLICE
  547. TCA_BPF_CLASSID
  548. TCA_BPF_OPS_LEN
  549. TCA_BPF_OPS
  550. TCA_BPF_FD
  551. TCA_BPF_NAME
  552. TCA_BPF_FLAGS
  553. TCA_BPF_FLAGS_GEN
  554. TCA_BPF_TAG
  555. TCA_BPF_ID
  556. TCA_BPF_MAX = TCA_BPF_ID
  557. )
  558. type TcBpf TcGen
  559. const (
  560. TCA_ACT_CONNMARK = 14
  561. )
  562. const (
  563. TCA_CONNMARK_UNSPEC = iota
  564. TCA_CONNMARK_PARMS
  565. TCA_CONNMARK_TM
  566. TCA_CONNMARK_MAX = TCA_CONNMARK_TM
  567. )
  568. // struct tc_connmark {
  569. // tc_gen;
  570. // __u16 zone;
  571. // };
  572. type TcConnmark struct {
  573. TcGen
  574. Zone uint16
  575. }
  576. func (msg *TcConnmark) Len() int {
  577. return SizeofTcConnmark
  578. }
  579. func DeserializeTcConnmark(b []byte) *TcConnmark {
  580. return (*TcConnmark)(unsafe.Pointer(&b[0:SizeofTcConnmark][0]))
  581. }
  582. func (x *TcConnmark) Serialize() []byte {
  583. return (*(*[SizeofTcConnmark]byte)(unsafe.Pointer(x)))[:]
  584. }
  585. const (
  586. TCA_ACT_MIRRED = 8
  587. )
  588. const (
  589. TCA_MIRRED_UNSPEC = iota
  590. TCA_MIRRED_TM
  591. TCA_MIRRED_PARMS
  592. TCA_MIRRED_MAX = TCA_MIRRED_PARMS
  593. )
  594. // struct tc_mirred {
  595. // tc_gen;
  596. // int eaction; /* one of IN/EGRESS_MIRROR/REDIR */
  597. // __u32 ifindex; /* ifindex of egress port */
  598. // };
  599. type TcMirred struct {
  600. TcGen
  601. Eaction int32
  602. Ifindex uint32
  603. }
  604. func (msg *TcMirred) Len() int {
  605. return SizeofTcMirred
  606. }
  607. func DeserializeTcMirred(b []byte) *TcMirred {
  608. return (*TcMirred)(unsafe.Pointer(&b[0:SizeofTcMirred][0]))
  609. }
  610. func (x *TcMirred) Serialize() []byte {
  611. return (*(*[SizeofTcMirred]byte)(unsafe.Pointer(x)))[:]
  612. }
  613. const (
  614. TCA_TUNNEL_KEY_UNSPEC = iota
  615. TCA_TUNNEL_KEY_TM
  616. TCA_TUNNEL_KEY_PARMS
  617. TCA_TUNNEL_KEY_ENC_IPV4_SRC
  618. TCA_TUNNEL_KEY_ENC_IPV4_DST
  619. TCA_TUNNEL_KEY_ENC_IPV6_SRC
  620. TCA_TUNNEL_KEY_ENC_IPV6_DST
  621. TCA_TUNNEL_KEY_ENC_KEY_ID
  622. TCA_TUNNEL_KEY_PAD
  623. TCA_TUNNEL_KEY_ENC_DST_PORT
  624. TCA_TUNNEL_KEY_NO_CSUM
  625. TCA_TUNNEL_KEY_ENC_OPTS
  626. TCA_TUNNEL_KEY_ENC_TOS
  627. TCA_TUNNEL_KEY_ENC_TTL
  628. TCA_TUNNEL_KEY_MAX
  629. )
  630. type TcTunnelKey struct {
  631. TcGen
  632. Action int32
  633. }
  634. func (x *TcTunnelKey) Len() int {
  635. return SizeofTcTunnelKey
  636. }
  637. func DeserializeTunnelKey(b []byte) *TcTunnelKey {
  638. return (*TcTunnelKey)(unsafe.Pointer(&b[0:SizeofTcTunnelKey][0]))
  639. }
  640. func (x *TcTunnelKey) Serialize() []byte {
  641. return (*(*[SizeofTcTunnelKey]byte)(unsafe.Pointer(x)))[:]
  642. }
  643. const (
  644. TCA_SKBEDIT_UNSPEC = iota
  645. TCA_SKBEDIT_TM
  646. TCA_SKBEDIT_PARMS
  647. TCA_SKBEDIT_PRIORITY
  648. TCA_SKBEDIT_QUEUE_MAPPING
  649. TCA_SKBEDIT_MARK
  650. TCA_SKBEDIT_PAD
  651. TCA_SKBEDIT_PTYPE
  652. TCA_SKBEDIT_MAX = TCA_SKBEDIT_MARK
  653. )
  654. type TcSkbEdit struct {
  655. TcGen
  656. }
  657. func (x *TcSkbEdit) Len() int {
  658. return SizeofTcSkbEdit
  659. }
  660. func DeserializeSkbEdit(b []byte) *TcSkbEdit {
  661. return (*TcSkbEdit)(unsafe.Pointer(&b[0:SizeofTcSkbEdit][0]))
  662. }
  663. func (x *TcSkbEdit) Serialize() []byte {
  664. return (*(*[SizeofTcSkbEdit]byte)(unsafe.Pointer(x)))[:]
  665. }
  666. // struct tc_police {
  667. // __u32 index;
  668. // int action;
  669. // __u32 limit;
  670. // __u32 burst;
  671. // __u32 mtu;
  672. // struct tc_ratespec rate;
  673. // struct tc_ratespec peakrate;
  674. // int refcnt;
  675. // int bindcnt;
  676. // __u32 capab;
  677. // };
  678. type TcPolice struct {
  679. Index uint32
  680. Action int32
  681. Limit uint32
  682. Burst uint32
  683. Mtu uint32
  684. Rate TcRateSpec
  685. PeakRate TcRateSpec
  686. Refcnt int32
  687. Bindcnt int32
  688. Capab uint32
  689. }
  690. func (msg *TcPolice) Len() int {
  691. return SizeofTcPolice
  692. }
  693. func DeserializeTcPolice(b []byte) *TcPolice {
  694. return (*TcPolice)(unsafe.Pointer(&b[0:SizeofTcPolice][0]))
  695. }
  696. func (x *TcPolice) Serialize() []byte {
  697. return (*(*[SizeofTcPolice]byte)(unsafe.Pointer(x)))[:]
  698. }
  699. const (
  700. TCA_FW_UNSPEC = iota
  701. TCA_FW_CLASSID
  702. TCA_FW_POLICE
  703. TCA_FW_INDEV
  704. TCA_FW_ACT
  705. TCA_FW_MASK
  706. TCA_FW_MAX = TCA_FW_MASK
  707. )
  708. const (
  709. TCA_MATCHALL_UNSPEC = iota
  710. TCA_MATCHALL_CLASSID
  711. TCA_MATCHALL_ACT
  712. TCA_MATCHALL_FLAGS
  713. )
  714. const (
  715. TCA_FQ_UNSPEC = iota
  716. TCA_FQ_PLIMIT // limit of total number of packets in queue
  717. TCA_FQ_FLOW_PLIMIT // limit of packets per flow
  718. TCA_FQ_QUANTUM // RR quantum
  719. TCA_FQ_INITIAL_QUANTUM // RR quantum for new flow
  720. TCA_FQ_RATE_ENABLE // enable/disable rate limiting
  721. TCA_FQ_FLOW_DEFAULT_RATE // obsolete do not use
  722. TCA_FQ_FLOW_MAX_RATE // per flow max rate
  723. TCA_FQ_BUCKETS_LOG // log2(number of buckets)
  724. TCA_FQ_FLOW_REFILL_DELAY // flow credit refill delay in usec
  725. TCA_FQ_ORPHAN_MASK // mask applied to orphaned skb hashes
  726. TCA_FQ_LOW_RATE_THRESHOLD // per packet delay under this rate
  727. )
  728. const (
  729. TCA_FQ_CODEL_UNSPEC = iota
  730. TCA_FQ_CODEL_TARGET
  731. TCA_FQ_CODEL_LIMIT
  732. TCA_FQ_CODEL_INTERVAL
  733. TCA_FQ_CODEL_ECN
  734. TCA_FQ_CODEL_FLOWS
  735. TCA_FQ_CODEL_QUANTUM
  736. TCA_FQ_CODEL_CE_THRESHOLD
  737. TCA_FQ_CODEL_DROP_BATCH_SIZE
  738. TCA_FQ_CODEL_MEMORY_LIMIT
  739. )
  740. const (
  741. TCA_HFSC_UNSPEC = iota
  742. TCA_HFSC_RSC
  743. TCA_HFSC_FSC
  744. TCA_HFSC_USC
  745. )
  746. // struct tc_sfq_qopt {
  747. // unsigned quantum; /* Bytes per round allocated to flow */
  748. // int perturb_period; /* Period of hash perturbation */
  749. // __u32 limit; /* Maximal packets in queue */
  750. // unsigned divisor; /* Hash divisor */
  751. // unsigned flows; /* Maximal number of flows */
  752. // };
  753. type TcSfqQopt struct {
  754. Quantum uint8
  755. Perturb int32
  756. Limit uint32
  757. Divisor uint8
  758. Flows uint8
  759. }
  760. func (x *TcSfqQopt) Len() int {
  761. return SizeofTcSfqQopt
  762. }
  763. func DeserializeTcSfqQopt(b []byte) *TcSfqQopt {
  764. return (*TcSfqQopt)(unsafe.Pointer(&b[0:SizeofTcSfqQopt][0]))
  765. }
  766. func (x *TcSfqQopt) Serialize() []byte {
  767. return (*(*[SizeofTcSfqQopt]byte)(unsafe.Pointer(x)))[:]
  768. }
  769. // struct tc_sfqred_stats {
  770. // __u32 prob_drop; /* Early drops, below max threshold */
  771. // __u32 forced_drop; /* Early drops, after max threshold */
  772. // __u32 prob_mark; /* Marked packets, below max threshold */
  773. // __u32 forced_mark; /* Marked packets, after max threshold */
  774. // __u32 prob_mark_head; /* Marked packets, below max threshold */
  775. // __u32 forced_mark_head;/* Marked packets, after max threshold */
  776. // };
  777. type TcSfqRedStats struct {
  778. ProbDrop uint32
  779. ForcedDrop uint32
  780. ProbMark uint32
  781. ForcedMark uint32
  782. ProbMarkHead uint32
  783. ForcedMarkHead uint32
  784. }
  785. func (x *TcSfqRedStats) Len() int {
  786. return SizeofTcSfqRedStats
  787. }
  788. func DeserializeTcSfqRedStats(b []byte) *TcSfqRedStats {
  789. return (*TcSfqRedStats)(unsafe.Pointer(&b[0:SizeofTcSfqRedStats][0]))
  790. }
  791. func (x *TcSfqRedStats) Serialize() []byte {
  792. return (*(*[SizeofTcSfqRedStats]byte)(unsafe.Pointer(x)))[:]
  793. }
  794. // struct tc_sfq_qopt_v1 {
  795. // struct tc_sfq_qopt v0;
  796. // unsigned int depth; /* max number of packets per flow */
  797. // unsigned int headdrop;
  798. // /* SFQRED parameters */
  799. // __u32 limit; /* HARD maximal flow queue length (bytes) */
  800. // __u32 qth_min; /* Min average length threshold (bytes) */
  801. // __u32 qth_max; /* Max average length threshold (bytes) */
  802. // unsigned char Wlog; /* log(W) */
  803. // unsigned char Plog; /* log(P_max/(qth_max-qth_min)) */
  804. // unsigned char Scell_log; /* cell size for idle damping */
  805. // unsigned char flags;
  806. // __u32 max_P; /* probability, high resolution */
  807. // /* SFQRED stats */
  808. // struct tc_sfqred_stats stats;
  809. // };
  810. type TcSfqQoptV1 struct {
  811. TcSfqQopt
  812. Depth uint32
  813. HeadDrop uint32
  814. Limit uint32
  815. QthMin uint32
  816. QthMax uint32
  817. Wlog byte
  818. Plog byte
  819. ScellLog byte
  820. Flags byte
  821. MaxP uint32
  822. TcSfqRedStats
  823. }
  824. func (x *TcSfqQoptV1) Len() int {
  825. return SizeofTcSfqQoptV1
  826. }
  827. func DeserializeTcSfqQoptV1(b []byte) *TcSfqQoptV1 {
  828. return (*TcSfqQoptV1)(unsafe.Pointer(&b[0:SizeofTcSfqQoptV1][0]))
  829. }
  830. func (x *TcSfqQoptV1) Serialize() []byte {
  831. return (*(*[SizeofTcSfqQoptV1]byte)(unsafe.Pointer(x)))[:]
  832. }