chiark / gitweb /
files in the right directory
[autopkgtest.git] / xen / vif-route-adt
1 #!/bin/bash -e
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 2>>/var/log/xen-hotplug.log
24 set -x
25 case $0 in */*) dir=${0%/*};; *) dir=.;; esac
26 . "$dir/vif-common.sh"
27
28 main_ip=$(dom0_ip)
29
30 case "$command" in
31     online)
32         ifconfig ${vif} ${main_ip} netmask 255.255.255.255 \
33                 broadcast ${main_ip} up
34         ip -f inet6 addr delete dev ${vif} local fe80::fcff:ffff:feff:ffff/64
35         ip -f inet neigh add \
36             to 172.18.45.66 \
37             dev ${vif} \
38             lladdr 00:16:3e:7c:aa:7f \
39             nud permanent
40         arp -i ${vif} -s 172.18.45.66 00:16:3e:7c:aa:7f pub
41         ipcmd='a'
42         iptcmd='-A'
43         ;;
44     offline)
45         ifdown ${vif}
46         ipcmd='d'
47         iptcmd='-D'
48         ;;
49 esac
50
51 iptables "$iptcmd" INPUT -i "$vif" -j AdtXenIn
52 iptables "$iptcmd" FORWARD -i "$vif" -j AdtXenFwd
53
54 if [ "${ip}" ] ; then
55     # If we've been given a list of IP addresses, then add routes from dom0 to
56     # the guest using those addresses.
57     for addr in ${ip} ; do
58       ip r ${ipcmd} ${addr} dev ${vif} src ${main_ip}
59     done 
60 fi
61
62 #S log debug "Successful vif-route $command for $vif."
63 if [ "$command" == "online" ]
64 then
65   success
66 fi