net/route: rewrite route-change-{dst, gw, if} into new API
v3 cover net/route: rewrite route-change-{dst, gw, if} into new API
Hi,
hope this version could be sufficient enough.
I've added some support to tst_net.sh for general IP address handling.
I'm thinking about adding support for adding general vlan support totst_net.sh instead of using add_macvlan() (virt_lib.sh, ipsec_lib.sh and dhcp_lib.sh would use it), but that would be in separate patchset.
Kind regards,
Petr
Petr Vorel (5):
tst_net.sh: enhance tst_add_ipaddr(), add tst_del_ipaddr() tst_net.sh: Add -m option to return mask in tst_ipaddr_un() network/route: Rewrite route-change-dst into new API network/route: Rewrite route-change-gw into new API network/route: Rewrite route-change-if into new API
runtest/net_stress.route | 12 +- testcases/lib/tst_net.sh | 81 +++-- .../network/stress/route/00_Descriptions.txt | 54 +-- .../network/stress/route/route-change-dst | 33 ++ .../network/stress/route/route-change-gw | 38 ++ .../network/stress/route/route-change-if | 87 +++++ testcases/network/stress/route/route-lib.sh | 17 + .../network/stress/route/route4-change-dst | 276 --------------- .../network/stress/route/route4-change-gw | 292 ---------------- .../network/stress/route/route4-change-if | 324 ------------------ .../network/stress/route/route6-change-dst | 272 --------------- .../network/stress/route/route6-change-gw | 292 ---------------- .../network/stress/route/route6-change-if | 323 ----------------- 13 files changed, 249 insertions(+), 1852 deletions(-) create mode 100755 testcases/network/stress/route/route-change-dst create mode 100755 testcases/network/stress/route/route-change-gw create mode 100755 testcases/network/stress/route/route-change-if create mode 100644 testcases/network/stress/route/route-lib.sh delete mode 100644 testcases/network/stress/route/route4-change-dst delete mode 100644 testcases/network/stress/route/route4-change-gw delete mode 100644 testcases/network/stress/route/route4-change-if delete mode 100644 testcases/network/stress/route/route6-change-dst delete mode 100644 testcases/network/stress/route/route6-change-gw delete mode 100644 testcases/network/stress/route/route6-change-if
Signature · 1 line
2.22.0
PATCH v3 1/5 tst_net.sh: enhance tst_add_ipaddr(), add tst_del_ipaddr()
These changes are intended for easier handling with IP addresses (not have to calculate dad for IPv6 when adding IP address). Add -a IP and -s options to tst_add_ipaddr()
tst_del_ipaddr() (which uses internally tst_add_ipaddr()) is defined mainly for better code readability.
--- testcases/lib/tst_net.sh | 48 +++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 11 deletions(-)
testcases/lib/tst_net.sh +37 -11
@@ -1,7 +1,7 @@ #!/bin/sh # SPDX-License-Identifier: GPL-2.0-or-later # Copyright (c) 2014-2017 Oracle and/or its affiliates. All Rights Reserved. -# Copyright (c) 2016-2018 Petr Vorel <[email protected]> +# Copyright (c) 2016-2019 Petr Vorel <[email protected]> # Author: Alexey Kodanev <[email protected]> [ -n "$TST_LIB_NET_LOADED" ] && return 0
@@ -443,14 +443,33 @@ tst_init_iface() tst_rhost_run -c "ip link set $iface up" } -# tst_add_ipaddr [TYPE] [LINK] -# TYPE: { lhost | rhost }; Default value is 'lhost'. -# LINK: link number starting from 0. Default value is '0'. +# tst_add_ipaddr [TYPE] [LINK] [-a IP] [-d] [-s] +# Options: +# TYPE: { lhost | rhost }, default value is 'lhost' +# LINK: link number starting from 0, default value is '0' +# -a IP: IP address to be added, default value is +# $(tst_ipaddr)/$IPV{4,6}_{L,R}PREFIX +# -d: delete address instead of adding +# -s: safe option, if something goes wrong, will exit with TBROK tst_add_ipaddr() { + local action="add" + local addr dad lsafe mask rsafe + + local OPTIND + while getopts a:ds opt; do + case "$opt" in + a) addr="$OPTARG" ;; + d) action="del" ;; + s) lsafe="ROD"; rsafe="-s" ;; + *) tst_brk TBROK "tst_add_ipaddr: unknown option: $OPTARG" ;; + esac + done + shift $((OPTIND - 1)) + local type="${1:-lhost}" local link_num="${2:-0}" - local mask dad + local iface=$(tst_iface $type $link_num) if [ "$TST_IPV6" ]; then dad="nodad"
@@ -458,17 +477,24 @@ tst_add_ipaddr() else [ "$type" = "lhost" ] && mask=$IPV4_LPREFIX || mask=$IPV4_RPREFIX fi - - local iface=$(tst_iface $type $link_num) + [ -n "$addr" ] || addr="$(tst_ipaddr $type)" + echo $addr | grep -q / || addr="$addr/$mask" if [ $type = "lhost" ]; then - tst_res_ TINFO "set local addr $(tst_ipaddr)/$mask" - ip addr add $(tst_ipaddr)/$mask dev $iface $dad + tst_res_ TINFO "set local addr $addr" + $lsafe ip addr $action $addr dev $iface $dad return $? fi - tst_res_ TINFO "set remote addr $(tst_ipaddr rhost)/$mask" - tst_rhost_run -c "ip addr add $(tst_ipaddr rhost)/$mask dev $iface $dad" + tst_res_ TINFO "set remote addr $addr" + tst_rhost_run $rsafe -c "ip addr $action $addr dev $iface $dad" +} + +# tst_del_ipaddr [ tst_add_ipaddr options ] +# Delete IP address +tst_del_ipaddr() +{ + tst_add_ipaddr -d $@ } # tst_restore_ipaddr [TYPE] [LINK]
Signature · 1 line
2.22.0
PATCH v3 2/5 tst_net.sh: Add -m option to return mask in tst_ipaddr_un()
In reply to Petr Vorel+ reformat docs a bit
--- testcases/lib/tst_net.sh | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
testcases/lib/tst_net.sh +14 -11
@@ -353,22 +353,25 @@ tst_ipaddr() # Get IP address of unused network, specified either by type and counter # or by net and host. -# tst_ipaddr_un [-cCOUNTER] [TYPE] +# tst_ipaddr_un [-cCOUNTER] [-m] [TYPE] # tst_ipaddr_un NET_ID [HOST_ID] -# TYPE: { lhost | rhost }; Default value is 'lhost'. -# COUNTER: Integer value for counting HOST_ID and NET_ID. Default is 1. -# NET_ID: Integer or hex value of net. For IPv4 is 3rd octet, for IPv6 -# is 3rd hextet. -# HOST_ID: Integer or hex value of host. For IPv4 is 4th octet, for -# IPv6 is the last hextet. Default value is 0. +# +# OPTIONS +# -c COUNTER: integer value for counting HOST_ID and NET_ID (default: 1) +# -m: print also mask +# TYPE: { lhost | rhost } (default: 'lhost') +# NET_ID: integer or hex value of net (IPv4: 3rd octet, IPv6: 3rd hextet) +# HOST_ID: integer or hex value of host (IPv4: 4th octet, IPv6: the last +# hextet, default: 0) tst_ipaddr_un() { - local counter host_id net_id max_host_id max_net_id tmp type + local counter host_id mask max_host_id max_net_id net_id tmp type local OPTIND - while getopts "c:" opt; do + while getopts "c:m" opt; do case $opt in c) counter="$OPTARG";; + m) [ "$TST_IPV6" ] && mask="/64" || mask="/24";; esac done shift $(($OPTIND - 1))
@@ -405,14 +408,14 @@ tst_ipaddr_un() host_id=$((host_id % max_net_id)) if [ -z "$TST_IPV6" ]; then - echo "${IPV4_NET16_UNUSED}.${net_id}.${host_id}" + echo "${IPV4_NET16_UNUSED}.${net_id}.${host_id}${mask}" return fi [ $host_id -gt 0 ] && host_id="$(printf %x $host_id)" || host_id= [ $net_id -gt 0 ] && net_id="$(printf %x $net_id)" || net_id= [ "$net_id" ] && net_id=":$net_id" - echo "${IPV6_NET32_UNUSED}${net_id}::${host_id}" + echo "${IPV6_NET32_UNUSED}${net_id}::${host_id}${mask}" } # tst_init_iface [TYPE] [LINK]
Signature · 1 line
2.22.0
PATCH v3 3/5 network/route: Rewrite route-change-dst into new API
In reply to Petr Vorel* Drop route command (use just ip command), support both IPv4 and IPv6
* Add route-lib.sh (will be used in other route-change-*)
* Use unused network range to avoid clash with real network
* Add verification with ping (previous version sent UDP datagram with ns-udpsender, but didn't verify receiving it on rhost and didn't setup rhost ip at all)
--- runtest/net_stress.route | 4 +- .../network/stress/route/00_Descriptions.txt | 18 +- .../network/stress/route/route-change-dst | 33 +++ testcases/network/stress/route/route-lib.sh | 17 ++ .../network/stress/route/route4-change-dst | 276 ------------------ .../network/stress/route/route6-change-dst | 272 ----------------- 6 files changed, 55 insertions(+), 565 deletions(-) create mode 100755 testcases/network/stress/route/route-change-dst create mode 100644 testcases/network/stress/route/route-lib.sh delete mode 100644 testcases/network/stress/route/route4-change-dst delete mode 100644 testcases/network/stress/route/route6-change-dst
runtest/net_stress.route +2 -2
@@ -2,13 +2,13 @@ # Stress test for routing table # -route4-change-dst route4-change-dst +route4-change-dst route-change-dst route4-change-gw route4-change-gw route4-change-if route4-change-if route4-redirect route4-redirect route4-rmmod route4-rmmod -route6-change-dst route6-change-dst +route6-change-dst route-change-dst -6 route6-change-gw route6-change-gw route6-change-if route6-change-if route6-redirect route6-redirect
testcases/network/stress/route/00_Descriptions.txt +3 -15
@@ -1,10 +1,6 @@ -route4-change-dst01 - Verify the kernel is not crashed when the destination of an IPv4 route - is changed frequently by route command - -route4-change-dst02 - Verify the kernel is not crashed when the destination of an IPv4 route - is changed frequently by ip command +route-change-dst + Verify the IPv4/IPv6 is not broken when ip command changes route + destination many times route4-change-gw01 Verify the kernel is not crashed when the gateway of an IPv4 route is
@@ -35,14 +31,6 @@ route4-rmmod02 then it is deleted by the removing network driver -route6-change-dst01 - Verify the kernel is not crashed when the destination of an IPv6 route - is changed frequently by route command - -route6-change-dst02 - Verify the kernel is not crashed when the destination of an IPv6 route - is changed frequently by ip command - route6-change-gw01 Verify the kernel is not crashed when the gateway of an IPv6 route is changed frequently by route command
testcases/network/stress/route/route-change-dst new file +33 -0
@@ -0,0 +1,33 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2019 Petr Vorel <[email protected]> +# Copyright (c) International Business Machines Corp., 2006 +# Author: Mitsuru Chinen <[email protected]> + +# Change route destination +# lhost: 10.0.0.2, rhost: 10.23.x.1 + +TST_TESTFUNC="test_dst" +. route-lib.sh + +setup() +{ + tst_res TINFO "change IPv$TST_IPVER route destination $NS_TIMES times" +} + +test_dst() +{ + local iface="$(tst_iface)" + local rt="$(tst_ipaddr_un -m $1)" + local rhost="$(tst_ipaddr_un $1 1)" + + tst_res TINFO "testing route '$rt'" + + tst_add_ipaddr -s -a $rhost rhost + ROD ip route add $rt dev $iface + EXPECT_PASS ping$TST_IPV6 -c1 -I $(tst_ipaddr) $rhost + ROD ip route del $rt dev $iface + tst_del_ipaddr -s -a $rhost rhost +} + +tst_run
testcases/network/stress/route/route-lib.sh new file +17 -0
@@ -0,0 +1,17 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2019 Petr Vorel <[email protected]> + +TST_NEEDS_ROOT=1 +TST_SETUP="setup" +TST_CLEANUP="route_cleanup" +TST_NEEDS_CMDS="ip" +TST_CNT=$NS_TIMES + +. tst_net.sh + +route_cleanup() +{ + tst_restore_ipaddr + tst_restore_ipaddr rhost +}
testcases/network/stress/route/route4-change-dst deleted +0 -276
276 lines not on this page · raw message
testcases/network/stress/route/route6-change-dst deleted +0 -272
272 lines not on this page · raw message
Signature · 1 line
2.22.0
PATCH v3 3/5 network/route: Rewrite route-change-dst into new API
Hi,
Quoted 9 lines
* Drop route command (use just ip command), support both IPv4 and IPv6
* Addroute-lib.sh(will be used in other route-change-*)
* Use unused network range to avoid clash with real network
* Add verification with ping (previous version sent UDP datagram with ns-udpsender, but didn't verify receiving it on rhost and didn't setup rhost ip at all)Suggested-by Alexey Kodanev <[email protected]>Signed-off-by Petr Vorel <[email protected]>
Quoted 9 lines
--- runtest/net_stress.route | 4 +- .../network/stress/route/00_Descriptions.txt | 18 +- .../network/stress/route/route-change-dst | 33 +++ testcases/network/stress/route/route-lib.sh | 17 ++ .../network/stress/route/route4-change-dst | 276 ------------------ .../network/stress/route/route6-change-dst | 272 ----------------- 6 files changed, 55 insertions(+), 565 deletions(-) create mode 100755 testcases/network/stress/route/route-change-dst
Just a small change, not worth of sending v2: use .sh extension for all 3 tests (route-change-{dst,gw,if}.sh).
Kind regards,
Petr
PATCH v3 4/5 network/route: Rewrite route-change-gw into new API
In reply to Petr Vorel* Drop route command (use just ip command), support both IPv4 and IPv6
* Use unused network range to avoid clash with real network
* Add verification with ping (previous version sent UDP datagram with ns-udpsender, but didn't verify receiving it on rhost and didn't setup rhost ip at all)
--- runtest/net_stress.route | 4 +- .../network/stress/route/00_Descriptions.txt | 18 +- .../network/stress/route/route-change-gw | 38 +++ .../network/stress/route/route4-change-gw | 292 ------------------ .../network/stress/route/route6-change-gw | 292 ------------------ 5 files changed, 43 insertions(+), 601 deletions(-) create mode 100755 testcases/network/stress/route/route-change-gw delete mode 100644 testcases/network/stress/route/route4-change-gw delete mode 100644 testcases/network/stress/route/route6-change-gw
runtest/net_stress.route +2 -2
@@ -3,13 +3,13 @@ # route4-change-dst route-change-dst -route4-change-gw route4-change-gw +route4-change-gw route-change-gw route4-change-if route4-change-if route4-redirect route4-redirect route4-rmmod route4-rmmod route6-change-dst route-change-dst -6 -route6-change-gw route6-change-gw +route6-change-gw route-change-gw -6 route6-change-if route6-change-if route6-redirect route6-redirect route6-rmmod route6-rmmod
testcases/network/stress/route/00_Descriptions.txt +3 -15
@@ -2,13 +2,9 @@ route-change-dst Verify the IPv4/IPv6 is not broken when ip command changes route destination many times -route4-change-gw01 - Verify the kernel is not crashed when the gateway of an IPv4 route is - changed frequently by route command - -route4-change-gw02 - Verify the kernel is not crashed when the gateway of an IPv4 route is - changed frequently by ip command +route-change-gw + Verify the IPv4/IPv6 is not broken when ip command changes route + gateway many times route4-change-if01 Verify the kernel is not crashed when the interface of an IPv4 route is
@@ -31,14 +27,6 @@ route4-rmmod02 then it is deleted by the removing network driver -route6-change-gw01 - Verify the kernel is not crashed when the gateway of an IPv6 route is - changed frequently by route command - -route6-change-gw02 - Verify the kernel is not crashed when the gateway of an IPv6 route is - changed frequently by ip command - route6-change-if01 Verify the kernel is not crashed when the interface of an IPv6 route is changed frequently by route command
testcases/network/stress/route/route-change-gw new file +38 -0
@@ -0,0 +1,38 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2019 Petr Vorel <[email protected]> +# Copyright (c) International Business Machines Corp., 2006 +# Author: Mitsuru Chinen <[email protected]> + +# Change route gateway +# lhost: 10.23.x.2, gw (on rhost): 10.23.x.1, rhost: 10.23.0.1 + +TST_TESTFUNC="test_gw" +. route-lib.sh + +setup() +{ + tst_res TINFO "change IPv$TST_IPVER route gateway $NS_TIMES times" + + rt="$(tst_ipaddr_un -m 0 0)" + lhost="$(tst_ipaddr_un 1 1)" + rhost="$(tst_ipaddr_un 0 1)" + tst_add_ipaddr -s -a $lhost + tst_add_ipaddr -s -a $rhost rhost +} + +test_gw() +{ + local gw="$(tst_ipaddr_un 1 $(($1 + 1)))" + local iface="$(tst_iface)" + + tst_res TINFO "testing route over gateway '$gw'" + + tst_add_ipaddr -s -a $gw rhost + ROD ip route replace $rt dev $iface via $gw + EXPECT_PASS ping$TST_IPV6 -c1 -I $lhost $rhost + ROD ip route del $rt dev $iface via $gw + tst_del_ipaddr -s -a $gw rhost +} + +tst_run
testcases/network/stress/route/route4-change-gw deleted +0 -292
292 lines not on this page · raw message
testcases/network/stress/route/route6-change-gw deleted +0 -292
292 lines not on this page · raw message
Signature · 1 line
2.22.0
PATCH v3 4/5 network/route: Rewrite route-change-gw into new API
Hi Petr,
Quoted 30 lines · Petr Vorel
* Drop route command (use just ip command), support both IPv4 and IPv6
* Use unused network range to avoid clash with real network
* Add verification with ping (previous version sent UDP datagram with ns-udpsender, but didn't verify receiving it on rhost and didn't setup rhost ip at all)Signed-off-by Petr Vorel <[email protected]>--- runtest/net_stress.route | 4 +- .../network/stress/route/00_Descriptions.txt | 18 +- .../network/stress/route/route-change-gw | 38 +++ .../network/stress/route/route4-change-gw | 292 ------------------ .../network/stress/route/route6-change-gw | 292 ------------------ 5 files changed, 43 insertions(+), 601 deletions(-) create mode 100755 testcases/network/stress/route/route-change-gw delete mode 100644 testcases/network/stress/route/route4-change-gw delete mode 100644 testcases/network/stress/route/route6-change-gw...
testcases/network/stress/route/route-change-gw new file +11
-0+ +# Change route gateway +# lhost: 10.23.x.2, gw (on rhost): 10.23.x.1, rhost: 10.23.0.1 + +TST_TESTFUNC="test_gw" +. route-lib.sh + +setup() +{ + tst_res TINFO "change IPv$TST_IPVER route gateway $NS_TIMES times" +
testcases/network/stress/route/route-change-gw line 26
Quoted 10 lines
testcases/network/stress/route/route-change-gw new file +10
-0+ rt="$(tst_ipaddr_un -m 0 0)" + lhost="$(tst_ipaddr_un 1 1)" + rhost="$(tst_ipaddr_un 0 1)" + tst_add_ipaddr -s -a $lhost + tst_add_ipaddr -s -a $rhost rhost +} + +test_gw() +{ + local gw="$(tst_ipaddr_un 1 $(($1 + 1)))"
We should keep $(($1 + 1)) within the valid range except already added IP address ($lhost), i.e. for IPv4 the range is 2..254 for host id:
local gw="$(tst_ipaddr_un 1 $(($1 % 253 + 2)))"
Either we could limit the value here or in the tst_ipaddr_un(). Looks like route-change-if needs a similar fix for net id?
testcases/network/stress/route/route-change-gw line 32
Quoted 6 lines
testcases/network/stress/route/route-change-gw new file +6
-0+ local iface="$(tst_iface)" + + tst_res TINFO "testing route over gateway '$gw'" + + tst_add_ipaddr -s -a $gw rhost + ROD ip route replace $rt dev $iface via $gw
May be it would be cleaner to use "add" instead of "replace" since we remove it and it shouldn't exist before a test start.
testcases/network/stress/route/route-change-gw line 33
Quoted 1 line
testcases/network/stress/route/route-change-gw new file +1
-0+ EXPECT_PASS ping$TST_IPV6 -c1 -I $lhost $rhost
It is better to redirect stdout to null:
EXPECT_PASS ping$TST_IPV6 -c1 -I $lhost $rhost \>/dev/null
The same for *-if and *-dst.
The rest in the patch-set looks good to me.
Quoted 5 lines
testcases/network/stress/route/route-change-gw new file +5
-0+ ROD ip route del $rt dev $iface via $gw + tst_del_ipaddr -s -a $gw rhost +} + +tst_run
PATCH v3 4/5 network/route: Rewrite route-change-gw into new API
Hi Alexey,
Quoted 46 lines
Hi Petr,
Quoted 30 lines · Petr Vorel
* Drop route command (use just ip command), support both IPv4 and IPv6
* Use unused network range to avoid clash with real network
* Add verification with ping (previous version sent UDP datagram with ns-udpsender, but didn't verify receiving it on rhost and didn't setup rhost ip at all)Signed-off-by Petr Vorel <[email protected]>--- runtest/net_stress.route | 4 +- .../network/stress/route/00_Descriptions.txt | 18 +- .../network/stress/route/route-change-gw | 38 +++ .../network/stress/route/route4-change-gw | 292 ------------------ .../network/stress/route/route6-change-gw | 292 ------------------ 5 files changed, 43 insertions(+), 601 deletions(-) create mode 100755 testcases/network/stress/route/route-change-gw delete mode 100644 testcases/network/stress/route/route4-change-gw delete mode 100644 testcases/network/stress/route/route6-change-gw...
(quoted diff) +11
-0+ +# Change route gateway +# lhost: 10.23.x.2, gw (on rhost): 10.23.x.1, rhost: 10.23.0.1 + +TST_TESTFUNC="test_gw" +. route-lib.sh + +setup() +{ + tst_res TINFO "change IPv$TST_IPVER route gateway $NS_TIMES times" +Review
Quoted 10 lines
(quoted diff) +10
-0+ rt="$(tst_ipaddr_un -m 0 0)" + lhost="$(tst_ipaddr_un 1 1)" + rhost="$(tst_ipaddr_un 0 1)" + tst_add_ipaddr -s -a $lhost + tst_add_ipaddr -s -a $rhost rhost +} + +test_gw() +{ + local gw="$(tst_ipaddr_un 1 $(($1 + 1)))"We should keep $(($1 + 1)) within the valid range except already added IP address ($lhost), i.e. for IPv4 the range is 2..254 for host id:
Quoted 4 lines
local gw="$(tst_ipaddr_un 1 $(($1 % 253 + 2)))"Either we could limit the value here or in the
tst_ipaddr_un(). Looks like route-change-if needs a similar fix for net id?
Good point (sorry to keep octet/hextet overflow related errors). Although it'd be simpler to fix it in the code, I'd prefer to have this support in tst_ipaddr_un(). Diff below adds -l MIN_HOST_ID (I'll post it as a part of v3), do we want to lower also max host id?
Quoted 10 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ local iface="$(tst_iface)" + + tst_res TINFO "testing route over gateway '$gw'" + + tst_add_ipaddr -s -a $gw rhost + ROD ip route replace $rt dev $iface via $gwMay be it would be cleaner to use "add" instead of "replace" since we remove it and it shouldn't exist before a test start.
Quoted 7 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ EXPECT_PASS ping$TST_IPV6 -c1 -I $lhost $rhostIt is better to redirect stdout to null:
EXPECT_PASSping$TST_IPV6 -c1 -I $lhost $rhost \>/dev/nullThe same for *-if and *-dst.
Agree with all you pointed out.
Quoted 1 line
The rest in the patch-set looks good to me.
Kind regards,
Petr
commit 3a3ed9bc93c18d899a81b0f592eec4d4402984b1
Author: Petr Vorel <[email protected]> Date: 2019-08-06 16:58:28 +0200
net/tst_ipaddr_un: Add -l MIN_HOST_ID support
lib/tst_net.sh +23 -8
@@ -361,11 +361,13 @@ tst_ipaddr() # Get IP address of unused network, specified either by type and counter # or by net and host. -# tst_ipaddr_un [-cCOUNTER] [-m] [TYPE] -# tst_ipaddr_un [-m] NET_ID [HOST_ID] +# tst_ipaddr_un [-c COUNTER] [-l MIN_HOST_ID] [-m] [TYPE] +# tst_ipaddr_un [-l MIN_HOST_ID] [-m] NET_ID [HOST_ID] # # OPTIONS # -c COUNTER: integer value for counting HOST_ID and NET_ID (default: 1) +# -l MIN_HOST_ID: min HOST_ID allowed minimal HOST_ID (useful for loop which +# overflow max HOST_ID) # -m: print also mask # TYPE: { lhost | rhost } (default: 'lhost') # NET_ID: integer or hex value of net (IPv4: 3rd octet, IPv6: 3rd hextet)
@@ -373,30 +375,39 @@ tst_ipaddr() # hextet, default: 0) tst_ipaddr_un() { - local counter host_id lower mask max_host_id max_net_id net_id tmp type + local counter host_id mask max_host_id max_net_id min_host_id net_id tmp type local OPTIND - while getopts "c:m" opt; do + [ "$TST_IPV6" ] && max_net_id=65535 || max_net_id=255 + max_host_id=$((max_net_id - 1)) + + while getopts "c:l:m" opt; do case $opt in c) counter="$OPTARG";; - l) lower="$OPTARG";; + l) + min_host_id="$OPTARG" + if ! tst_is_int "$min_host_id"; then + tst_brk TBROK "tst_ipaddr_un: -l must be integer ($min_host_id)" + fi + if [ $min_host_id -ge $max_host_id ]; then + tst_brk TBROK "tst_ipaddr_un: -l must be >= $max_host_id ($min_host_id)" + fi + ;; m) [ "$TST_IPV6" ] && mask="/64" || mask="/24";; esac done shift $(($OPTIND - 1)) - [ "$TST_IPV6" ] && max_net_id=65535 || max_net_id=255 - # counter if [ $# -eq 0 -o "$1" = "lhost" -o "$1" = "rhost" ]; then [ -z "$counter" ] && counter=1 [ $counter -lt 1 ] && counter=1 type="${1:-lhost}" - max_host_id=$((max_net_id - 1)) tmp=$((counter * 2)) [ "$type" = "rhost" ] && tmp=$((tmp - 1)) host_id=$((tmp % max_host_id)) + net_id=$((tmp / max_host_id)) if [ $host_id -eq 0 ]; then
@@ -415,7 +426,11 @@ tst_ipaddr_un() fi net_id=$((net_id % max_net_id)) + if [ "$min_host_id" ]; then + host_id=$(( host_id % (max_host_id - min_host_id + 1) + min_host_id )) + else host_id=$((host_id % max_net_id)) + fi if [ -z "$TST_IPV6" ]; then echo "${IPV4_NET16_UNUSED}.${net_id}.${host_id}${mask}"
PATCH v3 4/5 network/route: Rewrite route-change-gw into new API
Hi Petr,
Quoted 48 lines · Petr Vorel
Hi Alexey,
Quoted 45 lines
Hi Petr,
Quoted 30 lines · Petr Vorel
* Drop route command (use just ip command), support both IPv4 and IPv6
* Use unused network range to avoid clash with real network
* Add verification with ping (previous version sent UDP datagram with ns-udpsender, but didn't verify receiving it on rhost and didn't setup rhost ip at all)Signed-off-by Petr Vorel <[email protected]>--- runtest/net_stress.route | 4 +- .../network/stress/route/00_Descriptions.txt | 18 +- .../network/stress/route/route-change-gw | 38 +++ .../network/stress/route/route4-change-gw | 292 ------------------ .../network/stress/route/route6-change-gw | 292 ------------------ 5 files changed, 43 insertions(+), 601 deletions(-) create mode 100755 testcases/network/stress/route/route-change-gw delete mode 100644 testcases/network/stress/route/route4-change-gw delete mode 100644 testcases/network/stress/route/route6-change-gw...
(quoted diff) +11
-0+ +# Change route gateway +# lhost: 10.23.x.2, gw (on rhost): 10.23.x.1, rhost: 10.23.0.1 + +TST_TESTFUNC="test_gw" +. route-lib.sh + +setup() +{ + tst_res TINFO "change IPv$TST_IPVER route gateway $NS_TIMES times" +Review
Quoted 10 lines
(quoted diff) +10
-0+ rt="$(tst_ipaddr_un -m 0 0)" + lhost="$(tst_ipaddr_un 1 1)" + rhost="$(tst_ipaddr_un 0 1)" + tst_add_ipaddr -s -a $lhost + tst_add_ipaddr -s -a $rhost rhost +} + +test_gw() +{ + local gw="$(tst_ipaddr_un 1 $(($1 + 1)))"We should keep $(($1 + 1)) within the valid range except already added IP address ($lhost), i.e. for IPv4 the range is 2..254 for host id:
Quoted 8 lines
Quoted 4 lines
local gw="$(tst_ipaddr_un 1 $(($1 % 253 + 2)))"Either we could limit the value here or in the
tst_ipaddr_un(). Looks like route-change-if needs a similar fix for net id?Good point (sorry to keep octet/hextet overflow related errors). Although it'd be simpler to fix it in the code, I'd prefer to have this support in
tst_ipaddr_un(). Diff below adds -lMIN_HOST_ID(I'll post it as a part of v3), do we want to lower also max host id?
It can only be "max host id" option since we already have this variable in the function, and in the test setup, we could assign "lhost" variable with the max value:
lhost="$(tst_ipaddr_un 1 $max_host_id)"
Quoted 115 lines
Quoted 12 lines
Review
Quoted 8 lines
(quoted diff) +6
-0+ local iface="$(tst_iface)" + + tst_res TINFO "testing route over gateway '$gw'" + + tst_add_ipaddr -s -a $gw rhost + ROD ip route replace $rt dev $iface via $gwMay be it would be cleaner to use "add" instead of "replace" since we remove it and it shouldn't exist before a test start.
Quoted 7 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ EXPECT_PASS ping$TST_IPV6 -c1 -I $lhost $rhostIt is better to redirect stdout to null:
EXPECT_PASSping$TST_IPV6 -c1 -I $lhost $rhost \>/dev/nullThe same for *-if and *-dst.
Agree with all you pointed out.
Quoted 1 line
The rest in the patch-set looks good to me.
Kind regards,
Petrcommit
3a3ed9bc93c18d899a81b0f592eec4d4402984b1Author: Petr Vorel <[email protected]> Date: 2019-08-06 16:58:28 +0200
net/tst_ipaddr_un: Add -lMIN_HOST_IDsupportSigned-off-by Petr Vorel <[email protected]>lib/tst_net.sh +23
-8@@ -361,11 +361,13 @@ tst_ipaddr() # Get IP address of unused network, specified either by type and counter # or by net and host. -# tst_ipaddr_un [-cCOUNTER] [-m] [TYPE] -# tst_ipaddr_un [-m] NET_ID [HOST_ID] +# tst_ipaddr_un [-c COUNTER] [-l MIN_HOST_ID] [-m] [TYPE] +# tst_ipaddr_un [-l MIN_HOST_ID] [-m] NET_ID [HOST_ID] # # OPTIONS # -c COUNTER: integer value for counting HOST_ID and NET_ID (default: 1) +# -l MIN_HOST_ID: min HOST_ID allowed minimal HOST_ID (useful for loop which +# overflow max HOST_ID) # -m: print also mask # TYPE: { lhost | rhost } (default: 'lhost') # NET_ID: integer or hex value of net (IPv4: 3rd octet, IPv6: 3rd hextet)@@ -373,30 +375,39 @@ tst_ipaddr() # hextet, default: 0) tst_ipaddr_un() { - local counter host_id lower mask max_host_id max_net_id net_id tmp type + local counter host_id mask max_host_id max_net_id min_host_id net_id tmp type local OPTIND - while getopts "c:m" opt; do + [ "$TST_IPV6" ] && max_net_id=65535 || max_net_id=255 + max_host_id=$((max_net_id - 1)) + + while getopts "c:l:m" opt; do case $opt in c) counter="$OPTARG";; - l) lower="$OPTARG";; + l) + min_host_id="$OPTARG" + if ! tst_is_int "$min_host_id"; then + tst_brk TBROK "tst_ipaddr_un: -l must be integer ($min_host_id)" + fi + if [ $min_host_id -ge $max_host_id ]; then + tst_brk TBROK "tst_ipaddr_un: -l must be >= $max_host_id ($min_host_id)" + fi + ;; m) [ "$TST_IPV6" ] && mask="/64" || mask="/24";; esac done shift $(($OPTIND - 1)) - [ "$TST_IPV6" ] && max_net_id=65535 || max_net_id=255 - # counter if [ $# -eq 0 -o "$1" = "lhost" -o "$1" = "rhost" ]; then [ -z "$counter" ] && counter=1 [ $counter -lt 1 ] && counter=1 type="${1:-lhost}" - max_host_id=$((max_net_id - 1)) tmp=$((counter * 2)) [ "$type" = "rhost" ] && tmp=$((tmp - 1)) host_id=$((tmp % max_host_id)) + net_id=$((tmp / max_host_id)) if [ $host_id -eq 0 ]; then@@ -415,7 +426,11 @@ tst_ipaddr_un() fi net_id=$((net_id % max_net_id)) + if [ "$min_host_id" ]; then + host_id=$(( host_id % (max_host_id - min_host_id + 1) + min_host_id )) + else host_id=$((host_id % max_net_id)) + fi if [ -z "$TST_IPV6" ]; then echo "${IPV4_NET16_UNUSED}.${net_id}.${host_id}${mask}"
PATCH v3 4/5 network/route: Rewrite route-change-gw into new API
Hi Alexey,
Quoted 14 lines
Quoted 5 lines
Quoted 4 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ local gw="$(tst_ipaddr_un 1 $(($1 + 1)))"We should keep $(($1 + 1)) within the valid range except already added IP address ($lhost), i.e. for IPv4 the range is 2..254 for host id:
Quoted 8 lines
Quoted 4 lines
local gw="$(tst_ipaddr_un 1 $(($1 % 253 + 2)))"Either we could limit the value here or in the
tst_ipaddr_un(). Looks like route-change-if needs a similar fix for net id?Good point (sorry to keep octet/hextet overflow related errors). Although it'd be simpler to fix it in the code, I'd prefer to have this support in
tst_ipaddr_un(). Diff below adds -lMIN_HOST_ID(I'll post it as a part of v3), do we want to lower also max host id?
Quoted 5 lines
It can only be "max host id" option since we already have this variable in the function, and in the test setup, we could assign "lhost" variable with the max value:
lhost="$(tst_ipaddr_un 1 $max_host_id)"
I'll have to implement min value as well, because we have for non-counter mode (e.g tst_ipaddr_un $net_id $host_id) 0 as well, so it will break for invalid gateway 10.23.1.0. I wanted to avoid -c mode for these route tests.
I guess <0-254> for max host ID for this mode was good idea, but IMHO it should
be: <0-255> (to allow both network address and broadcast address), and allow to have minimize both min and max. So for case of valid address it'd would be:tst_ipaddr_un -l 1 -m 254 $net_id $host_id
Other could be to have range for this mode default suitable for hosts (<1..254>) as we have it for -c mode. Getting network would be:
tst_ipaddr_un -n $net_id # instead of tst_ipaddr_un $net_id 0
Getting broadcast would be:
tst_ipaddr_un -b $net_id # currently not possible at all with tst_ipaddr_un
This second proposal looks more usable to me, although -b and -n aren't obvious (long getopts would be better, but I think it's better to avoid them).
+ I'd still keep proposed -m max_host_id, so we could use tst_ipaddr_un $net_id 254 for route and tst_ipaddr_un -m 253 $net_id $1 for hosts.
Kind regards,
Petr
PATCH v3 5/5 network/route: Rewrite route-change-if into new API
In reply to Petr Vorel* Drop route command (use just ip command), support both IPv4 and IPv6
* Use unused network range to avoid clash with real network
* Add verification with ping (previous version sent UDP datagram with ns-udpsender, but didn't verify receiving it on rhost and didn't setup rhost ip at all)
* Add tst_get_ifaces_cnt() into tst_net.sh
---
I guess I shouldn't add tst_get_ifaces_cnt() to tst_net.sh, if nothing else uses it. I can move it to route-change-if.
runtest/net_stress.route | 4 +- testcases/lib/tst_net.sh | 8 + .../network/stress/route/00_Descriptions.txt | 18 +- .../network/stress/route/route-change-if | 87 +++++ .../network/stress/route/route4-change-if | 324 ------------------ .../network/stress/route/route6-change-if | 323 ----------------- 6 files changed, 100 insertions(+), 664 deletions(-) create mode 100755 testcases/network/stress/route/route-change-if delete mode 100644 testcases/network/stress/route/route4-change-if delete mode 100644 testcases/network/stress/route/route6-change-if
runtest/net_stress.route +2 -2
@@ -4,12 +4,12 @@ route4-change-dst route-change-dst route4-change-gw route-change-gw -route4-change-if route4-change-if +route4-change-if route-change-if route4-redirect route4-redirect route4-rmmod route4-rmmod route6-change-dst route-change-dst -6 route6-change-gw route-change-gw -6 -route6-change-if route6-change-if +route6-change-if route-change-if -6 route6-redirect route6-redirect route6-rmmod route6-rmmod
testcases/lib/tst_net.sh +8 -0
@@ -285,6 +285,14 @@ tst_get_ifaces() fi } +# Get count of test interfaces for local/remote host. +tst_get_ifaces_cnt() +{ + tst_test_cmds awk + local type="${1:-lhost}" + echo "$(tst_get_ifaces $type)" | awk '{print NF}' +} + # Get HW addresses from defined test interface names. # tst_get_hwaddrs [TYPE] # TYPE: { lhost | rhost }; Default value is 'lhost'.
testcases/network/stress/route/00_Descriptions.txt +3 -15
@@ -6,13 +6,9 @@ route-change-gw Verify the IPv4/IPv6 is not broken when ip command changes route gateway many times -route4-change-if01 - Verify the kernel is not crashed when the interface of an IPv4 route is - changed frequently by route command - -route4-change-if02 - Verify the kernel is not crashed when the interface of an IPv4 route is - changed frequently by ip command +route-change-if + Verify the IPv4/IPv6 is not broken when ip command changes route + interface many times route4-redirect01 Verify the kernel is not crashed when the IPv4 route is modified by
@@ -27,14 +23,6 @@ route4-rmmod02 then it is deleted by the removing network driver -route6-change-if01 - Verify the kernel is not crashed when the interface of an IPv6 route is - changed frequently by route command - -route6-change-if02 - Verify the kernel is not crashed when the interface of an IPv6 route is - changed frequently by ip command - route6-redirect01 Verify the kernel is not crashed when the IPv6 route is modified by ICMP Redirects frequently
testcases/network/stress/route/route-change-if new file +87 -0
87 lines not on this page · raw message
testcases/network/stress/route/route4-change-if deleted +0 -324
324 lines not on this page · raw message
testcases/network/stress/route/route6-change-if deleted +0 -323
323 lines not on this page · raw message
Signature · 1 line
2.22.0