Ignore:
Timestamp:
2012-05-07T20:21:47+02:00 (5 years ago)
Author:
jow
Message:

[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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • packages/net/natpmp/files/natpmp.init

    r10071 r31644  
    22 
    33START=70 
     4 
     5SERVICE_DAEMONIZE=1 
     6SERVICE_WRITE_PID=1 
    47 
    58IP=$(which ip) 
     
    1013natpmp_config() { 
    1114        local cfg="$1" 
    12          
     15 
    1316        config_get PUBLIC_IF "$cfg" outbound_interface 
    1417        config_get PRIVATE_IFS "$cfg" inbound_interfaces 
     
    1922        config_load natpmp 
    2023        config_foreach natpmp_config natpmp 
    21          
    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 
    2524 
    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 
     25        include /lib/network 
     26        scan_interfaces 
    2927 
    30     # Iterate through the private interfaces. 
    31     BIND_ARGS="" 
    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" 
    38             else 
    39                     echo "Could not get IP address of interface $IF. Skipping." >&2 
    40             fi 
    41     done 
     28        # Flush all the rules in the natpmp chain, or create it, if it doesn't exists. 
     29        $IPTABLES -t nat -F $IPTABLES_CHAIN 2>/dev/null || \ 
     30        $IPTABLES -t nat -N $IPTABLES_CHAIN 
    4231 
    43     if [ -z "$BIND_ARGS" ] ; then 
    44             echo "No IP addresses to bind to. Exiting." >&2 
    45             exit 1 
    46     fi 
     32        # Handle all incoming connections in the natpmp chain. 
     33        $IPTABLES -t nat -D PREROUTING -j $IPTABLES_CHAIN 2>/dev/null || true 
     34        $IPTABLES -t nat -A PREROUTING -j $IPTABLES_CHAIN 
    4735 
    48     $NATPMP -p $PIDFILE -b -i "$PUBLIC_IF" $BIND_ARGS -- "$IPTABLES_CHAIN" 
     36        # Iterate through the private interfaces. 
     37        BIND_ARGS="" 
     38        for IF in $PRIVATE_IFS; do 
     39                config_get IF "$IF" ifname "$IF" 
     40 
     41                # Get the IP address of this interface. 
     42                ADDR=`$IP addr show dev $IF 2>/dev/null | grep "^ *inet .* $IF\$" | cut -d " " -f 6 | cut -d / -f 1` 
     43                if [ -n "$ADDR" ] ; then 
     44                        # Add the IP address to the argument list. 
     45                        BIND_ARGS="$BIND_ARGS -a $ADDR" 
     46                else 
     47                        echo "Could not get IP address of interface $IF. Skipping." >&2 
     48                fi 
     49        done 
     50 
     51        if [ -z "$BIND_ARGS" ] ; then 
     52                echo "No IP addresses to bind to. Exiting." >&2 
     53                exit 1 
     54        fi 
     55 
     56        config_get PUBLIC_IF "$PUBLIC_IF" ifname "$PUBLIC_IF" 
     57 
     58        SERVICE_PID_FILE="$PIDFILE" 
     59        service_start $NATPMP -i "$PUBLIC_IF" $BIND_ARGS -- "$IPTABLES_CHAIN" 
    4960} 
    5061 
    5162stop() { 
    52     config_load natpmp 
    53     config_foreach natpmp_config natpmp 
     63        config_load natpmp 
     64        config_foreach natpmp_config natpmp 
    5465 
    55     # Unlink chain 
    56     $IPTABLES -t nat -D PREROUTING -j $IPTABLES_CHAIN 2>/dev/null || true 
     66        # Unlink chain 
     67        $IPTABLES -t nat -D PREROUTING -j $IPTABLES_CHAIN 2>/dev/null || true 
    5768 
    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 
     69        # Flush all the rules in the natpmp chain 
     70        $IPTABLES -t nat -F $IPTABLES_CHAIN 2>/dev/null && \ 
     71        $IPTABLES -t nat -X $IPTABLES_CHAIN 
    6172 
    62     kill $(cat $PIDFILE) 
     73        SERVICE_PID_FILE="$PIDFILE" 
     74        service_stop $NATPMP 
    6375} 
Note: See TracChangeset for help on using the changeset viewer.