Skip to contentSkip to conversation

ns-tools/set_ipv4addr: Use ip command as default

PATCH New Chen Hanxiao 2 participants 2 messages Sep 10, 2020 – Sep 11, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ns-tools/set_ipv4addr: Use ip command as default

From: Chen Hanxiao <[email protected]>

Set iproute as the default as ifconfig
has been deprecated on some of the distributions.

---
 testcases/network/stress/ns-tools/set_ipv4addr | 40 +++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 7 deletions(-)
testcases/network/stress/ns-tools/set_ipv4addr +33 -7
index 1ec0769..baf5d4a 100644
@@ -57,6 +57,8 @@ export LTPROOT
 # Check the environmanet variable for the test
 . check_envval || exit 1
 
+CMD="${CMD:-ip}"
+
 # Arguments
 if [ $# -ne 4 ]; then
     echo "Usage: $0 host_type link_num network_portion host_portion" >&2
@@ -77,17 +79,41 @@ fi
 addr=${network_part}.${host_part}
 netmask=`echo $network_part | sed "s/[[:digit:]]*/255/g"`.`echo $host_part | sed "s/[[:digit:]]*/0/g"`
 broadcast=${network_part}.`echo $host_part | sed "s/[[:digit:]]*/255/g"`
+prefix=0
+
+netmask_to_prefix()
+{
+    bits=0
+    for octet in $(echo $1| sed 's/\./ /g'); do
+        binbits=$(echo "obase=2; ibase=10; ${octet}"| bc | sed 's/0//g')
+        let bits+=${#binbits}
+    done
+    prefix=$bits
+}
+
+netmask_to_prefix $netmask
 
 # Assign IPv4 address to the interface belongs the link_num Test Link
 ifname=`get_ifname $host_type $link_num` || exit 1
 
-if [ $host_type = lhost ]; then
-    ifconfig $ifname up
-    ifconfig $ifname $addr netmask $netmask broadcast $broadcast
-    ret=$?
-else
-    ret=`$LTP_RSH $RHOST '( PATH=/sbin:/usr/sbin:$PATH ; ifconfig '$ifname' up && ifconfig '$ifname $addr' netmask '$netmask' broadcast '$broadcast' ) >/dev/null 2>&1; echo $?'`
-fi
+case $CMD in
+    ip)
+        if [ $host_type = lhost ]; then
+            ip link set $ifname up
+            ip address add $addr'/'$prefix dev $ifname broadcast $broadcast
+            ret=$?
+        else
+            ret=`$LTP_RSH $RHOST '( PATH=/sbin:/usr/sbin:$PATH ; ip link set '$ifname' up && ip address add '$addr'/'$prefix' dev '$ifname' broadcast '$broadcast' ) >/dev/null 2>&1; echo $?'`
+        fi ;;
+ifconfig)
+        if [ $host_type = lhost ]; then
+            ifconfig $ifname up
+            ifconfig $ifname $addr netmask $netmask broadcast $broadcast
+            ret=$?
+        else
+            ret=`$LTP_RSH $RHOST '( PATH=/sbin:/usr/sbin:$PATH ; ifconfig '$ifname' up && ifconfig '$ifname $addr' netmask '$netmask' broadcast '$broadcast' ) >/dev/null 2>&1; echo $?'`
+        fi ;;
+esac
 
 if [ $ret -gt 0 ]; then
     echo "Cannot set $addr to $ifname" >&2
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 ns-tools/set_ipv4addr: Use ip command as default

Hi Chen,

Quoted 4 lines

Set iproute as the default as ifconfig
has been deprecated on some of the distributions.

 testcases/network/stress/ns-tools/set_ipv4addr | 40 +++++++++++++++++++++-----

Thanks for your patch. While I appreciate you work on LTP networking tests, I'm against this change for a simple reason: everything which uses ns-tools needs to be rewritten to use new LTP network shell API (tst_net.sh). Only very simple fixes for really broken things like 4cf2f2bfd should be accepted.

Thus, please put your effort into rewriting these tests.
FYI Although it's a low priority for me I plan to work on these (I have wip at least for rmmod). Feel free to join this effort.
See https://github.com/linux-test-project/ltp/issues/310

Kind regards,
Petr