diff --git a/pkg/ip/link_linux.go b/pkg/ip/link_linux.go index 07adea192..e5bb6caff 100644 --- a/pkg/ip/link_linux.go +++ b/pkg/ip/link_linux.go @@ -32,11 +32,12 @@ var ErrLinkNotFound = errors.New("link not found") // makeVethPair is called from within the container's network namespace func makeVethPair(name, peer string, mtu int, mac string, hostNS ns.NetNS) (netlink.Link, error) { + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = name + linkAttrs.MTU = mtu + veth := &netlink.Veth{ - LinkAttrs: netlink.LinkAttrs{ - Name: name, - MTU: mtu, - }, + LinkAttrs: linkAttrs, PeerName: peer, PeerNamespace: netlink.NsFd(int(hostNS.Fd())), } diff --git a/pkg/ipam/ipam_linux_test.go b/pkg/ipam/ipam_linux_test.go index e5824746a..ddccdac64 100644 --- a/pkg/ipam/ipam_linux_test.go +++ b/pkg/ipam/ipam_linux_test.go @@ -56,11 +56,12 @@ var _ = Describe("ConfigureIface", func() { err = originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = LINK_NAME + // Add master err = netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: LINK_NAME, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) _, err = netlink.LinkByName(LINK_NAME) diff --git a/pkg/ns/README.md b/pkg/ns/README.md index 1e265c7a0..e5fef2db7 100644 --- a/pkg/ns/README.md +++ b/pkg/ns/README.md @@ -13,10 +13,10 @@ The `ns.Do()` method provides **partial** control over network namespaces for yo ```go err = targetNs.Do(func(hostNs ns.NetNS) error { + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = "dummy0" dummy := &netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: "dummy0", - }, + LinkAttrs: linkAttrs, } return netlink.LinkAdd(dummy) }) diff --git a/pkg/utils/sysctl/sysctl_linux_test.go b/pkg/utils/sysctl/sysctl_linux_test.go index 917b15325..9f6fdf572 100644 --- a/pkg/utils/sysctl/sysctl_linux_test.go +++ b/pkg/utils/sysctl/sysctl_linux_test.go @@ -48,11 +48,11 @@ var _ = Describe("Sysctl tests", func() { Expect(err).NotTo(HaveOccurred()) testIfaceName = fmt.Sprintf("cnitest.%d", rand.Intn(100000)) + testLinkAttrs := netlink.NewLinkAttrs() + testLinkAttrs.Name = testIfaceName + testLinkAttrs.Namespace = netlink.NsFd(int(testNs.Fd())) testIface := &netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: testIfaceName, - Namespace: netlink.NsFd(int(testNs.Fd())), - }, + LinkAttrs: testLinkAttrs, } err = netlink.LinkAdd(testIface) diff --git a/plugins/ipam/dhcp/dhcp_test.go b/plugins/ipam/dhcp/dhcp_test.go index 9c77a744c..cf5d0c0ee 100644 --- a/plugins/ipam/dhcp/dhcp_test.go +++ b/plugins/ipam/dhcp/dhcp_test.go @@ -155,11 +155,11 @@ var _ = Describe("DHCP Operations", func() { err = originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = hostVethName err = netlink.LinkAdd(&netlink.Veth{ - LinkAttrs: netlink.LinkAttrs{ - Name: hostVethName, - }, - PeerName: contVethName, + LinkAttrs: linkAttrs, + PeerName: contVethName, }) Expect(err).NotTo(HaveOccurred()) @@ -394,11 +394,11 @@ func dhcpSetupOriginalNS() (chan bool, string, ns.NetNS, ns.NetNS, error) { err = originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = hostBridgeName // Create bridge in the "host" (original) NS br = &netlink.Bridge{ - LinkAttrs: netlink.LinkAttrs{ - Name: hostBridgeName, - }, + LinkAttrs: linkAttrs, } err = netlink.LinkAdd(br) diff --git a/plugins/main/bridge/bridge.go b/plugins/main/bridge/bridge.go index 1c4fa59a6..e878b0a11 100644 --- a/plugins/main/bridge/bridge.go +++ b/plugins/main/bridge/bridge.go @@ -335,16 +335,11 @@ func bridgeByName(name string) (*netlink.Bridge, error) { } func ensureBridge(brName string, mtu int, promiscMode, vlanFiltering bool) (*netlink.Bridge, error) { + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = brName + linkAttrs.MTU = mtu br := &netlink.Bridge{ - LinkAttrs: netlink.LinkAttrs{ - Name: brName, - MTU: mtu, - // Let kernel use default txqueuelen; leaving it unset - // means 0, and a zero-length TX queue messes up FIFO - // traffic shapers which use TX queue length as the - // default packet limit - TxQLen: -1, - }, + LinkAttrs: linkAttrs, } if vlanFiltering { br.VlanFiltering = &vlanFiltering diff --git a/plugins/main/bridge/bridge_test.go b/plugins/main/bridge/bridge_test.go index c625ab098..d7d1bd1f0 100644 --- a/plugins/main/bridge/bridge_test.go +++ b/plugins/main/bridge/bridge_test.go @@ -1890,10 +1890,10 @@ var _ = Describe("bridge Operations", func() { err := originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = BRNAME err := netlink.LinkAdd(&netlink.Bridge{ - LinkAttrs: netlink.LinkAttrs{ - Name: BRNAME, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) link, err := netlink.LinkByName(BRNAME) diff --git a/plugins/main/dummy/dummy.go b/plugins/main/dummy/dummy.go index 3203c3ac6..ab12642c3 100644 --- a/plugins/main/dummy/dummy.go +++ b/plugins/main/dummy/dummy.go @@ -43,11 +43,12 @@ func parseNetConf(bytes []byte) (*types.NetConf, error) { func createDummy(ifName string, netns ns.NetNS) (*current.Interface, error) { dummy := ¤t.Interface{} + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = ifName + linkAttrs.Namespace = netlink.NsFd(int(netns.Fd())) + dm := &netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: ifName, - Namespace: netlink.NsFd(int(netns.Fd())), - }, + LinkAttrs: linkAttrs, } if err := netlink.LinkAdd(dm); err != nil { diff --git a/plugins/main/dummy/dummy_test.go b/plugins/main/dummy/dummy_test.go index 6d7c0d0a2..dba70d4d3 100644 --- a/plugins/main/dummy/dummy_test.go +++ b/plugins/main/dummy/dummy_test.go @@ -180,11 +180,11 @@ var _ = Describe("dummy Operations", func() { err = originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = MASTER_NAME // Add master err = netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: MASTER_NAME, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) m, err := netlink.LinkByName(MASTER_NAME) diff --git a/plugins/main/host-device/host-device_test.go b/plugins/main/host-device/host-device_test.go index 2c26d03cb..f33fd89c2 100644 --- a/plugins/main/host-device/host-device_test.go +++ b/plugins/main/host-device/host-device_test.go @@ -341,10 +341,10 @@ var _ = Describe("base functionality", func() { // prepare ifname in original namespace _ = originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = ifname err := netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: ifname, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) origLink, err = netlink.LinkByName(ifname) @@ -422,10 +422,10 @@ var _ = Describe("base functionality", func() { // prepare host device in original namespace _ = originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = ifname err := netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: ifname, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) origLink, err = netlink.LinkByName(ifname) @@ -483,10 +483,10 @@ var _ = Describe("base functionality", func() { // create another conflict host device with same name "dummy0" _ = originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = ifname err := netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: ifname, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) conflictLink, err = netlink.LinkByName(ifname) @@ -608,10 +608,10 @@ var _ = Describe("base functionality", func() { // prepare ifname in original namespace _ = originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = ifname err := netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: ifname, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) origLink, err = netlink.LinkByName(ifname) @@ -720,10 +720,10 @@ var _ = Describe("base functionality", func() { // prepare ifname in original namespace _ = originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = ifname err := netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: ifname, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) origLink, err = netlink.LinkByName(ifname) @@ -912,10 +912,10 @@ var _ = Describe("base functionality", func() { // prepare ifname in original namespace _ = originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = ifname err := netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: ifname, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) origLink, err = netlink.LinkByName(ifname) @@ -969,10 +969,10 @@ var _ = Describe("base functionality", func() { // prepare ifname in original namespace _ = originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = ifname err := netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: ifname, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) origLink, err = netlink.LinkByName(ifname) @@ -1093,10 +1093,10 @@ var _ = Describe("base functionality", func() { // prepare host device in original namespace _ = originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = ifname err := netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: ifname, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) origLink, err = netlink.LinkByName(ifname) @@ -1154,10 +1154,10 @@ var _ = Describe("base functionality", func() { // create another conflict host device with same name "dummy0" _ = originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = ifname err := netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: ifname, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) conflictLink, err = netlink.LinkByName(ifname) @@ -1227,10 +1227,10 @@ var _ = Describe("base functionality", func() { // prepare host device in original namespace _ = originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = hostIfname err := netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: hostIfname, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) origLink, err = netlink.LinkByName(hostIfname) @@ -1243,10 +1243,10 @@ var _ = Describe("base functionality", func() { // prepare device in container namespace with same name as host device _ = targetNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = containerAdditionalIfname err := netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: containerAdditionalIfname, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) containerLink, err = netlink.LinkByName(containerAdditionalIfname) diff --git a/plugins/main/ipvlan/ipvlan.go b/plugins/main/ipvlan/ipvlan.go index 2b939c239..3adb776a8 100644 --- a/plugins/main/ipvlan/ipvlan.go +++ b/plugins/main/ipvlan/ipvlan.go @@ -144,14 +144,15 @@ func createIpvlan(conf *NetConf, ifName string, netns ns.NetNS) (*current.Interf return nil, err } + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.MTU = conf.MTU + linkAttrs.Name = tmpName + linkAttrs.ParentIndex = m.Attrs().Index + linkAttrs.Namespace = netlink.NsFd(int(netns.Fd())) + mv := &netlink.IPVlan{ - LinkAttrs: netlink.LinkAttrs{ - MTU: conf.MTU, - Name: tmpName, - ParentIndex: m.Attrs().Index, - Namespace: netlink.NsFd(int(netns.Fd())), - }, - Mode: mode, + LinkAttrs: linkAttrs, + Mode: mode, } if conf.LinkContNs { diff --git a/plugins/main/ipvlan/ipvlan_test.go b/plugins/main/ipvlan/ipvlan_test.go index 3c787fd7a..eab72a95d 100644 --- a/plugins/main/ipvlan/ipvlan_test.go +++ b/plugins/main/ipvlan/ipvlan_test.go @@ -281,11 +281,11 @@ var _ = Describe("ipvlan Operations", func() { err = originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = MASTER_NAME // Add master err = netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: MASTER_NAME, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) _, err = netlink.LinkByName(MASTER_NAME) @@ -297,11 +297,11 @@ var _ = Describe("ipvlan Operations", func() { err = targetNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = MASTER_NAME_INCONTAINER // Add master err = netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: MASTER_NAME_INCONTAINER, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) _, err = netlink.LinkByName(MASTER_NAME_INCONTAINER) diff --git a/plugins/main/macvlan/macvlan.go b/plugins/main/macvlan/macvlan.go index 9becb3bf7..6ff918dab 100644 --- a/plugins/main/macvlan/macvlan.go +++ b/plugins/main/macvlan/macvlan.go @@ -226,12 +226,11 @@ func createMacvlan(conf *NetConf, ifName string, netns ns.NetNS) (*current.Inter return nil, err } - linkAttrs := netlink.LinkAttrs{ - MTU: conf.MTU, - Name: tmpName, - ParentIndex: m.Attrs().Index, - Namespace: netlink.NsFd(int(netns.Fd())), - } + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.MTU = conf.MTU + linkAttrs.Name = tmpName + linkAttrs.ParentIndex = m.Attrs().Index + linkAttrs.Namespace = netlink.NsFd(int(netns.Fd())) if conf.Mac != "" { addr, err := net.ParseMAC(conf.Mac) diff --git a/plugins/main/macvlan/macvlan_test.go b/plugins/main/macvlan/macvlan_test.go index ae73f99f2..72d84e469 100644 --- a/plugins/main/macvlan/macvlan_test.go +++ b/plugins/main/macvlan/macvlan_test.go @@ -208,11 +208,11 @@ var _ = Describe("macvlan Operations", func() { err = originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = MASTER_NAME // Add master err = netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: MASTER_NAME, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) _, err = netlink.LinkByName(MASTER_NAME) @@ -224,11 +224,11 @@ var _ = Describe("macvlan Operations", func() { err = targetNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = MASTER_NAME_INCONTAINER // Add master err = netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: MASTER_NAME_INCONTAINER, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) _, err = netlink.LinkByName(MASTER_NAME_INCONTAINER) diff --git a/plugins/main/tap/tap.go b/plugins/main/tap/tap.go index b7ce29a0f..057329e96 100644 --- a/plugins/main/tap/tap.go +++ b/plugins/main/tap/tap.go @@ -137,10 +137,9 @@ func createTapWithIptool(tmpName string, mtu int, multiqueue bool, mac string, o } func createLinkWithNetlink(tmpName string, mtu int, nsFd int, multiqueue bool, mac string, owner *uint32, group *uint32) error { - linkAttrs := netlink.LinkAttrs{ - Name: tmpName, - Namespace: netlink.NsFd(nsFd), - } + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = tmpName + linkAttrs.Namespace = netlink.NsFd(nsFd) if mtu != 0 { linkAttrs.MTU = mtu } diff --git a/plugins/main/tap/tap_test.go b/plugins/main/tap/tap_test.go index c39a25ee6..f89f066b0 100644 --- a/plugins/main/tap/tap_test.go +++ b/plugins/main/tap/tap_test.go @@ -346,10 +346,10 @@ var _ = Describe("Add, check, remove tap plugin", func() { Expect( targetNS.Do(func(ns.NetNS) error { + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = bridgeName if err := netlink.LinkAdd(&netlink.Bridge{ - LinkAttrs: netlink.LinkAttrs{ - Name: bridgeName, - }, + LinkAttrs: linkAttrs, }); err != nil { return err } diff --git a/plugins/main/vlan/vlan.go b/plugins/main/vlan/vlan.go index 9cc34763d..b64f7619e 100644 --- a/plugins/main/vlan/vlan.go +++ b/plugins/main/vlan/vlan.go @@ -119,14 +119,15 @@ func createVlan(conf *NetConf, ifName string, netns ns.NetNS) (*current.Interfac return nil, err } + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.MTU = conf.MTU + linkAttrs.Name = tmpName + linkAttrs.ParentIndex = m.Attrs().Index + linkAttrs.Namespace = netlink.NsFd(int(netns.Fd())) + v := &netlink.Vlan{ - LinkAttrs: netlink.LinkAttrs{ - MTU: conf.MTU, - Name: tmpName, - ParentIndex: m.Attrs().Index, - Namespace: netlink.NsFd(int(netns.Fd())), - }, - VlanId: conf.VlanID, + LinkAttrs: linkAttrs, + VlanId: conf.VlanID, } if conf.LinkContNs { diff --git a/plugins/main/vlan/vlan_test.go b/plugins/main/vlan/vlan_test.go index c0cd3ed30..d4d435a73 100644 --- a/plugins/main/vlan/vlan_test.go +++ b/plugins/main/vlan/vlan_test.go @@ -187,11 +187,11 @@ var _ = Describe("vlan Operations", func() { err = originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = MASTER_NAME // Add master err = netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: MASTER_NAME, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) m, err := netlink.LinkByName(MASTER_NAME) @@ -205,11 +205,11 @@ var _ = Describe("vlan Operations", func() { err = targetNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = MASTER_NAME_INCONTAINER // Add master err = netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: MASTER_NAME_INCONTAINER, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) m, err := netlink.LinkByName(MASTER_NAME_INCONTAINER) diff --git a/plugins/meta/bandwidth/bandwidth_suite_test.go b/plugins/meta/bandwidth/bandwidth_suite_test.go index ce7a94ce4..a976cc952 100644 --- a/plugins/meta/bandwidth/bandwidth_suite_test.go +++ b/plugins/meta/bandwidth/bandwidth_suite_test.go @@ -108,13 +108,13 @@ func makeTCPClientInNS(netns string, address string, port int, numBytes int) { } func createVeth(hostNs ns.NetNS, hostVethIfName string, containerNs ns.NetNS, containerVethIfName string, hostIP []byte, containerIP []byte, hostIfaceMTU int) { + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = hostVethIfName + linkAttrs.Flags = net.FlagUp + linkAttrs.MTU = hostIfaceMTU vethDeviceRequest := &netlink.Veth{ - LinkAttrs: netlink.LinkAttrs{ - Name: hostVethIfName, - Flags: net.FlagUp, - MTU: hostIfaceMTU, - }, - PeerName: containerVethIfName, + LinkAttrs: linkAttrs, + PeerName: containerVethIfName, } err := hostNs.Do(func(_ ns.NetNS) error { @@ -195,12 +195,12 @@ func createVeth(hostNs ns.NetNS, hostVethIfName string, containerNs ns.NetNS, co } func createVethInOneNs(netNS ns.NetNS, vethName, peerName string) { + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = vethName + linkAttrs.Flags = net.FlagUp vethDeviceRequest := &netlink.Veth{ - LinkAttrs: netlink.LinkAttrs{ - Name: vethName, - Flags: net.FlagUp, - }, - PeerName: peerName, + LinkAttrs: linkAttrs, + PeerName: peerName, } err := netNS.Do(func(_ ns.NetNS) error { @@ -224,13 +224,13 @@ func createMacvlan(netNS ns.NetNS, master, macvlanName string) { return fmt.Errorf("failed to lookup master %q: %v", master, err) } + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.MTU = m.Attrs().MTU + linkAttrs.Name = macvlanName + linkAttrs.ParentIndex = m.Attrs().Index macvlanDeviceRequest := &netlink.Macvlan{ - LinkAttrs: netlink.LinkAttrs{ - MTU: m.Attrs().MTU, - Name: macvlanName, - ParentIndex: m.Attrs().Index, - }, - Mode: netlink.MACVLAN_MODE_BRIDGE, + LinkAttrs: linkAttrs, + Mode: netlink.MACVLAN_MODE_BRIDGE, } if err = netlink.LinkAdd(macvlanDeviceRequest); err != nil { diff --git a/plugins/meta/firewall/firewall_iptables_test.go b/plugins/meta/firewall/firewall_iptables_test.go index 0ac168abe..6f4c76248 100644 --- a/plugins/meta/firewall/firewall_iptables_test.go +++ b/plugins/meta/firewall/firewall_iptables_test.go @@ -205,10 +205,10 @@ var _ = Describe("firewall plugin iptables backend", func() { err = originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = IFNAME err = netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: IFNAME, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) _, err = netlink.LinkByName(IFNAME) diff --git a/plugins/meta/sbr/sbr_linux_test.go b/plugins/meta/sbr/sbr_linux_test.go index d800143a5..731f71d81 100644 --- a/plugins/meta/sbr/sbr_linux_test.go +++ b/plugins/meta/sbr/sbr_linux_test.go @@ -53,7 +53,9 @@ func setup(targetNs ns.NetNS, status netStatus) error { err := targetNs.Do(func(_ ns.NetNS) error { for _, dev := range status.Devices { log.Printf("Adding dev %s\n", dev.Name) - link := &netlink.Dummy{LinkAttrs: netlink.LinkAttrs{Name: dev.Name}} + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = dev.Name + link := &netlink.Dummy{LinkAttrs: linkAttrs} err := netlink.LinkAdd(link) if err != nil { return err diff --git a/plugins/meta/tuning/tuning_test.go b/plugins/meta/tuning/tuning_test.go index 6d25072a4..09a9a8349 100644 --- a/plugins/meta/tuning/tuning_test.go +++ b/plugins/meta/tuning/tuning_test.go @@ -110,10 +110,10 @@ var _ = Describe("tuning plugin", func() { err = originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = IFNAME err = netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: IFNAME, - }, + LinkAttrs: linkAttrs, }) Expect(err).NotTo(HaveOccurred()) link, err := netlink.LinkByName(IFNAME) diff --git a/plugins/meta/vrf/vrf.go b/plugins/meta/vrf/vrf.go index 5b8fb62b3..93e5e8525 100644 --- a/plugins/meta/vrf/vrf.go +++ b/plugins/meta/vrf/vrf.go @@ -48,11 +48,11 @@ func createVRF(name string, tableID uint32) (*netlink.Vrf, error) { } } + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = name vrf := &netlink.Vrf{ - LinkAttrs: netlink.LinkAttrs{ - Name: name, - }, - Table: tableID, + LinkAttrs: linkAttrs, + Table: tableID, } err = netlink.LinkAdd(vrf) diff --git a/plugins/meta/vrf/vrf_test.go b/plugins/meta/vrf/vrf_test.go index 0c8efb51b..9993d10af 100644 --- a/plugins/meta/vrf/vrf_test.go +++ b/plugins/meta/vrf/vrf_test.go @@ -94,19 +94,19 @@ var _ = Describe("vrf plugin", func() { err = targetNS.Do(func(ns.NetNS) error { defer GinkgoRecover() + la0 := netlink.NewLinkAttrs() + la0.Name = IF0Name err = netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: IF0Name, - }, + LinkAttrs: la0, }) Expect(err).NotTo(HaveOccurred()) _, err = netlink.LinkByName(IF0Name) Expect(err).NotTo(HaveOccurred()) + la1 := netlink.NewLinkAttrs() + la1.Name = IF1Name err = netlink.LinkAdd(&netlink.Dummy{ - LinkAttrs: netlink.LinkAttrs{ - Name: IF1Name, - }, + LinkAttrs: la1, }) Expect(err).NotTo(HaveOccurred()) _, err = netlink.LinkByName(IF1Name) @@ -437,10 +437,10 @@ var _ = Describe("vrf plugin", func() { defer GinkgoRecover() l, err := netlink.LinkByName(IF0Name) Expect(err).NotTo(HaveOccurred()) + linkAttrs := netlink.NewLinkAttrs() + linkAttrs.Name = "testrbridge" br := &netlink.Bridge{ - LinkAttrs: netlink.LinkAttrs{ - Name: "testrbridge", - }, + LinkAttrs: linkAttrs, } err = netlink.LinkAdd(br) Expect(err).NotTo(HaveOccurred())