github.com/vishvananda/netlink@v1.3.1/nl/tc_linux.go (about)

     1  package nl
     2  
     3  import (
     4  	"bytes"
     5  	"encoding/binary"
     6  	"fmt"
     7  	"net"
     8  	"unsafe"
     9  
    10  	"golang.org/x/sys/unix"
    11  )
    12  
    13  // LinkLayer
    14  const (
    15  	LINKLAYER_UNSPEC = iota
    16  	LINKLAYER_ETHERNET
    17  	LINKLAYER_ATM
    18  )
    19  
    20  // ATM
    21  const (
    22  	ATM_CELL_PAYLOAD = 48
    23  	ATM_CELL_SIZE    = 53
    24  )
    25  
    26  const TC_LINKLAYER_MASK = 0x0F
    27  
    28  // Police
    29  const (
    30  	TCA_POLICE_UNSPEC = iota
    31  	TCA_POLICE_TBF
    32  	TCA_POLICE_RATE
    33  	TCA_POLICE_PEAKRATE
    34  	TCA_POLICE_AVRATE
    35  	TCA_POLICE_RESULT
    36  	TCA_POLICE_MAX = TCA_POLICE_RESULT
    37  )
    38  
    39  // Message types
    40  const (
    41  	TCA_UNSPEC = iota
    42  	TCA_KIND
    43  	TCA_OPTIONS
    44  	TCA_STATS
    45  	TCA_XSTATS
    46  	TCA_RATE
    47  	TCA_FCNT
    48  	TCA_STATS2
    49  	TCA_STAB
    50  	TCA_PAD
    51  	TCA_DUMP_INVISIBLE
    52  	TCA_CHAIN
    53  	TCA_HW_OFFLOAD
    54  	TCA_INGRESS_BLOCK
    55  	TCA_EGRESS_BLOCK
    56  	TCA_DUMP_FLAGS
    57  	TCA_MAX = TCA_DUMP_FLAGS
    58  )
    59  
    60  const (
    61  	TCA_ACT_TAB = 1
    62  	TCAA_MAX    = 1
    63  )
    64  
    65  const (
    66  	TCA_ACT_UNSPEC = iota
    67  	TCA_ACT_KIND
    68  	TCA_ACT_OPTIONS
    69  	TCA_ACT_INDEX
    70  	TCA_ACT_STATS
    71  	TCA_ACT_PAD
    72  	TCA_ACT_COOKIE
    73  	TCA_ACT_FLAGS
    74  	TCA_ACT_HW_STATS
    75  	TCA_ACT_USED_HW_STATS
    76  	TCA_ACT_IN_HW_COUNT
    77  	TCA_ACT_MAX
    78  )
    79  
    80  const (
    81  	TCA_ACT_SAMPLE_UNSPEC = iota
    82  	TCA_ACT_SAMPLE_TM
    83  	TCA_ACT_SAMPLE_PARMS
    84  	TCA_ACT_SAMPLE_RATE
    85  	TCA_ACT_SAMPLE_TRUNC_SIZE
    86  	TCA_ACT_SAMPLE_PSAMPLE_GROUP
    87  	TCA_ACT_SAMPLE_PAD
    88  	TCA_ACT_SAMPLE_MAX
    89  )
    90  
    91  const (
    92  	TCA_PRIO_UNSPEC = iota
    93  	TCA_PRIO_MQ
    94  	TCA_PRIO_MAX = TCA_PRIO_MQ
    95  )
    96  
    97  const (
    98  	TCA_STATS_UNSPEC = iota
    99  	TCA_STATS_BASIC
   100  	TCA_STATS_RATE_EST
   101  	TCA_STATS_QUEUE
   102  	TCA_STATS_APP
   103  	TCA_STATS_RATE_EST64
   104  	TCA_STATS_PAD
   105  	TCA_STATS_BASIC_HW
   106  	TCA_STATS_PKT64
   107  	TCA_STATS_MAX = TCA_STATS_PKT64
   108  )
   109  
   110  const (
   111  	SizeofTcMsg          = 0x14
   112  	SizeofTcActionMsg    = 0x04
   113  	SizeofTcPrioMap      = 0x14
   114  	SizeofTcRateSpec     = 0x0c
   115  	SizeofTcNetemQopt    = 0x18
   116  	SizeofTcNetemCorr    = 0x0c
   117  	SizeofTcNetemReorder = 0x08
   118  	SizeofTcNetemCorrupt = 0x08
   119  	SizeOfTcNetemRate    = 0x10
   120  	SizeofTcTbfQopt      = 2*SizeofTcRateSpec + 0x0c
   121  	SizeofTcHtbCopt      = 2*SizeofTcRateSpec + 0x14
   122  	SizeofTcHtbGlob      = 0x14
   123  	SizeofTcU32Key       = 0x10
   124  	SizeofTcU32Sel       = 0x10 // without keys
   125  	SizeofTcGen          = 0x16
   126  	SizeofTcConnmark     = SizeofTcGen + 0x04
   127  	SizeofTcCsum         = SizeofTcGen + 0x04
   128  	SizeofTcMirred       = SizeofTcGen + 0x08
   129  	SizeofTcVlan         = SizeofTcGen + 0x04
   130  	SizeofTcTunnelKey    = SizeofTcGen + 0x04
   131  	SizeofTcSkbEdit      = SizeofTcGen
   132  	SizeofTcPolice       = 2*SizeofTcRateSpec + 0x20
   133  	SizeofTcSfqQopt      = 0x0b
   134  	SizeofTcSfqRedStats  = 0x18
   135  	SizeofTcSfqQoptV1    = SizeofTcSfqQopt + SizeofTcSfqRedStats + 0x1c
   136  	SizeofUint32Bitfield = 0x8
   137  )
   138  
   139  // struct tcmsg {
   140  //   unsigned char tcm_family;
   141  //   unsigned char tcm__pad1;
   142  //   unsigned short  tcm__pad2;
   143  //   int   tcm_ifindex;
   144  //   __u32   tcm_handle;
   145  //   __u32   tcm_parent;
   146  //   __u32   tcm_info;
   147  // };
   148  
   149  type TcMsg struct {
   150  	Family  uint8
   151  	Pad     [3]byte
   152  	Ifindex int32
   153  	Handle  uint32
   154  	Parent  uint32
   155  	Info    uint32
   156  }
   157  
   158  func (msg *TcMsg) Len() int {
   159  	return SizeofTcMsg
   160  }
   161  
   162  func DeserializeTcMsg(b []byte) *TcMsg {
   163  	return (*TcMsg)(unsafe.Pointer(&b[0:SizeofTcMsg][0]))
   164  }
   165  
   166  func (x *TcMsg) Serialize() []byte {
   167  	return (*(*[SizeofTcMsg]byte)(unsafe.Pointer(x)))[:]
   168  }
   169  
   170  type Tcf struct {
   171  	Install  uint64
   172  	LastUse  uint64
   173  	Expires  uint64
   174  	FirstUse uint64
   175  }
   176  
   177  func DeserializeTcf(b []byte) *Tcf {
   178  	const size = int(unsafe.Sizeof(Tcf{}))
   179  	return (*Tcf)(unsafe.Pointer(&b[0:size][0]))
   180  }
   181  
   182  // struct tcamsg {
   183  //   unsigned char tca_family;
   184  //   unsigned char tca__pad1;
   185  //   unsigned short  tca__pad2;
   186  // };
   187  
   188  type TcActionMsg struct {
   189  	Family uint8
   190  	Pad    [3]byte
   191  }
   192  
   193  func (msg *TcActionMsg) Len() int {
   194  	return SizeofTcActionMsg
   195  }
   196  
   197  func DeserializeTcActionMsg(b []byte) *TcActionMsg {
   198  	return (*TcActionMsg)(unsafe.Pointer(&b[0:SizeofTcActionMsg][0]))
   199  }
   200  
   201  func (x *TcActionMsg) Serialize() []byte {
   202  	return (*(*[SizeofTcActionMsg]byte)(unsafe.Pointer(x)))[:]
   203  }
   204  
   205  const (
   206  	TC_PRIO_MAX = 15
   207  )
   208  
   209  // struct tc_prio_qopt {
   210  // 	int bands;      /* Number of bands */
   211  // 	__u8  priomap[TC_PRIO_MAX+1]; /* Map: logical priority -> PRIO band */
   212  // };
   213  
   214  type TcPrioMap struct {
   215  	Bands   int32
   216  	Priomap [TC_PRIO_MAX + 1]uint8
   217  }
   218  
   219  func (msg *TcPrioMap) Len() int {
   220  	return SizeofTcPrioMap
   221  }
   222  
   223  func DeserializeTcPrioMap(b []byte) *TcPrioMap {
   224  	return (*TcPrioMap)(unsafe.Pointer(&b[0:SizeofTcPrioMap][0]))
   225  }
   226  
   227  func (x *TcPrioMap) Serialize() []byte {
   228  	return (*(*[SizeofTcPrioMap]byte)(unsafe.Pointer(x)))[:]
   229  }
   230  
   231  const (
   232  	TCA_TBF_UNSPEC = iota
   233  	TCA_TBF_PARMS
   234  	TCA_TBF_RTAB
   235  	TCA_TBF_PTAB
   236  	TCA_TBF_RATE64
   237  	TCA_TBF_PRATE64
   238  	TCA_TBF_BURST
   239  	TCA_TBF_PBURST
   240  	TCA_TBF_MAX = TCA_TBF_PBURST
   241  )
   242  
   243  // struct tc_ratespec {
   244  //   unsigned char cell_log;
   245  //   __u8    linklayer; /* lower 4 bits */
   246  //   unsigned short  overhead;
   247  //   short   cell_align;
   248  //   unsigned short  mpu;
   249  //   __u32   rate;
   250  // };
   251  
   252  type TcRateSpec struct {
   253  	CellLog   uint8
   254  	Linklayer uint8
   255  	Overhead  uint16
   256  	CellAlign int16
   257  	Mpu       uint16
   258  	Rate      uint32
   259  }
   260  
   261  func (msg *TcRateSpec) Len() int {
   262  	return SizeofTcRateSpec
   263  }
   264  
   265  func DeserializeTcRateSpec(b []byte) *TcRateSpec {
   266  	return (*TcRateSpec)(unsafe.Pointer(&b[0:SizeofTcRateSpec][0]))
   267  }
   268  
   269  func (x *TcRateSpec) Serialize() []byte {
   270  	return (*(*[SizeofTcRateSpec]byte)(unsafe.Pointer(x)))[:]
   271  }
   272  
   273  /**
   274  * NETEM
   275   */
   276  
   277  const (
   278  	TCA_NETEM_UNSPEC = iota
   279  	TCA_NETEM_CORR
   280  	TCA_NETEM_DELAY_DIST
   281  	TCA_NETEM_REORDER
   282  	TCA_NETEM_CORRUPT
   283  	TCA_NETEM_LOSS
   284  	TCA_NETEM_RATE
   285  	TCA_NETEM_ECN
   286  	TCA_NETEM_RATE64
   287  	TCA_NETEM_MAX = TCA_NETEM_RATE64
   288  )
   289  
   290  // struct tc_netem_qopt {
   291  //	__u32	latency;	/* added delay (us) */
   292  //	__u32   limit;		/* fifo limit (packets) */
   293  //	__u32	loss;		/* random packet loss (0=none ~0=100%) */
   294  //	__u32	gap;		/* re-ordering gap (0 for none) */
   295  //	__u32   duplicate;	/* random packet dup  (0=none ~0=100%) */
   296  // 	__u32	jitter;		/* random jitter in latency (us) */
   297  // };
   298  
   299  type TcNetemQopt struct {
   300  	Latency   uint32
   301  	Limit     uint32
   302  	Loss      uint32
   303  	Gap       uint32
   304  	Duplicate uint32
   305  	Jitter    uint32
   306  }
   307  
   308  func (msg *TcNetemQopt) Len() int {
   309  	return SizeofTcNetemQopt
   310  }
   311  
   312  func DeserializeTcNetemQopt(b []byte) *TcNetemQopt {
   313  	return (*TcNetemQopt)(unsafe.Pointer(&b[0:SizeofTcNetemQopt][0]))
   314  }
   315  
   316  func (x *TcNetemQopt) Serialize() []byte {
   317  	return (*(*[SizeofTcNetemQopt]byte)(unsafe.Pointer(x)))[:]
   318  }
   319  
   320  // struct tc_netem_corr {
   321  //  __u32   delay_corr; /* delay correlation */
   322  //  __u32   loss_corr;  /* packet loss correlation */
   323  //  __u32   dup_corr;   /* duplicate correlation  */
   324  // };
   325  
   326  type TcNetemCorr struct {
   327  	DelayCorr uint32
   328  	LossCorr  uint32
   329  	DupCorr   uint32
   330  }
   331  
   332  func (msg *TcNetemCorr) Len() int {
   333  	return SizeofTcNetemCorr
   334  }
   335  
   336  func DeserializeTcNetemCorr(b []byte) *TcNetemCorr {
   337  	return (*TcNetemCorr)(unsafe.Pointer(&b[0:SizeofTcNetemCorr][0]))
   338  }
   339  
   340  func (x *TcNetemCorr) Serialize() []byte {
   341  	return (*(*[SizeofTcNetemCorr]byte)(unsafe.Pointer(x)))[:]
   342  }
   343  
   344  // struct tc_netem_reorder {
   345  //  __u32   probability;
   346  //  __u32   correlation;
   347  // };
   348  
   349  type TcNetemReorder struct {
   350  	Probability uint32
   351  	Correlation uint32
   352  }
   353  
   354  func (msg *TcNetemReorder) Len() int {
   355  	return SizeofTcNetemReorder
   356  }
   357  
   358  func DeserializeTcNetemReorder(b []byte) *TcNetemReorder {
   359  	return (*TcNetemReorder)(unsafe.Pointer(&b[0:SizeofTcNetemReorder][0]))
   360  }
   361  
   362  func (x *TcNetemReorder) Serialize() []byte {
   363  	return (*(*[SizeofTcNetemReorder]byte)(unsafe.Pointer(x)))[:]
   364  }
   365  
   366  // struct tc_netem_corrupt {
   367  //  __u32   probability;
   368  //  __u32   correlation;
   369  // };
   370  
   371  type TcNetemCorrupt struct {
   372  	Probability uint32
   373  	Correlation uint32
   374  }
   375  
   376  func (msg *TcNetemCorrupt) Len() int {
   377  	return SizeofTcNetemCorrupt
   378  }
   379  
   380  func DeserializeTcNetemCorrupt(b []byte) *TcNetemCorrupt {
   381  	return (*TcNetemCorrupt)(unsafe.Pointer(&b[0:SizeofTcNetemCorrupt][0]))
   382  }
   383  
   384  func (x *TcNetemCorrupt) Serialize() []byte {
   385  	return (*(*[SizeofTcNetemCorrupt]byte)(unsafe.Pointer(x)))[:]
   386  }
   387  
   388  // TcNetemRate is a struct that represents the rate of a netem qdisc
   389  type TcNetemRate struct {
   390  	Rate           uint32
   391  	PacketOverhead int32
   392  	CellSize       uint32
   393  	CellOverhead   int32
   394  }
   395  
   396  func (msg *TcNetemRate) Len() int {
   397  	return SizeofTcRateSpec
   398  }
   399  
   400  func DeserializeTcNetemRate(b []byte) *TcNetemRate {
   401  	return (*TcNetemRate)(unsafe.Pointer(&b[0:SizeofTcRateSpec][0]))
   402  }
   403  
   404  func (msg *TcNetemRate) Serialize() []byte {
   405  	return (*(*[SizeOfTcNetemRate]byte)(unsafe.Pointer(msg)))[:]
   406  }
   407  
   408  // struct tc_tbf_qopt {
   409  //   struct tc_ratespec rate;
   410  //   struct tc_ratespec peakrate;
   411  //   __u32   limit;
   412  //   __u32   buffer;
   413  //   __u32   mtu;
   414  // };
   415  
   416  type TcTbfQopt struct {
   417  	Rate     TcRateSpec
   418  	Peakrate TcRateSpec
   419  	Limit    uint32
   420  	Buffer   uint32
   421  	Mtu      uint32
   422  }
   423  
   424  func (msg *TcTbfQopt) Len() int {
   425  	return SizeofTcTbfQopt
   426  }
   427  
   428  func DeserializeTcTbfQopt(b []byte) *TcTbfQopt {
   429  	return (*TcTbfQopt)(unsafe.Pointer(&b[0:SizeofTcTbfQopt][0]))
   430  }
   431  
   432  func (x *TcTbfQopt) Serialize() []byte {
   433  	return (*(*[SizeofTcTbfQopt]byte)(unsafe.Pointer(x)))[:]
   434  }
   435  
   436  const (
   437  	TCA_HTB_UNSPEC = iota
   438  	TCA_HTB_PARMS
   439  	TCA_HTB_INIT
   440  	TCA_HTB_CTAB
   441  	TCA_HTB_RTAB
   442  	TCA_HTB_DIRECT_QLEN
   443  	TCA_HTB_RATE64
   444  	TCA_HTB_CEIL64
   445  	TCA_HTB_MAX = TCA_HTB_CEIL64
   446  )
   447  
   448  //struct tc_htb_opt {
   449  //	struct tc_ratespec	rate;
   450  //	struct tc_ratespec	ceil;
   451  //	__u32	buffer;
   452  //	__u32	cbuffer;
   453  //	__u32	quantum;
   454  //	__u32	level;		/* out only */
   455  //	__u32	prio;
   456  //};
   457  
   458  type TcHtbCopt struct {
   459  	Rate    TcRateSpec
   460  	Ceil    TcRateSpec
   461  	Buffer  uint32
   462  	Cbuffer uint32
   463  	Quantum uint32
   464  	Level   uint32
   465  	Prio    uint32
   466  }
   467  
   468  func (msg *TcHtbCopt) Len() int {
   469  	return SizeofTcHtbCopt
   470  }
   471  
   472  func DeserializeTcHtbCopt(b []byte) *TcHtbCopt {
   473  	return (*TcHtbCopt)(unsafe.Pointer(&b[0:SizeofTcHtbCopt][0]))
   474  }
   475  
   476  func (x *TcHtbCopt) Serialize() []byte {
   477  	return (*(*[SizeofTcHtbCopt]byte)(unsafe.Pointer(x)))[:]
   478  }
   479  
   480  type TcHtbGlob struct {
   481  	Version      uint32
   482  	Rate2Quantum uint32
   483  	Defcls       uint32
   484  	Debug        uint32
   485  	DirectPkts   uint32
   486  }
   487  
   488  func (msg *TcHtbGlob) Len() int {
   489  	return SizeofTcHtbGlob
   490  }
   491  
   492  func DeserializeTcHtbGlob(b []byte) *TcHtbGlob {
   493  	return (*TcHtbGlob)(unsafe.Pointer(&b[0:SizeofTcHtbGlob][0]))
   494  }
   495  
   496  func (x *TcHtbGlob) Serialize() []byte {
   497  	return (*(*[SizeofTcHtbGlob]byte)(unsafe.Pointer(x)))[:]
   498  }
   499  
   500  // HFSC
   501  
   502  type Curve struct {
   503  	m1 uint32
   504  	d  uint32
   505  	m2 uint32
   506  }
   507  
   508  type HfscCopt struct {
   509  	Rsc Curve
   510  	Fsc Curve
   511  	Usc Curve
   512  }
   513  
   514  func (c *Curve) Attrs() (uint32, uint32, uint32) {
   515  	return c.m1, c.d, c.m2
   516  }
   517  
   518  func (c *Curve) Set(m1 uint32, d uint32, m2 uint32) {
   519  	c.m1 = m1
   520  	c.d = d
   521  	c.m2 = m2
   522  }
   523  
   524  func DeserializeHfscCurve(b []byte) *Curve {
   525  	return &Curve{
   526  		m1: binary.LittleEndian.Uint32(b[0:4]),
   527  		d:  binary.LittleEndian.Uint32(b[4:8]),
   528  		m2: binary.LittleEndian.Uint32(b[8:12]),
   529  	}
   530  }
   531  
   532  func SerializeHfscCurve(c *Curve) (b []byte) {
   533  	t := make([]byte, binary.MaxVarintLen32)
   534  	binary.LittleEndian.PutUint32(t, c.m1)
   535  	b = append(b, t[:4]...)
   536  	binary.LittleEndian.PutUint32(t, c.d)
   537  	b = append(b, t[:4]...)
   538  	binary.LittleEndian.PutUint32(t, c.m2)
   539  	b = append(b, t[:4]...)
   540  	return b
   541  }
   542  
   543  type TcHfscOpt struct {
   544  	Defcls uint16
   545  }
   546  
   547  func (x *TcHfscOpt) Serialize() []byte {
   548  	return (*(*[2]byte)(unsafe.Pointer(x)))[:]
   549  }
   550  
   551  const (
   552  	TCA_U32_UNSPEC = iota
   553  	TCA_U32_CLASSID
   554  	TCA_U32_HASH
   555  	TCA_U32_LINK
   556  	TCA_U32_DIVISOR
   557  	TCA_U32_SEL
   558  	TCA_U32_POLICE
   559  	TCA_U32_ACT
   560  	TCA_U32_INDEV
   561  	TCA_U32_PCNT
   562  	TCA_U32_MARK
   563  	TCA_U32_MAX = TCA_U32_MARK
   564  )
   565  
   566  // struct tc_u32_key {
   567  //   __be32    mask;
   568  //   __be32    val;
   569  //   int   off;
   570  //   int   offmask;
   571  // };
   572  
   573  type TcU32Key struct {
   574  	Mask    uint32 // big endian
   575  	Val     uint32 // big endian
   576  	Off     int32
   577  	OffMask int32
   578  }
   579  
   580  func (msg *TcU32Key) Len() int {
   581  	return SizeofTcU32Key
   582  }
   583  
   584  func DeserializeTcU32Key(b []byte) *TcU32Key {
   585  	return (*TcU32Key)(unsafe.Pointer(&b[0:SizeofTcU32Key][0]))
   586  }
   587  
   588  func (x *TcU32Key) Serialize() []byte {
   589  	return (*(*[SizeofTcU32Key]byte)(unsafe.Pointer(x)))[:]
   590  }
   591  
   592  // struct tc_u32_sel {
   593  //   unsigned char   flags;
   594  //   unsigned char   offshift;
   595  //   unsigned char   nkeys;
   596  //
   597  //   __be16      offmask;
   598  //   __u16     off;
   599  //   short     offoff;
   600  //
   601  //   short     hoff;
   602  //   __be32      hmask;
   603  //   struct tc_u32_key keys[0];
   604  // };
   605  
   606  const (
   607  	TC_U32_TERMINAL  = 1 << iota
   608  	TC_U32_OFFSET    = 1 << iota
   609  	TC_U32_VAROFFSET = 1 << iota
   610  	TC_U32_EAT       = 1 << iota
   611  )
   612  
   613  type TcU32Sel struct {
   614  	Flags    uint8
   615  	Offshift uint8
   616  	Nkeys    uint8
   617  	Pad      uint8
   618  	Offmask  uint16 // big endian
   619  	Off      uint16
   620  	Offoff   int16
   621  	Hoff     int16
   622  	Hmask    uint32 // big endian
   623  	Keys     []TcU32Key
   624  }
   625  
   626  func (msg *TcU32Sel) Len() int {
   627  	return SizeofTcU32Sel + int(msg.Nkeys)*SizeofTcU32Key
   628  }
   629  
   630  func DeserializeTcU32Sel(b []byte) *TcU32Sel {
   631  	x := &TcU32Sel{}
   632  	copy((*(*[SizeofTcU32Sel]byte)(unsafe.Pointer(x)))[:], b)
   633  	next := SizeofTcU32Sel
   634  	var i uint8
   635  	for i = 0; i < x.Nkeys; i++ {
   636  		x.Keys = append(x.Keys, *DeserializeTcU32Key(b[next:]))
   637  		next += SizeofTcU32Key
   638  	}
   639  	return x
   640  }
   641  
   642  func (x *TcU32Sel) Serialize() []byte {
   643  	// This can't just unsafe.cast because it must iterate through keys.
   644  	buf := make([]byte, x.Len())
   645  	copy(buf, (*(*[SizeofTcU32Sel]byte)(unsafe.Pointer(x)))[:])
   646  	next := SizeofTcU32Sel
   647  	for _, key := range x.Keys {
   648  		keyBuf := key.Serialize()
   649  		copy(buf[next:], keyBuf)
   650  		next += SizeofTcU32Key
   651  	}
   652  	return buf
   653  }
   654  
   655  type TcGen struct {
   656  	Index   uint32
   657  	Capab   uint32
   658  	Action  int32
   659  	Refcnt  int32
   660  	Bindcnt int32
   661  }
   662  
   663  func (msg *TcGen) Len() int {
   664  	return SizeofTcGen
   665  }
   666  
   667  func DeserializeTcGen(b []byte) *TcGen {
   668  	return (*TcGen)(unsafe.Pointer(&b[0:SizeofTcGen][0]))
   669  }
   670  
   671  func (x *TcGen) Serialize() []byte {
   672  	return (*(*[SizeofTcGen]byte)(unsafe.Pointer(x)))[:]
   673  }
   674  
   675  // #define tc_gen \
   676  //   __u32                 index; \
   677  //   __u32                 capab; \
   678  //   int                   action; \
   679  //   int                   refcnt; \
   680  //   int                   bindcnt
   681  
   682  const (
   683  	TCA_ACT_GACT = 5
   684  )
   685  
   686  const (
   687  	TCA_GACT_UNSPEC = iota
   688  	TCA_GACT_TM
   689  	TCA_GACT_PARMS
   690  	TCA_GACT_PROB
   691  	TCA_GACT_MAX = TCA_GACT_PROB
   692  )
   693  
   694  type TcGact TcGen
   695  
   696  const (
   697  	TCA_ACT_BPF = 13
   698  )
   699  
   700  const (
   701  	TCA_ACT_BPF_UNSPEC = iota
   702  	TCA_ACT_BPF_TM
   703  	TCA_ACT_BPF_PARMS
   704  	TCA_ACT_BPF_OPS_LEN
   705  	TCA_ACT_BPF_OPS
   706  	TCA_ACT_BPF_FD
   707  	TCA_ACT_BPF_NAME
   708  	TCA_ACT_BPF_MAX = TCA_ACT_BPF_NAME
   709  )
   710  
   711  const (
   712  	TCA_BPF_FLAG_ACT_DIRECT uint32 = 1 << iota
   713  )
   714  
   715  const (
   716  	TCA_BPF_UNSPEC = iota
   717  	TCA_BPF_ACT
   718  	TCA_BPF_POLICE
   719  	TCA_BPF_CLASSID
   720  	TCA_BPF_OPS_LEN
   721  	TCA_BPF_OPS
   722  	TCA_BPF_FD
   723  	TCA_BPF_NAME
   724  	TCA_BPF_FLAGS
   725  	TCA_BPF_FLAGS_GEN
   726  	TCA_BPF_TAG
   727  	TCA_BPF_ID
   728  	TCA_BPF_MAX = TCA_BPF_ID
   729  )
   730  
   731  type TcBpf TcGen
   732  
   733  const (
   734  	TCA_ACT_CONNMARK = 14
   735  )
   736  
   737  const (
   738  	TCA_CONNMARK_UNSPEC = iota
   739  	TCA_CONNMARK_PARMS
   740  	TCA_CONNMARK_TM
   741  	TCA_CONNMARK_MAX = TCA_CONNMARK_TM
   742  )
   743  
   744  // struct tc_connmark {
   745  //   tc_gen;
   746  //   __u16 zone;
   747  // };
   748  
   749  type TcConnmark struct {
   750  	TcGen
   751  	Zone uint16
   752  }
   753  
   754  func (msg *TcConnmark) Len() int {
   755  	return SizeofTcConnmark
   756  }
   757  
   758  func DeserializeTcConnmark(b []byte) *TcConnmark {
   759  	return (*TcConnmark)(unsafe.Pointer(&b[0:SizeofTcConnmark][0]))
   760  }
   761  
   762  func (x *TcConnmark) Serialize() []byte {
   763  	return (*(*[SizeofTcConnmark]byte)(unsafe.Pointer(x)))[:]
   764  }
   765  
   766  const (
   767  	TCA_CSUM_UNSPEC = iota
   768  	TCA_CSUM_PARMS
   769  	TCA_CSUM_TM
   770  	TCA_CSUM_PAD
   771  	TCA_CSUM_MAX = TCA_CSUM_PAD
   772  )
   773  
   774  // struct tc_csum {
   775  //   tc_gen;
   776  //   __u32 update_flags;
   777  // }
   778  
   779  type TcCsum struct {
   780  	TcGen
   781  	UpdateFlags uint32
   782  }
   783  
   784  func (msg *TcCsum) Len() int {
   785  	return SizeofTcCsum
   786  }
   787  
   788  func DeserializeTcCsum(b []byte) *TcCsum {
   789  	return (*TcCsum)(unsafe.Pointer(&b[0:SizeofTcCsum][0]))
   790  }
   791  
   792  func (x *TcCsum) Serialize() []byte {
   793  	return (*(*[SizeofTcCsum]byte)(unsafe.Pointer(x)))[:]
   794  }
   795  
   796  const (
   797  	TCA_ACT_MIRRED = 8
   798  )
   799  
   800  const (
   801  	TCA_MIRRED_UNSPEC = iota
   802  	TCA_MIRRED_TM
   803  	TCA_MIRRED_PARMS
   804  	TCA_MIRRED_MAX = TCA_MIRRED_PARMS
   805  )
   806  
   807  // struct tc_mirred {
   808  // 	tc_gen;
   809  // 	int                     eaction;   /* one of IN/EGRESS_MIRROR/REDIR */
   810  // 	__u32                   ifindex;  /* ifindex of egress port */
   811  // };
   812  
   813  type TcMirred struct {
   814  	TcGen
   815  	Eaction int32
   816  	Ifindex uint32
   817  }
   818  
   819  func (msg *TcMirred) Len() int {
   820  	return SizeofTcMirred
   821  }
   822  
   823  func DeserializeTcMirred(b []byte) *TcMirred {
   824  	return (*TcMirred)(unsafe.Pointer(&b[0:SizeofTcMirred][0]))
   825  }
   826  
   827  func (x *TcMirred) Serialize() []byte {
   828  	return (*(*[SizeofTcMirred]byte)(unsafe.Pointer(x)))[:]
   829  }
   830  
   831  const (
   832  	TCA_VLAN_UNSPEC = iota
   833  	TCA_VLAN_TM
   834  	TCA_VLAN_PARMS
   835  	TCA_VLAN_PUSH_VLAN_ID
   836  	TCA_VLAN_PUSH_VLAN_PROTOCOL
   837  	TCA_VLAN_PAD
   838  	TCA_VLAN_PUSH_VLAN_PRIORITY
   839  	TCA_VLAN_PUSH_ETH_DST
   840  	TCA_VLAN_PUSH_ETH_SRC
   841  	TCA_VLAN_MAX
   842  )
   843  
   844  //struct tc_vlan {
   845  //	tc_gen;
   846  //	int v_action;
   847  //};
   848  
   849  type TcVlan struct {
   850  	TcGen
   851  	Action int32
   852  }
   853  
   854  func (msg *TcVlan) Len() int {
   855  	return SizeofTcVlan
   856  }
   857  
   858  func DeserializeTcVlan(b []byte) *TcVlan {
   859  	return (*TcVlan)(unsafe.Pointer(&b[0:SizeofTcVlan][0]))
   860  }
   861  
   862  func (x *TcVlan) Serialize() []byte {
   863  	return (*(*[SizeofTcVlan]byte)(unsafe.Pointer(x)))[:]
   864  }
   865  
   866  const (
   867  	TCA_TUNNEL_KEY_UNSPEC = iota
   868  	TCA_TUNNEL_KEY_TM
   869  	TCA_TUNNEL_KEY_PARMS
   870  	TCA_TUNNEL_KEY_ENC_IPV4_SRC
   871  	TCA_TUNNEL_KEY_ENC_IPV4_DST
   872  	TCA_TUNNEL_KEY_ENC_IPV6_SRC
   873  	TCA_TUNNEL_KEY_ENC_IPV6_DST
   874  	TCA_TUNNEL_KEY_ENC_KEY_ID
   875  	TCA_TUNNEL_KEY_PAD
   876  	TCA_TUNNEL_KEY_ENC_DST_PORT
   877  	TCA_TUNNEL_KEY_NO_CSUM
   878  	TCA_TUNNEL_KEY_ENC_OPTS
   879  	TCA_TUNNEL_KEY_ENC_TOS
   880  	TCA_TUNNEL_KEY_ENC_TTL
   881  	TCA_TUNNEL_KEY_MAX
   882  )
   883  
   884  type TcTunnelKey struct {
   885  	TcGen
   886  	Action int32
   887  }
   888  
   889  func (x *TcTunnelKey) Len() int {
   890  	return SizeofTcTunnelKey
   891  }
   892  
   893  func DeserializeTunnelKey(b []byte) *TcTunnelKey {
   894  	return (*TcTunnelKey)(unsafe.Pointer(&b[0:SizeofTcTunnelKey][0]))
   895  }
   896  
   897  func (x *TcTunnelKey) Serialize() []byte {
   898  	return (*(*[SizeofTcTunnelKey]byte)(unsafe.Pointer(x)))[:]
   899  }
   900  
   901  const (
   902  	TCA_SKBEDIT_UNSPEC = iota
   903  	TCA_SKBEDIT_TM
   904  	TCA_SKBEDIT_PARMS
   905  	TCA_SKBEDIT_PRIORITY
   906  	TCA_SKBEDIT_QUEUE_MAPPING
   907  	TCA_SKBEDIT_MARK
   908  	TCA_SKBEDIT_PAD
   909  	TCA_SKBEDIT_PTYPE
   910  	TCA_SKBEDIT_MASK
   911  	TCA_SKBEDIT_MAX
   912  )
   913  
   914  type TcSkbEdit struct {
   915  	TcGen
   916  }
   917  
   918  func (x *TcSkbEdit) Len() int {
   919  	return SizeofTcSkbEdit
   920  }
   921  
   922  func DeserializeSkbEdit(b []byte) *TcSkbEdit {
   923  	return (*TcSkbEdit)(unsafe.Pointer(&b[0:SizeofTcSkbEdit][0]))
   924  }
   925  
   926  func (x *TcSkbEdit) Serialize() []byte {
   927  	return (*(*[SizeofTcSkbEdit]byte)(unsafe.Pointer(x)))[:]
   928  }
   929  
   930  // struct tc_police {
   931  // 	__u32			index;
   932  // 	int			action;
   933  // 	__u32			limit;
   934  // 	__u32			burst;
   935  // 	__u32			mtu;
   936  // 	struct tc_ratespec	rate;
   937  // 	struct tc_ratespec	peakrate;
   938  // 	int				refcnt;
   939  // 	int				bindcnt;
   940  // 	__u32			capab;
   941  // };
   942  
   943  type TcPolice struct {
   944  	Index    uint32
   945  	Action   int32
   946  	Limit    uint32
   947  	Burst    uint32
   948  	Mtu      uint32
   949  	Rate     TcRateSpec
   950  	PeakRate TcRateSpec
   951  	Refcnt   int32
   952  	Bindcnt  int32
   953  	Capab    uint32
   954  }
   955  
   956  func (msg *TcPolice) Len() int {
   957  	return SizeofTcPolice
   958  }
   959  
   960  func DeserializeTcPolice(b []byte) *TcPolice {
   961  	return (*TcPolice)(unsafe.Pointer(&b[0:SizeofTcPolice][0]))
   962  }
   963  
   964  func (x *TcPolice) Serialize() []byte {
   965  	return (*(*[SizeofTcPolice]byte)(unsafe.Pointer(x)))[:]
   966  }
   967  
   968  const (
   969  	TCA_FW_UNSPEC = iota
   970  	TCA_FW_CLASSID
   971  	TCA_FW_POLICE
   972  	TCA_FW_INDEV
   973  	TCA_FW_ACT
   974  	TCA_FW_MASK
   975  	TCA_FW_MAX = TCA_FW_MASK
   976  )
   977  
   978  const (
   979  	TCA_MATCHALL_UNSPEC = iota
   980  	TCA_MATCHALL_CLASSID
   981  	TCA_MATCHALL_ACT
   982  	TCA_MATCHALL_FLAGS
   983  )
   984  
   985  const (
   986  	TCA_FQ_UNSPEC             = iota
   987  	TCA_FQ_PLIMIT             // limit of total number of packets in queue
   988  	TCA_FQ_FLOW_PLIMIT        // limit of packets per flow
   989  	TCA_FQ_QUANTUM            // RR quantum
   990  	TCA_FQ_INITIAL_QUANTUM    // RR quantum for new flow
   991  	TCA_FQ_RATE_ENABLE        // enable/disable rate limiting
   992  	TCA_FQ_FLOW_DEFAULT_RATE  // obsolete do not use
   993  	TCA_FQ_FLOW_MAX_RATE      // per flow max rate
   994  	TCA_FQ_BUCKETS_LOG        // log2(number of buckets)
   995  	TCA_FQ_FLOW_REFILL_DELAY  // flow credit refill delay in usec
   996  	TCA_FQ_ORPHAN_MASK        // mask applied to orphaned skb hashes
   997  	TCA_FQ_LOW_RATE_THRESHOLD // per packet delay under this rate
   998  	TCA_FQ_CE_THRESHOLD       // DCTCP-like CE-marking threshold
   999  	TCA_FQ_TIMER_SLACK        // timer slack
  1000  	TCA_FQ_HORIZON            // time horizon in us
  1001  	TCA_FQ_HORIZON_DROP       // drop packets beyond horizon, or cap their EDT
  1002  )
  1003  
  1004  const (
  1005  	TCA_FQ_CODEL_UNSPEC = iota
  1006  	TCA_FQ_CODEL_TARGET
  1007  	TCA_FQ_CODEL_LIMIT
  1008  	TCA_FQ_CODEL_INTERVAL
  1009  	TCA_FQ_CODEL_ECN
  1010  	TCA_FQ_CODEL_FLOWS
  1011  	TCA_FQ_CODEL_QUANTUM
  1012  	TCA_FQ_CODEL_CE_THRESHOLD
  1013  	TCA_FQ_CODEL_DROP_BATCH_SIZE
  1014  	TCA_FQ_CODEL_MEMORY_LIMIT
  1015  )
  1016  
  1017  const (
  1018  	TCA_HFSC_UNSPEC = iota
  1019  	TCA_HFSC_RSC
  1020  	TCA_HFSC_FSC
  1021  	TCA_HFSC_USC
  1022  )
  1023  
  1024  const (
  1025  	TCA_FLOWER_UNSPEC = iota
  1026  	TCA_FLOWER_CLASSID
  1027  	TCA_FLOWER_INDEV
  1028  	TCA_FLOWER_ACT
  1029  	TCA_FLOWER_KEY_ETH_DST       /* ETH_ALEN */
  1030  	TCA_FLOWER_KEY_ETH_DST_MASK  /* ETH_ALEN */
  1031  	TCA_FLOWER_KEY_ETH_SRC       /* ETH_ALEN */
  1032  	TCA_FLOWER_KEY_ETH_SRC_MASK  /* ETH_ALEN */
  1033  	TCA_FLOWER_KEY_ETH_TYPE      /* be16 */
  1034  	TCA_FLOWER_KEY_IP_PROTO      /* u8 */
  1035  	TCA_FLOWER_KEY_IPV4_SRC      /* be32 */
  1036  	TCA_FLOWER_KEY_IPV4_SRC_MASK /* be32 */
  1037  	TCA_FLOWER_KEY_IPV4_DST      /* be32 */
  1038  	TCA_FLOWER_KEY_IPV4_DST_MASK /* be32 */
  1039  	TCA_FLOWER_KEY_IPV6_SRC      /* struct in6_addr */
  1040  	TCA_FLOWER_KEY_IPV6_SRC_MASK /* struct in6_addr */
  1041  	TCA_FLOWER_KEY_IPV6_DST      /* struct in6_addr */
  1042  	TCA_FLOWER_KEY_IPV6_DST_MASK /* struct in6_addr */
  1043  	TCA_FLOWER_KEY_TCP_SRC       /* be16 */
  1044  	TCA_FLOWER_KEY_TCP_DST       /* be16 */
  1045  	TCA_FLOWER_KEY_UDP_SRC       /* be16 */
  1046  	TCA_FLOWER_KEY_UDP_DST       /* be16 */
  1047  
  1048  	TCA_FLOWER_FLAGS
  1049  	TCA_FLOWER_KEY_VLAN_ID       /* be16 */
  1050  	TCA_FLOWER_KEY_VLAN_PRIO     /* u8   */
  1051  	TCA_FLOWER_KEY_VLAN_ETH_TYPE /* be16 */
  1052  
  1053  	TCA_FLOWER_KEY_ENC_KEY_ID        /* be32 */
  1054  	TCA_FLOWER_KEY_ENC_IPV4_SRC      /* be32 */
  1055  	TCA_FLOWER_KEY_ENC_IPV4_SRC_MASK /* be32 */
  1056  	TCA_FLOWER_KEY_ENC_IPV4_DST      /* be32 */
  1057  	TCA_FLOWER_KEY_ENC_IPV4_DST_MASK /* be32 */
  1058  	TCA_FLOWER_KEY_ENC_IPV6_SRC      /* struct in6_addr */
  1059  	TCA_FLOWER_KEY_ENC_IPV6_SRC_MASK /* struct in6_addr */
  1060  	TCA_FLOWER_KEY_ENC_IPV6_DST      /* struct in6_addr */
  1061  	TCA_FLOWER_KEY_ENC_IPV6_DST_MASK /* struct in6_addr */
  1062  
  1063  	TCA_FLOWER_KEY_TCP_SRC_MASK  /* be16 */
  1064  	TCA_FLOWER_KEY_TCP_DST_MASK  /* be16 */
  1065  	TCA_FLOWER_KEY_UDP_SRC_MASK  /* be16 */
  1066  	TCA_FLOWER_KEY_UDP_DST_MASK  /* be16 */
  1067  	TCA_FLOWER_KEY_SCTP_SRC_MASK /* be16 */
  1068  	TCA_FLOWER_KEY_SCTP_DST_MASK /* be16 */
  1069  
  1070  	TCA_FLOWER_KEY_SCTP_SRC /* be16 */
  1071  	TCA_FLOWER_KEY_SCTP_DST /* be16 */
  1072  
  1073  	TCA_FLOWER_KEY_ENC_UDP_SRC_PORT      /* be16 */
  1074  	TCA_FLOWER_KEY_ENC_UDP_SRC_PORT_MASK /* be16 */
  1075  	TCA_FLOWER_KEY_ENC_UDP_DST_PORT      /* be16 */
  1076  	TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK /* be16 */
  1077  
  1078  	TCA_FLOWER_KEY_FLAGS      /* be32 */
  1079  	TCA_FLOWER_KEY_FLAGS_MASK /* be32 */
  1080  
  1081  	TCA_FLOWER_KEY_ICMPV4_CODE      /* u8 */
  1082  	TCA_FLOWER_KEY_ICMPV4_CODE_MASK /* u8 */
  1083  	TCA_FLOWER_KEY_ICMPV4_TYPE      /* u8 */
  1084  	TCA_FLOWER_KEY_ICMPV4_TYPE_MASK /* u8 */
  1085  	TCA_FLOWER_KEY_ICMPV6_CODE      /* u8 */
  1086  	TCA_FLOWER_KEY_ICMPV6_CODE_MASK /* u8 */
  1087  	TCA_FLOWER_KEY_ICMPV6_TYPE      /* u8 */
  1088  	TCA_FLOWER_KEY_ICMPV6_TYPE_MASK /* u8 */
  1089  
  1090  	TCA_FLOWER_KEY_ARP_SIP      /* be32 */
  1091  	TCA_FLOWER_KEY_ARP_SIP_MASK /* be32 */
  1092  	TCA_FLOWER_KEY_ARP_TIP      /* be32 */
  1093  	TCA_FLOWER_KEY_ARP_TIP_MASK /* be32 */
  1094  	TCA_FLOWER_KEY_ARP_OP       /* u8 */
  1095  	TCA_FLOWER_KEY_ARP_OP_MASK  /* u8 */
  1096  	TCA_FLOWER_KEY_ARP_SHA      /* ETH_ALEN */
  1097  	TCA_FLOWER_KEY_ARP_SHA_MASK /* ETH_ALEN */
  1098  	TCA_FLOWER_KEY_ARP_THA      /* ETH_ALEN */
  1099  	TCA_FLOWER_KEY_ARP_THA_MASK /* ETH_ALEN */
  1100  
  1101  	TCA_FLOWER_KEY_MPLS_TTL   /* u8 - 8 bits */
  1102  	TCA_FLOWER_KEY_MPLS_BOS   /* u8 - 1 bit */
  1103  	TCA_FLOWER_KEY_MPLS_TC    /* u8 - 3 bits */
  1104  	TCA_FLOWER_KEY_MPLS_LABEL /* be32 - 20 bits */
  1105  
  1106  	TCA_FLOWER_KEY_TCP_FLAGS      /* be16 */
  1107  	TCA_FLOWER_KEY_TCP_FLAGS_MASK /* be16 */
  1108  
  1109  	TCA_FLOWER_KEY_IP_TOS      /* u8 */
  1110  	TCA_FLOWER_KEY_IP_TOS_MASK /* u8 */
  1111  	TCA_FLOWER_KEY_IP_TTL      /* u8 */
  1112  	TCA_FLOWER_KEY_IP_TTL_MASK /* u8 */
  1113  
  1114  	TCA_FLOWER_KEY_CVLAN_ID       /* be16 */
  1115  	TCA_FLOWER_KEY_CVLAN_PRIO     /* u8   */
  1116  	TCA_FLOWER_KEY_CVLAN_ETH_TYPE /* be16 */
  1117  
  1118  	TCA_FLOWER_KEY_ENC_IP_TOS      /* u8 */
  1119  	TCA_FLOWER_KEY_ENC_IP_TOS_MASK /* u8 */
  1120  	TCA_FLOWER_KEY_ENC_IP_TTL      /* u8 */
  1121  	TCA_FLOWER_KEY_ENC_IP_TTL_MASK /* u8 */
  1122  
  1123  	TCA_FLOWER_KEY_ENC_OPTS
  1124  	TCA_FLOWER_KEY_ENC_OPTS_MASK
  1125  
  1126  	TCA_FLOWER_IN_HW_COUNT
  1127  
  1128  	TCA_FLOWER_KEY_PORT_SRC_MIN /* be16 */
  1129  	TCA_FLOWER_KEY_PORT_SRC_MAX /* be16 */
  1130  	TCA_FLOWER_KEY_PORT_DST_MIN /* be16 */
  1131  	TCA_FLOWER_KEY_PORT_DST_MAX /* be16 */
  1132  
  1133  	__TCA_FLOWER_MAX
  1134  )
  1135  
  1136  const TCA_CLS_FLAGS_SKIP_HW = 1 << 0 /* don't offload filter to HW */
  1137  const TCA_CLS_FLAGS_SKIP_SW = 1 << 1 /* don't use filter in SW */
  1138  
  1139  // struct tc_sfq_qopt {
  1140  // 	unsigned	quantum;	/* Bytes per round allocated to flow */
  1141  // 	int		perturb_period;	/* Period of hash perturbation */
  1142  // 	__u32		limit;		/* Maximal packets in queue */
  1143  // 	unsigned	divisor;	/* Hash divisor  */
  1144  // 	unsigned	flows;		/* Maximal number of flows  */
  1145  // };
  1146  
  1147  type TcSfqQopt struct {
  1148  	Quantum uint32
  1149  	Perturb int32
  1150  	Limit   uint32
  1151  	Divisor uint32
  1152  	Flows   uint32
  1153  }
  1154  
  1155  func (x *TcSfqQopt) Len() int {
  1156  	return SizeofTcSfqQopt
  1157  }
  1158  
  1159  func DeserializeTcSfqQopt(b []byte) *TcSfqQopt {
  1160  	return (*TcSfqQopt)(unsafe.Pointer(&b[0:SizeofTcSfqQopt][0]))
  1161  }
  1162  
  1163  func (x *TcSfqQopt) Serialize() []byte {
  1164  	return (*(*[SizeofTcSfqQopt]byte)(unsafe.Pointer(x)))[:]
  1165  }
  1166  
  1167  //	struct tc_sfqred_stats {
  1168  //		__u32           prob_drop;      /* Early drops, below max threshold */
  1169  //		__u32           forced_drop;	/* Early drops, after max threshold */
  1170  //		__u32           prob_mark;      /* Marked packets, below max threshold */
  1171  //		__u32           forced_mark;    /* Marked packets, after max threshold */
  1172  //		__u32           prob_mark_head; /* Marked packets, below max threshold */
  1173  //		__u32           forced_mark_head;/* Marked packets, after max threshold */
  1174  //	};
  1175  type TcSfqRedStats struct {
  1176  	ProbDrop       uint32
  1177  	ForcedDrop     uint32
  1178  	ProbMark       uint32
  1179  	ForcedMark     uint32
  1180  	ProbMarkHead   uint32
  1181  	ForcedMarkHead uint32
  1182  }
  1183  
  1184  func (x *TcSfqRedStats) Len() int {
  1185  	return SizeofTcSfqRedStats
  1186  }
  1187  
  1188  func DeserializeTcSfqRedStats(b []byte) *TcSfqRedStats {
  1189  	return (*TcSfqRedStats)(unsafe.Pointer(&b[0:SizeofTcSfqRedStats][0]))
  1190  }
  1191  
  1192  func (x *TcSfqRedStats) Serialize() []byte {
  1193  	return (*(*[SizeofTcSfqRedStats]byte)(unsafe.Pointer(x)))[:]
  1194  }
  1195  
  1196  //	struct tc_sfq_qopt_v1 {
  1197  //		struct tc_sfq_qopt v0;
  1198  //		unsigned int	depth;		/* max number of packets per flow */
  1199  //		unsigned int	headdrop;
  1200  //
  1201  // /* SFQRED parameters */
  1202  //
  1203  //	__u32		limit;		/* HARD maximal flow queue length (bytes) */
  1204  //	__u32		qth_min;	/* Min average length threshold (bytes) */
  1205  //	__u32		qth_max;	/* Max average length threshold (bytes) */
  1206  //	unsigned char   Wlog;		/* log(W)		*/
  1207  //	unsigned char   Plog;		/* log(P_max/(qth_max-qth_min))	*/
  1208  //	unsigned char   Scell_log;	/* cell size for idle damping */
  1209  //	unsigned char	flags;
  1210  //	__u32		max_P;		/* probability, high resolution */
  1211  //
  1212  // /* SFQRED stats */
  1213  //
  1214  //		struct tc_sfqred_stats stats;
  1215  //	};
  1216  type TcSfqQoptV1 struct {
  1217  	TcSfqQopt
  1218  	Depth    uint32
  1219  	HeadDrop uint32
  1220  	Limit    uint32
  1221  	QthMin   uint32
  1222  	QthMax   uint32
  1223  	Wlog     byte
  1224  	Plog     byte
  1225  	ScellLog byte
  1226  	Flags    byte
  1227  	MaxP     uint32
  1228  	TcSfqRedStats
  1229  }
  1230  
  1231  func (x *TcSfqQoptV1) Len() int {
  1232  	return SizeofTcSfqQoptV1
  1233  }
  1234  
  1235  func DeserializeTcSfqQoptV1(b []byte) *TcSfqQoptV1 {
  1236  	return (*TcSfqQoptV1)(unsafe.Pointer(&b[0:SizeofTcSfqQoptV1][0]))
  1237  }
  1238  
  1239  func (x *TcSfqQoptV1) Serialize() []byte {
  1240  	return (*(*[SizeofTcSfqQoptV1]byte)(unsafe.Pointer(x)))[:]
  1241  }
  1242  
  1243  // IPProto represents Flower ip_proto attribute
  1244  type IPProto uint8
  1245  
  1246  const (
  1247  	IPPROTO_TCP    IPProto = unix.IPPROTO_TCP
  1248  	IPPROTO_UDP    IPProto = unix.IPPROTO_UDP
  1249  	IPPROTO_SCTP   IPProto = unix.IPPROTO_SCTP
  1250  	IPPROTO_ICMP   IPProto = unix.IPPROTO_ICMP
  1251  	IPPROTO_ICMPV6 IPProto = unix.IPPROTO_ICMPV6
  1252  )
  1253  
  1254  func (i IPProto) Serialize() []byte {
  1255  	arr := make([]byte, 1)
  1256  	arr[0] = byte(i)
  1257  	return arr
  1258  }
  1259  
  1260  func (i IPProto) String() string {
  1261  	switch i {
  1262  	case IPPROTO_TCP:
  1263  		return "tcp"
  1264  	case IPPROTO_UDP:
  1265  		return "udp"
  1266  	case IPPROTO_SCTP:
  1267  		return "sctp"
  1268  	case IPPROTO_ICMP:
  1269  		return "icmp"
  1270  	case IPPROTO_ICMPV6:
  1271  		return "icmpv6"
  1272  	}
  1273  	return fmt.Sprintf("%d", i)
  1274  }
  1275  
  1276  const (
  1277  	MaxOffs        = 128
  1278  	SizeOfPeditSel = 24
  1279  	SizeOfPeditKey = 24
  1280  
  1281  	TCA_PEDIT_KEY_EX_HTYPE = 1
  1282  	TCA_PEDIT_KEY_EX_CMD   = 2
  1283  )
  1284  
  1285  const (
  1286  	TCA_PEDIT_UNSPEC = iota
  1287  	TCA_PEDIT_TM
  1288  	TCA_PEDIT_PARMS
  1289  	TCA_PEDIT_PAD
  1290  	TCA_PEDIT_PARMS_EX
  1291  	TCA_PEDIT_KEYS_EX
  1292  	TCA_PEDIT_KEY_EX
  1293  )
  1294  
  1295  // /* TCA_PEDIT_KEY_EX_HDR_TYPE_NETWROK is a special case for legacy users. It
  1296  //   - means no specific header type - offset is relative to the network layer
  1297  //     */
  1298  type PeditHeaderType uint16
  1299  
  1300  const (
  1301  	TCA_PEDIT_KEY_EX_HDR_TYPE_NETWORK = iota
  1302  	TCA_PEDIT_KEY_EX_HDR_TYPE_ETH
  1303  	TCA_PEDIT_KEY_EX_HDR_TYPE_IP4
  1304  	TCA_PEDIT_KEY_EX_HDR_TYPE_IP6
  1305  	TCA_PEDIT_KEY_EX_HDR_TYPE_TCP
  1306  	TCA_PEDIT_KEY_EX_HDR_TYPE_UDP
  1307  	__PEDIT_HDR_TYPE_MAX
  1308  )
  1309  
  1310  type PeditCmd uint16
  1311  
  1312  const (
  1313  	TCA_PEDIT_KEY_EX_CMD_SET = 0
  1314  	TCA_PEDIT_KEY_EX_CMD_ADD = 1
  1315  )
  1316  
  1317  type TcPeditSel struct {
  1318  	TcGen
  1319  	NKeys uint8
  1320  	Flags uint8
  1321  }
  1322  
  1323  func DeserializeTcPeditKey(b []byte) *TcPeditKey {
  1324  	return (*TcPeditKey)(unsafe.Pointer(&b[0:SizeOfPeditKey][0]))
  1325  }
  1326  
  1327  func DeserializeTcPedit(b []byte) (*TcPeditSel, []TcPeditKey) {
  1328  	x := &TcPeditSel{}
  1329  	copy((*(*[SizeOfPeditSel]byte)(unsafe.Pointer(x)))[:SizeOfPeditSel], b)
  1330  
  1331  	var keys []TcPeditKey
  1332  
  1333  	next := SizeOfPeditKey
  1334  	var i uint8
  1335  	for i = 0; i < x.NKeys; i++ {
  1336  		keys = append(keys, *DeserializeTcPeditKey(b[next:]))
  1337  		next += SizeOfPeditKey
  1338  	}
  1339  
  1340  	return x, keys
  1341  }
  1342  
  1343  type TcPeditKey struct {
  1344  	Mask    uint32
  1345  	Val     uint32
  1346  	Off     uint32
  1347  	At      uint32
  1348  	OffMask uint32
  1349  	Shift   uint32
  1350  }
  1351  
  1352  type TcPeditKeyEx struct {
  1353  	HeaderType PeditHeaderType
  1354  	Cmd        PeditCmd
  1355  }
  1356  
  1357  type TcPedit struct {
  1358  	Sel    TcPeditSel
  1359  	Keys   []TcPeditKey
  1360  	KeysEx []TcPeditKeyEx
  1361  	Extend uint8
  1362  }
  1363  
  1364  func (p *TcPedit) Encode(parent *RtAttr) {
  1365  	parent.AddRtAttr(TCA_ACT_KIND, ZeroTerminated("pedit"))
  1366  	actOpts := parent.AddRtAttr(TCA_ACT_OPTIONS, nil)
  1367  
  1368  	bbuf := bytes.NewBuffer(make([]byte, 0, int(unsafe.Sizeof(p.Sel)+unsafe.Sizeof(p.Keys))))
  1369  
  1370  	bbuf.Write((*(*[SizeOfPeditSel]byte)(unsafe.Pointer(&p.Sel)))[:])
  1371  
  1372  	for i := uint8(0); i < p.Sel.NKeys; i++ {
  1373  		bbuf.Write((*(*[SizeOfPeditKey]byte)(unsafe.Pointer(&p.Keys[i])))[:])
  1374  	}
  1375  	actOpts.AddRtAttr(TCA_PEDIT_PARMS_EX, bbuf.Bytes())
  1376  
  1377  	exAttrs := actOpts.AddRtAttr(int(TCA_PEDIT_KEYS_EX|NLA_F_NESTED), nil)
  1378  	for i := uint8(0); i < p.Sel.NKeys; i++ {
  1379  		keyAttr := exAttrs.AddRtAttr(int(TCA_PEDIT_KEY_EX|NLA_F_NESTED), nil)
  1380  
  1381  		htypeBuf := make([]byte, 2)
  1382  		cmdBuf := make([]byte, 2)
  1383  
  1384  		NativeEndian().PutUint16(htypeBuf, uint16(p.KeysEx[i].HeaderType))
  1385  		NativeEndian().PutUint16(cmdBuf, uint16(p.KeysEx[i].Cmd))
  1386  
  1387  		keyAttr.AddRtAttr(TCA_PEDIT_KEY_EX_HTYPE, htypeBuf)
  1388  		keyAttr.AddRtAttr(TCA_PEDIT_KEY_EX_CMD, cmdBuf)
  1389  	}
  1390  }
  1391  
  1392  func (p *TcPedit) SetEthDst(mac net.HardwareAddr) {
  1393  	u32 := NativeEndian().Uint32(mac)
  1394  	u16 := NativeEndian().Uint16(mac[4:])
  1395  
  1396  	tKey := TcPeditKey{}
  1397  	tKeyEx := TcPeditKeyEx{}
  1398  
  1399  	tKey.Val = u32
  1400  
  1401  	tKeyEx.HeaderType = TCA_PEDIT_KEY_EX_HDR_TYPE_ETH
  1402  	tKeyEx.Cmd = TCA_PEDIT_KEY_EX_CMD_SET
  1403  
  1404  	p.Keys = append(p.Keys, tKey)
  1405  	p.KeysEx = append(p.KeysEx, tKeyEx)
  1406  	p.Sel.NKeys++
  1407  
  1408  	tKey = TcPeditKey{}
  1409  	tKeyEx = TcPeditKeyEx{}
  1410  
  1411  	tKey.Val = uint32(u16)
  1412  	tKey.Mask = 0xffff0000
  1413  	tKey.Off = 4
  1414  	tKeyEx.HeaderType = TCA_PEDIT_KEY_EX_HDR_TYPE_ETH
  1415  	tKeyEx.Cmd = TCA_PEDIT_KEY_EX_CMD_SET
  1416  
  1417  	p.Keys = append(p.Keys, tKey)
  1418  	p.KeysEx = append(p.KeysEx, tKeyEx)
  1419  
  1420  	p.Sel.NKeys++
  1421  }
  1422  
  1423  func (p *TcPedit) SetEthSrc(mac net.HardwareAddr) {
  1424  	u16 := NativeEndian().Uint16(mac)
  1425  	u32 := NativeEndian().Uint32(mac[2:])
  1426  
  1427  	tKey := TcPeditKey{}
  1428  	tKeyEx := TcPeditKeyEx{}
  1429  
  1430  	tKey.Val = uint32(u16) << 16
  1431  	tKey.Mask = 0x0000ffff
  1432  	tKey.Off = 4
  1433  
  1434  	tKeyEx.HeaderType = TCA_PEDIT_KEY_EX_HDR_TYPE_ETH
  1435  	tKeyEx.Cmd = TCA_PEDIT_KEY_EX_CMD_SET
  1436  
  1437  	p.Keys = append(p.Keys, tKey)
  1438  	p.KeysEx = append(p.KeysEx, tKeyEx)
  1439  	p.Sel.NKeys++
  1440  
  1441  	tKey = TcPeditKey{}
  1442  	tKeyEx = TcPeditKeyEx{}
  1443  
  1444  	tKey.Val = u32
  1445  	tKey.Mask = 0
  1446  	tKey.Off = 8
  1447  
  1448  	tKeyEx.HeaderType = TCA_PEDIT_KEY_EX_HDR_TYPE_ETH
  1449  	tKeyEx.Cmd = TCA_PEDIT_KEY_EX_CMD_SET
  1450  
  1451  	p.Keys = append(p.Keys, tKey)
  1452  	p.KeysEx = append(p.KeysEx, tKeyEx)
  1453  
  1454  	p.Sel.NKeys++
  1455  }
  1456  
  1457  func (p *TcPedit) SetIPv6Src(ip6 net.IP) {
  1458  	u32 := NativeEndian().Uint32(ip6[:4])
  1459  
  1460  	tKey := TcPeditKey{}
  1461  	tKeyEx := TcPeditKeyEx{}
  1462  
  1463  	tKey.Val = u32
  1464  	tKey.Off = 8
  1465  	tKeyEx.HeaderType = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6
  1466  	tKeyEx.Cmd = TCA_PEDIT_KEY_EX_CMD_SET
  1467  
  1468  	p.Keys = append(p.Keys, tKey)
  1469  	p.KeysEx = append(p.KeysEx, tKeyEx)
  1470  	p.Sel.NKeys++
  1471  
  1472  	u32 = NativeEndian().Uint32(ip6[4:8])
  1473  	tKey = TcPeditKey{}
  1474  	tKeyEx = TcPeditKeyEx{}
  1475  
  1476  	tKey.Val = u32
  1477  	tKey.Off = 12
  1478  	tKeyEx.HeaderType = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6
  1479  	tKeyEx.Cmd = TCA_PEDIT_KEY_EX_CMD_SET
  1480  
  1481  	p.Keys = append(p.Keys, tKey)
  1482  	p.KeysEx = append(p.KeysEx, tKeyEx)
  1483  
  1484  	p.Sel.NKeys++
  1485  
  1486  	u32 = NativeEndian().Uint32(ip6[8:12])
  1487  	tKey = TcPeditKey{}
  1488  	tKeyEx = TcPeditKeyEx{}
  1489  
  1490  	tKey.Val = u32
  1491  	tKey.Off = 16
  1492  	tKeyEx.HeaderType = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6
  1493  	tKeyEx.Cmd = TCA_PEDIT_KEY_EX_CMD_SET
  1494  
  1495  	p.Keys = append(p.Keys, tKey)
  1496  	p.KeysEx = append(p.KeysEx, tKeyEx)
  1497  
  1498  	p.Sel.NKeys++
  1499  
  1500  	u32 = NativeEndian().Uint32(ip6[12:16])
  1501  	tKey = TcPeditKey{}
  1502  	tKeyEx = TcPeditKeyEx{}
  1503  
  1504  	tKey.Val = u32
  1505  	tKey.Off = 20
  1506  	tKeyEx.HeaderType = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6
  1507  	tKeyEx.Cmd = TCA_PEDIT_KEY_EX_CMD_SET
  1508  
  1509  	p.Keys = append(p.Keys, tKey)
  1510  	p.KeysEx = append(p.KeysEx, tKeyEx)
  1511  
  1512  	p.Sel.NKeys++
  1513  }
  1514  
  1515  func (p *TcPedit) SetDstIP(ip net.IP) {
  1516  	if ip.To4() != nil {
  1517  		p.SetIPv4Dst(ip)
  1518  	} else {
  1519  		p.SetIPv6Dst(ip)
  1520  	}
  1521  }
  1522  
  1523  func (p *TcPedit) SetSrcIP(ip net.IP) {
  1524  	if ip.To4() != nil {
  1525  		p.SetIPv4Src(ip)
  1526  	} else {
  1527  		p.SetIPv6Src(ip)
  1528  	}
  1529  }
  1530  
  1531  func (p *TcPedit) SetIPv6Dst(ip6 net.IP) {
  1532  	u32 := NativeEndian().Uint32(ip6[:4])
  1533  
  1534  	tKey := TcPeditKey{}
  1535  	tKeyEx := TcPeditKeyEx{}
  1536  
  1537  	tKey.Val = u32
  1538  	tKey.Off = 24
  1539  	tKeyEx.HeaderType = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6
  1540  	tKeyEx.Cmd = TCA_PEDIT_KEY_EX_CMD_SET
  1541  
  1542  	p.Keys = append(p.Keys, tKey)
  1543  	p.KeysEx = append(p.KeysEx, tKeyEx)
  1544  	p.Sel.NKeys++
  1545  
  1546  	u32 = NativeEndian().Uint32(ip6[4:8])
  1547  	tKey = TcPeditKey{}
  1548  	tKeyEx = TcPeditKeyEx{}
  1549  
  1550  	tKey.Val = u32
  1551  	tKey.Off = 28
  1552  	tKeyEx.HeaderType = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6
  1553  	tKeyEx.Cmd = TCA_PEDIT_KEY_EX_CMD_SET
  1554  
  1555  	p.Keys = append(p.Keys, tKey)
  1556  	p.KeysEx = append(p.KeysEx, tKeyEx)
  1557  
  1558  	p.Sel.NKeys++
  1559  
  1560  	u32 = NativeEndian().Uint32(ip6[8:12])
  1561  	tKey = TcPeditKey{}
  1562  	tKeyEx = TcPeditKeyEx{}
  1563  
  1564  	tKey.Val = u32
  1565  	tKey.Off = 32
  1566  	tKeyEx.HeaderType = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6
  1567  	tKeyEx.Cmd = TCA_PEDIT_KEY_EX_CMD_SET
  1568  
  1569  	p.Keys = append(p.Keys, tKey)
  1570  	p.KeysEx = append(p.KeysEx, tKeyEx)
  1571  
  1572  	p.Sel.NKeys++
  1573  
  1574  	u32 = NativeEndian().Uint32(ip6[12:16])
  1575  	tKey = TcPeditKey{}
  1576  	tKeyEx = TcPeditKeyEx{}
  1577  
  1578  	tKey.Val = u32
  1579  	tKey.Off = 36
  1580  	tKeyEx.HeaderType = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6
  1581  	tKeyEx.Cmd = TCA_PEDIT_KEY_EX_CMD_SET
  1582  
  1583  	p.Keys = append(p.Keys, tKey)
  1584  	p.KeysEx = append(p.KeysEx, tKeyEx)
  1585  
  1586  	p.Sel.NKeys++
  1587  }
  1588  
  1589  func (p *TcPedit) SetIPv4Src(ip net.IP) {
  1590  	u32 := NativeEndian().Uint32(ip.To4())
  1591  
  1592  	tKey := TcPeditKey{}
  1593  	tKeyEx := TcPeditKeyEx{}
  1594  
  1595  	tKey.Val = u32
  1596  	tKey.Off = 12
  1597  	tKeyEx.HeaderType = TCA_PEDIT_KEY_EX_HDR_TYPE_IP4
  1598  	tKeyEx.Cmd = TCA_PEDIT_KEY_EX_CMD_SET
  1599  
  1600  	p.Keys = append(p.Keys, tKey)
  1601  	p.KeysEx = append(p.KeysEx, tKeyEx)
  1602  	p.Sel.NKeys++
  1603  }
  1604  
  1605  func (p *TcPedit) SetIPv4Dst(ip net.IP) {
  1606  	u32 := NativeEndian().Uint32(ip.To4())
  1607  
  1608  	tKey := TcPeditKey{}
  1609  	tKeyEx := TcPeditKeyEx{}
  1610  
  1611  	tKey.Val = u32
  1612  	tKey.Off = 16
  1613  	tKeyEx.HeaderType = TCA_PEDIT_KEY_EX_HDR_TYPE_IP4
  1614  	tKeyEx.Cmd = TCA_PEDIT_KEY_EX_CMD_SET
  1615  
  1616  	p.Keys = append(p.Keys, tKey)
  1617  	p.KeysEx = append(p.KeysEx, tKeyEx)
  1618  	p.Sel.NKeys++
  1619  }
  1620  
  1621  // SetDstPort only tcp and udp are supported to set port
  1622  func (p *TcPedit) SetDstPort(dstPort uint16, protocol uint8) {
  1623  	tKey := TcPeditKey{}
  1624  	tKeyEx := TcPeditKeyEx{}
  1625  
  1626  	switch protocol {
  1627  	case unix.IPPROTO_TCP:
  1628  		tKeyEx.HeaderType = TCA_PEDIT_KEY_EX_HDR_TYPE_TCP
  1629  	case unix.IPPROTO_UDP:
  1630  		tKeyEx.HeaderType = TCA_PEDIT_KEY_EX_HDR_TYPE_UDP
  1631  	default:
  1632  		return
  1633  	}
  1634  
  1635  	tKeyEx.Cmd = TCA_PEDIT_KEY_EX_CMD_SET
  1636  
  1637  	tKey.Val = uint32(Swap16(dstPort)) << 16
  1638  	tKey.Mask = 0x0000ffff
  1639  	p.Keys = append(p.Keys, tKey)
  1640  	p.KeysEx = append(p.KeysEx, tKeyEx)
  1641  	p.Sel.NKeys++
  1642  }
  1643  
  1644  // SetSrcPort only tcp and udp are supported to set port
  1645  func (p *TcPedit) SetSrcPort(srcPort uint16, protocol uint8) {
  1646  	tKey := TcPeditKey{}
  1647  	tKeyEx := TcPeditKeyEx{}
  1648  
  1649  	switch protocol {
  1650  	case unix.IPPROTO_TCP:
  1651  		tKeyEx.HeaderType = TCA_PEDIT_KEY_EX_HDR_TYPE_TCP
  1652  	case unix.IPPROTO_UDP:
  1653  		tKeyEx.HeaderType = TCA_PEDIT_KEY_EX_HDR_TYPE_UDP
  1654  	default:
  1655  		return
  1656  	}
  1657  
  1658  	tKeyEx.Cmd = TCA_PEDIT_KEY_EX_CMD_SET
  1659  
  1660  	tKey.Val = uint32(Swap16(srcPort))
  1661  	tKey.Mask = 0xffff0000
  1662  	p.Keys = append(p.Keys, tKey)
  1663  	p.KeysEx = append(p.KeysEx, tKeyEx)
  1664  	p.Sel.NKeys++
  1665  }