Add support of 'weight' parameter at multipath route. Minor changes on script output.

This commit is contained in:
2018-08-23 03:15:11 +02:00
parent 156fe900af
commit 8e68e00fcd
2 changed files with 52 additions and 34 deletions

View File

@@ -152,26 +152,12 @@ for _online_device in $ONLINE_DEVICE_LIST ; do
done
#echo "All Devices:"
#for _device in "${inet_devices_arr[@]}" ; do
# echo -e "\t$_device"
#done
#echo "Online Devices:"
#for _device in "${online_devices_arr[@]}" ; do
# echo -e "\t$_device"
#done
#
#for inet_device in "${inet_devices_arr[@]}" ; do
# if [ -n "$ONLINE_DEVICE_LIST" ]; then
# if ! containsElement "$inet_device" "${online_devices_arr[@]}" ; then
# echo "$inet_device is offline"
# continue
# fi
# fi
#done
#
#echo ""
#exit
declare -A multipath_device_weigth_arr
declare -i weight
for _val in $MULTIPATH_DEVICE_WEIGHT ; do
IFS=':' read -a _val_arr <<< "${_val}"
multipath_device_weigth_arr[${_val_arr[0]}]=${_val_arr[1]}
done
## - Define associative arrays
@@ -714,8 +700,10 @@ while ! $configured && [ $_try_number -lt $max_attempts ] ; do
echo "/sbin/ip route add $_remote_gw_net dev $_key src $_local_gw_address table $_rt_name" >> $log_file
/sbin/ip route add $_remote_gw_net dev $_key src $_local_gw_address table $_rt_name >> $log_file 2>&1
else
echo -e "#\t[ info ]: Connection through $_key is already part of table $_rt_name" >> $log_file
echo -e "#\t[ info ]: Connection to $_remote_gw through $_key is already part of table $_rt_name" >> $log_file
fi
else
echo -e "#\t[ info ]: $_remote_gw_net through $_key is already part of table $_rt_name"
fi
else
## - Remote Network: 0.0.0.0
@@ -744,14 +732,21 @@ while ! $configured && [ $_try_number -lt $max_attempts ] ; do
default_gw_arg=""
for _key in "${!default_gw_arr[@]}"; do
if [[ -n "${multipath_device_weigth_arr[$_key]}" ]]; then
weight=${multipath_device_weigth_arr[$_key]}
else
weight=1
fi
[[ $weight -lt 1 ]] && weight=1
if $USE_DEFAULT_GW_ADDRESS ; then
## - Default Gateway: $remote_gw_address
## -
default_gw_arg="$default_gw_arg nexthop via ${default_gw_arr[$_key]} dev $_key weight 1"
default_gw_arg="nexthop via ${default_gw_arr[$_key]} dev $_key weight $weight $default_gw_arg"
else
## - Default Gateway: 0.0.0.0
## -
default_gw_arg="$default_gw_arg nexthop via 0.0.0.0 dev $_key weight 1"
default_gw_arg="nexthop via 0.0.0.0 dev $_key weight $weight $default_gw_arg"
fi
done