1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2014-2015 OpenWrt.org
7 mcproxy_handle_instances
() {
16 config_get_bool disabled
"$instance" 'disabled' '0'
17 config_get name
"$instance" "name" "$instance"
18 config_get upstreams
"$instance" "upstream"
19 config_get downstreams
"$instance" "downstream"
21 if [ $disabled -eq 1 ]; then
26 if [ -n "$upstreams" ]; then
28 for upstream
in $upstreams; do
29 str_up
="$str_up \"$upstream\""
34 if [ -n "$downstreams" ]; then
36 for downstream
in $downstreams; do
37 str_down
="$str_down \"$downstream\""
41 if [ ! -z $downstream ]; then
42 echo -e "${pre}pinstance ${name}:${str_up} ==>${str_down};\n" >> $conf_file
46 # mcproxy_list_table <var> <section> <option>
47 mcproxy_list_table
() {
53 config_get len
"$2" "${3}_LENGTH"
54 [ -z "$len" ] && return 0
55 while [ $c -le "$len" ]; do
56 config_get val
"$2" "${3}_ITEM$c"
57 append _buffer
"\t${val}\n"
61 export "${1}=${_buffer}";
64 mcproxy_handle_tables
() {
70 config_get name
"$table" "name" ""
71 mcproxy_list_table entries
"$table" "entries"
73 if [ ! -z $name ] && [ ! -z $table ]; then
74 echo -e "table $name {\n${entries}};\n" >> $conf_file
78 mcproxy_handle_behaviour
() {
90 config_get_bool disabled
"$behaviour" 'disabled' '0'
91 config_get instance
"$behaviour" "instance"
92 config_get section
"$behaviour" "section" "upstream"
93 config_get interface
"$behaviour" "interface" "*"
94 config_get direction
"$behaviour" "direction" "in"
95 config_get rulematching
"$behaviour" "rulematching"
96 config_get table
"$behaviour" "table"
98 if [ -z $instance ]; then
103 if [ ! -z $rulematching ]; then
104 rule_table
="rulematching $rulematching"
105 elif [ ! -z $table ]; then
109 config_get_bool whitelist
"$behaviour" 'whitelist' '0'
110 if [ $whitelist -eq 1 ]; then
116 rule_table
="$list table $table"
118 rule_table
="rulematching all"
121 if [ $disabled -eq 1 ]; then
125 echo -e "${pre}pinstance $instance $section \"$interface\" $direction $rule_table;\n" >> $conf_file
128 mcproxy_network_trigger
() {
129 procd_add_interface_trigger
"interface.*" "$1" /etc
/init.d
/mcproxy restart
131 mcproxy_handle_network
() {
134 config_list_foreach
"$instance" upstream mcproxy_network_trigger
135 config_list_foreach
"$instance" downstream mcproxy_network_trigger
143 config_get_bool aux
"$cfg" 'disabled' '0'
144 [ "$aux" = 1 ] && return 1
146 config_get conf_file
"$cfg" "file"
147 if [ ! -n "$conf_file" ]; then
149 conf_file
="/var/etc/mcproxy_${cfg}.conf"
152 config_get protocol
"$cfg" "protocol" "IGMPv3"
153 echo -e "protocol ${protocol};\n" > $conf_file
155 config_foreach mcproxy_handle_instances instance
$conf_file
156 config_foreach mcproxy_handle_tables table
$conf_file
157 config_foreach mcproxy_handle_behaviour behaviour
$conf_file
162 procd_set_param
command /usr
/sbin
/mcproxy
163 procd_append_param
command -f $conf_file
165 config_get_bool aux
"$cfg" 'respawn' '0'
166 [ "$aux" = 1 ] && procd_set_param respawn
169 config_foreach mcproxy_handle_network instance
177 procd_add_config_trigger
"config.change" "mcproxy" /etc
/init.d
/mcproxy restart
183 config_foreach start_instance mcproxy