[ovs-dev] [PATCH] dns-resolve: Stop dns resolving when dns servers are configured.

Yifeng Sun pkusunyifeng at gmail.com
Tue Nov 6 00:20:18 UTC 2018


DNS resolution should fail if no DNS servers are available. This
patch fixes it and also enables users to use environment variable
OVS_RESOLV_CONF to specify the path for DNS server configuration
file.

Suggested-by: Ben Pfaff <blp at ovn.org>
Suggested-by: Mark Michelson <mmichels at redhat.com>
Signed-off-by: Yifeng Sun <pkusunyifeng at gmail.com>
---
 lib/dns-resolve.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/lib/dns-resolve.c b/lib/dns-resolve.c
index 3c6d70e8fbba..60757cb1eb8a 100644
--- a/lib/dns-resolve.c
+++ b/lib/dns-resolve.c
@@ -83,14 +83,26 @@ dns_resolve_init(bool is_daemon)
     }
 
 #ifdef __linux__
-    const char *filename = "/etc/resolv.conf";
+    const char *filename = getenv("OVS_RESOLV_CONF");
+    if (filename == NULL) {
+        filename = "/etc/resolv.conf";
+    }
     struct stat s;
     if (!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));
+            ub_ctx_delete(ub_ctx__);
+            ub_ctx__ = NULL;
+            return;
         }
+    } else {
+        VLOG_WARN_RL(&rl, "Failed to read %s: %s",
+                     filename, ovs_strerror(errno));
+        ub_ctx_delete(ub_ctx__);
+        ub_ctx__ = NULL;
+        return;
     }
 #endif
 
-- 
2.7.4



More information about the dev mailing list