diff --git a/filter_linux.go b/filter_linux.go index 5514531d..a4b140dd 100644 --- a/filter_linux.go +++ b/filter_linux.go @@ -25,6 +25,11 @@ const ( // canonical nl.TcU32Sel with the appropriate endianness. type TcU32Sel = nl.TcU32Sel +// TcU32Mark contained of Mark in the U32 filters. This is the type alias and the +// frontend representation of nl.TcU32Mark. It is serialized into chanonical +// nl.TcU32Mark with the appropriate endianness. +type TcU32Mark = nl.TcU32Mark + // TcU32Key contained of Sel in the U32 filters. This is the type alias and the // frontend representation of nl.TcU32Key. It is serialized into chanonical // nl.TcU32Sel with the appropriate endianness. @@ -39,6 +44,7 @@ type U32 struct { Link uint32 RedirIndex int Sel *TcU32Sel + Mark *TcU32Mark Actions []Action } @@ -213,6 +219,12 @@ func (h *Handle) filterModify(filter Filter, flags int) error { } sel.Nkeys = uint8(len(sel.Keys)) options.AddRtAttr(nl.TCA_U32_SEL, sel.Serialize()) + + mark := filter.Mark + if mark != nil { + options.AddRtAttr(nl.TCA_U32_MARK, mark.Serialize()) + } + if filter.ClassId != 0 { options.AddRtAttr(nl.TCA_U32_CLASSID, nl.Uint32Attr(filter.ClassId)) } @@ -648,6 +660,9 @@ func parseU32Data(filter Filter, data []syscall.NetlinkRouteAttr) (bool, error) u32.Sel.Keys[i].Val = native.Uint32(htonl(key.Val)) } } + case nl.TCA_U32_MARK: + mark := nl.DeserializeTcU32Mark(datum.Value) + u32.Mark = mark case nl.TCA_U32_ACT: tables, err := nl.ParseRouteAttr(datum.Value) if err != nil { diff --git a/nl/tc_linux.go b/nl/tc_linux.go index c24d53eb..c9bfd117 100644 --- a/nl/tc_linux.go +++ b/nl/tc_linux.go @@ -88,6 +88,7 @@ const ( SizeofTcHtbGlob = 0x14 SizeofTcU32Key = 0x10 SizeofTcU32Sel = 0x10 // without keys + SizeofTcU32Mark = 0xc SizeofTcGen = 0x14 SizeofTcConnmark = SizeofTcGen + 0x04 SizeofTcMirred = SizeofTcGen + 0x08 @@ -603,6 +604,26 @@ func (x *TcGen) Serialize() []byte { return (*(*[SizeofTcGen]byte)(unsafe.Pointer(x)))[:] } +type TcU32Mark struct { + Val uint32 + Mask uint32 + Success uint32 +} + +func (msg *TcU32Mark) Len() int { + return SizeofTcU32Mark +} + +func DeserializeTcU32Mark(b []byte) *TcU32Mark { + x := &TcU32Mark{} + copy ((*(*[SizeofTcU32Mark]byte)(unsafe.Pointer(x)))[:], b) + return x +} + +func (x *TcU32Mark) Serialize() []byte { + return (*(*[SizeofTcU32Mark]byte)(unsafe.Pointer(x)))[:] +} + // #define tc_gen \ // __u32 index; \ // __u32 capab; \