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=Pb/MQdcG; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 8E9A05A0778 for ; Mon, 15 Dec 2025 02:55:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1765763702; 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=oiqNq318YhfQfBvfQxA1BwFfuOnFhigFrWbj5SiEUY0=; b=Pb/MQdcG1P7Jb9nA49p8X6XjcGgxYwNEzfLcEnVq7Hy3yebhmjJEnE/KG4hipkLp4OmcJ0 oxFEIfnRIHHdHAjmO7z8b5Bix3NZj2qYOdR7b5eWfcaiJzaz4EK3ezJ0Djnzn6Q3ScELXu EjNs38XzJzpIfEjdmvmmffI3oXd7nQ4= Received: from mx-prod-mc-01.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-671-YcGUvjIXNKaTuRh0h6Vwpw-1; Sun, 14 Dec 2025 20:54:59 -0500 X-MC-Unique: YcGUvjIXNKaTuRh0h6Vwpw-1 X-Mimecast-MFC-AGG-ID: YcGUvjIXNKaTuRh0h6Vwpw_1765763698 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5A16D19560A5; Mon, 15 Dec 2025 01:54:58 +0000 (UTC) Received: from jmaloy-thinkpadp16vgen1.rmtcaqc.csb (unknown [10.22.88.123]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7B63A3000218; Mon, 15 Dec 2025 01:54:57 +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: [RFC 12/12] netlink: Rename tap interface when late binding discovers template name Date: Sun, 14 Dec 2025 20:54:41 -0500 Message-ID: <20251215015441.887736-13-jmaloy@redhat.com> In-Reply-To: <20251215015441.887736-1-jmaloy@redhat.com> References: <20251215015441.887736-1-jmaloy@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ErFVllP-12VlnMwcpND2JtyJeZbN0ooJctMrZ9OcM5A_1765763698 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: B37YXIJYD6R6PATWXWNA6ZK65XKLWQVX X-Message-ID-Hash: B37YXIJYD6R6PATWXWNA6ZK65XKLWQVX 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: When pasta starts without a template interface (-I), it creates the tap device with the default name (tap0). Later, when late binding discovers the actual template interface, we now rename the device to match it. This ensures the namespace interface has the expected name, matching the discovered host interface. Key changes: - Add nl_link_rename() function to rename network interfaces - When late binding triggers with the default TAP name, bring it down, rename it to match the discovered interface, then bring it up Signed-off-by: Jon Maloy --- netlink.c | 37 +++++++++++++++++++++++++++++++++++++ tap.c | 27 +++++++++++++++++++++++++++ tap.h | 1 + 3 files changed, 65 insertions(+) diff --git a/netlink.c b/netlink.c index de04fb7..71089ab 100644 --- a/netlink.c +++ b/netlink.c @@ -44,6 +44,8 @@ /* Default namespace interface name from conf.c */ extern const char *pasta_default_ifn; +static int nl_link_rename(int s, unsigned int ifi, const char *name); + /* Same as RTA_NEXT() but for nexthops: RTNH_NEXT() doesn't take 'attrlen' */ #define RTNH_NEXT_AND_DEC(rtnh, attrlen) \ ((attrlen) -= RTNH_ALIGN((rtnh)->rtnh_len), RTNH_NEXT(rtnh)) @@ -315,6 +317,14 @@ static void nl_linkaddr_host_msg_read(struct ctx *c, const struct nlmsghdr *nh) } late_binding = true; + /* Rename interface if it is still using default name */ + if (is_default && strcmp(ifname, pasta_default_ifn)) { + nl_link_set_flags(nl_sock_ns, c->pasta_ifi, + 0, IFF_UP); + nl_link_rename(nl_sock_ns, c->pasta_ifi, ifname); + debug("Renamed tap: %s -> %s", + pasta_default_ifn, ifname); + } if (is_default) snprintf(c->pasta_ifn, sizeof(c->pasta_ifn), "%s", ifname); @@ -1943,6 +1953,33 @@ int nl_link_set_flags(int s, unsigned int ifi, return nl_do(s, &req, RTM_NEWLINK, 0, sizeof(req)); } +/** + * nl_link_rename() - Rename a network interface + * @s: Netlink socket + * @ifi: Interface index + * @name: New interface name + * + * Return: 0 on success, negative error code on failure + */ +static int nl_link_rename(int s, unsigned int ifi, const char *name) +{ + struct req_t { + struct nlmsghdr nlh; + struct ifinfomsg ifm; + struct rtattr rta; + char name[IFNAMSIZ]; + } req = { + .ifm.ifi_family = AF_UNSPEC, + .ifm.ifi_index = ifi, + .rta.rta_type = IFLA_IFNAME, + .rta.rta_len = RTA_LENGTH(IFNAMSIZ), + }; + + snprintf(req.name, IFNAMSIZ, "%s", name); + + return nl_do(s, &req, RTM_NEWLINK, 0, sizeof(req)); +} + /** * nl_neigh_msg_read() - Interpret a neighbour state message from netlink * @c: Execution context diff --git a/tap.c b/tap.c index a2a4459..cd59160 100644 --- a/tap.c +++ b/tap.c @@ -1502,6 +1502,33 @@ static void tap_sock_tun_init(struct ctx *c) tap_start_connection(c); } +/** + * tap_backend_init_late() - Create tap device for late binding + * @c: Execution context + * + * Called when late binding discovers the template interface name. + * Creates the TAP device with the discovered name. + */ +void tap_backend_init_late(struct ctx *c) +{ + if (c->mode != MODE_PASTA || c->fd_tap != -1) + return; + + if (!*c->pasta_ifn) { + warn("%s called with empty pasta_ifn", __func__); + return; + } + + NS_CALL(tap_ns_tun, c); + if (c->fd_tap == -1) { + err("Failed to set up tap device in namespace"); + return; + } + + tap_start_connection(c); + info("Created tap device %s for late binding", c->pasta_ifn); +} + /** * tap_sock_update_pool() - Set the buffer base and size for the pool of packets * @base: Buffer base diff --git a/tap.h b/tap.h index ee22a9d..b41eae9 100644 --- a/tap.h +++ b/tap.h @@ -118,6 +118,7 @@ void tap_handler_passt(struct ctx *c, uint32_t events, int tap_sock_unix_open(char *sock_path); void tap_sock_reset(struct ctx *c); void tap_backend_init(struct ctx *c); +void tap_backend_init_late(struct ctx *c); void tap_flush_pools(void); void tap_handler(struct ctx *c, const struct timespec *now); void tap_add_packet(struct ctx *c, struct iov_tail *data, -- 2.51.1