[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] network-bridge script support for multiple external interfaces

The attached patch allows the network-bridge script to be used to generate multiple bridges corresponding to different physical interfaces. It adds a new parameter, "virtnum", used to refer both to the loopback interface to be used and to set defaults regarding the physical interface and bridge name.

Thus, if one wishes to start xen-br0 on eth0 and xen-br1 on eth1, one need only call:

network-bridge start ## virtnum is 0 by default
network-bridge start virtnum=1

...well, that and set loopback.nloopbacks=2 in the Dom0 kernel parameters.
diff -r 70aa62954e91 tools/examples/network-bridge
--- a/tools/examples/network-bridge     Fri Oct 14 00:42:34 2005
+++ b/tools/examples/network-bridge     Fri Oct 14 08:13:17 2005
@@ -5,8 +5,8 @@
 # The script name to use is defined in /etc/xen/xend-config.sxp
 # in the network-script field.
-# This script creates a bridge (default xen-br0), adds a device
-# (default eth0) to it, copies the IP addresses from the device
+# This script creates a bridge (default xen-br${virtnum}), adds a device
+# (default eth${virtnum}) to it, copies the IP addresses from the device
 # to the bridge and adjusts the routes accordingly.
 # If all goes well, this should ensure that networking stays up.
@@ -20,8 +20,11 @@
 # Vars:
-# bridge     The bridge to use (default xen-br0).
-# netdev     The interface to add to the bridge (default eth0).
+# virtnum    Virtual device number to use (default 0). Numbers >=1
+#            require the netback driver to have nloopbacks set to a
+#            higher value than its default of 1.
+# bridge     The bridge to use (default xen-br${virtnum}).
+# netdev     The interface to add to the bridge (default eth${virtnum}).
 # antispoof  Whether to use iptables to prevent spoofing (default yes).
 # start:
@@ -60,11 +63,12 @@
 # Pull variables in args in to environment.
 for arg ; do export "${arg}" ; done
-echo "*network $OP bridge=$bridge netdev=$netdev antispoof=$antispoof" >&2
+echo "*network $OP bridge=$bridge netdev=$netdev antispoof=$antispoof 
virtnum=$virtnum" >&2
 # Usage: transfer_addrs src dst
 # Copy all IP addresses (including aliases) from device $src to device $dst.
@@ -182,11 +186,11 @@
     create_bridge ${bridge}
-    if ifconfig 2>/dev/null | grep -q veth0 ; then
-        return
-    fi
-    if ifconfig veth0 2>/dev/null | grep -q veth0 ; then
+    if ifconfig 2>/dev/null | grep -q veth${virtnum} ; then
+        return
+    fi
+    if ifconfig veth${virtnum} 2>/dev/null | grep -q veth${virtnum} ; then
        mac=`ifconfig ${netdev} | grep HWadd | sed -e 
        if ! ifdown ${netdev} ; then
                # if ifup didn't work, see if we have an ip= on cmd line
@@ -199,14 +203,14 @@
        ip link set ${netdev} name p${netdev}
-       ip link set veth0 name ${netdev}
+       ip link set veth${virtnum} name ${netdev}
        ifconfig p${netdev} -arp down
        ifconfig p${netdev} hw ether fe:ff:ff:ff:ff:ff
        ifconfig ${netdev} hw ether ${mac}
-       add_to_bridge ${bridge} vif0.0
+       add_to_bridge ${bridge} vif0.${virtnum}
        add_to_bridge ${bridge} p${netdev}
        ip link set ${bridge} up
-       ip link set vif0.0 up
+       ip link set vif0.${virtnum} up
        ip link set p${netdev} up
        if ! ifup ${netdev} ; then
                if [ ${kip} ] ; then
@@ -218,7 +222,7 @@
-       # old style without veth0
+       # old style without veth${virtnum}
        transfer_addrs ${netdev} ${bridge}
         transfer_routes ${netdev} ${bridge}
@@ -233,10 +237,10 @@
-    if ifconfig peth0 2>/dev/null | grep -q peth0 ; then
-        ifconfig vif0.0 down
-        mac=`ifconfig eth0 | grep HWadd | \
+    if ifconfig peth${virtnum} 2>/dev/null | grep -q peth${virtnum} ; then
+        ifconfig vif0.${virtnum} down
+        mac=`ifconfig eth${virtnum} | grep HWadd | \
             sed -e 's/.*\(..:..:..:..:..:..\).*/\1/'`
         ifconfig ${netdev} down
         ifconfig ${netdev} hw ether fe:ff:ff:ff:ff:ff
@@ -245,11 +249,11 @@
         ifconfig p${netdev} hw ether ${mac} arp 
         brctl delif ${bridge} p${netdev}
-        ip link set eth0 name veth0
-        ip link set peth0 name eth0
+        ip link set eth${virtnum} name veth${virtnum}
+        ip link set peth${virtnum} name eth${virtnum}
         ifconfig ${bridge} down
         brctl delbr ${bridge}
-        ifup eth0
+        ifup eth${virtnum}
         transfer_routes ${bridge} ${netdev}
Xen-devel mailing list



Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.