From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202512 header.b=oxoOClIG; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 496B55A0624 for ; Tue, 06 Jan 2026 07:10:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202512; t=1767679848; bh=N2HiSd+3PJrCiboT4f/rErAI+zGFzyeGR3zct60yIBk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oxoOClIGFtlJ/n47nEsgcfUjsFMEJhoafgewz9Xh+7+fl8nWioYkitu5ZS00pIwra O30ZtXkMRMCRYYa/hEbtDbocTrsx92n+dz70az8I6cb8fVvNpySpTTjpnpWmCJD+2D cxo6czM5QkkWT2hXLIQRW6RgwLrh2YCVZpK52c1lFdxyaTgfsF4k6IUDCf6S5ubRiM ZK+YCRlUKmqMVbAx0vZqIsppn91KLgOBYgaD2gt+Cj2Ph7I09xpuwiRB4eyiZBeLG9 epZPbkNg88k8VZ+1NwGu9RtM3DYQyMcNS/SoXdI+h5U8qJ8GLAuFwF2dz450Q/053j +PbiuMQVdZr2A== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4dlglD1kWNz4w26; Tue, 06 Jan 2026 17:10:48 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 2/2] fwd: Minor cleanup to fwd_nat_from_splice() Date: Tue, 6 Jan 2026 17:10:46 +1100 Message-ID: <20260106061046.3623968-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260106061046.3623968-1-david@gibson.dropbear.id.au> References: <20260106061046.3623968-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 5GR5BON2NNCENTTZ4HQTK3SNP3OUTIXU X-Message-ID-Hash: 5GR5BON2NNCENTTZ4HQTK3SNP3OUTIXU X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson 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: The order we do things in this function is slightly odd, and we have a redundant assignment to tgt->oport. Remove that, and re-order for clarity. Signed-off-by: David Gibson --- fwd.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/fwd.c b/fwd.c index 9b701ad0..961c533f 100644 --- a/fwd.c +++ b/fwd.c @@ -660,13 +660,15 @@ uint8_t fwd_nat_from_splice(const struct ctx *c, uint8_t proto, return PIF_NONE; } + /* Preserve the src & dest (loopback) addresses */ + tgt->oaddr = ini->eaddr; tgt->eaddr = ini->oaddr; - /* Preserve the specific loopback address used, but let the kernel pick - * a source port on the target side - */ - tgt->oaddr = ini->eaddr; + /* Let the kernel pick a host side source port */ tgt->oport = 0; + if (proto == IPPROTO_UDP) + /* But for UDP preserve the source port */ + tgt->oport = ini->eport; tgt->eport = ini->oport; if (proto == IPPROTO_TCP) @@ -674,12 +676,6 @@ uint8_t fwd_nat_from_splice(const struct ctx *c, uint8_t proto, else if (proto == IPPROTO_UDP) tgt->eport += c->udp.fwd_out.delta[tgt->eport]; - /* Let the kernel pick a host side source port */ - tgt->oport = 0; - if (proto == IPPROTO_UDP) - /* But for UDP preserve the source port */ - tgt->oport = ini->eport; - return PIF_HOST; } -- 2.52.0