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