Re: [PATCH net-next v4 3/4] tcp: add TCP_ECN_SEND_ECT_1 flag for congestion control

From: Eric Dumazet

Date: Thu Nov 19 2026 - 13:48:16 EST


Le jeu. 19 nov. 2026 à 19:01, <chia-yu.chang@xxxxxxxxxxxxxxxxxxx> a écrit :
>
> From: Chia-Yu Chang <chia-yu.chang@xxxxxxxxxxxxxxxxxxx>
>
> This patch introduces the new TCP_ECN_SEND_ECT_1 bit, which enables
> a congestion control module to control whether the connection
> transmits using ECT(1) (if the bit is set) or ECT(0) (otherwise),
> when congestion control is initialized after ECN negotiation.
>
> A congestion control module, such as the upcoming TCP Prague
> using L4S ECN, can set this new TCP_ECN_SEND_ECT_1 bit if it
> wants to send the ECT(1) code point in outgoing IP headers.
>
> Signed-off-by: Chia-Yu Chang <chia-yu.chang@xxxxxxxxxxxxxxxxxxx>
>
> --
> v3:
> - Update commit message
> - Update flag name and helper function name to eliminate confusion
> ---
> include/net/tcp.h | 1 +
> include/net/tcp_ecn.h | 6 ++++++
> net/ipv4/tcp_cong.c | 4 +++-
> net/ipv4/tcp_output.c | 2 +-
> 4 files changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/include/net/tcp.h b/include/net/tcp.h
> index 4b1159e6c125..0242fd6bbb07 100644
> --- a/include/net/tcp.h
> +++ b/include/net/tcp.h
> @@ -428,6 +428,7 @@ static inline void tcp_dec_quickack_mode(struct sock *sk)
> #define TCP_ECN_DEMAND_CWR BIT(2)
> #define TCP_ECN_SEEN BIT(3)
> #define TCP_ECN_MODE_ACCECN BIT(4)
> +#define TCP_ECN_SEND_ECT_1 BIT(5)

Who clears this bit ?

The only place where tp->ecn_flags is reset is tcp_ecn_send_syn().

If a module sets the bit, and the user later switches to another
congestion control with setsockopt(TCP_CONGESTION) on an AccECN
flow, tcp_ecn_send() will keep sending ECT(1) on every packet,
with a classic congestion response.

I do not think we should rely on each module ->release() to
clear it. tcp_reinit_congestion_control() should do it.

>
> #define TCP_ECN_DISABLED 0
> #define TCP_ECN_MODE_PENDING (TCP_ECN_MODE_RFC3168 | TCP_ECN_MODE_ACCECN)
> diff --git a/include/net/tcp_ecn.h b/include/net/tcp_ecn.h
> index 9ca016d98972..ff402cdb988d 100644
> --- a/include/net/tcp_ecn.h
> +++ b/include/net/tcp_ecn.h
> @@ -38,6 +38,12 @@ static inline void INET_ECN_xmit_negotiation_ect(struct sock *sk)
> __INET_ECN_xmit(sk, tcp_ca_ect_1_negotiation(sk));
> }
>
> +/* Apply either ECT(0) or ECT(1) based on TCP_ECN_SEND_ECT_1 flag */
> +static inline void INET_ECN_xmit_established_ect(struct sock *sk)
> +{
> + __INET_ECN_xmit(sk, tcp_sk(sk)->ecn_flags & TCP_ECN_SEND_ECT_1);
> +}
> +
> static inline void tcp_ecn_queue_cwr(struct tcp_sock *tp)
> {
> /* Do not set CWR if in AccECN mode! */
> diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c
> index 3331679c81d7..43b0634f7673 100644
> --- a/net/ipv4/tcp_cong.c
> +++ b/net/ipv4/tcp_cong.c
> @@ -240,7 +240,9 @@ void tcp_init_congestion_control(struct sock *sk)
> tcp_sk(sk)->prior_ssthresh = 0;
> if (icsk->icsk_ca_ops->init)
> icsk->icsk_ca_ops->init(sk);
> - if (tcp_ca_needs_ecn(sk))
> + if (tcp_ca_needs_accecn(sk))
> + INET_ECN_xmit_established_ect(sk);
> + else if (tcp_ca_needs_ecn(sk))
> INET_ECN_xmit(sk);

This only looks at the module flag, not at what was negotiated.

If AccECN negotiation failed (RFC 3168 fallback, or no ECN at all),
we still set ECT(0)/ECT(1) here. Is the module expected to handle
all the fallbacks from its ->init(), like DCTCP does ? If so,
please add a comment, and say it in the changelog.

> else
> INET_ECN_dontxmit(sk);
> diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c
> index 08d0d4a639fe..7b694479095e 100644
> --- a/net/ipv4/tcp_output.c
> +++ b/net/ipv4/tcp_output.c
> @@ -350,7 +350,7 @@ static void tcp_ecn_send(struct sock *sk, struct sk_buff *skb,
> if (tcp_ecn_mode_accecn(tp)) {
> if (!tcp_accecn_ace_fail_recv(tp) &&
> !tcp_accecn_ace_fail_send(tp))
> - INET_ECN_xmit(sk);
> + INET_ECN_xmit_established_ect(sk);
> else
> INET_ECN_dontxmit(sk);
> tcp_accecn_set_ace(tp, skb, th);
> --
> 2.34.1
>