qemu-ifup 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #! /bin/sh
  2. _ETHER=`route -n get default 2>/dev/null |awk '/interface:/ {print $2}'`
  3. _ETHER=${_ETHER:=trunk0}
  4. _BRIDGE=bridge0
  5. # Let the environment over-ride this
  6. [ "$BRIDGE" ] || BRIDGE=${_BRIDGE}
  7. [ "$ETHER" ] || ETHER=${_ETHER}
  8. if test `id -u` -ne 0; then
  9. DOAS=doas
  10. fi
  11. echo -n " {$1 ($BRIDGE <-> $ETHER)"
  12. # Set up our bridge
  13. $DOAS ifconfig $1 group tap > /dev/null 2>&1
  14. $DOAS ifconfig $BRIDGE create > /dev/null 2>&1 && {
  15. # Only add rules if the bridge creation succeeds; otherwise
  16. # duplicate rules get loaded each time qemu starts
  17. # The following two block carp packets from wasting cpu cycles inside the
  18. # qemu sessions, remove if testing carp inside qemu
  19. $DOAS ifconfig $BRIDGE rule block in on $ETHER dst 33:33:0:0:0:12
  20. $DOAS ifconfig $BRIDGE rule block in on $ETHER dst 01:00:5e:00:00:12
  21. }
  22. # Since we can specify ETHER and BRIDGE above, its possible that
  23. # this tap interface or this physical interface was setup as part of
  24. # a different bridge earlier, and that is never cleaned up, so we have
  25. # to cleanup here first before we set it up; a physical interface cannot
  26. # be member to more than one bridge, thankfully, or I never would have
  27. # caught this
  28. ifconfig bridge | sed -n '/^bridge[0-9]*/{s/:.*$//;p;}' | while read brif
  29. do
  30. $DOAS ifconfig $brif del $ETHER > /dev/null 2>&1
  31. $DOAS ifconfig $brif del $1 > /dev/null 2>&1
  32. done
  33. $DOAS ifconfig $BRIDGE add $ETHER up
  34. $DOAS ifconfig $BRIDGE add $1 up || true
  35. echo "}"