Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide the allmulticast option as own link attribute #635

Merged
merged 1 commit into from
May 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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)
Expand All @@ -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
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