From 0038728e5e0055c85037bbf7064fb21a507c6064 Mon Sep 17 00:00:00 2001 From: Erik Stidham Date: Tue, 21 Nov 2017 15:01:34 -0600 Subject: [PATCH] Set MAC addr for host side of veth pair - Use hardcoded MAC of EE:EE:EE:EE:EE:EE (matchs libnetwork) - If there is an error log message and fallback to kernel provided MAC --- calico_cni_test.go | 5 +++-- utils/network.go | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/calico_cni_test.go b/calico_cni_test.go index 7ec6297da..433758e03 100644 --- a/calico_cni_test.go +++ b/calico_cni_test.go @@ -62,8 +62,6 @@ var _ = Describe("CalicoCni", func() { log.Fatalf("Error getting result from the session: %v\n", err) } - mac := contVeth.Attrs().HardwareAddr - Expect(len(result.IPs)).Should(Equal(1)) ip := result.IPs[0].Address.IP.String() result.IPs[0].Address.IP = result.IPs[0].Address.IP.To4() // Make sure the IP is respresented as 4 bytes @@ -96,6 +94,8 @@ var _ = Describe("CalicoCni", func() { Expect(endpoints.Items[0].Name).Should(Equal(wrkload)) Expect(endpoints.Items[0].Namespace).Should(Equal(testutils.TEST_DEFAULT_NS)) + mac := contVeth.Attrs().HardwareAddr + Expect(endpoints.Items[0].Spec).Should(Equal(api.WorkloadEndpointSpec{ InterfaceName: fmt.Sprintf("cali%s", containerID), IPNetworks: []string{result.IPs[0].Address.String()}, @@ -116,6 +116,7 @@ var _ = Describe("CalicoCni", func() { Expect(err).ToNot(HaveOccurred()) Expect(hostVeth.Attrs().Flags.String()).Should(ContainSubstring("up")) Expect(hostVeth.Attrs().MTU).Should(Equal(1500)) + Expect(hostVeth.Attrs().HardwareAddr.String()).Should(Equal("ee:ee:ee:ee:ee:ee")) // Assert hostVeth sysctl values are set to what we expect for IPv4. err = testutils.CheckSysctlValue(fmt.Sprintf("/proc/sys/net/ipv4/conf/%s/proxy_arp", hostVethName), "1") diff --git a/utils/network.go b/utils/network.go index 2e19d8a1d..8837be102 100644 --- a/utils/network.go +++ b/utils/network.go @@ -59,6 +59,16 @@ func DoNetworking(args *skel.CmdArgs, conf types.NetConf, result *current.Result return err } + if mac, err := net.ParseMAC("EE:EE:EE:EE:EE:EE"); err != nil { + logger.Infof("failed to parse MAC Address: %v. Using kernel generated MAC.", err) + } else { + // Set the MAC address on the host side interface so the kernel does not + // have to generate a persistent address which fails some times. + if err = netlink.LinkSetHardwareAddr(hostVeth, mac); err != nil { + logger.Warnf("failed to Set MAC of %q: %v. Using kernel generated MAC.", hostVethName, err) + } + } + // Explicitly set the veth to UP state, because netlink doesn't always do that on all the platforms with net.FlagUp. // veth won't get a link local address unless it's set to UP state. if err = netlink.LinkSetUp(hostVeth); err != nil {