]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
nfacct: add variable to not zero counter after read
authorEric Leblond <eric@regit.org>
Wed, 1 Aug 2012 11:27:12 +0000 (11:27 +0000)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 3 Aug 2012 09:21:59 +0000 (11:21 +0200)
The default nfacct input plugin zeroes counter after each read. This
is a limitation as other software can't use the counter at the same
time as ulogd2.

This patch adds the zerocounter variable to the NFACCT input plugin.
If set to zero, the counters are not zeroed.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
input/sum/ulogd_inpflow_NFACCT.c
ulogd.conf.in

index f3b936f5460845ff64ba12e9728774628b7f4ef8..46767b760a302b92bac579a7e12abc47958d766b 100644 (file)
@@ -40,10 +40,17 @@ static struct config_keyset nfacct_kset = {
                        .options = CONFIG_OPT_NONE,
                        .u.value = 0,
                },
+               {
+                       .key     = "zerocounter",
+                       .type    = CONFIG_TYPE_INT,
+                       .options = CONFIG_OPT_NONE,
+                       .u.value = 1,
+               }
        },
-       .num_ces = 1,
+       .num_ces = 2,
 };
 #define pollint_ce(x)  (x->ces[0])
+#define zerocounter_ce(x) (x->ces[1])
 
 enum ulogd_nfacct_keys {
        ULOGD_NFACCT_NAME,
@@ -145,14 +152,21 @@ static int nfacct_read_cb(int fd, unsigned int what, void *param)
        return ret;
 }
 
-static int nfacct_send_request(struct nfacct_pluginstance *cpi)
+static int nfacct_send_request(struct ulogd_pluginstance *upi)
 {
+       struct nfacct_pluginstance *cpi =
+               (struct nfacct_pluginstance *)upi->private;
        struct nlmsghdr *nlh;
        char buf[MNL_SOCKET_BUFFER_SIZE];
+       int flushctr;
+
+       if (zerocounter_ce(upi->config_kset).u.value != 0)
+               flushctr = NFNL_MSG_ACCT_GET_CTRZERO;
+       else
+               flushctr = NFNL_MSG_ACCT_GET;
 
        cpi->seq = time(NULL);
-       nlh = nfacct_nlmsg_build_hdr(buf, NFNL_MSG_ACCT_GET_CTRZERO,
-                                    NLM_F_DUMP, cpi->seq);
+       nlh = nfacct_nlmsg_build_hdr(buf, flushctr, NLM_F_DUMP, cpi->seq);
 
        if (mnl_socket_sendto(cpi->nl, nlh, nlh->nlmsg_len) < 0) {
                ulogd_log(ULOGD_ERROR, "Cannot send netlink message\n");
@@ -167,7 +181,7 @@ static void polling_timer_cb(struct ulogd_timer *t, void *data)
        struct nfacct_pluginstance *cpi =
                (struct nfacct_pluginstance *)upi->private;
 
-       nfacct_send_request(cpi);
+       nfacct_send_request(upi);
 
        ulogd_add_timer(&cpi->timer, pollint_ce(upi->config_kset).u.value);
 }
@@ -234,12 +248,9 @@ static int destructor_nfacct(struct ulogd_pluginstance *upi)
 
 static void signal_nfacct(struct ulogd_pluginstance *upi, int signal)
 {
-       struct nfacct_pluginstance *cpi =
-               (struct nfacct_pluginstance *)upi->private;
-
        switch (signal) {
        case SIGUSR2:
-               nfacct_send_request(cpi);
+               nfacct_send_request(upi);
                break;
        }
 }
index 5f19caedb6f34ff6fd9bfeff0434b3b9016af23e..879ab3c904f70bc4e7f88d076e26edc438631cab 100644 (file)
@@ -263,3 +263,5 @@ mark = 1
 
 [acct1]
 pollinterval = 2
+# Set to zero to avoid zeroing counters after read
+#zerocounter = 0