ia64/xen-unstable

view tools/hotplug/Linux/vif-common.sh @ 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 e15d30dfb600
line source
1 #
2 # Copyright (c) 2005 XenSource Ltd.
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of version 2.1 of the GNU Lesser General Public
6 # License as published by the Free Software Foundation.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 #
19 dir=$(dirname "$0")
20 . "$dir/xen-hotplug-common.sh"
21 . "$dir/xen-network-common.sh"
23 findCommand "$@"
25 if [ "$command" != "online" ] &&
26 [ "$command" != "offline" ] &&
27 [ "$command" != "add" ] &&
28 [ "$command" != "remove" ]
29 then
30 log err "Invalid command: $command"
31 exit 1
32 fi
34 case "$command" in
35 add | remove)
36 exit 0
37 ;;
38 esac
41 # Parameters may be read from the environment, the command line arguments, and
42 # the store, with overriding in that order. The environment is given by the
43 # driver, the command line is given by the Xend global configuration, and
44 # store details are given by the per-domain or per-device configuration.
46 evalVariables "$@"
48 ip=${ip:-}
49 ip=$(xenstore_read_default "$XENBUS_PATH/ip" "$ip")
51 # Check presence of compulsory args.
52 XENBUS_PATH="${XENBUS_PATH:?}"
53 vif="${vif:?}"
56 vifname=$(xenstore_read_default "$XENBUS_PATH/vifname" "")
57 if [ "$vifname" ]
58 then
59 if [ "$command" == "online" ] && ! ip link show "$vifname" >&/dev/null
60 then
61 do_or_die ip link set "$vif" name "$vifname"
62 fi
63 vif="$vifname"
64 fi
67 frob_iptable()
68 {
69 if [ "$command" == "online" ]
70 then
71 local c="-A"
72 else
73 local c="-D"
74 fi
76 iptables "$c" FORWARD -m physdev --physdev-in "$vif" "$@" -j ACCEPT \
77 2>/dev/null ||
78 [ "$c" == "-D" ] ||
79 log err \
80 "iptables $c FORWARD -m physdev --physdev-in $vif $@ -j ACCEPT failed.
81 If you are using iptables, this may affect networking for guest domains."
82 }
85 ##
86 # Add or remove the appropriate entries in the iptables. With antispoofing
87 # turned on, we have to explicitly allow packets to the interface, regardless
88 # of the ip setting. If ip is set, then we additionally restrict the packets
89 # to those coming from the specified networks, though we allow DHCP requests
90 # as well.
91 #
92 handle_iptable()
93 {
94 # Check for a working iptables installation. Checking for the iptables
95 # binary is not sufficient, because the user may not have the appropriate
96 # modules installed. If iptables is not working, then there's no need to do
97 # anything with it, so we can just return.
98 if ! iptables -L -n >&/dev/null
99 then
100 return
101 fi
103 if [ "$ip" != "" ]
104 then
105 local addr
106 for addr in $ip
107 do
108 frob_iptable -s "$addr"
109 done
111 # Always allow the domain to talk to a DHCP server.
112 frob_iptable -p udp --sport 68 --dport 67
113 else
114 # No IP addresses have been specified, so allow anything.
115 frob_iptable
116 fi
117 }
120 ##
121 # ip_of interface
122 #
123 # Print the IP address currently in use at the given interface, or nothing if
124 # the interface is not up.
125 #
126 ip_of()
127 {
128 ip addr show "$1" | awk "/^.*inet.*$1\$/{print \$2}" | sed -n '1 s,/.*,,p'
129 }
132 ##
133 # dom0_ip
134 #
135 # Print the IP address of the interface in dom0 through which we are routing.
136 # This is the IP address on the interface specified as "netdev" as a parameter
137 # to these scripts, or eth0 by default. This function will call fatal if no
138 # such interface could be found.
139 #
140 dom0_ip()
141 {
142 local nd=${netdev:-eth0}
143 local result=$(ip_of "$nd")
144 if [ -z "$result" ]
145 then
146 fatal
147 "$netdev is not up. Bring it up or specify another interface with " \
148 "netdev=<if> as a parameter to $0."
149 fi
150 echo "$result"
151 }