2015-08-18 10:16:54 +00:00
|
|
|
package nl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2015-09-12 06:24:22 +00:00
|
|
|
// LinkLayer
|
|
|
|
const (
|
|
|
|
LINKLAYER_UNSPEC = iota
|
|
|
|
LINKLAYER_ETHERNET
|
|
|
|
LINKLAYER_ATM
|
|
|
|
)
|
|
|
|
|
|
|
|
// ATM
|
|
|
|
const (
|
|
|
|
ATM_CELL_PAYLOAD = 48
|
|
|
|
ATM_CELL_SIZE = 53
|
|
|
|
)
|
|
|
|
|
|
|
|
const TC_LINKLAYER_MASK = 0x0F
|
|
|
|
|
|
|
|
// Police
|
|
|
|
const (
|
|
|
|
TCA_POLICE_UNSPEC = iota
|
|
|
|
TCA_POLICE_TBF
|
|
|
|
TCA_POLICE_RATE
|
|
|
|
TCA_POLICE_PEAKRATE
|
|
|
|
TCA_POLICE_AVRATE
|
|
|
|
TCA_POLICE_RESULT
|
|
|
|
TCA_POLICE_MAX = TCA_POLICE_RESULT
|
|
|
|
)
|
|
|
|
|
2015-08-18 10:16:54 +00:00
|
|
|
// Message types
|
|
|
|
const (
|
|
|
|
TCA_UNSPEC = iota
|
|
|
|
TCA_KIND
|
|
|
|
TCA_OPTIONS
|
|
|
|
TCA_STATS
|
|
|
|
TCA_XSTATS
|
|
|
|
TCA_RATE
|
|
|
|
TCA_FCNT
|
|
|
|
TCA_STATS2
|
|
|
|
TCA_STAB
|
|
|
|
TCA_MAX = TCA_STAB
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
TCA_ACT_TAB = 1
|
|
|
|
TCAA_MAX = 1
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
TCA_PRIO_UNSPEC = iota
|
|
|
|
TCA_PRIO_MQ
|
|
|
|
TCA_PRIO_MAX = TCA_PRIO_MQ
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
SizeofTcMsg = 0x14
|
|
|
|
SizeofTcActionMsg = 0x04
|
|
|
|
SizeofTcPrioMap = 0x14
|
2015-08-18 21:07:01 +00:00
|
|
|
SizeofTcRateSpec = 0x0c
|
|
|
|
SizeofTcTbfQopt = 2*SizeofTcRateSpec + 0x0c
|
2015-09-10 23:20:18 +00:00
|
|
|
SizeofTcHtbCopt = 2*SizeofTcRateSpec + 0x14
|
2015-09-05 07:13:17 +00:00
|
|
|
SizeofTcHtbGlob = 0x14
|
2015-08-19 23:02:04 +00:00
|
|
|
SizeofTcU32Key = 0x10
|
|
|
|
SizeofTcU32Sel = 0x10 // without keys
|
|
|
|
SizeofTcMirred = 0x1c
|
2015-09-12 06:24:22 +00:00
|
|
|
SizeofTcPolice = 2*SizeofTcRateSpec + 0x20
|
2015-08-18 10:16:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// struct tcmsg {
|
|
|
|
// unsigned char tcm_family;
|
|
|
|
// unsigned char tcm__pad1;
|
|
|
|
// unsigned short tcm__pad2;
|
|
|
|
// int tcm_ifindex;
|
|
|
|
// __u32 tcm_handle;
|
|
|
|
// __u32 tcm_parent;
|
|
|
|
// __u32 tcm_info;
|
|
|
|
// };
|
|
|
|
|
|
|
|
type TcMsg struct {
|
|
|
|
Family uint8
|
|
|
|
Pad [3]byte
|
|
|
|
Ifindex int32
|
|
|
|
Handle uint32
|
|
|
|
Parent uint32
|
|
|
|
Info uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
func (msg *TcMsg) Len() int {
|
|
|
|
return SizeofTcMsg
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeserializeTcMsg(b []byte) *TcMsg {
|
|
|
|
return (*TcMsg)(unsafe.Pointer(&b[0:SizeofTcMsg][0]))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *TcMsg) Serialize() []byte {
|
|
|
|
return (*(*[SizeofTcMsg]byte)(unsafe.Pointer(x)))[:]
|
|
|
|
}
|
|
|
|
|
|
|
|
// struct tcamsg {
|
|
|
|
// unsigned char tca_family;
|
|
|
|
// unsigned char tca__pad1;
|
|
|
|
// unsigned short tca__pad2;
|
|
|
|
// };
|
|
|
|
|
|
|
|
type TcActionMsg struct {
|
|
|
|
Family uint8
|
|
|
|
Pad [3]byte
|
|
|
|
}
|
|
|
|
|
|
|
|
func (msg *TcActionMsg) Len() int {
|
|
|
|
return SizeofTcActionMsg
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeserializeTcActionMsg(b []byte) *TcActionMsg {
|
|
|
|
return (*TcActionMsg)(unsafe.Pointer(&b[0:SizeofTcActionMsg][0]))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *TcActionMsg) Serialize() []byte {
|
|
|
|
return (*(*[SizeofTcActionMsg]byte)(unsafe.Pointer(x)))[:]
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
TC_PRIO_MAX = 15
|
|
|
|
)
|
|
|
|
|
|
|
|
// struct tc_prio_qopt {
|
|
|
|
// int bands; /* Number of bands */
|
|
|
|
// __u8 priomap[TC_PRIO_MAX+1]; /* Map: logical priority -> PRIO band */
|
|
|
|
// };
|
|
|
|
|
|
|
|
type TcPrioMap struct {
|
|
|
|
Bands int32
|
|
|
|
Priomap [TC_PRIO_MAX + 1]uint8
|
|
|
|
}
|
|
|
|
|
2015-08-19 23:02:04 +00:00
|
|
|
func (msg *TcPrioMap) Len() int {
|
|
|
|
return SizeofTcPrioMap
|
|
|
|
}
|
|
|
|
|
2015-08-18 10:16:54 +00:00
|
|
|
func DeserializeTcPrioMap(b []byte) *TcPrioMap {
|
|
|
|
return (*TcPrioMap)(unsafe.Pointer(&b[0:SizeofTcPrioMap][0]))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *TcPrioMap) Serialize() []byte {
|
|
|
|
return (*(*[SizeofTcPrioMap]byte)(unsafe.Pointer(x)))[:]
|
|
|
|
}
|
|
|
|
|
2015-08-18 21:07:01 +00:00
|
|
|
const (
|
|
|
|
TCA_TBF_UNSPEC = iota
|
|
|
|
TCA_TBF_PARMS
|
|
|
|
TCA_TBF_RTAB
|
|
|
|
TCA_TBF_PTAB
|
|
|
|
TCA_TBF_RATE64
|
|
|
|
TCA_TBF_PRATE64
|
|
|
|
TCA_TBF_BURST
|
|
|
|
TCA_TBF_PBURST
|
|
|
|
TCA_TBF_MAX = TCA_TBF_PBURST
|
|
|
|
)
|
|
|
|
|
2015-08-18 10:16:54 +00:00
|
|
|
// struct tc_ratespec {
|
|
|
|
// unsigned char cell_log;
|
|
|
|
// __u8 linklayer; /* lower 4 bits */
|
|
|
|
// unsigned short overhead;
|
|
|
|
// short cell_align;
|
|
|
|
// unsigned short mpu;
|
|
|
|
// __u32 rate;
|
|
|
|
// };
|
|
|
|
|
2015-08-18 21:07:01 +00:00
|
|
|
type TcRateSpec struct {
|
|
|
|
CellLog uint8
|
|
|
|
Linklayer uint8
|
|
|
|
Overhead uint16
|
|
|
|
CellAlign int16
|
|
|
|
Mpu uint16
|
|
|
|
Rate uint32
|
|
|
|
}
|
|
|
|
|
2015-08-19 23:02:04 +00:00
|
|
|
func (msg *TcRateSpec) Len() int {
|
|
|
|
return SizeofTcRateSpec
|
|
|
|
}
|
|
|
|
|
2015-08-18 21:07:01 +00:00
|
|
|
func DeserializeTcRateSpec(b []byte) *TcRateSpec {
|
|
|
|
return (*TcRateSpec)(unsafe.Pointer(&b[0:SizeofTcRateSpec][0]))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *TcRateSpec) Serialize() []byte {
|
|
|
|
return (*(*[SizeofTcRateSpec]byte)(unsafe.Pointer(x)))[:]
|
|
|
|
}
|
|
|
|
|
2015-08-18 10:16:54 +00:00
|
|
|
// struct tc_tbf_qopt {
|
|
|
|
// struct tc_ratespec rate;
|
|
|
|
// struct tc_ratespec peakrate;
|
|
|
|
// __u32 limit;
|
|
|
|
// __u32 buffer;
|
|
|
|
// __u32 mtu;
|
|
|
|
// };
|
|
|
|
|
2015-08-18 21:07:01 +00:00
|
|
|
type TcTbfQopt struct {
|
|
|
|
Rate TcRateSpec
|
|
|
|
Peakrate TcRateSpec
|
|
|
|
Limit uint32
|
|
|
|
Buffer uint32
|
|
|
|
Mtu uint32
|
|
|
|
}
|
|
|
|
|
2015-08-19 23:02:04 +00:00
|
|
|
func (msg *TcTbfQopt) Len() int {
|
|
|
|
return SizeofTcTbfQopt
|
|
|
|
}
|
|
|
|
|
2015-08-18 21:07:01 +00:00
|
|
|
func DeserializeTcTbfQopt(b []byte) *TcTbfQopt {
|
|
|
|
return (*TcTbfQopt)(unsafe.Pointer(&b[0:SizeofTcTbfQopt][0]))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *TcTbfQopt) Serialize() []byte {
|
|
|
|
return (*(*[SizeofTcTbfQopt]byte)(unsafe.Pointer(x)))[:]
|
|
|
|
}
|
2015-08-19 23:02:04 +00:00
|
|
|
|
2015-09-05 07:13:17 +00:00
|
|
|
const (
|
|
|
|
TCA_HTB_UNSPEC = iota
|
|
|
|
TCA_HTB_PARMS
|
|
|
|
TCA_HTB_INIT
|
|
|
|
TCA_HTB_CTAB
|
|
|
|
TCA_HTB_RTAB
|
|
|
|
TCA_HTB_DIRECT_QLEN
|
|
|
|
TCA_HTB_RATE64
|
|
|
|
TCA_HTB_CEIL64
|
|
|
|
TCA_HTB_MAX = TCA_HTB_CEIL64
|
|
|
|
)
|
|
|
|
|
2015-09-10 23:20:18 +00:00
|
|
|
//struct tc_htb_opt {
|
|
|
|
// struct tc_ratespec rate;
|
|
|
|
// struct tc_ratespec ceil;
|
|
|
|
// __u32 buffer;
|
|
|
|
// __u32 cbuffer;
|
|
|
|
// __u32 quantum;
|
|
|
|
// __u32 level; /* out only */
|
|
|
|
// __u32 prio;
|
|
|
|
//};
|
|
|
|
|
|
|
|
type TcHtbCopt struct {
|
|
|
|
Rate TcRateSpec
|
|
|
|
Ceil TcRateSpec
|
|
|
|
Buffer uint32
|
|
|
|
Cbuffer uint32
|
|
|
|
Quantum uint32
|
|
|
|
Level uint32
|
|
|
|
Prio uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
func (msg *TcHtbCopt) Len() int {
|
|
|
|
return SizeofTcHtbCopt
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeserializeTcHtbCopt(b []byte) *TcHtbCopt {
|
|
|
|
return (*TcHtbCopt)(unsafe.Pointer(&b[0:SizeofTcHtbCopt][0]))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *TcHtbCopt) Serialize() []byte {
|
|
|
|
return (*(*[SizeofTcHtbCopt]byte)(unsafe.Pointer(x)))[:]
|
|
|
|
}
|
|
|
|
|
2015-09-05 07:13:17 +00:00
|
|
|
type TcHtbGlob struct {
|
|
|
|
Version uint32
|
|
|
|
Rate2Quantum uint32
|
|
|
|
Defcls uint32
|
|
|
|
Debug uint32
|
|
|
|
DirectPkts uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
func (msg *TcHtbGlob) Len() int {
|
|
|
|
return SizeofTcHtbGlob
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeserializeTcHtbGlob(b []byte) *TcHtbGlob {
|
|
|
|
return (*TcHtbGlob)(unsafe.Pointer(&b[0:SizeofTcHtbGlob][0]))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *TcHtbGlob) Serialize() []byte {
|
|
|
|
return (*(*[SizeofTcHtbGlob]byte)(unsafe.Pointer(x)))[:]
|
|
|
|
}
|
|
|
|
|
2015-08-19 23:02:04 +00:00
|
|
|
const (
|
|
|
|
TCA_U32_UNSPEC = iota
|
|
|
|
TCA_U32_CLASSID
|
|
|
|
TCA_U32_HASH
|
|
|
|
TCA_U32_LINK
|
|
|
|
TCA_U32_DIVISOR
|
|
|
|
TCA_U32_SEL
|
|
|
|
TCA_U32_POLICE
|
|
|
|
TCA_U32_ACT
|
|
|
|
TCA_U32_INDEV
|
|
|
|
TCA_U32_PCNT
|
|
|
|
TCA_U32_MARK
|
|
|
|
TCA_U32_MAX = TCA_U32_MARK
|
|
|
|
)
|
|
|
|
|
|
|
|
// struct tc_u32_key {
|
|
|
|
// __be32 mask;
|
|
|
|
// __be32 val;
|
|
|
|
// int off;
|
|
|
|
// int offmask;
|
|
|
|
// };
|
|
|
|
|
|
|
|
type TcU32Key struct {
|
|
|
|
Mask uint32 // big endian
|
|
|
|
Val uint32 // big endian
|
|
|
|
Off int32
|
|
|
|
OffMask int32
|
|
|
|
}
|
|
|
|
|
|
|
|
func (msg *TcU32Key) Len() int {
|
|
|
|
return SizeofTcU32Key
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeserializeTcU32Key(b []byte) *TcU32Key {
|
|
|
|
return (*TcU32Key)(unsafe.Pointer(&b[0:SizeofTcU32Key][0]))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *TcU32Key) Serialize() []byte {
|
|
|
|
return (*(*[SizeofTcU32Key]byte)(unsafe.Pointer(x)))[:]
|
|
|
|
}
|
|
|
|
|
|
|
|
// struct tc_u32_sel {
|
|
|
|
// unsigned char flags;
|
|
|
|
// unsigned char offshift;
|
|
|
|
// unsigned char nkeys;
|
|
|
|
//
|
|
|
|
// __be16 offmask;
|
|
|
|
// __u16 off;
|
|
|
|
// short offoff;
|
|
|
|
//
|
|
|
|
// short hoff;
|
|
|
|
// __be32 hmask;
|
|
|
|
// struct tc_u32_key keys[0];
|
|
|
|
// };
|
|
|
|
|
|
|
|
const (
|
|
|
|
TC_U32_TERMINAL = 1 << iota
|
|
|
|
TC_U32_OFFSET = 1 << iota
|
|
|
|
TC_U32_VAROFFSET = 1 << iota
|
|
|
|
TC_U32_EAT = 1 << iota
|
|
|
|
)
|
|
|
|
|
|
|
|
type TcU32Sel struct {
|
|
|
|
Flags uint8
|
|
|
|
Offshift uint8
|
|
|
|
Nkeys uint8
|
|
|
|
Pad uint8
|
|
|
|
Offmask uint16 // big endian
|
|
|
|
Off uint16
|
|
|
|
Offoff int16
|
|
|
|
Hoff int16
|
|
|
|
Hmask uint32 // big endian
|
|
|
|
Keys []TcU32Key
|
|
|
|
}
|
|
|
|
|
|
|
|
func (msg *TcU32Sel) Len() int {
|
|
|
|
return SizeofTcU32Sel + int(msg.Nkeys)*SizeofTcU32Key
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeserializeTcU32Sel(b []byte) *TcU32Sel {
|
|
|
|
x := &TcU32Sel{}
|
|
|
|
copy((*(*[SizeofTcU32Sel]byte)(unsafe.Pointer(x)))[:], b)
|
|
|
|
next := SizeofTcU32Sel
|
|
|
|
var i uint8
|
|
|
|
for i = 0; i < x.Nkeys; i++ {
|
|
|
|
x.Keys = append(x.Keys, *DeserializeTcU32Key(b[next:]))
|
|
|
|
next += SizeofTcU32Key
|
|
|
|
}
|
|
|
|
return x
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *TcU32Sel) Serialize() []byte {
|
|
|
|
// This can't just unsafe.cast because it must iterate through keys.
|
|
|
|
buf := make([]byte, x.Len())
|
|
|
|
copy(buf, (*(*[SizeofTcU32Sel]byte)(unsafe.Pointer(x)))[:])
|
|
|
|
next := SizeofTcU32Sel
|
|
|
|
for _, key := range x.Keys {
|
|
|
|
keyBuf := key.Serialize()
|
|
|
|
copy(buf[next:], keyBuf)
|
|
|
|
next += SizeofTcU32Key
|
|
|
|
}
|
|
|
|
return buf
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
TCA_ACT_MIRRED = 8
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
TCA_MIRRED_UNSPEC = iota
|
|
|
|
TCA_MIRRED_TM
|
|
|
|
TCA_MIRRED_PARMS
|
|
|
|
TCA_MIRRED_MAX = TCA_MIRRED_PARMS
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
TCA_EGRESS_REDIR = 1 /* packet redirect to EGRESS*/
|
|
|
|
TCA_EGRESS_MIRROR = 2 /* mirror packet to EGRESS */
|
|
|
|
TCA_INGRESS_REDIR = 3 /* packet redirect to INGRESS*/
|
|
|
|
TCA_INGRESS_MIRROR = 4 /* mirror packet to INGRESS */
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2015-08-20 01:49:04 +00:00
|
|
|
TC_ACT_UNSPEC = int32(-1)
|
|
|
|
TC_ACT_OK = 0
|
|
|
|
TC_ACT_RECLASSIFY = 1
|
|
|
|
TC_ACT_SHOT = 2
|
|
|
|
TC_ACT_PIPE = 3
|
|
|
|
TC_ACT_STOLEN = 4
|
|
|
|
TC_ACT_QUEUED = 5
|
|
|
|
TC_ACT_REPEAT = 6
|
|
|
|
TC_ACT_JUMP = 0x10000000
|
2015-08-19 23:02:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// #define tc_gen \
|
|
|
|
// __u32 index; \
|
|
|
|
// __u32 capab; \
|
|
|
|
// int action; \
|
|
|
|
// int refcnt; \
|
|
|
|
// int bindcnt
|
|
|
|
// struct tc_mirred {
|
|
|
|
// tc_gen;
|
|
|
|
// int eaction; /* one of IN/EGRESS_MIRROR/REDIR */
|
|
|
|
// __u32 ifindex; /* ifindex of egress port */
|
|
|
|
// };
|
|
|
|
|
|
|
|
type TcMirred struct {
|
|
|
|
Index uint32
|
|
|
|
Capab uint32
|
|
|
|
Action int32
|
|
|
|
Refcnt int32
|
|
|
|
Bindcnt int32
|
|
|
|
Eaction int32
|
|
|
|
Ifindex uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
func (msg *TcMirred) Len() int {
|
|
|
|
return SizeofTcMirred
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeserializeTcMirred(b []byte) *TcMirred {
|
|
|
|
return (*TcMirred)(unsafe.Pointer(&b[0:SizeofTcMirred][0]))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *TcMirred) Serialize() []byte {
|
|
|
|
return (*(*[SizeofTcMirred]byte)(unsafe.Pointer(x)))[:]
|
|
|
|
}
|
2015-09-12 06:24:22 +00:00
|
|
|
|
|
|
|
const (
|
|
|
|
TC_POLICE_UNSPEC = TC_ACT_UNSPEC
|
|
|
|
TC_POLICE_OK = TC_ACT_OK
|
|
|
|
TC_POLICE_RECLASSIFY = TC_ACT_RECLASSIFY
|
|
|
|
TC_POLICE_SHOT = TC_ACT_SHOT
|
|
|
|
TC_POLICE_PIPE = TC_ACT_PIPE
|
|
|
|
)
|
|
|
|
|
|
|
|
// struct tc_police {
|
|
|
|
// __u32 index;
|
|
|
|
// int action;
|
|
|
|
// __u32 limit;
|
|
|
|
// __u32 burst;
|
|
|
|
// __u32 mtu;
|
|
|
|
// struct tc_ratespec rate;
|
|
|
|
// struct tc_ratespec peakrate;
|
|
|
|
// int refcnt;
|
|
|
|
// int bindcnt;
|
|
|
|
// __u32 capab;
|
|
|
|
// };
|
|
|
|
|
|
|
|
type TcPolice struct {
|
|
|
|
Index uint32
|
|
|
|
Action int32
|
|
|
|
Limit uint32
|
|
|
|
Burst uint32
|
|
|
|
Mtu uint32
|
|
|
|
Rate TcRateSpec
|
|
|
|
PeakRate TcRateSpec
|
|
|
|
Refcnt int32
|
|
|
|
Bindcnt int32
|
|
|
|
Capab uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
func (msg *TcPolice) Len() int {
|
|
|
|
return SizeofTcPolice
|
|
|
|
}
|
|
|
|
|
|
|
|
func DeserializeTcPolice(b []byte) *TcPolice {
|
|
|
|
return (*TcPolice)(unsafe.Pointer(&b[0:SizeofTcPolice][0]))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *TcPolice) Serialize() []byte {
|
|
|
|
return (*(*[SizeofTcPolice]byte)(unsafe.Pointer(x)))[:]
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
TCA_FW_UNSPEC = iota
|
|
|
|
TCA_FW_CLASSID
|
|
|
|
TCA_FW_POLICE
|
|
|
|
TCA_FW_INDEV
|
|
|
|
TCA_FW_ACT
|
|
|
|
TCA_FW_MASK
|
|
|
|
TCA_FW_MAX = TCA_FW_MASK
|
|
|
|
)
|