From 6692a4555d8b1918484db9dc5561453e5ce1b6c5 Mon Sep 17 00:00:00 2001 From: Marcin Krol Date: Thu, 16 May 2024 01:06:48 +0200 Subject: [PATCH] - use ip command for configuring bond interfaces --- lib/ifdown-bond | 10 +++++----- lib/ifup | 12 +++++++----- lib/ifup-bond | 11 +++-------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/lib/ifdown-bond b/lib/ifdown-bond index 80a2cf2..f490bbe 100755 --- a/lib/ifdown-bond +++ b/lib/ifdown-bond @@ -35,19 +35,19 @@ fi setup_ip_param # forget all addresses -LC_ALL=C ip addr flush dev ${DEVICE} 2>&1 | grep -v "Nothing to flush" +LC_ALL=C ip addr flush dev "${DEVICE}" 2>&1 | grep -v "Nothing to flush" # release slave devices for SLAVE_DEV in $(cat /sys/class/net/${DEVICE}/bonding/slaves 2>/dev/null); do - echo "-${SLAVE_DEV}" > /sys/class/net/${DEVICE}/bonding/slaves + ip link set "${SLAVE_DEV}" nomaster done # bring bonding master down -ip link set ${DEVICE} down +ip link set "${DEVICE}" down # remove bonding master -if grep -wq "${DEVICE}" /sys/class/net/bonding_masters; then - echo "-${DEVICE}" > /sys/class/net/bonding_masters +if [ -d "/sys/class/net/${DEVICE}" ]; then + ip link del "${DEVICE}" type bond if [ $? -ne 0 ]; then exit 1 fi diff --git a/lib/ifup b/lib/ifup index 5d6fc21..b8536af 100755 --- a/lib/ifup +++ b/lib/ifup @@ -125,11 +125,13 @@ if [ -n "$ETHTOOL_OPTS" ] ; then fi if is_yes "$SLAVE" && [ -n "$MASTER" ] ; then - if ! grep -wq "${DEVICE}" /sys/class/net/${MASTER}/bonding/slaves 2>/dev/null; then - nls "Enslaving %s to %s" "$DEVICE" "$MASTER" - ip link set dev ${DEVICE} down - echo "+${DEVICE}" > /sys/class/net/${MASTER}/bonding/slaves 2>/dev/null - fi + # create master if it doesn't exist yet + [ ! -d "/sys/class/net/${MASTER}" ] && ip link add "${MASTER}" type bond + + nls "Enslaving %s to %s" "${DEVICE}" "${MASTER}" + ip link set "${DEVICE}" master "${MASTER}" + ip link set "${DEVICE}" up + exit 0 fi diff --git a/lib/ifup-bond b/lib/ifup-bond index 5651839..3c1d648 100755 --- a/lib/ifup-bond +++ b/lib/ifup-bond @@ -35,20 +35,15 @@ fi if [ ! -f /sys/class/net/bonding_masters ]; then modprobe -s bonding || exit 1 # delete default bond0 - echo "-bond0" > /sys/class/net/bonding_masters + ip link del bond0 type bond fi # set all major variables setup_ip_param # create bonding master -if ! grep -wq "${DEVICE}" /sys/class/net/bonding_masters; then - echo "+${DEVICE}" > /sys/class/net/bonding_masters - if [ $? -eq 0 ]; then - ip link set dev ${DEVICE} multicast ${MULTICAST} ${ARP} - else - exit 1 - fi +if [ ! -d "/sys/class/net/${DEVICE}" ]; then + ip link add "${DEVICE}" type bond fi # add the bits to setup driver parameters here -- 2.46.0