diff --git a/.rootkeys b/.rootkeys index 1afa18ea51..9126843031 100644 --- a/.rootkeys +++ b/.rootkeys @@ -325,7 +325,9 @@ 40278d94cIUWl2eRgnwZtr4hTyWT1Q tools/examples/init.d/xendomains 41dde8afTUuvdtFUlOx0ZRusKxyd8w tools/examples/mem-map.sxp 40ee75a9xFz6S05sDKu-JCLqyVTkDA tools/examples/network +41e661e1giIEKbJ25qfiP-ke8u8hFA tools/examples/network-route 40ee75a967sxgcRY4Q7zXoVUaJ4flA tools/examples/vif-bridge +41e661e1ooiRKlOfwumG6wwzc0PdhQ tools/examples/vif-route 40ee75a93cqxHp6MiYXxxwR5j2_8QQ tools/examples/xend-config.sxp 41dde8af6M2Pm1Rrv_f5jEFC_BIOIA tools/examples/xmexample.vmx 41090ec8Pj_bkgCBpg2W7WfmNkumEA tools/examples/xmexample1 diff --git a/tools/examples/Makefile b/tools/examples/Makefile index f0f8250ea0..7bae4d9fbc 100644 --- a/tools/examples/Makefile +++ b/tools/examples/Makefile @@ -14,8 +14,8 @@ XEN_CONFIGS += bochsrc # Xen script dir and scripts to go there. XEN_SCRIPT_DIR = /etc/xen/scripts -XEN_SCRIPTS = network -XEN_SCRIPTS += vif-bridge +XEN_SCRIPTS = network vif-bridge +XEN_SCRIPTS += network-route vif-route XEN_SCRIPTS += block-file XEN_SCRIPTS += block-enbd diff --git a/tools/examples/network-route b/tools/examples/network-route new file mode 100755 index 0000000000..cb217c068d --- /dev/null +++ b/tools/examples/network-route @@ -0,0 +1,19 @@ +#!/bin/sh +#============================================================================ +# Default Xen network start/stop script. +# Xend calls a network script when it starts. +# The script name to use is defined in /etc/xen/xend-config.sxp +# in the network-script field. +# +# Usage: +# +# network-route (start|stop|status) {VAR=VAL}* +# +# Vars: +# +# netdev The gateway interface (default eth0). +# antispoof Whether to use iptables to prevent spoofing (default yes). +# +#============================================================================ + +echo 1 >/proc/sys/net/ipv4/ip_forward diff --git a/tools/examples/vif-route b/tools/examples/vif-route new file mode 100755 index 0000000000..b15aea1e5c --- /dev/null +++ b/tools/examples/vif-route @@ -0,0 +1,76 @@ +#!/bin/sh +#============================================================================ +# /etc/xen/vif-route +# +# Script for configuring a vif in routed mode. +# Xend calls a vif script when bringing a vif up or down. +# This script is the default - but it can be configured for each vif. +# +# Example invocation: +# +# vif-route up domain=VM1 vif=vif1.0 ip="128.232.38.45/28 10.10.10.55/24" +# +# Usage: +# vif-route (up|down) {VAR=VAL}* +# +# Vars: +# +# domain name of the domain the interface is on (required). +# vif vif interface name (required). +# mac vif MAC address (required). +# ip list of IP networks for the vif, space-separated (optional). +#============================================================================ + +# Exit if anything goes wrong +set -e + +echo "vif-route $*" + +# Operation name. +OP=$1 +shift + +# Pull variables in args into environment +for arg ; do export "${arg}" ; done + +# Required parameters. Fail if not set. +domain=${domain:?} +vif=${vif:?} +mac=${mac:?} + +# Optional parameters. Set defaults. +ip=${ip:-''} # default to null (do nothing) + +main_ip=`ifconfig eth0 | grep "inet addr:" | sed -e 's/.*inet addr:\(\w\w*\.\w\w*\.\w\w*\.\w\w*\).*/\1/'` + +# Are we going up or down? +case $OP in + up) + ifconfig ${vif} 169.254.1.0 netmask 255.255.255.255 up + echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp + iptcmd='-A' + ipcmd='a' + ;; + down) + ifconfig ${vif} down + iptcmd='-D' + ipcmd='d' + ;; + *) + echo 'Invalid command: ' $OP + echo 'Valid commands are: up, down' + exit 1 + ;; +esac + +if [ ${ip} ] ; then + + # If we've been given a list of IP networks, allow pkts with these src addrs. + for addr in ${ip} ; do + ip r ${ipcmd} ${addr} dev ${vif} src ${main_ip} +# iptables ${iptcmd} FORWARD -m physdev --physdev-in ${vif} -s ${addr} -j ACCEPT + done + + # Always allow us to talk to a DHCP server anyhow. +# iptables ${iptcmd} FORWARD -m physdev --physdev-in ${vif} -p udp --sport 68 --dport 67 -j ACCEPT +fi diff --git a/tools/examples/xend-config.sxp b/tools/examples/xend-config.sxp index ee5dbbc0a3..a62b112519 100644 --- a/tools/examples/xend-config.sxp +++ b/tools/examples/xend-config.sxp @@ -8,12 +8,17 @@ # Specifying the empty string '' allows all connections. (xend-address '') +## Use the following if VIF traffic is routed. +# The script used to start/stop networking for xend. +#(network-script network-route) +# The default script used to control virtual interfaces. +#(vif-script vif-route) + +## Use the following if VIF traffic is bridged. # The script used to start/stop networking for xend. (network-script network) - # The default bridge that virtual interfaces should be connected to. (vif-bridge xen-br0) - # The default script used to control virtual interfaces. (vif-script vif-bridge) diff --git a/tools/python/xen/xm/create.py b/tools/python/xen/xm/create.py index 633888a643..7fc1887642 100644 --- a/tools/python/xen/xm/create.py +++ b/tools/python/xen/xm/create.py @@ -295,14 +295,18 @@ def configure_vifs(config_devs, vals): if idx < len(vifs): d = vifs[idx] mac = d.get('mac') + if not mac: + mac = randomMAC() bridge = d.get('bridge') script = d.get('script') backend = d.get('backend') + ip = d.get('ip') else: mac = randomMAC() bridge = None script = None backend = None + ip = None config_vif = ['vif'] config_vif.append(['mac', mac]) if bridge: @@ -311,6 +315,8 @@ def configure_vifs(config_devs, vals): config_vif.append(['script', script]) if backend: config_vif.append(['backend', backend]) + if ip: + config_vif.append(['ip', ip]) config_devs.append(['device', config_vif]) def configure_vfr(config, vals): @@ -399,7 +405,7 @@ def preprocess_vifs(opts, vals): (k, v) = b.strip().split('=', 1) k = k.strip() v = v.strip() - if k not in ['mac', 'bridge', 'script', 'backend']: + if k not in ['mac', 'bridge', 'script', 'backend', 'ip']: opts.err('Invalid vif specifier: ' + vif) d[k] = v vifs.append(d)