summaryrefslogtreecommitdiff
path: root/package/base-files/src/etc
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2025-01-05 01:18:33 +0100
committerWaldemar Brodkorb <wbx@openadk.org>2025-01-06 11:53:43 +0100
commita48246503550dfb7d818b110432f13334e211659 (patch)
tree9c068ea033d05837391cbf1719242614de0c36a4 /package/base-files/src/etc
parent23f8ed031ddd26cc8b7b84cb7f0e72448c17802b (diff)
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>
Diffstat (limited to 'package/base-files/src/etc')
-rwxr-xr-xpackage/base-files/src/etc/network/if-post-down.d/04-bonding20
-rwxr-xr-xpackage/base-files/src/etc/network/if-pre-up.d/05-bonding37
2 files changed, 57 insertions, 0 deletions
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