From 6232cc488cb3ce70fdf1ac7fd3ca3c72c9ffa49e Mon Sep 17 00:00:00 2001 From: Michael Richardson Date: Sat, 10 May 2014 17:03:11 -0400 Subject: [PATCH 1/6] tunslip6: remove trailing whitespace --- tools/tunslip6.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/tunslip6.c b/tools/tunslip6.c index 65e440800..71b05742c 100644 --- a/tools/tunslip6.c +++ b/tools/tunslip6.c @@ -34,7 +34,7 @@ /* Below define allows importing saved output into Wireshark as "Raw IP" packet type */ #define WIRESHARK_IMPORT_FORMAT 1 - + #include #include #include @@ -116,7 +116,7 @@ stamptime(void) time_t t; struct tm *tmp; char timec[20]; - + gettimeofday(&tv, NULL) ; msecs=tv.tv_usec/1000; secs=tv.tv_sec; @@ -226,7 +226,7 @@ serial_to_tun(FILE *inslip, int outfd) if(timestamp) stamptime(); fprintf(stderr,"*** Address:%s => %02x%02x:%02x%02x:%02x%02x:%02x%02x\n", // printf("*** Address:%s => %02x%02x:%02x%02x:%02x%02x:%02x%02x\n", - ipaddr, + ipaddr, addr.s6_addr[0], addr.s6_addr[1], addr.s6_addr[2], addr.s6_addr[3], addr.s6_addr[4], addr.s6_addr[5], @@ -240,7 +240,7 @@ serial_to_tun(FILE *inslip, int outfd) slip_send(slipfd, SLIP_END); } #define DEBUG_LINE_MARKER '\r' - } else if(uip.inbuf[0] == DEBUG_LINE_MARKER) { + } else if(uip.inbuf[0] == DEBUG_LINE_MARKER) { fwrite(uip.inbuf + 1, inbufptr - 1, 1, stdout); } else if(is_sensible_string(uip.inbuf, inbufptr)) { if(verbose==1) { /* strings already echoed below for verbose>1 */ @@ -310,7 +310,7 @@ serial_to_tun(FILE *inslip, int outfd) if(c=='\n') if(timestamp) stamptime(); } } - + break; } @@ -358,7 +358,7 @@ void slip_flushbuf(int fd) { int n; - + if(slip_empty()) { return; } @@ -636,7 +636,7 @@ ifconf(const char *tundev, const char *ipaddr) } else { cc=0; digit = c-'0'; - if (digit > 9) + if (digit > 9) digit = 10 + (c & 0xdf) - 'A'; a[ai] = (a[ai] << 4) + digit; } @@ -713,7 +713,7 @@ main(int argc, char **argv) case 'H': flowcontrol=1; break; - + case 'L': timestamp=1; break; @@ -755,7 +755,7 @@ main(int argc, char **argv) case 'T': tap = 1; break; - + case '?': case 'h': default: @@ -950,7 +950,7 @@ exit(1); FD_SET(slipfd, &rset); /* Read from slip ASAP! */ if(slipfd > maxfd) maxfd = slipfd; - + /* We only have one packet at a time queued for slip output. */ if(slip_empty()) { FD_SET(tunfd, &rset); @@ -964,12 +964,12 @@ exit(1); if(FD_ISSET(slipfd, &rset)) { serial_to_tun(inslip, tunfd); } - + if(FD_ISSET(slipfd, &wset)) { slip_flushbuf(slipfd); sigalarm_reset(); } - + /* Optional delay between outgoing packets */ /* Base delay times number of 6lowpan fragments to be sent */ if(delaymsec) { From ab2c110c708526729be4451180c5a2740f241eff Mon Sep 17 00:00:00 2001 From: Michael Richardson Date: Sat, 10 May 2014 17:15:23 -0400 Subject: [PATCH 2/6] tunslip6: show progres with -P argument --- tools/tunslip6.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/tunslip6.c b/tools/tunslip6.c index 71b05742c..9593792cd 100644 --- a/tools/tunslip6.c +++ b/tools/tunslip6.c @@ -62,7 +62,7 @@ const char *netmask; int slipfd = 0; uint16_t basedelay=0,delaymsec=0; uint32_t startsec,startmsec,delaystartsec,delaystartmsec; -int timestamp = 0, flowcontrol=0; +int timestamp = 0, flowcontrol=0, showprogress=0; int ssystem(const char *fmt, ...) __attribute__((__format__ (__printf__, 1, 2))); @@ -71,8 +71,7 @@ void write_to_serial(int outfd, void *inbuf, int len); void slip_send(int fd, unsigned char c); void slip_send_char(int fd, unsigned char c); -//#define PROGRESS(s) fprintf(stderr, s) -#define PROGRESS(s) do { } while (0) +#define PROGRESS(s) if(showprogress) fprintf(stderr, s) char tundev[1024] = { "" }; @@ -187,7 +186,7 @@ serial_to_tun(FILE *inslip, int outfd) clearerr(inslip); return; } - /* fprintf(stderr, ".");*/ + PROGRESS("."); switch(c) { case SLIP_END: if(inbufptr > 0) { @@ -704,7 +703,7 @@ main(int argc, char **argv) prog = argv[0]; setvbuf(stdout, NULL, _IOLBF, 0); /* Line buffered output. */ - while((c = getopt(argc, argv, "B:HLhs:t:v::d::a:p:T")) != -1) { + while((c = getopt(argc, argv, "B:HLPhs:t:v::d::a:p:T")) != -1) { switch(c) { case 'B': baudrate = atoi(optarg); @@ -718,6 +717,10 @@ main(int argc, char **argv) timestamp=1; break; + case 'P': + showprogress=1; + break; + case 's': if(strncmp("/dev/", optarg, 5) == 0) { siodev = optarg + 5; From 6b473301c5dfc1bf549d2b473bcef38352d7c556 Mon Sep 17 00:00:00 2001 From: Michael Richardson Date: Sat, 10 May 2014 17:16:35 -0400 Subject: [PATCH 3/6] tunslip6: removed commented out line printing IP address --- tools/tunslip6.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/tunslip6.c b/tools/tunslip6.c index 9593792cd..861868c84 100644 --- a/tools/tunslip6.c +++ b/tools/tunslip6.c @@ -224,7 +224,6 @@ serial_to_tun(FILE *inslip, int outfd) inet_pton(AF_INET6, ipaddr, &addr); if(timestamp) stamptime(); fprintf(stderr,"*** Address:%s => %02x%02x:%02x%02x:%02x%02x:%02x%02x\n", - // printf("*** Address:%s => %02x%02x:%02x%02x:%02x%02x:%02x%02x\n", ipaddr, addr.s6_addr[0], addr.s6_addr[1], addr.s6_addr[2], addr.s6_addr[3], From 6608b62b01953b8a263ffda65802c1bc9052c06c Mon Sep 17 00:00:00 2001 From: Michael Richardson Date: Sat, 10 May 2014 17:16:07 -0400 Subject: [PATCH 4/6] tunslip6: make printing of sensible strings from mote more reliable --- tools/tunslip6.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tools/tunslip6.c b/tools/tunslip6.c index 861868c84..b4390eacf 100644 --- a/tools/tunslip6.c +++ b/tools/tunslip6.c @@ -238,13 +238,21 @@ serial_to_tun(FILE *inslip, int outfd) slip_send(slipfd, SLIP_END); } #define DEBUG_LINE_MARKER '\r' - } else if(uip.inbuf[0] == DEBUG_LINE_MARKER) { - fwrite(uip.inbuf + 1, inbufptr - 1, 1, stdout); - } else if(is_sensible_string(uip.inbuf, inbufptr)) { - if(verbose==1) { /* strings already echoed below for verbose>1 */ - if (timestamp) stamptime(); - fwrite(uip.inbuf, inbufptr, 1, stdout); - } + if(uip.inbuf[0] == DEBUG_LINE_MARKER || + is_sensible_string(uip.inbuf, inbufptr)) { + unsigned char *out = uip.inbuf; + unsigned int len = inbufptr; + if(uip.inbuf[0] == DEBUG_LINE_MARKER) { + out++; + len--; + } + fprintf(stderr, "\n***"); + fwrite(out, len, 1, stderr); + fprintf(stderr, "***\n"); + } else { + fprintf(stderr, + "serial_to_tun: drop packet len=%d\n", inbufptr); + } } else { if(verbose>2) { if (timestamp) stamptime(); From f1433f7d5fc389749ceb769dd8ce413ab6e82ee8 Mon Sep 17 00:00:00 2001 From: Michael Richardson Date: Sat, 10 May 2014 17:19:51 -0400 Subject: [PATCH 5/6] tunslip6: option to turn off processing of IPA= address allocation --- tools/tunslip6.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/tools/tunslip6.c b/tools/tunslip6.c index b4390eacf..e2413cb88 100644 --- a/tools/tunslip6.c +++ b/tools/tunslip6.c @@ -704,13 +704,14 @@ main(int argc, char **argv) const char *port = NULL; const char *prog; int baudrate = -2; + int ipa_enable = 1; int tap = 0; slipfd = 0; prog = argv[0]; setvbuf(stdout, NULL, _IOLBF, 0); /* Line buffered output. */ - while((c = getopt(argc, argv, "B:HLPhs:t:v::d::a:p:T")) != -1) { + while((c = getopt(argc, argv, "B:HILPhs:t:v::d::a:p:T")) != -1) { switch(c) { case 'B': baudrate = atoi(optarg); @@ -736,6 +737,11 @@ main(int argc, char **argv) } break; + case 'I': + ipa_enable = 0; + fprintf(stderr, "Will not inquire about IP address using IPA=\n"); + break; + case 't': if(strncmp("/dev/", optarg, 5) == 0) { strncpy(tundev, optarg + 5, sizeof(tundev)); @@ -943,16 +949,15 @@ exit(1); FD_ZERO(&rset); FD_ZERO(&wset); -/* do not send IPA all the time... - add get MAC later... */ -/* if(got_sigalarm) { */ -/* /\* Send "?IPA". *\/ */ -/* slip_send(slipfd, '?'); */ -/* slip_send(slipfd, 'I'); */ -/* slip_send(slipfd, 'P'); */ -/* slip_send(slipfd, 'A'); */ -/* slip_send(slipfd, SLIP_END); */ -/* got_sigalarm = 0; */ -/* } */ + if(got_sigalarm && ipa_enable) { + /* Send "?IPA". */ + slip_send(slipfd, '?'); + slip_send(slipfd, 'I'); + slip_send(slipfd, 'P'); + slip_send(slipfd, 'A'); + slip_send(slipfd, SLIP_END); + got_sigalarm = 0; + } if(!slip_empty()) { /* Anything to flush? */ FD_SET(slipfd, &wset); @@ -977,7 +982,7 @@ exit(1); if(FD_ISSET(slipfd, &wset)) { slip_flushbuf(slipfd); - sigalarm_reset(); + if(ipa_enable) sigalarm_reset(); } /* Optional delay between outgoing packets */ @@ -995,7 +1000,7 @@ exit(1); if(slip_empty() && FD_ISSET(tunfd, &rset)) { size=tun_to_serial(tunfd, slipfd); slip_flushbuf(slipfd); - sigalarm_reset(); + if(ipa_enable) sigalarm_reset(); if(basedelay) { struct timeval tv; gettimeofday(&tv, NULL) ; From 11c3dcc622990b3b9b8e4d1e04c3a50c78411cdc Mon Sep 17 00:00:00 2001 From: Michael Richardson Date: Fri, 9 May 2014 14:25:59 -0400 Subject: [PATCH 6/6] tunslip6: added some better clarification of errors when TUNSETIFF fails --- tools/tunslip6.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/tunslip6.c b/tools/tunslip6.c index e2413cb88..4f3ff7e3e 100644 --- a/tools/tunslip6.c +++ b/tools/tunslip6.c @@ -520,6 +520,7 @@ tun_alloc(char *dev, int tap) int fd, err; if( (fd = open("/dev/net/tun", O_RDWR)) < 0 ) { + perror("can not open /dev/net/tun"); return -1; } @@ -536,8 +537,12 @@ tun_alloc(char *dev, int tap) if((err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ) { close(fd); + fprintf(stderr, "can not tunsetiff to %s (flags=%08x): %s\n", dev, ifr.ifr_flags, + strerror(errno)); return err; } + + /* get resulting tunnel name */ strcpy(dev, ifr.ifr_name); return fd; } @@ -932,7 +937,7 @@ exit(1); if(inslip == NULL) err(1, "main: fdopen"); tunfd = tun_alloc(tundev, tap); - if(tunfd == -1) err(1, "main: open"); + if(tunfd == -1) err(1, "main: open /dev/tun"); if (timestamp) stamptime(); fprintf(stderr, "opened %s device ``/dev/%s''\n", tap ? "tap" : "tun", tundev);