From: Martin KaFai Lau <martin.lau@linux.dev>
To: Kui-Feng Lee <kuifeng@meta.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org,
song@kernel.org, kernel-team@meta.com
Subject: Re: [PATCH bpf-next 2/2] selftests/bpf: Calls bpf_setsockopt() on a ktls enabled socket.
Date: Mon, 23 Jan 2023 16:52:35 -0800 [thread overview]
Message-ID: <737b9af6-4e2a-9da7-3968-fcb466e1eb8a@linux.dev> (raw)
In-Reply-To: <20230121025716.3039933-3-kuifeng@meta.com>
On 1/20/23 6:57 PM, Kui-Feng Lee wrote:
> +static void test_ktls(void)
> +{
> + struct tls12_crypto_info_aes_gcm_128 aes128;
> + struct setget_sockopt__bss *bss = skel->bss;
> + int cfd = -1, sfd = -1, fd = -1, ret;
> +
> + memset(bss, 0, sizeof(*bss));
> +
> + sfd = start_server(AF_INET, SOCK_STREAM, addr4_str, 0, 0);
> + if (!ASSERT_GE(sfd, 0, "start_server"))
> + return;
> + fd = connect_to_fd(sfd, 0);
> + if (!ASSERT_GE(fd, 0, "connect_to_fd"))
> + goto err_out;
> +
> + cfd = accept(sfd, NULL, 0);
> + if (!ASSERT_GE(cfd, 0, "accept"))
> + goto err_out;
> +
> + close(sfd);
> + sfd = -1;
> +
> + /* Setup KTLS */
> + ret = setsockopt(fd, IPPROTO_TCP, TCP_ULP, "tls", sizeof("tls"));
> + if (ret != 0) {
nit. ASSERT_OK(ret, ...). It should print the errno also.
> + ASSERT_EQ(errno, ENOENT, "setsockopt return ENOENT");
> + printf("Failure setting TCP_ULP, testing without tls\n");
Then these two ASSERT_EQ and printf are not needed.
> + goto err_out;
> + }
> + ret = setsockopt(cfd, IPPROTO_TCP, TCP_ULP, "tls", sizeof("tls"));
> + if (!ASSERT_EQ(ret, 0, "setsockopt"))
nit. ASSERT_OK.
> + goto err_out;
> +
> + memset(&aes128, 0, sizeof(aes128));
> + aes128.info.version = TLS_1_2_VERSION;
> + aes128.info.cipher_type = TLS_CIPHER_AES_GCM_128;
> +
> + ret = setsockopt(fd, SOL_TLS, TLS_TX, &aes128, sizeof(aes128));
> + if (!ASSERT_EQ(ret, 0, "setsockopt"))
> + goto err_out;
> +
> + ret = setsockopt(cfd, SOL_TLS, TLS_RX, &aes128, sizeof(aes128));
> + if (!ASSERT_EQ(ret, 0, "setsockopt"))
> + goto err_out;
> +
> + /* KTLS is enabled */
> +
> + close(fd);
> + /* At this point, the cfd socket is at the CLOSE_WAIT state
> + * and still run TLS protocol. The test for
> + * BPF_TCP_CLOSE_WAIT should be run at this point.
> + */
> + close(cfd);
> +
> + ASSERT_EQ(bss->nr_listen, 1, "nr_listen");
> + ASSERT_EQ(bss->nr_connect, 1, "nr_connect");
> + ASSERT_EQ(bss->nr_active, 1, "nr_active");
> + ASSERT_EQ(bss->nr_passive, 1, "nr_passive");
> + ASSERT_EQ(bss->nr_socket_post_create, 2, "nr_socket_post_create");
> + ASSERT_EQ(bss->nr_binddev, 2, "nr_bind");
> + ASSERT_EQ(bss->nr_fin_wait1, 1, "nr_fin_wait1");
> + return;
> +
> +err_out:
> + close(fd);
> + close(cfd);
> + close(sfd);
> +}
> +
> void test_setget_sockopt(void)
> {
> cg_fd = test__join_cgroup(CG_NAME);
> @@ -118,6 +188,7 @@ void test_setget_sockopt(void)
> test_tcp(AF_INET);
> test_udp(AF_INET6);
> test_udp(AF_INET);
> + test_ktls();
Although not related to the IPPROTO_IPV6 code path, it seems pretty cheap to
test AF_INET6 also like the above tests?
next prev parent reply other threads:[~2023-01-24 0:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-21 2:57 [PATCH bpf-next 0/2] Enable bpf_setsockopt() on ktls enabled sockets Kui-Feng Lee
2023-01-21 2:57 ` [PATCH bpf-next 1/2] bpf: Check the protocol of a sock to agree the calls to bpf_setsockopt() Kui-Feng Lee
2023-01-24 0:55 ` Martin KaFai Lau
2023-01-21 2:57 ` [PATCH bpf-next 2/2] selftests/bpf: Calls bpf_setsockopt() on a ktls enabled socket Kui-Feng Lee
2023-01-24 0:52 ` Martin KaFai Lau [this message]
2023-01-24 17:11 ` Kui-Feng Lee
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=737b9af6-4e2a-9da7-3968-fcb466e1eb8a@linux.dev \
--to=martin.lau@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kernel-team@meta.com \
--cc=kuifeng@meta.com \
--cc=song@kernel.org \
/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