* [LTP] [PATCH] ns-tools/set_ipv4addr: Use ip command as default
@ 2020-09-10 13:56 Chen Hanxiao
2020-09-11 8:37 ` Petr Vorel
0 siblings, 1 reply; 2+ messages in thread
From: Chen Hanxiao @ 2020-09-10 13:56 UTC (permalink / raw)
To: ltp
From: Chen Hanxiao <chenhx.fnst@cn.fujitsu.com>
Set iproute as the default as ifconfig
has been deprecated on some of the distributions.
Signed-off-by: Chen Hanxiao <chenhx.fnst@cn.fujitsu.com>
---
testcases/network/stress/ns-tools/set_ipv4addr | 40 +++++++++++++++++++++-----
1 file changed, 33 insertions(+), 7 deletions(-)
diff --git a/testcases/network/stress/ns-tools/set_ipv4addr b/testcases/network/stress/ns-tools/set_ipv4addr
index 1ec0769..baf5d4a 100644
--- a/testcases/network/stress/ns-tools/set_ipv4addr
+++ b/testcases/network/stress/ns-tools/set_ipv4addr
@@ -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
--
1.8.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* [LTP] [PATCH] ns-tools/set_ipv4addr: Use ip command as default
2020-09-10 13:56 [LTP] [PATCH] ns-tools/set_ipv4addr: Use ip command as default Chen Hanxiao
@ 2020-09-11 8:37 ` Petr Vorel
0 siblings, 0 replies; 2+ messages in thread
From: Petr Vorel @ 2020-09-11 8:37 UTC (permalink / raw)
To: ltp
Hi Chen,
> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-09-11 8:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-10 13:56 [LTP] [PATCH] ns-tools/set_ipv4addr: Use ip command as default Chen Hanxiao
2020-09-11 8:37 ` Petr Vorel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox