2
* (C) 2006-2007 by Pablo Neira Ayuso <pablo@netfilter.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
#include "conntrackd.h"
24
#include "us-conntrack.h"
26
#include <libnetfilter_conntrack/libnetfilter_conntrack.h>
30
struct __dump_container {
35
static int do_dump(void *data1, void *data2)
39
struct __dump_container *container = data1;
40
struct us_conntrack *u = data2;
44
memset(buf, 0, sizeof(buf));
45
size = nfct_snprintf(buf,
52
for (i = 0; i < u->cache->num_features; i++) {
53
if (u->cache->features[i]->dump) {
54
size += u->cache->features[i]->dump(u,
58
data += u->cache->features[i]->size;
61
size += sprintf(buf+size, "\n");
62
if (send(container->fd, buf, size, 0) == -1) {
70
void cache_dump(struct cache *c, int fd, int type)
72
struct __dump_container tmp = {
77
hashtable_iterate(c->h, (void *) &tmp, do_dump);
80
/* no need to clone, called from child process */
81
static int do_commit(void *data1, void *data2)
84
struct cache *c = data1;
85
struct us_conntrack *u = data2;
86
struct nf_conntrack *ct = u->ct;
89
* Set a reduced timeout for candidate-to-be-committed
90
* conntracks that live in the external cache
92
nfct_set_attr_u32(ct, ATTR_TIMEOUT, CONFIG(commit_timeout));
94
ret = nl_create_conntrack(ct);
108
/* keep iterating even if we have found errors */
112
void cache_commit(struct cache *c)
114
unsigned int commit_ok = c->commit_ok;
115
unsigned int commit_exist = c->commit_exist;
116
unsigned int commit_fail = c->commit_fail;
118
hashtable_iterate(c->h, c, do_commit);
120
/* calculate new entries committed */
121
commit_ok = c->commit_ok - commit_ok;
122
commit_fail = c->commit_fail - commit_fail;
123
commit_exist = c->commit_exist - commit_exist;
126
dlog(LOG_NOTICE, "Committed %u new entries", commit_ok);
129
dlog(LOG_NOTICE, "%u entries ignored, "
130
"already exist", commit_exist);
132
dlog(LOG_NOTICE, "%u entries can't be "
133
"committed", commit_fail);
136
static int do_flush(void *data1, void *data2)
138
struct cache *c = data1;
139
struct us_conntrack *u = data2;
146
void cache_flush(struct cache *c)
148
hashtable_iterate(c->h, c, do_flush);