Pārlūkot izejas kodu

sqm-scripts: Fix a minor bug, add copyrights, improve logging

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 <hannu.nyman@iki.fi>
Hannu Nyman 10 gadus atpakaļ
vecāks
revīzija
16d96ec143

+ 1
- 1
net/sqm-scripts/Makefile Parādīt failu

@@ -8,7 +8,7 @@
8 8
 include $(TOPDIR)/rules.mk
9 9
 
10 10
 PKG_NAME:=sqm-scripts
11
-PKG_VERSION:=6
11
+PKG_VERSION:=7
12 12
 PKG_RELEASE:=1
13 13
 PKG_LICENSE:=GPLv2
14 14
 

+ 6
- 45
net/sqm-scripts/files/usr/lib/sqm/functions.sh Parādīt failu

@@ -1,3 +1,9 @@
1
+# This program is free software; you can redistribute it and/or modify
2
+# it under the terms of the GNU General Public License version 2 as
3
+# published by the Free Software Foundation.
4
+#
5
+#       Copyright (C) 2012-4 Michael D. Taht, Toke Høiland-Jørgensen, Sebastian Moeller
6
+
1 7
 #improve the logread output
2 8
 sqm_logger() {
3 9
     logger -t SQM -s ${1}
@@ -74,42 +80,6 @@ get_ifb_associated_with_if() {
74 80
     echo ${CUR_IFB}
75 81
 }
76 82
 
77
-# what is the lowest-index currently not used ifb device
78
-#sm: hopefully this is not required any longer, and can be deleted after a bit more testing...
79
-get_lowest_unused_ifb() {
80
-    LOWEST_FREE_IFB=
81
-    # this just returns a list of currently existing IFBs, these need not be associated with any interface
82
-    CUR_UP_IFBS=$( ifconfig | grep -o -e ifb'[[:digit:]]\+' )
83
-    # the possible IFBs (N in insmod ifb numifbs=N)
84
-    here=$( pwd )
85
-    cd /sys/devices/virtual/net/
86
-    CUR_ALLOWED_IFBS=$( ls -d ifb* )
87
-    sqm_logger "Currently allowed IFBs: ${CUR_ALLOWED_IFBS}"
88
-    cd ${here}
89
-    # this is the sorted list of the active ifbs
90
-    # note for 3.10.32 unused and even down IFBs linger on in the tc output, so take $CUR_UP_IFBS instead
91
-    # a better test might be to check for each allowed IFB whether it is in use
92
-    # but the only way I figured out doing this means interating over all interfaces and that sounds costly
93
-    # so instead we rely on stop.sh actually calling ifconfig ${LAST_USED_IFB} down
94
-    CUR_USED_IFBS=$( tc -d qdisc | grep -o -e ifb'[[:digit:]]\+' | sort -u)
95
-    sqm_logger "Currently used IFBs: ${CUR_USED_IFBS}"
96
-    # now find the lowest index not in the sorted list
97
-    local CUR_IDX=0
98
-    while [ -z "$LOWEST_FREE_IFB" ]
99
-    do
100
-        #TMP=$( echo "${CUR_USED_IFBS}" | grep -o -e ifb${CUR_IDX} )
101
-        TMP=$( echo "${CUR_UP_IFBS}" | grep -o -e ifb${CUR_IDX} )
102
-        [ -z "$TMP" ] && LOWEST_FREE_IFB="ifb"${CUR_IDX}
103
-        CUR_IDX=$(( $CUR_IDX + 1 ))
104
-    done
105
-    # check whether the number is in the allowed range
106
-    LOWEST_FREE_IFB=$( echo "${CUR_ALLOWED_IFBS}" | grep -o -e ${LOWEST_FREE_IFB} )
107
-    [ -z "${LOWEST_FREE_IFB}" ] && sqm_logger "The IFB candidate ifb$(( ${CUR_IDX} - 1 )) is not in the range of allowed IFBs, bailing out..."
108
-    sqm_logger "selected ifb index: ${LOWEST_FREE_IFB}"
109
-    echo ${LOWEST_FREE_IFB}
110
-}
111
-
112
-# instead of playing around with indices just create a named IFB
113 83
 # ATTENTION, IFB names can only be 15 chararcters, so we chop of excessive characters at the start of the interface name 
114 84
 # if required
115 85
 create_new_ifb_for_if() {
@@ -134,8 +104,6 @@ get_ifb_for_if() {
134 104
     CUR_IF=$1
135 105
     # if an ifb is already associated return that
136 106
     CUR_IFB=$( get_ifb_associated_with_if ${CUR_IF} )
137
-    # otherwise find the lowest unused ifb device
138
-    #[ -z "$CUR_IFB" ] && CUR_IFB=$( get_lowest_unused_ifb )
139 107
     [ -z "$CUR_IFB" ] && CUR_IFB=$( create_new_ifb_for_if ${CUR_IF} )
140 108
     [ -z "$CUR_IFB" ] && sqm_logger "Could not find existing IFB for ${CUR_IF}, nor create a new IFB instead..."
141 109
     echo ${CUR_IFB}
@@ -145,13 +113,6 @@ get_ifb_for_if() {
145 113
 [ -z "$DEV" ] && DEV=$( get_ifb_for_if ${IFACE} )      # automagically get the right IFB device for the IFACE"
146 114
 
147 115
 
148
-
149
-#sqm_logger "iqdisc opts: ${iqdisc_opts}"
150
-#sqm_logger "eqdisc opts: ${eqdisc_opts}"
151
-
152
-#sqm_logger "LLAM: ${LLAM}"
153
-#sqm_logger "LINKLAYER: ${LINKLAYER}"
154
-
155 116
 get_htb_adsll_string() {
156 117
 	ADSLL=""
157 118
 	if [ "$LLAM" = "htb_private" -a "$LINKLAYER" != "none" ]; 

+ 11
- 4
net/sqm-scripts/files/usr/lib/sqm/run.sh Parādīt failu

@@ -1,5 +1,12 @@
1 1
 #!/bin/sh
2 2
 
3
+# This program is free software; you can redistribute it and/or modify
4
+# it under the terms of the GNU General Public License version 2 as
5
+# published by the Free Software Foundation.
6
+#
7
+#       Copyright (C) 2012-4 Michael D. Taht, Toke Høiland-Jørgensen, Sebastian Moeller
8
+
9
+
3 10
 . /lib/functions.sh
4 11
 
5 12
 STOP=$1
@@ -17,7 +24,7 @@ for STATE_FILE in ${PROTO_STATE_FILE_LIST} ; do
17 24
     then
18 25
 	STATE_FILE_BASE_NAME=$( basename ${STATE_FILE} )
19 26
 	CURRENT_INTERFACE=${STATE_FILE_BASE_NAME:${#ACTIVE_STATE_PREFIX}:$(( ${#STATE_FILE_BASE_NAME} - ${#ACTIVE_STATE_PREFIX} ))}        
20
-	logger -t SQM -s "Stopping SQM on interface: ${CURRENT_INTERFACE}"
27
+	logger -t SQM -s "${0} Stopping SQM on interface: ${CURRENT_INTERFACE}"
21 28
 	/usr/lib/sqm/stop.sh ${CURRENT_INTERFACE}
22 29
 	rm ${STATE_FILE}	# well, we stop it so it is not running anymore and hence no active state file needed...
23 30
     fi
@@ -38,7 +45,7 @@ run_simple_qos() {
38 45
 		# this should not be possible, delete after testing
39 46
 		local SECTION_STOP="stop"	# it seems the user just de-selected enable, so stop the active SQM
40 47
 	    else
41
-		logger -t SQM -s "SQM for interface ${IFACE} is not enabled, skipping over..."
48
+		logger -t SQM -s "${0} SQM for interface ${IFACE} is not enabled, skipping over..."
42 49
 		return 0	# since SQM is not active on the current interface nothing to do here
43 50
 	    fi
44 51
 	fi
@@ -72,10 +79,10 @@ run_simple_qos() {
72 79
 #	     /usr/lib/sqm/stop.sh
73 80
 #	     [ -f ${ACTIVE_STATE_FILE_FQN} ] && rm ${ACTIVE_STATE_FILE_FQN}	# conditional to avoid errors ACTIVE_STATE_FILE_FQN does not exist anymore
74 81
 #	     $(config_set "$section" enabled 0)	# this does not save to the config file only to the loaded memory representation
75
-#	     logger -t SQM -s "SQM qdiscs on ${IFACE} removed"
82
+	     logger -t SQM -s "${0} SQM qdiscs on ${IFACE} removed"
76 83
 	     return 0
77 84
 	fi
78
-	logger -t SQM -s "Queue Setup Script: ${SCRIPT}"
85
+	logger -t SQM -s "${0} Queue Setup Script: ${SCRIPT}"
79 86
 	[ -x "$SCRIPT" ] && { $SCRIPT ; touch ${ACTIVE_STATE_FILE_FQN}; }
80 87
 }
81 88
 

+ 7
- 4
net/sqm-scripts/files/usr/lib/sqm/simple.qos Parādīt failu

@@ -3,8 +3,11 @@
3 3
 # A 3 bin tc_codel and ipv6 enabled shaping script for
4 4
 # ethernet gateways
5 5
 
6
-# Copyright (C) 2012 Michael D Taht
7
-# GPLv2
6
+# This program is free software; you can redistribute it and/or modify
7
+# it under the terms of the GNU General Public License version 2 as
8
+# published by the Free Software Foundation.
9
+#
10
+#       Copyright (C) 2012-4 Michael D. Taht, Toke Høiland-Jørgensen, Sebastian Moeller
8 11
 
9 12
 # Compared to the complexity that debloat had become
10 13
 # 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
36 39
 
37 40
 if [ "$SQUASH_DSCP" = "1" ]
38 41
 then
39
-sqm_logger "Squashing differentiad services code points (DSCP) from ingress."
42
+sqm_logger "Squashing differentiated services code points (DSCP) from ingress."
40 43
 ipt -t mangle -I PREROUTING -i $IFACE -m dscp ! --dscp 0 -j DSCP --set-dscp-class be
41 44
 else
42
-sqm_logger "Keeping differentiad services code points (DSCP) from ingress."
45
+sqm_logger "Keeping differentiated services code points (DSCP) from ingress."
43 46
 ipt -t mangle -A PREROUTING -i $IFACE -m mark --mark 0x00 -g QOS_MARK_${IFACE} 
44 47
 fi
45 48
 

+ 5
- 2
net/sqm-scripts/files/usr/lib/sqm/simple_pppoe.qos Parādīt failu

@@ -3,8 +3,11 @@
3 3
 # A 3 bin tc_codel and ipv6 enabled shaping script for
4 4
 # ethernet gateways
5 5
 
6
-# Copyright (C) 2012 Michael D Taht
7
-# GPLv2
6
+# This program is free software; you can redistribute it and/or modify
7
+# it under the terms of the GNU General Public License version 2 as
8
+# published by the Free Software Foundation.
9
+#
10
+#       Copyright (C) 2012-4 Michael D. Taht, Toke Høiland-Jørgensen, Sebastian Moeller
8 11
 
9 12
 # Compared to the complexity that debloat had become
10 13
 # this cleanly shows a means of going from diffserv marking

+ 5
- 2
net/sqm-scripts/files/usr/lib/sqm/simplest.qos Parādīt failu

@@ -3,8 +3,11 @@
3 3
 # A 1 bin tc_codel and ipv6 enabled shaping script for
4 4
 # ethernet gateways. This is nearly the simplest possible
5 5
 
6
-# Copyright (C) 2013 Michael D Taht
7
-# GPLv2
6
+# This program is free software; you can redistribute it and/or modify
7
+# it under the terms of the GNU General Public License version 2 as
8
+# published by the Free Software Foundation.
9
+#
10
+#       Copyright (C) 2012-4 Michael D. Taht, Toke Høiland-Jørgensen, Sebastian Moeller
8 11
 
9 12
 . /usr/lib/sqm/functions.sh
10 13
 sqm_logger "Starting simplest.qos"

+ 11
- 4
net/sqm-scripts/files/usr/lib/sqm/stop.sh Parādīt failu

@@ -1,10 +1,17 @@
1 1
 #!/bin/sh
2 2
 
3
-. /usr/lib/sqm/functions.sh
3
+# This program is free software; you can redistribute it and/or modify
4
+# it under the terms of the GNU General Public License version 2 as
5
+# published by the Free Software Foundation.
6
+#
7
+#       Copyright (C) 2012-4 Michael D. Taht, Toke Høiland-Jørgensen, Sebastian Moeller
4 8
 
5 9
 # allow passing in the IFACE as first command line argument
6 10
 [ ! -z ${1} ] && IFACE=${1}
7
-sqm_logger "${0} Stopping ${IFACE}"
11
+# now IFACE is defined so we can source functions.sh without creating a spurious ifb4ge00
12
+. /usr/lib/sqm/functions.sh
13
+# sqm_logger is defined in functions.sh...
14
+sqm_logger "${0}: Stopping ${IFACE}"
8 15
 
9 16
 # make sure to only delete the ifb associated with the current interface
10 17
 CUR_IFB=$( get_ifb_associated_with_if ${IFACE} )
@@ -13,7 +20,7 @@ sqm_stop() {
13 20
 	tc qdisc del dev $IFACE ingress 2> /dev/null
14 21
 	tc qdisc del dev $IFACE root 2> /dev/null
15 22
 	[ ! -z "$CUR_IFB" ] && tc qdisc del dev $CUR_IFB root 2> /dev/null
16
-        [ ! -z "$CUR_IFB" ] && sqm_logger "${CUR_IFB} shaper deleted"
23
+        [ ! -z "$CUR_IFB" ] && sqm_logger "${0}: ${CUR_IFB} shaper deleted"
17 24
 }
18 25
 
19 26
 ipt_stop() {
@@ -30,6 +37,6 @@ sqm_stop
30 37
 ipt_stop
31 38
 [ ! -z "$CUR_IFB" ] && ifconfig ${CUR_IFB} down
32 39
 [ ! -z "$CUR_IFB" ] && ip link delete ${CUR_IFB} type ifb
33
-[ ! -z "$CUR_IFB" ] && sqm_logger "${CUR_IFB} interface deleted"
40
+[ ! -z "$CUR_IFB" ] && sqm_logger "${0}: ${CUR_IFB} interface deleted"
34 41
 
35 42
 exit 0