Jelajahi Sumber

Revert "Improve SQM_VERBOSITY handling"

This reverts commit 523cf78b54e98e2aa1f2e5900eb79f4eeab768e9.
Toke Høiland-Jørgensen 8 tahun lalu
induk
melakukan
45dd6a66c8
4 mengubah file dengan 41 tambahan dan 48 penghapusan
  1. 30 35
      src/functions.sh
  2. 2 4
      src/run-openwrt.sh
  3. 6 6
      src/start-sqm
  4. 3 3
      src/stop-sqm

+ 30 - 35
src/functions.sh

@@ -6,19 +6,14 @@
 
 #improve the logread output, but allow silencing it, if verbosity is set to 0
 sqm_logger() {
-    local CUR_VERBOSITY=""
-    [ -z "$2" ] && REQUESTED_LOG_LEVEL=${VERBOSITY_NORMAL} || REQUESTED_LOG_LEVEL=${2}
-
     if [ "$SQM_VERBOSITY" -gt "$VERBOSITY_SILENT" ] ; then
-	if [ "${SQM_VERBOSITY}" -ge "${REQUESTED_LOG_LEVEL}" ] ; then
-	    if [ "$SQM_SYSLOG" -eq "1" ]; then
-    		logger -t SQM -s "$*"
-	    else
-    		echo "$@" >&2
-	    fi
-	    #sm: slightly dangerous as this will keep adding to the log file
-	    [ -n "${SQM_DEBUG}" -a "${SQM_DEBUG}" == 1 ] && echo "$@" >> ${SQM_DEBUG_LOG}
+	if [ "$SQM_SYSLOG" -eq "1" ]; then
+    	    logger -t SQM -s "$*"
+	else
+    	    echo "$@" >&2
 	fi
+	#sm: slightly dangerous as this will keep adding to the log file
+	[ -n "${SQM_DEBUG}" -a "${SQM_DEBUG}" == 1 ] && echo "$@" >> ${SQM_DEBUG_LOG}
     fi
 }
 
