netfilter: ctnetlink: support individual atomic-get-and-reset of counters
authorPablo Neira Ayuso <pablo@netfilter.org>
Wed, 14 Dec 2011 12:01:32 +0000 (13:01 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Sun, 18 Dec 2011 00:31:49 +0000 (01:31 +0100)
This allows to use the get operation to atomically get-and-reset
counters.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/netfilter/nf_conntrack_netlink.c

index 77d209c..636617c 100644 (file)
@@ -1015,6 +1015,17 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
        if (err < 0)
                goto out;
 
+       if (NFNL_MSG_TYPE(nlh->nlmsg_type) == IPCTNL_MSG_CT_GET_CTRZERO) {
+               struct nf_conn_counter *acct;
+
+               acct = nf_conn_acct_find(ct);
+               if (acct) {
+                       atomic64_set(&acct[IP_CT_DIR_ORIGINAL].bytes, 0);
+                       atomic64_set(&acct[IP_CT_DIR_ORIGINAL].packets, 0);
+                       atomic64_set(&acct[IP_CT_DIR_REPLY].bytes, 0);
+                       atomic64_set(&acct[IP_CT_DIR_REPLY].packets, 0);
+               }
+       }
        return 0;
 
 free: