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.qs.icloud.com (qs-2002c-snip6-1.eps.apple.com [IPv6:2a01:b747:3006:207::18]) by passt.top (Postfix) with ESMTPS id 138625A061E for ; Thu, 29 Oct 2026 17:29:11 +0100 (CET) Received: from outbound.qs.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-2d-60-percent-11 (Postfix) with ESMTPS id 95E2719264A6; Thu, 29 Oct 2026 16:29:07 +0000 (UTC) X-ICL-RepId: 01a1887e-662c-7d4a-a5c7-71e378f1d742 X-ICL-Out-Info: HUtFAUMEWwJACUgATUQeDx5WFlZNRAJCTQhKBkMCWxxCD1YCWwZLVxQEHFYbdwNTCU0XWENdGxIWXUVbDE4fXRsXEkNNRQgPQhkQVgFYVl0FTRpcGFkPHAFKVloOWwRHFBcbXAAXG0YCBCMCXwBFAl4JVgEwFw9WTVEZShlYABwaSVheBFNWDkIJSgVcB1kLQQ9KC1gPRQBBAEEeXBoPVwZ5EFIUQwRZXlMIDU1DEkIVBBtGHkMEXy9dF14MXgU= Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=haytok.jp; s=sig1; t=1793291349; x=1824827349; bh=mWr7kNRFOE2Ijsc3jAab7Rgc4h99lpCAHa8n8Z40egk=; h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme; b=hF8wKKZPid8gDoQsSZuPo8tq3FaLtnvXHqwj4WexqAfx7/xJ4x8ftIqoX0++CyDtQ4UsA8HwDmKK2vfRnfCP3wsRn8Goiqlu8MOFLE1H+CmN2AbLUXoJeVJrGwpHEOGqLTS4zwf1AqZjDSPO75Wp4NRirYVYawvlz8mcJ/mZZW55WUF+nKLqjTdNN/krK4hEZd3My5wp+89B/6zACytfVnNJJH2ME9gLge6xkgGWrY/TuHMLUXRm0lHkoR9TAdtZ7XA89uuohuFBNlpBnbAnO1axyU38DK4Lihf2OK5AMvnAqAu9Ri9v6gzNGgtilhCYkQctnVJpTpkALNg1LmypmQ== mail-alias-created-date: 1766251435121 Received: from localhost.localdomain (unknown [17.57.155.37]) by p00-icloudmta-asmtp-us-east-2d-60-percent-11 (Postfix) with ESMTPSA id 0F16E19264BF; Thu, 29 Oct 2026 16:29:05 +0000 (UTC) From: Hayato Kiwata To: passt-dev@passt.top Subject: [PATCH] fwd, conf: Roll back to old rules if switching to new ones fails Date: Fri, 30 Oct 2026 01:28:58 +0900 Message-ID: <20261029162858.2199-1-dev@haytok.jp> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-GUID: KiOQtb4Arh3MSWWHJ2P2RzLB_uxEswTf X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDI5MDA2NCBTYWx0ZWRfX4H1v5DA7NFcY 1uz01TEFPQGJBsZWIT21UUq77oBBzvlfyp+WrbCcGSgeiOclVLLmKser64G+rd/vtUWp6de66Yi 2o6OsU8ZQZv9poyEUuFBaiynOVnl/Sauo5qciIDigT0c/e67wyjS3XUKZ7ZFGkSk1uxH6aqGpIs LhtV6nf4mYa9CoShHTQWynCGs7E0L5iFY2OLP/VJJ1lZ9DtLIeaJ8mT0jg+NubuAe7+hMn6P1RI XAD16mZk/Ys19G0Gbo0DIYkGJjBtRJRjoR5Kvxpk4J7zKV0SNKxkwfLEH0Eaf5c1rP+ASCkNWLT rIBk9IjeYBupIh/WL99UrMyB892lM5fDE0e4hbhO5vdebHdc0OA0Q865uga02Y= X-Authority-Info-Out: v=2.4 cv=brZBxUai c=1 sm=1 tr=0 ts=6ae37453 cx=c_apl:c_pps:t_out a=bsP7O+dXZ5uKcj+dsLqiMw==:117 a=bsP7O+dXZ5uKcj+dsLqiMw==:17 a=7tRfvhCesLuWmuHc:21 a=660iZSQnnn4A:10 a=VkNPw1HP01LnGYTKEx00:22 a=pNgXkJcRAAAA:8 a=Hc4DNsaFjqJbdE3gbDQA:9 a=tKe0A8swS_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8PwIQ0SCfCkxHyUZXtZh4qO+QopdwjmlU/WUzaQPFtD9Zhd2eL2MCvzt12 FhjvckwQfGFfjNd5aNFrCYS9fW4ZZWbCocexXfoYq67YkSS0yQAW2FO0E8CDOhVIvfJbUo xh4G543ApjJkvmMngfmcwTscc6yuBzKELNFLXMMNLZSS5K7mu0W1wCZOTuqZ6aFiOtH7lp zVOn4qJnQpZH0tm/XdVU4Ckmfzta28kCf2KcXY10bx8xOM8DgQfA== X-MailFrom: dev@haytok.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: IU75BD5GQUOSD5FEECB3OZ272ELFKQKP X-Message-ID-Hash: IU75BD5GQUOSD5FEECB3OZ272ELFKQKP X-Mailman-Approved-At: Thu, 29 Oct 2026 21:32:29 +0100 CC: 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: If fwd_listen_init() fails while switching to new forwarding rules received from pesto, we currently close the old listening sockets, report an error and keep the (partially bound) new rules. That leaves pasta in a state the user didn't ask for. Make fwd_listen_switch() return the result of fwd_listen_init(), and call it a second time from conf_handler() on failure to switch back to the old rules. Don't reset the count of the old table after closing its sockets, so that the old rules stay in c->fwd_pending and can be restored. The pending tables are cleared by conf_handler() before receiving new rules anyway. Note that reporting the failure to the client is left for a later patch. Link: https://archives.passt.top/passt-dev/20261025153025.600a4fe9@elisabeth/ Signed-off-by: Hayato Kiwata --- This is a follow-up to the discussion on the dropped patch linked above. Tested with: $ pasta --ns-ifname=tap0 --mtu=65520 --config-net --address=10.0.2.100 \ --netmask=24 --gateway=10.0.2.2 --dns-forward=10.0.2.3 --no-map-gw \ --tcp-ns=none --udp-ns=none --ipv4-only --tcp-ports=none \ --udp-ports=none --conf-path=/tmp/.pasta.sock \ -- python3 -m http.server 80 $ 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 $ 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 pasta logs: Listen failed for HOST TCP port 192.0.2.1/8080: Cannot assign requested address Couldn't listen on requested ports Error switching to new forwarding rules and the rule for port 8085 keeps working. Adding another valid rule afterwards works as before. conf.c | 7 ++++++- fwd.c | 10 +++++----- fwd.h | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/conf.c b/conf.c index 149a4c7..0d10ea4 100644 --- a/conf.c +++ b/conf.c @@ -2222,7 +2222,12 @@ void conf_handler(struct ctx *c, uint32_t events) " ", ""); } - fwd_listen_switch(c); + if (fwd_listen_switch(c) < 0) { + err("Error switching to new forwarding rules"); + /* Switch back to old rules (still in c->fwd_pending) */ + if (fwd_listen_switch(c) < 0) + err("Couldn't restore old forwarding rules"); + } } if (events & EPOLLHUP) { diff --git a/fwd.c b/fwd.c index 5679a3d..a081664 100644 --- a/fwd.c +++ b/fwd.c @@ -536,8 +536,10 @@ int fwd_listen_init(const struct ctx *c) /** * fwd_listen_switch() - Switch from current to pending rules table * @c: Execution context + * + * Return: 0 on success, -1 on failure */ -void fwd_listen_switch(struct ctx *c) +int fwd_listen_switch(struct ctx *c) { struct fwd_table *tmp[PIF_NUM_TYPES]; unsigned i; @@ -549,9 +551,8 @@ void fwd_listen_switch(struct ctx *c) if (!fwd) continue; - debug("Flushing %u old %s rules", fwd->count, pif_name(i)); + debug("Flushing %u %s rules", fwd->count, pif_name(i)); fwd_listen_close(fwd); - fwd->count = fwd->sock_count = 0; } /* Swap active and pending tables */ @@ -563,8 +564,7 @@ void fwd_listen_switch(struct ctx *c) memcpy((void *)c->fwd_pending, &tmp, sizeof(c->fwd_pending)); /* Start listening on the new tables */ - if (fwd_listen_init(c) < 0) - err("Error switching to new forwarding rules"); + return fwd_listen_init(c); } /* See enum in kernel's include/net/tcp_states.h */ diff --git a/fwd.h b/fwd.h index b60697d..a6c7bd8 100644 --- a/fwd.h +++ b/fwd.h @@ -61,7 +61,7 @@ int fwd_listen_sync(const struct ctx *c, uint8_t pif, const struct fwd_scan *tcp, const struct fwd_scan *udp); void fwd_listen_close(const struct fwd_table *fwd); int fwd_listen_init(const struct ctx *c); -void fwd_listen_switch(struct ctx *c); +int fwd_listen_switch(struct ctx *c); bool nat_inbound(const struct ctx *c, const union inany_addr *addr, union inany_addr *translated); -- 2.50.1 (Apple Git-155)