Skip to content

Commit 53eeeb5

Browse files
authored
Replace FW Filters with Flower filters (#963)
* Add a AddFlowerFilter method * Update unit tests * Remove AddFwFilter
1 parent 88a0f9b commit 53eeeb5

5 files changed

+25
-25
lines changed

injector/network_disruption.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,8 @@ func (i *networkDisruptionInjector) applyOperations() error {
490490
return fmt.Errorf("could not update the configuration of the bpf-network-tc-filter filter: %w", err)
491491
}
492492

493-
// create fw filter to classify packets based on their mark
494-
if err := i.config.TrafficController.AddFwFilter(interfaces, "4:0", types.InjectorCgroupClassID, "4:2"); err != nil {
493+
// create flower filter to classify packets based on their mark
494+
if err := i.config.TrafficController.AddFlowerFilter(interfaces, "4:0", types.InjectorCgroupClassID, "4:2"); err != nil {
495495
return fmt.Errorf("can't create the fw filter: %w", err)
496496
}
497497

@@ -505,8 +505,8 @@ func (i *networkDisruptionInjector) applyOperations() error {
505505
return fmt.Errorf("can't create a new qdisc: %w", err)
506506
}
507507

508-
// create fw filter to classify packets based on their mark
509-
if err := i.config.TrafficController.AddFwFilter(interfaces, "2:0", types.InjectorCgroupClassID, "2:2"); err != nil {
508+
// create flower filter to classify packets based on their mark
509+
if err := i.config.TrafficController.AddFlowerFilter(interfaces, "2:0", types.InjectorCgroupClassID, "2:2"); err != nil {
510510
return fmt.Errorf("can't create the fw filter: %w", err)
511511
}
512512
// parent 2:2 refers to the 2nd band of the 2nd prio qdisc

injector/network_disruption_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ var _ = Describe("Failure", func() {
9292
tc.EXPECT().AddNetem(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Maybe()
9393
tc.EXPECT().AddPrio(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Maybe()
9494
tc.EXPECT().AddFilter(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(0, nil).Maybe()
95-
tc.EXPECT().AddFwFilter(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Maybe()
95+
tc.EXPECT().AddFlowerFilter(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Maybe()
9696
tc.EXPECT().AddOutputLimit(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Maybe()
9797
tc.EXPECT().DeleteFilter(mock.Anything, mock.Anything).Return(nil).Maybe()
9898
tc.EXPECT().ClearQdisc(mock.Anything).Return(nil).Maybe()
@@ -294,7 +294,7 @@ var _ = Describe("Failure", func() {
294294
})
295295

296296
It("should add an fw filter to classify packets according to their classid set by iptables mark", func() {
297-
tc.AssertCalled(GinkgoT(), "AddFwFilter", []string{"lo", "eth0", "eth1"}, "2:0", "0x00020002", "2:2")
297+
tc.AssertCalled(GinkgoT(), "AddFlowerFilter", []string{"lo", "eth0", "eth1"}, "2:0", "0x00020002", "2:2")
298298
})
299299

300300
It("should apply disruptions to main interfaces 2nd band", func() {
@@ -720,7 +720,7 @@ var _ = Describe("Failure", func() {
720720
tc.AssertCalled(GinkgoT(), "AddPrio", interfaces, "3:2", "4:", uint32(2), mock.Anything)
721721

722722
By("adding an fw filter to classify packets according to their classid set by iptables mark")
723-
tc.AssertCalled(GinkgoT(), "AddFwFilter", interfaces, "4:0", "0x00020002", "4:2")
723+
tc.AssertCalled(GinkgoT(), "AddFlowerFilter", interfaces, "4:0", "0x00020002", "4:2")
724724

725725
By("adding an BPF filter to classify packets according to their method")
726726
tc.AssertCalled(GinkgoT(), "AddBPFFilter", interfaces, "2:0", "/usr/local/bin/bpf-network-tc-filter.bpf.o", "2:2", "classifier_methods")

network/tc.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type TrafficController interface {
6161
AddPrio(ifaces []string, parent string, handle string, bands uint32, priomap [16]uint32) error
6262
AddFilter(ifaces []string, parent string, handle string, srcIP, dstIP *net.IPNet, srcPort, dstPort int, prot protocol, state connState, flowid string) (uint32, error)
6363
DeleteFilter(iface string, priority uint32) error
64-
AddFwFilter(ifaces []string, parent string, handle string, flowid string) error
64+
AddFlowerFilter(ifaces []string, parent string, handle string, flowid string) error
6565
AddBPFFilter(ifaces []string, parent string, obj string, flowid string, section string) error
6666
ConfigBPFFilter(cmd executor, args ...string) error
6767
AddOutputLimit(ifaces []string, parent string, handle string, bytesPerSec uint) error
@@ -251,10 +251,10 @@ func (t *tc) DeleteFilter(iface string, priority uint32) error {
251251
return nil
252252
}
253253

254-
// AddFwFilter generates a cgroup filter
255-
func (t *tc) AddFwFilter(ifaces []string, parent string, handle string, flowid string) error {
254+
// AddFlowerFilter generates a tc filter of kind "flower"
255+
func (t *tc) AddFlowerFilter(ifaces []string, parent string, handle string, flowid string) error {
256256
for _, iface := range ifaces {
257-
if _, _, err := t.executer.Run(buildCmd("filter", iface, parent, "ip", 0, handle, "fw", "flowid "+flowid)); err != nil {
257+
if _, _, err := t.executer.Run(buildCmd("filter", iface, parent, "ip", 0, handle, "flower", "flowid "+flowid)); err != nil {
258258
return err
259259
}
260260
}

network/tc_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,14 @@ var _ = Describe("Tc", func() {
212212
})
213213
})
214214

215-
Describe("AddFwFilter", func() {
215+
Describe("AddFlowerFilter", func() {
216216
JustBeforeEach(func() {
217-
Expect(tcRunner.AddFwFilter(ifaces, parent, handle, flowid)).Should(Succeed())
217+
Expect(tcRunner.AddFlowerFilter(ifaces, parent, handle, flowid)).Should(Succeed())
218218
})
219219

220220
Context("add a cgroup filter", func() {
221221
It("should execute", func() {
222-
tcExecuter.AssertCalled(GinkgoT(), "Run", []string{"filter", "add", "dev", "lo", "protocol", "ip", "root", "fw", "flowid", "1:2"})
222+
tcExecuter.AssertCalled(GinkgoT(), "Run", []string{"filter", "add", "dev", "lo", "protocol", "ip", "root", "flower", "flowid", "1:2"})
223223
})
224224
})
225225
})

network/traffic_controller_mock.go

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)