From 8e68e00fcdd5e30de4971b0aba2b7c6f475d0112 Mon Sep 17 00:00:00 2001 From: Christoph Date: Thu, 23 Aug 2018 03:15:11 +0200 Subject: [PATCH] Add support of 'weight' parameter at multipath route. Minor changes on script output. --- check_net.conf.sample | 45 ++++++++++++++++++++++++++++++++----------- netconfig.sh | 41 +++++++++++++++++---------------------- 2 files changed, 52 insertions(+), 34 deletions(-) diff --git a/check_net.conf.sample b/check_net.conf.sample index 545583c..4ce23af 100644 --- a/check_net.conf.sample +++ b/check_net.conf.sample @@ -21,28 +21,51 @@ log_file=/var/log/check_net.log # - # - Example: # - _INITIAL_DEVICE_LIST="eth0:192.168.63.254 ppp-light" +# - _INITIAL_DEVICE_LIST="eth11:172.16.12.254 eth10:172.16.13.254 eth9:172.16.11.254" # - -_INITIAL_DEVICE_LIST="ppp-ckubu" +_INITIAL_DEVICE_LIST="" + # - Set to "false" uses "0.0.0.0" as remote gateway instead of the real address # - USE_REMOTE_GATEWAY_ADDRESS=true #USE_REMOTE_GATEWAY_ADDRESS=false -# - Set default gw (roundrobin) -# - -# - !! SET_MULTIPLE_DEFAULT_GW=true does not work for now.. -# - -SET_MULTIPLE_DEFAULT_GW=false -#SET_MULTIPLE_DEFAULT_GW=true - - # - Set to false uses "0.0.0.0" as default gateway adress instaed of real remote address # - USE_DEFAULT_GW_ADDRESS=true #USE_DEFAULT_GW_ADDRESS=false +# - Set up the default route to be a multipath route. +# - +# - This will balance the routes over all uplink providers (instead of +# - a prefered default route. +# - +# - Note: +# - that balancing will not be perfect, as it is route based, and routes +# - are cached. This means that routes to often-used sites will always be +# - over the same provider. +# - +# - !! At least within this script, multipath route only works as exspected +# - if all providers have a static uplink (and do not nat the uplink?) +# - +SET_MULTIPLE_DEFAULT_GW=false +#SET_MULTIPLE_DEFAULT_GW=true + +# - MULTIPATH_DEVICE_WEIGHT +# - +# - This a weight for (inet) devices of a multipath route reflecting +# - its relative bandwidth or quality. +# - +# - The default value for weight of any device is '1' +# - +# - Example: +# - MULTIPATH_DEVICE_WEIGHT="eth9:2 eth10:1 eth11:4" +# - +MULTIPATH_DEVICE_WEIGHT="eth9:2 eth11:4" + + # - Hostnames for ping test # - # - Note: The first two reachable hosts will be used for ping test. @@ -67,9 +90,9 @@ content_type='Content-Type: text/plain;\n charset="utf-8"' # - # - Example: # - ======== -# - local ip 192.168.10.1 through extern interface ppp-st and +# - local ip 192.168.10.1 through extern interface eth10 and # - local ip 192.168.10.13 through extern interface ppp-surf1 -# - rule_local_ips="ppp-st:192.168.10.1 ppp-surf1:192.168.10.13" +# - rule_local_ips="eth10:192.168.10.1 ppp-surf1:192.168.10.13" # - rule_local_ips="" diff --git a/netconfig.sh b/netconfig.sh index 5d64e6f..fbd832e 100755 --- a/netconfig.sh +++ b/netconfig.sh @@ -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