ia64/xen-unstable

view tools/hotplug/Linux/vif-bridge @ 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 415505139333
line source
1 #!/bin/bash
2 #============================================================================
3 # /etc/xen/vif-bridge
4 #
5 # Script for configuring a vif in bridged mode.
6 # The hotplugging system will call this script if it is specified either in
7 # the device configuration given to Xend, or the default Xend configuration
8 # in /etc/xen/xend-config.sxp. If the script is specified in neither of those
9 # places, then this script is the default.
10 #
11 # Usage:
12 # vif-bridge (add|remove|online|offline)
13 #
14 # Environment vars:
15 # vif vif interface name (required).
16 # XENBUS_PATH path to this device's details in the XenStore (required).
17 #
18 # Read from the store:
19 # bridge bridge to add the vif to (optional). Defaults to searching for the
20 # bridge itself.
21 # ip list of IP networks for the vif, space-separated (optional).
22 #
23 # up:
24 # Enslaves the vif interface to the bridge and adds iptables rules
25 # for its ip addresses (if any).
26 #
27 # down:
28 # Removes the vif interface from the bridge and removes the iptables
29 # rules for its ip addresses (if any).
30 #============================================================================
32 dir=$(dirname "$0")
33 . "$dir/vif-common.sh"
35 bridge=${bridge:-}
36 bridge=$(xenstore_read_default "$XENBUS_PATH/bridge" "$bridge")
38 if [ -z "$bridge" ]
39 then
40 bridge=$(brctl show | cut -d "
41 " -f 2 | cut -f 1)
43 if [ -z "$bridge" ]
44 then
45 fatal "Could not find bridge, and none was specified"
46 fi
47 else
48 #
49 # Old style bridge setup with netloop, used to have a bridge name
50 # of xenbrX, enslaving pethX and vif0.X, and then configuring
51 # eth0.
52 #
53 # New style bridge setup does not use netloop, so the bridge name
54 # is ethX and the physical device is enslaved pethX
55 #
56 # So if...
57 #
58 # - User asks for xenbrX
59 # - AND xenbrX doesn't exist
60 # - AND there is a ethX device which is a bridge
61 #
62 # ..then we translate xenbrX to ethX
63 #
64 # This lets old config files work without modification
65 #
66 if [ ! -e "/sys/class/net/$bridge" ] && [ -z "${bridge##xenbr*}" ]
67 then
68 if [ -e "/sys/class/net/eth${bridge#xenbr}/bridge" ]
69 then
70 bridge="eth${bridge#xenbr}"
71 fi
72 fi
73 fi
75 RET=0
76 ip link show $bridge 1>/dev/null 2>&1 || RET=1
77 if [ "$RET" -eq 1 ]
78 then
79 fatal "Could not find bridge device $bridge"
80 fi
82 case "$command" in
83 online)
84 setup_bridge_port "$vif"
85 add_to_bridge "$bridge" "$vif"
86 ;;
88 offline)
89 do_without_error brctl delif "$bridge" "$vif"
90 do_without_error ifconfig "$vif" down
91 ;;
92 esac
94 handle_iptable
96 log debug "Successful vif-bridge $command for $vif, bridge $bridge."
97 if [ "$command" == "online" ]
98 then
99 success
100 fi