From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 4046F5A0268 for ; Mon, 27 Feb 2023 14:29:59 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4PQLvg5rCPz4xDt; Tue, 28 Feb 2023 00:29:51 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1677504591; bh=oixcK2BoEltKxx6I1ozsNh48B/Bq404wuNX9D2WF3gk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lSwst8YQvWB/5OuNf3L3HRNn1+WP7ygS9JmnuxI8J4e4rOJEkKUCSElVgpbaqQhCV ymSiud/SbzTOna1U4llgp5cGbATXaeXa/G8gUUJwB4NjQXn1Gae9vKUvFPWUp/p2IP mIIk/44EZw6W/5NihALyVYh0/t6YT9cR5azyhanw= Date: Mon, 27 Feb 2023 23:04:24 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 2/3] conf: Split add_dns{4,6}() out of get_dns() Message-ID: References: <20230223170800.3888094-1-sbrivio@redhat.com> <20230223170800.3888094-3-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="NoyRO0nl7XCuXDSx" Content-Disposition: inline In-Reply-To: <20230223170800.3888094-3-sbrivio@redhat.com> Message-ID-Hash: GUCLPXSHURRKGVMYWBHTOOSTMILH5YOA X-Message-ID-Hash: GUCLPXSHURRKGVMYWBHTOOSTMILH5YOA 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: passt-dev@passt.top, Andrea Bolognani 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: --NoyRO0nl7XCuXDSx Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Feb 23, 2023 at 06:07:59PM +0100, Stefano Brivio wrote: > The logic handling which resolvers we add, and whether to add them, > is getting rather cramped in get_dns(): split it into separate > functions. >=20 > No functional changes intended. >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > conf.c | 86 ++++++++++++++++++++++++++++++++++------------------------ > 1 file changed, 51 insertions(+), 35 deletions(-) >=20 > diff --git a/conf.c b/conf.c > index 4dc0660..ed25e35 100644 > --- a/conf.c > +++ b/conf.c > @@ -382,6 +382,53 @@ bind_fail: > die("Failed to bind any port for '-%c %s', exiting", optname, optarg); > } > =20 > +/** > + * add_dns4() - Possibly add the IPv4 address of a DNS resolver to confi= guration > + * @c: Execution context > + * @addr: Address found in /etc/resolv.conf > + * @conf: Pointer to reference of current entry in array of IPv4 resolve= rs > + */ > +static void add_dns4(struct ctx *c, struct in_addr *addr, struct in_addr= **conf) > +{ > + /* Guest or container can only access local addresses via redirect */ > + if (IN4_IS_ADDR_LOOPBACK(addr)) { > + if (!c->no_map_gw) { > + **conf =3D c->ip4.gw; > + (*conf)++; > + } > + } else { > + **conf =3D *addr; > + (*conf)++; > + } > + > + if (IN4_IS_ADDR_UNSPECIFIED(&c->ip4.dns_host)) > + c->ip4.dns_host =3D *addr; > +} > + > +/** > + * add_dns6() - Possibly add the IPv6 address of a DNS resolver to confi= guration > + * @c: Execution context > + * @addr: Address found in /etc/resolv.conf > + * @conf: Pointer to reference of current entry in array of IPv6 resolve= rs > + */ > +static void add_dns6(struct ctx *c, > + struct in6_addr *addr, struct in6_addr **conf) > +{ > + /* Guest or container can only access local addresses via redirect */ > + if (IN6_IS_ADDR_LOOPBACK(addr)) { > + if (!c->no_map_gw) { > + memcpy(*conf, &c->ip6.gw, sizeof(**conf)); > + (*conf)++; > + } > + } else { > + memcpy(*conf, addr, sizeof(**conf)); > + (*conf)++; > + } > + > + if (IN6_IS_ADDR_UNSPECIFIED(&c->ip6.dns_host)) > + c->ip6.dns_host =3D *addr; > +} > + > /** > * get_dns() - Get nameserver addresses from local /etc/resolv.conf > * @c: Execution context > @@ -420,44 +467,13 @@ static void get_dns(struct ctx *c) > =20 > if (!dns4_set && > dns4 - &c->ip4.dns[0] < ARRAY_SIZE(c->ip4.dns) - 1 > - && inet_pton(AF_INET, p + 1, &dns4_tmp)) { > - /* Guest or container can only access local > - * addresses via local redirect > - */ > - if (IN4_IS_ADDR_LOOPBACK(&dns4_tmp)) { > - if (!c->no_map_gw) { > - *dns4 =3D c->ip4.gw; > - dns4++; > - } > - } else { > - *dns4 =3D dns4_tmp; > - dns4++; > - } > - > - if (IN4_IS_ADDR_UNSPECIFIED(&c->ip4.dns_host)) > - c->ip4.dns_host =3D dns4_tmp; > - } > + && inet_pton(AF_INET, p + 1, &dns4_tmp)) > + add_dns4(c, &dns4_tmp, &dns4); > =20 > if (!dns6_set && > dns6 - &c->ip6.dns[0] < ARRAY_SIZE(c->ip6.dns) - 1 > - && inet_pton(AF_INET6, p + 1, &dns6_tmp)) { > - /* Guest or container can only access local > - * addresses via local redirect > - */ > - if (IN6_IS_ADDR_LOOPBACK(&dns6_tmp)) { > - if (!c->no_map_gw) { > - memcpy(dns6, &c->ip6.gw, > - sizeof(*dns6)); > - dns6++; > - } > - } else { > - memcpy(dns6, &dns6_tmp, sizeof(*dns6)); > - dns6++; > - } > - > - if (IN6_IS_ADDR_UNSPECIFIED(&c->ip6.dns_host)) > - c->ip6.dns_host =3D dns6_tmp; > - } > + && inet_pton(AF_INET6, p + 1, &dns6_tmp)) > + add_dns6(c, &dns6_tmp, &dns6); > } else if (!dnss_set && strstr(line, "search ") =3D=3D line && > s =3D=3D c->dns_search) { > end =3D strpbrk(line, "\n"); --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --NoyRO0nl7XCuXDSx Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmP8nEIACgkQzQJF27ox 2GfTQw//Vo3N+5NlnL1zjR+YQhX9pqba+8QvhqsWLCxDcWQuT5T/ZtMXGDFelLtY oXpzuxW+E+hZS6qHegbyVRyr1Pf0mGV8Pq+0izIzZkbWfDYDZA1li0qPhwtHrK2y BHfVRv5qKdQp0dE/28xDyySbAKlpoRhN2fk9Nf88e/JdA0aWF+jdh9jJdNG5097s x7KBGofxDN6torR9SEPOAPLYyU7ZtQ0j4hGgvlKRFMtCvGOroX3YdYDzHxHqCm6k 5rv8Uojx0/qCDHd5yhpY0Yvco7nDmKyxAZfwwLovRppSXSyDHRhmWLe2TgVoRfbg lZORtlNj2SSU9cWGEnx40TdVxK1vzHdBahlFaxKqVb1CzryA12wvjbQTxuug+S8X UDOf+Yvc96EeWSoEMRVu6VvUflxOuIpglyJ5ak5UP17/0sOSV7wmYBrwHfkFHhwW hUhWrpaJ7eh0b8psR6vZhgk50BdWHMJT13kLfC2Q8mHgnvNVsectCcNU6nzYWuhY 4xQSF28hRX9uPEUH0dyPA4kRCnxgIbKkkf+sbQpr4E4AKeF1oB/IB71Knek8Y1a2 PNANyvwIBCYrL1XHnsTDK4ArU309WhHM9iJASOUqJcXWdM2GVgRadrkmZlrntqhh I5xM6Al8H0GS+1dp1tuVxOLZDEHItF2MoEOg+AAWf7kJjsg6yY4= =wtWY -----END PGP SIGNATURE----- --NoyRO0nl7XCuXDSx--