diff options
| author | Hayato Kiwata <dev@haytok.jp> | 2026-11-18 02:44:09 +0900 |
|---|---|---|
| committer | Stefano Brivio <sbrivio@redhat.com> | 2026-11-20 22:58:26 +0100 |
| commit | 885c39e8b9991a5c124a0630b013f44ba1a32172 (patch) | |
| tree | 536fba178b65e3c45b573e53c28c30b716699352 | |
| parent | fe78dd1d85d7ccc50cb26f8048ccad857c8823d4 (diff) | |
| download | passt-885c39e8b9991a5c124a0630b013f44ba1a32172.tar passt-885c39e8b9991a5c124a0630b013f44ba1a32172.tar.gz passt-885c39e8b9991a5c124a0630b013f44ba1a32172.tar.bz2 passt-885c39e8b9991a5c124a0630b013f44ba1a32172.tar.lz passt-885c39e8b9991a5c124a0630b013f44ba1a32172.tar.xz passt-885c39e8b9991a5c124a0630b013f44ba1a32172.tar.zst passt-885c39e8b9991a5c124a0630b013f44ba1a32172.zip | |
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 <dev@haytok.jp>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
| -rw-r--r-- | conf.c | 10 | ||||
| -rw-r--r-- | pesto.c | 27 | ||||
| -rw-r--r-- | pesto.h | 20 |
3 files changed, 54 insertions, 3 deletions
@@ -2299,6 +2299,7 @@ fail: void conf_handler(struct ctx *c, uint32_t events) { if (events & EPOLLIN) { + enum pesto_status status = PESTO_STATUS_OK; unsigned pif; /* Clear pending tables */ @@ -2323,11 +2324,18 @@ void conf_handler(struct ctx *c, uint32_t events) } if (fwd_listen_switch(c) < 0) { + status = 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 = 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"); } if (events & EPOLLHUP) { @@ -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); } @@ -19,13 +19,31 @@ * but was little enough used that we decided not to implement backwards * 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 apply the + * new rules (see enum pesto_status) + */ +#define PESTO_VERSION_STATUS 3 +#define PESTO_PROTOCOL_VERSION 3 /* Maximum size of a pif name, including \0 */ #define PIF_NAME_SIZE (128) #define PIF_NONE 0 /** + * enum pesto_status - Result of a configuration update (protocol version 3+) + * @PESTO_STATUS_OK: New rules applied + * @PESTO_STATUS_ROLLBACK: New rules failed, old rules restored + * @PESTO_STATUS_FAILED: New rules failed, couldn't restore old ones + * + * Sent by the server as a single byte after trying to apply the new rules. + */ +enum pesto_status { + PESTO_STATUS_OK = 0, + PESTO_STATUS_ROLLBACK = 1, + PESTO_STATUS_FAILED = 2, +}; + +/** * struct pesto_hello - Server introduction message * @magic: PESTO_SERVER_MAGIC * @version: Version number |
