sqm-scripts: Fix a minor bug, add copyrights, improve logging
authorHannu Nyman <redacted>
Sat, 18 Oct 2014 10:25:46 +0000 (13:25 +0300)
committerHannu Nyman <redacted>
Sat, 18 Oct 2014 10:25:46 +0000 (13:25 +0300)
Changes committed to the cerowrt original repo after the initial import here:
 - Better license & copyright statements, as requested
 - Fixed a minor bug in stopping sqm
 - Logging improvements
 - Dead code removed
 - Typos corrected

Signed-off-by: Hannu Nyman <redacted>
net/sqm-scripts/Makefile
net/sqm-scripts/files/usr/lib/sqm/functions.sh
net/sqm-scripts/files/usr/lib/sqm/run.sh
net/sqm-scripts/files/usr/lib/sqm/simple.qos
net/sqm-scripts/files/usr/lib/sqm/simple_pppoe.qos
net/sqm-scripts/files/usr/lib/sqm/simplest.qos
net/sqm-scripts/files/usr/lib/sqm/stop.sh

index 95fc5e72e26b52433309fd916df8f3e24d52978d..ea296f1b40c4284a84801cb8f9ddc9d8292f373d 100644 (file)
@@ -8,7 +8,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=sqm-scripts
-PKG_VERSION:=6
+PKG_VERSION:=7
 PKG_RELEASE:=1
 PKG_LICENSE:=GPLv2
 
