Merge pull request #676 from mcr/mcr_tunslip1
some additions to tunslip6 to make it a bit easier to diagnose problems with it
This commit is contained in:
commit
2398b1c287
|
@ -62,7 +62,7 @@ const char *netmask;
|
||||||
int slipfd = 0;
|
int slipfd = 0;
|
||||||
uint16_t basedelay=0,delaymsec=0;
|
uint16_t basedelay=0,delaymsec=0;
|
||||||
uint32_t startsec,startmsec,delaystartsec,delaystartmsec;
|
uint32_t startsec,startmsec,delaystartsec,delaystartmsec;
|
||||||
int timestamp = 0, flowcontrol=0;
|
int timestamp = 0, flowcontrol=0, showprogress=0;
|
||||||
|
|
||||||
int ssystem(const char *fmt, ...)
|
int ssystem(const char *fmt, ...)
|
||||||
__attribute__((__format__ (__printf__, 1, 2)));
|
__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(int fd, unsigned char c);
|
||||||
void slip_send_char(int fd, unsigned char c);
|
void slip_send_char(int fd, unsigned char c);
|
||||||
|
|
||||||
//#define PROGRESS(s) fprintf(stderr, s)
|
#define PROGRESS(s) if(showprogress) fprintf(stderr, s)
|
||||||
#define PROGRESS(s) do { } while (0)
|
|
||||||
|
|
||||||
char tundev[1024] = { "" };
|
char tundev[1024] = { "" };
|
||||||
|
|
||||||
|
@ -187,7 +186,7 @@ serial_to_tun(FILE *inslip, int outfd)
|
||||||
clearerr(inslip);
|
clearerr(inslip);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* fprintf(stderr, ".");*/
|
PROGRESS(".");
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case SLIP_END:
|
case SLIP_END:
|
||||||
if(inbufptr > 0) {
|
if(inbufptr > 0) {
|
||||||
|
@ -225,7 +224,6 @@ serial_to_tun(FILE *inslip, int outfd)
|
||||||
inet_pton(AF_INET6, ipaddr, &addr);
|
inet_pton(AF_INET6, ipaddr, &addr);
|
||||||
if(timestamp) stamptime();
|
if(timestamp) stamptime();
|
||||||
fprintf(stderr,"*** Address:%s => %02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
|
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[0], addr.s6_addr[1],
|
||||||
addr.s6_addr[2], addr.s6_addr[3],
|
addr.s6_addr[2], addr.s6_addr[3],
|
||||||
|
@ -240,12 +238,20 @@ serial_to_tun(FILE *inslip, int outfd)
|
||||||
slip_send(slipfd, SLIP_END);
|
slip_send(slipfd, SLIP_END);
|
||||||
}
|
}
|
||||||
#define DEBUG_LINE_MARKER '\r'
|
#define DEBUG_LINE_MARKER '\r'
|
||||||
} else if(uip.inbuf[0] == DEBUG_LINE_MARKER) {
|
if(uip.inbuf[0] == DEBUG_LINE_MARKER ||
|
||||||
fwrite(uip.inbuf + 1, inbufptr - 1, 1, stdout);
|
is_sensible_string(uip.inbuf, inbufptr)) {
|
||||||
} else if(is_sensible_string(uip.inbuf, inbufptr)) {
|
unsigned char *out = uip.inbuf;
|
||||||
if(verbose==1) { /* strings already echoed below for verbose>1 */
|
unsigned int len = inbufptr;
|
||||||
if (timestamp) stamptime();
|
if(uip.inbuf[0] == DEBUG_LINE_MARKER) {
|
||||||
fwrite(uip.inbuf, inbufptr, 1, stdout);
|
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 {
|
} else {
|
||||||
if(verbose>2) {
|
if(verbose>2) {
|
||||||
|
@ -514,6 +520,7 @@ tun_alloc(char *dev, int tap)
|
||||||
int fd, err;
|
int fd, err;
|
||||||
|
|
||||||
if( (fd = open("/dev/net/tun", O_RDWR)) < 0 ) {
|
if( (fd = open("/dev/net/tun", O_RDWR)) < 0 ) {
|
||||||
|
perror("can not open /dev/net/tun");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -530,8 +537,12 @@ tun_alloc(char *dev, int tap)
|
||||||
|
|
||||||
if((err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ) {
|
if((err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ) {
|
||||||
close(fd);
|
close(fd);
|
||||||
|
fprintf(stderr, "can not tunsetiff to %s (flags=%08x): %s\n", dev, ifr.ifr_flags,
|
||||||
|
strerror(errno));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* get resulting tunnel name */
|
||||||
strcpy(dev, ifr.ifr_name);
|
strcpy(dev, ifr.ifr_name);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
@ -698,13 +709,14 @@ main(int argc, char **argv)
|
||||||
const char *port = NULL;
|
const char *port = NULL;
|
||||||
const char *prog;
|
const char *prog;
|
||||||
int baudrate = -2;
|
int baudrate = -2;
|
||||||
|
int ipa_enable = 1;
|
||||||
int tap = 0;
|
int tap = 0;
|
||||||
slipfd = 0;
|
slipfd = 0;
|
||||||
|
|
||||||
prog = argv[0];
|
prog = argv[0];
|
||||||
setvbuf(stdout, NULL, _IOLBF, 0); /* Line buffered output. */
|
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:HILPhs:t:v::d::a:p:T")) != -1) {
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case 'B':
|
case 'B':
|
||||||
baudrate = atoi(optarg);
|
baudrate = atoi(optarg);
|
||||||
|
@ -718,6 +730,10 @@ main(int argc, char **argv)
|
||||||
timestamp=1;
|
timestamp=1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'P':
|
||||||
|
showprogress=1;
|
||||||
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
if(strncmp("/dev/", optarg, 5) == 0) {
|
if(strncmp("/dev/", optarg, 5) == 0) {
|
||||||
siodev = optarg + 5;
|
siodev = optarg + 5;
|
||||||
|
@ -726,6 +742,11 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'I':
|
||||||
|
ipa_enable = 0;
|
||||||
|
fprintf(stderr, "Will not inquire about IP address using IPA=\n");
|
||||||
|
break;
|
||||||
|
|
||||||
case 't':
|
case 't':
|
||||||
if(strncmp("/dev/", optarg, 5) == 0) {
|
if(strncmp("/dev/", optarg, 5) == 0) {
|
||||||
strncpy(tundev, optarg + 5, sizeof(tundev));
|
strncpy(tundev, optarg + 5, sizeof(tundev));
|
||||||
|
@ -916,7 +937,7 @@ exit(1);
|
||||||
if(inslip == NULL) err(1, "main: fdopen");
|
if(inslip == NULL) err(1, "main: fdopen");
|
||||||
|
|
||||||
tunfd = tun_alloc(tundev, tap);
|
tunfd = tun_alloc(tundev, tap);
|
||||||
if(tunfd == -1) err(1, "main: open");
|
if(tunfd == -1) err(1, "main: open /dev/tun");
|
||||||
if (timestamp) stamptime();
|
if (timestamp) stamptime();
|
||||||
fprintf(stderr, "opened %s device ``/dev/%s''\n",
|
fprintf(stderr, "opened %s device ``/dev/%s''\n",
|
||||||
tap ? "tap" : "tun", tundev);
|
tap ? "tap" : "tun", tundev);
|
||||||
|
@ -933,16 +954,15 @@ exit(1);
|
||||||
FD_ZERO(&rset);
|
FD_ZERO(&rset);
|
||||||
FD_ZERO(&wset);
|
FD_ZERO(&wset);
|
||||||
|
|
||||||
/* do not send IPA all the time... - add get MAC later... */
|
if(got_sigalarm && ipa_enable) {
|
||||||
/* if(got_sigalarm) { */
|
/* Send "?IPA". */
|
||||||
/* /\* Send "?IPA". *\/ */
|
slip_send(slipfd, '?');
|
||||||
/* slip_send(slipfd, '?'); */
|
slip_send(slipfd, 'I');
|
||||||
/* slip_send(slipfd, 'I'); */
|
slip_send(slipfd, 'P');
|
||||||
/* slip_send(slipfd, 'P'); */
|
slip_send(slipfd, 'A');
|
||||||
/* slip_send(slipfd, 'A'); */
|
slip_send(slipfd, SLIP_END);
|
||||||
/* slip_send(slipfd, SLIP_END); */
|
got_sigalarm = 0;
|
||||||
/* got_sigalarm = 0; */
|
}
|
||||||
/* } */
|
|
||||||
|
|
||||||
if(!slip_empty()) { /* Anything to flush? */
|
if(!slip_empty()) { /* Anything to flush? */
|
||||||
FD_SET(slipfd, &wset);
|
FD_SET(slipfd, &wset);
|
||||||
|
@ -967,7 +987,7 @@ exit(1);
|
||||||
|
|
||||||
if(FD_ISSET(slipfd, &wset)) {
|
if(FD_ISSET(slipfd, &wset)) {
|
||||||
slip_flushbuf(slipfd);
|
slip_flushbuf(slipfd);
|
||||||
sigalarm_reset();
|
if(ipa_enable) sigalarm_reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Optional delay between outgoing packets */
|
/* Optional delay between outgoing packets */
|
||||||
|
@ -985,7 +1005,7 @@ exit(1);
|
||||||
if(slip_empty() && FD_ISSET(tunfd, &rset)) {
|
if(slip_empty() && FD_ISSET(tunfd, &rset)) {
|
||||||
size=tun_to_serial(tunfd, slipfd);
|
size=tun_to_serial(tunfd, slipfd);
|
||||||
slip_flushbuf(slipfd);
|
slip_flushbuf(slipfd);
|
||||||
sigalarm_reset();
|
if(ipa_enable) sigalarm_reset();
|
||||||
if(basedelay) {
|
if(basedelay) {
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gettimeofday(&tv, NULL) ;
|
gettimeofday(&tv, NULL) ;
|
||||||
|
|
Loading…
Reference in a new issue