Using net.IsLoopback to determine if ifc is a loopback device

This commit is contained in:
Diptanu Choudhury 2016-02-08 07:57:31 -08:00
parent 68d0105634
commit fa45e0b8ca
2 changed files with 14 additions and 10 deletions

View file

@ -57,11 +57,11 @@ type Config struct {
// Node provides the base node // Node provides the base node
Node *structs.Node Node *structs.Node
// PluginMaxPort defines the highest port a plugin process can use // ExecutorMaxPort defines the highest port a plugin process can use
PluginMaxPort int ExecutorMaxPort int
// PluginMinPort defines the lowest port a plugin process can use // ExecutorMinPort defines the lowest port a plugin process can use
PluginMinPort int ExecutorMinPort int
// Options provides arbitrary key-value configuration for nomad internals, // Options provides arbitrary key-value configuration for nomad internals,
// like fingerprinters and drivers. The format is: // like fingerprinters and drivers. The format is:

View file

@ -241,12 +241,16 @@ func (a *Agent) setupClient() error {
// Reserve some ports for the plugins // Reserve some ports for the plugins
if runtime.GOOS == "windows" { 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 { if err != nil {
return fmt.Errorf("error finding the device name for the ip 127.0.0.1: %v", err) 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 var nr *structs.NetworkResource
for _, n := range conf.Node.Reserved.Networks { for _, n := range conf.Node.Reserved.Networks {
if n.Device == deviceName { if n.Device == deviceName {
@ -259,7 +263,7 @@ func (a *Agent) setupClient() error {
ReservedPorts: make([]structs.Port, 0), 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}) 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 return nil
} }
func (a *Agent) findInterfaceNameForIP(ip string) (string, error) { func (a *Agent) findLoopbackDevice() (string, error) {
var ifcs []net.Interface var ifcs []net.Interface
var err error var err error
var deviceName string var deviceName string
@ -288,7 +292,7 @@ func (a *Agent) findInterfaceNameForIP(ip string) (string, error) {
return deviceName, err return deviceName, err
} }
for _, addr := range addrs { for _, addr := range addrs {
if addr.String() == "127.0.0.1" { if net.ParseIP(addr.String()).IsLoopback() {
return ifc.Name, nil return ifc.Name, nil
} }
} }