aboutsummaryrefslogtreecommitdiff
path: root/scripts/qemu-ifup
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2018-09-05 19:39:12 +0200
committerToni Uhlig <matzeton@googlemail.com>2018-09-05 19:39:12 +0200
commit280a9b13d28b9f581259ba3aa8affb2f049f05a0 (patch)
tree9c37885340a651d70bb675da975ee5998b3e040f /scripts/qemu-ifup
parent48f9dc2b6a35cf2872613d74821d6e40379b984e (diff)
- Makefile should not create symlinks if they exist already
- uid/gid set to 0/0 in CPIO archive - provide the debian qemu-ifup script (used if /etc/qemu-ifup does not exist) - image-reinstall deletes the initramfs but leaves all other targets intact Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'scripts/qemu-ifup')
-rwxr-xr-xscripts/qemu-ifup43
1 files changed, 43 insertions, 0 deletions
diff --git a/scripts/qemu-ifup b/scripts/qemu-ifup
new file mode 100755
index 0000000..20c10de
--- /dev/null
+++ b/scripts/qemu-ifup
@@ -0,0 +1,43 @@
+#! /bin/sh
+# Script to bring a network (tap) device for qemu up.
+# The idea is to add the tap device to the same bridge
+# as we have default routing to.
+
+
+# in order to be able to find brctl
+PATH=$PATH:/sbin:/usr/sbin
+ip=$(which ip)
+
+if [ -n "$ip" ]; then
+ ip link set "$1" up
+else
+ brctl=$(which brctl)
+ if [ ! "$ip" -o ! "$brctl" ]; then
+ echo "W: $0: not doing any bridge processing: neither ip nor brctl utility not found" >&2
+ exit 0
+ fi
+ ifconfig "$1" 0.0.0.0 up
+fi
+
+switch=$(ip route ls | \
+ awk '/^default / {
+ for(i=0;i<NF;i++) { if ($i == "dev") { print $(i+1); next; } }
+ }'
+ )
+
+# only add the interface to default-route bridge if we
+# have such interface (with default route) and if that
+# interface is actually a bridge.
+# It is possible to have several default routes too
+for br in $switch; do
+ if [ -d /sys/class/net/$br/bridge/. ]; then
+ if [ -n "$ip" ]; then
+ ip link set "$1" master "$br"
+ else
+ brctl addif $br "$1"
+ fi
+ exit # exit with status of the previous command
+ fi
+done
+
+echo "W: $0: no bridge for guest interface found" >&2