aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/runqemu-gen-tapdevs
blob: 11de318c1a2d4cbd0f598f8f91e238e980fbf21e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { co
#!/bin/bash
#
# Create a "bank" of tap network devices that can be used by the
# runqemu script. This script needs to be run as root, and will
# use the tunctl binary from the build system sysroot. Note: many Linux 
# distros these days still use an older version of tunctl which does not
# support the group permissions option, hence the need to use the build
# system provided version.
#
# Copyright (C) 2010 Intel Corp.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

usage() {
	echo "Usage: sudo $0 <uid> <gid> <num> <staging_bindir_native>"
        echo "Where <uid> is the numeric user id the tap devices will be owned by"
	echo "Where <gid> is the numeric group id the tap devices will be owned by"
	echo "<num> is the number of tap devices to create (0 to remove all)"
	echo "<native-sysroot-basedir> is the path to the build system's native sysroot"
	echo "e.g. $ bitbake qemu-helper-native"
	echo "$ sudo $0 1000 1000 4 tmp/sysroots-components/x86_64/qemu-helper-native/usr/bin"
	exit 1
}

if [ $EUID -ne 0 ]; then
	echo "Error: This script must be run with root privileges"
	exit
fi

if [ $# -ne 4 ]; then
	echo "Error: Incorrect number of arguments"
	usage
fi

TUID=$1
GID=$2
COUNT=$3
STAGING_BINDIR_NATIVE=$4

TUNCTL=$STAGING_BINDIR_NATIVE/tunctl
if [[ ! -x "$TUNCTL" || -d "$TUNCTL" ]]; then
	echo "Error: $TUNCTL is not an executable"
	usage
fi

SCRIPT_DIR=`dirname $0`
RUNQEMU_IFUP="$SCRIPT_DIR/runqemu-ifup"
if [ ! -x "$RUNQEMU_IFUP" ]; then
	echo "Error: Unable to find the runqemu-ifup script in $SCRIPT_DIR"
	exit 1
fi

IFCONFIG=`which ip 2> /dev/null`
if [ -z "$IFCONFIG" ]; then
	# Is it ever anywhere else?
	IFCONFIG=/sbin/ip
fi
if [ ! -x "$IFCONFIG" ]; then
       echo "$IFCONFIG cannot be executed"
       exit 1
fi

if [ $COUNT -ge 0 ]; then
	# Ensure we start with a clean slate
	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
	rm -f /etc/runqemu-nosudo
else
	echo "Error: Incorrect count: $COUNT"
	exit 1
fi

if [ $COUNT -gt 0 ]; then
	echo "Creating $COUNT tap devices for UID: $TUID GID: $GID..."
	for ((index=0; index < $COUNT; index++)); do
		echo "Creating tap$index"
		ifup=`$RUNQEMU_IFUP $TUID $GID $STAGING_BINDIR_NATIVE 2>&1`
		if [ $? -ne 0 ]; then
			echo "Error running tunctl: $ifup"
			exit 1
		fi
	done

	echo "Note: For systems running NetworkManager, it's recommended"
	echo "Note: that the tap devices be set as unmanaged in the"
	echo "Note: NetworkManager.conf file. Add the following lines to"
	echo "Note: /etc/NetworkManager/NetworkManager.conf"
	echo "[keyfile]"
	echo "unmanaged-devices=interface-name:tap*"

	# The runqemu script will check for this file, and if it exists,
	# will use the existing bank of tap devices without creating
	# additional ones via sudo.
	touch /etc/runqemu-nosudo
fi