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.

84 lines
3.0 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-4 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. $TC qdisc add dev $IFACE root handle 1: `get_stab_string` htb default 10
  16. $TC class add dev $IFACE parent 1: classid 1:1 htb $LQ rate ${UPLINK}kbit ceil ${UPLINK}kbit `get_htb_adsll_string`
  17. $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`
  18. $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}
  19. }
  20. ingress() {
  21. sqm_logger "ingress"
  22. $TC qdisc del dev $IFACE handle ffff: ingress 2>/dev/null
  23. $TC qdisc add dev $IFACE handle ffff: ingress
  24. LQ="quantum `get_mtu $IFACE ${DOWNLINK}`"
  25. $TC qdisc del dev $DEV root 2>/dev/null
  26. $TC qdisc add dev $DEV root handle 1: `get_stab_string` htb default 10
  27. $TC class add dev $DEV parent 1: classid 1:1 htb $LQ rate ${DOWNLINK}kbit ceil ${DOWNLINK}kbit `get_htb_adsll_string`
  28. $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`
  29. # FIXME: I'd prefer to use a pre-nat filter but we need to detect if nat is on this interface
  30. # AND we need to permute by a random number which we can't do from userspace filters
  31. # Most high rate flows are REALLY close. This stomps on those harder, but hurts on high rate long distance
  32. #$TC qdisc add dev $DEV parent 1:10 handle 110: $QDISC limit $LIMIT $ECN interval 20ms target 3ms `get_flows ${DOWNLINK}`
  33. $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}
  34. ifconfig $DEV up
  35. # redirect all IP packets arriving in $IFACE to ifb0
  36. $TC filter add dev $IFACE parent ffff: protocol all prio 10 u32 \
  37. match u32 0 0 flowid 1:1 action mirred egress redirect dev $DEV
  38. }
  39. do_modules
  40. if [ "$UPLINK" -ne 0 ];
  41. then
  42. egress
  43. sqm_logger "egress shaping activated"
  44. else
  45. sqm_logger "egress shaping deactivated"
  46. tc qdisc del dev $IFACE root 2> /dev/null
  47. fi
  48. if [ "$DOWNLINK" -ne 0 ];
  49. then
  50. ingress
  51. sqm_logger "ingress shaping activated"
  52. else
  53. sqm_logger "ingress shaping deactivated"
  54. tc qdisc del dev $DEV root 2> /dev/null
  55. tc qdisc del dev $IFACE ingress 2> /dev/null
  56. fi
  57. # References:
  58. # This alternate shaper attempts to go for 1/u performance in a clever way
  59. # http://git.coverfire.com/?p=linux-qos-scripts.git;a=blob;f=src-3tos.sh;hb=HEAD
  60. # Comments
  61. # This does the right thing with ipv6 traffic.
  62. # Flaws
  63. # Many!