]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/lcp.c
When 'sync' option is present, the ppp_ahdl module isn't plumbed, so
[ppp.git] / pppd / lcp.c
index 1e01de11dfccb1fda3e8ffd1f1741f6ad915851a..2d90432f337ab68fa1c473f90ef35eb645f92126 100644 (file)
@@ -17,9 +17,7 @@
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
-#ifndef lint
-static char rcsid[] = "$Id: lcp.c,v 1.35 1999/03/16 02:47:00 paulus Exp $";
-#endif
+#define RCSID  "$Id: lcp.c,v 1.47 1999/12/23 01:27:28 paulus Exp $";
 
 /*
  * TODO:
@@ -35,11 +33,14 @@ static char rcsid[] = "$Id: lcp.c,v 1.35 1999/03/16 02:47:00 paulus Exp $";
 #include "chap.h"
 #include "magic.h"
 
+static const char rcsid[] = RCSID;
+
 /*
  * LCP-related command-line options.
  */
 int    lcp_echo_interval = 0;  /* Interval between LCP echo-requests */
 int    lcp_echo_fails = 0;     /* Tolerance to unanswered echo-requests */
+bool   lax_recv = 0;           /* accept control chars in asyncmap */
 
 static int setescape __P((char **));
 
@@ -63,7 +64,7 @@ static option_t lcp_option_list[] = {
     { "-as", o_uint32, &lcp_wantoptions[0].asyncmap,
       "Set asyncmap (for received packets)",
       OPT_OR, &lcp_wantoptions[0].neg_asyncmap },
-    { "nomagicnumber", o_bool, &lcp_wantoptions[0].neg_magicnumber,
+    { "nomagic", o_bool, &lcp_wantoptions[0].neg_magicnumber,
       "Disable magic number negotiation (looped-back line detection)",
       OPT_A2COPY, &lcp_allowoptions[0].neg_magicnumber },
     { "-mn", o_bool, &lcp_wantoptions[0].neg_magicnumber,
@@ -104,6 +105,8 @@ static option_t lcp_option_list[] = {
       "Set maximum number of LCP configure-request transmissions" },
     { "lcp-max-failure", o_int, &lcp_fsm[0].maxnakloops,
       "Set limit on number of LCP configure-naks" },
+    { "receive-all", o_bool, &lax_recv,
+      "Accept all received control characters", 1 },
     {NULL}
 };
 
@@ -115,9 +118,9 @@ lcp_options lcp_allowoptions[NUM_PPP];      /* Options we allow peer to request */
 lcp_options lcp_hisoptions[NUM_PPP];   /* Options that we ack'd */
 u_int32_t xmit_accm[NUM_PPP][8];               /* extended transmit ACCM */
 
-static u_int32_t lcp_echos_pending = 0;        /* Number of outstanding echo msgs */
-static u_int32_t lcp_echo_number   = 0;        /* ID number of next echo frame */
-static u_int32_t lcp_echo_timer_running = 0;  /* TRUE if a timer is running */
+static int lcp_echos_pending = 0;      /* Number of outstanding echo msgs */
+static int lcp_echo_number   = 0;      /* ID number of next echo frame */
+static int lcp_echo_timer_running = 0;  /* set if a timer is running */
 
 static u_char nak_buffer[PPP_MRU];     /* where we construct a nak packet */
 
@@ -192,6 +195,7 @@ struct protent lcp_protent = {
     NULL,
     1,
     "LCP",
+    NULL,
     lcp_option_list,
     NULL,
     NULL,
@@ -205,10 +209,10 @@ int lcp_loopbackfail = DEFLOOPBACKFAIL;
  */
 #define CILEN_VOID     2
 #define CILEN_CHAR     3
-#define CILEN_SHORT    4       /* CILEN_VOID + sizeof(short) */
-#define CILEN_CHAP     5       /* CILEN_VOID + sizeof(short) + 1 */
-#define CILEN_LONG     6       /* CILEN_VOID + sizeof(long) */
-#define CILEN_LQR      8       /* CILEN_VOID + sizeof(short) + sizeof(long) */
+#define CILEN_SHORT    4       /* CILEN_VOID + 2 */
+#define CILEN_CHAP     5       /* CILEN_VOID + 2 + 1 */
+#define CILEN_LONG     6       /* CILEN_VOID + 4 */
+#define CILEN_LQR      8       /* CILEN_VOID + 2 + 4 */
 #define CILEN_CBCP     3
 
 #define CODENAME(x)    ((x) == CONFACK ? "ACK" : \
@@ -332,7 +336,7 @@ lcp_close(unit, reason)
     fsm *f = &lcp_fsm[unit];
 
     if (phase != PHASE_DEAD)
-       phase = PHASE_TERMINATE;
+       new_phase(PHASE_TERMINATE);
     if (f->state == STOPPED && f->flags & (OPT_PASSIVE|OPT_SILENT)) {
        /*
         * This action is not strictly according to the FSM in RFC1548,
@@ -364,7 +368,7 @@ lcp_lowerup(unit)
      */
     ppp_set_xaccm(unit, xmit_accm[unit]);
     ppp_send_config(unit, PPP_MRU, 0xffffffff, 0, 0);
-    ppp_recv_config(unit, PPP_MRU, 0xffffffff,
+    ppp_recv_config(unit, PPP_MRU, (lax_recv? 0: 0xffffffff),
                    wo->neg_pcompression, wo->neg_accompression);
     peer_mru[unit] = PPP_MRU;
     lcp_allowoptions[unit].asyncmap = xmit_accm[unit][0];
@@ -453,7 +457,7 @@ lcp_rprotrej(f, inp, len)
     struct protent *protp;
     u_short prot;
 
-    if (len < sizeof (u_short)) {
+    if (len < 2) {
        LCPDEBUG(("lcp_rprotrej: Rcvd short Protocol-Reject packet!"));
        return;
     }
@@ -915,11 +919,18 @@ lcp_nakci(f, p, len)
            if (go->neg_chap) {
                /*
                 * We were asking for CHAP/MD5; they must want a different
-                * algorithm.  If they can't do MD5, we'll have to stop
+                * algorithm.  If they can't do MD5, we can ask for M$-CHAP
+                * if we support it, otherwise we'll have to stop
                 * asking for CHAP.
                 */
-               if (cichar != go->chap_mdtype)
-                   try.neg_chap = 0;
+               if (cichar != go->chap_mdtype) {
+#ifdef CHAPMS
+                   if (cichar == CHAP_MICROSOFT)
+                       go->chap_mdtype = CHAP_MICROSOFT;
+                   else
+#endif /* CHAPMS */
+                       try.neg_chap = 0;
+               }
            } else {
                /*
                 * Stop asking for PAP if we were asking for it.
@@ -1043,18 +1054,16 @@ lcp_nakci(f, p, len)
        p = next;
     }
 
-    /* If there is still anything left, this packet is bad. */
-    if (len != 0)
-       goto bad;
-
     /*
      * OK, the Nak is good.  Now we can update state.
+     * If there are any options left we ignore them.
      */
     if (f->state != OPENED) {
        if (looped_back) {
            if (++try.numloops >= lcp_loopbackfail) {
                notice("Serial line is looped back.");
                lcp_close(f->unit, "Loopback detected");
+               status = EXIT_LOOPBACK;
            }
        } else
            try.numloops = 0;
@@ -1322,7 +1331,7 @@ lcp_reqci(f, inp, lenp, reject_if_disagree)
            GETSHORT(cishort, p);
 
            /*
-            * Authtype must be UPAP or CHAP.
+            * Authtype must be PAP or CHAP.
             *
             * Note: if both ao->neg_upap and ao->neg_chap are set,
             * and the peer sends a Configure-Request with two
@@ -1345,6 +1354,8 @@ lcp_reqci(f, inp, lenp, reject_if_disagree)
                    PUTCHAR(CILEN_CHAP, nakp);
                    PUTSHORT(PPP_CHAP, nakp);
                    PUTCHAR(ao->chap_mdtype, nakp);
+                   /* XXX if we can do CHAP_MICROSOFT as well, we should
+                      probably put in another option saying so */
                    break;
                }
                ho->neg_upap = 1;
@@ -1550,7 +1561,7 @@ lcp_up(f)
                    (ho->neg_asyncmap? ho->asyncmap: 0xffffffff),
                    ho->neg_pcompression, ho->neg_accompression);
     ppp_recv_config(f->unit, (go->neg_mru? MAX(wo->mru, go->mru): PPP_MRU),
-                   (go->neg_asyncmap? go->asyncmap: 0xffffffff),
+                   (lax_recv? 0: go->neg_asyncmap? go->asyncmap: 0xffffffff),
                    go->neg_pcompression, go->neg_accompression);
 
     if (ho->neg_mru)
@@ -1723,7 +1734,7 @@ lcp_printpkt(p, plen, printer, arg)
                if (olen >= CILEN_CHAR) {
                    p += 2;
                    printer(arg, "callback ");
-                   GETSHORT(cishort, p);
+                   GETCHAR(cishort, p);
                    switch (cishort) {
                    case CBCP_OPT:
                        printer(arg, "CBCP");
@@ -1804,6 +1815,7 @@ void LcpLinkFailure (f)
        info("No response to %d echo-requests", lcp_echos_pending);
         notice("Serial link appears to be disconnected.");
         lcp_close(f->unit, "Peer not responding");
+       status = EXIT_PEER_DEAD;
     }
 }
 
@@ -1816,6 +1828,8 @@ LcpEchoCheck (f)
     fsm *f;
 {
     LcpSendEchoRequest (f);
+    if (f->state != OPENED)
+       return;
 
     /*
      * Start the timer for the next interval.
@@ -1847,7 +1861,9 @@ LcpEchoTimeout (arg)
 static void
 lcp_received_echo_reply (f, id, inp, len)
     fsm *f;
-    int id; u_char *inp; int len;
+    int id;
+    u_char *inp;
+    int len;
 {
     u_int32_t magic;