mirror of
https://github.com/rancher/os.git
synced 2025-09-15 22:49:08 +00:00
Stop overwriting a good resolv.conf file with the default one
Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
@@ -157,7 +157,7 @@ func populateDefault(netCfg *NetworkConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
func ApplyNetworkConfigs(netCfg *NetworkConfig, userSetHostname, userSetDNS bool) error {
|
||||
func ApplyNetworkConfigs(netCfg *NetworkConfig, userSetHostname, userSetDNS bool) (bool, error) {
|
||||
populateDefault(netCfg)
|
||||
|
||||
log.Debugf("Config: %#v", netCfg)
|
||||
@@ -169,7 +169,8 @@ func ApplyNetworkConfigs(netCfg *NetworkConfig, userSetHostname, userSetDNS bool
|
||||
|
||||
links, err := netlink.LinkList()
|
||||
if err != nil {
|
||||
return err
|
||||
log.Errorf("error getting LinkList: %s", err)
|
||||
return false, err
|
||||
}
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
@@ -180,7 +181,20 @@ func ApplyNetworkConfigs(netCfg *NetworkConfig, userSetHostname, userSetDNS bool
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
return err
|
||||
// make sure there was a DHCP set dns - or tell ros to write 8.8.8.8,8.8.8.4
|
||||
log.Infof("Checking to see if DNS was set by DHCP")
|
||||
dnsSet := false
|
||||
for _, link := range links {
|
||||
linkName := link.Attrs().Name
|
||||
log.Infof("dns testing %s", linkName)
|
||||
lease := getDhcpLease(linkName)
|
||||
if _, ok := lease["domain_name_servers"]; ok {
|
||||
log.Infof("dns was dhcp set for %s", linkName)
|
||||
dnsSet = true
|
||||
}
|
||||
}
|
||||
|
||||
return dnsSet, err
|
||||
}
|
||||
|
||||
func applyOuter(link netlink.Link, netCfg *NetworkConfig, wg *sync.WaitGroup, userSetHostname, userSetDNS bool) {
|
||||
@@ -222,14 +236,36 @@ func applyOuter(link netlink.Link, netCfg *NetworkConfig, wg *sync.WaitGroup, us
|
||||
}(linkName, match)
|
||||
}
|
||||
|
||||
func hasDhcp(iface string) bool {
|
||||
func getDhcpLease(iface string) (lease map[string]string) {
|
||||
lease = make(map[string]string)
|
||||
|
||||
out := getDhcpLeaseString(iface)
|
||||
log.Debugf("getDhcpLease %s: %s", iface, out)
|
||||
|
||||
lines := strings.Split(string(out), "\n")
|
||||
for _, line := range lines {
|
||||
l := strings.SplitN(line, "=", 2)
|
||||
log.Debugf("line: %v", l)
|
||||
if len(l) > 1 {
|
||||
lease[l[0]] = l[1]
|
||||
}
|
||||
}
|
||||
return lease
|
||||
}
|
||||
|
||||
func getDhcpLeaseString(iface string) []byte {
|
||||
cmd := exec.Command("dhcpcd", "-U", iface)
|
||||
//cmd.Stderr = os.Stderr
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
log.Debugf("dhcpcd -u %s: %s", iface, out)
|
||||
return out
|
||||
}
|
||||
|
||||
func hasDhcp(iface string) bool {
|
||||
out := getDhcpLeaseString(iface)
|
||||
log.Debugf("dhcpcd -U %s: %s", iface, out)
|
||||
return len(out) > 0
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user