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.4 1994/05/09 04:32:41 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 *f = &lcp_fsm[unit];
188 if (f->state == STOPPED && f->flags & (OPT_PASSIVE|OPT_SILENT)) {
190 * This action is not strictly according to the FSM in RFC1548,
191 * but it does mean that the program terminates if you do a
192 * lcp_close(0) in passive/silent mode when a connection hasn't
199 fsm_close(&lcp_fsm[unit]);
204 * lcp_lowerup - The lower layer is up.
211 ppp_set_xaccm(unit, xmit_accm[unit]);
212 ppp_send_config(unit, MTU, 0xffffffff, 0, 0);
213 ppp_recv_config(unit, MTU, 0, 0, 0);
214 peer_mru[unit] = MTU;
215 lcp_allowoptions[unit].asyncmap = xmit_accm[unit][0];
217 fsm_lowerup(&lcp_fsm[unit]);
222 * lcp_lowerdown - The lower layer is down.
228 fsm_lowerdown(&lcp_fsm[unit]);
233 * lcp_input - Input LCP packet.
236 lcp_input(unit, p, len)
241 fsm_input(&lcp_fsm[unit], p, len);
246 * lcp_extcode - Handle a LCP-specific code.
249 lcp_extcode(f, code, id, inp, len)
257 lcp_rprotrej(f, inp, len);
261 if( f->state != OPENED )
263 LCPDEBUG((LOG_INFO, "lcp: Echo-Request, Rcvd id %d", id));
264 fsm_sdata(f, ECHOREP, id, inp, len);
279 * lcp_rprotrej - Receive an Protocol-Reject.
281 * Figure out which protocol is rejected and inform it.
284 lcp_rprotrej(f, inp, len)
291 LCPDEBUG((LOG_INFO, "lcp_rprotrej."));
293 if (len < sizeof (u_short)) {
295 "lcp_rprotrej: Rcvd short Protocol-Reject packet!"));
302 "lcp_rprotrej: Rcvd Protocol-Reject packet for %x!",
306 * Protocol-Reject packets received in any state other than the LCP
307 * OPENED state SHOULD be silently discarded.
309 if( f->state != OPENED ){
310 LCPDEBUG((LOG_INFO, "Protocol-Reject discarded: LCP in state %d",
315 DEMUXPROTREJ(f->unit, prot); /* Inform protocol */
320 * lcp_protrej - A Protocol-Reject was received.
330 LCPDEBUG((LOG_WARNING,
331 "lcp_protrej: Received Protocol-Reject for LCP!"));
332 fsm_protreject(&lcp_fsm[unit]);
337 * lcp_sprotrej - Send a Protocol-Reject for some protocol.
340 lcp_sprotrej(unit, p, len)
346 * Send back the protocol and the information field of the
347 * rejected packet. We only get here if LCP is in the OPENED state.
352 fsm_sdata(&lcp_fsm[unit], PROTREJ, ++lcp_fsm[unit].id,
358 * lcp_resetci - Reset our CI.
364 lcp_wantoptions[f->unit].magicnumber = magic();
365 lcp_wantoptions[f->unit].numloops = 0;
366 lcp_gotoptions[f->unit] = lcp_wantoptions[f->unit];
367 peer_mru[f->unit] = MTU;
372 * lcp_cilen - Return length of our CI.
378 lcp_options *go = &lcp_gotoptions[f->unit];
380 #define LENCIVOID(neg) (neg ? CILEN_VOID : 0)
381 #define LENCICHAP(neg) (neg ? CILEN_CHAP : 0)
382 #define LENCISHORT(neg) (neg ? CILEN_SHORT : 0)
383 #define LENCILONG(neg) (neg ? CILEN_LONG : 0)
384 #define LENCILQR(neg) (neg ? CILEN_LQR: 0)
386 * NB: we only ask for one of CHAP and UPAP, even if we will
389 return (LENCISHORT(go->neg_mru) +
390 LENCILONG(go->neg_asyncmap) +
391 LENCICHAP(go->neg_chap) +
392 LENCISHORT(!go->neg_chap && go->neg_upap) +
393 LENCILQR(go->neg_lqr) +
394 LENCILONG(go->neg_magicnumber) +
395 LENCIVOID(go->neg_pcompression) +
396 LENCIVOID(go->neg_accompression));
401 * lcp_addci - Add our desired CIs to a packet.
404 lcp_addci(f, ucp, lenp)
409 lcp_options *go = &lcp_gotoptions[f->unit];
410 u_char *start_ucp = ucp;
412 #define ADDCIVOID(opt, neg) \
415 PUTCHAR(CILEN_VOID, ucp); \
417 #define ADDCISHORT(opt, neg, val) \
420 PUTCHAR(CILEN_SHORT, ucp); \
421 PUTSHORT(val, ucp); \
423 #define ADDCICHAP(opt, neg, val, digest) \
426 PUTCHAR(CILEN_CHAP, ucp); \
427 PUTSHORT(val, ucp); \
428 PUTCHAR(digest, ucp); \
430 #define ADDCILONG(opt, neg, val) \
433 PUTCHAR(CILEN_LONG, ucp); \
436 #define ADDCILQR(opt, neg, val) \
439 PUTCHAR(CILEN_LQR, ucp); \
440 PUTSHORT(LQR, ucp); \
444 ADDCISHORT(CI_MRU, go->neg_mru, go->mru);
445 ADDCILONG(CI_ASYNCMAP, go->neg_asyncmap, go->asyncmap);
446 ADDCICHAP(CI_AUTHTYPE, go->neg_chap, CHAP, go->chap_mdtype);
447 ADDCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, UPAP);
448 ADDCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
449 ADDCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
450 ADDCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
451 ADDCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
453 if (ucp - start_ucp != *lenp) {
454 /* this should never happen, because peer_mtu should be 1500 */
455 syslog(LOG_ERR, "Bug in lcp_addci: wrong length");
461 * lcp_ackci - Ack our CIs.
462 * This should not modify any state if the Ack is bad.
474 lcp_options *go = &lcp_gotoptions[f->unit];
475 u_char cilen, citype, cichar;
480 * CIs must be in exactly the same order that we sent.
481 * Check packet length and CI length at each step.
482 * If we find any deviations, then this packet is bad.
484 #define ACKCIVOID(opt, neg) \
486 if ((len -= CILEN_VOID) < 0) \
488 GETCHAR(citype, p); \
490 if (cilen != CILEN_VOID || \
494 #define ACKCISHORT(opt, neg, val) \
496 if ((len -= CILEN_SHORT) < 0) \
498 GETCHAR(citype, p); \
500 if (cilen != CILEN_SHORT || \
503 GETSHORT(cishort, p); \
504 if (cishort != val) \
507 #define ACKCICHAP(opt, neg, val, digest) \
509 if ((len -= CILEN_CHAP) < 0) \
511 GETCHAR(citype, p); \
513 if (cilen != CILEN_CHAP || \
516 GETSHORT(cishort, p); \
517 if (cishort != val) \
519 GETCHAR(cichar, p); \
520 if (cichar != digest) \
523 #define ACKCILONG(opt, neg, val) \
525 if ((len -= CILEN_LONG) < 0) \
527 GETCHAR(citype, p); \
529 if (cilen != CILEN_LONG || \
532 GETLONG(cilong, p); \
536 #define ACKCILQR(opt, neg, val) \
538 if ((len -= CILEN_LQR) < 0) \
540 GETCHAR(citype, p); \
542 if (cilen != CILEN_LQR || \
545 GETSHORT(cishort, p); \
546 if (cishort != LQR) \
548 GETLONG(cilong, p); \
553 ACKCISHORT(CI_MRU, go->neg_mru, go->mru);
554 ACKCILONG(CI_ASYNCMAP, go->neg_asyncmap, go->asyncmap);
555 ACKCICHAP(CI_AUTHTYPE, go->neg_chap, CHAP, go->chap_mdtype);
556 ACKCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, UPAP);
557 ACKCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
558 ACKCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
559 ACKCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
560 ACKCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
563 * If there are any remaining CIs, then this packet is bad.
569 LCPDEBUG((LOG_WARNING, "lcp_acki: received bad Ack!"));
575 * lcp_nakci - Peer has sent a NAK for some of our CIs.
576 * This should not modify any state if the Nak is bad
577 * or if LCP is in the OPENED state.
589 lcp_options *go = &lcp_gotoptions[f->unit];
590 lcp_options *wo = &lcp_wantoptions[f->unit];
591 u_char cilen, citype, cichar, *next;
594 lcp_options no; /* options we've seen Naks for */
595 lcp_options try; /* options to request next time */
598 BZERO(&no, sizeof(no));
602 * Any Nak'd CIs must be in exactly the same order that we sent.
603 * Check packet length and CI length at each step.
604 * If we find any deviations, then this packet is bad.
606 #define NAKCIVOID(opt, neg, code) \
608 len >= CILEN_VOID && \
609 p[1] == CILEN_VOID && \
612 INCPTR(CILEN_VOID, p); \
616 #define NAKCICHAP(opt, neg, code) \
618 len >= CILEN_CHAP && \
619 p[1] == CILEN_CHAP && \
623 GETSHORT(cishort, p); \
624 GETCHAR(cichar, p); \
628 #define NAKCISHORT(opt, neg, code) \
630 len >= CILEN_SHORT && \
631 p[1] == CILEN_SHORT && \
633 len -= CILEN_SHORT; \
635 GETSHORT(cishort, p); \
639 #define NAKCILONG(opt, neg, code) \
641 len >= CILEN_LONG && \
642 p[1] == CILEN_LONG && \
646 GETLONG(cilong, p); \
650 #define NAKCILQR(opt, neg, code) \
652 len >= CILEN_LQR && \
653 p[1] == CILEN_LQR && \
657 GETSHORT(cishort, p); \
658 GETLONG(cilong, p); \
664 * We don't care if they want to send us smaller packets than
665 * we want. Therefore, accept any MRU less than what we asked for,
666 * but then ignore the new value when setting the MRU in the kernel.
667 * If they send us a bigger MRU than what we asked, accept it, up to
668 * the limit of the default MRU we'd get if we didn't negotiate.
670 NAKCISHORT(CI_MRU, neg_mru,
671 if (cishort <= wo->mru || cishort < DEFMRU)
675 * Add any characters they want to our (receive-side) asyncmap.
677 NAKCILONG(CI_ASYNCMAP, neg_asyncmap,
678 try.asyncmap = go->asyncmap | cilong;
681 * If they can't cope with our CHAP hash algorithm, we'll have
682 * to stop asking for CHAP. We haven't got any other algorithm.
684 NAKCICHAP(CI_AUTHTYPE, neg_chap,
688 * Peer shouldn't send Nak for UPAP, protocol compression or
689 * address/control compression requests; they should send
690 * a Reject instead. If they send a Nak, treat it as a Reject.
693 NAKCISHORT(CI_AUTHTYPE, neg_upap,
698 * If they can't cope with our link quality protocol, we'll have
699 * to stop asking for LQR. We haven't got any other protocol.
700 * If they Nak the reporting period, take their value XXX ?
702 NAKCILONG(CI_QUALITY, neg_lqr,
706 try.lqr_period = cilong;
709 * Check for a looped-back line.
711 NAKCILONG(CI_MAGICNUMBER, neg_magicnumber,
712 try.magicnumber = magic();
717 NAKCIVOID(CI_PCOMPRESSION, neg_pcompression,
718 try.neg_pcompression = 0;
720 NAKCIVOID(CI_ACCOMPRESSION, neg_accompression,
721 try.neg_accompression = 0;
725 * There may be remaining CIs, if the peer is requesting negotiation
726 * on an option that we didn't include in our request packet.
727 * If we see an option that we requested, or one we've already seen
728 * in this packet, then this packet is bad.
729 * If we wanted to respond by starting to negotiate on the requested
730 * option(s), we could, but we don't, because except for the
731 * authentication type and quality protocol, if we are not negotiating
732 * an option, it is because we were told not to.
733 * For the authentication type, the Nak from the peer means
734 * `let me authenticate myself with you' which is a bit pointless.
735 * For the quality protocol, the Nak means `ask me to send you quality
736 * reports', but if we didn't ask for them, we don't want them.
738 while (len > CILEN_VOID) {
741 if( (len -= cilen) < 0 )
743 next = p + cilen - 2;
747 if (go->neg_mru || no.neg_mru || cilen != CILEN_SHORT)
751 if (go->neg_asyncmap || no.neg_asyncmap || cilen != CILEN_LONG)
755 if (go->neg_chap || no.neg_chap || go->neg_upap || no.neg_upap)
759 if (go->neg_magicnumber || no.neg_magicnumber ||
763 case CI_PCOMPRESSION:
764 if (go->neg_pcompression || no.neg_pcompression
765 || cilen != CILEN_VOID)
768 case CI_ACCOMPRESSION:
769 if (go->neg_accompression || no.neg_accompression
770 || cilen != CILEN_VOID)
774 if (go->neg_lqr || no.neg_lqr || cilen != CILEN_LQR)
783 /* If there is still anything left, this packet is bad. */
788 * OK, the Nak is good. Now we can update state.
790 if (f->state != OPENED) {
792 if (looped_back && try.numloops % lcp_warnloops == 0)
793 LCPDEBUG((LOG_INFO, "The line appears to be looped back."));
799 LCPDEBUG((LOG_WARNING, "lcp_nakci: received bad Nak!"));
805 * lcp_rejci - Peer has Rejected some of our CIs.
806 * This should not modify any state if the Reject is bad
807 * or if LCP is in the OPENED state.
810 * 0 - Reject was bad.
811 * 1 - Reject was good.
819 lcp_options *go = &lcp_gotoptions[f->unit];
825 lcp_options try; /* options to request next time */
830 * Any Rejected CIs must be in exactly the same order that we sent.
831 * Check packet length and CI length at each step.
832 * If we find any deviations, then this packet is bad.
834 #define REJCIVOID(opt, neg) \
836 len >= CILEN_VOID && \
837 p[1] == CILEN_VOID && \
840 INCPTR(CILEN_VOID, p); \
842 LCPDEBUG((LOG_INFO, "lcp_rejci rejected void opt %d", opt)); \
844 #define REJCISHORT(opt, neg, val) \
846 len >= CILEN_SHORT && \
847 p[1] == CILEN_SHORT && \
849 len -= CILEN_SHORT; \
851 GETSHORT(cishort, p); \
852 /* Check rejected value. */ \
853 if (cishort != val) \
856 LCPDEBUG((LOG_INFO,"lcp_rejci rejected short opt %d", opt)); \
858 #define REJCICHAP(opt, neg, val, digest) \
860 len >= CILEN_CHAP && \
861 p[1] == CILEN_CHAP && \
865 GETSHORT(cishort, p); \
866 GETCHAR(cichar, p); \
867 /* Check rejected value. */ \
868 if (cishort != val || cichar != digest) \
871 LCPDEBUG((LOG_INFO,"lcp_rejci rejected chap opt %d", opt)); \
873 #define REJCILONG(opt, neg, val) \
875 len >= CILEN_LONG && \
876 p[1] == CILEN_LONG && \
880 GETLONG(cilong, p); \
881 /* Check rejected value. */ \
885 LCPDEBUG((LOG_INFO,"lcp_rejci rejected long opt %d", opt)); \
887 #define REJCILQR(opt, neg, val) \
889 len >= CILEN_LQR && \
890 p[1] == CILEN_LQR && \
894 GETSHORT(cishort, p); \
895 GETLONG(cilong, p); \
896 /* Check rejected value. */ \
897 if (cishort != LQR || cichar != val) \
900 LCPDEBUG((LOG_INFO,"lcp_rejci rejected LQR opt %d", opt)); \
903 REJCISHORT(CI_MRU, neg_mru, go->mru);
904 REJCILONG(CI_ASYNCMAP, neg_asyncmap, go->asyncmap);
905 REJCICHAP(CI_AUTHTYPE, neg_chap, CHAP, go->chap_mdtype);
907 REJCISHORT(CI_AUTHTYPE, neg_upap, UPAP);
909 REJCILQR(CI_QUALITY, neg_lqr, go->lqr_period);
910 REJCILONG(CI_MAGICNUMBER, neg_magicnumber, go->magicnumber);
911 REJCIVOID(CI_PCOMPRESSION, neg_pcompression);
912 REJCIVOID(CI_ACCOMPRESSION, neg_accompression);
915 * If there are any remaining CIs, then this packet is bad.
920 * Now we can update state.
922 if (f->state != OPENED)
927 LCPDEBUG((LOG_WARNING, "lcp_rejci: received bad Reject!"));
928 LCPDEBUG((LOG_WARNING, "lcp_rejci: plen %d len %d off %d",
929 plen, len, p - start));
935 * lcp_reqci - Check the peer's requested CIs and send appropriate response.
937 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
938 * appropriately. If reject_if_disagree is non-zero, doesn't return
939 * CONFNAK; returns CONFREJ if it can't return CONFACK.
942 lcp_reqci(f, inp, lenp, reject_if_disagree)
944 u_char *inp; /* Requested CIs */
945 int *lenp; /* Length of requested CIs */
946 int reject_if_disagree;
948 lcp_options *go = &lcp_gotoptions[f->unit];
949 lcp_options *ho = &lcp_hisoptions[f->unit];
950 lcp_options *ao = &lcp_allowoptions[f->unit];
951 u_char *cip, *next; /* Pointer to current and next CIs */
952 u_char cilen, citype, cichar;/* Parsed len, type, char value */
953 u_short cishort; /* Parsed short value */
954 u_long cilong; /* Parse long value */
955 int rc = CONFACK; /* Final packet return code */
956 int orc; /* Individual option return code */
957 u_char *p; /* Pointer to next char to parse */
958 u_char *ucp = inp; /* Pointer to current output char */
959 int l = *lenp; /* Length left */
962 * Reset all his options.
964 BZERO(ho, sizeof(*ho));
967 * Process all his options.
971 orc = CONFACK; /* Assume success */
972 cip = p = next; /* Remember begining of CI */
973 if (l < 2 || /* Not enough data for CI header or */
974 p[1] < 2 || /* CI length too small or */
975 p[1] > l) { /* CI length too big? */
976 LCPDEBUG((LOG_WARNING, "lcp_reqci: bad CI length!"));
977 orc = CONFREJ; /* Reject bad CI */
978 cilen = l; /* Reject till end of packet */
979 l = 0; /* Don't loop again */
982 GETCHAR(citype, p); /* Parse CI type */
983 GETCHAR(cilen, p); /* Parse CI length */
984 l -= cilen; /* Adjust remaining length */
985 next += cilen; /* Step to next CI */
987 switch (citype) { /* Check CI type */
989 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd MRU"));
990 if (!ao->neg_mru || /* Allow option? */
991 cilen != CILEN_SHORT) { /* Check CI length */
992 orc = CONFREJ; /* Reject CI */
995 GETSHORT(cishort, p); /* Parse MRU */
996 LCPDEBUG((LOG_INFO, "(%d)", cishort));
999 * He must be able to receive at least our minimum.
1000 * No need to check a maximum. If he sends a large number,
1001 * we'll just ignore it.
1003 if (cishort < MINMRU) {
1004 orc = CONFNAK; /* Nak CI */
1005 if( !reject_if_disagree ){
1006 DECPTR(sizeof (short), p); /* Backup */
1007 PUTSHORT(MINMRU, p); /* Give him a hint */
1011 ho->neg_mru = 1; /* Remember he sent MRU */
1012 ho->mru = cishort; /* And remember value */
1016 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd ASYNCMAP"));
1017 if (!ao->neg_asyncmap ||
1018 cilen != CILEN_LONG) {
1023 LCPDEBUG((LOG_INFO, "(%lx)", cilong));
1026 * Asyncmap must have set at least the bits
1027 * which are set in lcp_allowoptions[unit].asyncmap.
1029 if ((ao->asyncmap & ~cilong) != 0) {
1031 if( !reject_if_disagree ){
1032 DECPTR(sizeof (long), p);
1033 PUTLONG(ao->asyncmap | cilong, p);
1037 ho->neg_asyncmap = 1;
1038 ho->asyncmap = cilong;
1042 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd AUTHTYPE"));
1043 if (cilen < CILEN_SHORT ||
1044 !(ao->neg_upap || ao->neg_chap)) {
1048 GETSHORT(cishort, p);
1049 LCPDEBUG((LOG_INFO, "(%x)", cishort));
1052 * Authtype must be UPAP or CHAP.
1054 * Note: if both ao->neg_upap and ao->neg_chap are set,
1055 * and the peer sends a Configure-Request with two
1056 * authenticate-protocol requests, one for CHAP and one
1057 * for UPAP, then we will reject the second request.
1058 * Whether we end up doing CHAP or UPAP depends then on
1059 * the ordering of the CIs in the peer's Configure-Request.
1062 if (cishort == UPAP) {
1063 if (!ao->neg_upap || /* we don't want to do PAP */
1064 ho->neg_chap || /* or we've already accepted CHAP */
1065 cilen != CILEN_SHORT) {
1066 LCPDEBUG((LOG_WARNING,
1067 "lcp_reqci: rcvd AUTHTYPE PAP, rejecting..."));
1074 if (cishort == CHAP) {
1075 if (!ao->neg_chap || /* we don't want to do CHAP */
1076 ho->neg_upap || /* or we've already accepted UPAP */
1077 cilen != CILEN_CHAP) {
1079 "lcp_reqci: rcvd AUTHTYPE CHAP, rejecting..."));
1083 GETCHAR(cichar, p); /* get digest type*/
1084 if (cichar != ao->chap_mdtype) {
1086 if( !reject_if_disagree ){
1087 DECPTR(sizeof (u_char), p);
1088 PUTCHAR(ao->chap_mdtype, p);
1092 ho->chap_mdtype = cichar; /* save md type */
1098 * We don't recognize the protocol they're asking for.
1105 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd QUALITY"));
1107 cilen != CILEN_LQR) {
1112 GETSHORT(cishort, p);
1114 LCPDEBUG((LOG_INFO, "(%x %lx)", cishort, cilong));
1115 if (cishort != LQR) {
1121 * Check the reporting period.
1122 * XXX When should we Nak this, and what with?
1126 case CI_MAGICNUMBER:
1127 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd MAGICNUMBER"));
1128 if (!(ao->neg_magicnumber || go->neg_magicnumber) ||
1129 cilen != CILEN_LONG) {
1134 LCPDEBUG((LOG_INFO, "(%lx)", cilong));
1137 * He must have a different magic number.
1139 if (go->neg_magicnumber &&
1140 cilong == go->magicnumber) {
1142 DECPTR(sizeof (long), p);
1143 cilong = magic(); /* Don't put magic() inside macro! */
1147 ho->neg_magicnumber = 1;
1148 ho->magicnumber = cilong;
1152 case CI_PCOMPRESSION:
1153 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd PCOMPRESSION"));
1154 if (!ao->neg_pcompression ||
1155 cilen != CILEN_VOID) {
1159 ho->neg_pcompression = 1;
1162 case CI_ACCOMPRESSION:
1163 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd ACCOMPRESSION"));
1164 if (!ao->neg_accompression ||
1165 cilen != CILEN_VOID) {
1169 ho->neg_accompression = 1;
1173 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd unknown option %d",
1180 LCPDEBUG((LOG_INFO, " (%s)", CODENAME(orc)));
1181 if (orc == CONFACK && /* Good CI */
1182 rc != CONFACK) /* but prior CI wasnt? */
1183 continue; /* Don't send this one */
1185 if (orc == CONFNAK) { /* Nak this CI? */
1186 if (reject_if_disagree) /* Getting fed up with sending NAKs? */
1187 orc = CONFREJ; /* Get tough if so */
1189 if (rc == CONFREJ) /* Rejecting prior CI? */
1190 continue; /* Don't send this one */
1191 if (rc == CONFACK) { /* Ack'd all prior CIs? */
1192 rc = CONFNAK; /* Not anymore... */
1193 ucp = inp; /* Backup */
1197 if (orc == CONFREJ && /* Reject this CI */
1198 rc != CONFREJ) { /* but no prior ones? */
1200 ucp = inp; /* Backup */
1202 if (ucp != cip) /* Need to move CI? */
1203 BCOPY(cip, ucp, cilen); /* Move it */
1204 INCPTR(cilen, ucp); /* Update output pointer */
1208 * If we wanted to send additional NAKs (for unsent CIs), the
1209 * code would go here. This must be done with care since it might
1210 * require a longer packet than we received. At present there
1211 * are no cases where we want to ask the peer to negotiate an option.
1214 *lenp = ucp - inp; /* Compute output length */
1215 LCPDEBUG((LOG_INFO, "lcp_reqci: returning CONF%s.", CODENAME(rc)));
1216 return (rc); /* Return final code */
1221 * lcp_up - LCP has come UP.
1223 * Start UPAP, IPCP, etc.
1229 lcp_options *wo = &lcp_wantoptions[f->unit];
1230 lcp_options *ho = &lcp_hisoptions[f->unit];
1231 lcp_options *go = &lcp_gotoptions[f->unit];
1232 lcp_options *ao = &lcp_allowoptions[f->unit];
1235 * Set our MTU to the smaller of the MTU we wanted and
1236 * the MRU our peer wanted. If we negotiated an MRU,
1237 * set our MRU to the larger of value we wanted and
1238 * the value we got in the negotiation.
1240 ppp_send_config(f->unit, MIN(ao->mru, (ho->neg_mru? ho->mru: MTU)),
1241 (ho->neg_asyncmap? ho->asyncmap: 0xffffffff),
1242 ho->neg_pcompression, ho->neg_accompression);
1243 ppp_recv_config(f->unit, (go->neg_mru? MAX(wo->mru, go->mru): MTU),
1244 (go->neg_asyncmap? go->asyncmap: 0xffffffff),
1245 go->neg_pcompression, go->neg_accompression);
1248 peer_mru[f->unit] = ho->mru;
1250 ChapLowerUp(f->unit); /* Enable CHAP */
1251 upap_lowerup(f->unit); /* Enable UPAP */
1252 ipcp_lowerup(f->unit); /* Enable IPCP */
1254 link_established(f->unit);
1259 * lcp_down - LCP has gone DOWN.
1261 * Alert other protocols.
1267 ipcp_lowerdown(f->unit);
1268 ChapLowerDown(f->unit);
1269 upap_lowerdown(f->unit);
1272 ppp_send_config(f->unit, MTU, 0xffffffff, 0, 0);
1273 ppp_recv_config(f->unit, MTU, 0, 0, 0);
1274 peer_mru[f->unit] = MTU;
1281 * lcp_starting - LCP needs the lower layer up.
1287 link_required(f->unit);
1292 * lcp_finished - LCP has finished with the lower layer.
1298 link_terminated(f->unit);
1303 * lcp_printpkt - print the contents of an LCP packet.
1305 char *lcp_codenames[] = {
1306 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1307 "TermReq", "TermAck", "CodeRej", "ProtRej",
1308 "EchoReq", "EchoRep", "DiscReq"
1312 lcp_printpkt(p, plen, printer, arg)
1315 void (*printer) __ARGS((void *, char *, ...));
1318 int code, id, len, olen;
1319 u_char *pstart, *optend;
1323 if (plen < HEADERLEN)
1329 if (len < HEADERLEN || len > plen)
1332 if (code >= 1 && code <= sizeof(lcp_codenames) / sizeof(char *))
1333 printer(arg, " %s", lcp_codenames[code-1]);
1335 printer(arg, " code=0x%x", code);
1336 printer(arg, " id=0x%x", id);
1343 /* print option list */
1348 if (olen < 2 || olen > len) {
1356 if (olen == CILEN_SHORT) {
1358 GETSHORT(cishort, p);
1359 printer(arg, "mru %d", cishort);
1363 if (olen == CILEN_LONG) {
1366 printer(arg, "asyncmap 0x%x", cilong);
1370 if (olen >= CILEN_SHORT) {
1372 printer(arg, "auth ");
1373 GETSHORT(cishort, p);
1376 printer(arg, "upap");
1379 printer(arg, "chap");
1382 printer(arg, "0x%x", cishort);
1387 if (olen >= CILEN_SHORT) {
1389 printer(arg, "quality ");
1390 GETSHORT(cishort, p);
1393 printer(arg, "lqr");
1396 printer(arg, "0x%x", cishort);
1400 case CI_MAGICNUMBER:
1401 if (olen == CILEN_LONG) {
1404 printer(arg, "magic 0x%x", cilong);
1407 case CI_PCOMPRESSION:
1408 if (olen == CILEN_VOID) {
1410 printer(arg, "pcomp");
1413 case CI_ACCOMPRESSION:
1414 if (olen == CILEN_VOID) {
1416 printer(arg, "accomp");
1420 while (p < optend) {
1422 printer(arg, " %.2x", code);
1429 /* print the rest of the bytes in the packet */
1430 for (; len > 0; --len) {
1432 printer(arg, " %.2x", code);