[8.09] merge r17680
[openwrt/svn-archive/archive.git] / net / miniupnpd / files / miniupnpd.hotplug
1 #!/bin/sh
2
3 /etc/init.d/miniupnpd enabled && {
4
5 local state="${ZONE}_${INTERFACE}"
6 local extif initifs
7
8 config_load upnpd
9 config_get extif config external_iface
10
11 if [ "$ACTION" = "add" ] && [ "$INTERFACE" = "$extif" ]; then
12
13 local active
14 config_get active "$state" ifname
15
16 [ -z "$active" ] && {
17 local ipaddr
18 config_get ipaddr "$extif" ipaddr
19
20 logger -t "upnp" "adding $INTERFACE ($DEVICE - $ipaddr) to firewall"
21
22 iptables -t nat -N MINIUPNPD 2>/dev/null
23 iptables -t nat -A prerouting_rule -i $DEVICE -d $ipaddr -j MINIUPNPD
24 iptables -t filter -N MINIUPNPD 2>/dev/null
25 iptables -t filter -A forwarding_rule -i $DEVICE ! -o $DEVICE -j MINIUPNPD
26
27 uci_set_state upnpd "$state" "" "firewall"
28 uci_set_state upnpd "$state" ifname "$DEVICE"
29 uci_set_state upnpd "$state" ipaddr "$ipaddr"
30 }
31
32 elif [ "$ACTION" = "remove" ] && [ "$INTERFACE" = "$extif" ]; then
33
34 local ifname ipaddr
35 config_get ifname "$state" ifname
36 config_get ipaddr "$state" ipaddr
37
38 [ -n "$ifname" ] && [ -n "$ipaddr" ] && {
39 logger -t "upnp" "removing $INTERFACE ($ifname - $ipaddr) from firewall"
40 iptables -t nat -D prerouting_rule -i $ifname -d $ipaddr -j MINIUPNPD
41 iptables -t filter -D forwarding_rule -i $DEVICE ! -o $DEVICE -j MINIUPNPD
42 uci_revert_state upnpd "$state"
43 }
44 fi
45 }
46