Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.09 KB | None | 0 0
  1. #!/bin/sh
  2. ##FreshJR_QOS v382.3 released 01/18/2017
  3. ##Script Tested on ASUS AC-68U, FW382.2, using Adaptive QOS with Manual Bandwidth Settings
  4. ##Modified version has bandwidth limiter enabled for LAN IP's 192.168.1.32 - 192.168.1.47
  5. ##Script Changes Unidentified Packet QOS destination from Default Traffic Container (Category7) into user definable (in WebUI) Other Traffic Container
  6. ##Script Changes Minimum Guarenteed Bandwidth per QOS category from 128Kbit into user defined percentages upload and download.
  7. ##Script supports custom QOS rules, to create rules copy applicable rule templates below, change filter parameters as desried, and then paste into custom rule start area.
  8. ## Included custom rule moves any TCP/UDP traffic on ports 500 & 4500 into VOIP traffic Container. (Wifi Calling)
  9. ## Included custom rule moves any TCP/UDP traffic on ports 16384 - 16415 into VOIP traffic Container. (Facetime)
  10.  
  11. #---------------------------------------------------------------------------------------------------------------
  12. # VALID FLOW ID'S FOR CUSTOM RULES
  13. # ${VOIP}, ${Gaming}, ${Others}, ${Web}, ${Streaming}, ${Downloads}, ${Default}
  14. #
  15. # VALID MARKS FOR IPTABLES
  16. # ${VOIP_mark}, ${Gaming_mark}, ${Others_mark}, ${Web_mark}, ${Streaming_mark}, ${Downloads_mark}, ${Default_mark}
  17. #
  18. # DOWNLOAD/INCOMMING TRAFFIC rule templates. See comments next to rule for details
  19. # ${tc} filter add dev br0 protocol all prio 1 u32 match ip dport 1234 0xffff flowid ${Downloads} #Template Rule 1 (All incomming traffic w/ LAN destination port 1234 goes to "Downloads" Traffic Container) (0xFFFF port mask defines only one port, if port range is desired see SNB forum post for guide)
  20. # ${tc} filter add dev br0 protocol all prio 1 u32 match ip dst 192.168.1.100/32 flowid ${VOIP} #Template Rule 2 (All incomming traffic w/ LAN destination ip 192.168.1.100 goes to "VOIP" Traffic Container)
  21. # ${tc} filter add dev br0 protocol all prio 1 u32 match u32 0xCCDDEEFF 0xffffffff at -16 flowid {VOIP} #Template Rule 3 (All incomming traffic w/ LAN destination MAC Address AA:BB:CC:DD:EE:FF goes to "VOIP" Traffic Container) **RULE USES LAST 8 MAC DIGITS
  22. # ${tc} filter add dev br0 protocol all prio 1 u32 match ip src 75.75.75.75/32 flowid ${Streaming} #Template Rule 4 (All incomming traffic w/ WAN server source ip 75.75.75.75 goes to "Streaming" Traffic Container) (/32 CIDR mask defines only one ip, if IP range is desired see SNB forum post for guide)
  23. #
  24. # UPLOAD/OUTOING TRAFFIC rule templates. See comments next to rule for details
  25. # ${tc} filter add dev eth0 protocol all prio 1 u32 match ip sport 1234 0xffff flowid ${Downloads} #Template Rule 1 (All outgoing traffic w/ LAN source port 1234 goes to "Downloads" Traffic Container) (0xFFFF port mask defines only one port, if port range is desired see SNB forum post for guide)
  26. # ${tc} filter add dev eth0 protocol all prio 1 u32 match ip src 192.168.1.100/32 flowid ${VOIP} #Template Rule 2 -->NOT WORKING/USE IPTABLES ALTERNATIVE<-- (All outgoing traffic w/ LAN source ip 192.168.1.123 goes to "VOIP" Traffic Container) **Reason this does not work is because you can only apply filters to egress traffic. The egress source IP of outgoing traffic is your Public WAN IP, not your Local LAN IP. So filter will not match on local IP.
  27. # ${tc} filter add dev eth0 protocol all prio 1 u32 match u16 0xEEFF 0xffff at -8 flowid {VOIP} #Template Rule 3 -->NOT WORKING/USE IPTABLES ALTERNATIVE<-- (All outgoing traffic w/ LAN source MAC Address AA:BB:CC:DD:EE:FF goes to "VOIP" Traffic Container) **RULE USES LAST 4 MAC DIGITS **Reason this does not work is because you can only apply filters to egress traffic. The egress source MAC ADDRESS of outgoing traffic is your Router MAC ADDRESS, not your client MAC ADDRESS. So filter will not match on local MAC ADDRESS.
  28. # ${tc} filter add dev eth0 protocol all prio 1 u32 match ip dst 75.75.75.75/32 flowid ${Streaming} #Template Rule 4 (All outgoing traffic w/ WAN server destination ip 75.75.75.75 goes to "Streaming" Traffic Container) (/32 CIDR mask defines only one ip, if IP range is desired see SNB forum post for guide)
  29. #
  30. # iptables -D POSTROUTING -t mangle -o eth0 -s 192.168.1.100/32 -j MARK --set-mark ${VOIP_mark} #Template Rule 2 WORKING ALTERNATIVE (Line1/2)
  31. # iptables -A POSTROUTING -t mangle -o eth0 -s 192.168.1.100/32 -j MARK --set-mark ${VOIP_mark} #Template Rule 2 WORKING ALTERNATIVE (Line1/2)
  32. # iptables -D POSTROUTING -t mangle -o eth0 -m mac --mac-source AA:BB:CC:DD:EE:FF -j MARK --set-mark ${VOIP_mark} #Template Rule 3 WORKING ALTERNATIVE (Line1/2)
  33. # iptables -A POSTROUTING -t mangle -o eth0 -m mac --mac-source AA:BB:CC:DD:EE:FF -j MARK --set-mark ${VOIP_mark} #Template Rule 3 WORKING ALTERNATIVE (Line1/2)
  34. #---------------------------------------------------------------------------------------------------------------
  35.  
  36. cru a FreshJR_QOS "0 0 * * * /jffs/scripts/FreshJR_QOS" ## schedules a daily check to see if modifcation is still persistant
  37.  
  38. Check_Lock () {
  39. if [ -f "/tmp/qos.lock" ] && [ -d "/proc/$(sed -n '2p' /tmp/qos.lock)" ]; then
  40. logger -st "Adaptive QOS" "[INFO] Lock File Detected from pid=$(sed -n '2p' /tmp/qos.lock) - Exiting Duplicate Instance"
  41. exit 1
  42. else
  43. echo "$@" > /tmp/qos.lock
  44. echo "$$" >> /tmp/qos.lock
  45. fi
  46. }
  47.  
  48. Check_Lock "$@"
  49.  
  50. if [ "$(nvram get qos_enable)" = "1" ] && [ "$(nvram get qos_type)" = "1" ] ; then
  51. logger "Adaptive QOS: Modification Script Started"
  52. sleep 30
  53.  
  54. if [ -e "/usr/sbin/realtc" ] ; then
  55. tc="realtc"
  56. else
  57. tc="tc"
  58. fi
  59.  
  60. #################### Variables Setup #####################
  61.  
  62. #DO NOT ADD OR REMOVE SPACES WHILE CHANGING VARIBLES, ADDITIONAL/MISSING SPACES WILL CAUSE FAILURE
  63.  
  64. #Percent of download speed guaranteed per QOS catagory, change below as desired (sum should equal 100)
  65. NetControl_DownBandPercent=5 #This value can be adjust as desired
  66. VoIP_DownBandPercent=25 #This value can be adjust as desired
  67. Gaming_DownBandPercent=15 #This value can be adjust as desired
  68. Others_DownBandPercent=10 #This value can be adjust as desired #Note: New destination for all unidentified traffic per script default
  69. WebSurfing_DownBandPercent=15 #This value can be adjust as desired
  70. Video_DownBandPercent=20 #This value can be adjust as desired
  71. FileTransfer_DownBandPercent=5 #This value can be adjust as desired
  72.  
  73. #Percent of upload speed guaranteed per QOS catagory, change below as desired (sum should equal 100)
  74. NetControl_UpBandPercent=5 #This value can be adjust as desired
  75. VoIP_UpBandPercent=25 #This value can be adjust as desired
  76. Gaming_UpBandPercent=15 #This value can be adjust as desired
  77. Others_UpBandPercent=10 #This value can be adjust as desired #Note: New destination for all unidentified traffic per script default
  78. WebSurfing_UpBandPercent=20 #This value can be adjust as desired
  79. Video_UpBandPercent=15 #This value can be adjust as desired
  80. FileTransfer_UpBandPercent=5 #This value can be adjust as desired
  81.  
  82. #Upload/download GUARENTEED and MAX percents for bandwith limiter
  83. Default_DownBandPercent=5 #This value can be adjust as desired #Guarented shared bandwidth for bandwidth limited clients #Note: Originally destination for unidentified traffic but repurposed for bandwith limited client traffic
  84. Default_UpBandPercent=5 #This value can be adjust as desired #Guarented shared bandwidth for bandwidth limited clients #Note: Originally destination for unidentified traffic but repurposed for bandwith limited client traffic
  85. Default_DownCeilPercent=75 #This value can be adjust as desired #Max shared bandwidth for bandwidth limiter (100 = no limiting) #Note: Has to be higher than Default_DownBandPercent
  86. Default_UpCeilPercent=75 #This value can be adjust as desired #Max shared bandwidth for bandwidth limiter (100 = no limiting) #Note: Has to be higher than Default_UpBandPercent
  87.  
  88. while read -r line; #reads all QOS rules, used to read user order of VOIP contianers
  89. do
  90. flowid="$( echo -n ${line} | sed -n -e 's/.*flowid //p' | tail -c 1)" #check if individual rule line output has valid flowID which would then correspond to an individual rules Traffic Container / Catagory / Flowid.
  91. if [ "${flowid}" != "" ] ; then #if valid flowID is found, read next line.
  92. read line
  93. mark="$(echo ${line} | sed -n -e 's/.*mark \([a-zA-z0-9]* [a-zA-z0-9]*\).*/\1/p')" #This line reads which individual QOS traffic rule / mark corresponds to the Traffic Container / Catagory / Flowid read in the previous line
  94.  
  95.  
  96. if [ "${mark}" = "0x80060000 0xc03f0000" ] ; then #VOIP
  97. eval "Cat${flowid}DownBandPercent=${VoIP_DownBandPercent}"
  98. eval "Cat${flowid}UpBandPercent=${VoIP_UpBandPercent}"
  99. VOIP="1:1${flowid}" #Use this variable for custom QOS rule flowID (case sensitive)
  100. fi
  101.  
  102. if [ "${mark}" = "0x80080000 0xc03f0000" ] ; then #Gaming
  103. eval "Cat${flowid}DownBandPercent=${Gaming_DownBandPercent}"
  104. eval "Cat${flowid}UpBandPercent=${Gaming_UpBandPercent}"
  105. Gaming="1:1${flowid}" #Use this variable for custom QOS rule flowID (case sensitive)
  106. fi
  107.  
  108. if [ "${mark}" = "0x800a0000 0xc03f0000" ] ; then #Others
  109. eval "Cat${flowid}DownBandPercent=${Others_DownBandPercent}"
  110. eval "Cat${flowid}UpBandPercent=${Others_UpBandPercent}"
  111. Others="1:1${flowid}" #Use this variable for custom QOS rule flowID (case sensitive)
  112. fi
  113.  
  114. if [ "${mark}" = "0x800d0000 0xc03f0000" ] ; then #Web Surfing
  115. eval "Cat${flowid}DownBandPercent=${WebSurfing_DownBandPercent}"
  116. eval "Cat${flowid}UpBandPercent=${WebSurfing_UpBandPercent}"
  117. Web="1:1${flowid}" #Use this variable for custom QOS rule flowID (case sensitive)
  118. fi
  119.  
  120. if [ "${mark}" = "0x80040000 0xc03f0000" ] ; then #Streaming
  121. eval "Cat${flowid}DownBandPercent=${Video_DownBandPercent}"
  122. eval "Cat${flowid}UpBandPercent=${Video_UpBandPercent}"
  123. Streaming="1:1${flowid}" #Use this variable for custom QOS rule flowID (case sensitive)
  124. fi
  125.  
  126. if [ "${mark}" = "0x80030000 0xc03f0000" ] ; then #Downloads
  127. eval "Cat${flowid}DownBandPercent=${FileTransfer_DownBandPercent}"
  128. eval "Cat${flowid}UpBandPercent=${FileTransfer_UpBandPercent}"
  129. Downloads="1:1${flowid}" #Use this variable for custom QOS rule flowID (case sensitive)
  130. fi
  131.  
  132. if [ "${mark}" = "0x80000000 0xc000ffff" ] ; then #Default (Unidentified traffic)
  133. Default="1:1${flowid}" #Use this variable for custom QOS rule flowID (case sensitive)
  134. fi
  135.  
  136. fi
  137. done <<EOF
  138. $(${tc} filter show dev br0 | grep -o "flowid.*" -A1 | sed '/^--$/d')
  139. EOF
  140.  
  141. Cat0DownBandPercent=${NetControl_DownBandPercent}
  142. Cat0UpBandPercent=${NetControl_UpBandPercent}
  143.  
  144. Cat7DownBandPercent=${Default_DownBandPercent}
  145. Cat7DownCeilPercent=${Default_DownCeilPercent}
  146.  
  147. Cat7UpBandPercent=${Default_UpBandPercent}
  148. Cat7UpCeilPercent=${Default_UpCeilPercent}
  149.  
  150.  
  151. ############################### Unidentified Traffic Priority & Custom Rules ##########################
  152.  
  153.  
  154. if [ "${Default}" = "1:17" ] ; then
  155. logger "Adaptive QOS: Changing container for Unidentified Traffic & Applying Custom Rules"
  156.  
  157. VOIP_mark="0x40060001" #Note these marks are same as filter match/mask combo but have a 1 at the end. That trailing one prevents the filters from being marked unidentified
  158. Gaming_mark="0x40080001"
  159. Others_mark="0x400a0001"
  160. Web_mark="0x400d0001"
  161. Streaming_mark="0x40040001"
  162. Downloads_mark="0x40030001"
  163. BandwidthLimiter_mark="0x403b0001"
  164.  
  165. #################### Custom Rules Setup #####################
  166.  
  167. ${tc} filter del dev br0 parent 1: prio 2 #Deletes rule routing unidentified traffic into "Default" traffic container
  168. ##DOWNLOAD (INCOMMING TRAFFIC) CUSTOM RULES START HERE
  169. ${tc} filter add dev br0 protocol all prio 2 u32 match ip dport 500 0xffff flowid ${VOIP} #Wifi Calling (All incomming traffic w/ LAN destination port 500 goes to "VOIP" Traffic Container)
  170. ${tc} filter add dev br0 protocol all prio 2 u32 match ip dport 4500 0xffff flowid ${VOIP} #Wifi Calling (All incomming traffic w/ LAN destination port 4500 goes to "VOIP" Traffic Container)
  171. ${tc} filter add dev br0 protocol all prio 2 u32 match ip dport 16384 0xffe0 flowid ${VOIP} #Facetime (All incomming traffic w/ LAN destination ports 16384 - 16415 goes to "VOIP" Traffic Container)
  172. ${tc} filter add dev br0 protocol all prio 2 u32 match ip dst 192.168.1.32/28 flowid ${Default} #Bandiwdth Limited Users on IP 192.168.1.32 - 192.168.1.47
  173. ##DOWNLOAD (INCOMMING TRAFFIC) CUSTOM RULES END HERE
  174. ${tc} filter add dev br0 protocol all prio 2 u32 match mark 0x80000000 0x8000ffff flowid ${Others} #Creates rule routing unidentified traffic into "Others" traffic container which user adjustable in webUI, instead of default reouting pf traffoc into non adjustable "Default" traffic container
  175. ${tc} filter del dev br0 parent 1: prio 22 #delete ASUS traffic rule that routes HTTPS traffic into "Net Control"
  176. ${tc} filter add dev br0 protocol all prio 22 u32 match mark 0x80140000 0xc03f0000 flowid ${Downloads} #create https traffic that routes HTTPS traffic into "Web Surfing"
  177.  
  178.  
  179. ${tc} filter del dev eth0 parent 1: prio 2 #Deletes rule routing unidentified traffic into "Default" traffic container
  180. ##UPLOAD (OUTGOING TRAFFIC) CUSTOM RULES START HERE
  181. ${tc} filter add dev eth0 protocol all prio 2 u32 match ip sport 500 0xffff flowid ${VOIP} #Wifi Calling (All outgoing traffic w/ LAN source port 500 goes to "VOIP" Traffic Container)
  182. ${tc} filter add dev eth0 protocol all prio 2 u32 match ip sport 4500 0xffff flowid ${VOIP} #Wifi Calling (All outgoing traffic w/ LAN source port 4500 goes to "VOIP" Traffic Container)
  183. ${tc} filter add dev eth0 protocol all prio 2 u32 match ip sport 16384 0xffe0 flowid ${VOIP} #Facetime (All outgoing traffic w/ LAN source ports 16384 - 16415 goes to "VOIP" Traffic Container)
  184. ${tc} filter add dev eth0 protocol all prio 2 u32 match mark 0x403b0000 0x403f0000 flowid ${Default} #Bandiwdth Limited Users iptables mark
  185. iptables -D POSTROUTING -t mangle -o eth0 -s 192.168.1.32/28 -j MARK --set-mark ${BandwidthLimiter_mark} #Bandiwdth Limited Users on IP 192.168.1.32 - 192.168.1.47
  186. iptables -A POSTROUTING -t mangle -o eth0 -s 192.168.1.32/28 -j MARK --set-mark ${BandwidthLimiter_mark} #Bandiwdth Limited Users on IP 192.168.1.32 - 192.168.1.47
  187. ##UPLOAD (OUTGOING TRAFFIC) CUSTOM RULES END HERE
  188. ${tc} filter add dev eth0 protocol all prio 2 u32 match mark 0x40000000 0x4000ffff flowid ${Others} #Creates rule routing unidentified traffic into "Others" traffic container which user adjustable in webUI, instead of default reouting pf traffoc into non adjustable "Default" traffic container
  189. ${tc} filter del dev eth0 parent 1: prio 22 #delete ASUS traffic rule that routes HTTPS traffic into "Net Control"
  190. ${tc} filter add dev eth0 protocol all prio 22 u32 match mark 0x40140000 0xc03f0000 flowid ${Downloads} #create https traffic that routes HTTPS traffic into "Web Surfing"
  191.  
  192.  
  193. ######################## Minimum Alotted Bandwidth Per QOS Catagory ##########################
  194.  
  195.  
  196. DownCeil="$(printf "%.0f" $(nvram get qos_ibw))" #Maximum download rate defined in WebUI
  197. UpCeil="$(printf "%.0f" $(nvram get qos_obw))"
  198.  
  199. DownRate0="$(expr ${DownCeil} \* ${Cat0DownBandPercent} / 100)" #New rates that correspond to user defined percentages above
  200. DownRate1="$(expr ${DownCeil} \* ${Cat1DownBandPercent} / 100)"
  201. DownRate2="$(expr ${DownCeil} \* ${Cat2DownBandPercent} / 100)"
  202. DownRate3="$(expr ${DownCeil} \* ${Cat3DownBandPercent} / 100)"
  203. DownRate4="$(expr ${DownCeil} \* ${Cat4DownBandPercent} / 100)"
  204. DownRate5="$(expr ${DownCeil} \* ${Cat5DownBandPercent} / 100)"
  205. DownRate6="$(expr ${DownCeil} \* ${Cat6DownBandPercent} / 100)"
  206. DownRate7="$(expr ${DownCeil} \* ${Cat7DownBandPercent} / 100)"
  207.  
  208. UpRate0="$(expr ${UpCeil} \* ${Cat0UpBandPercent} / 100)"
  209. UpRate1="$(expr ${UpCeil} \* ${Cat1UpBandPercent} / 100)"
  210. UpRate2="$(expr ${UpCeil} \* ${Cat2UpBandPercent} / 100)"
  211. UpRate3="$(expr ${UpCeil} \* ${Cat3UpBandPercent} / 100)"
  212. UpRate4="$(expr ${UpCeil} \* ${Cat4UpBandPercent} / 100)"
  213. UpRate5="$(expr ${UpCeil} \* ${Cat5UpBandPercent} / 100)"
  214. UpRate6="$(expr ${UpCeil} \* ${Cat6UpBandPercent} / 100)"
  215. UpRate7="$(expr ${UpCeil} \* ${Cat7UpBandPercent} / 100)"
  216.  
  217. DownCeil7="$(expr ${DownCeil} \* ${Cat7DownCeilPercent} / 100)"
  218. UpCeil7="$(expr ${UpCeil} \* ${Cat7UpCeilPercent} / 100)"
  219.  
  220. logger "Adaptive QOS: Changing minimum alloted bandwidth per QOS category to user defined percentages"
  221.  
  222. #read existing burst/cburst per download QOS class
  223. while read -r line;
  224. do
  225. if [ "$( echo ${line} | sed -n -e 's/.*1:10 //p' )" != "" ] ; then
  226. DownBurst0=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  227. DownCburst0=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  228. fi
  229.  
  230. if [ "$( echo ${line} | sed -n -e 's/.*1:11 //p' )" != "" ] ; then
  231. DownBurst1=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  232. DownCburst1=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  233. fi
  234.  
  235. if [ "$( echo ${line} | sed -n -e 's/.*1:12 //p' )" != "" ] ; then
  236. DownBurst2=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  237. DownCburst2=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  238. fi
  239.  
  240. if [ "$( echo ${line} | sed -n -e 's/.*1:13 //p' )" != "" ] ; then
  241. DownBurst3=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  242. DownCburst3=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  243. fi
  244.  
  245. if [ "$( echo ${line} | sed -n -e 's/.*1:14 //p' )" != "" ] ; then
  246. DownBurst4=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  247. DownCburst4=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  248. fi
  249.  
  250. if [ "$( echo ${line} | sed -n -e 's/.*1:15 //p' )" != "" ] ; then
  251. DownBurst5=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  252. DownCburst5=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  253. fi
  254.  
  255. if [ "$( echo ${line} | sed -n -e 's/.*1:16 //p' )" != "" ] ; then
  256. DownBurst6=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  257. DownCburst6=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  258. fi
  259.  
  260. if [ "$( echo ${line} | sed -n -e 's/.*1:17 //p' )" != "" ] ; then
  261. DownBurst7=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  262. DownCburst7=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  263. fi
  264. done <<EOF
  265. $( tc class show dev br0 | grep " 1:1" )
  266. EOF
  267.  
  268. #read existing burst/cburst per upload QOS class
  269. while read -r line;
  270. do
  271. if [ "$( echo ${line} | sed -n -e 's/.*1:10 //p' )" != "" ] ; then
  272. UpBurst0=$( echo ${line} | sed -n -e 's/.*burst \([a-zA-z0-9]*\).*/\1/p' )
  273. UpCburst0=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  274. fi
  275.  
  276. if [ "$( echo ${line} | sed -n -e 's/.*1:11 //p' )" != "" ] ; then
  277. UpBurst1=$( echo ${line} | sed -n -e 's/.*burst \([a-zA-z0-9]*\).*/\1/p' )
  278. UpCburst1=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  279. fi
  280.  
  281. if [ "$( echo ${line} | sed -n -e 's/.*1:12 //p' )" != "" ] ; then
  282. UpBurst2=$( echo ${line} | sed -n -e 's/.*burst \([a-zA-z0-9]*\).*/\1/p' )
  283. UpCburst2=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  284. fi
  285.  
  286. if [ "$( echo ${line} | sed -n -e 's/.*1:13 //p' )" != "" ] ; then
  287. UpBurst3=$( echo ${line} | sed -n -e 's/.*burst \([a-zA-z0-9]*\).*/\1/p' )
  288. UpCburst3=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  289. fi
  290.  
  291. if [ "$( echo ${line} | sed -n -e 's/.*1:14 //p' )" != "" ] ; then
  292. UpBurst4=$( echo ${line} | sed -n -e 's/.*burst \([a-zA-z0-9]*\).*/\1/p' )
  293. UpCburst4=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  294. fi
  295.  
  296. if [ "$( echo ${line} | sed -n -e 's/.*1:15 //p' )" != "" ] ; then
  297. UpBurst5=$( echo ${line} | sed -n -e 's/.*burst \([a-zA-z0-9]*\).*/\1/p' )
  298. UpCburst5=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  299. fi
  300.  
  301. if [ "$( echo ${line} | sed -n -e 's/.*1:16 //p' )" != "" ] ; then
  302. UpBurst6=$( echo ${line} | sed -n -e 's/.*burst \([a-zA-z0-9]*\).*/\1/p' )
  303. UpCburst6=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  304. fi
  305.  
  306. if [ "$( echo ${line} | sed -n -e 's/.*1:17 //p' )" != "" ] ; then
  307. UpBurst7=$( echo ${line} | sed -n -e 's/.*burst \([a-zA-z0-9]*\).*/\1/p' )
  308. UpCburst7=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  309. fi
  310. done <<EOF
  311. $( tc class show dev eth0 | grep " 1:1" )
  312. EOF
  313.  
  314.  
  315.  
  316. logger "Adaptive QOS: Changing minimum alloted bandwidth per QOS category to user defined percentages"
  317. tc class change dev br0 parent 1:1 classid 1:10 htb prio 0 rate ${DownRate0}Kbit ceil ${DownCeil}Kbit burst ${DownBurst0} cburst ${DownCburst0}
  318. tc class change dev br0 parent 1:1 classid 1:11 htb prio 1 rate ${DownRate1}Kbit ceil ${DownCeil}Kbit burst ${DownBurst1} cburst ${DownCburst1}
  319. tc class change dev br0 parent 1:1 classid 1:12 htb prio 2 rate ${DownRate2}Kbit ceil ${DownCeil}Kbit burst ${DownBurst2} cburst ${DownCburst2}
  320. tc class change dev br0 parent 1:1 classid 1:13 htb prio 3 rate ${DownRate3}Kbit ceil ${DownCeil}Kbit burst ${DownBurst3} cburst ${DownCburst3}
  321. tc class change dev br0 parent 1:1 classid 1:14 htb prio 4 rate ${DownRate4}Kbit ceil ${DownCeil}Kbit burst ${DownBurst4} cburst ${DownCburst4}
  322. tc class change dev br0 parent 1:1 classid 1:15 htb prio 5 rate ${DownRate5}Kbit ceil ${DownCeil}Kbit burst ${DownBurst5} cburst ${DownCburst5}
  323. tc class change dev br0 parent 1:1 classid 1:16 htb prio 6 rate ${DownRate6}Kbit ceil ${DownCeil}Kbit burst ${DownBurst6} cburst ${DownCburst6}
  324. tc class change dev br0 parent 1:1 classid 1:17 htb prio 7 rate ${DownRate7}Kbit ceil ${DownCeil7}Kbit burst ${DownBurst7} cburst ${DownCburst7}
  325.  
  326.  
  327. tc class change dev eth0 parent 1:1 classid 1:10 htb prio 0 rate ${UpRate0}Kbit ceil ${UpCeil}Kbit burst ${UpBurst0} cburst ${UpCburst0}
  328. tc class change dev eth0 parent 1:1 classid 1:11 htb prio 1 rate ${UpRate1}Kbit ceil ${UpCeil}Kbit burst ${UpBurst1} cburst ${UpCburst1}
  329. tc class change dev eth0 parent 1:1 classid 1:12 htb prio 2 rate ${UpRate2}Kbit ceil ${UpCeil}Kbit burst ${UpBurst2} cburst ${UpCburst2}
  330. tc class change dev eth0 parent 1:1 classid 1:13 htb prio 3 rate ${UpRate3}Kbit ceil ${UpCeil}Kbit burst ${UpBurst3} cburst ${UpCburst3}
  331. tc class change dev eth0 parent 1:1 classid 1:14 htb prio 4 rate ${UpRate4}Kbit ceil ${UpCeil}Kbit burst ${UpBurst4} cburst ${UpCburst4}
  332. tc class change dev eth0 parent 1:1 classid 1:15 htb prio 5 rate ${UpRate5}Kbit ceil ${UpCeil}Kbit burst ${UpBurst5} cburst ${UpCburst5}
  333. tc class change dev eth0 parent 1:1 classid 1:16 htb prio 6 rate ${UpRate6}Kbit ceil ${UpCeil}Kbit burst ${UpBurst6} cburst ${UpCburst6}
  334. tc class change dev eth0 parent 1:1 classid 1:17 htb prio 7 rate ${UpRate7}Kbit ceil ${UpCeil7}Kbit burst ${UpBurst7} cburst ${UpCburst7}
  335.  
  336. else
  337. logger "Adaptive QOS: No change required for QOS category bandwidth percentages"
  338. fi
  339. fi
  340.  
  341. rm -rf /tmp/qos.lock
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement