summaryrefslogtreecommitdiffstats
path: root/scripts/runqemu-ifup
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/runqemu-ifup')
-rwxr-xr-xscripts/runqemu-ifup65
1 files changed, 32 insertions, 33 deletions
diff --git a/scripts/runqemu-ifup b/scripts/runqemu-ifup
index bb661740c5..05c9325b6b 100755
--- a/scripts/runqemu-ifup
+++ b/scripts/runqemu-ifup
@@ -1,10 +1,7 @@
1#!/bin/bash 1#!/bin/bash
2# 2#
3# QEMU network interface configuration script. This utility needs to 3# QEMU network interface configuration script. This utility needs to
4# be run as root, and will use the tunctl binary from a native sysroot. 4# be run as root, and will use the ip utility
5# Note: many Linux distros these days still use an older version of
6# tunctl which does not support the group permissions option, hence
7# the need to use build system's version.
8# 5#
9# If you find yourself calling this script a lot, you can add the 6# If you find yourself calling this script a lot, you can add the
10# the following to your /etc/sudoers file to be able to run this 7# the following to your /etc/sudoers file to be able to run this
@@ -24,7 +21,7 @@
24# 21#
25 22
26usage() { 23usage() {
27 echo "sudo $(basename $0) <uid> <gid> <native-sysroot-basedir>" 24 echo "sudo $(basename $0) <gid>"
28} 25}
29 26
30if [ $EUID -ne 0 ]; then 27if [ $EUID -ne 0 ]; then
@@ -32,41 +29,43 @@ if [ $EUID -ne 0 ]; then
32 exit 1 29 exit 1
33fi 30fi
34 31
35if [ $# -ne 3 ]; then 32if [ $# -eq 2 ]; then
33 echo "Warning: uid parameter is ignored. It is no longer needed." >&2
34 GROUP="$2"
35elif [ $# -eq 1 ]; then
36 GROUP="$1"
37else
36 usage 38 usage
37 exit 1 39 exit 1
38fi 40fi
39 41
40USERID="-u $1"
41GROUP="-g $2"
42STAGING_BINDIR_NATIVE=$3
43 42
44TUNCTL=$STAGING_BINDIR_NATIVE/tunctl 43if [ -z "$OE_TAP_NAME" ]; then
45if [ ! -x "$TUNCTL" ]; then 44 OE_TAP_NAME=tap
46 echo "Error: Unable to find tunctl binary in '$STAGING_BINDIR_NATIVE', please bitbake qemu-helper-native"
47 exit 1
48fi 45fi
49 46
50TAP=`$TUNCTL -b $GROUP 2>&1` 47if taps=$(ip tuntap list 2>/dev/null); then
51STATUS=$? 48 tap_no_last=$(echo "$taps" |cut -f 1 -d ":" |grep -E "^$OE_TAP_NAME.*" |sed "s/$OE_TAP_NAME//g" | sort -rn | head -n 1)
52if [ $STATUS -ne 0 ]; then 49 if [ -z "$tap_no_last" ]; then
53# If tunctl -g fails, try using tunctl -u, for older host kernels 50 tap_no=0
54# which do not support the TUNSETGROUP ioctl 51 else
55 TAP=`$TUNCTL -b $USERID 2>&1` 52 tap_no=$(("$tap_no_last" + 1))
56 STATUS=$?
57 if [ $STATUS -ne 0 ]; then
58 echo "tunctl failed:"
59 exit 1
60 fi 53 fi
54 ip tuntap add "$OE_TAP_NAME$tap_no" mode tap group "$GROUP" && TAP=$OE_TAP_NAME$tap_no
55fi
56
57if [ -z "$TAP" ]; then
58 echo "Error: Unable to find a tap device to use"
59 exit 1
61fi 60fi
62 61
63IFCONFIG=`which ip 2> /dev/null` 62IPTOOL=`which ip 2> /dev/null`
64if [ "x$IFCONFIG" = "x" ]; then 63if [ "x$IPTOOL" = "x" ]; then
65 # better than nothing... 64 # better than nothing...
66 IFCONFIG=/sbin/ip 65 IPTOOL=/sbin/ip
67fi 66fi
68if [ ! -x "$IFCONFIG" ]; then 67if [ ! -x "$IPTOOL" ]; then
69 echo "$IFCONFIG cannot be executed" 68 echo "$IPTOOL cannot be executed"
70 exit 1 69 exit 1
71fi 70fi
72 71
@@ -79,22 +78,22 @@ if [ ! -x "$IPTABLES" ]; then
79 exit 1 78 exit 1
80fi 79fi
81 80
82n=$[ (`echo $TAP | sed 's/tap//'` * 2) + 1 ] 81n=$[ (`echo $TAP | sed "s/$OE_TAP_NAME//"` * 2) + 1 ]
83$IFCONFIG addr add 192.168.7.$n/32 broadcast 192.168.7.255 dev $TAP 82$IPTOOL addr add 192.168.7.$n/32 broadcast 192.168.7.255 dev $TAP
84STATUS=$? 83STATUS=$?
85if [ $STATUS -ne 0 ]; then 84if [ $STATUS -ne 0 ]; then
86 echo "Failed to set up IP addressing on $TAP" 85 echo "Failed to set up IP addressing on $TAP"
87 exit 1 86 exit 1
88fi 87fi
89$IFCONFIG link set dev $TAP up 88$IPTOOL link set dev $TAP up
90STATUS=$? 89STATUS=$?
91if [ $STATUS -ne 0 ]; then 90if [ $STATUS -ne 0 ]; then
92 echo "Failed to bring up $TAP" 91 echo "Failed to bring up $TAP"
93 exit 1 92 exit 1
94fi 93fi
95 94
96dest=$[ (`echo $TAP | sed 's/tap//'` * 2) + 2 ] 95dest=$[ (`echo $TAP | sed "s/$OE_TAP_NAME//"` * 2) + 2 ]
97$IFCONFIG route add to 192.168.7.$dest dev $TAP 96$IPTOOL route add to 192.168.7.$dest dev $TAP
98STATUS=$? 97STATUS=$?
99if [ $STATUS -ne 0 ]; then 98if [ $STATUS -ne 0 ]; then
100 echo "Failed to add route to 192.168.7.$dest using $TAP" 99 echo "Failed to add route to 192.168.7.$dest using $TAP"