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
104 struct nf_conn *found_ct;104 struct nf_conn *found_ct;
105 unsigned int length = 0;105 unsigned int length = 0;
106 106
107 *addit = true;107 *addit = tuple ? true : false;
108 108
109 /* check the saved connections */109 /* check the saved connections */
110 hlist_for_each_entry_safe(conn, n, head, node) {110 hlist_for_each_entry_safe(conn, n, head, node) {
@@ -117,7 +117,7 @@ static unsigned int check_hlist(struct net *net, · 6 unmodified lines
117 117
118 found_ct = nf_ct_tuplehash_to_ctrack(found);118 found_ct = nf_ct_tuplehash_to_ctrack(found);
119 119
120 if (nf_ct_tuple_equal(&conn->tuple, tuple)) {120 if (tuple && nf_ct_tuple_equal(&conn->tuple, tuple)) {
121 /*121 /*
122 * Just to be sure we have it only once in the list.122 * Just to be sure we have it only once in the list.
123 * We should not see tuples twice unless someone hooks123 * 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
220 goto restart;220 goto restart;
221 }221 }
222 222
223 if (!tuple)
224 return 0;
225
223 /* no match, need to insert new node */226 /* no match, need to insert new node */
224 rbconn = kmem_cache_alloc(conncount_rb_cachep, GFP_ATOMIC);227 rbconn = kmem_cache_alloc(conncount_rb_cachep, GFP_ATOMIC);
225 if (rbconn == NULL)228 if (rbconn == NULL)
@@ -242,6 +245,9 @@ count_tree(struct net *net, struct rb_root *root, · 16 unmodified lines
242 return 1;245 return 1;
243}246}
244 247
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 */
245unsigned int nf_conncount_count(struct net *net,251unsigned int nf_conncount_count(struct net *net,
246 struct nf_conncount_data *data,252 struct nf_conncount_data *data,
247 const u32 *key,253 const u32 *key,