miniupnpd: Added based on latest 20140523 version + IPv6 pinhole/SSL compilation...
[lede-routing/.git] / miniupnpd / files / firewall.include
1 #!/bin/sh
2 # miniupnpd integration for firewall3
3
4 IP6TABLES=/usr/sbin/ip6tables
5
6 iptables -t filter -N MINIUPNPD 2>/dev/null
7 iptables -t nat -N MINIUPNPD 2>/dev/null
8
9 [ -x $IP6TABLES ] && $IP6TABLES -t filter -N MINIUPNPD 2>/dev/null
10
11 . /lib/functions/network.sh
12
13 add_extzone_rules() {
14     local ext_zone=$1
15
16     # IPv4 - due to NAT, need to add both to nat and filter table
17     iptables -t filter -I zone_${ext_zone}_forward -j MINIUPNPD
18     iptables -t nat -I zone_${ext_zone}_prerouting -j MINIUPNPD
19
20     # IPv6 if available - filter only
21     [ -x $IP6TABLES ] && {
22         $IP6TABLES -t filter -I zone_${ext_zone}_forward -j MINIUPNPD
23     }
24 }
25
26 network_find_wan wan_iface
27 network_get_device wan_device $wan_iface
28
29 for ext_zone in $(fw3 -q device "$wan_device"); do
30     add_extzone_rules $ext_zone
31 done
32
33 for ext_iface in $(uci -q get upnpd.config.external_iface); do
34         for ext_zone in $(fw3 -q network "$ext_iface"); do
35             add_extzone_rules $ext_zone
36         done
37 done
38