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=g+vWwjCp; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 887455A065C for ; Thu, 18 Dec 2025 06:02:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202512; t=1766034152; bh=wZjjWLkrw+mu4TvK4OTzXaPoLEJ2CWRA9fYCVxYELRM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=g+vWwjCp70jfju0hY8yX0OxCu6tEQo3bvBbkCcmk8mkeDb/npMBPNPQWQvlEqwM1Q +kSB7aFVU2NfLeFBoZu3TdfBTUKiS5AKjNgxRC4KQEVudtJ0MJoTQPgf/5x1hgqfSo kL8ehACl8KpHUgoZSRE1ij7DSRe8PbDYZAgyz4F82QTMZ+yNJWjhnBsOtn/GfuLBfu e6LLpHzOUFmHWFVhROAarbgVrTRpdFu22Z3rkTtGBygeRxRnGvorlf++wMngluHU0t 1Il4I8c2opG+aBji95KAZ/GVaFJ1OaFE0NivOeqJ0/v2ABvOQG/Mk2abMccOwiPUZI UIMaGOnw5rD2g== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4dWz7D6nB3z4wH2; Thu, 18 Dec 2025 16:02:32 +1100 (AEDT) Date: Thu, 18 Dec 2025 16:02:27 +1100 From: David Gibson To: Jon Maloy Subject: Re: [RFC 12/12] netlink: Rename tap interface when late binding discovers template name Message-ID: References: <20251215015441.887736-1-jmaloy@redhat.com> <20251215015441.887736-13-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="rq8uoau5mF7qTegq" Content-Disposition: inline In-Reply-To: <20251215015441.887736-13-jmaloy@redhat.com> Message-ID-Hash: UMT72ICL7ULDLFVQ3Q2H2RTXWNDDP7C5 X-Message-ID-Hash: UMT72ICL7ULDLFVQ3Q2H2RTXWNDDP7C5 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: --rq8uoau5mF7qTegq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Dec 14, 2025 at 08:54:41PM -0500, Jon Maloy wrote: > When pasta starts without a template interface (-I), it creates the > tap Template interface is -i not -I. -I is the guest interface name - that should take precedence if specified, regardless of late binding or not. > device with the default name (tap0). Later, when late binding discovers > the actual template interface, we now rename the device to match it. >=20 > This ensures the namespace interface has the expected name, matching > the discovered host interface. >=20 > 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 >=20 > Signed-off-by: Jon Maloy > --- > netlink.c | 37 +++++++++++++++++++++++++++++++++++++ > tap.c | 27 +++++++++++++++++++++++++++ > tap.h | 1 + > 3 files changed, 65 insertions(+) >=20 > 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; > =20 > +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 'attrle= n' */ > #define RTNH_NEXT_AND_DEC(rtnh, attrlen) \ > ((attrlen) -=3D 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 =3D true; > =20 > + /* 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)); > } > =20 > +/** > + * 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 =3D { > + .ifm.ifi_family =3D AF_UNSPEC, > + .ifm.ifi_index =3D ifi, > + .rta.rta_type =3D IFLA_IFNAME, > + .rta.rta_len =3D 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); > } > =20 > +/** > + * 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) Uh... why would you need a second tap device? Also this function doesn't seem to be called. > +{ > + if (c->mode !=3D MODE_PASTA || c->fd_tap !=3D -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 =3D=3D -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, > --=20 > 2.51.1 >=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 --rq8uoau5mF7qTegq Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmlDiuIACgkQzQJF27ox 2Gfr8Q//d1B/MuI43cGfI5JJpLdZpuwpGrZ33tOj5R07zV/552krP+uR5l+awwKf nc0bMM+U4lGiUIQbs2prjZpJ2IMUJGMREhhwnG+l7bp8DDQ3CBgUrkJpsRNK8rgk WRBs9yhszphkbd6So47GEVoz95RMakqolPEgPc8wJcrTtfjlV0aWd6XwAwubeguQ VV7n8olg/Kvy7vcPLuqTGM4tBTxOjFEoGNhAmfRuHHn85ZuVsXTAhrT+b/8dnu07 YSfUxXMABSbZvpTY9h4Qw78SRrZBiNaawgT5IOz/iO7rn0olvsAslzEgYXZNWMjv MOHg3ytulXLamqskl/08+8fMpKqpelcMGxQH5eIoTXvAVl3diw/iblyGNl5gfu/U 0Hm7+sSpOyPUPckNT90l2lB6xE2WV6V4CNU/iGTuBgKcCUdDE2Jl8urE4B69KWTC NGaKgBiXe+a35yQ4D3JMJR5gdpHXnS2idt5JVbOscFdh8bE4dLDlveo8gt4yfCPU mdggA7vG4tX7Xw7bLxbb/9rmqOTLSngVdh/EICOplopKxo50jg298H8pRRCnw8vL GTg2isDCvEqAS8Ppvj1hIM3VJQ4E5+ZVwfqSJtGHIhCqTMsMD3/TmAdmWp5fsRtt aU1yI/z0UNDkYzlkYLKQgXlrHWJ4VUIX+mym2kBj2aU4n6fiqUE= =YwoT -----END PGP SIGNATURE----- --rq8uoau5mF7qTegq--