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.

98 lines
3.4 KiB

  1. #!/bin/sh
  2. # Cero3 Simple Shaper
  3. # A 1 bin tc_codel and ipv6 enabled shaping script for
  4. # ethernet gateways. This is nearly the simplest possible
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License version 2 as
  7. # published by the Free Software Foundation.
  8. #
  9. # Copyright (C) 2012-5 Michael D. Taht, Toke Høiland-Jørgensen, Sebastian Moeller
  10. . /usr/lib/sqm/functions.sh
  11. sqm_logger "Starting simplest.qos"
  12. egress() {
  13. LQ="quantum `get_mtu $IFACE ${UPLINK}`"
  14. $TC qdisc del dev $IFACE root 2>/dev/null
  15. case $QDISC in
  16. cake*)
  17. $TC qdisc add dev $IFACE root `get_stab_string` cake bandwidth ${UPLINK}kbit besteffort `get_cake_lla_string` ${EQDISC_OPTS}
  18. ;;
  19. *)
  20. $TC qdisc add dev $IFACE root handle 1: `get_stab_string` htb default 10
  21. $TC class add dev $IFACE parent 1: classid 1:1 htb $LQ rate ${UPLINK}kbit ceil ${UPLINK}kbit `get_htb_adsll_string`
  22. $TC class add dev $IFACE parent 1:1 classid 1:10 htb $LQ rate ${UPLINK}kbit ceil ${UPLINK}kbit prio 0 `get_htb_adsll_string`
  23. $TC qdisc add dev $IFACE parent 1:10 handle 110: $QDISC `get_limit ${ELIMIT}` `get_target "${ETARGET}" ${UPLINK}` `get_ecn ${EECN}` `get_flows ${UPLINK}` ${EQDISC_OPTS}
  24. ;;
  25. esac
  26. }
  27. ingress() {
  28. sqm_logger "ingress"
  29. $TC qdisc del dev $IFACE handle ffff: ingress 2>/dev/null
  30. $TC qdisc add dev $IFACE handle ffff: ingress
  31. LQ="quantum `get_mtu $IFACE ${DOWNLINK}`"
  32. $TC qdisc del dev $DEV root 2>/dev/null
  33. case $QDISC in
  34. cake*)
  35. $TC qdisc add dev $DEV root `get_stab_string` cake bandwidth ${DOWNLINK}kbit besteffort `get_cake_lla_string` ${IQDISC_OPTS}
  36. ;;
  37. *)
  38. $TC qdisc add dev $DEV root handle 1: `get_stab_string` htb default 10
  39. $TC class add dev $DEV parent 1: classid 1:1 htb $LQ rate ${DOWNLINK}kbit ceil ${DOWNLINK}kbit `get_htb_adsll_string`
  40. $TC class add dev $DEV parent 1:1 classid 1:10 htb $LQ rate ${DOWNLINK}kbit ceil ${DOWNLINK}kbit prio 0 `get_htb_adsll_string`
  41. # FIXME: I'd prefer to use a pre-nat filter but we need to detect if nat is on this interface
  42. # AND we need to permute by a random number which we can't do from userspace filters
  43. # Most high rate flows are REALLY close. This stomps on those harder, but hurts on high rate long distance
  44. #$TC qdisc add dev $DEV parent 1:10 handle 110: $QDISC limit $LIMIT $ECN interval 20ms target 3ms `get_flows ${DOWNLINK}`
  45. $TC qdisc add dev $DEV parent 1:10 handle 110: $QDISC `get_limit ${ILIMIT}` `get_target "${ITARGET}" ${DOWNLINK}` `get_ecn ${IECN}` `get_flows ${DOWNLINK}` ${IQDISC_OPTS}
  46. ;;
  47. esac
  48. ifconfig $DEV up
  49. # redirect all IP packets arriving in $IFACE to ifb0
  50. $TC filter add dev $IFACE parent ffff: protocol all prio 10 u32 \
  51. match u32 0 0 flowid 1:1 action mirred egress redirect dev $DEV
  52. }
  53. do_modules
  54. if [ "$UPLINK" -ne 0 ];
  55. then
  56. egress
  57. sqm_logger "egress shaping activated"
  58. else
  59. sqm_logger "egress shaping deactivated"
  60. tc qdisc del dev $IFACE root 2> /dev/null
  61. fi
  62. if [ "$DOWNLINK" -ne 0 ];
  63. then
  64. ingress
  65. sqm_logger "ingress shaping activated"
  66. else
  67. sqm_logger "ingress shaping deactivated"
  68. tc qdisc del dev $DEV root 2> /dev/null
  69. tc qdisc del dev $IFACE ingress 2> /dev/null
  70. fi
  71. # References:
  72. # This alternate shaper attempts to go for 1/u performance in a clever way
  73. # http://git.coverfire.com/?p=linux-qos-scripts.git;a=blob;f=src-3tos.sh;hb=HEAD
  74. # Comments
  75. # This does the right thing with ipv6 traffic.
  76. # Flaws
  77. # Many!