From 9fa70acc69504e1cebcd0b0feac27dc597eba6a0 Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Tue, 5 Aug 2008 22:37:40 +0000 Subject: [PATCH] Added debug capability on server --- CHANGELOG | 2 ++ man/iodine.8 | 8 +++++--- src/iodined.c | 27 ++++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index ea88adf..a5f5ec7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -17,6 +17,8 @@ CHANGES: - Fixed bug #21, now only IP address part of each packet is checked. Should remove the need for the -c option and also work with bugfixed DNS servers worldwide. + - Added -D option on server to enable debugging. Debug level 1 now prints + info about each RX/TX datagram. 2007-11-30: 0.4.1 "Tea Online" - Introduced encoding API diff --git a/man/iodine.8 b/man/iodine.8 index 2559b35..fdb28fe 100644 --- a/man/iodine.8 +++ b/man/iodine.8 @@ -25,7 +25,7 @@ iodine, iodined \- tunnel IPv4 over DNS .B iodined [-h] -.B iodined [-c] [-s] [-f] [-u +.B iodined [-c] [-s] [-f] [-D] [-u .I user .B ] [-P .I password @@ -79,13 +79,15 @@ and otherwise tunX. .SS Server Options: .TP .B -c -Disable checks on client IP and port on all incoming requests. -This might help if server is behind a NAT firewall. +Disable checks on client IP on all incoming requests. .TP .B -s Don't try to configure IP address or MTU. This should only be used if you have already configured the device that will be used. .TP +.B -D +Increase debug level. Level 1 prints info about each RX/TX packet. +.TP .B -m mtu Set 'mtu' as mtu size for the tunnel device. This will be sent to the client on connect, and the client will use the same mtu. diff --git a/src/iodined.c b/src/iodined.c index 70e9c99..4347e45 100644 --- a/src/iodined.c +++ b/src/iodined.c @@ -57,6 +57,8 @@ static int check_ip; static int my_mtu; static in_addr_t my_ip; +static int debug; + #if !defined(BSD) && !defined(__GLIBC__) static char *__progname; #endif @@ -327,6 +329,12 @@ tunnel_dns(int tun_fd, int dns_fd) if ((read = read_dns(dns_fd, &q)) <= 0) return 0; + + if (debug >= 1) { + struct sockaddr_in *tempin; + tempin = (struct sockaddr_in *) &(q.from); + printf("RX: client %s, type %d, name %s\n", inet_ntoa(tempin->sin_addr), q.type, q.name); + } switch (q.type) { case T_NULL: @@ -427,6 +435,13 @@ write_dns(int fd, struct query *q, char *data, int datalen) len = dns_encode(buf, sizeof(buf), q, QR_ANSWER, data, datalen); + if (debug >= 1) { + struct sockaddr_in *tempin; + tempin = (struct sockaddr_in *) &(q->from); + printf("TX: client %s, type %d, name %s, %d bytes data\n", + inet_ntoa(tempin->sin_addr), q->type, q->name, datalen); + } + sendto(fd, buf, len, 0, (struct sockaddr*)&q->from, q->fromlen); } @@ -499,6 +514,7 @@ main(int argc, char **argv) port = 53; check_ip = 1; skipipconfig = 0; + debug = 0; b32 = get_base32_encoder(); @@ -513,7 +529,7 @@ main(int argc, char **argv) memset(password, 0, sizeof(password)); srand(time(NULL)); - while ((choice = getopt(argc, argv, "vcsfhu:t:d:m:l:p:P:")) != -1) { + while ((choice = getopt(argc, argv, "vcsfhDu:t:d:m:l:p:P:")) != -1) { switch(choice) { case 'v': version(); @@ -530,6 +546,9 @@ main(int argc, char **argv) case 'h': help(); break; + case 'D': + debug++; + break; case 'u': username = optarg; break; @@ -605,6 +624,12 @@ main(int argc, char **argv) printf("You must manually forward port 53 to port %d for things to work.\n", port); } + if (debug) { + printf("Debug level %d enabled, will stay in foreground.\n", debug); + printf("Add more -D switches to set higher debug level.\n"); + foreground = 1; + } + if (listen_ip == INADDR_NONE) { warnx("Bad IP address to listen on.\n"); usage();