Skip to content

Commit bc92470

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: conntrack: add clash resolution stat counter
There is a misconception about what "insert_failed" means. We increment this even when a clash got resolved, so it might not indicate a problem. Add a dedicated counter for clash resolution and only increment insert_failed if a clash cannot be resolved. For the old /proc interface, export this in place of an older stat that got removed a while back. For ctnetlink, export this with a new attribute. Also correct an outdated comment that implies we add a duplicate tuple -- we only add the (unique) reply direction. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 4afc41d commit bc92470

5 files changed

Lines changed: 11 additions & 6 deletions

File tree

‎include/linux/netfilter/nf_conntrack_common.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct ip_conntrack_stat {
1010
unsigned int invalid;
1111
unsigned int insert;
1212
unsigned int insert_failed;
13+
unsigned int clash_resolve;
1314
unsigned int drop;
1415
unsigned int early_drop;
1516
unsigned int error;

‎include/uapi/linux/netfilter/nfnetlink_conntrack.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ enum ctattr_stats_cpu {
256256
CTA_STATS_EARLY_DROP,
257257
CTA_STATS_ERROR,
258258
CTA_STATS_SEARCH_RESTART,
259+
CTA_STATS_CLASH_RESOLVE,
259260
__CTA_STATS_MAX,
260261
};
261262
#define CTA_STATS_MAX (__CTA_STATS_MAX - 1)

‎net/netfilter/nf_conntrack_core.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,6 @@ nf_conntrack_hash_check_insert(struct nf_conn *ct)
859859

860860
out:
861861
nf_conntrack_double_unlock(hash, reply_hash);
862-
NF_CT_STAT_INC(net, insert_failed);
863862
local_bh_enable();
864863
return -EEXIST;
865864
}
@@ -934,7 +933,7 @@ static int __nf_ct_resolve_clash(struct sk_buff *skb,
934933
nf_conntrack_put(&loser_ct->ct_general);
935934
nf_ct_set(skb, ct, ctinfo);
936935

937-
NF_CT_STAT_INC(net, insert_failed);
936+
NF_CT_STAT_INC(net, clash_resolve);
938937
return NF_ACCEPT;
939938
}
940939

@@ -998,6 +997,8 @@ static int nf_ct_resolve_clash_harder(struct sk_buff *skb, u32 repl_idx)
998997

999998
hlist_nulls_add_head_rcu(&loser_ct->tuplehash[IP_CT_DIR_REPLY].hnnode,
1000999
&nf_conntrack_hash[repl_idx]);
1000+
1001+
NF_CT_STAT_INC(net, clash_resolve);
10011002
return NF_ACCEPT;
10021003
}
10031004

@@ -1027,10 +1028,10 @@ static int nf_ct_resolve_clash_harder(struct sk_buff *skb, u32 repl_idx)
10271028
*
10281029
* Failing that, the new, unconfirmed conntrack is still added to the table
10291030
* provided that the collision only occurs in the ORIGINAL direction.
1030-
* The new entry will be added after the existing one in the hash list,
1031+
* The new entry will be added only in the non-clashing REPLY direction,
10311032
* so packets in the ORIGINAL direction will continue to match the existing
10321033
* entry. The new entry will also have a fixed timeout so it expires --
1033-
* due to the collision, it will not see bidirectional traffic.
1034+
* due to the collision, it will only see reply traffic.
10341035
*
10351036
* Returns NF_DROP if the clash could not be resolved.
10361037
*/

‎net/netfilter/nf_conntrack_netlink.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2516,7 +2516,9 @@ ctnetlink_ct_stat_cpu_fill_info(struct sk_buff *skb, u32 portid, u32 seq,
25162516
nla_put_be32(skb, CTA_STATS_EARLY_DROP, htonl(st->early_drop)) ||
25172517
nla_put_be32(skb, CTA_STATS_ERROR, htonl(st->error)) ||
25182518
nla_put_be32(skb, CTA_STATS_SEARCH_RESTART,
2519-
htonl(st->search_restart)))
2519+
htonl(st->search_restart)) ||
2520+
nla_put_be32(skb, CTA_STATS_CLASH_RESOLVE,
2521+
htonl(st->clash_resolve)))
25202522
goto nla_put_failure;
25212523

25222524
nlmsg_end(skb, nlh);

‎net/netfilter/nf_conntrack_standalone.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ static int ct_cpu_seq_show(struct seq_file *seq, void *v)
435435
seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x "
436436
"%08x %08x %08x %08x %08x %08x %08x %08x %08x\n",
437437
nr_conntracks,
438-
0,
438+
st->clash_resolve, /* was: searched */
439439
st->found,
440440
0,
441441
st->invalid,

0 commit comments

Comments
 (0)