aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/docker/libnetwork/resolvconf/resolvconf.go
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2019-08-01 03:41:27 -0400
committerGitHub <noreply@github.com>2019-08-01 03:41:27 -0400
commit39de184b8bfb14954f77190f0e6127c1ddc363c0 (patch)
treeeb76e980bc7d8c7b64e93a2cf6293c0e073db860 /vendor/github.com/docker/libnetwork/resolvconf/resolvconf.go
parenta622f8d345b1853401de2e533e9fbf14ef169fa2 (diff)
parent141c7a5165261b0a75254107b63b2dac22203ebf (diff)
downloadpodman-39de184b8bfb14954f77190f0e6127c1ddc363c0.tar.gz
podman-39de184b8bfb14954f77190f0e6127c1ddc363c0.tar.bz2
podman-39de184b8bfb14954f77190f0e6127c1ddc363c0.zip
Merge pull request #3573 from rhatdan/vendor
Vendor in latest buildah code
Diffstat (limited to 'vendor/github.com/docker/libnetwork/resolvconf/resolvconf.go')
-rw-r--r--vendor/github.com/docker/libnetwork/resolvconf/resolvconf.go51
1 files changed, 41 insertions, 10 deletions
diff --git a/vendor/github.com/docker/libnetwork/resolvconf/resolvconf.go b/vendor/github.com/docker/libnetwork/resolvconf/resolvconf.go
index 5cb251b13..946bb8712 100644
--- a/vendor/github.com/docker/libnetwork/resolvconf/resolvconf.go
+++ b/vendor/github.com/docker/libnetwork/resolvconf/resolvconf.go
@@ -14,6 +14,45 @@ import (
"github.com/sirupsen/logrus"
)
+const (
+ // defaultPath is the default path to the resolv.conf that contains information to resolve DNS. See Path().
+ defaultPath = "/etc/resolv.conf"
+ // alternatePath is a path different from defaultPath, that may be used to resolve DNS. See Path().
+ alternatePath = "/run/systemd/resolve/resolv.conf"
+)
+
+var (
+ detectSystemdResolvConfOnce sync.Once
+ pathAfterSystemdDetection = defaultPath
+)
+
+// Path returns the path to the resolv.conf file that libnetwork should use.
+//
+// When /etc/resolv.conf contains 127.0.0.53 as the only nameserver, then
+// it is assumed systemd-resolved manages DNS. Because inside the container 127.0.0.53
+// is not a valid DNS server, Path() returns /run/systemd/resolve/resolv.conf
+// which is the resolv.conf that systemd-resolved generates and manages.
+// Otherwise Path() returns /etc/resolv.conf.
+//
+// Errors are silenced as they will inevitably resurface at future open/read calls.
+//
+// More information at https://www.freedesktop.org/software/systemd/man/systemd-resolved.service.html#/etc/resolv.conf
+func Path() string {
+ detectSystemdResolvConfOnce.Do(func() {
+ candidateResolvConf, err := ioutil.ReadFile(defaultPath)
+ if err != nil {
+ // silencing error as it will resurface at next calls trying to read defaultPath
+ return
+ }
+ ns := GetNameservers(candidateResolvConf, types.IP)
+ if len(ns) == 1 && ns[0] == "127.0.0.53" {
+ pathAfterSystemdDetection = alternatePath
+ logrus.Infof("detected 127.0.0.53 nameserver, assuming systemd-resolved, so using resolv.conf: %s", alternatePath)
+ }
+ })
+ return pathAfterSystemdDetection
+}
+
var (
// Note: the default IPv4 & IPv6 resolvers are set to Google's Public DNS
defaultIPv4Dns = []string{"nameserver 8.8.8.8", "nameserver 8.8.4.4"}
@@ -50,15 +89,7 @@ type File struct {
// Get returns the contents of /etc/resolv.conf and its hash
func Get() (*File, error) {
- resolv, err := ioutil.ReadFile("/etc/resolv.conf")
- if err != nil {
- return nil, err
- }
- hash, err := ioutils.HashData(bytes.NewReader(resolv))
- if err != nil {
- return nil, err
- }
- return &File{Content: resolv, Hash: hash}, nil
+ return GetSpecific(Path())
}
// GetSpecific returns the contents of the user specified resolv.conf file and its hash
@@ -81,7 +112,7 @@ func GetIfChanged() (*File, error) {
lastModified.Lock()
defer lastModified.Unlock()
- resolv, err := ioutil.ReadFile("/etc/resolv.conf")
+ resolv, err := ioutil.ReadFile(Path())
if err != nil {
return nil, err
}