From 5f2fc868c2d0841565778edda0e0ea2843a49431 Mon Sep 17 00:00:00 2001 From: stffabi Date: Sun, 16 Feb 2020 23:31:27 +0100 Subject: [PATCH] Add BridgeSetVlanFiltering to change VlanFiltering on an existing bridge Signed-off-by: stffabi --- link_linux.go | 10 ++++++++++ link_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/link_linux.go b/link_linux.go index 75eb3da..ec6840d 100644 --- a/link_linux.go +++ b/link_linux.go @@ -247,6 +247,16 @@ func (h *Handle) BridgeSetMcastSnoop(link Link, on bool) error { return h.linkModify(bridge, unix.NLM_F_ACK) } +func BridgeSetVlanFiltering(link Link, on bool) error { + return pkgHandle.BridgeSetVlanFiltering(link, on) +} + +func (h *Handle) BridgeSetVlanFiltering(link Link, on bool) error { + bridge := link.(*Bridge) + bridge.VlanFiltering = &on + return h.linkModify(bridge, unix.NLM_F_ACK) +} + func SetPromiscOn(link Link) error { return pkgHandle.SetPromiscOn(link) } diff --git a/link_test.go b/link_test.go index e4ac17f..1ea9906 100644 --- a/link_test.go +++ b/link_test.go @@ -1784,6 +1784,45 @@ func expectMcastSnooping(t *testing.T, linkName string, expected bool) { } } +func TestBridgeSetVlanFiltering(t *testing.T) { + minKernelRequired(t, 4, 4) + + tearDown := setUpNetlinkTest(t) + defer tearDown() + + bridgeName := "foo" + bridge := &Bridge{LinkAttrs: LinkAttrs{Name: bridgeName}} + if err := LinkAdd(bridge); err != nil { + t.Fatal(err) + } + expectVlanFiltering(t, bridgeName, false) + + if err := BridgeSetVlanFiltering(bridge, true); err != nil { + t.Fatal(err) + } + expectVlanFiltering(t, bridgeName, true) + + if err := BridgeSetVlanFiltering(bridge, false); err != nil { + t.Fatal(err) + } + expectVlanFiltering(t, bridgeName, false) + + if err := LinkDel(bridge); err != nil { + t.Fatal(err) + } +} + +func expectVlanFiltering(t *testing.T, linkName string, expected bool) { + bridge, err := LinkByName(linkName) + if err != nil { + t.Fatal(err) + } + + if actual := *bridge.(*Bridge).VlanFiltering; actual != expected { + t.Fatalf("expected %t got %t", expected, actual) + } +} + func TestBridgeCreationWithHelloTime(t *testing.T) { minKernelRequired(t, 3, 18)