Add allmulti to link attributes

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>
This commit is contained in:
Bjorn Svensson 2021-04-07 09:25:42 +02:00 committed by Alessandro Boch
parent 77f3f25cb4
commit 6063cc66d7
3 changed files with 7 additions and 11 deletions

View File

@ -35,6 +35,7 @@ type LinkAttrs struct {
Alias string
Statistics *LinkStatistics
Promisc int
Allmulti int
Xdp *LinkXdp
EncapType string
Protinfo *Protinfo

View File

@ -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)
@ -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)
@ -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

View File

@ -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)
}
@ -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")
}
@ -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) {