ia64/xen-unstable

view tools/examples/vif-route @ 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 06d84bf87159
children e31e64e00ac3
line source
1 #!/bin/sh
2 #============================================================================
3 # /etc/xen/vif-route
4 #
5 # Script for configuring a vif in routed 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-route up domain=VM1 vif=vif1.0 ip="128.232.38.45/28 10.10.10.55/24"
12 #
13 # Usage:
14 # vif-route (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 # mac vif MAC address (required).
21 # ip list of IP networks for the vif, space-separated (optional).
22 #============================================================================
24 # Exit if anything goes wrong
25 set -e
27 echo "*vif-route $*" >&2
29 # Operation name.
30 OP=$1
31 shift
33 # Pull variables in args into environment
34 for arg ; do export "${arg}" ; done
36 # Required parameters. Fail if not set.
37 domain=${domain:?}
38 vif=${vif:?}
39 mac=${mac:?}
41 # Optional parameters. Set defaults.
42 ip=${ip:-''} # default to null (do nothing)
44 main_ip=`ifconfig eth0 | grep "inet addr:" | sed -e 's/.*inet addr:\(\w\w*\.\w\w*\.\w\w*\.\w\w*\).*/\1/'`
46 # Are we going up or down?
47 case $OP in
48 up)
49 ifconfig ${vif} 169.254.1.0 netmask 255.255.255.255 up
50 echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp
51 iptcmd='-A'
52 ipcmd='a'
53 ;;
54 down)
55 ifconfig ${vif} down
56 iptcmd='-D'
57 ipcmd='d'
58 ;;
59 *)
60 echo 'Invalid command: ' $OP >&2
61 echo 'Valid commands are: up, down' >&2
62 exit 1
63 ;;
64 esac
66 if [ "${ip}" ] ; then
68 # If we've been given a list of IP networks, allow pkts with these src addrs.
69 for addr in ${ip} ; do
70 ip r ${ipcmd} ${addr} dev ${vif} src ${main_ip}
71 # iptables ${iptcmd} FORWARD -m physdev --physdev-in ${vif} -s ${addr} -j ACCEPT
72 done
74 # Always allow us to talk to a DHCP server anyhow.
75 # iptables ${iptcmd} FORWARD -m physdev --physdev-in ${vif} -p udp --sport 68 --dport 67 -j ACCEPT
76 fi