plugins: set MAC addresses based on IP

This will give deterministic MAC addresses for all interfaces CNI
creates and manages the IP for:
* bridge: container veth and host bridge
* macvlan: container veth
* ptp: container veth and host veth
This commit is contained in:
Stefan Junker
2016-06-28 17:46:17 -07:00
parent 3a1354cff6
commit 924b30b57d
7 changed files with 69 additions and 42 deletions

View File

@ -149,6 +149,14 @@ func cmdAdd(args *skel.CmdArgs) error {
}
err = netns.Do(func(_ ns.NetNS) error {
contVethLink, err := netlink.LinkByName(args.IfName)
if err != nil {
return fmt.Errorf("failed to lookup %q: %v", args.IfName, err)
}
if err := ip.SetHWAddrByIP(contVethLink, result.IP4.IP.IP, nil /* TODO IPv6 */); err != nil {
return err
}
return ipam.ConfigureIface(args.IfName, result)
})
if err != nil {