This repository has been archived by the owner on May 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
0002-Support-Mark-in-the-U32-filters.patch
99 lines (93 loc) · 2.86 KB
/
0002-Support-Mark-in-the-U32-filters.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
From d201dc1ff5bd7d175ebef27b30d75aa03e2f169b Mon Sep 17 00:00:00 2001
From: jeckypei <[email protected]>
Date: Fri, 13 Aug 2021 07:27:10 +0000
Subject: [PATCH] Support Mark in the U32 filters
---
filter_linux.go | 15 +++++++++++++++
nl/tc_linux.go | 21 +++++++++++++++++++++
2 files changed, 36 insertions(+)
diff --git a/filter_linux.go b/filter_linux.go
index 1f79682..c1b1f1f 100644
--- a/filter_linux.go
+++ b/filter_linux.go
@@ -26,6 +26,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.
@@ -40,6 +45,7 @@ type U32 struct {
Link uint32
RedirIndex int
Sel *TcU32Sel
+ Mark *TcU32Mark
Actions []Action
}
@@ -323,6 +329,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))
}
@@ -864,6 +876,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 c3e315c..4363220 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
SizeofTcCsum = SizeofTcGen + 0x04
@@ -605,6 +606,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; \
--
2.25.1