blob: f676d92a52e4f87275f9000d5955aa28e9d1820e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
#!/bin/sh /etc/rc.common
# Copyright (c) 2021 OpenWrt.org
START=19
USE_PROCD=1
PROG=/usr/sbin/qosify
add_option() {
local type="$1"
local name="$2"
config_get val "$cfg" "$name"
[ -n "$val" ] && json_add_$type "$name" "$val"
}
add_flow_config() {
local cfg="$1"
add_option string dscp_prio
add_option string dscp_bulk
add_option int bulk_trigger_timeout
add_option int bulk_trigger_pps
add_option int prio_max_avg_pkt_len
}
add_defaults() {
cfg="$1"
json_add_boolean reset 1
config_get files "$cfg" defaults
json_add_array files
for i in $files; do
json_add_string "" "$i"
done
json_close_array
add_flow_config "$cfg"
add_option int timeout
add_option string dscp_icmp
add_option string dscp_default_udp
add_option string dscp_default_tcp
}
add_interface() {
local cfg="$1"
config_get_bool disabled "$cfg" disabled 0
[ "$disabled" -gt 0 ] && return
config_get name "$cfg" name
json_add_object "$name"
config_get bw "$cfg" bandwidth
config_get bw_up "$cfg" bandwidth_up
bw_up="${bw_up:-$bw}"
[ -n "$bw_up" ] && json_add_string bandwidth_up "$bw_up"
config_get bw_down "$cfg" bandwidth_down
bw_down="${bw_down:-$bw}"
[ -n "$bw_down" ] && json_add_string bandwidth_down "$bw_down"
add_option string bandwidth
add_option boolean ingress
add_option boolean egress
add_option string mode
add_option boolean nat
add_option boolean host_isolate
add_option boolean autorate_ingress
add_option string ingress_options
add_option string egress_options
config_get user_options "$cfg" options
config_get otype "$cfg" overhead_type
options=
case "$otype" in
none);;
manual)
config_get overhead "$cfg" overhead
[ -n "$overhead" ] && append options "overhead $overhead"
config_get encap "$cfg" overhead_encap
[ -n "$encap" ] && append options "$encap"
;;
conservative|\
pppoa-vcmux|\
pppoa-llc|\
pppoe-vcmux|\
pppoe-llcsnap|\
bridged-vcmux|\
bridged-llcsnap|\
ipoa-vcmux|\
ipoa-llcsnap|\
pppoe-ptm|\
bridged-ptm|\
docsis|\
ethernet)
append options "$otype"
;;
esac
config_get mpu "$cfg" overhead_mpu
[ -n "$mpu" ] && append options "mpu $mpu"
config_get ovlan "$cfg" overhead_vlan
[ "${ovlan:-0}" -ge 2 ] && append options "ether-vlan"
[ "${ovlan:-0}" -ge 1 ] && append options "ether-vlan"
[ -n "$user_options" ] && append options "$user_options"
[ -n "$options" ] && json_add_string options "$options"
json_close_object
}
add_class() {
local cfg="$1"
config_get value "$cfg" value
config_get ingress "$cfg" ingress
config_get egress "$cfg" egress
json_add_object "$cfg"
json_add_string ingress "${ingress:-$value}"
json_add_string egress "${egress:-$value}"
add_flow_config "$cfg"
json_close_object
}
reload_service() {
json_init
config_load qosify
config_foreach add_defaults defaults
json_add_object interfaces
config_foreach add_interface interface
json_close_object
json_add_object classes
config_foreach add_class class
config_foreach add_class alias
json_close_object
json_add_object devices
config_foreach add_interface device
json_close_object
ubus call qosify config "$(json_dump)"
}
service_triggers() {
procd_add_reload_trigger qosify
}
start_service() {
procd_open_instance
procd_set_param command "$PROG"
procd_set_param respawn
procd_close_instance
}
service_started() {
ubus -t 10 wait_for qosify
[ $? = 0 ] && reload_service
}
|