From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 0C827138CD3 for ; Mon, 25 May 2015 10:04:25 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A9FCCE08A1; Mon, 25 May 2015 10:04:22 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id DA596E0897 for ; Mon, 25 May 2015 10:04:21 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id D86FB340B9F for ; Mon, 25 May 2015 10:04:20 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 8A37F9FF for ; Mon, 25 May 2015 10:04:19 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1426377306.6befe06a7e72b5b7f17c7f1118fc16000a0cce13.vapier@OpenRC> Subject: [gentoo-commits] proj/netifrc:master commit in: net/ X-VCS-Repository: proj/netifrc X-VCS-Files: net/bridge.sh X-VCS-Directories: net/ X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: 6befe06a7e72b5b7f17c7f1118fc16000a0cce13 X-VCS-Branch: master Date: Mon, 25 May 2015 10:04:19 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 2656cf1b-480d-405c-a481-1ae443548694 X-Archives-Hash: 439ac0bbc77b9c23d714447c9ef81ea4 commit: 6befe06a7e72b5b7f17c7f1118fc16000a0cce13 Author: Doug Freed mtu edu> AuthorDate: Sat Mar 14 23:55:06 2015 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Sat Mar 14 23:55:06 2015 +0000 URL: https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=6befe06a bridge: use/prefer iproute2/sysfs where possible Use and prefer iproute2 and sysfs over bridge-utils where possible. Most users already have iproute2 installed, so this reduces the number of external programs they need to use all of netifrc's functionality. net/bridge.sh | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 6 deletions(-) diff --git a/net/bridge.sh b/net/bridge.sh index 60d3eeb..87e4055 100644 --- a/net/bridge.sh +++ b/net/bridge.sh @@ -4,7 +4,7 @@ bridge_depend() { before interface macnet - program brctl + program ip brctl } _config_vars="$_config_vars bridge bridge_add brctl" @@ -29,6 +29,83 @@ _bridge_ports() done } +_brctl() +{ + if [ -z "${_bridge_use_ip}" ]; then + if ip -V >/dev/null 2>&1 && [ "$(ip -V | cut -c 24-29)" -ge 130430 ]; then + _bridge_use_ip=1 + else + _bridge_use_ip=0 + fi + fi + if [ "${_bridge_use_ip}" -eq 1 ]; then + case "$1" in + addbr) + ip link add "$2" type bridge + ;; + delbr) + ip link del "$2" + ;; + addif) + ip link set "$3" master "$2" + ;; + delif) + ip link set "$3" nomaster + ;; + setageing) + echo "$3" > /sys/class/net/"$2"/bridge/ageing_time + ;; + setgcint) + # appears to have been dropped in Debian, and I don't see a sysfs file for it + eerror "brctl setgcint is not supported!" + return 1 + ;; + stp) + if [ "$3" = "on" -o "$3" = "yes" -o "$3" = "1" ]; then + _stp_state=1 + elif [ "$3" = "off" -o "$3" = "no" -o "$3" = "0" ]; then + _stp_state=0 + else + eerror "Invalid STP state for brctl stp!" + return 1 + fi + echo ${_stp_state} > /sys/class/net/"$2"/bridge/stp_state + ;; + setbridgeprio) + echo "$3" > /sys/class/net/"$2"/bridge/priority + ;; + setfd) + echo "$3" > /sys/class/net/"$2"/bridge/forward_delay + ;; + sethello) + echo "$3" > /sys/class/net/"$2"/bridge/hello_time + ;; + setmaxage) + echo "$3" > /sys/class/net/"$2"/bridge/max_age + ;; + setpathcost) + echo "$4" > /sys/class/net/"$2"/brif/"$3"/path_cost + ;; + setportprio) + echo "$4" > /sys/class/net/"$2"/brif/"$3"/priority + ;; + hairpin) + if [ "$4" -eq "on" -o "$4" -eq "yes" -o "$4" -eq "1" ]; then + _hairpin_mode=1 + elif [ "$4" -eq "off" -o "$4" -eq "no" -o "$4" -eq "0" ]; then + _hairpin_mode=0 + else + eerror "Invalid hairpin mode for brctl hairpin!" + return 1 + fi + echo ${_hairpin_mode} > /sys/class/net/"$2"/brif/"$3"/hairpin_mode + ;; + esac + else + brctl "$@" + fi +} + bridge_pre_start() { local brif= oiface="${IFACE}" e= x= @@ -70,7 +147,7 @@ bridge_pre_start() if ! _is_bridge ; then ebegin "Creating bridge ${IFACE}" - if ! brctl addbr "${IFACE}"; then + if ! _brctl addbr "${IFACE}"; then eend 1 return 1 fi @@ -89,7 +166,7 @@ bridge_pre_start() x=$1 shift set -- "${x}" "${IFACE}" "$@" - brctl "$@" + _brctl "$@" done unset IFS @@ -120,7 +197,7 @@ bridge_pre_start() fi # The interface is known to exist now _up - if ! brctl addif "${BR_IFACE}" "${x}"; then + if ! _brctl addif "${BR_IFACE}" "${x}"; then eend 1 return 1 fi @@ -176,13 +253,13 @@ bridge_post_stop() ebegin "Removing port ${port}${extra}" local IFACE="${port}" _set_flag -promisc - brctl delif "${iface}" "${port}" + _brctl delif "${iface}" "${port}" eend $? done if ${delete}; then eoutdent - brctl delbr "${iface}" + _brctl delbr "${iface}" eend $? fi