ramips: add support for ELECOM WRC-1750GST2
[openwrt/openwrt.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 igmp_header() {
10 local quickleave verbose
11 config_get_bool quickleave "$1" quickleave 0
12 config_get verbose "$1" verbose 1
13
14 [ $verbose = "0" ] && logopts="-d"
15 [ $verbose = "2" ] && logopts="-v"
16 [ $verbose = "3" ] && logopts="-v -v"
17
18 mkdir -p /var/etc
19 rm -f /var/etc/igmpproxy.conf
20 [ $quickleave -gt 0 ] && echo "quickleave" >> /var/etc/igmpproxy.conf
21
22 [ -L /etc/igmpproxy.conf ] || ln -nsf /var/etc/igmpproxy.conf /etc/igmpproxy.conf
23 }
24
25 igmp_add_phyint() {
26 local network direction altnets device up
27
28 config_get network $1 network
29 config_get direction $1 direction
30 config_get altnets $1 altnet
31
32 local status="$(ubus -S call "network.interface.$network" status)"
33 [ -n "$status" ] || return
34
35 json_load "$status"
36 json_get_var device l3_device
37 json_get_var up up
38
39 [ -n "$device" -a "$up" = "1" ] || {
40 procd_append_param error "$network is not up"
41 return;
42 }
43
44 append netdevs "$device"
45
46 [ "$direction" = "upstream" ] && has_upstream=1
47
48 echo -e "\nphyint $device $direction ratelimit 0 threshold 1" >> /var/etc/igmpproxy.conf
49
50 if [ -n "$altnets" ]; then
51 local altnet
52 for altnet in $altnets; do
53 echo -e "\taltnet $altnet" >> /var/etc/igmpproxy.conf
54 done
55 fi
56 }
57
58 igmp_add_network() {
59 local network
60
61 config_get network $1 network
62 procd_add_interface_trigger "interface.*" $network /etc/init.d/igmpproxy reload
63 }
64
65 igmp_add_firewall_routing() {
66 config_get direction $1 direction
67 config_get zone $1 zone
68
69 if [ "$direction" != "downstream" ] || [ -z "$zone" ]; then
70 return 0
71 fi
72
73 # First drop SSDP packets then accept all other multicast
74
75 json_add_object ""
76 json_add_string type rule
77 json_add_string src "$upstream"
78 json_add_string dest "$zone"
79 json_add_string family ipv4
80 json_add_string proto udp
81 json_add_string dest_ip "239.255.255.250"
82 json_add_string target DROP
83 json_close_object
84
85 json_add_object ""
86 json_add_string type rule
87 json_add_string src "$upstream"
88 json_add_string dest "$zone"
89 json_add_string family ipv4
90 json_add_string proto udp
91 json_add_string dest_ip "224.0.0.0/4"
92 json_add_string target ACCEPT
93 json_close_object
94 }
95
96 igmp_add_firewall_network() {
97 config_get direction $1 direction
98 config_get zone $1 zone
99
100 [ ! -z "$zone" ] || return
101
102 json_add_object ""
103 json_add_string type rule
104 json_add_string src "$zone"
105 json_add_string family ipv4
106 json_add_string proto igmp
107 json_add_string target ACCEPT
108 json_close_object
109
110 [ "$direction" = "upstream" ] && {
111 upstream="$zone"
112 config_foreach igmp_add_firewall_routing phyint
113 }
114 }
115
116 service_triggers() {
117 procd_add_reload_trigger "igmpproxy"
118 config_foreach igmp_add_network phyint
119 }
120
121 start_service() {
122 has_upstream=
123 netdevs=
124 logopts=
125 config_load igmpproxy
126
127 config_foreach igmp_header igmpproxy
128 config_foreach igmp_add_phyint phyint
129 [ -n "$has_upstream" ] || return
130
131 procd_open_instance
132 procd_set_param command $PROG '-n'
133 [ -n "$logopts" ] && procd_append_param command $logopts
134 procd_append_param command $CONFIGFILE
135 procd_set_param file $CONFIGFILE
136 procd_set_param netdev $netdevs
137 procd_set_param respawn
138
139 procd_open_data
140
141 json_add_array firewall
142 config_foreach igmp_add_firewall_network phyint
143 json_close_array
144
145 procd_close_data
146
147 procd_close_instance
148 }
149
150 service_started() {
151 procd_set_config_changed firewall
152 }
153
154 stop_service() {
155 procd_set_config_changed firewall
156 }