Skip to contentSkip to conversation

net/sched: sch_cake: fix NAT destination port not being updated in cake_update_flowkeys

PATCH Applied Dudu Lu 3 participants 3 messages Apr 13 – Apr 16

Subsystems (4)
lore
Share & tools
lore

Dudu Lu

author
#0 lore raw

PATCH v2 1/1 net/sched: sch_cake: fix NAT destination port not being updated in cake_update_flowkeys

cake_update_flowkeys() is supposed to update the flow dissector keys with the NAT-translated addresses and ports from conntrack, so that CAKE's per-flow fairness correctly identifies post-NAT flows as belonging to the same connection.

For the source port, this works correctly:

    keys->ports.src = port;

But for the destination port, the assignment is reversed:

    port = keys->ports.dst;

This means the NAT destination port is never updated in the flow keys. As a result, when multiple connections are NATed to the same destination, CAKE treats them as separate flows because the original (pre-NAT) destination ports differ. This breaks CAKE's NAT-aware flow isolation when using the "nat" mode.

The bug was introduced in commit b0c19ed6088a ("sch_cake: Take advantage of skb->hash where appropriate") which refactored the original direct assignment into a compare-and-conditionally-update pattern, but wrote the destination port update backwards.

Fix by reversing the assignment direction to match the source port pattern.

Fixes b0c19ed6088a ("sch_cake: Take advantage of skb->hash where appropriate")
---
 net/sched/sch_cake.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_cake.c +1 -1
index 9efe23f8371b..4ac6c36ca6e4 100644
@@ -619,7 +619,7 @@ static bool cake_update_flowkeys(struct flow_keys *keys,
 		}
 		port = rev ? tuple.src.u.all : tuple.dst.u.all;
 		if (port != keys->ports.dst) {
-			port = keys->ports.dst;
+			keys->ports.dst = port;
 			upd = true;
 		}
 	}
Signature · 1 line
2.39.3 (Apple Git-145)
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 22 lines · Dudu Lu

cake_update_flowkeys() is supposed to update the flow dissector keys with the NAT-translated addresses and ports from conntrack, so that CAKE's per-flow fairness correctly identifies post-NAT flows as belonging to the same connection.

For the source port, this works correctly:

    keys->ports.src = port;

But for the destination port, the assignment is reversed:

    port = keys->ports.dst;

This means the NAT destination port is never updated in the flow keys. As a result, when multiple connections are NATed to the same destination, CAKE treats them as separate flows because the original (pre-NAT) destination ports differ. This breaks CAKE's NAT-aware flow isolation when using the "nat" mode.

The bug was introduced in commit b0c19ed6088a ("sch_cake: Take advantage of skb->hash where appropriate") which refactored the original direct assignment into a compare-and-conditionally-update pattern, but wrote the destination port update backwards.

Quoted 5 lines

Fix by reversing the assignment direction to match the source port pattern.

Fixes b0c19ed6088a ("sch_cake: Take advantage of skb->hash where appropriate")

Thank you for the fix!

#2 lore raw
In reply to Dudu Lu
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 9 lines · On Mon, 13 Apr 2026 19:00:41 +0800 you wrote:

cake_update_flowkeys() is supposed to update the flow dissector keys with the NAT-translated addresses and ports from conntrack, so that CAKE's per-flow fairness correctly identifies post-NAT flows as belonging to the same connection.

For the source port, this works correctly:

    keys->ports.src = port;

[...]

Here is the summary with links:
- [v2] net/sched: sch_cake: fix NAT destination port not being updated in cake_update_flowkeys

    https://git.kernel.org/netdev/net/c/f9e406647069

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html