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=RTzlzuQI; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id ECFC35A0265 for ; Wed, 06 May 2026 10:53:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1778057583; bh=RkDRDlIXybWU7GWlfPNqH3XeqMTpqyDOB9rncvgtVn0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RTzlzuQIHblv0BKDuIsCN35kzYJ90ozEUBZk3LWYkGflBvmcPUAsUkOqLHtytuuCx UOqKbJsDQeXG4PY+w1E/MvjsHUkC8snL4hJn+piq73hzoM/A4Fe3HE6gktUqaWxYJk 1FFzBs98edKVWjtnv7Lk0lyfjXr55288HDEJdQdwwBJOhtMVJLp5wt7QbWoSmfxx0S PaHz90P/SfnzgzHmDzKawBqEJAIACZLVpSJWrwCQ/q0pobdVopbuWpRELRMQE/XF0L REjBGHE8X0WN09QoJIU7kAjk0Ulo7yKh7g6p0E39lFzvnNVOLklSq7xCBvLjOQdkrO m21F9oM4M2Kow== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4g9Tg34dc3z4wLB; Wed, 06 May 2026 18:53:03 +1000 (AEST) Date: Wed, 6 May 2026 18:52:57 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v8 17/19] conf, fwd: Allow switching to new rules received from pesto Message-ID: References: <20260505234719.1437340-1-sbrivio@redhat.com> <20260505234719.1437340-18-sbrivio@redhat.com> <20260506103930.1b7023a6@elisabeth> <20260506104955.51cdc602@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="UhXkP/dPVMCrsV2U" Content-Disposition: inline In-Reply-To: <20260506104955.51cdc602@elisabeth> Message-ID-Hash: 3P4LVBZ2MK3VTVGKXYMJNEMNCYCR6GCB X-Message-ID-Hash: 3P4LVBZ2MK3VTVGKXYMJNEMNCYCR6GCB 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: Laurent Vivier , passt-dev@passt.top, Jon Maloy 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: --UhXkP/dPVMCrsV2U Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, May 06, 2026 at 10:49:55AM +0200, Stefano Brivio wrote: > On Wed, 6 May 2026 10:39:30 +0200 > Stefano Brivio wrote: >=20 > > On Wed, 6 May 2026 10:12:21 +0200 > > Laurent Vivier wrote: > >=20 > > > On 5/6/26 01:47, Stefano Brivio wrote: =20 > > > > From: David Gibson > > > >=20 > > > > We can now receive updates to the forwarding rules from the pesto c= lient > > > > and store them in a "pending" copy of the forwarding tables. Imple= ment > > > > switching to using the new rules. > > > >=20 > > > > The logic is in a new fwd_listen_switch(). For now this closes all > > > > listening sockets related to the old tables, swaps the active and p= ending > > > > tables, then listens based on the new tables. In future we look to= improve > > > > this so that we don't temporarily stop listening on ports that both= the > > > > old and new tables specify. > > > >=20 > > > > Signed-off-by: David Gibson > > > > [sbrivio: In fwd_listen_switch(), use the destination size as argum= ent > > > > to memcpy(), instead of sizeof(tmp), as suggested by Laurent] > > > > Signed-off-by: Stefano Brivio > > > > --- > > > > conf.c | 5 ++--- > > > > fwd.c | 34 ++++++++++++++++++++++++++++++++++ > > > > fwd.h | 1 + > > > > 3 files changed, 37 insertions(+), 3 deletions(-) > > > >=20 > > > > diff --git a/conf.c b/conf.c > > > > index 76344da..3f48793 100644 > > > > --- a/conf.c > > > > +++ b/conf.c > > > > @@ -2160,15 +2160,14 @@ void conf_handler(struct ctx *c, uint32_t e= vents) > > > > fwd_rules_dump(info, fwd->rules, fwd->count, > > > > " ", ""); > > > > } > > > > + > > > > + fwd_listen_switch(c); > > > > } > > > > =20 > > > > if (events & EPOLLHUP) { > > > > debug("Configuration client hangup"); > > > > - goto close; > > > > } > > > > =20 > > > > - return; > > > > - > > > > close: > > > > conf_close(c); > > > > =20 > > > > diff --git a/fwd.c b/fwd.c > > > > index d93d2e5..0697435 100644 > > > > --- a/fwd.c > > > > +++ b/fwd.c > > > > @@ -534,6 +534,40 @@ int fwd_listen_init(const struct ctx *c) > > > > return 0; > > > > } > > > > =20 > > > > +/** > > > > + * fwd_listen_switch() - Switch from current to pending rules table > > > > + * @c: Execution context > > > > + */ > > > > +void fwd_listen_switch(struct ctx *c) > > > > +{ > > > > + struct fwd_table *tmp[PIF_NUM_TYPES]; > > > > + unsigned i; > > > > + > > > > + /* Stop listening on the old tables */ > > > > + for (i =3D 0; i < PIF_NUM_TYPES; i++) { > > > > + struct fwd_table *fwd =3D c->fwd[i]; > > > > + > > > > + if (!fwd) > > > > + continue; > > > > + > > > > + debug("Flushing %u old %s rules", fwd->count, pif_name(i)); > > > > + fwd_listen_close(fwd); > > > > + fwd->count =3D fwd->sock_count =3D 0; > > > > + } > > > > + > > > > + /* Swap active and pending tables */ > > > > + static_assert(sizeof(tmp) =3D=3D sizeof(c->fwd) && > > > > + sizeof(tmp) =3D=3D sizeof(c->fwd_pending), > > > > + "Temporary has wrong size"); =20 > > >=20 > > > At this point: > > >=20 > > > c->fwd[PIF_HOST] =3D &fwd_in; > > > c->fwd[PIF_SPLICE] =3D &fwd_out; > > >=20 > > > c->fwd_pending[PIF_HOST] =3D &fwd_in_pending; > > > c->fwd_pending[PIF_SPLICE] =3D &fwd_out_pending; > > > =20 > > > > + memcpy(&tmp, (void *)c->fwd, sizeof(tmp)); > > > > + memcpy((void *)c->fwd, (void *)c->fwd_pending, sizeof(c->fwd)); > > > > + memcpy((void *)c->fwd_pending, &tmp, sizeof(c->fwd_pending)); = =20 > > >=20 > > > At this point: > > >=20 > > > c->fwd[PIF_HOST] =3D &fwd_in_pending; > > > c->fwd[PIF_SPLICE] =3D &fwd_out_pending; > > >=20 > > > c->fwd_pending[PIF_HOST] =3D &fwd_in; > > > c->fwd_pending[PIF_SPLICE] =3D &fwd_out; =20 > >=20 > > Yeah, makes sense, I can change that in v9. > >=20 > > > Perhaps it should be noted somewhere to avoid confusion in the future= ? =20 > >=20 > > What do you think should be noted exactly, and where? Can you show a > > practical example of the change you're proposing? >=20 > ...I'm leaving like it is in v9 to make sure I'm not misinterpreting > you, and also because the current (v8) version is obviously correct and > I also tested it fairly heavily by now. >=20 > I'd suggest optimising this (and commenting as needed) in a separate > patch later. As noted in another branch of this thread, I think all it really needs is renaming the globals that c->fwd and c->fwd_pending point to. They should just be fwd_in_[12] (or an array of 2 tables), instead of implying a semantic difference between the plain and "pending" copies. --=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 --UhXkP/dPVMCrsV2U Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmn7AV4ACgkQzQJF27ox 2Get2Q/8Di34b13cUNiFJJYwf0lWowNSWVaEJ4HzRmF3yXfY5QPwJC7ZcW+mRVQN CGKUCM6Q64nq+50+KzoIOehpV3zFNPbsad0AUIsnlgl0EEPUkk2GztzLsQ5Do4Hb 5dtXqD+rMU0oJZ8NuCKNhenBqr0DzhgtwG6YB6ngDcrxjIIGIq8R39W73Ttaz/s3 hpH0Si/yGxT9d7yAr4DC6ow3huXldcrx6bRhnmgBjbac+fDYSq2wfjkmp414X/5z QPeHe9Bo0TLeqVtmHfr/bOh9sMXWZTXk/vKJofS2Gqh/zIaNSS2czwxT+UolYjeo Q6NLGodRI2up26rL9HQblrZSah/xFXTJWg6b2ZNt4Ss6R55Po2XIJiHOfhpMjSAo ZoVb3a3B4jV4wd8y9WPq+QDfcYhi9UIoPAMxfQMsZ7uvWoqJydxauni4IplhGnt+ Mv+o7xYNW9v6UF0S0PQktVoxmvOE4pQLvPBSkja0CszhEV3PX5TQEUdZ/hqJMXUo icWze5HKvIDSTNcpK8zA1z/QE/dYZRdAg8Szyf02J3BDRVzwSws3sheWUHi2mf3h XQaNEXIkdZlfAeF1FlW4Rsc4www/rXkzkqz/wSCu0kbXmOJ14QUEhkPK+HkmCULI ni2PzYeQ7SRqahCKjLQfri8xJpmviwceODpPmjg4IjdLORCoRQc= =ALNL -----END PGP SIGNATURE----- --UhXkP/dPVMCrsV2U--