chiark / gitweb /
wip Xen support - files from adt-play on samual8
[autopkgtest.git] / xen / vif-script
1 #!/bin/sh
2 #============================================================================
3 # /etc/xen/vif-route
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
23 exec >/root/u 2>&1
24 set -x
25 date
26
27 dir=$(dirname "$0")
28 . "$dir/vif-common.sh"
29
30 main_ip=$(dom0_ip)
31
32 case "$command" in
33     online)
34         ifconfig ${vif} ${main_ip} netmask 255.255.255.255 \
35                 broadcast ${main_ip} up
36         ipcmd='a'
37         ;;
38     offline)
39         ifdown ${vif}
40         ipcmd='d'
41         ;;
42 esac
43
44 if [ "${ip}" ] ; then
45     # If we've been given a list of IP addresses, then add routes from dom0 to
46     # the guest using those addresses.
47     for addr in ${ip} ; do
48       ip r ${ipcmd} ${addr} dev ${vif} src ${main_ip}
49     done 
50 fi
51
52 handle_iptable
53
54 date >/root/t
55
56 iptable
57
58 log debug "Successful vif-route $command for $vif."
59 if [ "$command" == "online" ]
60 then
61   success
62 fi