run.sh 5.1 KB

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