de linuxmanr4, 2 años han pasado desde su publicación, escrito en Bash.
Insertar vínculo
  1. #!/bin/bash
  2. #
  3. #   IPCop very, very simple traffic shaper (limiter) for 1 device
  4. #
  5. # This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
  6. # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  7. #  
  8. # Copyright (c) 2007-2010 weizen_42
  9. #   based on ideas and documentation from:
  10. #     LARTC HowTo http://lartc.org/howto/index.html
  11. #     HTB Manual  http://luxik.cdi.cz/~devik/qos/htb/manual/userg.htm
  12. #
  13. # Change device, IP, max- and limitrate to suit your needs
  14. #
  15. # v1.0    initial release
  16. # v2.0    IPCop v2
  17. #
  18.  
  19.  
  20. TC=/sbin/tc
  21.  
  22. # read IPCop variables
  23. eval $(/usr/local/bin/readhash /var/ipcop/ethernet/settings)
  24. if [ -e "/var/ipcop/red/iface" ]; then
  25.     REAL_RED=`cat /var/ipcop/red/iface`
  26. fi
  27.  
  28. # which device to shape
  29. DEV=$RED_1_DEV
  30.  
  31. # limit IP 192.168.1.2, IPrange 192.168.1.0/24 or complete device 0.0.0.0/0
  32. IP=192.168.0.0/24
  33.  
  34. # from IPCop to IP/network
  35. DOWN_MAX=100mbit
  36. DOWN_LIMIT=2mbit
  37.  
  38. # from IP/network to IPCop
  39. UP_MAX=100mbit
  40. UP_LIMIT=2mbit
  41.  
  42. # See how we were called.
  43. case "$1" in
  44.   status)
  45.     echo -e "\\033[1;32m##### Queues on dev: $DEV \\033[0m"
  46.     $TC -s qdisc show dev $DEV
  47.     echo -e "\\033[1;32m\r##### Classes on dev: $DEV \\033[0m"
  48.     $TC -s class show dev $DEV
  49.     echo -e "\\033[1;32m##### Filters on dev: $DEV \\033[0m"
  50.     $TC -s filter show dev $DEV
  51.     ;;
  52.   start)
  53.     echo -e "\\033[1;32mStarting simple shaper on dev: $DEV \\033[0m"
  54.  
  55.     # qdisc htb, default class 1:99
  56.     $TC qdisc add dev $DEV root handle 1: htb default 99
  57.     # add root class with max rate and default class with max rate
  58.     $TC class add dev $DEV parent 1: classid 1:1 htb rate $DOWN_MAX
  59.     $TC class add dev $DEV parent 1:1 classid 1:99 htb rate $DOWN_MAX ceil $DOWN_MAX
  60.     # add rate and ceil limited class 1:10
  61.     $TC class add dev $DEV parent 1:1 classid 1:10 htb rate $DOWN_LIMIT ceil $DOWN_LIMIT
  62.     # match dst IP to 1:10
  63.     $TC filter add dev $DEV protocol ip parent 1:0 prio 1 u32 match ip dst $IP flowid 1:10
  64.  
  65.     # this might need some more work :-/
  66.     $TC qdisc add dev $DEV handle ffff: ingress
  67.     $TC filter add dev $DEV parent ffff: protocol ip prio 50 u32 match ip src $IP police rate $UP_LIMIT burst 10k drop flowid :1
  68.     ;;
  69.   stop)
  70.     echo -e "\\033[1;32mStopping simple shaper on dev: $DEV \\033[0m"
  71.     # clean existing down- and uplink qdiscs, hide errors
  72.     $TC qdisc del dev $DEV root    2> /dev/null > /dev/null
  73.     $TC qdisc del dev $DEV ingress 2> /dev/null > /dev/null
  74.     ;;
  75.   restart)
  76.     $0 stop
  77.     sleep 1
  78.     $0 start
  79.     ;;
  80.   *)
  81.     echo "Usage: $0 {start|stop|restart|status}"
  82.     exit 1
  83.     ;;
  84. esac
  85.  
  86. exit 0