ia64/xen-unstable

view tools/hotplug/Linux/network-nat @ 19497:2f6ed9318c03

network-bridge: Fix do_ifup in the case of ${bridge} != ${netdev}

On RHEL5.2, ifup ${bridge} fails if ${bridge} != ${netdev},
because RHEL5.2's ifup ${bridge} runs the following sequence:

1. Search CONFIG that has the same mac address of ${bridge}.=20
ifcfg-${netdev} is found.
2. Run "ip link set dev ${netdev} up".
# ${bridge} is expected.
3. Output "Failed to bring up ${netdev}."
Because ${netdev} does not exist.

Thus, do_ifup() should not use ifup if ${bridge} != ${netdev}.

Signed-off-by: KUWAMURA Shin'ya <kuwa@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Apr 02 11:48:10 2009 +0100 (2009-04-02)
parents 4bfc67b09e9c
children 9f945f16bd02
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 /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 # dhcp Whether to alter the local DHCP configuration (default no).
17 #
18 #============================================================================
20 dir=$(dirname "$0")
21 . "$dir/xen-script-common.sh"
22 . "$dir/xen-network-common.sh"
24 findCommand "$@"
25 evalVariables "$@"
27 netdev=${netdev:-eth0}
28 # antispoofing not yet implemented
29 antispoof=${antispoof:-no}
31 # turn on dhcp feature by default if dhcpd is installed
32 if [ -f /etc/dhcpd.conf ]
33 then
34 dhcp=${dhcp:-yes}
35 else
36 dhcp=${dhcp:-no}
37 fi
40 if [ "$dhcp" != 'no' ]
41 then
42 dhcpd_conf_file=$(find_dhcpd_conf_file)
43 dhcpd_init_file=$(find_dhcpd_init_file)
44 if [ -z "$dhcpd_conf_file" ] || [ -z "$dhcpd_init_file" ]
45 then
46 echo 'Failed to find dhcpd configuration or init file.' >&2
47 exit 1
48 fi
49 fi
52 function dhcp_start()
53 {
54 if ! grep -q "subnet 10.0.0.0" "$dhcpd_conf_file"
55 then
56 echo >>"$dhcpd_conf_file" "subnet 10.0.0.0 netmask 255.255.0.0 {}"
57 fi
59 "$dhcpd_init_file" restart
60 }
63 function dhcp_stop()
64 {
65 local tmpfile=$(mktemp)
66 grep -v "subnet 10.0.0.0" "$dhcpd_conf_file" >"$tmpfile"
67 if diff "$tmpfile" "$dhcpd_conf_file" >&/dev/null
68 then
69 rm "$tmpfile"
70 else
71 mv "$tmpfile" "$dhcpd_conf_file"
72 fi
74 "$dhcpd_init_file" restart
75 }
78 op_start() {
79 echo 1 >/proc/sys/net/ipv4/ip_forward
80 iptables -t nat -A POSTROUTING -o ${netdev} -j MASQUERADE
81 [ "$dhcp" != 'no' ] && dhcp_start
82 }
85 op_stop() {
86 [ "$dhcp" != 'no' ] && dhcp_stop
87 iptables -t nat -D POSTROUTING -o ${netdev} -j MASQUERADE
88 }
91 show_status() {
92 echo '============================================================'
93 ifconfig
94 echo ' '
95 ip route list
96 echo ' '
97 route -n
98 echo '============================================================'
100 }
102 case "$command" in
103 start)
104 op_start
105 ;;
107 stop)
108 op_stop
109 ;;
111 status)
112 show_status
113 ;;
115 *)
116 echo "Unknown command: $command" >&2
117 echo 'Valid commands are: start, stop, status' >&2
118 exit 1
119 esac