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.
Unified · Split
| @@ -104,7 +104,7 @@ static unsigned int check_hlist(struct net *net, · 103 unmodified lines | ||
| 104 | 104 | struct nf_conn *found_ct; |
| 105 | 105 | unsigned int length = 0; |
| 106 | 106 | |
| 107 | − *addit = true; | |
| 107 | + *addit = tuple ? true : false; | |
| 108 | 108 | |
| 109 | 109 | /* check the saved connections */ |
| 110 | 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 | 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 | 122 | * Just to be sure we have it only once in the list. |
| 123 | 123 | * 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 | 220 | goto restart; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | + if (!tuple) | |
| 224 | + return 0; | |
| 225 | + | |
| 223 | 226 | /* no match, need to insert new node */ |
| 224 | 227 | rbconn = kmem_cache_alloc(conncount_rb_cachep, GFP_ATOMIC); |
| 225 | 228 | if (rbconn == NULL) |
| @@ -242,6 +245,9 @@ count_tree(struct net *net, struct rb_root *root, · 16 unmodified lines | ||
| 242 | 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 | + */ | |
| 245 | 251 | unsigned int nf_conncount_count(struct net *net, |
| 246 | 252 | struct nf_conncount_data *data, |
| 247 | 253 | const u32 *key, |