Re: [PATCH net v3] tcp: fix device binding after failed IPv6 connect

From: Xia Yan

Date: Fri Nov 13 2026 - 06:24:42 EST


Hi Jakub,

v3 restores the binding on native IPv6 error returns from
tcp_v6_connect().
Ordinary handshake failures after it returns 0 may leave the
scope binding set. That is pre-existing behavior.

v3:
https://lore.kernel.org/netdev/20261111113455.284747-1-yanxia@xxxxxxxxxxxxxxxxxxxx/

Would you prefer to keep this fix limited to synchronous errors and
handle disconnect-time rollback, including deferred Fast Open,
separately, or cover both in this series?

In late_failure, v3 restores the binding while the socket can still be
in ehash. Moving the restore after tcp_set_state(TCP_CLOSE) would
instead overwrite a binding set by the CLOSE callback.

Should the socket be unhashed first?

sk->sk_prot->unhash(sk);
WRITE_ONCE(sk->sk_bound_dev_if, old_bound_dev_if);
tcp_set_state(sk, TCP_CLOSE);
inet_bhash2_reset_saddr(sk);

This keeps the restore before bind2 cleanup and lets the CLOSE
callback set the final binding. I haven't tested this ordering yet.

I'll wait for your feedback before preparing v4.

Thanks,
Xia Yan