Skip to contentSkip to conversation

Simplify network setup + fix some multicast network stress tests

RFC PATCH New Petr Vorel 3 participants 22 messages Aug 24, 2017 – Sep 11, 2017

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

v9 cover Simplify network setup + fix some multicast network stress tests

I decided to send v9 without route tests. Hope this helps to get v9 merged. I plan to send fixed route tests (both IPv4 + IPv6) + more macast tests in the next patch-set.

Kind regards,
Petr

Petr Vorel (7):
lib/test_net.sh: Add unused IP address helper functions network/stress: Add library helper for stress testing network/stress: Simplify make_background_tcp_traffic usage network/stress: Reduce the default number of cycles for various tests network/stress: Fix and cleanup part of multicast IPv4 tests
network: Add tools for setup IP related environment variables
network: Use tools to set up IPv4 and IPv6 related variables

 include/tst_net.h                                  | 153 +++++
 testcases/lib/.gitignore                           |   3 +
 testcases/lib/Makefile                             |   2 +-
 testcases/lib/test_net.sh                          | 168 ++++--
 testcases/lib/tst_net_iface_prefix.c               | 180 ++++++
 testcases/lib/tst_net_ip_prefix.c                  | 123 ++++
 testcases/lib/tst_net_vars.c                       | 645 +++++++++++++++++++++
 testcases/network/stress/interface/if-addr-adddel  |  21 +-
 .../network/stress/interface/if-addr-addlarge      |  22 +-
 testcases/network/stress/interface/if-lib.sh       |  73 ---
 testcases/network/stress/interface/if-mtu-change   |  19 +-
 testcases/network/stress/interface/if-route-adddel |  26 +-
 .../network/stress/interface/if-route-addlarge     |  21 +-
 testcases/network/stress/interface/if-updown       |   9 +-
 testcases/network/stress/interface/if4-addr-change |  21 +-
 .../stress/multicast/grp-operation/mcast4-grpope01 | 221 +------
 .../stress/multicast/grp-operation/mcast4-grpope02 | 230 +-------
 .../stress/multicast/grp-operation/mcast4-grpope03 | 217 +------
 .../stress/multicast/grp-operation/mcast4-grpope04 | 236 +-------
 .../stress/multicast/grp-operation/mcast4-lib.sh   | 118 ++++
 testcases/network/stress/ns-tools/Makefile         |   2 +-
 .../network/stress/ns-tools/test_net_stress.sh     | 138 +++++
 22 files changed, 1621 insertions(+), 1027 deletions(-)
 create mode 100644 include/tst_net.h
 create mode 100644 testcases/lib/tst_net_iface_prefix.c
 create mode 100644 testcases/lib/tst_net_ip_prefix.c
 create mode 100644 testcases/lib/tst_net_vars.c
 delete mode 100644 testcases/network/stress/interface/if-lib.sh
 create mode 100644 testcases/network/stress/multicast/grp-operation/mcast4-lib.sh
 create mode 100644 testcases/network/stress/ns-tools/test_net_stress.sh
Signature · 1 line
2.14.0
author
#1 lore raw

RFC PATCH v9 1/7 lib/test_net.sh: Add unused IP address helper functions

---
 testcases/lib/test_net.sh | 66 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 65 insertions(+), 1 deletion(-)
testcases/lib/test_net.sh +65 -1
index c11747a27..585ab51fe 100644
@@ -219,7 +219,7 @@ tst_ipaddr()
 {
 	local type="${1:-lhost}"
 	local ipv="${TST_IPV6:-4}"
-	local tst_host=
+	local tst_host
 
 	if [ "$type" = "lhost" ]; then
 		eval "tst_host=\$LHOST_IPV${ipv}_HOST"
@@ -234,6 +234,70 @@ tst_ipaddr()
 	fi
 }
 
+# Get IP address of unused network, specified by either by type and
+# counter or by net and host.
+# tst_ipaddr_un [-cCOUNTER] [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.
+tst_ipaddr_un()
+{
+	local counter host_id net_id max_host_id max_net_id tmp type
+	local OPTIND
+
+	while getopts "c:" opt; do
+		case $opt in
+			c) counter="$OPTARG";;
+		esac
+	done
+	shift $(($OPTIND - 1))
+
+	[ "$TST_IPV6" ] && max_net_id=65535 || max_net_id=255
+
+	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
+			host_id=$max_host_id
+			net_id=$((net_id - 1))
+		fi
+	else
+		net_id="$1"
+		host_id="${2:-0}"
+		max_host_id=$max_net_id
+		if [ "$TST_IPV6" ]; then
+			net_id=$(printf %d $net_id)
+			host_id=$(printf %d $host_id)
+		fi
+		[ $net_id -lt 0 ] && net_id=0
+		[ $host_id -lt 0 ] && host_id=1
+	fi
+
+	net_id=$((net_id % max_net_id))
+	host_id=$((host_id % max_host_id))
+
+	if [ "$TST_IPV6" ]; then
+		[ $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}"
+	else
+		echo "${IPV4_NET16_UNUSED}.${net_id}.${host_id}"
+	fi
+}
+
 # tst_init_iface [TYPE] [LINK]
 # TYPE: { lhost | rhost }; Default value is 'lhost'.
 # LINK: link number starting from 0. Default value is '0'.
Signature · 1 line
2.14.0
#2 lore raw

RFC PATCH v9 1/7 lib/test_net.sh: Add unused IP address helper functions

Hi,

Quoted 27 lines · Petr Vorel
---
 testcases/lib/test_net.sh | 66 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 65 insertions(+), 1 deletion(-)

...

testcases/lib/test_net.sh +22 -0
+
+	[ "$TST_IPV6" ] && max_net_id=65535 || max_net_id=255
+
+	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
+			host_id=$max_host_id
+			net_id=$((net_id - 1))
+		fi
+	else
+		net_id="$1"
+		host_id="${2:-0}"
+		max_host_id=$max_net_id

testcases/lib/test_net.sh tst_ipaddr() · line 289

Quoted 10 lines
testcases/lib/test_net.sh +10 -0
+		if [ "$TST_IPV6" ]; then
+			net_id=$(printf %d $net_id)
+			host_id=$(printf %d $host_id)
+		fi
+		[ $net_id -lt 0 ] && net_id=0
+		[ $host_id -lt 0 ] && host_id=1
+	fi
+
+	net_id=$((net_id % max_net_id))
+	host_id=$((host_id % max_host_id))

Changed to 'max_net_id' here and applied, otherwise we would have host_id 0 if counter = 254.

Thanks,
Alexey

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20170908/3c5cbb9d/attachment-0001.html>

author
#3 lore raw

RFC PATCH v9 2/7 network/stress: Add library helper for stress testing

In reply to Petr Vorel

+ use it in interface stress tests

test_net_stress.sh:
* test_net_stress.sh library is intended to be used throughout all stress tests reduce duplicity and use code from test_net.sh where possible instead of legacy scripts in testcases/network/stress/ns-tools/.
* TCID set automatically from basename.
* Add "unused network" related variables. So far used only IPv4 ones.
* Functions from if-lib.sh moved and (and some renamed) to test_net_stress.sh as they are going to be reused in other tests (not just interface stress tests).

Interfaces stress tests:
* Interfaces tests use test_net_stress.sh.
* Remove restore_ipaddr from cleanup functions as these functions would break netns testing with RTNETLINK errors. Use them just in setup during if-mtu-change where are really needed.

---
 testcases/lib/test_net.sh                          |   5 +-
 testcases/network/stress/interface/if-addr-adddel  |  15 +--
 .../network/stress/interface/if-addr-addlarge      |  16 +--
 testcases/network/stress/interface/if-lib.sh       |  73 -----------
 testcases/network/stress/interface/if-mtu-change   |  12 +-
 testcases/network/stress/interface/if-route-adddel |  19 +--
 .../network/stress/interface/if-route-addlarge     |  15 +--
 testcases/network/stress/interface/if-updown       |   9 +-
 testcases/network/stress/interface/if4-addr-change |   4 +-
 testcases/network/stress/ns-tools/Makefile         |   2 +-
 .../network/stress/ns-tools/test_net_stress.sh     | 136 +++++++++++++++++++++
 11 files changed, 171 insertions(+), 135 deletions(-)
 delete mode 100644 testcases/network/stress/interface/if-lib.sh
 create mode 100644 testcases/network/stress/ns-tools/test_net_stress.sh
testcases/lib/test_net.sh +3 -2
index 585ab51fe..b23c35553 100644
@@ -500,6 +500,7 @@ tst_ping()
 	local src_iface="${1:-$(tst_iface)}"
 	local dst_addr="${2:-$(tst_ipaddr rhost)}"; shift $(( $# >= 2 ? 2 : 0 ))
 	local msg_sizes="$*"
+	local msg="tst_ping IPv${TST_IPV6:-4} iface $src_iface, msg_size"
 	local ret=0
 
 	# ping cmd use 56 as default message size
@@ -508,9 +509,9 @@ tst_ping()
 			-s $size -i 0 > /dev/null 2>&1
 		ret=$?
 		if [ $ret -eq 0 ]; then
-			tst_resm TINFO "tst_ping IPv${TST_IPV6:-4} msg_size $size pass"
+			tst_resm TINFO "$msg $size: pass"
 		else
-			tst_resm TINFO "tst_ping IPv${TST_IPV6:-4} msg_size $size fail"
+			tst_resm TINFO "$msg $size: fail"
 			break
 		fi
 	done
testcases/network/stress/interface/if-addr-adddel +4 -11
index dcc018a48..42c2d5afa 100644
@@ -18,20 +18,13 @@
 # Author: Mitsuru Chinen <[email protected]>
 
 TST_TOTAL=2
-TCID=if-addr-adddel
 
-. if-lib.sh
-
-TST_CLEANUP="do_cleanup"
+TST_CLEANUP="netstress_cleanup"
 
 # The interval of the check interface activity
 CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
 
-do_cleanup()
-{
-	cleanup
-	restore_ipaddr
-}
+. test_net_stress.sh
 
 test_body()
 {
@@ -88,7 +81,7 @@ test_body()
 			return
 		fi
 
-		check_connectivity $cnt || return
+		check_connectivity_interval $cnt || return
 
 		cnt=$(($cnt + 1))
 
@@ -122,7 +115,7 @@ test_body()
 	tst_resm TPASS "Test is finished correctly"
 }
 
-setup
+netstress_setup
 
 tst_check_cmds ifconfig
 
testcases/network/stress/interface/if-addr-addlarge +4 -12
index 9e550068b..e667d9138 100644
@@ -18,20 +18,13 @@
 # Author: Mitsuru Chinen <[email protected]>
 
 TST_TOTAL=2
-TCID=if-addr-addlarge
 
-. if-lib.sh
-
-TST_CLEANUP="do_cleanup"
+TST_CLEANUP="netstress_cleanup"
 
 # The interval of the check interface activity
 CHECK_INTERVAL=${CHECK_INTERVAL:-$(($IP_TOTAL / 20))}
 
-do_cleanup()
-{
-	cleanup
-	restore_ipaddr
-}
+. test_net_stress.sh
 
 test_body()
 {
@@ -100,8 +93,7 @@ test_body()
 			return
 		fi
 
-		# Check the connectivity
-		check_connectivity $cnt || return
+		check_connectivity_interval $cnt || return
 
 		# Check the background TCP traffic
 		pgrep -x netstress > /dev/null || make_background_tcp_traffic
@@ -143,7 +135,7 @@ test_body()
 	tst_resm TPASS "Test is finished correctly"
 }
 
-setup
+netstress_setup
 
 tst_check_cmds ifconfig
 
testcases/network/stress/interface/if-lib.sh deleted +0 -73

73 lines not on this page · raw message

testcases/network/stress/interface/if-mtu-change +6 -6
index 637fa6389..03e6ba9d6 100644
@@ -18,9 +18,6 @@
 # Author: Mitsuru Chinen <[email protected]>
 
 TST_TOTAL=2
-TCID=if-mtu-change
-
-. if-lib.sh
 
 TST_CLEANUP="do_cleanup"
 
@@ -33,9 +30,12 @@ CHANGE6_VALUES="1280 1445 1335 1390 1500 1280 1500 1280 1335 1500"
 [ "$TST_IPV6" ] && CHANGE_VALUES=$CHANGE6_VALUES
 saved_mtu=
 
+. test_net_stress.sh
+
+
 do_cleanup()
 {
-	cleanup
+	netstress_cleanup
 	if [ "$saved_mtu" ]; then
 		ip li set $(tst_iface) mtu $saved_mtu
 		tst_rhost_run -c "ip li set $(tst_iface rhost) mtu $saved_mtu"
@@ -59,7 +59,7 @@ test_body()
 	local iface_rmt=$(tst_iface rhost)
 	[ "$TST_IPV6" ] && local netmask=64 || local netmask=16
 
-	tst_resm TINFO "'$cmd_name changes MTU $MTU_CHANGE_TIMES times " \
+	tst_resm TINFO "'$cmd_name changes MTU $MTU_CHANGE_TIMES times" \
 	               "every $CHANGE_INTERVAL seconds"
 
 	make_background_tcp_traffic
@@ -98,7 +98,7 @@ test_body()
 	done
 }
 
-setup
+netstress_setup
 
 tst_check_cmds ifconfig
 
testcases/network/stress/interface/if-route-adddel +6 -13
index 451674178..e207c5d79 100644
@@ -18,19 +18,12 @@
 # Author: Mitsuru Chinen <[email protected]>
 
 TST_TOTAL=2
-TCID=if-route-adddel
 
-. if-lib.sh
-
-TST_CLEANUP="do_cleanup"
+TST_CLEANUP="netstress_cleanup"
 
 CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
 
-do_cleanup()
-{
-	cleanup
-	restore_ipaddr
-}
+. test_net_stress.sh
 
 test_body()
 {
@@ -47,10 +40,10 @@ test_body()
 	local new_rt=
 	local opt_rt=
 	if [ "$TST_IPV6" ]; then
-		new_rt=${IPV6_NET32_UNUSED}::
+		new_rt="$(TST_IPV6=6 tst_ipaddr_un 0)"
 		opt_rt="/64"
 	else
-		new_rt="${IPV4_NET16_UNUSED}.23.0"
+		new_rt="$(tst_ipaddr_un 23)"
 		case $cmd_type in
 		rt_cmd) ;;
 		ip_cmd) opt_rt='/24' ;;
@@ -86,7 +79,7 @@ test_body()
 			return
 		fi
 
-		check_connectivity $cnt || return
+		check_connectivity_interval $cnt || return
 
 		# Check the background TCP traffic
 		pgrep -x netstress > /dev/null || make_background_tcp_traffic
@@ -97,7 +90,7 @@ test_body()
 	tst_resm TPASS "Test is finished correctly"
 }
 
-setup
+netstress_setup
 
 tst_check_cmds route
 
testcases/network/stress/interface/if-route-addlarge +4 -11
index e83cf60a7..3337b7225 100644
@@ -18,19 +18,12 @@
 # Author: Mitsuru Chinen <[email protected]>
 
 TST_TOTAL=2
-TCID=if-route-addlarge
 
