diff --git a/link_linux.go b/link_linux.go index 0ed307d..d4ccd09 100644 --- a/link_linux.go +++ b/link_linux.go @@ -675,6 +675,11 @@ func (h *Handle) LinkAdd(link Link) error { data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil) nl.NewRtAttrChild(data, nl.IFLA_MACVLAN_MODE, nl.Uint32Attr(macvlanModes[macv.Mode])) } + } else if macv, ok := link.(*Macvtap); ok { + if macv.Mode != MACVLAN_MODE_DEFAULT { + data := nl.NewRtAttrChild(linkInfo, nl.IFLA_INFO_DATA, nil) + nl.NewRtAttrChild(data, nl.IFLA_MACVLAN_MODE, nl.Uint32Attr(macvlanModes[macv.Mode])) + } } else if gretap, ok := link.(*Gretap); ok { addGretapAttrs(gretap, linkInfo) } diff --git a/link_test.go b/link_test.go index b431acf..ca11bb2 100644 --- a/link_test.go +++ b/link_test.go @@ -110,6 +110,16 @@ func testLinkAddDel(t *testing.T, link Link) { } } + if macv, ok := link.(*Macvtap); ok { + other, ok := result.(*Macvtap) + if !ok { + t.Fatal("Result of create is not a macvtap") + } + if macv.Mode != other.Mode { + t.Fatalf("Got unexpected mode: %d, expected: %d", other.Mode, macv.Mode) + } + } + if err = LinkDel(link); err != nil { t.Fatal(err) } @@ -247,6 +257,16 @@ func TestLinkAddDelMacvlan(t *testing.T) { Mode: MACVLAN_MODE_PRIVATE, }) + testLinkAddDel(t, &Macvlan{ + LinkAttrs: LinkAttrs{Name: "bar", ParentIndex: parent.Attrs().Index}, + Mode: MACVLAN_MODE_BRIDGE, + }) + + testLinkAddDel(t, &Macvlan{ + LinkAttrs: LinkAttrs{Name: "bar", ParentIndex: parent.Attrs().Index}, + Mode: MACVLAN_MODE_VEPA, + }) + if err := LinkDel(parent); err != nil { t.Fatal(err) } @@ -268,6 +288,20 @@ func TestLinkAddDelMacvtap(t *testing.T) { }, }) + testLinkAddDel(t, &Macvtap{ + Macvlan: Macvlan{ + LinkAttrs: LinkAttrs{Name: "bar", ParentIndex: parent.Attrs().Index}, + Mode: MACVLAN_MODE_BRIDGE, + }, + }) + + testLinkAddDel(t, &Macvtap{ + Macvlan: Macvlan{ + LinkAttrs: LinkAttrs{Name: "bar", ParentIndex: parent.Attrs().Index}, + Mode: MACVLAN_MODE_VEPA, + }, + }) + if err := LinkDel(parent); err != nil { t.Fatal(err) }