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.

123 lines
4.9 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=
  9. ACTIVE_STATE_PREFIX="SQM_active_on_"
  10. ACTIVE_STATE_FILE_DIR="/var/run/SQM"
  11. mkdir -p ${ACTIVE_STATE_FILE_DIR}
  12. PROTO_STATE_FILE_LIST=$( ls ${ACTIVE_STATE_FILE_DIR}/${ACTIVE_STATE_PREFIX}* 2> /dev/null )
  13. case ${1} in
  14. stop)
  15. logger -t SQM -s "run.sh stop"
  16. STOP=$1
  17. ;;
  18. interface)
  19. START_ON_IF=$2 # only process this interface
  20. logger -t SQM -s "Trying to re-start SQM on interface ${START_ON_IF}"
  21. # TODO if $2 is empty just bail...
  22. if [ -z ${START_ON_IF} ] ;
  23. then
  24. logger -t SQM -s "Interface name missing, nothing to do, bailing out"
  25. return 0
  26. fi
  27. # only try to restart the just hotplugged interface, so reduce the list of interfaces to stop to the specified one
  28. PROTO_STATE_FILE_LIST=${ACTIVE_STATE_FILE_DIR}/${ACTIVE_STATE_PREFIX}${START_ON_IF}
  29. ;;
  30. esac
  31. # the current uci config file does not necessarily contain sections for all interfaces with active
  32. # SQM instances, so use the ACTIVE_STATE_FILES to detect the interfaces on which to stop SQM.
  33. # Currently the .qos scripts start with stopping any existing traffic shaping so this should not
  34. # effectively change anything...
  35. for STATE_FILE in ${PROTO_STATE_FILE_LIST} ; do
  36. if [ -f ${STATE_FILE} ] ;
  37. then
  38. STATE_FILE_BASE_NAME=$( basename ${STATE_FILE} )
  39. CURRENT_INTERFACE=${STATE_FILE_BASE_NAME:${#ACTIVE_STATE_PREFIX}:$(( ${#STATE_FILE_BASE_NAME} - ${#ACTIVE_STATE_PREFIX} ))}
  40. logger -t SQM -s "${0} Stopping SQM on interface: ${CURRENT_INTERFACE}"
  41. /usr/lib/sqm/stop.sh ${CURRENT_INTERFACE}
  42. rm ${STATE_FILE} # well, we stop it so it is not running anymore and hence no active state file needed...
  43. fi
  44. done
  45. config_load sqm
  46. run_simple_qos() {
  47. local section="$1"
  48. export IFACE=$(config_get "$section" interface)
  49. # If called explicitly for one interface only , so ignore anything else
  50. [ -n "${START_ON_IF}" -a "$START_ON_IF" != "$IFACE" ] && return
  51. #logger -t SQM -s "marching on..."
  52. ACTIVE_STATE_FILE_FQN="${ACTIVE_STATE_FILE_DIR}/${ACTIVE_STATE_PREFIX}${IFACE}" # this marks interfaces as active with SQM
  53. [ -f "${ACTIVE_STATE_FILE_FQN}" ] && logger -t SQM -s "Uh, oh, ${ACTIVE_STATE_FILE_FQN} should already be stopped." # Not supposed to happen
  54. if [ $(config_get "$section" enabled) -ne 1 ];
  55. then
  56. if [ -f "${ACTIVE_STATE_FILE_FQN}" ];
  57. then
  58. # this should not be possible, delete after testing
  59. local SECTION_STOP="stop" # it seems the user just de-selected enable, so stop the active SQM
  60. else
  61. logger -t SQM -s "${0} SQM for interface ${IFACE} is not enabled, skipping over..."
  62. return 0 # since SQM is not active on the current interface nothing to do here
  63. fi
  64. fi
  65. export UPLINK=$(config_get "$section" upload)
  66. export DOWNLINK=$(config_get "$section" download)
  67. export LLAM=$(config_get "$section" linklayer_adaptation_mechanism)
  68. export LINKLAYER=$(config_get "$section" linklayer)
  69. export OVERHEAD=$(config_get "$section" overhead)
  70. export STAB_MTU=$(config_get "$section" tcMTU)
  71. export STAB_TSIZE=$(config_get "$section" tcTSIZE)
  72. export STAB_MPU=$(config_get "$section" tcMPU)
  73. export ILIMIT=$(config_get "$section" ilimit)
  74. export ELIMIT=$(config_get "$section" elimit)
  75. export ITARGET=$(config_get "$section" itarget)
  76. export ETARGET=$(config_get "$section" etarget)
  77. export IECN=$(config_get "$section" ingress_ecn)
  78. export EECN=$(config_get "$section" egress_ecn)
  79. export IQDISC_OPTS=$(config_get "$section" iqdisc_opts)
  80. export EQDISC_OPTS=$(config_get "$section" eqdisc_opts)
  81. export TARGET=$(config_get "$section" target)
  82. export SQUASH_DSCP=$(config_get "$section" squash_dscp)
  83. export SQUASH_INGRESS=$(config_get "$section" squash_ingress)
  84. export QDISC=$(config_get "$section" qdisc)
  85. export SCRIPT=/usr/lib/sqm/$(config_get "$section" script)
  86. # # there should be nothing left to stop, so just avoid calling the script
  87. if [ "$STOP" == "stop" -o "$SECTION_STOP" == "stop" ];
  88. then
  89. # /usr/lib/sqm/stop.sh
  90. # [ -f ${ACTIVE_STATE_FILE_FQN} ] && rm ${ACTIVE_STATE_FILE_FQN} # conditional to avoid errors ACTIVE_STATE_FILE_FQN does not exist anymore
  91. # $(config_set "$section" enabled 0) # this does not save to the config file only to the loaded memory representation
  92. logger -t SQM -s "${0} SQM qdiscs on ${IFACE} removed"
  93. return 0
  94. fi
  95. # in case of spurious hotplug events, try double check whether the interface is really up
  96. if [ ! -d /sys/class/net/${IFACE} ] ;
  97. then
  98. echo "${IFACE} does currently not exist, not even trying to start SQM on nothing." > /dev/kmsg
  99. logger -t SQM -s "${IFACE} does currently not exist, not even trying to start SQM on nothing."
  100. return 0
  101. fi
  102. logger -t SQM -s "${0} Queue Setup Script: ${SCRIPT}"
  103. [ -x "$SCRIPT" ] && { $SCRIPT ; touch ${ACTIVE_STATE_FILE_FQN}; }
  104. }
  105. config_foreach run_simple_qos