ia64/xen-unstable

view tools/examples/vif-bridge @ 4895:24dfd18ea63e

bitkeeper revision 1.1159.258.120 (42848bfe8kMyWWcBA64rq7h7l7AyoA)

Shadow code bug fix (found by Ian) that was breaking refcounts, and subsequently
causing migration problems.
author mafetter@fleming.research
date Fri May 13 11:14:06 2005 +0000 (2005-05-13)
parents 8b9d5ad416ea
children 2abc9e0c7f87
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 $*"
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
67 echo 'Valid commands are: up, down'
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/remove vif to/from bridge.
78 brctl ${brcmd} ${bridge} ${vif}
79 ifconfig ${vif} $OP
81 if [ ${ip} ] ; then
83 # If we've been given a list of IP networks, allow pkts with these src addrs.
84 for addr in ${ip} ; do
85 iptables ${iptcmd} FORWARD -m physdev --physdev-in ${vif} -s ${addr} -j ACCEPT
86 done
88 # Always allow us to talk to a DHCP server anyhow.
89 iptables ${iptcmd} FORWARD -m physdev --physdev-in ${vif} -p udp --sport 68 --dport 67 -j ACCEPT
90 fi