Skip to contentSkip to conversation

runqemu: Replace use of ifconfig with ip

PATCH In review Khem Raj 2 participants 3 messages May 8, 2013

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH 1/1 runqemu: Replace use of ifconfig with ip

ifconfig and its ilk (net-tools package) is deprecated in favour of iproute2 package and is now removed by many distro's e.g. Archlinux. So we replace ifconfig with ip utility

---
 scripts/runqemu-gen-tapdevs | 6 +++---
 scripts/runqemu-ifup        | 6 +++---
 scripts/runqemu-internal    | 6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)
scripts/runqemu-gen-tapdevs +3 -3
index f5be30a..d3b27be 100755
@@ -59,10 +59,10 @@ if [ ! -x "$RUNQEMU_IFUP" ]; then
 	exit 1
 fi
 
-IFCONFIG=`which ifconfig 2> /dev/null`
+IFCONFIG=`which ip 2> /dev/null`
 if [ -z "$IFCONFIG" ]; then
 	# Is it ever anywhere else?
-	IFCONFIG=/sbin/ifconfig
+	IFCONFIG=/sbin/ip
 fi
 if [ ! -x "$IFCONFIG" ]; then
        echo "$IFCONFIG cannot be executed"
@@ -70,7 +70,7 @@ if [ ! -x "$IFCONFIG" ]; then
 fi
 
 # Ensure we start with a clean slate
-for tap in `$IFCONFIG | grep ^tap | awk '{ print \$1 }' | sed s/://`; do
+for tap in `$IFCONFIG link | grep tap | awk '{ print \$2 }' | sed s/://`; do
 	echo "Note: Destroying pre-existing tap interface $tap..."
 	$TUNCTL -d $tap
 done
scripts/runqemu-ifup +3 -3
index 0926faf..8948153 100755
@@ -70,10 +70,10 @@ if [ $STATUS -ne 0 ]; then
 	fi
 fi
 
-IFCONFIG=`which ifconfig 2> /dev/null`
+IFCONFIG=`which ip 2> /dev/null`
 if [ "x$IFCONFIG" = "x" ]; then
 	# better than nothing...
-	IFCONFIG=/sbin/ifconfig
+	IFCONFIG=/sbin/ip
 fi
 if [ ! -x "$IFCONFIG" ]; then
 	echo "$IFCONFIG cannot be executed"
@@ -100,7 +100,7 @@ if [ ! -x "$IPTABLES" ]; then
 fi
 
 n=$[ (`echo $TAP | sed 's/tap//'` * 2) + 1 ]
-$IFCONFIG $TAP 192.168.7.$n netmask 255.255.255.255
+$IFCONFIG addr add 192.168.7.$n/32 dev $TAP
 
 dest=$[ (`echo $TAP | sed 's/tap//'` * 2) + 2 ]
 $ROUTE add -host 192.168.7.$dest $TAP
scripts/runqemu-internal +3 -3
index f11706d..d295013 100755
@@ -139,16 +139,16 @@ if [ ! -d "$LOCKDIR" ]; then
     chmod 777 $LOCKDIR
 fi
 
-IFCONFIG=`which ifconfig 2> /dev/null`
+IFCONFIG=`which ip 2> /dev/null`
 if [ -z "$IFCONFIG" ]; then
-    IFCONFIG=/sbin/ifconfig
+    IFCONFIG=/sbin/ip
 fi
 if [ ! -x "$IFCONFIG" ]; then
        echo "$IFCONFIG cannot be executed"
        exit 1
 fi
 
-POSSIBLE=`$IFCONFIG -a | grep '^tap' | awk '{print $1}' | sed s/://`
+POSSIBLE=`$IFCONFIG link | grep 'tap' | awk '{print $2}' | sed s/://`
 TAP=""
 LOCKFILE=""
 for tap in $POSSIBLE; do
Signature · 1 line
1.8.2.2
#1 lore raw
Quoted 15 lines · Khem Raj

ifconfig and its ilk (net-tools package) is deprecated in favour of iproute2 package and is now removed by many distro's e.g. Archlinux. So we replace ifconfig with ip utility

---
 scripts/runqemu-gen-tapdevs | 6 +++---
 scripts/runqemu-ifup        | 6 +++---
 scripts/runqemu-internal    | 6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)
scripts/runqemu-gen-tapdevs +0 -0
index f5be30a..d3b27be 100755

scripts/runqemu-gen-tapdevs if [ ! -x "$RUNQEMU_IFUP" ]; then · line 66

Quoted 10 lines
scripts/runqemu-gen-tapdevs +2 -2
@@ -59,10 +59,10 @@ if [ ! -x "$RUNQEMU_IFUP" ]; then
        exit 1
 fi
 
-IFCONFIG=`which ifconfig 2> /dev/null`
+IFCONFIG=`which ip 2> /dev/null`
 if [ -z "$IFCONFIG" ]; then
 
        # Is it ever anywhere else?
-       IFCONFIG=/sbin/ifconfig
+       IFCONFIG=/sbin/ip

Is the "command" command a Bourne shell builtin? If so, using

    IFCONFIG=$(command -pv ip)

might be better? (same applies to the other, following instances)

