Skip to contentSkip to conversation

netfilter: ctnetlink: remove expired entries first

PATCH Applied Florian Westphal 3 participants 9 messages Dec 9, 2021 – Dec 23, 2021

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 netfilter: ctnetlink: remove expired entries first

When dumping conntrack table to userspace via ctnetlink, check if the ct has already expired before doing any of the 'skip' checks.

This expires dead entries faster.
/proc handler also removes outdated entries first.

---
Vitaly, I suspect this might be related to the issue you reported, I suspect we skip the NAT-clash entries instead of evicting them from ctnetlink path too.

 net/netfilter/nf_conntrack_netlink.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/netfilter/nf_conntrack_netlink.c +3 -2
index 81d03acf68d4..ec4164c32d27 100644
@@ -1195,8 +1195,6 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
 		}
 		hlist_nulls_for_each_entry(h, n, &nf_conntrack_hash[cb->args[0]],
 					   hnnode) {
-			if (NF_CT_DIRECTION(h) != IP_CT_DIR_ORIGINAL)
-				continue;
 			ct = nf_ct_tuplehash_to_ctrack(h);
 			if (nf_ct_is_expired(ct)) {
 				if (i < ARRAY_SIZE(nf_ct_evict) &&
@@ -1208,6 +1206,9 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
 			if (!net_eq(net, nf_ct_net(ct)))
 				continue;
 
+			if (NF_CT_DIRECTION(h) != IP_CT_DIR_ORIGINAL)
+				continue;
+
 			if (cb->args[1]) {
 				if (ct != last)
 					continue;
Signature · 1 line
2.32.0
#1 lore raw
Quoted 41 lines · Florian Westphal

When dumping conntrack table to userspace via ctnetlink, check if the ct has already expired before doing any of the 'skip' checks.

This expires dead entries faster.
/proc handler also removes outdated entries first.

---
Vitaly, I suspect this might be related to the issue you reported, I suspect we skip the NAT-clash entries instead of evicting them from ctnetlink path too.

 net/netfilter/nf_conntrack_netlink.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/netfilter/nf_conntrack_netlink.c +3 -3
index 81d03acf68d4..ec4164c32d27 100644
@@ -1195,8 +1195,6 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
                }
                hlist_nulls_for_each_entry(h, n, &nf_conntrack_hash[cb->args[0]],
                                           hnnode) {
-                       if (NF_CT_DIRECTION(h) != IP_CT_DIR_ORIGINAL)
-                               continue;
                        ct = nf_ct_tuplehash_to_ctrack(h);
                        if (nf_ct_is_expired(ct)) {
                                if (i < ARRAY_SIZE(nf_ct_evict) &&
@@ -1208,6 +1206,9 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
                        if (!net_eq(net, nf_ct_net(ct)))
                                continue;
 
+                       if (NF_CT_DIRECTION(h) != IP_CT_DIR_ORIGINAL)
+                               continue;
+
                        if (cb->args[1]) {
                                if (ct != last)
                                        continue;
--
Quoted 2 lines

2.32.0

Florian, thanks for prompt turnaround on this. Seeing conntrack -C
107530
mandates the check what flows consume this many entries. I cannot do this if conntrack -L skips anything while kernel defaults to not exposing conntrack table via /proc. This server is not supposed to NAT anything by the way. We use some -j NOTRACK rules and I'd like to see what flows evade those rules and consume so many slots. Could you perhaps recommend a way to achieve this other than reconfiguring the kernel?

author maintainer
#2 lore raw
Quoted 27 lines · Vitaly Zuevsky
Quoted 24 lines
net/netfilter/nf_conntrack_netlink.c +3 -3
index 81d03acf68d4..ec4164c32d27 100644
@@ -1195,8 +1195,6 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
                }
                hlist_nulls_for_each_entry(h, n, &nf_conntrack_hash[cb->args[0]],
                                           hnnode) {
-                       if (NF_CT_DIRECTION(h) != IP_CT_DIR_ORIGINAL)
-                               continue;
                        ct = nf_ct_tuplehash_to_ctrack(h);
                        if (nf_ct_is_expired(ct)) {
                                if (i < ARRAY_SIZE(nf_ct_evict) &&
@@ -1208,6 +1206,9 @@ ctnetlink_dump_table(struct sk_buff *skb, struct netlink_callback *cb)
                        if (!net_eq(net, nf_ct_net(ct)))
                                continue;
 
+                       if (NF_CT_DIRECTION(h) != IP_CT_DIR_ORIGINAL)
+                               continue;
+
                        if (cb->args[1]) {
                                if (ct != last)
                                        continue;
--
Quoted 2 lines

2.32.0

Quoted 7 lines

Florian, thanks for prompt turnaround on this. Seeing conntrack -C
107530
mandates the check what flows consume this many entries. I cannot do this if conntrack -L skips anything while kernel defaults to not exposing conntrack table via /proc. This server is not supposed to NAT anything by the way.

Then this patch doesn't change anything.

Maybe 'conntrack -L unconfirmed' or 'conntrack -L dying' show something?

#3 lore raw
Quoted 12 lines · Florian Westphal
Quoted 11 lines
Quoted 3 lines

--
2.32.0

Florian, thanks for prompt turnaround on this. Seeing conntrack -C
107530
mandates the check what flows consume this many entries. I cannot do this if conntrack -L skips anything while kernel defaults to not exposing conntrack table via /proc. This server is not supposed to NAT anything by the way.

Quoted 3 lines

Then this patch doesn't change anything.

Maybe 'conntrack -L unconfirmed' or 'conntrack -L dying' show something?

Are you saying that was a patch? v2.32.0? Mind sharing a link for downloading the source and/or packaged release?
I would like to test it just in case, and if no luck, what do i do to file it as a bug?

#4 lore raw

Hi Florian

Do you have any news on this?
Meanwhile I cloned the repo git://git.netfilter.org/conntrack-tools,
ran ./autogen.sh to produce configure, and the latter failed with:

checking for rpc/rpc_msg.h... yes
./configure: line 13329: syntax error near unexpected token LIBTIRPC,' ./configure: line 13329: PKG_CHECK_MODULES(LIBTIRPC, libtirpc >= 0.1)'

Interestingly, PKG_CHECK_MODULES was never defined there. Is that repository for production code - I am confused?

Thank you.

Br Vitaly

Quoted 22 lines · Vitaly Zuevsky
Quoted 12 lines · Florian Westphal
Quoted 11 lines
Quoted 3 lines

--
2.32.0

Florian, thanks for prompt turnaround on this. Seeing conntrack -C
107530
mandates the check what flows consume this many entries. I cannot do this if conntrack -L skips anything while kernel defaults to not exposing conntrack table via /proc. This server is not supposed to NAT anything by the way.

Quoted 3 lines

Then this patch doesn't change anything.

Maybe 'conntrack -L unconfirmed' or 'conntrack -L dying' show something?

Are you saying that was a patch? v2.32.0? Mind sharing a link for downloading the source and/or packaged release?
I would like to test it just in case, and if no luck, what do i do to file it as a bug?

author maintainer
#5 lore raw
Quoted 6 lines · Vitaly Zuevsky

Hi Florian

Do you have any news on this?
Meanwhile I cloned the repo git://git.netfilter.org/conntrack-tools,
ran ./autogen.sh to produce configure, and the latter failed with:

Quoted 6 lines

checking for rpc/rpc_msg.h... yes
./configure: line 13329: syntax error near unexpected token LIBTIRPC,' ./configure: line 13329: PKG_CHECK_MODULES(LIBTIRPC, libtirpc >= 0.1)'

Interestingly, PKG_CHECK_MODULES was never defined there. Is that repository for production code - I am confused?

Sure. But the patch is for the kernel.
I already mentioned that this doesn't handle anything for non-nat case.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Maybe 'conntrack -L unconfirmed' or 'conntrack -L dying' show something?

Still stands.

Also, is there really a discrepancy? Please show output of

conntrack -C
conntrack -L | wc -l
conntrack -C

"conntrack -L" reclaims dead/timed-out entries, conntrack -C currently does not.

#6 lore raw
Quoted 7 lines · Florian Westphal

Sure. But the patch is for the kernel.
I already mentioned that this doesn't handle anything for non-nat case.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Maybe 'conntrack -L unconfirmed' or 'conntrack -L dying' show something?

Still stands.

Quoted 8 lines

Also, is there really a discrepancy? Please show output of

conntrack -C
conntrack -L | wc -l
conntrack -C

"conntrack -L" reclaims dead/timed-out entries, conntrack -C currently does not.

Of course... It is an order of magnitude difference:

# conntrack -L unconfirmed
conntrack v1.4.4 (conntrack-tools): 0 flow entries have been shown.
# conntrack -L dying
conntrack v1.4.4 (conntrack-tools): 0 flow entries have been shown.
# conntrack -C
88064
# conntrack -L | wc -l
conntrack v1.4.4 (conntrack-tools): 7641 flow entries have been shown.
7641
# conntrack -C
87706
# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.5 LTS"
#7 lore raw

Hi Florian

Further to our investigation, I have identified the cause of confusion:

# conntrack -C
141412
# conntrack -L >/dev/null
conntrack v1.4.4 (conntrack-tools): 8342 flow entries have been shown.
# conntrack -f ipv6 -L >/dev/null
conntrack v1.4.4 (conntrack-tools): 124358 flow entries have been shown.

so -C option implicitly sums up ipv4 and ipv6 counts, and -L option defaults to ipv4. This is neither a consistent UX practice nor properly documented. I am happy to bring it up - Christmas present xD

maintainer Applied
#8 lore raw
In reply to Florian Westphal
Quoted 5 lines · Florian Westphal

When dumping conntrack table to userspace via ctnetlink, check if the ct has already expired before doing any of the 'skip' checks.

This expires dead entries faster.
/proc handler also removes outdated entries first.

Applied, thanks