[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] [TOOLS] Clean up the network setup scripts. Create some



# HG changeset patch
# User kaf24@xxxxxxxxxxxxxxxxxxxx
# Node ID 45f504d6b548fde87c7272591e9b448702e18c54
# Parent  21e6625a6c016de7e984d5571373f04ee0a67987
[TOOLS] Clean up the network setup scripts. Create some
setup functions and use them everywhere.
Signed-off-by: Gerd Hoffmann <kraxel@xxxxxxx>
---
 tools/examples/network-bridge        |   36 ++++------------------------
 tools/examples/vif-bridge            |   12 +--------
 tools/examples/xen-network-common.sh |   45 +++++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 40 deletions(-)

diff -r 21e6625a6c01 -r 45f504d6b548 tools/examples/network-bridge
--- a/tools/examples/network-bridge     Sat Jun 17 08:38:35 2006 +0100
+++ b/tools/examples/network-bridge     Sat Jun 17 08:40:50 2006 +0100
@@ -151,30 +151,6 @@ link_exists()
     fi
 }
 
-
-# Usage: create_bridge bridge
-create_bridge () {
-    local bridge=$1
-
-    # Don't create the bridge if it already exists.
-    if ! brctl show | grep -q ${bridge} ; then
-       brctl addbr ${bridge}
-       brctl stp ${bridge} off
-       brctl setfd ${bridge} 0
-    fi
-    ip link set ${bridge} up
-}
-
-# Usage: add_to_bridge bridge dev
-add_to_bridge () {
-    local bridge=$1
-    local dev=$2
-    # Don't add $dev to $bridge if it's already on a bridge.
-    if ! brctl show | grep -q ${dev} ; then
-       brctl addif ${bridge} ${dev}
-    fi
-}
-
 # Set the default forwarding policy for $dev to drop.
 # Allow forwarding to the bridge.
 antispoofing () {
@@ -238,14 +214,13 @@ using loopback.nloopbacks=<N> on the dom
        fi
        ip link set ${netdev} name ${pdev}
        ip link set ${vdev} name ${netdev}
-       ip link set ${pdev} down arp off
-       ip link set ${pdev} addr fe:ff:ff:ff:ff:ff
-       ip addr flush ${pdev}
+
+       setup_bridge_port ${pdev}
+       setup_bridge_port ${vif0}
        ip link set ${netdev} addr ${mac} arp on
-       add_to_bridge ${bridge} ${vif0}
+
        ip link set ${bridge} up
-       ip link set ${vif0} up
-       ip link set ${pdev} up
+       add_to_bridge  ${bridge} ${vif0}
        add_to_bridge2 ${bridge} ${pdev}
        do_ifup ${netdev}
     else
@@ -301,6 +276,7 @@ add_to_bridge2() {
     local maxtries=10
 
     echo -n "Waiting for ${dev} to negotiate link."
+    ip link set ${dev} up
     for i in `seq ${maxtries}` ; do
        if ifconfig ${dev} | grep -q RUNNING ; then
            break
diff -r 21e6625a6c01 -r 45f504d6b548 tools/examples/vif-bridge
--- a/tools/examples/vif-bridge Sat Jun 17 08:38:35 2006 +0100
+++ b/tools/examples/vif-bridge Sat Jun 17 08:40:50 2006 +0100
@@ -48,16 +48,8 @@ fi
 
 case "$command" in
     online)
-        if brctl show | grep -q "$vif"
-        then
-          log debug "$vif already attached to a bridge"
-          exit 0
-        fi
-
-        brctl addif "$bridge" "$vif" ||
-          fatal "brctl addif $bridge $vif failed"
-
-        ifconfig "$vif" up || fatal "ifconfig $vif up failed"
+       setup_bridge_port "$vif"
+       add_to_bridge "$bridge" "$vif"
         ;;
 
     offline)
diff -r 21e6625a6c01 -r 45f504d6b548 tools/examples/xen-network-common.sh
--- a/tools/examples/xen-network-common.sh      Sat Jun 17 08:38:35 2006 +0100
+++ b/tools/examples/xen-network-common.sh      Sat Jun 17 08:40:50 2006 +0100
@@ -104,3 +104,48 @@ find_dhcpd_init_file()
 {
   first_file -x /etc/init.d/{dhcp3-server,dhcp,dhcpd}
 }
+
+# configure interfaces which act as pure bridge ports:
+#  - make quiet: no arp, no multicast (ipv6 autoconf)
+#  - set mac address to fe:ff:ff:ff:ff:ff
+setup_bridge_port() {
+    local dev="$1"
+
+    # take interface down ...
+    ip link set ${dev} down
+
+    # ... and configure it
+    ip link set ${dev} arp off
+    ip link set ${dev} multicast off
+    ip link set ${dev} addr fe:ff:ff:ff:ff:ff
+    ip addr flush ${dev}
+}
+
+# Usage: create_bridge bridge
+create_bridge () {
+    local bridge=$1
+
+    # Don't create the bridge if it already exists.
+    if [ ! -e "/sys/class/net/${bridge}/bridge" ]; then
+       brctl addbr ${bridge}
+       brctl stp ${bridge} off
+       brctl setfd ${bridge} 0
+        ip link set ${bridge} arp off
+        ip link set ${bridge} multicast off
+    fi
+    ip link set ${bridge} up
+}
+
+# Usage: add_to_bridge bridge dev
+add_to_bridge () {
+    local bridge=$1
+    local dev=$2
+
+    # Don't add $dev to $bridge if it's already on a bridge.
+    if [ -e "/sys/class/net/${bridge}/brif/${dev}" ]; then
+       return
+    fi
+    brctl addif ${bridge} ${dev}
+    ip link set ${dev} up
+}
+

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.