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|online)
26        ifconfig ${dev} ${main_ip} netmask 255.255.255.255 up
27        echo 1 >/proc/sys/net/ipv4/conf/${dev}/proxy_arp
28        ipcmd='add'
29        cmdprefix=''
30        ;;
31    remove|offline)
32        do_without_error ifdown ${dev}
33        ipcmd='del'
34        cmdprefix='do_without_error'
35        ;;
36esac
37
38case "${type_if}" in
39    tap)
40	metric=1
41	;;
42    vif)
43	metric=2
44	;;
45    *)
46	fatal "Unrecognised interface type ${type_if}"
47	;;
48esac
49
50# If we've been given a list of IP addresses, then add routes from dom0 to
51# the guest using those addresses.
52for addr in ${ip} ; do
53    ${cmdprefix} ip route ${ipcmd} ${addr} dev ${dev} src ${main_ip} metric ${metric}
54done
55
56handle_iptable
57
58call_hooks vif post
59
60log debug "Successful vif-route ${command} for ${dev}."
61if [ "${command}" = "online" ]
62then
63    success
64fi
65