Jon Mason
2005-Sep-29 22:20 UTC
[Xen-devel] [PATCH] tools: Fix network-bridge to work with Gentoo
This patch fixes domU networking in Gentoo. The change to ifup/ifdown (which isn''t availabe in Gentoo) prevents the bridge from being setup correctly. The patch below checks if ifup is avaiable, and if not starts the Gentoo networking scripts. Signed-off-by: Jon Mason <jdmason@us.ibm.com> # HG changeset patch # User root@pentium4 # Node ID 07ba15ba986268ff869d7d2253eab8eed3edbe8b # Parent f529cd119470032c2bc70b21432e733f9605727b Fix network-bridge to work with Gentoo diff -r f529cd119470 -r 07ba15ba9862 tools/examples/network-bridge --- a/tools/examples/network-bridge Thu Sep 29 17:28:28 2005 +++ b/tools/examples/network-bridge Thu Sep 29 22:03:46 2005 @@ -177,7 +177,12 @@ if ifconfig veth0 2>/dev/null | grep -q veth0 ; then mac=`ifconfig ${netdev} | grep HWadd | sed -e ''s/.*\(..:..:..:..:..:..\).*/\1/''` - if ! ifdown ${netdev} ; then + if which ifdown 2> /dev/null ; then + ifdown ${netdev} 2> RC=$? + else + /etc/init.d/net.${netdev} stop 2> RC=$? + fi + if ! $RC ; then # if ifup didn''t work, see if we have an ip= on cmd line if egrep ''ip=[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:'' /proc/cmdline ; then @@ -197,7 +202,12 @@ ip link set ${bridge} up ip link set vif0.0 up ip link set p${netdev} up - if ! ifup ${netdev} ; then + if which ifup 2> /dev/null ; then + ifup ${netdev} 2> RC=$? + else + /etc/init.d/net.${netdev} start 2> RC=$? + fi + if ! $RC ; then if [ ${kip} ] ; then # use the addresses we grocked from /proc/cmdline ifconfig ${netdev} ${kip} @@ -238,7 +248,7 @@ ip link set peth0 name eth0 ifconfig ${bridge} down brctl delbr ${bridge} - ifup eth0 + ifup eth0 2>/dev/null || /etc/init.d/net.eth0 start else transfer_routes ${bridge} ${netdev} _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Dan Smith
2005-Sep-29 23:11 UTC
Re: [Xen-devel] [PATCH] tools: Fix network-bridge to work with Gentoo
JM> This patch fixes domU networking in Gentoo. The change to JM> ifup/ifdown (which isn''t availabe in Gentoo) prevents the bridge JM> from being setup correctly. The patch below checks if ifup is JM> avaiable, and if not starts the Gentoo networking scripts. This brings up the idea about how we can be as distro-friendly as possible when it comes to network configuration. How about if we replace the distro-specific bits of the network-bridge script with calls out to a dedicated one, after we determine which distro we''re on? That way, we can cleanly add support for a new distro, without adding a bunch of if-then-elsif''s to the main script. Also, it would allow the distros to easily maintain and plug in their own scripts to integrate with their network configuration utilities. That way, they wouldn''t have to maintain a patch to the monolithic xen script. They could just drop their module into, say, /etc/xen/scripts/distros/redhat.sh, or something similar. I think that if we were to make a standard function interface (like LSB) that the scripts implement, then we could just source them and use their functions to carry out the wishes of the more complex logic in the master network-bridge script. Thoughts? -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Robb Romans
2005-Sep-29 23:23 UTC
Re: [Xen-devel] [PATCH] tools: Fix network-bridge to work with Gentoo
On Thursday 29 September 2005 05:20 pm, Jon Mason wrote:> This patch fixes domU networking in Gentoo. The change to > ifup/ifdown (which isn''t availabe in Gentoo) prevents the bridge from > being setup correctly. The patch below checks if ifup is avaiable, > and if not starts the Gentoo networking scripts. > > Signed-off-by: Jon Mason <jdmason@us.ibm.com> > > # HG changeset patch > # User root@pentium4 > # Node ID 07ba15ba986268ff869d7d2253eab8eed3edbe8b > # Parent f529cd119470032c2bc70b21432e733f9605727b > Fix network-bridge to work with Gentoo > > diff -r f529cd119470 -r 07ba15ba9862 tools/examples/network-bridge > --- a/tools/examples/network-bridge Thu Sep 29 17:28:28 2005 > +++ b/tools/examples/network-bridge Thu Sep 29 22:03:46 2005 > @@ -177,7 +177,12 @@ > > if ifconfig veth0 2>/dev/null | grep -q veth0 ; then > mac=`ifconfig ${netdev} | grep HWadd | sed -e > ''s/.*\(..:..:..:..:..:..\).*/\1/''` - if ! ifdown ${netdev} ; then > + if which ifdown 2> /dev/null ; then> + ifdown ${netdev} 2> RC=$?I don''t think you want the "2>" in there. You''re missing a semicolon in front of "RC=..."> + else > + /etc/init.d/net.${netdev} stop 2> RC=$?Same problem here.> + fi > + if ! $RC ; then > # if ifup didn''t work, see if we have an ip= on cmd line > if egrep ''ip=[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:'' /proc/cmdline ; > then > @@ -197,7 +202,12 @@ > ip link set ${bridge} up > ip link set vif0.0 up > ip link set p${netdev} up > - if ! ifup ${netdev} ; then > + if which ifup 2> /dev/null ; then > + ifup ${netdev} 2> RC=$?Same problem here.> + else > + /etc/init.d/net.${netdev} start 2> RC=$?Same problem here.> + fi > + if ! $RC ; then > if [ ${kip} ] ; then > # use the addresses we grocked from /proc/cmdline > ifconfig ${netdev} ${kip} > @@ -238,7 +248,7 @@ > ip link set peth0 name eth0 > ifconfig ${bridge} down > brctl delbr ${bridge} > - ifup eth0 > + ifup eth0 2>/dev/null || /etc/init.d/net.eth0 startI think you want to check whether ''ifup'' exists, not whether the command fails. Regards, Robb -- Robb Romans (512) 838-0419 Linux Commando T/L 678-0419 ARS NA5TT .-- - ..-. ..--.. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Nivedita Singhvi
2005-Sep-29 23:31 UTC
Re: [Xen-devel] [PATCH] tools: Fix network-bridge to work with Gentoo
Dan Smith wrote:> JM> This patch fixes domU networking in Gentoo. The change to > JM> ifup/ifdown (which isn''t availabe in Gentoo) prevents the bridge > JM> from being setup correctly. The patch below checks if ifup is > JM> avaiable, and if not starts the Gentoo networking scripts. > > This brings up the idea about how we can be as distro-friendly as > possible when it comes to network configuration. > > How about if we replace the distro-specific bits of the network-bridge > script with calls out to a dedicated one, after we determine which > distro we''re on? That way, we can cleanly add support for a new > distro, without adding a bunch of if-then-elsif''s to the main script. > > Also, it would allow the distros to easily maintain and plug in their > own scripts to integrate with their network configuration utilities. > That way, they wouldn''t have to maintain a patch to the monolithic xen > script. They could just drop their module into, say, > /etc/xen/scripts/distros/redhat.sh, or something similar. > > I think that if we were to make a standard function interface (like > LSB) that the scripts implement, then we could just source them and > use their functions to carry out the wishes of the more complex logic > in the master network-bridge script. > > Thoughts?Here''s one vote for doing that - need a clean point to insert customized pieces. thanks, Nivedita _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Pratt
2005-Sep-29 23:38 UTC
RE: [Xen-devel] [PATCH] tools: Fix network-bridge to work with Gentoo
> This patch fixes domU networking in Gentoo. The change to > ifup/ifdown (which isn''t availabe in Gentoo) prevents the > bridge from being setup correctly. The patch below checks if > ifup is avaiable, and if not starts the Gentoo networking scripts.Grrrr. At long last we have scripts that work on every version of SuSE, RHEL, Fedora, and Debain varient I''ve come across, and then gentoo does something different... I don''t particularly like this patches approach to fixing the problem, but then I don''t really think its worth a call-out to a separate vendor script either. I''d be inclined to pull the code around the ifup/down into a separate function and put the vendor workarounds in that to make it explicit. There''s already a bit of ugliness there to cope with setups where the interface is configured with ip= on the kernel command line rather than relying on vendor scripts at all. There''s also some subtle differences in the suse/rh ifup/down scripts. As I recall, the SuSE ones always return a status code of zero even if they fail. Anyhow, all of this is pretty easy to workaround, we should just pull it into a shell function for clarity. Ian _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Jon Mason
2005-Oct-04 23:54 UTC
[Xen-devel] [PATCH] tools: Fix network-bridge to work with Gentoo (version 2)
This patch fixes domU networking in Gentoo. The change to ifup/ifdown (which isn''t availabe in Gentoo) prevents the bridge from being setup correctly. The patch below checks if ifup is avaiable, and if not starts the Gentoo networking scripts. This new version includes shell functions where distro specific options may be handled (per Ian''s suggestion). Signed-off-by: Jon Mason <jdmason@us.ibm.com> # HG changeset patch # User root@pentium4 # Node ID 6de75791e5a54b8eb093c6630efb68f896c16fa3 # Parent 00037ba13f0bb8efe4b2c3efe40200eac21c68dd Fix network-bridge to work with Gentoo diff -r 00037ba13f0b -r 6de75791e5a5 tools/examples/network-bridge --- a/tools/examples/network-bridge Tue Oct 4 17:23:58 2005 +++ b/tools/examples/network-bridge Tue Oct 4 23:42:28 2005 @@ -54,6 +54,32 @@ antispoof=${antispoof:-no} echo "*network $OP bridge=$bridge netdev=$netdev antispoof=$antispoof" >&2 + +# Usage: eth_down interface +eth_down() { + local rc + local eth=$1 + ifdown=$(which ifdown 2>/dev/null) + if [ -n "$ifdown" ]; then + $ifdown ${eth}; rc=$? + else + /etc/init.d/net.${eth} stop; rc=$? + fi + return $rc +} + +# Usage: eth_up interface +eth_up() { + local rc + local eth=$1 + ifdown=$(which ifup 2>/dev/null) + if [ -n "$ifup" ]; then + $ifup ${eth}; rc=$? + else + /etc/init.d/net.${eth} start; rc=$? + fi + return $rc +} # Usage: transfer_addrs src dst # Copy all IP addresses (including aliases) from device $src to device $dst. @@ -177,7 +203,7 @@ if ifconfig veth0 2>/dev/null | grep -q veth0 ; then mac=`ifconfig ${netdev} | grep HWadd | sed -e ''s/.*\(..:..:..:..:..:..\).*/\1/''` - if ! ifdown ${netdev} ; then + if ! eth_down ${netdev} ; then # if ifup didn''t work, see if we have an ip= on cmd line if egrep ''ip=[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:'' /proc/cmdline ; then @@ -197,7 +223,7 @@ ip link set ${bridge} up ip link set vif0.0 up ip link set p${netdev} up - if ! ifup ${netdev} ; then + if ! eth_up ${netdev} ; then if [ ${kip} ] ; then # use the addresses we grocked from /proc/cmdline ifconfig ${netdev} ${kip} @@ -238,7 +264,7 @@ ip link set peth0 name eth0 ifconfig ${bridge} down brctl delbr ${bridge} - ifup eth0 + eth_up eth0 else transfer_routes ${bridge} ${netdev} _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Anthony Liguori
2005-Oct-05 04:03 UTC
Re: [Xen-devel] [PATCH] tools: Fix network-bridge to work with Gentoo (version 2)
A slightly less invasive way to do it is to have a Gentoo compatibility script that looks something like this: # Gentoo doesn''t have ifup/ifdown so if we''re on Gentoo define some which ifup >& /dev/null if [ "$?" != 0 -a -e /etc/conf.d/net ]; then ifup() { /etc/init.d/net.$1 start } ifdown() { /etc/init.d/net.$1 stop } fi This could then be sourced from the network script (or just inlined). Jon Mason wrote:>This patch fixes domU networking in Gentoo. The change to ifup/ifdown >(which isn''t availabe in Gentoo) prevents the bridge from being setup >correctly. The patch below checks if ifup is avaiable, and if not >starts the Gentoo networking scripts. > >This new version includes shell functions where distro specific options >may be handled (per Ian''s suggestion). > >Signed-off-by: Jon Mason <jdmason@us.ibm.com> > ># HG changeset patch ># User root@pentium4 ># Node ID 6de75791e5a54b8eb093c6630efb68f896c16fa3 ># Parent 00037ba13f0bb8efe4b2c3efe40200eac21c68dd > >Fix network-bridge to work with Gentoo > >diff -r 00037ba13f0b -r 6de75791e5a5 tools/examples/network-bridge >--- a/tools/examples/network-bridge Tue Oct 4 17:23:58 2005 >+++ b/tools/examples/network-bridge Tue Oct 4 23:42:28 2005 >@@ -54,6 +54,32 @@ > antispoof=${antispoof:-no} > > echo "*network $OP bridge=$bridge netdev=$netdev antispoof=$antispoof" >&2 >+ >+# Usage: eth_down interface >+eth_down() { >+ local rc >+ local eth=$1 >+ ifdown=$(which ifdown 2>/dev/null) >+ if [ -n "$ifdown" ]; then >+ $ifdown ${eth}; rc=$? >+ else >+ /etc/init.d/net.${eth} stop; rc=$? >+ fi >+ return $rc >+} >+ >+# Usage: eth_up interface >+eth_up() { >+ local rc >+ local eth=$1 >+ ifdown=$(which ifup 2>/dev/null) >+ if [ -n "$ifup" ]; then >+ $ifup ${eth}; rc=$? >+ else >+ /etc/init.d/net.${eth} start; rc=$? >+ fi >+ return $rc >+} > > # Usage: transfer_addrs src dst > # Copy all IP addresses (including aliases) from device $src to device $dst. >@@ -177,7 +203,7 @@ > > if ifconfig veth0 2>/dev/null | grep -q veth0 ; then > mac=`ifconfig ${netdev} | grep HWadd | sed -e ''s/.*\(..:..:..:..:..:..\).*/\1/''` >- if ! ifdown ${netdev} ; then >+ if ! eth_down ${netdev} ; then > # if ifup didn''t work, see if we have an ip= on cmd line > if egrep ''ip=[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:'' /proc/cmdline ; > then >@@ -197,7 +223,7 @@ > ip link set ${bridge} up > ip link set vif0.0 up > ip link set p${netdev} up >- if ! ifup ${netdev} ; then >+ if ! eth_up ${netdev} ; then > if [ ${kip} ] ; then > # use the addresses we grocked from /proc/cmdline > ifconfig ${netdev} ${kip} >@@ -238,7 +264,7 @@ > ip link set peth0 name eth0 > ifconfig ${bridge} down > brctl delbr ${bridge} >- ifup eth0 >+ eth_up eth0 > > else > transfer_routes ${bridge} ${netdev} > >_______________________________________________ >Xen-devel mailing list >Xen-devel@lists.xensource.com >http://lists.xensource.com/xen-devel > > >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Jeremy Katz
2005-Oct-05 15:05 UTC
Re: [Xen-devel] [PATCH] tools: Fix network-bridge to work with Gentoo (version 2)
On Tue, 2005-10-04 at 18:54 -0500, Jon Mason wrote:> This patch fixes domU networking in Gentoo. The change to ifup/ifdown > (which isn''t availabe in Gentoo) prevents the bridge from being setup > correctly. The patch below checks if ifup is avaiable, and if not > starts the Gentoo networking scripts. > > This new version includes shell functions where distro specific options > may be handled (per Ian''s suggestion).Doing this all in the same script feels like it''s going to spiral out of control into spaghetti-land kind of quickly and also not allow for some of the real variation that''s going to be desired for different distributions. Why try to do a one-size-fits-all instead of having scripts which really can be made to best fit the distro? With a more traditional build process, it would be easy enough to have distro specific scripts dropped into subdirs of the examples directory and use them as overrides/replacements. The thing that makes that tricky for Xen is the way make dist works. Thinking aloud -- maybe just setting a variable so we know we''re in the ''make dist'' case and using that to install all the distro specific stuff into DESTDIR and then letting install.sh also pick out the right distro would work. Then for the more normal install case, just the proper things for the distro would get installed. Does this seem reasonable? I''ll try to cook up something today Jeremy _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel