From 557cca536f82a25f110399fcd2964e07f5d51dcf 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 --- pkg/resolvconf/README.md | 1 + pkg/resolvconf/resolvconf.go | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 pkg/resolvconf/README.md diff --git a/pkg/resolvconf/README.md b/pkg/resolvconf/README.md new file mode 100644 index 0000000000..cdda554ba5 --- /dev/null +++ b/pkg/resolvconf/README.md @@ -0,0 +1 @@ +Package resolvconf provides utility code to query and update DNS configuration in /etc/resolv.conf diff --git a/pkg/resolvconf/resolvconf.go b/pkg/resolvconf/resolvconf.go index 61f92d9ae5..d6f0f7a954 100644 --- a/pkg/resolvconf/resolvconf.go +++ b/pkg/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 {