Validate resolv.conf for presence of nameserver entries

Co-authored-by: Brad Davidson <brad@oatmail.org>
Signed-off-by: linxin <linxin@geedgenetworks.com>
(cherry picked from commit f24ba9d3a9)
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
pull/10288/head
linxin 8 months ago committed by Brad Davidson
parent 2434cfd46e
commit d386eaf904

@ -316,19 +316,22 @@ func isValidResolvConf(resolvConfFile string) bool {
nameserver := regexp.MustCompile(`^nameserver\s+([^\s]*)`)
scanner := bufio.NewScanner(file)
foundNameserver := false
for scanner.Scan() {
ipMatch := nameserver.FindStringSubmatch(scanner.Text())
if len(ipMatch) == 2 {
ip := net.ParseIP(ipMatch[1])
if ip == nil || !ip.IsGlobalUnicast() {
return false
} else {
foundNameserver = true
}
}
}
if err := scanner.Err(); err != nil {
return false
}
return true
return foundNameserver
}
func locateOrGenerateResolvConf(envInfo *cmds.Agent) string {

Loading…
Cancel
Save