[PATCH mptcp-next v3 5/7] mptcp: enable bpf_setsockopt on the master socket
Gang Yan <[email protected]> Mon, 27 Jul 2026 10:28:47 +0800
| Newsgroups | dev.linux.lists.mptcp |
|---|---|
| Message-ID | <[email protected]> |
From: Gang Yan <[email protected]> bpf_setsockopt() currently cannot be used on mptcp master sockets: __bpf_setsockopt() dispatches by level to the protocol-agnostic sol_*_sockopt() helpers, which either reject the msk (sk_protocol == IPPROTO_MPTCP) and the ssk (sk_is_tcp() is false) or bypass mptcp's own dispatch (e.g. SOL_IP going straight to do_ip_setsockopt()). This patch routes any level to mptcp_setsockopt(), which already handles all levels. Signed-off-by: Gang Yan <[email protected]> --- include/net/mptcp.h | 9 +++++++++ net/core/filter.c | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 333bde2a0b76..fcce2b7e9ef9 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -237,6 +237,9 @@ static inline __be32 mptcp_reset_option(const struct sk_buff *skb) } void mptcp_active_detect_blackhole(struct sock *sk, bool expired); + +int mptcp_setsockopt(struct sock *sk, int level, int optname, + sockptr_t optval, unsigned int optlen); #else static inline void mptcp_init(void) @@ -314,6 +317,12 @@ static inline struct request_sock *mptcp_subflow_reqsk_alloc(const struct reques static inline __be32 mptcp_reset_option(const struct sk_buff *skb) { return htonl(0u); } static inline void mptcp_active_detect_blackhole(struct sock *sk, bool expired) { } + +static inline int mptcp_setsockopt(struct sock *sk, int level, int optname, + sockptr_t optval, unsigned int optlen) +{ + return -EINVAL; +} #endif /* CONFIG_MPTCP */ #if IS_ENABLED(CONFIG_MPTCP_IPV6) diff --git a/net/core/filter.c b/net/core/filter.c index b446aa8be5c3..18e650bf7393 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -5683,6 +5683,13 @@ static int __bpf_setsockopt(struct sock *sk, int level, int optname, if (!sk_fullsock(sk)) return -EINVAL; + /* Route any bpf_setsockopt on the mptcp socket to mptcp_setsockopt, + * which handles all levels. + */ + if (IS_ENABLED(CONFIG_MPTCP) && sk->sk_protocol == IPPROTO_MPTCP) + return mptcp_setsockopt(sk, level, optname, + KERNEL_SOCKPTR(optval), optlen); + if (level == SOL_SOCKET) return sol_socket_sockopt(sk, optname, optval, &optlen, false); else if (IS_ENABLED(CONFIG_INET) && level == SOL_IP) -- 2.43.0