Re: [PATCH bpf-next] selftests/bpf: Use make/remove netns helpers in mptcp

2024-10-29 Thread Martin KaFai Lau
On 10/24/24 1:11 AM, Geliang Tang wrote: From: Geliang Tang New netns selftest helpers make_netns() and remove_netns() has been added in network_helpers.c, let's use them in mptcp selftests too. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) --- tools/testing/selftests/bpf

Re: [PATCH bpf-next v1 1/4] selftests/bpf: Migrate *_POST_BIND test cases to prog_tests

2024-10-21 Thread Martin KaFai Lau
On 10/17/24 3:49 PM, Jordan Rife wrote: Move all BPF_CGROUP_INET6_POST_BIND and BPF_CGROUP_INET4_POST_BIND test cases to a new prog_test, prog_tests/sock_post_bind.c, except for LOAD_REJECT test cases. Signed-off-by: Jordan Rife --- .../selftests/bpf/prog_tests/sock_post_bind.c | 417

Re: [PATCH bpf-next v2 0/6] selftests/bpf: Various sockmap-related fixes

2024-08-19 Thread Martin KaFai Lau
On 7/31/24 3:01 AM, Michal Luczaj wrote: Series takes care of few bugs and missing features with the aim to improve the test coverage of sockmap/sockhash. Last patch is a create_pair() rewrite making use of __attribute__((cleanup)) to handle socket fd lifetime. Applied to bpf-next/net. Thanks.

Re: [PATCH bpf-next v4 2/2] selftests/bpf: Add mptcp subflow subtest

