#!/bin/bash
#
# vifinit 
#
# This is a silly little script to dump a couple of simple rules down to 
# the hypervisor to assign a full static IP to a given virtual interface.
# 
# Usage is:
#
#   vifinit [vif dom] [vif idx] [dotted decimal ip address]
#
if [ $# -ne 3 ] ; 
then
        echo "usage: $0 <domain_id> <vid_ifx> <dotted_decimal_ip_address>"
        exit
fi

#outbound rule:
echo $3 | grep -q "^169\\.254\\."
if [ $? -eq 0 ];
then
	# If this is a link local address, send to dom0
	echo "ADD ACCEPT srcaddr=$3 srcaddrmask=255.255.255.255 srcdom=$1 srcidx=$2 dstdom=0 dstidx=0 proto=any" > /proc/xeno/vfr
else
	# If this is not, send to wire
	echo "ADD ACCEPT srcaddr=$3 srcaddrmask=255.255.255.255 srcdom=$1 srcidx=$2 dst=PHYS proto=any" > /proc/xeno/vfr
fi

#inbound rule:
echo "ADD ACCEPT dstaddr=$3 dstaddrmask=255.255.255.255 src=ANY dstdom=$1 dstidx=$2 proto=any" > /proc/xeno/vfr

#----] done.

