Add BridgeSetVlanFiltering to change VlanFiltering on an existing bridge

Signed-off-by: stffabi <stffabi@pm.me>
This commit is contained in:
stffabi 2020-02-16 23:31:27 +01:00 committed by Alessandro Boch
parent bfba8e4149
commit 5f2fc868c2
2 changed files with 49 additions and 0 deletions

View File

@ -247,6 +247,16 @@ func (h *Handle) BridgeSetMcastSnoop(link Link, on bool) error {
return h.linkModify(bridge, unix.NLM_F_ACK) 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 { func SetPromiscOn(link Link) error {
return pkgHandle.SetPromiscOn(link) return pkgHandle.SetPromiscOn(link)
} }

View File

@ -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) { func TestBridgeCreationWithHelloTime(t *testing.T) {
minKernelRequired(t, 3, 18) minKernelRequired(t, 3, 18)