From 56117287f8b4fd4824cfb8777235502605a4ebf6 Mon Sep 17 00:00:00 2001 From: Bjorn Svensson Date: Wed, 7 Apr 2021 09:25:42 +0200 Subject: [PATCH] Add allmulti to link attributes Provide the status of the allmulticast option via the highlevel link attributes instead of requiring raw flag handling. --- link.go | 1 + link_linux.go | 6 ++++-- link_test.go | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/link.go b/link.go index 32ca7cd64..65e15f903 100644 --- a/link.go +++ b/link.go @@ -35,6 +35,7 @@ type LinkAttrs struct { Alias string Statistics *LinkStatistics Promisc int + Allmulti int Xdp *LinkXdp EncapType string Protinfo *Protinfo diff --git a/link_linux.go b/link_linux.go index 3b959299c..b29c48871 100644 --- a/link_linux.go +++ b/link_linux.go @@ -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) @@ -1624,7 +1623,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) @@ -1642,6 +1641,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 diff --git a/link_test.go b/link_test.go index b68dbb0a3..25a77ab92 100644 --- a/link_test.go +++ b/link_test.go @@ -2647,7 +2647,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") } @@ -2660,7 +2660,7 @@ 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") }