ia64/xen-unstable

view tools/examples/vif-bridge @ 6413:d61f8afd292c

1. Remove workaround patch
2. Update scripts/vif-bridge to not call 'brctl delif'

When a domU is shutdown/destroyed and the netif is destroyed, the
notify_call_chain triggered from unregister_netdevice() will trigger the
bridge event handler and which will call the proper code to remove the
device from the bridge.

I can't see any reason why brtcl delif should be called when taking out
a domain if the call chain will delete the interface from the bridge
when the vif is destroyed automatically.

Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Aug 25 15:51:30 2005 +0000 (2005-08-25)
parents 3b25e1de5efb
children b54144915ae6 0610add7c3fe b4b3f6be5226
line source
1 #!/bin/sh
2 #============================================================================
3 # /etc/xen/vif-bridge
4 #
5 # Script for configuring a vif in bridged mode.
6 # Xend calls a vif script when bringing a vif up or down.
7 # This script is the default - but it can be configured for each vif.
8 #
9 # Example invocation:
10 #
11 # vif-bridge up domain=VM1 vif=vif1.0 bridge=xen-br0 ip="128.232.38.45/28 10.10.10.55/24"
12 #
13 #
14 # Usage:
15 # vif-bridge (up|down) {VAR=VAL}*
16 #
17 # Vars:
18 #
19 # domain name of the domain the interface is on (required).
20 # vif vif interface name (required).
21 # mac vif MAC address (required).
22 # bridge bridge to add the vif to (required).
23 # ip list of IP networks for the vif, space-separated (optional).
24 #
25 # up:
26 # Enslaves the vif interface to the bridge and adds iptables rules
27 # for its ip addresses (if any).
28 #
29 # down:
30 # Removes the vif interface from the bridge and removes the iptables
31 # rules for its ip addresses (if any).
32 #============================================================================
34 # Exit if anything goes wrong
35 set -e
37 echo "*vif-bridge $*" >&2
39 # Operation name.
40 OP=$1
41 shift
43 # Pull variables in args into environment
44 for arg ; do export "${arg}" ; done
46 # Required parameters. Fail if not set.
47 domain=${domain:?}
48 vif=${vif:?}
49 mac=${mac:?}
50 bridge=${bridge:?}
52 # Optional parameters. Set defaults.
53 ip=${ip:-''} # default to null (do nothing)
55 # Are we going up or down?
56 case $OP in
57 up)
58 brcmd='addif'
59 iptcmd='-A'
60 ;;
61 down)
62 brcmd='delif'
63 iptcmd='-D'
64 ;;
65 *)
66 echo 'Invalid command: ' $OP >&2
67 echo 'Valid commands are: up, down' >&2
68 exit 1
69 ;;
70 esac
72 # Don't do anything if the bridge is "null".
73 if [ "${bridge}" == "null" ] ; then
74 exit
75 fi
77 # Add vif to bridge. vifs are auto-removed from bridge.
78 if [ "${brcmd}" == "addif" ] ; then
79 brctl ${brcmd} ${bridge} ${vif}
80 fi
81 ifconfig ${vif} $OP
83 if [ ${ip} ] ; then
85 # If we've been given a list of IP networks, allow pkts with these src addrs.
86 for addr in ${ip} ; do
87 iptables ${iptcmd} FORWARD -m physdev --physdev-in ${vif} -s ${addr} -j ACCEPT
88 done
90 # Always allow us to talk to a DHCP server anyhow.
91 iptables ${iptcmd} FORWARD -m physdev --physdev-in ${vif} -p udp --sport 68 --dport 67 -j ACCEPT
92 fi