2 * lcp.c - PPP Link Control Protocol.
4 * Copyright (c) 1989 Carnegie Mellon University.
7 * Redistribution and use in source and binary forms are permitted
8 * provided that the above copyright notice and this paragraph are
9 * duplicated in all such forms and that any documentation,
10 * advertising materials, and other materials related to such
11 * distribution and use acknowledge that the software was developed
12 * by Carnegie Mellon University. The name of the
13 * University may not be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 static char rcsid[] = "$Id: lcp.c,v 1.3 1994/04/18 04:00:25 paulus Exp $";
32 #include <sys/ioctl.h>
33 #include <sys/types.h>
34 #include <sys/socket.h>
38 #include <net/if_ppp.h>
39 #include <netinet/in.h>
53 fsm lcp_fsm[NPPP]; /* LCP fsm structure (global)*/
54 lcp_options lcp_wantoptions[NPPP]; /* Options that we want to request */
55 lcp_options lcp_gotoptions[NPPP]; /* Options that peer ack'd */
56 lcp_options lcp_allowoptions[NPPP]; /* Options we allow peer to request */
57 lcp_options lcp_hisoptions[NPPP]; /* Options that we ack'd */
58 u_long xmit_accm[NPPP][8]; /* extended transmit ACCM */
61 * Callbacks for fsm code. (CI = Configuration Information)
63 static void lcp_resetci __ARGS((fsm *)); /* Reset our CI */
64 static int lcp_cilen __ARGS((fsm *)); /* Return length of our CI */
65 static void lcp_addci __ARGS((fsm *, u_char *, int *)); /* Add our CI to pkt */
66 static int lcp_ackci __ARGS((fsm *, u_char *, int)); /* Peer ack'd our CI */
67 static int lcp_nakci __ARGS((fsm *, u_char *, int)); /* Peer nak'd our CI */
68 static int lcp_rejci __ARGS((fsm *, u_char *, int)); /* Peer rej'd our CI */
69 static int lcp_reqci __ARGS((fsm *, u_char *, int *, int)); /* Rcv peer CI */
70 static void lcp_up __ARGS((fsm *)); /* We're UP */
71 static void lcp_down __ARGS((fsm *)); /* We're DOWN */
72 static void lcp_starting __ARGS((fsm *)); /* We need lower layer up */
73 static void lcp_finished __ARGS((fsm *)); /* We need lower layer down */
74 static int lcp_extcode __ARGS((fsm *, int, int, u_char *, int));
75 static void lcp_rprotrej __ARGS((fsm *, u_char *, int));
77 static fsm_callbacks lcp_callbacks = { /* LCP callback routines */
78 lcp_resetci, /* Reset our Configuration Information */
79 lcp_cilen, /* Length of our Configuration Information */
80 lcp_addci, /* Add our Configuration Information */
81 lcp_ackci, /* ACK our Configuration Information */
82 lcp_nakci, /* NAK our Configuration Information */
83 lcp_rejci, /* Reject our Configuration Information */
84 lcp_reqci, /* Request peer's Configuration Information */
85 lcp_up, /* Called when fsm reaches OPENED state */
86 lcp_down, /* Called when fsm leaves OPENED state */
87 lcp_starting, /* Called when we want the lower layer up */
88 lcp_finished, /* Called when we want the lower layer down */
89 NULL, /* Called when Protocol-Reject received */
90 NULL, /* Retransmission is necessary */
91 lcp_extcode, /* Called to handle LCP-specific codes */
92 "LCP" /* String name of protocol */
95 int lcp_warnloops = DEFWARNLOOPS; /* Warn about a loopback this often */
98 * Length of each type of configuration option (in octets)
101 #define CILEN_SHORT 4 /* CILEN_VOID + sizeof(short) */
102 #define CILEN_CHAP 5 /* CILEN_VOID + sizeof(short) + 1 */
103 #define CILEN_LONG 6 /* CILEN_VOID + sizeof(long) */
104 #define CILEN_LQR 8 /* CILEN_VOID + sizeof(short) + sizeof(long) */
106 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
107 (x) == CONFNAK ? "NAK" : "REJ")
111 * lcp_init - Initialize LCP.
117 fsm *f = &lcp_fsm[unit];
118 lcp_options *wo = &lcp_wantoptions[unit];
119 lcp_options *ao = &lcp_allowoptions[unit];
123 f->callbacks = &lcp_callbacks;
129 wo->restart = 0; /* Set to 1 in kernels or multi-line
133 wo->neg_asyncmap = 0;
135 wo->neg_chap = 0; /* Set to 1 on server */
136 wo->neg_upap = 0; /* Set to 1 on server */
137 wo->chap_mdtype = CHAP_DIGEST_MD5;
138 wo->neg_magicnumber = 1;
139 wo->neg_pcompression = 1;
140 wo->neg_accompression = 1;
141 wo->neg_lqr = 0; /* no LQR implementation yet */
145 ao->neg_asyncmap = 1;
148 ao->chap_mdtype = CHAP_DIGEST_MD5;
150 ao->neg_magicnumber = 1;
151 ao->neg_pcompression = 1;
152 ao->neg_accompression = 1;
153 ao->neg_lqr = 0; /* no LQR implementation yet */
155 memset(xmit_accm[unit], 0, sizeof(xmit_accm[0]));
156 xmit_accm[unit][3] = 0x60000000;
161 * lcp_open - LCP is allowed to come up.
167 fsm *f = &lcp_fsm[unit];
168 lcp_options *wo = &lcp_wantoptions[unit];
172 f->flags |= OPT_PASSIVE;
174 f->flags |= OPT_SILENT;
180 * lcp_close - Take LCP down.
186 fsm_close(&lcp_fsm[unit]);
191 * lcp_lowerup - The lower layer is up.
198 ppp_set_xaccm(unit, xmit_accm[unit]);
199 ppp_send_config(unit, MTU, 0xffffffff, 0, 0);
200 ppp_recv_config(unit, MTU, 0, 0, 0);
201 peer_mru[unit] = MTU;
202 lcp_allowoptions[unit].asyncmap = xmit_accm[unit][0];
204 fsm_lowerup(&lcp_fsm[unit]);
209 * lcp_lowerdown - The lower layer is down.
215 fsm_lowerdown(&lcp_fsm[unit]);
220 * lcp_input - Input LCP packet.
223 lcp_input(unit, p, len)
228 fsm_input(&lcp_fsm[unit], p, len);
233 * lcp_extcode - Handle a LCP-specific code.
236 lcp_extcode(f, code, id, inp, len)
244 lcp_rprotrej(f, inp, len);
248 if( f->state != OPENED )
250 LCPDEBUG((LOG_INFO, "lcp: Echo-Request, Rcvd id %d", id));
251 fsm_sdata(f, ECHOREP, id, inp, len);
266 * lcp_rprotrej - Receive an Protocol-Reject.
268 * Figure out which protocol is rejected and inform it.
271 lcp_rprotrej(f, inp, len)
278 LCPDEBUG((LOG_INFO, "lcp_rprotrej."));
280 if (len < sizeof (u_short)) {
282 "lcp_rprotrej: Rcvd short Protocol-Reject packet!"));
289 "lcp_rprotrej: Rcvd Protocol-Reject packet for %x!",
293 * Protocol-Reject packets received in any state other than the LCP
294 * OPENED state SHOULD be silently discarded.
296 if( f->state != OPENED ){
297 LCPDEBUG((LOG_INFO, "Protocol-Reject discarded: LCP in state %d",
302 DEMUXPROTREJ(f->unit, prot); /* Inform protocol */
307 * lcp_protrej - A Protocol-Reject was received.
317 LCPDEBUG((LOG_WARNING,
318 "lcp_protrej: Received Protocol-Reject for LCP!"));
319 fsm_protreject(&lcp_fsm[unit]);
324 * lcp_sprotrej - Send a Protocol-Reject for some protocol.
327 lcp_sprotrej(unit, p, len)
333 * Send back the protocol and the information field of the
334 * rejected packet. We only get here if LCP is in the OPENED state.
339 fsm_sdata(&lcp_fsm[unit], PROTREJ, ++lcp_fsm[unit].id,
345 * lcp_resetci - Reset our CI.
351 lcp_wantoptions[f->unit].magicnumber = magic();
352 lcp_wantoptions[f->unit].numloops = 0;
353 lcp_gotoptions[f->unit] = lcp_wantoptions[f->unit];
354 peer_mru[f->unit] = MTU;
359 * lcp_cilen - Return length of our CI.
365 lcp_options *go = &lcp_gotoptions[f->unit];
367 #define LENCIVOID(neg) (neg ? CILEN_VOID : 0)
368 #define LENCICHAP(neg) (neg ? CILEN_CHAP : 0)
369 #define LENCISHORT(neg) (neg ? CILEN_SHORT : 0)
370 #define LENCILONG(neg) (neg ? CILEN_LONG : 0)
371 #define LENCILQR(neg) (neg ? CILEN_LQR: 0)
373 * NB: we only ask for one of CHAP and UPAP, even if we will
376 return (LENCISHORT(go->neg_mru) +
377 LENCILONG(go->neg_asyncmap) +
378 LENCICHAP(go->neg_chap) +
379 LENCISHORT(!go->neg_chap && go->neg_upap) +
380 LENCILQR(go->neg_lqr) +
381 LENCILONG(go->neg_magicnumber) +
382 LENCIVOID(go->neg_pcompression) +
383 LENCIVOID(go->neg_accompression));
388 * lcp_addci - Add our desired CIs to a packet.
391 lcp_addci(f, ucp, lenp)
396 lcp_options *go = &lcp_gotoptions[f->unit];
397 u_char *start_ucp = ucp;
399 #define ADDCIVOID(opt, neg) \
402 PUTCHAR(CILEN_VOID, ucp); \
404 #define ADDCISHORT(opt, neg, val) \
407 PUTCHAR(CILEN_SHORT, ucp); \
408 PUTSHORT(val, ucp); \
410 #define ADDCICHAP(opt, neg, val, digest) \
413 PUTCHAR(CILEN_CHAP, ucp); \
414 PUTSHORT(val, ucp); \
415 PUTCHAR(digest, ucp); \
417 #define ADDCILONG(opt, neg, val) \
420 PUTCHAR(CILEN_LONG, ucp); \
423 #define ADDCILQR(opt, neg, val) \
426 PUTCHAR(CILEN_LQR, ucp); \
427 PUTSHORT(LQR, ucp); \
431 ADDCISHORT(CI_MRU, go->neg_mru, go->mru);
432 ADDCILONG(CI_ASYNCMAP, go->neg_asyncmap, go->asyncmap);
433 ADDCICHAP(CI_AUTHTYPE, go->neg_chap, CHAP, go->chap_mdtype);
434 ADDCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, UPAP);
435 ADDCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
436 ADDCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
437 ADDCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
438 ADDCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
440 if (ucp - start_ucp != *lenp) {
441 /* this should never happen, because peer_mtu should be 1500 */
442 syslog(LOG_ERR, "Bug in lcp_addci: wrong length");
448 * lcp_ackci - Ack our CIs.
449 * This should not modify any state if the Ack is bad.
461 lcp_options *go = &lcp_gotoptions[f->unit];
462 u_char cilen, citype, cichar;
467 * CIs must be in exactly the same order that we sent.
468 * Check packet length and CI length at each step.
469 * If we find any deviations, then this packet is bad.
471 #define ACKCIVOID(opt, neg) \
473 if ((len -= CILEN_VOID) < 0) \
475 GETCHAR(citype, p); \
477 if (cilen != CILEN_VOID || \
481 #define ACKCISHORT(opt, neg, val) \
483 if ((len -= CILEN_SHORT) < 0) \
485 GETCHAR(citype, p); \
487 if (cilen != CILEN_SHORT || \
490 GETSHORT(cishort, p); \
491 if (cishort != val) \
494 #define ACKCICHAP(opt, neg, val, digest) \
496 if ((len -= CILEN_CHAP) < 0) \
498 GETCHAR(citype, p); \
500 if (cilen != CILEN_CHAP || \
503 GETSHORT(cishort, p); \
504 if (cishort != val) \
506 GETCHAR(cichar, p); \
507 if (cichar != digest) \
510 #define ACKCILONG(opt, neg, val) \
512 if ((len -= CILEN_LONG) < 0) \
514 GETCHAR(citype, p); \
516 if (cilen != CILEN_LONG || \
519 GETLONG(cilong, p); \
523 #define ACKCILQR(opt, neg, val) \
525 if ((len -= CILEN_LQR) < 0) \
527 GETCHAR(citype, p); \
529 if (cilen != CILEN_LQR || \
532 GETSHORT(cishort, p); \
533 if (cishort != LQR) \
535 GETLONG(cilong, p); \
540 ACKCISHORT(CI_MRU, go->neg_mru, go->mru);
541 ACKCILONG(CI_ASYNCMAP, go->neg_asyncmap, go->asyncmap);
542 ACKCICHAP(CI_AUTHTYPE, go->neg_chap, CHAP, go->chap_mdtype);
543 ACKCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, UPAP);
544 ACKCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
545 ACKCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
546 ACKCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
547 ACKCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
550 * If there are any remaining CIs, then this packet is bad.
556 LCPDEBUG((LOG_WARNING, "lcp_acki: received bad Ack!"));
562 * lcp_nakci - Peer has sent a NAK for some of our CIs.
563 * This should not modify any state if the Nak is bad
564 * or if LCP is in the OPENED state.
576 lcp_options *go = &lcp_gotoptions[f->unit];
577 lcp_options *wo = &lcp_wantoptions[f->unit];
578 u_char cilen, citype, cichar, *next;
581 lcp_options no; /* options we've seen Naks for */
582 lcp_options try; /* options to request next time */
585 BZERO(&no, sizeof(no));
589 * Any Nak'd CIs must be in exactly the same order that we sent.
590 * Check packet length and CI length at each step.
591 * If we find any deviations, then this packet is bad.
593 #define NAKCIVOID(opt, neg, code) \
595 len >= CILEN_VOID && \
596 p[1] == CILEN_VOID && \
599 INCPTR(CILEN_VOID, p); \
603 #define NAKCICHAP(opt, neg, code) \
605 len >= CILEN_CHAP && \
606 p[1] == CILEN_CHAP && \
610 GETSHORT(cishort, p); \
611 GETCHAR(cichar, p); \
615 #define NAKCISHORT(opt, neg, code) \
617 len >= CILEN_SHORT && \
618 p[1] == CILEN_SHORT && \
620 len -= CILEN_SHORT; \
622 GETSHORT(cishort, p); \
626 #define NAKCILONG(opt, neg, code) \
628 len >= CILEN_LONG && \
629 p[1] == CILEN_LONG && \
633 GETLONG(cilong, p); \
637 #define NAKCILQR(opt, neg, code) \
639 len >= CILEN_LQR && \
640 p[1] == CILEN_LQR && \
644 GETSHORT(cishort, p); \
645 GETLONG(cilong, p); \
651 * We don't care if they want to send us smaller packets than
652 * we want. Therefore, accept any MRU less than what we asked for,
653 * but then ignore the new value when setting the MRU in the kernel.
654 * If they send us a bigger MRU than what we asked, accept it, up to
655 * the limit of the default MRU we'd get if we didn't negotiate.
657 NAKCISHORT(CI_MRU, neg_mru,
658 if (cishort <= wo->mru || cishort < DEFMRU)
662 * Add any characters they want to our (receive-side) asyncmap.
664 NAKCILONG(CI_ASYNCMAP, neg_asyncmap,
665 try.asyncmap = go->asyncmap | cilong;
668 * If they can't cope with our CHAP hash algorithm, we'll have
669 * to stop asking for CHAP. We haven't got any other algorithm.
671 NAKCICHAP(CI_AUTHTYPE, neg_chap,
675 * Peer shouldn't send Nak for UPAP, protocol compression or
676 * address/control compression requests; they should send
677 * a Reject instead. If they send a Nak, treat it as a Reject.
680 NAKCISHORT(CI_AUTHTYPE, neg_upap,
685 * If they can't cope with our link quality protocol, we'll have
686 * to stop asking for LQR. We haven't got any other protocol.
687 * If they Nak the reporting period, take their value XXX ?
689 NAKCILONG(CI_QUALITY, neg_lqr,
693 try.lqr_period = cilong;
696 * Check for a looped-back line.
698 NAKCILONG(CI_MAGICNUMBER, neg_magicnumber,
699 try.magicnumber = magic();
704 NAKCIVOID(CI_PCOMPRESSION, neg_pcompression,
705 try.neg_pcompression = 0;
707 NAKCIVOID(CI_ACCOMPRESSION, neg_accompression,
708 try.neg_accompression = 0;
712 * There may be remaining CIs, if the peer is requesting negotiation
713 * on an option that we didn't include in our request packet.
714 * If we see an option that we requested, or one we've already seen
715 * in this packet, then this packet is bad.
716 * If we wanted to respond by starting to negotiate on the requested
717 * option(s), we could, but we don't, because except for the
718 * authentication type and quality protocol, if we are not negotiating
719 * an option, it is because we were told not to.
720 * For the authentication type, the Nak from the peer means
721 * `let me authenticate myself with you' which is a bit pointless.
722 * For the quality protocol, the Nak means `ask me to send you quality
723 * reports', but if we didn't ask for them, we don't want them.
725 while (len > CILEN_VOID) {
728 if( (len -= cilen) < 0 )
730 next = p + cilen - 2;
734 if (go->neg_mru || no.neg_mru || cilen != CILEN_SHORT)
738 if (go->neg_asyncmap || no.neg_asyncmap || cilen != CILEN_LONG)
742 if (go->neg_chap || no.neg_chap || go->neg_upap || no.neg_upap)
746 if (go->neg_magicnumber || no.neg_magicnumber ||
750 case CI_PCOMPRESSION:
751 if (go->neg_pcompression || no.neg_pcompression
752 || cilen != CILEN_VOID)
755 case CI_ACCOMPRESSION:
756 if (go->neg_accompression || no.neg_accompression
757 || cilen != CILEN_VOID)
761 if (go->neg_lqr || no.neg_lqr || cilen != CILEN_LQR)
770 /* If there is still anything left, this packet is bad. */
775 * OK, the Nak is good. Now we can update state.
777 if (f->state != OPENED) {
779 if (looped_back && try.numloops % lcp_warnloops == 0)
780 LCPDEBUG((LOG_INFO, "The line appears to be looped back."));
786 LCPDEBUG((LOG_WARNING, "lcp_nakci: received bad Nak!"));
792 * lcp_rejci - Peer has Rejected some of our CIs.
793 * This should not modify any state if the Reject is bad
794 * or if LCP is in the OPENED state.
797 * 0 - Reject was bad.
798 * 1 - Reject was good.
806 lcp_options *go = &lcp_gotoptions[f->unit];
812 lcp_options try; /* options to request next time */
817 * Any Rejected CIs must be in exactly the same order that we sent.
818 * Check packet length and CI length at each step.
819 * If we find any deviations, then this packet is bad.
821 #define REJCIVOID(opt, neg) \
823 len >= CILEN_VOID && \
824 p[1] == CILEN_VOID && \
827 INCPTR(CILEN_VOID, p); \
829 LCPDEBUG((LOG_INFO, "lcp_rejci rejected void opt %d", opt)); \
831 #define REJCISHORT(opt, neg, val) \
833 len >= CILEN_SHORT && \
834 p[1] == CILEN_SHORT && \
836 len -= CILEN_SHORT; \
838 GETSHORT(cishort, p); \
839 /* Check rejected value. */ \
840 if (cishort != val) \
843 LCPDEBUG((LOG_INFO,"lcp_rejci rejected short opt %d", opt)); \
845 #define REJCICHAP(opt, neg, val, digest) \
847 len >= CILEN_CHAP && \
848 p[1] == CILEN_CHAP && \
852 GETSHORT(cishort, p); \
853 GETCHAR(cichar, p); \
854 /* Check rejected value. */ \
855 if (cishort != val || cichar != digest) \
858 LCPDEBUG((LOG_INFO,"lcp_rejci rejected chap opt %d", opt)); \
860 #define REJCILONG(opt, neg, val) \
862 len >= CILEN_LONG && \
863 p[1] == CILEN_LONG && \
867 GETLONG(cilong, p); \
868 /* Check rejected value. */ \
872 LCPDEBUG((LOG_INFO,"lcp_rejci rejected long opt %d", opt)); \
874 #define REJCILQR(opt, neg, val) \
876 len >= CILEN_LQR && \
877 p[1] == CILEN_LQR && \
881 GETSHORT(cishort, p); \
882 GETLONG(cilong, p); \
883 /* Check rejected value. */ \
884 if (cishort != LQR || cichar != val) \
887 LCPDEBUG((LOG_INFO,"lcp_rejci rejected LQR opt %d", opt)); \
890 REJCISHORT(CI_MRU, neg_mru, go->mru);
891 REJCILONG(CI_ASYNCMAP, neg_asyncmap, go->asyncmap);
892 REJCICHAP(CI_AUTHTYPE, neg_chap, CHAP, go->chap_mdtype);
894 REJCISHORT(CI_AUTHTYPE, neg_upap, UPAP);
896 REJCILQR(CI_QUALITY, neg_lqr, go->lqr_period);
897 REJCILONG(CI_MAGICNUMBER, neg_magicnumber, go->magicnumber);
898 REJCIVOID(CI_PCOMPRESSION, neg_pcompression);
899 REJCIVOID(CI_ACCOMPRESSION, neg_accompression);
902 * If there are any remaining CIs, then this packet is bad.
907 * Now we can update state.
909 if (f->state != OPENED)
914 LCPDEBUG((LOG_WARNING, "lcp_rejci: received bad Reject!"));
915 LCPDEBUG((LOG_WARNING, "lcp_rejci: plen %d len %d off %d",
916 plen, len, p - start));
922 * lcp_reqci - Check the peer's requested CIs and send appropriate response.
924 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
925 * appropriately. If reject_if_disagree is non-zero, doesn't return
926 * CONFNAK; returns CONFREJ if it can't return CONFACK.
929 lcp_reqci(f, inp, lenp, reject_if_disagree)
931 u_char *inp; /* Requested CIs */
932 int *lenp; /* Length of requested CIs */
933 int reject_if_disagree;
935 lcp_options *go = &lcp_gotoptions[f->unit];
936 lcp_options *ho = &lcp_hisoptions[f->unit];
937 lcp_options *ao = &lcp_allowoptions[f->unit];
938 u_char *cip, *next; /* Pointer to current and next CIs */
939 u_char cilen, citype, cichar;/* Parsed len, type, char value */
940 u_short cishort; /* Parsed short value */
941 u_long cilong; /* Parse long value */
942 int rc = CONFACK; /* Final packet return code */
943 int orc; /* Individual option return code */
944 u_char *p; /* Pointer to next char to parse */
945 u_char *ucp = inp; /* Pointer to current output char */
946 int l = *lenp; /* Length left */
949 * Reset all his options.
951 BZERO(ho, sizeof(*ho));
954 * Process all his options.
958 orc = CONFACK; /* Assume success */
959 cip = p = next; /* Remember begining of CI */
960 if (l < 2 || /* Not enough data for CI header or */
961 p[1] < 2 || /* CI length too small or */
962 p[1] > l) { /* CI length too big? */
963 LCPDEBUG((LOG_WARNING, "lcp_reqci: bad CI length!"));
964 orc = CONFREJ; /* Reject bad CI */
965 cilen = l; /* Reject till end of packet */
966 l = 0; /* Don't loop again */
969 GETCHAR(citype, p); /* Parse CI type */
970 GETCHAR(cilen, p); /* Parse CI length */
971 l -= cilen; /* Adjust remaining length */
972 next += cilen; /* Step to next CI */
974 switch (citype) { /* Check CI type */
976 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd MRU"));
977 if (!ao->neg_mru || /* Allow option? */
978 cilen != CILEN_SHORT) { /* Check CI length */
979 orc = CONFREJ; /* Reject CI */
982 GETSHORT(cishort, p); /* Parse MRU */
983 LCPDEBUG((LOG_INFO, "(%d)", cishort));
986 * He must be able to receive at least our minimum.
987 * No need to check a maximum. If he sends a large number,
988 * we'll just ignore it.
990 if (cishort < MINMRU) {
991 orc = CONFNAK; /* Nak CI */
992 if( !reject_if_disagree ){
993 DECPTR(sizeof (short), p); /* Backup */
994 PUTSHORT(MINMRU, p); /* Give him a hint */
998 ho->neg_mru = 1; /* Remember he sent MRU */
999 ho->mru = cishort; /* And remember value */
1003 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd ASYNCMAP"));
1004 if (!ao->neg_asyncmap ||
1005 cilen != CILEN_LONG) {
1010 LCPDEBUG((LOG_INFO, "(%lx)", cilong));
1013 * Asyncmap must have set at least the bits
1014 * which are set in lcp_allowoptions[unit].asyncmap.
1016 if ((ao->asyncmap & ~cilong) != 0) {
1018 if( !reject_if_disagree ){
1019 DECPTR(sizeof (long), p);
1020 PUTLONG(ao->asyncmap | cilong, p);
1024 ho->neg_asyncmap = 1;
1025 ho->asyncmap = cilong;
1029 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd AUTHTYPE"));
1030 if (cilen < CILEN_SHORT ||
1031 !(ao->neg_upap || ao->neg_chap)) {
1035 GETSHORT(cishort, p);
1036 LCPDEBUG((LOG_INFO, "(%x)", cishort));
1039 * Authtype must be UPAP or CHAP.
1041 * Note: if both ao->neg_upap and ao->neg_chap are set,
1042 * and the peer sends a Configure-Request with two
1043 * authenticate-protocol requests, one for CHAP and one
1044 * for UPAP, then we will reject the second request.
1045 * Whether we end up doing CHAP or UPAP depends then on
1046 * the ordering of the CIs in the peer's Configure-Request.
1049 if (cishort == UPAP) {
1050 if (!ao->neg_upap || /* we don't want to do PAP */
1051 ho->neg_chap || /* or we've already accepted CHAP */
1052 cilen != CILEN_SHORT) {
1053 LCPDEBUG((LOG_WARNING,
1054 "lcp_reqci: rcvd AUTHTYPE PAP, rejecting..."));
1061 if (cishort == CHAP) {
1062 if (!ao->neg_chap || /* we don't want to do CHAP */
1063 ho->neg_upap || /* or we've already accepted UPAP */
1064 cilen != CILEN_CHAP) {
1066 "lcp_reqci: rcvd AUTHTYPE CHAP, rejecting..."));
1070 GETCHAR(cichar, p); /* get digest type*/
1071 if (cichar != ao->chap_mdtype) {
1073 if( !reject_if_disagree ){
1074 DECPTR(sizeof (u_char), p);
1075 PUTCHAR(ao->chap_mdtype, p);
1079 ho->chap_mdtype = cichar; /* save md type */
1085 * We don't recognize the protocol they're asking for.
1092 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd QUALITY"));
1094 cilen != CILEN_LQR) {
1099 GETSHORT(cishort, p);
1101 LCPDEBUG((LOG_INFO, "(%x %lx)", cishort, cilong));
1102 if (cishort != LQR) {
1108 * Check the reporting period.
1109 * XXX When should we Nak this, and what with?
1113 case CI_MAGICNUMBER:
1114 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd MAGICNUMBER"));
1115 if (!(ao->neg_magicnumber || go->neg_magicnumber) ||
1116 cilen != CILEN_LONG) {
1121 LCPDEBUG((LOG_INFO, "(%lx)", cilong));
1124 * He must have a different magic number.
1126 if (go->neg_magicnumber &&
1127 cilong == go->magicnumber) {
1129 DECPTR(sizeof (long), p);
1130 cilong = magic(); /* Don't put magic() inside macro! */
1134 ho->neg_magicnumber = 1;
1135 ho->magicnumber = cilong;
1139 case CI_PCOMPRESSION:
1140 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd PCOMPRESSION"));
1141 if (!ao->neg_pcompression ||
1142 cilen != CILEN_VOID) {
1146 ho->neg_pcompression = 1;
1149 case CI_ACCOMPRESSION:
1150 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd ACCOMPRESSION"));
1151 if (!ao->neg_accompression ||
1152 cilen != CILEN_VOID) {
1156 ho->neg_accompression = 1;
1160 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd unknown option %d",
1167 LCPDEBUG((LOG_INFO, " (%s)", CODENAME(orc)));
1168 if (orc == CONFACK && /* Good CI */
1169 rc != CONFACK) /* but prior CI wasnt? */
1170 continue; /* Don't send this one */
1172 if (orc == CONFNAK) { /* Nak this CI? */
1173 if (reject_if_disagree) /* Getting fed up with sending NAKs? */
1174 orc = CONFREJ; /* Get tough if so */
1176 if (rc == CONFREJ) /* Rejecting prior CI? */
1177 continue; /* Don't send this one */
1178 if (rc == CONFACK) { /* Ack'd all prior CIs? */
1179 rc = CONFNAK; /* Not anymore... */
1180 ucp = inp; /* Backup */
1184 if (orc == CONFREJ && /* Reject this CI */
1185 rc != CONFREJ) { /* but no prior ones? */
1187 ucp = inp; /* Backup */
1189 if (ucp != cip) /* Need to move CI? */
1190 BCOPY(cip, ucp, cilen); /* Move it */
1191 INCPTR(cilen, ucp); /* Update output pointer */
1195 * If we wanted to send additional NAKs (for unsent CIs), the
1196 * code would go here. This must be done with care since it might
1197 * require a longer packet than we received. At present there
1198 * are no cases where we want to ask the peer to negotiate an option.
1201 *lenp = ucp - inp; /* Compute output length */
1202 LCPDEBUG((LOG_INFO, "lcp_reqci: returning CONF%s.", CODENAME(rc)));
1203 return (rc); /* Return final code */
1208 * lcp_up - LCP has come UP.
1210 * Start UPAP, IPCP, etc.
1216 lcp_options *wo = &lcp_wantoptions[f->unit];
1217 lcp_options *ho = &lcp_hisoptions[f->unit];
1218 lcp_options *go = &lcp_gotoptions[f->unit];
1219 lcp_options *ao = &lcp_allowoptions[f->unit];
1222 * Set our MTU to the smaller of the MTU we wanted and
1223 * the MRU our peer wanted. If we negotiated an MRU,
1224 * set our MRU to the larger of value we wanted and
1225 * the value we got in the negotiation.
1227 ppp_send_config(f->unit, MIN(ao->mru, (ho->neg_mru? ho->mru: MTU)),
1228 (ho->neg_asyncmap? ho->asyncmap: 0xffffffff),
1229 ho->neg_pcompression, ho->neg_accompression);
1230 ppp_recv_config(f->unit, (go->neg_mru? MAX(wo->mru, go->mru): MTU),
1231 (go->neg_asyncmap? go->asyncmap: 0xffffffff),
1232 go->neg_pcompression, go->neg_accompression);
1235 peer_mru[f->unit] = ho->mru;
1237 ChapLowerUp(f->unit); /* Enable CHAP */
1238 upap_lowerup(f->unit); /* Enable UPAP */
1239 ipcp_lowerup(f->unit); /* Enable IPCP */
1241 link_established(f->unit);
1246 * lcp_down - LCP has gone DOWN.
1248 * Alert other protocols.
1254 ipcp_lowerdown(f->unit);
1255 ChapLowerDown(f->unit);
1256 upap_lowerdown(f->unit);
1259 ppp_send_config(f->unit, MTU, 0xffffffff, 0, 0);
1260 ppp_recv_config(f->unit, MTU, 0, 0, 0);
1261 peer_mru[f->unit] = MTU;
1268 * lcp_starting - LCP needs the lower layer up.
1274 link_required(f->unit);
1279 * lcp_finished - LCP has finished with the lower layer.
1285 link_terminated(f->unit);
1290 * lcp_printpkt - print the contents of an LCP packet.
1292 char *lcp_codenames[] = {
1293 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1294 "TermReq", "TermAck", "CodeRej", "ProtRej",
1295 "EchoReq", "EchoRep", "DiscReq"
1299 lcp_printpkt(p, plen, printer, arg)
1302 void (*printer) __ARGS((void *, char *, ...));
1305 int code, id, len, olen;
1306 u_char *pstart, *optend;
1310 if (plen < HEADERLEN)
1316 if (len < HEADERLEN || len > plen)
1319 if (code >= 1 && code <= sizeof(lcp_codenames) / sizeof(char *))
1320 printer(arg, " %s", lcp_codenames[code-1]);
1322 printer(arg, " code=0x%x", code);
1323 printer(arg, " id=0x%x", id);
1330 /* print option list */
1335 if (olen < 2 || olen > len) {
1343 if (olen == CILEN_SHORT) {
1345 GETSHORT(cishort, p);
1346 printer(arg, "mru %d", cishort);
1350 if (olen == CILEN_LONG) {
1353 printer(arg, "asyncmap 0x%x", cilong);
1357 if (olen >= CILEN_SHORT) {
1359 printer(arg, "auth ");
1360 GETSHORT(cishort, p);
1363 printer(arg, "upap");
1366 printer(arg, "chap");
1369 printer(arg, "0x%x", cishort);
1374 if (olen >= CILEN_SHORT) {
1376 printer(arg, "quality ");
1377 GETSHORT(cishort, p);
1380 printer(arg, "lqr");
1383 printer(arg, "0x%x", cishort);
1387 case CI_MAGICNUMBER:
1388 if (olen == CILEN_LONG) {
1391 printer(arg, "magic 0x%x", cilong);
1394 case CI_PCOMPRESSION:
1395 if (olen == CILEN_VOID) {
1397 printer(arg, "pcomp");
1400 case CI_ACCOMPRESSION:
1401 if (olen == CILEN_VOID) {
1403 printer(arg, "accomp");
1407 while (p < optend) {
1409 printer(arg, " %.2x", code);
1416 /* print the rest of the bytes in the packet */
1417 for (; len > 0; --len) {
1419 printer(arg, " %.2x", code);