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