vif-route-qubes 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. lockfile=/var/run/xen-hotplug/vif-lock
  26. case "$command" in
  27. online)
  28. ifconfig ${vif} up
  29. echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp
  30. ipcmd='add'
  31. iptables_cmd='-I PREROUTING 1'
  32. cmdprefix=''
  33. ;;
  34. offline)
  35. do_without_error ifdown ${vif}
  36. ipcmd='del'
  37. iptables_cmd='-D PREROUTING'
  38. cmdprefix='do_without_error'
  39. ;;
  40. esac
  41. domid=${vif/vif/}
  42. domid=${domid/.*/}
  43. # metric must be possitive, but prefer later interface
  44. # 32752 is max XID aka domid
  45. metric=$[ 32752 - $domid ]
  46. if [ "${ip}" ] ; then
  47. # If we've been given a list of IP addresses, then add routes from dom0 to
  48. # the guest using those addresses.
  49. for addr in ${ip} ; do
  50. ${cmdprefix} ip route ${ipcmd} ${addr} dev ${vif} metric $metric
  51. done
  52. echo -e "*raw\n$iptables_cmd -i ${vif} ! -s ${ip} -j DROP\nCOMMIT" | \
  53. ${cmdprefix} flock $lockfile iptables-restore --noflush
  54. back_ip=`qubesdb-read /qubes-netvm-gateway`
  55. ${cmdprefix} ip addr ${ipcmd} ${back_ip}/32 dev ${vif}
  56. fi
  57. log debug "Successful vif-route-qubes $command for $vif."
  58. if [ "$command" = "online" ]
  59. then
  60. # disable tx checksumming offload, apparently it doesn't work with our ancient qemu in stubdom
  61. do_without_error ethtool -K $vif tx off
  62. success
  63. fi