1 | #!/bin/bash |
---|
2 | |
---|
3 | |
---|
4 | |
---|
5 | |
---|
6 | #============================================================================ |
---|
7 | # /etc/xen/vif-route |
---|
8 | # |
---|
9 | # Script for configuring a vif in routed mode. |
---|
10 | # The hotplugging system will call this script if it is specified either in |
---|
11 | # the device configuration given to Xend, or the default Xend configuration |
---|
12 | # in /etc/xen/xend-config.sxp. If the script is specified in neither of those |
---|
13 | # places, then vif-bridge is the default. |
---|
14 | # |
---|
15 | # Usage: |
---|
16 | # vif-route (add|remove|online|offline) |
---|
17 | # |
---|
18 | # Environment vars: |
---|
19 | # vif vif interface name (required). |
---|
20 | # XENBUS_PATH path to this device's details in the XenStore (required). |
---|
21 | # Read from the store: |
---|
22 | # ip list of IP networks for the vif, space-separated (default given in |
---|
23 | # this script). |
---|
24 | # V6PREFIX prefix of v6 address to use |
---|
25 | # Note that the v6 support is kind of broken because there's not really a way to populate the v6 prefix |
---|
26 | # This script will set up proxy arp for any ip addresses that are being routed |
---|
27 | |
---|
28 | #============================================================================ |
---|
29 | |
---|
30 | dir=$(dirname "$0") |
---|
31 | . "$dir/vif-common.sh" |
---|
32 | |
---|
33 | main_ip=$(dom0_ip) |
---|
34 | |
---|
35 | case "$command" in |
---|
36 | online) |
---|
37 | ifconfig ${vif} ${main_ip} netmask 255.255.255.255 up |
---|
38 | echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp |
---|
39 | echo 1 >/proc/sys/net/ipv4/conf/${vif}/rp_filter |
---|
40 | ipcmd='add' |
---|
41 | cmdprefix='' |
---|
42 | ;; |
---|
43 | offline) |
---|
44 | do_without_error ifdown ${vif} |
---|
45 | if [ -f /var/run/radvd/radvd.pid.${vif} ] ; then |
---|
46 | do_without_error kill `cat /var/run/radvd/radvd.pid.${vif}` |
---|
47 | fi |
---|
48 | ipcmd='del' |
---|
49 | cmdprefix='do_without_error' |
---|
50 | ;; |
---|
51 | esac |
---|
52 | |
---|
53 | v6prefix=${v6prefix:-} |
---|
54 | v6prefix=$(xenstore_read_default "$XENBUS_PATH/v6prefix" "$v6prefix") |
---|
55 | |
---|
56 | if [ "${ip}" ] ; then |
---|
57 | # If we've been given a list of IP addresses, then add routes from dom0 to |
---|
58 | # the guest using those addresses. |
---|
59 | for addr in ${ip} ; do |
---|
60 | ${cmdprefix} ip route ${ipcmd} ${addr} dev ${vif} src ${main_ip} |
---|
61 | arpspoof -i eth0 ${addr}& |
---|
62 | sleep 5 |
---|
63 | kill %arpspoof |
---|
64 | done |
---|
65 | fi |
---|
66 | |
---|
67 | if [ x${v6prefix} != x ] ; then |
---|
68 | sed -e "s/@interface@/${vif}/" -e "s+@prefix@+${v6prefix}+" /etc/xen/radvd.conf.template >/var/run/radvd.conf.${vif} |
---|
69 | ${cmdprefix} ip -6 addr ${ipcmd} fe80::/64 scope link dev ${vif} |
---|
70 | if [ $1 = online ] ; then |
---|
71 | radvd -u radvd -C /var/run/radvd.conf.${vif} -p /var/run/radvd/radvd.pid.${vif} |
---|
72 | fi |
---|
73 | ${cmdprefix} ip -6 route ${ipcmd} ${v6prefix} dev ${vif} |
---|
74 | fi |
---|
75 | |
---|
76 | handle_iptable |
---|
77 | |
---|
78 | log debug "Successful vif-route $command for $vif." |
---|
79 | if [ "$command" == "online" ] |
---|
80 | then |
---|
81 | success |
---|
82 | fi |
---|