Skip to content

Commit

Permalink
Add BridgeSetVlanFiltering to change VlanFiltering on an existing bridge
Browse files Browse the repository at this point in the history
Signed-off-by: stffabi <stffabi@pm.me>
  • Loading branch information
stffabi authored and aboch committed Feb 18, 2020
1 parent bfba8e4 commit 5f2fc86
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
10 changes: 10 additions & 0 deletions link_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
39 changes: 39 additions & 0 deletions link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 5f2fc86

Please sign in to comment.