MPTCP Linux Development
 help / color / mirror / Atom feed
From: Matthieu Baerts <matttbe@kernel.org>
To: Geliang Tang <geliang@kernel.org>, mptcp@lists.linux.dev
Cc: Geliang Tang <tanggeliang@kylinos.cn>
Subject: Re: [PATCH mptcp-next v4 1/5] mptcp: update bpf_mptcp_sock_from_subflow
Date: Tue, 10 Dec 2024 12:43:55 +0100	[thread overview]
Message-ID: <63a651c3-0b8a-470f-a283-f70ae9c87870@kernel.org> (raw)
In-Reply-To: <8f9c34611d46f96a0047928ac41b385faf743805.1733733573.git.tanggeliang@kylinos.cn>

Hi Geliang,

On 09/12/2024 09:47, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> The input parameter of bpf_mptcp_sock_from_subflow() is an msk subsocket
> of type IPPROTO_TCP. This patch extends it to accept an IPPROTO_MPTCP
> socket. With this change, the function name bpf_mptcp_sock_from_subflow
> is no longer appropriate, and it is renamed to bpf_mptcp_sock_from_sock.

It took me a bit of time to find the reason: why do you need this, why
not adding a new helper, especially because you don't directly use it in
this series.

Please always clearly mention the reason, probably the most important
bit in a commit message, even if it is obvious to you. I then suggest
having a (hopefully) clearer commit message:

================================== 8< ==================================
bpf: extend bpf_skc_to_mptcp_sock to MPTCP sock

Currently, bpf_skc_to_mptcp_sock() can only be used with sockets that
are MPTCP subflows: TCP sockets with tp->is_mptcp, created by the kernel
from an MPTCP socket (IPPROTO_MPTCP). Typically used with BPF sock_ops
operators.

Here, this helper is extended to support MPTCP sockets, the ones created
by the userspace (IPPROTO_MPTCP). This is useful for BPF hooks involving
these sockets, e.g. [gs]etsocktopt.

bpf_skc_to_mptcp_sock() uses bpf_mptcp_sock_from_subflow(). The former
suggests any MPTCP type/subtype can be used, but the latter only accepts
subflow ones. So bpf_mptcp_sock_from_subflow is modified here to support
MPTCP socket, and renamed to avoid confusions.
================================== 8< ==================================

WDYT? Here the reason (bpf_skc_to_mptcp_sock supporting MPTCP sockets)
is explained, and the title is clearer ("update X" is too vague).

(...)

> diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c
> index e9db856972cb..a0f49af85d57 100644
> --- a/net/mptcp/bpf.c
> +++ b/net/mptcp/bpf.c
> @@ -188,8 +188,10 @@ static struct bpf_struct_ops bpf_mptcp_sched_ops = {
>  };
>  #endif /* CONFIG_BPF_JIT */
>  
> -struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk)
> +struct mptcp_sock *bpf_mptcp_sock_from_sock(struct sock *sk)
>  {
> +	if (sk && sk_fullsock(sk) && sk->sk_protocol == IPPROTO_MPTCP)
> +		return mptcp_sk(sk);
>  	if (sk && sk_fullsock(sk) && sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk))
>  		return mptcp_sk(mptcp_subflow_ctx(sk)->conn);

Maybe we should avoid repeating some checks?

  if (unlikely(!sk || !sk_fullsock(sk)))
      return NULL;

  if (sk->sk_protocol == IPPROTO_MPTCP)
      return mptcp_sk(sk);

  if (sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk))
      return mptcp_sk(mptcp_subflow_ctx(sk)->conn);

  return NULL;



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


  reply	other threads:[~2024-12-10 11:43 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-09  8:47 [PATCH mptcp-next v4 0/5] Squash to "Add mptcp_subflow bpf_iter support" Geliang Tang
2024-12-09  8:47 ` [PATCH mptcp-next v4 1/5] mptcp: update bpf_mptcp_sock_from_subflow Geliang Tang
2024-12-10 11:43   ` Matthieu Baerts [this message]
2024-12-09  8:47 ` [PATCH mptcp-next v4 2/5] bpf: Allow use of skc_to_mptcp_sock in cg_sockopt Geliang Tang
2024-12-10 11:44   ` Matthieu Baerts
2024-12-09  8:47 ` [PATCH mptcp-next v4 3/5] Squash to "bpf: Register mptcp common kfunc set" Geliang Tang
2024-12-10 11:46   ` Matthieu Baerts
2024-12-09  8:47 ` [PATCH mptcp-next v4 4/5] Squash to "bpf: Add mptcp_subflow bpf_iter" Geliang Tang
2024-12-10 11:48   ` Matthieu Baerts
2024-12-11  3:42     ` Geliang Tang
2024-12-09  8:47 ` [PATCH mptcp-next v4 5/5] Squash to "selftests/bpf: Add mptcp_subflow bpf_iter subtest" Geliang Tang
2024-12-09  9:52 ` [PATCH mptcp-next v4 0/5] Squash to "Add mptcp_subflow bpf_iter support" MPTCP CI
2024-12-10 11:42 ` Matthieu Baerts

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=63a651c3-0b8a-470f-a283-f70ae9c87870@kernel.org \
    --to=matttbe@kernel.org \
    --cc=geliang@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=tanggeliang@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