ia64/xen-unstable
changeset 8540:fbee8d9fbaba
Made network-bridge script work on ALL systems missing ifup/down.
This is done by defining ifup/down both to 'false' when they're
missing; then instead of attempting to parse the IP params from
the kernel command line, we get them from 'ip' instead. So this
works even with (for example) ip=dhcp on the kernel command line.
Also made a few minor syntax changes (in particular, replaced "=="
with "=", and ">&foo" with ">foo 2>foo") so this works with more
limited shells.
Signed-off-by: Ben Thomas <bjthomas3@gmail.com>
This is done by defining ifup/down both to 'false' when they're
missing; then instead of attempting to parse the IP params from
the kernel command line, we get them from 'ip' instead. So this
works even with (for example) ip=dhcp on the kernel command line.
Also made a few minor syntax changes (in particular, replaced "=="
with "=", and ">&foo" with ">foo 2>foo") so this works with more
limited shells.
Signed-off-by: Ben Thomas <bjthomas3@gmail.com>
author | emellor@leeni.uk.xensource.com |
---|---|
date | Tue Jan 10 14:33:00 2006 +0000 (2006-01-10) |
parents | a4ce0ba0f8ff |
children | 0a69deed5e1f |
files | tools/examples/network-bridge tools/examples/xen-network-common.sh |
line diff
1.1 --- a/tools/examples/network-bridge Tue Jan 10 14:24:12 2006 +0000 1.2 +++ b/tools/examples/network-bridge Tue Jan 10 14:33:00 2006 +0000 1.3 @@ -68,48 +68,19 @@ pdev="p${netdev}" 1.4 vdev="veth${vifnum}" 1.5 vif0="vif0.${vifnum}" 1.6 1.7 -legacy_mask_to_prefix() { 1.8 - mask=$1 1.9 - first=${mask%%.*} 1.10 - second=${mask#*.} 1.11 - third=${second#*.} 1.12 - fourth=${third#*.} 1.13 - second=${second%%.*} 1.14 - third=${third%%.*} 1.15 - declare -i INT FULLMASK BIT 1.16 - INT=$((((($first*256)+$second)*256+$third)*256+$fourth)) 1.17 - FULLMASK=4294967295 1.18 - BIT=1 1.19 - for bit in `seq 32 -1 0`; do 1.20 - if test $FULLMASK -eq $INT; then PREFIX=$bit; return; fi 1.21 - FULLMASK=$(($FULLMASK-$BIT)) 1.22 - BIT=$((BIT*2)) 1.23 - done 1.24 - echo "ERROR converting netmask $mask to prefix" 1.25 - exit 1 1.26 +get_ip_info() { 1.27 + addr_pfx=`ip addr show dev $1 | egrep '^ *inet' | sed -e 's/ *inet //' -e 's/ .*//'` 1.28 + gateway=`ip route show dev $1 | fgrep default | sed 's/default via //'` 1.29 } 1.30 - 1.31 -parse_kernel_ip() { 1.32 - if egrep 'ip=[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:' /proc/cmdline; then 1.33 - kip=`sed -e 's!.*ip=\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\):.*!\1!' /proc/cmdline` 1.34 - kmask=`sed -e 's!.*ip=[^:]*:[^:]*:[^:]*:\([^:]*\):.*!\1!' /proc/cmdline` 1.35 - kgate=`sed -e 's!.*ip=[^:]*:[^:]*:\([^:]*\):.*!\1!' /proc/cmdline` 1.36 - fi 1.37 -} 1.38 - 1.39 + 1.40 do_ifup() { 1.41 if ! ifup $1 ; then 1.42 - if [ ${kip} ] ; then 1.43 - # use the addresses we grocked from /proc/cmdline 1.44 - if [ -z "${kmask}" ]; then 1.45 - PREFIX=32 1.46 - else 1.47 - legacy_mask_to_prefix ${kmask} 1.48 - fi 1.49 + if [ ${addr_pfx} ] ; then 1.50 + # use the info from get_ip_info() 1.51 ip addr flush $1 1.52 - ip addr add ${kip}/${PREFIX} dev $1 1.53 + ip addr add ${addr_pfx} dev $1 1.54 ip link set dev $1 up 1.55 - [ ${kgate} ] && ip route add default via ${kgate} 1.56 + [ ${gateway} ] && ip route add default via ${gateway} 1.57 fi 1.58 fi 1.59 } 1.60 @@ -171,7 +142,7 @@ transfer_routes () { 1.61 # 1.62 link_exists() 1.63 { 1.64 - if ip link show "$1" >&/dev/null 1.65 + if ip link show "$1" >/dev/null 2>/dev/null 1.66 then 1.67 return 0 1.68 else 1.69 @@ -231,7 +202,7 @@ show_status () { 1.70 } 1.71 1.72 op_start () { 1.73 - if [ "${bridge}" == "null" ] ; then 1.74 + if [ "${bridge}" = "null" ] ; then 1.75 return 1.76 fi 1.77 1.78 @@ -259,9 +230,8 @@ using loopback.nloopbacks=<N> on the dom 1.79 preiftransfer ${netdev} 1.80 transfer_addrs ${netdev} ${vdev} 1.81 if ! ifdown ${netdev}; then 1.82 - # If ifdown fails, take the IP details from the kernel command 1.83 - # line. 1.84 - parse_kernel_ip 1.85 + # If ifdown fails, remember the IP details. 1.86 + get_ip_info ${netdev} 1.87 ip link set ${netdev} down 1.88 ip addr flush ${netdev} 1.89 fi 1.90 @@ -283,13 +253,13 @@ using loopback.nloopbacks=<N> on the dom 1.91 transfer_routes ${netdev} ${bridge} 1.92 fi 1.93 1.94 - if [ ${antispoof} == 'yes' ] ; then 1.95 + if [ ${antispoof} = 'yes' ] ; then 1.96 antispoofing 1.97 fi 1.98 } 1.99 1.100 op_stop () { 1.101 - if [ "${bridge}" == "null" ]; then 1.102 + if [ "${bridge}" = "null" ]; then 1.103 return 1.104 fi 1.105 if ! link_exists "$bridge"; then 1.106 @@ -301,7 +271,7 @@ op_stop () { 1.107 mac=`ip link show ${netdev} | grep 'link\/ether' | sed -e 's/.*ether \(..:..:..:..:..:..\).*/\1/'` 1.108 transfer_addrs ${netdev} ${pdev} 1.109 if ! ifdown ${netdev}; then 1.110 - parse_kernel_ip 1.111 + get_ip_info ${netdev} 1.112 fi 1.113 ip link set ${netdev} down arp off 1.114 ip link set ${netdev} addr fe:ff:ff:ff:ff:ff
2.1 --- a/tools/examples/xen-network-common.sh Tue Jan 10 14:24:12 2006 +0000 2.2 +++ b/tools/examples/xen-network-common.sh Tue Jan 10 14:33:00 2006 +0000 2.3 @@ -42,7 +42,7 @@ then 2.4 { 2.5 /sbin/ifup ${HWD_CONFIG_0} $1 2.6 } 2.7 -elif ! which ifup >&/dev/null 2.8 +elif ! which ifup >/dev/null 2>/dev/null 2.9 then 2.10 if [ -e /etc/conf.d/net ] 2.11 then 2.12 @@ -59,9 +59,18 @@ then 2.13 /etc/init.d/net.$1 stop 2.14 } 2.15 else 2.16 - logger -p "daemon.crit" -- \ 2.17 - "You don't have ifup and don't seem to be running Gentoo either!" 2.18 - exit 1 2.19 + preiftransfer() 2.20 + { 2.21 + true 2.22 + } 2.23 + ifup() 2.24 + { 2.25 + false 2.26 + } 2.27 + ifdown() 2.28 + { 2.29 + false 2.30 + } 2.31 fi 2.32 else 2.33 preiftransfer()