From patchwork Tue Nov 6 00:20:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yifeng Sun X-Patchwork-Id: 993484 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="t7Z2Smpt"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42pqvQ3s1xz9s7T for ; Tue, 6 Nov 2018 11:20:33 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 9E8988CC; Tue, 6 Nov 2018 00:20:30 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 31D8B89F for ; Tue, 6 Nov 2018 00:20:30 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id CBF6B7FB for ; Tue, 6 Nov 2018 00:20:29 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id j13-v6so5218626pff.11 for ; Mon, 05 Nov 2018 16:20:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=lUeEuoGHPX/lHeXzfFIMiylCAYbw59Igqh68CEEsb1M=; b=t7Z2SmptaoicG3DgAXCX02fsnhmpxKLo6iDlE2n4BqDr15JFXQ2VnRiFxwQtwAu5gj ZU9wrhuozHyiw1oCaYUJGS74aI6Wtk4NgKZ+Fohwj4UYhPNjzmBDrKOzxuBVlBvAjJvS 4G/nhUCKUhHOGvXYmcmdsSqNdRwmgINwE0v88ORTtZVeKoQWf+OXjlPLMBi9rfgdnyyH ISlvvK5vRLXmOqymeYqn+q6gjUuwtJ8NUJB5MCOgxljUuNbCLyPomtcSRyhYkPEduOm8 gDBlX2VIOvWPv3Iz5vmbFv8B0Oici+Oflids4Z8g0M1FwAAlblzN5wZorU1q450QdkIX h9EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=lUeEuoGHPX/lHeXzfFIMiylCAYbw59Igqh68CEEsb1M=; b=J6vHtoXcSCLbT3d4tDNklfc1uWiLZCJaOWfKzRFcUtQQXpv78YoABB3GsXHOen6PMQ VbSJGAIsYjLdBwn7xCYtkSnDQfPGb0zPzG6Dwv4IFLGlNr0A8fU+I/4EgH7yeDqtQ8UE 8yiay6XLywRx4v0G9xux6zyItCxwmdtn1iv7v14QSKo16yyjBziUYny8MRKuSPchQZ9c r3Td8jZT0UF0ZNo4aVnYvxl1363+DXl/OIx42K8JPRqxTWBobrqPwnwZOf1w6Tdx8L1q g7mPnBrRNOsePGRoUbYs/ch9IUS5QnjIgIH16sieZoabd5jN3LS42c4hTVlJp9VWDECd 6oVw== X-Gm-Message-State: AGRZ1gJGPj9R3u5PSdcG+6QrCUUTi0/l85fNfg5jXN5Lrch5Wcw2YzhC EG28rWpfDYZ3l9QK8O6jP2VVVkGQKoc= X-Google-Smtp-Source: AJdET5d0WewnOTlaQyLm7jv/fXopkX0JIekjCVd5otmTnDqKI6gRvUFf3pZQcAY+gQDlGOsLqlMeOA== X-Received: by 2002:a62:500c:: with SMTP id e12-v6mr24377152pfb.30.1541463629214; Mon, 05 Nov 2018 16:20:29 -0800 (PST) Received: from kern417.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id i88-v6sm40156790pfi.66.2018.11.05.16.20.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Nov 2018 16:20:28 -0800 (PST) From: Yifeng Sun To: dev@openvswitch.org, nusiddiq@redhat.com Date: Mon, 5 Nov 2018 16:20:18 -0800 Message-Id: <1541463618-3832-1-git-send-email-pkusunyifeng@gmail.com> X-Mailer: git-send-email 2.7.4 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] dns-resolve: Stop dns resolving when dns servers are configured. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org 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 Suggested-by: Mark Michelson Signed-off-by: Yifeng Sun --- 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