Advertisement
Guest User

Untitled

a guest
Dec 8th, 2015
623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Wonder Shaper
  4.  
  5. function show_help {
  6. echo "Wonder Shaper 1.2.1"
  7. echo
  8. echo "Usage: $0 [device] clean|[upload speed in Kb/s] [download speed in Kb/s]"
  9. echo "Example: $0 eth0 20 500"
  10. echo
  11. echo "https://bugzilla.redhat.com/enter_bug.cgi?product=Fedora&component=wondershaper"
  12. exit
  13. }
  14.  
  15. if [ $# -eq 0 ]; then
  16. show_help;
  17. fi
  18.  
  19. if [ $# -eq 1 ]; then
  20. tc -s qdisc ls dev $1
  21. tc -s class ls dev $1
  22. exit
  23. fi
  24.  
  25. if [ $# -eq 2 ]; then
  26. tc qdisc del dev $2 root 2> /dev/null > /dev/null
  27. tc qdisc del dev $2 ingress 2> /dev/null > /dev/null
  28. echo Wondershaper queues have been cleared.
  29. exit
  30. fi
  31.  
  32. if [ $# -ne 3 ]; then
  33. show_help;
  34. fi
  35.  
  36. # Set the following values to somewhat less than your actual download
  37. # and uplink speed. In kilobits. Also set the device that is to be shaped.
  38. DOWNLINK=$3
  39. UPLINK=$2
  40. DEV=$1
  41.  
  42. # low priority OUTGOING traffic - you can leave this blank if you want
  43. # low priority source netmasks
  44. NOPRIOHOSTSRC=
  45.  
  46. # low priority destination netmasks
  47. NOPRIOHOSTDST=
  48.  
  49. # low priority source ports
  50. NOPRIOPORTSRC=
  51.  
  52. # low priority destination ports
  53. NOPRIOPORTDST=
  54.  
  55. #########################################################
  56.  
  57. # clean existing down- and uplink qdiscs, hide errors
  58. tc qdisc del dev $DEV root 2> /dev/null > /dev/null
  59. tc qdisc del dev $DEV ingress 2> /dev/null > /dev/null
  60.  
  61. if [ "$1" = "stop" ]
  62. then
  63. exit
  64. fi
  65.  
  66. ###### uplink
  67.  
  68. # install root CBQ
  69.  
  70. tc qdisc add dev $DEV root handle 1: cbq avpkt 1000 bandwidth 1000mbit
  71.  
  72. # shape everything at $UPLINK speed - this prevents huge queues in your
  73. # DSL modem which destroy latency:
  74. # main class
  75.  
  76. tc class add dev $DEV parent 1: classid 1:1 cbq rate ${UPLINK}kbit \
  77. allot 1500 prio 5 bounded isolated
  78.  
  79. # high prio class 1:10:
  80.  
  81. tc class add dev $DEV parent 1:1 classid 1:10 cbq rate ${UPLINK}kbit \
  82. allot 1600 prio 1 avpkt 1000
  83.  
  84. # bulk and default class 1:20 - gets slightly less traffic,
  85. # and a lower priority:
  86.  
  87. tc class add dev $DEV parent 1:1 classid 1:20 cbq rate $[9*$UPLINK/10]kbit \
  88. allot 1600 prio 2 avpkt 1000
  89.  
  90. # 'traffic we hate'
  91.  
  92. tc class add dev $DEV parent 1:1 classid 1:30 cbq rate $[8*$UPLINK/10]kbit \
  93. allot 1600 prio 2 avpkt 1000
  94.  
  95. # all get Stochastic Fairness:
  96. tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10
  97. tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10
  98. tc qdisc add dev $DEV parent 1:30 handle 30: sfq perturb 10
  99.  
  100. # start filters
  101. # TOS Minimum Delay (ssh, NOT scp) in 1:10:
  102. tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
  103. match ip tos 0x10 0xff flowid 1:10
  104.  
  105. # ICMP (ip protocol 1) in the interactive class 1:10 so we
  106. # can do measurements & impress our friends:
  107. tc filter add dev $DEV parent 1:0 protocol ip prio 11 u32 \
  108. match ip protocol 1 0xff flowid 1:10
  109.  
  110. tc filter add dev $DEV parent 1:0 protocol ip prio 10 u32 \
  111. match ip protocol 17 0xff \
  112. match ip sport 4666 0xffff \
  113. flowid 1:30
  114.  
  115. # prioritize small packets (<64 bytes)
  116.  
  117. tc filter add dev $DEV parent 1: protocol ip prio 12 u32 \
  118. match ip protocol 6 0xff \
  119. match u8 0x05 0x0f at 0 \
  120. match u16 0x0000 0xffc0 at 2 \
  121. flowid 1:10
  122.  
  123.  
  124. # some traffic however suffers a worse fate
  125. for a in $NOPRIOPORTDST
  126. do
  127. tc filter add dev $DEV parent 1: protocol ip prio 14 u32 \
  128. match ip dport $a 0xffff flowid 1:30
  129. done
  130.  
  131. for a in $NOPRIOPORTSRC
  132. do
  133. tc filter add dev $DEV parent 1: protocol ip prio 15 u32 \
  134. match ip sport $a 0xffff flowid 1:30
  135. done
  136.  
  137. for a in $NOPRIOHOSTSRC
  138. do
  139. tc filter add dev $DEV parent 1: protocol ip prio 16 u32 \
  140. match ip src $a flowid 1:30
  141. done
  142.  
  143. for a in $NOPRIOHOSTDST
  144. do
  145. tc filter add dev $DEV parent 1: protocol ip prio 17 u32 \
  146. match ip dst $a flowid 1:30
  147. done
  148.  
  149. # rest is 'non-interactive' ie 'bulk' and ends up in 1:20
  150.  
  151. tc filter add dev $DEV parent 1: protocol ip prio 18 u32 \
  152. match ip dst 0.0.0.0/0 flowid 1:20
  153.  
  154.  
  155. ########## downlink #############
  156. # slow downloads down to somewhat less than the real speed to prevent
  157. # queuing at our ISP. Tune to see how high you can set it.
  158. # ISPs tend to have *huge* queues to make sure big downloads are fast
  159. #
  160. # attach ingress policer:
  161.  
  162. tc qdisc add dev $DEV handle ffff: ingress
  163.  
  164. # filter *everything* to it (0.0.0.0/0), drop everything that's
  165. # coming in too fast:
  166.  
  167. tc filter add dev $DEV parent ffff: protocol ip prio 50 u32 match ip src \
  168. 0.0.0.0/0 police rate ${DOWNLINK}kbit burst 10k drop flowid :1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement