summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2008-10-26 20:48:55 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2008-10-26 20:48:55 +0100
commitc9fc2e7843e56eec84d92b5baa208afdb5b81d3c (patch)
treecbb815e7d2d3a715eaeb81d10866c5049df757f7
parent367bd830bb88393a639f6f41c3f390f6dd3e120f (diff)
ftfw: add option `-v' to output debugging information (if any)
This patch introduces the option `-v' to show useful debugging information, if any. As for now, only sync-ftfw.c make use of it to display the content and the length of the resent list/queue. This is useful to check for message leaks. Other working modes or synchronization approaches may use it to display debugging information in the future. This patch removes _SIGNAL_DEBUG in sync-ftfw.c that was used for for the same purpose. However, it could only be enabled at compilation time and it uses signalling instead of the standard UNIX socket interface that conntrackd provides. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--include/conntrackd.h1
-rw-r--r--src/main.c7
-rw-r--r--src/sync-ftfw.c69
3 files changed, 42 insertions, 35 deletions
diff --git a/include/conntrackd.h b/include/conntrackd.h
index c0bb4bb..448d594 100644
--- a/include/conntrackd.h
+++ b/include/conntrackd.h
@@ -25,6 +25,7 @@
#define DUMP_INT_XML 24 /* dump internal cache in XML */
#define DUMP_EXT_XML 25 /* dump external cache in XML */
#define RESET_TIMERS 26 /* reset kernel timers */
+#define DEBUG_INFO 27 /* show debug info (if any) */
#define DEFAULT_CONFIGFILE "/etc/conntrackd/conntrackd.conf"
#define DEFAULT_LOCKFILE "/var/lock/conntrackd.lock"
diff --git a/src/main.c b/src/main.c
index b535c40..d6aa938 100644
--- a/src/main.c
+++ b/src/main.c
@@ -47,7 +47,8 @@ static const char usage_client_commands[] =
" -R, resync with kernel conntrack table\n"
" -n, request resync with other node (only FT-FW and NOTRACK modes)\n"
" -x, dump cache in XML format (requires -i or -e)"
- " -t, reset the kernel timeout (see PurgeTimeout clause)";
+ " -t, reset the kernel timeout (see PurgeTimeout clause)"
+ " -v, show internal debugging information (if any)";
static const char usage_options[] =
"Options:\n"
@@ -180,6 +181,10 @@ int main(int argc, char *argv[])
}
break;
+ case 'v':
+ set_operation_mode(&type, REQUEST, argv);
+ action = DEBUG_INFO;
+ break;
default:
show_usage(argv[0]);
fprintf(stderr, "Unknown option: %s\n", argv[i]);
diff --git a/src/sync-ftfw.c b/src/sync-ftfw.c
index b7eabdf..f900919 100644
--- a/src/sync-ftfw.c
+++ b/src/sync-ftfw.c
@@ -139,36 +139,6 @@ static void do_alive_alarm(struct alarm_block *a, void *data)
mcast_buffered_pending_netmsg(STATE_SYNC(mcast_client));
}
-#undef _SIGNAL_DEBUG
-#ifdef _SIGNAL_DEBUG
-
-static int rs_dump(void *data1, const void *data2)
-{
- struct nethdr_ack *net = data1;
-
- printf("in RS queue -> seq:%u flags:%u\n", net->seq, net->flags);
-
- return 0;
-}
-
-#include <signal.h>
-
-static void my_dump(int foo)
-{
- struct cache_ftfw *cn, *tmp;
-
- list_for_each_entry_safe(cn, tmp, &rs_list, rs_list) {
- struct us_conntrack *u;
-
- u = cache_get_conntrack(STATE_SYNC(internal), cn);
- printf("in RS list -> seq:%u\n", cn->seq);
- }
-
- queue_iterate(rs_queue, NULL, rs_dump);
-}
-
-#endif
-
static int ftfw_init(void)
{
tx_queue = queue_create(CONFIG(resend_queue_size));
@@ -189,10 +159,6 @@ static int ftfw_init(void)
/* set ack window size */
window = CONFIG(window_size);
-#ifdef _SIGNAL_DEBUG
- signal(SIGUSR1, my_dump);
-#endif
-
return 0;
}
@@ -219,6 +185,38 @@ static int do_cache_to_tx(void *data1, void *data2)
return 0;
}
+static int debug_rs_queue_dump_step(void *data1, const void *data2)
+{
+ struct nethdr_ack *net = data1;
+ const int *fd = data2;
+ char buf[512];
+ int size;
+
+ size = sprintf(buf, "seq:%u flags:%u\n", net->seq, net->flags);
+ send(*fd, buf, size, 0);
+ return 0;
+}
+
+static void debug_rs_dump(int fd)
+{
+ struct cache_ftfw *cn, *tmp;
+ char buf[512];
+ int size;
+
+ size = sprintf(buf, "resent list (len=%u):\n", rs_list_len);
+ send(fd, buf, size, 0);
+ list_for_each_entry_safe(cn, tmp, &rs_list, rs_list) {
+ struct us_conntrack *u;
+
+ u = cache_get_conntrack(STATE_SYNC(internal), cn);
+ size = sprintf(buf, "seq:%u\n", cn->seq);
+ send(fd, buf, size, 0);
+ }
+ size = sprintf(buf, "\nresent queue (len=%u):\n", queue_len(rs_queue));
+ send(fd, buf, size, 0);
+ queue_iterate(rs_queue, &fd, debug_rs_queue_dump_step);
+}
+
static int ftfw_local(int fd, int type, void *data)
{
int ret = 1;
@@ -232,6 +230,9 @@ static int ftfw_local(int fd, int type, void *data)
dlog(LOG_NOTICE, "sending bulk update");
cache_iterate(STATE_SYNC(internal), NULL, do_cache_to_tx);
break;
+ case DEBUG_INFO:
+ debug_rs_dump(fd);
+ break;
default:
ret = 0;
break;