igmpproxy: fix spurious restarts on interface events, pass used netdevs to procd...
[openwrt/staging/mkresin.git] / package / network / services / igmpproxy / files / igmpproxy.init
index 44f3f64c3ef3236b7603442b1dfd75af1c1ad2b0..d03f90f0c870b628303aa6e5edbd85bcf0089ec9 100644 (file)
@@ -39,7 +39,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 +51,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,7 +69,7 @@ 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() {
@@ -104,15 +111,20 @@ service_triggers() {
 }
 
 start_service() {
+       has_upstream=
+       netdevs=
        config_load igmpproxy
 
-       procd_open_instance
        config_foreach igmp_header igmpproxy
        config_foreach igmp_add_phyint phyint
+       [ -n "$has_upstream" ] || return
+
+       procd_open_instance
        procd_set_param command $PROG
        [ -n "$OPTIONS" ] && procd_append_param $OPTIONS
        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