vif-route-qubes 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. #============================================================================
  3. # /etc/xen/vif-route-qubes
  4. #
  5. # Script for configuring a vif in routed mode.
  6. # The hotplugging system will call this script if it is specified either in
  7. # the device configuration given to Xend, or the default Xend configuration
  8. # in /etc/xen/xend-config.sxp. If the script is specified in neither of those
  9. # places, then vif-bridge is the default.
  10. #
  11. # Usage:
  12. # vif-route (add|remove|online|offline)
  13. #
  14. # Environment vars:
  15. # vif vif interface name (required).
  16. # XENBUS_PATH path to this device's details in the XenStore (required).
  17. #
  18. # Read from the store:
  19. # ip list of IP networks for the vif, space-separated (default given in
  20. # this script).
  21. #============================================================================
  22. dir=$(dirname "$0")
  23. . "$dir/vif-common.sh"
  24. #main_ip=$(dom0_ip)
  25. case "$command" in
  26. online)
  27. ifconfig ${vif} up
  28. echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp
  29. ipcmd='add'
  30. iptables_cmd='-I FORWARD 1'
  31. cmdprefix=''
  32. ;;
  33. offline)
  34. do_without_error ifdown ${vif}
  35. ipcmd='del'
  36. iptables_cmd='-D FORWARD'
  37. cmdprefix='do_without_error'
  38. ;;
  39. esac
  40. if [ "${ip}" ] ; then
  41. # If we've been given a list of IP addresses, then add routes from dom0 to
  42. # the guest using those addresses.
  43. for addr in ${ip} ; do
  44. ${cmdprefix} ip route ${ipcmd} ${addr} dev ${vif}
  45. done
  46. echo ${cmdprefix} iptables $iptables_cmd -i ${vif} \! -s ${ip} -j DROP
  47. ${cmdprefix} iptables $iptables_cmd -i ${vif} \! -s ${ip} -j DROP
  48. fi
  49. log debug "Successful vif-route-qubes $command for $vif."
  50. if [ "$command" = "online" ]
  51. then
  52. success
  53. fi