1 #!/bin/sh /etc/rc.common
5 EXTRA_COMMANDS
=clear_leases
10 IPT_REPLAY
=/var
/run
/luci_splash.iptlog
11 LOCK
=/var
/run
/luci_splash.lock
12 [ -x /usr
/sbin
/ip6tables
] && [ -f /proc
/net
/ipv6_route
] && HAS_IPV6
=1
20 echo iptables
-D "$@" >> $IPT_REPLAY
24 [ "$HAS_IPV6" = 1 ] ||
return
26 echo ip6tables
-D "$@" >> $IPT_REPLAY
33 config_get zone
"$cfg" zone
34 [ -n "$zone" ] ||
return 0
36 config_get net
"$cfg" network
37 [ -n "$net" ] ||
return 0
39 config_get ifname
"$net" ifname
40 [ -n "$ifname" ] ||
return 0
42 config_get ipaddr
"$net" ipaddr
43 [ -n "$ipaddr" ] ||
return 0
45 config_get ip6addr
"$net" ip6addr
46 #[ -n "$ipaddr" ] || return 0
48 config_get netmask
"$net" netmask
49 [ -n "$netmask" ] ||
return 0
51 config_get
type "$net" type
53 parentiface
="$(uci -q get network.${net}.ifname)"
55 [ -n "$parentiface" ] && [ ! "$type" = "bridge" ] && {
56 parentiface
=${parentiface#@}
57 config_get parentproto
"$parentiface" proto
58 config_get parentipaddr
"$parentiface" ipaddr
59 config_get parentnetmask
"$parentiface" netmask
62 eval "$(ipcalc.sh $ipaddr $netmask)"
64 ### Add interface specific chain entry rules
65 ipt_log
"zone_${zone}_prerouting" -i "${ifname%:*}" -s "$NETWORK/$PREFIX" -j luci_splash_prerouting
-t nat
66 ipt_log
"zone_${zone}_forward" -i "${ifname%:*}" -s "$NETWORK/$PREFIX" -j luci_splash_forwarding
-t filter
68 if [ "$HAS_IPV6" = 1 ] && [ -n "$ip6addr" ]; then
69 ipt6_log
"zone_${zone}_forward" -i "${ifname%:*}" -s "$ip6addr" -j luci_splash_forwarding
-t filter
72 ### Allow traffic to the same subnet
73 iptables
-t nat
-I luci_splash_prerouting
-d "$ipaddr/${netmask:-32}" -j RETURN
74 iptables
-t filter
-I luci_splash_forwarding
-d "$ipaddr/${netmask:-32}" -j RETURN
76 ### Allow traffic to the mesh subnet
77 [ "$parentproto" = "static" -a -n "$parentipaddr" ] && {
78 iptables
-t nat
-I luci_splash_prerouting
-d "$parentipaddr/${parentnetmask:-32}" -j RETURN
79 iptables
-t filter
-I luci_splash_forwarding
-d "$parentipaddr/${parentnetmask:-32}" -j RETURN
82 qos_iface_add
"$ifname"
86 config_get zone
"$1" zone
87 [ -n "$zone" ] ||
return 0
89 config_get net
"$1" network
90 [ -n "$net" ] ||
return 0
92 config_get ifname
"$net" ifname
93 [ -n "$ifname" ] ||
return 0
95 # Clear interface specific rules
96 [ -s $IPT_REPLAY ] && {
97 grep -- "-i ${ifname%:*}" $IPT_REPLAY |
while read ln; do silent
$ln; done
98 sed -ie "/-i ${ifname%:*}/d" $IPT_REPLAY
101 qos_iface_del
"$ifname"
105 config_get mac
"$1" mac
112 config_get ipaddr
"$cfg" ipaddr
113 config_get netmask
"$cfg" netmask
115 [ -n "$ipaddr" ] && {
116 iptables
-t nat
-I luci_splash_prerouting
-d "$ipaddr/${netmask:-32}" -j RETURN
117 iptables
-t filter
-I luci_splash_forwarding
-d "$ipaddr/${netmask:-32}" -j RETURN
124 # 77 -> download root qdisc
125 # 78 -> upload root qdisc
126 # 79 -> fwmark: client->inet
127 # 80 -> fwmark: inet->client
129 silent tc qdisc del dev
"$iface" root handle
77:
131 if [ "$LIMIT_UP" -gt 0 -a "$LIMIT_DOWN" -gt 0 ]; then
132 tc qdisc add dev
"$iface" root handle
77: htb
134 # assume maximum rate of 20.000 kilobit for wlan
135 tc class add dev
"$iface" parent
77: classid
77:1 htb rate
20000kbit
137 # set download limit and burst
138 tc class add dev
"$iface" parent
77:1 classid
77:10 htb \
139 rate
${LIMIT_DOWN}kbit ceil
${LIMIT_DOWN_BURST}kbit prio
2
141 tc qdisc add dev
"$iface" parent
77:10 handle
78: sfq perturb
10
143 # adding ingress can result in "File exists" if qos-scripts are active
144 silent tc qdisc add dev
"$iface" ingress
146 # set client download speed
147 tc filter add dev
"$iface" parent
77: protocol ip prio
2 \
148 handle
80 fw flowid
77:10
150 # set client upload speed
151 tc filter add dev
"$iface" parent ffff
: protocol ip prio
1 \
152 handle
79 fw police rate
${LIMIT_UP}kbit mtu
6k burst
6k drop
159 silent tc qdisc del dev
"$iface" root handle
77:
160 silent tc qdisc del dev
"$iface" root handle
78:
161 silent tc filter del dev
"$iface" parent ffff
: protocol ip prio
1 handle
79 fw
165 ### Setup splash-relay
166 uci get uhttpd.splash
2>/dev
/null ||
{
168 set uhttpd.splash=uhttpd
169 set uhttpd.splash.home="/www/cgi-bin/splash/"
170 set uhttpd.splash.interpreter=".sh=/bin/ash"
171 set uhttpd.splash.listen_http="8082"
172 set uhttpd.splash.index_page="splash.sh"
173 set uhttpd.splash.error_page="/splash.sh"
179 ### We are started by the firewall include
188 config_load luci_splash
191 config_get LIMIT_UP general limit_up
192 config_get LIMIT_DOWN general limit_down
193 config_get LIMIT_DOWN_BURST general limit_down_burst
195 LIMIT_UP
="$((8*${LIMIT_UP:-0}))"
196 LIMIT_DOWN
="$((8*${LIMIT_DOWN:-0}))"
197 LIMIT_DOWN_BURST
="${LIMIT_DOWN_BURST:+$((8*$LIMIT_DOWN_BURST))}"
198 LIMIT_DOWN_BURST
="${LIMIT_DOWN_BURST:-$(($LIMIT_DOWN / 5 * 6))}"
200 ### Load required modules
201 [ "$LIMIT_UP" -gt 0 -a "$LIMIT_DOWN" -gt 0 ] && {
202 silent insmod act_police
204 silent insmod cls_u32
205 silent insmod sch_htb
206 silent insmod sch_sfq
207 silent insmod sch_ingress
211 iptables
-t nat
-N luci_splash_prerouting
212 iptables
-t nat
-N luci_splash_leases
213 iptables
-t filter
-N luci_splash_forwarding
214 iptables
-t filter
-N luci_splash_filter
216 if [ "$HAS_IPV6" = 1 ]; then
217 ip6tables
-t filter
-N luci_splash_forwarding
218 ip6tables
-t filter
-N luci_splash_filter
221 ### Clear iptables replay log
222 [ -s $IPT_REPLAY ] && .
$IPT_REPLAY
223 echo -n > $IPT_REPLAY
225 ### Build the main and portal rule
226 config_foreach iface_add iface
227 config_foreach subnet_add subnet
229 ### Add interface independant prerouting rules
230 iptables
-t nat
-A luci_splash_prerouting
-j luci_splash_leases
231 iptables
-t nat
-A luci_splash_leases
-p udp
--dport 53 -j REDIRECT
--to-ports 53
232 iptables
-t nat
-A luci_splash_leases
-p tcp
--dport 80 -j REDIRECT
--to-ports 8082
234 ### Add interface independant forwarding rules
235 iptables
-t filter
-A luci_splash_forwarding
-j luci_splash_filter
236 iptables
-t filter
-A luci_splash_filter
-p tcp
-j REJECT
--reject-with tcp-reset
237 iptables
-t filter
-A luci_splash_filter
-j REJECT
--reject-with icmp-net-prohibited
239 if [ "$HAS_IPV6" = 1 ]; then
240 ip6tables
-t filter
-A luci_splash_forwarding
-j luci_splash_filter
241 ip6tables
-t filter
-A luci_splash_filter
-p tcp
-j REJECT
--reject-with tcp-reset
242 ip6tables
-t filter
-A luci_splash_filter
-j REJECT
--reject-with adm-prohibited
246 [ "$LIMIT_UP" -gt 0 -a "$LIMIT_DOWN" -gt 0 ] && {
247 iptables
-t mangle
-N luci_splash_mark_out
248 iptables
-t mangle
-N luci_splash_mark_in
249 iptables
-t mangle
-I PREROUTING
-j luci_splash_mark_out
250 iptables
-t mangle
-I POSTROUTING
-j luci_splash_mark_in
251 if [ "$HAS_IPV6" = 1 ]; then
252 ip6tables
-t mangle
-N luci_splash_mark_out
253 ip6tables
-t mangle
-N luci_splash_mark_in
254 ip6tables
-t mangle
-I PREROUTING
-j luci_splash_mark_out
255 ip6tables
-t mangle
-I POSTROUTING
-j luci_splash_mark_in
259 ### Find active mac addresses
261 config_foreach mac_add lease
262 config_foreach mac_add blacklist
263 config_foreach mac_add whitelist
265 ### Add crontab entry
266 test -f /etc
/crontabs
/root ||
touch /etc
/crontabs
/root
267 grep -q luci-splash
/etc
/crontabs
/root ||
{
268 echo '*/5 * * * * /usr/sbin/luci-splash sync' >> /etc
/crontabs
/root
273 ### Populate iptables
274 [ -n "$MACS" ] && luci-splash add-rules
$MACS
282 config_load luci_splash
284 ### Clear interface rules
285 config_foreach iface_del iface
287 silent iptables
-t mangle
-D PREROUTING
-j luci_splash_mark_out
288 silent iptables
-t mangle
-D POSTROUTING
-j luci_splash_mark_in
290 if [ "$HAS_IPV6" = 1 ]; then
291 silent ip6tables
-t mangle
-D PREROUTING
-j luci_splash_mark_out
292 silent ip6tables
-t mangle
-D POSTROUTING
-j luci_splash_mark_in
296 silent iptables
-t nat
-F luci_splash_prerouting
297 silent iptables
-t nat
-F luci_splash_leases
298 silent iptables
-t filter
-F luci_splash_forwarding
299 silent iptables
-t filter
-F luci_splash_filter
300 silent iptables
-t mangle
-F luci_splash_mark_out
301 silent iptables
-t mangle
-F luci_splash_mark_in
303 if [ "$HAS_IPV6" = 1 ]; then
304 ip6tables
-t filter
-F luci_splash_forwarding
305 ip6tables
-t filter
-F luci_splash_filter
306 ip6tables
-t mangle
-F luci_splash_mark_out
307 ip6tables
-t mangle
-F luci_splash_mark_in
311 silent iptables
-t nat
-X luci_splash_prerouting
312 silent iptables
-t nat
-X luci_splash_leases
313 silent iptables
-t filter
-X luci_splash_forwarding
314 silent iptables
-t filter
-X luci_splash_filter
315 silent iptables
-t mangle
-X luci_splash_mark_out
316 silent iptables
-t mangle
-X luci_splash_mark_in
317 if [ "$HAS_IPV6" = 1 ]; then
318 ip6tables
-t filter
-X luci_splash_forwarding
319 ip6tables
-t filter
-X luci_splash_filter
320 ip6tables
-t mangle
-X luci_splash_mark_out
321 ip6tables
-t mangle
-X luci_splash_mark_in
323 sed -ie '/\/usr\/sbin\/luci-splash sync/d' /var
/spool
/cron
/crontabs
/root
329 ### Find active mac addresses
331 config_foreach mac_add lease
334 [ -n "$MACS" ] && luci-splash remove
$MACS