summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/run.c25
-rw-r--r--src/stats-mode.c1
-rw-r--r--src/sync-mode.c31
3 files changed, 21 insertions, 36 deletions
diff --git a/src/run.c b/src/run.c
index b436113..a6dfe15 100644
--- a/src/run.c
+++ b/src/run.c
@@ -278,6 +278,12 @@ init(void)
STATE(mode) = &stats_mode;
}
+ STATE(fds) = create_fds();
+ if (STATE(fds) == NULL) {
+ dlog(LOG_ERR, "can't create file descriptor pool");
+ return -1;
+ }
+
/* Initialization */
if (STATE(mode)->init() == -1) {
dlog(LOG_ERR, "initialization failed");
@@ -289,6 +295,7 @@ init(void)
dlog(LOG_ERR, "can't open unix socket!");
return -1;
}
+ register_fd(STATE(local).fd, STATE(fds));
STATE(event) = nl_init_event_handler();
if (STATE(event) == NULL) {
@@ -298,6 +305,7 @@ init(void)
return -1;
}
nfct_callback_register(STATE(event), NFCT_T_ALL, event_handler, NULL);
+ register_fd(nfct_fd(STATE(event)), STATE(fds));
STATE(dump) = nl_init_dump_handler();
if (STATE(dump) == NULL) {
@@ -324,6 +332,7 @@ init(void)
NFCT_T_ALL,
STATE(mode)->resync,
NULL);
+ register_fd(nfct_fd(STATE(resync)), STATE(fds));
/* no callback, it does not do anything with the output */
STATE(request) = nl_init_request_handler();
@@ -336,22 +345,6 @@ init(void)
init_alarm(&STATE(resync_alarm), NULL, do_resync_alarm);
- STATE(fds) = create_fds();
- if (STATE(fds) == NULL) {
- dlog(LOG_ERR, "can't create file descriptor pool");
- return -1;
- }
-
- register_fd(STATE(local).fd, STATE(fds));
- register_fd(nfct_fd(STATE(event)), STATE(fds));
- register_fd(nfct_fd(STATE(resync)), STATE(fds));
-
- if (STATE(mode)->register_fds &&
- STATE(mode)->register_fds(STATE(fds)) == -1) {
- dlog(LOG_ERR, "fds registration failed");
- return -1;
- }
-
/* Signals handling */
sigemptyset(&STATE(block));
sigaddset(&STATE(block), SIGTERM);
diff --git a/src/stats-mode.c b/src/stats-mode.c
index 159bbef..b742c0c 100644
--- a/src/stats-mode.c
+++ b/src/stats-mode.c
@@ -191,7 +191,6 @@ static int event_destroy_stats(struct nf_conntrack *ct)
struct ct_mode stats_mode = {
.init = init_stats,
- .register_fds = NULL,
.run = NULL,
.local = local_handler_stats,
.kill = kill_stats,
diff --git a/src/sync-mode.c b/src/sync-mode.c
index 2e189cb..54d0ebb 100644
--- a/src/sync-mode.c
+++ b/src/sync-mode.c
@@ -207,6 +207,8 @@ static void mcast_iface_handler(void)
static int init_sync(void)
{
+ int i;
+
state.sync = malloc(sizeof(struct ct_sync_state));
if (!state.sync) {
dlog(LOG_ERR, "can't allocate memory for sync");
@@ -261,6 +263,11 @@ static int init_sync(void)
dlog(LOG_ERR, "can't open multicast server!");
return -1;
}
+ for (i=0; i<STATE_SYNC(mcast_server)->num_links; i++) {
+ int fd = mcast_get_fd(STATE_SYNC(mcast_server)->multi[i]);
+ if (register_fd(fd, STATE(fds)) == -1)
+ return -1;
+ }
/* multicast client to send events on the wire */
STATE_SYNC(mcast_client) =
@@ -286,12 +293,17 @@ static int init_sync(void)
dlog(LOG_ERR, "can't open interface watcher");
return -1;
}
+ if (register_fd(nlif_fd(STATE_SYNC(mcast_iface)), STATE(fds)) == -1)
+ return -1;
STATE_SYNC(tx_queue) = queue_create(INT_MAX, QUEUE_F_EVFD);
if (STATE_SYNC(tx_queue) == NULL) {
dlog(LOG_ERR, "cannot create tx queue");
return -1;
}
+ if (register_fd(queue_get_eventfd(STATE_SYNC(tx_queue)),
+ STATE(fds)) == -1)
+ return -1;
/* initialization of multicast sequence generation */
STATE_SYNC(last_seq_sent) = time(NULL);
@@ -299,24 +311,6 @@ static int init_sync(void)
return 0;
}
-static int register_fds_sync(struct fds *fds)
-{
- int i;
-
- for (i=0; i<STATE_SYNC(mcast_server)->num_links; i++) {
- int fd = mcast_get_fd(STATE_SYNC(mcast_server)->multi[i]);
- if (register_fd(fd, fds) == -1)
- return -1;
- }
- if (register_fd(nlif_fd(STATE_SYNC(mcast_iface)), fds) == -1)
- return -1;
-
- if (register_fd(queue_get_eventfd(STATE_SYNC(tx_queue)), fds) == -1)
- return -1;
-
- return 0;
-}
-
static void run_sync(fd_set *readfds)
{
int i;
@@ -624,7 +618,6 @@ static int event_destroy_sync(struct nf_conntrack *ct)
struct ct_mode sync_mode = {
.init = init_sync,
- .register_fds = register_fds_sync,
.run = run_sync,
.local = local_handler_sync,
.kill = kill_sync,