@@ -47,7 +42,7 @@ ipt() {
 #sm: wrapper to call tc to allow debug logging 
 tc_wrapper() {
     tc_args=$*
-    sqm_logger "tc arguments: $tc_args" "${VERBOSITY_TOO_MUCH}"
+    [ "$SQM_VERBOSITY" -gt "$VERBOSITY_VERBOSE" ] && sqm_logger "tc arguments: $tc_args"
     [ "${SQM_DEBUG}" == 1 ] && echo "${TC_BINARY} $*" >> ${SQM_DEBUG_LOG}
     ${TC_BINARY} $* >> ${OUTPUT_TARGET} 2>&1
 }
@@ -55,7 +50,7 @@ tc_wrapper() {
 #sm: wrapper to call tc to allow debug logging 
 ip_wrapper() {
     ip_args=$*
-    sqm_logger "ip arguments: $ip_args" "${VERBOSITY_TOO_MUCH}"
+    [ "$SQM_VERBOSITY" -gt "$VERBOSITY_VERBOSE" ] && sqm_logger "ip arguments: $ip_args"
     [ "${SQM_DEBUG}" == 1 ] && echo "${IP_BINARY} $*" >> ${SQM_DEBUG_LOG}
     ${IP_BINARY} $* >> ${OUTPUT_TARGET} 2>&1
 }
@@ -85,7 +80,7 @@ get_ifb_associated_with_if() {
     # CUR_IFB=$( $TC -p filter show parent ffff: dev ${CUR_IF} | grep -o -e ifb'[[:digit:]]\+' )
     #local CUR_IFB=$( $TC -p filter show parent ffff: dev ${CUR_IF} | grep -o -e ifb'[^)]\+' )    # my editor's syntax coloration is limitied so I need a single quote in this line (between eiditor and s)
     local CUR_IFB=$( $TC -p filter show parent ffff: dev ${CUR_IF} | grep -o -E ifb'[^)\ ]+' )    # my editor's syntax coloration is limitied so I need a single quote in this line (between eiditor and s)
-    sqm_logger "ifb associated with interface ${CUR_IF}: ${CUR_IFB}" "${VERBOSITY_VERBOSE}"
+    [ "$SQM_VERBOSITY" -gt "$VERBOSITY_NORMAL" ] && sqm_logger "ifb associated with interface ${CUR_IF}: ${CUR_IFB}"
     #sm: we could not detect an associated IFB for CUR_IF
     if [ -z "${CUR_IFB}" ]; 
     then
@@ -99,7 +94,7 @@ get_ifb_associated_with_if() {
 	    sqm_logger "Please report this as an issue at https://github.com/tohojo/sqm-scripts"
 	    sqm_logger "Please copy and paste everything below the cut-here line into your issue report, thanks."
 	else
-	    sqm_logger "Currently no ifb is associated with ${CUR_IF}, this is normal during starting of the sqm system." "${VERBOSITY_VERBOSE}"
+	    [ "$SQM_VERBOSITY" -gt "$VERBOSITY_NORMAL" ] && sqm_logger "Currently no ifb is associated with ${CUR_IF}, this is normal during starting of the sqm system."
 	fi
     fi
     echo ${CUR_IFB}
@@ -152,7 +147,7 @@ get_ifb_for_if() {
     # if an ifb is already associated return that
     local CUR_IFB=$( get_ifb_associated_with_if ${CUR_IF} )
     [ -z "$CUR_IFB" ] && CUR_IFB=$( create_new_ifb_for_if ${CUR_IF} )
-    [ -z "$CUR_IFB" ] && sqm_logger "Could not find existing IFB for ${CUR_IF}, nor create a new IFB instead..." "${VERBOSITY_NORMAL}"
+    [ -z "$CUR_IFB" ] && sqm_logger "Could not find existing IFB for ${CUR_IF}, nor create a new IFB instead..."
     echo ${CUR_IFB}
 }
 
@@ -185,7 +180,7 @@ verify_qdisc() {
     $TC qdisc replace dev $ifb $root_string $qdisc #>>${OUTPUT_TARGET} 2>&1
     res=$?
     [ "$res" = "0" ] || not="NOT "
-    [ "$res" != "0" -o "(" "$SQM_VERBOSITY" -gt "$VERBOSITY_NORMAL" ")" ] && sqm_logger "QDISC $qdisc is ${not}useable." "${VERBOSITY_VERBOSE}"
+    [ "$res" != "0" -o "(" "$SQM_VERBOSITY" -gt "$VERBOSITY_NORMAL" ")" ] && sqm_logger "QDISC $qdisc is ${not}useable."
     delete_ifb $ifb
     return $res
 }
@@ -198,7 +193,7 @@ get_htb_adsll_string() {
         # HTB defaults to MTU 1600 and an implicit fixed TSIZE of 256, but HTB as of around 3.10.0
         # does not actually use a table in the kernel
         ADSLL="mpu ${STAB_MPU} linklayer ${LINKLAYER} overhead ${OVERHEAD} mtu ${STAB_MTU}"
-        sqm_logger "ADSLL: ${ADSLL}" "${VERBOSITY_VERBOSE}"
+        [ "$SQM_VERBOSITY" -gt "$VERBOSITY_NORMAL" ] && sqm_logger "ADSLL: ${ADSLL}"
     fi
     echo ${ADSLL}
 }
@@ -208,7 +203,7 @@ get_stab_string() {
     if [ "${LLAM}" = "tc_stab" -a "$LINKLAYER" != "none" ];
     then
         STABSTRING="stab mtu ${STAB_MTU} tsize ${STAB_TSIZE} mpu ${STAB_MPU} overhead ${OVERHEAD} linklayer ${LINKLAYER}"
-        sqm_logger "STAB: ${STABSTRING}" "${VERBOSITY_VERBOSE}"
+        [ "$SQM_VERBOSITY" -gt "$VERBOSITY_NORMAL" ] && sqm_logger "STAB: ${STABSTRING}"
     fi
     echo ${STABSTRING}
 }
@@ -224,7 +219,7 @@ get_cake_lla_string() {
         fi
 
         STABSTRING="${STABSTRING} overhead ${OVERHEAD}"
-        sqm_logger "cake link layer adjustments: ${STABSTRING}" "${VERBOSITY_VERBOSE}"
+        [ "$SQM_VERBOSITY" -gt "$VERBOSITY_NORMAL" ] && sqm_logger "cake link layer adjustments: ${STABSTRING}"
     fi
     echo ${STABSTRING}
 }
@@ -234,7 +229,7 @@ sqm_stop() {
     $TC qdisc del dev $IFACE ingress #2>> ${OUTPUT_TARGET}
     $TC qdisc del dev $IFACE root #2>> ${OUTPUT_TARGET}
     [ -n "$CUR_IFB" ] && $TC qdisc del dev $CUR_IFB root #2>> ${OUTPUT_TARGET}
-    [ -n "$CUR_IFB" ] && sqm_logger "${0}: ${CUR_IFB} shaper deleted" "${VERBOSITY_VERBOSE}"
+    [ -n "$CUR_IFB" -a "$SQM_VERBOSITY" -gt "$VERBOSITY_NORMAL" ] && sqm_logger "${0}: ${CUR_IFB} shaper deleted"
 
     [ -n "$CUR_IFB" ] && ipt -t mangle -D POSTROUTING -o $CUR_IFB -m mark --mark 0x00 -g QOS_MARK_${IFACE}
     ipt -t mangle -D POSTROUTING -o $IFACE -m mark --mark 0x00${IPT_MASK_STRING} -g QOS_MARK_${IFACE}
@@ -250,7 +245,7 @@ sqm_stop() {
 
     [ -n "$CUR_IFB" ] && $IP link set dev ${CUR_IFB} down
     [ -n "$CUR_IFB" ] && $IP link delete ${CUR_IFB} type ifb
-    [ -n "$CUR_IFB" ] && sqm_logger "${0}: ${CUR_IFB} interface deleted" "${VERBOSITY_NORMAL}"
+    [ -n "$CUR_IFB" ] && sqm_logger "${0}: ${CUR_IFB} interface deleted"
 }
 # Note this has side effects on the prio variable
 # and depends on the interface global too
@@ -321,7 +316,7 @@ get_htb_quantum() {
         CUR_QUANTUM=$((${CUR_QUANTUM} * 2))
     fi
 
-    sqm_logger "CUR_HTB_QUANTUM: ${CUR_QUANTUM}, BANDWIDTH: ${BANDWIDTH}" "${VERBOSITY_VERBOSE}"
+    [ "$SQM_VERBOSITY" -gt "$VERBOSITY_NORMAL" ] && sqm_logger "CUR_HTB_QUANTUM: ${CUR_QUANTUM}, BANDWIDTH: ${BANDWIDTH}"
 
     echo $CUR_QUANTUM
 }
@@ -331,7 +326,7 @@ get_htb_quantum() {
 # but I fear we actually need the wire size of the whole thing not so much the MTU
 get_mtu() {
     CUR_MTU=$(cat /sys/class/net/$1/mtu)
-    sqm_logger "IFACE: ${1} MTU: ${CUR_MTU}" "${VERBOSITY_VERBOSE}"
+    [ "$SQM_VERBOSITY" -gt "$VERBOSITY_NORMAL" ] && sqm_logger "IFACE: ${1} MTU: ${CUR_MTU}"
     echo ${CUR_MTU}
 }
 
@@ -375,7 +370,7 @@ get_flows_count() {
 get_target() {
     local CUR_TARGET=${1}
     local CUR_LINK_KBPS=${2}
-    [ ! -z "$CUR_TARGET" ] && sqm_logger "cur_target: ${CUR_TARGET} cur_bandwidth: ${CUR_LINK_KBPS}" "${VERBOSITY_NORMAL}"
+    [ ! -z "$CUR_TARGET" ] && sqm_logger "cur_target: ${CUR_TARGET} cur_bandwidth: ${CUR_LINK_KBPS}"
     CUR_TARGET_STRING=
     # either e.g. 100ms or auto
     CUR_TARGET_VALUE=$( echo ${CUR_TARGET} | grep -o -e \^'[[:digit:]]\+' )
@@ -407,9 +402,9 @@ get_target() {
                     TMP_INTERVAL_STRING=$( adapt_interval_to_slow_link $TMP_TARGET_US )
                     CUR_TARGET_STRING="target ${TMP_TARGET_US}us ${TMP_INTERVAL_STRING}"
                     AUTO_TARGET="1"
-                    sqm_logger "get_target defaulting to auto." "${VERBOSITY_VERBOSE}"
+                    [ "$SQM_VERBOSITY" -gt "$VERBOSITY_NORMAL" ] && sqm_logger "get_target defaulting to auto."
                 else
-                    sqm_logger "required link bandwidth in kbps not passed to get_target()." "${VERBOSITY_NORMAL}"
+                    sqm_logger "required link bandwidth in kbps not passed to get_target()."
                 fi
             fi
             # but still allow explicit use of the keyword auto for backward compatibility
@@ -422,7 +417,7 @@ get_target() {
                         CUR_TARGET_STRING="target ${TMP_TARGET_US}us ${TMP_INTERVAL_STRING}"
                         AUTO_TARGET="1"
                     else
-                        sqm_logger "required link bandwidth in kbps not passed to get_target()." "${VERBOSITY_NORMAL}"
+                        sqm_logger "required link bandwidth in kbps not passed to get_target()."
                     fi
                     ;;
             esac
@@ -433,9 +428,9 @@ get_target() {
                     then
                         CUR_TARGET_STRING=""    # return nothing so the default target is not over-ridden...
                         AUTO_TARGET="1"
-                        sqm_logger "get_target using qdisc default, no explicit target string passed." "${VERBOSITY_VERBOSE}"
+                        [ "$SQM_VERBOSITY" -gt "$VERBOSITY_NORMAL" ] && sqm_logger "get_target using qdisc default, no explicit target string passed."
                     else
-                        sqm_logger "required link bandwidth in kbps not passed to get_target()." "${VERBOSITY_NORMAL}"
+                        sqm_logger "required link bandwidth in kbps not passed to get_target()."
                     fi
                     ;;
             esac
@@ -443,7 +438,7 @@ get_target() {
             then
                 if [ -z "${CUR_TARGET_VALUE}" -o -z "${UNIT_VALID}" ];
                 then
-                    [ -z "$AUTO_TARGET" ] && sqm_logger "${CUR_TARGET} is not a well formed tc target specifier; e.g.: 5ms (or s, us), or one of the strings auto or default." "${VERBOSITY_NORMAL}"
+                    [ -z "$AUTO_TARGET" ] && sqm_logger "${CUR_TARGET} is not a well formed tc target specifier; e.g.: 5ms (or s, us), or one of the strings auto or default."
                 fi
             fi
             ;;
@@ -504,10 +499,10 @@ get_limit() {
                                           ;;
         bfifo) [ -z "$CURLIMIT" ] && [ ! -z "$LIMIT" ] && CURLIMIT=$(( ${LIMIT} * $( cat /sys/class/net/${IFACE}/mtu ) ))    # bfifo defaults to txquelength * MTU,
                ;;
-        *) sqm_logger "${QDISC} does not support a limit" "${VERBOSITY_NORMAL}"
+        *) sqm_logger "${QDISC} does not support a limit"
            ;;
     esac
-    sqm_logger "get_limit: $1 CURLIMIT: ${CURLIMIT}" "${VERBOSITY_VERBOSE}"
+    [ "$SQM_VERBOSITY" -gt "$VERBOSITY_NORMAL" ] && sqm_logger "get_limit: $1 CURLIMIT: ${CURLIMIT}"
 
     if [ ! -z "$CURLIMIT" ]
     then
@@ -540,10 +535,10 @@ get_ecn() {
             esac
             ;;
         *)
-            sqm_logger "ecn value $1 not handled" "${VERBOSITY_NORMAL}"
+            sqm_logger "ecn value $1 not handled"
             ;;
     esac
-    sqm_logger "get_ECN: $1 CURECN: ${CURECN} IECN: ${IECN} EECN: ${EECN}" "${VERBOSITY_VERBOSE}"
+    [ "$SQM_VERBOSITY" -gt "$VERBOSITY_NORMAL" ] && sqm_logger "get_ECN: $1 CURECN: ${CURECN} IECN: ${IECN} EECN: ${EECN}"
     echo ${CURECN}
 
 }

+ 2 - 4
src/run-openwrt.sh

@@ -55,16 +55,14 @@ run_sqm_scripts() {
     export TARGET=$(config_get "$section" target)
     export SQUASH_DSCP=$(config_get "$section" squash_dscp)
     export SQUASH_INGRESS=$(config_get "$section" squash_ingress)
+    export SQM_VERBOSITY=$(config_get "$section" verbosity)
 
     export QDISC=$(config_get "$section" qdisc)
     export SCRIPT=$(config_get "$section" script)
 
 
-    #sm: if SQM_DEBUG or SQM_VERBOSITY were passed in via the command line make them available to the other scripts
+    #sm: if SQM_DEBUG was passed in via the command line make it available to the other scripts
     [ -n "$SQM_DEBUG" ] && export SQM_DEBUG || export SQM_DEBUG=$(config_get "$section" debug_logging)
-    [ -n "$SQM_VERBOSITY" ] && export SQM_VERBOSITY || export SQM_VERBOSITY=$(config_get "$section" verbosity)
-    
-    
 
     #sm: only stop-sqm if there is something running
     CUR_STATE_FILE="${SQM_STATE_DIR}/${IFACE}.state"

+ 6 - 6
src/start-sqm

@@ -17,30 +17,30 @@ STATE_FILE="${SQM_STATE_DIR}/${IFACE}.state"
 [ -d "${SQM_STATE_DIR}" ] || mkdir -p "${SQM_STATE_DIR}"
 
 if [ -f "${STATE_FILE}" ]; then
-    sqm_logger "SQM already activated on ${IFACE}." "${VERBOSITY_VERBOSE}"
+    [ "$SQM_VERBOSITY" -gt "$VERBOSITY_NORMAL" ] && sqm_logger "SQM already activated on ${IFACE}."
     exit 1
 fi
 
 # in case of spurious hotplug events, try double check whether the interface is really up
 if [ ! -d /sys/class/net/${IFACE} ] ; then
-    sqm_logger "${IFACE} does currently not exist, not even trying to start SQM on nothing." "${VERBOSITY_VERBOSE}"
+    [ "$SQM_VERBOSITY" -gt "$VERBOSITY_NORMAL" ] && sqm_logger "${IFACE} does currently not exist, not even trying to start SQM on nothing."
     exit 1
 fi
 
 if [ "${ENABLED:-1}" -ne "1" ]; then
-    sqm_logger "SQM config disabled on ${IFACE}." "${VERBOSITY_VERBOSE}"
+    [ "$SQM_VERBOSITY" -gt "$VERBOSITY_NORMAL" ] && sqm_logger "SQM config disabled on ${IFACE}."
     exit 0
 fi
 
 if [ ! -f "${SQM_LIB_DIR}/$SCRIPT" ]; then
-    sqm_logger "SQM script ${SCRIPT} not found!" "${VERBOSITY_NORMAL}"
+    sqm_logger "SQM script ${SCRIPT} not found!"
     exit 1
 fi
 
 . "${SQM_LIB_DIR}/$SCRIPT"
 
-[ "${SQM_DEBUG}" == 1 ] && echo -e "\n\n\n$( date ): Starting SQM script: ${SCRIPT} on ${IFACE}, in: ${DOWNLINK} Kbps, out: ${UPLINK} Kbps\n" >> ${SQM_DEBUG_LOG}
-sqm_logger "${0}: Starting SQM script: ${SCRIPT} on ${IFACE}, in: ${DOWNLINK} Kbps, out: ${UPLINK} Kbps" "${VERBOSITY_NORMAL}"
+[ "${SQM_DEBUG}" == 1 ] && echo -e "\n$( date ): Starting SQM script: ${SCRIPT} on ${IFACE}, in: ${DOWNLINK} Kbps, out: ${UPLINK} Kbps" >> ${SQM_DEBUG_LOG}
+sqm_logger "${0}: Starting SQM script: ${SCRIPT} on ${IFACE}, in: ${DOWNLINK} Kbps, out: ${UPLINK} Kbps"
 sqm_start && write_state_file ${STATE_FILE} ${ALL_SQM_VARS}
 
 exit 0

+ 3 - 3
src/stop-sqm

@@ -15,15 +15,15 @@
 . ${SQM_LIB_DIR}/defaults.sh    #sm: this should allow debugging output for sqm_logger...
 STATE_FILE="${SQM_STATE_DIR}/${IFACE}.state"
 
-[ "${SQM_DEBUG}" == 1 ] && echo -e "\n\n\n$( date ): Stopping SQM on ${IFACE}\n" >> ${SQM_DEBUG_LOG}
-sqm_logger "${0}: Stopping SQM on ${IFACE}" "${VERBOSITY_NORMAL}"
+[ "${SQM_DEBUG}" == 1 ] && echo -e "\n\n\n$( date ): Stopping SQM on ${IFACE}" >> ${SQM_DEBUG_LOG}
+sqm_logger "${0}: Stopping SQM on ${IFACE}"
 
 # make sure to only delete the ifb associated with the current interface
 CUR_IFB=$( get_ifb_associated_with_if ${IFACE} )
 [ -z "$CUR_IFB" ] && CUR_IFB=$( ifb_name ${IFACE} )
 
 if [ ! -f "${SQM_LIB_DIR}/$SCRIPT" ]; then
-    sqm_logger "SQM script ${SCRIPT} not found!" "${VERBOSITY_NORMAL}"
+    sqm_logger "SQM script ${SCRIPT} not found!"
     exit 1
 fi