From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [nf-next PATCH 4/4] netfilter: conntrack: Improve invalid packet stats
Date: Tue, 8 Sep 2026 12:02:56 +0200 [thread overview]
Message-ID: <20260908100256.2648175-5-phil@nwl.cc> (raw)
In-Reply-To: <20260908100256.2648175-1-phil@nwl.cc>
If nf_ct_seq_adjust detects a malformed packet, increment 'invalid'
counter instead of 'drop'.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
net/netfilter/nf_conntrack_core.c | 7 ++++++-
net/netfilter/nf_conntrack_proto.c | 14 ++++++++++----
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index b0cd530cf8fe..45e0580e72d2 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -2241,7 +2241,12 @@ static int nf_confirm_cthelper(struct sk_buff *skb, struct nf_conn *ct,
if (test_bit(IPS_SEQ_ADJUST_BIT, &ct->status) &&
!nf_is_loopback_packet(skb)) {
- if (nf_ct_seq_adjust(skb, ct, ctinfo, protoff) < 0) {
+ int ret = nf_ct_seq_adjust(skb, ct, ctinfo, protoff);
+
+ if (ret == -EINVAL) {
+ NF_CT_STAT_INC_ATOMIC(nf_ct_net(ct), invalid);
+ return NF_DROP;
+ } else if (ret < 0) {
NF_CT_STAT_INC_ATOMIC(nf_ct_net(ct), drop);
return NF_DROP;
}
diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
index 0db404f662de..e4cc9a69494e 100644
--- a/net/netfilter/nf_conntrack_proto.c
+++ b/net/netfilter/nf_conntrack_proto.c
@@ -194,10 +194,16 @@ unsigned int nf_confirm(void *priv,
}
}
- if (seqadj_needed &&
- nf_ct_seq_adjust(skb, ct, ctinfo, protoff) < 0) {
- NF_CT_STAT_INC_ATOMIC(nf_ct_net(ct), drop);
- return NF_DROP;
+ if (seqadj_needed) {
+ int ret = nf_ct_seq_adjust(skb, ct, ctinfo, protoff);
+
+ if (ret == -EINVAL) {
+ NF_CT_STAT_INC_ATOMIC(nf_ct_net(ct), invalid);
+ return NF_DROP;
+ } else if (ret < 0) {
+ NF_CT_STAT_INC_ATOMIC(nf_ct_net(ct), drop);
+ return NF_DROP;
+ }
}
/* We've seen it coming out the other side: confirm it */
--
2.54.0
prev parent reply other threads:[~2026-09-08 10:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 10:02 [nf-next PATCH 0/4] netfilter: Conntrack counter review Phil Sutter
2026-09-08 10:02 ` [nf-next PATCH 1/4] netfilter: conntrack: Untangle insert_failed counter from others Phil Sutter
2026-09-08 10:02 ` [nf-next PATCH 2/4] netfilter: conntrack: Untangle drop and invalid counters Phil Sutter
2026-09-08 10:02 ` [nf-next PATCH 3/4] netfilter: conntrack: nf_ct_seq_adjust to return error cause Phil Sutter
2026-09-08 10:02 ` Phil Sutter [this message]
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=20260908100256.2648175-5-phil@nwl.cc \
--to=phil@nwl.cc \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.