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 Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id A6E855A0275 for ; Mon, 16 Nov 2026 05:34:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202610; t=1794803680; bh=UKlxMeGhF2xu9ILHvJoqS5sUXxjSac2B40z9jcAg2OQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ImBL8UzbwFKLDLEsQlVN2gKoEyhK594N/HNu2o2F9hZGbS8enGqXPfRnc01y/AhtJ MCg9H14PM7z7UAeeEVodObVEJZNOiVUiVD5Ux+XT/l2WVDRaxXTAvt9k1NDoO9jCv9 7ozl7ipQggzE83AB9CmTX3UJIA1RwioneCV3gol4/G+22K2Yv9WwWNJCOpci62qPRr ExbKJxDEdrVbQFhMw2oC6OvL+j59NEC8rX2seozL12UNTEft21y1jh939ASZ2N93DA 2LVY9pMXl+aH/xs/35T4reXMCrvWAkHeAj6ft0FYFuGdN1wxJQMWtINwycRFYB47Ky PiCb6uC1Fx2ag== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4jSZlN1NqNz4wLT; Mon, 16 Nov 2026 15:34:40 +1100 (AEDT) Date: Mon, 16 Nov 2026 14:29:42 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH] conf, pesto: Notify client of the result of rule updates Message-ID: References: <20261113085505.43460-1-dev@haytok.jp> <20261115012923.2502e272@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="rEo6/J6ZUZQSUY0i" Content-Disposition: inline In-Reply-To: <20261115012923.2502e272@elisabeth> Message-ID-Hash: 7LTOKX4VY3EDBX6S2NKKRYOABA3CDG5J X-Message-ID-Hash: 7LTOKX4VY3EDBX6S2NKKRYOABA3CDG5J 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: Hayato Kiwata , 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: --rEo6/J6ZUZQSUY0i Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Nov 15, 2026 at 01:29:25AM +0100, Stefano Brivio wrote: > Thanks, it looks good to me, and I also tested it briefly. Just two > minor details (which I can also fix up on merge if you prefer): >=20 > On Fri, 13 Nov 2026 17:55:05 +0900 > Hayato Kiwata wrote: >=20 > > Since commit 1776dcb7317e ("fwd, conf: Roll back to old rules if > > switching to new ones fails"), pasta tries to restore the old rules when > > switching to new rules fails. However, pesto has no way to know that, > > and exits successfully as if the new rules were applied. > >=20 > > In conf_handler(), write a one-byte status to the control socket after > > trying to apply the new rules. The status has three values: > > PESTO_STATUS_OK, PESTO_STATUS_ROLLBACK, and PESTO_STATUS_FAILED. In > > pesto, read the status after send_conf(), and if the update failed, > > print what happened and exit with a non-zero status. > >=20 > > Note that we bump PESTO_PROTOCOL_VERSION to 3 because this adds a > > message from the server. If the server version is lower than that, > > pesto doesn't read the status. Also, if the server fails to receive > > rules from the client, it still closes the connection without sending a > > status. > >=20 > > Link: https://archives.passt.top/passt-dev/20261025153025.600a4fe9@elis= abeth/ > > Signed-off-by: Hayato Kiwata > >=20 > > --- > > Tested with: > >=20 > > $ pesto -A --tcp-ports=3D127.0.0.1/8085:80 /tmp/.pasta.sock > >=20 > > $ pesto -A --tcp-ports=3D192.0.2.1/8080:80 /tmp/.pasta.sock > > Failed to apply new rules, old rules restored > >=20 > > $ echo $? > > 1 > >=20 > > $ pesto -s /tmp/.pasta.sock > > passt/pasta configuration (/tmp/.pasta.sock) > > HOST > > TCP [127.0.0.1]:8085 =3D> 80 > > SPLICE > >=20 > > $ curl -sI localhost:8085 | head -1 > > HTTP/1.0 200 OK > > --- > > conf.c | 10 +++++++++- > > pesto.c | 19 +++++++++++++++++++ > > pesto.h | 20 +++++++++++++++++++- > > 3 files changed, 47 insertions(+), 2 deletions(-) > >=20 > > diff --git a/conf.c b/conf.c > > index 7be0c79..f0fc606 100644 > > --- a/conf.c > > +++ b/conf.c > > @@ -2273,6 +2273,7 @@ fail: > > void conf_handler(struct ctx *c, uint32_t events) > > { > > if (events & EPOLLIN) { > > + enum pesto_status status =3D PESTO_STATUS_OK; > > unsigned pif; > > =20 > > /* Clear pending tables */ > > @@ -2297,11 +2298,18 @@ void conf_handler(struct ctx *c, uint32_t event= s) > > } > > =20 > > if (fwd_listen_switch(c) < 0) { > > + status =3D PESTO_STATUS_ROLLBACK; > > err("Error switching to new forwarding rules"); > > + > > /* Switch back to old rules (still in c->fwd_pending) */ > > - if (fwd_listen_switch(c) < 0) > > + if (fwd_listen_switch(c) < 0) { > > + status =3D PESTO_STATUS_FAILED; > > err("Couldn't restore old forwarding rules"); > > + } > > } > > + > > + if (write_u8(c->fd_control, status) < 0) > > + warn_perror("Failed to write status on control socket"); > > } > > =20 > > if (events & EPOLLHUP) { > > diff --git a/pesto.c b/pesto.c > > index eeaf274..89ece5d 100644 > > --- a/pesto.c > > +++ b/pesto.c > > @@ -513,6 +513,25 @@ int main(int argc, char **argv) > > =20 > > send_conf(s, &conf); > > =20 > > + if (s_version >=3D PESTO_VERSION_STATUS) { > > + uint8_t status; > > + > > + if (read_u8(s, &status) < 0) > > + die_perror("Couldn't read configuration status"); > > + > > + switch (status) { > > + case PESTO_STATUS_OK: > > + break; > > + case PESTO_STATUS_ROLLBACK: > > + die("Failed to apply new rules, old rules restored"); > > + case PESTO_STATUS_FAILED: > > + die( > > +"Failed to apply new rules, couldn't restore old ones"); > > + default: > > + die("Unknown configuration status %"PRIu8, status); >=20 > It doesn't impact functionality at least for the moment, but if we just > exit on error without shutdown() this becomes inconsistent with the > non-error path for no particular reason. I'm not sure if that's true. Something that came to light in debugging a bunch of the connection-end bugs we've had is that a close() (and thereby also an _exit()) on a TCP socket _usually_ causes a FIN rather than an RST. That can be changed by poking SO_LINGER, which we use. This is a Unix socket, rather than a TCP socket, but I'd similarly expect a close() or _exit() to result in a clean shutdown unless we've explicitly configured it otherwise with SO_LINGER. In fact, looking at the SO_LINGER entry in socket(7) it appears that _exit(3) will always linger (and therefore close cleanly), even if SO_LINGER *is* set. >=20 > It might become relevant the day we decide to export the configuration > over TCP as well, or if we implement any kind of "shell" mode for pesto. That's a reasonable point, however. > I'd rather turn those to warn() calls (we don't export err(), it could > be done but I don't think we really need it) and add break statements > for the PESTO_STATUS_ROLLBACK and PESTO_STATUS_FAILED cases. >=20 > > + } > > + } > > + > > noupdate: > > if (shutdown(s, SHUT_RDWR) < 0 || close(s) < 0) > > die_perror("Error shutting down control socket"); > > diff --git a/pesto.h b/pesto.h > > index 8db701b..5065530 100644 > > --- a/pesto.h > > +++ b/pesto.h > > @@ -19,12 +19,30 @@ > > * but was little enough used that we decided not to implement backwar= ds > > * compatiblity code (i.e. a v2 pesto will not work with a v1 pasta) > > */ > > -#define PESTO_PROTOCOL_VERSION 2 > > +/* Version 3 added a status byte, sent by the server after trying to a= pply the > > + * new rules (see enum pesto_status) > > + */ > > +#define PESTO_VERSION_STATUS 3 >=20 > By the way, I think this is pretty neat. It didn't occur to me that we > could (also) define version numbers with specific features. >=20 > > +#define PESTO_PROTOCOL_VERSION 3 > > =20 > > /* Maximum size of a pif name, including \0 */ > > #define PIF_NAME_SIZE (128) > > #define PIF_NONE 0 > > =20 > > +/** > > + * enum pesto_status - Result of a configuration update (protocol vers= ion 3+) > > + * >=20 > Nit: we're trying to make all the documentation kerneldoc compatible > (https://docs.kernel.org/doc-guide/kernel-doc.html), mostly for the sake > of https://bugs.passt.top/show_bug.cgi?id=3D35, and enums should have > their values documented in the header rather than inline, say: >=20 > * @PESTO_STATUS_OK: New rules applied >=20 > see also: >=20 > $ grep -B5 "enum [a-z0-9_]* {" *.c >=20 > ...I know, we haven't been very consistent with that so far. >=20 > > + * Sent by the server as a single byte after trying to apply the new r= ules. > > + */ > > +enum pesto_status { > > + /* New rules applied */ > > + PESTO_STATUS_OK =3D 0, > > + /* New rules failed, old rules restored */ > > + PESTO_STATUS_ROLLBACK =3D 1, > > + /* New rules failed, old rules couldn't be restored either */ > > + PESTO_STATUS_FAILED =3D 2, > > +}; > > + > > /** > > * struct pesto_hello - Server introduction message > > * @magic: PESTO_SERVER_MAGIC >=20 > --=20 > Stefano >=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 --rEo6/J6ZUZQSUY0i Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmr6eKUACgkQzQJF27ox 2Gefhg/9Eiz07rqS5Lw5W2DdATo1lfQDs7jWDC2hUv10qCuTOzD5HnD8CtUjpYiu t7pvMeHyG9WS2zif8DvguyNfoQ/U6UVEWbRIOIfiWgQgpW9QLAOGnr7kBFMEKX5O 0+BIs8/aXgtZwEcwzO6E6GQjpkXwVwkLieEi/ConmGJ6tAeh/d6DzRDLOS+ZFmlJ JzGdUiwa6FLQoR4rsxRd2jdywSsIhB327CH+jWmmkST+uSYbgsSpNVbfIs3rdPK/ UZqzBl0NgIRr9N9KqxMCNCYJpowwZxGIFCtqaeuHes0Z5eAQMZAqzJBh2WVsbKDL CrvPlQM7ri/MeahTdsCs7eKUH/Pf5ERc5cc/R8s2RRAei6uZeGQdR/Krra1JBzdu aFjK1ds0LaTZKmgU4K8PR1S6jNORrtGtbGxB99bRKkXAcp9hZMtEsKxCLJhMknAO xd4pJ78YS/uFT+YSZlPtuFSvkrvhvq9MP3/r/fljVNVBAgNVQ9Z3oWgCAOXdnt9C 5KaWl0gFMVWKluJ/zz5gQrL0Rs5jnfgikdS7yGDuvbc4zYtUwkMYjYEBtk5V7Rir h4jEpwjUF36nxFbxSvnyOkdKZkdqgx3njh/g3DNqCat3H6YM11l4ZMGhzx47l2ZW nuruBvV1vni+3pcVUxaq3MSpZgQFMMsgDzBD8RIDtxTRoEFHmmY= =Mlo8 -----END PGP SIGNATURE----- --rEo6/J6ZUZQSUY0i--