qos Improvements on mtk qos tc+iptable classification

This commit is contained in:
Padmalochan Mohapatra 2023-01-03 15:26:20 +00:00 committed by Rahul Thakur
parent 9192b863ea
commit f7e6238928
2 changed files with 37 additions and 25 deletions

View file

@ -4,6 +4,18 @@
ethwan="$(db -q get hw.board.ethernetWanPort)"
populate_no_of_queue(){
queue_num=8
# writing no. of queue per port into file and read on classify generate
if [ ! -d "/tmp/qos" ]; then
mkdir -p "/tmp/qos"
fi
no_queue_file="/tmp/qos/no_queue_per_port"
touch "$no_queue_file"
echo $queue_num >"$no_queue_file"
}
generate_queue(){
section="$1"
@ -29,6 +41,8 @@ generate_queue(){
uci commit qos
}
populate_no_of_queue
if [ -s "/etc/config/qos" ]; then
if uci -q get qos.@queue[0] >/dev/null; then
# return if there is any valid content

View file

@ -70,7 +70,7 @@ handle_queue() {
local port_bw="$3"
local root="$4"
local port_bs="$5"
local priority=0
config_get is_enable "$qid" "enable"
# no need to configure disabled queues
@ -127,21 +127,17 @@ handle_queue() {
# ignore precedence value in case of WRR, broadcom recommends that WRR queue should
# always have precedence value set to 0
if [ $salg -eq 2 ]; then
order=0
if [ $salg -ne 2 ]; then
priority=$order
fi
if [ $salg -eq 2 ]; then
tc class add dev $port parent ${root}: classid ${root}:$((order + 1)) cbq allot $bs bandwidth ${port_bw}kbit rate ${rate}kbit prio $order weight $wgt avpkt 1500 bounded isolated
else
tc class add dev $port parent ${root}: classid ${root}:$((order + 1)) cbq allot $bs bandwidth ${port_bw}kbit rate ${rate}kbit prio $order avpkt 1500 bounded isolated
if [ $order -ne 0 ]; then
if [ $salg -eq 2 ]; then
tc class add dev $port parent ${root}: classid ${root}:$order cbq allot $bs bandwidth ${port_bw}kbit rate ${rate}kbit prio $priority weight $wgt avpkt 1500 bounded isolated
else
tc class add dev $port parent ${root}: classid ${root}:$order cbq allot $bs bandwidth ${port_bw}kbit rate ${rate}kbit prio $priority avpkt 1500 bounded isolated
fi
tc filter add dev $port parent ${root}:0 prio $order handle $order fw classid ${root}:$order
fi
if [ $order -eq 0 ]; then
# By default flowid is targeted to queue 1.
tc filter add dev $port parent ${root}:0 protocol ip prio 1 u32 match u32 0 0 flowid ${root}:0
fi
Q_COUNT=$((Q_COUNT + 1))
}
@ -174,6 +170,10 @@ setup_qos() {
ebtables -t broute -I BROUTING -j qos
fi
iptables -w -t mangle -N qos_prerouting
ret=$?
[ $ret -eq 0 ] && iptables -w -t mangle -I PREROUTING -j qos_prerouting
iptables -w -t mangle -N qos_forward
ret=$?
[ $ret -eq 0 ] && iptables -w -t mangle -I FORWARD -j qos_forward
@ -182,9 +182,9 @@ setup_qos() {
ret=$?
[ $ret -eq 0 ] && iptables -w -t mangle -I OUTPUT -j qos_output
iptables -w -t mangle -N qos_postrouting
ip6tables -w -t mangle -N qos_prerouting
ret=$?
[ $ret -eq 0 ] && iptables -w -t mangle -I POSTROUTING -j qos_postrouting
[ $ret -eq 0 ] && ip6tables -w -t mangle -I PREROUTING -j qos_prerouting
ip6tables -t mangle -N qos_forward
ret=$?
@ -194,19 +194,16 @@ setup_qos() {
ret=$?
[ $ret -eq 0 ] && ip6tables -t mangle -I OUTPUT -j qos_output
ip6tables -w -t mangle -N qos_postrouting
ret=$?
[ $ret -eq 0 ] && ip6tables -w -t mangle -I POSTROUTING -j qos_postrouting
}
flush_chains() {
echo "iptables -w -t mangle -F qos_forward" > /tmp/qos/classify.iptables
echo "iptables -w -t mangle -F qos_output" >> /tmp/qos/classify.iptables
echo "iptables -w -t mangle -F qos_postrouting" >> /tmp/qos/classify.iptables
echo "iptables -w -t mangle -F qos_prerouting" >> /tmp/qos/classify.iptables
echo "ip6tables -w -t mangle -F qos_forward" > /tmp/qos/classify.ip6tables
echo "ip6tables -w -t mangle -F qos_output" >> /tmp/qos/classify.ip6tables
echo "ip6tables -w -t mangle -F qos_postrouting" >> /tmp/qos/classify.ip6tables
echo "ip6tables -w -t mangle -F qos_prerouting" >> /tmp/qos/classify.ip6tables
}
init_iptables_rule() {
@ -214,7 +211,7 @@ init_iptables_rule() {
}
iptables_filter_intf() {
IP_RULE="$IP_RULE -o $1"
IP_RULE="$IP_RULE -i $1"
}
iptables_filter_proto() {
@ -262,7 +259,7 @@ iptables_set_dscp_mark() {
}
iptables_set_traffic_class() {
IP_RULE="$IP_RULE -j CLASSIFY --set-class ${MAJOR}:$1"
IP_RULE="$IP_RULE -j MARK --set-mark $1"
}
append_rule_to_mangle_table() {
@ -385,14 +382,13 @@ handle_iptables_rules() {
#write iptables rule for dscp marking
[ -n "$IP_RULE" -a -n "$dscp_mark" ] && append_rule_to_mangle_table "qos_forward" $ip_version
if [ -n "$IP_RULE" -a -n "$traffic_class" ]; then
if [ "$ifname" == "lo" ]; then
#write iptables rule for putting WAN directed internal packets in different queue
append_rule_to_mangle_table "qos_output" $ip_version
else
#write iptables rule for putting WAN directed LAN packets in different queue
append_rule_to_mangle_table "qos_postrouting" $ip_version
append_rule_to_mangle_table "qos_prerouting" $ip_version
fi
fi
}
@ -523,11 +519,13 @@ configure_classify() {
#processing classify section
rm -f /tmp/qos/classify.iptables
rm -f /tmp/qos/classify.ip6tables
rm -f /tmp/qos/classify.order
# create files that will contain the rules if not present already
mkdir -p /tmp/qos/
touch /tmp/qos/classify.iptables
touch /tmp/qos/classify.ip6tables
touch /tmp/qos/classify.order
flush_chains