diff options
author | /C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org> | 2008-01-23 10:30:21 +0000 |
---|---|---|
committer | /C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org> | 2008-01-23 10:30:21 +0000 |
commit | a0754a2e4a63642e6fefb7bfbb19b9f5f9295009 (patch) | |
tree | 99bdabe7c5db15ac1939eee39faf788743a76775 | |
parent | 86c4c05681e8e38616fb7b0b575b4cd944ddfa83 (diff) | |
download | conntrack-tools-a0754a2e4a63642e6fefb7bfbb19b9f5f9295009.tar.gz conntrack-tools-a0754a2e4a63642e6fefb7bfbb19b9f5f9295009.zip |
Max Kellermann <max@duempel.org>:
added struct local_server, several cleanups in local socket infrastructure
This patch include minor changes by the comitter
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | include/conntrackd.h | 2 | ||||
-rw-r--r-- | include/local.h | 11 | ||||
-rw-r--r-- | src/local.c | 18 | ||||
-rw-r--r-- | src/run.c | 13 |
5 files changed, 27 insertions, 18 deletions
@@ -91,6 +91,7 @@ o improve error message if netlink initialization fails o merge mod_alarm() into add_alarm(), remove alarm_set_expiration() o remove init_alarm() before add_alarm() o fix error checking of local_create_server() +o added struct local_server, several cleanups in local socket infrastructure version 0.9.5 (2007/07/29) ------------------------------ diff --git a/include/conntrackd.h b/include/conntrackd.h index b223a17..47898e2 100644 --- a/include/conntrackd.h +++ b/include/conntrackd.h @@ -98,7 +98,7 @@ struct ct_general_state { sigset_t block; FILE *log; FILE *stats_log; - int local; + struct local_server local; struct ct_mode *mode; struct ignore_pool *ignore_pool; diff --git a/include/local.h b/include/local.h index be77d35..6940755 100644 --- a/include/local.h +++ b/include/local.h @@ -11,10 +11,15 @@ struct local_conf { char path[UNIX_PATH_MAX]; }; +struct local_server { + int fd; + char path[UNIX_PATH_MAX]; +}; + /* local server */ -int local_server_create(struct local_conf *conf); -void local_server_destroy(int fd, const char *); -int do_local_server_step(int fd, void *data, +int local_server_create(struct local_server *server, struct local_conf *conf); +void local_server_destroy(struct local_server *server); +int do_local_server_step(struct local_server *server, void *data, void (*process)(int fd, void *data)); /* local client */ diff --git a/src/local.c b/src/local.c index f0aba1c..258605f 100644 --- a/src/local.c +++ b/src/local.c @@ -26,7 +26,7 @@ #include <arpa/inet.h> #include <sys/un.h> -int local_server_create(struct local_conf *conf) +int local_server_create(struct local_server *server, struct local_conf *conf) { int fd; int len; @@ -59,23 +59,27 @@ int local_server_create(struct local_conf *conf) return -1; } - return fd; + server->fd = fd; + strcpy(server->path, conf->path); + + return 0; } -void local_server_destroy(int fd, const char *path) +void local_server_destroy(struct local_server *server) { - unlink(path); - close(fd); + unlink(server->path); + close(server->fd); } -int do_local_server_step(int fd, void *data, +int do_local_server_step(struct local_server *server, void *data, void (*process)(int fd, void *data)) { int rfd; struct sockaddr_un local; socklen_t sin_size = sizeof(struct sockaddr_un); - if ((rfd = accept(fd, (struct sockaddr *)&local, &sin_size)) == -1) + rfd = accept(server->fd, (struct sockaddr *) &local, &sin_size); + if (rfd == -1) return -1; process(rfd, data); @@ -40,7 +40,7 @@ void killer(int foo) nfct_close(STATE(dump)); ignore_pool_destroy(STATE(ignore_pool)); - local_server_destroy(STATE(local), CONFIG(local).path); + local_server_destroy(&STATE(local)); STATE(mode)->kill(); destroy_alarm_hash(); unlink(CONFIG(lockfile)); @@ -115,8 +115,7 @@ init(void) } /* local UNIX socket */ - STATE(local) = local_server_create(&CONFIG(local)); - if (STATE(local) == -1) { + if (local_server_create(&STATE(local), &CONFIG(local)) == -1) { dlog(LOG_ERR, "can't open unix socket!"); return -1; } @@ -165,10 +164,10 @@ static void __run(struct timeval *next_alarm) fd_set readfds; FD_ZERO(&readfds); - FD_SET(STATE(local), &readfds); + FD_SET(STATE(local).fd, &readfds); FD_SET(nfct_fd(STATE(event)), &readfds); - max = MAX(STATE(local), nfct_fd(STATE(event))); + max = MAX(STATE(local).fd, nfct_fd(STATE(event))); if (STATE(mode)->add_fds_to_set) max = MAX(max, STATE(mode)->add_fds_to_set(&readfds)); @@ -187,8 +186,8 @@ static void __run(struct timeval *next_alarm) sigprocmask(SIG_BLOCK, &STATE(block), NULL); /* order received via UNIX socket */ - if (FD_ISSET(STATE(local), &readfds)) - do_local_server_step(STATE(local), NULL, local_handler); + if (FD_ISSET(STATE(local).fd, &readfds)) + do_local_server_step(&STATE(local), NULL, local_handler); /* conntrack event has happened */ if (FD_ISSET(nfct_fd(STATE(event)), &readfds)) { |