Re: [PATCH bpf-next v10 1/2] bpf: tcp: add ecn_init callback to bpf_tcp_ops for per-connection ECN

From: bot+bpf-ci

Date: Fri Nov 27 2026 - 09:04:19 EST


> bpf: tcp: add ecn_init callback to bpf_tcp_ops for per-connection ECN

TL;DR:
- Commit message may misdescribe why syncookies skip ecn_init (no listener,
not no request sock); a comment is suggested
- Design question: Kuniyuki's v9 concerns (route attribute, callback cost) may
be unresolved

> bpf: tcp: add ecn_init callback to bpf_tcp_ops for per-connection ECN
>
> [ ... ]
> the default via bpf_get_retval(); an out-of-range return keeps it. With
> syncookies no request_sock is created, so the program is not invoked and
> the sysctl and route decide as before. No negotiated-mode state is
> stored; the decision taken at handshake time stands for the connection.
> [ ... ]

Is this accurate? In tcp_conn_request() a request sock is still allocated
when syncookies are in use, and tcp_ecn_create_request() still runs on it
and reaches tcp_ecn_init_bpf():

req = inet_reqsk_alloc(rsk_ops, sk, !want_cookie);
...
tcp_ecn_create_request(req, skb, sk, dst);

The program appears to be skipped only because a syncookie request sock is
allocated without a listener (attach_listener is false, so rsk_listener is
NULL). That makes sk_to_full_sk() return NULL inside bpf_tcp_ops_call_int():

struct sock *__sk = sk_to_full_sk(sk);
...
if (__sk) {

If the program did run on a cookie SYN, its ecn_ok decision would be encoded
in the cookie timestamp, but the ACK path re-validates it with
cookie_ecn_ok(), which reads only the sysctl and the route.

Could the commit message describe the actual mechanism (a request sock with
no listener, so sk_to_full_sk() returns NULL)? Would a short comment at the
tcp_ecn_create_request() call site also help keep the two paths from
silently disagreeing later?

> diff --git a/include/net/tcp.h b/include/net/tcp.h
> --- a/include/net/tcp.h
> +++ b/include/net/tcp.h

[ ... ]

> @@ -3035,6 +3035,12 @@ struct bpf_tcp_ops {
> */
> int (*rwnd_init)(struct sock *sk, struct request_sock *req);
>
> + /* Should return the ECN variant to negotiate in this handshake:
> + * one of net.ipv4.tcp_ecn values. bpf_get_retval() has the sysctl.
> + * @req as in timeout_init().
> + */
> + int (*ecn_init)(struct sock *sk, struct request_sock *req);
> +

Kuniyuki Iwashima raised design concerns on v9 that do not look fully
resolved.

He asked why ip-rule (or VRF) with a per-route attribute cannot be used,
noting that a route attribute would also work with syncookies:

> Why can't ip-rule (or VRF) be used with a per-route attribute ? Also, a
> route attribute would work with syncookie. ... one concern would be that we
> end up adding more single-purpose stateless callbacks during 3WHS, which
> could be more expensive than stateful solution.

The v10 respin only adjusted the commit message and applied his nits. Was
there a reply on the callback cost question, or from Amery Hung whom he
asked for input? Is ecn_init() still preferred over a stateful approach
such as rwnd_init() plus a kfunc, given that syncookies still bypass the
callback?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/46008849646