summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/conntrackd.h1
-rw-r--r--include/local.h7
-rw-r--r--src/local.c7
-rw-r--r--src/run.c22
-rw-r--r--src/stats-mode.c2
-rw-r--r--src/sync-ftfw.c5
-rw-r--r--src/sync-mode.c2
7 files changed, 26 insertions, 20 deletions
diff --git a/include/conntrackd.h b/include/conntrackd.h
index 040c252..417bac6 100644
--- a/include/conntrackd.h
+++ b/include/conntrackd.h
@@ -234,7 +234,6 @@ extern struct ct_mode stats_mode;
/* These live in run.c */
void killer(int foo);
-void local_handler(int fd, void *data);
int init(void);
void run(void);
diff --git a/include/local.h b/include/local.h
index 6940755..f9121b1 100644
--- a/include/local.h
+++ b/include/local.h
@@ -16,11 +16,16 @@ struct local_server {
char path[UNIX_PATH_MAX];
};
+/* callback return values */
+#define LOCAL_RET_ERROR -1
+#define LOCAL_RET_OK 0
+#define LOCAL_RET_STOLEN 1
+
/* local server */
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));
+ int (*process)(int fd, void *data));
/* local client */
int local_client_create(struct local_conf *conf);
diff --git a/src/local.c b/src/local.c
index 4739e56..feff608 100644
--- a/src/local.c
+++ b/src/local.c
@@ -72,7 +72,7 @@ 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))
+ int (*process)(int fd, void *data))
{
int rfd;
struct sockaddr_un local;
@@ -82,8 +82,9 @@ int do_local_server_step(struct local_server *server, void *data,
if (rfd == -1)
return -1;
- process(rfd, data);
- close(rfd);
+ /* This descriptor will be closed later, we ignore OK and errors */
+ if (process(rfd, data) != LOCAL_RET_STOLEN)
+ close(rfd);
return 0;
}
diff --git a/src/run.c b/src/run.c
index 95d51a2..87b6fb2 100644
--- a/src/run.c
+++ b/src/run.c
@@ -182,18 +182,18 @@ static void dump_stats_runtime(int fd)
send(fd, buf, size, 0);
}
-void local_handler(int fd, void *data)
+static int local_handler(int fd, void *data)
{
- int ret;
+ int ret = LOCAL_RET_OK;
int type;
ret = read(fd, &type, sizeof(type));
if (ret == -1) {
STATE(stats).local_read_failed++;
- return;
+ return LOCAL_RET_OK;
}
if (ret == 0)
- return;
+ return LOCAL_RET_OK;
switch(type) {
case FLUSH_MASTER:
@@ -207,22 +207,26 @@ void local_handler(int fd, void *data)
nl_flush_conntrack_table(STATE(flush));
exit(EXIT_SUCCESS);
}
- return;
+ break;
case RESYNC_MASTER:
STATE(stats).nl_kernel_table_resync++;
dlog(LOG_NOTICE, "resync with master table");
nl_dump_conntrack_table(STATE(dump));
- return;
+ break;
case STATS_RUNTIME:
dump_stats_runtime(fd);
- return;
+ break;
case STATS_PROCESS:
fork_process_dump(fd);
- return;
+ break;
}
- if (!STATE(mode)->local(fd, type, data))
+ ret = STATE(mode)->local(fd, type, data);
+ if (ret == LOCAL_RET_ERROR) {
STATE(stats).local_unknown_request++;
+ return LOCAL_RET_ERROR;
+ }
+ return ret;
}
static void do_overrun_resync_alarm(struct alarm_block *a, void *data)
diff --git a/src/stats-mode.c b/src/stats-mode.c
index b84c7a1..5cfb638 100644
--- a/src/stats-mode.c
+++ b/src/stats-mode.c
@@ -55,7 +55,7 @@ static void kill_stats(void)
/* handler for requests coming via UNIX socket */
static int local_handler_stats(int fd, int type, void *data)
{
- int ret = 1;
+ int ret = LOCAL_RET_OK;
switch(type) {
case DUMP_INTERNAL:
diff --git a/src/sync-ftfw.c b/src/sync-ftfw.c
index bf9f4f7..0d31e17 100644
--- a/src/sync-ftfw.c
+++ b/src/sync-ftfw.c
@@ -215,7 +215,7 @@ static void ftfw_local_queue(int fd)
static int ftfw_local(int fd, int type, void *data)
{
- int ret = 1;
+ int ret = LOCAL_RET_OK;
switch(type) {
case REQUEST_DUMP:
@@ -229,9 +229,6 @@ static int ftfw_local(int fd, int type, void *data)
case STATS_RSQUEUE:
ftfw_local_queue(fd);
break;
- default:
- ret = 0;
- break;
}
return ret;
diff --git a/src/sync-mode.c b/src/sync-mode.c
index 4d6956e..b0e2b02 100644
--- a/src/sync-mode.c
+++ b/src/sync-mode.c
@@ -403,7 +403,7 @@ static void dump_stats_sync_extended(int fd)
/* handler for requests coming via UNIX socket */
static int local_handler_sync(int fd, int type, void *data)
{
- int ret = 1;
+ int ret = LOCAL_RET_OK;
switch(type) {
case DUMP_INTERNAL: