Linux Netfilter discussions
 help / color / mirror / Atom feed
From: "Kerin Millar" <kfm@plushkava.net>
To: imnozi@gmail.com, netfilter@vger.kernel.org
Subject: Re: ipset not completely working in mangle:PREROUTING
Date: Tue, 26 May 2026 02:57:38 +0100	[thread overview]
Message-ID: <a276ecef-e609-4d55-bc71-ddb9c9ff2f3c@app.fastmail.com> (raw)
In-Reply-To: <20260525205736.1c76666f@playground>

On Tue, 26 May 2026, at 1:57 AM, imnozi@gmail.com wrote:
> iptables v1.8.7 (legacy)
> ipset v6.34, protocol version: 6
>
> I have four sets:
>   - blockSetHost (hash:ip)
>   - blockSetNet (hash:net)
>   - whiteSetHost (hash:ip)
>   - whiteSetNet (hash:net)
>
> I added rules to match the block sets in filter to INPUT, FORWARD and 
> OUTPUT. The rules match and jump to chain blDrop. In blDrop, if either 
> white set matches, control returns. If no match, the packet is dropped.
>
> This works well in filter. But there's one artifact. The blocked 
> packets are 'accounted' to the internal server where they would have 
> gone.

The meaning of this isn't altogether clear. I presume that you are referring to counters in some capacity.

>
> To fix this, I added the rules below to mangle. Here in mangle, the 
> white sets never match and all of the packets (that matched the block 
> sets) are dropped.

Be sure that you need to match on the NEW state. Otherwise, -t raw -A PREROUTING makes for a less expensive way of dropping ingress packets at the border.

>
> Is this another instance of 'it doesn't work in mangle or in PREROUTING'?

This is unlikely. Both -m set and -m state work in the same way across tables, though the raw table precludes matching on conntrack state.

>
> Thanks,
> Neal
>
> ----
> The rules used in mangle; eth3 is internet:
> -A blDrop -m set --match-set whiteSetNet src -j RETURN
> -A blDrop -m set --match-set whiteSetHost src -j RETURN
> -A blDrop -j DROP
>
> -A PREROUTING -i eth3 -p udp -m set --match-set blockSetHost src -m 
> state --state NEW -j blDrop
> -A PREROUTING -i eth3 -p tcp -m set --match-set blockSetHost src -m 
> state --state NEW -j blDrop
> -A PREROUTING -i eth3 -p udp -m set --match-set blockSetNet src -m 
> state --state NEW -j blDrop
> -A PREROUTING -i eth3 -p tcp -m set --match-set blockSetNet src -m 
> state --state NEW -j blDrop

An iptables-save -c dump would be preferable. These excerpts don't unambiguously qualify the containing table names. In particular, there is no way for the reader to determine whether the chain named "blDrop" in whatever table that may be is acting in the same way as the chain named "blDrop" that may still exist - or have once existed - in another table.

-- 
Kerin Millar

  reply	other threads:[~2026-05-26  1:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-26  0:57 ipset not completely working in mangle:PREROUTING imnozi
2026-05-26  1:57 ` Kerin Millar [this message]
2026-05-26  3:57   ` imnozi
2026-05-26  7:51     ` Jozsef Kadlecsik
2026-05-26 10:24       ` Slavko
2026-05-27  1:42 ` imnozi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a276ecef-e609-4d55-bc71-ddb9c9ff2f3c@app.fastmail.com \
    --to=kfm@plushkava.net \
    --cc=imnozi@gmail.com \
    --cc=netfilter@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox