Skip to content

Commit

Permalink
Merge pull request #141 from squeed/missing-mac
Browse files Browse the repository at this point in the history
pkg/ip: re-fetch the created link to return creation-time parameters
  • Loading branch information
Casey Callendrello authored Apr 12, 2018
2 parents dd8ff8a + 26dafaa commit 72b62ba
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pkg/ip/link_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ func makeVethPair(name, peer string, mtu int) (netlink.Link, error) {
if err := netlink.LinkAdd(veth); err != nil {
return nil, err
}
// Re-fetch the link to get its creation-time parameters, e.g. index and mac
veth2, err := netlink.LinkByName(name)
if err != nil {
netlink.LinkDel(veth) // try and clean up the link if possible.
return nil, err
}

return veth, nil
return veth2, nil
}

func peerExists(name string) bool {
Expand Down
7 changes: 7 additions & 0 deletions plugins/main/bridge/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,14 @@ func (tester *testerV03x) cmdAddTest(tc testCase) {

Expect(len(result.Interfaces)).To(Equal(3))
Expect(result.Interfaces[0].Name).To(Equal(BRNAME))
Expect(result.Interfaces[0].Mac).To(HaveLen(17))

Expect(result.Interfaces[1].Name).To(HavePrefix("veth"))
Expect(result.Interfaces[1].Mac).To(HaveLen(17))

Expect(result.Interfaces[2].Name).To(Equal(IFNAME))
Expect(result.Interfaces[2].Mac).To(HaveLen(17)) //mac is random
Expect(result.Interfaces[2].Sandbox).To(Equal(tester.targetNS.Path()))

// Make sure bridge link exists
link, err := netlink.LinkByName(result.Interfaces[0].Name)
Expand Down
15 changes: 14 additions & 1 deletion plugins/main/ptp/ptp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ var _ = Describe("ptp Operations", func() {
// Make sure ptp link exists in the target namespace
// Then, ping the gateway
seenIPs := 0

wantMac := ""
err = targetNs.Do(func(ns.NetNS) error {
defer GinkgoRecover()

link, err := netlink.LinkByName(IFNAME)
Expect(err).NotTo(HaveOccurred())
Expect(link.Attrs().Name).To(Equal(IFNAME))
wantMac = link.Attrs().HardwareAddr.String()

for _, ipc := range res.IPs {
if *ipc.Interface != 1 {
Expand All @@ -105,6 +107,17 @@ var _ = Describe("ptp Operations", func() {

Expect(seenIPs).To(Equal(numIPs))

// make sure the interfaces are correct
Expect(res.Interfaces).To(HaveLen(2))

Expect(res.Interfaces[0].Name).To(HavePrefix("veth"))
Expect(res.Interfaces[0].Mac).To(HaveLen(17))
Expect(res.Interfaces[0].Sandbox).To(BeEmpty())

Expect(res.Interfaces[1].Name).To(Equal(IFNAME))
Expect(res.Interfaces[1].Mac).To(Equal(wantMac))
Expect(res.Interfaces[1].Sandbox).To(Equal(targetNs.Path()))

// Call the plugins with the DEL command, deleting the veth endpoints
err = originalNS.Do(func(ns.NetNS) error {
defer GinkgoRecover()
Expand Down

0 comments on commit 72b62ba

Please sign in to comment.