diff --git a/prog/weaveutil/main.go b/prog/weaveutil/main.go index 2550d56d..24a6f581 100644 --- a/prog/weaveutil/main.go +++ b/prog/weaveutil/main.go @@ -20,6 +20,7 @@ func init() { "create-plugin-network": createPluginNetwork, "remove-plugin-network": removePluginNetwork, "container-addrs": containerAddrs, + "process-addrs": processAddrs, "attach-container": attach, "detach-container": detach, } diff --git a/prog/weaveutil/proc-addrs.go b/prog/weaveutil/proc-addrs.go new file mode 100644 index 00000000..23e16479 --- /dev/null +++ b/prog/weaveutil/proc-addrs.go @@ -0,0 +1,40 @@ +package main + +import ( + "strconv" + + "github.com/weaveworks/weave/common" + weavenet "github.com/weaveworks/weave/net" +) + +func processAddrs(args []string) error { + if len(args) < 1 { + cmdUsage("process-addrs", "") + } + bridgeName := args[0] + + pred, err := common.ConnectedToBridgePredicate(bridgeName) + if err != nil { + if err == weavenet.ErrLinkNotFound { + return nil + } + return err + } + + pids, err := common.AllPids("/proc") + if err != nil { + return err + } + + // NB: Because network namespaces (netns) are changed many times inside the loop, + // it's NOT safe to exec any code depending on the root netns without + // wrapping with WithNetNS*. + for _, pid := range pids { + netDevs, err := common.GetNetDevsWithPredicate(pid, pred) + if err != nil { + return err + } + printNetDevs(strconv.Itoa(pid), netDevs) + } + return nil +}