-. if-lib.sh
-
-TST_CLEANUP="do_cleanup"
+TST_CLEANUP="netstress_cleanup"
 
 CHECK_INTERVAL=${CHECK_INTERVAL:-$(($ROUTE_TOTAL / 20))}
 
-do_cleanup()
-{
-	cleanup
-	restore_ipaddr
-}
+. test_net_stress.sh
 
 test_body()
 {
@@ -93,7 +86,7 @@ test_body()
 			return
 		fi
 
-		check_connectivity $cnt || return
+		check_connectivity_interval $cnt || return
 
 		# Check the background TCP traffic
 		pgrep -x netstress > /dev/null || make_background_tcp_traffic
@@ -112,7 +105,7 @@ test_body()
 	tst_resm TPASS "Test is finished correctly"
 }
 
-setup
+netstress_setup
 
 tst_check_cmds route
 
testcases/network/stress/interface/if-updown +5 -4
index deefef639..5ab54a1f8 100644
@@ -18,12 +18,13 @@
 # Author: Mitsuru Chinen <[email protected]>
 
 TST_TOTAL=2
-TCID=if-updown
 
-. if-lib.sh
+TST_CLEANUP="netstress_cleanup"
 
 CHECK_INTERVAL=${CHECK_INTERVAL:-$(($IF_UPDOWN_TIMES / 20))}
 
+. test_net_stress.sh
+
 test_body()
 {
 	local cmd_type=$1
@@ -59,7 +60,7 @@ test_body()
 			return
 		fi
 
-		check_connectivity $cnt restore_ip || return
+		check_connectivity_interval $cnt restore_ip || return
 
 		cnt=$(($cnt + 1))
 	done
@@ -67,7 +68,7 @@ test_body()
 	tst_resm TPASS "Test is finished correctly"
 }
 
-setup
+netstress_setup
 
 tst_check_cmds ifconfig
 
testcases/network/stress/interface/if4-addr-change +2 -2
index 54b8fd5fb..567f86643 100644
@@ -21,12 +21,12 @@ TST_TOTAL=1
 TCID=if4-addr-change
 TST_CLEANUP="do_cleanup"
 
-. test_net.sh
-
 CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
 # Maximum host portion of the IPv4 address on the local host
 LHOST_IPV4_HOST_MAX="254"
 
+. test_net.sh
+
 do_cleanup()
 {
 	tst_restore_ipaddr
testcases/network/stress/ns-tools/Makefile +1 -1
index 61f85634a..1c186b232 100644
@@ -29,7 +29,7 @@ INSTALL_TARGETS		:= check_envval get_ifname initialize_if set_ipv4addr \
 			   check_icmpv6_connectivity check_netem check_setkey \
 			   create_file find_portbundle killall_icmp_traffic \
 			   killall_tcp_traffic killall_udp_traffic output_ipsec_conf \
-			   ns-echoclient
+			   ns-echoclient test_net_stress.sh
 
 FILTER_OUT_MAKE_TARGETS	:= ns-common
 
testcases/network/stress/ns-tools/test_net_stress.sh new file +136 -0

136 lines not on this page · raw message

Signature · 1 line
2.14.0
#4 lore raw

RFC PATCH v9 2/7 network/stress: Add library helper for stress testing

Quoted 17 lines · Petr Vorel

+ use it in interface stress tests

test_net_stress.sh:
* test_net_stress.sh library is intended to be used throughout all stress tests reduce duplicity and use code from test_net.sh where possible instead of legacy scripts in testcases/network/stress/ns-tools/.
* TCID set automatically from basename.
* Add "unused network" related variables. So far used only IPv4 ones.
* Functions from if-lib.sh moved and (and some renamed) to test_net_stress.sh as they are going to be reused in other tests (not just interface stress tests).

Interfaces stress tests:
* Interfaces tests use test_net_stress.sh.
* Remove restore_ipaddr from cleanup functions as these functions would break netns testing with RTNETLINK errors. Use them just in setup during if-mtu-change where are really needed.

...

Quoted 15 lines
testcases/network/stress/interface/if-mtu-change +0 -3
index 637fa6389..03e6ba9d6 100644
@@ -18,9 +18,6 @@
 # Author: Mitsuru Chinen <[email protected]>
 
 TST_TOTAL=2
-TCID=if-mtu-change
-
-. if-lib.sh
 
 TST_CLEANUP="do_cleanup"
 

testcases/network/stress/interface/if-mtu-change CHANGE6_VALUES="1280 1445 1335 1390 1500 1280 1500 1280 1335 1500" · line 35

Quoted 6 lines
testcases/network/stress/interface/if-mtu-change +3 -0
@@ -33,9 +30,12 @@ CHANGE6_VALUES="1280 1445 1335 1390 1500 1280 1500 1280 1335 1500"
 [ "$TST_IPV6" ] && CHANGE_VALUES=$CHANGE6_VALUES
 saved_mtu=
 
+. test_net_stress.sh
+
+

TST_IPV6 not defined in this case, sourced the library before the usage of this variable.

testcases/network/stress/interface/if-mtu-change CHANGE6_VALUES="1280 1445 1335 1390 1500 1280 1500 1280 1335 1500"

Quoted 12 lines
testcases/network/stress/interface/if-mtu-change +12 -0
+
+# Prefix of the Multicast Address
+MCAST_IPV4_ADDR_PREFIX="224.10"
+# Multicast Address
+MCAST_IPV4_ADDR="${MCAST_IPV4_ADDR_PREFIX}.10.1"
+
+LINK_TOTAL=$(echo $LHOST_HWADDRS | wc -w)
+RHOST_LINK_TOTAL=$(echo $RHOST_HWADDRS | wc -w)
+[ $LINK_TOTAL -ne $RHOST_LINK_TOTAL ] && \
+	tst_brkm TBROK "the number of element in LHOST_HWADDRS differs from RHOST_HWADDRS" \
+	"($LINK_TOTAL vs. $RHOST_LINK_TOTAL," \
+	"LHOST_HWADDRS: '$LHOST_HWADDRS' RHOST_HWADDRS: '$RHOST_HWADDRS')"

Didn't find the place where you need these variables. Are you going to use them somewhere or they are here just for checking network configuration?

I've removed them and applied the patch.

Thanks,
Alexey

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20170908/0a7d287b/attachment.html>

author
#5 lore raw

RFC PATCH v9 2/7 network/stress: Add library helper for stress testing

Hi Alexey,

thanks for your review and fixes!

Quoted 10 lines

testcases/network/stress/ns-tools/test_net_stress.sh line 45

Quoted 6 lines
testcases/network/stress/ns-tools/test_net_stress.sh new file +6 -0
+LINK_TOTAL=$(echo $LHOST_HWADDRS | wc -w)
+RHOST_LINK_TOTAL=$(echo $RHOST_HWADDRS | wc -w)
+[ $LINK_TOTAL -ne $RHOST_LINK_TOTAL ] && \
+	tst_brkm TBROK "the number of element in LHOST_HWADDRS differs from RHOST_HWADDRS" \
+	"($LINK_TOTAL vs. $RHOST_LINK_TOTAL," \
+	"LHOST_HWADDRS: '$LHOST_HWADDRS' RHOST_HWADDRS: '$RHOST_HWADDRS')"

Didn't find the place where you need these variables. Are you going to use them somewhere or they are here just for checking network configuration? I've removed them and applied the patch.

These are used in route4-change-if. I left them here while excluding route tests from v9. As you were talking about that multi test links are problematic and not many other tests are using them it was a right decision not to include it.

BTW Tests requiring multi test links are these:
route{4,6}-change-if (I tend to delete it)
tcp4-multi-diffnic01
udp4-multi-diffnic01
icmp4-multi-diffnic01

Kind regards,
Petr

author
#6 lore raw

RFC PATCH v9 3/7 network/stress: Simplify make_background_tcp_traffic usage

In reply to Petr Vorel
---
 testcases/network/stress/interface/if-addr-adddel    | 6 +-----
 testcases/network/stress/interface/if-addr-addlarge  | 6 +-----
 testcases/network/stress/interface/if-mtu-change     | 7 ++-----
 testcases/network/stress/interface/if-route-adddel   | 7 ++-----
 testcases/network/stress/interface/if-route-addlarge | 6 +-----
 testcases/network/stress/ns-tools/test_net_stress.sh | 2 ++
 6 files changed, 9 insertions(+), 25 deletions(-)
testcases/network/stress/interface/if-addr-adddel +1 -5
index 42c2d5afa..3b1ab50bb 100644
@@ -53,10 +53,9 @@ test_body()
 		return
 	fi
 
-	make_background_tcp_traffic
-
 	local cnt=1
 	while [ $cnt -le $NS_TIMES ]; do
+		make_background_tcp_traffic
 
 		case $cmd_type in
 		if_cmd)
@@ -85,9 +84,6 @@ test_body()
 
 		cnt=$(($cnt + 1))
 
-		# Check the background TCP traffic
-		pgrep -x netstress > /dev/null || make_background_tcp_traffic
-
 		case $cmd_type in
 		if_cmd)
 			if [ "$TST_IPV6" ]; then
testcases/network/stress/interface/if-addr-addlarge +1 -5
index e667d9138..c3cdb8fa9 100644
@@ -47,8 +47,6 @@ test_body()
 		return
 	fi
 
-	make_background_tcp_traffic
-
 	local x=1
 	local y=1
 	local cnt=1
@@ -61,6 +59,7 @@ test_body()
 	fi
 
 	while [ $cnt -le $IP_TOTAL ]; do
+		make_background_tcp_traffic
 
 		if [ "$TST_IPV6" ]; then
 			local hex_x=$(printf '%x' $x)
@@ -95,9 +94,6 @@ test_body()
 
 		check_connectivity_interval $cnt || return
 
-		# Check the background TCP traffic
-		pgrep -x netstress > /dev/null || make_background_tcp_traffic
-
 		case $cmd_type in
 		if_cmd)
 			if [ "$TST_IPV6" ]; then
testcases/network/stress/interface/if-mtu-change +2 -5
index 03e6ba9d6..9a13e4f43 100644
@@ -62,8 +62,6 @@ test_body()
 	tst_resm TINFO "'$cmd_name changes MTU $MTU_CHANGE_TIMES times" \
 	               "every $CHANGE_INTERVAL seconds"
 
-	make_background_tcp_traffic
-
 	mtu_array_len=$(echo $CHANGE_VALUES | wc -w)
 	local cnt=0
 	while [ $cnt -lt $MTU_CHANGE_TIMES ]; do
@@ -73,6 +71,8 @@ test_body()
 		mtu=$(echo $CHANGE_VALUES | cut -d ' ' -f $field)
 		[ $cnt -eq $MTU_CHANGE_TIMES ] && mtu="$saved_mtu"
 
+		make_background_tcp_traffic
+
 		tst_resm TINFO "set MTU to $mtu $cnt/$MTU_CHANGE_TIMES"
 		local ret=0
 		case $cmd_type in
@@ -92,9 +92,6 @@ test_body()
 		tst_sleep $CHANGE_INTERVAL
 
 		EXPECT_PASS tst_ping $(tst_ipaddr) $(tst_ipaddr rhost) "1 1000 65507"
-
-		# Check the background TCP traffic
-		pgrep -x netstress > /dev/null || make_background_tcp_traffic
 	done
 }
 
testcases/network/stress/interface/if-route-adddel +2 -5
index e207c5d79..64366fc52 100644
@@ -57,10 +57,10 @@ test_body()
 		return
 	fi
 
-	make_background_tcp_traffic
-
 	local cnt=1
 	while [ $cnt -le $NS_TIMES ]; do
+		make_background_tcp_traffic
+
 		case $cmd_type in
 		rt_cmd) route -A $inet add ${new_rt}${opt_rt} dev $iface ;;
 		ip_cmd) ip route add ${new_rt}${opt_rt} dev $iface ;;
@@ -81,9 +81,6 @@ test_body()
 
 		check_connectivity_interval $cnt || return
 
-		# Check the background TCP traffic
-		pgrep -x netstress > /dev/null || make_background_tcp_traffic
-
 		cnt=$(($cnt + 1))
 	done
 
testcases/network/stress/interface/if-route-addlarge +1 -5
index 3337b7225..b7e6952c2 100644
@@ -54,8 +54,6 @@ test_body()
 		return
 	fi
 
-	make_background_tcp_traffic
-
 	local x=1
 	local y=1
 	local cnt=1
@@ -68,6 +66,7 @@ test_body()
 	fi
 
 	while [ $cnt -le $ROUTE_TOTAL ]; do
+		make_background_tcp_traffic
 
 		if [ "$TST_IPV6" ]; then
 			local hex_x=$(printf '%x' $x)
@@ -88,9 +87,6 @@ test_body()
 
 		check_connectivity_interval $cnt || return
 
-		# Check the background TCP traffic
-		pgrep -x netstress > /dev/null || make_background_tcp_traffic
-
 		cnt=$(($cnt + 1))
 		y=$(($y + 1))
 		if [ $y -gt $xymax ]; then
testcases/network/stress/ns-tools/test_net_stress.sh +2 -0
index 065bc666f..472524731 100644
@@ -128,6 +128,8 @@ check_connectivity_interval()
 # IP: server IP; Default value is $(tst_ipaddr).
 make_background_tcp_traffic()
 {
+	pgrep -x netstress > /dev/null && return
+
 	local ip="${1:-$(tst_ipaddr)}"
 	local port=$(tst_get_unused_port ipv${ipver} stream)
 
Signature · 1 line
2.14.0
#7 lore raw

RFC PATCH v9 3/7 network/stress: Simplify make_background_tcp_traffic usage

Quoted 9 lines · Petr Vorel
---
 testcases/network/stress/interface/if-addr-adddel    | 6 +-----
 testcases/network/stress/interface/if-addr-addlarge  | 6 +-----
 testcases/network/stress/interface/if-mtu-change     | 7 ++-----
 testcases/network/stress/interface/if-route-adddel   | 7 ++-----
 testcases/network/stress/interface/if-route-addlarge | 6 +-----
 testcases/network/stress/ns-tools/test_net_stress.sh | 2 ++
 6 files changed, 9 insertions(+), 25 deletions(-)

Applied.

Thanks,
Alexey

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20170908/584fa215/attachment.html>

author
#8 lore raw

RFC PATCH v9 4/7 network/stress: Reduce the default number of cycles for various tests

In reply to Petr Vorel

Values reduced to one fifth resp. one tenth should be still enough even for stress testing.

---
 testcases/lib/test_net.sh | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
testcases/lib/test_net.sh +6 -6
index b23c35553..f72e4755f 100644
@@ -614,20 +614,20 @@ export FTP_UPLOAD_DIR="${FTP_UPLOAD_DIR:-/var/ftp/pub}"
 export FTP_UPLOAD_URLDIR="${FTP_UPLOAD_URLDIR:-pub}"
 
 # network/stress tests require additional parameters
-export NS_DURATION="${NS_DURATION:-3600}"
-export NS_TIMES="${NS_TIMES:-10000}"
+export NS_DURATION="${NS_DURATION:-720}"
+export NS_TIMES="${NS_TIMES:-2000}"
 export CONNECTION_TOTAL="${CONNECTION_TOTAL:-4000}"
-export IP_TOTAL="${IP_TOTAL:-10000}"
+export IP_TOTAL="${IP_TOTAL:-2000}"
 export IP_TOTAL_FOR_TCPIP="${IP_TOTAL_FOR_TCPIP:-100}"
-export ROUTE_TOTAL="${ROUTE_TOTAL:-10000}"
+export ROUTE_TOTAL="${ROUTE_TOTAL:-2000}"
 export MTU_CHANGE_TIMES="${MTU_CHANGE_TIMES:-1000}"
-export IF_UPDOWN_TIMES="${IF_UPDOWN_TIMES:-10000}"
+export IF_UPDOWN_TIMES="${IF_UPDOWN_TIMES:-2000}"
 export DOWNLOAD_BIGFILESIZE="${DOWNLOAD_BIGFILESIZE:-2147483647}"
 export DOWNLOAD_REGFILESIZE="${DOWNLOAD_REGFILESIZE:-1048576}"
 export UPLOAD_BIGFILESIZE="${UPLOAD_BIGFILESIZE:-2147483647}"
 export UPLOAD_REGFILESIZE="${UPLOAD_REGFILESIZE:-1024}"
 export MCASTNUM_NORMAL="${MCASTNUM_NORMAL:-20}"
-export MCASTNUM_HEAVY="${MCASTNUM_HEAVY:-40000}"
+export MCASTNUM_HEAVY="${MCASTNUM_HEAVY:-4000}"
 
 [ -n "$TST_USE_NETNS" -a "$TST_INIT_NETNS" != "no" ] && init_ltp_netspace
 
Signature · 1 line
2.14.0
#9 lore raw

RFC PATCH v9 4/7 network/stress: Reduce the default number of cycles for various tests

Quoted 29 lines · Petr Vorel

Values reduced to one fifth resp. one tenth should be still enough even for stress testing.

---
 testcases/lib/test_net.sh | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
testcases/lib/test_net.sh +5 -5
index b23c35553..f72e4755f 100644
@@ -614,20 +614,20 @@ export FTP_UPLOAD_DIR="${FTP_UPLOAD_DIR:-/var/ftp/pub}"
 export FTP_UPLOAD_URLDIR="${FTP_UPLOAD_URLDIR:-pub}"
 
 # network/stress tests require additional parameters
-export NS_DURATION="${NS_DURATION:-3600}"
-export NS_TIMES="${NS_TIMES:-10000}"
+export NS_DURATION="${NS_DURATION:-720}"
+export NS_TIMES="${NS_TIMES:-2000}"
 export CONNECTION_TOTAL="${CONNECTION_TOTAL:-4000}"
-export IP_TOTAL="${IP_TOTAL:-10000}"
+export IP_TOTAL="${IP_TOTAL:-2000}"
 export IP_TOTAL_FOR_TCPIP="${IP_TOTAL_FOR_TCPIP:-100}"
-export ROUTE_TOTAL="${ROUTE_TOTAL:-10000}"
+export ROUTE_TOTAL="${ROUTE_TOTAL:-2000}"
 export MTU_CHANGE_TIMES="${MTU_CHANGE_TIMES:-1000}"
-export IF_UPDOWN_TIMES="${IF_UPDOWN_TIMES:-10000}"
+export IF_UPDOWN_TIMES="${IF_UPDOWN_TIMES:-2000}"

testcases/lib/test_net.sh export FTP_UPLOAD_DIR="${FTP_UPLOAD_DIR:-/var/ftp/pub}" · line 633

Quoted 10 lines
testcases/lib/test_net.sh +1 -1
 export DOWNLOAD_BIGFILESIZE="${DOWNLOAD_BIGFILESIZE:-2147483647}"
 export DOWNLOAD_REGFILESIZE="${DOWNLOAD_REGFILESIZE:-1048576}"
 export UPLOAD_BIGFILESIZE="${UPLOAD_BIGFILESIZE:-2147483647}"
 export UPLOAD_REGFILESIZE="${UPLOAD_REGFILESIZE:-1024}"
 export MCASTNUM_NORMAL="${MCASTNUM_NORMAL:-20}"
-export MCASTNUM_HEAVY="${MCASTNUM_HEAVY:-40000}"
+export MCASTNUM_HEAVY="${MCASTNUM_HEAVY:-4000}"
 
 [ -n "$TST_USE_NETNS" -a "$TST_INIT_NETNS" != "no" ] && init_ltp_netspace
 

Applied, thank you.

Best regards,
Alexey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20170908/5bc37516/attachment.html>

author
#10 lore raw

RFC PATCH v9 5/7 network/stress: Fix and cleanup part of multicast IPv4 tests

In reply to Petr Vorel

* Fix test for SSH and netns based testing.
* Remove hardcoded rsh dependency.
* Create shell library mcast4-lib.sh (multicast IPv4 specific) to reduce duplicity in tests. Library uses test_stress_net.sh (and therefore test_net.sh).
* Cleanup code + fixed typos.

---
Although it's easy to convert these tests to handle both IPv4 and IPv6 I'll do it in a next patch-set.

---
 .../stress/multicast/grp-operation/mcast4-grpope01 | 221 ++-----------------
 .../stress/multicast/grp-operation/mcast4-grpope02 | 230 ++------------------
 .../stress/multicast/grp-operation/mcast4-grpope03 | 217 ++-----------------
 .../stress/multicast/grp-operation/mcast4-grpope04 | 236 ++-------------------
 .../stress/multicast/grp-operation/mcast4-lib.sh   | 118 +++++++++++
 5 files changed, 196 insertions(+), 826 deletions(-)
 create mode 100644 testcases/network/stress/multicast/grp-operation/mcast4-lib.sh
testcases/network/stress/multicast/grp-operation/mcast4-grpope01 +21 -200
index b03ff626b..086ecb1f9 100644
@@ -1,211 +1,32 @@
 #!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2006                 ##
-##                                                                            ##
-## 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    ##
-##                                                                            ##
-##                                                                            ##
-################################################################################
-#
-# File:
-#   mcast4-grpope01
-#
-# Description:
-#   Verify that the kernel is not crashed when joining lots of IPv4 multicast
-#   groups on a single socket
-#
-# Setup:
-#   See ltp-yyyymmdd/testcases/network/stress/README
-#
-# Author:
-#   Mitsuru Chinen <[email protected]>
-#
-# History:
-#	May 1 2006 - Created (Mitsuru Chinen)
-#
-#-----------------------------------------------------------------------
-# Uncomment line below for debug output.
-#trace_logic=${trace_logic:-"set -x"}
-$trace_logic
-
-# The test case ID, the test case count and the total number of test case
-TCID=mcast4-grpope01
-TST_TOTAL=1
-TST_COUNT=1
-export TCID
-export TST_COUNT
-export TST_TOTAL
-
-# Make sure the value of LTPROOT
-LTPROOT=${LTPROOT:-`(cd ../../../../.. ; pwd)`}
-export LTPROOT
-
-# Check the environmanet variable
-. check_envval || exit $TST_TOTAL
-
-# Number of the group
-MCASTNUM_HEAVY=${MCASTNUM_HEAVY:-40000}
-
-# The number of the test link where tests run
-LINK_NUM=${LINK_NUM:-0}
-
-# Network portion of the IPv4 address
-NETWORK_PART=${IPV4_NETWORK:-"10.0.0"}
-
-# Netmask of the IPv4 network
-NETWORK_MASK=24
-
-# Host portion of the IPv4 address
-LHOST_HOST_PART=${LHOST_IPV4_HOST:-"2"}     # local host
-RHOST_HOST_PART=${RHOST_IPV4_HOST:-"1"}     # remote host
-
-# Prefix of the Multicast Address
-MCAST_ADDR_PREFIX=224.10
-
-
-#-----------------------------------------------------------------------
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <[email protected]>
 #
-# Function: do_cleanup
+# 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.
 #
-# Description:
-#   Recover the system configuration
-#
-#-----------------------------------------------------------------------
-do_cleanup()
-{
-    # Make sure to kill the multicast receiver and sender
-    killall -SIGHUP ns-mcast_join >/dev/null 2>&1
-    $LTP_RSH $RHOST killall -SIGHUP ns-igmp_querier >/dev/null 2>&1
-
-    # Clean up each interface
-    initialize_if lhost ${LINK_NUM}
-    initialize_if rhost ${LINK_NUM}
-}
-
-
-#-----------------------------------------------------------------------
+# This program is distributed in the hope that it would 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.
 #
-# Function: do_setup
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
 #
 # Description:
-#   Configure the ssystem for the test
-#
-#-----------------------------------------------------------------------
-do_setup()
-{
-    # Initialize the system configuration
-    do_cleanup
-
-    # Call do_cleanup function before exit
-    trap do_cleanup 0
-
-    # name of interface of the local/remote host
-    lhost_ifname=`get_ifname lhost $LINK_NUM`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the local host"
-	exit $TST_TOTAL
-    fi
-
-    rhost_ifname=`get_ifname rhost $LINK_NUM`
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to get the interface name at the remote host"
-	exit $TST_TOTAL
-    fi
-
-    # Set IPv4 addresses to the interfaces
-    set_ipv4addr lhost $LINK_NUM $NETWORK_PART $LHOST_HOST_PART
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to add any IP address at the local host"
-	exit 1
-    fi
-
-    set_ipv4addr rhost $LINK_NUM $NETWORK_PART $RHOST_HOST_PART
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to add any IP address at the remote host"
-	exit 1
-    fi
-
-    # IPv4 address of the local/remote host
-    lhost_addr="${NETWORK_PART}.${LHOST_HOST_PART}"
-    rhost_addr="${NETWORK_PART}.${RHOST_HOST_PART}"
-
-    # Make sure the connectvity
-    check_icmpv4_connectivity $lhost_ifname $rhost_addr
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "There is no IPv4 connectivity."
-	exit 1
-    fi
-
-    # Make sure the sysctl values
-    sysctl -w net.ipv4.igmp_max_memberships=$MCASTNUM_HEAVY >/dev/null
-    if [ $? -ne 0 ]; then
-	tst_resm TBROK "Failed to set the sysctl value regarding multicast"
-	exit $TST_TOTAL
-    fi
-
-    sysctl -w net.ipv4.igmp_max_msf=10 >/dev/null
-    sysctl -w net.ipv4.conf.${lhost_ifname}.force_igmp_version=0 >/dev/null
-    sysctl -w net.ipv4.conf.all.force_igmp_version=0 >/dev/null
-}
-
-
-#-----------------------------------------------------------------------
-#
-# Main
-#
-#
-
-# Test description
-tst_resm TINFO "Verify that the kernel is not crashed when joining $MCASTNUM_HEAVY IPv4 multicast groups on a single socket"
-
-do_setup
-
-# Run a multicast join tool
-tmpfile=$TMPDIR/ns-mcast_join.$$
-ns-mcast_join -f 4 -I $lhost_ifname -n $MCASTNUM_HEAVY -p $MCAST_ADDR_PREFIX > $tmpfile
-if [ $? -ne 0 ]; then
-    tst_resm TBROK "Failed to start multicast joining tool Please check the environment"
-    rm -f $tmpfile
-    exit 1
-fi
-msg=`cat $tmpfile | grep groups`
-tst_resm TINFO "Joined $msg"
-rm -f $tmpfile
-
-# Send IGMP General Query from the remote host
-ret=`$LTP_RSH $RHOST ${LTPROOT}/testcases/bin/ns-igmp_querier -I $rhost_ifname -o -r 1' ; echo $?'`
-if [ $ret -ne 0 ]; then
-    tst_resm TBROK "Failed to start IGMP querier"
-    exit 1
-fi
-
-#-----------------------------------------------------------------------
+# Verify that the kernel is not crashed when joining lots of IPv4 multicast
+# groups on a single socket.
 #
-# Clean up
+# Setup: testcases/network/stress/README
 #
+# Author: Mitsuru Chinen <[email protected]>
 
-killall -SIGHUP ns-mcast_join >/dev/null 2>&1
-while true ; do
-    ps auxw | grep -v grep | grep ns-mcast_join > /dev/null
-    if [ $? -ne 0 ] ; then
-  	break
-    fi
-done
+. mcast4-lib.sh
 
-tst_resm TPASS "Test is finished successfully."
+tst_resm TINFO "joining $MCASTNUM_HEAVY IPv4 multicast groups on a single socket"
 
-exit 0
+mcast_setup $MCASTNUM_HEAVY
+do_multicast_test_multiple_join $MCASTNUM_HEAVY
+tst_exit
testcases/network/stress/multicast/grp-operation/mcast4-grpope02 +19 -211

239 lines not on this page · raw message

testcases/network/stress/multicast/grp-operation/mcast4-grpope03 +19 -198

226 lines not on this page · raw message

testcases/network/stress/multicast/grp-operation/mcast4-grpope04 +19 -217

245 lines not on this page · raw message

testcases/network/stress/multicast/grp-operation/mcast4-lib.sh new file +118 -0

118 lines not on this page · raw message

Signature · 1 line
2.14.0
#11 lore raw

RFC PATCH v9 5/7 network/stress: Fix and cleanup part of multicast IPv4 tests

Quoted 138 lines · Petr Vorel

* Fix test for SSH and netns based testing.
* Remove hardcoded rsh dependency.
* Create shell library mcast4-lib.sh (multicast IPv4 specific) to reduce duplicity in tests. Library uses test_stress_net.sh (and therefore test_net.sh).
* Cleanup code + fixed typos.

---
Although it's easy to convert these tests to handle both IPv4 and IPv6 I'll do it in a next patch-set.

---
 .../stress/multicast/grp-operation/mcast4-grpope01 | 221 ++-----------------
 .../stress/multicast/grp-operation/mcast4-grpope02 | 230 ++------------------
 .../stress/multicast/grp-operation/mcast4-grpope03 | 217 ++-----------------
 .../stress/multicast/grp-operation/mcast4-grpope04 | 236 ++-------------------
 .../stress/multicast/grp-operation/mcast4-lib.sh   | 118 +++++++++++
 5 files changed, 196 insertions(+), 826 deletions(-)
 create mode 100644 testcases/network/stress/multicast/grp-operation/mcast4-lib.sh

...

testcases/network/stress/multicast/grp-operation/mcast4-grpope04 +5 -7
-
-#-----------------------------------------------------------------------
-#
-# Clean up
-#
+. mcast4-lib.sh
 
-tst_resm TPASS "Test is finished successfully."
+tst_resm TINFO "joining and leaving the same IPv4 multicast group with a different source filters on $MCASTNUM_NORMAL sockets in $NS_TIMES times"
 
-exit 0
+mcast_setup $MCASTNUM_NORMAL
+do_multicast_test_join_leave true
+tst_exit
testcases/network/stress/multicast/grp-operation/mcast4-lib.sh new file +98 -0
new file mode 100644
index 000000000..b3ef44baa
@@ -0,0 +1,118 @@
+#!/bin/sh
+# Copyright (c) International Business Machines  Corp., 2006
+# Copyright (c) 2017 Petr Vorel <[email protected]>
+#
+# 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 would 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, see <http://www.gnu.org/licenses/>.
+#
+# Author: Petr Vorel <[email protected]>
+#
+# Setup script for mcast4-grpope* tests.
+
+TST_TOTAL=1
+TST_CLEANUP="mcast_cleanup"
+
+. test_net_stress.sh
+
+mcast_setup()
+{
+	local igmp_max_memberships="$1"
+	local increase_max="${2:-}"
+
+	netstress_setup
+	tst_tmpdir
+
+	SYSFS_IGMP_MAX_MEMBERSHIPS=$(sysctl -b net.ipv4.igmp_max_memberships)
+	SYSFS_IGMP_MAX_MSF=$(sysctl -b net.ipv4.igmp_max_msf)
+	SYSFS_FORCE_IGMP_VERSION=$(sysctl -b net.ipv4.conf.$(tst_iface).force_igmp_version)
+	SYSFS_ALL_FORCE_IGMP_VERSION=$(sysctl -b net.ipv4.conf.all.force_igmp_version)
+
+	if [ "$increase_max" = "true" ]; then
+		# Increase the maximum number of open file descriptors
+		[ $(ulimit -n) -lt $igmp_max_memberships ] && ROD ulimit -n $igmp_max_memberships
+	fi
+
+	ROD sysctl -qw net.ipv4.igmp_max_memberships=$igmp_max_memberships
+	ROD sysctl -qw net.ipv4.igmp_max_msf=10
+	ROD sysctl -qw net.ipv4.conf.$(tst_iface).force_igmp_version=0
+	ROD sysctl -qw net.ipv4.conf.all.force_igmp_version=0
+}
+
+mcast_cleanup()
+{
+	[ -n "$SYSFS_IGMP_MAX_MEMBERSHIPS" ] && sysctl -qw net.ipv4.igmp_max_memberships=$SYSFS_IGMP_MAX_MEMBERSHIPS
+	[ -n "$SYSFS_IGMP_MAX_MSF" ] && sysctl -qw net.ipv4.igmp_max_msf=$SYSFS_IGMP_MAX_MSF
+	[ -n "$SYSFS_FORCE_IGMP_VERSION" ] && sysctl -qw net.ipv4.conf.$(tst_iface).force_igmp_version=$SYSFS_FORCE_IGMP_VERSION
+	[ -n "$SYSFS_ALL_FORCE_IGMP_VERSION" ] && sysctl -qw net.ipv4.conf.all.force_igmp_version=$SYSFS_ALL_FORCE_IGMP_VERSION
+
+	pkill -SIGHUP -x ns-mcast_join
+	tst_sleep 10ms
+	pkill -9 -x ns-mcast_join
+
+	tst_rhost_run -c "pkill -SIGHUP -x ns-igmp_querier"
+
+	restore_ipaddr
+	restore_ipaddr rhost
+}
+
+do_multicast_test_multiple_join()
+{
+	local igmp_max_memberships="$1"
+	local param_multi_socket ret tmpfile
+
+	[ "${2:-}" = true ] && param_multi_socket="-m"
+
+	# Run a multicast join tool
+	tmpfile=ns-mcast_join.$$
+
+	EXPECT_PASS ns-mcast_join $param_multi_socket -f 4 -I $(tst_iface) -n $igmp_max_memberships -p $MCAST_IPV4_ADDR_PREFIX \> $tmpfile
+
+	tst_resm TINFO "joined $(grep groups $tmpfile)"
+
+	# Send IGMP General Query from the remote host
+	EXPECT_RHOST_PASS ns-igmp_querier -I $(tst_iface rhost) -o -r 1 -m $MCAST_IPV4_ADDR
+}
+
+do_multicast_test_join_leave()
+{
+	local cnt define_src_addr filter params ret src_addr x y
+
+	[ "$1" = true ] && define_src_addr=true
+
+	# Send IGMP General Query from the remote host
+	tst_rhost_run -s -c "ns-igmp_querier -I $(tst_iface rhost) -i 1000000000 -r 1 -b"
+
+	# Run a multicast join tool
+	cnt=0
+	while [ $cnt -lt $NS_TIMES ]; do
+		if [ "$define_src_addr" ]; then

testcases/network/stress/multicast/grp-operation/mcast4-lib.sh line 108

Quoted 10 lines
testcases/network/stress/multicast/grp-operation/mcast4-lib.sh new file +10 -0
+			x=$(($cnt / 254))
+			y=$(($cnt % 254 + 1))
+			if [ $x -gt 254 ]; then
+				tst_resm TINFO "the number of the connection is less than $cnt"
+				break
+			fi
+			src_addr=$(tst_ipaddr_un $x $y)
+
+			[ $((cnt % 5)) -ne 2 ] && filter="include" || filter="exclude"
+			params="-F $filter -s $src_addr"

Why not params="-F $filter -s $(tst_ipaddr_un -c$cnt)"?

Thanks,
Alexey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20170908/929f6c03/attachment.html>

author
#12 lore raw

RFC PATCH v9 5/7 network/stress: Fix and cleanup part of multicast IPv4 tests

Hi Alexey,

Quoted 1 line
Quoted 1 line

+++ b/testcases/network/stress/multicast/grp-operation/mcast4-lib.sh

...

Quoted 4 lines
Quoted 4 lines
testcases/network/stress/multicast/grp-operation/mcast4-lib.sh new file +4 -0
+do_multicast_test_join_leave()
+{
+	local cnt define_src_addr filter params ret src_addr x y
+
Quoted 8 lines

testcases/network/stress/multicast/grp-operation/mcast4-lib.sh line 97

Quoted 8 lines
testcases/network/stress/multicast/grp-operation/mcast4-lib.sh new file +8 -0
+	[ "$1" = true ] && define_src_addr=true
+
+	# Send IGMP General Query from the remote host
+	tst_rhost_run -s -c "ns-igmp_querier -I $(tst_iface rhost) -i 1000000000 -r 1 -b"
+
+	# Run a multicast join tool
+	cnt=0
+	while [ $cnt -lt $NS_TIMES ]; do

This is actually wrong variable ($MCASTNUM_NORMAL should be used or better variable passed by script which call this function). I'll plan to fix it in next version. With new version I also plan to switch it to be for both IPv4 and IPv6.

Quoted 6 lines
Quoted 6 lines
testcases/network/stress/multicast/grp-operation/mcast4-lib.sh new file +6 -0
+		if [ "$define_src_addr" ]; then
+			x=$(($cnt / 254))
+			y=$(($cnt % 254 + 1))
+			if [ $x -gt 254 ]; then
+				tst_resm TINFO "the number of the connection is less than $cnt"
+				break
Quoted 8 lines

testcases/network/stress/multicast/grp-operation/mcast4-lib.sh line 108

Quoted 5 lines
testcases/network/stress/multicast/grp-operation/mcast4-lib.sh new file +5 -0
+			fi
+			src_addr=$(tst_ipaddr_un $x $y)
+
+			[ $((cnt % 5)) -ne 2 ] && filter="include" || filter="exclude"
+			params="-F $filter -s $src_addr"

Why not params="-F $filter -s $(tst_ipaddr_un -c$cnt)"?

The original test runs:
ns-mcast_join -f 4 -I -l 65024 -a 224.10.10.1 -F include -s 10.10.0.1 & ns-mcast_join -f 4 -I -l 65024 -a 224.10.10.1 -F include -s 10.10.0.2 &
...
ns-mcast_join -f 4 -I -l 65024 -a 224.10.10.1 -F include -s 10.10.254.253 & ns-mcast_join -f 4 -I -l 65024 -a 224.10.10.1 -F include -s 10.10.254.254 &

=> it breaks loop if $NS_TIMES (or whatever variable is used) > 254*254 (=64516).

With -c switch $(tst_ipaddr_un -c$cnt)" we get half of IP's for the limit (as we're using just lhost IP's)
for cnt -lt $((254*255))

ns-mcast_join -f 4 -I ltp_ns_veth2 -l 3 -a 224.10.10.1 -F include -s 10.23.251.2 ns-mcast_join -f 4 -I ltp_ns_veth2 -l 3 -a 224.10.10.1 -F include -s 10.23.251.4
...
ns-mcast_join -f 4 -I ltp_ns_veth2 -l 3 -a 224.10.10.1 -F include -s 10.23.254.252 ns-mcast_join -f 4 -I ltp_ns_veth2 -l 3 -a 224.10.10.1 -F include -s 10.23.254.254

I suppose I can remove this limit.

Kind regards,
Petr

author
#13 lore raw

RFC PATCH v9 6/7 network: Add tools for setup IP related environment variables

In reply to Petr Vorel

New tools:
* tst_net_ip_prefix
Strip prefix from IP address and save both
If no prefix found sets default prefix.

* tst_net_iface_prefix
tst_net_iface_prefix reads prefix and interface from rtnetlink.

* tst_net_vars takes input of local and remote address and setup most of test link (IP related) environment variables.

NOTABLE CHANGES IN ENVIRONMENT VARIABLES:
Network variables are defined for both local and remote:
IPV4_NETWORK was replaced by IPV4_LNETWORK and IPV4_RNETWORK IPV6_NETWORK was replaced by IPV6_LNETWORK and IPV6_RNETWORK

NEW VARIABLES:
IPV4_LHOST, IPV4_RHOST, IPV4_LNETMASK, IPV4_RNETMASK, IPV4_LPREFIX, IPV4_RPREFIX, IPV6_LHOST, IPV6_RHOST, IPV6_LNETMASK, IPV6_RNETMASK, IPV6_LPREFIX, IPV6_RPREFIX,

For full list of environment variables which tools setup run:
tst_net_ip_prefix -h
tst_net_iface_prefix -h
tst_net_vars -h

Thanks a lot to Alexey Kodanev who reviewed many versions of this patch and give feedback and pointed out errors, as well as to Cyril Hrubis who reviewed orignal version of tst_net_vars.c.

---
 include/tst_net.h                    | 153 +++++++++
 testcases/lib/.gitignore             |   3 +
 testcases/lib/Makefile               |   2 +-
 testcases/lib/tst_net_iface_prefix.c | 180 ++++++++++
 testcases/lib/tst_net_ip_prefix.c    | 123 +++++++
 testcases/lib/tst_net_vars.c         | 645 +++++++++++++++++++++++++++++++++++
 6 files changed, 1105 insertions(+), 1 deletion(-)
 create mode 100644 include/tst_net.h
 create mode 100644 testcases/lib/tst_net_iface_prefix.c
 create mode 100644 testcases/lib/tst_net_ip_prefix.c
 create mode 100644 testcases/lib/tst_net_vars.c
include/tst_net.h new file +153 -0
new file mode 100644
index 000000000..cb97b7b61
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2017 Petr Vorel <[email protected]>
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <arpa/inet.h>
+#include <errno.h>
+
+#define MAX_IPV4_PREFIX 32
+#define MAX_IPV6_PREFIX 128
+
+#define tst_res_comment(...) { \
+	fprintf(stderr, "# "); \
+	tst_res(__VA_ARGS__); } \
+
+
+#define tst_brk_comment(...) { \
+	fprintf(stderr, "# "); \
+	tst_brk(TCONF, __VA_ARGS__); } \
+
+static inline void print_svar(const char *name, const char *val)
+{
+	if (name && val)
+		printf("export %s=\"%s\"\n", name, val);
+}
+
+static inline void print_svar_change(const char *name, const char *val)
+{
+	if (name && val)
+		printf("export %s=\"${%s:-%s}\"\n", name, name, val);
+}
+
+/*
+ * Function bit_count is from ipcalc project, ipcalc.c.
+ */
+static int bit_count(uint32_t i)
+{
+	int c = 0;
+	unsigned int seen_one = 0;
+
+	while (i > 0) {
+		if (i & 1) {
+			seen_one = 1;
+			c++;
+		} else {
+			if (seen_one)
+				return -1;
+		}
+		i >>= 1;
+	}
+
+	return c;
+}
+
+/*
+ * Function mask2prefix is from ipcalc project, ipcalc.c.
+ */
+static int mask2prefix(struct in_addr mask)
+{
+	return bit_count(ntohl(mask.s_addr));
+}
+
+/*
+ * Function ipv4_mask_to_int is from ipcalc project, ipcalc.c.
+ */
+static int ipv4_mask_to_int(const char *prefix)
+{
+	int ret;
+	struct in_addr in;
+
+	ret = inet_pton(AF_INET, prefix, &in);
+	if (ret == 0)
+		return -1;
+
+	return mask2prefix(in);
+}
+
+/*
+ * Function safe_atoi is from ipcalc project, ipcalc.c.
+ */
+static int safe_atoi(const char *s, int *ret_i)
+{
+	char *x = NULL;
+	long l;
+
+	errno = 0;
+	l = strtol(s, &x, 0);
+
+	if (!x || x == s || *x || errno)
+		return errno > 0 ? -errno : -EINVAL;
+
+	if ((long)(int)l != l)
+		return -ERANGE;
+
+	*ret_i = (int)l;
+
+	return 0;
+}
+
+/*
+ * Function get_prefix use code from ipcalc project, str_to_prefix/ipcalc.c.
+ */
+static int get_prefix(const char *ip_str, int is_ipv6)
+{
+	char *prefix_str = NULL;
+	int prefix = -1, r;
+
+	prefix_str = strchr(ip_str, '/');
+	if (!prefix_str)
+		return -1;
+
+	*(prefix_str++) = '\0';
+
+	if (!is_ipv6 && strchr(prefix_str, '.'))
+		prefix = ipv4_mask_to_int(prefix_str);
+	else {
+		r = safe_atoi(prefix_str, &prefix);
+		if (r != 0)
+			tst_brk_comment("conversion error: '%s' is not integer",
+					prefix_str);
+	}
+
+	if (prefix < 0 || ((is_ipv6 && prefix > MAX_IPV6_PREFIX) ||
+		(!is_ipv6 && prefix > MAX_IPV4_PREFIX)))
+		tst_brk_comment("bad %s prefix: %s", is_ipv6 ?  "IPv6" : "IPv4",
+				prefix_str);
+
+	return prefix;
+}
+
+static void get_in_addr(const char *ip_str, struct in_addr *ip)
+{
+	if (inet_pton(AF_INET, ip_str, ip) <= 0)
+		tst_brk_comment("bad IPv4 address: '%s'", ip_str);
+}
+
+static void get_in6_addr(const char *ip_str, struct in6_addr *ip6)
+{
+	if (inet_pton(AF_INET6, ip_str, ip6) <= 0)
+		tst_brk_comment("bad IPv6 address: '%s'", ip_str);
+}
testcases/lib/.gitignore +3 -0
index 522889bed..f36ed99fa 100644
@@ -4,3 +4,6 @@
 /tst_rod
 /tst_kvcmp
 /tst_device
+/tst_net_iface_prefix
+/tst_net_ip_prefix
+/tst_net_vars
testcases/lib/Makefile +1 -1
index 1127a59fe..398150ae0 100644
@@ -27,6 +27,6 @@ include $(top_srcdir)/include/mk/testcases.mk
 INSTALL_TARGETS		:= *.sh
 
 MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\
-			   tst_device
+			   tst_device tst_net_iface_prefix tst_net_ip_prefix tst_net_vars
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/lib/tst_net_iface_prefix.c new file +180 -0

180 lines not on this page · raw message

testcases/lib/tst_net_ip_prefix.c new file +123 -0

123 lines not on this page · raw message

testcases/lib/tst_net_vars.c new file +645 -0

645 lines not on this page · raw message

Signature · 1 line
2.14.0
#14 lore raw

RFC PATCH v9 6/7 network: Add tools for setup IP related environment variables

Quoted 20 lines · Petr Vorel

New tools:
* tst_net_ip_prefix
Strip prefix from IP address and save both
If no prefix found sets default prefix.

* tst_net_iface_prefix
tst_net_iface_prefix reads prefix and interface from rtnetlink.

* tst_net_vars takes input of local and remote address and setup most of test link (IP related) environment variables.

NOTABLE CHANGES IN ENVIRONMENT VARIABLES:
Network variables are defined for both local and remote:
IPV4_NETWORK was replaced by IPV4_LNETWORK and IPV4_RNETWORK IPV6_NETWORK was replaced by IPV6_LNETWORK and IPV6_RNETWORK

NEW VARIABLES:
IPV4_LHOST, IPV4_RHOST, IPV4_LNETMASK, IPV4_RNETMASK, IPV4_LPREFIX, IPV4_RPREFIX, IPV6_LHOST, IPV6_RHOST, IPV6_LNETMASK, IPV6_RNETMASK, IPV6_LPREFIX, IPV6_RPREFIX,

Quoted 8 lines

For full list of environment variables which tools setup run:
tst_net_ip_prefix -h
tst_net_iface_prefix -h
tst_net_vars -h

Thanks a lot to Alexey Kodanev who reviewed many versions of this patch and give feedback and pointed out errors, as well as to Cyril Hrubis who reviewed orignal version of tst_net_vars.c.

Applied with minor changes below, thank you!

Quoted 225 lines
---
 include/tst_net.h                    | 153 +++++++++
 testcases/lib/.gitignore             |   3 +
 testcases/lib/Makefile               |   2 +-
 testcases/lib/tst_net_iface_prefix.c | 180 ++++++++++
 testcases/lib/tst_net_ip_prefix.c    | 123 +++++++
 testcases/lib/tst_net_vars.c         | 645 +++++++++++++++++++++++++++++++++++
 6 files changed, 1105 insertions(+), 1 deletion(-)
 create mode 100644 include/tst_net.h
 create mode 100644 testcases/lib/tst_net_iface_prefix.c
 create mode 100644 testcases/lib/tst_net_ip_prefix.c
 create mode 100644 testcases/lib/tst_net_vars.c
include/tst_net.h new file +153 -0
new file mode 100644
index 000000000..cb97b7b61
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2017 Petr Vorel <[email protected]>
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <arpa/inet.h>
+#include <errno.h>
+
+#define MAX_IPV4_PREFIX 32
+#define MAX_IPV6_PREFIX 128
+
+#define tst_res_comment(...) { \
+	fprintf(stderr, "# "); \
+	tst_res(__VA_ARGS__); } \
+
+
+#define tst_brk_comment(...) { \
+	fprintf(stderr, "# "); \
+	tst_brk(TCONF, __VA_ARGS__); } \
+
+static inline void print_svar(const char *name, const char *val)
+{
+	if (name && val)
+		printf("export %s=\"%s\"\n", name, val);
+}
+
+static inline void print_svar_change(const char *name, const char *val)
+{
+	if (name && val)
+		printf("export %s=\"${%s:-%s}\"\n", name, name, val);
+}
+
+/*
+ * Function bit_count is from ipcalc project, ipcalc.c.
+ */
+static int bit_count(uint32_t i)
+{
+	int c = 0;
+	unsigned int seen_one = 0;
+
+	while (i > 0) {
+		if (i & 1) {
+			seen_one = 1;
+			c++;
+		} else {
+			if (seen_one)
+				return -1;
+		}
+		i >>= 1;
+	}
+
+	return c;
+}
+
+/*
+ * Function mask2prefix is from ipcalc project, ipcalc.c.
+ */
+static int mask2prefix(struct in_addr mask)
+{
+	return bit_count(ntohl(mask.s_addr));
+}
+
+/*
+ * Function ipv4_mask_to_int is from ipcalc project, ipcalc.c.
+ */
+static int ipv4_mask_to_int(const char *prefix)
+{
+	int ret;
+	struct in_addr in;
+
+	ret = inet_pton(AF_INET, prefix, &in);
+	if (ret == 0)
+		return -1;
+
+	return mask2prefix(in);
+}
+
+/*
+ * Function safe_atoi is from ipcalc project, ipcalc.c.
+ */
+static int safe_atoi(const char *s, int *ret_i)
+{
+	char *x = NULL;
+	long l;
+
+	errno = 0;
+	l = strtol(s, &x, 0);
+
+	if (!x || x == s || *x || errno)
+		return errno > 0 ? -errno : -EINVAL;
+
+	if ((long)(int)l != l)
+		return -ERANGE;
+
+	*ret_i = (int)l;
+
+	return 0;
+}
+
+/*
+ * Function get_prefix use code from ipcalc project, str_to_prefix/ipcalc.c.
+ */
+static int get_prefix(const char *ip_str, int is_ipv6)
+{
+	char *prefix_str = NULL;
+	int prefix = -1, r;
+
+	prefix_str = strchr(ip_str, '/');
+	if (!prefix_str)
+		return -1;
+
+	*(prefix_str++) = '\0';
+
+	if (!is_ipv6 && strchr(prefix_str, '.'))
+		prefix = ipv4_mask_to_int(prefix_str);
+	else {
+		r = safe_atoi(prefix_str, &prefix);
+		if (r != 0)
+			tst_brk_comment("conversion error: '%s' is not integer",
+					prefix_str);
+	}
+
+	if (prefix < 0 || ((is_ipv6 && prefix > MAX_IPV6_PREFIX) ||
+		(!is_ipv6 && prefix > MAX_IPV4_PREFIX)))
+		tst_brk_comment("bad %s prefix: %s", is_ipv6 ?  "IPv6" : "IPv4",
+				prefix_str);
+
+	return prefix;
+}
+
+static void get_in_addr(const char *ip_str, struct in_addr *ip)
+{
+	if (inet_pton(AF_INET, ip_str, ip) <= 0)
+		tst_brk_comment("bad IPv4 address: '%s'", ip_str);
+}
+
+static void get_in6_addr(const char *ip_str, struct in6_addr *ip6)
+{
+	if (inet_pton(AF_INET6, ip_str, ip6) <= 0)
+		tst_brk_comment("bad IPv6 address: '%s'", ip_str);
+}
testcases/lib/.gitignore +3 -0
index 522889bed..f36ed99fa 100644
@@ -4,3 +4,6 @@
 /tst_rod
 /tst_kvcmp
 /tst_device
