From a48246503550dfb7d818b110432f13334e211659 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Sun, 5 Jan 2025 01:18:33 +0100 Subject: 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 --- package/base-files/files/interfaces-dhcp | 11 ++++++- .../src/etc/network/if-post-down.d/04-bonding | 20 ++++++++++++ .../src/etc/network/if-pre-up.d/05-bonding | 37 ++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100755 package/base-files/src/etc/network/if-post-down.d/04-bonding create mode 100755 package/base-files/src/etc/network/if-pre-up.d/05-bonding (limited to 'package') diff --git a/package/base-files/files/interfaces-dhcp b/package/base-files/files/interfaces-dhcp index 11174c152..652101214 100644 --- a/package/base-files/files/interfaces-dhcp +++ b/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 diff --git a/package/base-files/src/etc/network/if-post-down.d/04-bonding b/package/base-files/src/etc/network/if-post-down.d/04-bonding new file mode 100755 index 000000000..0b9c9f362 --- /dev/null +++ b/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 diff --git a/package/base-files/src/etc/network/if-pre-up.d/05-bonding b/package/base-files/src/etc/network/if-pre-up.d/05-bonding new file mode 100755 index 000000000..489a2fcad --- /dev/null +++ b/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 -- cgit v1.2.3