From 64bbaecb07c99f4ce391b75a795fa274c12b0f7d Mon Sep 17 00:00:00 2001 From: Arthur Barr Date: Tue, 24 Mar 2015 07:12:59 +0000 Subject: [PATCH] Fix #11589 by adding README and comments to exported functions Signed-off-by: Arthur Barr --- resolvconf/README.md | 1 + resolvconf/resolvconf.go | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 resolvconf/README.md diff --git a/resolvconf/README.md b/resolvconf/README.md new file mode 100644 index 0000000..cdda554 --- /dev/null +++ b/resolvconf/README.md @@ -0,0 +1 @@ +Package resolvconf provides utility code to query and update DNS configuration in /etc/resolv.conf diff --git a/resolvconf/resolvconf.go b/resolvconf/resolvconf.go index 61f92d9..d6f0f7a 100644 --- a/resolvconf/resolvconf.go +++ b/resolvconf/resolvconf.go @@ -1,3 +1,4 @@ +// Package resolvconf provides utility code to query and update DNS configuration in /etc/resolv.conf package resolvconf import ( @@ -38,6 +39,7 @@ var lastModified struct { contents []byte } +// Get returns the contents of /etc/resolv.conf func Get() ([]byte, error) { resolv, err := ioutil.ReadFile("/etc/resolv.conf") if err != nil { @@ -46,7 +48,7 @@ func Get() ([]byte, error) { return resolv, nil } -// Retrieves the host /etc/resolv.conf file, checks against the last hash +// GetIfChanged retrieves the host /etc/resolv.conf file, checks against the last hash // and, if modified since last check, returns the bytes and new hash. // This feature is used by the resolv.conf updater for containers func GetIfChanged() ([]byte, string, error) { @@ -70,7 +72,7 @@ func GetIfChanged() ([]byte, string, error) { return nil, "", nil } -// retrieve the last used contents and hash of the host resolv.conf +// GetLastModified retrieves the last used contents and hash of the host resolv.conf. // Used by containers updating on restart func GetLastModified() ([]byte, string) { lastModified.Lock() @@ -79,14 +81,14 @@ func GetLastModified() ([]byte, string) { return lastModified.contents, lastModified.sha256 } -// FilterResolvDns has two main jobs: +// FilterResolvDns cleans up the config in resolvConf. It has two main jobs: // 1. It looks for localhost (127.*|::1) entries in the provided // resolv.conf, removing local nameserver entries, and, if the resulting // cleaned config has no defined nameservers left, adds default DNS entries // 2. Given the caller provides the enable/disable state of IPv6, the filter // code will remove all IPv6 nameservers if it is not enabled for containers // -// It also returns a boolean to notify the caller if changes were made at all +// It returns a boolean to notify the caller if changes were made at all func FilterResolvDns(resolvConf []byte, ipv6Enabled bool) ([]byte, bool) { changed := false cleanedResolvConf := localhostNSRegexp.ReplaceAll(resolvConf, []byte{}) @@ -126,7 +128,7 @@ func getLines(input []byte, commentMarker []byte) [][]byte { return output } -// returns true if the IP string matches the localhost IP regular expression. +// IsLocalhost returns true if ip matches the localhost IP regular expression. // Used for determining if nameserver settings are being passed which are // localhost addresses func IsLocalhost(ip string) bool { @@ -171,6 +173,9 @@ func GetSearchDomains(resolvConf []byte) []string { return domains } +// Build writes a configuration file to path containing a "nameserver" entry +// for every element in dns, and a "search" entry for every element in +// dnsSearch. func Build(path string, dns, dnsSearch []string) error { content := bytes.NewBuffer(nil) for _, dns := range dns {