From: Gang Yan <gang.yan@linux.dev>
To: mptcp@lists.linux.dev
Cc: pabeni@redhat.com, Gang Yan <yangang@kylinos.cn>
Subject: [PATCH mptcp-next 4/5] mptcp: add TCP_CONNECT_CB sock_ops hook
Date: Mon, 13 Jul 2026 17:57:34 +0800 [thread overview]
Message-ID: <20260713095735.1222033-5-gang.yan@linux.dev> (raw)
In-Reply-To: <20260713095735.1222033-1-gang.yan@linux.dev>
From: Gang Yan <yangang@kylinos.cn>
This patch adds a helper named 'mptcp_call_bpf' like tcp_call_bpf.
Invoke the new helper from mptcp_connect() with
BPF_SOCK_OPS_TCP_CONNECT_CB, placed after the subflow lock is acquired
and before tcp_connect(). At this point the msk lock is held by
__inet_stream_connect(), mirroring the placement of TCP_CONNECT_CB in
tcp_v4_connect()/tcp_v6_connect().
Signed-off-by: Gang Yan <yangang@kylinos.cn>
---
net/mptcp/protocol.c | 6 ++++++
net/mptcp/protocol.h | 30 ++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index ffcf5a1788f6..837bb76e5c2d 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -4149,6 +4149,12 @@ static int mptcp_connect(struct sock *sk, struct sockaddr_unsized *uaddr,
if (!msk->fastopening)
lock_sock(ssk);
+ /* Notify cgroup BPF on the msk before initiating the subflow connect.
+ * Mirrors BPF_SOCK_OPS_TCP_CONNECT_CB; msk lock is held by the
+ * caller (__inet_stream_connect) and ssk is held before.
+ */
+ mptcp_call_bpf(sk, BPF_SOCK_OPS_TCP_CONNECT_CB, 0, NULL);
+
/* the following mirrors closely a very small chunk of code from
* __inet_stream_connect()
*/
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index da40c6f3705f..b4640ba83a8b 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -1374,4 +1374,34 @@ mptcp_token_join_cookie_init_state(struct mptcp_subflow_request_sock *subflow_re
static inline void mptcp_join_cookie_init(void) {}
#endif
+#ifdef CONFIG_BPF_JIT
+static inline int mptcp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args)
+{
+ struct bpf_sock_ops_kern sock_ops;
+ int ret;
+
+ memset(&sock_ops, 0, offsetof(struct bpf_sock_ops_kern, temp));
+
+ if (sk_fullsock(sk)) {
+ sock_ops.is_fullsock = 1;
+ sock_ops.is_locked_tcp_sock = 1;
+ sock_owned_by_me(sk);
+ }
+
+ sock_ops.sk = sk;
+ sock_ops.op = op;
+
+ if (nargs > 0)
+ memcpy(sock_ops.args, args, nargs * sizeof(*args));
+
+ ret = BPF_CGROUP_RUN_PROG_SOCK_OPS(&sock_ops);
+ return ret == 0 ? sock_ops.reply : -1;
+}
+#else
+static inline int mptcp_call_bpf(struct sock *sk, int op, u32 nargs, u32 *args)
+{
+ return -1;
+}
+#endif
+
#endif /* __MPTCP_PROTOCOL_H */
--
2.43.0
next prev parent reply other threads:[~2026-07-13 9:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-13 9:57 [PATCH mptcp-next 0/5] mptcp: add bpf_setsockopt support in Gang Yan
2026-07-13 9:57 ` [PATCH mptcp-next 1/5] mptcp: use sockopt_lock/release_sock in sockopt Gang Yan
2026-07-13 9:57 ` [PATCH mptcp-next 2/5] mptcp: reject sockopt requiring ssks' lock in BPF context Gang Yan
2026-07-13 9:57 ` [PATCH mptcp-next 3/5] mptcp: enable bpf_setsockopt on the master socket Gang Yan
2026-07-13 9:57 ` Gang Yan [this message]
2026-07-13 9:57 ` [PATCH mptcp-next 5/5] selftests: bpf: verify mptcp bpf_setsockopt from TCP_CONNECT_CB Gang Yan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260713095735.1222033-5-gang.yan@linux.dev \
--to=gang.yan@linux.dev \
--cc=mptcp@lists.linux.dev \
--cc=pabeni@redhat.com \
--cc=yangang@kylinos.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox