tc_linux.go 23 KB

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