Browse Source

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>
lilik-openwrt-22.03
Hannu Nyman 10 years ago
parent
commit
16d96ec143
7 changed files with 46 additions and 62 deletions
  1. +1
    -1
      net/sqm-scripts/Makefile
  2. +6
    -45
      net/sqm-scripts/files/usr/lib/sqm/functions.sh
  3. +11
    -4
      net/sqm-scripts/files/usr/lib/sqm/run.sh
  4. +7
    -4
      net/sqm-scripts/files/usr/lib/sqm/simple.qos
  5. +5
    -2
      net/sqm-scripts/files/usr/lib/sqm/simple_pppoe.qos
  6. +5
    -2
      net/sqm-scripts/files/usr/lib/sqm/simplest.qos
  7. +11
    -4
      net/sqm-scripts/files/usr/lib/sqm/stop.sh

+ 1
- 1
net/sqm-scripts/Makefile View 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


+ 6
- 45
net/sqm-scripts/files/usr/lib/sqm/functions.sh View 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" ];


+ 11
- 4
net/sqm-scripts/files/usr/lib/sqm/run.sh View File

@ -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}; }
}


+ 7
- 4
net/sqm-scripts/files/usr/lib/sqm/simple.qos View File

@ -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


+ 5
- 2
net/sqm-scripts/files/usr/lib/sqm/simple_pppoe.qos View File

@ -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


+ 5
- 2
net/sqm-scripts/files/usr/lib/sqm/simplest.qos View File

@ -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"


+ 11
- 4
net/sqm-scripts/files/usr/lib/sqm/stop.sh View File

@ -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

Loading…
Cancel
Save