diff --git a/qosmngr/files/airoha/lib/qos/qos.sh b/qosmngr/files/airoha/lib/qos/qos.sh index 9e58e032a..5537d3a82 100755 --- a/qosmngr/files/airoha/lib/qos/qos.sh +++ b/qosmngr/files/airoha/lib/qos/qos.sh @@ -23,6 +23,13 @@ get_burst_size_per_queue() { echo "0" } +# marking value be decimal for linux target as it uses set-mark whereas other +# targets uses set-xmark, hence this function can't make it common +ip_rule_get_converted_tos() { + con_tos=$(printf %x $1) + echo $con_tos +} + configure_qos() { # queue configuration is being done after shaper configuration, # If port shapingrate configuration on DISC device is called after queue configuration then diff --git a/qosmngr/files/broadcom/lib/qos/qos.sh b/qosmngr/files/broadcom/lib/qos/qos.sh index 6f03667f1..4465bbd7d 100755 --- a/qosmngr/files/broadcom/lib/qos/qos.sh +++ b/qosmngr/files/broadcom/lib/qos/qos.sh @@ -180,6 +180,13 @@ iptables_set_traffic_class() { IP_RULE="$IP_RULE -j MARK --set-xmark 0x$1/0x$1" } +# marking value be decimal for linux target as it uses set-mark whereas other +# targets uses set-xmark, hence this function can't make it common +ip_rule_get_converted_tos() { + con_tos=$(printf %x $1) + echo $con_tos +} + ebt_match_ipv6_dscp() { #when ethertype is not configured by user then both proto rules of ipv4 #and ipv6 to be installed so update BR6_RULE string as well otherwise diff --git a/qosmngr/files/common/lib/qos/ip_rule.sh b/qosmngr/files/common/lib/qos/ip_rule.sh index 5427d9e0f..1bcf904a0 100755 --- a/qosmngr/files/common/lib/qos/ip_rule.sh +++ b/qosmngr/files/common/lib/qos/ip_rule.sh @@ -1,52 +1,65 @@ #!/bin/sh # add ip rule from qos uci -IP_RULE="" +FWD_POLICY="" init_ip_rule() { - IP_RULE="" + FWD_POLICY="" } ip_rule_match_inif() { - IP_RULE="$IP_RULE iif $1" + FWD_POLICY="$FWD_POLICY iif $1" } ip_rule_match_proto() { - IP_RULE="$IP_RULE ipproto $1" + FWD_POLICY="$FWD_POLICY ipproto $1" } ip_rule_match_dest_port() { - IP_RULE="$IP_RULE dport $1" + FWD_POLICY="$FWD_POLICY dport $1" } ip_rule_match_src_port() { - IP_RULE="$IP_RULE sport $1" + FWD_POLICY="$FWD_POLICY sport $1" } ip_rule_match_dest_ip() { - IP_RULE="$IP_RULE to $1" + FWD_POLICY="$FWD_POLICY to $1" } ip_rule_match_src_ip() { - IP_RULE="$IP_RULE from $1" + FWD_POLICY="$FWD_POLICY from $1" } ip_rule_match_dest_port_range() { - IP_RULE="$IP_RULE dport $1-$2" + FWD_POLICY="$FWD_POLICY dport $1-$2" } ip_rule_match_src_port_range() { - IP_RULE="$IP_RULE sport $1-$2" -} - -ip_rule_match_tos() { - dscp_filter=$1 - tos_val=$((dscp_filter<<2)) - IP_RULE="$IP_RULE tos 0x$tos_val" + FWD_POLICY="$FWD_POLICY sport $1-$2" } ip_rule_match_fwmark() { - IP_RULE="$IP_RULE fwmark $1" + FWD_POLICY="$FWD_POLICY fwmark $1" +} + +ip_rule_handle_match_tos() { + local dscp="$2" + local IPTOS_LOWDELAY="0x10" + local tos_val="$((dscp<<2))" + + # ip rule not accept beyond 0x10, to handle further value mark the tos + # value through iptable and route with that marked value by fwmark + # in ip rule + if [ "$((tos_val))" -gt "$((IPTOS_LOWDELAY))" ]; then + handle_iptables_rules $1 $(ip_rule_get_converted_tos $tos_val) + ip_rule_match_fwmark $(printf 0x%x $tos_val) + else + FWD_POLICY="$FWD_POLICY tos $(printf %x $tos_val)" + if [ -n "$3" ]; then + ip_rule_match_fwmark $3 + fi + fi } handle_ip_rule() { @@ -60,7 +73,7 @@ handle_ip_rule() { config_get src_ip "$cid" "src_ip" config_get ifname "$cid" "ifname" config_get proto "$cid" "proto" - config_get tos "$cid" "dscp_filter" + config_get dscp "$cid" "dscp_filter" config_get fwmark "$cid" "traffic_class" config_get dest_port "$cid" "dest_port" config_get dest_port_range "$cid" "dest_port_range" @@ -92,14 +105,20 @@ handle_ip_rule() { ip_rule_match_src_port_range $src_port $src_port_range fi - [ -n "$tos" ] && ip_rule_match_tos $tos - - [ -n "$fwmark" ] && ip_rule_match_fwmark $fwmark + if [ -n "$dscp" ]; then + # If tos and fwmark configured then fwmark be igroned/skipped + # in the case of tos value greater than 0x10 and if tos value + # less than 0x10 then both tos and fwmark then both configuration + #considered/applied for ip rule. + ip_rule_handle_match_tos $cid $dscp $fwmark + elif [ -n "$fwmark" ]; then + ip_rule_match_fwmark $fwmark + fi # forming full ip rule - if [ -n "$IP_RULE" ]; then - echo "ip rule add $IP_RULE table $fwding_policy" >> /tmp/qos/classify.iprule - echo "ip rule del $IP_RULE table $fwding_policy" >> /tmp/qos/classify.del_iprule + if [ -n "$FWD_POLICY" ]; then + echo "ip rule add $FWD_POLICY table $fwding_policy" >> /tmp/qos/classify.iprule + echo "ip rule del $FWD_POLICY table $fwding_policy" >> /tmp/qos/classify.del_iprule fi } diff --git a/qosmngr/files/common/lib/qos/iptables.sh b/qosmngr/files/common/lib/qos/iptables.sh index ad8535a33..a5e42e51c 100755 --- a/qosmngr/files/common/lib/qos/iptables.sh +++ b/qosmngr/files/common/lib/qos/iptables.sh @@ -70,10 +70,18 @@ handle_iptables_rules() { local cid="$1" local ip_version=0 local is_l3_rule=0 + traffic_class=$2 init_iptables_rule + + # If traffic class non empty/zero then function call for handling fowrwarding + # policy in the case of tos greater than 0x10. + # In this case, traffic class should not be read from config and use value in arg + if [ -z "$traffic_class" ]; then + config_get traffic_class "$cid" "traffic_class" + fi + config_get proto "$cid" "proto" - config_get traffic_class "$cid" "traffic_class" config_get dscp_mark "$cid" "dscp_mark" config_get dscp_filter "$cid" "dscp_filter" config_get dest_port "$cid" "dest_port" diff --git a/qosmngr/files/linux/lib/qos/qos.sh b/qosmngr/files/linux/lib/qos/qos.sh index 5e5b1e527..4509bb4f9 100755 --- a/qosmngr/files/linux/lib/qos/qos.sh +++ b/qosmngr/files/linux/lib/qos/qos.sh @@ -155,6 +155,12 @@ iptables_set_traffic_class() { IP_RULE="$IP_RULE -j MARK --set-mark $1" } +# marking value be decimal for linux target as it uses set-mark whereas other +# targets uses set-xmark, hence this function can't make it common +ip_rule_get_converted_tos() { + echo $1 +} + ebt_match_ipv6_dscp() { #when ethertype is not configured by user then both proto rules of ipv4 #and ipv6 to be installed so update BR6_RULE string as well otherwise