mirror of https://github.com/k3s-io/k3s
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/10290/head
parent
13eafdd23a
commit
6781d660bf
|
@ -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…
Reference in New Issue