diff --git a/Documentation/intro/install/general.rst b/Documentation/intro/install/general.rst index 537137ef5..71dfeaefc 100644 --- a/Documentation/intro/install/general.rst +++ b/Documentation/intro/install/general.rst @@ -97,6 +97,8 @@ need the following software: you want to enable ovs-vswitchd and other utilities to use DNS names when specifying OpenFlow and OVSDB remotes. If unbound library is already installed, then Open vSwitch will automatically build with support for it. + The environment variable OVS_RESOLV_CONF can be used to specify DNS server + configuration file (the default file on Linux is /etc/resolv.conf). On Linux, you may choose to compile the kernel module that comes with the Open vSwitch distribution or to use the kernel module built into the Linux kernel diff --git a/NEWS b/NEWS index fc8ab05de..8eba5a38f 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,8 @@ Post-v2.10.0 - ovs-vswitchd: * New configuration option "offload-rebalance", that enables dynamic rebalancing of offloaded flows. + - The environment variable OVS_RESOLV_CONF, if set, is now used + as the DNS server configuration file. v2.10.0 - 18 Aug 2018 --------------------- diff --git a/lib/dns-resolve.c b/lib/dns-resolve.c index 7d735749e..e98e65f49 100644 --- a/lib/dns-resolve.c +++ b/lib/dns-resolve.c @@ -82,14 +82,21 @@ dns_resolve_init(bool is_daemon) return; } -#ifdef __linux__ - const char *filename = "/etc/resolv.conf"; + const char *filename = getenv("OVS_RESOLV_CONF"); + if (!filename) { +#ifdef _WIN32 + /* On Windows, NULL means to use the system default nameserver. */ +#else + filename = "/etc/resolv.conf"; +#endif + } struct stat s; - if (!stat(filename, &s) || errno != ENOENT) { + if (!filename || !stat(filename, &s) || errno != ENOENT) { int retval = ub_ctx_resolvconf(ub_ctx__, filename); if (retval != 0) { VLOG_WARN_RL(&rl, "Failed to read %s: %s", - filename, ub_strerror(retval)); + filename ? filename : "system default nameserver", + ub_strerror(retval)); ub_ctx_delete(ub_ctx__); ub_ctx__ = NULL; return; @@ -101,7 +108,6 @@ dns_resolve_init(bool is_daemon) ub_ctx__ = NULL; return; } -#endif /* Handles '/etc/hosts' on Linux and 'WINDIR/etc/hosts' on Windows. */ int retval = ub_ctx_hosts(ub_ctx__, NULL);