1#!/bin/bash
2#============================================================================
3# ${XEN_SCRIPT_DIR}/vif-route
4#
5# Script for configuring a vif in routed mode.
6#
7# Usage:
8# vif-route (add|remove|online|offline)
9#
10# Environment vars:
11# dev         vif interface name (required).
12# XENBUS_PATH path to this device's details in the XenStore (required).
13#
14# Read from the store:
15# ip      list of IP networks for the vif, space-separated (default given in
16#         this script).
17#============================================================================
18
19dir=$(dirname "$0")
20. "${dir}/vif-common.sh"
21
22main_ip=$(dom0_ip)
23
24case "${command}" in
25    add)
26        ;&
27    online)
28        ifconfig ${dev} ${main_ip} netmask 255.255.255.255 up
29        echo 1 >/proc/sys/net/ipv4/conf/${dev}/proxy_arp
30        ipcmd='add'
31        cmdprefix=''
32        ;;
33    remove)
34        ;&
35    offline)
36        do_without_error ifdown ${dev}
37        ipcmd='del'
38        cmdprefix='do_without_error'
39        ;;
40esac
41
42case "${type_if}" in
43    tap)
44	metric=1
45	;;
46    vif)
47	metric=2
48	;;
49    *)
50	fatal "Unrecognised interface type ${type_if}"
51	;;
52esac
53
54# If we've been given a list of IP addresses, then add routes from dom0 to
55# the guest using those addresses.
56for addr in ${ip} ; do
57    ${cmdprefix} ip route ${ipcmd} ${addr} dev ${dev} src ${main_ip} metric ${metric}
58done
59
60handle_iptable
61
62call_hooks vif post
63
64log debug "Successful vif-route ${command} for ${dev}."
65if [ "${command}" = "online" ]
66then
67    success
68fi
69