]> git.ozlabs.org Git - ppp.git/commitdiff
Allow *-max-terminate to be set to zero -- meaning that one Terminate-
authorJames Carlson <carlsonj@workingcode.com>
Mon, 2 Feb 2004 02:52:51 +0000 (02:52 +0000)
committerJames Carlson <carlsonj@workingcode.com>
Mon, 2 Feb 2004 02:52:51 +0000 (02:52 +0000)
Request will be sent, but no waiting will be done.  Fixed termination
code so that link statistics are printed only once.

pppd/fsm.c
pppd/main.c

index 4a5c2a80c31166f8dc3fb84d3743083186bfebc4..387f7012928f0d2d7d9bab6a0c1ab3fccb34d143 100644 (file)
@@ -40,7 +40,7 @@
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
  * 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:
 
 /*
  * 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.
 
 /*
  * fsm_close - Start closing connection.
@@ -230,19 +267,7 @@ fsm_close(f, reason)
     case ACKRCVD:
     case ACKSENT:
     case OPENED:
     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;
     }
 }
        break;
     }
 }
@@ -689,17 +714,7 @@ fsm_protreject(f)
        break;
 
     case OPENED:
        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:
        break;
 
     default:
index 1c570eee7860338ae31139ef7f4ed6e06d46a4e2..6e50947000ed65e620bb12089582ef306bf54fc0 100644 (file)
@@ -40,7 +40,7 @@
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
  * 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 <stdio.h>
 #include <ctype.h>
 
 #include <stdio.h>
 #include <ctype.h>
@@ -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);
        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;
     }
 }
 
     }
 }