[PATCH v2] conf, pesto: Notify client of the result of rule updates
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
On Wed, 18 Nov 2026 02:44:09 +0900
Hayato Kiwata
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
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
participants (2)
-
Hayato Kiwata
-
Stefano Brivio