From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=fail reason="key not found in DNS" header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202312 header.b=bXfmZlEE; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 6FD9A5A0278 for ; Wed, 21 Aug 2024 06:20:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1724214023; bh=//zvq0eb31sdWmJuyoJPSvJ7ANqKWgJFzVycujw+qjw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bXfmZlEE80h8EaxPdeYzS7NNWAhSn9lJUl25JKl20oKobuwnwNvl7V8+fYzmU3NXq INr2JZPycgdhZ12qYuxnd4jX1bZQDOoOnw96RFLmjwOXvcmUutbNvJos2uwlXTJ1af bhSABlESmTyRh6OhnnEvhXD1Ga9MVx++URgmymm5OuRDdt6sMdmph9rahokW5F+cX9 HVj92yFGA4EZ7D5PjsHQ+2rOMWBIzyp+7sZvsuPWmoA/y0ueeDjt4T4r3C3/m6hq7M gvSI14ffgyweUsQ0ZiK0+R6GO2E9HuUaCUYgW53+jXBa9ZqXIWvFPfP12GGcamil04 0yQPV3Jj05h9w== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WpY5z22M5z4x8G; Wed, 21 Aug 2024 14:20:23 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 06/23] conf: More accurately count entries added in get_dns() Date: Wed, 21 Aug 2024 14:20:02 +1000 Message-ID: <20240821042020.718422-7-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240821042020.718422-1-david@gibson.dropbear.id.au> References: <20240821042020.718422-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: ODCB3IAQMZKV625SQWZEVRQ3ASYSGFUS X-Message-ID-Hash: ODCB3IAQMZKV625SQWZEVRQ3ASYSGFUS X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Paul Holzinger , David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: get_dns() counts the number of guest DNS servers it adds, and gives an error if it couldn't add any. However, this count ignores the fact that add_dns[46]() may in some cases *not* add an entry. Use the array indices we're already tracking to get an accurate count. Signed-off-by: David Gibson --- conf.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/conf.c b/conf.c index 2a52bc32..d19013c1 100644 --- a/conf.c +++ b/conf.c @@ -427,7 +427,6 @@ static void get_dns(struct ctx *c) struct lineread resolvconf; struct in6_addr dns6_tmp; struct in_addr dns4_tmp; - unsigned int added = 0; ssize_t line_len; char *line, *end; const char *p; @@ -455,16 +454,12 @@ static void get_dns(struct ctx *c) *end = 0; if (!dns4_set && dns4_idx < ARRAY_SIZE(c->ip4.dns) - 1 - && inet_pton(AF_INET, p + 1, &dns4_tmp)) { + && inet_pton(AF_INET, p + 1, &dns4_tmp)) dns4_idx += add_dns4(c, &dns4_tmp, dns4_idx); - added++; - } if (!dns6_set && dns6_idx < ARRAY_SIZE(c->ip6.dns) - 1 - && inet_pton(AF_INET6, p + 1, &dns6_tmp)) { + && inet_pton(AF_INET6, p + 1, &dns6_tmp)) dns6_idx += add_dns6(c, &dns6_tmp, dns6_idx); - added++; - } } else if (!dnss_set && strstr(line, "search ") == line && s == c->dns_search) { end = strpbrk(line, "\n"); @@ -491,7 +486,7 @@ static void get_dns(struct ctx *c) out: if (!dns_set) { - if (!added) + if (!(dns4_idx + dns6_idx)) warn("Couldn't get any nameserver address"); if (c->no_dhcp_dns) -- 2.46.0