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=I2rUM916; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 8C0615A0265 for ; Wed, 06 May 2026 10:24:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1778055862; bh=wTBLu1wZfMYGO/Uwbk7zMb0+Zn2ww3kteqmm+dL9hmE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=I2rUM916Fk8mnupq0qe/9rVcl6Ct6ON8WqTW2zjm/gi/eaCK97wlDX1/3QKjNuGBN Y82lISX1rx0f1hiyKB2M13QlgopqCMr66834mszZZjsfgN8XnZBbPEDKYchA5x5Ztj ATne32AmVe4dZvZJRXCzDS5J8kFr3+xe57kpDsLRBAM/pGcF9rSukk+PoRzCUfvZ4t +KenI+EJolfj7wWfTwMMbJVdqusUtc9a1+ZVkNsSPBHe2ZjKbrRdBPMOfqxD9XsgDG q6q069wewW6L8HlGPSzQTy+4SpbCn5nEalfjpysCtXLZhFaZPF7OxwW31kbG6Q54jf TX2vJHdzvKDUg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4g9T1y4N8kz4wL2; Wed, 06 May 2026 18:24:22 +1000 (AEST) Date: Wed, 6 May 2026 18:23:18 +1000 From: David Gibson To: Laurent Vivier 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> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="W9oeoGtT2G1xlv09" Content-Disposition: inline In-Reply-To: Message-ID-Hash: 6COL3SUC4TRPBAKD6L72BDBERLKPUDGJ X-Message-ID-Hash: 6COL3SUC4TRPBAKD6L72BDBERLKPUDGJ 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: Stefano Brivio , 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: --W9oeoGtT2G1xlv09 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, May 06, 2026 at 10:12:21AM +0200, Laurent Vivier wrote: > On 5/6/26 01:47, Stefano Brivio wrote: > > From: David Gibson > >=20 > > We can now receive updates to the forwarding rules from the pesto client > > and store them in a "pending" copy of the forwarding tables. Implement > > 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 pendi= ng > > tables, then listens based on the new tables. In future we look to imp= rove > > 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 argument > > 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 event= s) > > fwd_rules_dump(info, fwd->rules, fwd->count, > > " ", ""); > > } > > + > > + fwd_listen_switch(c); > > } > > if (events & EPOLLHUP) { > > debug("Configuration client hangup"); > > - goto close; > > } > > - return; > > - > > close: > > conf_close(c); > > 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; > > } > > +/** > > + * 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 > 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 > 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 > Perhaps it should be noted somewhere to avoid confusion in the future? > Or to copy the content of the rules rather than the pointer to the rules? Ah, good point. The problem is the names of the globals - it's not really one "real" and one "pending" table, just two tables that switch between those roles. --=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 --W9oeoGtT2G1xlv09 Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmn6+mwACgkQzQJF27ox 2Gdi4Q//YVN+YTTI/dtM4la5L31gkFkssXKnCP1OegsAzcSKV7h98JXSdSCZBvjh 6pQhp2WWH+A4B760Marq4nBlan0nNp27gyWhziB1TLxQU+JpK/bmaG2ZQOv4NvPS kjVGnNVJ33tP79/MRttmbBfOqHQdehVyQ3gVht9xJO1LhYjqMpYvuK+4mrqL9IcQ Gxq5b8R0Ai2O4+gCX9DA64l6oqXATdtDWD1cSXdT7jjdoL3FctxaNGVE+SxJVZR5 Nkf4sQeFSLz0FTBg9cV7d7NpwC49eS80DDdbnDEa894Z/gkpXii+GXe/KoTkaGVY FeEBvvxTpmheJS7g3cZYrXetiB0YKeP3Qn1/S0rTNdA7YawLmcGQjw07BXrbBiDR X8q4ITb7bXFsfXS0WSm679ku/eYmVV4p+HbT60cW5H/Y/n+OxyNKvE1JBjovZRaF lso+eJviEQe1qmMb3iw0cNBoNwIsqgaaGY6Y0GMPyPEYrQn/kaLLk7UIVxJ0TFzz pw+0Wp41O8SKoAsDNFmNfW2nHX5Qbn/Q+vqKTdsCZW/xhtD9sztSRYRpmAjkIM4A Oo1olVim5ztfXSaI79dU7fGs/i2yyo0+0+YHxV12FjQ02bSFXsqeFqUtHrLNuhPa qoTueqsmT8NrvHr5N2f5bbckaecURPykEhupsE3uHh5Xfi1A/K8= =nEWW -----END PGP SIGNATURE----- --W9oeoGtT2G1xlv09--