From fa45e0b8cac99e6308ef0aecc236732557f2f658 Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Mon, 8 Feb 2016 07:57:31 -0800 Subject: [PATCH] Using net.IsLoopback to determine if ifc is a loopback device --- client/config/config.go | 8 ++++---- command/agent/agent.go | 16 ++++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/client/config/config.go b/client/config/config.go index bb595c6ad..0d59a1b9a 100644 --- a/client/config/config.go +++ b/client/config/config.go @@ -57,11 +57,11 @@ type Config struct { // Node provides the base node Node *structs.Node - // PluginMaxPort defines the highest port a plugin process can use - PluginMaxPort int + // ExecutorMaxPort defines the highest port a plugin process can use + ExecutorMaxPort int - // PluginMinPort defines the lowest port a plugin process can use - PluginMinPort int + // ExecutorMinPort defines the lowest port a plugin process can use + ExecutorMinPort int // Options provides arbitrary key-value configuration for nomad internals, // like fingerprinters and drivers. The format is: diff --git a/command/agent/agent.go b/command/agent/agent.go index 8ae8f4823..28e5e6b60 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -241,12 +241,16 @@ func (a *Agent) setupClient() error { // Reserve some ports for the plugins if runtime.GOOS == "windows" { - deviceName, err := a.findInterfaceNameForIP("127.0.0.1") + deviceName, err := a.findLoopbackDevice() + if conf.ExecutorMaxPort == 0 { + conf.ExecutorMaxPort = 15000 + } + if conf.ExecutorMinPort == 0 { + conf.ExecutorMinPort = 14000 + } if err != nil { return fmt.Errorf("error finding the device name for the ip 127.0.0.1: %v", err) } - conf.PluginMinPort = 14000 - conf.PluginMaxPort = 15000 var nr *structs.NetworkResource for _, n := range conf.Node.Reserved.Networks { if n.Device == deviceName { @@ -259,7 +263,7 @@ func (a *Agent) setupClient() error { ReservedPorts: make([]structs.Port, 0), } } - for i := conf.PluginMinPort; i <= conf.PluginMaxPort; i++ { + for i := conf.ExecutorMinPort; i <= conf.ExecutorMaxPort; i++ { nr.ReservedPorts = append(nr.ReservedPorts, structs.Port{Label: fmt.Sprintf("plugin-%d", i), Value: i}) } @@ -274,7 +278,7 @@ func (a *Agent) setupClient() error { return nil } -func (a *Agent) findInterfaceNameForIP(ip string) (string, error) { +func (a *Agent) findLoopbackDevice() (string, error) { var ifcs []net.Interface var err error var deviceName string @@ -288,7 +292,7 @@ func (a *Agent) findInterfaceNameForIP(ip string) (string, error) { return deviceName, err } for _, addr := range addrs { - if addr.String() == "127.0.0.1" { + if net.ParseIP(addr.String()).IsLoopback() { return ifc.Name, nil } }