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.
This commit is contained in:
@ -117,7 +117,7 @@ func SetupVeth(contVethName string, mtu int, hostNS ns.NetNS) (hostVeth, contVet
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = hostNS.Do(func(_ ns.NetNS) error {
|
err = hostNS.Do(func(_ ns.NetNS) error {
|
||||||
hostVeth, err := netlink.LinkByName(hostVethName)
|
hostVeth, err = netlink.LinkByName(hostVethName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to lookup %q in %q: %v", hostVethName, hostNS.Path(), err)
|
return fmt.Errorf("failed to lookup %q in %q: %v", hostVethName, hostNS.Path(), err)
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,8 @@ var _ = Describe("Link", func() {
|
|||||||
hostNetNS ns.NetNS
|
hostNetNS ns.NetNS
|
||||||
containerNetNS ns.NetNS
|
containerNetNS ns.NetNS
|
||||||
ifaceCounter int = 0
|
ifaceCounter int = 0
|
||||||
|
hostVeth netlink.Link
|
||||||
|
containerVeth netlink.Link
|
||||||
hostVethName string
|
hostVethName string
|
||||||
containerVethName string
|
containerVethName string
|
||||||
|
|
||||||
@ -70,7 +72,7 @@ var _ = Describe("Link", func() {
|
|||||||
_ = containerNetNS.Do(func(ns.NetNS) error {
|
_ = containerNetNS.Do(func(ns.NetNS) error {
|
||||||
defer GinkgoRecover()
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -94,8 +96,9 @@ var _ = Describe("Link", func() {
|
|||||||
_ = containerNetNS.Do(func(ns.NetNS) error {
|
_ = containerNetNS.Do(func(ns.NetNS) error {
|
||||||
defer GinkgoRecover()
|
defer GinkgoRecover()
|
||||||
|
|
||||||
_, err := netlink.LinkByName(containerVethName)
|
containerVethFromName, err := netlink.LinkByName(containerVethName)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(containerVethFromName.Attrs().Index).To(Equal(containerVeth.Attrs().Index))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@ -103,8 +106,9 @@ var _ = Describe("Link", func() {
|
|||||||
_ = hostNetNS.Do(func(ns.NetNS) error {
|
_ = hostNetNS.Do(func(ns.NetNS) error {
|
||||||
defer GinkgoRecover()
|
defer GinkgoRecover()
|
||||||
|
|
||||||
_, err := netlink.LinkByName(hostVethName)
|
hostVethFromName, err := netlink.LinkByName(hostVethName)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(hostVethFromName.Attrs().Index).To(Equal(hostVeth.Attrs().Index))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user