Skip to content

Commit

Permalink
Validate resolv.conf for presence of nameserver entries
Browse files Browse the repository at this point in the history
Co-authored-by: Brad Davidson <brad@oatmail.org>
Signed-off-by: linxin <linxin@geedgenetworks.com>
  • Loading branch information
linxin and brandond committed May 24, 2024
1 parent 2669d67 commit f24ba9d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f24ba9d

Please sign in to comment.