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
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
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