Use a bridge to connect the vif and tap interfaces for HVMs; this
[invirt/packages/invirt-xen-config.git] / vif-invirtroute
1 #!/bin/bash
2
3 #============================================================================
4 # /etc/xen/vif-route
5 #
6 # Script for configuring a vif in routed mode.
7 # The hotplugging system will call this script if it is specified either in
8 # the device configuration given to Xend, or the default Xend configuration
9 # in /etc/xen/xend-config.sxp.  If the script is specified in neither of those
10 # places, then vif-bridge is the default.
11 #
12 # Usage:
13 # vif-route (add|remove|online|offline)
14 #
15 # Environment vars:
16 # vif         vif interface name (required).
17 # XENBUS_PATH path to this device's details in the XenStore (required).
18 # Read from the store:
19 # ip      list of IP networks for the vif, space-separated (default given in
20 #         this script).
21 #
22 # This script will set up proxy arp  for any ip addresses that are being routed
23 # type read to determine if the device is ioemu
24
25 #============================================================================
26
27 dir=$(dirname "$0")
28 . "$dir/vif-common.sh"
29
30 main_ip=$(dom0_ip)
31 dev=${dev:-${vif}}
32
33 brname=dom${vif#vif}
34
35 case "$command" in
36     online)
37         setup_bridge_port ${dev}
38         setup_bridge_port ${vif}
39         create_bridge ${brname}
40         add_to_bridge ${brname} ${dev}
41         add_to_bridge ${brname} ${vif}
42         ifconfig ${brname} ${main_ip} netmask 255.255.255.255 up
43         echo 1 >/proc/sys/net/ipv4/conf/${brname}/proxy_arp
44         echo 1 >/proc/sys/net/ipv4/conf/${brname}/rp_filter
45         xenstore-write "$XENBUS_PATH/feature-gso-tcpv4" 0
46         ethtool -K ${vif} tso off
47         ipcmd='add'
48         cmdprefix=''
49         ;;
50     offline)
51         do_without_error brctl delif ${brname} ${vif}
52         do_without_error brctl delif ${brname} ${dev}
53         do_without_error ifconfig ${brname} down
54         ipcmd='del'
55         cmdprefix='do_without_error'
56         ;;
57 esac
58
59 vif_type=$(xenstore_read_default "$XENBUS_PATH/type" "viffront")
60 if [  ${vif_type} != "ioemu"  -o  x${qemu_online} = xyes ] ; then
61     if [ "${ip}" ] ; then
62     # If we've been given a list of IP addresses, then add routes from dom0 to
63     # the guest using those addresses.
64         for addr in ${ip} ; do
65             ${cmdprefix} ip route ${ipcmd} ${addr} dev ${brname} src ${main_ip}
66             if [ "$command" == "online" ]; then
67                 arpspoof -i $(invirt-getconf xen.iface) -t 18.181.0.1 ${addr}&
68                 sleep 5
69                 kill %arpspoof
70             fi
71         done 
72     fi
73 fi
74
75 if [ "$command" == "offline" ]
76 then
77     do_without_error brctl delbr ${brname}
78 fi
79
80 log debug "Successful vif-route $command for $vif."
81 if [ "$command" == "online" ]
82 then
83   success
84 fi