Quoted 52 lines
scripts/runqemu-gen-tapdevs +0 -0
 fi
 if [ ! -x "$IFCONFIG" ]; then

echo "$IFCONFIG cannot be executed"

scripts/runqemu-gen-tapdevs +1 -1
@@ -70,7 +70,7 @@ if [ ! -x "$IFCONFIG" ]; then
 fi
 
 # Ensure we start with a clean slate
-for tap in `$IFCONFIG | grep ^tap | awk '{ print \$1 }' | sed s/://`; do
+for tap in `$IFCONFIG link | grep tap | awk '{ print \$2 }' | sed s/://`; do
        echo "Note: Destroying pre-existing tap interface $tap..."
        $TUNCTL -d $tap
 done
scripts/runqemu-ifup +3 -3
index 0926faf..8948153 100755
@@ -70,10 +70,10 @@ if [ $STATUS -ne 0 ]; then
        fi
 fi
 
-IFCONFIG=`which ifconfig 2> /dev/null`
+IFCONFIG=`which ip 2> /dev/null`
 if [ "x$IFCONFIG" = "x" ]; then
        # better than nothing...
-       IFCONFIG=/sbin/ifconfig
+       IFCONFIG=/sbin/ip
 fi
 if [ ! -x "$IFCONFIG" ]; then
        echo "$IFCONFIG cannot be executed"
@@ -100,7 +100,7 @@ if [ ! -x "$IPTABLES" ]; then
 fi
 
 n=$[ (`echo $TAP | sed 's/tap//'` * 2) + 1 ]
-$IFCONFIG $TAP 192.168.7.$n netmask 255.255.255.255
+$IFCONFIG addr add 192.168.7.$n/32 dev $TAP
 
 dest=$[ (`echo $TAP | sed 's/tap//'` * 2) + 2 ]
 $ROUTE add -host 192.168.7.$dest $TAP
scripts/runqemu-internal +2 -2
index f11706d..d295013 100755
@@ -139,16 +139,16 @@ if [ ! -d "$LOCKDIR" ]; then
     chmod 777 $LOCKDIR
 fi
 
-IFCONFIG=`which ifconfig 2> /dev/null`
+IFCONFIG=`which ip 2> /dev/null`
 if [ -z "$IFCONFIG" ]; then
-    IFCONFIG=/sbin/ifconfig
+    IFCONFIG=/sbin/ip
 fi

scripts/runqemu-internal if [ ! -d "$LOCKDIR" ]; then · line 154

Quoted 10 lines
scripts/runqemu-internal +1 -1
 if [ ! -x "$IFCONFIG" ]; then
        echo "$IFCONFIG cannot be executed"
        exit 1
 fi
 
-POSSIBLE=`$IFCONFIG -a | grep '^tap' | awk '{print $1}' | sed s/://`
+POSSIBLE=`$IFCONFIG link | grep 'tap' | awk '{print $2}' | sed s/://`
 TAP=""
 LOCKFILE=""
 for tap in $POSSIBLE; do

It does seem a little silly to continue to use a variable named IFCONFIG now that you're switching away from "ifconfig" :-)

author
#2 lore raw
Quoted 27 lines · Trevor Woerner
Quoted 23 lines · Khem Raj

ifconfig and its ilk (net-tools package) is deprecated in favour of iproute2 package and is now removed by many distro's e.g. Archlinux. So we replace ifconfig with ip utility

---

scripts/runqemu-gen-tapdevs | 6 +++---
scripts/runqemu-ifup        | 6 +++---
scripts/runqemu-internal    | 6 +++---
3 files changed, 9 insertions(+), 9 deletions(-)
scripts/runqemu-gen-tapdevs +0 -0
index f5be30a..d3b27be 100755
@@ -59,10 +59,10 @@ if [ ! -x "$RUNQEMU_IFUP" ]; then
       exit 1

fi

scripts/runqemu-gen-tapdevs +1 -1
-IFCONFIG=`which ifconfig 2> /dev/null`
+IFCONFIG=`which ip 2> /dev/null`

if [ -z "$IFCONFIG" ]; then

# Is it ever anywhere else?

scripts/runqemu-gen-tapdevs

Quoted 2 lines
scripts/runqemu-gen-tapdevs +1 -1
-       IFCONFIG=/sbin/ifconfig
+       IFCONFIG=/sbin/ip
Quoted 5 lines

Is the "command" command a Bourne shell builtin? If so, using

   IFCONFIG=$(command -pv ip)

might be better? (same applies to the other, following instances)

this would be for another day.

Quoted 9 lines
Quoted 6 lines
scripts/runqemu-gen-tapdevs +1 -1
-POSSIBLE=`$IFCONFIG -a | grep '^tap' | awk '{print $1}' | sed s/://`
+POSSIBLE=`$IFCONFIG link | grep 'tap' | awk '{print $2}' | sed s/://`

TAP=""
LOCKFILE=""
for tap in $POSSIBLE; do

It does seem a little silly to continue to use a variable named IFCONFIG now that you're switching away from "ifconfig" :-)

ip would replace more commands there eventually, thats why I left the variable as it is since eventually we want to replace all net-tools with iproute2 provides utilities.