History

netfilter: conncount: Support count only use case

Currently, nf_conncount_count() counts the number of connections that matches key and inserts a conntrack 'tuple' with the same key into the accounting data structure. This patch supports another use case that only counts the number of connections where 'tuple' is not provided. Therefore, proper changes are made on nf_conncount_count() to support the case where 'tuple' is NULL. This could be useful for querying statistics or debugging purpose.

Yi-Hung Wei committed 8 years ago

Commit 35d8deb1 parent 6aec2081 file · +8 −2Browse files

Unified · Split

net/netfilter/nf_conncount.c+8−2
@@ -104,7 +104,7 @@ static unsigned int check_hlist(struct net *net, · 103 unmodified lines
104104 struct nf_conn *found_ct;
105105 unsigned int length = 0;
106106
107− *addit = true;
107+ *addit = tuple ? true : false;
108108
109109 /* check the saved connections */
110110 hlist_for_each_entry_safe(conn, n, head, node) {
@@ -117,7 +117,7 @@ static unsigned int check_hlist(struct net *net, · 6 unmodified lines
117117
118118 found_ct = nf_ct_tuplehash_to_ctrack(found);
119119
120− if (nf_ct_tuple_equal(&conn->tuple, tuple)) {
120+ if (tuple && nf_ct_tuple_equal(&conn->tuple, tuple)) {
121121 /*
122122 * Just to be sure we have it only once in the list.
123123 * We should not see tuples twice unless someone hooks
@@ -220,6 +220,9 @@ count_tree(struct net *net, struct rb_root *root, · 96 unmodified lines
220220 goto restart;
221221 }
222222
223+ if (!tuple)
224+ return 0;
225+
223226 /* no match, need to insert new node */
224227 rbconn = kmem_cache_alloc(conncount_rb_cachep, GFP_ATOMIC);
225228 if (rbconn == NULL)
@@ -242,6 +245,9 @@ count_tree(struct net *net, struct rb_root *root, · 16 unmodified lines
242245 return 1;
243246 }
244247
248+/* Count and return number of conntrack entries in 'net' with particular 'key'.
249+ * If 'tuple' is not null, insert it into the accounting data structure.
250+ */
245251 unsigned int nf_conncount_count(struct net *net,
246252 struct nf_conncount_data *data,
247253 const u32 *key,