From 31ef82276a4579f547a88c6a8a5c5a792abcfbfc Mon Sep 17 00:00:00 2001 From: Tom Denham Date: Mon, 29 Aug 2016 14:10:36 -0700 Subject: [PATCH] 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. --- ip/link.go | 2 +- ip/link_test.go | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ip/link.go b/ip/link.go index 1cab50cd..43b37390 100644 --- a/ip/link.go +++ b/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/ip/link_test.go b/ip/link_test.go index d4eff9b0..3df9ab8f 100644 --- a/ip/link_test.go +++ b/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 })