From 16d7e8af48513db4e4154076243e434579a1fd47 Mon Sep 17 00:00:00 2001 From: Alex Crawford Date: Wed, 11 Jun 2014 23:20:59 -0700 Subject: [PATCH] fix(network): Take down all interfaces properly The map of interfaces wasn't being populated correctly. Also, clean up some prints. --- network/stanza.go | 12 ++++++------ system/networkd.go | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/network/stanza.go b/network/stanza.go index dca59aa..a6db8c4 100644 --- a/network/stanza.go +++ b/network/stanza.go @@ -96,7 +96,7 @@ func splitStanzas(lines []string) ([][]string, error) { } else if curStanza != nil { curStanza = append(curStanza, line) } 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": return parseInterfaceStanza(attributes, rawStanza[1:]) 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 { - 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 len(gateways) == 1 { @@ -247,7 +247,7 @@ func parseInterfaceStanza(attributes []string, options []string) (*stanzaInterfa case "dhcp": conf = configMethodDHCP{} 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 { @@ -282,11 +282,11 @@ func parseVLANStanza(iface string, conf configMethod, attributes []string, optio } else if strings.HasPrefix(iface, "vlan") { id = strings.TrimPrefix(iface, "vlan") } 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 { - return nil, fmt.Errorf("malformed vlan name %s", iface) + return nil, fmt.Errorf("malformed vlan name %q", iface) } options["id"] = []string{id} options["raw_device"] = options["vlan_raw_device"] diff --git a/system/networkd.go b/system/networkd.go index c795563..f49a15d 100644 --- a/system/networkd.go +++ b/system/networkd.go @@ -36,7 +36,9 @@ func downNetworkInterfaces(interfaces []network.InterfaceGenerator) error { sysInterfaceMap := make(map[string]*net.Interface) if systemInterfaces, err := net.Interfaces(); err == nil { 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 { return err