direct-io.hg

changeset 10430:45f504d6b548

[TOOLS] Clean up the network setup scripts. Create some
setup functions and use them everywhere.
Signed-off-by: Gerd Hoffmann <kraxel@suse.de>
author kaf24@firebug.cl.cam.ac.uk
date Sat Jun 17 08:40:50 2006 +0100 (2006-06-17)
parents 21e6625a6c01
children c6f8fcca0282
files tools/examples/network-bridge tools/examples/vif-bridge tools/examples/xen-network-common.sh
line diff
     1.1 --- a/tools/examples/network-bridge	Sat Jun 17 08:38:35 2006 +0100
     1.2 +++ b/tools/examples/network-bridge	Sat Jun 17 08:40:50 2006 +0100
     1.3 @@ -151,30 +151,6 @@ link_exists()
     1.4      fi
     1.5  }
     1.6  
     1.7 -
     1.8 -# Usage: create_bridge bridge
     1.9 -create_bridge () {
    1.10 -    local bridge=$1
    1.11 -
    1.12 -    # Don't create the bridge if it already exists.
    1.13 -    if ! brctl show | grep -q ${bridge} ; then
    1.14 -	brctl addbr ${bridge}
    1.15 -	brctl stp ${bridge} off
    1.16 -	brctl setfd ${bridge} 0
    1.17 -    fi
    1.18 -    ip link set ${bridge} up
    1.19 -}
    1.20 -
    1.21 -# Usage: add_to_bridge bridge dev
    1.22 -add_to_bridge () {
    1.23 -    local bridge=$1
    1.24 -    local dev=$2
    1.25 -    # Don't add $dev to $bridge if it's already on a bridge.
    1.26 -    if ! brctl show | grep -q ${dev} ; then
    1.27 -	brctl addif ${bridge} ${dev}
    1.28 -    fi
    1.29 -}
    1.30 -
    1.31  # Set the default forwarding policy for $dev to drop.
    1.32  # Allow forwarding to the bridge.
    1.33  antispoofing () {
    1.34 @@ -238,14 +214,13 @@ using loopback.nloopbacks=<N> on the dom
    1.35  	fi
    1.36  	ip link set ${netdev} name ${pdev}
    1.37  	ip link set ${vdev} name ${netdev}
    1.38 -	ip link set ${pdev} down arp off
    1.39 -	ip link set ${pdev} addr fe:ff:ff:ff:ff:ff
    1.40 -	ip addr flush ${pdev}
    1.41 +
    1.42 +	setup_bridge_port ${pdev}
    1.43 +	setup_bridge_port ${vif0}
    1.44  	ip link set ${netdev} addr ${mac} arp on
    1.45 -	add_to_bridge ${bridge} ${vif0}
    1.46 +
    1.47  	ip link set ${bridge} up
    1.48 -	ip link set ${vif0} up
    1.49 -	ip link set ${pdev} up
    1.50 +	add_to_bridge  ${bridge} ${vif0}
    1.51  	add_to_bridge2 ${bridge} ${pdev}
    1.52  	do_ifup ${netdev}
    1.53      else
    1.54 @@ -301,6 +276,7 @@ add_to_bridge2() {
    1.55      local maxtries=10
    1.56  
    1.57      echo -n "Waiting for ${dev} to negotiate link."
    1.58 +    ip link set ${dev} up
    1.59      for i in `seq ${maxtries}` ; do
    1.60  	if ifconfig ${dev} | grep -q RUNNING ; then
    1.61  	    break
     2.1 --- a/tools/examples/vif-bridge	Sat Jun 17 08:38:35 2006 +0100
     2.2 +++ b/tools/examples/vif-bridge	Sat Jun 17 08:40:50 2006 +0100
     2.3 @@ -48,16 +48,8 @@ fi
     2.4  
     2.5  case "$command" in
     2.6      online)
     2.7 -        if brctl show | grep -q "$vif"
     2.8 -        then
     2.9 -          log debug "$vif already attached to a bridge"
    2.10 -          exit 0
    2.11 -        fi
    2.12 -
    2.13 -        brctl addif "$bridge" "$vif" ||
    2.14 -          fatal "brctl addif $bridge $vif failed"
    2.15 -
    2.16 -        ifconfig "$vif" up || fatal "ifconfig $vif up failed"
    2.17 +	setup_bridge_port "$vif"
    2.18 +	add_to_bridge "$bridge" "$vif"
    2.19          ;;
    2.20  
    2.21      offline)
     3.1 --- a/tools/examples/xen-network-common.sh	Sat Jun 17 08:38:35 2006 +0100
     3.2 +++ b/tools/examples/xen-network-common.sh	Sat Jun 17 08:40:50 2006 +0100
     3.3 @@ -104,3 +104,48 @@ find_dhcpd_init_file()
     3.4  {
     3.5    first_file -x /etc/init.d/{dhcp3-server,dhcp,dhcpd}
     3.6  }
     3.7 +
     3.8 +# configure interfaces which act as pure bridge ports:
     3.9 +#  - make quiet: no arp, no multicast (ipv6 autoconf)
    3.10 +#  - set mac address to fe:ff:ff:ff:ff:ff
    3.11 +setup_bridge_port() {
    3.12 +    local dev="$1"
    3.13 +
    3.14 +    # take interface down ...
    3.15 +    ip link set ${dev} down
    3.16 +
    3.17 +    # ... and configure it
    3.18 +    ip link set ${dev} arp off
    3.19 +    ip link set ${dev} multicast off
    3.20 +    ip link set ${dev} addr fe:ff:ff:ff:ff:ff
    3.21 +    ip addr flush ${dev}
    3.22 +}
    3.23 +
    3.24 +# Usage: create_bridge bridge
    3.25 +create_bridge () {
    3.26 +    local bridge=$1
    3.27 +
    3.28 +    # Don't create the bridge if it already exists.
    3.29 +    if [ ! -e "/sys/class/net/${bridge}/bridge" ]; then
    3.30 +	brctl addbr ${bridge}
    3.31 +	brctl stp ${bridge} off
    3.32 +	brctl setfd ${bridge} 0
    3.33 +        ip link set ${bridge} arp off
    3.34 +        ip link set ${bridge} multicast off
    3.35 +    fi
    3.36 +    ip link set ${bridge} up
    3.37 +}
    3.38 +
    3.39 +# Usage: add_to_bridge bridge dev
    3.40 +add_to_bridge () {
    3.41 +    local bridge=$1
    3.42 +    local dev=$2
    3.43 +
    3.44 +    # Don't add $dev to $bridge if it's already on a bridge.
    3.45 +    if [ -e "/sys/class/net/${bridge}/brif/${dev}" ]; then
    3.46 +	return
    3.47 +    fi
    3.48 +    brctl addif ${bridge} ${dev}
    3.49 +    ip link set ${dev} up
    3.50 +}
    3.51 +