Description: fix IDLE_WAIT implementation Author: Michael Douglass Origin: http://poptop.cvs.sourceforge.net/viewvc/poptop/poptop/pptpctrl.c?r1=1.21&r2=1.22 Forwarded: not-needed Bug-Debian: http://bugs.debian.org/692654 --- a/AUTHORS +++ b/AUTHORS @@ -28,6 +28,7 @@ Chris Wilson Anton Gorlov Charlie Brady +Michael Douglass The Linux PPTP Server takes advantage of some Linux PPTP client code written by C. Scott Ananian --- a/pptpctrl.c +++ b/pptpctrl.c @@ -226,6 +226,7 @@ int echo_wait = FALSE; /* Waiting for echo? */ u_int32_t echo_count = 0; /* Sequence # of echo */ time_t echo_time = 0; /* Time last echo req sent */ + time_t last_time = time(NULL); /* Time last received data */ struct timeval idleTime; /* How long to select() */ /* General local variables */ @@ -281,16 +282,6 @@ } else if (encaps_gre(-1, NULL, 0)) /* Pending ack and nothing else to do */ encaps_gre(gre_fd, NULL, 0); /* send ack with no payload */ - else if (echo_wait != TRUE) { - /* Timeout. Start idle link detection. */ - echo_count++; - if (pptpctrl_debug) - syslog(LOG_DEBUG, "CTRL: Sending ECHO REQ id %d", echo_count); - time(&echo_time); - make_echo_req_packet(rply_packet, &rply_size, echo_count); - echo_wait = TRUE; - send_packet = TRUE; - } break; default: @@ -328,6 +319,7 @@ /* handle control messages */ if (FD_ISSET(clientSocket, &fds)) { + time(&last_time); send_packet = TRUE; switch (read_pptp_packet(clientSocket, packet, rply_packet, &rply_size)) { case 0: @@ -420,6 +412,15 @@ /* Otherwise, the already-formed reply will do fine, so send it */ } + /* send echo request packet if we have not heard from the TCP socket in IDLE_TIME */ + } else if (echo_wait != TRUE && (time(NULL) - last_time) > IDLE_WAIT) { + echo_count++; + if (pptpctrl_debug) + syslog(LOG_DEBUG, "CTRL: Sending ECHO REQ id %d", echo_count); + time(&echo_time); + make_echo_req_packet(rply_packet, &rply_size, echo_count); + echo_wait = TRUE; + send_packet = TRUE; } /* send reply packet - this may block, but it should be very rare */