mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
110 lines
2.3 KiB
Bash
110 lines
2.3 KiB
Bash
#!/bin/sh
|
|
# add ip rule from qos uci
|
|
|
|
IP_RULE=""
|
|
|
|
init_ip_rule() {
|
|
IP_RULE=""
|
|
}
|
|
|
|
ip_rule_match_inif() {
|
|
IP_RULE="$IP_RULE iif $1"
|
|
}
|
|
|
|
ip_rule_match_proto() {
|
|
IP_RULE="$IP_RULE ipproto $1"
|
|
}
|
|
|
|
ip_rule_match_dest_port() {
|
|
IP_RULE="$IP_RULE dport $1"
|
|
}
|
|
|
|
ip_rule_match_src_port() {
|
|
IP_RULE="$IP_RULE sport $1"
|
|
}
|
|
|
|
ip_rule_match_dest_ip() {
|
|
IP_RULE="$IP_RULE to $1"
|
|
}
|
|
|
|
ip_rule_match_src_ip() {
|
|
IP_RULE="$IP_RULE from $1"
|
|
}
|
|
|
|
ip_rule_match_dest_port_range() {
|
|
IP_RULE="$IP_RULE dport $1-$2"
|
|
}
|
|
|
|
ip_rule_match_src_port_range() {
|
|
IP_RULE="$IP_RULE sport $1-$2"
|
|
}
|
|
|
|
ip_rule_match_tos() {
|
|
IP_RULE="$IP_RULE tos $1"
|
|
}
|
|
|
|
ip_rule_match_fwmark() {
|
|
IP_RULE="$IP_RULE fwmark $1"
|
|
}
|
|
|
|
handle_ip_rule() {
|
|
cid=$1
|
|
fwding_policy=$2
|
|
|
|
init_ip_rule
|
|
|
|
# get uci value for selector/match
|
|
config_get dest_ip "$cid" "dest_ip"
|
|
config_get src_ip "$cid" "src_ip"
|
|
config_get ifname "$cid" "ifname"
|
|
config_get proto "$cid" "proto"
|
|
config_get tos "$cid" "dscp_check"
|
|
config_get fwmark "$cid" "traffic_class"
|
|
config_get dest_port "$cid" "dest_port"
|
|
config_get dest_port_range "$cid" "dest_port_range"
|
|
config_get src_port "$cid" "src_port"
|
|
config_get src_port_range "$cid" "src_port_range"
|
|
|
|
# forming selector/match for rule
|
|
[ -n "$ifname" ] && ip_rule_match_inif $ifname
|
|
|
|
[ -n "$proto" ] && ip_rule_match_proto $proto
|
|
|
|
if [ -n "$src_port" -a -z "$src_port_range" ]; then
|
|
ip_rule_match_src_port $src_port
|
|
fi
|
|
|
|
if [ -n "$dest_port" -a -z "$dest_port_range" ]; then
|
|
ip_rule_match_dest_port $dest_port
|
|
fi
|
|
|
|
[ -n "$src_ip" ] && ip_rule_match_src_ip $src_ip
|
|
|
|
[ -n "$dest_ip" ] && ip_rule_match_dest_ip $dest_ip
|
|
|
|
if [ -n "$dest_port" -a -n "$dest_port_range" ]; then
|
|
ip_rule_match_dest_port_range $dest_port $dest_port_range
|
|
fi
|
|
|
|
if [ -n "$src_port" -a -n "$src_port_range" ]; then
|
|
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
|
|
|
|
# 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
|
|
fi
|
|
}
|
|
|
|
flush_ip_rule() {
|
|
if [ -s "/tmp/qos/classify.del_iprule" ]; then
|
|
sh /tmp/qos/classify.del_iprule
|
|
rm -f /tmp/qos/classify.del_iprule
|
|
fi
|
|
touch /tmp/qos/classify.del_iprule
|
|
}
|