Commit b6df3247 authored by subramanian c's avatar subramanian c
Browse files

qos: Deprecate firewall.qos and handle through qos config

Description:
    Deprecate firewall.qos and handle through qos config

Change Summary:
    Deprecate firewall.qos, generate classify config
for existing rules in /etc/config/qos along with queue
and parsed/converted through /lib/qos/qos.sh
    For airoha, Parse the qos classify config and create
temp file (/tmp/qos/classify.order) corresponding to the
interface with the combination of "order"_"classify id".
Sort this file in assending order based on the order value.
Read and apply classify config in the order of tmp file sequence.
parent 43dd5bf8
#!/bin/sh
. /lib/functions.sh
cpu_model="$(cat /proc/socinfo | grep 'SoC Name' | cut -d':' -f2)"
classify_no=0
generate_dns_rule(){
classify_no=$((classify_no + 1))
uci add qos classify
uci rename qos.@classify[-1]="c${classify_no}"
uci set qos.@classify[-1].proto="udp"
uci set qos.@classify[-1].ethertype="IPv4"
uci set qos.@classify[-1].dest_port="53"
uci set qos.@classify[-1].traffic_class="$1"
}
generate_dhcp_rule(){
classify_no=$((classify_no + 1))
uci add qos classify
uci rename qos.@classify[-1]="c${classify_no}"
uci set qos.@classify[-1].proto="udp"
uci set qos.@classify[-1].ethertype="IPv4"
uci set qos.@classify[-1].dest_port="67"
uci set qos.@classify[-1].dest_port_range="68"
uci set qos.@classify[-1].traffic_class="$1"
}
generate_igmp_rule(){
classify_no=$((classify_no + 1))
uci add qos classify
uci rename qos.@classify[-1]="c${classify_no}"
uci set qos.@classify[-1].proto="IGMP"
uci set qos.@classify[-1].ethertype="IPv4"
uci set qos.@classify[-1].traffic_class="$1"
}
generate_icmp_rule(){
classify_no=$((classify_no + 1))
uci add qos classify
uci rename qos.@classify[-1]="c${classify_no}"
uci set qos.@classify[-1].proto="icmp"
uci set qos.@classify[-1].ethertype="IPv4"
uci set qos.@classify[-1].traffic_class="$1"
classify_no=$((classify_no + 1))
uci add qos classify
uci rename qos.@classify[-1]="c${classify_no}"
uci set qos.@classify[-1].proto="icmp"
uci set qos.@classify[-1].ethertype="IPv4"
uci set qos.@classify[-1].traffic_class="$2"
}
generate_classify(){
# assign no. of queue based on target model
if [ "$cpu_model" == "BCM68" ]; then
queue_num=4
elif [ grep -qE '[0-9]+ archer$' /proc/devices ]; then
queue_num=4
else
queue_num=8
fi
# assign queue type
if [ $queue_num -eq 8 ]; then
q_def_queue="0x0"
q_low="0x1"
q_besteffort="0x2"
q_normal="0x3"
q_video="0x4"
q_medium="0x5"
q_high="0x6"
q_highest="0x7"
elif [ $queue_num -eq 4 ]; then
q_def_queue="0x0"
q_normal="0x1"
q_medium="0x2"
q_highest="0x3"
fi
# Local generated DNS traffic goes to q_highest
generate_dns_rule $q_highest
generate_igmp_rule $q_highest
generate_dhcp_rule $q_highest
generate_icmp_rule $q_highest $q_normal
for i in `seq 1 7`; do
classify_no=$((classify_no + 1))
uci add qos classify
uci rename qos.@classify[-1]="c${classify_no}"
uci set qos.@classify[-1].pcp_check="$i"
uci set qos.@classify[-1].traffic_class="$i"
done
uci commit qos
}
if [ -s "/etc/config/qos" ]; then
if [ uci -q get qos.@classify[0] >/dev/null]; then
if [ uci -q get qos.@queue[0] >/dev/null ]; then
# return if there is any valid content
exit
else
rm -f /etc/config/qos
fi
fi
fi
touch /etc/config/qos
generate_classify
#!/bin/sh
# Common classifier library
# Handle classify section
handle_classify() {
cid="$1" #classify section ID
#counter variable to assign classify order value if not added in config
temp_corder=1
# Function to handle a classify order
handle_classify_order() {
local cid="$1" #classify section ID
config_get is_enable "$cid" "enable" 1
# No need to configure disabled classify
if [ $is_enable == '0' ]; then
return
fi
# Create classify file containing classify order
local corder_file="/tmp/qos/classify.order"
config_get c_order "$cid" "order"
if [ -z "$c_order" ]; then
c_order=$temp_corder;
temp_corder=$((temp_corder + 1))
fi
value=${c_order}_${cid}
echo $value >> $corder_file
config_get is_enable "$cid" "enable"
# no need to configure disabled classify rules
if [ -z "$is_enable" ] || [ "$is_enable" == "0" ]; then
return
fi
}
# Sort classify, lower value in uci means higher precedence, so this
# function sorts the classify order in assending order
sort_classify_by_order() {
local corder_file="/tmp/qos/classify.order"
local tmp_corder_file="/tmp/qos/tmp_classify.order"
handle_ebtables_rules "$cid"
handle_iptables_rules "$cid"
handle_policer_rules "$cid"
sort -n -k1 $corder_file > $tmp_corder_file
cp $tmp_corder_file $corder_file
rm -f $tmp_corder_file
}
#function to handle a classify section
handle_classify() {
cid="$1" #classify section ID
config_get is_enable "$cid" "enable"
# no need to configure disabled classify rules
if [ "$is_enable" == '0' ]; then
return
fi
local corder_file="/tmp/qos/classify.order"
while read -r line; do
line_cid=$(echo $line | cut -d '_' -f 2)
handle_ebtables_rules $line_cid
handle_iptables_rules $line_cid
handle_policer_rules $line_cid
done < "$corder_file"
}
# Configure classifier based on UCI subtree 'qos.classify'
configure_classify() {
......@@ -24,21 +68,27 @@ configure_classify() {
rm -f /tmp/qos/classify.ebtables
rm -f /tmp/qos/classify.iptables
rm -f /tmp/qos/classify.ip6tables
rm -f /tmp/qos/classify.order
rm -f /tmp/qos/tmp_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.ebtables
touch /tmp/qos/classify.order
touch /tmp/qos/tmp_classify.order
# Add flush chain rules
flush_chains
# Load UCI file
config_load qos
config_foreach handle_classify classify
config_foreach handle_classify_order classify
sort_classify_by_order
handle_classify classify
sh /tmp/qos/classify.ebtables
sh /tmp/qos/classify.iptables
sh /tmp/qos/classify.ip6tables
}
\ No newline at end of file
}
#!/bin/sh
. /lib/functions.sh
cpu_model="$(cat /proc/socinfo | grep 'SoC Name' | cut -d':' -f2)"
classify_no=0
generate_dns_rule(){
classify_no=$((classify_no + 1))
uci add qos classify
uci rename qos.@classify[-1]="c${classify_no}"
uci set qos.@classify[-1].ifname="lo"
uci set qos.@classify[-1].proto="udp"
uci set qos.@classify[-1].ethertype="IPv4"
uci set qos.@classify[-1].dest_port="53"
uci set qos.@classify[-1].traffic_class="$1"
}
generate_dhcp_rule(){
classify_no=$((classify_no + 1))
uci add qos classify
uci rename qos.@classify[-1]="c${classify_no}"
uci set qos.@classify[-1].ifname="lo"
uci set qos.@classify[-1].proto="udp"
uci set qos.@classify[-1].ethertype="IPv4"
uci set qos.@classify[-1].dest_port_range="67:68"
uci set qos.@classify[-1].traffic_class="$1"
}
generate_igmp_rule(){
classify_no=$((classify_no + 1))
uci add qos classify
uci rename qos.@classify[-1]="c${classify_no}"
uci set qos.@classify[-1].ifname="lo"
uci set qos.@classify[-1].proto="IGMP"
uci set qos.@classify[-1].ethertype="IPv4"
uci set qos.@classify[-1].dest_port="2"
uci set qos.@classify[-1].traffic_class="$1"
}
generate_icmp_rule(){
classify_no=$((classify_no + 1))
uci add qos classify
uci rename qos.@classify[-1]="c${classify_no}"
uci set qos.@classify[-1].ifname="lo"
uci set qos.@classify[-1].proto="icmp"
uci set qos.@classify[-1].ethertype="IPv4"
uci set qos.@classify[-1].traffic_class="$1"
classify_no=$((classify_no + 1))
uci add qos classify
uci rename qos.@classify[-1]="c${classify_no}"
uci set qos.@classify[-1].proto="icmp"
uci set qos.@classify[-1].ethertype="IPv4"
uci set qos.@classify[-1].traffic_class="$2"
}
generate_classify(){
# assign no. of queue based on target model
if [ "$cpu_model" == "BCM68" ]; then
queue_num=4
elif [ grep -qE '[0-9]+ archer$' /proc/devices ]; then
queue_num=4
else
queue_num=8
fi
# assign queue type
if [ $queue_num -eq 8 ]; then
q_def_queue="0x0"
q_low="0x1"
q_besteffort="0x2"
q_normal="0x3"
q_video="0x4"
q_medium="0x5"
q_high="0x6"
q_highest="0x7"
elif [ $queue_num -eq 4 ]; then
q_def_queue="0x0"
q_normal="0x1"
q_medium="0x2"
q_highest="0x3"
fi
# Local generated DNS traffic goes to q_highest
generate_dns_rule $q_highest
generate_igmp_rule $q_highest
generate_dhcp_rule $q_highest
generate_icmp_rule $q_highest $q_normal
for i in `seq 1 7`; do
classify_no=$((classify_no + 1))
uci add qos classify
uci rename qos.@classify[-1]="c${classify_no}"
uci set qos.@classify[-1].pcp_check="$i"
uci set qos.@classify[-1].traffic_class="$i"
done
uci commit qos
}
if [ -s "/etc/config/qos" ]; then
if [ uci -q get qos.@classify[0] >/dev/null]; then
if [ uci -q get qos.@queue[0] >/dev/null ]; then
# return if there is any valid content
exit
else
rm -f /etc/config/qos
fi
fi
fi
touch /etc/config/qos
generate_classify
......@@ -11,7 +11,7 @@ Q_COUNT=0
SP_Q_PRIO=7
#counter variable to assign classify order value if not added in config
temp_order=1
temp_corder=1
cfg_name=""
cfg_type=""
......@@ -1042,8 +1042,8 @@ handle_classify_order() {
config_get c_order "$cid" "order"
if [ -z "$c_order" ]; then
c_order=$temp_order;
temp_order=$((temp_order + 1))
c_order=$temp_corder;
temp_corder=$((temp_corder + 1))
fi
value=${c_order}_${cid}
......@@ -1074,11 +1074,11 @@ handle_classify() {
local corder_file="/tmp/qos/classify.order"
while read -r line; do
line_cid=${line: 2}
line_cid=$(echo $line | cut -d '_' -f 2)
handle_ebtables_rules $line_cid
handle_iptables_rules $line_cid
handle_policer_rules $line_cid
handle_policer_rules $line_cid
done < "$corder_file"
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment