qos: Handle forwarding policy tos value

This commit is contained in:
subramanianc 2023-04-10 13:48:42 +05:30
parent 9d098e087f
commit 2c1aeae4e3
5 changed files with 72 additions and 25 deletions

View file

@ -23,6 +23,13 @@ get_burst_size_per_queue() {
echo "0" 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() { configure_qos() {
# queue configuration is being done after shaper configuration, # queue configuration is being done after shaper configuration,
# If port shapingrate configuration on DISC device is called after queue configuration then # If port shapingrate configuration on DISC device is called after queue configuration then

View file

@ -180,6 +180,13 @@ iptables_set_traffic_class() {
IP_RULE="$IP_RULE -j MARK --set-xmark 0x$1/0x$1" 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() { ebt_match_ipv6_dscp() {
#when ethertype is not configured by user then both proto rules of ipv4 #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 #and ipv6 to be installed so update BR6_RULE string as well otherwise

View file

@ -1,52 +1,65 @@
#!/bin/sh #!/bin/sh
# add ip rule from qos uci # add ip rule from qos uci
IP_RULE="" FWD_POLICY=""
init_ip_rule() { init_ip_rule() {
IP_RULE="" FWD_POLICY=""
} }
ip_rule_match_inif() { ip_rule_match_inif() {
IP_RULE="$IP_RULE iif $1" FWD_POLICY="$FWD_POLICY iif $1"
} }
ip_rule_match_proto() { ip_rule_match_proto() {
IP_RULE="$IP_RULE ipproto $1" FWD_POLICY="$FWD_POLICY ipproto $1"
} }
ip_rule_match_dest_port() { ip_rule_match_dest_port() {
IP_RULE="$IP_RULE dport $1" FWD_POLICY="$FWD_POLICY dport $1"
} }
ip_rule_match_src_port() { ip_rule_match_src_port() {
IP_RULE="$IP_RULE sport $1" FWD_POLICY="$FWD_POLICY sport $1"
} }
ip_rule_match_dest_ip() { ip_rule_match_dest_ip() {
IP_RULE="$IP_RULE to $1" FWD_POLICY="$FWD_POLICY to $1"
} }
ip_rule_match_src_ip() { 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_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_match_src_port_range() {
IP_RULE="$IP_RULE sport $1-$2" FWD_POLICY="$FWD_POLICY sport $1-$2"
}
ip_rule_match_tos() {
dscp_filter=$1
tos_val=$((dscp_filter<<2))
IP_RULE="$IP_RULE tos 0x$tos_val"
} }
ip_rule_match_fwmark() { 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() { handle_ip_rule() {
@ -60,7 +73,7 @@ handle_ip_rule() {
config_get src_ip "$cid" "src_ip" config_get src_ip "$cid" "src_ip"
config_get ifname "$cid" "ifname" config_get ifname "$cid" "ifname"
config_get proto "$cid" "proto" 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 fwmark "$cid" "traffic_class"
config_get dest_port "$cid" "dest_port" config_get dest_port "$cid" "dest_port"
config_get dest_port_range "$cid" "dest_port_range" 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 ip_rule_match_src_port_range $src_port $src_port_range
fi fi
[ -n "$tos" ] && ip_rule_match_tos $tos if [ -n "$dscp" ]; then
# If tos and fwmark configured then fwmark be igroned/skipped
[ -n "$fwmark" ] && ip_rule_match_fwmark $fwmark # 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 # forming full ip rule
if [ -n "$IP_RULE" ]; then if [ -n "$FWD_POLICY" ]; then
echo "ip rule add $IP_RULE table $fwding_policy" >> /tmp/qos/classify.iprule echo "ip rule add $FWD_POLICY table $fwding_policy" >> /tmp/qos/classify.iprule
echo "ip rule del $IP_RULE table $fwding_policy" >> /tmp/qos/classify.del_iprule echo "ip rule del $FWD_POLICY table $fwding_policy" >> /tmp/qos/classify.del_iprule
fi fi
} }

View file

@ -70,10 +70,18 @@ handle_iptables_rules() {
local cid="$1" local cid="$1"
local ip_version=0 local ip_version=0
local is_l3_rule=0 local is_l3_rule=0
traffic_class=$2
init_iptables_rule 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 proto "$cid" "proto"
config_get traffic_class "$cid" "traffic_class"
config_get dscp_mark "$cid" "dscp_mark" config_get dscp_mark "$cid" "dscp_mark"
config_get dscp_filter "$cid" "dscp_filter" config_get dscp_filter "$cid" "dscp_filter"
config_get dest_port "$cid" "dest_port" config_get dest_port "$cid" "dest_port"

View file

@ -155,6 +155,12 @@ iptables_set_traffic_class() {
IP_RULE="$IP_RULE -j MARK --set-mark $1" 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() { ebt_match_ipv6_dscp() {
#when ethertype is not configured by user then both proto rules of ipv4 #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 #and ipv6 to be installed so update BR6_RULE string as well otherwise