public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top, Stefano Brivio <sbrivio@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 2/2] fwd: Minor cleanup to fwd_nat_from_splice()
Date: Tue,  6 Jan 2026 17:10:46 +1100	[thread overview]
Message-ID: <20260106061046.3623968-3-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20260106061046.3623968-1-david@gibson.dropbear.id.au>

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 <david@gibson.dropbear.id.au>
---
 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


      parent reply	other threads:[~2026-01-06  6:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-06  6:10 [PATCH 0/2] Small cleanups to splice forwarding logic David Gibson
2026-01-06  6:10 ` [PATCH 1/2] fwd: Remove now-unnecessary handling of unspecified oaddr from splice David Gibson
2026-01-06  6:10 ` David Gibson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260106061046.3623968-3-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).