diff options
Diffstat (limited to 'scripts/runqemu-ifup')
-rwxr-xr-x | scripts/runqemu-ifup | 65 |
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 | ||
26 | usage() { | 23 | usage() { |
27 | echo "sudo $(basename $0) <uid> <gid> <native-sysroot-basedir>" | 24 | echo "sudo $(basename $0) <gid>" |
28 | } | 25 | } |
29 | 26 | ||
30 | if [ $EUID -ne 0 ]; then | 27 | if [ $EUID -ne 0 ]; then |
@@ -32,41 +29,43 @@ if [ $EUID -ne 0 ]; then | |||
32 | exit 1 | 29 | exit 1 |
33 | fi | 30 | fi |
34 | 31 | ||
35 | if [ $# -ne 3 ]; then | 32 | if [ $# -eq 2 ]; then |
33 | echo "Warning: uid parameter is ignored. It is no longer needed." >&2 | ||
34 | GROUP="$2" | ||
35 | elif [ $# -eq 1 ]; then | ||
36 | GROUP="$1" | ||
37 | else | ||
36 | usage | 38 | usage |
37 | exit 1 | 39 | exit 1 |
38 | fi | 40 | fi |
39 | 41 | ||
40 | USERID="-u $1" | ||
41 | GROUP="-g $2" | ||
42 | STAGING_BINDIR_NATIVE=$3 | ||
43 | 42 | ||
44 | TUNCTL=$STAGING_BINDIR_NATIVE/tunctl | 43 | if [ -z "$OE_TAP_NAME" ]; then |
45 | if [ ! -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 | ||
48 | fi | 45 | fi |
49 | 46 | ||
50 | TAP=`$TUNCTL -b $GROUP 2>&1` | 47 | if taps=$(ip tuntap list 2>/dev/null); then |
51 | STATUS=$? | 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) |
52 | if [ $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 | ||
55 | fi | ||
56 | |||
57 | if [ -z "$TAP" ]; then | ||
58 | echo "Error: Unable to find a tap device to use" | ||
59 | exit 1 | ||
61 | fi | 60 | fi |
62 | 61 | ||
63 | IFCONFIG=`which ip 2> /dev/null` | 62 | IPTOOL=`which ip 2> /dev/null` |
64 | if [ "x$IFCONFIG" = "x" ]; then | 63 | if [ "x$IPTOOL" = "x" ]; then |
65 | # better than nothing... | 64 | # better than nothing... |
66 | IFCONFIG=/sbin/ip | 65 | IPTOOL=/sbin/ip |
67 | fi | 66 | fi |
68 | if [ ! -x "$IFCONFIG" ]; then | 67 | if [ ! -x "$IPTOOL" ]; then |
69 | echo "$IFCONFIG cannot be executed" | 68 | echo "$IPTOOL cannot be executed" |
70 | exit 1 | 69 | exit 1 |
71 | fi | 70 | fi |
72 | 71 | ||
@@ -79,22 +78,22 @@ if [ ! -x "$IPTABLES" ]; then | |||
79 | exit 1 | 78 | exit 1 |
80 | fi | 79 | fi |
81 | 80 | ||
82 | n=$[ (`echo $TAP | sed 's/tap//'` * 2) + 1 ] | 81 | n=$[ (`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 |
84 | STATUS=$? | 83 | STATUS=$? |
85 | if [ $STATUS -ne 0 ]; then | 84 | if [ $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 |
88 | fi | 87 | fi |
89 | $IFCONFIG link set dev $TAP up | 88 | $IPTOOL link set dev $TAP up |
90 | STATUS=$? | 89 | STATUS=$? |
91 | if [ $STATUS -ne 0 ]; then | 90 | if [ $STATUS -ne 0 ]; then |
92 | echo "Failed to bring up $TAP" | 91 | echo "Failed to bring up $TAP" |
93 | exit 1 | 92 | exit 1 |
94 | fi | 93 | fi |
95 | 94 | ||
96 | dest=$[ (`echo $TAP | sed 's/tap//'` * 2) + 2 ] | 95 | dest=$[ (`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 |
98 | STATUS=$? | 97 | STATUS=$? |
99 | if [ $STATUS -ne 0 ]; then | 98 | if [ $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" |