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
Subject: Re: [PATCH bpf-next v3 4/5] selftests/bpf: Use connect_to_addr_str in sk_lookup
Date: Thu, 18 Jul 2024 14:45:03 -0700 [thread overview]
Message-ID: <6f22c8bc-8681-4027-a69a-492f418f04e0@linux.dev> (raw)
In-Reply-To: <a41193347fc775f934b60ad8e2dca4cf04177127.1721282219.git.tanggeliang@kylinos.cn>
On 7/17/24 11:22 PM, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> This patch uses the new helper connect_to_addr_str() in make_client()
> instead of using local defined function make_socket() + connect(). This
> local function can be dropped latter.
>
> A new parameter "expect_errno" is added for make_client() too to allow
> different "expect_errno" is passed to make_client(). It is used to check
> with "errno" after invoking connect_to_addr_str().
>
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
> .../selftests/bpf/prog_tests/sk_lookup.c | 26 +++++++------------
> 1 file changed, 10 insertions(+), 16 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c
> index ae87c00867ba..beea7866b37f 100644
> --- a/tools/testing/selftests/bpf/prog_tests/sk_lookup.c
> +++ b/tools/testing/selftests/bpf/prog_tests/sk_lookup.c
> @@ -229,25 +229,19 @@ static int make_server(int sotype, const char *ip, int port,
> return -1;
> }
>
> -static int make_client(int sotype, const char *ip, int port)
> +static int make_client(int sotype, const char *ip, int port, int expect_errno)
> {
> - struct sockaddr_storage addr = {0};
> - int err, fd;
> -
> - fd = make_socket(sotype, ip, port, &addr);
> - if (fd < 0)
> - return -1;
> + int fd;
>
> - err = connect(fd, (void *)&addr, inetaddr_len(&addr));
> - if (CHECK(err, "make_client", "connect")) {
> + fd = connect_to_addr_str(is_ipv6(ip) ? AF_INET6 : AF_INET,
> + sotype, ip, port, NULL);
> + if (CHECK(fd < 0 && (!expect_errno || errno != expect_errno),
> + "make_client", "connect_to_addr_str")) {
> log_err("failed to connect client socket");
> - goto fail;
> + return -1;
> }
>
> return fd;
> -fail:
> - close(fd);
> - return -1;
> }
>
> static __u64 socket_cookie(int fd)
> @@ -646,7 +640,7 @@ static void run_lookup_prog(const struct test *t)
> goto close;
> }
>
> - client_fd = make_client(t->sotype, t->connect_to.ip, t->connect_to.port);
> + client_fd = make_client(t->sotype, t->connect_to.ip, t->connect_to.port, 0);
> if (client_fd < 0)
> goto close;
>
> @@ -1152,7 +1146,7 @@ static void run_sk_assign_connected(struct test_sk_lookup *skel,
> if (server_fd < 0)
> return;
>
> - connected_fd = make_client(sotype, EXT_IP4, EXT_PORT);
> + connected_fd = make_client(sotype, EXT_IP4, EXT_PORT, 0);
> if (connected_fd < 0)
> goto out_close_server;
>
> @@ -1166,7 +1160,7 @@ static void run_sk_assign_connected(struct test_sk_lookup *skel,
> goto out_close_connected;
>
> /* Try to redirect TCP SYN / UDP packet to a connected socket */
> - client_fd = make_client(sotype, EXT_IP4, EXT_PORT);
> + client_fd = make_client(sotype, EXT_IP4, EXT_PORT, 0);
No errno is expected in all these cases. directly call connect_to_addr_str()
instead of calling make_client.
> if (client_fd < 0)
> goto out_unlink_prog;
> if (sotype == SOCK_DGRAM) {
next prev parent reply other threads:[~2024-07-18 21:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-18 6:22 [PATCH bpf-next v3 0/5] use network helpers, part 9 Geliang Tang
2024-07-18 6:22 ` [PATCH bpf-next v3 1/5] selftests/bpf: Drop type of connect_to_fd_opts Geliang Tang
2024-07-18 6:22 ` [PATCH bpf-next v3 2/5] selftests/bpf: Drop must_fail from network_helper_opts Geliang Tang
2024-07-18 21:41 ` Martin KaFai Lau
2024-07-18 6:22 ` [PATCH bpf-next v3 3/5] selftests/bpf: Add connect_to_addr_str helper Geliang Tang
2024-07-18 6:22 ` [PATCH bpf-next v3 4/5] selftests/bpf: Use connect_to_addr_str in sk_lookup Geliang Tang
2024-07-18 21:45 ` Martin KaFai Lau [this message]
2024-07-18 6:22 ` [PATCH bpf-next v3 5/5] selftests/bpf: Drop make_socket " Geliang Tang
2024-07-18 22:38 ` Martin KaFai Lau
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=6f22c8bc-8681-4027-a69a-492f418f04e0@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=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