From: James Carlson Date: Mon, 2 Feb 2004 02:52:51 +0000 (+0000) Subject: Allow *-max-terminate to be set to zero -- meaning that one Terminate- X-Git-Tag: ppp-2.4.7~251 X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=commitdiff_plain;h=428d4139c39999841f8ecc76a8b3414fd93edd3f Allow *-max-terminate to be set to zero -- meaning that one Terminate- Request will be sent, but no waiting will be done. Fixed termination code so that link statistics are printed only once. --- diff --git a/pppd/fsm.c b/pppd/fsm.c index 4a5c2a8..387f701 100644 --- a/pppd/fsm.c +++ b/pppd/fsm.c @@ -40,7 +40,7 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define RCSID "$Id: fsm.c,v 1.20 2003/06/29 10:06:14 paulus Exp $" +#define RCSID "$Id: fsm.c,v 1.21 2004/02/02 02:52:51 carlsonj Exp $" /* * TODO: @@ -201,6 +201,43 @@ fsm_open(f) } } +/* + * terminate_layer - Start process of shutting down the FSM + * + * Cancel any timeout running, notify upper layers we're done, and + * send a terminate-request message as configured. + */ +static void +terminate_layer(f) + fsm *f; +{ + if( f->state != OPENED ) + UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ + else if( f->callbacks->down ) + (*f->callbacks->down)(f); /* Inform upper layers we're down */ + + /* Init restart counter and send Terminate-Request */ + f->retransmits = f->maxtermtransmits; + fsm_sdata(f, TERMREQ, f->reqid = ++f->id, + (u_char *) f->term_reason, f->term_reason_len); + + if (f->retransmits == 0) { + /* + * User asked for no terminate requests at all; just close it. + * We've already fired off one Terminate-Request just to be nice + * to the peer, but we're not going to wait for a reply. + */ + f->state = CLOSED; + if( f->callbacks->finished ) + (*f->callbacks->finished)(f); + return; + } + + TIMEOUT(fsm_timeout, f, f->timeouttime); + --f->retransmits; + + f->state = CLOSING; +} /* * fsm_close - Start closing connection. @@ -230,19 +267,7 @@ fsm_close(f, reason) case ACKRCVD: case ACKSENT: case OPENED: - if( f->state != OPENED ) - UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */ - else if( f->callbacks->down ) - (*f->callbacks->down)(f); /* Inform upper layers we're down */ - - /* Init restart counter, send Terminate-Request */ - f->retransmits = f->maxtermtransmits; - fsm_sdata(f, TERMREQ, f->reqid = ++f->id, - (u_char *) f->term_reason, f->term_reason_len); - TIMEOUT(fsm_timeout, f, f->timeouttime); - --f->retransmits; - - f->state = CLOSING; + terminate_layer(f); break; } } @@ -689,17 +714,7 @@ fsm_protreject(f) break; case OPENED: - if( f->callbacks->down ) - (*f->callbacks->down)(f); - - /* Init restart counter, send Terminate-Request */ - f->retransmits = f->maxtermtransmits; - fsm_sdata(f, TERMREQ, f->reqid = ++f->id, - (u_char *) f->term_reason, f->term_reason_len); - TIMEOUT(fsm_timeout, f, f->timeouttime); - --f->retransmits; - - f->state = STOPPING; + terminate_layer(f); break; default: diff --git a/pppd/main.c b/pppd/main.c index 1c570ee..6e50947 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -40,7 +40,7 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define RCSID "$Id: main.c,v 1.131 2004/01/13 04:00:34 paulus Exp $" +#define RCSID "$Id: main.c,v 1.132 2004/02/02 02:52:51 carlsonj Exp $" #include #include @@ -1173,6 +1173,7 @@ print_link_stats() info("Connect time %d.%d minutes.", t/10, t%10); info("Sent %u bytes, received %u bytes.", link_stats.bytes_out, link_stats.bytes_in); + link_stats_valid = 0; } }