BPF List
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Geliang Tang <geliang@kernel.org>
Cc: Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Mykola Lysenko <mykolal@fb.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>,
	Geliang Tang <tanggeliang@kylinos.cn>,
	bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
	Stanislav Fomichev <sdf@fomichev.me>
Subject: Re: [PATCH bpf-next v11 7/9] selftests/bpf: Add connect_fd_to_addr_str helper
Date: Wed, 10 Jul 2024 12:20:00 -0700	[thread overview]
Message-ID: <9d3251b3-af0d-40f8-ba92-2b676799da55@linux.dev> (raw)
In-Reply-To: <96f04aa5677d628ad5eae1981565b24bf94c9d77.1720515893.git.tanggeliang@kylinos.cn>

On 7/9/24 2:16 AM, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> Similar to connect_fd_to_fd() helper to connect from a client fd to a
> server fd, this patch adds a new helper connect_fd_to_addr_str() to connect
> from a client fd to a server address. It accepts the server address string
> "addr_str", together with the server family, type and port, as parameters
> instead of using a "server_fd" like connect_fd_to_fd().
> 
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
>   tools/testing/selftests/bpf/network_helpers.c | 21 +++++++++++++++++++
>   tools/testing/selftests/bpf/network_helpers.h |  3 +++
>   2 files changed, 24 insertions(+)
> 
> diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c
> index e0cba4178e41..9758e707b859 100644
> --- a/tools/testing/selftests/bpf/network_helpers.c
> +++ b/tools/testing/selftests/bpf/network_helpers.c
> @@ -388,6 +388,27 @@ int connect_fd_to_fd(int client_fd, int server_fd, int timeout_ms)
>   	return 0;
>   }
>   
> +int connect_fd_to_addr_str(int client_fd, int family, int type,

Similar to the comment in the earlier revision on the existing 
connect_to_fd_opts. The "int type" is redundant of "int client_fd".

and where is the "int type" arg actually used in this new function?

Beside, is it more useful for patch 8 to add connect_to_addr_str() which calls 
socket()/client_socket(), connect(), and then return the client_fd instead?

Something like this?

int connect_to_addr_str(int family, int type, const char *addr_str, __u16 port,
			const struct network_helper_opts *opts)

Patch 1-6 is applied with the mentioned minor changes. Thanks.


> +			   const char *addr_str, __u16 port,
> +			   const struct network_helper_opts *opts)
> +{
> +	struct sockaddr_storage addr;
> +	socklen_t len;
> +
> +	if (!opts)
> +		opts = &default_opts;
> +
> +	if (settimeo(client_fd, opts->timeout_ms))
> +		return -1;
> +
> +	if (make_sockaddr(family, addr_str, port, &addr, &len)) {
> +		log_err("Failed to make server addr");
> +		return -1;
> +	}
> +
> +	return connect_fd_to_addr(client_fd, &addr, len, false);
> +}
> +
>   int make_sockaddr(int family, const char *addr_str, __u16 port,
>   		  struct sockaddr_storage *addr, socklen_t *len)
>   {


  reply	other threads:[~2024-07-10 19:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-09  9:16 [PATCH bpf-next v11 0/9] use network helpers, part 8 Geliang Tang
2024-07-09  9:16 ` [PATCH bpf-next v11 1/9] selftests/bpf: Add backlog for network_helper_opts Geliang Tang
2024-07-09  9:16 ` [PATCH bpf-next v11 2/9] selftests/bpf: Add ASSERT_OK_FD macro Geliang Tang
2024-07-10 19:00   ` Martin KaFai Lau
2024-07-09  9:16 ` [PATCH bpf-next v11 3/9] selftests/bpf: Close fd in error path in drop_on_reuseport Geliang Tang
2024-07-10 19:02   ` Martin KaFai Lau
2024-07-09  9:16 ` [PATCH bpf-next v11 4/9] selftests/bpf: Use start_server_str in sk_lookup Geliang Tang
2024-07-09  9:16 ` [PATCH bpf-next v11 5/9] selftests/bpf: Use start_server_addr " Geliang Tang
2024-07-09  9:16 ` [PATCH bpf-next v11 6/9] selftests/bpf: Use connect_fd_to_fd " Geliang Tang
2024-07-10 19:04   ` Martin KaFai Lau
2024-07-09  9:16 ` [PATCH bpf-next v11 7/9] selftests/bpf: Add connect_fd_to_addr_str helper Geliang Tang
2024-07-10 19:20   ` Martin KaFai Lau [this message]
2024-07-09  9:16 ` [PATCH bpf-next v11 8/9] selftests/bpf: Use connect_fd_to_addr_str in sk_lookup Geliang Tang
2024-07-09  9:16 ` [PATCH bpf-next v11 9/9] selftests/bpf: Drop make_socket " Geliang Tang
2024-07-10 19:00 ` [PATCH bpf-next v11 0/9] use network helpers, part 8 patchwork-bot+netdevbpf

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=9d3251b3-af0d-40f8-ba92-2b676799da55@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=geliang@kernel.org \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mykolal@fb.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=tanggeliang@kylinos.cn \
    --cc=yonghong.song@linux.dev \
    /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