Route tests using netlink API (dst,gw)
v3 cover Route tests using netlink API (dst,gw)
Hi Alexey,
another attempt to add netlink C based tests.
This lazy approach does not create end point on rhost, thus port is unreachable:
17:26:16.235937 IP 10.23.0.1 > 10.23.1.1: ICMP 10.23.0.1 udp port 49893 unreachable, length 44
Compare shell based tests:
17:26:32.879209 IP 10.23.1.1 > 10.23.0.1: ICMP echo request, id 17161, seq 1, length 64 17:26:32.879244 IP 10.23.0.1 > 10.23.1.1: ICMP echo reply, id 17161, seq 1, length 64
I used this approach as we agreed that both approaches are useful.
BTW I guess NS_TIMES=10 is not really much for route stress tests. Maybe we want to increase it again. If yes, not sure if there should be special variable just for route tests.
Maybe route-change-netlink.c should just exit 0 or 1, to get rid of verbose output:
route-change-netlink-dst 1 TINFO: initialize 'lhost' 'ltp_ns_veth2' interface route-change-netlink-dst 1 TINFO: add local addr 10.0.0.2/24 route-change-netlink-dst 1 TINFO: add local addr fd00:1:1:1::2/64 route-change-netlink-dst 1 TINFO: initialize 'rhost' 'ltp_ns_veth1' interface route-change-netlink-dst 1 TINFO: add remote addr 10.0.0.1/24 route-change-netlink-dst 1 TINFO: add remote addr fd00:1:1:1::1/64 route-change-netlink-dst 1 TINFO: Network config (local -- remote):
route-change-netlink-dst 1 TINFO: ltp_ns_veth2 -- ltp_ns_veth1 route-change-netlink-dst 1 TINFO: 10.0.0.2/24 -- 10.0.0.1/24 route-change-netlink-dst 1 TINFO: fd00:1:1:1::2/64 -- fd00:1:1:1::1/64 route-change-netlink-dst 1 TINFO: timeout per run is 0h 5m 0s route-change-netlink-dst 1 TINFO: change IPv4 route destination 10 times tst_test.c:1239: INFO: Timeout per run is 0h 05m 00s
route-change-netlink.c:311: INFO: adding and deleting route with different destination 10 times route-change-netlink.c:336: PASS: routes created and deleted
Summary:
passed 1 failed 0 skipped 0
warnings 0
route-change-netlink-dst 1 TPASS: route-change-netlink -c 10 -d ltp_ns_veth2 -p 49075 -l 10.0.0.2 -r '10.23.4.1^10.23.3.1^10.23.2.1^10.23.1.1^10.23.0.1^' passed as expected route-change-netlink-dst 2 TINFO: initialize 'lhost' 'ltp_ns_veth2' interface
route-change-netlink-dst 2 TINFO: add local addr 10.0.0.2/24
route-change-netlink-dst 2 TINFO: add local addr fd00:1:1:1::2/64
route-change-netlink-dst 2 TINFO: initialize 'rhost' 'ltp_ns_veth1' interface
route-change-netlink-dst 2 TINFO: add remote addr 10.0.0.1/24
route-change-netlink-dst 2 TINFO: add remote addr fd00:1:1:1::1/64
Summary:
passed 1 failed 0 skipped 0
warnings 0
Petr Vorel (2):
net: Move setup_addrinfo() into tst_net.h net/route: Add netlink based route change gw/dest tests
configure.ac | 1 + include/mk/config.mk.in | 2 + include/tst_net.h | 9 +- include/tst_private.h | 1 + lib/tst_net.c | 14 + m4/ltp-libmnl.m4 | 8 + runtest/net_stress.route | 4 + testcases/network/netstress/netstress.c | 20 +- testcases/network/stress/route/.gitignore | 1 + .../network/stress/route/00_Descriptions.txt | 39 +- testcases/network/stress/route/Makefile | 30 +- .../network/stress/route/route-change-dst.sh | 1 + .../network/stress/route/route-change-gw.sh | 10 +- .../network/stress/route/route-change-if.sh | 1 + .../stress/route/route-change-netlink-dst.sh | 33 ++ .../stress/route/route-change-netlink-gw.sh | 30 ++ .../stress/route/route-change-netlink.c | 348 ++++++++++++++++++ testcases/network/stress/route/route-lib.sh | 34 +- travis/debian.cross-compile.sh | 1 + travis/debian.sh | 1 + travis/fedora.sh | 3 + travis/tumbleweed.sh | 1 + 22 files changed, 518 insertions(+), 74 deletions(-) create mode 100644 m4/ltp-libmnl.m4 create mode 100644 testcases/network/stress/route/.gitignore create mode 100755 testcases/network/stress/route/route-change-netlink-dst.sh create mode 100755 testcases/network/stress/route/route-change-netlink-gw.sh create mode 100644 testcases/network/stress/route/route-change-netlink.c
Signature · 1 line
2.26.0
RFC PATCH v3 1/2 net: Move setup_addrinfo() into tst_net.h
as tst_setup_addrinfo().
This allows reusing it in next commit.
---
Changes v1->v2:
* setup_addrinfo() renamed to tst_setup_addrinfo()
* rebase
include/tst_net.h | 9 +++++++-- include/tst_private.h | 1 + lib/tst_net.c | 14 ++++++++++++++ testcases/network/netstress/netstress.c | 20 ++++---------------- 4 files changed, 26 insertions(+), 18 deletions(-)
include/tst_net.h +7 -2
@@ -7,9 +7,10 @@#define TST_NET_H_ #include <arpa/inet.h> -#include <sys/types.h> +#include <netdb.h> #include <netinet/in.h> #include <netinet/ip.h> +#include <sys/types.h> void tst_get_in_addr (const char *ip_str,struct in_addr *ip);void tst_get_in6_addr (const char *ip_str,struct in6_addr *ip6);
@@ -27,4 +28,8 @@ void tst_init_sockaddr_inet_bin(struct sockaddr_in *sa, uint32_t ip_val, uint16_void tst_init_sockaddr_inet6 (struct sockaddr_in6 *sa,const char *ip_str,uint16_t port);void tst_init_sockaddr_inet6_bin (struct sockaddr_in6 *sa,const struct in6_addr *ip_val,uint16_t port); -#endif +void tst_setup_addrinfo (const char *src_addr,const char *port, +const struct addrinfo *hints, +struct addrinfo **addr_info); + +#endif /* TST_NET_H_ */
include/tst_private.h +1 -0
@@ -10,6 +10,7 @@#define TST_PRIVATE_H_ #include <stdio.h> +#include <netdb.h> #define MAX_IPV4_PREFIX 32#define MAX_IPV6_PREFIX 128
lib/tst_net.c +14 -0
@@ -5,6 +5,7 @@*/ #include <errno.h> +#include <netdb.h> #include <string.h> #include <stdlib.h>
@@ -204,3 +205,16 @@ void tst_init_sockaddr_inet6_bin(struct sockaddr_in6 *sa, const struct in6_addr sa->sin6_port =htons (port);memcpy (&sa->sin6_addr, ip_val,sizeof (struct in6_addr )); } + +void tst_setup_addrinfo (const char *src_addr,const char *port, +const struct addrinfo *hints, +struct addrinfo **addr_info) +{ +int err =getaddrinfo (src_addr, port, hints, addr_info); + +if (err) +tst_brk (TBROK ,"getaddrinfo failed, %s" ,gai_strerror (err)); + +if (!*addr_info) +tst_brk (TBROK ,"failed to get the address" ); +}
testcases/network/netstress/netstress.c +4 -16
@@ -29,6 +29,7 @@#include "tst_safe_stdio.h" #include "tst_safe_pthread.h" #include "tst_test.h" +#include "tst_net.h" static const int max_msg_len = (1 <<16 ) -1 ;static const int min_msg_len =5 ;
@@ -441,19 +442,6 @@ static int parse_client_request(const char *msg)static struct timespec tv_client_start;static struct timespec tv_client_end; -static void setup_addrinfo (const char *src_addr,const char *port, -const struct addrinfo *hints, -struct addrinfo **addr_info) -{ -int err =getaddrinfo (src_addr, port, hints, addr_info); - -if (err) -tst_brk (TBROK ,"getaddrinfo failed, %s" ,gai_strerror (err)); - -if (!*addr_info) -tst_brk (TBROK ,"failed to get the address" ); -} -static void client_init (void ) {if (clients_num >=MAX_THREADS ) {
@@ -471,8 +459,8 @@ static void client_init(void) hints.ai_protocol =0 ;if (source_addr) -setup_addrinfo (source_addr,NULL , &hints, &local_addrinfo); -setup_addrinfo (server_addr, tcp_port, &hints, &remote_addrinfo); +tst_setup_addrinfo (source_addr,NULL , &hints, &local_addrinfo); +tst_setup_addrinfo (server_addr, tcp_port, &hints, &remote_addrinfo);tst_res (TINFO ,"Running the test over IPv%s" , (remote_addrinfo->ai_family ==AF_INET6 ) ?"6" :"4" );
@@ -667,7 +655,7 @@ static void server_init(void)if (source_addr && !strchr (source_addr,':' ))SAFE_ASPRINTF (&src_addr,"::ffff:%s" , source_addr); -setup_addrinfo (src_addr ? src_addr : source_addr, tcp_port, +tst_setup_addrinfo (src_addr ? src_addr : source_addr, tcp_port, &hints, &local_addrinfo);free (src_addr);
Signature · 1 line
2.26.0
RFC PATCH v3 1/2 net: Move setup_addrinfo() into tst_net.h
Hi Petr,
Quoted 127 lines · Petr Vorel
as
tst_setup_addrinfo().This allows reusing it in next commit.
Signed-off-by Petr Vorel <[email protected]>---
Changesv1->v2:
*setup_addrinfo()renamed totst_setup_addrinfo()
* rebaseinclude/tst_net.h | 9 +++++++-- include/tst_private.h | 1 + lib/tst_net.c | 14 ++++++++++++++ testcases/network/netstress/netstress.c | 20 ++++---------------- 4 files changed, 26 insertions(+), 18 deletions(-)include/tst_net.h +7
-2@@ -7,9 +7,10 @@#define TST_NET_H_ #include <arpa/inet.h> -#include <sys/types.h> +#include <netdb.h> #include <netinet/in.h> #include <netinet/ip.h> +#include <sys/types.h> void tst_get_in_addr (const char *ip_str,struct in_addr *ip);void tst_get_in6_addr (const char *ip_str,struct in6_addr *ip6);@@ -27,4 +28,8 @@ void tst_init_sockaddr_inet_bin(struct sockaddr_in *sa, uint32_t ip_val, uint16_void tst_init_sockaddr_inet6 (struct sockaddr_in6 *sa,const char *ip_str,uint16_t port);void tst_init_sockaddr_inet6_bin (struct sockaddr_in6 *sa,const struct in6_addr *ip_val,uint16_t port); -#endif +void tst_setup_addrinfo (const char *src_addr,const char *port, +const struct addrinfo *hints, +struct addrinfo **addr_info); + +#endif /* TST_NET_H_ */ include/tst_private.h +1
-0@@ -10,6 +10,7 @@#define TST_PRIVATE_H_ #include <stdio.h> +#include <netdb.h> #define MAX_IPV4_PREFIX 32#define MAX_IPV6_PREFIX 128lib/tst_net.c +14
-0@@ -5,6 +5,7 @@*/ #include <errno.h> +#include <netdb.h> #include <string.h> #include <stdlib.h> @@ -204,3 +205,16 @@ void tst_init_sockaddr_inet6_bin(struct sockaddr_in6 *sa, const struct in6_addr sa->sin6_port =htons (port);memcpy (&sa->sin6_addr, ip_val,sizeof (struct in6_addr )); } + +void tst_setup_addrinfo (const char *src_addr,const char *port, +const struct addrinfo *hints, +struct addrinfo **addr_info) +{ +int err =getaddrinfo (src_addr, port, hints, addr_info); + +if (err) +tst_brk (TBROK ,"getaddrinfo failed, %s" ,gai_strerror (err)); + +if (!*addr_info) +tst_brk (TBROK ,"failed to get the address" ); +}testcases/network/netstress/netstress.c +3
-15@@ -29,6 +29,7 @@#include "tst_safe_stdio.h" #include "tst_safe_pthread.h" #include "tst_test.h" +#include "tst_net.h" static const int max_msg_len = (1 <<16 ) -1 ;static const int min_msg_len =5 ;@@ -441,19 +442,6 @@ static int parse_client_request(const char *msg)static struct timespec tv_client_start;static struct timespec tv_client_end; -static void setup_addrinfo (const char *src_addr,const char *port, -const struct addrinfo *hints, -struct addrinfo **addr_info) -{ -int err =getaddrinfo (src_addr, port, hints, addr_info); - -if (err) -tst_brk (TBROK ,"getaddrinfo failed, %s" ,gai_strerror (err)); - -if (!*addr_info) -tst_brk (TBROK ,"failed to get the address" ); -} -static void client_init (void ) {if (clients_num >=MAX_THREADS ) {@@ -471,8 +459,8 @@ static void client_init(void) hints.ai_protocol =0 ;if (source_addr) -setup_addrinfo (source_addr,NULL , &hints, &local_addrinfo); -setup_addrinfo (server_addr, tcp_port, &hints, &remote_addrinfo); +tst_setup_addrinfo (source_addr,NULL , &hints, &local_addrinfo); +tst_setup_addrinfo (server_addr, tcp_port, &hints, &remote_addrinfo);tst_res (TINFO ,"Running the test over IPv%s" , (remote_addrinfo->ai_family ==AF_INET6 ) ?"6" :"4" );
testcases/network/netstress/netstress.c static void server_init(void) · line 661
Quoted 8 lines
testcases/network/netstress/netstress.c +1
-1@@ -667,7 +655,7 @@ static void server_init(void)if (source_addr && !strchr (source_addr,':' ))SAFE_ASPRINTF (&src_addr,"::ffff:%s" , source_addr); -setup_addrinfo (src_addr ? src_addr : source_addr, tcp_port, +tst_setup_addrinfo (src_addr ? src_addr : source_addr, tcp_port, &hints, &local_addrinfo);free (src_addr);
RFC PATCH v3 2/2 net/route: Add netlink based route change gw/dest tests
In reply to Petr Vorel* use libmnl and new C API
* reuse code in tst_net.h (added in previous commit)
* add shell wrapper route-change-netlink.sh (set environment with tst_net.sh instead of using deprecated helpers in testcases/network/stress/ns-tools/)
* add tst_ipaddr_un() into C API, unlike shell API this implementation does not support -c tst_ipaddr_un [-cCOUNTER] [TYPE] syntax.
Travis:
* add libmnl libraries to most of travis jobs
Cleanup:
* cleanup test description
* other cleanup
---
Changes v1->v2:
* Drop tst_ipaddr_un() in C. I did more complete implementation than in v1, but then decided to pass parameters in from shell.
* Find free rhost port in shell and pass it to C.
configure.ac | 1 + include/mk/config.mk.in | 2 + m4/ltp-libmnl.m4 | 8 + runtest/net_stress.route | 4 + testcases/network/stress/route/.gitignore | 1 + .../network/stress/route/00_Descriptions.txt | 39 +- testcases/network/stress/route/Makefile | 30 +- .../network/stress/route/route-change-dst.sh | 1 + .../network/stress/route/route-change-gw.sh | 10 +- .../network/stress/route/route-change-if.sh | 1 + .../stress/route/route-change-netlink-dst.sh | 33 ++ .../stress/route/route-change-netlink-gw.sh | 30 ++ .../stress/route/route-change-netlink.c | 348 ++++++++++++++++++ testcases/network/stress/route/route-lib.sh | 34 +- travis/debian.cross-compile.sh | 1 + travis/debian.sh | 1 + travis/fedora.sh | 3 + travis/tumbleweed.sh | 1 + 18 files changed, 492 insertions(+), 56 deletions(-) create mode 100644 m4/ltp-libmnl.m4 create mode 100644 testcases/network/stress/route/.gitignore create mode 100755 testcases/network/stress/route/route-change-netlink-dst.sh create mode 100755 testcases/network/stress/route/route-change-netlink-gw.sh create mode 100644 testcases/network/stress/route/route-change-netlink.c
configure.ac +1 -0
@@ -300,6 +300,7 @@ LTP_CHECK_CRYPTO LTP_CHECK_FORTIFY_SOURCE LTP_CHECK_KERNEL_DEVEL LTP_CHECK_KEYUTILS_SUPPORT +LTP_CHECK_LIBMNL LTP_CHECK_LINUX_PTRACE LTP_CHECK_LINUXRANDOM LTP_CHECK_MREMAP_FIXED
include/mk/config.mk.in +2 -0
@@ -43,6 +43,8 @@ TIRPC_CFLAGS := @TIRPC_CFLAGS@ TIRPC_LIBS := @TIRPC_LIBS@ KEYUTILS_LIBS := @KEYUTILS_LIBS@ HAVE_FTS_H := @HAVE_FTS_H@ +LIBMNL_LIBS := @LIBMNL_LIBS@ +LIBMNL_CFLAGS := @LIBMNL_CFLAGS@ prefix := @prefix@
m4/ltp-libmnl.m4 new file +8 -0
@@ -0,0 +1,8 @@ +dnl SPDX-License-Identifier: GPL-2.0-or-later +dnl Copyright (c) 2019 Petr Vorel <[email protected]> + +AC_DEFUN([LTP_CHECK_LIBMNL], [ + PKG_CHECK_MODULES([LIBMNL], [libmnl], [ + AC_DEFINE([HAVE_LIBMNL], [1], [Define to 1 if you have libmnl library and headers]) + ], [have_libmnl=no]) +])
runtest/net_stress.route +4 -0
@@ -2,11 +2,15 @@ route4-change-dst route-change-dst.sh route4-change-gw route-change-gw.sh route4-change-if route-change-if.sh +route4-change-netlink-dst route-change-netlink.sh +route4-change-netlink-gw route-change-netlink.sh -g route4-redirect route4-redirect route4-rmmod route4-rmmod route6-change-dst route-change-dst.sh -6 route6-change-gw route-change-gw.sh -6 route6-change-if route-change-if.sh -6 +route6-change-netlink-dst route-change-netlink.sh +route6-change-netlink-gw route-change-netlink.sh -g route6-redirect route6-redirect route6-rmmod route6-rmmod
testcases/network/stress/route/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/route-change-netlink
testcases/network/stress/route/00_Descriptions.txt +13 -26
@@ -1,36 +1,23 @@ route{4,6}-change-dst - Verify the IPv4/IPv6 is not broken when ip command changes route - destination many times + Change IPv4/IPv6 route destination by ip command route{4,6}-change-gw - Verify the IPv4/IPv6 is not broken when ip command changes route - gateway many times + Change IPv4/IPv6 route gateway by ip command route{4,6}-change-if - Verify the IPv4/IPv6 is not broken when ip command changes route - interface many times + Change IPv4/IPv6 route interface by ip command -route4-redirect01 - Verify the kernel is not crashed when the IPv4 route is modified by - ICMP Redirects frequently +route{4,6}-change-netlink-dst + Change IPv4/IPv6 route destination by libmnl API -route4-rmmod01 - Verify the kernel is not crashed when IPv4 route is add by route command - then it is deleted by the removing network driver +route{4,6}-change-netlink-gw + Change IPv4/IPv6 route gateway by libmnl API -route4-rmmod02 - Verify the kernel is not crashed when IPv4 route is add by ip command - then it is deleted by the removing network driver +route{4,6}-redirect01 + Change IPv4/IPv6 route by ICMP Redirects frequently +route{4,6}-rmmod01 + Add IPv4/IPv6 route by route command then delete it by the removing network driver -route6-redirect01 - Verify the kernel is not crashed when the IPv6 route is modified by - ICMP Redirects frequently - -route6-rmmod01 - Verify the kernel is not crashed when IPv6 route is add by route command - then it is deleted by the removing network driver - -route6-rmmod02 - Verify the kernel is not crashed when IPv6 route is add by ip command - then it is deleted by the removing network driver +route{4,6}-rmmod02 + Add IPv4/IPv6 route by ip command then delete it by the removing network driver
testcases/network/stress/route/Makefile +8 -22
@@ -1,29 +1,15 @@ -# -# network/stress/route test suite Makefile. -# -# Copyright (C) 2009, Cisco Systems Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2009, Cisco Systems Inc. +# Copyright (c) Linux Test Project, 2006-2020 # Ngie Cooper, October 2009 -# top_srcdir ?= ../../../.. -include $(top_srcdir)/include/mk/env_pre.mk +include $(top_srcdir)/include/mk/testcases.mk -INSTALL_TARGETS := route* +INSTALL_TARGETS += route[4-6]-* *.sh + +route-change-netlink: CFLAGS += $(LIBMNL_CFLAGS) +route-change-netlink: LDLIBS += $(LIBMNL_LIBS) include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/network/stress/route/route-change-dst.sh +1 -0
@@ -9,6 +9,7 @@ # lhost: 10.0.0.2, rhost: 10.23.x.1 TST_TESTFUNC="test_dst" +TST_CNT=$NS_TIMES . route-lib.sh setup()
testcases/network/stress/route/route-change-gw.sh +3 -7
@@ -1,6 +1,6 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0-or-later -# Copyright (c) 2019 Petr Vorel <[email protected]> +# Copyright (c) 2019-2020 Petr Vorel <[email protected]> # Copyright (c) International Business Machines Corp., 2006 # Author: Mitsuru Chinen <[email protected]> # Rewrite into new shell API: Petr Vorel
@@ -9,17 +9,13 @@ # lhost: 10.23.1.1, gw (on rhost): 10.23.1.x, rhost: 10.23.0.1 TST_TESTFUNC="test_gw" +TST_CNT=$NS_TIMES . route-lib.sh setup() { tst_res TINFO "change IPv$TST_IPVER route gateway $NS_TIMES times" - - rt="$(tst_ipaddr_un -p 0 0)" - lhost="$(tst_ipaddr_un 1 1)" - rhost="$(tst_ipaddr_un 0 1)" - tst_add_ipaddr -s -q -a $lhost - tst_add_ipaddr -s -q -a $rhost rhost + setup_gw } test_gw()
testcases/network/stress/route/route-change-if.sh +1 -0
@@ -9,6 +9,7 @@ # lhost: 10.23.x.2, gw (on rhost): 10.23.x.1, rhost: 10.23.0.1, switching ifaces on lhost TST_TESTFUNC="test_if" +TST_CNT=$NS_TIMES . route-lib.sh TST_CLEANUP="cleanup"
testcases/network/stress/route/route-change-netlink-dst.sh new file +33 -0
@@ -0,0 +1,33 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2020 Petr Vorel <[email protected]> +# +# Change route destination via netlink +# lhost: 10.0.0.2, rhost: 10.23.x.1 + +TST_TESTFUNC="test_netlink" +. route-lib.sh + +setup() +{ + tst_res TINFO "change IPv$TST_IPVER route destination $NS_TIMES times" + + local cnt=0 + local gw rhost rhost_all rt + + check_max_ip + + while [ $cnt -lt $NS_TIMES -a $cnt -lt $MAX_IP ]; do + rt="$(tst_ipaddr_un -p $cnt)" + rhost="$(tst_ipaddr_un $cnt 1)" + rhost_all="$rhost^$rhost_all" + + tst_add_ipaddr -s -q -a $rhost rhost + ROD ip route add $rt dev $(tst_iface) + cnt=$((cnt+1)) + done + + ROUTE_CHANGE_NETLINK_PARAMS="-l $(tst_ipaddr) -r '$rhost_all'" +} + +tst_run
testcases/network/stress/route/route-change-netlink-gw.sh new file +30 -0
@@ -0,0 +1,30 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2020 Petr Vorel <[email protected]> +# +# Change route gateway via netlink +# lhost: 10.23.1.1, gw (on rhost): 10.23.1.x, rhost: 10.23.0.1 + +TST_TESTFUNC="test_netlink" +. route-lib.sh + +setup() +{ + tst_res TINFO "change IPv$TST_IPVER route gateway $NS_TIMES times" + + local cnt=0 + + check_max_ip + setup_gw + + while [ $cnt -lt $NS_TIMES -a $cnt -lt $MAX_IP ]; do + gw="$(tst_ipaddr_un -h 2,$max_ip_limit 1 $(($cnt + 1)))" + gw_all="$gw^$gw_all" + tst_add_ipaddr -s -q -a $gw rhost + cnt=$((cnt+1)) + done + + ROUTE_CHANGE_NETLINK_PARAMS="-g "$gw_all" -l $lhost -r $rhost" +} + +tst_run
testcases/network/stress/route/route-change-netlink.c new file +348 -0
348 lines not on this page · raw message
testcases/network/stress/route/route-lib.sh +33 -1
@@ -6,10 +6,42 @@ TST_NEEDS_ROOT=1 TST_SETUP="setup" TST_CLEANUP="route_cleanup" TST_NEEDS_CMDS="ip" -TST_CNT=$NS_TIMES . tst_net.sh +MAX_IP=${MAX_IP:-5} + +check_max_ip() +{ + local max_ip_limit=254 + [ "$TST_IPV6" ] && max_ip_limit=65534 + + tst_is_int $MAX_IP || tst_brk TBROK "\$MAX_IP not int ($MAX_IP)" + [ "$MAX_IP" -gt $max_ip_limit ] && MAX_IP=$max_ip_limit +} + +setup_gw() +{ + tst_res TINFO "change IPv$TST_IPVER route gateway $NS_TIMES times" + + rt="$(tst_ipaddr_un -p 0 0)" + lhost="$(tst_ipaddr_un 1 1)" + rhost="$(tst_ipaddr_un 0 1)" + tst_add_ipaddr -s -q -a $lhost + tst_add_ipaddr -s -q -a $rhost rhost +} + + +test_netlink() +{ + local ip_flag + [ "$TST_IPV6" ] && ip_flag="-6" + + local port=$(tst_rhost_run -s -c "tst_get_unused_port ipv${TST_IPVER} dgram") + + EXPECT_PASS route-change-netlink -c $NS_TIMES -d $(tst_iface) $ip_flag -p $port $ROUTE_CHANGE_NETLINK_PARAMS +} + route_cleanup() { tst_restore_ipaddr
travis/debian.cross-compile.sh +1 -0
@@ -20,4 +20,5 @@ apt update apt install -y --no-install-recommends \ gcc-${gcc_arch}-linux-gnu \ libc6-dev-${ARCH}-cross \ + libmnl-dev:$ARCH \ libtirpc-dev:$ARCH
travis/debian.sh +1 -0
@@ -28,6 +28,7 @@ apt install -y --no-install-recommends \ libkeyutils-dev \ libkeyutils1 \ libmm-dev \ + libmnl-dev \ libnuma-dev \ libnuma1 \ libselinux1-dev \
travis/fedora.sh +3 -0
@@ -13,3 +13,6 @@ yum -y install \ libtirpc-devel \ pkg-config \ redhat-lsb-core + +# CentOS 8 doesn't have libmnl-devel +yum -y install libmnl-devel || yum -y install libmnl
travis/tumbleweed.sh +1 -0
@@ -15,6 +15,7 @@ zypper --non-interactive install --no-recommends \ libacl-devel \ libaio-devel \ libcap-devel \ + libmnl-devel \ libnuma-devel \ libopenssl-devel \ libselinux-devel \
Signature · 1 line
2.26.0
RFC PATCH v3 2/2 net/route: Add netlink based route change gw/dest tests
Hi Alexey,
Quoted 7 lines
+++ b/runtest/net_stress.route
(quoted diff) +2
-0@@ -2,11 +2,15 @@ route4-change-dst route-change-dst.sh route4-change-gw route-change-gw.sh route4-change-if route-change-if.sh +route4-change-netlink-dst route-change-netlink.sh +route4-change-netlink-gw route-change-netlink.sh -g
Review line 16
Quoted 10 lines
(quoted diff) +2
-0route4-redirect route4-redirect route4-rmmod route4-rmmod route6-change-dst route-change-dst.sh -6 route6-change-gw route-change-gw.sh -6 route6-change-if route-change-if.sh -6 +route6-change-netlink-dst route-change-netlink.sh +route6-change-netlink-gw route-change-netlink.sh -g route6-redirect route6-redirect route6-rmmod route6-rmmod
I haven't updated the runtest file (route-change-netlink.sh => route-change-netlink-dst.sh and route-change-netlink-gw.sh)
Kind regards,
Petr
net_stress.route +4 -4
@@ -2,15 +2,15 @@ route4-change-dst route-change-dst.sh route4-change-gw route-change-gw.sh route4-change-if route-change-if.sh -route4-change-netlink-dst route-change-netlink.sh -route4-change-netlink-gw route-change-netlink.sh -g +route4-change-netlink-dst route-change-netlink-dst.sh +route4-change-netlink-gw route-change-netlink-gw.sh -g route4-redirect route4-redirect route4-rmmod route4-rmmod route6-change-dst route-change-dst.sh -6 route6-change-gw route-change-gw.sh -6 route6-change-if route-change-if.sh -6 -route6-change-netlink-dst route-change-netlink.sh -route6-change-netlink-gw route-change-netlink.sh -g +route6-change-netlink-dst route-change-netlink-dst.sh +route6-change-netlink-gw route-change-netlink-gw.sh -g route6-redirect route6-redirect route6-rmmod route6-rmmod
RFC PATCH v3 2/2 net/route: Add netlink based route change gw/dest tests
In reply to Petr VorelHi Alexey,
Quoted 2 lines
* use libmnl and new C API
* reuse code intst_net.h(added in previous commit)
Sorry, these 2 are also outdated:
Quoted 2 lines
* add shell wrapper
route-change-netlink.sh(set environment withtst_net.shinstead of using deprecated helpers in testcases/network/stress/ns-tools/)
2 wrappers.
Quoted 2 lines
* add
tst_ipaddr_un()into C API, unlike shell API this implementation does not support -ctst_ipaddr_un[-cCOUNTER] [TYPE] syntax.
That was removed in this version.
Kind regards,
Petr
RFC PATCH v3 2/2 net/route: Add netlink based route change gw/dest tests
In reply to Petr VorelQuoted 239 lines · Petr Vorel
* use libmnl and new C API
* reuse code intst_net.h(added in previous commit)
* add shell wrapperroute-change-netlink.sh(set environment withtst_net.shinstead of using deprecated helpers in testcases/network/stress/ns-tools/)
* addtst_ipaddr_un()into C API, unlike shell API this implementation does not support -ctst_ipaddr_un[-cCOUNTER] [TYPE] syntax.Travis:
* add libmnl libraries to most of travis jobsCleanup:
* cleanup test description
* other cleanupSigned-off-by Petr Vorel <[email protected]>---
Changesv1->v2:
* Droptst_ipaddr_un()in C. I did more complete implementation than in v1, but then decided to pass parameters in from shell.
* Find free rhost port in shell and pass it to C.configure.ac | 1 + include/mk/config.mk.in | 2 + m4/ltp-libmnl.m4 | 8 + runtest/net_stress.route | 4 + testcases/network/stress/route/.gitignore | 1 + .../network/stress/route/00_Descriptions.txt | 39 +- testcases/network/stress/route/Makefile | 30 +- .../network/stress/route/route-change-dst.sh | 1 + .../network/stress/route/route-change-gw.sh | 10 +- .../network/stress/route/route-change-if.sh | 1 + .../stress/route/route-change-netlink-dst.sh | 33 ++ .../stress/route/route-change-netlink-gw.sh | 30 ++ .../stress/route/route-change-netlink.c | 348 ++++++++++++++++++ testcases/network/stress/route/route-lib.sh | 34 +- travis/debian.cross-compile.sh | 1 + travis/debian.sh | 1 + travis/fedora.sh | 3 + travis/tumbleweed.sh | 1 + 18 files changed, 492 insertions(+), 56 deletions(-) create mode 100644 m4/ltp-libmnl.m4 create mode 100644 testcases/network/stress/route/.gitignore create mode 100755 testcases/network/stress/route/route-change-netlink-dst.sh create mode 100755 testcases/network/stress/route/route-change-netlink-gw.sh create mode 100644 testcases/network/stress/route/route-change-netlink.cconfigure.ac +1
-0@@ -300,6 +300,7 @@ LTP_CHECK_CRYPTO LTP_CHECK_FORTIFY_SOURCE LTP_CHECK_KERNEL_DEVEL LTP_CHECK_KEYUTILS_SUPPORT +LTP_CHECK_LIBMNL LTP_CHECK_LINUX_PTRACE LTP_CHECK_LINUXRANDOM LTP_CHECK_MREMAP_FIXEDinclude/mk/config.mk.in +2
-0@@ -43,6 +43,8 @@ TIRPC_CFLAGS := @TIRPC_CFLAGS@ TIRPC_LIBS := @TIRPC_LIBS@ KEYUTILS_LIBS := @KEYUTILS_LIBS@ HAVE_FTS_H := @HAVE_FTS_H@ +LIBMNL_LIBS := @LIBMNL_LIBS@ +LIBMNL_CFLAGS := @LIBMNL_CFLAGS@ prefix := @prefix@m4/ltp-libmnl.m4 new file +8
-0@@ -0,0 +1,8 @@ +dnl SPDX-License-Identifier: GPL-2.0-or-later +dnl Copyright (c) 2019 Petr Vorel <[email protected]> + +AC_DEFUN([LTP_CHECK_LIBMNL], [ + PKG_CHECK_MODULES([LIBMNL], [libmnl], [ + AC_DEFINE([HAVE_LIBMNL], [1], [Define to 1 if you have libmnl library and headers]) + ], [have_libmnl=no]) +])runtest/net_stress.route +4
-0@@ -2,11 +2,15 @@ route4-change-dst route-change-dst.sh route4-change-gw route-change-gw.sh route4-change-if route-change-if.sh +route4-change-netlink-dst route-change-netlink.sh +route4-change-netlink-gw route-change-netlink.sh -g route4-redirect route4-redirect route4-rmmod route4-rmmod route6-change-dst route-change-dst.sh -6 route6-change-gw route-change-gw.sh -6 route6-change-if route-change-if.sh -6 +route6-change-netlink-dst route-change-netlink.sh +route6-change-netlink-gw route-change-netlink.sh -g route6-redirect route6-redirect route6-rmmod route6-rmmodtestcases/network/stress/route/.gitignore new file +1
-0@@ -0,0 +1 @@ +/route-change-netlinktestcases/network/stress/route/00_Descriptions.txt +13
-26@@ -1,36 +1,23 @@ route{4,6}-change-dst - Verify the IPv4/IPv6 is not broken when ip command changes route - destination many times + Change IPv4/IPv6 route destination by ip command route{4,6}-change-gw - Verify the IPv4/IPv6 is not broken when ip command changes route - gateway many times + Change IPv4/IPv6 route gateway by ip command route{4,6}-change-if - Verify the IPv4/IPv6 is not broken when ip command changes route - interface many times + Change IPv4/IPv6 route interface by ip command -route4-redirect01 - Verify the kernel is not crashed when the IPv4 route is modified by - ICMP Redirects frequently +route{4,6}-change-netlink-dst + Change IPv4/IPv6 route destination by libmnl API -route4-rmmod01 - Verify the kernel is not crashed when IPv4 route is add by route command - then it is deleted by the removing network driver +route{4,6}-change-netlink-gw + Change IPv4/IPv6 route gateway by libmnl API -route4-rmmod02 - Verify the kernel is not crashed when IPv4 route is add by ip command - then it is deleted by the removing network driver +route{4,6}-redirect01 + Change IPv4/IPv6 route by ICMP Redirects frequently +route{4,6}-rmmod01 + Add IPv4/IPv6 route by route command then delete it by the removing network driver -route6-redirect01 - Verify the kernel is not crashed when the IPv6 route is modified by - ICMP Redirects frequently - -route6-rmmod01 - Verify the kernel is not crashed when IPv6 route is add by route command - then it is deleted by the removing network driver - -route6-rmmod02 - Verify the kernel is not crashed when IPv6 route is add by ip command - then it is deleted by the removing network driver +route{4,6}-rmmod02 + Add IPv4/IPv6 route by ip command then delete it by the removing network drivertestcases/network/stress/route/Makefile +7
-22@@ -1,29 +1,15 @@ -# -# network/stress/route test suite Makefile. -# -# Copyright (C) 2009, Cisco Systems Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2009, Cisco Systems Inc. +# Copyright (c) Linux Test Project, 2006-2020 # Ngie Cooper, October 2009 -# top_srcdir ?= ../../../.. -include $(top_srcdir)/include/mk/env_pre.mk +include $(top_srcdir)/include/mk/testcases.mk -INSTALL_TARGETS := route* +INSTALL_TARGETS += route[4-6]-* *.sh> + +route-change-netlink: CFLAGS += $(LIBMNL_CFLAGS) +route-change-netlink: LDLIBS += $(LIBMNL_LIBS) include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/network/stress/route/route-change-dst.sh +1
-0@@ -9,6 +9,7 @@ # lhost: 10.0.0.2, rhost: 10.23.x.1 TST_TESTFUNC="test_dst" +TST_CNT=$NS_TIMES . route-lib.sh setup()testcases/network/stress/route/route-change-gw.sh +2
-1@@ -1,6 +1,6 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0-or-later -# Copyright (c) 2019 Petr Vorel <[email protected]> +# Copyright (c) 2019-2020 Petr Vorel <[email protected]> # Copyright (c) International Business Machines Corp., 2006 # Author: Mitsuru Chinen <[email protected]> # Rewrite into new shell API: Petr Vorel@@ -9,17 +9,13 @@ # lhost: 10.23.1.1, gw (on rhost): 10.23.1.x, rhost: 10.23.0.1 TST_TESTFUNC="test_gw" +TST_CNT=$NS_TIMES . route-lib.sh setup()
testcases/network/stress/route/route-change-gw.sh line 19
Quoted 10 lines
testcases/network/stress/route/route-change-gw.sh +1
-6{ tst_res TINFO "change IPv$TST_IPVER route gateway $NS_TIMES times" - - rt="$(tst_ipaddr_un -p 0 0)" - lhost="$(tst_ipaddr_un 1 1)" - rhost="$(tst_ipaddr_un 0 1)" - tst_add_ipaddr -s -q -a $lhost - tst_add_ipaddr -s -q -a $rhost rhost + setup_gw }
TST_SETUP=setup_gw
Quoted 475 lines
testcases/network/stress/route/route-change-gw.sh +0
-0test_gw()testcases/network/stress/route/route-change-if.sh +1
-0@@ -9,6 +9,7 @@ # lhost: 10.23.x.2, gw (on rhost): 10.23.x.1, rhost: 10.23.0.1, switching ifaces on lhost TST_TESTFUNC="test_if" +TST_CNT=$NS_TIMES . route-lib.sh TST_CLEANUP="cleanup"testcases/network/stress/route/route-change-netlink-dst.sh new file +33
-0@@ -0,0 +1,33 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2020 Petr Vorel <[email protected]> +# +# Change route destination via netlink +# lhost: 10.0.0.2, rhost: 10.23.x.1 + +TST_TESTFUNC="test_netlink" +. route-lib.sh + +setup() +{ + tst_res TINFO "change IPv$TST_IPVER route destination $NS_TIMES times" + + local cnt=0 + local gw rhost rhost_all rt + + check_max_ip + + while [ $cnt -lt $NS_TIMES -a $cnt -lt $MAX_IP ]; do + rt="$(tst_ipaddr_un -p $cnt)" + rhost="$(tst_ipaddr_un $cnt 1)" + rhost_all="$rhost^$rhost_all" + + tst_add_ipaddr -s -q -a $rhost rhost + ROD ip route add $rt dev $(tst_iface) + cnt=$((cnt+1)) + done + + ROUTE_CHANGE_NETLINK_PARAMS="-l $(tst_ipaddr) -r '$rhost_all'" +} + +tst_runtestcases/network/stress/route/route-change-netlink-gw.sh new file +30
-0@@ -0,0 +1,30 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2020 Petr Vorel <[email protected]> +# +# Change route gateway via netlink +# lhost: 10.23.1.1, gw (on rhost): 10.23.1.x, rhost: 10.23.0.1 + +TST_TESTFUNC="test_netlink" +. route-lib.sh + +setup() +{ + tst_res TINFO "change IPv$TST_IPVER route gateway $NS_TIMES times" + + local cnt=0 + + check_max_ip + setup_gw + + while [ $cnt -lt $NS_TIMES -a $cnt -lt $MAX_IP ]; do + gw="$(tst_ipaddr_un -h 2,$max_ip_limit 1 $(($cnt + 1)))" + gw_all="$gw^$gw_all" + tst_add_ipaddr -s -q -a $gw rhost + cnt=$((cnt+1)) + done + + ROUTE_CHANGE_NETLINK_PARAMS="-g "$gw_all" -l $lhost -r $rhost" +} + +tst_runtestcases/network/stress/route/route-change-netlink.c new file +348
-0@@ -0,0 +1,348 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 Petr Vorel <[email protected]> +*/ + +/* +* dst: lhost: 10.0.0.2, rhost: 10.23.x.1 +* gw: lhost: 10.23.1.1, gw (on rhost): 10.23.1.x, rhost: 10.23.0.1 +* if: lhost: 10.23.x.2, gw (on rhost): 10.23.x.1, rhost: 10.23.0.1, switching ifaces on lhost +*/ + +#include "config.h" +#include "tst_test.h" + +#ifdef HAVE_LIBMNL + +#include <string.h> + +#include <libmnl/libmnl.h> +#include <linux/rtnetlink.h> +#include <net/if.h> +#include <netdb.h> +#include <netinet/in.h> + +#include "tst_net.h" +#include "tst_safe_net.h" +#include "tst_safe_stdio.h" + +#define NS_TIMES_MAX 65535 + +#define IP_ADDR_DELIMITER '^' +#define STR (x) #x +#define CHR2STR (x) STR(x) + +static char *c_opt, *d_opt, *g_opt, *ipv6_opt, *l_opt, *p_opt, *r_opt; + +static int family =AF_INET ; +static int fd, num_loops, port; + +static unsigned int is_ipv6, max, prefix; + +static struct mnl_socket *nl; +static struct addrinfo *lhost_addrinfo, *rhost_addrinfo; + +struct in_addr ip; +struct in6_addr ip6; + +union { +in_addr_t ip; +struct in6_addr ip6; +} dst; + +struct iface { +char iface[IFNAMSIZ ]; +unsigned int index; +struct iface *next; +}; + +struct ip_addr { +char ip[INET6_ADDRSTRLEN ]; +struct ip_addr *next; +}; + +static struct ip_addr *gw, *lhost, *rhost; +static struct iface *iface; +static unsigned int gw_len, iface_len, lhost_len, rhost_len; + +void save_iface_str (struct iface **list,const char *item) +{ +struct iface *n =SAFE_MALLOC (sizeof (*n)); + +strncpy (n->iface, item,sizeof (n->iface)); + n->iface[sizeof (n->iface)-1 ] ='\0' ; + + n->index =if_nametoindex (item); +if (!n->index) +tst_brk (TBROK ,"if_nametoindex failed, '%s' not found" , item); + n->next = *list; + *list = n; +} + +void save_ip_str (struct ip_addr **list,const char *item) +{ +struct ip_addr *n =SAFE_MALLOC (sizeof (*n)); + +strncpy (n->ip, item,sizeof (n->ip)); + n->ip[sizeof (n->ip)-1 ] ='\0' ; + + n->next = *list; + *list = n; +} + +int save_iface (struct iface **list,char *item) +{ +int len =0 ; + +while ((item =strtok (item,CHR2STR (IP_ADDR_DELIMITER ))) !=NULL ) { +save_iface_str (list, item); + item =NULL ; + len++; + } + +return len; +} + +int save_ip (struct ip_addr **list,char *item) +{ +int len =0 ; + +while ((item =strtok (item,CHR2STR (IP_ADDR_DELIMITER ))) !=NULL ) { +save_ip_str (list, item); + item =NULL ; + len++; + } + +return len; +} + +static void setup (void ) +{ + prefix =24 ; +if (ipv6_opt) { + family =AF_INET6 ; + is_ipv6 =1 ; + prefix =64 ; + } +if (!c_opt) +tst_brk (TBROK ,"missing number of loops (-c num)" ); + +if (!d_opt) +tst_brk (TBROK ,"Missing iface (-d iface)" ); + +if (!l_opt) +tst_brk (TBROK ,"Missing lhost IP (-l IP)" ); + +if (!p_opt) +tst_brk (TBROK ,"Missing rhost port (-p port)" ); + +if (!r_opt) +tst_brk (TBROK ,"Missing rhost IP (-r IP)" ); + +if (tst_parse_int (p_opt, &port,1 ,65535 )) +tst_brk (TBROK ,"invalid rhost port '%s'" , p_opt); + +if (tst_parse_int (c_opt, &num_loops,1 ,65535 )) +tst_brk (TBROK ,"invalid number of loops '%s'" , c_opt); + + iface_len =save_iface (&iface, d_opt); + lhost_len =save_ip (&lhost, l_opt); + rhost_len =save_ip (&rhost, r_opt); + + max =MAX (lhost_len, rhost_len); +if (lhost_len >1 && rhost_len >1 && lhost_len != rhost_len) +tst_brk (TBROK ,"-l and -r have more IP, they need to have the same count" ); + + max =MAX (iface_len, max); +if (iface_len >1 && max >1 && iface_len != max) +tst_brk (TBROK ,"-d has more NIC and %s has more IP, they need to have the same count" , + lhost_len >1 ?"-l" :"-r" ); + +if (g_opt) { + gw_len =save_ip (&gw, g_opt); + max =MAX (gw_len, max); + +if (gw_len >1 && max >1 && gw_len != max) { +if (iface_len == max) +tst_brk (TBROK ,"-d has more NIC and -g has more IP, they need to have the same count" ); +else +tst_brk (TBROK ,"-g and %s have more IP, they need to have the same count" , + lhost_len >1 ?"-l" :"-r" ); + } + } +} + +static void cleanup (void ) +{ +if (fd >0 ) +close (fd); + +if (nl) +mnl_socket_close (nl); + +if (lhost_addrinfo) +freeaddrinfo (lhost_addrinfo); + +if (rhost_addrinfo) +freeaddrinfo (rhost_addrinfo); +} + +static void rtnl_route (int iface,char *destination,uint32_t prefix,char + *gateway,int type) +{ +union { +in_addr_t ip; +struct in6_addr ip6; + } dst; +union { +in_addr_t ip; +struct in6_addr ip6; + } gw; + +struct mnl_socket *nl; +char buf[MNL_SOCKET_BUFFER_SIZE ]; +struct nlmsghdr *nlh; +struct rtmsg *rtm; +uint32_t seq, portid; +int ret; + +if (!inet_pton (family, destination, &dst)) +tst_brk (TBROK ,"inet_pton failed ('%s', errno=%d): %s" , + destination, errno,strerror (errno)); + +if (gateway && !inet_pton (family, gateway, &gw)) +tst_brk (TBROK ,"inet_pton failed ('%s', errno=%d): %s" , gateway, + errno,strerror (errno)); + + nlh =mnl_nlmsg_put_header (buf); + nlh->nlmsg_type = type; + nlh->nlmsg_flags =NLM_F_REQUEST |NLM_F_CREATE |NLM_F_ACK ; + nlh->nlmsg_seq = seq =time (NULL ); + + rtm =mnl_nlmsg_put_extra_header (nlh,sizeof (struct rtmsg )); + rtm->rtm_family = family; + rtm->rtm_dst_len = prefix; + rtm->rtm_src_len =0 ; + rtm->rtm_tos =0 ; + rtm->rtm_protocol =RTPROT_STATIC ; + rtm->rtm_table =RT_TABLE_MAIN ; + rtm->rtm_type =RTN_UNICAST ; + rtm->rtm_scope = (gateway) ?RT_SCOPE_UNIVERSE :RT_SCOPE_LINK ; + rtm->rtm_flags =0 ; + +if (is_ipv6) +mnl_attr_put (nlh,RTA_DST ,sizeof (struct in6_addr ), &dst); +else +mnl_attr_put_u32 (nlh,RTA_DST , dst.ip); + +mnl_attr_put_u32 (nlh,RTA_OIF , iface); +if (gateway) { +if (is_ipv6) +mnl_attr_put (nlh,RTA_GATEWAY ,sizeof (struct in6_addr ), + &gw.ip6); +else +mnl_attr_put_u32 (nlh,RTA_GATEWAY , gw.ip); + } + + nl =mnl_socket_open (NETLINK_ROUTE ); +if (nl ==NULL ) +tst_brk (TBROK ,"mnl_socket_open failed (errno=%d): %s" , errno, +strerror (errno)); + +if (mnl_socket_bind (nl,0 ,MNL_SOCKET_AUTOPID ) <0 ) +tst_brk (TBROK ,"mnl_socket_bind failed (errno=%d): %s" , errno, +strerror (errno)); + + portid =mnl_socket_get_portid (nl); + +if (mnl_socket_sendto (nl, nlh, nlh->nlmsg_len) <0 ) +tst_brk (TBROK ,"mnl_socket_sendto failed (errno=%d): %s" , errno, +strerror (errno)); + + ret =mnl_socket_recvfrom (nl, buf,sizeof (buf)); +if (ret <0 ) +tst_brk (TBROK ,"mnl_socket_recvfrom failed (ret=%d, errno=%d): %s" , + ret, errno,strerror (errno)); + + ret =mnl_cb_run (buf, ret, seq, portid,NULL ,NULL ); +if (ret <0 ) +tst_brk (TBROK ,"mnl_cb_run failed (ret=%d, errno=%d): %s" , ret, + errno,strerror (errno)); + +mnl_socket_close (nl); +} + +static void send_udp (char *local,char *remote) +{ + fd =SAFE_SOCKET (family,SOCK_DGRAM ,IPPROTO_UDP ); + +struct addrinfo hints; +memset (&hints,0 ,sizeof (struct addrinfo )); + hints.ai_family = family; + hints.ai_socktype =SOCK_DGRAM ; + hints.ai_flags =0 ; + hints.ai_protocol =0 ; + hints.ai_addr =INADDR_ANY ; + +tst_setup_addrinfo (local,NULL , &hints, &lhost_addrinfo); +tst_setup_addrinfo (remote, p_opt, &hints, &rhost_addrinfo); + +SAFE_SENDTO (1 , fd, remote,sizeof (remote),MSG_CONFIRM , + rhost_addrinfo->ai_addr, rhost_addrinfo->ai_addrlen); + +close (fd); +} + +static void run (void ) +{ +int i; + +tst_res (TINFO ,"adding and deleting route with different destination %d times" , num_loops); + +struct ip_addr *p_gw = gw, *p_lhost = lhost, *p_rhost = rhost; +struct iface *p_iface = iface; +char dst[INET6_ADDRSTRLEN ]; + +for (i =0 ; i < num_loops; i++) { +if (!strncpy (dst, rhost->ip,sizeof (dst))) +tst_brk (TBROK ,"failed copy IP '%s'" , rhost->ip); + dst[strlen (rhost->ip)-1 ] ='\0' ; + +if (!strcat (dst,"0" )) +tst_brk (TBROK ,"strcat failed: '%s'" , dst); + +rtnl_route (iface->index, dst, prefix, gw->ip,RTM_NEWROUTE ); +send_udp (lhost->ip, rhost->ip); +rtnl_route (iface->index, dst, prefix, gw->ip,RTM_DELROUTE ); + +if (gw) + gw = gw->next ?: p_gw; + iface = iface->next ?: p_iface; + lhost = lhost->next ?: p_lhost; + rhost = rhost->next ?: p_rhost; + } + +tst_res (TPASS ,"routes created and deleted" ); +} + +static struct tst_option options[] = { + {"6" , &ipv6_opt,"-6 Use IPv6 (default is IPv4)" }, + {"c:" , &c_opt," num loops (mandatory)" }, + {"d:" , &d_opt,"-d iface Interface to work on (mandatory)" }, + {"g:" , &g_opt,"-g x gateway IP" }, + {"l:" , &l_opt,"-l x lhost IP (mandatory)" }, + {"p:" , &p_opt,"-p port rhost port (mandatory)" }, + {"r:" , &r_opt,"-r x rhost IP (mandatory)\n\n-g, -l, -g IP paramter can contain more IP, separated by " +CHR2STR (IP_ADDR_DELIMITER )}, + {NULL ,NULL ,NULL } +}; +static struct tst_test test = { + .test_all = run, + .needs_root =1 , + .setup = setup, + .cleanup = cleanup, + .options = options, +}; +#else +TST_TEST_TCONF ("libmnl library and headers are required" ); +#endif /* HAVE_LIBMNL */ testcases/network/stress/route/route-lib.sh +20
-1@@ -6,10 +6,42 @@ TST_NEEDS_ROOT=1 TST_SETUP="setup" TST_CLEANUP="route_cleanup" TST_NEEDS_CMDS="ip" -TST_CNT=$NS_TIMES . tst_net.sh +MAX_IP=${MAX_IP:-5} + +check_max_ip() +{ + local max_ip_limit=254 + [ "$TST_IPV6" ] && max_ip_limit=65534 + + tst_is_int $MAX_IP || tst_brk TBROK "\$MAX_IP not int ($MAX_IP)" + [ "$MAX_IP" -gt $max_ip_limit ] && MAX_IP=$max_ip_limit +} + +setup_gw() +{ + tst_res TINFO "change IPv$TST_IPVER route gateway $NS_TIMES times" + + rt="$(tst_ipaddr_un -p 0 0)" + lhost="$(tst_ipaddr_un 1 1)" + rhost="$(tst_ipaddr_un 0 1)" + tst_add_ipaddr -s -q -a $lhost + tst_add_ipaddr -s -q -a $rhost rhost
testcases/network/stress/route/route-lib.sh TST_NEEDS_ROOT=1 · line 41
Quoted 10 lines
testcases/network/stress/route/route-lib.sh +10
-0+} + + +test_netlink() +{ + local ip_flag + [ "$TST_IPV6" ] && ip_flag="-6" + + local port=$(tst_rhost_run -s -c "tst_get_unused_port ipv${TST_IPVER} dgram") +
What will be listen on this remote port?
testcases/network/stress/route/route-lib.sh TST_NEEDS_ROOT=1 · line 42
Quoted 1 line
testcases/network/stress/route/route-lib.sh +1
-0+ EXPECT_PASS route-change-netlink -c $NS_TIMES -d $(tst_iface) $ip_flag -p $port $ROUTE_CHANGE_NETLINK_PARAMS
EXPECT_PASS doesn't handle TCONF when libmnl-devel is missing.
Quoted 51 lines
testcases/network/stress/route/route-lib.sh +2
-0+} + route_cleanup() { tst_restore_ipaddrtravis/debian.cross-compile.sh +1
-0@@ -20,4 +20,5 @@ apt update apt install -y --no-install-recommends \ gcc-${gcc_arch}-linux-gnu \ libc6-dev-${ARCH}-cross \ + libmnl-dev:$ARCH \ libtirpc-dev:$ARCHtravis/debian.sh +1
-0@@ -28,6 +28,7 @@ apt install -y --no-install-recommends \ libkeyutils-dev \ libkeyutils1 \ libmm-dev \ + libmnl-dev \ libnuma-dev \ libnuma1 \ libselinux1-dev \travis/fedora.sh +3
-0@@ -13,3 +13,6 @@ yum -y install \ libtirpc-devel \ pkg-config \ redhat-lsb-core + +# CentOS 8 doesn't have libmnl-devel +yum -y install libmnl-devel || yum -y install libmnltravis/tumbleweed.sh +1
-0@@ -15,6 +15,7 @@ zypper --non-interactive install --no-recommends \ libacl-devel \ libaio-devel \ libcap-devel \ + libmnl-devel \ libnuma-devel \ libopenssl-devel \ libselinux-devel \
RFC PATCH v3 2/2 net/route: Add netlink based route change gw/dest tests
Hi Alexey,
thanks for your review!
Quoted 1 line
Quoted 1 line
testcases/network/stress/route/route-change-gw.sh +0
-0
...
Quoted 5 lines
Quoted 5 lines
setup()
{testcases/network/stress/route/route-change-gw.sh +0
-2tst_res TINFO "change IPv$TST_IPVER route gateway $NS_TIMES times" - - rt="$(tst_ipaddr_un -p 0 0)"
Quoted 8 lines
testcases/network/stress/route/route-change-gw.sh line 19
Quoted 6 lines
testcases/network/stress/route/route-change-gw.sh +1
-4- lhost="$(tst_ipaddr_un 1 1)" - rhost="$(tst_ipaddr_un 0 1)" - tst_add_ipaddr -s -q -a $lhost - tst_add_ipaddr -s -q -a $rhost rhost + setup_gw }TST_SETUP=setup_gw
OK, I hesitated, whethertst_res TINFO "change IPv$TST_IPVER route gateway $NS_TIMES times" should be part of setup_gw() or not in the end I accidentally left it on both places. OK, I'll keep it in setup_gw() and remove from route-change-netlink-gw.sh + use TST_SETUP=setup_gw here (in route-change-gw.sh).
Quoted 1 line
Quoted 1 line
testcases/network/stress/route/route-lib.sh +0
-0
...
Quoted 9 lines
testcases/network/stress/route/route-lib.sh TST_NEEDS_ROOT=1 · line 41
Quoted 7 lines
testcases/network/stress/route/route-lib.sh +7
-0+test_netlink() +{ + local ip_flag + [ "$TST_IPV6" ] && ip_flag="-6" + + local port=$(tst_rhost_run -s -c "tst_get_unused_port ipv${TST_IPVER} dgram") +What will be listen on this remote port?
Nothing. We've talked about it in the past. I struggled to setup remote workers (problems to detect that the setup is up before testing starts), but I can rethink it again. What do you suggest: one daemon which would run several threads (each of them bind to specific IP) or several single thread instances? IMHO not binding to specific IP does not garant traffic is taking path we want.
Quoted 3 lines
testcases/network/stress/route/route-lib.sh TST_NEEDS_ROOT=1 · line 42
Quoted 1 line
testcases/network/stress/route/route-lib.sh +1
-0+ EXPECT_PASS route-change-netlink -c $NS_TIMES -d $(tst_iface) $ip_flag -p $port $ROUTE_CHANGE_NETLINK_PARAMS
EXPECT_PASSdoesn't handle TCONF when libmnl-devel is missing.
Thanks, I'll fix it.
tst_test.c:865: CONF: libmnl library and headers are required
route-change-netlink-gw 1 TFAIL: route-change-netlink -c 10 -d ltp_ns_veth2 -p 40645 -g 10.23.1.7^10.23.1.6^10.23.1.5^10.23.1.4^10.23.1.3^ -l 10.23.1.1 -r 10.23.0.1 failed unexpectedly
I propose to handle this in EXPECT_PASS() (send a separate RFC patch for it).
Kind regards,
Petr
RFC PATCH v3 2/2 net/route: Add netlink based route change gw/dest tests
Quoted 38 lines · Petr Vorel
Hi Alexey,
thanks for your review!
Quoted 1 line
Quoted 1 line
testcases/network/stress/route/route-change-gw.sh +0
-0...
Quoted 5 lines
Quoted 5 lines
setup()
{testcases/network/stress/route/route-change-gw.sh +0
-2tst_res TINFO "change IPv$TST_IPVER route gateway $NS_TIMES times" - - rt="$(tst_ipaddr_un -p 0 0)"Quoted 8 lines
testcases/network/stress/route/route-change-gw.sh line 19
Quoted 6 lines
testcases/network/stress/route/route-change-gw.sh +1
-4- lhost="$(tst_ipaddr_un 1 1)" - rhost="$(tst_ipaddr_un 0 1)" - tst_add_ipaddr -s -q -a $lhost - tst_add_ipaddr -s -q -a $rhost rhost + setup_gw }TST_SETUP=setup_gw
OK, I hesitated, whether
tst_resTINFO "change IPv$TST_IPVER route gateway $NS_TIMES times" should be part ofsetup_gw()or not in the end I accidentally left it on both places. OK, I'll keep it insetup_gw()and remove fromroute-change-netlink-gw.sh+ use TST_SETUP=setup_gw here (inroute-change-gw.sh).Quoted 1 line
Quoted 1 line
testcases/network/stress/route/route-lib.sh +0
-0...
Quoted 9 lines
testcases/network/stress/route/route-lib.sh TST_NEEDS_ROOT=1 · line 41
Quoted 7 lines
testcases/network/stress/route/route-lib.sh +7
-0+test_netlink() +{ + local ip_flag + [ "$TST_IPV6" ] && ip_flag="-6" + + local port=$(tst_rhost_run -s -c "tst_get_unused_port ipv${TST_IPVER} dgram") +What will be listen on this remote port?
Quoted 5 lines
Nothing. We've talked about it in the past. I struggled to setup remote workers (problems to detect that the setup is up before testing starts), but I can rethink it again. What do you suggest: one daemon which would run several threads (each of them bind to specific IP) or several single thread instances? IMHO not binding to specific IP does not garant traffic is taking path we want.
Hi Petr,
Then, for now we can pass arbitrary port, no need for tst_get_unused_port(), e.g. 65535.
Quoted 11 lines
Quoted 4 lines
testcases/network/stress/route/route-lib.sh TST_NEEDS_ROOT=1 · line 42
Quoted 2 lines
testcases/network/stress/route/route-lib.sh +1
-0+ EXPECT_PASS route-change-netlink -c $NS_TIMES -d $(tst_iface) $ip_flag -p $port $ROUTE_CHANGE_NETLINK_PARAMS
EXPECT_PASSdoesn't handle TCONF when libmnl-devel is missing.Thanks, I'll fix it.
tst_test.c:865: CONF: libmnl library and headers are required
route-change-netlink-gw 1 TFAIL: route-change-netlink -c 10 -dltp_ns_veth2-p 40645 -g 10.23.1.7^10.23.1.6^10.23.1.5^10.23.1.4^10.23.1.3^ -l 10.23.1.1 -r 10.23.0.1 failed unexpectedlyI propose to handle this in
EXPECT_PASS()(send a separate RFC patch for it).
Not sure if it would work for non-ltp binaries...
Quoted 4 lines
Kind regards,
Petr
RFC PATCH v3 2/2 net/route: Add netlink based route change gw/dest tests
Hi Alexey,
Quoted 2 lines
Then, for now we can pass arbitrary port, no need for
tst_get_unused_port(), e.g. 65535.
Right, it really does not matter to check that port.
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
testcases/network/stress/route/route-lib.sh TST_NEEDS_ROOT=1 · line 42
Quoted 1 line
testcases/network/stress/route/route-lib.sh +1
-0+ EXPECT_PASS route-change-netlink -c $NS_TIMES -d $(tst_iface) $ip_flag -p $port $ROUTE_CHANGE_NETLINK_PARAMS
EXPECT_PASSdoesn't handle TCONF when libmnl-devel is missing.
Quoted 8 lines
Quoted 6 lines
Thanks, I'll fix it.
tst_test.c:865: CONF: libmnl library and headers are required
route-change-netlink-gw 1 TFAIL: route-change-netlink -c 10 -dltp_ns_veth2-p 40645 -g 10.23.1.7^10.23.1.6^10.23.1.5^10.23.1.4^10.23.1.3^ -l 10.23.1.1 -r 10.23.0.1 failed unexpectedlyI propose to handle this in
EXPECT_PASS()(send a separate RFC patch for it).Not sure if it would work for non-ltp binaries...
True. Do you think there would be more usage for something like EXPECT_PASS_LTP(), where I'd handle 32 as TCONF, 3 as TFAIL, 4 as TWARN? I can handle it just in the test.
BTW there is this error handling already in tst_netload() for netstress.c, so there could be function which returns $res according to exit code and EXPECT_PASS_LTP() which uses it.
Kind regards,
Petr