* [PATCH 0/2] Small cleanups to splice forwarding logic
@ 2026-01-06 6:10 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 ` [PATCH 2/2] fwd: Minor cleanup to fwd_nat_from_splice() David Gibson
0 siblings, 2 replies; 3+ messages in thread
From: David Gibson @ 2026-01-06 6:10 UTC (permalink / raw)
To: passt-dev, Stefano Brivio; +Cc: David Gibson
While working on more flexible forwarding stuff, noticed a couple of
warts here.
David Gibson (2):
fwd: Remove now-unnecessary handling of unspecified oaddr from splice
fwd: Minor cleanup to fwd_nat_from_splice()
fwd.c | 25 ++++++++-----------------
1 file changed, 8 insertions(+), 17 deletions(-)
--
2.52.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] fwd: Remove now-unnecessary handling of unspecified oaddr from splice
2026-01-06 6:10 [PATCH 0/2] Small cleanups to splice forwarding logic David Gibson
@ 2026-01-06 6:10 ` David Gibson
2026-01-06 6:10 ` [PATCH 2/2] fwd: Minor cleanup to fwd_nat_from_splice() David Gibson
1 sibling, 0 replies; 3+ messages in thread
From: David Gibson @ 2026-01-06 6:10 UTC (permalink / raw)
To: passt-dev, Stefano Brivio; +Cc: David Gibson
fwd_nat_from_splice() has several cases that deal with the possibility of
ini->oaddr being unspecified. That used to be a possible case, but since
e3c4c4175ce6 ("tcp: Always populate oaddr field for socket initiated
flows") and 59cc89f4cc01 ("udp, udp_flow: Track our specific address on
socket interfaces") we now always populate ini->oaddr with a specified
address for all flows.
Remove the now-unnecessary fallback logic.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
fwd.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/fwd.c b/fwd.c
index 44a0e109..9b701ad0 100644
--- a/fwd.c
+++ b/fwd.c
@@ -650,7 +650,7 @@ uint8_t fwd_nat_from_splice(const struct ctx *c, uint8_t proto,
const struct flowside *ini, struct flowside *tgt)
{
if (!inany_is_loopback(&ini->eaddr) ||
- (!inany_is_loopback(&ini->oaddr) && !inany_is_unspecified(&ini->oaddr))) {
+ !inany_is_loopback(&ini->oaddr)) {
char estr[INANY_ADDRSTRLEN], fstr[INANY_ADDRSTRLEN];
debug("Non loopback address on %s: [%s]:%hu -> [%s]:%hu",
@@ -660,12 +660,7 @@ uint8_t fwd_nat_from_splice(const struct ctx *c, uint8_t proto,
return PIF_NONE;
}
- if (!inany_is_unspecified(&ini->oaddr))
- tgt->eaddr = ini->oaddr;
- else if (inany_v4(&ini->oaddr))
- tgt->eaddr = inany_loopback4;
- else
- tgt->eaddr = inany_loopback6;
+ tgt->eaddr = ini->oaddr;
/* Preserve the specific loopback address used, but let the kernel pick
* a source port on the target side
--
2.52.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] fwd: Minor cleanup to fwd_nat_from_splice()
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
1 sibling, 0 replies; 3+ messages in thread
From: David Gibson @ 2026-01-06 6:10 UTC (permalink / raw)
To: passt-dev, Stefano Brivio; +Cc: David Gibson
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-01-06 6:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/2] fwd: Minor cleanup to fwd_nat_from_splice() David Gibson
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).