1 #!/bin/sh /etc/rc.common
6 IPTABLES
=$
(which iptables
)
7 NATPMP
=/usr
/sbin
/natpmp
8 PIDFILE
=/var
/run
/natpmp.pid
13 config_get PUBLIC_IF
"$cfg" outbound_interface
14 config_get PRIVATE_IFS
"$cfg" inbound_interfaces
15 config_get IPTABLES_CHAIN
"$cfg" iptables_chain
20 config_foreach natpmp_config natpmp
22 # Flush all the rules in the natpmp chain, or create it, if it doesn't exists.
23 $IPTABLES -t nat
-F $IPTABLES_CHAIN 2>/dev
/null || \
24 $IPTABLES -t nat
-N $IPTABLES_CHAIN
26 # Handle all incoming connections in the natpmp chain.
27 $IPTABLES -t nat
-D PREROUTING
-j $IPTABLES_CHAIN 2>/dev
/null || true
28 $IPTABLES -t nat
-A PREROUTING
-j $IPTABLES_CHAIN
30 # Iterate through the private interfaces.
32 for IF
in $PRIVATE_IFS; do
33 # Get the IP address of this interface.
34 ADDR
=`$IP addr show dev $IF 2>/dev/null | grep "^ *inet .* $IF\$" | cut -d " " -f 6 | cut -d / -f 1`
35 if [ -n "$ADDR" ] ; then
36 # Add the IP address to the argument list.
37 BIND_ARGS
="$BIND_ARGS -a $ADDR"
39 echo "Could not get IP address of interface $IF. Skipping." >&2
43 if [ -z "$BIND_ARGS" ] ; then
44 echo "No IP addresses to bind to. Exiting." >&2
48 $NATPMP -p $PIDFILE -b -i "$PUBLIC_IF" $BIND_ARGS -- "$IPTABLES_CHAIN"
53 config_foreach natpmp_config natpmp
56 $IPTABLES -t nat
-D PREROUTING
-j $IPTABLES_CHAIN 2>/dev
/null || true
58 # Flush all the rules in the natpmp chain
59 $IPTABLES -t nat
-F $IPTABLES_CHAIN 2>/dev
/null
&& \
60 $IPTABLES -t nat
-X $IPTABLES_CHAIN