Skip to contentSkip to conversation

xend: Do not mess with bridge if admin has set one up already

PATCH In review Ian Jackson 5 participants 8 messages Jun 14, 2010 – Jun 16, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xend: Do not mess with bridge if admin has set one up already

Previously, the default "network-script", /etc/xen/scripts/network-bridge, would attempt to do its horrid work even if you had already set everything up in /etc/network/interfaces.

Setting up your bridge in /etc/network/interfaces is:
* easy
* required for libxl since libxl never does it for you
* not a fragile piece of lunacy
* properly documented
* the way everyone would expect it to work

In this small patch we make it so that the default config for xend doesn't mess about on startup if you already have a bridge, and doesn't mess about on shutdown unless your first-named bridge (eth0 or xenbr0, normally) doesn't also have a physical interface named p<whatever> (peth0 or pxenbr0) enslaved to it. The latter test is not ideal but will hopefully do from now until the time xend finally dies.

We also fix the "documentation" - ie, the comments in the default xend-config.sxp - to correspond to reality.

tools/examples/xend-config.sxp +17 -2
diff -r 125b3493dac9 tools/examples/xend-config.sxp
@@ -147,8 +147,22 @@
 #
 # (network-script 'network-bridge netdev=eth1')
 #
-# The bridge is named xenbr0, by default.  To rename the bridge, use
+# The bridge is named eth0, by default (yes, really!)
 #
+
+# It is normally much better to create the bridge yourself in
+# /etc/network/interfaces.  network-bridge start does nothing if you
+# already have a bridge, and network-bridge stop does nothing if the
+# default bridge name (normally eth0) is not a bridge.  See
+# bridge-utils-interfaces(5) for full information on the syntax in
+# /etc/network/interfaces, but you probably want something like this:
+#    iface xenbr0 inet static
+#        address [etc]
+#        netmask [etc]
+#        [etc]
+#        bridge_ports eth0
+#
+# To have network-bridge create a differently-named bridge, use:
 # (network-script 'network-bridge bridge=<name>')
 #
 # It is possible to use the network-bridge script in more complicated
@@ -169,7 +183,8 @@
 # configuring a new vif, but a value specified here would act as a default.
 #
 # If you are using only one bridge, the vif-bridge script will discover that,
-# so there is no need to specify it explicitly.
+# so there is no need to specify it explicitly.  The default is to use
+# the bridge which is listed first in the output from brctl.
 #
 (vif-script vif-bridge)
 
tools/hotplug/Linux/network-bridge +8 -0
diff -r 125b3493dac9 tools/hotplug/Linux/network-bridge
@@ -216,6 +216,10 @@
 	return
     fi
 
+    if [ `brctl show | wc -l` != 1 ]; then
+        return
+    fi
+
     if link_exists "$pdev"; then
         # The device is already up.
         return
@@ -263,6 +267,10 @@
     fi
     if ! link_exists "$bridge"; then
 	return
+    fi
+    if ! [ -e "/sys/class/net/${bridge}/brif/${pdev}" ]; then
+        # $bridge is not a bridge to which pdev is enslaved
+        return
     fi
 
     claim_lock "network-bridge"
#1 lore raw
Quoted 4 lines · Ian Jackson

Previously, the default "network-script", /etc/xen/scripts/network-bridge, would attempt to do its horrid work even if you had already set everything up in /etc/network/interfaces.

Instead of talking about "/etc/network/interfaces" you could write
"distro-specific network scripts like /etc/network/interfaces or /etc/sysconfig/network-scripts/ifcfg-*" :)

-- Pasi

Quoted 87 lines

Setting up your bridge in /etc/network/interfaces is:
* easy
* required for libxl since libxl never does it for you
* not a fragile piece of lunacy
* properly documented
* the way everyone would expect it to work

In this small patch we make it so that the default config for xend doesn't mess about on startup if you already have a bridge, and doesn't mess about on shutdown unless your first-named bridge (eth0 or xenbr0, normally) doesn't also have a physical interface named p<whatever> (peth0 or pxenbr0) enslaved to it. The latter test is not ideal but will hopefully do from now until the time xend finally dies.

