MPTCP Linux Development
 help / color / mirror / Atom feed
From: Matthieu Baerts <matttbe@kernel.org>
To: Gang Yan <yangang@kylinos.cn>, mptcp@lists.linux.dev
Cc: Geliang Tang <geliang@kernel.org>
Subject: Re: [mptcp-next v2 5/7] selftests: mptcp: add a helper to get subflow_info
Date: Tue, 22 Apr 2025 15:23:32 +0200	[thread overview]
Message-ID: <c737fb9f-d3a8-45b1-87bf-afb7d3e57ca9@kernel.org> (raw)
In-Reply-To: <376ac5afbb35463387e8db2f009ff5b628cd69c7.1744793332.git.yangang@kylinos.cn>

Hello,

On 16/04/2025 10:59, Gang Yan wrote:
> This patch adds 'get_subflow_info' in 'mptcp_diag', which can check whether
> a TCP connection is an MPTCP subflow based on the "INET_ULP_INFO_MPTCP"
> with tcp_diag method.
> 
> Co-developed-by: Geliang Tang <geliang@kernel.org>
> Signed-off-by: Geliang Tang <geliang@kernel.org>
> Signed-off-by: Gang Yan <yangang@kylinos.cn>
> ---
>  .../testing/selftests/net/mptcp/mptcp_diag.c  | 86 ++++++++++++++++++-
>  1 file changed, 84 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_diag.c b/tools/testing/selftests/net/mptcp/mptcp_diag.c
> index 2116b40bc927..28b1704d0c78 100644
> --- a/tools/testing/selftests/net/mptcp/mptcp_diag.c
> +++ b/tools/testing/selftests/net/mptcp/mptcp_diag.c
> @@ -8,6 +8,7 @@
>  #include <sys/socket.h>
>  #include <netinet/in.h>
>  #include <linux/tcp.h>
> +#include <arpa/inet.h>
>  
>  #include <unistd.h>
>  #include <stdlib.h>
> @@ -19,8 +20,13 @@
>  #define IPPROTO_MPTCP 262
>  #endif
>  
> +#define parse_rtattr_nested(tb, max, rta) \
> +	(parse_rtattr_flags((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta), \
> +			    NLA_F_NESTED))
> +
>  struct params {
>  	__u32 target_token;
> +	char subflow_addr[1024];

detail: maybe add a 's': subflow_addrs.

>  };
>  
>  struct mptcp_info {

(...)

> @@ -244,6 +285,41 @@ static void get_mptcpinfo(__u32 token)
>  	close(fd);
>  }
>  
> +static void get_subflow_info(char *subflow_addr)
> +{
> +	struct inet_diag_req_v2 r = {
> +		.sdiag_family           = AF_INET,
> +		.sdiag_protocol         = IPPROTO_TCP,
> +	};
> +	int sport, dport;
> +	char saddr[64];	// Take ipv6 into consideration

Detail: the comments are usually with the "/* ... */" style. You can
also remove the comment and declare both [sd]addr on the same line I think.

> +	char daddr[64];
> +	int ret;
> +	int fd;
> +
> +	ret = sscanf(subflow_addr, "%s %d %s %d", saddr, &sport, daddr, &dport);
> +	if (ret != 4)
> +		die_perror("IP PORT Pairs has style problems!");
> +
> +	printf("%s:%d -> %s:%d\n", saddr, sport, daddr, dport);
> +
> +	fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG);
> +	if (fd < 0)
> +		die_perror("Netlink socket");
> +
> +	r.id.idiag_cookie[0] = INET_DIAG_NOCOOKIE;
> +	r.id.idiag_cookie[1] = INET_DIAG_NOCOOKIE;

Can you not set it above, when declaring 'r'? Same for 'idiag_ext'.

> +	r.id.idiag_sport = htons(sport);
> +	r.id.idiag_dport = htons(dport);
> +	r.id.idiag_if = 0;

Do you need to explicitly set it to 0? Is it not 0 by default?

> +
> +	inet_pton(AF_INET, saddr, &r.id.idiag_src);
> +	inet_pton(AF_INET, daddr, &r.id.idiag_dst);
> +	r.idiag_ext |= (1 << (INET_DIAG_INFO - 1));
> +	send_query(fd, &r, IPPROTO_TCP);
> +	recv_nlmsg(fd, IPPROTO_TCP);
> +}
> +
>  static void parse_opts(int argc, char **argv, struct params *p)
>  {
>  	int c;

(...)

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


  reply	other threads:[~2025-04-22 13:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-16  8:59 [mptcp-next v2 0/7] Add 'dump_subflow' test in selftests Gang Yan
2025-04-16  8:59 ` [mptcp-next v2 1/7] selftests: mptcp: add struct params in mptcp_diag Gang Yan
2025-04-16  8:59 ` [mptcp-next v2 2/7] selftests: mptcp: refactor send_query parameters for code clarity Gang Yan
2025-04-22 13:22   ` Matthieu Baerts
2025-04-16  8:59 ` [mptcp-next v2 3/7] selftests: mptcp: refine the 'iovlen' handling logic Gang Yan
2025-04-22 13:22   ` Matthieu Baerts
2025-04-16  8:59 ` [mptcp-next v2 4/7] selftests: mptcp: refactor NLMSG handling with 'proto' Gang Yan
2025-04-16  8:59 ` [mptcp-next v2 5/7] selftests: mptcp: add a helper to get subflow_info Gang Yan
2025-04-22 13:23   ` Matthieu Baerts [this message]
2025-04-16  8:59 ` [mptcp-next v2 6/7] selftests: mptcp: add a helper to print subflow_info Gang Yan
2025-04-22 13:23   ` Matthieu Baerts
2025-04-16  8:59 ` [mptcp-next v2 7/7] selftests: mptcp: add chk_sublfow in diag.sh Gang Yan
2025-04-22 13:24   ` Matthieu Baerts
2025-04-16 10:20 ` [mptcp-next v2 0/7] Add 'dump_subflow' test in selftests MPTCP CI
2025-04-22 13:22 ` 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=c737fb9f-d3a8-45b1-87bf-afb7d3e57ca9@kernel.org \
    --to=matttbe@kernel.org \
    --cc=geliang@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --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