mcproxy: update to latest version, add UCI support 74/head
authorÁlvaro Fernández Rojas <noltari@gmail.com>
Wed, 31 Dec 2014 19:40:56 +0000 (20:40 +0100)
committerÁlvaro Fernández Rojas <noltari@gmail.com>
Wed, 31 Dec 2014 20:22:02 +0000 (21:22 +0100)
Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
mcproxy/Makefile
mcproxy/files/mcproxy.conf
mcproxy/files/mcproxy.config [new file with mode: 0644]
mcproxy/files/mcproxy.init
mcproxy/patches/0004-uclibc-add-defs.patch [new file with mode: 0644]

index ef0b09e3e643f08685a997fcffcdfb6b66bbc130..cb3fb2080b8dae04db143f5b78d094d737a142d7 100644 (file)
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2006-2011 OpenWrt.org
+# Copyright (C) 2014 OpenWrt.org
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
@@ -8,8 +8,8 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=mcproxy
-PKG_SOURCE_VERSION:=6638aa9aabd2ccdde8915b61a8e0fb995b1f91a3
-PKG_VERSION:=2014-05-31-$(PKG_SOURCE_VERSION)
+PKG_SOURCE_VERSION:=b7bd2d0809a0d1f177181c361b9a6c83e193b79a
+PKG_VERSION:=2014-12-31-$(PKG_SOURCE_VERSION)
 PKG_RELEASE:=1
 
 PKG_SOURCE_PROTO:=git
@@ -40,11 +40,15 @@ endef
 
 define Package/mcproxy/conffiles
 /etc/mcproxy.conf
+/etc/config/mcproxy
 endef
 
 define Package/mcproxy/install
+       $(INSTALL_DIR) $(1)/etc
+       $(INSTALL_CONF) ./files/mcproxy.conf $(1)/etc/mcproxy.conf
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_CONF) ./files/mcproxy.config $(1)/etc/config/mcproxy
        $(INSTALL_DIR) $(1)/etc/init.d
-       $(INSTALL_CONF) ./files/mcproxy.conf $(1)/etc
        $(INSTALL_BIN) ./files/mcproxy.init $(1)/etc/init.d/mcproxy
        $(INSTALL_DIR) $(1)/usr/sbin
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/mcproxy-bin $(1)/usr/sbin/mcproxy
index 60a655e545bdd08008de6b807803d166bdb4e9ba..936cdda1773a586293fb2935a15cf385701b250d 100644 (file)
@@ -2,13 +2,67 @@
 ##-- mcproxy configuration script --##
 ######################################
 
-# Erase or comment out the following line when configured
-disable;
-
 # Protocol: IGMPv1|IGMPv2|IGMPv3 (IPv4) - MLDv1|MLDv2 (IPv6)
 protocol IGMPv3;
 
+###########################################
+
 # Proxy Instance: upstream ==> downstream
-pinstance proxy1: eth1 ==> "eth0.1";
-#pinstance proxy2: "eth0.2" ==> "br-lan";
-#pinstance proxy3: eth0 ==> eth1 eth2;
+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/mcproxy/files/mcproxy.config b/mcproxy/files/mcproxy.config
new file mode 100644 (file)
index 0000000..10cc410
--- /dev/null
@@ -0,0 +1,231 @@
+# 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 '{(*|*)}'
index 7a3303030e5b36d72ca0c8aefda41618ba894c52..a7584e890ea848cd6c5dbb580e3e6047b23e365c 100644 (file)
 #!/bin/sh /etc/rc.common
+# Copyright (C) 2014 OpenWrt.org
 
 START=50
 USE_PROCD=1
 
-start_service() {
+# mcproxy_list_iface <var> <section> <option>
+mcproxy_list_iface() {
+       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 "\"${val}\""
+               c="$(($c + 1))"
+       done
+
+       export "${1}=${_buffer}";
+}
+
+mcproxy_handle_instances() {
+       local instance="$1"
+       local conf_file="$2"
+       local disabled
+       local pre=""
+       local name
+       local upstream
+       local downstream
+
+       config_get_bool disabled "$instance" 'disabled' '0'
+       config_get name "$instance" "name" "$instance"
+       mcproxy_list_iface upstream "$instance" "upstream"
+       mcproxy_list_iface downstream "$instance" "downstream"
+
+       if [ $disabled -eq 1 ]; then
+               pre="# "
+       fi
+
+       if [ ! -z $upstream ] && [ ! -z $downstream ]; then
+               echo -e "${pre}pinstance ${name}: ${upstream} ==> ${downstream};\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 table_name
+       local table_entries
+
+       config_get table_name "$table" "name" ""
+       mcproxy_list_table table_entries "$table" "entries"
+
+       if [ ! -z $name ] && [ ! -z $table ]; then
+               echo -e "table $table_name {\n" >> $conf_file
+               echo -e "$table_entries\n" >> $conf_file
+               echo -e "};\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
+}
+
+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
+               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 /etc/mcproxy.conf
+       procd_append_param command -f $conf_file
+
+       config_get_bool aux "$cfg" 'respawn' '0'
+       [ "$aux" = 1 ] && procd_set_param respawn
 
-       procd_set_param respawn
        procd_close_instance
 }
+
+service_triggers() { 
+       procd_add_reload_trigger "mcproxy" 
+}
+
+start_service() {
+       config_load mcproxy
+       config_foreach start_instance mcproxy
+}
diff --git a/mcproxy/patches/0004-uclibc-add-defs.patch b/mcproxy/patches/0004-uclibc-add-defs.patch
new file mode 100644 (file)
index 0000000..022cb02
--- /dev/null
@@ -0,0 +1,11 @@
+--- a/mcproxy/src/utils/mc_socket.cpp
++++ b/mcproxy/src/utils/mc_socket.cpp
+@@ -38,6 +38,8 @@
+ #include <unistd.h>
+ #ifdef __UCLIBC__
++#define IP_MULTICAST_ALL 49
++
+ #include "sourcefilter.cpp"
+ #endif /* __UCLIBC__ */