[PATCH mptcp-next v3 3/6] selftests: mptcp: new approach of getting addr

Geliang Tang posted 6 patches 4 years ago
There is a newer version of this series
[PATCH mptcp-next v3 3/6] selftests: mptcp: new approach of getting addr
Posted by Geliang Tang 4 years ago
This patch implemented a more flexible approach to get the address
from the PM dump output.

The original code in the backup tests only works for the output of
'pm_nl_ctl dump'. It chooses the last item in the endpoints dump
table to parse the address in it, and the address is always showed
at the end of the item.

But it dosen't work for the output of 'ip mptcp endpoint show', the
address is always showed at the front of the item. This patch rewrites
the backup tests to fit for the 'ip mptcp' output.

Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh
index 395f06784582..086e0778a1fa 100755
--- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
@@ -240,6 +240,11 @@ is_v6()
 	[ -z "${1##*:*}" ]
 }
 
+is_addr()
+{
+	[ -z "${1##*[.:]*}" ]
+}
+
 # $1: ns, $2: port
 wait_local_port_listen()
 {
@@ -552,11 +557,17 @@ do_transfer()
 	if [ ! -z $sflags ]; then
 		sleep 1
 		for netns in "$ns1" "$ns2"; do
-			dump=(`ip netns exec $netns ./pm_nl_ctl dump`)
-			if [ ${#dump[@]} -gt 0 ]; then
-				addr=${dump[${#dump[@]} - 1]}
+			ip netns exec $netns ./pm_nl_ctl dump | while read line; do
+				local arr=($line)
+				local addr
+
+				for addr in ${arr[@]}; do
+					if is_addr $addr; then
+						break
+					fi
+				done
 				ip netns exec $netns ./pm_nl_ctl set $addr flags $sflags
-			fi
+			done
 		done
 	fi
 
-- 
2.31.1