+/tst_net_iface_prefix
+/tst_net_ip_prefix
+/tst_net_vars
testcases/lib/Makefile +1 -1
index 1127a59fe..398150ae0 100644
@@ -27,6 +27,6 @@ include $(top_srcdir)/include/mk/testcases.mk
 INSTALL_TARGETS		:= *.sh
 
 MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\
-			   tst_device
+			   tst_device tst_net_iface_prefix tst_net_ip_prefix tst_net_vars
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/lib/tst_net_iface_prefix.c new file +23 -0
new file mode 100644
index 000000000..c5cc61a0b
@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 2017 Petr Vorel <[email protected]>
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/rtnetlink.h>
+#include <net/if.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define TST_NO_DEFAULT_MAIN

testcases/lib/tst_net_iface_prefix.c line 33

Quoted 10 lines
testcases/lib/tst_net_iface_prefix.c new file +10 -0
+#include "tst_test.h"
+
+#include "tst_net.h"
+
+typedef struct data {
+	char *ifname;
+	int prefix;
+} data;
+
+static data vars;

removed struct data

Quoted 6 lines
testcases/lib/tst_net_iface_prefix.c new file +6 -0
+
+static void usage(const char *cmd)
+{
+	fprintf(stderr, "USAGE:\n"
+		"%s IPV4_LHOST/IPV4_LPREFIX\n"
+		"%s -r IPV4_RHOST/IPV4_RPREFIX\n"

testcases/lib/tst_net_iface_prefix.c line 49

Quoted 10 lines
testcases/lib/tst_net_iface_prefix.c new file +10 -0
+		"%s IPV6_LHOST/IPV6_LPREFIX\n"
+		"%s -r IPV6_RHOST/IPV6_RPREFIX\n\n"
+		"%s IPV4_LHOST\n"
+		"%s -r IPV4_RHOST\n\n"
+		"%s IPV6_LHOST\n"
+		"%s -r IPV6_RHOST\n\n"
+		"%s -h\n\n"
+		"Set prefix and interface name for given IP.\n"
+		"Tries to find prefix and interface from kernel exported info (rtnetlink).\n\n"
+		"If prefix is not provided, is tried to be detected from rtnetlink data for local IP address, which is used for remote prefix as well. If is not found use default values.\n"

removed redundant description

Quoted 70 lines
testcases/lib/tst_net_iface_prefix.c new file +70 -0
+		"EXPORTED VARIABLES:\n"
+		"Export one of following variables:\n"
+		"Export one of following variables:\n"
+		"IPV4_LPREFIX: IPv4 prefix for IPV4_LNETWORK\n"
+		"IPV4_RPREFIX: IPv4 prefix for IPV4_RNETWORK\n"
+		"IPV6_LPREFIX: IPv6 prefix for IPV6_LNETWORK\n"
+		"IPV6_RPREFIX: IPv6 prefix for IPV6_RNETWORK\n"
+		"Export one of following variables (if found):\n"
+		"LHOST_IFACES: iface name of the local host (*)\n"
+		"RHOST_IFACES: iface name of the remote host (*)\n\n"
+		"(*): respect user settings\n"
+		"Iface (LHOST_IFACES, RHOST_IFACES) as user might want to use more ifaces.\n\n"
+		"PARAMS:\n"
+		"-h this help\n"
+		"-r export remote environment variables\n",
+		cmd, cmd, cmd, cmd, cmd, cmd, cmd, cmd, cmd);
+}
+
+static int read_iface_prefix(const char *ip_str, int is_ipv6)
+{
+	uint8_t family = is_ipv6 ? AF_INET6 : AF_INET;
+
+	char buf[16384];
+	int len;
+
+	struct {
+		struct nlmsghdr nlhdr;
+		struct ifaddrmsg addrmsg;
+	} msg;
+
+	struct nlmsghdr *retmsg;
+
+	int sock = SAFE_SOCKET(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+
+	memset(&msg, 0, sizeof(msg));
+	msg.nlhdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
+	msg.nlhdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT;
+	msg.nlhdr.nlmsg_type = RTM_GETADDR;
+	msg.addrmsg.ifa_family = family;
+
+	SAFE_SEND(1, sock, &msg, msg.nlhdr.nlmsg_len, 0);
+	len = recv(sock, buf, sizeof(buf), 0);
+	retmsg = (struct nlmsghdr *)buf;
+
+	while NLMSG_OK(retmsg, len) {
+		char ifname[IFNAMSIZ];
+		struct ifaddrmsg *retaddr;
+		struct rtattr *retrta;
+		char pradd[128];
+		int attlen;
+
+		retaddr = (struct ifaddrmsg *)NLMSG_DATA(retmsg);
+		retrta = (struct rtattr *)IFA_RTA(retaddr);
+		attlen = IFA_PAYLOAD(retmsg);
+
+		while RTA_OK(retrta, attlen) {
+			if (retrta->rta_type == IFA_ADDRESS) {
+				inet_ntop(family, RTA_DATA(retrta), pradd,
+					  sizeof(pradd));
+
+				if_indextoname(retaddr->ifa_index, ifname);
+
+				if (!strcmp(pradd, ip_str)) {
+					vars.prefix = retaddr->ifa_prefixlen;
+					vars.ifname = strdup(ifname);
+					return 0;
+				}
+			}
+			retrta = RTA_NEXT(retrta, attlen);
+		}

testcases/lib/tst_net_iface_prefix.c line 129

Quoted 10 lines
testcases/lib/tst_net_iface_prefix.c new file +10 -0
+		retmsg = NLMSG_NEXT(retmsg, len);
+	}
+
+	return -1;
+}
+
+static void print_ivar(const char *name, unsigned int val)
+{
+	if (name)
+		printf("export %s=%d\n", name, val);

removed the check for 'name' as it's always not NULL.

Quoted 82 lines
testcases/lib/tst_net_iface_prefix.c new file +51 -0
+}
+
+int main(int argc, char *argv[])
+{
+	char *ip_str = NULL, *prefix_str = NULL;
+	int is_ipv6, is_rhost = 0;
+	struct in_addr ip;
+	struct in6_addr ip6;
+
+	int is_usage = argc > 1 && (!strcmp(argv[1], "-h") ||
+		!strcmp(argv[1], "--help"));
+	if (argc < 2 || is_usage) {
+		usage(argv[0]);
+		exit(is_usage ? EXIT_SUCCESS : EXIT_FAILURE);
+	}
+	if (!strcmp(argv[1], "-r"))
+		is_rhost = 1;
+
+	ip_str = argv[is_rhost ? 2 : 1];
+	is_ipv6 = !!strchr(ip_str, ':');
+
+	prefix_str = strchr(ip_str, '/');
+	if (prefix_str) {
+		vars.prefix = get_prefix(ip_str, is_ipv6);
+		tst_res_comment(TINFO,
+			"IP address '%s' contains prefix %d, using it and don't search for iface.\n",
+			ip_str, vars.prefix);
+	} else if (read_iface_prefix(ip_str, is_ipv6)) {
+		tst_res_comment(TINFO,
+			"prefix and interface not found for '%s'.\n", ip_str);
+		exit(EXIT_SUCCESS);
+	}
+
+	/* checks for validity of IP string */
+	if (is_ipv6)
+		get_in6_addr(ip_str, &ip6);
+	else
+		get_in_addr(ip_str, &ip);
+
+	if (is_ipv6) {
+		print_svar_change("LHOST_IFACES", vars.ifname);
+		print_ivar(is_rhost ? "IPV6_RPREFIX" : "IPV6_LPREFIX",
+			vars.prefix);
+	} else {
+		print_svar_change("RHOST_IFACES", vars.ifname);
+		print_ivar(is_rhost ? "IPV4_RPREFIX" : "IPV4_LPREFIX",
+			vars.prefix);
+	}
+
+	exit(EXIT_SUCCESS);
+}
testcases/lib/tst_net_ip_prefix.c new file +25 -0
new file mode 100644
index 000000000..6654f75a9
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2017 Petr Vorel <[email protected]>
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/rtnetlink.h>
+#include <net/if.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+

testcases/lib/tst_net_ip_prefix.c line 35

Quoted 10 lines
testcases/lib/tst_net_ip_prefix.c new file +10 -0
+#include "tst_net.h"
+
+#define DEFAULT_IPV4_PREFIX 24
+#define DEFAULT_IPV6_PREFIX 64
+
+typedef struct data {
+	int prefix;
+} data;
+
+static data vars;

removed 'struct data' here as well and defined 'prefix' as a local variable in main().

Quoted 5 lines
testcases/lib/tst_net_ip_prefix.c new file +5 -0
+
+static void usage(const char *cmd)
+{
+	fprintf(stderr, "USAGE:\n"
+		"%s IPV4_LHOST/IPV4_LPREFIX\n"

testcases/lib/tst_net_ip_prefix.c line 50

Quoted 10 lines
testcases/lib/tst_net_ip_prefix.c new file +10 -0
+		"%s -r IPV4_RHOST/IPV4_RPREFIX\n"
+		"%s IPV6_LHOST/IPV6_LPREFIX\n"
+		"%s -r IPV6_RHOST/IPV6_RPREFIX\n\n"
+		"%s IPV4_LHOST\n"
+		"%s -r IPV4_RHOST\n\n"
+		"%s IPV6_LHOST\n"
+		"%s -r IPV6_RHOST\n\n"
+		"%s -h\n\n"
+		"Set IP without prefix and prefix for given IP.\n"
+		"If prefix is not provided, is tried to be detected from rtnetlink data for local IP address, which is used for remote prefix as well. If is not found use default values.\n"

Fixed description here (it's not using rtnetlink).

Thanks,
Alexey

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20170908/07cd5a93/attachment-0001.html>

#15 lore raw

RFC PATCH v9 6/7 network: Add tools for setup IP related environment variables

----- Original Message -----

Quoted 31 lines · Petr Vorel

New tools:
* tst_net_ip_prefix
Strip prefix from IP address and save both
If no prefix found sets default prefix.

* tst_net_iface_prefix
tst_net_iface_prefix reads prefix and interface from rtnetlink.

* tst_net_vars takes input of local and remote address and setup most of test link (IP related) environment variables.

NOTABLE CHANGES IN ENVIRONMENT VARIABLES:
Network variables are defined for both local and remote:
IPV4_NETWORK was replaced by IPV4_LNETWORK and IPV4_RNETWORK IPV6_NETWORK was replaced by IPV6_LNETWORK and IPV6_RNETWORK

NEW VARIABLES:
IPV4_LHOST, IPV4_RHOST, IPV4_LNETMASK, IPV4_RNETMASK, IPV4_LPREFIX, IPV4_RPREFIX,
IPV6_LHOST, IPV6_RHOST, IPV6_LNETMASK, IPV6_RNETMASK, IPV6_LPREFIX, IPV6_RPREFIX,

For full list of environment variables which tools setup run:
tst_net_ip_prefix -h
tst_net_iface_prefix -h
tst_net_vars -h

Quoted 5 lines

Thanks a lot to Alexey Kodanev who reviewed many versions of this patch and give feedback and pointed out errors, as well as to Cyril Hrubis who reviewed orignal version of tst_net_vars.c.

Applied with minor changes below, thank you!

Hi,

this breaks the build for me on older RHELs.
I can build it OK with HEAD at
782ed69385e1 "network/stress: Reduce the default number of cycles for various tests"
but later commits fail.

RHEL5.6:
---------

make[2]: Entering directory `/root/ltp/testcases/lib'
gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -D_FORTIFY_SOURCE=2 -I../../include -I../../include -I../../in
clude/old/ -L../../lib tst_net_iface_prefix.c -lltp -o tst_net_iface_prefix
In file included from /usr/include/net/if.h:26,

                 from tst_net_iface_prefix.c:19:

/usr/include/sys/types.h:46: error: conflicting types for ‘loff_t’ /usr/include/linux/types.h:30: error: previous declaration of ‘loff_t’ was here /usr/include/sys/types.h:62: error: conflicting types for ‘dev_t’ /usr/include/linux/types.h:13: error: previous declaration of ‘dev_t’ was here In file included from /usr/include/sys/types.h:133,

                 from /usr/include/net/if.h:26,
                 from tst_net_iface_prefix.c:19:
/usr/include/time.h:105: error: conflicting types for ‘timer_t’
/usr/include/linux/types.h:22: error: previous declaration of ‘timer_t’ was here
In file included from /usr/include/net/if.h:26,
                 from tst_net_iface_prefix.c:19:

/usr/include/sys/types.h:198: error: conflicting types for ‘int64_t’ /usr/include/linux/types.h:98: error: previous declaration of ‘int64_t’ was here /usr/include/sys/types.h:204: error: conflicting types for ‘u_int64_t’ /usr/include/linux/types.h:97: error: previous declaration of ‘u_int64_t’ was here In file included from /usr/include/sys/types.h:220,

                 from /usr/include/net/if.h:26,
                 from tst_net_iface_prefix.c:19:
/usr/include/sys/select.h:78: error: conflicting types for ‘fd_set’
/usr/include/linux/types.h:12: error: previous declaration of ‘fd_set’ was here
In file included from /usr/include/net/if.h:26,
                 from tst_net_iface_prefix.c:19:
/usr/include/sys/types.h:235: error: conflicting types for ‘blkcnt_t’
/usr/include/linux/types.h:114: error: previous declaration of ‘blkcnt_t’ was here
In file included from /usr/include/sys/uio.h:29,
                 from /usr/include/sys/socket.h:27,
                 from /usr/include/net/if.h:27,
                 from tst_net_iface_prefix.c:19:
/usr/include/bits/uio.h:45: error: redefinition of ‘struct iovec’
In file included from /usr/include/sys/socket.h:35,
                 from /usr/include/net/if.h:27,
                 from tst_net_iface_prefix.c:19:

/usr/include/bits/socket.h:146: error: redefinition of ‘struct sockaddr’ /usr/include/bits/socket.h:163: error: redefinition of ‘struct __kernel_sockaddr_storage’ /usr/include/bits/socket.h:173: error: expected identifier before numeric constant /usr/include/bits/socket.h:216: error: redefinition of ‘struct msghdr’ /usr/include/bits/socket.h:234: error: redefinition of ‘struct cmsghdr’ /usr/include/bits/socket.h:264: error: conflicting types for ‘__cmsg_nxthdr’ /usr/include/linux/socket.h:129: error: previous definition of ‘__cmsg_nxthdr’ was here /usr/include/bits/socket.h:292: error: expected identifier before numeric constant /usr/include/bits/socket.h:303: error: redefinition of ‘struct ucred’ /usr/include/bits/socket.h:315: error: redefinition of ‘struct linger’
In file included from /usr/include/netinet/in.h:23,

                 from ../../include/tst_safe_net.h:23,
                 from ../../include/tst_test.h:82,
                 from tst_net_iface_prefix.c:24:

/usr/include/stdint.h:56: error: conflicting types for ‘uint64_t’ /usr/include/linux/types.h:96: error: previous declaration of ‘uint64_t’ was here tst_net_iface_prefix.c: In function ‘read_iface_prefix’:
tst_net_iface_prefix.c:80: warning: comparison between signed and unsigned make[2]: *** [tst_net_iface_prefix] Error 1
make[2]: Leaving directory `/root/ltp/testcases/lib'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/root/ltp/testcases'
make: *** [testcases-all] Error 2

RHEL6.0:
---------

make[2]: Entering directory `/root/ltp/testcases/lib'
gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -D_FORTIFY_SOURCE=2 -I../../include -I../../include -I../../include/old/ -L../../lib tst_net_iface_prefix.c -lltp -o tst_net_iface_prefix
In file included from /usr/include/linux/rtnetlink.h:5,

                 from tst_net_iface_prefix.c:18:

/usr/include/linux/netlink.h:34: error: expected specifier-qualifier-list before ‘sa_family_t’ tst_net_iface_prefix.c: In function ‘read_iface_prefix’:
tst_net_iface_prefix.c:80: warning: comparison between signed and unsigned integer expressions make[2]: *** [tst_net_iface_prefix] Error 1
make[2]: Leaving directory `/root/ltp/testcases/lib'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/root/ltp/testcases'
make: *** [testcases-all] Error 2

Regards,
Jan

author
#16 lore raw

RFC PATCH v9 6/7 network: Add tools for setup IP related environment variables

Hi Jan,

Quoted 78 lines

Hi,

this breaks the build for me on older RHELs.
I can build it OK with HEAD at
782ed69385e1 "network/stress: Reduce the default number of cycles for various tests"
but later commits fail.

RHEL5.6:
---------

make[2]: Entering directory `/root/ltp/testcases/lib'
gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -D_FORTIFY_SOURCE=2 -I../../include -I../../include -I../../in
clude/old/ -L../../lib tst_net_iface_prefix.c -lltp -o tst_net_iface_prefix
In file included from /usr/include/net/if.h:26,

                 from tst_net_iface_prefix.c:19:

/usr/include/sys/types.h:46: error: conflicting types for ‘loff_t’ /usr/include/linux/types.h:30: error: previous declaration of ‘loff_t’ was here /usr/include/sys/types.h:62: error: conflicting types for ‘dev_t’ /usr/include/linux/types.h:13: error: previous declaration of ‘dev_t’ was here In file included from /usr/include/sys/types.h:133,

                 from /usr/include/net/if.h:26,
                 from tst_net_iface_prefix.c:19:
/usr/include/time.h:105: error: conflicting types for ‘timer_t’
/usr/include/linux/types.h:22: error: previous declaration of ‘timer_t’ was here
In file included from /usr/include/net/if.h:26,
                 from tst_net_iface_prefix.c:19:

/usr/include/sys/types.h:198: error: conflicting types for ‘int64_t’ /usr/include/linux/types.h:98: error: previous declaration of ‘int64_t’ was here /usr/include/sys/types.h:204: error: conflicting types for ‘u_int64_t’ /usr/include/linux/types.h:97: error: previous declaration of ‘u_int64_t’ was here In file included from /usr/include/sys/types.h:220,

                 from /usr/include/net/if.h:26,
                 from tst_net_iface_prefix.c:19:
/usr/include/sys/select.h:78: error: conflicting types for ‘fd_set’
/usr/include/linux/types.h:12: error: previous declaration of ‘fd_set’ was here
In file included from /usr/include/net/if.h:26,
                 from tst_net_iface_prefix.c:19:
/usr/include/sys/types.h:235: error: conflicting types for ‘blkcnt_t’
/usr/include/linux/types.h:114: error: previous declaration of ‘blkcnt_t’ was here
In file included from /usr/include/sys/uio.h:29,
                 from /usr/include/sys/socket.h:27,
                 from /usr/include/net/if.h:27,
                 from tst_net_iface_prefix.c:19:
/usr/include/bits/uio.h:45: error: redefinition of ‘struct iovec’
In file included from /usr/include/sys/socket.h:35,
                 from /usr/include/net/if.h:27,
                 from tst_net_iface_prefix.c:19:

/usr/include/bits/socket.h:146: error: redefinition of ‘struct sockaddr’ /usr/include/bits/socket.h:163: error: redefinition of ‘struct __kernel_sockaddr_storage’ /usr/include/bits/socket.h:173: error: expected identifier before numeric constant /usr/include/bits/socket.h:216: error: redefinition of ‘struct msghdr’ /usr/include/bits/socket.h:234: error: redefinition of ‘struct cmsghdr’ /usr/include/bits/socket.h:264: error: conflicting types for ‘__cmsg_nxthdr’ /usr/include/linux/socket.h:129: error: previous definition of ‘__cmsg_nxthdr’ was here /usr/include/bits/socket.h:292: error: expected identifier before numeric constant /usr/include/bits/socket.h:303: error: redefinition of ‘struct ucred’ /usr/include/bits/socket.h:315: error: redefinition of ‘struct linger’
In file included from /usr/include/netinet/in.h:23,

                 from ../../include/tst_safe_net.h:23,
                 from ../../include/tst_test.h:82,
                 from tst_net_iface_prefix.c:24:

/usr/include/stdint.h:56: error: conflicting types for ‘uint64_t’ /usr/include/linux/types.h:96: error: previous declaration of ‘uint64_t’ was here tst_net_iface_prefix.c: In function ‘read_iface_prefix’:
tst_net_iface_prefix.c:80: warning: comparison between signed and unsigned make[2]: *** [tst_net_iface_prefix] Error 1
make[2]: Leaving directory `/root/ltp/testcases/lib'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/root/ltp/testcases'
make: *** [testcases-all] Error 2

RHEL6.0:
---------

make[2]: Entering directory `/root/ltp/testcases/lib'
gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -D_FORTIFY_SOURCE=2 -I../../include -I../../include -I../../include/old/ -L../../lib tst_net_iface_prefix.c -lltp -o tst_net_iface_prefix
In file included from /usr/include/linux/rtnetlink.h:5,

                 from tst_net_iface_prefix.c:18:
Quoted 8 lines

/usr/include/linux/netlink.h:34: error: expected specifier-qualifier-list before ‘sa_family_t’ tst_net_iface_prefix.c: In function ‘read_iface_prefix’:
tst_net_iface_prefix.c:80: warning: comparison between signed and unsigned integer expressions make[2]: *** [tst_net_iface_prefix] Error 1
make[2]: Leaving directory `/root/ltp/testcases/lib'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/root/ltp/testcases'
make: *** [testcases-all] Error 2

I'll have a look at it. RHEL6.0 uses gcc 4.4.x, RHEL5.6 uses gcc 4.1). Sorry for problems, I didn't expect so old gcc to be supported. It would be nice to explicitly define somewhere which compilers we still support / care about.

Kind regards,
Petr

#17 lore raw

RFC PATCH v9 6/7 network: Add tools for setup IP related environment variables

In reply to Jan Stancek
Quoted 117 lines · Jan Stancek

----- Original Message -----

Quoted 31 lines · Petr Vorel

New tools:
* tst_net_ip_prefix
Strip prefix from IP address and save both
If no prefix found sets default prefix.

* tst_net_iface_prefix
tst_net_iface_prefix reads prefix and interface from rtnetlink.

* tst_net_vars takes input of local and remote address and setup most of test link (IP related) environment variables.

NOTABLE CHANGES IN ENVIRONMENT VARIABLES:
Network variables are defined for both local and remote:
IPV4_NETWORK was replaced by IPV4_LNETWORK and IPV4_RNETWORK IPV6_NETWORK was replaced by IPV6_LNETWORK and IPV6_RNETWORK

NEW VARIABLES:
IPV4_LHOST, IPV4_RHOST, IPV4_LNETMASK, IPV4_RNETMASK, IPV4_LPREFIX, IPV4_RPREFIX,
IPV6_LHOST, IPV6_RHOST, IPV6_LNETMASK, IPV6_RNETMASK, IPV6_LPREFIX, IPV6_RPREFIX,

For full list of environment variables which tools setup run:
tst_net_ip_prefix -h
tst_net_iface_prefix -h
tst_net_vars -h

Quoted 5 lines

Thanks a lot to Alexey Kodanev who reviewed many versions of this patch and give feedback and pointed out errors, as well as to Cyril Hrubis who reviewed orignal version of tst_net_vars.c.

Applied with minor changes below, thank you!

Hi,

this breaks the build for me on older RHELs.
I can build it OK with HEAD at
782ed69385e1 "network/stress: Reduce the default number of cycles for various tests"
but later commits fail.

RHEL5.6:
---------

make[2]: Entering directory `/root/ltp/testcases/lib'
gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -D_FORTIFY_SOURCE=2 -I../../include -I../../include -I../../in
clude/old/ -L../../lib tst_net_iface_prefix.c -lltp -o tst_net_iface_prefix
In file included from /usr/include/net/if.h:26,

                 from tst_net_iface_prefix.c:19:

/usr/include/sys/types.h:46: error: conflicting types for ‘loff_t’ /usr/include/linux/types.h:30: error: previous declaration of ‘loff_t’ was here /usr/include/sys/types.h:62: error: conflicting types for ‘dev_t’ /usr/include/linux/types.h:13: error: previous declaration of ‘dev_t’ was here In file included from /usr/include/sys/types.h:133,

                 from /usr/include/net/if.h:26,
                 from tst_net_iface_prefix.c:19:
/usr/include/time.h:105: error: conflicting types for ‘timer_t’
/usr/include/linux/types.h:22: error: previous declaration of ‘timer_t’ was here
In file included from /usr/include/net/if.h:26,
                 from tst_net_iface_prefix.c:19:

/usr/include/sys/types.h:198: error: conflicting types for ‘int64_t’ /usr/include/linux/types.h:98: error: previous declaration of ‘int64_t’ was here /usr/include/sys/types.h:204: error: conflicting types for ‘u_int64_t’ /usr/include/linux/types.h:97: error: previous declaration of ‘u_int64_t’ was here In file included from /usr/include/sys/types.h:220,

                 from /usr/include/net/if.h:26,
                 from tst_net_iface_prefix.c:19:
/usr/include/sys/select.h:78: error: conflicting types for ‘fd_set’
/usr/include/linux/types.h:12: error: previous declaration of ‘fd_set’ was here
In file included from /usr/include/net/if.h:26,
                 from tst_net_iface_prefix.c:19:
/usr/include/sys/types.h:235: error: conflicting types for ‘blkcnt_t’
/usr/include/linux/types.h:114: error: previous declaration of ‘blkcnt_t’ was here
In file included from /usr/include/sys/uio.h:29,
                 from /usr/include/sys/socket.h:27,
                 from /usr/include/net/if.h:27,
                 from tst_net_iface_prefix.c:19:
/usr/include/bits/uio.h:45: error: redefinition of ‘struct iovec’
In file included from /usr/include/sys/socket.h:35,
                 from /usr/include/net/if.h:27,
                 from tst_net_iface_prefix.c:19:

/usr/include/bits/socket.h:146: error: redefinition of ‘struct sockaddr’ /usr/include/bits/socket.h:163: error: redefinition of ‘struct __kernel_sockaddr_storage’ /usr/include/bits/socket.h:173: error: expected identifier before numeric constant /usr/include/bits/socket.h:216: error: redefinition of ‘struct msghdr’ /usr/include/bits/socket.h:234: error: redefinition of ‘struct cmsghdr’ /usr/include/bits/socket.h:264: error: conflicting types for ‘__cmsg_nxthdr’ /usr/include/linux/socket.h:129: error: previous definition of ‘__cmsg_nxthdr’ was here /usr/include/bits/socket.h:292: error: expected identifier before numeric constant /usr/include/bits/socket.h:303: error: redefinition of ‘struct ucred’ /usr/include/bits/socket.h:315: error: redefinition of ‘struct linger’
In file included from /usr/include/netinet/in.h:23,

                 from ../../include/tst_safe_net.h:23,
                 from ../../include/tst_test.h:82,
                 from tst_net_iface_prefix.c:24:

/usr/include/stdint.h:56: error: conflicting types for ‘uint64_t’ /usr/include/linux/types.h:96: error: previous declaration of ‘uint64_t’ was here tst_net_iface_prefix.c: In function ‘read_iface_prefix’:
tst_net_iface_prefix.c:80: warning: comparison between signed and unsigned make[2]: *** [tst_net_iface_prefix] Error 1
make[2]: Leaving directory `/root/ltp/testcases/lib'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/root/ltp/testcases'
make: *** [testcases-all] Error 2

RHEL6.0:
---------

make[2]: Entering directory `/root/ltp/testcases/lib'
gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -D_FORTIFY_SOURCE=2 -I../../include -I../../include -I../../include/old/ -L../../lib tst_net_iface_prefix.c -lltp -o tst_net_iface_prefix
In file included from /usr/include/linux/rtnetlink.h:5,

                 from tst_net_iface_prefix.c:18:
Quoted 8 lines

/usr/include/linux/netlink.h:34: error: expected specifier-qualifier-list before ‘sa_family_t’ tst_net_iface_prefix.c: In function ‘read_iface_prefix’:
tst_net_iface_prefix.c:80: warning: comparison between signed and unsigned integer expressions make[2]: *** [tst_net_iface_prefix] Error 1
make[2]: Leaving directory `/root/ltp/testcases/lib'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/root/ltp/testcases'
make: *** [testcases-all] Error 2

Hi Jan,

Looks like a known problem with rtnetlink include:

https://www.spinics.net/lists/netdev/msg171723.html

We should includesys/socket.hbefore rtnetlink.h.Is it fixing the build?

(quoted diff) +0 -0

b/testcases/lib/tst_net_iface_prefix.c
index f82e1fa..803f1e7 100644

testcases/lib/tst_net_iface_prefix.c +1 -0
@@ -15,6 +15,7 @@
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <sys/socket.h>
 #include <linux/rtnetlink.h>
 #include <net/if.h>
 #include <stdio.h>

Thanks,
Alexey

#18 lore raw

RFC PATCH v9 6/7 network: Add tools for setup IP related environment variables

----- Original Message -----

Quoted 152 lines · Jan Stancek
Quoted 137 lines

----- Original Message -----

Quoted 31 lines · Petr Vorel

New tools:
* tst_net_ip_prefix
Strip prefix from IP address and save both
If no prefix found sets default prefix.

* tst_net_iface_prefix
tst_net_iface_prefix reads prefix and interface from rtnetlink.

* tst_net_vars takes input of local and remote address and setup most of test link (IP related) environment variables.

NOTABLE CHANGES IN ENVIRONMENT VARIABLES:
Network variables are defined for both local and remote:
IPV4_NETWORK was replaced by IPV4_LNETWORK and IPV4_RNETWORK IPV6_NETWORK was replaced by IPV6_LNETWORK and IPV6_RNETWORK

NEW VARIABLES:
IPV4_LHOST, IPV4_RHOST, IPV4_LNETMASK, IPV4_RNETMASK, IPV4_LPREFIX, IPV4_RPREFIX,
IPV6_LHOST, IPV6_RHOST, IPV6_LNETMASK, IPV6_RNETMASK, IPV6_LPREFIX, IPV6_RPREFIX,

For full list of environment variables which tools setup run:
tst_net_ip_prefix -h
tst_net_iface_prefix -h
tst_net_vars -h

Quoted 5 lines

Thanks a lot to Alexey Kodanev who reviewed many versions of this patch and give feedback and pointed out errors, as well as to Cyril Hrubis who reviewed orignal version of tst_net_vars.c.

Applied with minor changes below, thank you!

Hi,

this breaks the build for me on older RHELs.
I can build it OK with HEAD at
782ed69385e1 "network/stress: Reduce the default number of cycles for various tests"
but later commits fail.

RHEL5.6:
---------

make[2]: Entering directory `/root/ltp/testcases/lib' gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W

(quoted diff) +0 -2
-Wold-style-definition -D_FORTIFY_SOURCE=2 -I../../include -I../../include
-I../../in

clude/old/ -L../../lib tst_net_iface_prefix.c -lltp -o
tst_net_iface_prefix
In file included from /usr/include/net/if.h:26,

                 from tst_net_iface_prefix.c:19:

/usr/include/sys/types.h:46: error: conflicting types for ‘loff_t’ /usr/include/linux/types.h:30: error: previous declaration of ‘loff_t’ was here
/usr/include/sys/types.h:62: error: conflicting types for ‘dev_t’ /usr/include/linux/types.h:13: error: previous declaration of ‘dev_t’ was here
In file included from /usr/include/sys/types.h:133,

                 from /usr/include/net/if.h:26,
                 from tst_net_iface_prefix.c:19:

/usr/include/time.h:105: error: conflicting types for ‘timer_t’ /usr/include/linux/types.h:22: error: previous declaration of ‘timer_t’ was here
In file included from /usr/include/net/if.h:26,

                 from tst_net_iface_prefix.c:19:

/usr/include/sys/types.h:198: error: conflicting types for ‘int64_t’ /usr/include/linux/types.h:98: error: previous declaration of ‘int64_t’ was here
/usr/include/sys/types.h:204: error: conflicting types for ‘u_int64_t’ /usr/include/linux/types.h:97: error: previous declaration of ‘u_int64_t’ was here
In file included from /usr/include/sys/types.h:220,

                 from /usr/include/net/if.h:26,
                 from tst_net_iface_prefix.c:19:

/usr/include/sys/select.h:78: error: conflicting types for ‘fd_set’ /usr/include/linux/types.h:12: error: previous declaration of ‘fd_set’ was here
In file included from /usr/include/net/if.h:26,

                 from tst_net_iface_prefix.c:19:

/usr/include/sys/types.h:235: error: conflicting types for ‘blkcnt_t’ /usr/include/linux/types.h:114: error: previous declaration of ‘blkcnt_t’ was here
In file included from /usr/include/sys/uio.h:29,

                 from /usr/include/sys/socket.h:27,
                 from /usr/include/net/if.h:27,
                 from tst_net_iface_prefix.c:19:
/usr/include/bits/uio.h:45: error: redefinition of ‘struct iovec’
In file included from /usr/include/sys/socket.h:35,
                 from /usr/include/net/if.h:27,
                 from tst_net_iface_prefix.c:19:

/usr/include/bits/socket.h:146: error: redefinition of ‘struct sockaddr’ /usr/include/bits/socket.h:163: error: redefinition of ‘struct __kernel_sockaddr_storage’
/usr/include/bits/socket.h:173: error: expected identifier before numeric constant
/usr/include/bits/socket.h:216: error: redefinition of ‘struct msghdr’ /usr/include/bits/socket.h:234: error: redefinition of ‘struct cmsghdr’ /usr/include/bits/socket.h:264: error: conflicting types for ‘__cmsg_nxthdr’
/usr/include/linux/socket.h:129: error: previous definition of ‘__cmsg_nxthdr’ was here
/usr/include/bits/socket.h:292: error: expected identifier before numeric constant
/usr/include/bits/socket.h:303: error: redefinition of ‘struct ucred’ /usr/include/bits/socket.h:315: error: redefinition of ‘struct linger’ In file included from /usr/include/netinet/in.h:23,

                 from ../../include/tst_safe_net.h:23,
                 from ../../include/tst_test.h:82,
                 from tst_net_iface_prefix.c:24:

/usr/include/stdint.h:56: error: conflicting types for ‘uint64_t’ /usr/include/linux/types.h:96: error: previous declaration of ‘uint64_t’ was here
tst_net_iface_prefix.c: In function ‘read_iface_prefix’:
tst_net_iface_prefix.c:80: warning: comparison between signed and unsigned make[2]: *** [tst_net_iface_prefix] Error 1
make[2]: Leaving directory `/root/ltp/testcases/lib'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/root/ltp/testcases'
make: *** [testcases-all] Error 2

RHEL6.0:
---------

make[2]: Entering directory `/root/ltp/testcases/lib' gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W

(quoted diff) +0 -2
-Wold-style-definition -D_FORTIFY_SOURCE=2 -I../../include -I../../include
-I../../include/old/   -L../../lib  tst_net_iface_prefix.c   -lltp -o

tst_net_iface_prefix
In file included from /usr/include/linux/rtnetlink.h:5,

                 from tst_net_iface_prefix.c:18:
Quoted 10 lines

/usr/include/linux/netlink.h:34: error: expected specifier-qualifier-list before ‘sa_family_t’
tst_net_iface_prefix.c: In function ‘read_iface_prefix’:
tst_net_iface_prefix.c:80: warning: comparison between signed and unsigned integer expressions
make[2]: *** [tst_net_iface_prefix] Error 1
make[2]: Leaving directory `/root/ltp/testcases/lib'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/root/ltp/testcases'
make: *** [testcases-all] Error 2

Hi Jan,

Quoted 5 lines

Looks like a known problem with rtnetlink include:

https://www.spinics.net/lists/netdev/msg171723.html

We should includesys/socket.hbefore rtnetlink.h.Is it fixing the build?

Yes, this fixed the build for me.

Regards,
Jan

Quoted 18 lines
testcases/lib/tst_net_iface_prefix.c +1 -0
index f82e1fa..803f1e7 100644
@@ -15,6 +15,7 @@
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <sys/socket.h>
 #include <linux/rtnetlink.h>
 #include <net/if.h>
 #include <stdio.h>

Thanks,
Alexey

author
#19 lore raw

RFC PATCH v9 6/7 network: Add tools for setup IP related environment variables

Hi Alexey,

Quoted 7 lines
Quoted 5 lines

Looks like a known problem with rtnetlink include:

https://www.spinics.net/lists/netdev/msg171723.html

We should includesys/socket.hbefore rtnetlink.h.Is it fixing the build?

Yes, this fixed the build for me.

Thank you for fixing it!

Quoted 1 line

tst_net_iface_prefix.c:80: warning: comparison between signed and unsigned

I'll post a fix for this warning.

Kind regards,
Petr

author
#20 lore raw

RFC PATCH v9 7/7 network: Use tools to set up IPv4 and IPv6 related variables

In reply to Petr Vorel

Tools (tst_net_ip_prefix, tst_net_iface_prefix, tst_net_vars) simplify setup as it only needs to have passed 4 IP addresses (IPv4 lhost + rhost and IPv6 lhost + rhost).

It's possible to define different network part for local and remote hosts.

---
 testcases/lib/test_net.sh                          | 95 ++++++++++++++--------
 testcases/network/stress/interface/if4-addr-change | 17 ++--
 2 files changed, 74 insertions(+), 38 deletions(-)
testcases/lib/test_net.sh +62 -33
index f72e4755f..654200c61 100644
@@ -218,19 +218,10 @@ tst_read_opts $*
 tst_ipaddr()
 {
 	local type="${1:-lhost}"
-	local ipv="${TST_IPV6:-4}"
-	local tst_host
-
-	if [ "$type" = "lhost" ]; then
-		eval "tst_host=\$LHOST_IPV${ipv}_HOST"
-	else
-		eval "tst_host=\$RHOST_IPV${ipv}_HOST"
-	fi
-
 	if [ "$TST_IPV6" ]; then
-		echo "${IPV6_NETWORK}:${tst_host}"
+		[ "$type" = "lhost" ] && echo "$IPV6_LHOST" || echo "$IPV6_RHOST"
 	else
-		echo "${IPV4_NETWORK}.${tst_host}"
+		[ "$type" = "lhost" ] && echo "$IPV4_LHOST" || echo "$IPV4_RHOST"
 	fi
 }
 
@@ -333,9 +324,13 @@ tst_add_ipaddr()
 {
 	local type="${1:-lhost}"
 	local link_num="${2:-0}"
+	local mask
 
-	local mask=24
-	[ "$TST_IPV6" ] && mask=64
+	if [ "$TST_IPV6" ]; then
+		[ "$type" = "lhost" ] && mask=$IPV6_LPREFIX || mask=$IPV6_RPREFIX
+	else
+		[ "$type" = "lhost" ] && mask=$IPV4_LPREFIX || mask=$IPV4_RPREFIX
+	fi
 
 	local iface=$(tst_iface $type $link_num)
 
@@ -589,24 +584,57 @@ export PASSWD="${PASSWD:-}"
 export LTP_RSH="${LTP_RSH:-rsh -n}"
 
 # Test Links
-# Set first three octets of the network address, default is '10.0.0'
-export IPV4_NETWORK="${IPV4_NETWORK:-10.0.0}"
-# Set local host last octet, default is '2'
-export LHOST_IPV4_HOST="${LHOST_IPV4_HOST:-2}"
-# Set remote host last octet, default is '1'
-export RHOST_IPV4_HOST="${RHOST_IPV4_HOST:-1}"
-# Set the reverse of IPV4_NETWORK
-export IPV4_NET_REV="${IPV4_NET_REV:-0.0.10}"
-# Set first three octets of the network address, default is 'fd00:1:1:1'
-export IPV6_NETWORK="${IPV6_NETWORK:-fd00:1:1:1}"
-# Set local host last octet, default is '2'
-export LHOST_IPV6_HOST="${LHOST_IPV6_HOST:-:2}"
-# Set remote host last octet, default is '1'
-export RHOST_IPV6_HOST="${RHOST_IPV6_HOST:-:1}"
-
-# Networks that aren't reachable through the test links
-export IPV4_NET16_UNUSED="${IPV4_NET16_UNUSED:-10.23}"
-export IPV6_NET32_UNUSED="${IPV6_NET32_UNUSED:-fd00:23}"
+# IPV{4,6}_{L,R}HOST can be set with or without prefix (e.g. IP or IP/prefix),
+# but if you use IP/prefix form, /prefix will be removed by tst_net_vars.
+IPV4_LHOST="${IPV4_LHOST:-10.0.0.2/24}"
+IPV4_RHOST="${IPV4_RHOST:-10.0.0.1/24}"
+IPV6_LHOST="${IPV6_LHOST:-fd00:1:1:1::2/64}"
+IPV6_RHOST="${IPV6_RHOST:-fd00:1:1:1::1/64}"
+
+# tst_net_ip_prefix
+# Strip prefix from IP address and save both If no prefix found sets
+# default prefix.
+#
+# tst_net_iface_prefix reads prefix and interface from rtnetlink.
+# If nothing found sets default prefix value.
+#
+# tst_net_vars exports environment variables related to test links and
+# networks that aren't reachable through the test links.
+#
+# For full list of exported environment variables see:
+# tst_net_ip_prefix -h
+# tst_net_iface_prefix -h
+# tst_net_vars -h
+if [ -z "$TST_PARSE_VARIABLES" ]; then
+	tst_resm TINFO "Parsing IP and prefixes from IPv4 lhost: '$IPV4_LHOST'," \
+		"rhost: '$IPV4_RHOST', IPv6 lhost: '$IPV6_LHOST', rhost: '$IPV6_RHOST'"
+	eval $(tst_net_ip_prefix $IPV4_LHOST || echo "exit $?")
+	eval $(tst_net_ip_prefix -r $IPV4_RHOST || echo "exit $?")
+	eval $(tst_net_ip_prefix $IPV6_LHOST || echo "exit $?")
+	eval $(tst_net_ip_prefix -r $IPV6_RHOST || echo "exit $?")
+fi
+
+[ -n "$TST_USE_NETNS" -a "$TST_INIT_NETNS" != "no" ] && init_ltp_netspace
+
+if [ -z "$TST_PARSE_VARIABLES" ]; then
+	tst_resm TINFO "Parsing prefixes and ifaces from rtnetlink"
+	eval $(tst_net_iface_prefix $IPV4_LHOST || echo "exit $?")
+	eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV4_RHOST \
+		|| echo "exit $?")
+	eval $(tst_net_iface_prefix $IPV6_LHOST || echo "exit $?")
+	eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV6_RHOST \
+		|| echo "exit $?")
+
+	tst_resm TINFO "Parsing all remaining variables from IPv4 lhost:" \
+		"'$IPV4_LHOST/$IPV4_LPREFIX', rhost: '$IPV4_RHOST/$IPV4_RPREFIX'," \
+		"IPv6 lhost: '$IPV6_LHOST/$IPV6_LPREFIX', rhost: '$IPV6_RHOST/$IPV6_RPREFIX'"
+	eval $(tst_net_vars $IPV4_LHOST/$IPV4_LPREFIX $IPV4_RHOST/$IPV4_RPREFIX \
+		|| echo "exit $?")
+	eval $(tst_net_vars $IPV6_LHOST/$IPV6_LPREFIX $IPV6_RHOST/$IPV6_RPREFIX \
+		|| echo "exit $?")
+
+	export TST_PARSE_VARIABLES="yes"
+fi
 
 export HTTP_DOWNLOAD_DIR="${HTTP_DOWNLOAD_DIR:-/var/www/html}"
 export FTP_DOWNLOAD_DIR="${FTP_DOWNLOAD_DIR:-/var/ftp}"
@@ -629,12 +657,13 @@ export UPLOAD_REGFILESIZE="${UPLOAD_REGFILESIZE:-1024}"
 export MCASTNUM_NORMAL="${MCASTNUM_NORMAL:-20}"
 export MCASTNUM_HEAVY="${MCASTNUM_HEAVY:-4000}"
 
-[ -n "$TST_USE_NETNS" -a "$TST_INIT_NETNS" != "no" ] && init_ltp_netspace
-
 # Warning: make sure to set valid interface names and IP addresses below.
 # Set names for test interfaces, e.g. "eth0 eth1"
+# This is fallback for LHOST_IFACES in case tst_net_vars finds nothing or we
+# want to use more ifaces.
 export LHOST_IFACES="${LHOST_IFACES:-eth0}"
 export RHOST_IFACES="${RHOST_IFACES:-eth0}"
+
 # Set corresponding HW addresses, e.g. "00:00:00:00:00:01 00:00:00:00:00:02"
 export LHOST_HWADDRS="${LHOST_HWADDRS:-$(tst_get_hwaddrs lhost)}"
 export RHOST_HWADDRS="${RHOST_HWADDRS:-$(tst_get_hwaddrs rhost)}"
testcases/network/stress/interface/if4-addr-change +12 -5
index 567f86643..a7469c252 100644
@@ -48,12 +48,19 @@ while [ $cnt -lt $NS_TIMES ]; do
 
 	[ $num -eq $RHOST_IPV4_HOST ] && continue
 
-	# Change IPv4 address
-	lhost_ipv4addr="${IPV4_NETWORK}.${num}"
+	# check prefix and fix values for prefix != 24
+	add_to_net=
+	if [ $IPV4_LPREFIX -lt 8 -o $IPV4_LPREFIX -ge 32 ] ; then
+		tst_brkm TCONF "test must be with prefix >= 8 and prefix < 32 ($IPV4_LPREFIX)"
+	elif [ $IPV4_LPREFIX -lt 16 ]; then # N.x.x.num
+		add_to_net=".0.1"
+	elif [ $IPV4_LPREFIX -lt 24 ]; then # N.N.x.num
+		add_to_net=".1"
+	fi
 
-	ifconfig $(tst_iface) $lhost_ipv4addr netmask 255.255.255.0 \
-		broadcast 255.255.255.255 || \
-		tst_brkm TFAIL "Failed to change into ${lhost_ipv4addr}"
+	# Change IPv4 address
+	ROD ifconfig $(tst_iface) ${IPV4_LNETWORK}${add_to_net}.${num} netmask \
+		$IPV4_LNETMASK broadcast $IPV4_LBROADCAST
 
 	cnt=$(($cnt + 1))
 
Signature · 1 line
2.14.0
#21 lore raw

RFC PATCH v9 7/7 network: Use tools to set up IPv4 and IPv6 related variables

Quoted 116 lines · Petr Vorel

Tools (tst_net_ip_prefix, tst_net_iface_prefix, tst_net_vars) simplify setup as it only needs to have passed 4 IP addresses (IPv4 lhost + rhost and IPv6 lhost + rhost).

It's possible to define different network part for local and remote hosts.

---
 testcases/lib/test_net.sh                          | 95 ++++++++++++++--------
 testcases/network/stress/interface/if4-addr-change | 17 ++--
 2 files changed, 74 insertions(+), 38 deletions(-)
testcases/lib/test_net.sh +47 -31
index f72e4755f..654200c61 100644
@@ -218,19 +218,10 @@ tst_read_opts $*
 tst_ipaddr()
 {
 	local type="${1:-lhost}"
-	local ipv="${TST_IPV6:-4}"
-	local tst_host
-
-	if [ "$type" = "lhost" ]; then
-		eval "tst_host=\$LHOST_IPV${ipv}_HOST"
-	else
-		eval "tst_host=\$RHOST_IPV${ipv}_HOST"
-	fi
-
 	if [ "$TST_IPV6" ]; then
-		echo "${IPV6_NETWORK}:${tst_host}"
+		[ "$type" = "lhost" ] && echo "$IPV6_LHOST" || echo "$IPV6_RHOST"
 	else
-		echo "${IPV4_NETWORK}.${tst_host}"
+		[ "$type" = "lhost" ] && echo "$IPV4_LHOST" || echo "$IPV4_RHOST"
 	fi
 }
 
@@ -333,9 +324,13 @@ tst_add_ipaddr()
 {
 	local type="${1:-lhost}"
 	local link_num="${2:-0}"
+	local mask
 
-	local mask=24
-	[ "$TST_IPV6" ] && mask=64
+	if [ "$TST_IPV6" ]; then
+		[ "$type" = "lhost" ] && mask=$IPV6_LPREFIX || mask=$IPV6_RPREFIX
+	else
+		[ "$type" = "lhost" ] && mask=$IPV4_LPREFIX || mask=$IPV4_RPREFIX
+	fi
 
 	local iface=$(tst_iface $type $link_num)
 
@@ -589,24 +584,57 @@ export PASSWD="${PASSWD:-}"
 export LTP_RSH="${LTP_RSH:-rsh -n}"
 
 # Test Links
-# Set first three octets of the network address, default is '10.0.0'
-export IPV4_NETWORK="${IPV4_NETWORK:-10.0.0}"
-# Set local host last octet, default is '2'
-export LHOST_IPV4_HOST="${LHOST_IPV4_HOST:-2}"
-# Set remote host last octet, default is '1'
-export RHOST_IPV4_HOST="${RHOST_IPV4_HOST:-1}"
-# Set the reverse of IPV4_NETWORK
-export IPV4_NET_REV="${IPV4_NET_REV:-0.0.10}"
-# Set first three octets of the network address, default is 'fd00:1:1:1'
-export IPV6_NETWORK="${IPV6_NETWORK:-fd00:1:1:1}"
-# Set local host last octet, default is '2'
-export LHOST_IPV6_HOST="${LHOST_IPV6_HOST:-:2}"
-# Set remote host last octet, default is '1'
-export RHOST_IPV6_HOST="${RHOST_IPV6_HOST:-:1}"
-
-# Networks that aren't reachable through the test links
-export IPV4_NET16_UNUSED="${IPV4_NET16_UNUSED:-10.23}"
-export IPV6_NET32_UNUSED="${IPV6_NET32_UNUSED:-fd00:23}"
+# IPV{4,6}_{L,R}HOST can be set with or without prefix (e.g. IP or IP/prefix),
+# but if you use IP/prefix form, /prefix will be removed by tst_net_vars.
+IPV4_LHOST="${IPV4_LHOST:-10.0.0.2/24}"
+IPV4_RHOST="${IPV4_RHOST:-10.0.0.1/24}"
+IPV6_LHOST="${IPV6_LHOST:-fd00:1:1:1::2/64}"
+IPV6_RHOST="${IPV6_RHOST:-fd00:1:1:1::1/64}"
+
+# tst_net_ip_prefix
+# Strip prefix from IP address and save both If no prefix found sets
+# default prefix.
+#
+# tst_net_iface_prefix reads prefix and interface from rtnetlink.
+# If nothing found sets default prefix value.
+#
+# tst_net_vars exports environment variables related to test links and
+# networks that aren't reachable through the test links.
+#
+# For full list of exported environment variables see:
+# tst_net_ip_prefix -h
+# tst_net_iface_prefix -h
+# tst_net_vars -h
+if [ -z "$TST_PARSE_VARIABLES" ]; then
+	tst_resm TINFO "Parsing IP and prefixes from IPv4 lhost: '$IPV4_LHOST'," \
+		"rhost: '$IPV4_RHOST', IPv6 lhost: '$IPV6_LHOST', rhost: '$IPV6_RHOST'"
+	eval $(tst_net_ip_prefix $IPV4_LHOST || echo "exit $?")
+	eval $(tst_net_ip_prefix -r $IPV4_RHOST || echo "exit $?")
+	eval $(tst_net_ip_prefix $IPV6_LHOST || echo "exit $?")
+	eval $(tst_net_ip_prefix -r $IPV6_RHOST || echo "exit $?")
+fi
+
+[ -n "$TST_USE_NETNS" -a "$TST_INIT_NETNS" != "no" ] && init_ltp_netspace
+
+if [ -z "$TST_PARSE_VARIABLES" ]; then
+	tst_resm TINFO "Parsing prefixes and ifaces from rtnetlink"
+	eval $(tst_net_iface_prefix $IPV4_LHOST || echo "exit $?")
+	eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV4_RHOST \
+		|| echo "exit $?")
+	eval $(tst_net_iface_prefix $IPV6_LHOST || echo "exit $?")
+	eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV6_RHOST \

testcases/lib/test_net.sh export PASSWD="${PASSWD:-}" · line 635

Quoted 10 lines
testcases/lib/test_net.sh +10 -0
+		|| echo "exit $?")
+
+	tst_resm TINFO "Parsing all remaining variables from IPv4 lhost:" \
+		"'$IPV4_LHOST/$IPV4_LPREFIX', rhost: '$IPV4_RHOST/$IPV4_RPREFIX'," \
+		"IPv6 lhost: '$IPV6_LHOST/$IPV6_LPREFIX', rhost: '$IPV6_RHOST/$IPV6_RPREFIX'"
+	eval $(tst_net_vars $IPV4_LHOST/$IPV4_LPREFIX $IPV4_RHOST/$IPV4_RPREFIX \
+		|| echo "exit $?")
+	eval $(tst_net_vars $IPV6_LHOST/$IPV6_LPREFIX $IPV6_RHOST/$IPV6_RPREFIX \
+		|| echo "exit $?")
+

Changed tst_resm messages (+ printing interfaces) and applied, thank you!

tst_resm TINFO "Network config (local -- remote):"
tst_resm TINFO "$LHOST_IFACES -- $RHOST_IFACES"
tst_resm TINFO "$IPV4_LHOST/$IPV4_LPREFIX -- $IPV4_RHOST/$IPV4_RPREFIX" tst_resm TINFO "$IPV6_LHOST/$IPV6_LPREFIX -- $IPV6_RHOST/$IPV6_RPREFIX"

Best regards,
Alexey

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20170908/a9550689/attachment.html>