#! /bin/sh -e

if ip link show tap0 >/dev/null 2>&1; then
  echo "tap0 exists, exiting..." >&2
  exit 1
fi

ip tuntap add dev tap0 mode tap
#Now set tap0 up, set its IP address in openwrt host's subnet (172.16.1.1/24) and we are ready to go
ip link set tap0 up
ip addr add 172.16.1.2/24 dev tap0

#qemu -net vde -net nic,model=ne2k_pci -hda openwrt*.img
#vde_tunctl #Creates iface tap0
#This will NOT work without script=no,downscript=no
qemu -hda openwrt*.img -net nic -net tap,ifname=tap0,script=no,downscript=no

ip addr del 172.16.1.2/24 dev tap0
ip link set tap0 down
ip tuntap del dev tap0 mode tap
