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" -d "$ipaddr/${netmask:-32}" -j RETURN
44 iptables -t nat -I luci_splash_leases -s "$NETWORK/$PREFIX" -d "$ipaddr/${netmask:-32}" -j RETURN
46 [ "$parentproto" = "static" -a -n "$parentipaddr" ] && {
47 iptables -t filter -I luci_splash_filter -s "$NETWORK/$PREFIX" -d "$parentipaddr/${parentnetmask:-32}" -j RETURN
48 iptables -t nat -I luci_splash_leases -s "$NETWORK/$PREFIX" -d "$parentipaddr/${parentnetmask:-32}" -j RETURN
51 iptables -t filter -A luci_splash_filter -s "$NETWORK/$PREFIX" -p udp --dport 53 -j RETURN
52 iptables -t filter -A luci_splash_filter -s "$NETWORK/$PREFIX" -p tcp --dport 22 -j RETURN # XXX: ssh really needed?
53 iptables -t filter -A luci_splash_filter -s "$NETWORK/$PREFIX" -p tcp --dport 80 -j RETURN
54 iptables -t filter -A luci_splash_filter -s "$NETWORK/$PREFIX" -j REJECT --reject-with icmp-admin-prohibited
56 qos_iface_add "$ifname"
58 append SPLASH_INTERFACES "$ifname"
62 config_get zone "$1" zone
63 [ -n "$zone" ] || return 0
65 while iptables -t nat -D prerouting_${zone} -j luci_splash_prerouting 2>&-; do :; done
67 config_get net "$1" network
68 [ -n "$net" ] || return 0
70 config_get ifname "$net" ifname
71 [ -n "$ifname" ] || return 0
73 qos_iface_del "$ifname"
79 config_get mac "$cfg" mac
81 iptables -t filter -I luci_splash_filter -m mac --mac-source "$mac" -j DROP
82 iptables -t nat -I luci_splash_leases -m mac --mac-source "$mac" -j DROP
89 config_get mac "$cfg" mac
91 iptables -t filter -I luci_splash_filter -m mac --mac-source "$mac" -j RETURN
92 iptables -t nat -I luci_splash_leases -m mac --mac-source "$mac" -j RETURN
99 config_get mac "$cfg" mac
100 config_get ban "$cfg" kicked
105 local oIFS="$IFS"; IFS=":"
107 IFS="$oIFS"; unset oIFS
110 local mac_post="$3$4$5$6"
113 iptables -t filter -I luci_splash_filter -m mac --mac-source "$mac" -j RETURN
114 iptables -t nat -I luci_splash_leases -m mac --mac-source "$mac" -j "${ban:-RETURN}"
116 [ "$LIMIT_UP" -gt 0 -a "$LIMIT_DOWN" -gt 0 ] && {
117 iptables -t mangle -I luci_splash_mark -m mac --mac-source "$mac" -j MARK --set-mark 79
119 for i in $SPLASH_INTERFACES; do
120 tc filter add dev $i parent 77:0 protocol ip prio 2 handle ::$handle u32 \
121 match u16 0x0800 0xFFFF at -2 match u32 0x$mac_post 0xFFFFFFFF at -12 \
122 match u16 0x$mac_pre 0xFFFF at -14 flowid 77:10
131 config_get ipaddr "$cfg" ipaddr
132 config_get netmask "$cfg" netmask
134 [ -n "$ipaddr" ] && {
135 iptables -t filter -I luci_splash_filter -d "$ipaddr/${netmask:-32}" -j RETURN
136 iptables -t nat -I luci_splash_portal -d "$ipaddr/${netmask:-32}" -j RETURN
143 # 77 -> download root qdisc
144 # 78 -> upload root qdisc
147 silent tc qdisc del dev "$iface" root handle 77:
149 if [ "$LIMIT_UP" -gt 0 -a "$LIMIT_DOWN" -gt 0 ]; then
150 tc qdisc add dev "$iface" root handle 77: htb
152 # assume maximum rate of 20.000 kilobit for wlan
153 tc class add dev "$iface" parent 77: classid 77:1 htb rate 20000kbit
155 # set download limit and burst
156 tc class add dev "$iface" parent 77:1 classid 77:10 htb \
157 rate ${LIMIT_DOWN}kb ceil ${LIMIT_DOWN_BURST}kb prio 2
159 tc qdisc add dev "$iface" parent 77:10 handle 78: sfq perturb 10
161 # adding ingress can result in "File exists" if qos-scripts are active
162 silent tc qdisc add dev "$iface" ingress
164 # set client upload speed
165 tc filter add dev "$iface" parent ffff: protocol ip prio 1 \
166 handle 79 fw police rate ${LIMIT_UP}kb mtu 6k burst 6k drop
173 silent tc qdisc del dev "$iface" root handle 77:
174 silent tc qdisc del dev "$iface" root handle 78:
175 silent tc filter del dev "$iface" parent ffff: protocol ip prio 1 handle 79 fw
179 ### Setup splash-relay
180 uci get lucid.splashr || {
182 set lucid.splashr=daemon
183 set lucid.splashr.slave=httpd
184 add_list lucid.splashr.address=8082
185 add_list lucid.splashr.publisher=splashredir
186 set lucid.splashr.enabled=1
188 set lucid.splashredir=Redirector
189 set lucid.splashredir.name=Splashd
190 set lucid.splashredir.virtual='/'
191 set lucid.splashredir.physical=':80/luci/splash'
197 ### We are started by the firewall include
202 ### Read chains from config
205 config_load luci_splash
208 config_get LIMIT_UP general limit_up
209 config_get LIMIT_DOWN general limit_down
210 config_get LIMIT_DOWN_BURST general limit_down_burst
212 LIMIT_UP="${LIMIT_UP:-0}"
213 LIMIT_DOWN="${LIMIT_DOWN:-0}"
214 LIMIT_DOWN_BURST="${LIMIT_DOWN_BURST:-$(($LIMIT_DOWN * 2))}"
216 ### Load required modules
217 [ "$LIMIT_UP" -gt 0 -a "$LIMIT_DOWN" -gt 0 ] && {
219 silent insmod cls_u32
220 silent insmod sch_htb
221 silent insmod sch_ingress
225 iptables -t filter -N luci_splash_filter
226 iptables -t nat -N luci_splash_portal
227 iptables -t nat -N luci_splash_leases
228 iptables -t nat -N luci_splash_prerouting
230 [ "$LIMIT_UP" -gt 0 -a "$LIMIT_DOWN" -gt 0 ] && \
231 iptables -t mangle -N luci_splash_mark
233 ### Build the main and portal rule
234 config_foreach iface_add iface
235 config_foreach subnet_add subnet
236 config_foreach blacklist_add blacklist
237 config_foreach whitelist_add whitelist
238 config_foreach lease_add lease
240 ### Build the portal rule
241 iptables -t filter -I INPUT -j luci_splash_filter
242 iptables -t filter -I FORWARD -j luci_splash_filter
244 [ "$LIMIT_UP" -gt 0 -a "$LIMIT_DOWN" -gt 0 ] && \
245 iptables -t mangle -I PREROUTING -j luci_splash_mark
247 ### Allow icmp, dns and traceroute
248 iptables -t nat -A luci_splash_portal -p udp --dport 33434:33523 -j RETURN
249 iptables -t nat -A luci_splash_portal -p icmp -j RETURN
250 iptables -t nat -A luci_splash_portal -p udp --dport 53 -j RETURN
252 ### Redirect the rest into the lease chain
253 iptables -t nat -A luci_splash_portal -j luci_splash_leases
255 ### Build the leases rule
256 iptables -t nat -A luci_splash_leases -p tcp --dport 80 -j REDIRECT --to-ports 8082
258 ### Add crontab entry
259 test -f /etc/crontabs/root || touch /etc/crontabs/root
260 grep -q luci-splash /etc/crontabs/root || {
261 echo '*/5 * * * * /usr/sbin/luci-splash sync' >> /etc/crontabs/root
266 ### Clear interface rules
269 config_load luci_splash
270 config_foreach iface_del iface
272 silent iptables -t filter -D INPUT -j luci_splash_filter
273 silent iptables -t filter -D FORWARD -j luci_splash_filter
274 silent iptables -t mangle -D PREROUTING -j luci_splash_mark
277 silent iptables -t nat -F luci_splash_leases
278 silent iptables -t nat -F luci_splash_portal
279 silent iptables -t nat -F luci_splash_prerouting
280 silent iptables -t filter -F luci_splash_filter
281 silent iptables -t mangle -F luci_splash_mark
284 silent iptables -t nat -X luci_splash_leases
285 silent iptables -t nat -X luci_splash_portal
286 silent iptables -t nat -X luci_splash_prerouting
287 silent iptables -t filter -X luci_splash_filter
288 silent iptables -t mangle -X luci_splash_mark
290 sed -ie '/\/usr\/sbin\/luci-splash sync/d' /var/spool/cron/crontabs/root
296 while uci -P /var/state del luci_splash.@lease[0] 2>&-;do :; done