tcp: rehash onto different ECMP path on retransmit timeout
Subsystems (4)
cover tcp: rehash onto different ECMP path on retransmit timeout
I configured an ECMP route across two local interfaces, expecting autoflowlabel to adapt when one of those interfaces is blocked in reaching the destination. However, it did not. This affected SYN, SYN/ACK, and established traffic.
I was able to make this work as I expected it to by calling sk_dst_reset() at times when txhash was updated, and propagating sk_txhash into fl6->mp_hash so fib6_select_path() uses the socket's current hash for ECMP selection.
I expected autoflowlabel to apply to local ECMP routes, and think it should, but am open to feedback if this isn't the right way to do it.
Patch 1 has the kernel changes; patch 2 adds a selftest exercising SYN, SYN/ACK, and established connection rehash over a two-path ECMP topology. The selftest retries a SYN 26 times, so has a tiny (~3e-8) probability of false failure if repeatedly unlucky with ECMP path selection.
Neil Spring (2):
tcp: rehash onto different ECMP path on retransmit timeout
selftests: net: add ECMP rehash test
net/ipv4/tcp_input.c | 4 +- net/ipv4/tcp_minisocks.c | 9 + net/ipv4/tcp_plb.c | 1 + net/ipv4/tcp_timer.c | 1 + net/ipv6/inet6_connection_sock.c | 8 + tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/ecmp_rehash.sh | 354 +++++++++++++++++++++ 7 files changed, 377 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/net/ecmp_rehash.sh
Signature · 1 line
2.52.0
PATCH 1/2 tcp: rehash onto different ECMP path on retransmit timeout
Add sk_dst_reset() alongside sk_rethink_txhash() in the RTO, PLB, and spurious-retrans paths so that the next transmit triggers a fresh route lookup. Propagate sk_txhash into fl6->mp_hash in inet6_csk_route_req() and inet6_csk_route_socket() so fib6_select_path() uses the socket's current hash for ECMP selection.
The ir_iif update in tcp_check_req() covers both IPv4 and IPv6 because it was cleaner than gating on address family; IPv4 is otherwise unaltered, and not having autoflowlabel in IPv4 means I wouldn't expect a new path on timeout.
It is possible that PLB does not need this (that there are other methods of reacting to local congestion); I added the sk_dst_reset for consistency.
--- net/ipv4/tcp_input.c | 4 +++- net/ipv4/tcp_minisocks.c | 9 +++++++++ net/ipv4/tcp_plb.c | 1 + net/ipv4/tcp_timer.c | 1 + net/ipv6/inet6_connection_sock.c | 8 ++++++++ 5 files changed, 22 insertions(+), 1 deletion(-)
net/ipv4/tcp_input.c +3 -1
@@ -5014,8 +5014,10 @@ static void tcp_rcv_spurious_retrans(struct sock *sk, skb->protocol == htons(ETH_P_IPV6) && (tcp_sk(sk)->inet_conn.icsk_ack.lrcv_flowlabel != ntohl(ip6_flowlabel(ipv6_hdr(skb)))) && - sk_rethink_txhash(sk)) + sk_rethink_txhash(sk)) {NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPDUPLICATEDATAREHASH ); +sk_dst_reset (sk); + }/* Save last flowlabel after a spurious retrans. */ tcp_save_lrcv_flowlabel (sk, skb);
net/ipv4/tcp_minisocks.c +9 -0
@@ -750,6 +750,15 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,* Reset timer after retransmitting SYNACK, similar to * the idea of fast retransmit in recovery. */ + +#if IS_ENABLED (CONFIG_IPV6 ) +if (sk->sk_family ==AF_INET6 ) +inet_rsk (req)->ir_iif =tcp_v6_iif (skb); + else +#endif +inet_rsk (req)->ir_iif = +inet_request_bound_dev_if (sk, skb); +if (!tcp_oow_rate_limited (sock_net (sk), skb,LINUX_MIB_TCPACKSKIPPEDSYNRECV , &tcp_rsk (req)->last_oow_ack_time)) {
net/ipv4/tcp_plb.c +1 -0
@@ -79,6 +79,7 @@ void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb)return ;sk_rethink_txhash (sk); +sk_dst_reset (sk); plb->consec_cong_rounds =0 ;tcp_sk (sk)->plb_rehash++;NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPPLBREHASH );
net/ipv4/tcp_timer.c +1 -0
@@ -299,6 +299,7 @@ static int tcp_write_timeout(struct sock *sk)if (sk_rethink_txhash (sk)) { tp->timeout_rehash++;__NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPTIMEOUTREHASH ); +sk_dst_reset (sk); }return 0 ;
net/ipv6/inet6_connection_sock.c +8 -0
@@ -48,6 +48,11 @@ struct dst_entry *inet6_csk_route_req(const struct sock *sk, fl6->flowi6_uid =sk_uid (sk);security_req_classify_flow (req,flowi6_to_flowi_common (fl6)); +if (req->num_retrans) + fl6->mp_hash =jhash_1word (req->num_retrans, + (__force u32 )ireq->ir_rmt_port) + >>1 ; +if (!dst) { dst =ip6_dst_lookup_flow (sock_net (sk), sk, fl6, final_p);if (IS_ERR (dst))
@@ -70,6 +75,9 @@ struct dst_entry *inet6_csk_route_socket(struct sock *sk, fl6->saddr = np->saddr; fl6->flowlabel = np->flow_label;IP6_ECN_flow_xmit (sk, fl6->flowlabel); + +if (sk->sk_txhash) + fl6->mp_hash = sk->sk_txhash >>1 ; fl6->flowi6_oif = sk->sk_bound_dev_if; fl6->flowi6_mark = sk->sk_mark; fl6->fl6_sport = inet->inet_sport;
Signature · 1 line
2.52.0
PATCH 2/2 selftests: net: add ECMP rehash test
In reply to Neil SpringAdd ecmp_rehash.sh to exercise TCP ECMP path re-selection on retransmission timeout. Three tests cover client SYN rehash, server SYN/ACK rehash, and midstream RTO rehash of an established connection over a two-path ECMP topology with one leg blocked by tc.
The SYN test retries 26 times, so has a false negative probability of ~(1/2)^25 ≈ 3e-8.
--- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/ecmp_rehash.sh | 354 +++++++++++++++++++++ 2 files changed, 355 insertions(+) create mode 100755 tools/testing/selftests/net/ecmp_rehash.sh
tools/testing/selftests/net/Makefile +1 -0
@@ -25,6 +25,7 @@ TEST_PROGS := \ cmsg_time.sh \ double_udp_encap.sh \ drop_monitor_tests.sh \ + ecmp_rehash.sh \ fcnal-ipv4.sh \ fcnal-ipv6.sh \ fcnal-other.sh \
tools/testing/selftests/net/ecmp_rehash.sh new file +354 -0
354 lines not on this page · raw message
Signature · 1 line
2.52.0
Quoted 46 lines · Neil Spring
Add
sk_dst_reset()alongsidesk_rethink_txhash()in the RTO, PLB, and spurious-retrans paths so that the next transmit triggers a fresh route lookup. Propagatesk_txhashintofl6->mp_hashininet6_csk_route_req()andinet6_csk_route_socket()sofib6_select_path()uses the socket's current hash for ECMP selection.The
ir_iifupdate intcp_check_req()covers both IPv4 and IPv6 because it was cleaner than gating on address family; IPv4 is otherwise unaltered, and not having autoflowlabel in IPv4 means I wouldn't expect a new path on timeout.It is possible that PLB does not need this (that there are other methods of reacting to local congestion); I added the
sk_dst_resetfor consistency.Signed-off-by Neil Spring <[email protected]>--- net/ipv4/tcp_input.c | 4 +++- net/ipv4/tcp_minisocks.c | 9 +++++++++ net/ipv4/tcp_plb.c | 1 + net/ipv4/tcp_timer.c | 1 + net/ipv6/inet6_connection_sock.c | 8 ++++++++ 5 files changed, 22 insertions(+), 1 deletion(-)net/ipv4/tcp_input.c +3
-1@@ -5014,8 +5014,10 @@ static void tcp_rcv_spurious_retrans(struct sock *sk, skb->protocol == htons(ETH_P_IPV6) && (tcp_sk(sk)->inet_conn.icsk_ack.lrcv_flowlabel != ntohl(ip6_flowlabel(ipv6_hdr(skb)))) && - sk_rethink_txhash(sk)) + sk_rethink_txhash(sk)) {NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPDUPLICATEDATAREHASH ); +sk_dst_reset (sk); + }/* Save last flowlabel after a spurious retrans. */ tcp_save_lrcv_flowlabel (sk, skb);net/ipv4/tcp_minisocks.c +0
-0
net/ipv4/tcp_minisocks.c struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb, · line 753
Quoted 4 lines
net/ipv4/tcp_minisocks.c +1
-0@@ -750,6 +750,15 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,* Reset timer after retransmitting SYNACK, similar to * the idea of fast retransmit in recovery. */ +
What is the following part doing?tcp_v6_init_req() uses something quite different before setting ir_iif A comment explaining the rationale would be nice.
Quoted 40 lines
net/ipv4/tcp_minisocks.c +8
-0+#if IS_ENABLED (CONFIG_IPV6 ) +if (sk->sk_family ==AF_INET6 ) +inet_rsk (req)->ir_iif =tcp_v6_iif (skb); + else +#endif +inet_rsk (req)->ir_iif = +inet_request_bound_dev_if (sk, skb); +if (!tcp_oow_rate_limited (sock_net (sk), skb,LINUX_MIB_TCPACKSKIPPEDSYNRECV , &tcp_rsk (req)->last_oow_ack_time)) {net/ipv4/tcp_plb.c +1
-0@@ -79,6 +79,7 @@ void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb)return ;sk_rethink_txhash (sk); +sk_dst_reset (sk); plb->consec_cong_rounds =0 ;tcp_sk (sk)->plb_rehash++;NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPPLBREHASH );net/ipv4/tcp_timer.c +1
-0@@ -299,6 +299,7 @@ static int tcp_write_timeout(struct sock *sk)if (sk_rethink_txhash (sk)) { tp->timeout_rehash++;__NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPTIMEOUTREHASH ); +sk_dst_reset (sk); }return 0 ;net/ipv6/inet6_connection_sock.c +0
-0
net/ipv6/inet6_connection_sock.c struct dst_entry *inet6_csk_route_req(const struct sock *sk, · line 54
Quoted 7 lines
net/ipv6/inet6_connection_sock.c +4
-0@@ -48,6 +48,11 @@ struct dst_entry *inet6_csk_route_req(const struct sock *sk, fl6->flowi6_uid =sk_uid (sk);security_req_classify_flow (req,flowi6_to_flowi_common (fl6)); +if (req->num_retrans) + fl6->mp_hash =jhash_1word (req->num_retrans, + (__force u32 )ireq->ir_rmt_port) + >>1 ;
Why not setting mp_hash to sk_txhash ?
Why are you using ">> 1" ?
rt6_multipath_hash() seems to be bypassed, it might be time to add a comment there
explaining that mp_hash needs to be 31-bit only...
Perhaps use rt6_multipath_hash() and expand it to use a socket pointer to retrieve sk->sk_txhash when/if possible
instead of yet another flow dissection.
net/ipv6/inet6_connection_sock.c struct dst_entry *inet6_csk_route_socket(struct sock *sk, · line 80
Quoted 11 lines
net/ipv6/inet6_connection_sock.c +4
-0+if (!dst) { dst =ip6_dst_lookup_flow (sock_net (sk), sk, fl6, final_p);if (IS_ERR (dst))@@ -70,6 +75,9 @@ struct dst_entry *inet6_csk_route_socket(struct sock *sk, fl6->saddr = np->saddr; fl6->flowlabel = np->flow_label;IP6_ECN_flow_xmit (sk, fl6->flowlabel); + +if (sk->sk_txhash) + fl6->mp_hash = sk->sk_txhash >>1 ;
Seems inconsistent, and same question about the right shift.
Quoted 6 lines
net/ipv6/inet6_connection_sock.c +0
-1fl6->flowi6_oif = sk->sk_bound_dev_if; fl6->flowi6_mark = sk->sk_mark; fl6->fl6_sport = inet->inet_sport; --2.52.0
Thanks Eric for looking at this; sorry for the duplicate email as I failed to reply all; comments below.
On Tue, Apr 7, 2026 at 6:09=E2=80=AFPM Eric Dumazet <[email protected]> w= rote:
Quoted 1 line
On Tue, Apr 7, 2026 at 5:28=E2=80=AFPM Neil Spring <[email protected]> wr=
ote:
Quoted 25 lines
Quoted 25 lines
Add
sk_dst_reset()alongsidesk_rethink_txhash()in the RTO, PLB, and spurious-retrans paths so that the next transmit triggers a fresh route lookup. Propagatesk_txhashintofl6->mp_hashininet6_csk_route_req()andinet6_csk_route_socket()sofib6_select_path()uses the socket's current hash for ECMP selection.The
ir_iifupdate intcp_check_req()covers both IPv4 and IPv6 because it was cleaner than gating on address family; IPv4 is otherwise unaltered, and not having autoflowlabel in IPv4 means I wouldn't expect a new path on timeout.It is possible that PLB does not need this (that there are other methods of reacting to local congestion); I added the
sk_dst_resetfor consistency.Signed-off-by Neil Spring <[email protected]>--- net/ipv4/tcp_input.c | 4 +++- net/ipv4/tcp_minisocks.c | 9 +++++++++ net/ipv4/tcp_plb.c | 1 + net/ipv4/tcp_timer.c | 1 + net/ipv6/inet6_connection_sock.c | 8 ++++++++ 5 files changed, 22 insertions(+), 1 deletion(-)
Quoted 5 lines
net/ipv4/tcp_input.c static void tcp_rcv_spurious_retrans(struct sock=
Quoted 5 lines
net/ipv4/tcp_input.c +0
-0@@ -5014,8 +5014,10 @@ static void tcp_rcv_spurious_retrans(struct sock=
*sk,
Quoted 6 lines
net/ipv4/tcp_input.c static void tcp_rcv_spurious_retrans(struct sock *sk,
Quoted 6 lines
net/ipv4/tcp_input.c +1
-1skb->protocol =3D=3D htons(ETH_P_IPV6) && (tcp_sk(sk)->inet_conn.icsk_ack.lrcv_flowlabel !=3D ntohl(ip6_flowlabel(ipv6_hdr(skb)))) && - sk_rethink_txhash(sk)) + sk_rethink_txhash(sk)) { NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPDUPLICATEDATAR=
EHASH);
Quoted 10 lines
net/ipv4/tcp_minisocks.c struct sock *tcp_check_req(struct sock *sk, struct=
Quoted 10 lines
net/ipv4/tcp_input.c +2
-0+sk_dst_reset (sk); + }/* Save last flowlabel after a spurious retrans. */ tcp_save_lrcv_flowlabel (sk, skb);net/ipv4/tcp_minisocks.c +0
-0@@ -750,6 +750,15 @@ struct sock *tcp_check_req(struct sock *sk, struct=
sk_buff *skb,
Quoted 8 lines
net/ipv4/tcp_minisocks.c struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb, · line 753
Quoted 4 lines
net/ipv4/tcp_minisocks.c +1
-0* Reset timer after retransmitting SYNACK, similar to * the idea of fast retransmit in recovery. */ +What is the following part doing?
tcp_v6_init_req()uses something quite different before settingir_iifA comment explaining the rationale would be nice.
Comment added in v2. The behavior I thought I observed was that the ir_iif goes into fl6->flowi6_oif in inet6_csk_route_req(), limiting options to any next hop on that interface, so if we received a retransmitted syn on a new interface, we should try to use the new interface for the response.
Quoted 11 lines
net/ipv4/tcp_minisocks.c struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
Quoted 11 lines
net/ipv4/tcp_minisocks.c +8
-0+#if IS_ENABLED (CONFIG_IPV6 ) + if (sk->sk_family =3D=3D AF_INET6) + inet_rsk(req)->ir_iif =3D tcp_v6_iif(skb); + else +#endif + inet_rsk(req)->ir_iif =3D +inet_request_bound_dev_if (sk, skb); + if (!tcp_oow_rate_limited(sock_net(sk), skb, LINUX_MIB_TCPACKSKIPPEDSYNREC=
V,
Quoted 1 line
net/ipv4/tcp_minisocks.c struct sock *tcp_check_req(struct sock *sk, struct= · line 764
Quoted 1 line
net/ipv4/tcp_minisocks.c +0
-0&tcp_rsk(req)->last_oow_ack_t=
ime)) {
Quoted 5 lines
net/ipv4/tcp_plb.c void tcp_plb_check_rehash(struct sock *sk, struct tcp=
Quoted 5 lines
net/ipv4/tcp_plb.c +0
-0@@ -79,6 +79,7 @@ void tcp_plb_check_rehash(struct sock *sk, struct tcp=
_plb_state *plb)
Quoted 15 lines
Quoted 12 lines
net/ipv4/tcp_plb.c +1
-0return ;sk_rethink_txhash (sk); +sk_dst_reset (sk); plb->consec_cong_rounds =3D 0;tcp_sk (sk)->plb_rehash++;NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPPLBREHASH );net/ipv4/tcp_timer.c +0
-0net/ipv4/tcp_timer.c static int tcp_write_timeout(struct sock *sk) · line 301
Quoted 3 lines
net/ipv4/tcp_timer.c +0
-0@@ -299,6 +299,7 @@ static int tcp_write_timeout(struct sock *sk) if (sk_rethink_txhash(sk)) { tp->timeout_rehash++; __NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPTIMEOUTREHAS=
H);
Quoted 5 lines
net/ipv6/inet6_connecti=
Quoted 5 lines
net/ipv4/tcp_timer.c +1
-0+sk_dst_reset (sk); }return 0 ;net/ipv6/inet6_connecti= renamed from net/ipv6/inet6_connection_sock.c +0
-0
on_sock.c
Quoted 4 lines
net/ipv6/inet6_connection_sock.c struct dst_entry *inet6_csk_route_req(const struct s=
Quoted 4 lines
index
37534e116899..2fe753bb38b4100644net/ipv6/inet6_connection_sock.c +0
-0@@ -48,6 +48,11 @@ struct dst_entry *inet6_csk_route_req(const struct s=
ock *sk,
Quoted 6 lines
net/ipv6/inet6_connection_sock.c struct dst_entry *inet6_csk_route_req(const struct sock *sk,
Quoted 6 lines
net/ipv6/inet6_connection_sock.c +3
-0fl6->flowi6_uid =3D sk_uid(sk);security_req_classify_flow (req,flowi6_to_flowi_common (fl6)); +if (req->num_retrans) + fl6->mp_hash =3D jhash_1word(req->num_retrans, + (__force u32)ireq->ir_rmt_po=
rt)
Quoted 3 lines
net/ipv6/inet6_connection_sock.c struct dst_entry *inet6_csk_route_req(const struct sock *sk, · line 54
Quoted 1 line
net/ipv6/inet6_connection_sock.c +1
-0+ >> 1;Why not setting
mp_hashtosk_txhash?
To be honest, I was trying to avoid adding #include <tcp.h> to the top of inet6_connection_sock.c, which is needed to get tcp_rsk(req)->txhash, but that does make better code, using that in v2.
Quoted 1 line
Why are you using ">> 1" ?
The >> 1 is due to rt6_multipath_hash returning its computed value shifted right one before going into mp_hash in route.c sites. I understood mp_hash can't have the high bit set and still work due to fib6_select_path treating it as a signed integer when comparing to fib_nh_upper_bound.
Quoted 7 lines
rt6_multipath_hash()seems to be bypassed, it might be time to add a comment there
explaining thatmp_hashneeds to be 31-bit only...Perhaps use
rt6_multipath_hash()and expand it to use a socket pointer to retrievesk->sk_txhashwhen/if possible
instead of yet another flow dissection.
I think thyour comment above (grabbing txhash) avoids the dissection.
Quoted 4 lines
net/ipv6/inet6_connection_sock.c struct dst_entry *inet6_csk_route_req(const struct sock *sk,
Quoted 4 lines
net/ipv6/inet6_connection_sock.c +1
-0+ if (!dst) { dst =3D ip6_dst_lookup_flow(sock_net(sk), sk, fl6, fina=
l_p);
Quoted 2 lines
net/ipv6/inet6_connection_sock.c struct dst_entry *inet6_csk_route_socket(struct sock =
Quoted 2 lines
net/ipv6/inet6_connection_sock.c +0
-0if (IS_ERR (dst))@@ -70,6 +75,9 @@ struct dst_entry *inet6_csk_route_socket(struct sock =
*sk,
Quoted 8 lines
net/ipv6/inet6_connection_sock.c struct dst_entry *inet6_csk_route_socket(struct sock *sk,
Quoted 6 lines
net/ipv6/inet6_connection_sock.c +3
-0fl6->saddr =3D np->saddr; fl6->flowlabel =3D np->flow_label;IP6_ECN_flow_xmit (sk, fl6->flowlabel); + +if (sk->sk_txhash) + fl6->mp_hash =3D sk->sk_txhash >> 1;Seems inconsistent, and same question about the right shift.
Adding comment and standardizing on
* tcp_rsk(req)->txhash >> 1 for request sockets,
* sk->sk_txhash >> 1 for established sockets.
Quoted 8 lines
Quoted 8 lines
net/ipv6/inet6_connection_sock.c +0
-1fl6->flowi6_oif =3D sk->sk_bound_dev_if; fl6->flowi6_mark =3D sk->sk_mark; fl6->fl6_sport =3D inet->inet_sport; --2.52.0
Quoted 139 lines · Eric Dumazet
Quoted 2 lines
Quoted 46 lines · Neil Spring
Add
sk_dst_reset()alongsidesk_rethink_txhash()in the RTO, PLB, and spurious-retrans paths so that the next transmit triggers a fresh route lookup. Propagatesk_txhashintofl6->mp_hashininet6_csk_route_req()andinet6_csk_route_socket()sofib6_select_path()uses the socket's current hash for ECMP selection.The
ir_iifupdate intcp_check_req()covers both IPv4 and IPv6 because it was cleaner than gating on address family; IPv4 is otherwise unaltered, and not having autoflowlabel in IPv4 means I wouldn't expect a new path on timeout.It is possible that PLB does not need this (that there are other methods of reacting to local congestion); I added the
sk_dst_resetfor consistency.Signed-off-by Neil Spring <[email protected]>--- net/ipv4/tcp_input.c | 4 +++- net/ipv4/tcp_minisocks.c | 9 +++++++++ net/ipv4/tcp_plb.c | 1 + net/ipv4/tcp_timer.c | 1 + net/ipv6/inet6_connection_sock.c | 8 ++++++++ 5 files changed, 22 insertions(+), 1 deletion(-)net/ipv4/tcp_input.c +3
-1@@ -5014,8 +5014,10 @@ static void tcp_rcv_spurious_retrans(struct sock *sk, skb->protocol == htons(ETH_P_IPV6) && (tcp_sk(sk)->inet_conn.icsk_ack.lrcv_flowlabel != ntohl(ip6_flowlabel(ipv6_hdr(skb)))) && - sk_rethink_txhash(sk)) + sk_rethink_txhash(sk)) {NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPDUPLICATEDATAREHASH ); +sk_dst_reset (sk); + }/* Save last flowlabel after a spurious retrans. */ tcp_save_lrcv_flowlabel (sk, skb);net/ipv4/tcp_minisocks.c +0
-0net/ipv4/tcp_minisocks.c struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb, · line 753
Quoted 4 lines
net/ipv4/tcp_minisocks.c +1
-0@@ -750,6 +750,15 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,* Reset timer after retransmitting SYNACK, similar to * the idea of fast retransmit in recovery. */ +What is the following part doing?
tcp_v6_init_req()uses something quite different before settingir_iifA comment explaining the rationale would be nice.Quoted 40 lines
net/ipv4/tcp_minisocks.c +8
-0+#if IS_ENABLED (CONFIG_IPV6 ) +if (sk->sk_family ==AF_INET6 ) +inet_rsk (req)->ir_iif =tcp_v6_iif (skb); + else +#endif +inet_rsk (req)->ir_iif = +inet_request_bound_dev_if (sk, skb); +if (!tcp_oow_rate_limited (sock_net (sk), skb,LINUX_MIB_TCPACKSKIPPEDSYNRECV , &tcp_rsk (req)->last_oow_ack_time)) {net/ipv4/tcp_plb.c +1
-0@@ -79,6 +79,7 @@ void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb)return ;sk_rethink_txhash (sk); +sk_dst_reset (sk); plb->consec_cong_rounds =0 ;tcp_sk (sk)->plb_rehash++;NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPPLBREHASH );net/ipv4/tcp_timer.c +1
-0@@ -299,6 +299,7 @@ static int tcp_write_timeout(struct sock *sk)if (sk_rethink_txhash (sk)) { tp->timeout_rehash++;__NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPTIMEOUTREHASH ); +sk_dst_reset (sk); }return 0 ;net/ipv6/inet6_connection_sock.c +0
-0net/ipv6/inet6_connection_sock.c struct dst_entry *inet6_csk_route_req(const struct sock *sk, · line 54
Quoted 7 lines
net/ipv6/inet6_connection_sock.c +4
-0@@ -48,6 +48,11 @@ struct dst_entry *inet6_csk_route_req(const struct sock *sk, fl6->flowi6_uid =sk_uid (sk);security_req_classify_flow (req,flowi6_to_flowi_common (fl6)); +if (req->num_retrans) + fl6->mp_hash =jhash_1word (req->num_retrans, + (__force u32 )ireq->ir_rmt_port) + >>1 ;Why not setting
mp_hashtosk_txhash?Why are you using ">> 1" ?
rt6_multipath_hash()seems to be bypassed, it might be time to add a comment there
explaining thatmp_hashneeds to be 31-bit only...Perhaps use
rt6_multipath_hash()and expand it to use a socket pointer to retrievesk->sk_txhashwhen/if possible
instead of yet another flow dissection.net/ipv6/inet6_connection_sock.c struct dst_entry *inet6_csk_route_socket(struct sock *sk, · line 80
Quoted 11 lines
net/ipv6/inet6_connection_sock.c +4
-0+if (!dst) { dst =ip6_dst_lookup_flow (sock_net (sk), sk, fl6, final_p);if (IS_ERR (dst))@@ -70,6 +75,9 @@ struct dst_entry *inet6_csk_route_socket(struct sock *sk, fl6->saddr = np->saddr; fl6->flowlabel = np->flow_label;IP6_ECN_flow_xmit (sk, fl6->flowlabel); + +if (sk->sk_txhash) + fl6->mp_hash = sk->sk_txhash >>1 ;Seems inconsistent, and same question about the right shift.
Quoted 6 lines
net/ipv6/inet6_connection_sock.c +0
-1fl6->flowi6_oif = sk->sk_bound_dev_if; fl6->flowi6_mark = sk->sk_mark; fl6->fl6_sport = inet->inet_sport; --2.52.0
v2 cover tcp: rehash onto different ECMP path on retransmit timeout
In reply to Neil SpringMake TCP retransmission timeouts select a different ECMP path for IPv6.
Currently sk_rethink_txhash() changes the socket's txhash on RTO, but the cached route is reused and the new hash is not propagated into the ECMP path selection logic. This series adds sk_dst_reset() alongside sk_rethink_txhash() to force a fresh route lookup, and sets fl6->mp_hash from sk_txhash so fib6_select_path() picks a path based on the new hash.
Three selftest scenarios verify the behavior: SYN retransmission, SYN/ACK retransmission (server-side), and midstream RTO on an established connection.
Changes since v1:
- Use tcp_rsk(req)->txhash instead of jhash_1word(req->num_retrans, ...) for ECMP path selection in inet6_csk_route_req(), making the request socket path consistent with the established socket path (Eric Dumazet)
- Add comments explaining the >> 1 shift for 31-bit mp_hash range
- Add comment explaining the ir_iif update rationale in tcp_check_req()
- Use socat -u (unidirectional) in selftest to avoid SIGPIPE race
- Increase tcp_syn_retries and tcp_syn_linear_timeouts to 25 for better rehash coverage; add tcp_synack_retries=10 on the server
Neil Spring (2):
tcp: rehash onto different ECMP path on retransmit timeout
selftests: net: add ECMP rehash test
net/ipv4/tcp_input.c | 4 +- net/ipv4/tcp_minisocks.c | 13 + net/ipv4/tcp_plb.c | 1 + net/ipv4/tcp_timer.c | 1 + net/ipv6/inet6_connection_sock.c | 11 + tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/ecmp_rehash.sh | 361 +++++++++++++++++++++ 7 files changed, 391 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/net/ecmp_rehash.sh
Signature · 1 line
2.52.0
PATCH v2 1/2 tcp: rehash onto different ECMP path on retransmit timeout
Add sk_dst_reset() alongside sk_rethink_txhash() in the RTO, PLB, and spurious-retrans paths so that the next transmit triggers a fresh route lookup. Propagate sk_txhash into fl6->mp_hash in inet6_csk_route_req() and inet6_csk_route_socket() so fib6_select_path() uses the socket's current hash for ECMP selection.
The ir_iif update in tcp_check_req() covers both IPv4 and IPv6 because it was cleaner than gating on address family; IPv4 is otherwise unaltered, and not having autoflowlabel in IPv4 means I wouldn't expect a new path on timeout.
It is possible that PLB does not need this (that there are other methods of reacting to local congestion); I added the sk_dst_reset for consistency.
--- net/ipv4/tcp_input.c | 4 +++- net/ipv4/tcp_minisocks.c | 13 +++++++++++++ net/ipv4/tcp_plb.c | 1 + net/ipv4/tcp_timer.c | 1 + net/ipv6/inet6_connection_sock.c | 11 +++++++++++ 5 files changed, 29 insertions(+), 1 deletion(-)
net/ipv4/tcp_input.c +3 -1
@@ -5014,8 +5014,10 @@ static void tcp_rcv_spurious_retrans(struct sock *sk, skb->protocol == htons(ETH_P_IPV6) && (tcp_sk(sk)->inet_conn.icsk_ack.lrcv_flowlabel != ntohl(ip6_flowlabel(ipv6_hdr(skb)))) && - sk_rethink_txhash(sk)) + sk_rethink_txhash(sk)) {NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPDUPLICATEDATAREHASH ); +sk_dst_reset (sk); + }/* Save last flowlabel after a spurious retrans. */ tcp_save_lrcv_flowlabel (sk, skb);
net/ipv4/tcp_minisocks.c +13 -0
@@ -750,6 +750,19 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,* Reset timer after retransmitting SYNACK, similar to * the idea of fast retransmit in recovery. */ + +/* Update ir_iif to match the interface the retransmitted +* SYN arrived on; inet6_csk_route_req() uses this as +* flowi6_oif, constraining ECMP path for the SYN/ACK. +*/ +#if IS_ENABLED (CONFIG_IPV6 ) +if (sk->sk_family ==AF_INET6 ) +inet_rsk (req)->ir_iif =tcp_v6_iif (skb); + else +#endif +inet_rsk (req)->ir_iif = +inet_request_bound_dev_if (sk, skb); +if (!tcp_oow_rate_limited (sock_net (sk), skb,LINUX_MIB_TCPACKSKIPPEDSYNRECV , &tcp_rsk (req)->last_oow_ack_time)) {
net/ipv4/tcp_plb.c +1 -0
@@ -79,6 +79,7 @@ void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb)return ;sk_rethink_txhash (sk); +sk_dst_reset (sk); plb->consec_cong_rounds =0 ;tcp_sk (sk)->plb_rehash++;NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPPLBREHASH );
net/ipv4/tcp_timer.c +1 -0
@@ -299,6 +299,7 @@ static int tcp_write_timeout(struct sock *sk)if (sk_rethink_txhash (sk)) { tp->timeout_rehash++;__NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPTIMEOUTREHASH ); +sk_dst_reset (sk); }return 0 ;
net/ipv6/inet6_connection_sock.c +11 -0
@@ -14,6 +14,7 @@#include <linux/ipv6.h> #include <linux/jhash.h> #include <linux/slab.h> +#include <linux/tcp.h> #include <net/addrconf.h> #include <net/inet_connection_sock.h>
@@ -48,6 +49,12 @@ struct dst_entry *inet6_csk_route_req(const struct sock *sk, fl6->flowi6_uid =sk_uid (sk);security_req_classify_flow (req,flowi6_to_flowi_common (fl6)); +/* Use the request socket's txhash (re-rolled by tcp_rtx_synack()) +* for ECMP path selection; >> 1 for 31-bit mp_hash range. +*/ +if (tcp_rsk (req)->txhash) + fl6->mp_hash =tcp_rsk (req)->txhash >>1 ; +if (!dst) { dst =ip6_dst_lookup_flow (sock_net (sk), sk, fl6, final_p);if (IS_ERR (dst))
@@ -70,6 +77,10 @@ struct dst_entry *inet6_csk_route_socket(struct sock *sk, fl6->saddr = np->saddr; fl6->flowlabel = np->flow_label;IP6_ECN_flow_xmit (sk, fl6->flowlabel); + +/* >> 1 for 31-bit mp_hash range matching nhc_upper_bound. */ +if (sk->sk_txhash) + fl6->mp_hash = sk->sk_txhash >>1 ; fl6->flowi6_oif = sk->sk_bound_dev_if; fl6->flowi6_mark = sk->sk_mark; fl6->fl6_sport = inet->inet_sport;
Signature · 1 line
2.52.0
PATCH v2 2/2 selftests: net: add ECMP rehash test
In reply to Neil SpringAdd ecmp_rehash.sh to exercise TCP ECMP path re-selection on retransmission timeout. Three tests cover client SYN rehash, server SYN/ACK rehash, and midstream RTO rehash of an established connection over a two-path ECMP topology with one leg blocked by tc.
The SYN test retries 26 times, so has a false negative probability of ~(1/2)^25 ≈ 3e-8.
--- tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/ecmp_rehash.sh | 361 +++++++++++++++++++++ 2 files changed, 362 insertions(+) create mode 100755 tools/testing/selftests/net/ecmp_rehash.sh
tools/testing/selftests/net/Makefile +1 -0
@@ -25,6 +25,7 @@ TEST_PROGS := \ cmsg_time.sh \ double_udp_encap.sh \ drop_monitor_tests.sh \ + ecmp_rehash.sh \ fcnal-ipv4.sh \ fcnal-ipv6.sh \ fcnal-other.sh \
tools/testing/selftests/net/ecmp_rehash.sh new file +361 -0
361 lines not on this page · raw message
Signature · 1 line
2.52.0
Quoted 12 lines · Neil Spring
Add
sk_dst_reset()alongsidesk_rethink_txhash()in the RTO, PLB, and spurious-retrans paths so that the next transmit triggers a fresh route lookup. Propagatesk_txhashintofl6->mp_hashininet6_csk_route_req()andinet6_csk_route_socket()sofib6_select_path()uses the socket's current hash for ECMP selection.The
ir_iifupdate intcp_check_req()covers both IPv4 and IPv6 because it was cleaner than gating on address family; IPv4 is otherwise unaltered, and not having autoflowlabel in IPv4 means I wouldn't expect a new path on timeout.
Quoted 5 lines
It is possible that PLB does not need this (that there are other methods of reacting to local congestion); I added the
sk_dst_resetfor consistency.Signed-off-by Neil Spring <[email protected]>
Please make sure to wait ~24 hours between sending a new version.
Documentation/process/maintainer-netdev.rst
Quoted 29 lines
--- net/ipv4/tcp_input.c | 4 +++- net/ipv4/tcp_minisocks.c | 13 +++++++++++++ net/ipv4/tcp_plb.c | 1 + net/ipv4/tcp_timer.c | 1 + net/ipv6/inet6_connection_sock.c | 11 +++++++++++ 5 files changed, 29 insertions(+), 1 deletion(-)net/ipv4/tcp_input.c +3
-1@@ -5014,8 +5014,10 @@ static void tcp_rcv_spurious_retrans(struct sock *sk, skb->protocol == htons(ETH_P_IPV6) && (tcp_sk(sk)->inet_conn.icsk_ack.lrcv_flowlabel != ntohl(ip6_flowlabel(ipv6_hdr(skb)))) && - sk_rethink_txhash(sk)) + sk_rethink_txhash(sk)) {NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPDUPLICATEDATAREHASH ); +sk_dst_reset (sk); + }/* Save last flowlabel after a spurious retrans. */ tcp_save_lrcv_flowlabel (sk, skb);net/ipv4/tcp_minisocks.c +0
-0
net/ipv4/tcp_minisocks.c struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb, · line 757
Quoted 8 lines
net/ipv4/tcp_minisocks.c +5
-0@@ -750,6 +750,19 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,* Reset timer after retransmitting SYNACK, similar to * the idea of fast retransmit in recovery. */ + +/* Update ir_iif to match the interface the retransmitted +* SYN arrived on; inet6_csk_route_req() uses this as +* flowi6_oif, constraining ECMP path for the SYN/ACK. +*/
Please put this part in a separate patch.
Explain why it is important that the SYN/ACK is sent on the same interface ?
What happens if it is not ?
Why are we keeping tcp_v6_init_req() part? Would it be dead code ?
/* So that link locals have meaning */
if ((!sk_listener->sk_bound_dev_if || l3_slave) &&
ipv6_addr_type(&ireq->ir_v6_rmt_addr) & IPV6_ADDR_LINKLOCAL)
ireq->ir_iif = tcp_v6_iif(skb);Quoted 61 lines
net/ipv4/tcp_minisocks.c +8
-0+#if IS_ENABLED (CONFIG_IPV6 ) +if (sk->sk_family ==AF_INET6 ) +inet_rsk (req)->ir_iif =tcp_v6_iif (skb); + else +#endif +inet_rsk (req)->ir_iif = +inet_request_bound_dev_if (sk, skb); +if (!tcp_oow_rate_limited (sock_net (sk), skb,LINUX_MIB_TCPACKSKIPPEDSYNRECV , &tcp_rsk (req)->last_oow_ack_time)) {net/ipv4/tcp_plb.c +1
-0@@ -79,6 +79,7 @@ void tcp_plb_check_rehash(struct sock *sk, struct tcp_plb_state *plb)return ;sk_rethink_txhash (sk); +sk_dst_reset (sk); plb->consec_cong_rounds =0 ;tcp_sk (sk)->plb_rehash++;NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPPLBREHASH );net/ipv4/tcp_timer.c +1
-0@@ -299,6 +299,7 @@ static int tcp_write_timeout(struct sock *sk)if (sk_rethink_txhash (sk)) { tp->timeout_rehash++;__NET_INC_STATS (sock_net (sk),LINUX_MIB_TCPTIMEOUTREHASH ); +sk_dst_reset (sk); }return 0 ;net/ipv6/inet6_connection_sock.c +7
-0@@ -14,6 +14,7 @@#include <linux/ipv6.h> #include <linux/jhash.h> #include <linux/slab.h> +#include <linux/tcp.h> #include <net/addrconf.h> #include <net/inet_connection_sock.h> @@ -48,6 +49,12 @@ struct dst_entry *inet6_csk_route_req(const struct sock *sk, fl6->flowi6_uid =sk_uid (sk);security_req_classify_flow (req,flowi6_to_flowi_common (fl6)); +/* Use the request socket's txhash (re-rolled by tcp_rtx_synack()) +* for ECMP path selection; >> 1 for 31-bit mp_hash range. +*/ +if (tcp_rsk (req)->txhash) + fl6->mp_hash =tcp_rsk (req)->txhash >>1 ; +if (!dst) { dst =ip6_dst_lookup_flow (sock_net (sk), sk, fl6, final_p);if (IS_ERR (dst))
net/ipv6/inet6_connection_sock.c struct dst_entry *inet6_csk_route_socket(struct sock *sk, · line 82
Quoted 6 lines
net/ipv6/inet6_connection_sock.c +3
-0@@ -70,6 +77,10 @@ struct dst_entry *inet6_csk_route_socket(struct sock *sk, fl6->saddr = np->saddr; fl6->flowlabel = np->flow_label;IP6_ECN_flow_xmit (sk, fl6->flowlabel); + +/* >> 1 for 31-bit mp_hash range matching nhc_upper_bound. */ +if (sk->sk_txhash)
Why is the test needed ?
Note that because of the right shift , sk_txhash == 1 would become 0 anyway.
Quoted 7 lines
net/ipv6/inet6_connection_sock.c +1
-1+ fl6->mp_hash = sk->sk_txhash >>1 ; fl6->flowi6_oif = sk->sk_bound_dev_if; fl6->flowi6_mark = sk->sk_mark; fl6->fl6_sport = inet->inet_sport; --2.52.0
Neal Cardwell
maintainerQuoted 14 lines · Eric Dumazet
Quoted 12 lines · Neil Spring
Add
sk_dst_reset()alongsidesk_rethink_txhash()in the RTO, PLB, and spurious-retrans paths so that the next transmit triggers a fresh route lookup. Propagatesk_txhashintofl6->mp_hashininet6_csk_route_req()andinet6_csk_route_socket()sofib6_select_path()uses the socket's current hash for ECMP selection.The
ir_iifupdate intcp_check_req()covers both IPv4 and IPv6 because it was cleaner than gating on address family; IPv4 is otherwise unaltered, and not having autoflowlabel in IPv4 means I wouldn't expect a new path on timeout.
Quoted 5 lines
Quoted 5 lines
It is possible that PLB does not need this (that there are other methods of reacting to local congestion); I added the
sk_dst_resetfor consistency.Signed-off-by Neil Spring <[email protected]>
For the next rev, I would suggest in the commit titles to rephrase "ECMP" as "local ECMP" (e.g., rather than "tcp: rehash onto different ECMP path on retransmit timeout" using "tcp: rehash onto different local ECMP path on retransmit timeout").
Rationale: the existing Protective ReRoute ( from 3acf3ec3f4b0f "tcp:
Change txhash on every SYN and RTO retransmit" and discussed in
https://dl.acm.org/doi/10.1145/3603269.3604867 ) already changes flow labels as an attempt to change the ECMP/WCMP path in the middle of the network. So I found the original titles (like "tcp: rehash onto different ECMP path on retransmit timeout") a little confusing, since they read a bit like they are saying they implement something that is already implemented. :-)
Thanks,
neal
Jakub Kicinski
maintainerRe: [PATCH net-next v2 2/2] selftests: net: add ECMP rehash test
In reply to Neil SpringQuoted 7 lines · On Wed, 8 Apr 2026 00:05:14 -0700 Neil Spring wrote:
Add
ecmp_rehash.shto exercise TCP ECMP path re-selection on retransmission timeout. Three tests cover client SYN rehash, server SYN/ACK rehash, and midstream RTO rehash of an established connection over a two-path ECMP topology with one leg blocked by tc.The SYN test retries 26 times, so has a false negative probability of ~(1/2)^25 ≈ 3e-8.
I think this is failing in netdev CI:
TAP version 13
1..1
# timeout set to 3600 # selftests: net: ecmp_rehash.sh # 30.31 [+30.31] TEST: ECMP RTO rehash: establish with blocked paths [FAIL] # 30.31 [+0.00] SYNs did not appear on both paths (rehash not working) # 30.32 [+0.01] 2026/04/07 23:36:18 socat[18706] W exiting on signal 15 # 33.44 [+3.12] 2026/04/07 23:36:21 socat[21325] E read(7, 0x560db4041000, 8192): Connection reset by peer # 33.45 [+0.01] TEST: ECMP SYN/ACK rehash: blocked return path [ OK ] # 33.45 [+0.01] 2026/04/07 23:36:21 socat[21137] W exiting on signal 15 # 34.76 [+1.31] 51TEST: ECMP midstream rehash: block active path [FAIL] # 99.81 [+65.04] data transfer failed after blocking veth0a # 99.82 [+0.01] 2026/04/07 23:37:27 socat[21345] W exiting on signal 15 not ok 1 selftests: net: ecmp_rehash.sh # exit=1
Also please start a new thread when you post v3.