1 /*****************************************************************************
\r
2 * lcp.c - Network Link Control Protocol program file.
\r
4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
\r
5 * portions Copyright (c) 1997 by Global Election Systems Inc.
\r
7 * The authors hereby grant permission to use, copy, modify, distribute,
\r
8 * and license this software and its documentation for any purpose, provided
\r
9 * that existing copyright notices are retained in all copies and that this
\r
10 * notice and the following disclaimer are included verbatim in any
\r
11 * distributions. No written agreement, license, or royalty fee is required
\r
12 * for any of the authorized uses.
\r
14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
\r
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
\r
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
\r
17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
\r
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
\r
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
\r
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
\r
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
25 ******************************************************************************
\r
28 * 03-01-01 Marc Boucher <marc@mbsi.ca>
\r
30 * 97-12-01 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
\r
32 *****************************************************************************/
\r
35 * lcp.c - PPP Link Control Protocol.
\r
37 * Copyright (c) 1989 Carnegie Mellon University.
\r
38 * All rights reserved.
\r
40 * Redistribution and use in source and binary forms are permitted
\r
41 * provided that the above copyright notice and this paragraph are
\r
42 * duplicated in all such forms and that any documentation,
\r
43 * advertising materials, and other materials related to such
\r
44 * distribution and use acknowledge that the software was developed
\r
45 * by Carnegie Mellon University. The name of the
\r
46 * University may not be used to endorse or promote products derived
\r
47 * from this software without specific prior written permission.
\r
48 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
\r
49 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
\r
50 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
\r
54 #include "lwip/opt.h"
\r
56 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
\r
59 #include "pppdebug.h"
\r
70 #include "netif/ppp_oe.h"
\r
72 #define PPPOE_MAXMTU PPP_MAXMRU
\r
76 /*************************/
\r
77 /*** LOCAL DEFINITIONS ***/
\r
78 /*************************/
\r
80 * Length of each type of configuration option (in octets)
\r
82 #define CILEN_VOID 2
\r
83 #define CILEN_CHAR 3
\r
84 #define CILEN_SHORT 4 /* CILEN_VOID + sizeof(short) */
\r
85 #define CILEN_CHAP 5 /* CILEN_VOID + sizeof(short) + 1 */
\r
86 #define CILEN_LONG 6 /* CILEN_VOID + sizeof(long) */
\r
87 #define CILEN_LQR 8 /* CILEN_VOID + sizeof(short) + sizeof(long) */
\r
88 #define CILEN_CBCP 3
\r
91 /***********************************/
\r
92 /*** LOCAL FUNCTION DECLARATIONS ***/
\r
93 /***********************************/
\r
95 * Callbacks for fsm code. (CI = Configuration Information)
\r
97 static void lcp_resetci (fsm*); /* Reset our CI */
\r
98 static int lcp_cilen (fsm*); /* Return length of our CI */
\r
99 static void lcp_addci (fsm*, u_char*, int*); /* Add our CI to pkt */
\r
100 static int lcp_ackci (fsm*, u_char*, int); /* Peer ack'd our CI */
\r
101 static int lcp_nakci (fsm*, u_char*, int); /* Peer nak'd our CI */
\r
102 static int lcp_rejci (fsm*, u_char*, int); /* Peer rej'd our CI */
\r
103 static int lcp_reqci (fsm*, u_char*, int*, int); /* Rcv peer CI */
\r
104 static void lcp_up (fsm*); /* We're UP */
\r
105 static void lcp_down (fsm*); /* We're DOWN */
\r
106 static void lcp_starting (fsm*); /* We need lower layer up */
\r
107 static void lcp_finished (fsm*); /* We need lower layer down */
\r
108 static int lcp_extcode (fsm*, int, u_char, u_char*, int);
\r
110 static void lcp_rprotrej (fsm*, u_char*, int);
\r
113 * routines to send LCP echos to peer
\r
115 static void lcp_echo_lowerup (int);
\r
116 static void lcp_echo_lowerdown (int);
\r
117 static void LcpEchoTimeout (void*);
\r
118 static void lcp_received_echo_reply (fsm*, int, u_char*, int);
\r
119 static void LcpSendEchoRequest (fsm*);
\r
120 static void LcpLinkFailure (fsm*);
\r
121 static void LcpEchoCheck (fsm*);
\r
124 * Protocol entry points.
\r
125 * Some of these are called directly.
\r
127 static void lcp_input (int, u_char *, int);
\r
128 static void lcp_protrej (int);
\r
130 #define CODENAME(x) ((x) == CONFACK ? "ACK" : (x) == CONFNAK ? "NAK" : "REJ")
\r
133 /******************************/
\r
134 /*** PUBLIC DATA STRUCTURES ***/
\r
135 /******************************/
\r
137 LinkPhase lcp_phase[NUM_PPP]; /* Phase of link session (RFC 1661) */
\r
138 lcp_options lcp_wantoptions[NUM_PPP]; /* Options that we want to request */
\r
139 lcp_options lcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
\r
140 lcp_options lcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
\r
141 lcp_options lcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
\r
142 ext_accm xmit_accm[NUM_PPP]; /* extended transmit ACCM */
\r
146 /*****************************/
\r
147 /*** LOCAL DATA STRUCTURES ***/
\r
148 /*****************************/
\r
149 static fsm lcp_fsm[NUM_PPP]; /* LCP fsm structure (global)*/
\r
150 static u_int lcp_echo_interval = LCP_ECHOINTERVAL; /* Interval between LCP echo-requests */
\r
151 static u_int lcp_echo_fails = LCP_MAXECHOFAILS; /* Tolerance to unanswered echo-requests */
\r
152 static u32_t lcp_echos_pending = 0; /* Number of outstanding echo msgs */
\r
153 static u32_t lcp_echo_number = 0; /* ID number of next echo frame */
\r
154 static u32_t lcp_echo_timer_running = 0; /* TRUE if a timer is running */
\r
156 static u_char nak_buffer[PPP_MRU]; /* where we construct a nak packet */
\r
158 static fsm_callbacks lcp_callbacks = { /* LCP callback routines */
\r
159 lcp_resetci, /* Reset our Configuration Information */
\r
160 lcp_cilen, /* Length of our Configuration Information */
\r
161 lcp_addci, /* Add our Configuration Information */
\r
162 lcp_ackci, /* ACK our Configuration Information */
\r
163 lcp_nakci, /* NAK our Configuration Information */
\r
164 lcp_rejci, /* Reject our Configuration Information */
\r
165 lcp_reqci, /* Request peer's Configuration Information */
\r
166 lcp_up, /* Called when fsm reaches LS_OPENED state */
\r
167 lcp_down, /* Called when fsm leaves LS_OPENED state */
\r
168 lcp_starting, /* Called when we want the lower layer up */
\r
169 lcp_finished, /* Called when we want the lower layer down */
\r
170 NULL, /* Called when Protocol-Reject received */
\r
171 NULL, /* Retransmission is necessary */
\r
172 lcp_extcode, /* Called to handle LCP-specific codes */
\r
173 "LCP" /* String name of protocol */
\r
176 struct protent lcp_protent = {
\r
198 int lcp_loopbackfail = DEFLOOPBACKFAIL;
\r
202 /***********************************/
\r
203 /*** PUBLIC FUNCTION DEFINITIONS ***/
\r
204 /***********************************/
\r
206 * lcp_init - Initialize LCP.
\r
211 fsm *f = &lcp_fsm[unit];
\r
212 lcp_options *wo = &lcp_wantoptions[unit];
\r
213 lcp_options *ao = &lcp_allowoptions[unit];
\r
216 f->protocol = PPP_LCP;
\r
217 f->callbacks = &lcp_callbacks;
\r
223 wo->restart = 0; /* Set to 1 in kernels or multi-line implementations */
\r
225 wo->mru = PPP_DEFMRU;
\r
226 wo->neg_asyncmap = 1;
\r
227 wo->asyncmap = 0x00000000l; /* Assume don't need to escape any ctl chars. */
\r
228 wo->neg_chap = 0; /* Set to 1 on server */
\r
229 wo->neg_upap = 0; /* Set to 1 on server */
\r
230 wo->chap_mdtype = CHAP_DIGEST_MD5;
\r
231 wo->neg_magicnumber = 1;
\r
232 wo->neg_pcompression = 1;
\r
233 wo->neg_accompression = 1;
\r
234 wo->neg_lqr = 0; /* no LQR implementation yet */
\r
238 ao->mru = PPP_MAXMRU;
\r
239 ao->neg_asyncmap = 1;
\r
240 ao->asyncmap = 0x00000000l; /* Assume don't need to escape any ctl chars. */
\r
241 ao->neg_chap = (CHAP_SUPPORT != 0);
\r
242 ao->chap_mdtype = CHAP_DIGEST_MD5;
\r
243 ao->neg_upap = (PAP_SUPPORT != 0);
\r
244 ao->neg_magicnumber = 1;
\r
245 ao->neg_pcompression = 1;
\r
246 ao->neg_accompression = 1;
\r
247 ao->neg_lqr = 0; /* no LQR implementation yet */
\r
248 ao->neg_cbcp = (CBCP_SUPPORT != 0);
\r
251 * Set transmit escape for the flag and escape characters plus anything
\r
252 * set for the allowable options.
\r
254 memset(xmit_accm[unit], 0, sizeof(xmit_accm[0]));
\r
255 xmit_accm[unit][15] = 0x60;
\r
256 xmit_accm[unit][0] = (u_char)((ao->asyncmap & 0xFF));
\r
257 xmit_accm[unit][1] = (u_char)((ao->asyncmap >> 8) & 0xFF);
\r
258 xmit_accm[unit][2] = (u_char)((ao->asyncmap >> 16) & 0xFF);
\r
259 xmit_accm[unit][3] = (u_char)((ao->asyncmap >> 24) & 0xFF);
\r
260 LCPDEBUG((LOG_INFO, "lcp_init: xmit_accm=%X %X %X %X\n",
\r
261 xmit_accm[unit][0],
\r
262 xmit_accm[unit][1],
\r
263 xmit_accm[unit][2],
\r
264 xmit_accm[unit][3]));
\r
266 lcp_phase[unit] = PHASE_INITIALIZE;
\r
271 * lcp_open - LCP is allowed to come up.
\r
276 fsm *f = &lcp_fsm[unit];
\r
277 lcp_options *wo = &lcp_wantoptions[unit];
\r
281 f->flags |= OPT_PASSIVE;
\r
284 f->flags |= OPT_SILENT;
\r
288 lcp_phase[unit] = PHASE_ESTABLISH;
\r
293 * lcp_close - Take LCP down.
\r
296 lcp_close(int unit, char *reason)
\r
298 fsm *f = &lcp_fsm[unit];
\r
300 if (lcp_phase[unit] != PHASE_DEAD) {
\r
301 lcp_phase[unit] = PHASE_TERMINATE;
\r
303 if (f->state == LS_STOPPED && f->flags & (OPT_PASSIVE|OPT_SILENT)) {
\r
305 * This action is not strictly according to the FSM in RFC1548,
\r
306 * but it does mean that the program terminates if you do an
\r
307 * lcp_close() in passive/silent mode when a connection hasn't
\r
308 * been established.
\r
310 f->state = LS_CLOSED;
\r
313 fsm_close(&lcp_fsm[unit], reason);
\r
319 * lcp_lowerup - The lower layer is up.
\r
322 lcp_lowerup(int unit)
\r
324 lcp_options *wo = &lcp_wantoptions[unit];
\r
327 * Don't use A/C or protocol compression on transmission,
\r
328 * but accept A/C and protocol compressed packets
\r
329 * if we are going to ask for A/C and protocol compression.
\r
331 ppp_set_xaccm(unit, &xmit_accm[unit]);
\r
332 ppp_send_config(unit, PPP_MRU, 0xffffffffl, 0, 0);
\r
333 ppp_recv_config(unit, PPP_MRU, 0x00000000l,
\r
334 wo->neg_pcompression, wo->neg_accompression);
\r
335 peer_mru[unit] = PPP_MRU;
\r
336 lcp_allowoptions[unit].asyncmap = (u_long)xmit_accm[unit][0]
\r
337 | ((u_long)xmit_accm[unit][1] << 8)
\r
338 | ((u_long)xmit_accm[unit][2] << 16)
\r
339 | ((u_long)xmit_accm[unit][3] << 24);
\r
340 LCPDEBUG((LOG_INFO, "lcp_lowerup: asyncmap=%X %X %X %X\n",
\r
341 xmit_accm[unit][3],
\r
342 xmit_accm[unit][2],
\r
343 xmit_accm[unit][1],
\r
344 xmit_accm[unit][0]));
\r
346 fsm_lowerup(&lcp_fsm[unit]);
\r
351 * lcp_lowerdown - The lower layer is down.
\r
354 lcp_lowerdown(int unit)
\r
356 fsm_lowerdown(&lcp_fsm[unit]);
\r
360 * lcp_sprotrej - Send a Protocol-Reject for some protocol.
\r
363 lcp_sprotrej(int unit, u_char *p, int len)
\r
366 * Send back the protocol and the information field of the
\r
367 * rejected packet. We only get here if LCP is in the LS_OPENED state.
\r
370 fsm_sdata(&lcp_fsm[unit], PROTREJ, ++lcp_fsm[unit].id, p, len);
\r
375 /**********************************/
\r
376 /*** LOCAL FUNCTION DEFINITIONS ***/
\r
377 /**********************************/
\r
379 * lcp_input - Input LCP packet.
\r
382 lcp_input(int unit, u_char *p, int len)
\r
384 fsm *f = &lcp_fsm[unit];
\r
386 fsm_input(f, p, len);
\r
391 * lcp_extcode - Handle a LCP-specific code.
\r
394 lcp_extcode(fsm *f, int code, u_char id, u_char *inp, int len)
\r
400 lcp_rprotrej(f, inp, len);
\r
404 if (f->state != LS_OPENED) {
\r
407 LCPDEBUG((LOG_INFO, "lcp: Echo-Request, Rcvd id %d\n", id));
\r
409 PUTLONG(lcp_gotoptions[f->unit].magicnumber, magp);
\r
410 fsm_sdata(f, ECHOREP, id, inp, len);
\r
414 lcp_received_echo_reply(f, id, inp, len);
\r
428 * lcp_rprotrej - Receive an Protocol-Reject.
\r
430 * Figure out which protocol is rejected and inform it.
\r
433 lcp_rprotrej(fsm *f, u_char *inp, int len)
\r
436 struct protent *protp;
\r
439 if (len < sizeof (u_short)) {
\r
440 LCPDEBUG((LOG_INFO, "lcp_rprotrej: Rcvd short Protocol-Reject packet!\n"));
\r
444 GETSHORT(prot, inp);
\r
446 LCPDEBUG((LOG_INFO, "lcp_rprotrej: Rcvd Protocol-Reject packet for %x!\n", prot));
\r
449 * Protocol-Reject packets received in any state other than the LCP
\r
450 * LS_OPENED state SHOULD be silently discarded.
\r
452 if( f->state != LS_OPENED ) {
\r
453 LCPDEBUG((LOG_INFO, "Protocol-Reject discarded: LCP in state %d\n", f->state));
\r
458 * Upcall the proper Protocol-Reject routine.
\r
460 for (i = 0; (protp = ppp_protocols[i]) != NULL; ++i) {
\r
461 if (protp->protocol == prot && protp->enabled_flag) {
\r
462 (*protp->protrej)(f->unit);
\r
467 LCPDEBUG((LOG_WARNING, "Protocol-Reject for unsupported protocol 0x%x\n", prot));
\r
472 * lcp_protrej - A Protocol-Reject was received.
\r
475 lcp_protrej(int unit)
\r
477 LWIP_UNUSED_ARG(unit);
\r
479 * Can't reject LCP!
\r
481 LCPDEBUG((LOG_WARNING, "lcp_protrej: Received Protocol-Reject for LCP!\n"));
\r
482 fsm_protreject(&lcp_fsm[unit]);
\r
487 * lcp_resetci - Reset our CI.
\r
490 lcp_resetci(fsm *f)
\r
492 lcp_wantoptions[f->unit].magicnumber = magic();
\r
493 lcp_wantoptions[f->unit].numloops = 0;
\r
494 lcp_gotoptions[f->unit] = lcp_wantoptions[f->unit];
\r
495 peer_mru[f->unit] = PPP_MRU;
\r
496 auth_reset(f->unit);
\r
501 * lcp_cilen - Return length of our CI.
\r
503 static int lcp_cilen(fsm *f)
\r
505 lcp_options *go = &lcp_gotoptions[f->unit];
\r
507 #define LENCIVOID(neg) ((neg) ? CILEN_VOID : 0)
\r
508 #define LENCICHAP(neg) ((neg) ? CILEN_CHAP : 0)
\r
509 #define LENCISHORT(neg) ((neg) ? CILEN_SHORT : 0)
\r
510 #define LENCILONG(neg) ((neg) ? CILEN_LONG : 0)
\r
511 #define LENCILQR(neg) ((neg) ? CILEN_LQR: 0)
\r
512 #define LENCICBCP(neg) ((neg) ? CILEN_CBCP: 0)
\r
514 * NB: we only ask for one of CHAP and UPAP, even if we will
\r
517 return (LENCISHORT(go->neg_mru && go->mru != PPP_DEFMRU) +
\r
518 LENCILONG(go->neg_asyncmap && go->asyncmap != 0xFFFFFFFFl) +
\r
519 LENCICHAP(go->neg_chap) +
\r
520 LENCISHORT(!go->neg_chap && go->neg_upap) +
\r
521 LENCILQR(go->neg_lqr) +
\r
522 LENCICBCP(go->neg_cbcp) +
\r
523 LENCILONG(go->neg_magicnumber) +
\r
524 LENCIVOID(go->neg_pcompression) +
\r
525 LENCIVOID(go->neg_accompression));
\r
530 * lcp_addci - Add our desired CIs to a packet.
\r
533 lcp_addci(fsm *f, u_char *ucp, int *lenp)
\r
535 lcp_options *go = &lcp_gotoptions[f->unit];
\r
536 u_char *start_ucp = ucp;
\r
538 #define ADDCIVOID(opt, neg) \
\r
540 LCPDEBUG((LOG_INFO, "lcp_addci: opt=%d\n", opt)); \
\r
541 PUTCHAR(opt, ucp); \
\r
542 PUTCHAR(CILEN_VOID, ucp); \
\r
544 #define ADDCISHORT(opt, neg, val) \
\r
546 LCPDEBUG((LOG_INFO, "lcp_addci: INT opt=%d %X\n", opt, val)); \
\r
547 PUTCHAR(opt, ucp); \
\r
548 PUTCHAR(CILEN_SHORT, ucp); \
\r
549 PUTSHORT(val, ucp); \
\r
551 #define ADDCICHAP(opt, neg, val, digest) \
\r
553 LCPDEBUG((LOG_INFO, "lcp_addci: CHAP opt=%d %X\n", opt, val)); \
\r
554 PUTCHAR(opt, ucp); \
\r
555 PUTCHAR(CILEN_CHAP, ucp); \
\r
556 PUTSHORT(val, ucp); \
\r
557 PUTCHAR(digest, ucp); \
\r
559 #define ADDCILONG(opt, neg, val) \
\r
561 LCPDEBUG((LOG_INFO, "lcp_addci: L opt=%d %lX\n", opt, val)); \
\r
562 PUTCHAR(opt, ucp); \
\r
563 PUTCHAR(CILEN_LONG, ucp); \
\r
564 PUTLONG(val, ucp); \
\r
566 #define ADDCILQR(opt, neg, val) \
\r
568 LCPDEBUG((LOG_INFO, "lcp_addci: LQR opt=%d %lX\n", opt, val)); \
\r
569 PUTCHAR(opt, ucp); \
\r
570 PUTCHAR(CILEN_LQR, ucp); \
\r
571 PUTSHORT(PPP_LQR, ucp); \
\r
572 PUTLONG(val, ucp); \
\r
574 #define ADDCICHAR(opt, neg, val) \
\r
576 LCPDEBUG((LOG_INFO, "lcp_addci: CHAR opt=%d %X '%z'\n", opt, val, val)); \
\r
577 PUTCHAR(opt, ucp); \
\r
578 PUTCHAR(CILEN_CHAR, ucp); \
\r
579 PUTCHAR(val, ucp); \
\r
582 ADDCISHORT(CI_MRU, go->neg_mru && go->mru != PPP_DEFMRU, go->mru);
\r
583 ADDCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFFl, go->asyncmap);
\r
584 ADDCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype);
\r
585 ADDCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
\r
586 ADDCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
\r
587 ADDCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
\r
588 ADDCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
\r
589 ADDCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
\r
590 ADDCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
\r
592 if (ucp - start_ucp != *lenp) {
\r
593 /* this should never happen, because peer_mtu should be 1500 */
\r
594 LCPDEBUG((LOG_ERR, "Bug in lcp_addci: wrong length\n"));
\r
600 * lcp_ackci - Ack our CIs.
\r
601 * This should not modify any state if the Ack is bad.
\r
605 * 1 - Ack was good.
\r
608 lcp_ackci(fsm *f, u_char *p, int len)
\r
610 lcp_options *go = &lcp_gotoptions[f->unit];
\r
611 u_char cilen, citype, cichar;
\r
616 * CIs must be in exactly the same order that we sent.
\r
617 * Check packet length and CI length at each step.
\r
618 * If we find any deviations, then this packet is bad.
\r
620 #define ACKCIVOID(opt, neg) \
\r
622 if ((len -= CILEN_VOID) < 0) \
\r
624 GETCHAR(citype, p); \
\r
625 GETCHAR(cilen, p); \
\r
626 if (cilen != CILEN_VOID || citype != opt) \
\r
629 #define ACKCISHORT(opt, neg, val) \
\r
631 if ((len -= CILEN_SHORT) < 0) \
\r
633 GETCHAR(citype, p); \
\r
634 GETCHAR(cilen, p); \
\r
635 if (cilen != CILEN_SHORT || citype != opt) \
\r
637 GETSHORT(cishort, p); \
\r
638 if (cishort != val) \
\r
641 #define ACKCICHAR(opt, neg, val) \
\r
643 if ((len -= CILEN_CHAR) < 0) \
\r
645 GETCHAR(citype, p); \
\r
646 GETCHAR(cilen, p); \
\r
647 if (cilen != CILEN_CHAR || citype != opt) \
\r
649 GETCHAR(cichar, p); \
\r
650 if (cichar != val) \
\r
653 #define ACKCICHAP(opt, neg, val, digest) \
\r
655 if ((len -= CILEN_CHAP) < 0) \
\r
657 GETCHAR(citype, p); \
\r
658 GETCHAR(cilen, p); \
\r
659 if (cilen != CILEN_CHAP || citype != opt) \
\r
661 GETSHORT(cishort, p); \
\r
662 if (cishort != val) \
\r
664 GETCHAR(cichar, p); \
\r
665 if (cichar != digest) \
\r
668 #define ACKCILONG(opt, neg, val) \
\r
670 if ((len -= CILEN_LONG) < 0) \
\r
672 GETCHAR(citype, p); \
\r
673 GETCHAR(cilen, p); \
\r
674 if (cilen != CILEN_LONG || citype != opt) \
\r
676 GETLONG(cilong, p); \
\r
677 if (cilong != val) \
\r
680 #define ACKCILQR(opt, neg, val) \
\r
682 if ((len -= CILEN_LQR) < 0) \
\r
684 GETCHAR(citype, p); \
\r
685 GETCHAR(cilen, p); \
\r
686 if (cilen != CILEN_LQR || citype != opt) \
\r
688 GETSHORT(cishort, p); \
\r
689 if (cishort != PPP_LQR) \
\r
691 GETLONG(cilong, p); \
\r
692 if (cilong != val) \
\r
696 ACKCISHORT(CI_MRU, go->neg_mru && go->mru != PPP_DEFMRU, go->mru);
\r
697 ACKCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFFl, go->asyncmap);
\r
698 ACKCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype);
\r
699 ACKCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
\r
700 ACKCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
\r
701 ACKCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
\r
702 ACKCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
\r
703 ACKCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
\r
704 ACKCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
\r
707 * If there are any remaining CIs, then this packet is bad.
\r
712 LCPDEBUG((LOG_INFO, "lcp_acki: Ack\n"));
\r
715 LCPDEBUG((LOG_WARNING, "lcp_acki: received bad Ack!\n"));
\r
721 * lcp_nakci - Peer has sent a NAK for some of our CIs.
\r
722 * This should not modify any state if the Nak is bad
\r
723 * or if LCP is in the LS_OPENED state.
\r
727 * 1 - Nak was good.
\r
730 lcp_nakci(fsm *f, u_char *p, int len)
\r
732 lcp_options *go = &lcp_gotoptions[f->unit];
\r
733 lcp_options *wo = &lcp_wantoptions[f->unit];
\r
734 u_char citype, cichar, *next;
\r
737 lcp_options no; /* options we've seen Naks for */
\r
738 lcp_options try; /* options to request next time */
\r
739 int looped_back = 0;
\r
742 BZERO(&no, sizeof(no));
\r
746 * Any Nak'd CIs must be in exactly the same order that we sent.
\r
747 * Check packet length and CI length at each step.
\r
748 * If we find any deviations, then this packet is bad.
\r
750 #define NAKCIVOID(opt, neg, code) \
\r
752 len >= CILEN_VOID && \
\r
753 p[1] == CILEN_VOID && \
\r
755 len -= CILEN_VOID; \
\r
756 INCPTR(CILEN_VOID, p); \
\r
760 #define NAKCICHAP(opt, neg, code) \
\r
762 len >= CILEN_CHAP && \
\r
763 p[1] == CILEN_CHAP && \
\r
765 len -= CILEN_CHAP; \
\r
767 GETSHORT(cishort, p); \
\r
768 GETCHAR(cichar, p); \
\r
772 #define NAKCICHAR(opt, neg, code) \
\r
774 len >= CILEN_CHAR && \
\r
775 p[1] == CILEN_CHAR && \
\r
777 len -= CILEN_CHAR; \
\r
779 GETCHAR(cichar, p); \
\r
783 #define NAKCISHORT(opt, neg, code) \
\r
785 len >= CILEN_SHORT && \
\r
786 p[1] == CILEN_SHORT && \
\r
788 len -= CILEN_SHORT; \
\r
790 GETSHORT(cishort, p); \
\r
794 #define NAKCILONG(opt, neg, code) \
\r
796 len >= CILEN_LONG && \
\r
797 p[1] == CILEN_LONG && \
\r
799 len -= CILEN_LONG; \
\r
801 GETLONG(cilong, p); \
\r
805 #define NAKCILQR(opt, neg, code) \
\r
807 len >= CILEN_LQR && \
\r
808 p[1] == CILEN_LQR && \
\r
810 len -= CILEN_LQR; \
\r
812 GETSHORT(cishort, p); \
\r
813 GETLONG(cilong, p); \
\r
819 * We don't care if they want to send us smaller packets than
\r
820 * we want. Therefore, accept any MRU less than what we asked for,
\r
821 * but then ignore the new value when setting the MRU in the kernel.
\r
822 * If they send us a bigger MRU than what we asked, accept it, up to
\r
823 * the limit of the default MRU we'd get if we didn't negotiate.
\r
825 if (go->neg_mru && go->mru != PPP_DEFMRU) {
\r
826 NAKCISHORT(CI_MRU, neg_mru,
\r
827 if (cishort <= wo->mru || cishort < PPP_DEFMRU) {
\r
834 * Add any characters they want to our (receive-side) asyncmap.
\r
836 if (go->neg_asyncmap && go->asyncmap != 0xFFFFFFFFl) {
\r
837 NAKCILONG(CI_ASYNCMAP, neg_asyncmap,
\r
838 try.asyncmap = go->asyncmap | cilong;
\r
843 * If they've nak'd our authentication-protocol, check whether
\r
844 * they are proposing a different protocol, or a different
\r
845 * hash algorithm for CHAP.
\r
847 if ((go->neg_chap || go->neg_upap)
\r
848 && len >= CILEN_SHORT
\r
849 && p[0] == CI_AUTHTYPE && p[1] >= CILEN_SHORT && p[1] <= len) {
\r
852 no.neg_chap = go->neg_chap;
\r
853 no.neg_upap = go->neg_upap;
\r
855 GETSHORT(cishort, p);
\r
856 if (cishort == PPP_PAP && cilen == CILEN_SHORT) {
\r
858 * If we were asking for CHAP, they obviously don't want to do it.
\r
859 * If we weren't asking for CHAP, then we were asking for PAP,
\r
860 * in which case this Nak is bad.
\r
862 if (!go->neg_chap) {
\r
867 } else if (cishort == PPP_CHAP && cilen == CILEN_CHAP) {
\r
868 GETCHAR(cichar, p);
\r
869 if (go->neg_chap) {
\r
871 * We were asking for CHAP/MD5; they must want a different
\r
872 * algorithm. If they can't do MD5, we'll have to stop
\r
875 if (cichar != go->chap_mdtype) {
\r
880 * Stop asking for PAP if we were asking for it.
\r
887 * We don't recognize what they're suggesting.
\r
888 * Stop asking for what we were asking for.
\r
890 if (go->neg_chap) {
\r
895 p += cilen - CILEN_SHORT;
\r
900 * If they can't cope with our link quality protocol, we'll have
\r
901 * to stop asking for LQR. We haven't got any other protocol.
\r
902 * If they Nak the reporting period, take their value XXX ?
\r
904 NAKCILQR(CI_QUALITY, neg_lqr,
\r
905 if (cishort != PPP_LQR) {
\r
908 try.lqr_period = cilong;
\r
913 * Only implementing CBCP...not the rest of the callback options
\r
915 NAKCICHAR(CI_CALLBACK, neg_cbcp,
\r
920 * Check for a looped-back line.
\r
922 NAKCILONG(CI_MAGICNUMBER, neg_magicnumber,
\r
923 try.magicnumber = magic();
\r
928 * Peer shouldn't send Nak for protocol compression or
\r
929 * address/control compression requests; they should send
\r
930 * a Reject instead. If they send a Nak, treat it as a Reject.
\r
932 NAKCIVOID(CI_PCOMPRESSION, neg_pcompression,
\r
933 try.neg_pcompression = 0;
\r
935 NAKCIVOID(CI_ACCOMPRESSION, neg_accompression,
\r
936 try.neg_accompression = 0;
\r
940 * There may be remaining CIs, if the peer is requesting negotiation
\r
941 * on an option that we didn't include in our request packet.
\r
942 * If we see an option that we requested, or one we've already seen
\r
943 * in this packet, then this packet is bad.
\r
944 * If we wanted to respond by starting to negotiate on the requested
\r
945 * option(s), we could, but we don't, because except for the
\r
946 * authentication type and quality protocol, if we are not negotiating
\r
947 * an option, it is because we were told not to.
\r
948 * For the authentication type, the Nak from the peer means
\r
949 * `let me authenticate myself with you' which is a bit pointless.
\r
950 * For the quality protocol, the Nak means `ask me to send you quality
\r
951 * reports', but if we didn't ask for them, we don't want them.
\r
952 * An option we don't recognize represents the peer asking to
\r
953 * negotiate some option we don't support, so ignore it.
\r
955 while (len > CILEN_VOID) {
\r
956 GETCHAR(citype, p);
\r
958 if (cilen < CILEN_VOID || (len -= cilen) < 0) {
\r
961 next = p + cilen - 2;
\r
965 if ((go->neg_mru && go->mru != PPP_DEFMRU)
\r
966 || no.neg_mru || cilen != CILEN_SHORT) {
\r
969 GETSHORT(cishort, p);
\r
970 if (cishort < PPP_DEFMRU) {
\r
975 if ((go->neg_asyncmap && go->asyncmap != 0xFFFFFFFFl)
\r
976 || no.neg_asyncmap || cilen != CILEN_LONG) {
\r
981 if (go->neg_chap || no.neg_chap || go->neg_upap || no.neg_upap) {
\r
985 case CI_MAGICNUMBER:
\r
986 if (go->neg_magicnumber || no.neg_magicnumber ||
\r
987 cilen != CILEN_LONG) {
\r
991 case CI_PCOMPRESSION:
\r
992 if (go->neg_pcompression || no.neg_pcompression
\r
993 || cilen != CILEN_VOID) {
\r
997 case CI_ACCOMPRESSION:
\r
998 if (go->neg_accompression || no.neg_accompression
\r
999 || cilen != CILEN_VOID) {
\r
1004 if (go->neg_lqr || no.neg_lqr || cilen != CILEN_LQR) {
\r
1012 /* If there is still anything left, this packet is bad. */
\r
1018 * OK, the Nak is good. Now we can update state.
\r
1020 if (f->state != LS_OPENED) {
\r
1021 if (looped_back) {
\r
1022 if (++try.numloops >= lcp_loopbackfail) {
\r
1023 LCPDEBUG((LOG_NOTICE, "Serial line is looped back.\n"));
\r
1024 lcp_close(f->unit, "Loopback detected");
\r
1035 LCPDEBUG((LOG_WARNING, "lcp_nakci: received bad Nak!\n"));
\r
1041 * lcp_rejci - Peer has Rejected some of our CIs.
\r
1042 * This should not modify any state if the Reject is bad
\r
1043 * or if LCP is in the LS_OPENED state.
\r
1046 * 0 - Reject was bad.
\r
1047 * 1 - Reject was good.
\r
1050 lcp_rejci(fsm *f, u_char *p, int len)
\r
1052 lcp_options *go = &lcp_gotoptions[f->unit];
\r
1056 lcp_options try; /* options to request next time */
\r
1061 * Any Rejected CIs must be in exactly the same order that we sent.
\r
1062 * Check packet length and CI length at each step.
\r
1063 * If we find any deviations, then this packet is bad.
\r
1065 #define REJCIVOID(opt, neg) \
\r
1067 len >= CILEN_VOID && \
\r
1068 p[1] == CILEN_VOID && \
\r
1070 len -= CILEN_VOID; \
\r
1071 INCPTR(CILEN_VOID, p); \
\r
1073 LCPDEBUG((LOG_INFO, "lcp_rejci: void opt %d rejected\n", opt)); \
\r
1075 #define REJCISHORT(opt, neg, val) \
\r
1077 len >= CILEN_SHORT && \
\r
1078 p[1] == CILEN_SHORT && \
\r
1080 len -= CILEN_SHORT; \
\r
1082 GETSHORT(cishort, p); \
\r
1083 /* Check rejected value. */ \
\r
1084 if (cishort != val) { \
\r
1088 LCPDEBUG((LOG_INFO,"lcp_rejci: short opt %d rejected\n", opt)); \
\r
1090 #define REJCICHAP(opt, neg, val, digest) \
\r
1092 len >= CILEN_CHAP && \
\r
1093 p[1] == CILEN_CHAP && \
\r
1095 len -= CILEN_CHAP; \
\r
1097 GETSHORT(cishort, p); \
\r
1098 GETCHAR(cichar, p); \
\r
1099 /* Check rejected value. */ \
\r
1100 if (cishort != val || cichar != digest) { \
\r
1104 try.neg_upap = 0; \
\r
1105 LCPDEBUG((LOG_INFO,"lcp_rejci: chap opt %d rejected\n", opt)); \
\r
1107 #define REJCILONG(opt, neg, val) \
\r
1109 len >= CILEN_LONG && \
\r
1110 p[1] == CILEN_LONG && \
\r
1112 len -= CILEN_LONG; \
\r
1114 GETLONG(cilong, p); \
\r
1115 /* Check rejected value. */ \
\r
1116 if (cilong != val) { \
\r
1120 LCPDEBUG((LOG_INFO,"lcp_rejci: long opt %d rejected\n", opt)); \
\r
1122 #define REJCILQR(opt, neg, val) \
\r
1124 len >= CILEN_LQR && \
\r
1125 p[1] == CILEN_LQR && \
\r
1127 len -= CILEN_LQR; \
\r
1129 GETSHORT(cishort, p); \
\r
1130 GETLONG(cilong, p); \
\r
1131 /* Check rejected value. */ \
\r
1132 if (cishort != PPP_LQR || cilong != val) { \
\r
1136 LCPDEBUG((LOG_INFO,"lcp_rejci: LQR opt %d rejected\n", opt)); \
\r
1138 #define REJCICBCP(opt, neg, val) \
\r
1140 len >= CILEN_CBCP && \
\r
1141 p[1] == CILEN_CBCP && \
\r
1143 len -= CILEN_CBCP; \
\r
1145 GETCHAR(cichar, p); \
\r
1146 /* Check rejected value. */ \
\r
1147 if (cichar != val) { \
\r
1151 LCPDEBUG((LOG_INFO,"lcp_rejci: Callback opt %d rejected\n", opt)); \
\r
1154 REJCISHORT(CI_MRU, neg_mru, go->mru);
\r
1155 REJCILONG(CI_ASYNCMAP, neg_asyncmap, go->asyncmap);
\r
1156 REJCICHAP(CI_AUTHTYPE, neg_chap, PPP_CHAP, go->chap_mdtype);
\r
1157 if (!go->neg_chap) {
\r
1158 REJCISHORT(CI_AUTHTYPE, neg_upap, PPP_PAP);
\r
1160 REJCILQR(CI_QUALITY, neg_lqr, go->lqr_period);
\r
1161 REJCICBCP(CI_CALLBACK, neg_cbcp, CBCP_OPT);
\r
1162 REJCILONG(CI_MAGICNUMBER, neg_magicnumber, go->magicnumber);
\r
1163 REJCIVOID(CI_PCOMPRESSION, neg_pcompression);
\r
1164 REJCIVOID(CI_ACCOMPRESSION, neg_accompression);
\r
1167 * If there are any remaining CIs, then this packet is bad.
\r
1173 * Now we can update state.
\r
1175 if (f->state != LS_OPENED) {
\r
1181 LCPDEBUG((LOG_WARNING, "lcp_rejci: received bad Reject!\n"));
\r
1187 * lcp_reqci - Check the peer's requested CIs and send appropriate response.
\r
1189 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
\r
1190 * appropriately. If reject_if_disagree is non-zero, doesn't return
\r
1191 * CONFNAK; returns CONFREJ if it can't return CONFACK.
\r
1194 lcp_reqci(fsm *f,
\r
1195 u_char *inp, /* Requested CIs */
\r
1196 int *lenp, /* Length of requested CIs */
\r
1197 int reject_if_disagree)
\r
1199 lcp_options *go = &lcp_gotoptions[f->unit];
\r
1200 lcp_options *ho = &lcp_hisoptions[f->unit];
\r
1201 lcp_options *ao = &lcp_allowoptions[f->unit];
\r
1202 u_char *cip, *next; /* Pointer to current and next CIs */
\r
1203 int cilen, citype, cichar; /* Parsed len, type, char value */
\r
1204 u_short cishort; /* Parsed short value */
\r
1205 u32_t cilong; /* Parse long value */
\r
1206 int rc = CONFACK; /* Final packet return code */
\r
1207 int orc; /* Individual option return code */
\r
1208 u_char *p; /* Pointer to next char to parse */
\r
1209 u_char *rejp; /* Pointer to next char in reject frame */
\r
1210 u_char *nakp; /* Pointer to next char in Nak frame */
\r
1211 int l = *lenp; /* Length left */
\r
1213 char traceBuf[80];
\r
1218 * Reset all his options.
\r
1220 BZERO(ho, sizeof(*ho));
\r
1223 * Process all his options.
\r
1226 nakp = nak_buffer;
\r
1229 orc = CONFACK; /* Assume success */
\r
1230 cip = p = next; /* Remember begining of CI */
\r
1231 if (l < 2 || /* Not enough data for CI header or */
\r
1232 p[1] < 2 || /* CI length too small or */
\r
1233 p[1] > l) { /* CI length too big? */
\r
1234 LCPDEBUG((LOG_WARNING, "lcp_reqci: bad CI length!\n"));
\r
1235 orc = CONFREJ; /* Reject bad CI */
\r
1236 cilen = l; /* Reject till end of packet */
\r
1237 l = 0; /* Don't loop again */
\r
1241 GETCHAR(citype, p); /* Parse CI type */
\r
1242 GETCHAR(cilen, p); /* Parse CI length */
\r
1243 l -= cilen; /* Adjust remaining length */
\r
1244 next += cilen; /* Step to next CI */
\r
1246 switch (citype) { /* Check CI type */
\r
1248 if (!ao->neg_mru) { /* Allow option? */
\r
1249 LCPDEBUG((LOG_INFO, "lcp_reqci: Reject MRU - not allowed\n"));
\r
1250 orc = CONFREJ; /* Reject CI */
\r
1252 } else if (cilen != CILEN_SHORT) { /* Check CI length */
\r
1253 LCPDEBUG((LOG_INFO, "lcp_reqci: Reject MRU - bad length\n"));
\r
1254 orc = CONFREJ; /* Reject CI */
\r
1257 GETSHORT(cishort, p); /* Parse MRU */
\r
1260 * He must be able to receive at least our minimum.
\r
1261 * No need to check a maximum. If he sends a large number,
\r
1262 * we'll just ignore it.
\r
1264 if (cishort < PPP_MINMRU) {
\r
1265 LCPDEBUG((LOG_INFO, "lcp_reqci: Nak - MRU too small\n"));
\r
1266 orc = CONFNAK; /* Nak CI */
\r
1267 PUTCHAR(CI_MRU, nakp);
\r
1268 PUTCHAR(CILEN_SHORT, nakp);
\r
1269 PUTSHORT(PPP_MINMRU, nakp); /* Give him a hint */
\r
1272 ho->neg_mru = 1; /* Remember he sent MRU */
\r
1273 ho->mru = cishort; /* And remember value */
\r
1275 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " MRU %d", cishort);
\r
1276 traceNdx = strlen(traceBuf);
\r
1281 if (!ao->neg_asyncmap) {
\r
1282 LCPDEBUG((LOG_INFO, "lcp_reqci: Reject ASYNCMAP not allowed\n"));
\r
1285 } else if (cilen != CILEN_LONG) {
\r
1286 LCPDEBUG((LOG_INFO, "lcp_reqci: Reject ASYNCMAP bad length\n"));
\r
1290 GETLONG(cilong, p);
\r
1293 * Asyncmap must have set at least the bits
\r
1294 * which are set in lcp_allowoptions[unit].asyncmap.
\r
1296 if ((ao->asyncmap & ~cilong) != 0) {
\r
1297 LCPDEBUG((LOG_INFO, "lcp_reqci: Nak ASYNCMAP %lX missing %lX\n",
\r
1298 cilong, ao->asyncmap));
\r
1300 PUTCHAR(CI_ASYNCMAP, nakp);
\r
1301 PUTCHAR(CILEN_LONG, nakp);
\r
1302 PUTLONG(ao->asyncmap | cilong, nakp);
\r
1305 ho->neg_asyncmap = 1;
\r
1306 ho->asyncmap = cilong;
\r
1308 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " ASYNCMAP=%lX", cilong);
\r
1309 traceNdx = strlen(traceBuf);
\r
1314 if (cilen < CILEN_SHORT) {
\r
1315 LCPDEBUG((LOG_INFO, "lcp_reqci: Reject AUTHTYPE missing arg\n"));
\r
1318 } else if (!(ao->neg_upap || ao->neg_chap)) {
\r
1320 * Reject the option if we're not willing to authenticate.
\r
1322 LCPDEBUG((LOG_INFO, "lcp_reqci: Reject AUTHTYPE not allowed\n"));
\r
1326 GETSHORT(cishort, p);
\r
1329 * Authtype must be UPAP or CHAP.
\r
1331 * Note: if both ao->neg_upap and ao->neg_chap are set,
\r
1332 * and the peer sends a Configure-Request with two
\r
1333 * authenticate-protocol requests, one for CHAP and one
\r
1334 * for UPAP, then we will reject the second request.
\r
1335 * Whether we end up doing CHAP or UPAP depends then on
\r
1336 * the ordering of the CIs in the peer's Configure-Request.
\r
1339 if (cishort == PPP_PAP) {
\r
1340 if (ho->neg_chap) { /* we've already accepted CHAP */
\r
1341 LCPDEBUG((LOG_WARNING, "lcp_reqci: Reject AUTHTYPE PAP already accepted\n"));
\r
1344 } else if (cilen != CILEN_SHORT) {
\r
1345 LCPDEBUG((LOG_WARNING, "lcp_reqci: Reject AUTHTYPE PAP bad len\n"));
\r
1349 if (!ao->neg_upap) { /* we don't want to do PAP */
\r
1350 LCPDEBUG((LOG_WARNING, "lcp_reqci: Nak AUTHTYPE PAP not allowed\n"));
\r
1351 orc = CONFNAK; /* NAK it and suggest CHAP */
\r
1352 PUTCHAR(CI_AUTHTYPE, nakp);
\r
1353 PUTCHAR(CILEN_CHAP, nakp);
\r
1354 PUTSHORT(PPP_CHAP, nakp);
\r
1355 PUTCHAR(ao->chap_mdtype, nakp);
\r
1360 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " PAP (%X)", cishort);
\r
1361 traceNdx = strlen(traceBuf);
\r
1365 if (cishort == PPP_CHAP) {
\r
1366 if (ho->neg_upap) { /* we've already accepted PAP */
\r
1367 LCPDEBUG((LOG_WARNING, "lcp_reqci: Reject AUTHTYPE CHAP accepted PAP\n"));
\r
1370 } else if (cilen != CILEN_CHAP) {
\r
1371 LCPDEBUG((LOG_WARNING, "lcp_reqci: Reject AUTHTYPE CHAP bad len\n"));
\r
1375 if (!ao->neg_chap) { /* we don't want to do CHAP */
\r
1376 LCPDEBUG((LOG_WARNING, "lcp_reqci: Nak AUTHTYPE CHAP not allowed\n"));
\r
1377 orc = CONFNAK; /* NAK it and suggest PAP */
\r
1378 PUTCHAR(CI_AUTHTYPE, nakp);
\r
1379 PUTCHAR(CILEN_SHORT, nakp);
\r
1380 PUTSHORT(PPP_PAP, nakp);
\r
1383 GETCHAR(cichar, p); /* get digest type*/
\r
1384 if (cichar != CHAP_DIGEST_MD5
\r
1386 && cichar != CHAP_MICROSOFT
\r
1389 LCPDEBUG((LOG_WARNING, "lcp_reqci: Nak AUTHTYPE CHAP digest=%d\n", cichar));
\r
1391 PUTCHAR(CI_AUTHTYPE, nakp);
\r
1392 PUTCHAR(CILEN_CHAP, nakp);
\r
1393 PUTSHORT(PPP_CHAP, nakp);
\r
1394 PUTCHAR(ao->chap_mdtype, nakp);
\r
1398 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " CHAP %X,%d", cishort, cichar);
\r
1399 traceNdx = strlen(traceBuf);
\r
1401 ho->chap_mdtype = cichar; /* save md type */
\r
1407 * We don't recognize the protocol they're asking for.
\r
1408 * Nak it with something we're willing to do.
\r
1409 * (At this point we know ao->neg_upap || ao->neg_chap.)
\r
1412 PUTCHAR(CI_AUTHTYPE, nakp);
\r
1413 if (ao->neg_chap) {
\r
1414 LCPDEBUG((LOG_WARNING, "lcp_reqci: Nak AUTHTYPE %d req CHAP\n", cishort));
\r
1415 PUTCHAR(CILEN_CHAP, nakp);
\r
1416 PUTSHORT(PPP_CHAP, nakp);
\r
1417 PUTCHAR(ao->chap_mdtype, nakp);
\r
1419 LCPDEBUG((LOG_WARNING, "lcp_reqci: Nak AUTHTYPE %d req PAP\n", cishort));
\r
1420 PUTCHAR(CILEN_SHORT, nakp);
\r
1421 PUTSHORT(PPP_PAP, nakp);
\r
1426 GETSHORT(cishort, p);
\r
1427 GETLONG(cilong, p);
\r
1429 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " QUALITY (%x %x)", cishort, (unsigned int) cilong);
\r
1430 traceNdx = strlen(traceBuf);
\r
1433 if (!ao->neg_lqr ||
\r
1434 cilen != CILEN_LQR) {
\r
1440 * Check the protocol and the reporting period.
\r
1441 * XXX When should we Nak this, and what with?
\r
1443 if (cishort != PPP_LQR) {
\r
1445 PUTCHAR(CI_QUALITY, nakp);
\r
1446 PUTCHAR(CILEN_LQR, nakp);
\r
1447 PUTSHORT(PPP_LQR, nakp);
\r
1448 PUTLONG(ao->lqr_period, nakp);
\r
1453 case CI_MAGICNUMBER:
\r
1454 if (!(ao->neg_magicnumber || go->neg_magicnumber) ||
\r
1455 cilen != CILEN_LONG) {
\r
1459 GETLONG(cilong, p);
\r
1461 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " MAGICNUMBER (%lX)", cilong);
\r
1462 traceNdx = strlen(traceBuf);
\r
1466 * He must have a different magic number.
\r
1468 if (go->neg_magicnumber &&
\r
1469 cilong == go->magicnumber) {
\r
1470 cilong = magic(); /* Don't put magic() inside macro! */
\r
1472 PUTCHAR(CI_MAGICNUMBER, nakp);
\r
1473 PUTCHAR(CILEN_LONG, nakp);
\r
1474 PUTLONG(cilong, nakp);
\r
1477 ho->neg_magicnumber = 1;
\r
1478 ho->magicnumber = cilong;
\r
1482 case CI_PCOMPRESSION:
\r
1484 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " PCOMPRESSION");
\r
1485 traceNdx = strlen(traceBuf);
\r
1487 if (!ao->neg_pcompression ||
\r
1488 cilen != CILEN_VOID) {
\r
1492 ho->neg_pcompression = 1;
\r
1495 case CI_ACCOMPRESSION:
\r
1497 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " ACCOMPRESSION");
\r
1498 traceNdx = strlen(traceBuf);
\r
1500 if (!ao->neg_accompression ||
\r
1501 cilen != CILEN_VOID) {
\r
1505 ho->neg_accompression = 1;
\r
1510 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " CI_MRRU");
\r
1511 traceNdx = strlen(traceBuf);
\r
1518 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " CI_SSNHF");
\r
1519 traceNdx = strlen(traceBuf);
\r
1526 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " CI_EPDISC");
\r
1527 traceNdx = strlen(traceBuf);
\r
1534 snprintf(&traceBuf[traceNdx], sizeof(traceBuf), " unknown %d", citype);
\r
1535 traceNdx = strlen(traceBuf);
\r
1543 if (traceNdx >= 80 - 32) {
\r
1544 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd%s\n", traceBuf));
\r
1548 if (orc == CONFACK && /* Good CI */
\r
1549 rc != CONFACK) { /* but prior CI wasnt? */
\r
1550 continue; /* Don't send this one */
\r
1553 if (orc == CONFNAK) { /* Nak this CI? */
\r
1554 if (reject_if_disagree /* Getting fed up with sending NAKs? */
\r
1555 && citype != CI_MAGICNUMBER) {
\r
1556 orc = CONFREJ; /* Get tough if so */
\r
1558 if (rc == CONFREJ) { /* Rejecting prior CI? */
\r
1559 continue; /* Don't send this one */
\r
1564 if (orc == CONFREJ) { /* Reject this CI */
\r
1566 if (cip != rejp) { /* Need to move rejected CI? */
\r
1567 BCOPY(cip, rejp, cilen); /* Move it */
\r
1569 INCPTR(cilen, rejp); /* Update output pointer */
\r
1574 * If we wanted to send additional NAKs (for unsent CIs), the
\r
1575 * code would go here. The extra NAKs would go at *nakp.
\r
1576 * At present there are no cases where we want to ask the
\r
1577 * peer to negotiate an option.
\r
1582 *lenp = (int)(next - inp);
\r
1586 * Copy the Nak'd options from the nak_buffer to the caller's buffer.
\r
1588 *lenp = (int)(nakp - nak_buffer);
\r
1589 BCOPY(nak_buffer, inp, *lenp);
\r
1592 *lenp = (int)(rejp - inp);
\r
1597 if (traceNdx > 0) {
\r
1598 LCPDEBUG((LOG_INFO, "lcp_reqci: %s\n", traceBuf));
\r
1601 LCPDEBUG((LOG_INFO, "lcp_reqci: returning CONF%s.\n", CODENAME(rc)));
\r
1602 return (rc); /* Return final code */
\r
1607 * lcp_up - LCP has come UP.
\r
1612 lcp_options *wo = &lcp_wantoptions[f->unit];
\r
1613 lcp_options *ho = &lcp_hisoptions[f->unit];
\r
1614 lcp_options *go = &lcp_gotoptions[f->unit];
\r
1615 lcp_options *ao = &lcp_allowoptions[f->unit];
\r
1617 if (!go->neg_magicnumber) {
\r
1618 go->magicnumber = 0;
\r
1620 if (!ho->neg_magicnumber) {
\r
1621 ho->magicnumber = 0;
\r
1625 * Set our MTU to the smaller of the MTU we wanted and
\r
1626 * the MRU our peer wanted. If we negotiated an MRU,
\r
1627 * set our MRU to the larger of value we wanted and
\r
1628 * the value we got in the negotiation.
\r
1630 ppp_send_config(f->unit, LWIP_MIN(ao->mru, (ho->neg_mru? ho->mru: PPP_MRU)),
\r
1631 (ho->neg_asyncmap? ho->asyncmap: 0xffffffffl),
\r
1632 ho->neg_pcompression, ho->neg_accompression);
\r
1634 * If the asyncmap hasn't been negotiated, we really should
\r
1635 * set the receive asyncmap to ffffffff, but we set it to 0
\r
1636 * for backwards contemptibility.
\r
1638 ppp_recv_config(f->unit, (go->neg_mru? LWIP_MAX(wo->mru, go->mru): PPP_MRU),
\r
1639 (go->neg_asyncmap? go->asyncmap: 0x00000000),
\r
1640 go->neg_pcompression, go->neg_accompression);
\r
1642 if (ho->neg_mru) {
\r
1643 peer_mru[f->unit] = ho->mru;
\r
1646 lcp_echo_lowerup(f->unit); /* Enable echo messages */
\r
1648 link_established(f->unit);
\r
1653 * lcp_down - LCP has gone DOWN.
\r
1655 * Alert other protocols.
\r
1660 lcp_options *go = &lcp_gotoptions[f->unit];
\r
1662 lcp_echo_lowerdown(f->unit);
\r
1664 link_down(f->unit);
\r
1666 ppp_send_config(f->unit, PPP_MRU, 0xffffffffl, 0, 0);
\r
1667 ppp_recv_config(f->unit, PPP_MRU,
\r
1668 (go->neg_asyncmap? go->asyncmap: 0x00000000),
\r
1669 go->neg_pcompression, go->neg_accompression);
\r
1670 peer_mru[f->unit] = PPP_MRU;
\r
1675 * lcp_starting - LCP needs the lower layer up.
\r
1678 lcp_starting(fsm *f)
\r
1680 link_required(f->unit);
\r
1685 * lcp_finished - LCP has finished with the lower layer.
\r
1688 lcp_finished(fsm *f)
\r
1690 link_terminated(f->unit);
\r
1696 * print_string - print a readable representation of a string using
\r
1700 print_string( char *p, int len, void (*printer) (void *, char *, ...), void *arg)
\r
1704 printer(arg, "\"");
\r
1705 for (; len > 0; --len) {
\r
1707 if (' ' <= c && c <= '~') {
\r
1708 if (c == '\\' || c == '"') {
\r
1709 printer(arg, "\\");
\r
1711 printer(arg, "%c", c);
\r
1715 printer(arg, "\\n");
\r
1718 printer(arg, "\\r");
\r
1721 printer(arg, "\\t");
\r
1724 printer(arg, "\\%.3o", c);
\r
1728 printer(arg, "\"");
\r
1733 * lcp_printpkt - print the contents of an LCP packet.
\r
1735 static char *lcp_codenames[] = {
\r
1736 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
\r
1737 "TermReq", "TermAck", "CodeRej", "ProtRej",
\r
1738 "EchoReq", "EchoRep", "DiscReq"
\r
1742 lcp_printpkt( u_char *p, int plen, void (*printer) (void *, char *, ...), void *arg)
\r
1744 int code, id, len, olen;
\r
1745 u_char *pstart, *optend;
\r
1749 if (plen < HEADERLEN) {
\r
1756 if (len < HEADERLEN || len > plen) {
\r
1760 if (code >= 1 && code <= sizeof(lcp_codenames) / sizeof(char *)) {
\r
1761 printer(arg, " %s", lcp_codenames[code-1]);
\r
1763 printer(arg, " code=0x%x", code);
\r
1765 printer(arg, " id=0x%x", id);
\r
1772 /* print option list */
\r
1773 while (len >= 2) {
\r
1777 if (olen < 2 || olen > len) {
\r
1780 printer(arg, " <");
\r
1782 optend = p + olen;
\r
1785 if (olen == CILEN_SHORT) {
\r
1787 GETSHORT(cishort, p);
\r
1788 printer(arg, "mru %d", cishort);
\r
1792 if (olen == CILEN_LONG) {
\r
1794 GETLONG(cilong, p);
\r
1795 printer(arg, "asyncmap 0x%lx", cilong);
\r
1799 if (olen >= CILEN_SHORT) {
\r
1801 printer(arg, "auth ");
\r
1802 GETSHORT(cishort, p);
\r
1803 switch (cishort) {
\r
1805 printer(arg, "pap");
\r
1808 printer(arg, "chap");
\r
1811 printer(arg, "0x%x", cishort);
\r
1816 if (olen >= CILEN_SHORT) {
\r
1818 printer(arg, "quality ");
\r
1819 GETSHORT(cishort, p);
\r
1820 switch (cishort) {
\r
1822 printer(arg, "lqr");
\r
1825 printer(arg, "0x%x", cishort);
\r
1830 if (olen >= CILEN_CHAR) {
\r
1832 printer(arg, "callback ");
\r
1833 GETSHORT(cishort, p);
\r
1834 switch (cishort) {
\r
1836 printer(arg, "CBCP");
\r
1839 printer(arg, "0x%x", cishort);
\r
1843 case CI_MAGICNUMBER:
\r
1844 if (olen == CILEN_LONG) {
\r
1846 GETLONG(cilong, p);
\r
1847 printer(arg, "magic 0x%x", cilong);
\r
1850 case CI_PCOMPRESSION:
\r
1851 if (olen == CILEN_VOID) {
\r
1853 printer(arg, "pcomp");
\r
1856 case CI_ACCOMPRESSION:
\r
1857 if (olen == CILEN_VOID) {
\r
1859 printer(arg, "accomp");
\r
1863 while (p < optend) {
\r
1865 printer(arg, " %.2x", code);
\r
1867 printer(arg, ">");
\r
1873 if (len > 0 && *p >= ' ' && *p < 0x7f) {
\r
1874 printer(arg, " ");
\r
1875 print_string((char*)p, len, printer, arg);
\r
1885 GETLONG(cilong, p);
\r
1886 printer(arg, " magic=0x%x", cilong);
\r
1893 /* print the rest of the bytes in the packet */
\r
1894 for (; len > 0; --len) {
\r
1896 printer(arg, " %.2x", code);
\r
1899 return (int)(p - pstart);
\r
1904 * Time to shut down the link because there is nothing out there.
\r
1907 LcpLinkFailure (fsm *f)
\r
1909 if (f->state == LS_OPENED) {
\r
1910 LCPDEBUG((LOG_INFO, "No response to %d echo-requests\n", lcp_echos_pending));
\r
1911 LCPDEBUG((LOG_NOTICE, "Serial link appears to be disconnected.\n"));
\r
1912 lcp_close(f->unit, "Peer not responding");
\r
1917 * Timer expired for the LCP echo requests from this process.
\r
1920 LcpEchoCheck (fsm *f)
\r
1922 LcpSendEchoRequest (f);
\r
1925 * Start the timer for the next interval.
\r
1927 LWIP_ASSERT("lcp_echo_timer_running == 0", lcp_echo_timer_running == 0);
\r
1929 TIMEOUT (LcpEchoTimeout, f, lcp_echo_interval);
\r
1930 lcp_echo_timer_running = 1;
\r
1934 * LcpEchoTimeout - Timer expired on the LCP echo
\r
1937 LcpEchoTimeout (void *arg)
\r
1939 if (lcp_echo_timer_running != 0) {
\r
1940 lcp_echo_timer_running = 0;
\r
1941 LcpEchoCheck ((fsm *) arg);
\r
1946 * LcpEchoReply - LCP has received a reply to the echo
\r
1949 lcp_received_echo_reply (fsm *f, int id, u_char *inp, int len)
\r
1953 LWIP_UNUSED_ARG(id);
\r
1955 /* Check the magic number - don't count replies from ourselves. */
\r
1957 LCPDEBUG((LOG_WARNING, "lcp: received short Echo-Reply, length %d\n", len));
\r
1960 GETLONG(magic, inp);
\r
1961 if (lcp_gotoptions[f->unit].neg_magicnumber && magic == lcp_gotoptions[f->unit].magicnumber) {
\r
1962 LCPDEBUG((LOG_WARNING, "appear to have received our own echo-reply!\n"));
\r
1966 /* Reset the number of outstanding echo frames */
\r
1967 lcp_echos_pending = 0;
\r
1971 * LcpSendEchoRequest - Send an echo request frame to the peer
\r
1974 LcpSendEchoRequest (fsm *f)
\r
1977 u_char pkt[4], *pktp;
\r
1980 * Detect the failure of the peer at this point.
\r
1982 if (lcp_echo_fails != 0) {
\r
1983 if (lcp_echos_pending++ >= lcp_echo_fails) {
\r
1984 LcpLinkFailure(f);
\r
1985 lcp_echos_pending = 0;
\r
1990 * Make and send the echo request frame.
\r
1992 if (f->state == LS_OPENED) {
\r
1993 lcp_magic = lcp_gotoptions[f->unit].magicnumber;
\r
1995 PUTLONG(lcp_magic, pktp);
\r
1996 fsm_sdata(f, ECHOREQ, (u_char)(lcp_echo_number++ & 0xFF), pkt, (int)(pktp - pkt));
\r
2001 * lcp_echo_lowerup - Start the timer for the LCP frame
\r
2005 lcp_echo_lowerup (int unit)
\r
2007 fsm *f = &lcp_fsm[unit];
\r
2009 /* Clear the parameters for generating echo frames */
\r
2010 lcp_echos_pending = 0;
\r
2011 lcp_echo_number = 0;
\r
2012 lcp_echo_timer_running = 0;
\r
2014 /* If a timeout interval is specified then start the timer */
\r
2015 if (lcp_echo_interval != 0) {
\r
2021 * lcp_echo_lowerdown - Stop the timer for the LCP frame
\r
2025 lcp_echo_lowerdown (int unit)
\r
2027 fsm *f = &lcp_fsm[unit];
\r
2029 if (lcp_echo_timer_running != 0) {
\r
2030 UNTIMEOUT (LcpEchoTimeout, f);
\r
2031 lcp_echo_timer_running = 0;
\r
2035 #endif /* PPP_SUPPORT */
\r