ia64/xen-unstable

view tools/examples/vif-nat @ 7238:971e7c7411b3

Raise an exception if an error appears on the pipes to our children, and make
sure that the child's pipes are closed even under that exception. Move the
handling of POLLHUP to the end of the loop, so that we guarantee to read any
remaining data from the child if POLLHUP and POLLIN appear at the same time.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Thu Oct 06 10:13:11 2005 +0100 (2005-10-06)
parents 3b25e1de5efb
children e31e64e00ac3
line source
1 #!/bin/sh
2 #============================================================================
3 # /etc/xen/vif-nat
4 #
5 # Script for configuring a vif in routed-nat mode.
6 # Xend calls a vif script when bringing a vif up or down.
7 # This script is the default - but it can be configured for each vif.
8 #
9 # Example invocation:
10 #
11 # vif-nat up domain=VM1 vif=vif1.0 ip="192.168.0.10/31"
12 #
13 # Usage:
14 # vif-nat (up|down) {VAR=VAL}*
15 #
16 # Vars:
17 #
18 # domain name of the domain the interface is on (required).
19 # vif vif interface name (required).
20 # ip list of IP networks for the vif, space-separated (required).
21 #============================================================================
23 # Exit if anything goes wrong
24 set -e
26 echo "*vif-nat $*" >&2
28 # Operation name.
29 OP=$1
30 shift
32 # Pull variables in args into environment
33 for arg ; do export "${arg}" ; done
35 # Required parameters. Fail if not set.
36 domain=${domain:?}
37 vif=${vif:?}
38 ip=${ip:?}
40 # strip /netmask
41 vif_ip=`echo ${ip} | awk -F/ '{print $1}'`
43 main_ip=`ifconfig eth0 | grep "inet addr:" | sed -e 's/.*inet addr:\(\w\w*\.\w\w*\.\w\w*\.\w\w*\).*/\1/'`
45 # Are we going up or down?
46 case $OP in
47 up)
48 ifconfig ${vif} ${vif_ip} netmask 255.255.255.0 up
49 echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp
50 iptcmd='-A'
51 ipcmd='a'
52 ;;
53 down)
54 ifconfig ${vif} down
55 iptcmd='-D'
56 ipcmd='d'
57 ;;
58 *)
59 echo 'Invalid command: ' $OP >&2
60 echo 'Valid commands are: up, down' >&2
61 exit 1
62 ;;
63 esac
65 ip r ${ipcmd} ${ip} dev ${vif} src ${main_ip}
66 # iptables ${iptcmd} FORWARD -m physdev --physdev-in ${vif} -p udp --sport 68 --dport 67 -j ACCEPT