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=202602 header.b=d8oqbIdY; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id C68DA5A0269 for ; Wed, 25 Mar 2026 02:46:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1774403174; bh=qG6mh1JDv+i9gDHpL+uqtuYfzW+Fom7yoAdPhNTgT8k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=d8oqbIdYN1xJVCuehmYSrKPA9lZIFdvThNIxiwfN8FZ/675RBfSpnVT92HZSIG+rX +zjxix+gvPOkXpoIHHVgNsrCLmKBbo7tNDxArHaP8ROqVU/9/iwPp4/xmAk5gQohHf IZhF9JkUUtTlH48HHxAnONPbnMR9ZGNKXBdqg24MkUDjtweW7bq3NfImKmAs7CuW8k eYMax8TzyybART3a8YGTDac3bmjH6yhqTpdmUL70BtVLxdk9zVBGXH8BofDhMKCnbl +747tV9T7ciCkGi3ABXjhMUZxRZhi5hNCNrjLSsRNnvgIJ0n2i/UlXDVwpl0mjWzWw fLOfbhr4B8fgQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fgV9y3sXvz4wM8; Wed, 25 Mar 2026 12:46:14 +1100 (AEDT) Date: Wed, 25 Mar 2026 12:22:02 +1100 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v6 10/13] migrate: Update protocol to v3 for multi-address support Message-ID: References: <20260322004333.365713-1-jmaloy@redhat.com> <20260322004333.365713-11-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="wbKXFF5lRNm3+SYx" Content-Disposition: inline In-Reply-To: <20260322004333.365713-11-jmaloy@redhat.com> Message-ID-Hash: LY5GYROHLMQ7OSJP2FEKRZTTBJ7ICZ2P X-Message-ID-Hash: LY5GYROHLMQ7OSJP2FEKRZTTBJ7ICZ2P 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: --wbKXFF5lRNm3+SYx Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Mar 21, 2026 at 08:43:30PM -0400, Jon Maloy wrote: > We update the migration protocol to version 3 to support distributing > multiple addresses from the unified address array. The new protocol > migrates all address entries in the array, along with their prefix > lengths and flags, and leaves it to the receiver to filter which > ones he wants to apply. >=20 > Signed-off-by: Jon Maloy LGTM, except insofar as it might need updates due to changes in the preceding patches. >=20 > --- > v4: - Broke out as separate commit > - Made number of transferable addresses variable >=20 > v6: - Separated internal and wire transfer format > --- > migrate.c | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 178 insertions(+) >=20 > diff --git a/migrate.c b/migrate.c > index a92301b..7b9a2f6 100644 > --- a/migrate.c > +++ b/migrate.c > @@ -44,6 +44,71 @@ struct migrate_seen_addrs_v2 { > unsigned char mac[ETH_ALEN]; > } __attribute__((packed)); > =20 > +/** > + * Wire format flags for address migration (v3) > + * These are stable values - do not change existing assignments > + */ > +#define MIGRATE_ADDR_USER BIT(0) > +#define MIGRATE_ADDR_HOST BIT(1) > +#define MIGRATE_ADDR_LINKLOCAL BIT(2) > +#define MIGRATE_ADDR_OBSERVED BIT(3) > + > +/** > + * struct migrate_addr_v3 - Wire format for a single address entry > + * @addr: IPv6 or IPv4-mapped address (16 bytes) > + * @prefix_len: Prefix length > + * @flags: MIGRATE_ADDR_* flags (wire format) > + */ > +struct migrate_addr_v3 { > + struct in6_addr addr; > + uint8_t prefix_len; > + uint8_t flags; > +} __attribute__((__packed__)); > + > +/** > + * flags_to_wire() - Convert internal flags to stable wire format > + * @flags: Internal CONF_ADDR_* flags > + * > + * Return: Wire format MIGRATE_ADDR_* flags > + */ > +static uint8_t flags_to_wire(uint8_t flags) > +{ > + uint8_t wire =3D 0; > + > + if (flags & CONF_ADDR_USER) > + wire |=3D MIGRATE_ADDR_USER; > + if (flags & CONF_ADDR_HOST) > + wire |=3D MIGRATE_ADDR_HOST; > + if (flags & CONF_ADDR_LINKLOCAL) > + wire |=3D MIGRATE_ADDR_LINKLOCAL; > + if (flags & CONF_ADDR_OBSERVED) > + wire |=3D MIGRATE_ADDR_OBSERVED; > + > + return wire; > +} > + > +/** > + * flags_from_wire() - Convert wire format flags to internal format > + * @wire: Wire format MIGRATE_ADDR_* flags > + * > + * Return: Internal CONF_ADDR_* flags > + */ > +static uint8_t flags_from_wire(uint8_t wire) > +{ > + uint8_t flags =3D 0; > + > + if (wire & MIGRATE_ADDR_USER) > + flags |=3D CONF_ADDR_USER; > + if (wire & MIGRATE_ADDR_HOST) > + flags |=3D CONF_ADDR_HOST; > + if (wire & MIGRATE_ADDR_LINKLOCAL) > + flags |=3D CONF_ADDR_LINKLOCAL; > + if (wire & MIGRATE_ADDR_OBSERVED) > + flags |=3D CONF_ADDR_OBSERVED; > + > + return flags; > +} > + > /** > * seen_addrs_source_v2() - Copy and send guest observed addresses from = source > * @c: Execution context > @@ -126,6 +191,98 @@ static int seen_addrs_target_v2(struct ctx *c, > return 0; > } > =20 > +/** > + * addrs_source_v3() - Send all addresses with flags from source > + * @c: Execution context > + * @stage: Migration stage, unused > + * @fd: File descriptor for state transfer > + * > + * Send all address entries using a stable wire format. Each field is > + * serialized explicitly to avoid coupling the wire format to internal > + * structure layout or flag bit assignments. > + * > + * Return: 0 on success, positive error code on failure > + */ > +/* cppcheck-suppress [constParameterCallback, unmatchedSuppression] */ > +static int addrs_source_v3(struct ctx *c, > + const struct migrate_stage *stage, int fd) > +{ > + uint8_t addr_count =3D c->addr_count; > + const struct guest_addr *a; > + > + (void)stage; > + > + /* Send count first */ > + if (write_all_buf(fd, &addr_count, sizeof(addr_count))) > + return errno; > + > + /* Send each address in stable wire format */ > + for_each_addr(a, c, 0) { > + struct migrate_addr_v3 wire =3D { > + .addr =3D a->addr.a6, > + .prefix_len =3D a->prefix_len, > + .flags =3D flags_to_wire(a->flags), > + }; > + > + if (write_all_buf(fd, &wire, sizeof(wire))) > + return errno; > + } > + > + /* Send MAC */ > + if (write_all_buf(fd, c->guest_mac, ETH_ALEN)) > + return errno; > + > + return 0; > +} > + > +/** > + * addrs_target_v3() - Receive addresses on target > + * @c: Execution context > + * @stage: Migration stage, unused > + * @fd: File descriptor for state transfer > + * > + * Receive address entries from the stable wire format and merge only > + * observed addresses into local array. Source sends all addresses for > + * forward compatibility, but target only applies those marked as observ= ed. > + * > + * Return: 0 on success, positive error code on failure > + */ > +static int addrs_target_v3(struct ctx *c, > + const struct migrate_stage *stage, int fd) > +{ > + uint8_t addr_count, i; > + > + (void)stage; > + > + if (read_all_buf(fd, &addr_count, sizeof(addr_count))) > + return errno; > + > + if (addr_count > MAX_GUEST_ADDRS) > + addr_count =3D MAX_GUEST_ADDRS; > + > + /* Read each address from stable wire format */ > + for (i =3D 0; i < addr_count; i++) { > + struct migrate_addr_v3 wire; > + struct guest_addr addr; > + > + if (read_all_buf(fd, &wire, sizeof(wire))) > + return errno; > + > + addr.addr.a6 =3D wire.addr; > + addr.prefix_len =3D wire.prefix_len; > + addr.flags =3D flags_from_wire(wire.flags); > + > + if (addr.flags & CONF_ADDR_OBSERVED) > + fwd_set_addr(c, &addr.addr, addr.flags, > + addr.prefix_len); > + } > + > + if (read_all_buf(fd, c->guest_mac, ETH_ALEN)) > + return errno; > + > + return 0; > +} > + > /* Stages for version 2 */ > static const struct migrate_stage stages_v2[] =3D { > { > @@ -146,8 +303,29 @@ static const struct migrate_stage stages_v2[] =3D { > { 0 }, > }; > =20 > +/* Stages for version 3 (multiple observed IPv4 addresses) */ > +static const struct migrate_stage stages_v3[] =3D { > + { > + .name =3D "addresses", > + .source =3D addrs_source_v3, > + .target =3D addrs_target_v3, > + }, > + { > + .name =3D "prepare flows", > + .source =3D flow_migrate_source_pre, > + .target =3D NULL, > + }, > + { > + .name =3D "transfer flows", > + .source =3D flow_migrate_source, > + .target =3D flow_migrate_target, > + }, > + { 0 }, > +}; > + > /* Supported encoding versions, from latest (most preferred) to oldest */ > static const struct migrate_version versions[] =3D { > + { 3, stages_v3, }, > { 2, stages_v2, }, > /* v1 was released, but not widely used. It had bad endianness for the > * MSS and omitted timestamps, which meant it usually wouldn't work. > --=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 --wbKXFF5lRNm3+SYx Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmnDOLkACgkQzQJF27ox 2GeUgg//SoXZ71vieStUYlT7+W8lsjy35hiKSqAb1patLCFSjfhoquUUQSs4w9my ZlPYrQGs3SVeEaQAyXV0XmzFQ9jylOomkIn2deETxmhKE5Ut73CKoc6wCRokp1a4 oMJeI92fuic5OnC906sX7HiifqEm+AbomJiTxuY+VmMbfK+NMIK4iepboaWJxi1F fG91ZoJLB3CTERYnjxFcHbd6RZrCMWy6c88UUEMY0hKbWrmCVx2o7PScSOHzeT2g nQj88JDzVi5xCdqVwE+iespKUmbRqnQPEbAYclE5XRMLL9QLoWqMtakXTz0KGdAe ePjgxtnp+57EMY7XrILOxRwKIpkYfgC9jV4InPzW+lsaAsLiyZmUnSqLlP6qeA1q U8iJMRR8aZmoBT9qlM577htJpNQY7VsnJgHtGjKoIrf+ZZcIvNvZsmVINUDkfB2U z8uWK0RNoB4emcfuU12TycCt7ulab4co+VHHwwNTp1cVGXgyeLEj3ZhLkUJ9PEQN Cy5SD3LYMDErWA6tJ5rZvbDAhaZ48WX3nZMaO0zk9XEkCSo8lj94rC5q0ykTn8Mx oufb4Omt1RYctZIN92rLxmRTjZ9QirFzqEI1w2gdifNEg69BLQnx3PYEc38rMmQ6 0HdQi+uIjZHT0tXHJmyeXUsfL9bnWBwgDgEFAFNbakB2TbAVLgw= =UiWx -----END PGP SIGNATURE----- --wbKXFF5lRNm3+SYx--