blob: 3ff8f19dadca90bcdaed34bbbd7889b728c6f991 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
#!/bin/sh /etc/rc.common
# Copyright (C) 2010-2014 OpenWrt.org
START=99
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
config_get_bool quickleave "$1" quickleave 0
mkdir -p /var/etc
rm -f /var/etc/igmpproxy.conf
[ $quickleave -gt 0 ] && echo "quickleave" >> /var/etc/igmpproxy.conf
[ -L /etc/igmpproxy.conf ] || ln -nsf /var/etc/igmpproxy.conf /etc/igmpproxy.conf
}
igmp_add_phyint() {
local network direction altnets device up
config_get network $1 network
config_get direction $1 direction
config_get altnets $1 altnet
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
[ -n "$device" -a "$up" = "1" ] || {
procd_append_param error "$network is not up"
return;
}
[[ "$direction" = "upstream" ]] && has_upstream=1
echo -e "\nphyint $device $direction ratelimit 0 threshold 1" >> /var/etc/igmpproxy.conf
if [ -n "$altnets" ]; then
local altnet
for altnet in $altnets; do
echo -e "\taltnet $altnet" >> /var/etc/igmpproxy.conf
done
fi
}
igmp_add_network() {
local network
config_get network $1 network
procd_add_interface_trigger "interface.*" $network /etc/init.d/igmpproxy restart
}
igmp_add_firewall_routing() {
config_get network $1 network
config_get direction $1 direction
[[ "$direction" = "downstream" ]] || return 0
json_add_object ""
json_add_string type rule
json_add_string src "$upstream"
json_add_string dest "$network"
json_add_string family ipv4
json_add_string proto udp
json_add_string dest_ip "224.0.0.0/4"
json_add_string target ACCEPT
json_close_object
}
igmp_add_firewall_network() {
config_get network $1 network
config_get direction $1 direction
json_add_object ""
json_add_string type rule
json_add_string src "$network"
json_add_string proto igmp
json_add_string target ACCEPT
json_close_object
[[ "$direction" = "upstream" ]] && {
upstream="$network"
config_foreach igmp_add_firewall_routing phyint
}
}
service_triggers() {
procd_add_reload_trigger "igmpproxy"
}
start_service() {
has_upstream=
config_load igmpproxy
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 respawn
procd_open_trigger
config_foreach igmp_add_network phyint
procd_close_trigger
procd_open_data
json_add_array firewall
config_foreach igmp_add_firewall_network phyint
json_close_array
procd_close_data
procd_close_instance
}
service_started() {
procd_set_config_changed firewall
}
|