We also fix the "documentation" - ie, the comments in the default xend-config.sxp - to correspond to reality.

diff -r 125b3493dac9 tools/examples/xend-config.sxp

tools/examples/xend-config.sxp +17 -2
@@ -147,8 +147,22 @@
 #
 # (network-script 'network-bridge netdev=eth1')
 #
-# The bridge is named xenbr0, by default.  To rename the bridge, use
+# The bridge is named eth0, by default (yes, really!)
 #
+
+# It is normally much better to create the bridge yourself in
+# /etc/network/interfaces.  network-bridge start does nothing if you
+# already have a bridge, and network-bridge stop does nothing if the
+# default bridge name (normally eth0) is not a bridge.  See
+# bridge-utils-interfaces(5) for full information on the syntax in
+# /etc/network/interfaces, but you probably want something like this:
+#    iface xenbr0 inet static
+#        address [etc]
+#        netmask [etc]
+#        [etc]
+#        bridge_ports eth0
+#
+# To have network-bridge create a differently-named bridge, use:
 # (network-script 'network-bridge bridge=<name>')
 #
 # It is possible to use the network-bridge script in more complicated
@@ -169,7 +183,8 @@
 # configuring a new vif, but a value specified here would act as a default.
 #
 # If you are using only one bridge, the vif-bridge script will discover that,
-# so there is no need to specify it explicitly.
+# so there is no need to specify it explicitly.  The default is to use
+# the bridge which is listed first in the output from brctl.
 #
 (vif-script vif-bridge)
 

diff -r 125b3493dac9 tools/hotplug/Linux/network-bridge

tools/hotplug/Linux/network-bridge +8 -0
@@ -216,6 +216,10 @@
 	return
     fi
 
+    if [ `brctl show | wc -l` != 1 ]; then
+        return
+    fi
+
     if link_exists "$pdev"; then
         # The device is already up.
         return
@@ -263,6 +267,10 @@
     fi
     if ! link_exists "$bridge"; then
 	return
+    fi
+    if ! [ -e "/sys/class/net/${bridge}/brif/${pdev}" ]; then
+        # $bridge is not a bridge to which pdev is enslaved
+        return
     fi
 
     claim_lock "network-bridge"

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

#2 lore raw

Pasi Kärkkäinen writes ("Re: [Xen-devel] [PATCH] xend: Do not mess with bridge if admin has set one up already"):

Quoted 7 lines · Ian Jackson
Quoted 3 lines

Previously, the default "network-script", /etc/xen/scripts/network-bridge, would attempt to do its horrid work even if you had already set everything up in /etc/network/interfaces.

Instead of talking about "/etc/network/interfaces" you could write
"distro-specific network scripts like /etc/network/interfaces or /etc/sysconfig/network-scripts/ifcfg-*" :)

I look forward to your patch on top of mine :-).

Ian.

#3 lore raw
In reply to Ian Jackson
Quoted 26 lines

-----Original Message-----
From: [email protected] [mailto:xen-devel- [email protected]] On Behalf Of Ian Jackson
Sent: Monday, June 14, 2010 8:07 AM
To: [email protected]
Subject: [Xen-devel] [PATCH] xend: Do not mess with bridge if admin has set one up already

Previously, the default "network-script", /etc/xen/scripts/network-bridge, would attempt to do its horrid work even if you had already set everything up in /etc/network/interfaces.

Setting up your bridge in /etc/network/interfaces is:
* easy
* required for libxl since libxl never does it for you
* not a fragile piece of lunacy
* properly documented
* the way everyone would expect it to work

In this small patch we make it so that the default config for xend doesn't mess about on startup if you already have a bridge, and doesn't mess about on shutdown unless your first-named bridge (eth0 or xenbr0, normally) doesn't also have a physical interface named p<whatever> (peth0 or pxenbr0) enslaved to it. The latter test is not ideal but will hopefully do from now until the time xend finally dies.

Quoted 4 lines

We also fix the "documentation" - ie, the comments in the default xend-config.sxp - to correspond to reality.

Finally! Much Appreciated!!!

