Message ID | 20250210134550.3189616-3-zhangmingyi5@huawei.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | BPF |
Headers | show |
Series | bpf-next: Introduced to support the ULP to get or set sockets | expand |
On 2/10/25 5:45 AM, zhangmingyi wrote: > From: Mingyi Zhang <zhangmingyi5@huawei.com> > > We try to use bpf_set/getsockopt to set/get TCP_ULP in sockops, and "tls" > need connect is established.To avoid impacting other test cases, I have > written a separate test case file. > > Signed-off-by: Mingyi Zhang <zhangmingyi5@huawei.com> > Signed-off-by: Xin Liu <liuxin350@huawei.com> > --- > .../bpf/prog_tests/setget_sockopt_tcp_ulp.c | 78 +++++++++++++++++++ > .../bpf/progs/setget_sockopt_tcp_ulp.c | 33 ++++++++ > 2 files changed, 111 insertions(+) > create mode 100644 tools/testing/selftests/bpf/prog_tests/setget_sockopt_tcp_ulp.c > create mode 100644 tools/testing/selftests/bpf/progs/setget_sockopt_tcp_ulp.c > > diff --git a/tools/testing/selftests/bpf/prog_tests/setget_sockopt_tcp_ulp.c b/tools/testing/selftests/bpf/prog_tests/setget_sockopt_tcp_ulp.c > new file mode 100644 > index 000000000000..748da2c7d255 > --- /dev/null > +++ b/tools/testing/selftests/bpf/prog_tests/setget_sockopt_tcp_ulp.c > @@ -0,0 +1,78 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* Copyright (c) Meta Platforms, Inc. and affiliates. */ This is not right. > + > +#define _GNU_SOURCE > +#include <net/if.h> > + > +#include "test_progs.h" > +#include "network_helpers.h" > + > +#include "setget_sockopt_tcp_ulp.skel.h" > + > +#define CG_NAME "/setget-sockopt-tcp-ulp-test" > + > +static const char addr4_str[] = "127.0.0.1"; > +static const char addr6_str[] = "::1"; > +static struct setget_sockopt_tcp_ulp *skel; > +static int cg_fd; > + > +static int create_netns(void) > +{ > + if (!ASSERT_OK(unshare(CLONE_NEWNET), "create netns")) > + return -1; > + if (!ASSERT_OK(system("ip link set dev lo up"), "set lo up")) > + return -1; > + return 0; > +} > + > +static int modprobe_tls(void) > +{ > + if (!ASSERT_OK(system("modprobe tls"), "tls modprobe failed")) > + return -1; > + return 0; > +} > + > +static void test_tcp_ulp(int family) First, the bpf CI still fails to compile for the same reason as v1. You should have received an email from bpf CI bot. Please ensure it is addressed first before reposting. This repeated bpf CI error is an automatic nack. pw-bot: cr The subject tagging should be "[PATCH v2 bpf-next ...] selftests/bpf: ... ". There are many examples to follow in the mailing list if it is not clear. Regarding the v1 comment: "...separate it out into its own BPF program..." The comment was made at the bpf prog file, "progs/setget_sockopt.c". I meant only create a separate bpf program. The user space part can stay in prog_tests/setget_sockopt.c. Move this function, test_tcp_ulp, to prog_tests/setget_sockopt.c. Then all the above config preparation codes and the test_setget_sockopt_tcp_ulp() can be saved. modprobe_tls() is not needed also. Do it after the test_ktls(). Take a look at test_nonstandard_opt() in prog_tests/setget_sockopt.c. It is testing another bpf prog in the same prog_tests/setget_sockopt.c. Also, for the bpf prog, do you really need to test at BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB? If not, just testing at SEC("lsm_cgroup/socket_post_create") will be easier. You can detach the previously attached skel->links.socket_post_create by using bpf_link__destroy() first and then attach yours bpf prog to do the test. > +{ > + struct setget_sockopt_tcp_ulp__bss *bss = skel->bss; > + int sfd, cfd; > + > + memset(bss, 0, sizeof(*bss)); > + sfd = start_server(family, SOCK_STREAM, > + family == AF_INET6 ? addr6_str : addr4_str, 0, 0); > + if (!ASSERT_GE(sfd, 0, "start_server")) > + return; > + > + cfd = connect_to_fd(sfd, 0); > + if (!ASSERT_GE(cfd, 0, "connect_to_fd_server")) { > + close(sfd); > + return; > + } > + close(sfd); > + close(cfd); > + > + ASSERT_EQ(bss->nr_tcp_ulp, 3, "nr_tcp_ulp"); > +} > + > +void test_setget_sockopt_tcp_ulp(void) > +{ > + cg_fd = test__join_cgroup(CG_NAME); > + if (cg_fd < 0) > + return; > + if (create_netns() && modprobe_tls()) > + goto done; > + skel = setget_sockopt_tcp_ulp__open(); > + if (!ASSERT_OK_PTR(skel, "open skel")) > + goto done; > + if (!ASSERT_OK(setget_sockopt_tcp_ulp__load(skel), "load skel")) > + goto done; > + skel->links.skops_sockopt_tcp_ulp = > + bpf_program__attach_cgroup(skel->progs.skops_sockopt_tcp_ulp, cg_fd); > + if (!ASSERT_OK_PTR(skel->links.skops_sockopt_tcp_ulp, "attach_cgroup")) > + goto done; > + test_tcp_ulp(AF_INET); > + test_tcp_ulp(AF_INET6); > +done: > + setget_sockopt_tcp_ulp__destroy(skel); > + close(cg_fd); > +} > diff --git a/tools/testing/selftests/bpf/progs/setget_sockopt_tcp_ulp.c b/tools/testing/selftests/bpf/progs/setget_sockopt_tcp_ulp.c > new file mode 100644 > index 000000000000..bd1009766463 > --- /dev/null > +++ b/tools/testing/selftests/bpf/progs/setget_sockopt_tcp_ulp.c > @@ -0,0 +1,33 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* Copyright (c) Meta Platforms, Inc. and affiliates. */ Same here. > + > +#include "vmlinux.h" > +#include "bpf_tracing_net.h" > +#include <bpf/bpf_helpers.h> > + > +int nr_tcp_ulp; > + > +SEC("sockops") > +int skops_sockopt_tcp_ulp(struct bpf_sock_ops *skops) > +{ > + static const char target_ulp[] = "tls"; > + char verify_ulp[sizeof(target_ulp)]; > + > + switch (skops->op) { > + case BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB: > + if (bpf_setsockopt(skops, IPPROTO_TCP, TCP_ULP, (void *)target_ulp, > + sizeof(target_ulp)) != 0) > + return 1; > + nr_tcp_ulp++; > + if (bpf_getsockopt(skops, IPPROTO_TCP, TCP_ULP, verify_ulp, > + sizeof(verify_ulp)) != 0) > + return 1; > + nr_tcp_ulp++; > + if (bpf_strncmp(verify_ulp, sizeof(target_ulp), "tls") != 0) > + return 1; > + nr_tcp_ulp++; > + } > + return 1; > +} > + > +char _license[] SEC("license") = "GPL"; > \ No newline at end of file
Hi zhangmingyi,
kernel test robot noticed the following build errors:
[auto build test ERROR on bpf-next/master]
[also build test ERROR on bpf/master mptcp/export mptcp/export-net linus/master v6.14-rc2 next-20250214]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/zhangmingyi/bpf-next-Introduced-to-support-the-ULP-to-get-or-set-sockets/20250210-215203
base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
patch link: https://lore.kernel.org/r/20250210134550.3189616-3-zhangmingyi5%40huawei.com
patch subject: [PATCH v2 2/2] bpf-next: selftest for TCP_ULP in bpf_setsockopt
compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250215/202502150104.1LKDPqiq-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202502150104.1LKDPqiq-lkp@intel.com/
All errors (new ones prefixed by >>):
>> progs/setget_sockopt_tcp_ulp.c:18:42: error: use of undeclared identifier 'TCP_ULP'; did you mean 'MCP_UC'?
18 | if (bpf_setsockopt(skops, IPPROTO_TCP, TCP_ULP, (void *)target_ulp,
| ^~~~~~~
| MCP_UC
tools/testing/selftests/bpf/tools/include/vmlinux.h:18434:2: note: 'MCP_UC' declared here
18434 | MCP_UC = 2,
| ^
progs/setget_sockopt_tcp_ulp.c:22:42: error: use of undeclared identifier 'TCP_ULP'; did you mean 'MCP_UC'?
22 | if (bpf_getsockopt(skops, IPPROTO_TCP, TCP_ULP, verify_ulp,
| ^~~~~~~
| MCP_UC
tools/testing/selftests/bpf/tools/include/vmlinux.h:18434:2: note: 'MCP_UC' declared here
18434 | MCP_UC = 2,
| ^
2 errors generated.
diff --git a/tools/testing/selftests/bpf/prog_tests/setget_sockopt_tcp_ulp.c b/tools/testing/selftests/bpf/prog_tests/setget_sockopt_tcp_ulp.c new file mode 100644 index 000000000000..748da2c7d255 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_tests/setget_sockopt_tcp_ulp.c @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) Meta Platforms, Inc. and affiliates. */ + +#define _GNU_SOURCE +#include <net/if.h> + +#include "test_progs.h" +#include "network_helpers.h" + +#include "setget_sockopt_tcp_ulp.skel.h" + +#define CG_NAME "/setget-sockopt-tcp-ulp-test" + +static const char addr4_str[] = "127.0.0.1"; +static const char addr6_str[] = "::1"; +static struct setget_sockopt_tcp_ulp *skel; +static int cg_fd; + +static int create_netns(void) +{ + if (!ASSERT_OK(unshare(CLONE_NEWNET), "create netns")) + return -1; + if (!ASSERT_OK(system("ip link set dev lo up"), "set lo up")) + return -1; + return 0; +} + +static int modprobe_tls(void) +{ + if (!ASSERT_OK(system("modprobe tls"), "tls modprobe failed")) + return -1; + return 0; +} + +static void test_tcp_ulp(int family) +{ + struct setget_sockopt_tcp_ulp__bss *bss = skel->bss; + int sfd, cfd; + + memset(bss, 0, sizeof(*bss)); + sfd = start_server(family, SOCK_STREAM, + family == AF_INET6 ? addr6_str : addr4_str, 0, 0); + if (!ASSERT_GE(sfd, 0, "start_server")) + return; + + cfd = connect_to_fd(sfd, 0); + if (!ASSERT_GE(cfd, 0, "connect_to_fd_server")) { + close(sfd); + return; + } + close(sfd); + close(cfd); + + ASSERT_EQ(bss->nr_tcp_ulp, 3, "nr_tcp_ulp"); +} + +void test_setget_sockopt_tcp_ulp(void) +{ + cg_fd = test__join_cgroup(CG_NAME); + if (cg_fd < 0) + return; + if (create_netns() && modprobe_tls()) + goto done; + skel = setget_sockopt_tcp_ulp__open(); + if (!ASSERT_OK_PTR(skel, "open skel")) + goto done; + if (!ASSERT_OK(setget_sockopt_tcp_ulp__load(skel), "load skel")) + goto done; + skel->links.skops_sockopt_tcp_ulp = + bpf_program__attach_cgroup(skel->progs.skops_sockopt_tcp_ulp, cg_fd); + if (!ASSERT_OK_PTR(skel->links.skops_sockopt_tcp_ulp, "attach_cgroup")) + goto done; + test_tcp_ulp(AF_INET); + test_tcp_ulp(AF_INET6); +done: + setget_sockopt_tcp_ulp__destroy(skel); + close(cg_fd); +} diff --git a/tools/testing/selftests/bpf/progs/setget_sockopt_tcp_ulp.c b/tools/testing/selftests/bpf/progs/setget_sockopt_tcp_ulp.c new file mode 100644 index 000000000000..bd1009766463 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/setget_sockopt_tcp_ulp.c @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) Meta Platforms, Inc. and affiliates. */ + +#include "vmlinux.h" +#include "bpf_tracing_net.h" +#include <bpf/bpf_helpers.h> + +int nr_tcp_ulp; + +SEC("sockops") +int skops_sockopt_tcp_ulp(struct bpf_sock_ops *skops) +{ + static const char target_ulp[] = "tls"; + char verify_ulp[sizeof(target_ulp)]; + + switch (skops->op) { + case BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB: + if (bpf_setsockopt(skops, IPPROTO_TCP, TCP_ULP, (void *)target_ulp, + sizeof(target_ulp)) != 0) + return 1; + nr_tcp_ulp++; + if (bpf_getsockopt(skops, IPPROTO_TCP, TCP_ULP, verify_ulp, + sizeof(verify_ulp)) != 0) + return 1; + nr_tcp_ulp++; + if (bpf_strncmp(verify_ulp, sizeof(target_ulp), "tls") != 0) + return 1; + nr_tcp_ulp++; + } + return 1; +} + +char _license[] SEC("license") = "GPL"; \ No newline at end of file