ia64/xen-unstable
changeset 8303:52f214d983fb
Flush the addresses from the new eth0 before trying to add the new address to
it, when using ip on the kernel command line and not using the installed ifup /
ifdown. This stops the script bailing out if there is already an address
attached to that device, which was leaving the device without routing (since
this has already been removed).
Fix the stop action under the same circumstances. No attempt was made to
restore the kernel command line details to the interfaces if the ifdown failed
in that case.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
it, when using ip on the kernel command line and not using the installed ifup /
ifdown. This stops the script bailing out if there is already an address
attached to that device, which was leaving the device without routing (since
this has already been removed).
Fix the stop action under the same circumstances. No attempt was made to
restore the kernel command line details to the interfaces if the ifdown failed
in that case.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
author | emellor@leeni.uk.xensource.com |
---|---|
date | Thu Dec 08 16:11:48 2005 +0000 (2005-12-08) |
parents | e64e28e36e02 |
children | efc71a3e9f6f |
files | tools/examples/network-bridge |
line diff
1.1 --- a/tools/examples/network-bridge Thu Dec 08 15:54:35 2005 +0000 1.2 +++ b/tools/examples/network-bridge Thu Dec 08 16:11:48 2005 +0000 1.3 @@ -89,6 +89,31 @@ legacy_mask_to_prefix() { 1.4 exit 1 1.5 } 1.6 1.7 +parse_kernel_ip() { 1.8 + if egrep 'ip=[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:' /proc/cmdline; then 1.9 + kip=`sed -e 's!.*ip=\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\):.*!\1!' /proc/cmdline` 1.10 + kmask=`sed -e 's!.*ip=[^:]*:[^:]*:[^:]*:\([^:]*\):.*!\1!' /proc/cmdline` 1.11 + kgate=`sed -e 's!.*ip=[^:]*:[^:]*:\([^:]*\):.*!\1!' /proc/cmdline` 1.12 + fi 1.13 +} 1.14 + 1.15 +do_ifup() { 1.16 + if ! ifup $1 ; then 1.17 + if [ ${kip} ] ; then 1.18 + # use the addresses we grocked from /proc/cmdline 1.19 + if [ -z "${kmask}" ]; then 1.20 + PREFIX=32 1.21 + else 1.22 + legacy_mask_to_prefix ${kmask} 1.23 + fi 1.24 + ip addr flush $1 1.25 + ip addr add ${kip}/${PREFIX} dev $1 1.26 + ip link set dev $1 up 1.27 + [ ${kgate} ] && ip route add default via ${kgate} 1.28 + fi 1.29 + fi 1.30 +} 1.31 + 1.32 # Usage: transfer_addrs src dst 1.33 # Copy all IP addresses (including aliases) from device $src to device $dst. 1.34 transfer_addrs () { 1.35 @@ -234,14 +259,11 @@ using loopback.nloopbacks=<N> on the dom 1.36 preiftransfer ${netdev} 1.37 transfer_addrs ${netdev} ${vdev} 1.38 if ! ifdown ${netdev}; then 1.39 - # if ifup didn't work, see if we have an ip= on cmd line 1.40 - if egrep 'ip=[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:' /proc/cmdline; then 1.41 - kip=`sed -e 's!.*ip=\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\):.*!\1!' /proc/cmdline` 1.42 - kmask=`sed -e 's!.*ip=[^:]*:[^:]*:[^:]*:\([^:]*\):.*!\1!' /proc/cmdline` 1.43 - kgate=`sed -e 's!.*ip=[^:]*:[^:]*:\([^:]*\):.*!\1!' /proc/cmdline` 1.44 - ip link set ${netdev} down 1.45 - ip addr flush ${netdev} 1.46 - fi 1.47 + # If ifdown fails, take the IP details from the kernel command 1.48 + # line. 1.49 + parse_kernel_ip 1.50 + ip link set ${netdev} down 1.51 + ip addr flush ${netdev} 1.52 fi 1.53 ip link set ${netdev} name ${pdev} 1.54 ip link set ${vdev} name ${netdev} 1.55 @@ -253,20 +275,8 @@ using loopback.nloopbacks=<N> on the dom 1.56 add_to_bridge ${bridge} ${pdev} 1.57 ip link set ${bridge} up 1.58 ip link set ${vif0} up 1.59 - ip link set ${pdev} up 1.60 - if ! ifup ${netdev} ; then 1.61 - if [ ${kip} ] ; then 1.62 - # use the addresses we grocked from /proc/cmdline 1.63 - if [ -z "${kmask}" ]; then 1.64 - PREFIX=32; 1.65 - else 1.66 - legacy_mask_to_prefix ${kmask}; 1.67 - fi 1.68 - ip addr add ${kip}/${PREFIX} dev ${netdev} 1.69 - ip link set dev ${netdev} up 1.70 - [ ${kgate} ] && ip route add default via ${kgate} 1.71 - fi 1.72 - fi 1.73 + ip link set ${pdev} up 1.74 + do_ifup ${netdev} 1.75 else 1.76 # old style without ${vdev} 1.77 transfer_addrs ${netdev} ${bridge} 1.78 @@ -290,7 +300,9 @@ op_stop () { 1.79 ip link set dev ${vif0} down 1.80 mac=`ip link show ${netdev} | grep 'link\/ether' | sed -e 's/.*ether \(..:..:..:..:..:..\).*/\1/'` 1.81 transfer_addrs ${netdev} ${pdev} 1.82 - ifdown ${netdev} 1.83 + if ! ifdown ${netdev}; then 1.84 + parse_kernel_ip 1.85 + fi 1.86 ip link set ${netdev} down arp off 1.87 ip link set ${netdev} addr fe:ff:ff:ff:ff:ff 1.88 ip link set ${pdev} down 1.89 @@ -303,8 +315,7 @@ op_stop () { 1.90 1.91 ip link set ${netdev} name ${vdev} 1.92 ip link set ${pdev} name ${netdev} 1.93 - ifup ${netdev} 1.94 - 1.95 + do_ifup ${netdev} 1.96 else 1.97 transfer_routes ${bridge} ${netdev} 1.98 ip link set ${bridge} down