2006-12-08 18:36:31 +00:00
|
|
|
#!/bin/sh
|
2008-12-25 03:25:13 +00:00
|
|
|
|
2010-09-15 02:57:50 +00:00
|
|
|
miniupnpd_add_rules() {
|
|
|
|
local zone="$1"
|
|
|
|
local network="$2"
|
|
|
|
local iface="$3"
|
2008-12-25 03:25:13 +00:00
|
|
|
|
2010-09-15 02:57:50 +00:00
|
|
|
miniupnpd_remove_rules
|
2009-09-23 00:48:24 +00:00
|
|
|
|
2010-09-15 02:57:50 +00:00
|
|
|
logger -t miniupnpd "adding firewall rules for $iface to zone $zone"
|
2009-09-23 00:48:24 +00:00
|
|
|
|
2010-09-15 02:57:50 +00:00
|
|
|
iptables -t nat -N MINIUPNPD 2>/dev/null
|
2010-09-19 15:50:48 +00:00
|
|
|
iptables -t nat -I zone_${zone}_prerouting -i $iface -j MINIUPNPD
|
2010-09-15 02:57:50 +00:00
|
|
|
iptables -t filter -N MINIUPNPD 2>/dev/null
|
2010-09-19 15:50:48 +00:00
|
|
|
iptables -t filter -I zone_${zone}_forward -i $iface ! -o $iface -j MINIUPNPD
|
2009-09-23 00:48:24 +00:00
|
|
|
|
2010-09-15 02:57:50 +00:00
|
|
|
uci_set_state upnpd state "" state
|
|
|
|
uci_set_state upnpd state zone "$zone"
|
|
|
|
uci_set_state upnpd state ifname "$iface"
|
|
|
|
uci_set_state upnpd state network "$network"
|
2008-12-25 03:25:13 +00:00
|
|
|
}
|
2009-09-23 00:48:24 +00:00
|
|
|
|
2010-09-15 02:57:50 +00:00
|
|
|
miniupnpd_remove_rules() {
|
|
|
|
local zone="$(uci_get_state upnpd state zone)"
|
|
|
|
local iface="$(uci_get_state upnpd state ifname)"
|
|
|
|
|
|
|
|
[ -n "$zone" ] && [ -n "$iface" ] && {
|
|
|
|
logger -t miniupnpd "removing firewall rules for $iface from zone $zone"
|
|
|
|
|
|
|
|
while iptables -t nat -D zone_${zone}_prerouting \
|
|
|
|
-i $iface -j MINIUPNPD 2>/dev/null; do :; done
|
|
|
|
|
|
|
|
while iptables -t filter -D zone_${zone}_forward \
|
|
|
|
-i $iface ! -o $iface -j MINIUPNPD 2>/dev/null; do :; done
|
|
|
|
}
|
|
|
|
|
|
|
|
uci_revert_state upnpd
|
|
|
|
}
|
|
|
|
|
|
|
|
/etc/init.d/miniupnpd enabled && [ -n "`pidof miniupnpd`" ] && {
|
|
|
|
|
|
|
|
local extif="$(uci_get upnpd config external_iface)"
|
|
|
|
local curif="$(uci_get_state upnpd state network)"
|
|
|
|
|
|
|
|
if [ "$ACTION" = "add" ] && [ "$INTERFACE" = "$extif" ]; then
|
|
|
|
miniupnpd_add_rules "$ZONE" "$INTERFACE" "$DEVICE"
|
|
|
|
elif [ "$ACTION" = "remove" ] && [ "$INTERFACE" = "$curif" ]; then
|
|
|
|
miniupnpd_remove_rules
|
|
|
|
fi
|
|
|
|
}
|