ia64/xen-unstable

view tools/examples/vif-bridge @ 6946:e703abaf6e3d

Add behaviour to the remove methods to remove the transaction's path itself. This allows us to write Remove(path) to remove the specified path rather than having to slice the path ourselves.
author emellor@ewan
date Sun Sep 18 14:42:13 2005 +0100 (2005-09-18)
parents 3233e7ecfa9f
children 06d84bf87159
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