Skip to content

Commit

Permalink
implement auto-bandwith
Browse files Browse the repository at this point in the history
  • Loading branch information
maghuro committed Jun 27, 2020
1 parent 0b63138 commit fd81ba3
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions cake-qos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ Filter_Version(){
}

Validate_Bandwidth(){
if echo "$1" | /bin/grep -oq "^[1-9][0-9]*\.\?[0-9]*$"; then
if "$1" = "auto"; then
return 0
elif echo "$1" | /bin/grep -oq "^[1-9][0-9]*\.\?[0-9]*$"; then
return 0
else
return 1
Expand Down Expand Up @@ -246,21 +248,33 @@ cake_start(){
cake_stop

cru a "$SCRIPT_NAME_FANCY" "*/60 * * * * ${SCRIPT_DIR}/${SCRIPT_NAME} checkrun"

Print_Output "true" "Starting - settings: ${dlspeed}Mbit | ${upspeed}Mbit | $queueprio | $extraoptions" "$PASS"
[ "${dlspeed}" = "auto" ] && dlspeed="auto" || dlspeed="${dlspeed}Mbit"
[ "${upspeed}" = "auto" ] && upspeed="auto" || upspeed="${upspeed}Mbit"
if [ "${dlspeed}" = "auto" ] || [ "${upspeed}" = "auto" ]; then
extraoptions="autorate-ingress $extraoptions"
fi
Print_Output "true" "Starting - settings: $printdl | $printup | $queueprio | $extraoptions" "$PASS"
runner disable 2>/dev/null
fc disable 2>/dev/null
fc flush 2>/dev/null
nvram set runner_disable="1"
nvram set fc_disable="1"
nvram commit
insmod /opt/lib/modules/sch_cake.ko 2>/dev/null
/opt/sbin/tc qdisc replace dev eth0 root cake bandwidth "${upspeed}Mbit" nat "$queueprio" $extraoptions # options needs to be left unquoted to support multiple extra parameters
if [ "${updspeed}" = "auto"; then
/opt/sbin/tc qdisc replace dev eth0 root cake nat "$queueprio" $extraoptions # options needs to be left unquoted to support multiple extra parameters
else
/opt/sbin/tc qdisc replace dev eth0 root cake bandwidth "${upspeed}" nat "$queueprio" $extraoptions # options needs to be left unquoted to support multiple extra parameters
fi
ip link add name ifb9eth0 type ifb
/opt/sbin/tc qdisc del dev eth0 ingress 2>/dev/null
/opt/sbin/tc qdisc add dev eth0 handle ffff: ingress
/opt/sbin/tc qdisc del dev ifb9eth0 root 2>/dev/null
/opt/sbin/tc qdisc add dev ifb9eth0 root cake bandwidth "${dlspeed}Mbit" nat wash ingress "$queueprio" $extraoptions # options needs to be left unquoted to support multiple extra parameters
if [ "${dlspeed}" = "auto"; then
/opt/sbin/tc qdisc add dev ifb9eth0 root cake nat wash ingress "$queueprio" $extraoptions # options needs to be left unquoted to support multiple extra parameters
else
/opt/sbin/tc qdisc add dev ifb9eth0 root cake bandwidth "${dlspeed}" nat wash ingress "$queueprio" $extraoptions # options needs to be left unquoted to support multiple extra parameters
fi
ifconfig ifb9eth0 up
/opt/sbin/tc filter add dev eth0 parent ffff: protocol all prio 10 u32 match u32 0 0 flowid 1:1 action mirred egress redirect dev ifb9eth0
}
Expand Down Expand Up @@ -365,7 +379,7 @@ Cake_Menu(){
case "$menu2" in
1)
option2="dlspeed"
echo "Please enter your download speed:"
echo "Please enter your download speed (or auto):"
printf "[Mbit]: "
read -r "option3"
echo
Expand All @@ -378,7 +392,7 @@ Cake_Menu(){
;;
2)
option2="upspeed"
echo "Please enter your upload speed:"
echo "Please enter your upload speed (or auto):"
printf "[Mbit]: "
read -r "option3"
echo
Expand Down Expand Up @@ -556,7 +570,7 @@ case $1 in
if [ -z "$dlspeed" ]; then
while true; do
echo
echo "Please enter your download speed:"
echo "Please enter your download speed (or auto):"
printf "[Mbit]: "
read -r "dlspeed"
echo
Expand All @@ -571,7 +585,7 @@ case $1 in
if [ -z "$upspeed" ]; then
while true; do
echo
echo "Please enter your upload speed:"
echo "Please enter your upload speed (or auto):"
printf "[Mbit]: "
read -r "upspeed"
echo
Expand Down

0 comments on commit fd81ba3

Please sign in to comment.