All of lore.kernel.org
 help / color / mirror / Atom feed
From: <b19537@freescale.com>
To: <openembedded-devel@lists.openembedded.org>
Subject: [PATCH meta-oe 1/9] bridge-utils: add
Date: Fri, 16 Dec 2011 10:39:25 +0800	[thread overview]
Message-ID: <1324003173-13994-1-git-send-email-b19537@freescale.com> (raw)

From: Zhenhua Luo <b19537@freescale.com>

    bridge-utils provides tools for ethernet bridging.

Signed-off-by: Zhenhua Luo <b19537@freescale.com>
---
 .../bridge-utils/bridge-utils.inc                  |   30 +++
 .../bridge-utils/bridge-utils_1.4.bb               |    6 +
 .../bridge-utils/files/ifupdown.sh                 |  245 ++++++++++++++++++++
 3 files changed, 281 insertions(+), 0 deletions(-)
 create mode 100644 meta-oe/recipes-connectivity/bridge-utils/bridge-utils.inc
 create mode 100644 meta-oe/recipes-connectivity/bridge-utils/bridge-utils_1.4.bb
 create mode 100644 meta-oe/recipes-connectivity/bridge-utils/files/ifupdown.sh

diff --git a/meta-oe/recipes-connectivity/bridge-utils/bridge-utils.inc b/meta-oe/recipes-connectivity/bridge-utils/bridge-utils.inc
new file mode 100644
index 0000000..5ac6c83
--- /dev/null
+++ b/meta-oe/recipes-connectivity/bridge-utils/bridge-utils.inc
@@ -0,0 +1,30 @@
+DESCRIPTION = "Tools for ethernet bridging."
+HOMEPAGE = "http://bridge.sourceforge.net/"
+SECTION = "console/network"
+LICENSE = "GPL"
+DEPENDS = "sysfsutils"
+RRECOMMENDS_${PN} = "kernel-module-bridge"
+
+SRC_URI = "${SOURCEFORGE_MIRROR}/bridge/bridge-utils-${PV}.tar.gz file://ifupdown.sh"
+
+inherit autotools
+
+EXTRA_OECONF = "--with-linux-headers=${STAGING_INCDIR}"
+
+do_install_append () {
+	mv ${D}${sbindir}/brctl ${D}${sbindir}/brctl.${PN}
+	install -d ${D}/${datadir}/bridge-utils
+	install -d ${D}/${sysconfdir}/network/if-pre-up.d
+	install -d ${D}/${sysconfdir}/network/if-post-down.d
+	install -m 0755 ${WORKDIR}/ifupdown.sh  ${D}/${datadir}/bridge-utils/
+	ln -s ${datadir}/bridge-utils/ifupdown.sh ${D}/${sysconfdir}/network/if-pre-up.d/bridge
+	ln -s ${datadir}/bridge-utils/ifupdown.sh ${D}/${sysconfdir}/network/if-post-down.d/bridge
+}
+
+pkg_postinst_${PN} () {
+	update-alternatives --install ${sbindir}/brctl brctl brctl.${PN} 100
+}
+
+pkg_prerm_${PN} () {
+	update-alternatives --remove brctl brctl.${PN}
+}
diff --git a/meta-oe/recipes-connectivity/bridge-utils/bridge-utils_1.4.bb b/meta-oe/recipes-connectivity/bridge-utils/bridge-utils_1.4.bb
new file mode 100644
index 0000000..00a5815
--- /dev/null
+++ b/meta-oe/recipes-connectivity/bridge-utils/bridge-utils_1.4.bb
@@ -0,0 +1,6 @@
+require bridge-utils.inc
+
+LIC_FILES_CHKSUM = "file://COPYING;md5=f9d20a453221a1b7e32ae84694da2c37"
+
+SRC_URI[md5sum] = "0182fcac3a2b307113bbec34e5f1c673"
+SRC_URI[sha256sum] = "876975e9bcc302aa8b829161ea3348b12b9b879f1db0dc98feaed8d0e5dd5933"
diff --git a/meta-oe/recipes-connectivity/bridge-utils/files/ifupdown.sh b/meta-oe/recipes-connectivity/bridge-utils/files/ifupdown.sh
new file mode 100644
index 0000000..a67ffcc
--- /dev/null
+++ b/meta-oe/recipes-connectivity/bridge-utils/files/ifupdown.sh
@@ -0,0 +1,245 @@
+#!/bin/sh
+
+# You don't usually need to touch this file at all, the full configuration
+# of the bridge can be done in a standard way on /etc/network/interfaces.
+
+# Have a look at /usr/share/doc/bridge-utils/README.Debian if you want
+# more info about the way on wich a bridge is set up on Debian.
+
+if [ ! -x /usr/sbin/brctl ]
+then
+  exit 0
+fi
+
+case "$IF_BRIDGE_PORTS" in
+    "")
+	exit 0
+	;;
+    none)
+	INTERFACES=""
+	;;
+    *)
+	INTERFACES="$IF_BRIDGE_PORTS"
+	;;
+esac
+
+# Previous work (create the interface)
+if [ "$MODE" = "start" ] ; then
+  brctl addbr $IFACE || exit 1
+# Wait for the ports to become available
+  if [ "$IF_BRIDGE_WAITPORT" ]
+  then
+    set x $IF_BRIDGE_WAITPORT &&   
+    shift &&
+    WAIT="$1" &&
+    shift &&
+    WAITPORT="$@" &&
+    if [ -z "$WAITPORT" ];then WAITPORT="$IF_BRIDGE_PORTS";fi &&
+    STARTTIME=$(date +%s) &&
+    NOTFOUND="true" &&
+    /bin/echo -e "\nWaiting for a max of $WAIT seconds for $WAITPORT to become available." &&
+    while [ "$(($(date +%s)-$STARTTIME))" -le "$WAIT" ] && [ -n "$NOTFOUND" ]
+    do
+      NOTFOUND=""
+      for i in $WAITPORT
+      do
+        if ! grep -q "^[\ ]*$i:.*$" /proc/net/dev;then NOTFOUND="true";fi
+      done
+      if [ -n "$NOTFOUND" ];then sleep 1;fi
+    done
+  fi
+# Previous work (stop the interface)
+elif [ "$MODE" = "stop" ];  then
+  ifconfig $IFACE down || exit 1
+fi
+
+all_interfaces= &&
+unset all_interfaces &&
+set x $INTERFACES &&
+shift &&
+while [ x"${1+set}" = xset ]
+do
+  # For compatibility: the `all' option.
+  case $1 in
+      all)
+	shift &&
+	set regex eth.\* noregex "$@"
+	;;
+  esac
+
+  # Primitive state machine...
+  case $1-`uname -s` in
+      regex-Linux)
+	all_interfaces=`sed -n 's%^[\ ]*\([^:]*\):.*$%\1%p' < /proc/net/dev`
+	shift
+	;;
+      regex-*)
+	echo -n "$0 needs to be ported for your `uname -s` system.  " >&2
+	echo "Trying to continue nevertheless." >&2
+	shift
+	;;
+      noregex-*)
+	all_interfaces=
+	unset all_interfaces
+	shift
+	;;
+  esac
+
+  case ${all_interfaces+regex}-${1+set} in
+      regex-set)
+	# The following interface specification are to be parsed as regular
+	# expressions against all interfaces the system provides.
+	i=`egrep "^$1$" << EOAI
+$all_interfaces
+EOAI
+`
+	shift
+	;;
+      *-set)
+	# Literal interfaces.
+	i=$1
+	shift
+	;;
+      *)
+	# No interface specification is following.
+	i=
+	;;
+  esac
+
+  for port in $i
+  do
+    # We attach and configure each port of the bridge
+    if [ "$MODE" = "start" ] ; then
+      if [ -x /etc/network/if-pre-up.d/vlan ]; then
+        env IFACE=$port /etc/network/if-pre-up.d/vlan
+      fi
+      if [ "$IF_BRIDGE_HW" ]
+      then
+         ifconfig $port down; ifconfig $port hw ether $IF_BRIDGE_HW
+      fi
+      brctl addif $IFACE $port && ifconfig $port 0.0.0.0 up
+    # We detach each port of the bridge
+    elif [ "$MODE" = "stop" ];  then
+      ifconfig $port down && brctl delif $IFACE $port && \
+        if [ -x /etc/network/if-post-down.d/vlan ]; then
+          env IFACE=$port /etc/network/if-post-down.d/vlan
+        fi
+    fi
+  done
+done
+
+# We finish setting up the bridge
+if [ "$MODE" = "start" ] ; then
+
+  if [ "$IF_BRIDGE_AGEING" ]
+  then
+    brctl setageing $IFACE $IF_BRIDGE_AGEING
+  fi
+
+  if [ "$IF_BRIDGE_BRIDGEPRIO" ]
+  then
+    brctl setbridgeprio $IFACE $IF_BRIDGE_BRIDGEPRIO
+  fi
+
+  if [ "$IF_BRIDGE_FD" ]
+  then
+    brctl setfd $IFACE $IF_BRIDGE_FD
+  fi
+
+  if [ "$IF_BRIDGE_GCINT" ]
+  then
+    brctl setgcint $IFACE $IF_BRIDGE_GCINT
+  fi
+
+  if [ "$IF_BRIDGE_HELLO" ]
+  then
+    brctl sethello $IFACE $IF_BRIDGE_HELLO
+  fi
+
+  if [ "$IF_BRIDGE_MAXAGE" ]
+  then
+    brctl setmaxage $IFACE $IF_BRIDGE_MAXAGE
+  fi
+
+  if [ "$IF_BRIDGE_PATHCOST" ]
+  then
+    brctl setpathcost $IFACE $IF_BRIDGE_PATHCOST
+  fi
+
+  if [ "$IF_BRIDGE_PORTPRIO" ]
+  then
+    brctl setportprio $IFACE $IF_BRIDGE_PORTPRIO
+  fi
+
+  if [ "$IF_BRIDGE_STP" ]
+  then
+    brctl stp $IFACE $IF_BRIDGE_STP
+  fi
+
+
+  # We activate the bridge
+  ifconfig $IFACE 0.0.0.0 up
+
+
+  # Calculate the maximum time to wait for the bridge to be ready
+  if [ "$IF_BRIDGE_MAXWAIT" ]
+  then
+    MAXWAIT=$IF_BRIDGE_MAXWAIT
+  else
+    MAXWAIT=$(brctl showstp $IFACE|sed -n 's/^.*forward delay[ \t]*\(.*\)\..*bridge forward delay[ \t]*\(.*\)\..*$/\1 \2/p')
+    if [ "$MAXWAIT" ]
+    then
+      if [ ${MAXWAIT% *} -gt ${MAXWAIT#* } ]
+      then
+        MAXWAIT=$((2*(${MAXWAIT% *}+1)))
+      else
+        MAXWAIT=$((2*(${MAXWAIT#* }+1)))
+      fi
+    else
+      if [ "$IF_BRIDGE_FD" ]
+      then
+        MAXWAIT=$((2*(${IF_BRIDGE_FD%.*}+1)))
+      else
+        MAXWAIT=32
+      fi
+      /bin/echo -e "\nWaiting $MAXWAIT seconds for $IFACE to get ready."
+      sleep $MAXWAIT
+      MAXWAIT=0
+    fi
+  fi
+
+  # Wait for the bridge to be ready
+  if [ "$MAXWAIT" != 0 ]
+  then
+    /bin/echo -e "\nWaiting for $IFACE to get ready (MAXWAIT is $MAXWAIT seconds)."
+
+    unset BREADY
+    unset TRANSITIONED
+    COUNT=0
+
+    while [ ! "$BREADY" -a $COUNT -lt $MAXWAIT ]
+    do
+      sleep 1
+      COUNT=$(($COUNT+1))
+      BREADY=true
+      for i in $(brctl showstp $IFACE|sed -n 's/^.*port id.*state[ \t]*\(.*\)$/\1/p')
+      do
+        if [ "$i" = "listening" -o "$i" = "learning" -o "$i" = "forwarding" -o "$i" = "blocking" ]
+        then
+          TRANSITIONED=true
+        fi
+        if [ "$i" != "forwarding" -a "$i" != "blocking" ] && [ ! "$TRANSITIONED" -o "$i" != "disabled" ]
+        then
+          unset BREADY
+        fi
+      done
+    done
+
+  fi
+
+# Finally we destroy the interface
+elif [ "$MODE" = "stop" ];  then
+
+  brctl delbr $IFACE
+
+fi
-- 
1.7.0.4





             reply	other threads:[~2011-12-16  2:58 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-16  2:39 b19537 [this message]
2011-12-16  2:39 ` [PATCH meta-oe 2/9] ietutils: add b19537
2011-12-16  7:48   ` Koen Kooi
2011-12-16  2:39 ` [PATCH meta-oe 3/9] ipsec-tools: add b19537
2011-12-16  7:49   ` Koen Kooi
2011-12-16  2:39 ` [PATCH meta-oe 4/9] libnfnetlink: add b19537
2011-12-16  7:50   ` Koen Kooi
2011-12-16  2:39 ` [PATCH meta-oe 5/9] nerperf: add b19537
2011-12-16  7:51   ` Koen Kooi
2011-12-16  9:19     ` Luo Zhenhua-B19537
2011-12-16  9:22       ` Koen Kooi
2011-12-16 21:54         ` Khem Raj
2011-12-19  9:52           ` Luo Zhenhua-B19537
2011-12-19 19:20             ` Khem Raj
2011-12-19 22:31           ` Flanagan, Elizabeth
2011-12-20  2:31             ` Luo Zhenhua-B19537
2011-12-21  6:26             ` Luo Zhenhua-B19537
2011-12-21 17:37               ` Flanagan, Elizabeth
2011-12-22  2:44                 ` Luo Zhenhua-B19537
2011-12-29 18:19                   ` Flanagan, Elizabeth
2011-12-16  2:39 ` [PATCH meta-oe 6/9] ptpd: add b19537
2011-12-16  7:52   ` Koen Kooi
2011-12-16 21:57   ` Khem Raj
2011-12-16  2:39 ` [PATCH meta-oe 7/9] strongswan: add b19537
2011-12-16  7:53   ` Koen Kooi
2011-12-16  2:39 ` [PATCH meta-oe 8/9] rng-tools: add b19537
2011-12-16  7:53   ` Koen Kooi
2011-12-16  2:39 ` [PATCH meta-oe 9/9] xfsprogs: add b19537
2011-12-16  7:54   ` Koen Kooi
2011-12-16  7:45 ` [PATCH meta-oe 1/9] bridge-utils: add Koen Kooi
2011-12-16  8:48   ` Luo Zhenhua-B19537

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1324003173-13994-1-git-send-email-b19537@freescale.com \
    --to=b19537@freescale.com \
    --cc=openembedded-devel@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.