selftests/bpf: Migrate test_xdp_redirect_multi.sh to test_progs
Subsystems (6)
v4 cover selftests/bpf: Migrate test_xdp_redirect_multi.sh to test_progs
Hi all,
This patch series continues the work to migrate the *.sh tests into prog_tests framework.
test_xdp_redirect_multi.sh tests the XDP redirections done through bpf_redirect_map().
This is already partly covered by test_xdp_veth.c that already tests map redirections at XDP level. What isn't covered yet by test_xdp_veth is the use of the broadcast flags (BPF_F_BROADCAST or BPF_F_EXCLUDE_INGRESS) and XDP egress programs.
Hence, this patch series add test cases to test_xdp_veth.c to get rid of the test_xdp_redirect_multi.sh:
- PATCH 1 Add an helper to generate unique names
- PATCH 2 to 9 rework test_xdp_veth to make it more generic and allow to configure different test cases
- PATCH 10 adds test cases for 'classic' bpf_redirect_map()
- PATCH 11 and 12 cover the broadcast flags
- PATCH 13 covers the XDP egress programs
- PATCH 14 removes test_xdp_redirect_multi.sh
---
Changes in v4:
- Remove the NO_IP #define
- append_tid() takes string's size as input to ensure there is enough
space to fit the thread ID at the end
- Fix PATCH 12's commit log
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Add append_tid() helper and use unique names to allow parallel testing
- Check create_network()'s return value through ASSERT_OK()
- Remove check_ping() and unused defines
- Change next_veth type (from string to int)
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Use serial_test_* to avoid conflict between tests
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Bastien Curutchet (eBPF Foundation) (14):
selftests/bpf: helpers: Add append_tid() selftests/bpf: test_xdp_veth: Remove unused defines selftests/bpf: test_xdp_veth: Remove unecessarry check_ping() selftests/bpf: test_xdp_veth: Use int to describe next veth selftests/bpf: test_xdp_veth: Split network configuration selftests/bpf: test_xdp_veth: Rename config[] selftests/bpf: test_xdp_veth: Add prog_config[] table selftests/bpf: test_xdp_veth: Add XDP flags to prog_configuration selftests/bpf: test_xdp_veth: Use unique names selftests/bpf: test_xdp_veth: Add new test cases for XDP flags selftests/bpf: Optionally select broadcasting flags selftests/bpf: test_xdp_veth: Add XDP broadcast redirection tests selftests/bpf: test_xdp_veth: Add XDP program on egress test selftests/bpf: Remove test_xdp_redirect_multi.sh
tools/testing/selftests/bpf/Makefile | 2 - tools/testing/selftests/bpf/network_helpers.c | 17 + tools/testing/selftests/bpf/network_helpers.h | 12 + .../selftests/bpf/prog_tests/test_xdp_veth.c | 588 ++++++++++++++++----- .../testing/selftests/bpf/progs/xdp_redirect_map.c | 89 ++++ .../selftests/bpf/progs/xdp_redirect_multi_kern.c | 41 +- .../selftests/bpf/test_xdp_redirect_multi.sh | 214 -------- tools/testing/selftests/bpf/xdp_redirect_multi.c | 226 -------- 8 files changed, 615 insertions(+), 574 deletions(-)
---
base-commit: 421ec9c8f46a25743870a8cbaff76de293752e00
change-id: 20250103-redirect-multi-245d6eafb5d1
Best regards,
Signature · 1 line
Bastien Curutchet (eBPF Foundation) <[email protected]>
PATCH v4 1/14 selftests/bpf: helpers: Add append_tid()
Some tests can't be run in parallel because they use same namespace names or veth names.
Create an helper that appends the thread ID to a given string. 8 characters are used for it (7 digits + '\0')
--- tools/testing/selftests/bpf/network_helpers.c | 17 +++++++++++++++++ tools/testing/selftests/bpf/network_helpers.h | 12 ++++++++++++ 2 files changed, 29 insertions(+)
tools/testing/selftests/bpf/network_helpers.c +17 -0
@@ -446,6 +446,23 @@ char *ping_command(int family)return "ping" ; } +int append_tid (char *str,size_t sz) +{ +size_t end; + +if (!str) +return -1 ; + + end =strlen (str); +if (end +8 > sz) +return -1 ; + +sprintf (&str[end],"%07d" ,gettid ()); + str[end +7 ] ='\0' ; + +return 0 ; +} +int remove_netns (const char *name) {char *cmd;
tools/testing/selftests/bpf/network_helpers.h +12 -0
@@ -98,6 +98,18 @@ int send_recv_data(int lfd, int fd, uint32_t total_bytes);int make_netns (const char *name);int remove_netns (const char *name); +/** +* append_tid() - Append thread ID to the given string. +* +* @str: string to extend +* @sz: string's size +* +* 8 characters are used to append the thread ID (7 digits + '\0') +* +* Returns -1 on errors, 0 otherwise +*/ +int append_tid (char *str,size_t sz); +static __u16 csum_fold (__u32 csum) { csum = (csum &0xffff ) + (csum >>16 );
Signature · 1 line
2.48.1
PATCH v4 2/14 selftests/bpf: test_xdp_veth: Remove unused defines
In reply to Bastien Curutchet (eBPF Foundation)IP_CMD_MAX_LEN and NS_SUFFIX_LEN aren't used anywhere.
Remove these unused defines
--- tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c | 2 -- 1 file changed, 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c +0 -2
@@ -25,11 +25,9 @@#include "xdp_tx.skel.h" #define VETH_PAIRS_COUNT 3 -#define NS_SUFFIX_LEN 6#define VETH_NAME_MAX_LEN 16#define IP_SRC "10.1.1.11"#define IP_DST "10.1.1.33" -#define IP_CMD_MAX_LEN 128struct skeletons {struct xdp_dummy *xdp_dummy;
Signature · 1 line
2.48.1
PATCH v4 3/14 selftests/bpf: test_xdp_veth: Remove unecessarry check_ping()
In reply to Bastien Curutchet (eBPF Foundation)check_ping() directly returns a SYS_NOFAIL without any previous treatment. It's called only once in the file and hardcodes the used namespace and ip address.
Replace check_ping() with a direct call of SYS_NOFAIL in the test.
--- tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c +5 -10
@@ -170,15 +170,6 @@ static void cleanup_network(void)SYS_NOFAIL ("ip netns del %s" , config[i].namespace); } -static int check_ping (struct skeletons *skeletons) -{ -/* Test: if all interfaces are properly configured, we must be able to ping -* veth33 from veth11 -*/ -return SYS_NOFAIL ("ip netns exec %s ping -c 1 -W 1 %s > /dev/null" , - config[0 ].namespace,IP_DST ); -} -void test_xdp_veth_redirect (void ) {struct skeletons skeletons = {};
@@ -198,7 +189,11 @@ void test_xdp_veth_redirect(void)if (configure_network (&skeletons)) goto destroy_xdp_redirect_map; -ASSERT_OK (check_ping (&skeletons),"ping" ); +/* Test: if all interfaces are properly configured, we must be able to ping +* veth33 from veth11 +*/ +ASSERT_OK (SYS_NOFAIL ("ip netns exec %s ping -c 1 -W 1 %s > /dev/null" , + config[0 ].namespace,IP_DST ),"ping" ); destroy_xdp_redirect_map:xdp_redirect_map__destroy (skeletons.xdp_redirect_maps);
Signature · 1 line
2.48.1
PATCH v4 4/14 selftests/bpf: test_xdp_veth: Use int to describe next veth
In reply to Bastien Curutchet (eBPF Foundation)In the struct veth_configuration, the next_veth string is used to tell the next virtual interface to which packets must be redirected to. So it has to match the local_veth string of an other veth_configuration.
Change next_veth type to int to avoid handling two identical strings. This integer is used as an offset in the network configuration table.
--- tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c +7 -5
@@ -39,7 +39,7 @@ struct veth_configuration {char local_veth[VETH_NAME_MAX_LEN ];/* Interface in main namespace */ char remote_veth[VETH_NAME_MAX_LEN ];/* Peer interface in dedicated namespace*/ const char *namespace;/* Namespace for the remote veth */ -char next_veth[VETH_NAME_MAX_LEN ];/* Local interface to redirect traffic to */ +int next_veth;/* Local interface to redirect traffic to */ char *remote_addr;/* IP address of the remote veth */ };
@@ -47,21 +47,21 @@ static struct veth_configuration config[VETH_PAIRS_COUNT] = { { .local_veth = "veth1", .remote_veth = "veth11", - .next_veth = "veth2", + .next_veth = 1, .remote_addr = IP_SRC, .namespace ="ns-veth11" }, { .local_veth = "veth2", .remote_veth = "veth22", - .next_veth = "veth3", + .next_veth = 2, .remote_addr = NULL, .namespace ="ns-veth22" }, { .local_veth = "veth3", .remote_veth = "veth33", - .next_veth = "veth1", + .next_veth = 0, .remote_addr = IP_DST, .namespace = "ns-veth33" }
@@ -144,7 +144,9 @@ static int configure_network(struct skeletons *skeletons)if (!ASSERT_GE (map_fd,0 ,"open redirect map" )) goto fail;for (i =0 ; i <VETH_PAIRS_COUNT ; i++) { - interface_id =if_nametoindex (config[i].next_veth); +int next_veth = config[i].next_veth; + + interface_id =if_nametoindex (config[next_veth].local_veth);if (!ASSERT_NEQ (interface_id,0 ,"non zero interface index" )) goto fail; err =bpf_map_update_elem (map_fd, &i, &interface_id,BPF_ANY );
Signature · 1 line
2.48.1
PATCH v4 5/14 selftests/bpf: test_xdp_veth: Split network configuration
In reply to Bastien Curutchet (eBPF Foundation)configure_network() does two things : it first creates the network topology and then configures the BPF maps to fit the test needs. This isn't convenient if we want to re-use the same network topology for different test cases.
Rename configure_network() create_network().
Move the BPF configuration to the test itself.
Split the test description in two parts, first the description of the network topology, then the description of the test case. Remove the veth indexes from the ASCII art as dynamic ones are used
--- .../selftests/bpf/prog_tests/test_xdp_veth.c | 81 +++++++++++++--------- 1 file changed, 47 insertions(+), 34 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c +47 -34
@@ -3,17 +3,27 @@/* Create 3 namespaces with 3 veth peers, and forward packets in-between using * native XDP * -* XDP_TX -* NS1(veth11) NS2(veth22) NS3(veth33) -* | | | -* | | | -* (veth1, (veth2, (veth3, -* id:111) id:122) id:133) -* ^ | ^ | ^ | -* | | XDP_REDIRECT | | XDP_REDIRECT | | -* | ------------------ ------------------ | -* ----------------------------------------- -* XDP_REDIRECT +* Network topology: +* ---------- ---------- ---------- +* | NS1 | | NS2 | | NS3 | +* | veth11 | | veth22 | | veth33 | +* ----|----- -----|---- -----|---- +* | | | +* veth1 veth2 veth3 +* +* Test cases: +* - [test_xdp_veth_redirect] : ping veth33 from veth11 +* +* veth11 veth22 veth33 +* (XDP_PASS) (XDP_TX) (XDP_PASS) +* | | | +* | | | +* veth1 veth2 veth3 +* (XDP_REDIRECT) (XDP_REDIRECT) (XDP_REDIRECT) +* ^ | ^ | ^ | +* | | | | | | +* | ------------------ ------------------ | +* ----------------------------------------- */ #define _GNU_SOURCE
@@ -119,12 +129,9 @@ static int attach_programs_to_veth_pair(struct skeletons *skeletons, int index)return 0 ; } -static int configure_network (struct skeletons *skeletons) +static int create_network (void ) { -int interface_id; -int map_fd; -int err; -int i =0 ; +int i;/* First create and configure all interfaces */ for (i =0 ; i <VETH_PAIRS_COUNT ; i++) {
@@ -139,27 +146,11 @@ static int configure_network(struct skeletons *skeletons) config[i].remote_veth); } -/* Then configure the redirect map and attach programs to interfaces */ - map_fd =bpf_map__fd (skeletons->xdp_redirect_maps->maps.tx_port); -if (!ASSERT_GE (map_fd,0 ,"open redirect map" )) - goto fail; -for (i =0 ; i <VETH_PAIRS_COUNT ; i++) { -int next_veth = config[i].next_veth; - - interface_id =if_nametoindex (config[next_veth].local_veth); -if (!ASSERT_NEQ (interface_id,0 ,"non zero interface index" )) - goto fail; - err =bpf_map_update_elem (map_fd, &i, &interface_id,BPF_ANY ); -if (!ASSERT_OK (err,"configure interface redirection through map" )) - goto fail; -if (attach_programs_to_veth_pair (skeletons, i)) - goto fail; - } -return 0 ; fail:return -1 ; + }static void cleanup_network (void )
@@ -175,6 +166,8 @@ static void cleanup_network(void)void test_xdp_veth_redirect (void ) {struct skeletons skeletons = {}; +int map_fd; +int i; skeletons.xdp_dummy =xdp_dummy__open_and_load ();if (!ASSERT_OK_PTR (skeletons.xdp_dummy,"xdp_dummy__open_and_load" ))
@@ -188,9 +181,29 @@ void test_xdp_veth_redirect(void)if (!ASSERT_OK_PTR (skeletons.xdp_redirect_maps,"xdp_redirect_map__open_and_load" )) goto destroy_xdp_tx; -if (configure_network (&skeletons)) +if (!ASSERT_OK (create_network (),"create_network" )) goto destroy_xdp_redirect_map; +/* Then configure the redirect map and attach programs to interfaces */ + map_fd =bpf_map__fd (skeletons.xdp_redirect_maps->maps.tx_port); +if (!ASSERT_OK_FD (map_fd,"open redirect map" )) + goto destroy_xdp_redirect_map; + +for (i =0 ; i <VETH_PAIRS_COUNT ; i++) { +int next_veth = config[i].next_veth; +int interface_id; +int err; + + interface_id =if_nametoindex (config[next_veth].local_veth); +if (!ASSERT_NEQ (interface_id,0 ,"non zero interface index" )) + goto destroy_xdp_redirect_map; + err =bpf_map_update_elem (map_fd, &i, &interface_id,BPF_ANY ); +if (!ASSERT_OK (err,"configure interface redirection through map" )) + goto destroy_xdp_redirect_map; +if (attach_programs_to_veth_pair (&skeletons, i)) + goto destroy_xdp_redirect_map; + } +/* Test: if all interfaces are properly configured, we must be able to ping * veth33 from veth11 */
Signature · 1 line
2.48.1
PATCH v4 6/14 selftests/bpf: test_xdp_veth: Rename config[]
In reply to Bastien Curutchet (eBPF Foundation)The network topology is held by the config[] table. This 'config' name is a bit too generic if we want to add other configuration variables.
Rename config[] to net_config[].
--- .../selftests/bpf/prog_tests/test_xdp_veth.c | 32 +++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c +16 -16
@@ -53,7 +53,7 @@ struct veth_configuration {char *remote_addr;/* IP address of the remote veth */ }; -static struct veth_configuration config[VETH_PAIRS_COUNT ] = { +static struct veth_configuration net_config[VETH_PAIRS_COUNT ] = { { .local_veth ="veth1" , .remote_veth ="veth11" ,
@@ -105,17 +105,17 @@ static int attach_programs_to_veth_pair(struct skeletons *skeletons, int index) remote_link = &skeletons->xdp_dummy->links.xdp_dummy_prog;break ; } - interface =if_nametoindex (config[index].local_veth); + interface =if_nametoindex (net_config[index].local_veth);if (!ASSERT_NEQ (interface,0 ,"non zero interface index" ))return -1 ; link =bpf_program__attach_xdp (local_prog, interface);if (!ASSERT_OK_PTR (link,"attach xdp program to local veth" ))return -1 ; *local_link = link; - nstoken =open_netns (config[index].namespace); + nstoken =open_netns (net_config[index].namespace);if (!ASSERT_OK_PTR (nstoken,"switch to remote veth namespace" ))return -1 ; - interface =if_nametoindex (config[index].remote_veth); + interface =if_nametoindex (net_config[index].remote_veth);if (!ASSERT_NEQ (interface,0 ,"non zero interface index" )) {close_netns (nstoken);return -1 ;
@@ -135,15 +135,15 @@ static int create_network(void)/* First create and configure all interfaces */ for (i =0 ; i <VETH_PAIRS_COUNT ; i++) { -SYS (fail,"ip netns add %s" , config[i].namespace); +SYS (fail,"ip netns add %s" , net_config[i].namespace);SYS (fail,"ip link add %s type veth peer name %s netns %s" , - config[i].local_veth, config[i].remote_veth, config[i].namespace); -SYS (fail,"ip link set dev %s up" , config[i].local_veth); -if (config[i].remote_addr) -SYS (fail,"ip -n %s addr add %s/24 dev %s" , config[i].namespace, - config[i].remote_addr, config[i].remote_veth); -SYS (fail,"ip -n %s link set dev %s up" , config[i].namespace, - config[i].remote_veth); + net_config[i].local_veth, net_config[i].remote_veth, net_config[i].namespace); +SYS (fail,"ip link set dev %s up" , net_config[i].local_veth); +if (net_config[i].remote_addr) +SYS (fail,"ip -n %s addr add %s/24 dev %s" , net_config[i].namespace, + net_config[i].remote_addr, net_config[i].remote_veth); +SYS (fail,"ip -n %s link set dev %s up" , net_config[i].namespace, + net_config[i].remote_veth); }return 0 ;
@@ -160,7 +160,7 @@ static void cleanup_network(void)/* Deleting namespaces is enough to automatically remove veth pairs as well */ for (i =0 ; i <VETH_PAIRS_COUNT ; i++) -SYS_NOFAIL ("ip netns del %s" , config[i].namespace); +SYS_NOFAIL ("ip netns del %s" , net_config[i].namespace); }void test_xdp_veth_redirect (void )
@@ -190,11 +190,11 @@ void test_xdp_veth_redirect(void) goto destroy_xdp_redirect_map;for (i =0 ; i <VETH_PAIRS_COUNT ; i++) { -int next_veth = config[i].next_veth; +int next_veth = net_config[i].next_veth;int interface_id;int err; - interface_id =if_nametoindex (config[next_veth].local_veth); + interface_id =if_nametoindex (net_config[next_veth].local_veth);if (!ASSERT_NEQ (interface_id,0 ,"non zero interface index" )) goto destroy_xdp_redirect_map; err =bpf_map_update_elem (map_fd, &i, &interface_id,BPF_ANY );
@@ -208,7 +208,7 @@ void test_xdp_veth_redirect(void)* veth33 from veth11 */ ASSERT_OK (SYS_NOFAIL ("ip netns exec %s ping -c 1 -W 1 %s > /dev/null" , - config[0 ].namespace,IP_DST ),"ping" ); + net_config[0 ].namespace,IP_DST ),"ping" ); destroy_xdp_redirect_map:xdp_redirect_map__destroy (skeletons.xdp_redirect_maps);
Signature · 1 line
2.48.1
PATCH v4 7/14 selftests/bpf: test_xdp_veth: Add prog_config[] table
In reply to Bastien Curutchet (eBPF Foundation)The BPF program attached to each veth is hardcoded through the use of the struct skeletons. It prevents from re-using the initialization code in new test cases.
Replace the struct skeletons by a bpf_object table.
Add a struct prog_configuration that holds the name of BPF program to load on a given veth pair.
Use bpf_object__find_program_by_name() / bpf_xdp_attach() API instead of bpf_program__attach_xdp() to retrieve the BPF programs from their names. Detach BPF progs in the cleanup() as it's not automatically done by this API.
--- .../selftests/bpf/prog_tests/test_xdp_veth.c | 133 +++++++++++++-------- 1 file changed, 80 insertions(+), 53 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c +80 -53
@@ -38,12 +38,7 @@#define VETH_NAME_MAX_LEN 16#define IP_SRC "10.1.1.11"#define IP_DST "10.1.1.33" - -struct skeletons { -struct xdp_dummy *xdp_dummy; -struct xdp_tx *xdp_tx; -struct xdp_redirect_map *xdp_redirect_maps; -}; +#define PROG_NAME_MAX_LEN 128struct veth_configuration {char local_veth[VETH_NAME_MAX_LEN ];/* Interface in main namespace */
@@ -77,55 +72,59 @@ static struct veth_configuration net_config[VETH_PAIRS_COUNT] = { } }; -static int attach_programs_to_veth_pair (struct skeletons *skeletons,int index) +struct prog_configuration { +char local_name[PROG_NAME_MAX_LEN ];/* BPF prog to attach to local_veth */ +char remote_name[PROG_NAME_MAX_LEN ];/* BPF prog to attach to remote_veth */ +}; + +static int attach_programs_to_veth_pair (struct bpf_object **objs,size_t nb_obj, +struct prog_configuration *prog,int index) {struct bpf_program *local_prog, *remote_prog; -struct bpf_link **local_link, **remote_link;struct nstoken *nstoken; -struct bpf_link *link; -int interface; - -switch (index) { -case 0 : - local_prog = skeletons->xdp_redirect_maps->progs.xdp_redirect_map_0; - local_link = &skeletons->xdp_redirect_maps->links.xdp_redirect_map_0; - remote_prog = skeletons->xdp_dummy->progs.xdp_dummy_prog; - remote_link = &skeletons->xdp_dummy->links.xdp_dummy_prog; -break ; -case 1 : - local_prog = skeletons->xdp_redirect_maps->progs.xdp_redirect_map_1; - local_link = &skeletons->xdp_redirect_maps->links.xdp_redirect_map_1; - remote_prog = skeletons->xdp_tx->progs.xdp_tx; - remote_link = &skeletons->xdp_tx->links.xdp_tx; -break ; -case 2 : - local_prog = skeletons->xdp_redirect_maps->progs.xdp_redirect_map_2; - local_link = &skeletons->xdp_redirect_maps->links.xdp_redirect_map_2; - remote_prog = skeletons->xdp_dummy->progs.xdp_dummy_prog; - remote_link = &skeletons->xdp_dummy->links.xdp_dummy_prog; -break ; +int interface, ret, i; + +for (i =0 ; i < nb_obj; i++) { + local_prog =bpf_object__find_program_by_name (objs[i], prog[index].local_name); +if (local_prog) +break ; } +if (!ASSERT_OK_PTR (local_prog,"find local program" )) +return -1 ; + +for (i =0 ; i < nb_obj; i++) { + remote_prog =bpf_object__find_program_by_name (objs[i], prog[index].remote_name); +if (remote_prog) +break ; + } +if (!ASSERT_OK_PTR (remote_prog,"find remote program" )) +return -1 ; + interface =if_nametoindex (net_config[index].local_veth);if (!ASSERT_NEQ (interface,0 ,"non zero interface index" ))return -1 ; - link =bpf_program__attach_xdp (local_prog, interface); -if (!ASSERT_OK_PTR (link,"attach xdp program to local veth" )) + + ret =bpf_xdp_attach (interface,bpf_program__fd (local_prog),0 ,NULL ); +if (!ASSERT_OK (ret,"attach xdp program to local veth" ))return -1 ; - *local_link = link; + nstoken =open_netns (net_config[index].namespace);if (!ASSERT_OK_PTR (nstoken,"switch to remote veth namespace" ))return -1 ; + interface =if_nametoindex (net_config[index].remote_veth);if (!ASSERT_NEQ (interface,0 ,"non zero interface index" )) {close_netns (nstoken);return -1 ; } - link =bpf_program__attach_xdp (remote_prog, interface); - *remote_link = link; -close_netns (nstoken); -if (!ASSERT_OK_PTR (link,"attach xdp program to remote veth" )) + + ret =bpf_xdp_attach (interface,bpf_program__fd (remote_prog),0 ,NULL ); +if (!ASSERT_OK (ret,"attach xdp program to remote veth" )) { +close_netns (nstoken);return -1 ; + } +close_netns (nstoken);return 0 ; }
@@ -150,45 +149,73 @@ static int create_network(void) fail:return -1 ; - }static void cleanup_network (void ) { +struct nstoken *nstoken;int i; -/* Deleting namespaces is enough to automatically remove veth pairs as well -*/ -for (i =0 ; i <VETH_PAIRS_COUNT ; i++) +for (i =0 ; i <VETH_PAIRS_COUNT ; i++) { +bpf_xdp_detach (if_nametoindex (net_config[i].local_veth),0 ,NULL ); + nstoken =open_netns (net_config[i].namespace); +if (nstoken) { +bpf_xdp_detach (if_nametoindex (net_config[i].remote_veth),0 ,NULL ); +close_netns (nstoken); + } +/* in case the detach failed */ +SYS_NOFAIL ("ip link del %s" , net_config[i].local_veth);SYS_NOFAIL ("ip netns del %s" , net_config[i].namespace); + } } +#define VETH_REDIRECT_SKEL_NB 3void test_xdp_veth_redirect (void ) { -struct skeletons skeletons = {}; +struct prog_configuration ping_config[VETH_PAIRS_COUNT ] = { + { + .local_name ="xdp_redirect_map_0" , + .remote_name ="xdp_dummy_prog" , + }, + { + .local_name ="xdp_redirect_map_1" , + .remote_name ="xdp_tx" , + }, + { + .local_name ="xdp_redirect_map_2" , + .remote_name ="xdp_dummy_prog" , + } + }; +struct bpf_object *bpf_objs[VETH_REDIRECT_SKEL_NB ]; +struct xdp_redirect_map *xdp_redirect_map; +struct xdp_dummy *xdp_dummy; +struct xdp_tx *xdp_tx;int map_fd;int i; - skeletons.xdp_dummy =xdp_dummy__open_and_load (); -if (!ASSERT_OK_PTR (skeletons.xdp_dummy,"xdp_dummy__open_and_load" )) + xdp_dummy =xdp_dummy__open_and_load (); +if (!ASSERT_OK_PTR (xdp_dummy,"xdp_dummy__open_and_load" ))return ; - skeletons.xdp_tx =xdp_tx__open_and_load (); -if (!ASSERT_OK_PTR (skeletons.xdp_tx,"xdp_tx__open_and_load" )) + xdp_tx =xdp_tx__open_and_load (); +if (!ASSERT_OK_PTR (xdp_tx,"xdp_tx__open_and_load" )) goto destroy_xdp_dummy; - skeletons.xdp_redirect_maps =xdp_redirect_map__open_and_load (); -if (!ASSERT_OK_PTR (skeletons.xdp_redirect_maps,"xdp_redirect_map__open_and_load" )) + xdp_redirect_map =xdp_redirect_map__open_and_load (); +if (!ASSERT_OK_PTR (xdp_redirect_map,"xdp_redirect_map__open_and_load" )) goto destroy_xdp_tx;if (!ASSERT_OK (create_network (),"create_network" )) goto destroy_xdp_redirect_map;/* Then configure the redirect map and attach programs to interfaces */ - map_fd =bpf_map__fd (skeletons.xdp_redirect_maps->maps.tx_port); + map_fd =bpf_map__fd (xdp_redirect_map->maps.tx_port);if (!ASSERT_OK_FD (map_fd,"open redirect map" )) goto destroy_xdp_redirect_map; + bpf_objs[0 ] = xdp_dummy->obj; + bpf_objs[1 ] = xdp_tx->obj; + bpf_objs[2 ] = xdp_redirect_map->obj;for (i =0 ; i <VETH_PAIRS_COUNT ; i++) {int next_veth = net_config[i].next_veth;int interface_id;
@@ -200,7 +227,7 @@ void test_xdp_veth_redirect(void) err =bpf_map_update_elem (map_fd, &i, &interface_id,BPF_ANY );if (!ASSERT_OK (err,"configure interface redirection through map" )) goto destroy_xdp_redirect_map; -if (attach_programs_to_veth_pair (&skeletons, i)) +if (attach_programs_to_veth_pair (bpf_objs,VETH_REDIRECT_SKEL_NB , ping_config, i)) goto destroy_xdp_redirect_map; }
@@ -211,11 +238,11 @@ void test_xdp_veth_redirect(void) net_config[0].namespace, IP_DST), "ping"); destroy_xdp_redirect_map: -xdp_redirect_map__destroy (skeletons.xdp_redirect_maps); +xdp_redirect_map__destroy (xdp_redirect_map); destroy_xdp_tx: -xdp_tx__destroy (skeletons.xdp_tx); +xdp_tx__destroy (xdp_tx); destroy_xdp_dummy: -xdp_dummy__destroy (skeletons.xdp_dummy); +xdp_dummy__destroy (xdp_dummy);cleanup_network (); }
Signature · 1 line
2.48.1
PATCH v4 8/14 selftests/bpf: test_xdp_veth: Add XDP flags to prog_configuration
In reply to Bastien Curutchet (eBPF Foundation)XDP flags are hardcoded to 0 at attachment.
Add flags attributes to the struct prog_configuration to allow flag modifications for each test case.
--- tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c +12 -2
@@ -75,6 +75,8 @@ static struct veth_configuration net_config[VETH_PAIRS_COUNT] = {struct prog_configuration {char local_name[PROG_NAME_MAX_LEN ];/* BPF prog to attach to local_veth */ char remote_name[PROG_NAME_MAX_LEN ];/* BPF prog to attach to remote_veth */ +u32 local_flags;/* XDP flags to use on local_veth */ +u32 remote_flags;/* XDP flags to use on remote_veth */ }; static int attach_programs_to_veth_pair(struct bpf_object **objs, size_t nb_obj,
@@ -104,7 +106,8 @@ static int attach_programs_to_veth_pair(struct bpf_object **objs, size_t nb_obj,if (!ASSERT_NEQ (interface,0 ,"non zero interface index" ))return -1 ; - ret =bpf_xdp_attach (interface,bpf_program__fd (local_prog),0 ,NULL ); + ret =bpf_xdp_attach (interface,bpf_program__fd (local_prog), + prog[index].local_flags,NULL );if (!ASSERT_OK (ret,"attach xdp program to local veth" ))return -1 ;
@@ -118,7 +121,8 @@ static int attach_programs_to_veth_pair(struct bpf_object **objs, size_t nb_obj,return -1 ; } - ret =bpf_xdp_attach (interface,bpf_program__fd (remote_prog),0 ,NULL ); + ret =bpf_xdp_attach (interface,bpf_program__fd (remote_prog), + prog[index].remote_flags,NULL );if (!ASSERT_OK (ret,"attach xdp program to remote veth" )) {close_netns (nstoken);return -1 ;
@@ -176,14 +180,20 @@ void test_xdp_veth_redirect(void) { .local_name = "xdp_redirect_map_0", .remote_name = "xdp_dummy_prog", + .local_flags = 0, + .remote_flags = 0, }, { .local_name = "xdp_redirect_map_1", .remote_name = "xdp_tx", + .local_flags = 0, + .remote_flags = 0, }, { .local_name = "xdp_redirect_map_2", .remote_name = "xdp_dummy_prog", + .local_flags = 0, + .remote_flags = 0, } };struct bpf_object *bpf_objs[VETH_REDIRECT_SKEL_NB ];
Signature · 1 line
2.48.1
PATCH v4 9/14 selftests/bpf: test_xdp_veth: Use unique names
In reply to Bastien Curutchet (eBPF Foundation)The network namespaces and the veth used by the tests have hardcoded names that can conflict with other tests during parallel runs.
Use the append_tid() helper to ensure the uniqueness of these names. Use the static network configuration table as a template on which thread IDs are appended in each test.
Set a fixed size to remote_addr field so the struct veth_configuration can also have a fixed size.
--- .../selftests/bpf/prog_tests/test_xdp_veth.c | 51 ++++++++++++++-------- 1 file changed, 33 insertions(+), 18 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c +33 -18
@@ -35,40 +35,42 @@#include "xdp_tx.skel.h" #define VETH_PAIRS_COUNT 3 -#define VETH_NAME_MAX_LEN 16 +#define VETH_NAME_MAX_LEN 32 +#define IP_MAX_LEN 16#define IP_SRC "10.1.1.11"#define IP_DST "10.1.1.33"#define PROG_NAME_MAX_LEN 128 +#define NS_NAME_MAX_LEN 32struct veth_configuration {char local_veth[VETH_NAME_MAX_LEN ];/* Interface in main namespace */ char remote_veth[VETH_NAME_MAX_LEN ];/* Peer interface in dedicated namespace*/ -const char *namespace;/* Namespace for the remote veth */ +char namespace[NS_NAME_MAX_LEN ];/* Namespace for the remote veth */ int next_veth;/* Local interface to redirect traffic to */ -char *remote_addr;/* IP address of the remote veth */ +char remote_addr[IP_MAX_LEN ];/* IP address of the remote veth */ }; -static struct veth_configuration net_config[VETH_PAIRS_COUNT ] = { +static const struct veth_configuration default_config[VETH_PAIRS_COUNT ] = { { - .local_veth ="veth1" , + .local_veth ="veth1-" , .remote_veth ="veth11" , .next_veth =1 , .remote_addr =IP_SRC , - .namespace ="ns-veth11" + .namespace ="ns-veth11-" }, { - .local_veth ="veth2" , + .local_veth ="veth2-" , .remote_veth ="veth22" , .next_veth =2 , - .remote_addr =NULL , - .namespace ="ns-veth22" + .remote_addr ="" , + .namespace ="ns-veth22-" }, { - .local_veth ="veth3" , + .local_veth ="veth3-" , .remote_veth ="veth33" , .next_veth =0 , .remote_addr =IP_DST , - .namespace ="ns-veth33" + .namespace ="ns-veth33-" } };
@@ -80,6 +82,7 @@ struct prog_configuration { };static int attach_programs_to_veth_pair (struct bpf_object **objs,size_t nb_obj, +struct veth_configuration *net_config,struct prog_configuration *prog,int index) {struct bpf_program *local_prog, *remote_prog;
@@ -132,17 +135,27 @@ static int attach_programs_to_veth_pair(struct bpf_object **objs, size_t nb_obj,return 0 ; } -static int create_network (void ) +static int create_network (struct veth_configuration *net_config) { -int i; +int i, err; + +memcpy (net_config, default_config,VETH_PAIRS_COUNT *sizeof (struct veth_configuration ));/* First create and configure all interfaces */ for (i =0 ; i <VETH_PAIRS_COUNT ; i++) { + err =append_tid (net_config[i].namespace,NS_NAME_MAX_LEN ); +if (!ASSERT_OK (err,"append TID to ns name" )) +return -1 ; + + err =append_tid (net_config[i].local_veth,VETH_NAME_MAX_LEN ); +if (!ASSERT_OK (err,"append TID to local veth name" )) +return -1 ; +SYS (fail,"ip netns add %s" , net_config[i].namespace);SYS (fail,"ip link add %s type veth peer name %s netns %s" , net_config[i].local_veth, net_config[i].remote_veth, net_config[i].namespace);SYS (fail,"ip link set dev %s up" , net_config[i].local_veth); -if (net_config[i].remote_addr) +if (net_config[i].remote_addr[0 ])SYS (fail,"ip -n %s addr add %s/24 dev %s" , net_config[i].namespace, net_config[i].remote_addr, net_config[i].remote_veth); SYS(fail, "ip -n %s link set dev %s up", net_config[i].namespace,
@@ -155,7 +168,7 @@ static int create_network(void)return -1 ; } -static void cleanup_network (void ) +static void cleanup_network (struct veth_configuration *net_config) {struct nstoken *nstoken;int i;
@@ -196,6 +209,7 @@ void test_xdp_veth_redirect(void) .remote_flags = 0, } }; +struct veth_configuration net_config[VETH_PAIRS_COUNT ];struct bpf_object *bpf_objs[VETH_REDIRECT_SKEL_NB ];struct xdp_redirect_map *xdp_redirect_map;struct xdp_dummy *xdp_dummy;
@@ -215,7 +229,7 @@ void test_xdp_veth_redirect(void)if (!ASSERT_OK_PTR (xdp_redirect_map,"xdp_redirect_map__open_and_load" )) goto destroy_xdp_tx; -if (!ASSERT_OK (create_network (),"create_network" )) +if (!ASSERT_OK (create_network (net_config),"create network" )) goto destroy_xdp_redirect_map;/* Then configure the redirect map and attach programs to interfaces */
@@ -237,7 +251,8 @@ void test_xdp_veth_redirect(void) err =bpf_map_update_elem (map_fd, &i, &interface_id,BPF_ANY );if (!ASSERT_OK (err,"configure interface redirection through map" )) goto destroy_xdp_redirect_map; -if (attach_programs_to_veth_pair (bpf_objs,VETH_REDIRECT_SKEL_NB , ping_config, i)) +if (attach_programs_to_veth_pair (bpf_objs,VETH_REDIRECT_SKEL_NB , + net_config, ping_config, i)) goto destroy_xdp_redirect_map; }
@@ -254,5 +269,5 @@ void test_xdp_veth_redirect(void) destroy_xdp_dummy:xdp_dummy__destroy (xdp_dummy); -cleanup_network (); +cleanup_network (net_config); }
Signature · 1 line
2.48.1
PATCH v4 10/14 selftests/bpf: test_xdp_veth: Add new test cases for XDP flags
In reply to Bastien Curutchet (eBPF Foundation)The XDP redirection is tested without any flag provided to the xdp_attach() function.
Add two subtests that check the correct behaviour with XDP_FLAGS_{DRV/SKB}_MODE flags
--- .../selftests/bpf/prog_tests/test_xdp_veth.c | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c +20 -7
@@ -33,6 +33,7 @@#include "xdp_dummy.skel.h" #include "xdp_redirect_map.skel.h" #include "xdp_tx.skel.h" +#include <uapi/linux/if_link.h> #define VETH_PAIRS_COUNT 3#define VETH_NAME_MAX_LEN 32
@@ -187,26 +188,26 @@ static void cleanup_network(struct veth_configuration *net_config) }#define VETH_REDIRECT_SKEL_NB 3 -void test_xdp_veth_redirect (void ) +static void xdp_veth_redirect (u32 flags) {struct prog_configuration ping_config[VETH_PAIRS_COUNT ] = { { .local_name ="xdp_redirect_map_0" , .remote_name ="xdp_dummy_prog" , - .local_flags =0 , - .remote_flags =0 , + .local_flags = flags, + .remote_flags = flags, }, { .local_name ="xdp_redirect_map_1" , .remote_name ="xdp_tx" , - .local_flags =0 , - .remote_flags =0 , + .local_flags = flags, + .remote_flags = flags, }, { .local_name ="xdp_redirect_map_2" , .remote_name ="xdp_dummy_prog" , - .local_flags =0 , - .remote_flags =0 , + .local_flags = flags, + .remote_flags = flags, } };struct veth_configuration net_config[VETH_PAIRS_COUNT ];
@@ -271,3 +272,15 @@ void test_xdp_veth_redirect(void)cleanup_network (net_config); } + +void test_xdp_veth_redirect (void ) +{ +if (test__start_subtest ("0" )) +xdp_veth_redirect (0 ); + +if (test__start_subtest ("DRV_MODE" )) +xdp_veth_redirect (XDP_FLAGS_DRV_MODE ); + +if (test__start_subtest ("SKB_MODE" )) +xdp_veth_redirect (XDP_FLAGS_SKB_MODE ); +}
Signature · 1 line
2.48.1
PATCH v4 11/14 selftests/bpf: Optionally select broadcasting flags
In reply to Bastien Curutchet (eBPF Foundation)Broadcasting flags are hardcoded for each kind for protocol.
Create a redirect_flags map that allows to select the broadcasting flags to use in the bpf_redirect_map(). The protocol ID is used as a key. Set the old hardcoded values as default if the map isn't filled by the BPF caller.
--- .../selftests/bpf/progs/xdp_redirect_multi_kern.c | 41 +++++++++++++++------- 1 file changed, 29 insertions(+), 12 deletions(-)
tools/testing/selftests/bpf/progs/xdp_redirect_multi_kern.c +29 -12
@@ -34,6 +34,14 @@ struct {__uint (max_entries,128 ); } mac_map SEC(".maps"); +/* map to store redirect flags for each protocol*/ +struct { + __uint(type, BPF_MAP_TYPE_HASH); + __type(key, __u16); + __type(value, __u64); + __uint(max_entries, 16); +} redirect_flags SEC(".maps"); + SEC("xdp")int xdp_redirect_map_multi_prog (struct xdp_md *ctx) {
@@ -41,25 +49,34 @@ int xdp_redirect_map_multi_prog(struct xdp_md *ctx)void *data = (void *)(long )ctx->data;int if_index = ctx->ingress_ifindex;struct ethhdr *eth = data; +__u64 *flags_from_map;__u16 h_proto;__u64 nh_off; +__u64 flags; nh_off =sizeof (*eth);if (data + nh_off > data_end)return XDP_DROP ; - h_proto = eth->h_proto; - -/* Using IPv4 for (BPF_F_BROADCAST | BPF_F_EXCLUDE_INGRESS) testing */ -if (h_proto ==bpf_htons (ETH_P_IP )) -return bpf_redirect_map (&map_all,0 , -BPF_F_BROADCAST |BPF_F_EXCLUDE_INGRESS ); -/* Using IPv6 for none flag testing */ -else if (h_proto ==bpf_htons (ETH_P_IPV6 )) -return bpf_redirect_map (&map_all, if_index,0 ); -/* All others for BPF_F_BROADCAST testing */ -else -return bpf_redirect_map (&map_all,0 ,BPF_F_BROADCAST ); + h_proto =bpf_htons (eth->h_proto); + + flags_from_map =bpf_map_lookup_elem (&redirect_flags, &h_proto); + +/* Default flags for IPv4 : (BPF_F_BROADCAST | BPF_F_EXCLUDE_INGRESS) */ +if (h_proto ==ETH_P_IP ) { + flags = flags_from_map ? *flags_from_map :BPF_F_BROADCAST |BPF_F_EXCLUDE_INGRESS ; +return bpf_redirect_map (&map_all,0 , flags); + } +/* Default flags for IPv6 : 0 */ +if (h_proto ==ETH_P_IPV6 ) { + flags = flags_from_map ? *flags_from_map :0 ; +return bpf_redirect_map (&map_all, if_index, flags); + } +/* Default flags for others BPF_F_BROADCAST : 0 */ +else { + flags = flags_from_map ? *flags_from_map :BPF_F_BROADCAST ; +return bpf_redirect_map (&map_all,0 , flags); + } }/* The following 2 progs are for 2nd devmap prog testing */
Signature · 1 line
2.48.1
PATCH v4 12/14 selftests/bpf: test_xdp_veth: Add XDP broadcast redirection tests
In reply to Bastien Curutchet (eBPF Foundation)XDP redirections with BPF_F_BROADCAST and BPF_F_EXCLUDE_INGRESS flags are tested by test_xdp_redirect_multi.sh but not within the test_progs framework.
Add a broadcast test case in test_xdp_veth.c to test them. Use the same BPF programs than the one used by test_xdp_redirect_multi.sh.
Use a BPF map to select the broadcast flags.
Use a BPF map with an entry per veth to check whether packets are received or not
--- .../selftests/bpf/prog_tests/test_xdp_veth.c | 150 +++++++++++++++++++++ .../testing/selftests/bpf/progs/xdp_redirect_map.c | 49 +++++++ 2 files changed, 199 insertions(+)
tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c +150 -0
@@ -24,6 +24,23 @@* | | | | | | * | ------------------ ------------------ | * ----------------------------------------- +* +* - [test_xdp_veth_broadcast_redirect]: broadcast from veth11 +* - IPv4 ping : BPF_F_BROADCAST | BPF_F_EXCLUDE_INGRESS +* -> echo request received by all except veth11 +* - IPv4 ping : BPF_F_BROADCAST +* -> echo request received by all veth +* +* veth11 veth22 veth33 +* (XDP_PASS) (XDP_PASS) (XDP_PASS) +* | | | +* | | | +* veth1 veth2 veth3 +* (XDP_REDIRECT) (XDP_REDIRECT) (XDP_REDIRECT) +* | ^ ^ +* | | | +* ---------------------------------------- +* */ #define _GNU_SOURCE
@@ -32,6 +49,7 @@#include "network_helpers.h" #include "xdp_dummy.skel.h" #include "xdp_redirect_map.skel.h" +#include "xdp_redirect_multi_kern.skel.h" #include "xdp_tx.skel.h" #include <uapi/linux/if_link.h>
@@ -40,6 +58,7 @@#define IP_MAX_LEN 16#define IP_SRC "10.1.1.11"#define IP_DST "10.1.1.33" +#define IP_NEIGH "10.1.1.253"#define PROG_NAME_MAX_LEN 128#define NS_NAME_MAX_LEN 32
@@ -273,6 +292,114 @@ static void xdp_veth_redirect(u32 flags)cleanup_network (net_config); } +#define BROADCAST_REDIRECT_SKEL_NB 2 +static void xdp_veth_broadcast_redirect (u32 attach_flags,u64 redirect_flags) +{ +struct prog_configuration prog_cfg[VETH_PAIRS_COUNT ] = { + { + .local_name ="xdp_redirect_map_multi_prog" , + .remote_name ="xdp_count_0" , + .local_flags = attach_flags, + .remote_flags = attach_flags, + }, + { + .local_name ="xdp_redirect_map_multi_prog" , + .remote_name ="xdp_count_1" , + .local_flags = attach_flags, + .remote_flags = attach_flags, + }, + { + .local_name ="xdp_redirect_map_multi_prog" , + .remote_name ="xdp_count_2" , + .local_flags = attach_flags, + .remote_flags = attach_flags, + } + }; +struct bpf_object *bpf_objs[BROADCAST_REDIRECT_SKEL_NB ]; +struct xdp_redirect_multi_kern *xdp_redirect_multi_kern; +struct veth_configuration net_config[VETH_PAIRS_COUNT ]; +struct xdp_redirect_map *xdp_redirect_map; +struct bpf_devmap_val devmap_val = {}; +u16 protocol =ETH_P_IP ; +int group_map; +int flags_map; +int cnt_map; +u64 cnt =0 ; +int i, err; + + xdp_redirect_multi_kern =xdp_redirect_multi_kern__open_and_load (); +if (!ASSERT_OK_PTR (xdp_redirect_multi_kern,"xdp_redirect_multi_kern__open_and_load" )) +return ; + + xdp_redirect_map =xdp_redirect_map__open_and_load (); +if (!ASSERT_OK_PTR (xdp_redirect_map,"xdp_redirect_map__open_and_load" )) + goto destroy_xdp_redirect_multi_kern; + +if (!ASSERT_OK (create_network (net_config),"create network" )) + goto destroy_xdp_redirect_map; + + group_map =bpf_map__fd (xdp_redirect_multi_kern->maps.map_all); +if (!ASSERT_OK_FD (group_map,"open map_all" )) + goto destroy_xdp_redirect_map; + + flags_map =bpf_map__fd (xdp_redirect_multi_kern->maps.redirect_flags); +if (!ASSERT_OK_FD (group_map,"open map_all" )) + goto destroy_xdp_redirect_map; + + err =bpf_map_update_elem (flags_map, &protocol, &redirect_flags,BPF_NOEXIST ); +if (!ASSERT_OK (err,"init IP count" )) + goto destroy_xdp_redirect_map; + + cnt_map =bpf_map__fd (xdp_redirect_map->maps.rxcnt); +if (!ASSERT_OK_FD (cnt_map,"open rxcnt map" )) + goto destroy_xdp_redirect_map; + + bpf_objs[0 ] = xdp_redirect_multi_kern->obj; + bpf_objs[1 ] = xdp_redirect_map->obj; +for (i =0 ; i <VETH_PAIRS_COUNT ; i++) { +int ifindex =if_nametoindex (net_config[i].local_veth); + +if (attach_programs_to_veth_pair (bpf_objs,BROADCAST_REDIRECT_SKEL_NB , + net_config, prog_cfg, i)) + goto destroy_xdp_redirect_map; + +SYS (destroy_xdp_redirect_map, +"ip -n %s neigh add %s lladdr 00:00:00:00:00:01 dev %s" , + net_config[i].namespace,IP_NEIGH , net_config[i].remote_veth); + + devmap_val.ifindex = ifindex; + err =bpf_map_update_elem (group_map, &ifindex, &devmap_val,0 ); +if (!ASSERT_OK (err,"bpf_map_update_elem" )) + goto destroy_xdp_redirect_map; + + } + +SYS_NOFAIL ("ip netns exec %s ping %s -i 0.1 -c 4 -W1 > /dev/null " , + net_config[0 ].namespace,IP_NEIGH ); + +for (i =0 ; i <VETH_PAIRS_COUNT ; i++) { + err =bpf_map_lookup_elem (cnt_map, &i, &cnt); +if (!ASSERT_OK (err,"get IP cnt" )) + goto destroy_xdp_redirect_map; + +if (redirect_flags &BPF_F_EXCLUDE_INGRESS ) +/* veth11 shouldn't receive the ICMP requests; +* others should +*/ +ASSERT_EQ (cnt, i ?4 :0 ,"compare IP cnt" ); +else +/* All remote veth should receive the ICMP requests */ +ASSERT_EQ (cnt,4 ,"compare IP cnt" ); + } + +destroy_xdp_redirect_map: +xdp_redirect_map__destroy (xdp_redirect_map); +destroy_xdp_redirect_multi_kern: +xdp_redirect_multi_kern__destroy (xdp_redirect_multi_kern); + +cleanup_network (net_config); +} +void test_xdp_veth_redirect (void ) {if (test__start_subtest ("0" ))
@@ -284,3 +411,26 @@ void test_xdp_veth_redirect(void)if (test__start_subtest ("SKB_MODE" ))xdp_veth_redirect (XDP_FLAGS_SKB_MODE ); } + +void test_xdp_veth_broadcast_redirect (void ) +{ +if (test__start_subtest ("0/BROADCAST" )) +xdp_veth_broadcast_redirect (0 ,BPF_F_BROADCAST ); + +if (test__start_subtest ("0/(BROADCAST | EXCLUDE_INGRESS)" )) +xdp_veth_broadcast_redirect (0 ,BPF_F_BROADCAST |BPF_F_EXCLUDE_INGRESS ); + +if (test__start_subtest ("DRV_MODE/BROADCAST" )) +xdp_veth_broadcast_redirect (XDP_FLAGS_DRV_MODE ,BPF_F_BROADCAST ); + +if (test__start_subtest ("DRV_MODE/(BROADCAST | EXCLUDE_INGRESS)" )) +xdp_veth_broadcast_redirect (XDP_FLAGS_DRV_MODE , +BPF_F_BROADCAST |BPF_F_EXCLUDE_INGRESS ); + +if (test__start_subtest ("SKB_MODE/BROADCAST" )) +xdp_veth_broadcast_redirect (XDP_FLAGS_SKB_MODE ,BPF_F_BROADCAST ); + +if (test__start_subtest ("SKB_MODE/(BROADCAST | EXCLUDE_INGRESS)" )) +xdp_veth_broadcast_redirect (XDP_FLAGS_SKB_MODE , +BPF_F_BROADCAST |BPF_F_EXCLUDE_INGRESS ); +}
tools/testing/selftests/bpf/progs/xdp_redirect_map.c +49 -0
60 lines not on this page · raw message
Signature · 1 line
2.48.1
Martin KaFai Lau
reviewerRe: [PATCH bpf-next v4 12/14] selftests/bpf: test_xdp_veth: Add XDP broadcast redirection tests
Quoted 67 lines · Bastien Curutchet (eBPF Foundation)
tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c +67
-0+#define BROADCAST_REDIRECT_SKEL_NB 2 +static void xdp_veth_broadcast_redirect (u32 attach_flags,u64 redirect_flags) +{ +struct prog_configuration prog_cfg[VETH_PAIRS_COUNT ] = { + { + .local_name ="xdp_redirect_map_multi_prog" , + .remote_name ="xdp_count_0" , + .local_flags = attach_flags, + .remote_flags = attach_flags, + }, + { + .local_name ="xdp_redirect_map_multi_prog" , + .remote_name ="xdp_count_1" , + .local_flags = attach_flags, + .remote_flags = attach_flags, + }, + { + .local_name ="xdp_redirect_map_multi_prog" , + .remote_name ="xdp_count_2" , + .local_flags = attach_flags, + .remote_flags = attach_flags, + } + }; +struct bpf_object *bpf_objs[BROADCAST_REDIRECT_SKEL_NB ]; +struct xdp_redirect_multi_kern *xdp_redirect_multi_kern; +struct veth_configuration net_config[VETH_PAIRS_COUNT ]; +struct xdp_redirect_map *xdp_redirect_map; +struct bpf_devmap_val devmap_val = {}; +u16 protocol =ETH_P_IP ; +int group_map; +int flags_map; +int cnt_map; +u64 cnt =0 ; +int i, err; + + xdp_redirect_multi_kern =xdp_redirect_multi_kern__open_and_load (); +if (!ASSERT_OK_PTR (xdp_redirect_multi_kern,"xdp_redirect_multi_kern__open_and_load" )) +return ; + + xdp_redirect_map =xdp_redirect_map__open_and_load (); +if (!ASSERT_OK_PTR (xdp_redirect_map,"xdp_redirect_map__open_and_load" )) + goto destroy_xdp_redirect_multi_kern; + +if (!ASSERT_OK (create_network (net_config),"create network" )) + goto destroy_xdp_redirect_map; + + group_map =bpf_map__fd (xdp_redirect_multi_kern->maps.map_all); +if (!ASSERT_OK_FD (group_map,"open map_all" )) + goto destroy_xdp_redirect_map; + + flags_map =bpf_map__fd (xdp_redirect_multi_kern->maps.redirect_flags); +if (!ASSERT_OK_FD (group_map,"open map_all" )) + goto destroy_xdp_redirect_map; + + err =bpf_map_update_elem (flags_map, &protocol, &redirect_flags,BPF_NOEXIST ); +if (!ASSERT_OK (err,"init IP count" )) + goto destroy_xdp_redirect_map; + + cnt_map =bpf_map__fd (xdp_redirect_map->maps.rxcnt); +if (!ASSERT_OK_FD (cnt_map,"open rxcnt map" )) + goto destroy_xdp_redirect_map; + + bpf_objs[0 ] = xdp_redirect_multi_kern->obj; + bpf_objs[1 ] = xdp_redirect_map->obj; +for (i =0 ; i <VETH_PAIRS_COUNT ; i++) { +int ifindex =if_nametoindex (net_config[i].local_veth); +
tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c static void xdp_veth_redirect(u32 flags) · line 371
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c +10
-0+if (attach_programs_to_veth_pair (bpf_objs,BROADCAST_REDIRECT_SKEL_NB , + net_config, prog_cfg, i)) + goto destroy_xdp_redirect_map; + +SYS (destroy_xdp_redirect_map, +"ip -n %s neigh add %s lladdr 00:00:00:00:00:01 dev %s" , + net_config[i].namespace,IP_NEIGH , net_config[i].remote_veth); + + devmap_val.ifindex = ifindex; + err =bpf_map_update_elem (group_map, &ifindex, &devmap_val,0 );
I ran this test in a loop and failed at this line permanently (errno E2BIG -7) after enough iterations. I believe the problem is the group_map (aka "map_all" in the BPF program) has a max_entries 1024 and ifindex can go beyond 1024 after some "./test_progs" iterations. Understood that it is likely an existing assumption in the "map_all" definition but it needs to be addressed first before moving to test_progs.
Quoted 66 lines
tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c +54
-0+if (!ASSERT_OK (err,"bpf_map_update_elem" )) + goto destroy_xdp_redirect_map; + + } + +SYS_NOFAIL ("ip netns exec %s ping %s -i 0.1 -c 4 -W1 > /dev/null " , + net_config[0 ].namespace,IP_NEIGH ); + +for (i =0 ; i <VETH_PAIRS_COUNT ; i++) { + err =bpf_map_lookup_elem (cnt_map, &i, &cnt); +if (!ASSERT_OK (err,"get IP cnt" )) + goto destroy_xdp_redirect_map; + +if (redirect_flags &BPF_F_EXCLUDE_INGRESS ) +/* veth11 shouldn't receive the ICMP requests; +* others should +*/ +ASSERT_EQ (cnt, i ?4 :0 ,"compare IP cnt" ); +else +/* All remote veth should receive the ICMP requests */ +ASSERT_EQ (cnt,4 ,"compare IP cnt" ); + } + +destroy_xdp_redirect_map: +xdp_redirect_map__destroy (xdp_redirect_map); +destroy_xdp_redirect_multi_kern: +xdp_redirect_multi_kern__destroy (xdp_redirect_multi_kern); + +cleanup_network (net_config); +} +void test_xdp_veth_redirect (void ) {if (test__start_subtest ("0" ))@@ -284,3 +411,26 @@ void test_xdp_veth_redirect(void)if (test__start_subtest ("SKB_MODE" ))xdp_veth_redirect (XDP_FLAGS_SKB_MODE ); } + +void test_xdp_veth_broadcast_redirect (void ) +{ +if (test__start_subtest ("0/BROADCAST" )) +xdp_veth_broadcast_redirect (0 ,BPF_F_BROADCAST ); + +if (test__start_subtest ("0/(BROADCAST | EXCLUDE_INGRESS)" )) +xdp_veth_broadcast_redirect (0 ,BPF_F_BROADCAST |BPF_F_EXCLUDE_INGRESS ); + +if (test__start_subtest ("DRV_MODE/BROADCAST" )) +xdp_veth_broadcast_redirect (XDP_FLAGS_DRV_MODE ,BPF_F_BROADCAST ); + +if (test__start_subtest ("DRV_MODE/(BROADCAST | EXCLUDE_INGRESS)" )) +xdp_veth_broadcast_redirect (XDP_FLAGS_DRV_MODE , +BPF_F_BROADCAST |BPF_F_EXCLUDE_INGRESS ); + +if (test__start_subtest ("SKB_MODE/BROADCAST" )) +xdp_veth_broadcast_redirect (XDP_FLAGS_SKB_MODE ,BPF_F_BROADCAST ); + +if (test__start_subtest ("SKB_MODE/(BROADCAST | EXCLUDE_INGRESS)" )) +xdp_veth_broadcast_redirect (XDP_FLAGS_SKB_MODE , +BPF_F_BROADCAST |BPF_F_EXCLUDE_INGRESS ); +}tools/testing/selftests/bpf/progs/xdp_redirect_map.c +0
-0
tools/testing/selftests/bpf/progs/xdp_redirect_map.c line 4
Quoted 4 lines
tools/testing/selftests/bpf/progs/xdp_redirect_map.c +2
-0@@ -1,7 +1,11 @@// SPDX-License-Identifier: GPL-2.0 +#include <linux/if_ether.h> +#include <linux/ip.h>
I have compiler error complaining about __always_inline not defined. Likely ordering issue and environment specific. Regardless, I believe the ip.h is unnecessary, so better clean it up.
I am going to land the patch 1-10 and change the cover letter a little to reflect the fact that patch 11-14 will be a followup. Please post the remaining patches after fixing the bpf_map_update_elem issue. Thanks.
Quoted 58 lines
tools/testing/selftests/bpf/progs/xdp_redirect_map.c +47
-0+#include <linux/bpf.h> #include <bpf/bpf_helpers.h> +#include <bpf/bpf_endian.h> struct { __uint(type, BPF_MAP_TYPE_DEVMAP);@@ -28,4 +32,49 @@ int xdp_redirect_map_2(struct xdp_md *xdp)return bpf_redirect_map (&tx_port,2 ,0 ); } +struct { + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 3); + __type(key, __u32); + __type(value, __u64); +} rxcnt SEC(".maps"); + +static int xdp_count (struct xdp_md *xdp,__u32 key) +{ +void *data_end = (void *)(long )xdp->data_end; +void *data = (void *)(long )xdp->data; +struct ethhdr *eth = data; +__u64 *count; + +if (data +sizeof (*eth) > data_end) +return XDP_DROP ; + +if (bpf_htons (eth->h_proto) ==ETH_P_IP ) { +/* We only count IPv4 packets */ + count =bpf_map_lookup_elem (&rxcnt, &key); +if (count) + *count +=1 ; + } + +return XDP_PASS ; +} + +SEC("xdp") +int xdp_count_0 (struct xdp_md *xdp) +{ +return xdp_count (xdp,0 ); +} + +SEC("xdp") +int xdp_count_1 (struct xdp_md *xdp) +{ +return xdp_count (xdp,1 ); +} + +SEC("xdp") +int xdp_count_2 (struct xdp_md *xdp) +{ +return xdp_count (xdp,2 ); +} + char _license[] SEC("license") = "GPL";
Re: [PATCH bpf-next v4 12/14] selftests/bpf: test_xdp_veth: Add XDP broadcast redirection tests
Hi Martin,
Quoted 3 lines · Martin KaFai Lau
Quoted 2 lines · Bastien Curutchet (eBPF Foundation)
(quoted diff) +2
-0+#define BROADCAST_REDIRECT_SKEL_NB 2 +static void xdp_veth_broadcast_redirect(u32 attach_flags, u64
[...]
Quoted 44 lines
Quoted 28 lines
tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c +6
-0+ + group_map = bpf_map__fd(xdp_redirect_multi_kern->maps.map_all); + if (!ASSERT_OK_FD(group_map, "open map_all")) + goto destroy_xdp_redirect_map; + + flags_map = bpf_map__fd(xdp_redirect_multi_kern-Quoted 1 line
maps.redirect_flags);
+ if (!ASSERT_OK_FD(group_map, "open
map_all"))
+ gotodestroy_xdp_redirect_map;
+
+ err =bpf_map_update_elem(flags_map, &protocol, &redirect_flags, BPF_NOEXIST);
+ if (!ASSERT_OK(err, "init IP count"))
+ gotodestroy_xdp_redirect_map;tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c +11
-0+ + cnt_map = bpf_map__fd(xdp_redirect_map->maps.rxcnt); + if (!ASSERT_OK_FD(cnt_map, "open rxcnt map")) + goto destroy_xdp_redirect_map; + + bpf_objs[0] = xdp_redirect_multi_kern->obj; + bpf_objs[1] = xdp_redirect_map->obj; + for (i = 0; i < VETH_PAIRS_COUNT; i++) { + int ifindex = if_nametoindex(net_config[i].local_veth); + + if (attach_programs_to_veth_pair(bpf_objs,
BROADCAST_REDIRECT_SKEL_NB,
+net_config,prog_cfg, i)) + gotodestroy_xdp_redirect_map;Quoted 8 lines
+
+ SYS(destroy_xdp_redirect_map,
+ "ip -n %s neigh add %s lladdr 00:00:00:00:00:01 dev %s", + net_config[i].namespace,IP_NEIGH, net_config[i].remote_veth);
+
+ devmap_val.ifindex = ifindex;
+ err =bpf_map_update_elem(group_map, &ifindex, &devmap_val, 0);I ran this test in a loop and failed at this line permanently (errno E2BIG -7) after enough iterations. I believe the problem is the
group_map(aka "map_all" in the BPF program) has amax_entries1024 and ifindex can go beyond 1024 after some "./test_progs" iterations. Understood that it is likely an existing assumption in the "map_all" definition but it needs to be addressed first before moving totest_progs.Quoted 5 lines
+ if (!ASSERT_OK(err, "
bpf_map_update_elem")) + gotodestroy_xdp_redirect_map;tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c +3
-0+ + } +
[...]
Quoted 11 lines
tools/testing/selftests/bpf/progs/xdp_redirect_map.c line 3
Quoted 8 lines
tools/testing/selftests/bpf/progs/xdp_redirect_map.c +2
-0@@ -1,7 +1,11 @@ // SPDX-License-Identifier: GPL-2.0 +#include <linux/if_ether.h> +#include <linux/ip.h> I have compiler error complaining about
__always_inlinenot defined. Likely ordering issue and environment specific. Regardless, I believe theip.his unnecessary, so better clean it up.
Quoted 2 lines
I am going to land the patch 1-10 and change the cover letter a little to reflect the fact that patch 11-14 will be a followup. Please post the remaining patches after fixing the
bpf_map_update_elemissue. Thanks.
Ok thank you, I plan to solve this issue by using a dedicated namespace instead of the root namespace so the index won't be incremented every time test_progs is launched. I'll send the new iteration once tested on my side.
Best regards,
Bastien
PATCH v4 13/14 selftests/bpf: test_xdp_veth: Add XDP program on egress test
In reply to Bastien Curutchet (eBPF Foundation)XDP programs loaded on egress is tested by test_xdp_redirect_multi.sh but not by the test_progs framework.
Add a test case in test_xdp_veth.c to test the XDP program on egress. Use the same BPF program than test_xdp_redirect_multi.sh that replaces the source MAC address by one provided through a BPF map. Use a BPF program that stores the source MAC of received packets in a map to check the test results.
--- .../selftests/bpf/prog_tests/test_xdp_veth.c | 125 +++++++++++++++++++++ .../testing/selftests/bpf/progs/xdp_redirect_map.c | 40 +++++++ 2 files changed, 165 insertions(+)
tools/testing/selftests/bpf/prog_tests/test_xdp_veth.c +125 -0
@@ -30,6 +30,8 @@* -> echo request received by all except veth11 * - IPv4 ping : BPF_F_BROADCAST * -> echo request received by all veth +* - [test_xdp_veth_egress]: +* - all src mac should be the magic mac * * veth11 veth22 veth33 * (XDP_PASS) (XDP_PASS) (XDP_PASS)
@@ -400,6 +402,117 @@ static void xdp_veth_broadcast_redirect(u32 attach_flags, u64 redirect_flags)cleanup_network (net_config); } +#define VETH_EGRESS_SKEL_NB 3 +static void xdp_veth_egress (u32 flags) +{ +struct prog_configuration prog_cfg[VETH_PAIRS_COUNT ] = { + { + .local_name ="xdp_redirect_map_all_prog" , + .remote_name ="xdp_dummy_prog" , + .local_flags = flags, + .remote_flags = flags, + }, + { + .local_name ="xdp_redirect_map_all_prog" , + .remote_name ="store_mac_1" , + .local_flags = flags, + .remote_flags = flags, + }, + { + .local_name ="xdp_redirect_map_all_prog" , + .remote_name ="store_mac_2" , + .local_flags = flags, + .remote_flags = flags, + } + }; +const char magic_mac[6 ] = {0xAA ,0xBB ,0xCC ,0xDD ,0xEE ,0xFF }; +struct xdp_redirect_multi_kern *xdp_redirect_multi_kern; +struct veth_configuration net_config[VETH_PAIRS_COUNT ]; +struct bpf_object *bpf_objs[VETH_EGRESS_SKEL_NB ]; +struct xdp_redirect_map *xdp_redirect_map; +struct bpf_devmap_val devmap_val = {}; +int mac_map, egress_map, res_map; +struct xdp_dummy *xdp_dummy; +int err; +int i; + + xdp_dummy =xdp_dummy__open_and_load (); +if (!ASSERT_OK_PTR (xdp_dummy,"xdp_dummy__open_and_load" )) +return ; + + xdp_redirect_multi_kern =xdp_redirect_multi_kern__open_and_load (); +if (!ASSERT_OK_PTR (xdp_redirect_multi_kern,"xdp_redirect_multi_kern__open_and_load" )) + goto destroy_xdp_dummy; + + xdp_redirect_map =xdp_redirect_map__open_and_load (); +if (!ASSERT_OK_PTR (xdp_redirect_map,"xdp_redirect_map__open_and_load" )) + goto destroy_xdp_redirect_multi_kern; + +if (!ASSERT_OK (create_network (net_config),"create network" )) + goto destroy_xdp_redirect_map; + + mac_map =bpf_map__fd (xdp_redirect_multi_kern->maps.mac_map); +if (!ASSERT_OK_FD (mac_map,"open mac_map" )) + goto destroy_xdp_redirect_map; + + egress_map =bpf_map__fd (xdp_redirect_multi_kern->maps.map_egress); +if (!ASSERT_OK_FD (egress_map,"open map_egress" )) + goto destroy_xdp_redirect_map; + + devmap_val.bpf_prog.fd =bpf_program__fd (xdp_redirect_multi_kern->progs.xdp_devmap_prog); + + bpf_objs[0 ] = xdp_dummy->obj; + bpf_objs[1 ] = xdp_redirect_multi_kern->obj; + bpf_objs[2 ] = xdp_redirect_map->obj; +for (i =0 ; i <VETH_PAIRS_COUNT ; i++) { +int ifindex =if_nametoindex (net_config[i].local_veth); + +SYS (destroy_xdp_redirect_map, +"ip -n %s neigh add %s lladdr 00:00:00:00:00:01 dev %s" , + net_config[i].namespace,IP_NEIGH , net_config[i].remote_veth); + +if (attach_programs_to_veth_pair (bpf_objs,VETH_REDIRECT_SKEL_NB , + net_config, prog_cfg, i)) + goto destroy_xdp_redirect_map; + + err =bpf_map_update_elem (mac_map, &ifindex, magic_mac,0 ); +if (!ASSERT_OK (err,"bpf_map_update_elem" )) + goto destroy_xdp_redirect_map; + + devmap_val.ifindex = ifindex; + err =bpf_map_update_elem (egress_map, &ifindex, &devmap_val,0 ); +if (!ASSERT_OK (err,"bpf_map_update_elem" )) + goto destroy_xdp_redirect_map; + } + +SYS_NOFAIL ("ip netns exec %s ping %s -i 0.1 -c 4 -W1 > /dev/null " , + net_config[0 ].namespace,IP_NEIGH ); + + res_map =bpf_map__fd (xdp_redirect_map->maps.rx_mac); +if (!ASSERT_OK_FD (res_map,"open rx_map" )) + goto destroy_xdp_redirect_map; + +for (i =0 ; i <2 ; i++) { +u32 key = i; +u64 res; + + err =bpf_map_lookup_elem (res_map, &key, &res); +if (!ASSERT_OK (err,"get MAC res" )) + goto destroy_xdp_redirect_map; + +ASSERT_STRNEQ ((const char *)&res, magic_mac,ETH_ALEN ,"compare mac" ); + } + +destroy_xdp_redirect_map: +xdp_redirect_map__destroy (xdp_redirect_map); +destroy_xdp_redirect_multi_kern: +xdp_redirect_multi_kern__destroy (xdp_redirect_multi_kern); +destroy_xdp_dummy: +xdp_dummy__destroy (xdp_dummy); + +cleanup_network (net_config); +} +void test_xdp_veth_redirect (void ) {if (test__start_subtest ("0" ))
@@ -434,3 +547,15 @@ void test_xdp_veth_broadcast_redirect(void)xdp_veth_broadcast_redirect (XDP_FLAGS_SKB_MODE ,BPF_F_BROADCAST |BPF_F_EXCLUDE_INGRESS ); } + +void test_xdp_veth_egress (void ) +{ +if (test__start_subtest ("0/egress" )) +xdp_veth_egress (0 ); + +if (test__start_subtest ("DRV_MODE/egress" )) +xdp_veth_egress (XDP_FLAGS_DRV_MODE ); + +if (test__start_subtest ("SKB_MODE/egress" )) +xdp_veth_egress (XDP_FLAGS_SKB_MODE ); +}
tools/testing/selftests/bpf/progs/xdp_redirect_map.c +40 -0
@@ -77,4 +77,44 @@ int xdp_count_2(struct xdp_md *xdp)return xdp_count (xdp,2 ); } +struct { + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 2); + __type(key, __u32); + __type(value, __be64); +} rx_mac SEC(".maps"); + +static int store_mac (struct xdp_md *xdp,__u32 id) +{ +void *data_end = (void *)(long )xdp->data_end; +void *data = (void *)(long )xdp->data; +struct ethhdr *eth = data; +__u32 key = id; +__be64 mac =0 ; + +if (data +sizeof (*eth) > data_end) +return XDP_DROP ; + +/* Only store IPv4 MAC to avoid being polluted by IPv6 packets */ +if (eth->h_proto ==bpf_htons (ETH_P_IP )) { +__builtin_memcpy (&mac, eth->h_source,ETH_ALEN ); +bpf_map_update_elem (&rx_mac, &key, &mac,0 ); +bpf_printk ("%s - %x" , __func__, mac); + } + +return XDP_PASS ; +} + +SEC("xdp") +int store_mac_1 (struct xdp_md *xdp) +{ +return store_mac (xdp,0 ); +} + +SEC("xdp") +int store_mac_2 (struct xdp_md *xdp) +{ +return store_mac (xdp,1 ); +} + char _license[] SEC("license") = "GPL";
Signature · 1 line
2.48.1
PATCH v4 14/14 selftests/bpf: Remove test_xdp_redirect_multi.sh
In reply to Bastien Curutchet (eBPF Foundation)The tests done by test_xdp_redirect_multi.sh are now fully covered by the CI through test_xdp_veth.c.
Remove test_xdp_redirect_multi.sh
Remove xdp_redirect_multi.c that was used by the script to load and attach the BPF programs.
Remove their entries in the Makefile
--- tools/testing/selftests/bpf/Makefile | 2 - .../selftests/bpf/test_xdp_redirect_multi.sh | 214 ------------------- tools/testing/selftests/bpf/xdp_redirect_multi.c | 226 --------------------- 3 files changed, 442 deletions(-)
tools/testing/selftests/bpf/Makefile +0 -2
@@ -100,7 +100,6 @@ TEST_FILES = xsk_prereqs.sh $(wildcard progs/btf_dump_test_case_*.c) # Order correspond to 'make run_tests' order TEST_PROGS := test_kmod.sh \ - test_xdp_redirect_multi.sh \ test_tunnel.sh \ test_lwt_seg6local.sh \ test_lirc_mode2.sh \
@@ -135,7 +134,6 @@ TEST_GEN_PROGS_EXTENDED = \ veristat \ xdp_features \ xdp_hw_metadata \ - xdp_redirect_multi \ xdp_synproxy \ xdping \ xskxceiver
tools/testing/selftests/bpf/test_xdp_redirect_multi.sh deleted +0 -214
214 lines not on this page · raw message
tools/testing/selftests/bpf/xdp_redirect_multi.c deleted +0 -226
226 lines not on this page · raw message
Signature · 1 line
2.48.1