selftests/bpf: Migrate test_tunnel.sh to test_progs
Subsystems (3)
cover selftests/bpf: Migrate test_tunnel.sh to test_progs
Hi all,
This patch series continues the work to migrate the *.sh tests into prog_tests framework.
The test_tunnel.sh script has already been partly migrated to test_progs in prog_tests/test_tunnel.c so I add my work to it.
PATCH 1 & 2 create some helpers to avoid code duplication and ease the migration in the following patches.
PATCH 3 to 9 migrate the tests of gre, ip6gre, erspan, ip6erspan, geneve, ip6geneve and ip6tnl tunnels.
PATCH 10 removes test_tunnel.sh
---
Bastien Curutchet (eBPF Foundation) (10):
selftests/bpf: test_tunnel: Add generic_attach* helpers selftests/bpf: test_tunnel: Add ping helpers selftests/bpf: test_tunnel: Move gre tunnel test to test_progs selftests/bpf: test_tunnel: Move ip6gre tunnel test to test_progs selftests/bpf: test_tunnel: Move erspan tunnel tests to test_progs selftests/bpf: test_tunnel: Move ip6erspan tunnel test to test_progs selftests/bpf: test_tunnel: Move geneve tunnel test to test_progs selftests/bpf: test_tunnel: Move ip6geneve tunnel test to test_progs selftests/bpf: test_tunnel: Move ip6tnl tunnel tests to test_progs selftests/bpf: test_tunnel: Remove test_tunnel.sh
tools/testing/selftests/bpf/Makefile | 1 - .../testing/selftests/bpf/prog_tests/test_tunnel.c | 627 +++++++++++++++++--- tools/testing/selftests/bpf/test_tunnel.sh | 645 --------------------- 3 files changed, 532 insertions(+), 741 deletions(-)
---
base-commit: 16566afa71143757b49fc4b2a331639f487d105a
change-id: 20250131-tunnels-59b641ea3f10
Best regards,
Signature · 1 line
Bastien Curutchet (eBPF Foundation) <[email protected]>
PATCH 1/10 selftests/bpf: test_tunnel: Add generic_attach* helpers
A fair amount of code duplication is present among tests to attach BPF programs.
Create generic_attach* helpers that attach BPF programs to a given interface.
Use ASSERT_OK_FD() instead of ASSERT_GE() to check fd's validity. Use these helpers in all the available tests.
--- .../testing/selftests/bpf/prog_tests/test_tunnel.c | 128 ++++++++++----------- 1 file changed, 62 insertions(+), 66 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_tunnel.c +62 -66
@@ -397,6 +397,56 @@ static int attach_tc_prog(struct bpf_tc_hook *hook, int igr_fd, int egr_fd)return 0 ; } +static int generic_attach (const char *dev,int igr_fd,int egr_fd) +{ + DECLARE_LIBBPF_OPTS(bpf_tc_hook, tc_hook, .attach_point = BPF_TC_INGRESS); +int ifindex =-1 ; + +if (!ASSERT_OK_FD (igr_fd,"check ingress fd" )) +return -1 ; +if (!ASSERT_OK_FD (egr_fd,"check egress fd" )) +return -1 ; + + ifindex =if_nametoindex (dev); +if (!ASSERT_NEQ (ifindex,0 ,"get ifindex" )) +return -1 ; + + tc_hook.ifindex = ifindex; +return attach_tc_prog (&tc_hook, igr_fd, egr_fd); +} + +static int generic_attach_igr (const char *dev,int igr_fd) +{ + DECLARE_LIBBPF_OPTS(bpf_tc_hook, tc_hook, .attach_point = BPF_TC_INGRESS); +int ifindex =-1 ; + +if (!ASSERT_OK_FD (igr_fd,"check ingress fd" )) +return -1 ; + + ifindex =if_nametoindex (dev); +if (!ASSERT_NEQ (ifindex,0 ,"get ifindex" )) +return -1 ; + + tc_hook.ifindex = ifindex; +return attach_tc_prog (&tc_hook, igr_fd,-1 ); +} + +static int generic_attach_egr (const char *dev,int egr_fd) +{ + DECLARE_LIBBPF_OPTS(bpf_tc_hook, tc_hook, .attach_point = BPF_TC_EGRESS); +int ifindex =-1 ; + +if (!ASSERT_OK_FD (egr_fd,"check egress fd" )) +return -1 ; + + ifindex =if_nametoindex (dev); +if (!ASSERT_NEQ (ifindex,0 ,"get ifindex" )) +return -1 ; + + tc_hook.ifindex = ifindex; +return attach_tc_prog (&tc_hook,-1 , egr_fd); +} +static void test_vxlan_tunnel (void ) {struct test_tunnel_kern *skel =NULL ;
@@ -404,11 +454,9 @@ static void test_vxlan_tunnel(void)int local_ip_map_fd =-1 ;int set_src_prog_fd, get_src_prog_fd;int set_dst_prog_fd; -int key =0 , ifindex =-1 ; +int key =0 ;uint local_ip;int err; -DECLARE_LIBBPF_OPTS (bpf_tc_hook, tc_hook, - .attach_point = BPF_TC_INGRESS);/* add vxlan tunnel */ err =add_vxlan_tunnel ();
@@ -419,42 +467,22 @@ static void test_vxlan_tunnel(void) skel =test_tunnel_kern__open_and_load ();if (!ASSERT_OK_PTR (skel,"test_tunnel_kern__open_and_load" )) goto done; - ifindex =if_nametoindex (VXLAN_TUNL_DEV1 ); -if (!ASSERT_NEQ (ifindex,0 ,"vxlan11 ifindex" )) - goto done; - tc_hook.ifindex = ifindex; get_src_prog_fd =bpf_program__fd (skel->progs.vxlan_get_tunnel_src); set_src_prog_fd =bpf_program__fd (skel->progs.vxlan_set_tunnel_src); -if (!ASSERT_GE (get_src_prog_fd,0 ,"bpf_program__fd" )) - goto done; -if (!ASSERT_GE (set_src_prog_fd,0 ,"bpf_program__fd" )) - goto done; -if (attach_tc_prog (&tc_hook, get_src_prog_fd, set_src_prog_fd)) +if (generic_attach (VXLAN_TUNL_DEV1 , get_src_prog_fd, set_src_prog_fd)) goto done;/* load and attach bpf prog to veth dev tc hook point */ - ifindex =if_nametoindex ("veth1" ); -if (!ASSERT_NEQ (ifindex,0 ,"veth1 ifindex" )) - goto done; - tc_hook.ifindex = ifindex; set_dst_prog_fd =bpf_program__fd (skel->progs.veth_set_outer_dst); -if (!ASSERT_GE (set_dst_prog_fd,0 ,"bpf_program__fd" )) - goto done; -if (attach_tc_prog (&tc_hook, set_dst_prog_fd,-1 )) +if (generic_attach_igr ("veth1" , set_dst_prog_fd)) goto done;/* load and attach prog set_md to tunnel dev tc hook point at_ns0 */ nstoken =open_netns ("at_ns0" );if (!ASSERT_OK_PTR (nstoken,"setns src" )) goto done; - ifindex =if_nametoindex (VXLAN_TUNL_DEV0 ); -if (!ASSERT_NEQ (ifindex,0 ,"vxlan00 ifindex" )) - goto done; - tc_hook.ifindex = ifindex; set_dst_prog_fd =bpf_program__fd (skel->progs.vxlan_set_tunnel_dst); -if (!ASSERT_GE (set_dst_prog_fd,0 ,"bpf_program__fd" )) - goto done; -if (attach_tc_prog (&tc_hook,-1 , set_dst_prog_fd)) +if (generic_attach_egr (VXLAN_TUNL_DEV0 , set_dst_prog_fd)) goto done;close_netns (nstoken);
@@ -488,11 +516,9 @@ static void test_ip6vxlan_tunnel(void)int local_ip_map_fd =-1 ;int set_src_prog_fd, get_src_prog_fd;int set_dst_prog_fd; -int key =0 , ifindex =-1 ; +int key =0 ;uint local_ip;int err; -DECLARE_LIBBPF_OPTS (bpf_tc_hook, tc_hook, - .attach_point = BPF_TC_INGRESS);/* add vxlan tunnel */ err =add_ip6vxlan_tunnel ();
@@ -503,31 +529,17 @@ static void test_ip6vxlan_tunnel(void) skel =test_tunnel_kern__open_and_load ();if (!ASSERT_OK_PTR (skel,"test_tunnel_kern__open_and_load" )) goto done; - ifindex =if_nametoindex (IP6VXLAN_TUNL_DEV1 ); -if (!ASSERT_NEQ (ifindex,0 ,"ip6vxlan11 ifindex" )) - goto done; - tc_hook.ifindex = ifindex; get_src_prog_fd =bpf_program__fd (skel->progs.ip6vxlan_get_tunnel_src); set_src_prog_fd =bpf_program__fd (skel->progs.ip6vxlan_set_tunnel_src); -if (!ASSERT_GE (set_src_prog_fd,0 ,"bpf_program__fd" )) - goto done; -if (!ASSERT_GE (get_src_prog_fd,0 ,"bpf_program__fd" )) - goto done; -if (attach_tc_prog (&tc_hook, get_src_prog_fd, set_src_prog_fd)) +if (generic_attach (IP6VXLAN_TUNL_DEV1 , get_src_prog_fd, set_src_prog_fd)) goto done;/* load and attach prog set_md to tunnel dev tc hook point at_ns0 */ nstoken =open_netns ("at_ns0" );if (!ASSERT_OK_PTR (nstoken,"setns src" )) goto done; - ifindex =if_nametoindex (IP6VXLAN_TUNL_DEV0 ); -if (!ASSERT_NEQ (ifindex,0 ,"ip6vxlan00 ifindex" )) - goto done; - tc_hook.ifindex = ifindex; set_dst_prog_fd =bpf_program__fd (skel->progs.ip6vxlan_set_tunnel_dst); -if (!ASSERT_GE (set_dst_prog_fd,0 ,"bpf_program__fd" )) - goto done; -if (attach_tc_prog (&tc_hook,-1 , set_dst_prog_fd)) +if (generic_attach_egr (IP6VXLAN_TUNL_DEV0 , set_dst_prog_fd)) goto done;close_netns (nstoken);
@@ -559,10 +571,7 @@ static void test_ipip_tunnel(enum ipip_encap encap)struct test_tunnel_kern *skel =NULL ;struct nstoken *nstoken;int set_src_prog_fd, get_src_prog_fd; -int ifindex =-1 ;int err; -DECLARE_LIBBPF_OPTS (bpf_tc_hook, tc_hook, - .attach_point = BPF_TC_INGRESS);/* add ipip tunnel */ err =add_ipip_tunnel (encap);
@@ -573,10 +582,6 @@ static void test_ipip_tunnel(enum ipip_encap encap) skel =test_tunnel_kern__open_and_load ();if (!ASSERT_OK_PTR (skel,"test_tunnel_kern__open_and_load" )) goto done; - ifindex =if_nametoindex (IPIP_TUNL_DEV1 ); -if (!ASSERT_NEQ (ifindex,0 ,"ipip11 ifindex" )) - goto done; - tc_hook.ifindex = ifindex;switch (encap) {case FOU :
@@ -598,11 +603,7 @@ static void test_ipip_tunnel(enum ipip_encap encap) skel->progs.ipip_set_tunnel); } -if (!ASSERT_GE (set_src_prog_fd,0 ,"bpf_program__fd" )) - goto done; -if (!ASSERT_GE (get_src_prog_fd,0 ,"bpf_program__fd" )) - goto done; -if (attach_tc_prog (&tc_hook, get_src_prog_fd, set_src_prog_fd)) +if (generic_attach (IPIP_TUNL_DEV1 , get_src_prog_fd, set_src_prog_fd)) goto done;/* ping from root namespace test */
@@ -628,8 +629,6 @@ static void test_ipip_tunnel(enum ipip_encap encap)static void test_xfrm_tunnel (void ) { -DECLARE_LIBBPF_OPTS (bpf_tc_hook, tc_hook, - .attach_point = BPF_TC_INGRESS);LIBBPF_OPTS (bpf_xdp_attach_opts, opts);struct test_tunnel_kern *skel =NULL ;struct nstoken *nstoken;
@@ -646,19 +645,16 @@ static void test_xfrm_tunnel(void)if (!ASSERT_OK_PTR (skel,"test_tunnel_kern__open_and_load" )) goto done; - ifindex =if_nametoindex ("veth1" ); -if (!ASSERT_NEQ (ifindex,0 ,"veth1 ifindex" )) - goto done;/* attach tc prog to tunnel dev */ - tc_hook.ifindex = ifindex; tc_prog_fd =bpf_program__fd (skel->progs.xfrm_get_state); -if (!ASSERT_GE (tc_prog_fd,0 ,"bpf_program__fd" )) - goto done; -if (attach_tc_prog (&tc_hook, tc_prog_fd,-1 )) +if (generic_attach_igr ("veth1" , tc_prog_fd)) goto done;/* attach xdp prog to tunnel dev */ + ifindex =if_nametoindex ("veth1" ); +if (!ASSERT_NEQ (ifindex,0 ,"veth1 ifindex" )) + goto done; xdp_prog_fd =bpf_program__fd (skel->progs.xfrm_get_state_xdp);if (!ASSERT_GE (xdp_prog_fd,0 ,"bpf_program__fd" )) goto done;
Signature · 1 line
2.48.1
Re: [PATCH bpf-next 01/10] selftests/bpf: test_tunnel: Add generic_attach* helpers
Quoted 18 lines · Bastien Curutchet (eBPF Foundation)
A fair amount of code duplication is present among tests to attach BPF programs.
Create generic_attach* helpers that attach BPF programs to a given interface.
UseASSERT_OK_FD()instead ofASSERT_GE()to check fd's validity. Use these helpers in all the available tests.Signed-off-by Bastien Curutchet (eBPF Foundation) <[email protected]>--- .../testing/selftests/bpf/prog_tests/test_tunnel.c | 128 ++++++++++----------- 1 file changed, 62 insertions(+), 66 deletions(-)tools/testing/selftests/bpf/prog_tests/test_tunnel.c +0
-0
tools/testing/selftests/bpf/prog_tests/test_tunnel.c static int attach_tc_prog(struct bpf_tc_hook *hook, int igr_fd, int egr_fd) · line 402
Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/test_tunnel.c +3
-0@@ -397,6 +397,56 @@ static int attach_tc_prog(struct bpf_tc_hook *hook, int igr_fd, int egr_fd)return 0 ; } +static int generic_attach (const char *dev,int igr_fd,int egr_fd) +{ + DECLARE_LIBBPF_OPTS(bpf_tc_hook, tc_hook, .attach_point = BPF_TC_INGRESS);
nit: .attach_point = BPF_TC_INGRESS is a bit confusing to me here (because we later attach both ingress and egress progs); mostly because the way attach_tc_prog is written I think. Can we move tc_hook definition to attach_tc_prog and make it .attach_point=BPF_TC_INGRESS|BPF_TC_EGRESS? And then we can make attach_tc_prog accept ifindex instead of tc_hook.
int attach_tc_prog(int ifindex, igr_fd, egr_fd)
{
DECLARE_LIBBPF_OPTS(bpf_tc_hook, tc_hook, .attach_point = BPF_TC_INGRESS|BPF_TC_EGRESS);
bpf_tc_hook_create(&tc_hook);
if (igr_fd >= 0) {
tc_hook.attach_point = BPF_TC_INGRESS;
...
}
if (egr_fd >= 0) {
tc_hook.attach_point = BPF_TC_EGRESS;
...
}
}Or is it just me?
Re: [PATCH bpf-next 01/10] selftests/bpf: test_tunnel: Add generic_attach* helpers
Hi Stanislav,
Quoted 48 lines · Stanislav Fomichev
Quoted 18 lines · Bastien Curutchet (eBPF Foundation)
A fair amount of code duplication is present among tests to attach BPF programs.
Create generic_attach* helpers that attach BPF programs to a given interface.
UseASSERT_OK_FD()instead ofASSERT_GE()to check fd's validity. Use these helpers in all the available tests.Signed-off-by Bastien Curutchet (eBPF Foundation) <[email protected]>--- .../testing/selftests/bpf/prog_tests/test_tunnel.c | 128 ++++++++++----------- 1 file changed, 62 insertions(+), 66 deletions(-)tools/testing/selftests/bpf/prog_tests/test_tunnel.c +0
-0tools/testing/selftests/bpf/prog_tests/test_tunnel.c static int attach_tc_prog(struct bpf_tc_hook *hook, int igr_fd, int egr_fd) · line 402
Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/test_tunnel.c +3
-0@@ -397,6 +397,56 @@ static int attach_tc_prog(struct bpf_tc_hook *hook, int igr_fd, int egr_fd)return 0 ; } +static int generic_attach (const char *dev,int igr_fd,int egr_fd) +{ + DECLARE_LIBBPF_OPTS(bpf_tc_hook, tc_hook, .attach_point = BPF_TC_INGRESS);nit: .attach_point =
BPF_TC_INGRESSis a bit confusing to me here (because we later attach both ingress and egress progs); mostly because the wayattach_tc_progis written I think. Can we movetc_hookdefinition toattach_tc_progand make it .attach_point=BPF_TC_INGRESS|BPF_TC_EGRESS? And then we can makeattach_tc_progaccept ifindex instead oftc_hook.int
attach_tc_prog(int ifindex, igr_fd, egr_fd){ DECLARE_LIBBPF_OPTS(bpf_tc_hook, tc_hook, .attach_point = BPF_TC_INGRESS|BPF_TC_EGRESS); bpf_tc_hook_create(&tc_hook); if (igr_fd >= 0) { tc_hook.attach_point = BPF_TC_INGRESS; ... } if (egr_fd >= 0) { tc_hook.attach_point = BPF_TC_EGRESS; ... } }
Quoted 1 line
Or is it just me?
I agree with you, it will be better this way. I'll do it in V2.
Best regards,
Bastien
PATCH 2/10 selftests/bpf: test_tunnel: Add ping helpers
In reply to Bastien Curutchet (eBPF Foundation)All tests use more or less the same ping commands as final validation. Also test_ping()'s return value is checked with ASSERT_OK() while this check is already done by the SYS() macro inside test_ping().
Create helpers around test_ping() and use them in the tests to avoid code duplication.
Remove the unnecessary ASSERT_OK() from the tests.
--- .../testing/selftests/bpf/prog_tests/test_tunnel.c | 53 ++++++++++------------ 1 file changed, 24 insertions(+), 29 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_tunnel.c +24 -29
@@ -364,6 +364,25 @@ static int test_ping(int family, const char *addr)return -1 ; } +static void ping_dev0 (void ) +{ +/* ping from root namespace test */ +test_ping (AF_INET ,IP4_ADDR_TUNL_DEV0 ); +} + +static void ping_dev1 (void ) +{ +struct nstoken *nstoken; + +/* ping from at_ns0 namespace test */ + nstoken =open_netns ("at_ns0" ); +if (!ASSERT_OK_PTR (nstoken,"setns" )) +return ; + +test_ping (AF_INET ,IP4_ADDR_TUNL_DEV1 ); +close_netns (nstoken); +} +static int attach_tc_prog (struct bpf_tc_hook *hook,int igr_fd,int egr_fd) { DECLARE_LIBBPF_OPTS(bpf_tc_opts, opts1, .handle = 1,
@@ -496,9 +515,7 @@ static void test_vxlan_tunnel(void) goto done;/* ping test */ - err =test_ping (AF_INET ,IP4_ADDR_TUNL_DEV0 ); -if (!ASSERT_OK (err,"test_ping" )) - goto done; +ping_dev0 (); done:/* delete vxlan tunnel */
@@ -553,9 +570,7 @@ static void test_ip6vxlan_tunnel(void) goto done;/* ping test */ - err =test_ping (AF_INET ,IP4_ADDR_TUNL_DEV0 ); -if (!ASSERT_OK (err,"test_ping" )) - goto done; +ping_dev0 (); done:/* delete ipv6 vxlan tunnel */
@@ -569,7 +584,6 @@ static void test_ip6vxlan_tunnel(void)static void test_ipip_tunnel (enum ipip_encap encap) {struct test_tunnel_kern *skel =NULL ; -struct nstoken *nstoken;int set_src_prog_fd, get_src_prog_fd;int err;
@@ -606,19 +620,8 @@ static void test_ipip_tunnel(enum ipip_encap encap)if (generic_attach (IPIP_TUNL_DEV1 , get_src_prog_fd, set_src_prog_fd)) goto done; -/* ping from root namespace test */ - err =test_ping (AF_INET ,IP4_ADDR_TUNL_DEV0 ); -if (!ASSERT_OK (err,"test_ping" )) - goto done; - -/* ping from at_ns0 namespace test */ - nstoken =open_netns ("at_ns0" ); -if (!ASSERT_OK_PTR (nstoken,"setns" )) - goto done; - err =test_ping (AF_INET ,IP4_ADDR_TUNL_DEV1 ); -if (!ASSERT_OK (err,"test_ping" )) - goto done; -close_netns (nstoken); +ping_dev0 (); +ping_dev1 (); done:/* delete ipip tunnel */
@@ -631,7 +634,6 @@ static void test_xfrm_tunnel(void) {LIBBPF_OPTS (bpf_xdp_attach_opts, opts);struct test_tunnel_kern *skel =NULL ; -struct nstoken *nstoken;int xdp_prog_fd;int tc_prog_fd;int ifindex;
@@ -662,14 +664,7 @@ static void test_xfrm_tunnel(void)if (!ASSERT_OK (err,"bpf_xdp_attach" )) goto done; -/* ping from at_ns0 namespace test */ - nstoken =open_netns ("at_ns0" ); -if (!ASSERT_OK_PTR (nstoken,"setns" )) - goto done; - err =test_ping (AF_INET ,IP4_ADDR_TUNL_DEV1 ); -close_netns (nstoken); -if (!ASSERT_OK (err,"test_ping" )) - goto done; +ping_dev1 ();if (!ASSERT_EQ (skel->bss->xfrm_reqid,1 ,"req_id" )) goto done;
Signature · 1 line
2.48.1
Re: [PATCH bpf-next 02/10] selftests/bpf: test_tunnel: Add ping helpers
Quoted 9 lines · Bastien Curutchet (eBPF Foundation)
All tests use more or less the same ping commands as final validation. Also test_ping()'s return value is checked with
ASSERT_OK()while this check is already done by theSYS()macro insidetest_ping().Create helpers around
test_ping()and use them in the tests to avoid code duplication.
Remove the unnecessaryASSERT_OK()from the tests.Signed-off-by Bastien Curutchet (eBPF Foundation) <[email protected]>
PATCH 3/10 selftests/bpf: test_tunnel: Move gre tunnel test to test_progs
In reply to Bastien Curutchet (eBPF Foundation)gre tunnels are tested in the test_tunnel.sh but not in the test_progs framework.
Add a new test in test_progs to test gre tunnels. It uses the same network topology and the same BPF programs than the script. Remove test_gre() and test_gre_no_tunnel_key() from the script.
--- .../testing/selftests/bpf/prog_tests/test_tunnel.c | 97 ++++++++++++++++++++++ tools/testing/selftests/bpf/test_tunnel.sh | 79 ------------------ 2 files changed, 97 insertions(+), 79 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_tunnel.c +97 -0
@@ -98,6 +98,9 @@#define XFRM_SPI_IN_TO_OUT 0x1#define XFRM_SPI_OUT_TO_IN 0x2 +#define GRE_TUNL_DEV0 "gre00" +#define GRE_TUNL_DEV1 "gre11" +#define PING_ARGS "-i 0.01 -c 3 -w 10 -q"static int config_device (void )
@@ -216,6 +219,18 @@ static int set_ipip_encap(const char *ipproto, const char *type)return -1 ; } +static int set_ipv4_addr (const char *dev0,const char *dev1) +{ +SYS (fail,"ip -n at_ns0 link set dev %s up" , dev0); +SYS (fail,"ip -n at_ns0 addr add dev %s %s/24" , dev0,IP4_ADDR_TUNL_DEV0 ); +SYS (fail,"ip link set dev %s up" , dev1); +SYS (fail,"ip addr add dev %s %s/24" , dev1,IP4_ADDR_TUNL_DEV1 ); + +return 0 ; +fail: +return 1 ; +} +static int add_ipip_tunnel (enum ipip_encap encap) {int err;
@@ -356,6 +371,31 @@ static void delete_xfrm_tunnel(void) IP4_ADDR1_VETH1, IP4_ADDR_VETH0, XFRM_SPI_OUT_TO_IN); } +static int add_ipv4_tunnel (const char *dev0,const char *dev1, +const char *type,const char *opt) +{ +if (!type || !opt || !dev0 || !dev1) +return -1 ; + +SYS (fail,"ip -n at_ns0 link add dev %s type %s %s local %s remote %s" , + dev0, type, opt,IP4_ADDR_VETH0 ,IP4_ADDR1_VETH1 ); + +SYS (fail,"ip link add dev %s type %s external" , dev1, type); + +return set_ipv4_addr (dev0, dev1); +fail: +return -1 ; +} + +static void delete_tunnel (const char *dev0,const char *dev1) +{ +if (!dev0 || !dev1) +return ; + +SYS_NOFAIL ("ip netns exec at_ns0 ip link delete dev %s" , dev0); +SYS_NOFAIL ("ip link delete dev %s" , dev1); +} +static int test_ping (int family,const char *addr) {SYS (fail,"%s %s %s > /dev/null" ,ping_command (family),PING_ARGS , addr);
@@ -681,6 +721,59 @@ static void test_xfrm_tunnel(void)test_tunnel_kern__destroy (skel); } +enum gre_test { +GRE , +GRE_NOKEY , +GRETAP , +GRETAP_NOKEY , +}; + +static void test_gre_tunnel (enum gre_test test) +{ +struct test_tunnel_kern *skel; +int set_fd, get_fd; +int err; + + skel =test_tunnel_kern__open_and_load (); +if (!ASSERT_OK_PTR (skel,"test_tunnel_kern__open_and_load" )) +return ; + +switch (test) { +case GRE : + err =add_ipv4_tunnel (GRE_TUNL_DEV0 ,GRE_TUNL_DEV1 ,"gre" ,"seq" ); + set_fd =bpf_program__fd (skel->progs.gre_set_tunnel_no_key); + get_fd =bpf_program__fd (skel->progs.gre_get_tunnel); +break ; +case GRE_NOKEY : + err =add_ipv4_tunnel (GRE_TUNL_DEV0 ,GRE_TUNL_DEV1 ,"gre" ,"seq key 2" ); + set_fd =bpf_program__fd (skel->progs.gre_set_tunnel); + get_fd =bpf_program__fd (skel->progs.gre_get_tunnel); +break ; +case GRETAP : + err =add_ipv4_tunnel (GRE_TUNL_DEV0 ,GRE_TUNL_DEV1 ,"gretap" ,"seq" ); + set_fd =bpf_program__fd (skel->progs.gre_set_tunnel_no_key); + get_fd =bpf_program__fd (skel->progs.gre_get_tunnel); +break ; +case GRETAP_NOKEY : + err =add_ipv4_tunnel (GRE_TUNL_DEV0 ,GRE_TUNL_DEV1 ,"gretap" ,"seq key 2" ); + set_fd =bpf_program__fd (skel->progs.gre_set_tunnel); + get_fd =bpf_program__fd (skel->progs.gre_get_tunnel); +break ; + } +if (!ASSERT_OK (err,"add tunnel" )) + goto done; + +if (generic_attach (GRE_TUNL_DEV1 , get_fd, set_fd)) + goto done; + +ping_dev0 (); +ping_dev1 (); + +done: +delete_tunnel (GRE_TUNL_DEV0 ,GRE_TUNL_DEV1 ); +test_tunnel_kern__destroy (skel); +} +#define RUN_TEST (name, ...) \ ({ \ if (test__start_subtest(#name)) { \
@@ -698,6 +791,10 @@ static void *test_tunnel_run_tests(void *arg)RUN_TEST (ipip_tunnel,FOU );RUN_TEST (ipip_tunnel,GUE );RUN_TEST (xfrm_tunnel); +RUN_TEST (gre_tunnel,GRE ); +RUN_TEST (gre_tunnel,GRE_NOKEY ); +RUN_TEST (gre_tunnel,GRETAP ); +RUN_TEST (gre_tunnel,GRETAP_NOKEY );return NULL ; }
tools/testing/selftests/bpf/test_tunnel.sh +0 -79
109 lines not on this page · raw message
Signature · 1 line
2.48.1
Re: [PATCH bpf-next 03/10] selftests/bpf: test_tunnel: Move gre tunnel test to test_progs
Quoted 8 lines · Bastien Curutchet (eBPF Foundation)
gre tunnels are tested in the
test_tunnel.shbut not in thetest_progsframework.Add a new test in
test_progsto test gre tunnels. It uses the same network topology and the same BPF programs than the script. Removetest_gre()andtest_gre_no_tunnel_key()from the script.Signed-off-by Bastien Curutchet (eBPF Foundation) <[email protected]>
PATCH 4/10 selftests/bpf: test_tunnel: Move ip6gre tunnel test to test_progs
In reply to Bastien Curutchet (eBPF Foundation)ip6gre tunnels are tested in the test_tunnel.sh but not in the test_progs framework.
Add a new test in test_progs to test ip6gre tunnels. It uses the same network topology and the same BPF programs than the script. Disable the IPv6 DAD feature because it can take lot of time and cause some tests to fail depending on the environment they're run on.
Remove test_ip6gre() and test_ip6gretap() from the script.
--- .../testing/selftests/bpf/prog_tests/test_tunnel.c | 110 +++++++++++++++++++++ tools/testing/selftests/bpf/test_tunnel.sh | 95 ------------------ 2 files changed, 110 insertions(+), 95 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_tunnel.c +110 -0
@@ -71,6 +71,8 @@#define IP4_ADDR2_VETH1 "172.16.1.20"#define IP4_ADDR_TUNL_DEV0 "10.1.1.100"#define IP4_ADDR_TUNL_DEV1 "10.1.1.200" +#define IP6_ADDR_TUNL_DEV0 "fc80::100" +#define IP6_ADDR_TUNL_DEV1 "fc80::200"#define IP6_ADDR_VETH0 "::11"#define IP6_ADDR1_VETH1 "::22"
@@ -101,11 +103,21 @@#define GRE_TUNL_DEV0 "gre00"#define GRE_TUNL_DEV1 "gre11" +#define IP6GRE_TUNL_DEV0 "ip6gre00" +#define IP6GRE_TUNL_DEV1 "ip6gre11" +#define PING_ARGS "-i 0.01 -c 3 -w 10 -q"static int config_device (void ) {SYS (fail,"ip netns add at_ns0" ); + +/* disable IPv6 DAD because it might take too long and fail tests */ +SYS (fail,"ip netns exec at_ns0 sysctl -wq net.ipv6.conf.default.accept_dad=0" ); +SYS (fail,"ip netns exec at_ns0 sysctl -wq net.ipv6.conf.all.accept_dad=0" ); +SYS (fail,"sysctl -wq net.ipv6.conf.default.accept_dad=0" ); +SYS (fail,"sysctl -wq net.ipv6.conf.all.accept_dad=0" ); +SYS (fail,"ip link add veth0 address " MAC_VETH1 " type veth peer name veth1" );SYS (fail,"ip link set veth0 netns at_ns0" );SYS (fail,"ip addr add " IP4_ADDR1_VETH1 "/24 dev veth1" );
@@ -396,6 +408,42 @@ static void delete_tunnel(const char *dev0, const char *dev1)SYS_NOFAIL ("ip link delete dev %s" , dev1); } +static int set_ipv6_addr (const char *dev0,const char *dev1) +{ +SYS (fail,"ip -n at_ns0 addr add %s/96 dev veth0" ,IP6_ADDR_VETH0 ); +SYS (fail,"ip -n at_ns0 link set dev veth0 up" ); +SYS (fail,"ip addr add %s/96 dev veth1" ,IP6_ADDR1_VETH1 ); +SYS (fail,"ip link set dev veth1 up" ); + +SYS (fail,"ip -n at_ns0 addr add dev %s %s/24" , dev0,IP4_ADDR_TUNL_DEV0 ); +SYS (fail,"ip -n at_ns0 addr add dev %s %s/96" , dev0,IP6_ADDR_TUNL_DEV0 ); +SYS (fail,"ip -n at_ns0 link set dev %s up" , dev0); + +SYS (fail,"ip addr add dev %s %s/24" , dev1,IP4_ADDR_TUNL_DEV1 ); +SYS (fail,"ip addr add dev %s %s/96" , dev1,IP6_ADDR_TUNL_DEV1 ); +SYS (fail,"ip link set dev %s up" , dev1); +return 0 ; +fail: +return 1 ; +} + +static int add_ipv6_tunnel (const char *dev0,const char *dev1, +const char *type,const char *opt) +{ +if (!type || !opt || !dev0 || !dev1) +return -1 ; + +SYS (fail,"ip -n at_ns0 link add dev %s type %s %s local %s remote %s" , + dev0, type, opt,IP6_ADDR_VETH0 ,IP6_ADDR1_VETH1 ); + +SYS (fail,"ip link add dev %s type %s external" , dev1, type); + +return set_ipv6_addr (dev0, dev1); +fail: +return -1 ; +} + +static int test_ping (int family,const char *addr) {SYS (fail,"%s %s %s > /dev/null" ,ping_command (family),PING_ARGS , addr);
@@ -423,6 +471,24 @@ static void ping_dev1(void)close_netns (nstoken); } +static void ping6_veth0 (void ) +{ +test_ping (AF_INET6 ,IP6_ADDR_VETH0 ); +} + +static void ping6_dev1 (void ) +{ +struct nstoken *nstoken; + +/* ping from at_ns0 namespace test */ + nstoken =open_netns ("at_ns0" ); +if (!ASSERT_OK_PTR (nstoken,"setns" )) +return ; + +test_ping (AF_INET ,IP6_ADDR_TUNL_DEV1 ); +close_netns (nstoken); +} +static int attach_tc_prog (struct bpf_tc_hook *hook,int igr_fd,int egr_fd) { DECLARE_LIBBPF_OPTS(bpf_tc_opts, opts1, .handle = 1,
@@ -774,6 +840,48 @@ static void test_gre_tunnel(enum gre_test test)test_tunnel_kern__destroy (skel); } +enum ip6gre_test { +IP6GRE , +IP6GRETAP +}; + +static void test_ip6gre_tunnel (enum ip6gre_test test) +{ +struct test_tunnel_kern *skel; +int set_fd, get_fd; +int err; + + skel =test_tunnel_kern__open_and_load (); +if (!ASSERT_OK_PTR (skel,"test_tunnel_kern__open_and_load" )) +return ; + +switch (test) { +case IP6GRE : + err =add_ipv6_tunnel (IP6GRE_TUNL_DEV0 ,IP6GRE_TUNL_DEV1 , +"ip6gre" ,"flowlabel 0xbcdef key 2" ); +break ; +case IP6GRETAP : + err =add_ipv6_tunnel (IP6GRE_TUNL_DEV0 ,IP6GRE_TUNL_DEV1 , +"ip6gretap" ,"flowlabel 0xbcdef key 2" ); +break ; + } +if (!ASSERT_OK (err,"add tunnel" )) + goto done; + + set_fd =bpf_program__fd (skel->progs.ip6gretap_set_tunnel); + get_fd =bpf_program__fd (skel->progs.ip6gretap_get_tunnel); +if (generic_attach (IP6GRE_TUNL_DEV1 , get_fd, set_fd)) + goto done; + +ping6_veth0 (); +ping6_dev1 (); +ping_dev0 (); +ping_dev1 (); +done: +delete_tunnel (IP6GRE_TUNL_DEV0 ,IP6GRE_TUNL_DEV1 ); +test_tunnel_kern__destroy (skel); +} +#define RUN_TEST (name, ...) \ ({ \ if (test__start_subtest(#name)) { \
@@ -795,6 +903,8 @@ static void *test_tunnel_run_tests(void *arg)RUN_TEST (gre_tunnel,GRE_NOKEY );RUN_TEST (gre_tunnel,GRETAP );RUN_TEST (gre_tunnel,GRETAP_NOKEY ); +RUN_TEST (ip6gre_tunnel,IP6GRE ); +RUN_TEST (ip6gre_tunnel,IP6GRETAP );return NULL ; }
tools/testing/selftests/bpf/test_tunnel.sh +0 -95
125 lines not on this page · raw message
Signature · 1 line
2.48.1
Re: [PATCH bpf-next 04/10] selftests/bpf: test_tunnel: Move ip6gre tunnel test to test_progs
Quoted 40 lines · Bastien Curutchet (eBPF Foundation)
ip6gre tunnels are tested in the
test_tunnel.shbut not in thetest_progsframework.Add a new test in
test_progsto test ip6gre tunnels. It uses the same network topology and the same BPF programs than the script. Disable the IPv6 DAD feature because it can take lot of time and cause some tests to fail depending on the environment they're run on.
Removetest_ip6gre()andtest_ip6gretap()from the script.Signed-off-by Bastien Curutchet (eBPF Foundation) <[email protected]>--- .../testing/selftests/bpf/prog_tests/test_tunnel.c | 110 +++++++++++++++++++++ tools/testing/selftests/bpf/test_tunnel.sh | 95 ------------------ 2 files changed, 110 insertions(+), 95 deletions(-)tools/testing/selftests/bpf/prog_tests/test_tunnel.c +5
-0@@ -71,6 +71,8 @@#define IP4_ADDR2_VETH1 "172.16.1.20"#define IP4_ADDR_TUNL_DEV0 "10.1.1.100"#define IP4_ADDR_TUNL_DEV1 "10.1.1.200" +#define IP6_ADDR_TUNL_DEV0 "fc80::100" +#define IP6_ADDR_TUNL_DEV1 "fc80::200"#define IP6_ADDR_VETH0 "::11"#define IP6_ADDR1_VETH1 "::22"@@ -101,11 +103,21 @@#define GRE_TUNL_DEV0 "gre00"#define GRE_TUNL_DEV1 "gre11" +#define IP6GRE_TUNL_DEV0 "ip6gre00" +#define IP6GRE_TUNL_DEV1 "ip6gre11" +#define PING_ARGS "-i 0.01 -c 3 -w 10 -q"static int config_device (void ) {SYS (fail,"ip netns add at_ns0" );
[..]
tools/testing/selftests/bpf/prog_tests/test_tunnel.c line 119
Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/test_tunnel.c +5
-0+/* disable IPv6 DAD because it might take too long and fail tests */ +SYS (fail,"ip netns exec at_ns0 sysctl -wq net.ipv6.conf.default.accept_dad=0" ); +SYS (fail,"ip netns exec at_ns0 sysctl -wq net.ipv6.conf.all.accept_dad=0" ); +SYS (fail,"sysctl -wq net.ipv6.conf.default.accept_dad=0" ); +SYS (fail,"sysctl -wq net.ipv6.conf.all.accept_dad=0" );
ip addr add ... nodad should be a less invasive alternative?
Re: [PATCH bpf-next 04/10] selftests/bpf: test_tunnel: Move ip6gre tunnel test to test_progs
Hi Stanislav
Quoted 44 lines · Stanislav Fomichev
Quoted 40 lines · Bastien Curutchet (eBPF Foundation)
ip6gre tunnels are tested in the
test_tunnel.shbut not in thetest_progsframework.Add a new test in
test_progsto test ip6gre tunnels. It uses the same network topology and the same BPF programs than the script. Disable the IPv6 DAD feature because it can take lot of time and cause some tests to fail depending on the environment they're run on.
Removetest_ip6gre()andtest_ip6gretap()from the script.Signed-off-by Bastien Curutchet (eBPF Foundation) <[email protected]>--- .../testing/selftests/bpf/prog_tests/test_tunnel.c | 110 +++++++++++++++++++++ tools/testing/selftests/bpf/test_tunnel.sh | 95 ------------------ 2 files changed, 110 insertions(+), 95 deletions(-)tools/testing/selftests/bpf/prog_tests/test_tunnel.c +5
-0@@ -71,6 +71,8 @@#define IP4_ADDR2_VETH1 "172.16.1.20"#define IP4_ADDR_TUNL_DEV0 "10.1.1.100"#define IP4_ADDR_TUNL_DEV1 "10.1.1.200" +#define IP6_ADDR_TUNL_DEV0 "fc80::100" +#define IP6_ADDR_TUNL_DEV1 "fc80::200"#define IP6_ADDR_VETH0 "::11"#define IP6_ADDR1_VETH1 "::22"@@ -101,11 +103,21 @@#define GRE_TUNL_DEV0 "gre00"#define GRE_TUNL_DEV1 "gre11" +#define IP6GRE_TUNL_DEV0 "ip6gre00" +#define IP6GRE_TUNL_DEV1 "ip6gre11" +#define PING_ARGS "-i 0.01 -c 3 -w 10 -q"static int config_device (void ) {SYS (fail,"ip netns add at_ns0" );[..]
Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/test_tunnel.c line 119
Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/test_tunnel.c +5
-0+/* disable IPv6 DAD because it might take too long and fail tests */ +SYS (fail,"ip netns exec at_ns0 sysctl -wq net.ipv6.conf.default.accept_dad=0" ); +SYS (fail,"ip netns exec at_ns0 sysctl -wq net.ipv6.conf.all.accept_dad=0" ); +SYS (fail,"sysctl -wq net.ipv6.conf.default.accept_dad=0" ); +SYS (fail,"sysctl -wq net.ipv6.conf.all.accept_dad=0" );
ip addr add ... nodadshould be a less invasive alternative?
I didn't know I could do it through ip addr, I'll try this !
Best regards,
Bastien
PATCH 5/10 selftests/bpf: test_tunnel: Move erspan tunnel tests to test_progs
In reply to Bastien Curutchet (eBPF Foundation)erspan tunnels are tested in the test_tunnel.sh but not in the test_progs framework.
Add a new test in test_progs to test erspan tunnels. It uses the same network topology and the same BPF programs than the script. Remove test_erspan() from the script.
--- .../testing/selftests/bpf/prog_tests/test_tunnel.c | 46 +++++++++++++++++++ tools/testing/selftests/bpf/test_tunnel.sh | 52 ---------------------- 2 files changed, 46 insertions(+), 52 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_tunnel.c +46 -0
@@ -106,6 +106,9 @@#define IP6GRE_TUNL_DEV0 "ip6gre00"#define IP6GRE_TUNL_DEV1 "ip6gre11" +#define ERSPAN_TUNL_DEV0 "erspan00" +#define ERSPAN_TUNL_DEV1 "erspan11" +#define PING_ARGS "-i 0.01 -c 3 -w 10 -q"static int config_device (void )
@@ -882,6 +885,47 @@ static void test_ip6gre_tunnel(enum ip6gre_test test)test_tunnel_kern__destroy (skel); } +enum erspan_test { +V1 , +V2 +}; + +static void test_erspan_tunnel (enum erspan_test test) +{ +struct test_tunnel_kern *skel; +int set_fd, get_fd; +int err; + + skel =test_tunnel_kern__open_and_load (); +if (!ASSERT_OK_PTR (skel,"test_tunnel_kern__open_and_load" )) +return ; + +switch (test) { +case V1 : + err =add_ipv4_tunnel (ERSPAN_TUNL_DEV0 ,ERSPAN_TUNL_DEV1 , +"erspan" ,"seq key 2 erspan_ver 1 erspan 123" ); +break ; +case V2 : + err =add_ipv4_tunnel (ERSPAN_TUNL_DEV0 ,ERSPAN_TUNL_DEV1 , +"erspan" , +"seq key 2 erspan_ver 2 erspan_dir egress erspan_hwid 3" ); +break ; + } +if (!ASSERT_OK (err,"add tunnel" )) + goto done; + + set_fd =bpf_program__fd (skel->progs.erspan_set_tunnel); + get_fd =bpf_program__fd (skel->progs.erspan_get_tunnel); +if (generic_attach (ERSPAN_TUNL_DEV1 , get_fd, set_fd)) + goto done; + +ping_dev0 (); +ping_dev1 (); +done: +delete_tunnel (ERSPAN_TUNL_DEV0 ,ERSPAN_TUNL_DEV1 ); +test_tunnel_kern__destroy (skel); +} +#define RUN_TEST (name, ...) \ ({ \ if (test__start_subtest(#name)) { \
@@ -905,6 +949,8 @@ static void *test_tunnel_run_tests(void *arg)RUN_TEST (gre_tunnel,GRETAP_NOKEY );RUN_TEST (ip6gre_tunnel,IP6GRE );RUN_TEST (ip6gre_tunnel,IP6GRETAP ); +RUN_TEST (erspan_tunnel,V1 ); +RUN_TEST (erspan_tunnel,V2 );return NULL ; }
tools/testing/selftests/bpf/test_tunnel.sh +0 -52
76 lines not on this page · raw message
Signature · 1 line
2.48.1
Re: [PATCH bpf-next 05/10] selftests/bpf: test_tunnel: Move erspan tunnel tests to test_progs
Quoted 8 lines · Bastien Curutchet (eBPF Foundation)
erspan tunnels are tested in the
test_tunnel.shbut not in thetest_progsframework.Add a new test in
test_progsto test erspan tunnels. It uses the same network topology and the same BPF programs than the script. Removetest_erspan()from the script.Signed-off-by Bastien Curutchet (eBPF Foundation) <[email protected]>
PATCH 6/10 selftests/bpf: test_tunnel: Move ip6erspan tunnel test to test_progs
In reply to Bastien Curutchet (eBPF Foundation)ip6erspan tunnels are tested in the test_tunnel.sh but not in the test_progs framework.
Add a new test in test_progs to test ip6erspan tunnels. It uses the same network topology and the same BPF programs than the script. Remove test_ip6erspan() from the script.
--- .../testing/selftests/bpf/prog_tests/test_tunnel.c | 41 +++++++++++++++ tools/testing/selftests/bpf/test_tunnel.sh | 58 ---------------------- 2 files changed, 41 insertions(+), 58 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_tunnel.c +41 -0
@@ -109,6 +109,9 @@#define ERSPAN_TUNL_DEV0 "erspan00"#define ERSPAN_TUNL_DEV1 "erspan11" +#define IP6ERSPAN_TUNL_DEV0 "ip6erspan00" +#define IP6ERSPAN_TUNL_DEV1 "ip6erspan11" +#define PING_ARGS "-i 0.01 -c 3 -w 10 -q"static int config_device (void )
@@ -926,6 +929,42 @@ static void test_erspan_tunnel(enum erspan_test test)test_tunnel_kern__destroy (skel); } +static void test_ip6erspan_tunnel (enum erspan_test test) +{ +struct test_tunnel_kern *skel; +int set_fd, get_fd; +int err; + + skel =test_tunnel_kern__open_and_load (); +if (!ASSERT_OK_PTR (skel,"test_tunnel_kern__open_and_load" )) +return ; + +switch (test) { +case V1 : + err =add_ipv6_tunnel (IP6ERSPAN_TUNL_DEV0 ,IP6ERSPAN_TUNL_DEV1 , +"ip6erspan" ,"seq key 2 erspan_ver 1 erspan 123" ); +break ; +case V2 : + err =add_ipv6_tunnel (IP6ERSPAN_TUNL_DEV0 ,IP6ERSPAN_TUNL_DEV1 , +"ip6erspan" , +"seq key 2 erspan_ver 2 erspan_dir egress erspan_hwid 7" ); +break ; + } +if (!ASSERT_OK (err,"add tunnel" )) + goto done; + + set_fd =bpf_program__fd (skel->progs.ip4ip6erspan_set_tunnel); + get_fd =bpf_program__fd (skel->progs.ip4ip6erspan_get_tunnel); +if (generic_attach (IP6ERSPAN_TUNL_DEV1 , get_fd, set_fd)) + goto done; + +ping6_veth0 (); +ping_dev1 (); +done: +delete_tunnel (IP6ERSPAN_TUNL_DEV0 ,IP6ERSPAN_TUNL_DEV1 ); +test_tunnel_kern__destroy (skel); +} +#define RUN_TEST (name, ...) \ ({ \ if (test__start_subtest(#name)) { \
@@ -951,6 +990,8 @@ static void *test_tunnel_run_tests(void *arg)RUN_TEST (ip6gre_tunnel,IP6GRETAP );RUN_TEST (erspan_tunnel,V1 );RUN_TEST (erspan_tunnel,V2 ); +RUN_TEST (ip6erspan_tunnel,V1 ); +RUN_TEST (ip6erspan_tunnel,V2 );return NULL ; }
tools/testing/selftests/bpf/test_tunnel.sh +0 -58
82 lines not on this page · raw message
Signature · 1 line
2.48.1
Re: [PATCH bpf-next 06/10] selftests/bpf: test_tunnel: Move ip6erspan tunnel test to test_progs
Quoted 8 lines · Bastien Curutchet (eBPF Foundation)
ip6erspan tunnels are tested in the
test_tunnel.shbut not in thetest_progsframework.Add a new test in
test_progsto test ip6erspan tunnels. It uses the same network topology and the same BPF programs than the script. Removetest_ip6erspan()from the script.Signed-off-by Bastien Curutchet (eBPF Foundation) <[email protected]>
PATCH 7/10 selftests/bpf: test_tunnel: Move geneve tunnel test to test_progs
In reply to Bastien Curutchet (eBPF Foundation)geneve tunnels are tested in the test_tunnel.sh but not in the test_progs framework.
Add a new test in test_progs to test geneve tunnels. It uses the same network topology and the same BPF programs than the script. Remove test_geneve() from the script.
--- .../testing/selftests/bpf/prog_tests/test_tunnel.c | 45 ++++++++++++++++++++++ tools/testing/selftests/bpf/test_tunnel.sh | 45 ---------------------- 2 files changed, 45 insertions(+), 45 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_tunnel.c +45 -0
@@ -112,6 +112,9 @@#define IP6ERSPAN_TUNL_DEV0 "ip6erspan00"#define IP6ERSPAN_TUNL_DEV1 "ip6erspan11" +#define GENEVE_TUNL_DEV0 "geneve00" +#define GENEVE_TUNL_DEV1 "geneve11" +#define PING_ARGS "-i 0.01 -c 3 -w 10 -q"static int config_device (void )
@@ -449,6 +452,21 @@ static int add_ipv6_tunnel(const char *dev0, const char *dev1,return -1 ; } +static int add_geneve_tunnel (const char *dev0,const char *dev1, +const char *type,const char *opt) +{ +if (!type || !opt || !dev0 || !dev1) +return -1 ; + +SYS (fail,"ip -n at_ns0 link add dev %s type %s id 2 %s remote %s" , + dev0, type, opt,IP4_ADDR1_VETH1 ); + +SYS (fail,"ip link add dev %s type %s %s external" , dev1, type, opt); + +return set_ipv4_addr (dev0, dev1); +fail: +return -1 ; +}static int test_ping (int family,const char *addr) {
@@ -965,6 +983,32 @@ static void test_ip6erspan_tunnel(enum erspan_test test)test_tunnel_kern__destroy (skel); } +static void test_geneve_tunnel (void ) +{ +struct test_tunnel_kern *skel; +int set_fd, get_fd; +int err; + + skel =test_tunnel_kern__open_and_load (); +if (!ASSERT_OK_PTR (skel,"test_tunnel_kern__open_and_load" )) +return ; + + err =add_geneve_tunnel (GENEVE_TUNL_DEV0 ,GENEVE_TUNL_DEV1 , +"geneve" ,"dstport 6081" ); +if (!ASSERT_OK (err,"add tunnel" )) + goto done; + + set_fd =bpf_program__fd (skel->progs.geneve_set_tunnel); + get_fd =bpf_program__fd (skel->progs.geneve_get_tunnel); +if (generic_attach (GENEVE_TUNL_DEV1 , get_fd, set_fd)) + goto done; + +ping_dev0 (); +ping_dev1 (); +done: +delete_tunnel (GENEVE_TUNL_DEV0 ,GENEVE_TUNL_DEV1 ); +test_tunnel_kern__destroy (skel); +}#define RUN_TEST (name, ...) \ ({ \ if (test__start_subtest(#name)) { \
@@ -992,6 +1036,7 @@ static void *test_tunnel_run_tests(void *arg)RUN_TEST (erspan_tunnel,V2 );RUN_TEST (ip6erspan_tunnel,V1 );RUN_TEST (ip6erspan_tunnel,V2 ); +RUN_TEST (geneve_tunnel);return NULL ; }
tools/testing/selftests/bpf/test_tunnel.sh +0 -45
75 lines not on this page · raw message
Signature · 1 line
2.48.1
Re: [PATCH bpf-next 07/10] selftests/bpf: test_tunnel: Move geneve tunnel test to test_progs
Quoted 8 lines · Bastien Curutchet (eBPF Foundation)
geneve tunnels are tested in the
test_tunnel.shbut not in thetest_progsframework.Add a new test in
test_progsto test geneve tunnels. It uses the same network topology and the same BPF programs than the script. Removetest_geneve()from the script.Signed-off-by Bastien Curutchet (eBPF Foundation) <[email protected]>
PATCH 8/10 selftests/bpf: test_tunnel: Move ip6geneve tunnel test to test_progs
In reply to Bastien Curutchet (eBPF Foundation)ip6geneve tunnels are tested in the test_tunnel.sh but not in the test_progs framework.
Add a new test in test_progs to test ip6geneve tunnels. It uses the same network topology and the same BPF programs than the script. Remove test_ip6geneve() from the script.
--- .../testing/selftests/bpf/prog_tests/test_tunnel.c | 48 +++++++++++++++++++++ tools/testing/selftests/bpf/test_tunnel.sh | 49 ---------------------- 2 files changed, 48 insertions(+), 49 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_tunnel.c +48 -0
@@ -115,6 +115,9 @@#define GENEVE_TUNL_DEV0 "geneve00"#define GENEVE_TUNL_DEV1 "geneve11" +#define IP6GENEVE_TUNL_DEV0 "ip6geneve00" +#define IP6GENEVE_TUNL_DEV1 "ip6geneve11" +#define PING_ARGS "-i 0.01 -c 3 -w 10 -q"static int config_device (void )
@@ -468,6 +471,22 @@ static int add_geneve_tunnel(const char *dev0, const char *dev1,return -1 ; } +static int add_ip6geneve_tunnel (const char *dev0,const char *dev1, +const char *type,const char *opt) +{ +if (!type || !opt || !dev0 || !dev1) +return -1 ; + +SYS (fail,"ip -n at_ns0 link add dev %s type %s id 22 %s remote %s" , + dev0, type, opt,IP6_ADDR1_VETH1 ); + +SYS (fail,"ip link add dev %s type %s %s external" , dev1, type, opt); + +return set_ipv6_addr (dev0, dev1); +fail: +return -1 ; +} +static int test_ping (int family,const char *addr) {SYS (fail,"%s %s %s > /dev/null" ,ping_command (family),PING_ARGS , addr);
@@ -1009,6 +1028,34 @@ static void test_geneve_tunnel(void)delete_tunnel (GENEVE_TUNL_DEV0 ,GENEVE_TUNL_DEV1 );test_tunnel_kern__destroy (skel); } + +static void test_ip6geneve_tunnel (void ) +{ +struct test_tunnel_kern *skel; +int set_fd, get_fd; +int err; + + skel =test_tunnel_kern__open_and_load (); +if (!ASSERT_OK_PTR (skel,"test_tunnel_kern__open_and_load" )) +return ; + + err =add_ip6geneve_tunnel (IP6GENEVE_TUNL_DEV0 ,IP6GENEVE_TUNL_DEV1 , +"geneve" ,"" ); +if (!ASSERT_OK (err,"add tunnel" )) + goto done; + + set_fd =bpf_program__fd (skel->progs.ip6geneve_set_tunnel); + get_fd =bpf_program__fd (skel->progs.ip6geneve_get_tunnel); +if (generic_attach (IP6GENEVE_TUNL_DEV1 , get_fd, set_fd)) + goto done; + +ping_dev0 (); +ping_dev1 (); +done: +delete_tunnel (IP6GENEVE_TUNL_DEV0 ,IP6GENEVE_TUNL_DEV1 ); +test_tunnel_kern__destroy (skel); +} +#define RUN_TEST (name, ...) \ ({ \ if (test__start_subtest(#name)) { \
@@ -1037,6 +1084,7 @@ static void *test_tunnel_run_tests(void *arg)RUN_TEST (ip6erspan_tunnel,V1 );RUN_TEST (ip6erspan_tunnel,V2 );RUN_TEST (geneve_tunnel); +RUN_TEST (ip6geneve_tunnel);return NULL ; }
tools/testing/selftests/bpf/test_tunnel.sh +0 -49
73 lines not on this page · raw message
Signature · 1 line
2.48.1
Re: [PATCH bpf-next 08/10] selftests/bpf: test_tunnel: Move ip6geneve tunnel test to test_progs
Quoted 8 lines · Bastien Curutchet (eBPF Foundation)
ip6geneve tunnels are tested in the
test_tunnel.shbut not in thetest_progsframework.Add a new test in
test_progsto test ip6geneve tunnels. It uses the same network topology and the same BPF programs than the script. Removetest_ip6geneve()from the script.Signed-off-by Bastien Curutchet (eBPF Foundation) <[email protected]>
PATCH 9/10 selftests/bpf: test_tunnel: Move ip6tnl tunnel tests to test_progs
In reply to Bastien Curutchet (eBPF Foundation)ip6tnl tunnels are tested in the test_tunnel.sh but not in the test_progs framework.
Add a new test in test_progs to test ip6tnl tunnels. It uses the same network topology and the same BPF programs than the script. Remove test_ipip6() and test_ip6ip6() from the script.
--- .../testing/selftests/bpf/prog_tests/test_tunnel.c | 59 +++++++++++++++ tools/testing/selftests/bpf/test_tunnel.sh | 88 ---------------------- 2 files changed, 59 insertions(+), 88 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_tunnel.c +59 -0
@@ -118,6 +118,9 @@#define IP6GENEVE_TUNL_DEV0 "ip6geneve00"#define IP6GENEVE_TUNL_DEV1 "ip6geneve11" +#define IP6TNL_TUNL_DEV0 "ip6tnl00" +#define IP6TNL_TUNL_DEV1 "ip6tnl11" +#define PING_ARGS "-i 0.01 -c 3 -w 10 -q"static int config_device (void )
@@ -519,6 +522,11 @@ static void ping6_veth0(void)test_ping (AF_INET6 ,IP6_ADDR_VETH0 ); } +static void ping6_dev0 (void ) +{ +test_ping (AF_INET6 ,IP6_ADDR_TUNL_DEV0 ); +} +static void ping6_dev1 (void ) {struct nstoken *nstoken;
@@ -1056,6 +1064,55 @@ static void test_ip6geneve_tunnel(void)test_tunnel_kern__destroy (skel); } +enum ip6tnl_test { +IPIP6 , +IP6IP6 +}; + +static void test_ip6tnl_tunnel (enum ip6tnl_test test) +{ +struct test_tunnel_kern *skel; +int set_fd, get_fd; +int err; + + skel =test_tunnel_kern__open_and_load (); +if (!ASSERT_OK_PTR (skel,"test_tunnel_kern__open_and_load" )) +return ; + + err =add_ipv6_tunnel (IP6TNL_TUNL_DEV0 ,IP6TNL_TUNL_DEV1 ,"ip6tnl" ,"" ); +if (!ASSERT_OK (err,"add tunnel" )) + goto done; + +switch (test) { +case IPIP6 : + set_fd =bpf_program__fd (skel->progs.ipip6_set_tunnel); + get_fd =bpf_program__fd (skel->progs.ipip6_get_tunnel); +break ; +case IP6IP6 : + set_fd =bpf_program__fd (skel->progs.ip6ip6_set_tunnel); + get_fd =bpf_program__fd (skel->progs.ip6ip6_get_tunnel); +break ; + } +if (generic_attach (IP6TNL_TUNL_DEV1 , get_fd, set_fd)) + goto done; + +ping6_veth0 (); +switch (test) { +case IPIP6 : +ping_dev0 (); +ping_dev1 (); +break ; +case IP6IP6 : +ping6_dev0 (); +ping6_dev1 (); +break ; + } + +done: +delete_tunnel (IP6TNL_TUNL_DEV0 ,IP6TNL_TUNL_DEV1 ); +test_tunnel_kern__destroy (skel); +} +#define RUN_TEST (name, ...) \ ({ \ if (test__start_subtest(#name)) { \
@@ -1085,6 +1142,8 @@ static void *test_tunnel_run_tests(void *arg)RUN_TEST (ip6erspan_tunnel,V2 );RUN_TEST (geneve_tunnel);RUN_TEST (ip6geneve_tunnel); +RUN_TEST (ip6tnl_tunnel,IPIP6 ); +RUN_TEST (ip6tnl_tunnel,IP6IP6 );return NULL ; }
tools/testing/selftests/bpf/test_tunnel.sh +0 -88
112 lines not on this page · raw message
Signature · 1 line
2.48.1
Re: [PATCH bpf-next 09/10] selftests/bpf: test_tunnel: Move ip6tnl tunnel tests to test_progs
Quoted 8 lines · Bastien Curutchet (eBPF Foundation)
ip6tnl tunnels are tested in the
test_tunnel.shbut not in thetest_progsframework.Add a new test in
test_progsto test ip6tnl tunnels. It uses the same network topology and the same BPF programs than the script. Removetest_ipip6()andtest_ip6ip6()from the script.Signed-off-by Bastien Curutchet (eBPF Foundation) <[email protected]>
PATCH 10/10 selftests/bpf: test_tunnel: Remove test_tunnel.sh
In reply to Bastien Curutchet (eBPF Foundation)All tests from test_tunnel.sh have been migrated into test test_progs. The last test remaining in the script is the test_ipip() that is already covered in the test_prog framework by the NONE case of test_ipip_tunnel().
Remove the test_tunnel.sh script and its Makefile entry
--- tools/testing/selftests/bpf/Makefile | 1 - tools/testing/selftests/bpf/test_tunnel.sh | 179 ----------------------------- 2 files changed, 180 deletions(-)
tools/testing/selftests/bpf/Makefile +0 -1
@@ -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_tunnel.sh \ test_lwt_seg6local.sh \ test_lirc_mode2.sh \ test_xdp_vlan_mode_generic.sh \
tools/testing/selftests/bpf/test_tunnel.sh deleted +0 -179
179 lines not on this page · raw message
Signature · 1 line
2.48.1
Re: [PATCH bpf-next 10/10] selftests/bpf: test_tunnel: Remove test_tunnel.sh
Quoted 7 lines · Bastien Curutchet (eBPF Foundation)
All tests from
test_tunnel.shhave been migrated into testtest_progs. The last test remaining in the script is thetest_ipip()that is already covered in thetest_progframework by the NONE case oftest_ipip_tunnel().Remove the
test_tunnel.shscript and itsMakefileentrySigned-off-by Bastien Curutchet (eBPF Foundation) <[email protected]>