1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2010-2014 OpenWrt.org
6 PROG
=/usr
/sbin
/igmpproxy
7 CONFIGFILE
=/var
/etc
/igmpproxy.conf
10 local quickleave verbose
11 config_get_bool quickleave
"$1" quickleave
0
12 config_get verbose
"$1" verbose
1
14 [ $verbose = "0" ] && logopts
="-d"
15 [ $verbose = "2" ] && logopts
="-v"
16 [ $verbose = "3" ] && logopts
="-v -v"
19 rm -f /var
/etc
/igmpproxy.conf
20 [ $quickleave -gt 0 ] && echo "quickleave" >> /var
/etc
/igmpproxy.conf
22 [ -L /etc
/igmpproxy.conf
] ||
ln -nsf /var
/etc
/igmpproxy.conf
/etc
/igmpproxy.conf
26 local network direction altnets device up
28 config_get network
$1 network
29 config_get direction
$1 direction
30 config_get altnets
$1 altnet
32 local status
="$(ubus -S call "network.interface.
$network" status)"
33 [ -n "$status" ] ||
return
36 json_get_var device l3_device
39 [ -n "$device" -a "$up" = "1" ] ||
{
40 procd_append_param error
"$network is not up"
44 append netdevs
"$device"
46 [[ "$direction" = "upstream" ]] && has_upstream
=1
48 echo -e "\nphyint $device $direction ratelimit 0 threshold 1" >> /var
/etc
/igmpproxy.conf
50 if [ -n "$altnets" ]; then
52 for altnet
in $altnets; do
53 echo -e "\taltnet $altnet" >> /var
/etc
/igmpproxy.conf
61 config_get network
$1 network
62 procd_add_interface_trigger
"interface.*" $network /etc
/init.d
/igmpproxy reload
65 igmp_add_firewall_routing
() {
66 config_get direction
$1 direction
67 config_get zone
$1 zone
69 [[ "$direction" = "downstream" && ! -z "$zone" ]] ||
return 0
71 # First drop SSDP packets then accept all other multicast
74 json_add_string
type rule
75 json_add_string src
"$upstream"
76 json_add_string dest
"$zone"
77 json_add_string family ipv4
78 json_add_string proto udp
79 json_add_string dest_ip
"239.255.255.250"
80 json_add_string target DROP
84 json_add_string
type rule
85 json_add_string src
"$upstream"
86 json_add_string dest
"$zone"
87 json_add_string family ipv4
88 json_add_string proto udp
89 json_add_string dest_ip
"224.0.0.0/4"
90 json_add_string target ACCEPT
94 igmp_add_firewall_network
() {
95 config_get direction
$1 direction
96 config_get zone
$1 zone
98 [ ! -z "$zone" ] ||
return
101 json_add_string
type rule
102 json_add_string src
"$zone"
103 json_add_string family ipv4
104 json_add_string proto igmp
105 json_add_string target ACCEPT
108 [[ "$direction" = "upstream" ]] && {
110 config_foreach igmp_add_firewall_routing phyint
115 procd_add_reload_trigger
"igmpproxy"
116 config_foreach igmp_add_network phyint
123 config_load igmpproxy
125 config_foreach igmp_header igmpproxy
126 config_foreach igmp_add_phyint phyint
127 [ -n "$has_upstream" ] ||
return
130 procd_set_param
command $PROG '-n'
131 [ -n "$logopts" ] && procd_append_param
command $logopts
132 procd_append_param
command $CONFIGFILE
133 procd_set_param
file $CONFIGFILE
134 procd_set_param netdev
$netdevs
135 procd_set_param respawn
139 json_add_array firewall
140 config_foreach igmp_add_firewall_network phyint
149 procd_set_config_changed firewall
153 procd_set_config_changed firewall