]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/ccp.c
Set current_option for error reporting. Bug and fix by Clive Nicolson.
[ppp.git] / pppd / ccp.c
index 3e408ba27f6e4339174dccad4e2f23f012eca99a..378749e1a6463c43ea01592fbaaa3cb2f56c32f6 100644 (file)
@@ -25,7 +25,7 @@
  * OR MODIFICATIONS.
  */
 
-#define RCSID  "$Id: ccp.c,v 1.36 2002/05/28 17:00:57 dfs Exp $"
+#define RCSID  "$Id: ccp.c,v 1.40 2002/10/27 11:46:24 fcusack Exp $"
 
 #include <stdlib.h>
 #include <string.h>
@@ -37,7 +37,7 @@
 
 #ifdef MPPE
 #include "chap_ms.h"   /* mppe_xxxx_key */
-#include "lcp.h"       /* lcp_close() */
+#include "lcp.h"       /* lcp_close(), lcp_fsm */
 #endif
 
 static const char rcsid[] = RCSID;
@@ -512,9 +512,10 @@ ccp_protrej(unit)
     fsm_lowerdown(&ccp_fsm[unit]);
 
 #ifdef MPPE
-    if (ccp_gotoptions[unit].mppe)
+    if (ccp_gotoptions[unit].mppe) {
        error("MPPE required but peer negotiation failed");
        lcp_close(unit, "MPPE required but peer negotiation failed");
+    }
 #endif
 
 }
@@ -685,7 +686,8 @@ ccp_addci(f, p, lenp)
 
     /*
      * Add the compression types that we can receive, in decreasing
-     * preference order.
+     * preference order.  Get the kernel to allocate the first one
+     * in case it gets Acked.
      */
 #ifdef MPPE
     if (go->mppe) {
@@ -737,21 +739,25 @@ ccp_addci(f, p, lenp)
        p[0] = CI_BSD_COMPRESS;
        p[1] = CILEN_BSD_COMPRESS;
        p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits);
-       for (;;) {
-           if (go->bsd_bits < BSD_MIN_BITS) {
-               go->bsd_compress = 0;
-               break;
-           }
-           res = ccp_test(f->unit, p, CILEN_BSD_COMPRESS, 0);
-           if (res > 0) {
-               p += CILEN_BSD_COMPRESS;
-               break;
-           } else if (res < 0) {
-               go->bsd_compress = 0;
-               break;
+       if (p != p0) {
+           p += CILEN_BSD_COMPRESS;    /* not the first option */
+       } else {
+           for (;;) {
+               if (go->bsd_bits < BSD_MIN_BITS) {
+                   go->bsd_compress = 0;
+                   break;
+               }
+               res = ccp_test(f->unit, p, CILEN_BSD_COMPRESS, 0);
+               if (res > 0) {
+                   p += CILEN_BSD_COMPRESS;
+                   break;
+               } else if (res < 0) {
+                   go->bsd_compress = 0;
+                   break;
+               }
+               --go->bsd_bits;
+               p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits);
            }
-           --go->bsd_bits;
-           p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits);
        }
     }
     /* XXX Should Predictor 2 be preferable to Predictor 1? */
@@ -1420,7 +1426,7 @@ ccp_up(f)
     if (go->mppe) {
        BZERO(mppe_recv_key, MPPE_MAX_KEY_LEN);
        BZERO(mppe_send_key, MPPE_MAX_KEY_LEN);
-       start_networks(f->unit);                /* Bring up IP et al */
+       continue_networks(f->unit);             /* Bring up IP et al */
     }
 #endif
 }
@@ -1438,8 +1444,12 @@ ccp_down(f)
     ccp_flags_set(f->unit, 1, 0);
 #ifdef MPPE
     if (ccp_gotoptions[f->unit].mppe) {
-       error("MPPE disabled");
-       lcp_close(f->unit, "MPPE disabled");
+       ccp_gotoptions[f->unit].mppe = 0;
+       if (lcp_fsm[f->unit].state == OPENED) {
+           /* If LCP is not already going down, make sure it does. */
+           error("MPPE disabled");
+           lcp_close(f->unit, "MPPE disabled");
+       }
     }
 #endif
 }