#!/bin/sh

IPTABLES=/sbin/iptables
RULE=$1
IP=$2
PORT=$3

if [ -z "${RULE}"  -o  -z "${IP}" ] ; then
    echo "Usage: $0 RULE IP.ADDR [PORT]"
    exit 1
fi


unset PORTRST
if [ -n "${PORT}" ]; then
    PORTRST="--sport $PORT"
fi

CMD="${IPTABLES} -D ${RULE} -p udp -s ${IP} ${PORTRST} -j DROP"

${CMD}
EXITCODE=$?

if [ ${EXITCODE} -eq 0 ]; then
    while ${CMD} >/dev/null 2>&1
    do
	NEXT=1
    done
fi

exit ${EXITCODE}
