75d111f3c06657d4a3b9cfad8629701ac1c43534
[librecmc/librecmc.git] / package / network / services / igmpproxy / files / igmpproxy.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2010-2014 OpenWrt.org
3
4 START=99
5 USE_PROCD=1
6 PROG=/usr/sbin/igmpproxy
7 CONFIGFILE=/var/etc/igmpproxy.conf
8
9 # igmpproxy supports both a debug mode and verbosity, which are very useful
10 # when something isn't working.
11 #
12 # Debug mode will print everything to stdout instead of syslog. Generally
13 # verbosity should NOT be set as it will quickly fill your syslog.
14 #
15 # Put any debug or verbosity options into IGMP_OPTS
16 #
17 # Examples:
18 # OPTIONS="-d -v -v" - debug mode and very verbose, this will land in
19 #                        stdout and not in syslog
20 # OPTIONS="-v" - be verbose, this will write aditional information to syslog
21
22 OPTIONS=""
23 UPSTREAM=0
24
25 igmp_header() {
26         local quickleave
27         config_get_bool quickleave "$1" quickleave 0
28
29         mkdir -p /var/etc
30         rm -f /var/etc/igmpproxy.conf
31         [ $quickleave -gt 0 ] && echo "quickleave" >> /var/etc/igmpproxy.conf
32
33         [ -L /etc/igmpproxy.conf ] || ln -nsf /var/etc/igmpproxy.conf /etc/igmpproxy.conf
34 }
35
36 igmp_add_phyint() {
37         local network direction altnets device up
38
39         config_get network $1 network
40         config_get direction $1 direction
41         config_get altnets $1 altnet
42
43         json_load "$(ifstatus $network)"
44         json_get_var device l3_device
45         json_get_var up up
46         [ -n "$device" -a "$up" = "1" ] || return;
47
48         UPSTREAM=1
49
50         echo -e "\nphyint $device $direction ratelimit 0 threshold 1" >> /var/etc/igmpproxy.conf
51
52         if [ -n "$altnets" ]; then
53                 local altnet
54                 for altnet in $altnets; do
55                         echo -e "\taltnet $altnet" >> /var/etc/igmpproxy.conf
56                 done
57         fi
58 }
59
60 service_triggers() {
61         procd_add_reload_trigger "igmpproxy"
62 }
63
64 start_service() {
65         config_load igmpproxy
66
67         config_foreach igmp_header igmpproxy
68         config_foreach igmp_add_phyint phyint
69
70         [ $UPSTREAM = 1 ] || return
71
72         procd_open_instance
73         procd_set_param command $PROG
74         [ -n "$OPTIONS" ] && procd_append_param $OPTIONS
75         procd_append_param command $CONFIGFILE
76         procd_set_param file $CONFIGFILE
77         procd_set_param respawn
78         procd_close_instance
79 }