[PATCH net-next v5 2/4] tcp: rename ECN transmit helper function

From: chia-yu . chang

Date: Mon Nov 30 2026 - 07:57:57 EST


From: Chia-Yu Chang <chia-yu.chang@xxxxxxxxxxxxxxxxxxx>

Rename INET_ECN_xmit_ect_1_negotiation() to
INET_ECN_xmit_negotiation_ect(). The previous name suggests that the
helper always uses ECT(1), while it actually chooses the ECT codepoint
to be used during the ECN negotiation.

This renaming also prepares for the introduction of a similarly named
helper function for established connections in the followup patch.

Signed-off-by: Chia-Yu Chang <chia-yu.chang@xxxxxxxxxxxxxxxxxxx>

---
v5:
- Document detailed comments for INET_ECN_xmit_negotiation_ect()

v3:
- Rename helper to better reflect its behavior
---
include/net/tcp_ecn.h | 25 +++++++++++++++++++++----
net/ipv4/tcp_cong.c | 4 ++--
2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/include/net/tcp_ecn.h b/include/net/tcp_ecn.h
index 865d5c5a7718..3bb0b2f692f4 100644
--- a/include/net/tcp_ecn.h
+++ b/include/net/tcp_ecn.h
@@ -32,8 +32,25 @@ enum tcp_accecn_option {
TCP_ACCECN_OPTION_PERSIST = 3,
};

-/* Apply either ECT(0) or ECT(1) based on TCP_CONG_ECT_1_NEGOTIATION flag */
-static inline void INET_ECN_xmit_ect_1_negotiation(struct sock *sk)
+/**
+ * INET_ECN_xmit_negotiation_ect - set the ECT codepoint used before CA init
+ * @sk: TCP socket
+ *
+ * Mark the socket ECN-capable for the packets sent while ECN is still being
+ * negotiated (SYN, SYN-ACK), i.e. before tcp_init_congestion_control() runs.
+ *
+ * The codepoint is chosen by the congestion control module:
+ * ECT(1) if TCP_CONG_ECT_1_NEGOTIATION is set, otherwise ECT(0).
+ *
+ * This does not decide whether ECT should be sent at all: callers only use
+ * it when the module (TCP_CONG_NEEDS_ECN) or a BPF program asked for ECT
+ * on these packets.
+ *
+ * This changes the socket TOS/tclass, not a single packet, so the codepoint
+ * stays in effect until tcp_init_congestion_control() or tcp_ecn_send()
+ * selects the one used for the established flow.
+ */
+static inline void INET_ECN_xmit_negotiation_ect(struct sock *sk)
{
__INET_ECN_xmit(sk, tcp_ca_ect_1_negotiation(sk));
}
@@ -583,7 +600,7 @@ static inline void tcp_ecn_send_synack(struct sock *sk, struct sk_buff *skb)
TCP_SKB_CB(skb)->tcp_flags &= ~TCPHDR_ECE;
else if (tcp_ca_needs_ecn(sk) ||
tcp_bpf_ca_needs_ecn(sk))
- INET_ECN_xmit_ect_1_negotiation(sk);
+ INET_ECN_xmit_negotiation_ect(sk);

if (tp->ecn_flags & TCP_ECN_MODE_ACCECN) {
TCP_SKB_CB(skb)->tcp_flags &= ~TCPHDR_ACE;
@@ -618,7 +635,7 @@ static inline void tcp_ecn_send_syn(struct sock *sk, struct sk_buff *skb)

if (use_ecn) {
if (tcp_ca_needs_ecn(sk) || bpf_needs_ecn)
- INET_ECN_xmit_ect_1_negotiation(sk);
+ INET_ECN_xmit_negotiation_ect(sk);

TCP_SKB_CB(skb)->tcp_flags |= TCPHDR_ECE | TCPHDR_CWR;
if (use_accecn) {
diff --git a/net/ipv4/tcp_cong.c b/net/ipv4/tcp_cong.c
index e3f462f161dd..3331679c81d7 100644
--- a/net/ipv4/tcp_cong.c
+++ b/net/ipv4/tcp_cong.c
@@ -228,7 +228,7 @@ void tcp_assign_congestion_control(struct sock *sk)

memset(icsk->icsk_ca_priv, 0, sizeof(icsk->icsk_ca_priv));
if (ca->flags & TCP_CONG_NEEDS_ECN)
- INET_ECN_xmit_ect_1_negotiation(sk);
+ INET_ECN_xmit_negotiation_ect(sk);
else
INET_ECN_dontxmit(sk);
}
@@ -258,7 +258,7 @@ static void tcp_reinit_congestion_control(struct sock *sk,
memset(icsk->icsk_ca_priv, 0, sizeof(icsk->icsk_ca_priv));

if (ca->flags & TCP_CONG_NEEDS_ECN)
- INET_ECN_xmit_ect_1_negotiation(sk);
+ INET_ECN_xmit_negotiation_ect(sk);
else
INET_ECN_dontxmit(sk);

--
2.34.1