[PATCH] mptcp: Align mptcp_inet6_sk with other protocols

Pedro Falcato posted 1 patch 9 months, 1 week ago
There is a newer version of this series
net/mptcp/protocol.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] mptcp: Align mptcp_inet6_sk with other protocols
Posted by Pedro Falcato 9 months, 1 week ago
Ever since commit f5f80e32de12 ("ipv6: remove hard coded limitation on
ipv6_pinfo") that protocols stopped using the old "obj_size -
sizeof(struct ipv6_pinfo)" way of grabbing ipv6_pinfo, that severely
restricted struct layout and caused fun, hard to see issues.

However, mptcp_inet6_sk wasn't fixed (unlike tcp_inet6_sk). Do so.
The non-cloned sockets already do the right thing using
ipv6_pinfo_offset + the generic IPv6 code.

Signed-off-by: Pedro Falcato <pfalcato@suse.de>
---
 net/mptcp/protocol.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 26ffa06c21e8..c4fd558307f2 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -3142,9 +3142,9 @@ static int mptcp_disconnect(struct sock *sk, int flags)
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
 static struct ipv6_pinfo *mptcp_inet6_sk(const struct sock *sk)
 {
-	unsigned int offset = sizeof(struct mptcp6_sock) - sizeof(struct ipv6_pinfo);
+	struct mptcp6_sock *msk6 = container_of(mptcp_sk(sk), struct mptcp6_sock, msk);
 
-	return (struct ipv6_pinfo *)(((u8 *)sk) + offset);
+	return &msk6->np;
 }
 
 static void mptcp_copy_ip6_options(struct sock *newsk, const struct sock *sk)
-- 
2.49.0
Re: [PATCH] mptcp: Align mptcp_inet6_sk with other protocols
Posted by patchwork-bot+netdevbpf@kernel.org 9 months, 1 week ago
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 30 Apr 2025 16:45:41 +0100 you wrote:
> Ever since commit f5f80e32de12 ("ipv6: remove hard coded limitation on
> ipv6_pinfo") that protocols stopped using the old "obj_size -
> sizeof(struct ipv6_pinfo)" way of grabbing ipv6_pinfo, that severely
> restricted struct layout and caused fun, hard to see issues.
> 
> However, mptcp_inet6_sk wasn't fixed (unlike tcp_inet6_sk). Do so.
> The non-cloned sockets already do the right thing using
> ipv6_pinfo_offset + the generic IPv6 code.
> 
> [...]

Here is the summary with links:
  - mptcp: Align mptcp_inet6_sk with other protocols
    https://git.kernel.org/netdev/net-next/c/a2f6476ed18a

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Re: [PATCH] mptcp: Align mptcp_inet6_sk with other protocols
Posted by Matthieu Baerts 9 months, 1 week ago
Hi Pedro,

On 30/04/2025 17:45, Pedro Falcato wrote:
> Ever since commit f5f80e32de12 ("ipv6: remove hard coded limitation on
> ipv6_pinfo") that protocols stopped using the old "obj_size -
> sizeof(struct ipv6_pinfo)" way of grabbing ipv6_pinfo, that severely
> restricted struct layout and caused fun, hard to see issues.
> 
> However, mptcp_inet6_sk wasn't fixed (unlike tcp_inet6_sk). Do so.
> The non-cloned sockets already do the right thing using
> ipv6_pinfo_offset + the generic IPv6 code.
> 
> Signed-off-by: Pedro Falcato <pfalcato@suse.de>
> ---
>  net/mptcp/protocol.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 26ffa06c21e8..c4fd558307f2 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -3142,9 +3142,9 @@ static int mptcp_disconnect(struct sock *sk, int flags)
>  #if IS_ENABLED(CONFIG_MPTCP_IPV6)
>  static struct ipv6_pinfo *mptcp_inet6_sk(const struct sock *sk)
>  {
> -	unsigned int offset = sizeof(struct mptcp6_sock) - sizeof(struct ipv6_pinfo);
> +	struct mptcp6_sock *msk6 = container_of(mptcp_sk(sk), struct mptcp6_sock, msk);
>  
> -	return (struct ipv6_pinfo *)(((u8 *)sk) + offset);
> +	return &msk6->np;

Thank you for suggesting this! Good idea, that's clearer!

Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>

@Netdev maintainers: this can be applied in net-next directly.

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.