summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xscripts/poky-gen-tapdevs85
-rwxr-xr-xscripts/poky-qemu-internal11
2 files changed, 96 insertions, 0 deletions
diff --git a/scripts/poky-gen-tapdevs b/scripts/poky-gen-tapdevs
new file mode 100755
index 0000000000..2117a7b08e
--- /dev/null
+++ b/scripts/poky-gen-tapdevs
@@ -0,0 +1,85 @@
1#!/bin/bash
2#
3# Create a "bank" of tap network devices that can be used by the
4# poky-qemu script. This script needs to be run as root, and will
5# use the tunctl binary from a Poky sysroot. Note: many Linux distros
6# these days still use an older version of tunctl which does not
7# support the group permissions option, hence the need to use Poky's
8# version.
9#
10# Copyright (C) 2010 Intel Corp.
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License version 2 as
14# published by the Free Software Foundation.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License along
22# with this program; if not, write to the Free Software Foundation, Inc.,
23# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
25usage() {
26 echo "Usage: sudo $0 <gid> <num> <native-sysroot-basedir>"
27 echo "Where <gid> is the numeric group id the tap devices will be owned by"
28 echo "<num> is the number of tap devices to create (0 to remove all)"
29 echo "<native-sysroot-basedir> is the path to Poky's native sysroot"
30 exit 1
31}
32
33if [ $EUID -ne 0 ]; then
34 echo "Error: This script must be run with root privileges"
35 exit
36fi
37
38if [ $# -ne 3 ]; then
39 echo "Error: Incorrect number of arguments"
40 usage
41fi
42
43GID=$1
44COUNT=$2
45SYSROOT=$3
46
47TUNCTL=$SYSROOT/usr/bin/tunctl
48if [[ ! -x "$TUNCTL" || -d "$TUNCTL" ]]; then
49 echo "Error: $TUNCTL is not an executable"
50 usage
51fi
52
53SCRIPT_DIR=`dirname $0`
54POKY_QEMU_IFUP="$SCRIPT_DIR/poky-qemu-ifup"
55if [ ! -x "$POKY_QEMU_IFUP" ]; then
56 echo "Error: Unable to find the poky-qemu-ifup script in $SCRIPT_DIR"
57 exit 1
58fi
59
60IFCONFIG=`which ifconfig`
61if [ -z "$IFCONFIG" ]; then
62 # Is it ever anywhere else?
63 IFCONFIG=/sbin/ifconfig
64fi
65
66# Ensure we start with a clean slate
67for tap in `$IFCONFIG | grep ^tap | awk '{ print \$1 }'`; do
68 echo "Note: Destroying pre-existing tap interface $tap..."
69 $TUNCTL -d $tap
70done
71
72echo "Creating $COUNT tap devices for GID $GID..."
73for ((index=0; index < $COUNT; index++)); do
74 echo "Creating tap$index"
75 ifup=`$POKY_QEMU_IFUP $GID $SYSROOT 2>&1`
76 if [ $? -ne 0 ]; then
77 echo "Error running tunctl: $ifup"
78 exit 1
79 fi
80done
81
82# The poky-qemu script will check for this file, and if it exists,
83# will use the existing bank of tap devices without creating
84# additional ones via sudo.
85touch /etc/poky-nosudo
diff --git a/scripts/poky-qemu-internal b/scripts/poky-qemu-internal
index c3720d9ce2..0ea38eef60 100755
--- a/scripts/poky-qemu-internal
+++ b/scripts/poky-qemu-internal
@@ -50,6 +50,10 @@ if [ -z "$QEMU_MEMORY" ]; then
50 50
51fi 51fi
52 52
53# This flag file is created when poky-gen-tapdevs creates a bank of
54# tap devices, indicating that the user does not have sudo privs.
55NOSUDO_FLAG="/etc/poky-nosudo"
56
53QEMUIFUP=`which poky-qemu-ifup` 57QEMUIFUP=`which poky-qemu-ifup`
54QEMUIFDOWN=`which poky-qemu-ifdown` 58QEMUIFDOWN=`which poky-qemu-ifdown`
55 59
@@ -81,6 +85,13 @@ for tap in $POSSIBLE; do
81done 85done
82 86
83if [ "$TAP" = "" ]; then 87if [ "$TAP" = "" ]; then
88 if [ -e "$NOSUDO_FLAG" ]; then
89 echo "Error: There are no available tap devices to use for networking,"
90 echo "and I see $NOSUDO_FLAG exists, so I am not going to try creating"
91 echo "a new one with sudo."
92 exit 1
93 fi
94
84 GROUPID=`id -g` 95 GROUPID=`id -g`
85 echo 'Setting up tap interface under sudo' 96 echo 'Setting up tap interface under sudo'
86 tap=`sudo $QEMUIFUP $GROUPID $POKY_NATIVE_SYSROOT` 97 tap=`sudo $QEMUIFUP $GROUPID $POKY_NATIVE_SYSROOT`