debuggers.hg

view tools/hotplug/Linux/vif-bridge @ 21990:0232bc7c9544

tools/hotplug, Use udev rules instead of qemu script to setup the bridge.
From: Anthony PERARD <anthony.perard@citrix.com>

This patch adds a second argument to vif-bridge script. It can be "vif"
or "tap". "vif" give the default behavior and "tap" just add the
interface to the found bridge when the action is "add".

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
tools/hotplug/Linux/vif-bridge | 20 ++++++---
tools/hotplug/Linux/vif-common.sh | 70 ++++++++++++++++++++++++---------
tools/hotplug/Linux/xen-backend.rules | 5 +-
tools/libxl/libxl.c | 6 +-
4 files changed, 70 insertions(+), 31 deletions(-)
author Anthony Perard <anthony.perard@citrix.com>
date Mon Aug 09 16:46:02 2010 +0100 (2010-08-09)
parents 415505139333
children 937488219719
line source
1 #!/bin/bash
2 #============================================================================
3 # ${XEN_SCRIPT_DIR}/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 ${XEN_CONFIG_DIR}/xend-config.sxp. If the script is specified in
9 # neither of those 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 "$dev"
85 add_to_bridge "$bridge" "$dev"
86 ;;
88 offline)
89 do_without_error brctl delif "$bridge" "$dev"
90 do_without_error ifconfig "$dev" down
91 ;;
93 add)
94 add_to_bridge "$bridge" "$dev"
95 ;;
96 esac
98 if [ "$type_if" = vif ]; then
99 handle_iptable
100 fi
102 log debug "Successful vif-bridge $command for $dev, bridge $bridge."
103 if [ "$type_if" = vif -a "$command" = "online" ]
104 then
105 success
106 fi