Annotation of embedaddon/miniupnpd/netfilter/iptables_init_and_clean.sh, revision 1.1.1.2

1.1       misho       1: #! /bin/sh
1.1.1.2 ! misho       2: # $Id: iptables_init_and_clean.sh,v 1.3 2012/03/05 20:36:19 nanard Exp $
1.1       misho       3: # Improved Miniupnpd iptables init script.
                      4: # Checks for state of filter before doing anything..
                      5: 
                      6: EXTIF=eth0
                      7: IPTABLES=/sbin/iptables
1.1.1.2 ! misho       8: EXTIP="`LC_ALL=C /sbin/ifconfig $EXTIF | grep 'inet ' | awk '{print $2}' | sed -e 's/.*://'`"
1.1       misho       9: NDIRTY="`LC_ALL=C /sbin/iptables -t nat -L -n | grep 'MINIUPNPD' | awk '{printf $1}'`"
                     10: FDIRTY="`LC_ALL=C /sbin/iptables -t filter -L -n | grep 'MINIUPNPD' | awk '{printf $1}'`"
                     11: echo "External IP = $EXTIP"
                     12: 
                     13: if [[ $NDIRTY = "MINIUPNPDChain" ]]; then
                     14:         echo "Nat table dirty; Cleaning..."
                     15:         $IPTABLES -t nat -F MINIUPNPD
                     16: elif [[ $NDIRTY = "Chain" ]]; then
                     17:         echo "Dirty NAT chain but no reference..? Fixsted."
                     18:         $IPTABLES -t nat -A PREROUTING -d $EXTIP -i $EXTIF -j MINIUPNPD
                     19:         $IPTABLES -t nat -F MINIUPNPD
                     20: else
                     21:         echo "NAT table clean..initalizing.."
                     22:         $IPTABLES -t nat -N MINIUPNPD
                     23:         $IPTABLES -t nat -A PREROUTING -d $EXTIP -i $EXTIF -j MINIUPNPD
                     24: fi
                     25: if [[ $FDIRTY = "MINIUPNPDChain" ]]; then
                     26:         echo "Filter table dirty; Cleaning..."
                     27:         $IPTABLES -t filter -F MINIUPNPD
                     28: elif [[ $FDIRTY = "Chain" ]]; then
                     29:         echo "Dirty filter chain but no reference..? Fixsted."
                     30:         $IPTABLES -t filter -I FORWARD 4 -i $EXTIF ! -o $EXTIF -j MINIUPNPD
                     31:         $IPTABLES -t filter -F MINIUPNPD
                     32: else
                     33:         echo "Filter table clean..initalizing.."
                     34:         $IPTABLES -t filter -N MINIUPNPD
                     35:         $IPTABLES -t filter -I FORWARD 4 -i $EXTIF ! -o $EXTIF -j MINIUPNPD
1.1.1.2 ! misho      36: fi
1.1       misho      37: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>