From a1dab0aa400d4f23877267838d5a8fc8bcaa43d6 Mon Sep 17 00:00:00 2001 From: Piotr Skamruk Date: Mon, 7 Mar 2016 16:41:04 +0100 Subject: [PATCH] macvlan: set proxy_arp in time of creating interface Resolves CNI part of https://github.com/coreos/rkt/issues/1765 Second part would be adding similar lines into kvm flavored macvlan support (in time of creating macvtap device). --- plugins/main/macvlan/macvlan.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/plugins/main/macvlan/macvlan.go b/plugins/main/macvlan/macvlan.go index f6891a34..0635f263 100644 --- a/plugins/main/macvlan/macvlan.go +++ b/plugins/main/macvlan/macvlan.go @@ -26,9 +26,14 @@ import ( "github.com/appc/cni/pkg/ns" "github.com/appc/cni/pkg/skel" "github.com/appc/cni/pkg/types" + "github.com/appc/cni/pkg/utils/sysctl" "github.com/vishvananda/netlink" ) +const ( + IPv4InterfaceArpProxySysctlTemplate = "net.ipv4.conf.%s.proxy_arp" +) + type NetConf struct { types.NetConf Master string `json:"master"` @@ -80,7 +85,7 @@ func createMacvlan(conf *NetConf, ifName string, netns *os.File) error { return fmt.Errorf("failed to lookup master %q: %v", conf.Master, err) } - // due to kernel bug we have to create with tmpname or it might + // due to kernel bug we have to create with tmpName or it might // collide with the name on the host and error out tmpName, err := ip.RandomVethName() if err != nil { @@ -101,6 +106,14 @@ func createMacvlan(conf *NetConf, ifName string, netns *os.File) error { return fmt.Errorf("failed to create macvlan: %v", err) } + // TODO: duplicate following lines for ipv6 support, when it will be added in other places + ipv4SysctlValueName := fmt.Sprintf(IPv4InterfaceArpProxySysctlTemplate, tmpName) + if _, err := sysctl.Sysctl(ipv4SysctlValueName, "1"); err != nil { + // remove the newly added link and ignore errors, because we already are in a failed state + _ = netlink.LinkDel(mv) + return fmt.Errorf("failed to set proxy_arp on newly added interface %q: %v", tmpName, err) + } + return ns.WithNetNS(netns, false, func(_ *os.File) error { err := renameLink(tmpName, ifName) if err != nil {