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.1 1993/11/11 03:54: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 */
60 * Callbacks for fsm code. (CI = Configuration Information)
62 static void lcp_resetci __ARGS((fsm *)); /* Reset our CI */
63 static int lcp_cilen __ARGS((fsm *)); /* Return length of our CI */
64 static void lcp_addci __ARGS((fsm *, u_char *, int *)); /* Add our CI to pkt */
65 static int lcp_ackci __ARGS((fsm *, u_char *, int)); /* Peer ack'd our CI */
66 static int lcp_nakci __ARGS((fsm *, u_char *, int)); /* Peer nak'd our CI */
67 static int lcp_rejci __ARGS((fsm *, u_char *, int)); /* Peer rej'd our CI */
68 static int lcp_reqci __ARGS((fsm *, u_char *, int *, int)); /* Rcv peer CI */
69 static void lcp_up __ARGS((fsm *)); /* We're UP */
70 static void lcp_down __ARGS((fsm *)); /* We're DOWN */
71 static void lcp_starting __ARGS((fsm *)); /* We need lower layer up */
72 static void lcp_finished __ARGS((fsm *)); /* We need lower layer down */
73 static int lcp_extcode __ARGS((fsm *, int, int, u_char *, int));
74 static void lcp_rprotrej __ARGS((fsm *, u_char *, int));
76 static fsm_callbacks lcp_callbacks = { /* LCP callback routines */
77 lcp_resetci, /* Reset our Configuration Information */
78 lcp_cilen, /* Length of our Configuration Information */
79 lcp_addci, /* Add our Configuration Information */
80 lcp_ackci, /* ACK our Configuration Information */
81 lcp_nakci, /* NAK our Configuration Information */
82 lcp_rejci, /* Reject our Configuration Information */
83 lcp_reqci, /* Request peer's Configuration Information */
84 lcp_up, /* Called when fsm reaches OPENED state */
85 lcp_down, /* Called when fsm leaves OPENED state */
86 lcp_starting, /* Called when we want the lower layer up */
87 lcp_finished, /* Called when we want the lower layer down */
88 NULL, /* Called when Protocol-Reject received */
89 NULL, /* Retransmission is necessary */
90 lcp_extcode, /* Called to handle LCP-specific codes */
91 "LCP" /* String name of protocol */
94 int lcp_warnloops = DEFWARNLOOPS; /* Warn about a loopback this often */
97 * Length of each type of configuration option (in octets)
100 #define CILEN_SHORT 4 /* CILEN_VOID + sizeof(short) */
101 #define CILEN_CHAP 5 /* CILEN_VOID + sizeof(short) + 1 */
102 #define CILEN_LONG 6 /* CILEN_VOID + sizeof(long) */
103 #define CILEN_LQR 8 /* CILEN_VOID + sizeof(short) + sizeof(long) */
105 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
106 (x) == CONFNAK ? "NAK" : "REJ")
110 * lcp_init - Initialize LCP.
116 fsm *f = &lcp_fsm[unit];
117 lcp_options *wo = &lcp_wantoptions[unit];
118 lcp_options *ao = &lcp_allowoptions[unit];
122 f->callbacks = &lcp_callbacks;
128 wo->restart = 0; /* Set to 1 in kernels or multi-line
132 wo->neg_asyncmap = 1;
134 wo->neg_chap = 0; /* Set to 1 on server */
135 wo->neg_upap = 0; /* Set to 1 on server */
136 wo->chap_mdtype = CHAP_DIGEST_MD5;
137 wo->neg_magicnumber = 1;
138 wo->neg_pcompression = 1;
139 wo->neg_accompression = 1;
140 wo->neg_lqr = 0; /* no LQR implementation yet */
144 ao->neg_asyncmap = 1;
147 ao->chap_mdtype = CHAP_DIGEST_MD5;
149 ao->neg_magicnumber = 1;
150 ao->neg_pcompression = 1;
151 ao->neg_accompression = 1;
152 ao->neg_lqr = 0; /* no LQR implementation yet */
158 * lcp_open - LCP is allowed to come up.
164 fsm *f = &lcp_fsm[unit];
165 lcp_options *wo = &lcp_wantoptions[unit];
169 f->flags |= OPT_PASSIVE;
171 f->flags |= OPT_SILENT;
177 * lcp_close - Take LCP down.
183 fsm_close(&lcp_fsm[unit]);
188 * lcp_lowerup - The lower layer is up.
195 ppp_send_config(unit, MTU, 0xffffffff, 0, 0);
196 ppp_recv_config(unit, MTU, 0, 0, 0);
197 peer_mru[unit] = MTU;
199 fsm_lowerup(&lcp_fsm[unit]);
204 * lcp_lowerdown - The lower layer is down.
210 fsm_lowerdown(&lcp_fsm[unit]);
215 * lcp_input - Input LCP packet.
218 lcp_input(unit, p, len)
223 fsm_input(&lcp_fsm[unit], p, len);
228 * lcp_extcode - Handle a LCP-specific code.
231 lcp_extcode(f, code, id, inp, len)
239 lcp_rprotrej(f, inp, len);
243 if( f->state != OPENED )
245 LCPDEBUG((LOG_INFO, "lcp: Echo-Request, Rcvd id %d", id));
246 fsm_sdata(f, ECHOREP, id, inp, len);
261 * lcp_rprotrej - Receive an Protocol-Reject.
263 * Figure out which protocol is rejected and inform it.
266 lcp_rprotrej(f, inp, len)
273 LCPDEBUG((LOG_INFO, "lcp_rprotrej."));
275 if (len < sizeof (u_short)) {
277 "lcp_rprotrej: Rcvd short Protocol-Reject packet!"));
284 "lcp_rprotrej: Rcvd Protocol-Reject packet for %x!",
288 * Protocol-Reject packets received in any state other than the LCP
289 * OPENED state SHOULD be silently discarded.
291 if( f->state != OPENED ){
292 LCPDEBUG((LOG_INFO, "Protocol-Reject discarded: LCP in state %d",
297 DEMUXPROTREJ(f->unit, prot); /* Inform protocol */
302 * lcp_protrej - A Protocol-Reject was received.
312 LCPDEBUG((LOG_WARNING,
313 "lcp_protrej: Received Protocol-Reject for LCP!"));
314 fsm_protreject(&lcp_fsm[unit]);
319 * lcp_sprotrej - Send a Protocol-Reject for some protocol.
322 lcp_sprotrej(unit, p, len)
328 * Send back the protocol and the information field of the
329 * rejected packet. We only get here if LCP is in the OPENED state.
334 fsm_sdata(&lcp_fsm[unit], PROTREJ, ++lcp_fsm[unit].id,
340 * lcp_resetci - Reset our CI.
346 lcp_wantoptions[f->unit].magicnumber = magic();
347 lcp_wantoptions[f->unit].numloops = 0;
348 lcp_gotoptions[f->unit] = lcp_wantoptions[f->unit];
349 peer_mru[f->unit] = MTU;
354 * lcp_cilen - Return length of our CI.
360 lcp_options *go = &lcp_gotoptions[f->unit];
362 #define LENCIVOID(neg) (neg ? CILEN_VOID : 0)
363 #define LENCICHAP(neg) (neg ? CILEN_CHAP : 0)
364 #define LENCISHORT(neg) (neg ? CILEN_SHORT : 0)
365 #define LENCILONG(neg) (neg ? CILEN_LONG : 0)
366 #define LENCILQR(neg) (neg ? CILEN_LQR: 0)
368 * NB: we only ask for one of CHAP and UPAP, even if we will
371 return (LENCISHORT(go->neg_mru) +
372 LENCILONG(go->neg_asyncmap) +
373 LENCICHAP(go->neg_chap) +
374 LENCISHORT(!go->neg_chap && go->neg_upap) +
375 LENCILQR(go->neg_lqr) +
376 LENCILONG(go->neg_magicnumber) +
377 LENCIVOID(go->neg_pcompression) +
378 LENCIVOID(go->neg_accompression));
383 * lcp_addci - Add our desired CIs to a packet.
386 lcp_addci(f, ucp, lenp)
391 lcp_options *go = &lcp_gotoptions[f->unit];
392 u_char *start_ucp = ucp;
394 #define ADDCIVOID(opt, neg) \
397 PUTCHAR(CILEN_VOID, ucp); \
399 #define ADDCISHORT(opt, neg, val) \
402 PUTCHAR(CILEN_SHORT, ucp); \
403 PUTSHORT(val, ucp); \
405 #define ADDCICHAP(opt, neg, val, digest) \
408 PUTCHAR(CILEN_CHAP, ucp); \
409 PUTSHORT(val, ucp); \
410 PUTCHAR(digest, ucp); \
412 #define ADDCILONG(opt, neg, val) \
415 PUTCHAR(CILEN_LONG, ucp); \
418 #define ADDCILQR(opt, neg, val) \
421 PUTCHAR(CILEN_LQR, ucp); \
422 PUTSHORT(LQR, ucp); \
426 ADDCISHORT(CI_MRU, go->neg_mru, go->mru);
427 ADDCILONG(CI_ASYNCMAP, go->neg_asyncmap, go->asyncmap);
428 ADDCICHAP(CI_AUTHTYPE, go->neg_chap, CHAP, go->chap_mdtype);
429 ADDCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, UPAP);
430 ADDCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
431 ADDCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
432 ADDCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
433 ADDCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
435 if (ucp - start_ucp != *lenp) {
436 /* this should never happen, because peer_mtu should be 1500 */
437 syslog(LOG_ERR, "Bug in lcp_addci: wrong length");
443 * lcp_ackci - Ack our CIs.
444 * This should not modify any state if the Ack is bad.
456 lcp_options *go = &lcp_gotoptions[f->unit];
457 u_char cilen, citype, cichar;
462 * CIs must be in exactly the same order that we sent.
463 * Check packet length and CI length at each step.
464 * If we find any deviations, then this packet is bad.
466 #define ACKCIVOID(opt, neg) \
468 if ((len -= CILEN_VOID) < 0) \
470 GETCHAR(citype, p); \
472 if (cilen != CILEN_VOID || \
476 #define ACKCISHORT(opt, neg, val) \
478 if ((len -= CILEN_SHORT) < 0) \
480 GETCHAR(citype, p); \
482 if (cilen != CILEN_SHORT || \
485 GETSHORT(cishort, p); \
486 if (cishort != val) \
489 #define ACKCICHAP(opt, neg, val, digest) \
491 if ((len -= CILEN_CHAP) < 0) \
493 GETCHAR(citype, p); \
495 if (cilen != CILEN_CHAP || \
498 GETSHORT(cishort, p); \
499 if (cishort != val) \
501 GETCHAR(cichar, p); \
502 if (cichar != digest) \
505 #define ACKCILONG(opt, neg, val) \
507 if ((len -= CILEN_LONG) < 0) \
509 GETCHAR(citype, p); \
511 if (cilen != CILEN_LONG || \
514 GETLONG(cilong, p); \
518 #define ACKCILQR(opt, neg, val) \
520 if ((len -= CILEN_LQR) < 0) \
522 GETCHAR(citype, p); \
524 if (cilen != CILEN_LQR || \
527 GETSHORT(cishort, p); \
528 if (cishort != LQR) \
530 GETLONG(cilong, p); \
535 ACKCISHORT(CI_MRU, go->neg_mru, go->mru);
536 ACKCILONG(CI_ASYNCMAP, go->neg_asyncmap, go->asyncmap);
537 ACKCICHAP(CI_AUTHTYPE, go->neg_chap, CHAP, go->chap_mdtype);
538 ACKCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, UPAP);
539 ACKCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
540 ACKCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
541 ACKCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
542 ACKCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
545 * If there are any remaining CIs, then this packet is bad.
551 LCPDEBUG((LOG_WARNING, "lcp_acki: received bad Ack!"));
557 * lcp_nakci - Peer has sent a NAK for some of our CIs.
558 * This should not modify any state if the Nak is bad
559 * or if LCP is in the OPENED state.
571 lcp_options *go = &lcp_gotoptions[f->unit];
572 lcp_options *wo = &lcp_wantoptions[f->unit];
573 u_char cilen, citype, cichar, *next;
576 lcp_options no; /* options we've seen Naks for */
577 lcp_options try; /* options to request next time */
580 BZERO(&no, sizeof(no));
584 * Any Nak'd CIs must be in exactly the same order that we sent.
585 * Check packet length and CI length at each step.
586 * If we find any deviations, then this packet is bad.
588 #define NAKCIVOID(opt, neg, code) \
590 len >= CILEN_VOID && \
591 p[1] == CILEN_VOID && \
594 INCPTR(CILEN_VOID, p); \
598 #define NAKCICHAP(opt, neg, code) \
600 len >= CILEN_CHAP && \
601 p[1] == CILEN_CHAP && \
605 GETSHORT(cishort, p); \
606 GETCHAR(cichar, p); \
610 #define NAKCISHORT(opt, neg, code) \
612 len >= CILEN_SHORT && \
613 p[1] == CILEN_SHORT && \
615 len -= CILEN_SHORT; \
617 GETSHORT(cishort, p); \
621 #define NAKCILONG(opt, neg, code) \
623 len >= CILEN_LONG && \
624 p[1] == CILEN_LONG && \
628 GETLONG(cilong, p); \
632 #define NAKCILQR(opt, neg, code) \
634 len >= CILEN_LQR && \
635 p[1] == CILEN_LQR && \
639 GETSHORT(cishort, p); \
640 GETLONG(cilong, p); \
646 * We don't care if they want to send us smaller packets than
647 * we want. Therefore, accept any MRU less than what we asked for,
648 * but then ignore the new value when setting the MRU in the kernel.
649 * If they send us a bigger MRU than what we asked, accept it, up to
650 * the limit of the default MRU we'd get if we didn't negotiate.
652 NAKCISHORT(CI_MRU, neg_mru,
653 if (cishort <= wo->mru || cishort < DEFMRU)
657 * Add any characters they want to our (receive-side) asyncmap.
659 NAKCILONG(CI_ASYNCMAP, neg_asyncmap,
660 try.asyncmap = go->asyncmap | cilong;
663 * If they can't cope with our CHAP hash algorithm, we'll have
664 * to stop asking for CHAP. We haven't got any other algorithm.
666 NAKCICHAP(CI_AUTHTYPE, neg_chap,
670 * Peer shouldn't send Nak for UPAP, protocol compression or
671 * address/control compression requests; they should send
672 * a Reject instead. If they send a Nak, treat it as a Reject.
675 NAKCISHORT(CI_AUTHTYPE, neg_upap,
680 * If they can't cope with our link quality protocol, we'll have
681 * to stop asking for LQR. We haven't got any other protocol.
682 * If they Nak the reporting period, take their value XXX ?
684 NAKCILONG(CI_QUALITY, neg_lqr,
688 try.lqr_period = cilong;
691 * Check for a looped-back line.
693 NAKCILONG(CI_MAGICNUMBER, neg_magicnumber,
694 try.magicnumber = magic();
699 NAKCIVOID(CI_PCOMPRESSION, neg_pcompression,
700 try.neg_pcompression = 0;
702 NAKCIVOID(CI_ACCOMPRESSION, neg_accompression,
703 try.neg_accompression = 0;
707 * There may be remaining CIs, if the peer is requesting negotiation
708 * on an option that we didn't include in our request packet.
709 * If we see an option that we requested, or one we've already seen
710 * in this packet, then this packet is bad.
711 * If we wanted to respond by starting to negotiate on the requested
712 * option(s), we could, but we don't, because except for the
713 * authentication type and quality protocol, if we are not negotiating
714 * an option, it is because we were told not to.
715 * For the authentication type, the Nak from the peer means
716 * `let me authenticate myself with you' which is a bit pointless.
717 * For the quality protocol, the Nak means `ask me to send you quality
718 * reports', but if we didn't ask for them, we don't want them.
720 while (len > CILEN_VOID) {
723 if( (len -= cilen) < 0 )
725 next = p + cilen - 2;
729 if (go->neg_mru || no.neg_mru || cilen != CILEN_SHORT)
733 if (go->neg_asyncmap || no.neg_asyncmap || cilen != CILEN_LONG)
737 if (go->neg_chap || no.neg_chap || go->neg_upap || no.neg_upap)
741 if (go->neg_magicnumber || no.neg_magicnumber ||
745 case CI_PCOMPRESSION:
746 if (go->neg_pcompression || no.neg_pcompression
747 || cilen != CILEN_VOID)
750 case CI_ACCOMPRESSION:
751 if (go->neg_accompression || no.neg_accompression
752 || cilen != CILEN_VOID)
756 if (go->neg_lqr || no.neg_lqr || cilen != CILEN_LQR)
765 /* If there is still anything left, this packet is bad. */
770 * OK, the Nak is good. Now we can update state.
772 if (f->state != OPENED) {
774 if (looped_back && try.numloops % lcp_warnloops == 0)
775 LCPDEBUG((LOG_INFO, "The line appears to be looped back."));
781 LCPDEBUG((LOG_WARNING, "lcp_nakci: received bad Nak!"));
787 * lcp_rejci - Peer has Rejected some of our CIs.
788 * This should not modify any state if the Reject is bad
789 * or if LCP is in the OPENED state.
792 * 0 - Reject was bad.
793 * 1 - Reject was good.
801 lcp_options *go = &lcp_gotoptions[f->unit];
807 lcp_options try; /* options to request next time */
812 * Any Rejected CIs must be in exactly the same order that we sent.
813 * Check packet length and CI length at each step.
814 * If we find any deviations, then this packet is bad.
816 #define REJCIVOID(opt, neg) \
818 len >= CILEN_VOID && \
819 p[1] == CILEN_VOID && \
822 INCPTR(CILEN_VOID, p); \
824 LCPDEBUG((LOG_INFO, "lcp_rejci rejected void opt %d", opt)); \
826 #define REJCISHORT(opt, neg, val) \
828 len >= CILEN_SHORT && \
829 p[1] == CILEN_SHORT && \
831 len -= CILEN_SHORT; \
833 GETSHORT(cishort, p); \
834 /* Check rejected value. */ \
835 if (cishort != val) \
838 LCPDEBUG((LOG_INFO,"lcp_rejci rejected short opt %d", opt)); \
840 #define REJCICHAP(opt, neg, val, digest) \
842 len >= CILEN_CHAP && \
843 p[1] == CILEN_CHAP && \
847 GETSHORT(cishort, p); \
848 GETCHAR(cichar, p); \
849 /* Check rejected value. */ \
850 if (cishort != val || cichar != digest) \
853 LCPDEBUG((LOG_INFO,"lcp_rejci rejected chap opt %d", opt)); \
855 #define REJCILONG(opt, neg, val) \
857 len >= CILEN_LONG && \
858 p[1] == CILEN_LONG && \
862 GETLONG(cilong, p); \
863 /* Check rejected value. */ \
867 LCPDEBUG((LOG_INFO,"lcp_rejci rejected long opt %d", opt)); \
869 #define REJCILQR(opt, neg, val) \
871 len >= CILEN_LQR && \
872 p[1] == CILEN_LQR && \
876 GETSHORT(cishort, p); \
877 GETLONG(cilong, p); \
878 /* Check rejected value. */ \
879 if (cishort != LQR || cichar != val) \
882 LCPDEBUG((LOG_INFO,"lcp_rejci rejected LQR opt %d", opt)); \
885 REJCISHORT(CI_MRU, neg_mru, go->mru);
886 REJCILONG(CI_ASYNCMAP, neg_asyncmap, go->asyncmap);
887 REJCICHAP(CI_AUTHTYPE, neg_chap, CHAP, go->chap_mdtype);
889 REJCISHORT(CI_AUTHTYPE, neg_upap, UPAP);
891 REJCILQR(CI_QUALITY, neg_lqr, go->lqr_period);
892 REJCILONG(CI_MAGICNUMBER, neg_magicnumber, go->magicnumber);
893 REJCIVOID(CI_PCOMPRESSION, neg_pcompression);
894 REJCIVOID(CI_ACCOMPRESSION, neg_accompression);
897 * If there are any remaining CIs, then this packet is bad.
902 * Now we can update state.
904 if (f->state != OPENED)
909 LCPDEBUG((LOG_WARNING, "lcp_rejci: received bad Reject!"));
910 LCPDEBUG((LOG_WARNING, "lcp_rejci: plen %d len %d off %d",
911 plen, len, p - start));
917 * lcp_reqci - Check the peer's requested CIs and send appropriate response.
919 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
920 * appropriately. If reject_if_disagree is non-zero, doesn't return
921 * CONFNAK; returns CONFREJ if it can't return CONFACK.
924 lcp_reqci(f, inp, lenp, reject_if_disagree)
926 u_char *inp; /* Requested CIs */
927 int *lenp; /* Length of requested CIs */
928 int reject_if_disagree;
930 lcp_options *go = &lcp_gotoptions[f->unit];
931 lcp_options *ho = &lcp_hisoptions[f->unit];
932 lcp_options *ao = &lcp_allowoptions[f->unit];
933 u_char *cip, *next; /* Pointer to current and next CIs */
934 u_char cilen, citype, cichar;/* Parsed len, type, char value */
935 u_short cishort; /* Parsed short value */
936 u_long cilong; /* Parse long value */
937 int rc = CONFACK; /* Final packet return code */
938 int orc; /* Individual option return code */
939 u_char *p; /* Pointer to next char to parse */
940 u_char *ucp = inp; /* Pointer to current output char */
941 int l = *lenp; /* Length left */
944 * Reset all his options.
946 BZERO(ho, sizeof(*ho));
949 * Process all his options.
953 orc = CONFACK; /* Assume success */
954 cip = p = next; /* Remember begining of CI */
955 if (l < 2 || /* Not enough data for CI header or */
956 p[1] < 2 || /* CI length too small or */
957 p[1] > l) { /* CI length too big? */
958 LCPDEBUG((LOG_WARNING, "lcp_reqci: bad CI length!"));
959 orc = CONFREJ; /* Reject bad CI */
960 cilen = l; /* Reject till end of packet */
961 l = 0; /* Don't loop again */
964 GETCHAR(citype, p); /* Parse CI type */
965 GETCHAR(cilen, p); /* Parse CI length */
966 l -= cilen; /* Adjust remaining length */
967 next += cilen; /* Step to next CI */
969 switch (citype) { /* Check CI type */
971 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd MRU"));
972 if (!ao->neg_mru || /* Allow option? */
973 cilen != CILEN_SHORT) { /* Check CI length */
974 orc = CONFREJ; /* Reject CI */
977 GETSHORT(cishort, p); /* Parse MRU */
978 LCPDEBUG((LOG_INFO, "(%d)", cishort));
981 * He must be able to receive at least our minimum.
982 * No need to check a maximum. If he sends a large number,
983 * we'll just ignore it.
985 if (cishort < MINMRU) {
986 orc = CONFNAK; /* Nak CI */
987 if( !reject_if_disagree ){
988 DECPTR(sizeof (short), p); /* Backup */
989 PUTSHORT(MINMRU, p); /* Give him a hint */
993 ho->neg_mru = 1; /* Remember he sent MRU */
994 ho->mru = cishort; /* And remember value */
998 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd ASYNCMAP"));
999 if (!ao->neg_asyncmap ||
1000 cilen != CILEN_LONG) {
1005 LCPDEBUG((LOG_INFO, "(%lx)", cilong));
1008 * Asyncmap must have set at least the bits
1009 * which are set in lcp_allowoptions[unit].asyncmap.
1011 if ((ao->asyncmap & ~cilong) != 0) {
1013 if( !reject_if_disagree ){
1014 DECPTR(sizeof (long), p);
1015 PUTLONG(ao->asyncmap | cilong, p);
1019 ho->neg_asyncmap = 1;
1020 ho->asyncmap = cilong;
1024 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd AUTHTYPE"));
1025 if (cilen < CILEN_SHORT ||
1026 !(ao->neg_upap || ao->neg_chap)) {
1030 GETSHORT(cishort, p);
1031 LCPDEBUG((LOG_INFO, "(%x)", cishort));
1034 * Authtype must be UPAP or CHAP.
1036 * Note: if both ao->neg_upap and ao->neg_chap are set,
1037 * and the peer sends a Configure-Request with two
1038 * authenticate-protocol requests, one for CHAP and one
1039 * for UPAP, then we will reject the second request.
1040 * Whether we end up doing CHAP or UPAP depends then on
1041 * the ordering of the CIs in the peer's Configure-Request.
1044 if (cishort == UPAP) {
1045 if (!ao->neg_upap || /* we don't want to do PAP */
1046 ho->neg_chap || /* or we've already accepted CHAP */
1047 cilen != CILEN_SHORT) {
1048 LCPDEBUG((LOG_WARNING,
1049 "lcp_reqci: rcvd AUTHTYPE PAP, rejecting..."));
1056 if (cishort == CHAP) {
1057 if (!ao->neg_chap || /* we don't want to do CHAP */
1058 ho->neg_upap || /* or we've already accepted UPAP */
1059 cilen != CILEN_CHAP) {
1061 "lcp_reqci: rcvd AUTHTYPE CHAP, rejecting..."));
1065 GETCHAR(cichar, p); /* get digest type*/
1066 if (cichar != ao->chap_mdtype) {
1068 if( !reject_if_disagree ){
1069 DECPTR(sizeof (u_char), p);
1070 PUTCHAR(ao->chap_mdtype, p);
1074 ho->chap_mdtype = cichar; /* save md type */
1080 * We don't recognize the protocol they're asking for.
1087 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd QUALITY"));
1089 cilen != CILEN_LQR) {
1094 GETSHORT(cishort, p);
1096 LCPDEBUG((LOG_INFO, "(%x %lx)", cishort, cilong));
1097 if (cishort != LQR) {
1103 * Check the reporting period.
1104 * XXX When should we Nak this, and what with?
1108 case CI_MAGICNUMBER:
1109 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd MAGICNUMBER"));
1110 if (!(ao->neg_magicnumber || go->neg_magicnumber) ||
1111 cilen != CILEN_LONG) {
1116 LCPDEBUG((LOG_INFO, "(%lx)", cilong));
1119 * He must have a different magic number.
1121 if (go->neg_magicnumber &&
1122 cilong == go->magicnumber) {
1124 DECPTR(sizeof (long), p);
1125 cilong = magic(); /* Don't put magic() inside macro! */
1129 ho->neg_magicnumber = 1;
1130 ho->magicnumber = cilong;
1134 case CI_PCOMPRESSION:
1135 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd PCOMPRESSION"));
1136 if (!ao->neg_pcompression ||
1137 cilen != CILEN_VOID) {
1141 ho->neg_pcompression = 1;
1144 case CI_ACCOMPRESSION:
1145 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd ACCOMPRESSION"));
1146 if (!ao->neg_accompression ||
1147 cilen != CILEN_VOID) {
1151 ho->neg_accompression = 1;
1155 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd unknown option %d",
1162 LCPDEBUG((LOG_INFO, " (%s)", CODENAME(orc)));
1163 if (orc == CONFACK && /* Good CI */
1164 rc != CONFACK) /* but prior CI wasnt? */
1165 continue; /* Don't send this one */
1167 if (orc == CONFNAK) { /* Nak this CI? */
1168 if (reject_if_disagree) /* Getting fed up with sending NAKs? */
1169 orc = CONFREJ; /* Get tough if so */
1171 if (rc == CONFREJ) /* Rejecting prior CI? */
1172 continue; /* Don't send this one */
1173 if (rc == CONFACK) { /* Ack'd all prior CIs? */
1174 rc = CONFNAK; /* Not anymore... */
1175 ucp = inp; /* Backup */
1179 if (orc == CONFREJ && /* Reject this CI */
1180 rc != CONFREJ) { /* but no prior ones? */
1182 ucp = inp; /* Backup */
1184 if (ucp != cip) /* Need to move CI? */
1185 BCOPY(cip, ucp, cilen); /* Move it */
1186 INCPTR(cilen, ucp); /* Update output pointer */
1190 * If we wanted to send additional NAKs (for unsent CIs), the
1191 * code would go here. This must be done with care since it might
1192 * require a longer packet than we received. At present there
1193 * are no cases where we want to ask the peer to negotiate an option.
1196 *lenp = ucp - inp; /* Compute output length */
1197 LCPDEBUG((LOG_INFO, "lcp_reqci: returning CONF%s.", CODENAME(rc)));
1198 return (rc); /* Return final code */
1203 * lcp_up - LCP has come UP.
1205 * Start UPAP, IPCP, etc.
1211 lcp_options *wo = &lcp_wantoptions[f->unit];
1212 lcp_options *ho = &lcp_hisoptions[f->unit];
1213 lcp_options *go = &lcp_gotoptions[f->unit];
1214 lcp_options *ao = &lcp_allowoptions[f->unit];
1217 * Set our MTU to the smaller of the MTU we wanted and
1218 * the MRU our peer wanted. If we negotiated an MRU,
1219 * set our MRU to the larger of value we wanted and
1220 * the value we got in the negotiation.
1222 ppp_send_config(f->unit, (ho->neg_mru? MIN(ao->mru, ho->mru): MTU),
1223 (ho->neg_asyncmap? ho->asyncmap: 0xffffffff),
1224 ho->neg_pcompression, ho->neg_accompression);
1225 ppp_recv_config(f->unit, (go->neg_mru? MAX(wo->mru, go->mru): MTU),
1226 (go->neg_asyncmap? go->asyncmap: 0xffffffff),
1227 go->neg_pcompression, go->neg_accompression);
1230 peer_mru[f->unit] = ho->mru;
1232 ChapLowerUp(f->unit); /* Enable CHAP */
1233 upap_lowerup(f->unit); /* Enable UPAP */
1234 ipcp_lowerup(f->unit); /* Enable IPCP */
1236 link_established(f->unit);
1241 * lcp_down - LCP has gone DOWN.
1243 * Alert other protocols.
1249 ipcp_lowerdown(f->unit);
1250 ChapLowerDown(f->unit);
1251 upap_lowerdown(f->unit);
1254 ppp_send_config(f->unit, MTU, 0xffffffff, 0, 0);
1255 ppp_recv_config(f->unit, MTU, 0, 0, 0);
1256 peer_mru[f->unit] = MTU;
1257 syslog(LOG_NOTICE, "Connection terminated.");
1262 * lcp_starting - LCP needs the lower layer up.
1268 link_required(f->unit);
1273 * lcp_finished - LCP has finished with the lower layer.
1279 link_terminated(f->unit);