summaryrefslogtreecommitdiffstats
path: root/main/bridge
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2012-03-15 13:36:27 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2012-03-15 13:36:27 +0000
commitaa875936d99eee357006dc5a8a9547adc6aac845 (patch)
treedb7f35aa4048e1610e62e7c63b89a44ef8f9a9df /main/bridge
parent86c2c6527c68246b409ecb163074dafc1a222551 (diff)
downloadaports-aa875936d99eee357006dc5a8a9547adc6aac845.tar.bz2
aports-aa875936d99eee357006dc5a8a9547adc6aac845.tar.xz
main/bridge: moved from testing
Diffstat (limited to 'main/bridge')
-rw-r--r--main/bridge/APKBUILD39
-rwxr-xr-xmain/bridge/bridge.pre-up139
2 files changed, 178 insertions, 0 deletions
diff --git a/main/bridge/APKBUILD b/main/bridge/APKBUILD
new file mode 100644
index 000000000..72b901e63
--- /dev/null
+++ b/main/bridge/APKBUILD
@@ -0,0 +1,39 @@
+# Contributor: Natanael Copa <ncopa@alpinelinux.org>
+# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
+pkgname=bridge
+pkgver=1.5
+pkgrel=0
+pkgdesc="Scripts for configuring network bridge interfaces"
+url="http://wiki.alpinelinux.org/wiki/Bridge"
+arch="noarch"
+license="GPL"
+depends=""
+makedepends=""
+install=""
+subpackages=""
+source="bridge.pre-up"
+
+_builddir=
+prepare() {
+ local i
+ cd "$_builddir"
+ for i in $source; do
+ case $i in
+ *.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
+ esac
+ done
+}
+
+build() {
+ return 0
+}
+
+package() {
+ cd "$_builddir"
+ install -Dm755 "$srcdir"/bridge.pre-up \
+ "$pkgdir"/etc/network/if-pre-up.d/bridge
+ install -d "$pkgdir"/etc/network/if-post-down.d
+ ln -s ../if-pre-up.d/bridge "$pkgdir"/etc/network/if-post-down.d/bridge
+}
+
+md5sums="ba87e0186cd37bcf6e3515207141bc4e bridge.pre-up"
diff --git a/main/bridge/bridge.pre-up b/main/bridge/bridge.pre-up
new file mode 100755
index 000000000..7cb4160f5
--- /dev/null
+++ b/main/bridge/bridge.pre-up
@@ -0,0 +1,139 @@
+#!/bin/sh
+
+# Copyright (C) 2012 Natanael Copa <ncopa@alpinelinux.org>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 as published
+# by the Free Software Foundation. See http://www.gnu.org/ for details.
+
+all_ports_exist() {
+ local i=
+ for i in "$@"; do
+ [ -d /sys/class/net/$i ] || return 1
+ done
+ return 0
+}
+
+wait_ports() {
+ local timeout= waitports=
+ [ -z "$IF_BRIDGE_WAITPORT" ] && return 0
+ set -- $IF_BRIDGE_WAITPORT
+ timeout="$1"
+ shift
+ waitports="$@"
+ [ -z "$waitports" ] && waitports="$PORTS"
+ while ! all_ports_exist $waitports; do
+ [ "$timeout" -eq 0 ] && return 0
+ timeout=$(($timeout - 1))
+ sleep 1
+ done
+}
+
+all_ports() {
+ local i=
+ for i in /sys/class/net/*/ifindex; do
+ i=${i%/*}
+ i=${i##*/}
+ case "$i" in
+ lo|$IFACE) continue;;
+ *) echo $i;;
+ esac
+ done
+}
+
+add_ports() {
+ local port=
+ for port in $PORTS; do
+ if [ -x /etc/network/ip-pre-up.d/vlan ]; then
+ env IFACE=$port /etc/network/if-pre-up.d/vlan
+ fi
+ if [ -n "$IF_BRIDGE_HW" ]; then
+ ip link set dev $port addr $IF_BRIDGE_HW
+ fi
+ brctl addif $IFACE $port && ip link set dev $port up
+ done
+}
+
+del_ports() {
+ local port=
+ for port in $PORTS; do
+ ip link set dev $port down
+ brctl delif $IFACE $port
+ if [ -x /etc/network/ip-post-down.d/vlan ]; then
+ env IFACE=$port /etc/network/if-post-down.d/vlan
+ fi
+ done
+}
+
+set_bridge_opts() {
+ [ -n "$IF_BRIDGE_AGEING" ] \
+ && brctl setageing $IFACE $IF_BRIDGE_AGEING
+ [ -n "$IF_BRIDGE_BRIDGEPRIO" ] \
+ && brctl setbridgeprio $IFACE $IF_BRIDGE_BRIDGEPRIO
+ [ -n "$IF_BRIDGE_FD" ] \
+ && brctl setfd $IFACE $IF_BRIDGE_FD
+ [ -n "$IF_BRIDGE_GCINT" ] \
+ && brctl setgcint $IFACE $IF_BRIDGE_GCINT
+ [ -n "$IF_BRIDGE_HELLO" ] \
+ && brctl sethello $IFACE $IF_BRIDGE_HELLO
+ [ -n "$IF_BRIDGE_MAXAGE" ] \
+ && brctl setmaxage $IFACE $IF_BRIDGE_MAXAGE
+ [ -n "$IF_BRIDGE_PATHCOST" ] \
+ && brctl setpathcost $IFACE $IF_BRIDGE_PATHCOST
+ [ -n "$IF_BRIDGE_PORTPRIO" ] \
+ && brctl setportprio $IFACE $IF_BRIDGE_PORTPRIO
+ [ -n "$IF_BRIDGE_STP" ] \
+ && brctl stp $IFACE $IF_BRIDGE_STP
+}
+
+all_ports_ready() {
+ local port=
+ for port in $PORTS; do
+ case $(cat /sys/class/net/$IFACE/brif/$port/state) in
+ ""|0|3) ;; # 0 = disabled, 3 = forwarding
+ [12]) return 1;;
+ esac
+ done
+ return 0
+}
+
+find_maxwait() {
+ awk '{printf("%.f\n", 2 * $0 / 100); }' \
+ /sys/class/net/$IFACE/bridge/forward_delay
+}
+
+wait_bridge() {
+ local timeout=$IF_BRIDGE_MAXWAIT
+ if [ -z "$timeout" ]; then
+ timeout=$(find_maxwait)
+ fi
+ ip link set dev $IFACE up
+ while ! all_ports_ready; do
+ [ $timeout -eq 0 ] && break
+ timeout=$(($timeout - 1))
+ sleep 1
+ done
+}
+
+case "$IF_BRIDGE_PORTS" in
+"") ;;
+none) PORTS="";;
+all) PORTS=$(all_ports);;
+*) PORTS="$IF_BRIDGE_PORTS";;
+esac
+
+[ -z "$PORTS" ] && exit
+
+case "$MODE" in
+start)
+ brctl addbr $IFACE || exit 1
+ wait_ports
+ set_bridge_opts
+ add_ports
+ wait_bridge
+ ;;
+stop) del_ports
+ brctl delbr $IFACE || exit 1
+ ;;
+esac
+