Skip to content

Commit

Permalink
add support for bridge port neighbor suppression
Browse files Browse the repository at this point in the history
this PR adds support for setting neigh_suppress attribute to a member port of a bridge
  • Loading branch information
bersoare authored and aboch committed Sep 22, 2023
1 parent 229a102 commit a4fcbb7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
8 changes: 8 additions & 0 deletions link_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2461,6 +2461,14 @@ func (h *Handle) LinkSetBrProxyArpWiFi(link Link, mode bool) error {
return h.setProtinfoAttr(link, mode, nl.IFLA_BRPORT_PROXYARP_WIFI)
}

func LinkSetBrNeighSuppress(link Link, mode bool) error {
return pkgHandle.LinkSetBrNeighSuppress(link, mode)
}

func (h *Handle) LinkSetBrNeighSuppress(link Link, mode bool) error {
return h.setProtinfoAttr(link, mode, nl.IFLA_BRPORT_NEIGH_SUPPRESS)
}

func (h *Handle) setProtinfoAttr(link Link, mode bool, attr int) error {
base := link.Attrs()
h.ensureIndex(base)
Expand Down
22 changes: 13 additions & 9 deletions protinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import (

// Protinfo represents bridge flags from netlink.
type Protinfo struct {
Hairpin bool
Guard bool
FastLeave bool
RootBlock bool
Learning bool
Flood bool
ProxyArp bool
ProxyArpWiFi bool
Isolated bool
Hairpin bool
Guard bool
FastLeave bool
RootBlock bool
Learning bool
Flood bool
ProxyArp bool
ProxyArpWiFi bool
Isolated bool
NeighSuppress bool
}

// String returns a list of enabled flags
Expand Down Expand Up @@ -51,6 +52,9 @@ func (prot *Protinfo) String() string {
if prot.Isolated {
boolStrings = append(boolStrings, "Isolated")
}
if prot.NeighSuppress {
boolStrings = append(boolStrings, "NeighSuppress")
}
return strings.Join(boolStrings, " ")
}

Expand Down
2 changes: 2 additions & 0 deletions protinfo_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func parseProtinfo(infos []syscall.NetlinkRouteAttr) (pi Protinfo) {
pi.ProxyArpWiFi = byteToBool(info.Value[0])
case nl.IFLA_BRPORT_ISOLATED:
pi.Isolated = byteToBool(info.Value[0])
case nl.IFLA_BRPORT_NEIGH_SUPPRESS:
pi.NeighSuppress = byteToBool(info.Value[0])
}
}
return
Expand Down
21 changes: 21 additions & 0 deletions protinfo_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build linux
// +build linux

package netlink
Expand Down Expand Up @@ -83,6 +84,9 @@ func TestProtinfo(t *testing.T) {
if pi1.Flood != oldpi1.Flood {
t.Fatalf("Flood field was changed for %s but shouldn't", iface1.Name)
}
if pi1.NeighSuppress != oldpi1.NeighSuppress {
t.Fatalf("NeighSuppress field was changed for %s but shouldn't", iface1.Name)
}

if err := LinkSetGuard(iface2, true); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -118,6 +122,9 @@ func TestProtinfo(t *testing.T) {
if pi2.Flood != oldpi2.Flood {
t.Fatalf("Flood field was changed for %s but shouldn't", iface2.Name)
}
if pi2.NeighSuppress != oldpi2.NeighSuppress {
t.Fatalf("NeighSuppress field was changed for %s but shouldn't", iface2.Name)
}

if err := LinkSetHairpin(iface3, true); err == nil || err.Error() != "operation not supported" {
t.Fatalf("Set protinfo attrs for link without master is not supported, but err: %s", err)
Expand Down Expand Up @@ -162,6 +169,20 @@ func TestProtinfo(t *testing.T) {
t.Fatalf("Flood field was changed for %s but shouldn't", iface4.Name)
}

// BR_NEIGH_SUPPRESS added on 4.15
minKernelRequired(t, 4, 15)

if err := LinkSetBrNeighSuppress(iface1, true); err != nil {
t.Fatal(err)
}
pi1, err = LinkGetProtinfo(iface1)
if err != nil {
t.Fatal(err)
}
if !pi1.NeighSuppress {
t.Fatalf("NeighSuppress is not enabled for %s but should", iface1.Name)
}

// Setting kernel requirement for next tests which require BRPORT_ISOLATED
minKernelRequired(t, 4, 18)

Expand Down

0 comments on commit a4fcbb7

Please sign in to comment.