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=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202512 header.b=RuT9gEJ7; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id EEA855A0624 for ; Fri, 06 Feb 2026 09:47:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202512; t=1770367630; bh=t6sHDGSxJIjhRDbVr/OKs5diL+6BwrQ/D7l5BBBG7ck=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RuT9gEJ7PpKIvXwuCVnd+iTlls5dcqonjB2Z9xeCUgWw/p8SOxemjN7pSp2kuMa+u NI7WlBnCg4uu4nQ/xV/IvIPdHch57RSRL0T+UTVHWAyhoLv72nXFXH6mOU+9o8kTU8 CZb0sBACq2fcBQ17uOjqpkyDxyPmOaZ1yBIwSoIGfNva/V4Ma3e3tcqLxGOzx4izkO eMxpMj2ehmfpkZEkf/D7lQe8VxqMQ+DAWRqeFaMhUhUqXR+yyOKAj6iiMQ7ukK+goE GjV4YIV74ppy9G1JtRi2XCtJDJ1XE6tI7LQYUZKHv7tPMGYWBAxd9ckY8uTxc+yDi8 b35+vJ6VzjAqA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4f6nlL2gT7z4w8w; Fri, 06 Feb 2026 19:47:10 +1100 (AEDT) Date: Fri, 6 Feb 2026 19:40:02 +1100 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v3 06/11] pasta: Extract pasta_ns_conf_ip4/6() to reduce nesting Message-ID: References: <20260130214447.2540791-1-jmaloy@redhat.com> <20260130214447.2540791-7-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="TRVQiJX5VE4cg0yC" Content-Disposition: inline In-Reply-To: <20260130214447.2540791-7-jmaloy@redhat.com> Message-ID-Hash: SKIHTE4LOZH6EBTCNV5W5WISPNF6W4K7 X-Message-ID-Hash: SKIHTE4LOZH6EBTCNV5W5WISPNF6W4K7 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: sbrivio@redhat.com, dgibson@redhat.com, passt-dev@passt.top 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: --TRVQiJX5VE4cg0yC Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jan 30, 2026 at 04:44:42PM -0500, Jon Maloy wrote: > Extract the IPv4 and IPv6 namespace configuration code from > pasta_ns_conf() into separate static functions. This reduces > indentation depth and prepares for adding multi-address support. >=20 > No functional change. This seems fine in isolation, but I think it moves in the wrong direction in context. With the unified address array, we want to step through and set all the addresses in a single pass - this kind of works against that. >=20 > Signed-off-by: Jon Maloy > --- > pasta.c | 182 ++++++++++++++++++++++++++++++-------------------------- > 1 file changed, 96 insertions(+), 86 deletions(-) >=20 > diff --git a/pasta.c b/pasta.c > index 08f35f4..de0ba14 100644 > --- a/pasta.c > +++ b/pasta.c > @@ -303,6 +303,98 @@ void pasta_start_ns(struct ctx *c, uid_t uid, gid_t = gid, > die_perror("Failed to join network namespace"); > } > =20 > +/** > + * pasta_ns_conf_ip4() - Configure IPv4 in namespace > + * @c: Execution context > + */ > +static void pasta_ns_conf_ip4(struct ctx *c) > +{ > + int rc =3D 0; > + > + if (c->ip4.no_copy_addrs) { > + struct inany_addr_entry *e =3D first_v4(c); > + > + rc =3D nl_addr_set(nl_sock_ns, c->pasta_ifi, AF_INET, > + inany_v4(&e->addr), e->prefix_len - 96); > + } else { > + rc =3D nl_addr_dup(nl_sock, c->ifi4, > + nl_sock_ns, c->pasta_ifi, AF_INET); > + } > + > + if (rc < 0) { > + die("Couldn't set IPv4 address(es) in namespace: %s", > + strerror_(-rc)); > + } > + > + if (c->ip4.no_copy_routes) { > + rc =3D nl_route_set_def(nl_sock_ns, c->pasta_ifi, > + AF_INET, &c->ip4.guest_gw); > + } else { > + rc =3D nl_route_dup(nl_sock, c->ifi4, nl_sock_ns, > + c->pasta_ifi, AF_INET); > + } > + > + if (rc < 0) { > + die("Couldn't set IPv4 route(s) in guest: %s", > + strerror_(-rc)); > + } > +} > + > +/** > + * pasta_ns_conf_ip6() - Configure IPv6 in namespace > + * @c: Execution context > + */ > +static void pasta_ns_conf_ip6(struct ctx *c) > +{ > + struct inany_addr_entry *e; > + int rc =3D 0; > + > + rc =3D nl_addr_get_ll(nl_sock_ns, c->pasta_ifi, &c->ip6.addr_ll_seen); > + if (rc < 0) { > + warn("Can't get LL address from namespace: %s", > + strerror_(-rc)); > + } > + > + rc =3D nl_addr_set_ll_nodad(nl_sock_ns, c->pasta_ifi); > + if (rc < 0) { > + warn("Can't set nodad for LL in namespace: %s", > + strerror_(-rc)); > + } > + > + /* We dodged DAD: re-enable neighbour solicitations */ > + nl_link_set_flags(nl_sock_ns, c->pasta_ifi, 0, IFF_NOARP); > + > + if (c->ip6.no_copy_addrs) { > + e =3D first_v6(c); > + > + if (e && !IN6_IS_ADDR_UNSPECIFIED(&e->addr.a6)) { > + rc =3D nl_addr_set(nl_sock_ns, c->pasta_ifi, > + AF_INET6, &e->addr.a6, 64); > + } > + } else { > + rc =3D nl_addr_dup(nl_sock, c->ifi6, > + nl_sock_ns, c->pasta_ifi, AF_INET6); > + } > + > + if (rc < 0) { > + die("Couldn't set IPv6 address(es) in namespace: %s", > + strerror_(-rc)); > + } > + > + if (c->ip6.no_copy_routes) { > + rc =3D nl_route_set_def(nl_sock_ns, c->pasta_ifi, > + AF_INET6, &c->ip6.guest_gw); > + } else { > + rc =3D nl_route_dup(nl_sock, c->ifi6, > + nl_sock_ns, c->pasta_ifi, AF_INET6); > + } > + > + if (rc < 0) { > + die("Couldn't set IPv6 route(s) in guest: %s", > + strerror_(-rc)); > + } > +} > + > /** > * pasta_ns_conf() - Set up loopback and tap interfaces in namespace as = needed > * @c: Execution context > @@ -336,93 +428,11 @@ void pasta_ns_conf(struct ctx *c) > =20 > nl_link_set_flags(nl_sock_ns, c->pasta_ifi, flags, flags); > =20 > - if (c->ifi4) { > - if (c->ip4.no_copy_addrs) { > - struct inany_addr_entry *e =3D first_v4(c); > - > - rc =3D nl_addr_set(nl_sock_ns, c->pasta_ifi, > - AF_INET, > - inany_v4(&e->addr), > - e->prefix_len); > - } else { > - rc =3D nl_addr_dup(nl_sock, c->ifi4, > - nl_sock_ns, c->pasta_ifi, > - AF_INET); > - } > - > - if (rc < 0) { > - die("Couldn't set IPv4 address(es) in namespace: %s", > - strerror_(-rc)); > - } > - > - if (c->ip4.no_copy_routes) { > - rc =3D nl_route_set_def(nl_sock_ns, c->pasta_ifi, > - AF_INET, > - &c->ip4.guest_gw); > - } else { > - rc =3D nl_route_dup(nl_sock, c->ifi4, nl_sock_ns, > - c->pasta_ifi, AF_INET); > - } > - > - if (rc < 0) { > - die("Couldn't set IPv4 route(s) in guest: %s", > - strerror_(-rc)); > - } > - } > + if (c->ifi4) > + pasta_ns_conf_ip4(c); > =20 > - if (c->ifi6) { > - rc =3D nl_addr_get_ll(nl_sock_ns, c->pasta_ifi, > - &c->ip6.addr_ll_seen); > - if (rc < 0) { > - warn("Can't get LL address from namespace: %s", > - strerror_(-rc)); > - } > - > - rc =3D nl_addr_set_ll_nodad(nl_sock_ns, c->pasta_ifi); > - if (rc < 0) { > - warn("Can't set nodad for LL in namespace: %s", > - strerror_(-rc)); > - } > - > - /* We dodged DAD: re-enable neighbour solicitations */ > - nl_link_set_flags(nl_sock_ns, c->pasta_ifi, > - 0, IFF_NOARP); > - > - if (c->ip6.no_copy_addrs) { > - struct inany_addr_entry *e =3D first_v6(c); > - > - if (e && !IN6_IS_ADDR_UNSPECIFIED(&e->addr.a6)) { > - rc =3D nl_addr_set(nl_sock_ns, > - c->pasta_ifi, > - AF_INET6, > - &e->addr.a6, 64); > - } > - } else { > - rc =3D nl_addr_dup(nl_sock, c->ifi6, > - nl_sock_ns, c->pasta_ifi, > - AF_INET6); > - } > - > - if (rc < 0) { > - die("Couldn't set IPv6 address(es) in namespace: %s", > - strerror_(-rc)); > - } > - > - if (c->ip6.no_copy_routes) { > - rc =3D nl_route_set_def(nl_sock_ns, c->pasta_ifi, > - AF_INET6, > - &c->ip6.guest_gw); > - } else { > - rc =3D nl_route_dup(nl_sock, c->ifi6, > - nl_sock_ns, c->pasta_ifi, > - AF_INET6); > - } > - > - if (rc < 0) { > - die("Couldn't set IPv6 route(s) in guest: %s", > - strerror_(-rc)); > - } > - } > + if (c->ifi6) > + pasta_ns_conf_ip6(c); > } > =20 > proto_update_l2_buf(c->guest_mac); > --=20 > 2.52.0 >=20 --=20 David Gibson (he or they) | 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 --TRVQiJX5VE4cg0yC Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmmFqNYACgkQzQJF27ox 2GfUdRAAguXRVB420GX98LRbuVstIttvLyl6kJ4kmoQgRwB85XAJedBY3tZRGVPW bgeXQXI1Rdr50ggFs3wd4at5VVHvqlUxtvstxQdNV78axCYHALo5vEPICuEIAiuO 1sNlrc9rdMU7yPdFOvAJA3Qojc+09+6Qt62/yRjQYkuhUAxVv87yvxZpItmoFLlI vrISsa9HgoZSJMjjvjEtA4ewHaf52OUkmearl4lEow6JSqDo+chExCz63EtVJSrC mpv1x0Ao5QhvFgbFl3wJID7zxnj6NsI74R0sM0I8cQG53czCUgWfZVz/W3qDmbxw 0EybwyVwqDGg+T+ZYrJ7Q38Hfk4nBgwOlLF3wWe8R/ZoLbZ4AZBDITxitdu8M+cN hZw1x4wQ36rAoLOxT0OZSA1t1l7ZVwRacaFTvpMgA8WxQCG9Wuefbg47yarzqRkW hO0oUBdEyEtYpK3AxcqF1nkEN+Cj0TlL7l5iOc0Jc/MjiuaGuVXguO/BHFwy4qBw 7zpk4isRKhIoAUjDJ9K4g6ZcmdPOheabRhXv0MFPJY/zrcAhJ5FOfmqMhMCIqXZQ sIOYBHWhPferh2E8UvIgAV/f3wxVAK7pPRsXLhZhC9G+/64fvL8zb7fG8Lz0pq9E 9aj0pUnxU1+gBLzq0jRLpBS4QEv8QNE8JkQxRX86Pz9on8MxBBs= =1tS9 -----END PGP SIGNATURE----- --TRVQiJX5VE4cg0yC--