You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.8 KiB

  1. #!/bin/sh
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License version 2 as
  4. # published by the Free Software Foundation.
  5. #
  6. # Copyright (C) 2012-4 Michael D. Taht, Toke Høiland-Jørgensen, Sebastian Moeller
  7. . /lib/functions.sh
  8. STOP=$1
  9. ACTIVE_STATE_PREFIX="SQM_active_on_"
  10. ACTIVE_STATE_FILE_DIR="/var/run/SQM"
  11. mkdir -p ${ACTIVE_STATE_FILE_DIR}
  12. # the current uci config file does not necessarily contain sections for all interfaces with active
  13. # SQM instances, so use the ACTIVE_STATE_FILES to detect the interfaces on which to stop SQM.
  14. # Currently the .qos scripts start with stopping any existing traffic shaping so this should not
  15. # effectively change anything...
  16. PROTO_STATE_FILE_LIST=$( ls ${ACTIVE_STATE_FILE_DIR}/${ACTIVE_STATE_PREFIX}* 2> /dev/null )
  17. for STATE_FILE in ${PROTO_STATE_FILE_LIST} ; do
  18. if [ -f ${STATE_FILE} ] ;
  19. then
  20. STATE_FILE_BASE_NAME=$( basename ${STATE_FILE} )
  21. CURRENT_INTERFACE=${STATE_FILE_BASE_NAME:${#ACTIVE_STATE_PREFIX}:$(( ${#STATE_FILE_BASE_NAME} - ${#ACTIVE_STATE_PREFIX} ))}
  22. logger -t SQM -s "${0} Stopping SQM on interface: ${CURRENT_INTERFACE}"
  23. /usr/lib/sqm/stop.sh ${CURRENT_INTERFACE}
  24. rm ${STATE_FILE} # well, we stop it so it is not running anymore and hence no active state file needed...
  25. fi
  26. done
  27. config_load sqm
  28. run_simple_qos() {
  29. local section="$1"
  30. export IFACE=$(config_get "$section" interface)
  31. ACTIVE_STATE_FILE_FQN="${ACTIVE_STATE_FILE_DIR}/${ACTIVE_STATE_PREFIX}${IFACE}" # this marks interfaces as active with SQM
  32. [ -f "${ACTIVE_STATE_FILE_FQN}" ] && logger -t SQM -s "Uh, oh, ${ACTIVE_STATE_FILE_FQN} should already be stopped." # Not supposed to happen
  33. if [ $(config_get "$section" enabled) -ne 1 ];
  34. then
  35. if [ -f "${ACTIVE_STATE_FILE_FQN}" ];
  36. then
  37. # this should not be possible, delete after testing
  38. local SECTION_STOP="stop" # it seems the user just de-selected enable, so stop the active SQM
  39. else
  40. logger -t SQM -s "${0} SQM for interface ${IFACE} is not enabled, skipping over..."
  41. return 0 # since SQM is not active on the current interface nothing to do here
  42. fi
  43. fi
  44. export UPLINK=$(config_get "$section" upload)
  45. export DOWNLINK=$(config_get "$section" download)
  46. export LLAM=$(config_get "$section" linklayer_adaptation_mechanism)
  47. export LINKLAYER=$(config_get "$section" linklayer)
  48. export OVERHEAD=$(config_get "$section" overhead)
  49. export STAB_MTU=$(config_get "$section" tcMTU)
  50. export STAB_TSIZE=$(config_get "$section" tcTSIZE)
  51. export STAB_MPU=$(config_get "$section" tcMPU)
  52. export ILIMIT=$(config_get "$section" ilimit)
  53. export ELIMIT=$(config_get "$section" elimit)
  54. export ITARGET=$(config_get "$section" itarget)
  55. export ETARGET=$(config_get "$section" etarget)
  56. export IECN=$(config_get "$section" ingress_ecn)
  57. export EECN=$(config_get "$section" egress_ecn)
  58. export IQDISC_OPTS=$(config_get "$section" iqdisc_opts)
  59. export EQDISC_OPTS=$(config_get "$section" eqdisc_opts)
  60. export TARGET=$(config_get "$section" target)
  61. export SQUASH_DSCP=$(config_get "$section" squash_dscp)
  62. export SQUASH_INGRESS=$(config_get "$section" squash_ingress)
  63. export QDISC=$(config_get "$section" qdisc)
  64. export SCRIPT=/usr/lib/sqm/$(config_get "$section" script)
  65. # # there should be nothing left to stop, so just avoid calling the script
  66. if [ "$STOP" == "stop" -o "$SECTION_STOP" == "stop" ];
  67. then
  68. # /usr/lib/sqm/stop.sh
  69. # [ -f ${ACTIVE_STATE_FILE_FQN} ] && rm ${ACTIVE_STATE_FILE_FQN} # conditional to avoid errors ACTIVE_STATE_FILE_FQN does not exist anymore
  70. # $(config_set "$section" enabled 0) # this does not save to the config file only to the loaded memory representation
  71. logger -t SQM -s "${0} SQM qdiscs on ${IFACE} removed"
  72. return 0
  73. fi
  74. logger -t SQM -s "${0} Queue Setup Script: ${SCRIPT}"
  75. [ -x "$SCRIPT" ] && { $SCRIPT ; touch ${ACTIVE_STATE_FILE_FQN}; }
  76. }
  77. config_foreach run_simple_qos