Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Mark in the U32 filters #676

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions filter_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -39,6 +44,7 @@ type U32 struct {
Link uint32
RedirIndex int
Sel *TcU32Sel
Mark *TcU32Mark
Actions []Action
}

Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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 {
Expand Down
21 changes: 21 additions & 0 deletions nl/tc_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const (
SizeofTcHtbGlob = 0x14
SizeofTcU32Key = 0x10
SizeofTcU32Sel = 0x10 // without keys
SizeofTcU32Mark = 0xc
SizeofTcGen = 0x14
SizeofTcConnmark = SizeofTcGen + 0x04
SizeofTcMirred = SizeofTcGen + 0x08
Expand Down Expand Up @@ -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; \
Expand Down