Skip to contentSkip to conversation

network-bridge script support for multiple external interfaces

PATCH In review Charles Duffy 2 participants 3 messages Oct 14, 2005 – Oct 15, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

tools/examples/network-bridge +27 -23
diff -r 70aa62954e91 tools/examples/network-bridge
@@ -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
 
-bridge=${bridge:-xen-br0}
-netdev=${netdev:-eth0}
+virtnum=${virtnum:-0}
+bridge=${bridge:-xen-br${virtnum}}
+netdev=${netdev:-eth${virtnum}}
 antispoof=${antispoof:-no}
 
-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 's/.*\(..:..:..:..:..:..\).*/\1/'`
 	if ! ifdown ${netdev} ; then
 		# if ifup didn't work, see if we have an ip= on cmd line
@@ -199,14 +203,14 @@
 		fi
 	fi
 	ip link set ${netdev} name p${netdev}
-	ip link set veth0 name ${netdev}
+	ip link set veth${virtnum} name ${netdev}
 	ifconfig p${netdev} 0.0.0.0 -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 @@
 		fi
         fi
     else
-	# old style without veth0
+	# old style without veth${virtnum}
 	transfer_addrs ${netdev} ${bridge}
         transfer_routes ${netdev} ${bridge}
     fi
@@ -233,10 +237,10 @@
         return
     fi
 
-    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} 0.0.0.0 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}
 
     else
         transfer_routes ${bridge} ${netdev}

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 1 line · Charles Duffy
 # antispoof  Whether to use iptables to prevent spoofing (default yes).

[...]

Quoted 1 line

antispoof=${antispoof:-no}

The antispoof default is not consistent with the comment.

Signature · 1 line
David Hopwood <[email protected]>
#2 lore raw
Quoted 7 lines · David Hopwood
Quoted 1 line · Charles Duffy
 # antispoof  Whether to use iptables to prevent spoofing (default yes).

[...]

Quoted 1 line

antispoof=${antispoof:-no}

The antispoof default is not consistent with the comment.

Quite so. (That's original behavior, though, and so any fix for it should be checked in as a separate changeset -- from my revision-control-nazi days I still have a strong preference for keeping different fixes in different changesets so that they can be merged, accepted or rejected, and otherwise handled individually).