Advertisement
Guest User

Untitled

a guest
Jan 13th, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 22.20 KB | None | 0 0
  1. #!/bin/sh
  2. ##FreshJR_QOS v382.2 released 01/13/2017
  3. ##Script Tested on ASUS AC-68U, FW382.2, using Adaptive QOS with Manual Bandwidth Settings
  4. ##Script Changes Unidentified Packet QOS destination from Default Traffic Container (Category7) into user definable (in WebUI) Other Traffic Container
  5. ##Script Changes Minimum Guarenteed Bandwidth per QOS category from 128Kbit into user defined percentages upload and download.
  6. ##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.
  7. ##  Included custom rule moves any TCP/UDP traffic on ports 500 & 4500 into VOIP traffic Container.         (Wifi Calling)                 
  8. ##  Included custom rule moves any TCP/UDP traffic on ports 16384 - 16415 into VOIP traffic Container.      (Facetime)                 
  9.  
  10. #---------------------------------------------------------------------------------------------------------------
  11. #   VALID FLOW ID'S FOR CUSTOM RULES
  12. #    ${VOIP}, ${Gaming}, ${Others}, ${Web}, ${Streaming}, ${Downloads}, ${Default}
  13. #
  14. #   VALID MARKS FOR IPTABLES
  15. #    ${VOIP_mark}, ${Gaming_mark}, ${Others_mark}, ${Web_mark}, ${Streaming_mark}, ${Downloads_mark}, ${Default_mark}
  16. #
  17. #   DOWNLOAD/INCOMMING TRAFFIC rule templates.  See comments next to rule for details
  18. #    ${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)
  19. #    ${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)                                          
  20. #    ${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
  21. #    ${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)                                                                               
  22. #
  23. #   UPLOAD/OUTOING TRAFFIC rule templates.      See comments next to rule for details
  24. #    ${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)
  25. #    ${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.                                
  26. #    ${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.   
  27. #    ${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)                                                                                                       
  28. #  
  29. #    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)
  30. #    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)
  31. #    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)
  32. #    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)
  33. #---------------------------------------------------------------------------------------------------------------       
  34.  
  35. cru a FreshJR_QOS "0 0 * * * /jffs/scripts/FreshJR_QOS"     ## schedules a daily check to see if modifcation is still persistant
  36.  
  37. Check_Lock () {
  38.         if [ -f "/tmp/qos.lock" ] && [ -d "/proc/$(sed -n '2p' /tmp/qos.lock)" ]; then
  39.             logger -st "Adaptive QOS" "[INFO] Lock File Detected from pid=$(sed -n '2p' /tmp/qos.lock) - Exiting Duplicate Instance"
  40.             exit 1
  41.         else
  42.             echo "$@" > /tmp/qos.lock
  43.             echo "$$" >> /tmp/qos.lock
  44.         fi
  45. }
  46.  
  47. Check_Lock "$@"
  48.  
  49. if [ "$(nvram get qos_enable)" = "1" ] && [ "$(nvram get qos_type)" = "1" ] ; then
  50.     logger "Adaptive QOS: Modification Script Started"
  51.     sleep 180    
  52.  
  53.     if [ -e "/usr/sbin/realtc" ] ; then
  54.         tc="realtc"
  55.     else
  56.         tc="tc"
  57.     fi
  58.    
  59.     ####################  Variables Setup #####################
  60.  
  61.     #Percent of download speed guaranteed per QOS catagory, change below as desired (sum should equal 100)
  62.         NetControl_DownBandPercent=5                    #This value can be adjust as desired
  63.         VoIP_DownBandPercent=20                         #This value can be adjust as desired
  64.         Gaming_DownBandPercent=15                       #This value can be adjust as desired
  65.         Others_DownBandPercent=10                       #This value can be adjust as desired        #Note: New destination for all unidentified traffic per script default
  66.         WebSurfing_DownBandPercent=10                   #This value can be adjust as desired
  67.         Video_DownBandPercent=30                        #This value can be adjust as desired
  68.         FileTransfer_DownBandPercent=5                  #This value can be adjust as desired
  69.         Default_DownBandPercent=5                       #This value can be adjust as desired        #Note: Original destination all for unidentified traffic, no traffic should flow here
  70.    
  71.     #Percent of upload speed guaranteed per QOS catagory, change below as desired (sum should equal 100)
  72.         NetControl_UpBandPercent=5                      #This value can be adjust as desired
  73.         VoIP_UpBandPercent=20                           #This value can be adjust as desired
  74.         Gaming_UpBandPercent=15                         #This value can be adjust as desired
  75.         Others_UpBandPercent=30                         #This value can be adjust as desired        #Note: New destination for all unidentified traffic per script default
  76.         WebSurfing_UpBandPercent=10                     #This value can be adjust as desired
  77.         Video_UpBandPercent=10                          #This value can be adjust as desired
  78.         FileTransfer_UpBandPercent=5                    #This value can be adjust as desired
  79.         Default_UpBandPercent=5                         #This value can be adjust as desired        #Note: Original destination all for unidentified traffic, no traffic should flow here
  80.    
  81.    
  82.     while read -r line;                                                                         #reads all QOS rules, used to read user order of contianers
  83.     do
  84.             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.
  85.             if [ "${flowid}" != "" ] ; then                                                     #if valid flowID is found, read next line.  
  86.                     read line                                                                  
  87.                     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
  88.                                            
  89.  
  90.                     if [ "${mark}" = "0x80060000 0xc03f0000" ] ; then                       #VOIP
  91.                         eval "Cat${flowid}DownBandPercent=${VoIP_DownBandPercent}"
  92.                         eval "Cat${flowid}UpBandPercent=${VoIP_UpBandPercent}"
  93.                         VOIP="1:1${flowid}"                                         #Use this variable for custom QOS rule flowID (case sensitive)
  94.                     fi
  95.                    
  96.                     if [ "${mark}" = "0x80080000 0xc03f0000" ] ; then                       #Gaming
  97.                         eval "Cat${flowid}DownBandPercent=${Gaming_DownBandPercent}"
  98.                         eval "Cat${flowid}UpBandPercent=${Gaming_UpBandPercent}"
  99.                         Gaming="1:1${flowid}"                                       #Use this variable for custom QOS rule flowID (case sensitive)
  100.                     fi
  101.                    
  102.                     if [ "${mark}" = "0x800a0000 0xc03f0000" ] ; then                       #Others
  103.                         eval "Cat${flowid}DownBandPercent=${Others_DownBandPercent}"
  104.                         eval "Cat${flowid}UpBandPercent=${Others_UpBandPercent}"
  105.                         Others="1:1${flowid}"                                       #Use this variable for custom QOS rule flowID (case sensitive)
  106.                     fi
  107.                    
  108.                     if [ "${mark}" = "0x800d0000 0xc03f0000" ] ; then                       #Web Surfing
  109.                         eval "Cat${flowid}DownBandPercent=${WebSurfing_DownBandPercent}"
  110.                         eval "Cat${flowid}UpBandPercent=${WebSurfing_UpBandPercent}"
  111.                         Web="1:1${flowid}"                                          #Use this variable for custom QOS rule flowID (case sensitive)
  112.                     fi
  113.                    
  114.                     if [ "${mark}" = "0x80040000 0xc03f0000" ] ; then                       #Streaming
  115.                         eval "Cat${flowid}DownBandPercent=${Video_DownBandPercent}"
  116.                         eval "Cat${flowid}UpBandPercent=${Video_UpBandPercent}"
  117.                         Streaming="1:1${flowid}"                                    #Use this variable for custom QOS rule flowID (case sensitive)
  118.                     fi
  119.                    
  120.                     if [ "${mark}" = "0x80030000 0xc03f0000" ] ; then                       #Downloads
  121.                         eval "Cat${flowid}DownBandPercent=${FileTransfer_DownBandPercent}"
  122.                         eval "Cat${flowid}UpBandPercent=${FileTransfer_UpBandPercent}"
  123.                         Downloads="1:1${flowid}"                                    #Use this variable for custom QOS rule flowID (case sensitive)
  124.                     fi
  125.                    
  126.                     if [ "${mark}" = "0x80000000 0xc000ffff" ] ; then                       #Default (Unidentified traffic)
  127.                         Default="1:1${flowid}"                                      #Use this variable for custom QOS rule flowID (case sensitive)
  128.                     fi
  129.                        
  130.             fi
  131.     done <<EOF
  132.         $(${tc} filter show dev br0 | grep -o "flowid.*" -A1 | sed '/^--$/d')
  133. EOF
  134.    
  135.     Cat0DownBandPercent=${NetControl_DownBandPercent}
  136.     Cat0UpBandPercent=${NetControl_UpBandPercent}
  137.  
  138.     Cat7DownBandPercent=${Default_DownBandPercent}
  139.     Cat7UpBandPercent=${Default_UpBandPercent}
  140.    
  141.     ############################### Unidentified Traffic Priority & Custom Rules ##########################
  142.    
  143.      
  144.     if [ "${Default}" != "1:117" ] ; then
  145.         logger "Adaptive QOS: Changing container for Unidentified Traffic & Applying Custom Rules"
  146.  
  147.         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 caught by unidentified mask
  148.         Gaming_mark="0x40080001"
  149.         Others_mark="0x400a0001"
  150.         Web_mark="0x400d0001"
  151.         Streaming_mark="0x40040001"
  152.         Downloads_mark="0x40030001"
  153.         Default_mark="0x40000001"
  154.  
  155.         ####################  Custom Rules Setup #####################
  156.        
  157.         ${tc} filter del dev br0 parent 1: prio 2                                                                   #Deletes rule routing unidentified traffic into "Default" traffic container
  158.             ##DOWNLOAD (INCOMMING TRAFFIC) CUSTOM RULES START HERE
  159.             ${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)                              
  160.             ${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)
  161.             ${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)
  162.             ##DOWNLOAD (INCOMMING TRAFFIC) CUSTOM RULES END HERE
  163.         ${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      
  164.         ${tc} filter del dev br0 parent 1: prio 22                                                                  #delete ASUS traffic rule that routes HTTPS traffic into "Net Control"
  165.         ${tc} filter add dev br0 protocol all prio 22 u32 match mark 0x80130000 0xc03f0000 flowid ${Web}            #create https traffic that routes HTTPS traffic into "Web Surfing"
  166.  
  167.            
  168.         ${tc} filter del dev eth0 parent 1: prio 2                                                                  #Deletes rule routing unidentified traffic into "Default" traffic container
  169.             ##UPLOAD (OUTGOING TRAFFIC) CUSTOM RULES START HERE                                            
  170.             ${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)                                      
  171.             ${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)
  172.             ${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)
  173.             ##UPLOAD (OUTGOING TRAFFIC) CUSTOM RULES END HERE                                              
  174.         ${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      
  175.         ${tc} filter del dev eth0 parent 1: prio 22                                                                 #delete ASUS traffic rule that routes HTTPS traffic into "Net Control"
  176.         ${tc} filter add dev eth0 protocol all prio 22 u32 match mark 0x40130000 0xc03f0000 flowid ${Web}           #create https traffic that routes HTTPS traffic into "Web Surfing"
  177.  
  178.      
  179.     ######################## Minimum Alotted Bandwidth Per QOS Catagory ##########################
  180.    
  181.    
  182.         DownCeil="$(printf "%.0f" $(nvram get qos_ibw))"                                                            #Maximum download rate defined in WebUI
  183.         UpCeil="$(printf "%.0f" $(nvram get qos_obw))"
  184.  
  185.         DownRate0="$(expr ${DownCeil} \* ${Cat0DownBandPercent} / 100)"                                         #New rates that correspond to user defined percentages above
  186.         DownRate1="$(expr ${DownCeil} \* ${Cat1DownBandPercent} / 100)"
  187.         DownRate2="$(expr ${DownCeil} \* ${Cat2DownBandPercent} / 100)"
  188.         DownRate3="$(expr ${DownCeil} \* ${Cat3DownBandPercent} / 100)"
  189.         DownRate4="$(expr ${DownCeil} \* ${Cat4DownBandPercent} / 100)"
  190.         DownRate5="$(expr ${DownCeil} \* ${Cat5DownBandPercent} / 100)"
  191.         DownRate6="$(expr ${DownCeil} \* ${Cat6DownBandPercent} / 100)"
  192.         DownRate7="$(expr ${DownCeil} \* ${Cat7DownBandPercent} / 100)"
  193.  
  194.         UpRate0="$(expr ${UpCeil} \* ${Cat0UpBandPercent} / 100)"
  195.         UpRate1="$(expr ${UpCeil} \* ${Cat1UpBandPercent} / 100)"
  196.         UpRate2="$(expr ${UpCeil} \* ${Cat2UpBandPercent} / 100)"
  197.         UpRate3="$(expr ${UpCeil} \* ${Cat3UpBandPercent} / 100)"
  198.         UpRate4="$(expr ${UpCeil} \* ${Cat4UpBandPercent} / 100)"
  199.         UpRate5="$(expr ${UpCeil} \* ${Cat5UpBandPercent} / 100)"
  200.         UpRate6="$(expr ${UpCeil} \* ${Cat6UpBandPercent} / 100)"
  201.         UpRate7="$(expr ${UpCeil} \* ${Cat7UpBandPercent} / 100)"
  202.        
  203.  
  204.         logger "Adaptive QOS: Changing minimum alloted bandwidth per QOS category to user defined percentages"
  205.  
  206.             #read existing burst/cburst per download QOS class
  207.             while read -r line;                                                                        
  208.             do
  209.                 if [ "$( echo ${line} | sed -n -e 's/.*1:10 //p' )" != "" ] ; then                                                     
  210.                     DownBurst0=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  211.                     DownCburst0=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  212.                 fi
  213.                
  214.                 if [ "$( echo ${line} | sed -n -e 's/.*1:11 //p' )" != "" ] ; then                                                     
  215.                     DownBurst1=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  216.                     DownCburst1=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  217.                 fi
  218.                
  219.                 if [ "$( echo ${line} | sed -n -e 's/.*1:12 //p' )" != "" ] ; then                                                     
  220.                     DownBurst2=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  221.                     DownCburst2=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  222.                 fi
  223.  
  224.                 if [ "$( echo ${line} | sed -n -e 's/.*1:13 //p' )" != "" ] ; then                                                     
  225.                     DownBurst3=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  226.                     DownCburst3=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  227.                 fi
  228.  
  229.                 if [ "$( echo ${line} | sed -n -e 's/.*1:14 //p' )" != "" ] ; then                                                     
  230.                     DownBurst4=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  231.                     DownCburst4=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  232.                 fi
  233.  
  234.                 if [ "$( echo ${line} | sed -n -e 's/.*1:15 //p' )" != "" ] ; then                                                     
  235.                     DownBurst5=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  236.                     DownCburst5=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  237.                 fi
  238.  
  239.                 if [ "$( echo ${line} | sed -n -e 's/.*1:16 //p' )" != "" ] ; then                                                     
  240.                     DownBurst6=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  241.                     DownCburst6=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  242.                 fi             
  243.  
  244.                 if [ "$( echo ${line} | sed -n -e 's/.*1:17 //p' )" != "" ] ; then                                                     
  245.                     DownBurst7=$( echo ${line} | sed -n -e 's/.* burst \([a-zA-z0-9]*\).*/\1/p' )
  246.                     DownCburst7=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  247.                 fi             
  248.             done <<EOF
  249.                 $( tc class show dev br0 | grep " 1:1" )
  250. EOF
  251.  
  252.             #read existing burst/cburst per upload QOS class
  253.             while read -r line;                                                                        
  254.             do
  255.                 if [ "$( echo ${line} | sed -n -e 's/.*1:10 //p' )" != "" ] ; then                                                     
  256.                     UpBurst0=$( echo ${line} | sed -n -e 's/.*burst \([a-zA-z0-9]*\).*/\1/p' )
  257.                     UpCburst0=$( 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:11 //p' )" != "" ] ; then                                                     
  261.                     UpBurst1=$( echo ${line} | sed -n -e 's/.*burst \([a-zA-z0-9]*\).*/\1/p' )
  262.                     UpCburst1=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  263.                 fi
  264.                
  265.                 if [ "$( echo ${line} | sed -n -e 's/.*1:12 //p' )" != "" ] ; then                                                     
  266.                     UpBurst2=$( echo ${line} | sed -n -e 's/.*burst \([a-zA-z0-9]*\).*/\1/p' )
  267.                     UpCburst2=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  268.                 fi
  269.  
  270.                 if [ "$( echo ${line} | sed -n -e 's/.*1:13 //p' )" != "" ] ; then                                                     
  271.                     UpBurst3=$( echo ${line} | sed -n -e 's/.*burst \([a-zA-z0-9]*\).*/\1/p' )
  272.                     UpCburst3=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  273.                 fi
  274.  
  275.                 if [ "$( echo ${line} | sed -n -e 's/.*1:14 //p' )" != "" ] ; then                                                     
  276.                     UpBurst4=$( echo ${line} | sed -n -e 's/.*burst \([a-zA-z0-9]*\).*/\1/p' )
  277.                     UpCburst4=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  278.                 fi
  279.  
  280.                 if [ "$( echo ${line} | sed -n -e 's/.*1:15 //p' )" != "" ] ; then                                                     
  281.                     UpBurst5=$( echo ${line} | sed -n -e 's/.*burst \([a-zA-z0-9]*\).*/\1/p' )
  282.                     UpCburst5=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  283.                 fi
  284.  
  285.                 if [ "$( echo ${line} | sed -n -e 's/.*1:16 //p' )" != "" ] ; then                                                     
  286.                     UpBurst6=$( echo ${line} | sed -n -e 's/.*burst \([a-zA-z0-9]*\).*/\1/p' )
  287.                     UpCburst6=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  288.                 fi             
  289.  
  290.                 if [ "$( echo ${line} | sed -n -e 's/.*1:17 //p' )" != "" ] ; then                                                     
  291.                     UpBurst7=$( echo ${line} | sed -n -e 's/.*burst \([a-zA-z0-9]*\).*/\1/p' )
  292.                     UpCburst7=$( echo ${line} | sed -n -e 's/.*cburst \([a-zA-z0-9]*\).*/\1/p' )
  293.                 fi             
  294.             done <<EOF
  295.                 $( tc class show dev eth0 | grep " 1:1" )
  296. EOF
  297.  
  298.         tc class change dev br0 parent 1:1 classid 1:10 htb prio 0 rate ${DownRate0}Kbit ceil ${DownCeil}Kbit burst ${DownBurst0} cburst ${DownCburst0}
  299.         tc class change dev br0 parent 1:1 classid 1:11 htb prio 1 rate ${DownRate1}Kbit ceil ${DownCeil}Kbit burst ${DownBurst1} cburst ${DownCburst1}
  300.         tc class change dev br0 parent 1:1 classid 1:12 htb prio 2 rate ${DownRate2}Kbit ceil ${DownCeil}Kbit burst ${DownBurst2} cburst ${DownCburst2}
  301.         tc class change dev br0 parent 1:1 classid 1:13 htb prio 3 rate ${DownRate3}Kbit ceil ${DownCeil}Kbit burst ${DownBurst3} cburst ${DownCburst3}
  302.         tc class change dev br0 parent 1:1 classid 1:14 htb prio 4 rate ${DownRate4}Kbit ceil ${DownCeil}Kbit burst ${DownBurst4} cburst ${DownCburst4}
  303.         tc class change dev br0 parent 1:1 classid 1:15 htb prio 5 rate ${DownRate5}Kbit ceil ${DownCeil}Kbit burst ${DownBurst5} cburst ${DownCburst5}
  304.         tc class change dev br0 parent 1:1 classid 1:16 htb prio 6 rate ${DownRate6}Kbit ceil ${DownCeil}Kbit burst ${DownBurst6} cburst ${DownCburst6}
  305.         tc class change dev br0 parent 1:1 classid 1:17 htb prio 7 rate ${DownRate7}Kbit ceil ${DownCeil}Kbit burst ${DownBurst7} cburst ${DownCburst7}
  306.        
  307.  
  308.         tc class change dev eth0 parent 1:1 classid 1:10 htb prio 0 rate ${UpRate0}Kbit ceil ${UpCeil}Kbit burst ${UpBurst0} cburst ${UpCburst0}
  309.         tc class change dev eth0 parent 1:1 classid 1:11 htb prio 1 rate ${UpRate1}Kbit ceil ${UpCeil}Kbit burst ${UpBurst1} cburst ${UpCburst1}
  310.         tc class change dev eth0 parent 1:1 classid 1:12 htb prio 2 rate ${UpRate2}Kbit ceil ${UpCeil}Kbit burst ${UpBurst2} cburst ${UpCburst2}
  311.         tc class change dev eth0 parent 1:1 classid 1:13 htb prio 3 rate ${UpRate3}Kbit ceil ${UpCeil}Kbit burst ${UpBurst3} cburst ${UpCburst3}
  312.         tc class change dev eth0 parent 1:1 classid 1:14 htb prio 4 rate ${UpRate4}Kbit ceil ${UpCeil}Kbit burst ${UpBurst4} cburst ${UpCburst4}
  313.         tc class change dev eth0 parent 1:1 classid 1:15 htb prio 5 rate ${UpRate5}Kbit ceil ${UpCeil}Kbit burst ${UpBurst5} cburst ${UpCburst5}
  314.         tc class change dev eth0 parent 1:1 classid 1:16 htb prio 6 rate ${UpRate6}Kbit ceil ${UpCeil}Kbit burst ${UpBurst6} cburst ${UpCburst6}
  315.         tc class change dev eth0 parent 1:1 classid 1:17 htb prio 7 rate ${UpRate7}Kbit ceil ${UpCeil}Kbit burst ${UpBurst7} cburst ${UpCburst7}
  316.     else
  317.         logger "Adaptive QOS: No change required for QOS category bandwidth percentages"
  318.     fi
  319. fi 
  320.  
  321. rm -rf /tmp/qos.lock
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement