From: jow Date: Mon, 7 May 2012 18:21:47 +0000 (+0000) Subject: [packages] natpmp: several fixes X-Git-Url: http://207.154.207.93/?a=commitdiff_plain;h=f90214ebbdcceca79d47b60627fa1a4394ab8a19;p=packages.git [packages] natpmp: several fixes - use service wrappers to launch natpmp, its builtin daemon setup is broken - rework uci config to allow logical ifnames - change and fix default config to use abstract "lan" and "wan" instead of hardcoded (and improperly formatted) device names git-svn-id: svn://svn.openwrt.org/openwrt/packages@31644 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- diff --git a/net/natpmp/Makefile b/net/natpmp/Makefile index 959fcf665..4bb496ef4 100644 --- a/net/natpmp/Makefile +++ b/net/natpmp/Makefile @@ -1,5 +1,5 @@ # -# Copyright (C) 2007-2011 OpenWrt.org +# Copyright (C) 2007-2012 OpenWrt.org # # This is free software, licensed under the GNU General Public License v2. # See /LICENSE for more information. @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=natpmp PKG_VERSION:=0.2.3 -PKG_RELEASE:=3 +PKG_RELEASE:=4 PKG_SOURCE_URL:=http://download.savannah.nongnu.org/releases/natpmp/ PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz diff --git a/net/natpmp/files/natpmp.config b/net/natpmp/files/natpmp.config index a01867e05..9239d56ac 100644 --- a/net/natpmp/files/natpmp.config +++ b/net/natpmp/files/natpmp.config @@ -1,4 +1,4 @@ config natpmp - option outbound_interface vlan0 - option inbound_interfaces br-lan eth1 + option outbound_interface wan + option inbound_interfaces lan option iptables_chain natpmp diff --git a/net/natpmp/files/natpmp.init b/net/natpmp/files/natpmp.init index 289a63d08..3b4bba245 100644 --- a/net/natpmp/files/natpmp.init +++ b/net/natpmp/files/natpmp.init @@ -2,6 +2,9 @@ START=70 +SERVICE_DAEMONIZE=1 +SERVICE_WRITE_PID=1 + IP=$(which ip) IPTABLES=$(which iptables) NATPMP=/usr/sbin/natpmp @@ -9,7 +12,7 @@ PIDFILE=/var/run/natpmp.pid natpmp_config() { local cfg="$1" - + config_get PUBLIC_IF "$cfg" outbound_interface config_get PRIVATE_IFS "$cfg" inbound_interfaces config_get IPTABLES_CHAIN "$cfg" iptables_chain @@ -18,46 +21,55 @@ natpmp_config() { start() { config_load natpmp config_foreach natpmp_config natpmp - - # Flush all the rules in the natpmp chain, or create it, if it doesn't exists. - $IPTABLES -t nat -F $IPTABLES_CHAIN 2>/dev/null || \ - $IPTABLES -t nat -N $IPTABLES_CHAIN - - # Handle all incoming connections in the natpmp chain. - $IPTABLES -t nat -D PREROUTING -j $IPTABLES_CHAIN 2>/dev/null || true - $IPTABLES -t nat -A PREROUTING -j $IPTABLES_CHAIN - - # Iterate through the private interfaces. - BIND_ARGS="" - for IF in $PRIVATE_IFS; do - # Get the IP address of this interface. - ADDR=`$IP addr show dev $IF 2>/dev/null | grep "^ *inet .* $IF\$" | cut -d " " -f 6 | cut -d / -f 1` - if [ -n "$ADDR" ] ; then - # Add the IP address to the argument list. - BIND_ARGS="$BIND_ARGS -a $ADDR" - else - echo "Could not get IP address of interface $IF. Skipping." >&2 - fi - done - - if [ -z "$BIND_ARGS" ] ; then - echo "No IP addresses to bind to. Exiting." >&2 - exit 1 - fi - - $NATPMP -p $PIDFILE -b -i "$PUBLIC_IF" $BIND_ARGS -- "$IPTABLES_CHAIN" + + include /lib/network + scan_interfaces + + # Flush all the rules in the natpmp chain, or create it, if it doesn't exists. + $IPTABLES -t nat -F $IPTABLES_CHAIN 2>/dev/null || \ + $IPTABLES -t nat -N $IPTABLES_CHAIN + + # Handle all incoming connections in the natpmp chain. + $IPTABLES -t nat -D PREROUTING -j $IPTABLES_CHAIN 2>/dev/null || true + $IPTABLES -t nat -A PREROUTING -j $IPTABLES_CHAIN + + # Iterate through the private interfaces. + BIND_ARGS="" + for IF in $PRIVATE_IFS; do + config_get IF "$IF" ifname "$IF" + + # Get the IP address of this interface. + ADDR=`$IP addr show dev $IF 2>/dev/null | grep "^ *inet .* $IF\$" | cut -d " " -f 6 | cut -d / -f 1` + if [ -n "$ADDR" ] ; then + # Add the IP address to the argument list. + BIND_ARGS="$BIND_ARGS -a $ADDR" + else + echo "Could not get IP address of interface $IF. Skipping." >&2 + fi + done + + if [ -z "$BIND_ARGS" ] ; then + echo "No IP addresses to bind to. Exiting." >&2 + exit 1 + fi + + config_get PUBLIC_IF "$PUBLIC_IF" ifname "$PUBLIC_IF" + + SERVICE_PID_FILE="$PIDFILE" + service_start $NATPMP -i "$PUBLIC_IF" $BIND_ARGS -- "$IPTABLES_CHAIN" } stop() { - config_load natpmp - config_foreach natpmp_config natpmp + config_load natpmp + config_foreach natpmp_config natpmp - # Unlink chain - $IPTABLES -t nat -D PREROUTING -j $IPTABLES_CHAIN 2>/dev/null || true + # Unlink chain + $IPTABLES -t nat -D PREROUTING -j $IPTABLES_CHAIN 2>/dev/null || true - # Flush all the rules in the natpmp chain - $IPTABLES -t nat -F $IPTABLES_CHAIN 2>/dev/null && \ - $IPTABLES -t nat -X $IPTABLES_CHAIN + # Flush all the rules in the natpmp chain + $IPTABLES -t nat -F $IPTABLES_CHAIN 2>/dev/null && \ + $IPTABLES -t nat -X $IPTABLES_CHAIN - kill $(cat $PIDFILE) + SERVICE_PID_FILE="$PIDFILE" + service_stop $NATPMP }