c4139d7381a82dbd9a1dbca073555816437b5c10
[openwrt/staging/thess.git] / package / network / config / qosify / files / qosify.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (c) 2021 OpenWrt.org
3
4 START=19
5
6 USE_PROCD=1
7 PROG=/usr/sbin/qosify
8
9 add_option() {
10 local type="$1"
11 local name="$2"
12
13 config_get val "$cfg" "$name"
14
15 [ -n "$val" ] && json_add_$type "$name" "$val"
16 }
17
18 add_defaults() {
19 cfg="$1"
20
21 json_add_boolean reset 1
22
23 config_get files "$cfg" defaults
24 json_add_array files
25 for i in $files; do
26 json_add_string "" "$i"
27 done
28 json_close_array
29
30 add_option int timeout
31 add_option string dscp_prio
32 add_option string dscp_bulk
33 add_option string dscp_icmp
34 add_option string dscp_default_udp
35 add_option string dscp_default_tcp
36 add_option int bulk_trigger_timeout
37 add_option int bulk_trigger_pps
38 add_option int prio_max_avg_pkt_len
39 }
40
41 add_interface() {
42 local cfg="$1"
43
44 config_get_bool disabled "$cfg" disabled 0
45 [ "$disabled" -gt 0 ] && return
46
47 config_get name "$cfg" name
48 json_add_object "$name"
49
50 config_get bw "$cfg" bandwidth
51
52 config_get bw_up "$cfg" bandwidth_up
53 bw_up="${bw_up:-$bw}"
54 [ -n "$bw_up" ] && json_add_string bandwidth_up "$bw_up"
55
56 config_get bw_down "$cfg" bandwidth_down
57 bw_down="${bw_down:-$bw}"
58 [ -n "$bw_down" ] && json_add_string bandwidth_down "$bw_down"
59
60 add_option string bandwidth
61 add_option boolean ingress
62 add_option boolean egress
63 add_option string mode
64 add_option boolean host_isolate
65 add_option boolean autorate_ingress
66 add_option string ingress_options
67 add_option string egress_options
68 add_option string options
69
70 json_close_object
71 }
72
73 reload_service() {
74 json_init
75
76 config_load qosify
77
78 config_foreach add_defaults defaults
79
80 json_add_object interfaces
81 config_foreach add_interface interface
82 json_close_object
83
84 json_add_object devices
85 config_foreach add_interface device
86 json_close_object
87
88 ubus call qosify config "$(json_dump)"
89 }
90
91 service_triggers() {
92 procd_add_reload_trigger qosify
93 }
94
95 start_service() {
96 procd_open_instance
97 procd_set_param command "$PROG"
98 procd_set_param respawn
99 procd_close_instance
100 }
101
102 service_started() {
103 ubus -t 10 wait_for qosify
104 [ $? = 0 ] && reload_service
105 }