Skip to content

Commit

Permalink
Add allmulti to link attributes
Browse files Browse the repository at this point in the history
Provide the status of the allmulticast option via the highlevel
link attributes instead of requiring raw flag handling.

Avoid comparing all rawflags before and after in tests due to that
the IFF_RUNNING flag might change independenly.

Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
  • Loading branch information
bjosv authored and tl committed Apr 5, 2022
1 parent b348dbd commit b9bf300
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
1 change: 1 addition & 0 deletions link.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type LinkAttrs struct {
Alias string
Statistics *LinkStatistics
Promisc int
Allmulti int
Xdp *LinkXdp
EncapType string
Protinfo *Protinfo
Expand Down
6 changes: 4 additions & 2 deletions link_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ func (h *Handle) LinkSetAllmulticastOn(link Link) error {
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
msg.Change = unix.IFF_ALLMULTI
msg.Flags = unix.IFF_ALLMULTI

msg.Index = int32(base.Index)
req.AddData(msg)

Expand Down Expand Up @@ -1628,7 +1627,7 @@ func execGetLink(req *nl.NetlinkRequest) (Link, error) {
}
}

// linkDeserialize deserializes a raw message received from netlink into
// LinkDeserialize deserializes a raw message received from netlink into
// a link object.
func LinkDeserialize(hdr *unix.NlMsghdr, m []byte) (Link, error) {
msg := nl.DeserializeIfInfomsg(m)
Expand All @@ -1646,6 +1645,9 @@ func LinkDeserialize(hdr *unix.NlMsghdr, m []byte) (Link, error) {
if msg.Flags&unix.IFF_PROMISC != 0 {
base.Promisc = 1
}
if msg.Flags&unix.IFF_ALLMULTI != 0 {
base.Allmulti = 1
}
var (
link Link
stats32 *LinkStatistics32
Expand Down
11 changes: 2 additions & 9 deletions link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2636,8 +2636,6 @@ func TestLinkSetAllmulticast(t *testing.T) {
t.Fatal(err)
}

rawFlagsStart := link.Attrs().RawFlags

if err := LinkSetAllmulticastOn(link); err != nil {
t.Fatal(err)
}
Expand All @@ -2647,7 +2645,7 @@ func TestLinkSetAllmulticast(t *testing.T) {
t.Fatal(err)
}

if link.Attrs().RawFlags&unix.IFF_ALLMULTI != uint32(unix.IFF_ALLMULTI) {
if link.Attrs().Allmulti != 1 {
t.Fatal("IFF_ALLMULTI was not set")
}

Expand All @@ -2660,14 +2658,9 @@ func TestLinkSetAllmulticast(t *testing.T) {
t.Fatal(err)
}

if link.Attrs().RawFlags&unix.IFF_ALLMULTI != 0 {
if link.Attrs().Allmulti != 0 {
t.Fatal("IFF_ALLMULTI is still set")
}

rawFlagsEnd := link.Attrs().RawFlags
if rawFlagsStart != rawFlagsEnd {
t.Fatalf("RawFlags start value:%d differs from end value:%d", rawFlagsStart, rawFlagsEnd)
}
}

func TestLinkSetMacvlanMode(t *testing.T) {
Expand Down

0 comments on commit b9bf300

Please sign in to comment.