--- /dev/null
+#
+# Copyright (C) 2006-2014 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=miniupnpd
+PKG_VERSION:=1.8.20140523
+PKG_RELEASE:=1
+
+PKG_SOURCE_URL:=http://miniupnp.free.fr/files
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_MD5SUM:=fcac89e11da091b1cc61f43d83c9e4f5
+
+PKG_MAINTAINER:=Markus Stenberg <fingon@iki.fi>
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/miniupnpd
+ SECTION:=net
+ CATEGORY:=Network
+ DEPENDS:=+iptables +libip4tc +IPV6:libip6tc +IPV6:ip6tables +libnfnetlink
+ TITLE:=Lightweight UPnP daemon
+ SUBMENU:=Firewall
+ URL:=http://miniupnp.free.fr/
+endef
+
+define Package/miniupnpd/conffiles
+/etc/config/upnpd
+endef
+
+define Package/miniupnpd/postinst
+#!/bin/sh
+
+if [ -z "$$IPKG_INSTROOT" ]; then
+ ( . /etc/uci-defaults/99-miniupnpd )
+ rm -f /etc/uci-defaults/99-miniupnpd
+fi
+
+exit 0
+endef
+
+define Build/Prepare
+ $(call Build/Prepare/Default)
+ echo "OpenWrt/$(OPENWRTVERSION)" | tr \(\)\ _ >$(PKG_BUILD_DIR)/os.openwrt
+endef
+
+MAKE_FLAGS += \
+ LIBS="" \
+ CC="$(TARGET_CC) -DIPTABLES_143 -lnfnetlink -lip4tc $(if $(CONFIG_IPV6),-lip6tc)" \
+ CONFIG_OPTIONS="$(if $(CONFIG_IPV6),--ipv6) --leasefile" \
+ -f Makefile.linux \
+ miniupnpd
+
+define Package/miniupnpd/install
+ $(INSTALL_DIR) $(1)/usr/sbin $(1)/etc/init.d $(1)/etc/config $(1)/etc/uci-defaults $(1)/etc/hotplug.d/iface $(1)/usr/share/miniupnpd
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/miniupnpd $(1)/usr/sbin/miniupnpd
+ $(INSTALL_BIN) ./files/miniupnpd.init $(1)/etc/init.d/miniupnpd
+ $(INSTALL_CONF) ./files/upnpd.config $(1)/etc/config/upnpd
+ $(INSTALL_DATA) ./files/miniupnpd.hotplug $(1)/etc/hotplug.d/iface/50-miniupnpd
+ $(INSTALL_DATA) ./files/miniupnpd.defaults $(1)/etc/uci-defaults/99-miniupnpd
+ $(INSTALL_DATA) ./files/firewall.include $(1)/usr/share/miniupnpd/firewall.include
+endef
+
+$(eval $(call BuildPackage,miniupnpd))
--- /dev/null
+#!/bin/sh
+# miniupnpd integration for firewall3
+
+IP6TABLES=/usr/sbin/ip6tables
+
+iptables -t filter -N MINIUPNPD 2>/dev/null
+iptables -t nat -N MINIUPNPD 2>/dev/null
+
+[ -x $IP6TABLES ] && $IP6TABLES -t filter -N MINIUPNPD 2>/dev/null
+
+. /lib/functions/network.sh
+
+add_extzone_rules() {
+ local ext_zone=$1
+
+ # IPv4 - due to NAT, need to add both to nat and filter table
+ iptables -t filter -I zone_${ext_zone}_forward -j MINIUPNPD
+ iptables -t nat -I zone_${ext_zone}_prerouting -j MINIUPNPD
+
+ # IPv6 if available - filter only
+ [ -x $IP6TABLES ] && {
+ $IP6TABLES -t filter -I zone_${ext_zone}_forward -j MINIUPNPD
+ }
+}
+
+network_find_wan wan_iface
+network_get_device wan_device $wan_iface
+
+for ext_zone in $(fw3 -q device "$wan_device"); do
+ add_extzone_rules $ext_zone
+done
+
+for ext_iface in $(uci -q get upnpd.config.external_iface); do
+ for ext_zone in $(fw3 -q network "$ext_iface"); do
+ add_extzone_rules $ext_zone
+ done
+done
+
--- /dev/null
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2006-2011 OpenWrt.org
+
+START=95
+
+SERVICE_USE_PID=1
+
+upnpd_get_port_range() {
+ local _var="$1"; shift
+ local _val
+
+ config_get _val "$@"
+
+ case "$_val" in
+ [0-9]*[:-][0-9]*)
+ export -n -- "${_var}_start=${_val%%[:-]*}"
+ export -n -- "${_var}_end=${_val##*[:-]}"
+ ;;
+ [0-9]*)
+ export -n -- "${_var}_start=$_val"
+ export -n -- "${_var}_end="
+ ;;
+ esac
+}
+
+conf_rule_add() {
+ local cfg="$1"
+ local tmpconf="$2"
+ local action external_port_start external_port_end int_addr
+ local internal_port_start internal_port_end
+
+ config_get action "$cfg" action "deny" # allow or deny
+ upnpd_get_port_range "ext" "$cfg" ext_ports "0-65535" # external ports: x, x-y, x:y
+ config_get int_addr "$cfg" int_addr "0.0.0.0/0" # ip or network and subnet mask (internal)
+ upnpd_get_port_range "int" "$cfg" int_ports "0-65535" # internal ports: x, x-y, x:y or range
+
+ # Make a single IP IP/32 so that miniupnpd.conf can use it.
+ case "$int_addr" in
+ */*) ;;
+ *) int_addr="$int_addr/32" ;;
+ esac
+
+ echo "${action} ${ext_start}${ext_end:+-}${ext_end} ${int_addr} ${int_start}${int_end:+-}${int_end}" >>$tmpconf
+}
+
+upnpd_write_bool() {
+ local opt="$1"
+ local def="${2:-0}"
+ local alt="$3"
+ local val
+
+ config_get_bool val config "$opt" "$def"
+ if [ "$val" -eq 0 ]; then
+ echo "${alt:-$opt}=no" >> $tmpconf
+ else
+ echo "${alt:-$opt}=yes" >> $tmpconf
+ fi
+}
+
+boot() {
+ return
+}
+
+start() {
+ config_load "upnpd"
+ local extiface intiface upload download logging secure enabled natpmp
+ local extip port usesysuptime conffile serial_number model_number
+ local uuid notify_interval presentation_url enable_upnp
+ local upnp_lease_file clean_ruleset_threshold clean_ruleset_interval
+ local ipv6_listening_ip
+
+ config_get extiface config external_iface
+ config_get intiface config internal_iface
+ config_get extip config external_ip
+ config_get port config port 5000
+ config_get upload config upload
+ config_get download config download
+ config_get_bool logging config log_output 0
+ config_get conffile config config_file
+ config_get serial_number config serial_number
+ config_get model_number config model_number
+ config_get uuid config uuid
+ config_get notify_interval config notify_interval
+ config_get presentation_url config presentation_url
+ config_get upnp_lease_file config upnp_lease_file
+ config_get clean_ruleset_threshold config clean_ruleset_threshold
+ config_get clean_ruleset_interval config clean_ruleset_interval
+ config_get ipv6_listening_ip config ipv6_listening_ip
+
+ local args
+
+ . /lib/functions/network.sh
+
+ local ifname
+
+ [ -n "$extiface" ] || network_find_wan extiface
+
+ network_get_device ifname ${extiface}
+
+ if [ -n "$conffile" ]; then
+ args="-f $conffile"
+ else
+ local tmpconf="/var/etc/miniupnpd.conf"
+ args="-f $tmpconf"
+ mkdir -p /var/etc
+
+ echo "ext_ifname=$ifname" >$tmpconf
+
+ [ -n "$extip" ] && \
+ echo "ext_ip=$extip" >>$tmpconf
+
+ local iface
+ for iface in ${intiface:-lan}; do
+ local device
+ network_get_device device "$iface" && {
+ echo "listening_ip=$device" >>$tmpconf
+ }
+ done
+
+ [ "$port" != "auto" ] && \
+ echo "port=$port" >>$tmpconf
+
+ config_load "upnpd"
+ upnpd_write_bool enable_natpmp 1
+ upnpd_write_bool enable_upnp 1
+ upnpd_write_bool secure_mode 1
+ upnpd_write_bool pcp_allow_thirdparty 0
+ upnpd_write_bool system_uptime 1
+
+ [ -n "$upnp_lease_file" ] && \
+ echo "lease_file=$upnp_lease_file" >>$tmpconf
+
+ [ -n "$upload" -a -n "$download" ] && {
+ echo "bitrate_down=$(($download * 1024 * 8))" >>$tmpconf
+ echo "bitrate_up=$(($upload * 1024 * 8))" >>$tmpconf
+ }
+
+ [ -n "${presentation_url}" ] && \
+ echo "presentation_url=${presentation_url}" >>$tmpconf
+
+ [ -n "${notify_interval}" ] && \
+ echo "notify_interval=${notify_interval}" >>$tmpconf
+
+ [ -n "${clean_ruleset_threshold}" ] && \
+ echo "clean_ruleset_threshold=${clean_ruleset_threshold}" >>$tmpconf
+
+ [ -n "${clean_ruleset_interval}" ] && \
+ echo "clean_ruleset_interval=${clean_ruleset_interval}" >>$tmpconf
+
+ [ -n "${ipv6_listening_ip}" ] && \
+ echo "ipv6_listening_ip=${ipv6_listening_ip}" >>$tmpconf
+
+ [ -z "$uuid" ] && {
+ uuid="$(cat /proc/sys/kernel/random/uuid)"
+ uci set upnpd.config.uuid=$uuid
+ uci commit upnpd
+ }
+
+ [ "$uuid" = "nocli" ] || \
+ echo "uuid=$uuid" >>$tmpconf
+
+ [ -n "${serial_number}" ] && \
+ echo "serial=${serial_number}" >>$tmpconf
+
+ [ -n "${model_number}" ] && \
+ echo "model_number=${model_number}" >>$tmpconf
+
+ config_foreach conf_rule_add perm_rule "$tmpconf"
+ fi
+
+
+ if [ -n "$ifname" ]; then
+ # start firewall
+ iptables -L MINIUPNPD >/dev/null 2>/dev/null || fw3 reload
+
+ if [ "$logging" = "1" ]; then
+ SERVICE_DAEMONIZE=1 \
+ service_start /usr/sbin/miniupnpd $args -d
+ else
+ SERVICE_DAEMONIZE= \
+ service_start /usr/sbin/miniupnpd $args
+ fi
+ else
+ logger -t "upnp daemon" "external interface not found, not starting"
+ fi
+}
+
+stop() {
+ service_stop /usr/sbin/miniupnpd
+
+ iptables -t nat -F MINIUPNPD 2>/dev/null
+ iptables -t filter -F MINIUPNPD 2>/dev/null
+
+ [ -x /usr/sbin/ip6tables ] && {
+ ip6tables -t filter -F MINIUPNPD 2>/dev/null
+ }
+}