From: Stefano Brivio <sbrivio@redhat.com>
To: Hayato Kiwata <dev@haytok.jp>
Cc: passt-dev@passt.top, david@gibson.dropbear.id.au
Subject: Re: [PATCH v2] conf, pesto: Notify client of the result of rule updates
Date: Fri, 20 Nov 2026 23:59:02 +0100 (CET) [thread overview]
Message-ID: <20261120235844.75da1afa@elisabeth> (raw)
In-Reply-To: <20261117174409.20250-1-dev@haytok.jp>
On Wed, 18 Nov 2026 02:44:09 +0900
Hayato Kiwata <dev@haytok.jp> wrote:
> 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.
>
> 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.
>
> 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.
>
> Link: https://archives.passt.top/passt-dev/20261025153025.600a4fe9@elisabeth/
> Signed-off-by: Hayato Kiwata <dev@haytok.jp>
Applied, thanks! One minor thing that _could_ be addressed as a
follow-up:
> [...]
>
> +++ b/pesto.c
> @@ -318,6 +318,7 @@ int main(int argc, char **argv)
> struct sockaddr_un a = { AF_UNIX, "" };
> struct configuration conf = { 0 };
> bool update = false, show = false;
> + int exit_status = EXIT_SUCCESS;
> struct pesto_hello hello;
> struct sock_fprog prog;
> int optname, ret, s;
> @@ -513,9 +514,33 @@ int main(int argc, char **argv)
>
> send_conf(s, &conf);
>
> + if (s_version >= 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:
> + exit_status = EXIT_FAILURE;
> + warn("Failed to apply new rules, old rules restored");
> + break;
> + case PESTO_STATUS_FAILED:
> + exit_status = EXIT_FAILURE;
> + warn(
> +"Failed to apply new rules, couldn't restore old ones");
> + break;
> + default:
> + exit_status = EXIT_FAILURE;
> + warn("Unknown configuration status %"PRIu8, status);
> + }
> + }
> +
> noupdate:
> if (shutdown(s, SHUT_RDWR) < 0 || close(s) < 0)
> die_perror("Error shutting down control socket");
>
> - exit(0);
> + exit(exit_status);
We already have a 'status' variable, and the condition is trivial
enough that we could probably drop 'exit_status', broaden the scope of
'status', and:
exit(status == PESTO_STATUS_OK ? EXIT_SUCCESS : EXIT_FAILURE);
which saves a few lines without impairing readability (...I think). Not
a strong preference from my side though.
--
Stefano
prev parent reply other threads:[~2026-11-20 22:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 17:44 Hayato Kiwata
2026-11-20 22:59 ` Stefano Brivio [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120235844.75da1afa@elisabeth \
--to=sbrivio@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=dev@haytok.jp \
--cc=passt-dev@passt.top \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).