ASR_BASE
Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/external/routing/mcproxy/files/mcproxy.conf b/external/routing/mcproxy/files/mcproxy.conf
new file mode 100644
index 0000000..936cdda
--- /dev/null
+++ b/external/routing/mcproxy/files/mcproxy.conf
@@ -0,0 +1,68 @@
+######################################
+##-- mcproxy configuration script --##
+######################################
+
+# Protocol: IGMPv1|IGMPv2|IGMPv3 (IPv4) - MLDv1|MLDv2 (IPv6)
+protocol IGMPv3;
+
+###########################################
+
+# Proxy Instance: upstream ==> downstream
+pinstance A: ap a1 ==> ap a2;
+pinstance B: bp b1 ==> bp b2;
+
+###########################################
+
+# Tables
+table allways {
+ (*|*)
+};
+
+table piA_peering_ifs {
+ ap(*|*)
+};
+
+table piA_upstreams {
+ a1(*|*)
+};
+
+table piB_peering_ifs {
+ bp(*|*)
+};
+
+table piB_upstreams {
+ b1(*|*)
+};
+
+###########################################
+
+# Instance Behaviour
+pinstance A upstream * in rulematching mutex 10; #or 25ms (u4)
+#pinstance A upstream * out rulematching all; #default
+
+pinstance A upstream ap out blacklist table allways; #(u1)
+#pinstance A upstream ap in whitelist table {(*|*)}; #default (u2, u3)
+
+pinstance A upstream a1 out blacklist table piA_peering_ifs; #(u3_1)
+#pinstance A upstream a1 in whitelist table {(*|*)}; #default
+
+pinstance A downstream ap in blacklist table allways; #(d1)
+pinstance A downstream ap out blacklist table piA_upstreams; #(d2, d2_1, d3, d4)
+
+#pinstance A downstream a2 in whitelist table {(*|*)}; #default
+#pinstance A downstream a2 out whitelist table {(*|*)}; #default
+
+pinstance B upstream * in rulematching mutex 10; #or 25ms (u4)
+#pinstance B upstream * out rulematching all; #default
+
+pinstance B upstream bp out blacklist table allways; #(u1)
+#pinstance B upstream bp in whitelist table {(*|*)}; #default (u2, u3)
+
+pinstance B upstream b1 out blacklist table piB_peering_ifs; #(u3_1)
+#pinstance b upstream b1 in whitelist table {(*|*)}; #default
+
+pinstance B downstream bp in blacklist table allways; #(d1)
+pinstance B downstream bp out blacklist table piB_upstreams; #(d2, d2_1, d3, d4)
+
+#pinstance B downstream b2 in whitelist table {(*|*)}; #default
+#pinstance B downstream b2 out whitelist table {(*|*)}; #default
diff --git a/external/routing/mcproxy/files/mcproxy.config b/external/routing/mcproxy/files/mcproxy.config
new file mode 100644
index 0000000..f028795
--- /dev/null
+++ b/external/routing/mcproxy/files/mcproxy.config
@@ -0,0 +1,239 @@
+# Use your own MCProxy config file
+config mcproxy 'mcproxy_file'
+ option disabled '1'
+ option respawn '1'
+ option file '/etc/mcproxy.conf'
+
+# Use OpenWrt UCI config
+config mcproxy 'mcproxy'
+ option disabled '1'
+ option respawn '1'
+ option protocol 'IGMPv3'
+
+###########################################
+
+# Simple configuration examples
+
+config instance
+ option disabled '1'
+ option name 'proxy1'
+ list upstream 'eth1'
+ list downstream 'eth0.2'
+
+config instance
+ option disabled '1'
+ option name 'proxy2'
+ list upstream 'eth0.2'
+ list downstream 'eth0.4'
+ list downstream 'br-lan'
+
+config instance
+ option disabled '1'
+ option name 'proxy3'
+ list upstream 'eth1.2'
+ list upstream 'eth1.4'
+ list downstream 'eth0.1'
+
+###########################################
+
+# Advanced configuration example
+
+config instance
+ option name 'A'
+ list upstream 'ap'
+ list upstream 'a1'
+ list downstream 'ap'
+ list downstream 'a2'
+
+config instance
+ option name 'B'
+ list upstream 'bp'
+ list upstream 'b1'
+ list downstream 'bp'
+ list downstream 'b2'
+
+config table
+ option name 'allways'
+ list entries '(*|*)'
+
+config table
+ option name 'piA_peering_ifs'
+ list entries 'ap(*|*)'
+
+config table
+ option name 'piA_upstreams'
+ list entries 'a1(*|*)'
+
+config table
+ option name 'piB_peering_ifs'
+ list entries 'bp(*|*)'
+
+config table
+ option name 'piB_upstreams'
+ list entries 'b1(*|*)'
+
+config behaviour
+ option instance 'A'
+ option section 'upstream'
+ option interface '*'
+ option direction 'in'
+ option rulematching 'mutex 10'
+
+config behaviour
+ option disabled '1'
+ option instance 'A'
+ option section 'upstream'
+ option interface '*'
+ option direction 'out'
+ option rulematching 'all'
+
+config behaviour
+ option instance 'A'
+ option section 'upstream'
+ option interface 'ap'
+ option direction 'out'
+ option table 'allways'
+
+config behaviour
+ option disabled '1'
+ option instance 'A'
+ option section 'upstream'
+ option interface 'ap'
+ option direction 'in'
+ option whitelist '1'
+ option table '{(*|*)}'
+
+config behaviour
+ option instance 'A'
+ option section 'upstream'
+ option interface 'a1'
+ option direction 'out'
+ option table 'piA_peering_ifs'
+
+config behaviour
+ option disabled '1'
+ option instance 'A'
+ option section 'upstream'
+ option interface 'a1'
+ option direction 'in'
+ option whitelist '1'
+ option table '{(*|*)}'
+
+config behaviour
+ option instance 'A'
+ option section 'downstream'
+ option interface 'ap'
+ option direction 'in'
+ option table 'allways'
+
+config behaviour
+ option instance 'A'
+ option section 'downstream'
+ option interface 'ap'
+ option direction 'out'
+ option table 'piA_upstreams'
+
+config behaviour
+ option disabled '1'
+ option instance 'A'
+ option section 'downstream'
+ option interface 'a2'
+ option direction 'in'
+ option whitelist '1'
+ option table '{(*|*)}'
+
+config behaviour
+ option disabled '1'
+ option instance 'A'
+ option section 'downstream'
+ option interface 'a2'
+ option direction 'out'
+ option whitelist '1'
+ option table '{(*|*)}'
+
+config behaviour
+ option instance 'B'
+ option section 'upstream'
+ option interface '*'
+ option direction 'in'
+ option rulematching 'mutex 10'
+
+config behaviour
+ option disabled '1'
+ option instance 'B'
+ option section 'upstream'
+ option interface '*'
+ option direction 'out'
+ option rulematching 'all'
+
+config behaviour
+ option instance 'B'
+ option section 'upstream'
+ option interface 'bp'
+ option direction 'out'
+ option table 'allways'
+
+config behaviour
+ option disabled '1'
+ option instance 'B'
+ option section 'upstream'
+ option interface 'bp'
+ option direction 'in'
+ option whitelist '1'
+ option table '{(*|*)}'
+
+config behaviour
+ option instance 'B'
+ option section 'upstream'
+ option interface 'b1'
+ option direction 'out'
+ option table 'piB_peering_ifs'
+
+config behaviour
+ option disabled '1'
+ option instance 'B'
+ option section 'upstream'
+ option interface 'b1'
+ option direction 'in'
+ option whitelist '1'
+ option table '{(*|*)}'
+
+config behaviour
+ option instance 'B'
+ option section 'downstream'
+ option interface 'bp'
+ option direction 'in'
+ option table 'allways'
+
+config behaviour
+ option instance 'B'
+ option section 'downstream'
+ option interface 'bp'
+ option direction 'out'
+ option table 'piB_upstreams'
+
+config behaviour
+ option disabled '1'
+ option instance 'B'
+ option section 'downstream'
+ option interface 'b2'
+ option direction 'in'
+ option whitelist '1'
+ option table '{(*|*)}'
+
+config behaviour
+ option disabled '1'
+ option instance 'B'
+ option section 'downstream'
+ option interface 'b2'
+ option direction 'out'
+ option whitelist '1'
+ option table '{(*|*)}'
+
+config blocks blocks
+ # mDNS
+ list entries '(*|239.255.255.0/24)'
+ # SSDP
+ list entries '(*|224.0.0.0/24)'
+ # SLP
+ list entries '(*|239.192.0.0/16)'
diff --git a/external/routing/mcproxy/files/mcproxy.init b/external/routing/mcproxy/files/mcproxy.init
new file mode 100644
index 0000000..60e4c87
--- /dev/null
+++ b/external/routing/mcproxy/files/mcproxy.init
@@ -0,0 +1,184 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2014-2015 OpenWrt.org
+
+START=99
+USE_PROCD=1
+
+mcproxy_handle_instances() {
+ local instance="$1"
+ local conf_file="$2"
+ local disabled
+ local pre=""
+ local name
+ local upstreams
+ local downstreams
+
+ config_get_bool disabled "$instance" 'disabled' '0'
+ config_get name "$instance" "name" "$instance"
+ config_get upstreams "$instance" "upstream"
+ config_get downstreams "$instance" "downstream"
+
+ if [ $disabled -eq 1 ]; then
+ pre="# "
+ fi
+
+ local str_up=""
+ if [ -n "$upstreams" ]; then
+ local upstream
+ for upstream in $upstreams; do
+ str_up="$str_up \"$upstream\""
+ done
+ fi
+
+ local str_down=""
+ if [ -n "$downstreams" ]; then
+ local downstream
+ for downstream in $downstreams; do
+ str_down="$str_down \"$downstream\""
+ done
+ fi
+
+ if [ ! -z $downstream ]; then
+ echo -e "${pre}pinstance ${name}:${str_up} ==>${str_down};\n" >> $conf_file
+ fi
+}
+
+# mcproxy_list_table <var> <section> <option>
+mcproxy_list_table() {
+ local val
+ local len
+ local _buffer
+ local c=1
+
+ config_get len "$2" "${3}_LENGTH"
+ [ -z "$len" ] && return 0
+ while [ $c -le "$len" ]; do
+ config_get val "$2" "${3}_ITEM$c"
+ append _buffer "\t${val}\n"
+ c="$(($c + 1))"
+ done
+
+ export "${1}=${_buffer}";
+}
+
+mcproxy_handle_tables() {
+ local table="$1"
+ local conf_file="$2"
+ local name
+ local entries
+
+ config_get name "$table" "name" ""
+ mcproxy_list_table entries "$table" "entries"
+
+ if [ ! -z $name ] && [ ! -z $table ]; then
+ echo -e "table $name {\n${entries}};\n" >> $conf_file
+ fi
+}
+
+mcproxy_handle_behaviour() {
+ local behaviour="$1"
+ local conf_file="$2"
+ local disabled
+ local pre=""
+ local instance
+ local section
+ local interface
+ local direction
+ local rulematching
+ local table
+
+ config_get_bool disabled "$behaviour" 'disabled' '0'
+ config_get instance "$behaviour" "instance"
+ config_get section "$behaviour" "section" "upstream"
+ config_get interface "$behaviour" "interface" "*"
+ config_get direction "$behaviour" "direction" "in"
+ config_get rulematching "$behaviour" "rulematching"
+ config_get table "$behaviour" "table"
+
+ if [ -z $instance ]; then
+ return 1
+ fi
+
+ local rule_table
+ if [ ! -z $rulematching ]; then
+ rule_table="rulematching $rulematching"
+ elif [ ! -z $table ]; then
+ local whitelist
+ local list
+
+ config_get_bool whitelist "$behaviour" 'whitelist' '0'
+ if [ $whitelist -eq 1 ]; then
+ list="whitelist"
+ else
+ list="blacklist"
+ fi
+
+ rule_table="$list table $table"
+ else
+ rule_table="rulematching all"
+ fi
+
+ if [ $disabled -eq 1 ]; then
+ pre="# "
+ fi
+
+ echo -e "${pre}pinstance $instance $section \"$interface\" $direction $rule_table;\n" >> $conf_file
+}
+
+mcproxy_network_trigger() {
+ procd_add_interface_trigger "interface.*" "$1" /etc/init.d/mcproxy restart
+}
+mcproxy_handle_network() {
+ local instance="$1"
+
+ config_list_foreach "$instance" upstream mcproxy_network_trigger
+ config_list_foreach "$instance" downstream mcproxy_network_trigger
+}
+
+start_instance() {
+ local cfg="$1"
+ local aux
+ local conf_file
+
+ config_get_bool aux "$cfg" 'disabled' '0'
+ [ "$aux" = 1 ] && return 1
+
+ config_get conf_file "$cfg" "file"
+ if [ ! -n "$conf_file" ]; then
+ mkdir -p /var/etc
+ conf_file="/var/etc/mcproxy_${cfg}.conf"
+
+ local protocol
+ config_get protocol "$cfg" "protocol" "IGMPv3"
+ echo -e "protocol ${protocol};\n" > $conf_file
+
+ config_foreach mcproxy_handle_instances instance $conf_file
+ config_foreach mcproxy_handle_tables table $conf_file
+ config_foreach mcproxy_handle_behaviour behaviour $conf_file
+ fi
+
+ procd_open_instance
+
+ procd_set_param command /usr/sbin/mcproxy
+ procd_append_param command -f $conf_file
+
+ config_get_bool aux "$cfg" 'respawn' '0'
+ [ "$aux" = 1 ] && procd_set_param respawn
+
+ procd_open_trigger
+ config_foreach mcproxy_handle_network instance
+ procd_close_trigger
+
+ procd_close_instance
+}
+
+service_triggers() {
+ procd_open_trigger
+ procd_add_config_trigger "config.change" "mcproxy" /etc/init.d/mcproxy restart
+ procd_close_trigger
+}
+
+start_service() {
+ config_load mcproxy
+ config_foreach start_instance mcproxy
+}