]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
NFCT: fix reset counters via SIGUSR2 signal
authorPablo Neira Ayuso <pablo@netfilter.org>
Wed, 13 Jan 2010 10:39:18 +0000 (11:39 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Sun, 17 Jan 2010 21:23:18 +0000 (22:23 +0100)
This patch fixes a feature that allows to force the logging of
the existing entries and reset the counters.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
input/flow/ulogd_inpflow_NFCT.c

index 0e1156f25fe48e93bb021aabba9a9aa106853671..abc94aec678cd482c60ef77c62d5bd9d31108133 100644 (file)
@@ -874,13 +874,62 @@ static int read_cb_ovh(int fd, unsigned int what, void *param)
        return 0;
 }
 
-static int get_ctr_zero(struct ulogd_pluginstance *upi)
+static int
+dump_reset_handler(enum nf_conntrack_msg_type type,
+                  struct nf_conntrack *ct, void *data)
 {
-       int family = 0; /* any */
+       struct ulogd_pluginstance *upi = data;
        struct nfct_pluginstance *cpi =
                        (struct nfct_pluginstance *)upi->private;
+       int ret = NFCT_CB_CONTINUE, rc, id;
+       struct ct_timestamp *ts;
+
+       switch(type) {
+       case NFCT_T_UPDATE:
+               id = hashtable_hash(cpi->ct_active, ct);
+               ts = (struct ct_timestamp *)
+                       hashtable_find(cpi->ct_active, ct, id);
+               if (ts)
+                       nfct_copy(ts->ct, ct, NFCT_CP_META);
+               else {
+                       ts = calloc(sizeof(struct ct_timestamp), 1);
+                       if (ts == NULL)
+                               return NFCT_CB_CONTINUE;
+
+                       ts->ct = ct;
+                       gettimeofday(&ts->time[START], NULL);
+
+                       rc = hashtable_add(cpi->ct_active, &ts->hashnode, id);
+                       if (rc < 0) {
+                               free(ts);
+                               return NFCT_CB_CONTINUE;
+                       }
+                       ret = NFCT_CB_STOLEN;
+               }
+               do_propagate_ct(upi, ct, type, ts);
+               break;
+       default:
+               ulogd_log(ULOGD_NOTICE, "unknown netlink message type\n");
+               break;
+       }
+       return ret;
+}
+
+static void get_ctr_zero(struct ulogd_pluginstance *upi)
+{
+       struct nfct_handle *h;
+       int family = AF_UNSPEC;
+
+       h = nfct_open(CONNTRACK, 0);
+       if (h == NULL) {
+               ulogd_log(ULOGD_FATAL, "Cannot dump and reset counters\n");
+               return;
+       }
+       nfct_callback_register(h, NFCT_T_ALL, &dump_reset_handler, upi);
+       if (nfct_query(h, NFCT_Q_DUMP_RESET, &family) == -1)
+               ulogd_log(ULOGD_FATAL, "Cannot dump and reset counters\n");
 
-       return nfct_query(cpi->cth, NFCT_Q_DUMP_RESET, &family);
+       nfct_close(h);
 }
 
 static void polling_timer_cb(struct ulogd_timer *t, void *data)