#!/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

${IPTABLES} -L ${RULE} > /dev/null 2>&1
EXIST=$?
if [ "$EXIST" -ne "0" ] ; then
   DIR=`dirname $0`
   $DIR/middle_fw_start ${RULE}
fi

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

${IPTABLES} -A ${RULE} -p udp -s ${IP} ${PORTRST} -j DROP

