1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix #11589 by adding README and comments to exported functions

Signed-off-by: Arthur Barr <arthur.barr@uk.ibm.com>
This commit is contained in:
Arthur Barr 2015-03-24 07:12:59 +00:00
parent 4b4bdb5be5
commit 557cca536f
2 changed files with 11 additions and 5 deletions

1
pkg/resolvconf/README.md Normal file
View file

@ -0,0 +1 @@
Package resolvconf provides utility code to query and update DNS configuration in /etc/resolv.conf

View file

@ -1,3 +1,4 @@
// Package resolvconf provides utility code to query and update DNS configuration in /etc/resolv.conf
package resolvconf package resolvconf
import ( import (
@ -38,6 +39,7 @@ var lastModified struct {
contents []byte contents []byte
} }
// Get returns the contents of /etc/resolv.conf
func Get() ([]byte, error) { func Get() ([]byte, error) {
resolv, err := ioutil.ReadFile("/etc/resolv.conf") resolv, err := ioutil.ReadFile("/etc/resolv.conf")
if err != nil { if err != nil {
@ -46,7 +48,7 @@ func Get() ([]byte, error) {
return resolv, nil 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. // and, if modified since last check, returns the bytes and new hash.
// This feature is used by the resolv.conf updater for containers // This feature is used by the resolv.conf updater for containers
func GetIfChanged() ([]byte, string, error) { func GetIfChanged() ([]byte, string, error) {
@ -70,7 +72,7 @@ func GetIfChanged() ([]byte, string, error) {
return nil, "", nil 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 // Used by containers updating on restart
func GetLastModified() ([]byte, string) { func GetLastModified() ([]byte, string) {
lastModified.Lock() lastModified.Lock()
@ -79,14 +81,14 @@ func GetLastModified() ([]byte, string) {
return lastModified.contents, lastModified.sha256 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 // 1. It looks for localhost (127.*|::1) entries in the provided
// resolv.conf, removing local nameserver entries, and, if the resulting // resolv.conf, removing local nameserver entries, and, if the resulting
// cleaned config has no defined nameservers left, adds default DNS entries // cleaned config has no defined nameservers left, adds default DNS entries
// 2. Given the caller provides the enable/disable state of IPv6, the filter // 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 // 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) { func FilterResolvDns(resolvConf []byte, ipv6Enabled bool) ([]byte, bool) {
changed := false changed := false
cleanedResolvConf := localhostNSRegexp.ReplaceAll(resolvConf, []byte{}) cleanedResolvConf := localhostNSRegexp.ReplaceAll(resolvConf, []byte{})
@ -126,7 +128,7 @@ func getLines(input []byte, commentMarker []byte) [][]byte {
return output 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 // Used for determining if nameserver settings are being passed which are
// localhost addresses // localhost addresses
func IsLocalhost(ip string) bool { func IsLocalhost(ip string) bool {
@ -171,6 +173,9 @@ func GetSearchDomains(resolvConf []byte) []string {
return domains 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 { func Build(path string, dns, dnsSearch []string) error {
content := bytes.NewBuffer(nil) content := bytes.NewBuffer(nil)
for _, dns := range dns { for _, dns := range dns {