From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bvS/V2CD; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 15E1B5A0274 for ; Tue, 17 Feb 2026 23:18:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1771366709; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AuXLU6TdrEOFHVot8sIwE8EJPg5xn1Mb6Fjnxi5jyFw=; b=bvS/V2CDFerTNE2Hl9qJ1oC9aypB1GuZsb8XUZqy6lusssLV8KhpqJD6QYMDtfx+zmWXND elJaOxrCl5qlnsQA3gDsz0bmp1fwqT11a686ynRC9Y52EQ9teIQnqEu9JmFByiQKAfu1TJ KFIOlf9cUmN5xHWL6rKn57tsIOZtYWI= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-656-a1z0Wl70N9OkEu1Dm8ecMg-1; Tue, 17 Feb 2026 17:18:26 -0500 X-MC-Unique: a1z0Wl70N9OkEu1Dm8ecMg-1 X-Mimecast-MFC-AGG-ID: a1z0Wl70N9OkEu1Dm8ecMg_1771366705 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A0B58195605A; Tue, 17 Feb 2026 22:18:25 +0000 (UTC) Received: from jmaloy-thinkpadp16vgen1.rmtcaqc.csb (unknown [10.22.80.48]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A41EF1800348; Tue, 17 Feb 2026 22:18:23 +0000 (UTC) From: Jon Maloy To: sbrivio@redhat.com, dgibson@redhat.com, david@gibson.dropbear.id.au, jmaloy@redhat.com, passt-dev@passt.top Subject: [PATCH v4 05/12] pasta: Extract pasta_ns_conf_ip4/6() to reduce nesting Date: Tue, 17 Feb 2026 17:18:07 -0500 Message-ID: <20260217221814.4053583-6-jmaloy@redhat.com> In-Reply-To: <20260217221814.4053583-1-jmaloy@redhat.com> References: <20260217221814.4053583-1-jmaloy@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: TrGyImoU2CXx3-jUB_DZvEIefQcmvUU-DA_T3WD8IS8_1771366705 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: ADNJOSSW2BXF2LT557PEOAERKNAYUPZW X-Message-ID-Hash: ADNJOSSW2BXF2LT557PEOAERKNAYUPZW X-MailFrom: jmaloy@redhat.com 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 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: 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. No functional change. Signed-off-by: Jon Maloy --- v4: - Leaving them unchanged for now, despite David's comment. I tried, and the result wasn't pretty. I will try to revisit this at a later moment. --- pasta.c | 193 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 107 insertions(+), 86 deletions(-) diff --git a/pasta.c b/pasta.c index 4728445..59f5ba8 100644 --- a/pasta.c +++ b/pasta.c @@ -303,6 +303,109 @@ void pasta_start_ns(struct ctx *c, uid_t uid, gid_t gid, die_perror("Failed to join network namespace"); } +/** + * pasta_ns_conf_ip4() - Configure IPv4 in namespace + * @c: Execution context + */ +static void pasta_ns_conf_ip4(struct ctx *c) +{ + int rc = 0; + + if (c->ip4.no_copy_addrs) { + const struct inany_addr_entry *e = first_v4(c); + + if (e) + rc = nl_addr_set(nl_sock_ns, + c->pasta_ifi, AF_INET, + inany_v4(&e->addr), + inany_prefix4(e)); + } else { + rc = 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 = nl_route_set_def(nl_sock_ns, c->pasta_ifi, + AF_INET, + &c->ip4.guest_gw); + } else { + rc = 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) +{ + int rc = 0; + + rc = 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 = 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) { + const struct inany_addr_entry *e = first_v6(c); + + if (e) + rc = nl_addr_set(nl_sock_ns, + c->pasta_ifi, + AF_INET6, + &e->addr.a6, + e->prefix_len); + } else { + rc = 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 = nl_route_set_def(nl_sock_ns, c->pasta_ifi, + AF_INET6, + &c->ip6.guest_gw); + } else { + rc = 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 @@ -327,7 +430,6 @@ void pasta_ns_conf(struct ctx *c) if (c->pasta_conf_ns) { unsigned int flags = IFF_UP; - struct inany_addr_entry *e; if (c->mtu) nl_link_set_mtu(nl_sock_ns, c->pasta_ifi, c->mtu); @@ -337,92 +439,11 @@ void pasta_ns_conf(struct ctx *c) nl_link_set_flags(nl_sock_ns, c->pasta_ifi, flags, flags); - if (c->ifi4) { - if (c->ip4.no_copy_addrs) { - e = first_v4(c); - if (e) - rc = nl_addr_set(nl_sock_ns, - c->pasta_ifi, AF_INET, - inany_v4(&e->addr), - e->prefix_len - 96); - } else { - rc = 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 = nl_route_set_def(nl_sock_ns, c->pasta_ifi, - AF_INET, - &c->ip4.guest_gw); - } else { - rc = 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); - if (c->ifi6) { - rc = 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 = 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 = first_v6(c); - if (e) - rc = nl_addr_set(nl_sock_ns, - c->pasta_ifi, - AF_INET6, - &e->addr.a6, - e->prefix_len); - } else { - rc = 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 = nl_route_set_def(nl_sock_ns, c->pasta_ifi, - AF_INET6, - &c->ip6.guest_gw); - } else { - rc = 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); } proto_update_l2_buf(c->guest_mac); -- 2.52.0