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 config_get parentiface
"$net" interface
32 [ -n "$parentiface" ] && {
33 config_get parentproto
"$parentiface" proto
34 config_get parentipaddr
"$parentiface" ipaddr
35 config_get parentnetmask
"$parentiface" netmask
38 eval "$(ipcalc.sh $ipaddr $netmask)"
40 iptables
-t nat
-A prerouting_
${zone} -j luci_splash_prerouting
41 iptables
-t nat
-A luci_splash_prerouting
-j luci_splash_portal
43 iptables
-t filter
-I luci_splash_filter
-s ! "$NETWORK/$PREFIX" -j RETURN
44 iptables
-t nat
-I luci_splash_leases
-s ! "$NETWORK/$PREFIX" -j RETURN
46 iptables
-t filter
-I luci_splash_filter
-s "$NETWORK/$PREFIX" -d "$ipaddr/${netmask:-32}" -j RETURN
47 iptables
-t nat
-I luci_splash_leases
-s "$NETWORK/$PREFIX" -d "$ipaddr/${netmask:-32}" -j RETURN
49 [ "$parentproto" = "static" -a -n "$parentipaddr" ] && {
50 iptables
-t filter
-I luci_splash_filter
-s "$NETWORK/$PREFIX" -d "$parentipaddr/${parentnetmask:-32}" -j RETURN
51 iptables
-t nat
-I luci_splash_leases
-s "$NETWORK/$PREFIX" -d "$parentipaddr/${parentnetmask:-32}" -j RETURN
54 iptables
-t filter
-A luci_splash_filter
-s "$NETWORK/$PREFIX" -p udp
--dport 53 -j RETURN
55 iptables
-t filter
-A luci_splash_filter
-s "$NETWORK/$PREFIX" -p tcp
--dport 22 -j RETURN
# XXX: ssh really needed?
56 iptables
-t filter
-A luci_splash_filter
-s "$NETWORK/$PREFIX" -p tcp
--dport 80 -j RETURN
57 iptables
-t filter
-A luci_splash_filter
-s "$NETWORK/$PREFIX" -j REJECT
--reject-with icmp-admin-prohibited
59 qos_iface_add
"$ifname"
61 append SPLASH_INTERFACES
"$ifname"
65 config_get zone
"$1" zone
66 [ -n "$zone" ] ||
return 0
68 while iptables
-t nat
-D prerouting_
${zone} -j luci_splash_prerouting
2>&-; do :; done
70 config_get net
"$1" network
71 [ -n "$net" ] ||
return 0
73 config_get ifname
"$net" ifname
74 [ -n "$ifname" ] ||
return 0
76 qos_iface_del
"$ifname"
82 config_get mac
"$cfg" mac
84 iptables
-t filter
-I luci_splash_filter
-m mac
--mac-source "$mac" -j DROP
85 iptables
-t nat
-I luci_splash_leases
-m mac
--mac-source "$mac" -j DROP
92 config_get mac
"$cfg" mac
94 iptables
-t filter
-I luci_splash_filter
-m mac
--mac-source "$mac" -j RETURN
95 iptables
-t nat
-I luci_splash_leases
-m mac
--mac-source "$mac" -j RETURN
102 config_get mac
"$cfg" mac
103 config_get ban
"$cfg" kicked
108 local oIFS
="$IFS"; IFS
=":"
110 IFS
="$oIFS"; unset oIFS
113 local mac_post
="$3$4$5$6"
116 iptables
-t filter
-I luci_splash_filter
-m mac
--mac-source "$mac" -j RETURN
117 iptables
-t nat
-I luci_splash_leases
-m mac
--mac-source "$mac" -j "${ban:-RETURN}"
119 [ "$LIMIT_UP" -gt 0 -a "$LIMIT_DOWN" -gt 0 ] && {
120 iptables
-t mangle
-I luci_splash_mark
-m mac
--mac-source "$mac" -j MARK
--set-mark 79
122 for i
in $SPLASH_INTERFACES; do
123 tc filter add dev
$i parent
77:0 protocol ip prio
2 handle
::$handle u32 \
124 match u16
0x0800 0xFFFF at -2 match u32
0x
$mac_post 0xFFFFFFFF at -12 \
125 match u16
0x
$mac_pre 0xFFFF at -14 flowid
77:10
134 config_get ipaddr
"$cfg" ipaddr
135 config_get netmask
"$cfg" netmask
137 [ -n "$ipaddr" ] && {
138 iptables
-t filter
-I luci_splash_filter
-d "$ipaddr/${netmask:-32}" -j RETURN
139 iptables
-t nat
-I luci_splash_portal
-d "$ipaddr/${netmask:-32}" -j RETURN
146 # 77 -> download root qdisc
147 # 78 -> upload root qdisc
150 silent tc qdisc del dev
"$iface" root handle
77:
152 if [ "$LIMIT_UP" -gt 0 -a "$LIMIT_DOWN" -gt 0 ]; then
153 tc qdisc add dev
"$iface" root handle
77: htb
155 # assume maximum rate of 20.000 kilobit for wlan
156 tc class add dev
"$iface" parent
77: classid
77:1 htb rate
20000kbit
158 # set download limit and burst
159 tc class add dev
"$iface" parent
77:1 classid
77:10 htb \
160 rate
${LIMIT_DOWN}kb ceil
${LIMIT_DOWN_BURST}kb prio
2
162 tc qdisc add dev
"$iface" parent
77:10 handle
78: sfq perturb
10
164 # adding ingress can result in "File exists" if qos-scripts are active
165 silent tc qdisc add dev
"$iface" ingress
167 # set client upload speed
168 tc filter add dev
"$iface" parent ffff
: protocol ip prio
1 \
169 handle
79 fw police rate
${LIMIT_UP}kb mtu
6k burst
6k drop
176 silent tc qdisc del dev
"$iface" root handle
77:
177 silent tc qdisc del dev
"$iface" root handle
78:
178 silent tc filter del dev
"$iface" parent ffff
: protocol ip prio
1 handle
79 fw
182 ### Setup splash-relay
183 uci get lucid.splashr ||
{
185 set lucid.splashr=daemon
186 set lucid.splashr.slave=httpd
187 add_list lucid.splashr.address=8082
188 add_list lucid.splashr.publisher=splashredir
189 set lucid.splashr.enabled=1
191 set lucid.splashredir=Redirector
192 set lucid.splashredir.name=Splashd
193 set lucid.splashredir.virtual='/'
194 set lucid.splashredir.physical=':80/luci/splash'
200 ### We are started by the firewall include
205 ### Read chains from config
208 config_load luci_splash
211 config_get LIMIT_UP general limit_up
212 config_get LIMIT_DOWN general limit_down
213 config_get LIMIT_DOWN_BURST general limit_down_burst
215 LIMIT_UP
="${LIMIT_UP:-0}"
216 LIMIT_DOWN
="${LIMIT_DOWN:-0}"
217 LIMIT_DOWN_BURST
="${LIMIT_DOWN_BURST:-$(($LIMIT_DOWN * 2))}"
219 ### Load required modules
220 [ "$LIMIT_UP" -gt 0 -a "$LIMIT_DOWN" -gt 0 ] && {
222 silent insmod cls_u32
223 silent insmod sch_htb
224 silent insmod sch_ingress
228 iptables
-t filter
-N luci_splash_filter
229 iptables
-t nat
-N luci_splash_portal
230 iptables
-t nat
-N luci_splash_leases
231 iptables
-t nat
-N luci_splash_prerouting
233 [ "$LIMIT_UP" -gt 0 -a "$LIMIT_DOWN" -gt 0 ] && \
234 iptables
-t mangle
-N luci_splash_mark
236 ### Build the main and portal rule
237 config_foreach iface_add iface
238 config_foreach subnet_add subnet
239 config_foreach blacklist_add blacklist
240 config_foreach whitelist_add whitelist
241 config_foreach lease_add lease
243 ### Build the portal rule
244 iptables
-t filter
-I INPUT
-j luci_splash_filter
245 iptables
-t filter
-I FORWARD
-j luci_splash_filter
247 [ "$LIMIT_UP" -gt 0 -a "$LIMIT_DOWN" -gt 0 ] && \
248 iptables
-t mangle
-I PREROUTING
-j luci_splash_mark
250 ### Allow icmp, dns and traceroute
251 iptables
-t nat
-A luci_splash_portal
-p udp
--dport 33434:33523 -j RETURN
252 iptables
-t nat
-A luci_splash_portal
-p icmp
-j RETURN
253 iptables
-t nat
-A luci_splash_portal
-p udp
--dport 53 -j RETURN
255 ### Redirect the rest into the lease chain
256 iptables
-t nat
-A luci_splash_portal
-j luci_splash_leases
258 ### Build the leases rule
259 iptables
-t nat
-A luci_splash_leases
-p tcp
--dport 80 -j REDIRECT
--to-ports 8082
261 ### Add crontab entry
262 test -f /etc
/crontabs
/root ||
touch /etc
/crontabs
/root
263 grep -q luci-splash
/etc
/crontabs
/root ||
{
264 echo '*/5 * * * * /usr/sbin/luci-splash sync' >> /etc
/crontabs
/root
269 ### Clear interface rules
272 config_load luci_splash
273 config_foreach iface_del iface
275 silent iptables
-t filter
-D INPUT
-j luci_splash_filter
276 silent iptables
-t filter
-D FORWARD
-j luci_splash_filter
277 silent iptables
-t mangle
-D PREROUTING
-j luci_splash_mark
280 silent iptables
-t nat
-F luci_splash_leases
281 silent iptables
-t nat
-F luci_splash_portal
282 silent iptables
-t nat
-F luci_splash_prerouting
283 silent iptables
-t filter
-F luci_splash_filter
284 silent iptables
-t mangle
-F luci_splash_mark
287 silent iptables
-t nat
-X luci_splash_leases
288 silent iptables
-t nat
-X luci_splash_portal
289 silent iptables
-t nat
-X luci_splash_prerouting
290 silent iptables
-t filter
-X luci_splash_filter
291 silent iptables
-t mangle
-X luci_splash_mark
293 sed -ie '/\/usr\/sbin\/luci-splash sync/d' /var
/spool
/cron
/crontabs
/root
299 while uci
-P /var
/state del luci_splash.@lease
[0] 2>&-;do :; done