Skip to content

Commit e20cb98

Browse files
e0neaboch
authored andcommitted
Support skip_hw/skip_sw flags
This feature could not be tested with virtual interfaces that's why unit-tests aren't added into this change.
1 parent 7f2b136 commit e20cb98

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

filter_linux.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ type Flower struct {
6464
EncSrcIPMask net.IPMask
6565
EncDestPort uint16
6666
EncKeyId uint32
67+
SkipHw bool
68+
SkipSw bool
6769

6870
Actions []Action
6971
}
@@ -130,6 +132,15 @@ func (filter *Flower) encode(parent *nl.RtAttr) error {
130132
parent.AddRtAttr(nl.TCA_FLOWER_KEY_ENC_KEY_ID, htonl(filter.EncKeyId))
131133
}
132134

135+
var flags uint32 = 0
136+
if filter.SkipHw {
137+
flags |= nl.TCA_CLS_FLAGS_SKIP_HW
138+
}
139+
if filter.SkipSw {
140+
flags |= nl.TCA_CLS_FLAGS_SKIP_SW
141+
}
142+
parent.AddRtAttr(nl.TCA_FLOWER_FLAGS, htonl(flags))
143+
133144
actionsAttr := parent.AddRtAttr(nl.TCA_FLOWER_ACT, nil)
134145
if err := EncodeActions(actionsAttr, filter.Actions); err != nil {
135146
return err
@@ -171,6 +182,16 @@ func (filter *Flower) decode(data []syscall.NetlinkRouteAttr) error {
171182
if err != nil {
172183
return err
173184
}
185+
case nl.TCA_FLOWER_FLAGS:
186+
attr := nl.DeserializeUint32Bitfield(datum.Value)
187+
skipSw := attr.Value & nl.TCA_CLS_FLAGS_SKIP_HW
188+
skipHw := attr.Value & nl.TCA_CLS_FLAGS_SKIP_SW
189+
if skipSw != 0 {
190+
filter.SkipSw = true
191+
}
192+
if skipHw != 0 {
193+
filter.SkipHw = true
194+
}
174195
}
175196
}
176197
return nil
@@ -344,7 +365,6 @@ func (h *Handle) filterModify(filter Filter, flags int) error {
344365
return err
345366
}
346367
}
347-
348368
req.AddData(options)
349369
_, err := req.Execute(unix.NETLINK_ROUTE, 0)
350370
return err

filter_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -1850,7 +1850,6 @@ func TestFilterFlowerAddDel(t *testing.T) {
18501850
if filter.EncDestPort != flower.EncDestPort {
18511851
t.Fatalf("Flower EncDestPort doesn't match")
18521852
}
1853-
18541853
mia, ok := flower.Actions[0].(*MirredAction)
18551854
if !ok {
18561855
t.Fatal("Unable to find mirred action")

nl/nl_linux.go

+13
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,19 @@ func NewIfInfomsgChild(parent *RtAttr, family int) *IfInfomsg {
330330
return msg
331331
}
332332

333+
type Uint32Bitfield struct {
334+
Value uint32
335+
Selector uint32
336+
}
337+
338+
func (a *Uint32Bitfield) Serialize() []byte {
339+
return (*(*[SizeofUint32Bitfield]byte)(unsafe.Pointer(a)))[:]
340+
}
341+
342+
func DeserializeUint32Bitfield(data []byte) *Uint32Bitfield {
343+
return (*Uint32Bitfield)(unsafe.Pointer(&data[0:SizeofUint32Bitfield][0]))
344+
}
345+
333346
type Uint32Attribute struct {
334347
Type uint16
335348
Value uint32

nl/tc_linux.go

+10
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ const (
6363
TCA_ACT_OPTIONS
6464
TCA_ACT_INDEX
6565
TCA_ACT_STATS
66+
TCA_ACT_PAD
67+
TCA_ACT_COOKIE
68+
TCA_ACT_FLAGS
69+
TCA_ACT_HW_STATS
70+
TCA_ACT_USED_HW_STATS
71+
TCA_ACT_IN_HW_COUNT
6672
TCA_ACT_MAX
6773
)
6874

@@ -105,6 +111,7 @@ const (
105111
SizeofTcSfqQopt = 0x0b
106112
SizeofTcSfqRedStats = 0x18
107113
SizeofTcSfqQoptV1 = SizeofTcSfqQopt + SizeofTcSfqRedStats + 0x1c
114+
SizeofUint32Bitfield = 0x8
108115
)
109116

110117
// struct tcmsg {
@@ -1030,6 +1037,9 @@ const (
10301037
__TCA_FLOWER_MAX
10311038
)
10321039

1040+
const TCA_CLS_FLAGS_SKIP_HW = 1 << 0 /* don't offload filter to HW */
1041+
const TCA_CLS_FLAGS_SKIP_SW = 1 << 1 /* don't use filter in SW */
1042+
10331043
// struct tc_sfq_qopt {
10341044
// unsigned quantum; /* Bytes per round allocated to flow */
10351045
// int perturb_period; /* Period of hash perturbation */

0 commit comments

Comments
 (0)