#! /bin/sh
# Script to bring a network (tap) device for qemu-kvm up
# The idea is to add the tap device to the same bridge
# as we have default routing to.

switch=$(ip route ls | \
    awk '/^default / {
          for(i=0;i<NF;i++) { if ($i == "dev") { print $(i+1); exit; } }
         }'
        )
/sbin/ifconfig $1 0.0.0.0 up

# only add the interface to default-route bridge if we
# have such interface (with default route) and if that
# interface is actually a bridge.
if [ -n "$switch" -a -d /sys/class/net/$switch/bridge/. ]; then
  /usr/sbin/brctl addif $switch $1 || :
fi