2024-08-19 Thread Martin KaFai Lau
On 8/17/24 7:13 PM, Geliang Tang wrote: Take a look at a recent example [0]. The mptcp test is under a cgroup already and has the cgroup setup. An extra "cgroup/getsockopt" prog should be enough. That prog can walk the msk->conn_list and use bpf_rdonly_cast (or the >> bpf_core_cast macro in libb

Re: [PATCH bpf-next v2 0/6] selftests/bpf: Various sockmap-related fixes

2024-08-19 Thread Martin KaFai Lau
On 8/16/24 12:03 PM, Jakub Sitnicki wrote: On Wed, Aug 14, 2024 at 06:14 PM +02, Michal Luczaj wrote: On 8/6/24 19:45, Jakub Sitnicki wrote: On Tue, Aug 06, 2024 at 07:18 PM +02, Michal Luczaj wrote: Great, thanks for the review. With this completed, I guess we can unwind the (mail) stack to [

Re: [PATCH bpf-next v4 4/4] selftests/bpf: convert test_skb_cgroup_id_user to test_progs

2024-08-14 Thread Martin KaFai Lau
On 8/13/24 5:45 AM, Alexis Lothoré (eBPF Foundation) wrote: +#define DST_ADDR "ff02::1" [ ... ] +static int wait_local_ip(void) +{ + char *ping_cmd = ping_command(AF_INET6); + int i, err; + + for (i = 0; i < WAIT_AUTO_IP_MAX_ATTEMPT; i++) { + err = SYS_NOFAIL(

Re: [PATCH bpf-next v4 2/2] selftests/bpf: Add mptcp subflow subtest

2024-08-14 Thread Martin KaFai Lau
On 8/14/24 3:04 AM, Matthieu Baerts wrote: Hi Martin, Thank you for your reply! On 14/08/2024 03:12, Martin KaFai Lau wrote: On 8/5/24 2:52 AM, Matthieu Baerts (NGI0) wrote: +static int endpoint_init(char *flags) +{ +    SYS(fail, "ip -net %s link add veth1 type veth peer name

Re: [PATCH bpf-next v4 2/2] selftests/bpf: Add mptcp subflow subtest

2024-08-14 Thread Martin KaFai Lau
On 8/5/24 2:52 AM, Matthieu Baerts (NGI0) wrote: +static void run_subflow(char *new) +{ + int server_fd, client_fd, err; + char cc[TCP_CA_NAME_MAX]; + socklen_t len = sizeof(cc); + + server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0); + if (!ASSERT_GE(server_

Re: [PATCH bpf-next] selftests/bpf: Avoid subtraction after htons() in ipip tests

2024-08-13 Thread Martin KaFai Lau
On 8/8/24 2:24 AM, Toke Høiland-Jørgensen wrote: Asbjørn Sloth Tønnesen writes: On little-endian systems, doing subtraction after htons() leads to interesting results: Given: MAGIC_BYTES = 123 = 0x007B aka. in big endian: 0x7B00 = 31488 sizeof(struct iphdr) = 20 Before this patch: __bp

Re: [PATCH bpf-next v4 2/2] selftests/bpf: Add mptcp subflow subtest

2024-08-13 Thread Martin KaFai Lau
On 8/5/24 2:52 AM, Matthieu Baerts (NGI0) wrote: +static int endpoint_init(char *flags) +{ + SYS(fail, "ip -net %s link add veth1 type veth peer name veth2", NS_TEST); + SYS(fail, "ip -net %s addr add %s/24 dev veth1", NS_TEST, ADDR_1); + SYS(fail, "ip -net %s link set dev veth

Re: [PATCH bpf-next v2 4/4] selftests/bpf: convert test_skb_cgroup_id_user to test_progs

2024-08-09 Thread Martin KaFai Lau
On 8/6/24 12:55 AM, Alexis Lothoré (eBPF Foundation) wrote: diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup_ancestor.c b/tools/testing/selftests/bpf/prog_tests/cgroup_ancestor.c new file mode 100644 index ..4e41463533c0 --- /dev/null +++ b/tools/testing/selftests/bpf/prog_

Re: [PATCH bpf-next v2 2/4] selftests/bpf: convert test_cgroup_storage to test_progs

2024-08-09 Thread Martin KaFai Lau
On 8/6/24 12:55 AM, Alexis Lothoré (eBPF Foundation) wrote: +++ b/tools/testing/selftests/bpf/prog_tests/cgroup_storage.c @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include "cgroup_helpers.h" +#include "cgroup_storage.skel.h" + +#define TEST_CGROUP "/test-bpf-cgroup-stor

Re: [PATCH bpf-next v2 1/4] selftests/bpf: convert get_current_cgroup_id_user to test_progs

2024-08-09 Thread Martin KaFai Lau
On 8/6/24 12:55 AM, Alexis Lothoré (eBPF Foundation) wrote: +void test_cgroup_get_current_cgroup_id(void) +{ + struct get_cgroup_id_kern *skel; + const struct timespec req = { + .tv_sec = 0, + .tv_nsec = 1, + }; + int cgroup_fd; + __u64 uc

Re: [PATCH bpf-next v3 2/3] selftests/bpf: convert test_dev_cgroup to test_progs

2024-07-30 Thread Martin KaFai Lau
On 7/30/24 4:59 AM, Alexis Lothoré (eBPF Foundation) wrote: +static void test_read(const char *path, char *buf, int buf_size, + int expected_ret) +{ + int ret, fd; + + fd = open(path, O_RDONLY); + + /* A bare open on unauthorized device should fail */ +

Re: [PATCH bpf-next v3 2/3] selftests/bpf: Add mptcp pm_nl_ctl link

2024-07-24 Thread Martin KaFai Lau
On 7/24/24 1:24 AM, Matthieu Baerts wrote: Hi Geliang, Thank you for your reply! On 24/07/2024 09:42, Geliang Tang wrote: Hi Matt, On Sat, 2024-07-06 at 02:25 +0200, Matthieu Baerts wrote: Hi Martin, Thank you for your reply! On 06/07/2024 01:10, Martin KaFai Lau wrote: On 7/4/24 3:48 AM

Re: [PATCH bpf-next v3 5/5] selftests/bpf: Drop make_socket in sk_lookup

2024-07-18 Thread Martin KaFai Lau
On 7/17/24 11:22 PM, Geliang Tang wrote: From: Geliang Tang Use local helper make_client() in drop_on_lookup(), drop_on_reuseport() and run_multi_prog_lookup() instead of using make_socket() + connect(). Then make_socket() and inetaddr_len() can be dropped. Signed-off-by: Geliang Tang --- .

Re: [PATCH bpf-next v3 4/5] selftests/bpf: Use connect_to_addr_str in sk_lookup

2024-07-18 Thread Martin KaFai Lau
On 7/17/24 11:22 PM, Geliang Tang wrote: From: Geliang Tang 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_clien

Re: [PATCH bpf-next v3 2/5] selftests/bpf: Drop must_fail from network_helper_opts

2024-07-18 Thread Martin KaFai Lau
On 7/17/24 11:22 PM, Geliang Tang wrote: diff --git a/tools/testing/selftests/bpf/network_helpers.c b/tools/testing/selftests/bpf/network_helpers.c index 15e0e0bb7553..48c27c810db7 100644 --- a/tools/testing/selftests/bpf/network_helpers.c +++ b/tools/testing/selftests/bpf/network_helpers.c @@ -

Re: [PATCH bpf-next v1 0/3] add bpf_file_d_path helper and selftests

2024-07-18 Thread Martin KaFai Lau
On 7/18/24 4:51 AM, Lin Yikai wrote: v1: - patch 2: - [1/2] add bpf_file_d_path helper - [2/2] add selftest to it Hi, we are looking to add the "bpf_file_d_path" helper, used to retrieve the path from a struct file object. bpf_file_d_path(void *file, char *dst, u32 size);

Re: [PATCH bpf-next v2 2/5] selftests/bpf: Drop must_fail from network_helper_opts

2024-07-12 Thread Martin KaFai Lau
checked in cgroup_v1v2.c directly, no need to check them in connect_fd_to_addr() in network_helpers.c. This also makes connect_fd_to_addr() function useless. It can be replaced by connect(). Suggested-by: Martin KaFai Lau Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_help

Re: [PATCH bpf-next 2/5] selftests/bpf: Drop must_fail from network_helper_opts

2024-07-11 Thread Martin KaFai Lau
checked in cgroup_v1v2.c directly, no need to check them in connect_fd_to_addr() in network_helpers.c. This also makes connect_fd_to_addr() function useless. It can be replaced by connect(). Suggested-by: Martin KaFai Lau Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/network_help

Re: [PATCH bpf-next v2 0/2] BPF selftests misc fixes

2024-07-10 Thread Martin KaFai Lau
On 7/10/24 6:10 AM, Geliang Tang wrote: From: Geliang Tang v2: - only check the first "link" (link_nl) in test_mixed_links(). - Drop patch 2 in v1. Resend patch 1 out of "skip ENOTSUPP BPF selftests" set as Eduard suggested. Together with another fix for xdp_adjust_tail. This is not very

Re: [PATCH bpf-next v11 7/9] selftests/bpf: Add connect_fd_to_addr_str helper

2024-07-10 Thread Martin KaFai Lau
On 7/9/24 2:16 AM, Geliang Tang wrote: From: Geliang Tang 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", toge

Re: [PATCH bpf-next v11 6/9] selftests/bpf: Use connect_fd_to_fd in sk_lookup

2024-07-10 Thread Martin KaFai Lau
On 7/9/24 2:16 AM, Geliang Tang wrote: From: Geliang Tang This patch uses public helper connect_fd_to_fd() exported in network_helpers.h instead of using getsockname() + connect() in run_lookup_prog() in prog_tests/sk_lookup.c. This can simplify the code. Signed-off-by: Geliang Tang --- too

Re: [PATCH bpf-next v11 3/9] selftests/bpf: Close fd in error path in drop_on_reuseport

2024-07-10 Thread Martin KaFai Lau
On 7/9/24 2:16 AM, Geliang Tang wrote: From: Geliang Tang In the error path when update_lookup_map() fails in drop_on_reuseport in prog_tests/sk_lookup.c, "server1", the fd of server 1, should be closed. This patch fixes this by using "goto close_srv1" lable instead of "detach" to close "server

Re: [PATCH bpf-next v11 2/9] selftests/bpf: Add ASSERT_OK_FD macro

2024-07-10 Thread Martin KaFai Lau
On 7/9/24 2:16 AM, Geliang Tang wrote: From: Geliang Tang Add a new dedicated ASSERT macro ASSERT_OK_FD to test whether a socket FD is valid or not. It can be used to replace macros ASSERT_GT(fd, 0, ""), ASSERT_NEQ(fd, -1, "") or statements (fd < 0), (fd != -1). Suggest

Re: [PATCH bpf-next v10 07/12] selftests/bpf: Set expect_errno for cgroup_skb_sk_lookup

2024-07-08 Thread Martin KaFai Lau
On 7/7/24 7:29 PM, Geliang Tang wrote: From: Geliang Tang EINPROGRESS is skipped in run_lookup_test() in cgroup_skb_sk_lookup tests, but it is still showed in the log: ./test_progs -t cgroup_skb_sk_lookup -v run_cgroup_bpf_test:PASS:skel_open_load 0 nsec run_cgroup_bpf_test:PASS:cgroup_j

Re: [PATCH bpf-next v10 06/12] selftests/bpf: Add expect_errno for network_helper_opts

2024-07-08 Thread Martin KaFai Lau
On 7/8/24 12:15 PM, Eduard Zingerman wrote: On Mon, 2024-07-08 at 10:29 +0800, Geliang Tang wrote: [...] diff --git a/tools/testing/selftests/bpf/network_helpers.h b/tools/testing/selftests/bpf/network_helpers.h index fcda6b2333ad..14d161d35248 100644 --- a/tools/testing/selftests/bpf/network

Re: [PATCH bpf-next v3 2/3] selftests/bpf: Add mptcp pm_nl_ctl link

2024-07-05 Thread Martin KaFai Lau
On 7/4/24 3:48 AM, Matthieu Baerts wrote: diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index e0b3887b3d2d..204269d0b5b8 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -144,7 +144,7 @@ TEST_GEN_PROGS_EXTE

Re: [PATCH bpf-next v8 8/9] selftests/bpf: Use connect_to_addr in sk_lookup

2024-07-05 Thread Martin KaFai Lau
On 7/4/24 7:58 PM, Geliang Tang wrote: From: Geliang Tang Use public network helpers make_sockaddr() and connect_to_addr() instead of using the local defined function make_socket() and connect(). This make_socket() can be dropped latter. Signed-off-by: Geliang Tang --- .../selftests/bpf/pr

Re: [PATCH bpf-next v6 8/9] selftests/bpf: Use connect_to_addr in sk_lookup

2024-07-03 Thread Martin KaFai Lau
On 6/28/24 6:20 PM, Geliang Tang wrote: From: Geliang Tang Use public network helpers make_sockaddr() and connect_to_addr() instead of using the local defined function make_socket() and connect(). This make_socket() can be dropped latter. Signed-off-by: Geliang Tang --- .../selftests/bpf/p

Re: [PATCH bpf-next v6 6/9] selftests/bpf: Use start_server_str in sk_lookup

2024-07-03 Thread Martin KaFai Lau
On 6/28/24 6:20 PM, Geliang Tang wrote: +static int make_server(int sotype, const char *ip, int port, + struct bpf_program *reuseport_prog) +{ + struct cb_opts cb_opts = { + .family = is_ipv6(ip) ? AF_INET6 : AF_INET, + .sotype = sotype, +

Re: [PATCH bpf-next v6 3/9] selftests/bpf: Use connect_to_fd in sockmap_ktls

2024-07-03 Thread Martin KaFai Lau
On 6/28/24 6:20 PM, Geliang Tang wrote: From: Geliang Tang Use public network helper connect_to_fd() instead of open-coding it in prog_tests/sockmap_ktls.c. This can avoid duplicate code. Acked-by: Eduard Zingerman Signed-off-by: Geliang Tang --- .../selftests/bpf/prog_tests/sockmap_ktls.c

Re: [PATCH bpf-next v6 2/9] selftests/bpf: Use start_server_str in sockmap_ktls

2024-07-03 Thread Martin KaFai Lau
On 6/28/24 6:20 PM, Geliang Tang wrote: static void test_sockmap_ktls_disconnect_after_delete(int family, int map) { + struct network_helper_opts opts = { + .backlog = SOMAXCONN, + }; struct sockaddr_storage addr = {0}; socklen_t len = sizeof(addr);

Re: [PATCH bpf-next v6 1/9] selftests/bpf: Add backlog for network_helper_opts

2024-07-03 Thread Martin KaFai Lau
On 6/28/24 6:20 PM, Geliang Tang wrote: From: Geliang Tang Some callers expect __start_server() helper to pass their own "backlog" value to listen() instead of the default of 1. So this patch adds struct member "backlog" for network_helper_opts to allow callers to set "backlog" value via start_

Re: [PATCH bpf-next v2 1/8] selftests/bpf: Add unshare_netns helper

2024-05-29 Thread Martin KaFai Lau
On 5/15/24 6:13 PM, Geliang Tang wrote: From: Geliang Tang Many BPF selftests create new test network namespaces by using CLONE_NEWNET flag to unshare the network namespace, so that the calling process is moved into a new network namespace which is not shared with any previously existing proces

Re: [PATCH bpf-next v5 6/7] selftests/bpf: Use connect_to_fd_opts in do_test in bpf_tcp_ca

2024-05-28 Thread Martin KaFai Lau
On 5/25/24 5:08 AM, Geliang Tang wrote: From: Geliang Tang This patch uses connect_to_fd_opts() instead of using connect_fd_to_fd() and settcpca() in do_test() in prog_tests/bpf_tcp_ca.c to accept a struct network_helper_opts argument. Then define a dctcp dedicated post_socket_cb callback stg_

Re: [PATCH bpf-next v4 0/6] use network helpers, part 5

2024-05-24 Thread Martin KaFai Lau
On 5/23/24 8:21 PM, Geliang Tang wrote: From: Geliang Tang This patchset uses post_socket_cb and post_connect_cb callbacks of struct network_helper_opts to refactor do_test() in bpf_tcp_ca.c to move dctcp test dedicated code out of do_test() into test_dctcp(). Overall looks good. It needs ano

Re: [PATCH bpf-next v4 4/6] selftests/bpf: Use start_server_str in bpf_tcp_ca

2024-05-24 Thread Martin KaFai Lau
On 5/23/24 8:21 PM, Geliang Tang wrote: From: Geliang Tang This patch uses new helper start_server_str() in do_test() in bpf_tcp_ca.c to accept a struct network_helper_opts argument instead of using start_server() and settcpca(). Then change the type of the first paramenter I think it missed

Re: [PATCH bpf-next v4 3/6] selftests/bpf: Use post_socket_cb in connect_to_fd_opts

2024-05-24 Thread Martin KaFai Lau
On 5/23/24 8:21 PM, Geliang Tang wrote: +static int cc_cb(int fd, void *opts) +{ + struct cb_opts *cb_opts = (struct cb_opts *)opts; + + return setsockopt(fd, SOL_TCP, TCP_CONGESTION, cb_opts->cc, + strlen(cb_opts->cc) + 1); Since this cc_cb is in the test it

Re: [PATCH bpf-next v3 2/8] selftests/bpf: Drop type parameter of start_server_addr

2024-05-23 Thread Martin KaFai Lau
On 5/22/24 2:23 AM, Geliang Tang wrote: diff --git a/tools/testing/selftests/bpf/prog_tests/sk_assign.c b/tools/testing/selftests/bpf/prog_tests/sk_assign.c index 0b9bd1d6f7cc..517d1186e386 100644 --- a/tools/testing/selftests/bpf/prog_tests/sk_assign.c +++ b/tools/testing/selftests/bpf/prog_tes

Re: [PATCH bpf-next v2 2/4] selftests/bpf: Use start_server_addr in bpf_tcp_ca

2024-05-21 Thread Martin KaFai Lau
On 5/14/24 9:20 PM, Geliang Tang wrote: From: Geliang Tang This patch uses start_server_addr() in do_test() in prog_tests/bpf_tcp_ca.c to accept a struct network_helper_opts argument instead of using start_server() and settcpca(). Then change the type of the first paramenter of do_test() into a

Re: [PATCH bpf-next v2 1/4] selftests/bpf: Use post_socket_cb in connect_to_fd_opts

2024-05-21 Thread Martin KaFai Lau
On 5/14/24 9:20 PM, Geliang Tang wrote: From: Geliang Tang Since the post_socket_cb() callback is added in struct network_helper_opts, it's make sense to use it not only in __start_server(), but also in connect_to_fd_opts(). Then it can be used to set TCP_CONGESTION sockopt. Add a post_socket_

Re: [PATCH bpf-next 2/6] selftests/bpf: Use start_server_addr in sockopt_inherit

2024-05-09 Thread Martin KaFai Lau
On 5/5/24 4:35 AM, Geliang Tang wrote: From: Geliang Tang Include network_helpers.h in prog_tests/sockopt_inherit.c, use public helper start_server_addr() instead of the local defined function start_server(). This can avoid duplicate code. Add a helper custom_cb() to set SOL_CUSTOM sockopt loo

Re: [PATCH bpf-next 1/6] selftests/bpf: Add post_socket_cb for network_helper_opts

2024-05-09 Thread Martin KaFai Lau
On 5/5/24 4:35 AM, Geliang Tang wrote: From: Geliang Tang __start_server() sets SO_REUSPORT through setsockopt() when the parameter 'reuseport' is set. This patch makes it more flexible by adding a function pointer post_socket_cb, together with 'struct post_socket_opts cb_opts' for future exten

Re: [PATCH bpf-next 4/6] selftests/bpf: Add setsockopt for network_helper_opts

2024-04-30 Thread Martin KaFai Lau
On 4/24/24 8:23 PM, Geliang Tang wrote: +static int setsockopt_reuseport(int fd, const void *optval, socklen_t optlen) +{ + return setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, optval, optlen); } [ ... ] void free_fds(int *fds, unsigned int nr_close_fds) diff --git a/tools/testing/sel

Re: [PATCH v2 bpf-next 4/6] selftests/bpf: Add IPv4 and IPv6 sockaddr test cases

2024-04-29 Thread Martin KaFai Lau
On 4/28/24 10:47 AM, Jordan Rife wrote: Also, all this setup (and test) has to be done in a new netns. Anything blocking the kfunc in patch 2 using the current task netns instead of the init_net? Add nodad to the "ip -6 addr add...". just in case it may add unnecessary delay. This interface/addre

Re: [PATCH v2 bpf-next 4/6] selftests/bpf: Add IPv4 and IPv6 sockaddr test cases

2024-04-22 Thread Martin KaFai Lau
On 4/18/24 9:37 AM, Jordan Rife wrote: The test_sock_addr.{c,sh} can be retired as long as all its tests are migrated to sock_addr.c test_sock_addr.c has a few more test dimensions than prog_tests/sock_addr.c currently does, so it covers a few more scenarios. struct sock_addr_test { const

Re: [PATCH v2 bpf-next 4/6] selftests/bpf: Add IPv4 and IPv6 sockaddr test cases

2024-04-17 Thread Martin KaFai Lau
On 4/17/24 10:08 AM, Jordan Rife wrote: Can the test_sock_addr.{c,sh} be retired after this patch? I know it's not used in the BPF CI tests, but is it still used in any other contexts? If anyone depends on the test_sock_addr binary, it will have to start using "./test_progs -t sock_addr". T

Re: [PATCH bpf-next v4 09/14] selftests/bpf: Use log_err in network_helpers

2024-04-17 Thread Martin KaFai Lau
On 4/16/24 3:13 AM, Geliang Tang wrote: From: Geliang Tang The helpers ASSERT_OK/GE/OK_PTR should avoid using in public functions. This patch uses log_err() to replace them in network_helpers.c, then uses ASSERT_OK_PTR() to check the return values of all open_netns(). Signed-off-by: Geliang Ta

Re: [PATCH bpf-next v4 06/14] selftests/bpf: Use connect_to_addr in sk_assign

2024-04-17 Thread Martin KaFai Lau
On 4/16/24 3:13 AM, Geliang Tang wrote: From: Geliang Tang This patch uses public helper connect_to_addr() exported in network_helpers.h instead of the local defined function connect_to_server() in prog_tests/sk_assign.c. This can avoid duplicate code. The code that sets SO_SNDTIMEO timeout as

Re: [PATCH bpf-next v4 02/14] selftests/bpf: Add start_server_addr* helpers

2024-04-17 Thread Martin KaFai Lau
On 4/16/24 3:13 AM, Geliang Tang wrote: From: Geliang Tang In order to pair up with connect_to_addr(), this patch adds a new helper start_server_addr(), and another one start_server_addr_opts(), which is a wrapper of __start_server(), only added a network_helper_opts arg at the end. They all a

Re: [PATCH v2 bpf-next 4/6] selftests/bpf: Add IPv4 and IPv6 sockaddr test cases

2024-04-15 Thread Martin KaFai Lau
On 4/12/24 9:52 AM, Jordan Rife wrote: This patch lays the groundwork for testing IPv4 and IPv6 sockaddr hooks and their interaction with both socket syscalls and kernel functions (e.g. kernel_connect, kernel_bind, etc.) and moves the test cases from the old-style bpf/test_sock_addr.c self test i

Re: [PATCH v2 bpf-next 2/6] selftests/bpf: Implement socket kfuncs for bpf_testmod

2024-04-15 Thread Martin KaFai Lau
On 4/12/24 9:52 AM, Jordan Rife wrote: This patch adds a set of kfuncs to bpf_testmod that can be used to manipulate a socket from kernel space. Signed-off-by: Jordan Rife --- .../selftests/bpf/bpf_testmod/bpf_testmod.c | 139 ++ .../bpf/bpf_testmod/bpf_testmod_kfunc.h

Re: [PATCH v2 bpf-next 4/6] selftests/bpf: Add IPv4 and IPv6 sockaddr test cases

2024-04-15 Thread Martin KaFai Lau
On 4/12/24 9:52 AM, Jordan Rife wrote: This patch lays the groundwork for testing IPv4 and IPv6 sockaddr hooks and their interaction with both socket syscalls and kernel functions (e.g. kernel_connect, kernel_bind, etc.) and moves the test cases from the old-style bpf/test_sock_addr.c self test i

Re: [PATCH bpf-next v2 11/14] selftests/bpf: Use start_server_setsockopt in sockopt_inherit

2024-04-11 Thread Martin KaFai Lau
On 4/10/24 6:03 PM, Geliang Tang wrote: From: Geliang Tang Include network_helpers.h in prog_tests/sockopt_inherit.c, use public helpers make_sockaddr() and start_server_setsockopt() instead of the local defined function start_server(). This can avoid duplicate code. Add a helper setsockopt_lo

Re: [PATCH bpf-next v2 01/14] selftests/bpf: Add start_server_addr helper

2024-04-11 Thread Martin KaFai Lau
On 4/10/24 6:03 PM, Geliang Tang wrote: From: Geliang Tang In order to pair up with connect_to addr(), this patch adds a new helper start_server_addr(), which is a wrapper of __start_server(), and accepts an argument 'addr' of 'struct sockaddr' type instead of a string type argument like start_

Re: [PATCH bpf-next v5 2/2] selftests/bpf: Export send_recv_data helper

2024-04-11 Thread Martin KaFai Lau
On 4/10/24 10:43 PM, Geliang Tang wrote: +static void *send_recv_server(void *arg) +{ + struct send_recv_arg *a = (struct send_recv_arg *)arg; + ssize_t nr_sent = 0, bytes = 0; + char batch[1500]; + int err = 0, fd; + + fd = accept(a->fd, NULL, NULL); + while (

Re: [PATCH bpf-next v4 3/3] selftests/bpf: Support nonblock for send_recv_data

2024-04-10 Thread Martin KaFai Lau
On 4/9/24 11:13 PM, Geliang Tang wrote: From: Geliang Tang Some tests, such as the MPTCP bpf tests, require send_recv_data helper to run in nonblock mode. This patch adds nonblock support for send_recv_data(). Check if it is currently in nonblock mode, and if so, ignore EWOULDBLOCK to continue

Re: [PATCH bpf-next v4 2/3] selftests/bpf: Export send_recv_data helper

2024-04-10 Thread Martin KaFai Lau
On 4/9/24 11:13 PM, Geliang Tang wrote: +int send_recv_data(int lfd, int fd, uint32_t total_bytes) +{ + ssize_t nr_recv = 0, bytes = 0; + struct send_recv_arg arg = { + .fd = lfd, + .bytes = total_bytes, + .stop = 0, + }; +

Re: [PATCH net-next 0/4] selftests: move bpf-offload test from bpf to net

2024-04-09 Thread Martin KaFai Lau
needed. Acked-by: Martin KaFai Lau

Re: [PATCH bpf-next v2 2/2] selftests/bpf: Export send_recv_data helper

2024-04-08 Thread Martin KaFai Lau
On 4/8/24 8:51 PM, Geliang Tang wrote: +static void *send_recv_server(void *arg) +{ + struct send_recv_arg *a = (struct send_recv_arg *)arg; + ssize_t nr_sent = 0, bytes = 0; + char batch[1500]; + int err = 0, fd; + + fd = accept(a->fd, NULL, NULL); + while (fd

Re: [PATCH v1 bpf-next 5/8] selftests/bpf: Factor out load_path and defines from test_sock_addr

2024-04-02 Thread Martin KaFai Lau
On 3/29/24 12:18 PM, Jordan Rife wrote: diff --git a/tools/testing/selftests/bpf/sock_addr_helpers.c b/tools/testing/selftests/bpf/sock_addr_helpers.c new file mode 100644 index 0..ff2eb09870f16 --- /dev/null +++ b/tools/testing/selftests/bpf/sock_addr_helpers.c @@ -0,0 +1,46 @@ +//

Re: [PATCH v1 bpf-next 4/8] selftests/bpf: Add recv_msg_from_client to network helpers

2024-04-02 Thread Martin KaFai Lau
On 3/29/24 12:18 PM, Jordan Rife wrote: +int recvmsg_from_client(int sockfd, struct sockaddr_storage *src_addr) +{ + struct timeval tv; + struct msghdr hdr; + struct iovec iov; + char data[64]; + fd_set rfds; + + FD_ZERO(&rfds); + FD_SET(sockfd, &rfds); +

Re: [PATCH v1 bpf-next 1/8] selftests/bpf: Introduce sock_addr_testmod

2024-04-02 Thread Martin KaFai Lau
On 3/29/24 12:18 PM, Jordan Rife wrote: +static int do_sock_op(int op, struct sockaddr *addr, int addrlen) This function can be made as a new kfunc in bpf_testmod.c. The sock_create_kern() could be moved to here also. Take a look at the register_btf_kfunc_id_set() usage in bpf_testmod.c and h

Re: [PATCH] tools/testing/selftests/bpf/test_tc_tunnel.sh: Prevent client connect before server bind

2024-03-13 Thread Martin KaFai Lau
On 3/10/24 1:45 AM, Alessandro Carminati wrote: Hi Martin, Thanks for the review. Il giorno ven 8 mar 2024 alle ore 02:03 Martin KaFai Lau ha scritto: On 2/29/24 6:00 AM, Alessandro Carminati (Red Hat) wrote: In some systems, the netcat server can incur in delay to start listening. When

Re: [PATCH] tools/testing/selftests/bpf/test_tc_tunnel.sh: Prevent client connect before server bind

2024-03-07 Thread Martin KaFai Lau
On 2/29/24 6:00 AM, Alessandro Carminati (Red Hat) wrote: In some systems, the netcat server can incur in delay to start listening. When this happens, the test can randomly fail in various points. This is an example error message: # ip gre none gso # encap 192.168.1.1 to 192.168.1.2, type

Re: [PATCH RFC bpf-next v2 02/10] bpf/helpers: introduce sleepable timers

2024-02-15 Thread Martin KaFai Lau
On 2/14/24 9:18 AM, Benjamin Tissoires wrote: +static void bpf_timer_work_cb(struct work_struct *work) +{ + struct bpf_hrtimer *t = container_of(work, struct bpf_hrtimer, work); + struct bpf_map *map = t->map; + void *value = t->value; + bpf_callback_t callback_fn; +

Re: [PATCH] bpf: Separate bpf_local_storage_lookup() fast and slow paths

2024-02-06 Thread Martin KaFai Lau
On 2/6/24 9:04 AM, Marco Elver wrote: On Mon, Feb 05, 2024 at 03:24PM -0800, Martin KaFai Lau wrote: [...] Or can you suggest different functions to hook to for the recursion test? I don't prefer to add another tracepoint for the selftest. Ok - I also checked, even though it should be

Re: [PATCH] bpf: Separate bpf_local_storage_lookup() fast and slow paths

2024-02-05 Thread Martin KaFai Lau
On 2/5/24 7:00 AM, Marco Elver wrote: On Wed, 31 Jan 2024 at 20:52, Martin KaFai Lau wrote: [...] | num_maps: 1000 | local_storage cache sequential get: | | | hits throughput: 0.357 ± 0.005 M ops/s | 0.325 ± 0.005 M ops/s

Re: [PATCH] selftests/bpf: Use ARRAY_SIZE for array length

2024-02-02 Thread Martin KaFai Lau
On 2/2/24 1:06 AM, Jiapeng Chong wrote: Use of macro ARRAY_SIZE to calculate array size minimizes the redundant code and improves code reusability. ./tools/testing/selftests/bpf/progs/syscall.c:122:26-27: WARNING: Use ARRAY_SIZE. Reported-by: Abaci Robot Closes: https://bugzilla.openanolis.cn

Re: [PATCH] bpf: Separate bpf_local_storage_lookup() fast and slow paths

2024-01-31 Thread Martin KaFai Lau
On 1/31/24 6:18 AM, Marco Elver wrote: To allow the compiler to inline the bpf_local_storage_lookup() fast- path, factor it out by making bpf_local_storage_lookup() a static inline function and move the slow-path to bpf_local_storage_lookup_slowpath(). Base on results from './benchs/run_bench_lo

Re: [PATCH bpf-next] bpf: Allow setting SO_TIMESTAMPING* with bpf_setsockopt()

2024-01-17 Thread Martin KaFai Lau
On 1/17/24 7:55 AM, Willem de Bruijn wrote: Martin KaFai Lau wrote: On 1/16/24 7:17 AM, Willem de Bruijn wrote: Jörn-Thorben Hinz wrote: A BPF application, e.g., a TCP congestion control, might benefit from or even require precise (=hardware) packet timestamps. These timestamps are already

Re: [PATCH bpf-next] bpf: Allow setting SO_TIMESTAMPING* with bpf_setsockopt()

2024-01-16 Thread Martin KaFai Lau
On 1/16/24 7:17 AM, Willem de Bruijn wrote: Jörn-Thorben Hinz wrote: A BPF application, e.g., a TCP congestion control, might benefit from or even require precise (=hardware) packet timestamps. These timestamps are already available through __sk_buff.hwtstamp and bpf_sock_ops.skb_hwtstamp, but c

Re: [PATCH bpf-next 0/2] bpf: add csum/ip_summed fields to __sk_buff

2024-01-02 Thread Martin KaFai Lau
On 1/2/24 10:11 AM, Stanislav Fomichev wrote: On 12/29, Menglong Dong wrote: For now, we have to call some helpers when we need to update the csum, such as bpf_l4_csum_replace, bpf_l3_csum_replace, etc. These helpers are not inlined, which causes poor performance. In fact, we can define our own

Re: [PATCH bpf-next v5 5/9] bpf: selftests: Add verifier tests for CO-RE bitfield writes

2023-12-13 Thread Martin KaFai Lau
On 12/11/23 12:20 PM, Daniel Xu wrote: Add some tests that exercise BPF_CORE_WRITE_BITFIELD() macro. Since some non-trivial bit fiddling is going on, make sure various edge cases (such as adjacent bitfields and bitfields at the edge of structs) are exercised. Hi DanielXu, I have pushed the libb

Re: [PATCH v7 11/11] selftests/bpf/sockopt: Add io_uring support

2023-10-19 Thread Martin KaFai Lau
ing two tests. This is going to help to exercise the io_uring subsystem: * getsockopt: read ctx->optlen * getsockopt: support smaller ctx->optlen Acked-by: Martin KaFai Lau

Re: [PATCH bpf-next v2 2/2] selftests/bpf: Add pairs_redir_to_connected helper

2023-10-05 Thread Martin KaFai Lau
On 10/5/23 12:21 AM, Geliang Tang wrote: --- a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c @@ -1336,32 +1336,22 @@ static void test_redir(struct test_sockmap_listen *skel, struct bpf_map *map, } } -static void

Re: [PATCH v6 8/8] selftests/bpf/sockopt: Add io_uring support

2023-09-13 Thread Martin KaFai Lau
On 9/13/23 8:27 AM, Breno Leitao wrote: Expand the BPF sockopt test to use also check for io_uring {g,s}etsockopt commands operations. Create infrastructure to run io_uring tests using the mini_liburing helpers, so, the {g,s}etsockopt operation could either be called from system calls, or, via i