index 63a67e358641fd5cc33c1fd4b33dc1dced0b7795..f2ed44bbe8d73cec05440ca970a0dbba7f4c1cad 100644 (file)
@@ -1,3 +1,9 @@
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+#       Copyright (C) 2012-4 Michael D. Taht, Toke Høiland-Jørgensen, Sebastian Moeller
+
 #improve the logread output
 sqm_logger() {
     logger -t SQM -s ${1}
@@ -74,42 +80,6 @@ get_ifb_associated_with_if() {
     echo ${CUR_IFB}
 }
 
-# what is the lowest-index currently not used ifb device
-#sm: hopefully this is not required any longer, and can be deleted after a bit more testing...
-get_lowest_unused_ifb() {
-    LOWEST_FREE_IFB=
-    # this just returns a list of currently existing IFBs, these need not be associated with any interface
-    CUR_UP_IFBS=$( ifconfig | grep -o -e ifb'[[:digit:]]\+' )
-    # the possible IFBs (N in insmod ifb numifbs=N)
-    here=$( pwd )
-    cd /sys/devices/virtual/net/
-    CUR_ALLOWED_IFBS=$( ls -d ifb* )
-    sqm_logger "Currently allowed IFBs: ${CUR_ALLOWED_IFBS}"
-    cd ${here}
-    # this is the sorted list of the active ifbs
-    # note for 3.10.32 unused and even down IFBs linger on in the tc output, so take $CUR_UP_IFBS instead
-    # a better test might be to check for each allowed IFB whether it is in use
-    # but the only way I figured out doing this means interating over all interfaces and that sounds costly
-    # so instead we rely on stop.sh actually calling ifconfig ${LAST_USED_IFB} down
-    CUR_USED_IFBS=$( tc -d qdisc | grep -o -e ifb'[[:digit:]]\+' | sort -u)
-    sqm_logger "Currently used IFBs: ${CUR_USED_IFBS}"
-    # now find the lowest index not in the sorted list
-    local CUR_IDX=0
-    while [ -z "$LOWEST_FREE_IFB" ]
-    do
-        #TMP=$( echo "${CUR_USED_IFBS}" | grep -o -e ifb${CUR_IDX} )
-        TMP=$( echo "${CUR_UP_IFBS}" | grep -o -e ifb${CUR_IDX} )
-        [ -z "$TMP" ] && LOWEST_FREE_IFB="ifb"${CUR_IDX}
-        CUR_IDX=$(( $CUR_IDX + 1 ))
-    done
-    # check whether the number is in the allowed range
-    LOWEST_FREE_IFB=$( echo "${CUR_ALLOWED_IFBS}" | grep -o -e ${LOWEST_FREE_IFB} )
-    [ -z "${LOWEST_FREE_IFB}" ] && sqm_logger "The IFB candidate ifb$(( ${CUR_IDX} - 1 )) is not in the range of allowed IFBs, bailing out..."
-    sqm_logger "selected ifb index: ${LOWEST_FREE_IFB}"
-    echo ${LOWEST_FREE_IFB}
-}
-
-# instead of playing around with indices just create a named IFB
 # ATTENTION, IFB names can only be 15 chararcters, so we chop of excessive characters at the start of the interface name 
 # if required
 create_new_ifb_for_if() {
@@ -134,8 +104,6 @@ get_ifb_for_if() {
     CUR_IF=$1
     # if an ifb is already associated return that
     CUR_IFB=$( get_ifb_associated_with_if ${CUR_IF} )
-    # otherwise find the lowest unused ifb device
-    #[ -z "$CUR_IFB" ] && CUR_IFB=$( get_lowest_unused_ifb )
     [ -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..."
     echo ${CUR_IFB}
@@ -145,13 +113,6 @@ get_ifb_for_if() {
 [ -z "$DEV" ] && DEV=$( get_ifb_for_if ${IFACE} )      # automagically get the right IFB device for the IFACE"
 
 
-
-#sqm_logger "iqdisc opts: ${iqdisc_opts}"
-#sqm_logger "eqdisc opts: ${eqdisc_opts}"
-
-#sqm_logger "LLAM: ${LLAM}"
-#sqm_logger "LINKLAYER: ${LINKLAYER}"
-
 get_htb_adsll_string() {
        ADSLL=""
        if [ "$LLAM" = "htb_private" -a "$LINKLAYER" != "none" ]; 
index 5453bea3f3f6c1f9fcec13f8794c8d6e083367a7..d7b86a220f64688408d58690fc07177e814e7320 100755 (executable)
@@ -1,5 +1,12 @@
 #!/bin/sh
 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+#       Copyright (C) 2012-4 Michael D. Taht, Toke Høiland-Jørgensen, Sebastian Moeller
+
+
 . /lib/functions.sh
 
 STOP=$1
@@ -17,7 +24,7 @@ for STATE_FILE in ${PROTO_STATE_FILE_LIST} ; do
     then
        STATE_FILE_BASE_NAME=$( basename ${STATE_FILE} )
        CURRENT_INTERFACE=${STATE_FILE_BASE_NAME:${#ACTIVE_STATE_PREFIX}:$(( ${#STATE_FILE_BASE_NAME} - ${#ACTIVE_STATE_PREFIX} ))}        
-       logger -t SQM -s "Stopping SQM on interface: ${CURRENT_INTERFACE}"
+       logger -t SQM -s "${0} Stopping SQM on interface: ${CURRENT_INTERFACE}"
        /usr/lib/sqm/stop.sh ${CURRENT_INTERFACE}
        rm ${STATE_FILE}        # well, we stop it so it is not running anymore and hence no active state file needed...
     fi
@@ -38,7 +45,7 @@ run_simple_qos() {
                # this should not be possible, delete after testing
                local SECTION_STOP="stop"       # it seems the user just de-selected enable, so stop the active SQM
            else
-               logger -t SQM -s "SQM for interface ${IFACE} is not enabled, skipping over..."
+               logger -t SQM -s "${0} SQM for interface ${IFACE} is not enabled, skipping over..."
                return 0        # since SQM is not active on the current interface nothing to do here
            fi
        fi
@@ -72,10 +79,10 @@ run_simple_qos() {
 #           /usr/lib/sqm/stop.sh
 #           [ -f ${ACTIVE_STATE_FILE_FQN} ] && rm ${ACTIVE_STATE_FILE_FQN}     # conditional to avoid errors ACTIVE_STATE_FILE_FQN does not exist anymore
 #           $(config_set "$section" enabled 0) # this does not save to the config file only to the loaded memory representation
-#           logger -t SQM -s "SQM qdiscs on ${IFACE} removed"
+            logger -t SQM -s "${0} SQM qdiscs on ${IFACE} removed"
             return 0
        fi
-       logger -t SQM -s "Queue Setup Script: ${SCRIPT}"
+       logger -t SQM -s "${0} Queue Setup Script: ${SCRIPT}"
        [ -x "$SCRIPT" ] && { $SCRIPT ; touch ${ACTIVE_STATE_FILE_FQN}; }
 }
 
index efafada4cdd957c9f68ef4832f7122b69ed7a573..c752660bb4904735dc21a0c851c75eafca8ce6a7 100755 (executable)
@@ -3,8 +3,11 @@
 # A 3 bin tc_codel and ipv6 enabled shaping script for
 # ethernet gateways
 
-# Copyright (C) 2012 Michael D Taht
-# GPLv2
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+#       Copyright (C) 2012-4 Michael D. Taht, Toke Høiland-Jørgensen, Sebastian Moeller
 
 # Compared to the complexity that debloat had become
 # this cleanly shows a means of going from diffserv marking
@@ -36,10 +39,10 @@ ipt -t mangle -A QOS_MARK_${IFACE} -m tos  --tos Minimize-Delay -j MARK --set-ma
 
 if [ "$SQUASH_DSCP" = "1" ]
 then
-sqm_logger "Squashing differentiad services code points (DSCP) from ingress."
+sqm_logger "Squashing differentiated services code points (DSCP) from ingress."
 ipt -t mangle -I PREROUTING -i $IFACE -m dscp ! --dscp 0 -j DSCP --set-dscp-class be
 else
-sqm_logger "Keeping differentiad services code points (DSCP) from ingress."
+sqm_logger "Keeping differentiated services code points (DSCP) from ingress."
 ipt -t mangle -A PREROUTING -i $IFACE -m mark --mark 0x00 -g QOS_MARK_${IFACE} 
 fi
 
index 4a47d4676a1e54cd736c1d82881d60d503b14535..2e84fab9ee8f7c3e0d7bab458fa791c1e3ee8d45 100755 (executable)
@@ -3,8 +3,11 @@
 # A 3 bin tc_codel and ipv6 enabled shaping script for
 # ethernet gateways
 
-# Copyright (C) 2012 Michael D Taht
-# GPLv2
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+#       Copyright (C) 2012-4 Michael D. Taht, Toke Høiland-Jørgensen, Sebastian Moeller
 
 # Compared to the complexity that debloat had become
 # this cleanly shows a means of going from diffserv marking
index e82bcff5c35dfc93298e4bc145af539c4e8a664f..f06c25211ea544550727f1e270785bba90b6fad7 100755 (executable)
@@ -3,8 +3,11 @@
 # A 1 bin tc_codel and ipv6 enabled shaping script for
 # ethernet gateways. This is nearly the simplest possible
 
-# Copyright (C) 2013 Michael D Taht
-# GPLv2
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+#       Copyright (C) 2012-4 Michael D. Taht, Toke Høiland-Jørgensen, Sebastian Moeller
 
 . /usr/lib/sqm/functions.sh
 sqm_logger "Starting simplest.qos"
index f7323e8b926e585fa9fc85752299d0c0f002e05d..29e213b69d025462313a9472f01743e080b72d5a 100755 (executable)
@@ -1,10 +1,17 @@
 #!/bin/sh
 
-. /usr/lib/sqm/functions.sh
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+#       Copyright (C) 2012-4 Michael D. Taht, Toke Høiland-Jørgensen, Sebastian Moeller
 
 # allow passing in the IFACE as first command line argument
 [ ! -z ${1} ] && IFACE=${1}
-sqm_logger "${0} Stopping ${IFACE}"
+# now IFACE is defined so we can source functions.sh without creating a spurious ifb4ge00
+. /usr/lib/sqm/functions.sh
+# sqm_logger is defined in functions.sh...
+sqm_logger "${0}: Stopping ${IFACE}"
 
 # make sure to only delete the ifb associated with the current interface
 CUR_IFB=$( get_ifb_associated_with_if ${IFACE} )
@@ -13,7 +20,7 @@ sqm_stop() {
        tc qdisc del dev $IFACE ingress 2> /dev/null
        tc qdisc del dev $IFACE root 2> /dev/null
        [ ! -z "$CUR_IFB" ] && tc qdisc del dev $CUR_IFB root 2> /dev/null
-        [ ! -z "$CUR_IFB" ] && sqm_logger "${CUR_IFB} shaper deleted"
+        [ ! -z "$CUR_IFB" ] && sqm_logger "${0}: ${CUR_IFB} shaper deleted"
 }
 
 ipt_stop() {
@@ -30,6 +37,6 @@ sqm_stop
 ipt_stop
 [ ! -z "$CUR_IFB" ] && ifconfig ${CUR_IFB} down
 [ ! -z "$CUR_IFB" ] && ip link delete ${CUR_IFB} type ifb
-[ ! -z "$CUR_IFB" ] && sqm_logger "${CUR_IFB} interface deleted"
+[ ! -z "$CUR_IFB" ] && sqm_logger "${0}: ${CUR_IFB} interface deleted"
 
 exit 0
\ No newline at end of file
git clone https://git.99rst.org/PROJECT