For too long I've had to hack the scripts every time I install a new Xen setup so that it won't muck with my custom bridge settings.

Thanks!!!!

- Greg

#4 lore raw
In reply to Ian Jackson
Quoted 3 lines · Ian Jackson

Previously, the default "network-script", /etc/xen/scripts/network-bridge, would attempt to do its horrid work even if you had already set everything up in /etc/network/interfaces.

I like it. One of the first patches I apply to any newly cloned Xen tree is:

tools/examples/xend-config.sxp +1 -1
diff -r 2d74cb5f973f -r ed212583c51b tools/examples/xend-config.sxp
@@ -154,7 +154,7 @@
 # two fake interfaces per guest domain.  To do things like this, write
 # yourself a wrapper script, and call network-bridge from it, as appropriate.
 #
-(network-script network-bridge)
+#(network-script network-bridge)
 
 # The script used to control virtual interfaces.  This can be overridden on a
 # per-vif basis when creating a domain or a configuring a new vif.  The

Which is slightly more aggressive.

Quoted 2 lines

Setting up your bridge in /etc/network/interfaces is:
* easy

FWIW I typically use a stanza like:
iface xenbr0 inet dhcp
bridge_ports eth0
bridge_stp off
bridge_waitport 0
bridge_fd 0
bridge_maxwait 0

I think only bridge_ports is strictly required but the others are useful. As you note in the patch the bridge-utils-interfaces(5) manpage describes the available settings.

Ian.

#5 lore raw
Quoted 7 lines · Ian Campbell
Quoted 3 lines · Ian Jackson

Previously, the default "network-script", /etc/xen/scripts/network-bridge, would attempt to do its horrid work even if you had already set everything up in /etc/network/interfaces.

I like it. One of the first patches I apply to any newly cloned Xen tree is:

I wonder should we supply any init/hotplug/udev scripts at all?

-- Keir

Quoted 37 lines

diff -r 2d74cb5f973f -r ed212583c51b tools/examples/xend-config.sxp

tools/examples/xend-config.sxp Fri Jun 11 11:01:02 2010 +0100 renamed from tools/examples/xend-config.sxp Thu Jun 10 10:19:26 2010 +0100 +1 -1
@@ -154,7 +154,7 @@
 # two fake interfaces per guest domain.  To do things like this, write
 # yourself a wrapper script, and call network-bridge from it, as appropriate.
 #
-(network-script network-bridge)
+#(network-script network-bridge)
 
 # The script used to control virtual interfaces.  This can be overridden on a
 # per-vif basis when creating a domain or a configuring a new vif.  The

Which is slightly more aggressive.

Quoted 2 lines

Setting up your bridge in /etc/network/interfaces is:
* easy

FWIW I typically use a stanza like:
iface xenbr0 inet dhcp
bridge_ports eth0
bridge_stp off
bridge_waitport 0
bridge_fd 0
bridge_maxwait 0

I think only bridge_ports is strictly required but the others are useful. As you note in the patch the bridge-utils-interfaces(5) manpage describes the available settings.

Ian.

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

#6 lore raw

Keir Fraser writes ("Re: [Xen-devel] [PATCH] xend: Do not mess with bridge if admin has set one up already"):

Quoted 1 line

I wonder should we supply any init/hotplug/udev scripts at all?

We do still need to supply hotplug scripts to plumb block and vif backends to the appropriate dom0 resources. When you're using xl, that's all you need.

Ian.

#7 lore raw
In reply to Keir Fraser
Quoted 11 lines · Keir Fraser
Quoted 7 lines · Ian Campbell
Quoted 3 lines · Ian Jackson

Previously, the default "network-script", /etc/xen/scripts/network-bridge, would attempt to do its horrid work even if you had already set everything up in /etc/network/interfaces.

I like it. One of the first patches I apply to any newly cloned Xen tree is:

I wonder should we supply any init/hotplug/udev scripts at all?

Including something in tools/examples (where they already live today) seems reasonable to provide, well, examples.

I'm not sure it always makes sense to install all of them, at least by default. But perhaps that is a case by case determination (initscripts are different beasts to udev configuration etc)?