ia64/xen-unstable

view tools/hotplug/Linux/network-nat @ 19818:415505139333

Get rid of hardcoded pathes for stubdom and hotplug scripts

- Have the buid system generate a file which exports the install paths
for the hotplug scripts and stubdom / stubdom-dm
- Move file generation code from tools/python/Makefile into a gmake
macro
in Config.mk to avoid maintenance of three duplicates each with its
own
tweaks and bugs
- Export gmake variables into ioemu as shell variables
for upcoming ioemu patches
- Do above as a gmake macro to avoid maintenance of several duplicates
- Adjust hotplug scripts to find the right xen binaries from the
install directory
- Adjust stubdom-dm to use the install directories

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Jun 23 17:25:51 2009 +0100 (2009-06-23)
parents 9f945f16bd02
children
line source
1 #!/bin/bash -x
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 ${XEN_CONFIG_DIR}/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 # dhcp Whether to alter the local DHCP configuration (default no).
17 #
18 #============================================================================
20 dir=$(dirname "$0")
21 . "$dir/hotplugpath.sh"
22 . "$dir/xen-script-common.sh"
23 . "$dir/xen-network-common.sh"
25 findCommand "$@"
26 evalVariables "$@"
28 netdev=${netdev:-eth0}
29 # antispoofing not yet implemented
30 antispoof=${antispoof:-no}
32 # turn on dhcp feature by default if dhcpd is installed
33 if [ -f /etc/dhcpd.conf ]
34 then
35 dhcp=${dhcp:-yes}
36 else
37 dhcp=${dhcp:-no}
38 fi
41 if [ "$dhcp" != 'no' ]
42 then
43 dhcpd_conf_file=$(find_dhcpd_conf_file)
44 dhcpd_init_file=$(find_dhcpd_init_file)
45 if [ -z "$dhcpd_conf_file" ] || [ -z "$dhcpd_init_file" ]
46 then
47 echo 'Failed to find dhcpd configuration or init file.' >&2
48 exit 1
49 fi
50 fi
52 domain_name=`cat /etc/resolv.conf | grep -v "#" | grep -E 'search|domain' -i | tail -n 1 | awk '{ print $2 }'`
53 nameserver=`cat /etc/resolv.conf | grep -v "#" | grep "nameserver" -i -m 1 | awk '{ print $2 }'`
55 function dhcp_start()
56 {
57 if ! grep -q "subnet 10.0.0.0" "$dhcpd_conf_file"
58 then
59 echo >>"$dhcpd_conf_file" "subnet 10.0.0.0 netmask 255.255.0.0 {\
60 option domain-name \"$domain_name\";\
61 option domain-name-servers $nameserver; }"
62 fi
64 "$dhcpd_init_file" restart
65 }
68 function dhcp_stop()
69 {
70 local tmpfile=$(mktemp)
71 grep -v "subnet 10.0.0.0" "$dhcpd_conf_file" >"$tmpfile"
72 if diff "$tmpfile" "$dhcpd_conf_file" >&/dev/null
73 then
74 rm "$tmpfile"
75 else
76 mv "$tmpfile" "$dhcpd_conf_file"
77 fi
79 "$dhcpd_init_file" restart
80 }
83 op_start() {
84 echo 1 >/proc/sys/net/ipv4/ip_forward
85 iptables -t nat -A POSTROUTING -o ${netdev} -j MASQUERADE
86 [ "$dhcp" != 'no' ] && dhcp_start
87 }
90 op_stop() {
91 [ "$dhcp" != 'no' ] && dhcp_stop
92 iptables -t nat -D POSTROUTING -o ${netdev} -j MASQUERADE
93 }
96 show_status() {
97 echo '============================================================'
98 ifconfig
99 echo ' '
100 ip route list
101 echo ' '
102 route -n
103 echo '============================================================'
105 }
107 case "$command" in
108 start)
109 op_start
110 ;;
112 stop)
113 op_stop
114 ;;
116 status)
117 show_status
118 ;;
120 *)
121 echo "Unknown command: $command" >&2
122 echo 'Valid commands are: start, stop, status' >&2
123 exit 1
124 esac