From nobody Fri Nov 22 01:30:39 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 536D816F271 for ; Thu, 22 Aug 2024 09:23:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318583; cv=none; b=ZZx7KJrUc+2XOn/03gEl1i2wUscD4PcXm529isRS4jx5oqdY0w0Enfz9g4QEamj1NHPZks7Synpd73HNwgu0RcP63ggFWlpDorYKznVUASgeQH97cobybLcxA+m+vCrtL7loIm0ct2eU0UXZS9C07Rq6HzNGmqkDxjhL3TD1hSY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318583; c=relaxed/simple; bh=3YBsv84w4lrU4OmbMelhgmMuJXJl6kxTL5qbkP/gLBE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Adm/R2vpXiIqFncFi3vItbNIz6R/jP6kg1cnQxCfsLcK+/IajVrAbZncF1mLSG0GqLZxYD9Ypdnv069V+fx57wSONI1F3cx4z9tqzaQtlI7wTy7UQ8J1LowKxPRK5EmdW1JE5Z9JsPeFg2yvZV7TyIkMVDfUOVuAt+aZCpVPoA8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aY5eLBg4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aY5eLBg4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89A56C4AF09; Thu, 22 Aug 2024 09:23:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724318583; bh=3YBsv84w4lrU4OmbMelhgmMuJXJl6kxTL5qbkP/gLBE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aY5eLBg4vwkw5wJvqKQyp8W/ATr6Y2t95+3oDaiaVPsVtpqeI9EW4L2+unyJfomKm fKNXyLg5QaM60yr+L+VDo/YfdPKDsyL4rKq9A9piF3FZYnDgiQ0KzAqZPoW6fav0K7 MnF5KZ2fH6yW/Lq5kc9SbuNrkymnIeRA27R+Uvabfx3DxZy2YcwMj6z5ez6TTUfBCx xQuho08cHTrGWAf4Y074tmGIgdNiSFilPDmMLlIsMjtt51d4bZVzrV6UVKVGj/8IBc 9qMSoU/IVnXz84vhgJnlsHSg87a8Oun0Nsn6krzFtZU45xtFxxEO0IdV7pdswL4vBt X1ciInzBWsv/w== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 1/2] Squash to "selftests/bpf: Add mptcp subflow subtest" Date: Thu, 22 Aug 2024 17:22:50 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Drop ss_search() from run_subflow(). Now ss_search() are only used by bpf_sched tests. It will be dropped in next step. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 38 +++++-------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing= /selftests/bpf/prog_tests/mptcp.c index 73adc58cd776..d4c5209fbfaf 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -368,22 +368,9 @@ static int endpoint_init(char *flags) return -1; } =20 -static int _ss_search(char *src, char *dst, char *port, char *keyword) +static void run_subflow(void) { - return SYS_NOFAIL("ip netns exec %s ss -enita src %s dst %s %s %d | grep = -q '%s'", - NS_TEST, src, dst, port, PORT_1, keyword); -} - -static int ss_search(char *src, char *keyword) -{ - return _ss_search(src, ADDR_1, "dport", keyword); -} - -static void run_subflow(char *new) -{ - int server_fd, client_fd, err; - char cc[TCP_CA_NAME_MAX]; - socklen_t len; + int server_fd, client_fd; =20 server_fd =3D start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0); if (!ASSERT_GE(server_fd, 0, "start_mptcp_server")) @@ -393,19 +380,8 @@ static void run_subflow(char *new) if (!ASSERT_GE(client_fd, 0, "connect to fd")) goto close_server; =20 - len =3D sizeof(cc); - err =3D getsockopt(server_fd, SOL_TCP, TCP_CONGESTION, cc, &len); - if (!ASSERT_OK(err, "getsockopt(server_fd, TCP_CONGESTION)")) - goto close_client; - send_byte(client_fd); =20 - ASSERT_OK(ss_search(ADDR_1, "fwmark:0x1"), "ss_search fwmark:0x1"); - ASSERT_OK(ss_search(ADDR_2, "fwmark:0x2"), "ss_search fwmark:0x2"); - ASSERT_OK(ss_search(ADDR_1, new), "ss_search new cc"); - ASSERT_OK(ss_search(ADDR_2, cc), "ss_search default cc"); - -close_client: close(client_fd); close_server: close(server_fd); @@ -441,7 +417,7 @@ static void test_subflow(void) if (endpoint_init("subflow") < 0) goto close_netns; =20 - run_subflow(skel->data->cc); + run_subflow(); =20 close_netns: cleanup_netns(nstoken); @@ -470,9 +446,15 @@ static struct nstoken *sched_init(char *flags, char *s= ched) return NULL; } =20 +static int ss_search(char *src, char *dst, char *port, char *keyword) +{ + return SYS_NOFAIL("ip netns exec %s ss -enita src %s dst %s %s %d | grep = -q '%s'", + NS_TEST, src, dst, port, PORT_1, keyword); +} + static int has_bytes_sent(char *dst) { - return _ss_search(ADDR_1, dst, "sport", "bytes_sent:"); + return ss_search(ADDR_1, dst, "sport", "bytes_sent:"); } =20 static void send_data_and_verify(char *sched, bool addr1, bool addr2) --=20 2.43.0 From nobody Fri Nov 22 01:30:39 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3487117CA12 for ; Thu, 22 Aug 2024 09:23:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318587; cv=none; b=Z3Ofo6BrOl4fpmBpapwLiq+F/+IuXCGJJQH+qwQjjYW1UUmk0zO7u6J48pFa9MOHrrnzYrsczuM/mfSytVFnJ/hKCwloEfyRYGkz5A5E7ltb63hns1aCc+eh2PyeBikN0NFmAcSaBLIFGe8C47hn/CIGZtZCM/uoW44vtrfzZhs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318587; c=relaxed/simple; bh=FzSETpjsjaPxqKoRGWTcl3SzqZZiG8gjKJiafRMmTi8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MHmyyKM7c+WUFzT1x0z3MLBC7qZ4ZkVuzcuhMAXFC4tV7KLOXQ2OzCA5lNDeqSczbzjUVQbUSnSJUfFyz4+1aiIded2m9VW+pksYEyIM+dlkL0ZpSvlMzIklwMEYo22RvGYoZMXMID5AudqUrZnqjzrRfRmxHFNM9DVLRrJytQY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MzcF4yPY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MzcF4yPY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C752C32782; Thu, 22 Aug 2024 09:23:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724318586; bh=FzSETpjsjaPxqKoRGWTcl3SzqZZiG8gjKJiafRMmTi8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MzcF4yPYlTWunIXHFB9h3o8YdY66P3kunXaQAedQEvb2Nr8l4QAKoTbGn1gOpYp13 HcSkTUdTDbgicCmF3xTn5BtKTaHHn0BIZZh+a4e7wJdO1xF4ak2QQpqnyZ10/d6jJ1 Mj5P9tbraAYBFjg5xRfz534honZLYXSJloREdhh2eXU8wz1Qkc+1D4Qpm05jm+by4o jScVKHkPUepAwTL6nKY/Wa48FG7q6eoWALyYcBlLS6IpGFGpe/720Y/zyMaisbOu/B Nwo1xSgGQxFxbAGubq3Kp2dEnIe4Yh0NyIOQbdM/GI/0kS9kJlglyglbIbVn0JuxNV I0Eq16hreuKcA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Martin KaFai Lau Subject: [PATCH mptcp-next v3 2/2] selftests/bpf: Add getsockopt to inspect mptcp subflow Date: Thu, 22 Aug 2024 17:22:51 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang This patch adds a "cgroup/getsockopt" way to inspect the subflows of a mptcp socket. mptcp_for_each_stubflow() and other helpers related to list_dentry are added into progs/mptcp_bpf.h. Add an extra "cgroup/getsockopt" prog to walk the msk->conn_list and use bpf_core_cast to cast a pointer to tcp_sock for readonly. It will allow to inspect all the fields in a tcp_sock. Suggested-by: Martin KaFai Lau Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 23 ++++++++ tools/testing/selftests/bpf/progs/mptcp_bpf.h | 35 ++++++++++++ .../selftests/bpf/progs/mptcp_subflow.c | 55 +++++++++++++++++++ 3 files changed, 113 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing= /selftests/bpf/prog_tests/mptcp.c index d4c5209fbfaf..143ed1c756e1 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -371,6 +371,10 @@ static int endpoint_init(char *flags) static void run_subflow(void) { int server_fd, client_fd; + char cc[TCP_CA_NAME_MAX]; + unsigned int mark; + socklen_t len; + int err; =20 server_fd =3D start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0); if (!ASSERT_GE(server_fd, 0, "start_mptcp_server")) @@ -382,6 +386,18 @@ static void run_subflow(void) =20 send_byte(client_fd); =20 + sleep(0.1); + + len =3D sizeof(mark); + err =3D getsockopt(client_fd, SOL_SOCKET, SO_MARK, &mark, &len); + if (!ASSERT_OK(err, "getsockopt(client_fd, SO_MARK)")) + goto close_client; + + len =3D sizeof(cc); + err =3D getsockopt(client_fd, SOL_TCP, TCP_CONGESTION, cc, &len); + ASSERT_OK(err, "getsockopt(client_fd, TCP_CONGESTION)"); + +close_client: close(client_fd); close_server: close(server_fd); @@ -392,6 +408,7 @@ static void test_subflow(void) int cgroup_fd, prog_fd, err; struct mptcp_subflow *skel; struct nstoken *nstoken; + struct bpf_link *link; =20 cgroup_fd =3D test__join_cgroup("/mptcp_subflow"); if (!ASSERT_GE(cgroup_fd, 0, "join_cgroup: mptcp_subflow")) @@ -417,6 +434,11 @@ static void test_subflow(void) if (endpoint_init("subflow") < 0) goto close_netns; =20 + link =3D bpf_program__attach_cgroup(skel->progs._getsockopt_subflow, + cgroup_fd); + if (!ASSERT_OK_PTR(link, "getsockopt prog")) + goto close_netns; + run_subflow(); =20 close_netns: @@ -425,6 +447,7 @@ static void test_subflow(void) mptcp_subflow__destroy(skel); close_cgroup: close(cgroup_fd); + bpf_link__destroy(link); } =20 static struct nstoken *sched_init(char *flags, char *sched) diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf.h b/tools/testing/= selftests/bpf/progs/mptcp_bpf.h index 782f36ed027e..70d9f5888976 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf.h +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf.h @@ -4,9 +4,44 @@ =20 #include #include +#include "bpf_experimental.h" =20 #define MPTCP_SUBFLOWS_MAX 8 =20 +static inline int list_is_head(const struct list_head *list, + const struct list_head *head) +{ + return list =3D=3D head; +} + +#define list_entry(ptr, type, member) \ + container_of(ptr, type, member) + +#define list_first_entry(ptr, type, member) \ + list_entry((ptr)->next, type, member) + +#define list_next_entry(pos, member) \ + list_entry((pos)->member.next, typeof(*(pos)), member) + +#define list_entry_is_head(pos, head, member) \ + list_is_head(&pos->member, (head)) + +#define list_for_each_entry(pos, head, member) \ + for (pos =3D list_first_entry(head, typeof(*pos), member); \ + !list_entry_is_head(pos, head, member); \ + cond_break, pos =3D list_next_entry(pos, member)) + +#define list_for_each_entry_safe(pos, n, head, member) \ + for (pos =3D list_first_entry(head, typeof(*pos), member), \ + n =3D list_next_entry(pos, member); \ + !list_entry_is_head(pos, head, member); \ + cond_break, pos =3D n, n =3D list_next_entry(n, member)) + +#define mptcp_for_each_subflow(__msk, __subflow) \ + list_for_each_entry(__subflow, &((__msk)->conn_list), node) +#define mptcp_for_each_subflow_safe(__msk, __subflow, __tmp) \ + list_for_each_entry_safe(__subflow, __tmp, &((__msk)->conn_list), node) + extern void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subf= low, bool scheduled) __ksym; =20 diff --git a/tools/testing/selftests/bpf/progs/mptcp_subflow.c b/tools/test= ing/selftests/bpf/progs/mptcp_subflow.c index bc572e1d6df8..e8cc157278d2 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_subflow.c +++ b/tools/testing/selftests/bpf/progs/mptcp_subflow.c @@ -4,6 +4,7 @@ =20 /* vmlinux.h, bpf_helpers.h and other 'define' */ #include "bpf_tracing_net.h" +#include "mptcp_bpf.h" =20 char _license[] SEC("license") =3D "GPL"; =20 @@ -57,3 +58,57 @@ int mptcp_subflow(struct bpf_sock_ops *skops) =20 return 1; } + +static int _check_getsockopt_subflows_mark(struct mptcp_sock *msk, struct = bpf_sockopt *ctx) +{ + struct mptcp_subflow_context *subflow; + int i =3D 0; + + mptcp_for_each_subflow(msk, subflow) { + struct sock *ssk; + + ssk =3D mptcp_subflow_tcp_sock(bpf_core_cast(subflow, + struct mptcp_subflow_context)); + + if (ssk->sk_mark !=3D ++i) + ctx->retval =3D -1; + } + + return 1; +} + +static int _check_getsockopt_subflow_cc(struct mptcp_sock *msk, struct bpf= _sockopt *ctx) +{ + struct mptcp_subflow_context *subflow, *tmp; + + mptcp_for_each_subflow_safe(msk, subflow, tmp) { + struct inet_connection_sock *icsk; + struct sock *ssk; + + ssk =3D mptcp_subflow_tcp_sock(bpf_core_cast(subflow, + struct mptcp_subflow_context)); + icsk =3D bpf_core_cast(ssk, struct inet_connection_sock); + + if (ssk->sk_mark =3D=3D 1 && + __builtin_memcmp(icsk->icsk_ca_ops->name, cc, TCP_CA_NAME_MAX)) + ctx->retval =3D -1; + } + + return 1; +} + +SEC("cgroup/getsockopt") +int _getsockopt_subflow(struct bpf_sockopt *ctx) +{ + struct mptcp_sock *msk =3D bpf_core_cast(ctx->sk, struct mptcp_sock); + + if (!msk || !msk->token) + return 1; + + if (ctx->level =3D=3D SOL_SOCKET && ctx->optname =3D=3D SO_MARK) + return _check_getsockopt_subflows_mark(msk, ctx); + if (ctx->level =3D=3D SOL_TCP && ctx->optname =3D=3D TCP_CONGESTION) + return _check_getsockopt_subflow_cc(msk, ctx); + + return 1; +} --=20 2.43.0