From c9fc2e7843e56eec84d92b5baa208afdb5b81d3c Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Sun, 26 Oct 2008 20:48:55 +0100 Subject: 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 --- src/sync-ftfw.c | 69 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 34 deletions(-) (limited to 'src/sync-ftfw.c') 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 - -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; -- cgit v1.2.3