igmpproxy: run in foreground for procd
[openwrt/staging/mkresin.git] / package / network / services / igmpproxy / files / igmpproxy.init
index 44f3f64c3ef3236b7603442b1dfd75af1c1ad2b0..0c30895ad610cc3a4fb570ddb2d42049cc8b9a7c 100644 (file)
@@ -6,24 +6,13 @@ USE_PROCD=1
 PROG=/usr/sbin/igmpproxy
 CONFIGFILE=/var/etc/igmpproxy.conf
 
-# igmpproxy supports both a debug mode and verbosity, which are very useful
-# when something isn't working.
-#
-# Debug mode will print everything to stdout instead of syslog. Generally
-# verbosity should NOT be set as it will quickly fill your syslog.
-#
-# Put any debug or verbosity options into IGMP_OPTS
-#
-# Examples:
-# OPTIONS="-d -v -v" - debug mode and very verbose, this will land in
-#                        stdout and not in syslog
-# OPTIONS="-v" - be verbose, this will write aditional information to syslog
-
-OPTIONS=""
-
 igmp_header() {
-       local quickleave
+       local quickleave verbose
        config_get_bool quickleave "$1" quickleave 0
+       config_get verbose "$1" verbose 0
+
+       [ $verbose = "1" ] && logopts="-v"
+       [ $verbose = "2" ] && logopts="-v -v"
 
        mkdir -p /var/etc
        rm -f /var/etc/igmpproxy.conf
@@ -39,7 +28,10 @@ igmp_add_phyint() {
        config_get direction $1 direction
        config_get altnets $1 altnet
 
-       json_load "$(ifstatus $network)"
+       local status="$(ubus -S call "network.interface.$network" status)"
+       [ -n "$status" ] || return
+
+       json_load "$status"
        json_get_var device l3_device
        json_get_var up up
 
@@ -48,6 +40,10 @@ igmp_add_phyint() {
                return;
        }
 
+       append netdevs "$device"
+
+       [[ "$direction" = "upstream" ]] && has_upstream=1
+
        echo -e "\nphyint $device $direction ratelimit 0 threshold 1" >> /var/etc/igmpproxy.conf
 
        if [ -n "$altnets" ]; then
@@ -62,19 +58,19 @@ igmp_add_network() {
        local network
 
        config_get network $1 network
-       procd_add_interface_trigger "interface.*" $network /etc/init.d/igmpproxy restart
+       procd_add_interface_trigger "interface.*" $network /etc/init.d/igmpproxy reload
 }
 
 igmp_add_firewall_routing() {
-       config_get network $1 network
        config_get direction $1 direction
+       config_get zone $1 zone
 
-       [[ "$direction" = "downstream" ]] || return 0
+       [[ "$direction" = "downstream" && ! -z "$zone" ]] || return 0
 
        json_add_object ""
        json_add_string type rule
        json_add_string src "$upstream"
-       json_add_string dest "$network"
+       json_add_string dest "$zone"
        json_add_string family ipv4
        json_add_string proto udp
        json_add_string dest_ip "224.0.0.0/4"
@@ -83,40 +79,47 @@ igmp_add_firewall_routing() {
 }
 
 igmp_add_firewall_network() {
-       config_get network $1 network
        config_get direction $1 direction
+       config_get zone $1 zone
+
+       [ ! -z "$zone" ] || return
 
        json_add_object ""
        json_add_string type rule
-       json_add_string src "$network"
+       json_add_string src "$zone"
+       json_add_string family ipv4
        json_add_string proto igmp
        json_add_string target ACCEPT
        json_close_object
 
        [[ "$direction" = "upstream" ]] && {
-               upstream="$network"
+               upstream="$zone"
                config_foreach igmp_add_firewall_routing phyint
        }
 }
 
 service_triggers() {
        procd_add_reload_trigger "igmpproxy"
+       config_foreach igmp_add_network phyint
 }
 
 start_service() {
+       has_upstream=
+       netdevs=
+       logopts=
        config_load igmpproxy
 
-       procd_open_instance
        config_foreach igmp_header igmpproxy
        config_foreach igmp_add_phyint phyint
-       procd_set_param command $PROG
-       [ -n "$OPTIONS" ] && procd_append_param $OPTIONS
+       [ -n "$has_upstream" ] || return
+
+       procd_open_instance
+       procd_set_param command $PROG '-n'
+       [ -n "$logopts" ] && procd_append_param command $logopts
        procd_append_param command $CONFIGFILE
        procd_set_param file $CONFIGFILE
+       procd_set_param netdev $netdevs
        procd_set_param respawn
-       procd_open_trigger
-       config_foreach igmp_add_network phyint
-       procd_close_trigger
 
        procd_open_data
 
@@ -132,3 +135,7 @@ start_service() {
 service_started() {
        procd_set_config_changed firewall
 }
+
+stop_service() {
+       procd_set_config_changed firewall
+}