From 05194422ee8fa038d99fe77a2e9d776d25623fd2 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Sat, 17 Jan 2009 18:03:53 +0100 Subject: src: remove register_fds hooks This patch moves the file descriptor registration after the initialization instead of having a specific hook for this. Signed-off-by: Pablo Neira Ayuso --- include/conntrackd.h | 1 - src/run.c | 25 +++++++++---------------- src/stats-mode.c | 1 - src/sync-mode.c | 31 ++++++++++++------------------- 4 files changed, 21 insertions(+), 37 deletions(-) diff --git a/include/conntrackd.h b/include/conntrackd.h index d5b61c6..fbf126a 100644 --- a/include/conntrackd.h +++ b/include/conntrackd.h @@ -199,7 +199,6 @@ extern struct ct_general_state st; struct ct_mode { int (*init)(void); - int (*register_fds)(struct fds *fds); void (*run)(fd_set *readfds); int (*local)(int fd, int type, void *data); void (*kill)(void); 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; inum_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; inum_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, -- cgit v1.2.3