Advertisement
Guest User

tc bandwidth shaping using port range

a guest
Dec 9th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.39 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. TC=/sbin/tc
  4. IF=wlan0
  5. IP=10.0.0.2
  6. DOWN=5mbit
  7. UP=4kbps
  8. U32="$TC filter add dev $IF protocol ip parent 1:0 prio 1 u32"
  9.  
  10.  
  11. start() {
  12.  
  13. $TC qdisc add dev $IF root handle 1: htb default 30
  14. $TC class add dev $IF parent 1: classid 1:1 htb rate $DOWN
  15. $TC class add dev $IF parent 1: classid 1:2 htb rate $UP
  16. $U32 match ip dst $IP/32 flowid 1:1
  17. $U32 match ip src $IP/32 flowid 1:2
  18. $U32 match ip protocol 17 0xff flowid 1:2
  19.  
  20. # Source Port Range
  21. $U32 match ip sport 27960 0xfff8 flowid 1:2
  22. $U32 match ip sport 27968 0xffe0 flowid 1:2
  23. $U32 match ip sport 28000 0xffff flowid 1:2
  24.  
  25. # Destination Port Range
  26. $U32 match ip dport 27960 0xfff8 flowid 1:2
  27. $U32 match ip dport 27968 0xffe0 flowid 1:2
  28. $U32 match ip dport 28000 0xffff flowid 1:2
  29.  
  30. }
  31.  
  32. stop() {
  33.  
  34.     $TC qdisc del dev $IF root
  35.  
  36. }
  37.  
  38. restart() {
  39.  
  40.     stop
  41.     sleep 1
  42.     start
  43.  
  44. }
  45.  
  46. show() {
  47.  
  48.     $TC -s qdisc ls dev $IF
  49.  
  50. }
  51.  
  52. case "$1" in
  53.  
  54.   start)
  55.  
  56.     echo -n "Starting bandwidth shaping: "
  57.     start
  58.     echo "done"
  59.     ;;
  60.  
  61.   stop)
  62.  
  63.     echo -n "Stopping bandwidth shaping: "
  64.     stop
  65.     echo "done"
  66.     ;;
  67.  
  68.   restart)
  69.  
  70.     echo -n "Restarting bandwidth shaping: "
  71.     restart
  72.     echo "done"
  73.     ;;
  74.  
  75.   show)
  76.  
  77.     echo "Bandwidth shaping status for $IF:"
  78.     show
  79.     echo ""
  80.     ;;
  81.  
  82.   *)
  83.  
  84.     pwd=$(pwd)
  85.     echo "Usage: shaper {start|stop|restart|show}"
  86.     ;;
  87.  
  88. esac
  89.  
  90. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement