Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added if block to drop rule in INPUT chain if it is not at first position #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions update-blacklist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ if ! ipset list -n|command grep -q "$IPSET_BLACKLIST_NAME"; then
fi
fi

# drop rule if it isn't in a first position
if [ `iptables -L INPUT --line-num|command grep "match-set $IPSET_BLACKLIST_NAME" | cut -f1 -d" "` != "1" ]; then
if [[ ${FORCE:-no} != yes ]]; then
echo >&2 "Error: iptables need to drop ipset INPUT rule, drop it using:"
echo >&2 "# iptables -D INPUT -m set --match-set $IPSET_BLACKLIST_NAME src -j DROP"
exit 1
fi
if ! iptables -D INPUT -m set --match-set "$IPSET_BLACKLIST_NAME" src -j DROP; then
echo >&2 "Error: while dropping the --match-set ipset rule from iptables"
exit 1
fi
fi

# create the iptables binding if needed (or abort if does not exists and FORCE=no)
if ! iptables -vL INPUT|command grep -q "match-set $IPSET_BLACKLIST_NAME"; then
# we may also have assumed that INPUT rule n°1 is about packets statistics (traffic monitoring)
Expand Down