fix(network): Take down all interfaces properly
The map of interfaces wasn't being populated correctly. Also, clean up some prints.
This commit is contained in:
parent
159f4a2c7c
commit
16d7e8af48
@ -96,7 +96,7 @@ func splitStanzas(lines []string) ([][]string, error) {
|
|||||||
} else if curStanza != nil {
|
} else if curStanza != nil {
|
||||||
curStanza = append(curStanza, line)
|
curStanza = append(curStanza, line)
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("missing stanza start '%s'", line)
|
return nil, fmt.Errorf("missing stanza start %q", line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ func parseStanza(rawStanza []string) (stanza, error) {
|
|||||||
case "iface":
|
case "iface":
|
||||||
return parseInterfaceStanza(attributes, rawStanza[1:])
|
return parseInterfaceStanza(attributes, rawStanza[1:])
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown stanza '%s'", kind)
|
return nil, fmt.Errorf("unknown stanza %q", kind)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,7 +204,7 @@ func parseInterfaceStanza(attributes []string, options []string) (*stanzaInterfa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if config.address.IP == nil || config.address.Mask == nil {
|
if config.address.IP == nil || config.address.Mask == nil {
|
||||||
return nil, fmt.Errorf("malformed static network config for '%s'", iface)
|
return nil, fmt.Errorf("malformed static network config for %q", iface)
|
||||||
}
|
}
|
||||||
if gateways, ok := optionMap["gateway"]; ok {
|
if gateways, ok := optionMap["gateway"]; ok {
|
||||||
if len(gateways) == 1 {
|
if len(gateways) == 1 {
|
||||||
@ -247,7 +247,7 @@ func parseInterfaceStanza(attributes []string, options []string) (*stanzaInterfa
|
|||||||
case "dhcp":
|
case "dhcp":
|
||||||
conf = configMethodDHCP{}
|
conf = configMethodDHCP{}
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("invalid config method '%s'", confMethod)
|
return nil, fmt.Errorf("invalid config method %q", confMethod)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := optionMap["vlan_raw_device"]; ok {
|
if _, ok := optionMap["vlan_raw_device"]; ok {
|
||||||
@ -282,11 +282,11 @@ func parseVLANStanza(iface string, conf configMethod, attributes []string, optio
|
|||||||
} else if strings.HasPrefix(iface, "vlan") {
|
} else if strings.HasPrefix(iface, "vlan") {
|
||||||
id = strings.TrimPrefix(iface, "vlan")
|
id = strings.TrimPrefix(iface, "vlan")
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("malformed vlan name %s", iface)
|
return nil, fmt.Errorf("malformed vlan name %q", iface)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := strconv.Atoi(id); err != nil {
|
if _, err := strconv.Atoi(id); err != nil {
|
||||||
return nil, fmt.Errorf("malformed vlan name %s", iface)
|
return nil, fmt.Errorf("malformed vlan name %q", iface)
|
||||||
}
|
}
|
||||||
options["id"] = []string{id}
|
options["id"] = []string{id}
|
||||||
options["raw_device"] = options["vlan_raw_device"]
|
options["raw_device"] = options["vlan_raw_device"]
|
||||||
|
@ -36,7 +36,9 @@ func downNetworkInterfaces(interfaces []network.InterfaceGenerator) error {
|
|||||||
sysInterfaceMap := make(map[string]*net.Interface)
|
sysInterfaceMap := make(map[string]*net.Interface)
|
||||||
if systemInterfaces, err := net.Interfaces(); err == nil {
|
if systemInterfaces, err := net.Interfaces(); err == nil {
|
||||||
for _, iface := range systemInterfaces {
|
for _, iface := range systemInterfaces {
|
||||||
sysInterfaceMap[iface.Name] = &iface
|
// Need a copy of the interface so we can take the address
|
||||||
|
temp := iface
|
||||||
|
sysInterfaceMap[temp.Name] = &temp
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user