bonding: accept list of slaves in uci list notation
Rework the bonding.sh protocol handler to accept slave interface names
encoded in uci list notation. Also replace ifconfig up/down with ip
link calls while we're at it.
Fixes: #11455
Fixes: https://github.com/openwrt/luci/issues/4473
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit 57a77386de
)
This commit is contained in:
parent
a43822546e
commit
1a169546f2
2 changed files with 25 additions and 20 deletions
|
@ -8,7 +8,7 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=proto-bonding
|
PKG_NAME:=proto-bonding
|
||||||
PKG_VERSION:=2020-03-30
|
PKG_VERSION:=2021-04-09
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=1
|
||||||
|
|
||||||
PKG_LICENSE:=GPL-2.0
|
PKG_LICENSE:=GPL-2.0
|
||||||
|
|
|
@ -37,7 +37,7 @@ proto_bonding_init_config() {
|
||||||
|
|
||||||
proto_config_add_string "bonding_policy"
|
proto_config_add_string "bonding_policy"
|
||||||
proto_config_add_string "link_monitoring"
|
proto_config_add_string "link_monitoring"
|
||||||
proto_config_add_string "slaves"
|
proto_config_add_array "slaves"
|
||||||
proto_config_add_string "all_slaves_active"
|
proto_config_add_string "all_slaves_active"
|
||||||
|
|
||||||
proto_config_add_string "min_links"
|
proto_config_add_string "min_links"
|
||||||
|
@ -66,6 +66,28 @@ proto_bonding_init_config() {
|
||||||
proto_config_add_string "use_carrier"
|
proto_config_add_string "use_carrier"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proto_bonding_add_slave() {
|
||||||
|
local slave=$1
|
||||||
|
local idx=$2
|
||||||
|
local cfg=$3
|
||||||
|
local link=$4
|
||||||
|
|
||||||
|
if [ ! -e "/sys/class/net/$slave" ]; then
|
||||||
|
echo "$cfg" "No slave device $slave found"
|
||||||
|
proto_notify_error "$cfg" NO_DEVICE
|
||||||
|
proto_block_restart "$cfg"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
ip link set dev "$slave" down
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
echo "+$slave" > /sys/class/net/"$link"/bonding/slaves
|
||||||
|
|
||||||
|
ip link set dev "$slave" up
|
||||||
|
}
|
||||||
|
|
||||||
proto_bonding_setup() {
|
proto_bonding_setup() {
|
||||||
local cfg="$1"
|
local cfg="$1"
|
||||||
local link="bonding-$cfg"
|
local link="bonding-$cfg"
|
||||||
|
@ -157,24 +179,7 @@ proto_bonding_setup() {
|
||||||
# Add slaves to bonding interface
|
# Add slaves to bonding interface
|
||||||
local slaves
|
local slaves
|
||||||
json_get_vars slaves
|
json_get_vars slaves
|
||||||
|
json_for_each_item proto_bonding_add_slave slaves "$cfg" "$link"
|
||||||
for slave in $slaves; do
|
|
||||||
|
|
||||||
if [ "$(cat /proc/net/dev |grep "$slave")" == "" ]; then
|
|
||||||
echo "$cfg" "No slave device $slave found"
|
|
||||||
proto_notify_error "$cfg" NO_DEVICE
|
|
||||||
proto_block_restart "$cfg"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
ifconfig "$slave" down
|
|
||||||
|
|
||||||
sleep 1
|
|
||||||
|
|
||||||
echo "+$slave" > /sys/class/net/"$link"/bonding/slaves
|
|
||||||
|
|
||||||
ifconfig "$slave" up
|
|
||||||
done
|
|
||||||
|
|
||||||
[ -n "$all_slaves_active" ] && echo "$all_slaves_active" > /sys/class/net/"$link"/bonding/all_slaves_active
|
[ -n "$all_slaves_active" ] && echo "$all_slaves_active" > /sys/class/net/"$link"/bonding/all_slaves_active
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue