1 #!/bin/sh /etc/rc.common
3 EXTRA_COMMANDS
=clear_leases
16 config_get zone
"$cfg" zone
17 [ -n "$zone" ] ||
return 0
19 config_get net
"$cfg" network
20 [ -n "$net" ] ||
return 0
22 config_get ifname
"$net" ifname
23 [ -n "$ifname" ] ||
return 0
25 config_get ipaddr
"$net" ipaddr
26 [ -n "$ipaddr" ] ||
return 0
28 config_get netmask
"$net" netmask
29 [ -n "$netmask" ] ||
return 0
31 eval "$(ipcalc.sh $ipaddr $netmask)"
33 iptables
-t nat
-A prerouting_
${zone} -j luci_splash_prerouting
34 iptables
-t nat
-A luci_splash_prerouting
-s "$NETWORK/$PREFIX" -p ! tcp
-j luci_splash_portal
35 iptables
-t nat
-A luci_splash_prerouting
-s "$NETWORK/$PREFIX" -d ! "$ipaddr" -j luci_splash_portal
36 iptables
-t nat
-A luci_splash_prerouting
-s "$NETWORK/$PREFIX" -d "$ipaddr" -p tcp
-m multiport
! --dport 22,80,443 -j luci_splash_portal
38 qos_iface_add
"$ifname"
40 append SPLASH_INTERFACES
"$ifname"
44 config_get zone
"$1" zone
45 [ -n "$zone" ] ||
return 0
47 config_get ifname
"$1" ifname
48 [ -n "$ifname" ] ||
return 0
50 while iptables
-t nat
-D prerouting_
${zone} -j luci_splash_prerouting
2>&-; do :; done
52 qos_iface_del
"$ifname"
58 config_get mac
"$cfg" mac
60 iptables
-t filter
-I luci_splash_counter
-m mac
--mac-source "$mac" -j RETURN
61 iptables
-t nat
-I luci_splash_leases
-m mac
--mac-source "$mac" -j DROP
68 config_get mac
"$cfg" mac
70 iptables
-t filter
-I luci_splash_counter
-m mac
--mac-source "$mac" -j RETURN
71 iptables
-t nat
-I luci_splash_leases
-m mac
--mac-source "$mac" -j RETURN
78 config_get mac
"$cfg" mac
79 config_get ban
"$cfg" kicked
84 local oIFS
="$IFS"; IFS
=":"
86 IFS
="$oIFS"; unset oIFS
89 local mac_post
="$3$4$5$6"
92 iptables
-t filter
-I luci_splash_counter
-m mac
--mac-source "$mac" -j RETURN
93 iptables
-t mangle
-I luci_splash_mark
-m mac
--mac-source "$mac" -j MARK
--set-mark 79
94 iptables
-t nat
-I luci_splash_leases
-m mac
--mac-source "$mac" -j "${ban:-RETURN}"
96 for i
in $SPLASH_INTERFACES; do
97 tc filter add dev
$i parent
77:0 protocol ip prio
2 handle
::$handle u32 \
98 match u16
0x0800 0xFFFF at -2 match u32
0x
$mac_post 0xFFFFFFFF at -12 \
99 match u16
0x
$mac_pre 0xFFFF at -14 flowid
77:10
107 # 77 -> download root qdisc
108 # 78 -> upload root qdisc
111 tc qdisc del dev
"$iface" root handle
77:
113 if [ "$LIMIT_UP" -gt 0 -a "$LIMIT_DOWN" -gt 0 ]; then
114 tc qdisc add dev
"$iface" root handle
77: htb
116 # assume maximum rate of 20.000 kilobit for wlan
117 tc class add dev
"$iface" parent
77: classid
77:1 htb rate
20000kbit
119 # set download limit and burst
120 tc class add dev
"$iface" parent
77:1 classid
77:10 htb \
121 rate
${LIMIT_DOWN}kbit ceil
${LIMIT_DOWN_BURST}kbit prio
2
123 tc qdisc add dev
"$iface" parent
77:10 handle
78: sfq perturb
10
125 # adding ingress can result in "File exists" if qos-scripts are active
126 silent tc qdisc add dev
"$iface" ingress
128 # set client upload speed
129 tc filter add dev
"$iface" parent ffff
: protocol ip prio
1 \
130 handle
79 fw police rate
${LIMIT_UP}kbit mtu
6k burst
6k drop
137 tc qdisc del dev
"$iface" root handle
77:
138 tc qdisc del dev
"$iface" root handle
78:
139 tc filter del dev
"$iface" parent ffff
: protocol ip prio
1 handle
79 fw
143 ### Setup splash-relay
144 uci get lucid.splashr ||
{
146 set lucid.splashr=daemon
147 set lucid.splashr.slave=httpd
148 add_list lucid.splashr.address=8082
149 add_list lucid.splashr.publisher=splashredir
150 set lucid.splashr.enabled=1
152 set lucid.splashredir=Redirector
153 set lucid.splashredir.name=Splashd
154 set lucid.splashredir.virtual='/'
155 set lucid.splashredir.physical=':80/luci/splash'
161 ### We are started by the firewall include
166 ### Read chains from config
169 config_load luci_splash
172 config_get LIMIT_UP general limit_up
173 config_get LIMIT_DOWN general limit_down
174 config_get LIMIT_DOWN_BURST general limit_down_burst
176 LIMIT_UP
="${LIMIT_UP:-0}"
177 LIMIT_DOWN
="${LIMIT_DOWN:-0}"
178 LIMIT_DOWN_BURST
="${LIMIT_DOWN_BURST:-$(($LIMIT_DOWN * 2))}"
180 ### Load required modules
181 [ "$LIMIT_IP" -gt 0 -a "$LIMIT_DOWN" -gt 0 ] && {
183 silent insmod cls_route
184 silent insmod cls_rsvp
185 silent insmod cls_rsvp6
186 silent insmod cls_tcindex
187 silent insmod cls_u32
188 silent insmod sch_cbq
189 silent insmod sch_csz
190 silent insmod sch_dsmark
191 silent insmod sch_gred
192 silent insmod sch_hfsc
193 silent insmod sch_htb
194 silent insmod sch_ingress
195 silent insmod sch_red
196 silent insmod sch_tbf
197 silent insmod sch_teql
201 iptables
-t filter
-N luci_splash_counter
202 iptables
-t nat
-N luci_splash_portal
203 iptables
-t nat
-N luci_splash_leases
204 iptables
-t nat
-N luci_splash_prerouting
206 [ "$LIMIT_UP" -gt 0 -a "$LIMIT_DOWN" -gt 0 ] && \
207 iptables
-t mangle
-N luci_splash_mark
209 ### Build the main and portal rule
210 config_foreach iface_add iface
211 config_foreach blacklist_add blacklist
212 config_foreach whitelist_add whitelist
213 config_foreach lease_add lease
215 ### Build the portal rule
216 iptables
-t filter
-I INPUT
-j luci_splash_counter
217 iptables
-t filter
-I FORWARD
-j luci_splash_counter
219 [ "$LIMIT_UP" -gt 0 -a "$LIMIT_DOWN" -gt 0 ] && \
220 iptables
-t mangle
-I PREROUTING
-j luci_splash_mark
222 iptables
-t nat
-A luci_splash_portal
-p udp
--dport 33434:33523 -j RETURN
223 iptables
-t nat
-A luci_splash_portal
-p icmp
-j RETURN
224 iptables
-t nat
-A luci_splash_portal
-p udp
--dport 53 -j RETURN
225 iptables
-t nat
-A luci_splash_portal
-j luci_splash_leases
227 ### Build the leases rule
228 iptables
-t nat
-A luci_splash_leases
-p tcp
--dport 80 -j REDIRECT
--to-ports 8082
229 iptables
-t nat
-A luci_splash_leases
-j DROP
231 ### Add crontab entry
232 test -f /etc
/crontabs
/root ||
touch /etc
/crontabs
/root
233 grep -q luci-splash
/etc
/crontabs
/root ||
{
234 echo '*/5 * * * * /usr/sbin/luci-splash sync' >> /etc
/crontabs
/root
237 ### Start the splash httpd
238 start-stop-daemon
-S -m -p /var
/run
/luci-splashd.pid
-b -q -x /usr
/bin
/luci-splashd
242 ### Clear interface rules
243 config_load luci_splash
244 config_foreach iface_del iface
246 silent iptables
-t filter
-D INPUT
-j luci_splash_counter
247 silent iptables
-t filter
-D FORWARD
-j luci_splash_counter
248 silent iptables
-t mangle
-D PREROUTING
-j luci_splash_mark
251 silent iptables
-t nat
-F luci_splash_leases
252 silent iptables
-t nat
-F luci_splash_portal
253 silent iptables
-t nat
-F luci_splash_prerouting
254 silent iptables
-t filter
-F luci_splash_counter
255 silent iptables
-t mangle
-F luci_splash_mark
258 silent iptables
-t nat
-X luci_splash_leases
259 silent iptables
-t nat
-X luci_splash_portal
260 silent iptables
-t nat
-X luci_splash_prerouting
261 silent iptables
-t filter
-X luci_splash_counter
262 silent iptables
-t mangle
-X luci_splash_mark
264 ### Stop the splash httpd
265 start-stop-daemon
-K -p /var
/run
/luci-splashd.pid
-s KILL
-q
267 sed -ie '/\/usr\/sbin\/luci-splash sync/d' /var
/spool
/cron
/crontabs
/root
273 while uci
-P /var
/state del luci_splash.@lease
[0] 2>&-;do :; done