From: Tom Denham Date: Mon, 29 Aug 2016 21:10:36 +0000 (-0700) Subject: pkg/ip: Ensure that SetupVeth returns correct hostVeth X-Git-Url: https://git.halfball.org/?a=commitdiff_plain;h=726c6b45783fefad0a384479eab854bf878ed8b0;p=cni.git pkg/ip: Ensure that SetupVeth returns correct hostVeth The veth is moved from the container NS to the host NS. This is handled by the code that sets the link to UP but the wrong hostVeth is returned to the calling code. --- diff --git a/pkg/ip/link.go b/pkg/ip/link.go index 1cab50c..43b3739 100644 --- a/pkg/ip/link.go +++ b/pkg/ip/link.go @@ -117,7 +117,7 @@ func SetupVeth(contVethName string, mtu int, hostNS ns.NetNS) (hostVeth, contVet } err = hostNS.Do(func(_ ns.NetNS) error { - hostVeth, err := netlink.LinkByName(hostVethName) + hostVeth, err = netlink.LinkByName(hostVethName) if err != nil { return fmt.Errorf("failed to lookup %q in %q: %v", hostVethName, hostNS.Path(), err) } diff --git a/pkg/ip/link_test.go b/pkg/ip/link_test.go index d4eff9b..3df9ab8 100644 --- a/pkg/ip/link_test.go +++ b/pkg/ip/link_test.go @@ -46,6 +46,8 @@ var _ = Describe("Link", func() { hostNetNS ns.NetNS containerNetNS ns.NetNS ifaceCounter int = 0 + hostVeth netlink.Link + containerVeth netlink.Link hostVethName string containerVethName string @@ -70,7 +72,7 @@ var _ = Describe("Link", func() { _ = containerNetNS.Do(func(ns.NetNS) error { defer GinkgoRecover() - hostVeth, containerVeth, err := ip.SetupVeth(fmt.Sprintf(ifaceFormatString, ifaceCounter), mtu, hostNetNS) + hostVeth, containerVeth, err = ip.SetupVeth(fmt.Sprintf(ifaceFormatString, ifaceCounter), mtu, hostNetNS) if err != nil { return err } @@ -94,8 +96,9 @@ var _ = Describe("Link", func() { _ = containerNetNS.Do(func(ns.NetNS) error { defer GinkgoRecover() - _, err := netlink.LinkByName(containerVethName) + containerVethFromName, err := netlink.LinkByName(containerVethName) Expect(err).NotTo(HaveOccurred()) + Expect(containerVethFromName.Attrs().Index).To(Equal(containerVeth.Attrs().Index)) return nil }) @@ -103,8 +106,9 @@ var _ = Describe("Link", func() { _ = hostNetNS.Do(func(ns.NetNS) error { defer GinkgoRecover() - _, err := netlink.LinkByName(hostVethName) + hostVethFromName, err := netlink.LinkByName(hostVethName) Expect(err).NotTo(HaveOccurred()) + Expect(hostVethFromName.Attrs().Index).To(Equal(hostVeth.Attrs().Index)) return nil })