From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=haytok.jp Received: from outbound.pv.icloud.com (pv-2003k-snip6-3.eps.apple.com [IPv6:2a01:b747:3003:205::71]) by passt.top (Postfix) with ESMTPS id 4BFAE5A0265 for ; Tue, 17 Nov 2026 18:44:19 +0100 (CET) Received: from outbound.pv.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-west-1a-20-percent-0 (Postfix) with ESMTPS id 2B40C180171F; Tue, 17 Nov 2026 17:44:15 +0000 (UTC) X-ICL-RepId: 01a1ea9c-05b7-7a2b-81cc-2eaf575266c8 Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=haytok.jp; s=sig1; t=1794937457; x=1826473457; bh=586Hl/d13Aqir1t3eHRB40pT8i4I565nq7I7V6QgxZU=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=O84qwWP8Bb6Qhr7AV2S0pA/OWH4OQmjOORt98TrqdEUps+VKwVXg9eqSpsdN4+de2A6BkTADt4zJ6hVPk2rzWAmOzSMG44bCKjRfHgKQRaQb3nfb1DE2wkBo5ySVcvTJK317ebyAQYh9irKeD/Py0uNK1otcgUPhbR8t51wLO+ueeIiyfMTaq5lOdsH5+hyp/BWve2jCt3jUe33m920/HNvgnNZnKuoJgR4jTXv5pmpU9K8ZF+mINcGaSlRjb7T1JbXXFsb6sGGa7zFmiPmVKjT8mPKvxAPUIWujBrKrRR/GHFrpElJQE8g2uQ0fDg5rGE5E322+qS81DgjPlanykA== mail-alias-created-date: 1766251435121 Received: from localhost.localdomain (unknown [17.156.192.29]) by p00-icloudmta-asmtp-us-west-1a-20-percent-0 (Postfix) with ESMTPSA id 9F9C4180126F; Tue, 17 Nov 2026 17:44:14 +0000 (UTC) From: Hayato Kiwata To: passt-dev@passt.top Subject: [PATCH v2] conf, pesto: Notify client of the result of rule updates Date: Wed, 18 Nov 2026 02:44:09 +0900 Message-ID: <20261117174409.20250-1-dev@haytok.jp> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-GUID: 2lJ-TcyW9wIZnNzUUobeCEVKpa1g3Jqo X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTE3MDA3MCBTYWx0ZWRfX0lCuoVQiIPJ+ fpZmFgFWeA113zHMZ5sdiyUUWXmnPj0X74GORR4lC6oTKiPcxYdvK6aIeBoXDMoLSK6UQA8tGzi 3iJQdrMvUD1yJjfAMZ7HzMeQ8QUSK9cWccwggilgwhmcVdnItUZXka70LC5k9yGfVFdIhHE0yxi Lu+hkrtjkHujlWNihVFhlOIBp3Md9pR7/K6Y8g/p7ir3a2FLZipoJ0nQW8iAgGGcGxLa0ccQxQL rD+wKjkFKAesSX6cATfW+VP7VJEBN2bB26Wn3hib0Ppix/4y+tdOTm1IE/cO5pEYh5twEHanIXx PJA+aUJMOKeM3X4b+ThnZjPrZX/Et3qdalaoy6Bnh0lbwWAQnh3haKRSaXFPo0= X-Authority-Info-Out: v=2.4 cv=DodbOW/+ c=1 sm=1 tr=0 ts=6afc9270 cx=c_apl:c_pps:t_out a=aW9mcIavGNWWFvFFKOxBSA==:117 a=aW9mcIavGNWWFvFFKOxBSA==:17 a=zJRp6_cAMcgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=pNgXkJcRAAAA:8 a=RPpv3yIanOwiejHpQasA:9 a=tKe0A8swS_RTMQ4Dt1Wu:22 X-Proofpoint-ORIG-GUID: 2lJ-TcyW9wIZnNzUUobeCEVKpa1g3Jqo X-JNJ: AAAAAAABB+H2JYBThnmnXUfa6ZZ3siUTtF4lge7wOrLtonU6ypAw5LlD9GIvPNtNy8RW1a 5ySSQtd35QhLC10gdiP7pVqBmazVSSeYMFNKGR4YwyL5EhAascmjleEgsmY3ZiN6lgERS/ 0Wydq5ipTzsXRKdCt4ngNNXjdeRuKDJlLadzdi+9J6Pb/FbfBTfMpnJq+bQ2tl4fytc9dr ZfmEH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ok.jp X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation Message-ID-Hash: AUJMTDHK7REBYVV5QOCRA3HBH7DU5BDC X-Message-ID-Hash: AUJMTDHK7REBYVV5QOCRA3HBH7DU5BDC X-Mailman-Approved-At: Tue, 17 Nov 2026 20:49:17 +0100 CC: sbrivio@redhat.com, david@gibson.dropbear.id.au, Hayato Kiwata 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: 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 --- v2: - Make enum pesto_status comments kernel-doc compatible - In pesto, use warn() and break instead of die(), so that we call shutdown() and close() on failure as well - Add exit_status variable to keep the non-zero exit status on failure v1: - https://archives.passt.top/passt-dev/20261113085505.43460-1-dev@haytok.jp/ Tested with: $ pesto -A --tcp-ports=127.0.0.1/8085:80 /tmp/.pasta.sock $ pesto -A --tcp-ports=192.0.2.1/8080:80 /tmp/.pasta.sock Failed to apply new rules, old rules restored $ echo $? 1 $ pesto -s /tmp/.pasta.sock passt/pasta configuration (/tmp/.pasta.sock) HOST TCP [127.0.0.1]:8085 => 80 SPLICE $ curl -sI localhost:8085 | head -1 HTTP/1.0 200 OK --- conf.c | 10 +++++++++- pesto.c | 27 ++++++++++++++++++++++++++- pesto.h | 20 +++++++++++++++++++- 3 files changed, 54 insertions(+), 3 deletions(-) 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 = PESTO_STATUS_OK; unsigned pif; /* Clear pending tables */ @@ -2297,11 +2298,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) { diff --git a/pesto.c b/pesto.c index eeaf274..03edc29 100644 --- a/pesto.c +++ 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); } diff --git a/pesto.h b/pesto.h index 8db701b..794a9d8 100644 --- a/pesto.h +++ b/pesto.h @@ -19,12 +19,30 @@ * 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 -- 2.50.1 (Apple Git-155)