ia64/xen-unstable

view tools/examples/network-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 e47e953c9e10
line source
1 #!/bin/sh
2 #============================================================================
3 # Default Xen network start/stop script when using NAT.
4 # Xend calls a network script when it starts.
5 # The script name to use is defined in /etc/xen/xend-config.sxp
6 # in the network-script field.
7 #
8 # Usage:
9 #
10 # network-nat (start|stop|status) {VAR=VAL}*
11 #
12 # Vars:
13 #
14 # netdev The gateway interface (default eth0).
15 # antispoof Whether to use iptables to prevent spoofing (default no).
16 #
17 #============================================================================
21 # Exit if anything goes wrong.
22 set -e
24 # First arg is the operation.
25 OP=$1
26 shift
28 # Pull variables in args in to environment.
29 for arg ; do export "${arg}" ; done
31 netdev=${netdev:-eth0}
32 # antispoofing not yet implemented
33 antispoof=${antispoof:-no}
35 echo "*network-nat $OP netdev=$netdev antispoof=$antispoof" >&2
38 op_start() {
39 echo 1 >/proc/sys/net/ipv4/ip_forward
40 iptables -t nat -A POSTROUTING -o ${netdev} -j MASQUERADE
41 }
44 op_stop() {
45 iptables -t nat -D POSTROUTING -o ${netdev} -j MASQUERADE
46 }
49 show_status() {
50 echo '============================================================'
51 ifconfig
52 echo ' '
53 ip route list
54 echo ' '
55 route -n
56 echo '============================================================'
58 }
60 case ${OP} in
61 start)
62 op_start
63 ;;
65 stop)
66 op_stop
67 ;;
69 status)
70 show_status
71 ;;
73 *)
74 echo 'Unknown command: ' ${OP} >&2
75 echo 'Valid commands are: start, stop, status' >&2
76 exit 1
77 esac