From b871fc687ae7670deb0e30a1c97851dadbc708c2 Mon Sep 17 00:00:00 2001 From: Johannes Truschnigg Date: Sat, 3 Sep 2022 14:12:00 +0200 Subject: [PATCH] Config wizard: implement TX detection/choice --- sqm_lagthrottle_suggest_config.sh | 35 ++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/sqm_lagthrottle_suggest_config.sh b/sqm_lagthrottle_suggest_config.sh index 2e36ea1..c323941 100755 --- a/sqm_lagthrottle_suggest_config.sh +++ b/sqm_lagthrottle_suggest_config.sh @@ -55,12 +55,12 @@ echo "" >&2 _goon -_h "set SQM device (downstream)" -ifb_dev=$(find /sys/devices/virtual/net/ -name ifb\* -print | head -n 1) -if [ -e /sys/devices/virtual/net/ifb* ] +_h "set SQM device (downstream/rx)" +ifb_dev=$( (find /sys/devices/virtual/net/ -name ifb\* -print; echo sorry-no-dev-found) | head -n 1) +if [ -e "${ifb_dev}" ] then - printf 'Likely network device auto-detected to apply traffic shaping to:\n\t%s\n\n' "${ifb_dev}" >&2 - printf 'Please confirm this by supplying either this device path,\nor a custom value to replace it:\n\t' >&2 + printf 'Auto-detected downstream (rx) network device to adjust:\n\t%s\n\n' "${ifb_dev}" >&2 + printf 'Please confirm this by supplying either this device path again,\nor a custom value to replace it:\n\t' >&2 read ifb_dev else printf 'FATAL: No SQM shaping network device could be determined.\nAre you sure SQM has been set up via luci-app-sqm?\n' >&2 @@ -70,12 +70,29 @@ echo "" >&2 if ! [ -f "${ifb_dev}"///statistics/tx_bytes ] then - printf 'FATAL: No SQM shaping network device could be identified at\n\t%s\n' "${ifb_dev}" >&2 + printf 'FATAL: No SQM shaping network device could be identified at\n\t"%s"\n' "${ifb_dev}" >&2 exit 1 fi stats_rx="${ifb_dev}"/statistics/tx_bytes -iface_rx="${ifb_dev%%*/}" +iface_rx="${ifb_dev##*/}" + +iface_tx="${iface_rx/ifb4/}" +if [ -e /sys/class/net/"${iface_tx}" ] +then + printf 'Auto-detected dependent upstream (tx) device:\n\t%s\n\n' "${iface_tx}" >&2 + printf 'Please confirm this by supplying either this interface name again,\nor a custom value to replace it:\n\t' >&2 +else + printf 'Failed to auto-detect a suitable upstream/tx interface.\nPlease supply a valid sysfs device path to it.\n\t' >&2 +fi +read iface_tx + +if ! [ -f /sys/class/net/"${iface_tx}"///statistics/rx_bytes ] +then + printf 'FATAL: No suitable network device could be identified at\n\t"%s"\n' "/sys/class/net/${iface_tx}" >&2 + exit 1 +fi +stats_tx=/sys/class/net/"${iface_tx}"/statistics/rx_bytes _goon _h "set bandwidth limits" @@ -89,7 +106,7 @@ echo "" >&2 if ! [ ${bw_down_min}0 -lt ${bw_down_max}0 ] then - printf 'FATAL: Maximum shaping bandwith must be greater than minimum.\n' + printf 'FATAL: Maximum shaping bandwith must be greater than the minimum.\n' exit 1 fi _goon @@ -205,6 +222,8 @@ printf 'BW_MIN_RX="%d"\n' "${bw_down_min}" >> "${cfgo}" printf 'BW_MAX_RX="%d"\n' "${bw_down_max}" >> "${cfgo}" printf 'STATS_RX="%s"\n' "${stats_rx}" >> "${cfgo}" printf 'IFACE_RX="%s"\n' "${iface_rx##*/}" >> "${cfgo}" +printf 'STATS_TX="%s"\n' "${stats_tx}" >> "${cfgo}" +printf 'IFACE_TX="%s"\n' "${iface_tx##*/}" >> "${cfgo}" printf 'OPTIMIZATION_PREFERENCE="%s"\n' "${bw_or_lat_bias}" >> "${cfgo}" printf 'TREND_DECISION="%s"\n' "${relaxed_or_eager}" >> "${cfgo}" -- 2.39.5