Browse Source

package: base-files: Add bonding support to network scripts

Also add a sample LACP configuration and while being at it, fix the
documentation URL.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Phil Sutter 3 months ago
parent
commit
a482465035

+ 10 - 1
package/base-files/files/interfaces-dhcp

@@ -22,6 +22,15 @@ iface eth0 inet dhcp
 #  bridge-ports eth0 eth1
 ##
 
+## LACP configuration
+#auto lacp0
+#iface lacp0 inet dhcp
+#  bond-ports eth0 eth1
+#  bond-mode 802.3ad
+#  bond-miimon 100
+#  bond-lacp-rate slow
+#  bond-xmit-hash-policy layer2+3
+
 ## pppoe configuration
 #auto ppp0
 #iface ppp0 inet ppp
@@ -55,4 +64,4 @@ iface eth0 inet dhcp
 #  wireless-passphrase xxxxxxxx
 ##
 
-# for more special cases see: http://www.openadk.org/doku.php?id=network
+# for more special cases see: https://docs.openadk.org/html/manual.html#network-configuration

+ 20 - 0
package/base-files/src/etc/network/if-post-down.d/04-bonding

@@ -0,0 +1,20 @@
+#!/bin/sh
+
+case "$IF_BOND_PORTS" in
+"")
+	exit 0
+	;;
+none)
+	INTERFACES=""
+	;;
+*)
+	INTERFACES="$IF_BOND_PORTS"
+	;;
+esac
+
+for IF in $INTERFACES; do
+	ip link set $IF nomaster
+	ip link set $IF down
+done
+ip link del $IFACE
+exit 0

+ 37 - 0
package/base-files/src/etc/network/if-pre-up.d/05-bonding

@@ -0,0 +1,37 @@
+#!/bin/sh
+
+INTERFACES=""
+BONDOPTS=""
+for var in $(env | grep '^IF_BOND_'); do
+	val="${var#*=}"
+	opt="${var%%=*}"
+	if [ "$opt" == "IF_BOND_PORTS" ]; then
+		case "$val" in
+		none)
+			INTERFACES=""
+			;;
+		*)
+			INTERFACES="$val"
+			;;
+		esac
+		continue
+	fi
+	opt="$(tr '[A-Z]' '[a-z]' <<< ${opt#IF_BOND_})"
+	BONDOPTS+=" $opt"
+	[ -n "$val" ] && BONDOPTS+=" $val"
+done
+
+[ -n "$INTERFACES" ] || exit 0
+
+ip link add $IFACE type bond ${BONDOPTS} || exit 1
+for IF in $INTERFACES; do
+	if ! grep -q $IF /proc/net/dev; then
+		echo "Error: interface '$IF' does not exist!"
+		ip link del $IFACE
+		exit 1
+	fi
+	ip link set $IF master $IFACE
+	ip link set $IF up
+done
+
+exit 0