2008-04-27 11:10:09 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
2009-07-06 21:14:59 +00:00
|
|
|
|
2008-04-27 11:10:09 +00:00
|
|
|
START=70
|
2009-02-20 01:30:30 +00:00
|
|
|
EXTRA_COMMANDS=clear_leases
|
2009-06-09 12:15:31 +00:00
|
|
|
LIMIT_DOWN=0
|
|
|
|
LIMIT_DOWN_BURST=0
|
|
|
|
LIMIT_UP=0
|
|
|
|
|
2009-07-06 21:14:59 +00:00
|
|
|
IPT_REPLAY=/var/run/luci_splash.iptlog
|
|
|
|
LOCK=/var/run/luci_splash.lock
|
|
|
|
|
2009-06-09 12:15:31 +00:00
|
|
|
silent() {
|
|
|
|
"$@" 2>/dev/null
|
|
|
|
}
|
2008-04-27 11:10:09 +00:00
|
|
|
|
2009-07-06 21:14:59 +00:00
|
|
|
ipt_log() {
|
|
|
|
iptables -I "$@"
|
|
|
|
echo iptables -D "$@" >> $IPT_REPLAY
|
|
|
|
}
|
|
|
|
|
2008-04-27 11:10:09 +00:00
|
|
|
iface_add() {
|
|
|
|
local cfg="$1"
|
2010-10-28 16:58:05 +00:00
|
|
|
|
2008-08-05 12:58:20 +00:00
|
|
|
config_get zone "$cfg" zone
|
|
|
|
[ -n "$zone" ] || return 0
|
2010-10-28 16:58:05 +00:00
|
|
|
|
2008-08-07 20:21:38 +00:00
|
|
|
config_get net "$cfg" network
|
|
|
|
[ -n "$net" ] || return 0
|
2009-06-09 12:15:31 +00:00
|
|
|
|
|
|
|
config_get ifname "$net" ifname
|
|
|
|
[ -n "$ifname" ] || return 0
|
2010-10-28 16:58:05 +00:00
|
|
|
|
2008-08-07 20:21:38 +00:00
|
|
|
config_get ipaddr "$net" ipaddr
|
|
|
|
[ -n "$ipaddr" ] || return 0
|
2010-10-28 16:58:05 +00:00
|
|
|
|
2008-08-07 20:21:38 +00:00
|
|
|
config_get netmask "$net" netmask
|
|
|
|
[ -n "$netmask" ] || return 0
|
2010-10-28 16:58:05 +00:00
|
|
|
|
2009-06-16 21:41:29 +00:00
|
|
|
config_get parentiface "$net" interface
|
|
|
|
[ -n "$parentiface" ] && {
|
|
|
|
config_get parentproto "$parentiface" proto
|
|
|
|
config_get parentipaddr "$parentiface" ipaddr
|
|
|
|
config_get parentnetmask "$parentiface" netmask
|
|
|
|
}
|
2010-10-28 16:58:05 +00:00
|
|
|
|
2008-08-07 20:21:38 +00:00
|
|
|
eval "$(ipcalc.sh $ipaddr $netmask)"
|
2009-02-20 00:38:37 +00:00
|
|
|
|
2009-07-06 21:14:59 +00:00
|
|
|
### Add interface specific chain entry rules
|
|
|
|
ipt_log "zone_${zone}_prerouting" -i "${ifname%:*}" -s "$NETWORK/$PREFIX" -j luci_splash_prerouting -t nat
|
|
|
|
ipt_log "zone_${zone}_forward" -i "${ifname%:*}" -s "$NETWORK/$PREFIX" -j luci_splash_forwarding -t filter
|
2009-06-25 21:25:19 +00:00
|
|
|
|
2009-07-06 21:14:59 +00:00
|
|
|
### Allow traffic to the same subnet
|
|
|
|
iptables -t nat -I luci_splash_prerouting -d "$ipaddr/${netmask:-32}" -j RETURN
|
|
|
|
iptables -t filter -I luci_splash_forwarding -d "$ipaddr/${netmask:-32}" -j RETURN
|
2009-06-16 21:41:29 +00:00
|
|
|
|
2009-07-06 21:14:59 +00:00
|
|
|
### Allow traffic to the mesh subnet
|
2009-06-16 21:41:29 +00:00
|
|
|
[ "$parentproto" = "static" -a -n "$parentipaddr" ] && {
|
2009-07-06 21:14:59 +00:00
|
|
|
iptables -t nat -I luci_splash_prerouting -d "$parentipaddr/${parentnetmask:-32}" -j RETURN
|
|
|
|
iptables -t filter -I luci_splash_forwarding -d "$parentipaddr/${parentnetmask:-32}" -j RETURN
|
2009-06-16 21:41:29 +00:00
|
|
|
}
|
|
|
|
|
2009-06-09 12:15:31 +00:00
|
|
|
qos_iface_add "$ifname"
|
2008-04-27 11:10:09 +00:00
|
|
|
}
|
|
|
|
|
2009-02-20 04:15:54 +00:00
|
|
|
iface_del() {
|
2010-10-28 16:58:05 +00:00
|
|
|
config_get zone "$1" zone
|
2009-02-20 04:15:54 +00:00
|
|
|
[ -n "$zone" ] || return 0
|
2009-06-09 12:15:31 +00:00
|
|
|
|
2009-06-16 21:41:29 +00:00
|
|
|
config_get net "$1" network
|
|
|
|
[ -n "$net" ] || return 0
|
|
|
|
|
|
|
|
config_get ifname "$net" ifname
|
|
|
|
[ -n "$ifname" ] || return 0
|
|
|
|
|
2009-07-06 21:14:59 +00:00
|
|
|
# Clear interface specific rules
|
|
|
|
[ -s $IPT_REPLAY ] && {
|
|
|
|
grep -- "-i ${ifname%:*}" $IPT_REPLAY | while read ln; do silent $ln; done
|
|
|
|
sed -ie "/-i ${ifname%:*}/d" $IPT_REPLAY
|
2009-06-06 09:41:02 +00:00
|
|
|
}
|
2008-04-27 11:10:09 +00:00
|
|
|
|
2009-07-06 21:14:59 +00:00
|
|
|
qos_iface_del "$ifname"
|
2009-06-09 12:15:31 +00:00
|
|
|
}
|
|
|
|
|
2009-07-06 21:14:59 +00:00
|
|
|
mac_add() {
|
|
|
|
config_get mac "$1" mac
|
|
|
|
append MACS "$mac"
|
2009-06-16 21:41:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
subnet_add() {
|
|
|
|
local cfg="$1"
|
2010-10-28 16:58:05 +00:00
|
|
|
|
2009-06-16 21:41:29 +00:00
|
|
|
config_get ipaddr "$cfg" ipaddr
|
|
|
|
config_get netmask "$cfg" netmask
|
2010-10-28 16:58:05 +00:00
|
|
|
|
2009-06-16 21:41:29 +00:00
|
|
|
[ -n "$ipaddr" ] && {
|
2009-07-06 21:14:59 +00:00
|
|
|
iptables -t nat -I luci_splash_prerouting -d "$ipaddr/${netmask:-32}" -j RETURN
|
|
|
|
iptables -t filter -I luci_splash_forwarding -d "$ipaddr/${netmask:-32}" -j RETURN
|
2009-06-06 09:41:02 +00:00
|
|
|
}
|
2008-04-27 11:10:09 +00:00
|
|
|
}
|
|
|
|
|
2009-06-09 12:15:31 +00:00
|
|
|
qos_iface_add() {
|
|
|
|
local iface="$1"
|
|
|
|
|
|
|
|
# 77 -> download root qdisc
|
|
|
|
# 78 -> upload root qdisc
|
2009-07-06 21:14:59 +00:00
|
|
|
# 79 -> fwmark: client->inet
|
|
|
|
# 80 -> fwmark: inet->client
|
2009-06-09 12:15:31 +00:00
|
|
|
|
2009-06-09 12:30:16 +00:00
|
|
|
silent tc qdisc del dev "$iface" root handle 77:
|
2009-06-09 12:15:31 +00:00
|
|
|
|
|
|
|
if [ "$LIMIT_UP" -gt 0 -a "$LIMIT_DOWN" -gt 0 ]; then
|
|
|
|
tc qdisc add dev "$iface" root handle 77: htb
|
|
|
|
|
|
|
|
# assume maximum rate of 20.000 kilobit for wlan
|
|
|
|
tc class add dev "$iface" parent 77: classid 77:1 htb rate 20000kbit
|
|
|
|
|
|
|
|
# set download limit and burst
|
|
|
|
tc class add dev "$iface" parent 77:1 classid 77:10 htb \
|
2009-07-06 21:14:59 +00:00
|
|
|
rate ${LIMIT_DOWN}kbit ceil ${LIMIT_DOWN_BURST}kbit prio 2
|
2009-06-09 12:15:31 +00:00
|
|
|
|
|
|
|
tc qdisc add dev "$iface" parent 77:10 handle 78: sfq perturb 10
|
|
|
|
|
|
|
|
# adding ingress can result in "File exists" if qos-scripts are active
|
|
|
|
silent tc qdisc add dev "$iface" ingress
|
2009-05-26 17:44:02 +00:00
|
|
|
|
2009-07-06 21:14:59 +00:00
|
|
|
# set client download speed
|
|
|
|
tc filter add dev "$iface" parent 77: protocol ip prio 2 \
|
|
|
|
handle 80 fw flowid 77:10
|
|
|
|
|
2009-06-09 12:15:31 +00:00
|
|
|
# set client upload speed
|
|
|
|
tc filter add dev "$iface" parent ffff: protocol ip prio 1 \
|
2009-07-06 21:14:59 +00:00
|
|
|
handle 79 fw police rate ${LIMIT_UP}kbit mtu 6k burst 6k drop
|
2010-10-28 16:58:05 +00:00
|
|
|
fi
|
2009-06-09 12:15:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
qos_iface_del() {
|
|
|
|
local iface="$1"
|
|
|
|
|
2009-06-09 12:30:16 +00:00
|
|
|
silent tc qdisc del dev "$iface" root handle 77:
|
|
|
|
silent tc qdisc del dev "$iface" root handle 78:
|
|
|
|
silent tc filter del dev "$iface" parent ffff: protocol ip prio 1 handle 79 fw
|
2009-06-09 12:15:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
boot() {
|
|
|
|
### Setup splash-relay
|
2010-10-28 16:58:05 +00:00
|
|
|
uci get uhttpd.splash 2>/dev/null || {
|
2009-05-26 17:44:02 +00:00
|
|
|
uci batch <<EOF
|
2010-10-28 16:58:05 +00:00
|
|
|
set uhttpd.splash=uhttpd
|
|
|
|
set uhttpd.splash.home="/www/cgi-bin/splash/"
|
|
|
|
set uhttpd.splash.interpreter=".sh=/bin/ash"
|
|
|
|
set uhttpd.splash.listen_http="8082"
|
|
|
|
set uhttpd.splash.index_page="splash.sh"
|
|
|
|
set uhttpd.splash.error_page="/splash.sh"
|
|
|
|
|
|
|
|
commit uhttpd
|
2009-05-26 17:44:02 +00:00
|
|
|
EOF
|
|
|
|
}
|
2009-06-09 12:15:31 +00:00
|
|
|
|
|
|
|
### We are started by the firewall include
|
2009-02-20 04:15:54 +00:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2008-04-27 11:10:09 +00:00
|
|
|
start() {
|
2011-07-01 11:33:46 +00:00
|
|
|
lock $LOCK
|
2009-07-06 21:14:59 +00:00
|
|
|
|
2011-02-17 19:17:01 +00:00
|
|
|
include /lib/network
|
|
|
|
scan_interfaces
|
|
|
|
config_load luci_splash
|
|
|
|
|
2009-06-09 12:15:31 +00:00
|
|
|
### Find QoS limits
|
|
|
|
config_get LIMIT_UP general limit_up
|
|
|
|
config_get LIMIT_DOWN general limit_down
|
|
|
|
config_get LIMIT_DOWN_BURST general limit_down_burst
|
|
|
|
|
2009-07-06 21:14:59 +00:00
|
|
|
LIMIT_UP="$((8*${LIMIT_UP:-0}))"
|
|
|
|
LIMIT_DOWN="$((8*${LIMIT_DOWN:-0}))"
|
|
|
|
LIMIT_DOWN_BURST="${LIMIT_DOWN_BURST:+$((8*$LIMIT_DOWN_BURST))}"
|
|
|
|
LIMIT_DOWN_BURST="${LIMIT_DOWN_BURST:-$(($LIMIT_DOWN / 5 * 6))}"
|
2009-06-09 12:15:31 +00:00
|
|
|
|
|
|
|
### Load required modules
|
2009-06-09 12:41:36 +00:00
|
|
|
[ "$LIMIT_UP" -gt 0 -a "$LIMIT_DOWN" -gt 0 ] && {
|
2010-10-28 18:20:15 +00:00
|
|
|
silent insmod act_police
|
2009-06-09 12:15:31 +00:00
|
|
|
silent insmod cls_fw
|
|
|
|
silent insmod cls_u32
|
|
|
|
silent insmod sch_htb
|
2009-07-06 21:14:59 +00:00
|
|
|
silent insmod sch_sfq
|
2009-06-09 12:15:31 +00:00
|
|
|
silent insmod sch_ingress
|
|
|
|
}
|
2009-06-06 09:41:02 +00:00
|
|
|
|
2008-04-27 11:10:09 +00:00
|
|
|
### Create subchains
|
2009-06-09 12:15:31 +00:00
|
|
|
iptables -t nat -N luci_splash_prerouting
|
2009-07-06 21:14:59 +00:00
|
|
|
iptables -t nat -N luci_splash_leases
|
|
|
|
iptables -t filter -N luci_splash_forwarding
|
|
|
|
iptables -t filter -N luci_splash_filter
|
2009-06-09 12:15:31 +00:00
|
|
|
|
2009-07-06 21:14:59 +00:00
|
|
|
### Clear iptables replay log
|
|
|
|
[ -s $IPT_REPLAY ] && . $IPT_REPLAY
|
|
|
|
echo -n > $IPT_REPLAY
|
2009-06-06 09:41:02 +00:00
|
|
|
|
2008-04-27 11:10:09 +00:00
|
|
|
### Build the main and portal rule
|
2009-06-09 12:15:31 +00:00
|
|
|
config_foreach iface_add iface
|
2009-06-16 21:41:29 +00:00
|
|
|
config_foreach subnet_add subnet
|
2009-06-09 12:15:31 +00:00
|
|
|
|
2009-07-06 21:14:59 +00:00
|
|
|
### Add interface independant prerouting rules
|
|
|
|
iptables -t nat -A luci_splash_prerouting -j luci_splash_leases
|
|
|
|
iptables -t nat -A luci_splash_leases -p udp --dport 53 -j REDIRECT --to-ports 53
|
|
|
|
iptables -t nat -A luci_splash_leases -p tcp --dport 80 -j REDIRECT --to-ports 8082
|
2009-06-16 21:41:29 +00:00
|
|
|
|
2009-07-06 21:14:59 +00:00
|
|
|
### Add interface independant forwarding rules
|
|
|
|
iptables -t filter -A luci_splash_forwarding -j luci_splash_filter
|
|
|
|
iptables -t filter -A luci_splash_filter -p tcp -j REJECT --reject-with tcp-reset
|
|
|
|
iptables -t filter -A luci_splash_filter -j REJECT --reject-with icmp-net-prohibited
|
|
|
|
|
|
|
|
### Add QoS chain
|
|
|
|
[ "$LIMIT_UP" -gt 0 -a "$LIMIT_DOWN" -gt 0 ] && {
|
|
|
|
iptables -t mangle -N luci_splash_mark_out
|
|
|
|
iptables -t mangle -N luci_splash_mark_in
|
|
|
|
iptables -t mangle -I PREROUTING -j luci_splash_mark_out
|
|
|
|
iptables -t mangle -I POSTROUTING -j luci_splash_mark_in
|
|
|
|
}
|
|
|
|
|
|
|
|
### Find active mac addresses
|
|
|
|
MACS=""
|
|
|
|
config_foreach mac_add lease
|
|
|
|
config_foreach mac_add blacklist
|
|
|
|
config_foreach mac_add whitelist
|
2009-06-16 21:41:29 +00:00
|
|
|
|
2008-09-23 13:15:50 +00:00
|
|
|
### Add crontab entry
|
2009-05-13 10:10:30 +00:00
|
|
|
test -f /etc/crontabs/root || touch /etc/crontabs/root
|
|
|
|
grep -q luci-splash /etc/crontabs/root || {
|
|
|
|
echo '*/5 * * * * /usr/sbin/luci-splash sync' >> /etc/crontabs/root
|
2008-09-23 13:15:50 +00:00
|
|
|
}
|
2009-07-06 21:14:59 +00:00
|
|
|
|
|
|
|
lock -u $LOCK
|
|
|
|
|
|
|
|
### Populate iptables
|
|
|
|
[ -n "$MACS" ] && luci-splash add-rules $MACS
|
2008-04-27 11:10:09 +00:00
|
|
|
}
|
|
|
|
|
2009-02-20 00:38:37 +00:00
|
|
|
stop() {
|
2011-07-01 11:33:46 +00:00
|
|
|
lock $LOCK
|
2009-07-06 21:14:59 +00:00
|
|
|
|
2011-02-17 19:17:01 +00:00
|
|
|
include /lib/network
|
|
|
|
scan_interfaces
|
|
|
|
config_load luci_splash
|
|
|
|
|
2009-02-20 00:38:37 +00:00
|
|
|
### Clear interface rules
|
|
|
|
config_foreach iface_del iface
|
2009-06-06 09:41:02 +00:00
|
|
|
|
2009-07-06 21:14:59 +00:00
|
|
|
silent iptables -t mangle -D PREROUTING -j luci_splash_mark_out
|
|
|
|
silent iptables -t mangle -D POSTROUTING -j luci_splash_mark_in
|
2010-10-28 16:58:05 +00:00
|
|
|
|
2008-04-27 11:10:09 +00:00
|
|
|
### Clear subchains
|
2009-06-09 12:15:31 +00:00
|
|
|
silent iptables -t nat -F luci_splash_prerouting
|
2009-07-06 21:14:59 +00:00
|
|
|
silent iptables -t nat -F luci_splash_leases
|
|
|
|
silent iptables -t filter -F luci_splash_forwarding
|
2009-06-16 21:41:29 +00:00
|
|
|
silent iptables -t filter -F luci_splash_filter
|
2009-07-06 21:14:59 +00:00
|
|
|
silent iptables -t mangle -F luci_splash_mark_out
|
|
|
|
silent iptables -t mangle -F luci_splash_mark_in
|
2010-10-28 16:58:05 +00:00
|
|
|
|
2008-04-27 11:10:09 +00:00
|
|
|
### Delete subchains
|
2009-06-09 12:15:31 +00:00
|
|
|
silent iptables -t nat -X luci_splash_prerouting
|
2009-07-06 21:14:59 +00:00
|
|
|
silent iptables -t nat -X luci_splash_leases
|
|
|
|
silent iptables -t filter -X luci_splash_forwarding
|
2009-06-16 21:41:29 +00:00
|
|
|
silent iptables -t filter -X luci_splash_filter
|
2009-07-06 21:14:59 +00:00
|
|
|
silent iptables -t mangle -X luci_splash_mark_out
|
|
|
|
silent iptables -t mangle -X luci_splash_mark_in
|
2010-10-28 16:58:05 +00:00
|
|
|
|
2009-02-20 01:30:30 +00:00
|
|
|
sed -ie '/\/usr\/sbin\/luci-splash sync/d' /var/spool/cron/crontabs/root
|
2009-07-06 21:14:59 +00:00
|
|
|
|
|
|
|
lock -u $LOCK
|
2009-02-20 01:30:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
clear_leases() {
|
2009-07-06 21:14:59 +00:00
|
|
|
### Find active mac addresses
|
|
|
|
MACS=""
|
|
|
|
config_foreach mac_add lease
|
|
|
|
|
|
|
|
### Clear leases
|
|
|
|
[ -n "$MACS" ] && luci-splash remove $MACS
|
2008-04-27 11:10:09 +00:00
|
|
|
}
|
|
|
|
|