direct-io.hg

changeset 15203:f8819cb5f892

[NET] Remove netloop from network bridge init scripts.

The scripts are partly based on work by Daniel P. Berrange.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
author kfraser@localhost.localdomain
date Mon Jun 04 11:01:46 2007 +0100 (2007-06-04)
parents 00e0e2d7c156
children 1712c62b913c
files tools/examples/network-bridge tools/examples/vif-bridge tools/examples/xen-network-common.sh tools/examples/xend-config.sxp tools/ioemu/patches/qemu-target-i386-dm tools/ioemu/target-i386-dm/qemu-ifup
line diff
     1.1 --- a/tools/examples/network-bridge	Mon Jun 04 10:14:53 2007 +0100
     1.2 +++ b/tools/examples/network-bridge	Mon Jun 04 11:01:46 2007 +0100
     1.3 @@ -5,9 +5,10 @@
     1.4  # The script name to use is defined in /etc/xen/xend-config.sxp
     1.5  # in the network-script field.
     1.6  #
     1.7 -# This script creates a bridge (default xenbr${vifnum}), adds a device
     1.8 -# (default eth${vifnum}) to it, copies the IP addresses from the device
     1.9 -# to the bridge and adjusts the routes accordingly.
    1.10 +# This script creates a bridge (default ${netdev}), adds a device
    1.11 +# (defaults to the device on the default gateway route) to it, copies
    1.12 +# the IP addresses from the device to the bridge and adjusts the routes
    1.13 +# accordingly.
    1.14  #
    1.15  # If all goes well, this should ensure that networking stays up.
    1.16  # However, some configurations are upset by this, especially
    1.17 @@ -20,31 +21,27 @@
    1.18  #
    1.19  # Vars:
    1.20  #
    1.21 -# vifnum     Virtual device number to use (default 0). Numbers >=8
    1.22 -#            require the netback driver to have nloopbacks set to a
    1.23 -#            higher value than its default of 8.
    1.24 -# bridge     The bridge to use (default xenbr${vifnum}).
    1.25 -# netdev     The interface to add to the bridge (default eth${vifnum}).
    1.26 +# bridge     The bridge to use (default ${netdev}).
    1.27 +# netdev     The interface to add to the bridge (default gateway device).
    1.28  # antispoof  Whether to use iptables to prevent spoofing (default no).
    1.29  #
    1.30  # Internal Vars:
    1.31  # pdev="p${netdev}"
    1.32 -# vdev="veth${vifnum}"
    1.33 -# vif0="vif0.${vifnum}"
    1.34 +# tdev=tmpbridge
    1.35  #
    1.36  # start:
    1.37 -# Creates the bridge
    1.38 -# Copies the IP and MAC addresses from netdev to vdev
    1.39 +# Creates the bridge as tdev
    1.40 +# Copies the IP and MAC addresses from pdev to bridge
    1.41  # Renames netdev to be pdev 
    1.42 -# Renames vdev to be netdev 
    1.43 -# Enslaves pdev, vdev to bridge
    1.44 +# Renames tdev to bridge
    1.45 +# Enslaves pdev to bridge
    1.46  #
    1.47  # stop:
    1.48 -# Removes netdev from the bridge
    1.49 -# Transfers addresses, routes from netdev to pdev
    1.50 -# Renames netdev to vdev
    1.51 +# Removes pdev from the bridge
    1.52 +# Transfers addresses, routes from bridge to pdev
    1.53 +# Renames bridge to tdev
    1.54  # Renames pdev to netdev 
    1.55 -# Deletes bridge
    1.56 +# Deletes tdev
    1.57  #
    1.58  # status:
    1.59  # Print addresses, interfaces, routes
    1.60 @@ -59,15 +56,13 @@ dir=$(dirname "$0")
    1.61  findCommand "$@"
    1.62  evalVariables "$@"
    1.63  
    1.64 -vifnum=${vifnum:-$(ip route list | awk '/^default / { print $NF }' | sed 's/^[^0-9]*//')}
    1.65 -vifnum=${vifnum:-0}
    1.66 -bridge=${bridge:-xenbr${vifnum}}
    1.67 -netdev=${netdev:-eth${vifnum}}
    1.68 +netdev=${netdev:-$(ip route list | awk '/^default / { print $NF }' |
    1.69 +		   sed 's/.* dev //')}
    1.70 +bridge=${bridge:-${netdev}}
    1.71  antispoof=${antispoof:-no}
    1.72  
    1.73  pdev="p${netdev}"
    1.74 -vdev="veth${vifnum}"
    1.75 -vif0="vif0.${vifnum}"
    1.76 +tdev=tmpbridge
    1.77  
    1.78  get_ip_info() {
    1.79      addr_pfx=`ip addr show dev $1 | egrep '^ *inet' | sed -e 's/ *inet //' -e 's/ .*//'`
    1.80 @@ -157,7 +152,6 @@ antispoofing () {
    1.81      iptables -P FORWARD DROP
    1.82      iptables -F FORWARD
    1.83      iptables -A FORWARD -m physdev --physdev-in ${pdev} -j ACCEPT
    1.84 -    iptables -A FORWARD -m physdev --physdev-in ${vif0} -j ACCEPT
    1.85  }
    1.86  
    1.87  # Usage: show_status dev bridge
    1.88 @@ -184,53 +178,27 @@ op_start () {
    1.89      fi
    1.90  
    1.91      if link_exists "$pdev"; then
    1.92 -	# The device is already up.
    1.93 -	return
    1.94 -    fi
    1.95 -    if link_exists veth0 && ! link_exists "$vdev"; then
    1.96 -	echo "
    1.97 -Link $vdev is missing.
    1.98 -This may be because you have reached the limit of the number of interfaces
    1.99 -that the loopback driver supports.  If the loopback driver is a module, you
   1.100 -may raise this limit by passing it as a parameter (nloopbacks=<N>); if the
   1.101 -driver is compiled statically into the kernel, then you may set the parameter
   1.102 -using netloop.nloopbacks=<N> on the domain 0 kernel command line.
   1.103 -" >&2
   1.104 -	exit 1
   1.105 +        # The device is already up.
   1.106 +        return
   1.107      fi
   1.108  
   1.109 -    create_bridge ${bridge}
   1.110 -
   1.111 -    if link_exists "$vdev"; then
   1.112 -	mac=`ip link show ${netdev} | grep 'link\/ether' | sed -e 's/.*ether \(..:..:..:..:..:..\).*/\1/'`
   1.113 -	preiftransfer ${netdev}
   1.114 -	transfer_addrs ${netdev} ${vdev}
   1.115 -	if ! ifdown ${netdev}; then
   1.116 -	    # If ifdown fails, remember the IP details.
   1.117 -	    get_ip_info ${netdev}
   1.118 -	    ip link set ${netdev} down
   1.119 -	    ip addr flush ${netdev}
   1.120 -	fi
   1.121 -	ip link set ${netdev} name ${pdev}
   1.122 -	ip link set ${vdev} name ${netdev}
   1.123 +    create_bridge ${tdev}
   1.124  
   1.125 -	setup_bridge_port ${pdev}
   1.126 -	setup_bridge_port ${vif0}
   1.127 -	ip link set ${netdev} addr ${mac} arp on
   1.128 +    preiftransfer ${netdev}
   1.129 +    transfer_addrs ${netdev} ${tdev}
   1.130 +    if ! ifdown ${netdev}; then
   1.131 +	# If ifdown fails, remember the IP details.
   1.132 +	get_ip_info ${netdev}
   1.133 +	ip link set ${netdev} down
   1.134 +	ip addr flush ${netdev}
   1.135 +    fi
   1.136 +    ip link set ${netdev} name ${pdev}
   1.137 +    ip link set ${tdev} name ${bridge}
   1.138  
   1.139 -	ip link set ${bridge} up
   1.140 -	add_to_bridge  ${bridge} ${vif0}
   1.141 -	add_to_bridge2 ${bridge} ${pdev}
   1.142 -	do_ifup ${netdev}
   1.143 -    else
   1.144 -	ip link set ${bridge} arp on
   1.145 -	ip link set ${bridge} multicast on
   1.146 -	# old style without ${vdev}
   1.147 -	transfer_addrs  ${netdev} ${bridge}
   1.148 -	transfer_routes ${netdev} ${bridge}
   1.149 -	# Attach the real interface to the bridge.
   1.150 -	add_to_bridge ${bridge} ${netdev}
   1.151 -    fi
   1.152 +    setup_bridge_port ${pdev}
   1.153 +
   1.154 +    add_to_bridge2 ${bridge} ${pdev}
   1.155 +    do_ifup ${bridge}
   1.156  
   1.157      if [ ${antispoof} = 'yes' ] ; then
   1.158  	antispoofing
   1.159 @@ -245,31 +213,21 @@ op_stop () {
   1.160  	return
   1.161      fi
   1.162  
   1.163 -    if link_exists "$pdev"; then
   1.164 -	ip link set dev ${vif0} down
   1.165 -	mac=`ip link show ${netdev} | grep 'link\/ether' | sed -e 's/.*ether \(..:..:..:..:..:..\).*/\1/'`
   1.166 -	transfer_addrs ${netdev} ${pdev}
   1.167 -	if ! ifdown ${netdev}; then
   1.168 -	    get_ip_info ${netdev}
   1.169 -	fi
   1.170 -	ip link set ${netdev} down arp off
   1.171 -	ip link set ${netdev} addr fe:ff:ff:ff:ff:ff
   1.172 -	ip link set ${pdev} down
   1.173 -	ip addr flush ${netdev}
   1.174 -	ip link set ${pdev} addr ${mac} arp on
   1.175 +    transfer_addrs ${bridge} ${pdev}
   1.176 +    if ! ifdown ${bridge}; then
   1.177 +	get_ip_info ${bridge}
   1.178 +    fi
   1.179 +    ip link set ${pdev} down
   1.180 +    ip addr flush ${bridge}
   1.181  
   1.182 -	brctl delif ${bridge} ${pdev}
   1.183 -	brctl delif ${bridge} ${vif0}
   1.184 -	ip link set ${bridge} down
   1.185 +    brctl delif ${bridge} ${pdev}
   1.186 +    ip link set ${bridge} down
   1.187  
   1.188 -	ip link set ${netdev} name ${vdev}
   1.189 -	ip link set ${pdev} name ${netdev}
   1.190 -	do_ifup ${netdev}
   1.191 -    else
   1.192 -	transfer_routes ${bridge} ${netdev}
   1.193 -	ip link set ${bridge} down
   1.194 -    fi
   1.195 -    brctl delbr ${bridge}
   1.196 +    ip link set ${bridge} name ${tdev}
   1.197 +    ip link set ${pdev} name ${netdev}
   1.198 +    do_ifup ${netdev}
   1.199 +
   1.200 +    brctl delbr ${tdev}
   1.201  }
   1.202  
   1.203  # adds $dev to $bridge but waits for $dev to be in running state first
     2.1 --- a/tools/examples/vif-bridge	Mon Jun 04 10:14:53 2007 +0100
     2.2 +++ b/tools/examples/vif-bridge	Mon Jun 04 11:01:46 2007 +0100
     2.3 @@ -44,6 +44,32 @@ then
     2.4    then
     2.5       fatal "Could not find bridge, and none was specified"
     2.6    fi
     2.7 +else
     2.8 +  #
     2.9 +  # Old style bridge setup with netloop, used to have a bridge name
    2.10 +  # of xenbrX, enslaving pethX and vif0.X, and then configuring
    2.11 +  # eth0.
    2.12 +  #
    2.13 +  # New style bridge setup does not use netloop, so the bridge name
    2.14 +  # is ethX and the physical device is enslaved pethX
    2.15 +  #
    2.16 +  # So if...
    2.17 +  #
    2.18 +  #   - User asks for xenbrX
    2.19 +  #   - AND xenbrX doesn't exist
    2.20 +  #   - AND there is a ethX device which is a bridge
    2.21 +  #
    2.22 +  # ..then we translate xenbrX to ethX
    2.23 +  #
    2.24 +  # This lets old config files work without modification
    2.25 +  #
    2.26 +  if [ ! -e "/sys/class/net/$bridge" ] && [ -z "${bridge##xenbr*}" ]
    2.27 +  then
    2.28 +     if [ -e "/sys/class/net/eth${bridge#xenbr}/bridge" ]
    2.29 +     then
    2.30 +        bridge="eth${bridge#xenbr}"
    2.31 +     fi
    2.32 +  fi
    2.33  fi
    2.34  
    2.35  RET=0
    2.36 @@ -68,7 +94,7 @@ esac
    2.37  handle_iptable
    2.38  
    2.39  log debug "Successful vif-bridge $command for $vif, bridge $bridge."
    2.40 -if [ "$command" = "online" ]
    2.41 +if [ "$command" == "online" ]
    2.42  then
    2.43    success
    2.44  fi
     3.1 --- a/tools/examples/xen-network-common.sh	Mon Jun 04 10:14:53 2007 +0100
     3.2 +++ b/tools/examples/xen-network-common.sh	Mon Jun 04 11:01:46 2007 +0100
     3.3 @@ -90,8 +90,6 @@ find_dhcpd_init_file()
     3.4  }
     3.5  
     3.6  # configure interfaces which act as pure bridge ports:
     3.7 -#  - make quiet: no arp, no multicast (ipv6 autoconf)
     3.8 -#  - set mac address to fe:ff:ff:ff:ff:ff
     3.9  setup_bridge_port() {
    3.10      local dev="$1"
    3.11  
    3.12 @@ -99,9 +97,6 @@ setup_bridge_port() {
    3.13      ip link set ${dev} down
    3.14  
    3.15      # ... and configure it
    3.16 -    ip link set ${dev} arp off
    3.17 -    ip link set ${dev} multicast off
    3.18 -    ip link set ${dev} addr fe:ff:ff:ff:ff:ff
    3.19      ip addr flush ${dev}
    3.20  }
    3.21  
    3.22 @@ -114,15 +109,7 @@ create_bridge () {
    3.23  	brctl addbr ${bridge}
    3.24  	brctl stp ${bridge} off
    3.25  	brctl setfd ${bridge} 0
    3.26 -        ip link set ${bridge} arp off
    3.27 -        ip link set ${bridge} multicast off
    3.28      fi
    3.29 -
    3.30 -    # A small MTU disables IPv6 (and therefore IPv6 addrconf).
    3.31 -    mtu=$(ip link show ${bridge} | sed -n 's/.* mtu \([0-9]\+\).*/\1/p')
    3.32 -    ip link set ${bridge} mtu 68
    3.33 -    ip link set ${bridge} up
    3.34 -    ip link set ${bridge} mtu ${mtu:-1500}
    3.35  }
    3.36  
    3.37  # Usage: add_to_bridge bridge dev
     4.1 --- a/tools/examples/xend-config.sxp	Mon Jun 04 10:14:53 2007 +0100
     4.2 +++ b/tools/examples/xend-config.sxp	Mon Jun 04 11:01:46 2007 +0100
     4.3 @@ -116,9 +116,7 @@
     4.4  ##
     4.5  # To bridge network traffic, like this:
     4.6  #
     4.7 -# dom0: fake eth0 -> vif0.0 -+
     4.8 -#                            |
     4.9 -#                          bridge -> real eth0 -> the network
    4.10 +# dom0: ----------------- bridge -> real eth0 -> the network
    4.11  #                            |
    4.12  # domU: fake eth0 -> vifN.0 -+
    4.13  #
     5.1 --- a/tools/ioemu/patches/qemu-target-i386-dm	Mon Jun 04 10:14:53 2007 +0100
     5.2 +++ b/tools/ioemu/patches/qemu-target-i386-dm	Mon Jun 04 11:01:46 2007 +0100
     5.3 @@ -1405,8 +1405,8 @@ Index: ioemu/target-i386-dm/qemu-dm.debu
     5.4  Index: ioemu/target-i386-dm/qemu-ifup
     5.5  ===================================================================
     5.6  --- /dev/null	1970-01-01 00:00:00.000000000 +0000
     5.7 -+++ ioemu/target-i386-dm/qemu-ifup	2007-05-11 10:01:09.000000000 +0100
     5.8 -@@ -0,0 +1,9 @@
     5.9 ++++ ioemu/target-i386-dm/qemu-ifup	2007-06-03 11:50:25.000000000 +1000
    5.10 +@@ -0,0 +1,37 @@
    5.11  +#!/bin/sh
    5.12  +
    5.13  +#. /etc/rc.d/init.d/functions
    5.14 @@ -1414,5 +1414,33 @@ Index: ioemu/target-i386-dm/qemu-ifup
    5.15  +
    5.16  +echo 'config qemu network with xen bridge for ' $*
    5.17  +
    5.18 ++bridge=$2
    5.19 ++
    5.20 ++#
    5.21 ++# Old style bridge setup with netloop, used to have a bridge name
    5.22 ++# of xenbrX, enslaving pethX and vif0.X, and then configuring
    5.23 ++# eth0.
    5.24 ++#
    5.25 ++# New style bridge setup does not use netloop, so the bridge name
    5.26 ++# is ethX and the physical device is enslaved pethX
    5.27 ++#
    5.28 ++# So if...
    5.29 ++#
    5.30 ++#   - User asks for xenbrX
    5.31 ++#   - AND xenbrX doesn't exist
    5.32 ++#   - AND there is a ethX device which is a bridge
    5.33 ++#
    5.34 ++# ..then we translate xenbrX to ethX
    5.35 ++#
    5.36 ++# This lets old config files work without modification
    5.37 ++#
    5.38 ++if [ ! -e "/sys/class/net/$bridge" ] && [ -z "${bridge##xenbr*}" ]
    5.39 ++then
    5.40 ++   if [ -e "/sys/class/net/eth${bridge#xenbr}/bridge" ]
    5.41 ++   then
    5.42 ++      bridge="eth${bridge#xenbr}"
    5.43 ++   fi
    5.44 ++fi
    5.45 ++
    5.46  +ifconfig $1 0.0.0.0 up
    5.47 -+brctl addif $2 $1
    5.48 ++brctl addif $bridge $1
     6.1 --- a/tools/ioemu/target-i386-dm/qemu-ifup	Mon Jun 04 10:14:53 2007 +0100
     6.2 +++ b/tools/ioemu/target-i386-dm/qemu-ifup	Mon Jun 04 11:01:46 2007 +0100
     6.3 @@ -5,5 +5,33 @@
     6.4  
     6.5  echo 'config qemu network with xen bridge for ' $*
     6.6  
     6.7 +bridge=$2
     6.8 +
     6.9 +#
    6.10 +# Old style bridge setup with netloop, used to have a bridge name
    6.11 +# of xenbrX, enslaving pethX and vif0.X, and then configuring
    6.12 +# eth0.
    6.13 +#
    6.14 +# New style bridge setup does not use netloop, so the bridge name
    6.15 +# is ethX and the physical device is enslaved pethX
    6.16 +#
    6.17 +# So if...
    6.18 +#
    6.19 +#   - User asks for xenbrX
    6.20 +#   - AND xenbrX doesn't exist
    6.21 +#   - AND there is a ethX device which is a bridge
    6.22 +#
    6.23 +# ..then we translate xenbrX to ethX
    6.24 +#
    6.25 +# This lets old config files work without modification
    6.26 +#
    6.27 +if [ ! -e "/sys/class/net/$bridge" ] && [ -z "${bridge##xenbr*}" ]
    6.28 +then
    6.29 +   if [ -e "/sys/class/net/eth${bridge#xenbr}/bridge" ]
    6.30 +   then
    6.31 +      bridge="eth${bridge#xenbr}"
    6.32 +   fi
    6.33 +fi
    6.34 +
    6.35  ifconfig $1 0.0.0.0 up
    6.36 -brctl addif $2 $1
    6.37 +brctl addif $bridge $1