From 8bb8f70bb6c10f4551bbf4c97c80b9d5dd31fcaf Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 14 Jun 2016 17:53:34 +0100 Subject: [PATCH] Perform arp configuration for plugin-connected containers --- common/utils.go | 19 +++++++++++++++++++ plugin/net/watcher.go | 5 +++++ weave | 1 + 3 files changed, 25 insertions(+) diff --git a/common/utils.go b/common/utils.go index 666eb4f7..7086cd9f 100644 --- a/common/utils.go +++ b/common/utils.go @@ -6,6 +6,7 @@ import ( "os" "strings" + "github.com/j-keck/arping" "github.com/vishvananda/netlink" "github.com/vishvananda/netns" @@ -34,6 +35,7 @@ type NetDev struct { } // Search the network namespace of a process for interfaces matching a predicate +// Note that the predicate is called while the goroutine is inside the process' netns func FindNetDevs(processID int, match func(link netlink.Link) bool) ([]NetDev, error) { var netDevs []NetDev @@ -137,3 +139,20 @@ func GetBridgeNetDev(bridgeName string) ([]NetDev, error) { return link.Attrs().Name == bridgeName }) } + +// Do post-attach configuration of all veths we have created +func ConfigureARPforVeths(processID int, prefix string) error { + _, err := FindNetDevs(processID, func(link netlink.Link) bool { + ifName := link.Attrs().Name + if strings.HasPrefix(ifName, prefix) { + weavenet.ConfigureARPCache(ifName) + if addrs, err := netlink.AddrList(link, netlink.FAMILY_V4); err == nil { + for _, addr := range addrs { + arping.GratuitousArpOverIfaceByName(addr.IPNet.IP, ifName) + } + } + } + return false + }) + return err +} diff --git a/plugin/net/watcher.go b/plugin/net/watcher.go index e72ba570..3217b646 100644 --- a/plugin/net/watcher.go +++ b/plugin/net/watcher.go @@ -4,7 +4,9 @@ import ( "fmt" weaveapi "github.com/weaveworks/weave/api" + "github.com/weaveworks/weave/common" "github.com/weaveworks/weave/common/docker" + weavenet "github.com/weaveworks/weave/net" ) const ( @@ -44,6 +46,9 @@ func (w *watcher) ContainerStarted(id string) { if err := w.weave.RegisterWithDNS(id, fqdn, net.IPAddress); err != nil { w.driver.warn("ContainerStarted", "unable to register %s with weaveDNS: %s", id, err) } + if err := common.ConfigureARPforVeths(info.State.Pid, weavenet.VethName); err != nil { + w.driver.warn("ContainerStarted", "unable to configure interfaces: %s", err) + } } } } diff --git a/weave b/weave index 9bc0340f..1709d910 100755 --- a/weave +++ b/weave @@ -1747,6 +1747,7 @@ launch_plugin_if_not_running() { if ! PLUGIN_CONTAINER=$(docker run -d --name=$PLUGIN_CONTAINER_NAME \ $(docker_run_options) \ $RESTART_POLICY \ + --pid=host \ -v /run/docker/plugins:/run/docker/plugins \ -e WEAVE_HTTP_ADDR \ $WEAVEPLUGIN_DOCKER_ARGS $PLUGIN_IMAGE $COVERAGE_ARGS \