1 /*****************************************************************************
2 * lcp.c - Network Link Control Protocol program file.
4 * Copyright (c) 2003 by Marc Boucher, Services Informatiques (MBSI) inc.
5 * portions Copyright (c) 1997 by Global Election Systems Inc.
7 * The authors hereby grant permission to use, copy, modify, distribute,
8 * and license this software and its documentation for any purpose, provided
9 * that existing copyright notices are retained in all copies and that this
10 * notice and the following disclaimer are included verbatim in any
11 * distributions. No written agreement, license, or royalty fee is required
12 * for any of the authorized uses.
14 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS *AS IS* AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 ******************************************************************************
28 * 03-01-01 Marc Boucher <marc@mbsi.ca>
30 * 97-12-01 Guy Lancaster <lancasterg@acm.org>, Global Election Systems Inc.
32 *****************************************************************************/
35 * lcp.c - PPP Link Control Protocol.
37 * Copyright (c) 1989 Carnegie Mellon University.
38 * All rights reserved.
40 * Redistribution and use in source and binary forms are permitted
41 * provided that the above copyright notice and this paragraph are
42 * duplicated in all such forms and that any documentation,
43 * advertising materials, and other materials related to such
44 * distribution and use acknowledge that the software was developed
45 * by Carnegie Mellon University. The name of the
46 * University may not be used to endorse or promote products derived
47 * from this software without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
49 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
50 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
65 /*************************/
66 /*** LOCAL DEFINITIONS ***/
67 /*************************/
69 * Length of each type of configuration option (in octets)
73 #define CILEN_SHORT 4 /* CILEN_VOID + sizeof(short) */
74 #define CILEN_CHAP 5 /* CILEN_VOID + sizeof(short) + 1 */
75 #define CILEN_LONG 6 /* CILEN_VOID + sizeof(long) */
76 #define CILEN_LQR 8 /* CILEN_VOID + sizeof(short) + sizeof(long) */
80 /***********************************/
81 /*** LOCAL FUNCTION DECLARATIONS ***/
82 /***********************************/
84 * Callbacks for fsm code. (CI = Configuration Information)
86 static void lcp_resetci (fsm
*); /* Reset our CI */
87 static int lcp_cilen (fsm
*); /* Return length of our CI */
88 static void lcp_addci (fsm
*, u_char
*, int*); /* Add our CI to pkt */
89 static int lcp_ackci (fsm
*, u_char
*, int);/* Peer ack'd our CI */
90 static int lcp_nakci (fsm
*, u_char
*, int);/* Peer nak'd our CI */
91 static int lcp_rejci (fsm
*, u_char
*, int);/* Peer rej'd our CI */
92 static int lcp_reqci (fsm
*, u_char
*, int*, int); /* Rcv peer CI */
93 static void lcp_up (fsm
*); /* We're UP */
94 static void lcp_down (fsm
*); /* We're DOWN */
95 static void lcp_starting (fsm
*); /* We need lower layer up */
96 static void lcp_finished (fsm
*); /* We need lower layer down */
97 static int lcp_extcode (fsm
*, int, u_char
, u_char
*, int);
99 static void lcp_rprotrej (fsm
*, u_char
*, int);
102 * routines to send LCP echos to peer
104 static void lcp_echo_lowerup (int);
105 static void lcp_echo_lowerdown (int);
106 static void LcpEchoTimeout (void*);
107 static void lcp_received_echo_reply (fsm
*, int, u_char
*, int);
108 static void LcpSendEchoRequest (fsm
*);
109 static void LcpLinkFailure (fsm
*);
110 static void LcpEchoCheck (fsm
*);
113 * Protocol entry points.
114 * Some of these are called directly.
116 static void lcp_input (int, u_char
*, int);
117 static void lcp_protrej (int);
119 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
120 (x) == CONFNAK ? "NAK" : "REJ")
123 /******************************/
124 /*** PUBLIC DATA STRUCTURES ***/
125 /******************************/
127 LinkPhase lcp_phase
[NUM_PPP
]; /* Phase of link session (RFC 1661) */
128 lcp_options lcp_wantoptions
[NUM_PPP
]; /* Options that we want to request */
129 lcp_options lcp_gotoptions
[NUM_PPP
]; /* Options that peer ack'd */
130 lcp_options lcp_allowoptions
[NUM_PPP
]; /* Options we allow peer to request */
131 lcp_options lcp_hisoptions
[NUM_PPP
]; /* Options that we ack'd */
132 ext_accm xmit_accm
[NUM_PPP
]; /* extended transmit ACCM */
136 /*****************************/
137 /*** LOCAL DATA STRUCTURES ***/
138 /*****************************/
139 static fsm lcp_fsm
[NUM_PPP
]; /* LCP fsm structure (global)*/
140 static u_int lcp_echo_interval
= LCP_ECHOINTERVAL
; /* Interval between LCP echo-requests */
141 static u_int lcp_echo_fails
= LCP_MAXECHOFAILS
; /* Tolerance to unanswered echo-requests */
142 static u32_t lcp_echos_pending
= 0; /* Number of outstanding echo msgs */
143 static u32_t lcp_echo_number
= 0; /* ID number of next echo frame */
144 static u32_t lcp_echo_timer_running
= 0; /* TRUE if a timer is running */
146 static u_char nak_buffer
[PPP_MRU
]; /* where we construct a nak packet */
148 static fsm_callbacks lcp_callbacks
= { /* LCP callback routines */
149 lcp_resetci
, /* Reset our Configuration Information */
150 lcp_cilen
, /* Length of our Configuration Information */
151 lcp_addci
, /* Add our Configuration Information */
152 lcp_ackci
, /* ACK our Configuration Information */
153 lcp_nakci
, /* NAK our Configuration Information */
154 lcp_rejci
, /* Reject our Configuration Information */
155 lcp_reqci
, /* Request peer's Configuration Information */
156 lcp_up
, /* Called when fsm reaches OPENED state */
157 lcp_down
, /* Called when fsm leaves OPENED state */
158 lcp_starting
, /* Called when we want the lower layer up */
159 lcp_finished
, /* Called when we want the lower layer down */
160 NULL
, /* Called when Protocol-Reject received */
161 NULL
, /* Retransmission is necessary */
162 lcp_extcode
, /* Called to handle LCP-specific codes */
163 "LCP" /* String name of protocol */
166 struct protent lcp_protent
= {
188 int lcp_loopbackfail
= DEFLOOPBACKFAIL
;
192 /***********************************/
193 /*** PUBLIC FUNCTION DEFINITIONS ***/
194 /***********************************/
196 * lcp_init - Initialize LCP.
198 void lcp_init(int unit
)
200 fsm
*f
= &lcp_fsm
[unit
];
201 lcp_options
*wo
= &lcp_wantoptions
[unit
];
202 lcp_options
*ao
= &lcp_allowoptions
[unit
];
205 f
->protocol
= PPP_LCP
;
206 f
->callbacks
= &lcp_callbacks
;
212 wo
->restart
= 0; /* Set to 1 in kernels or multi-line
215 wo
->mru
= PPP_DEFMRU
;
216 wo
->neg_asyncmap
= 1;
217 wo
->asyncmap
= 0x00000000l
; /* Assume don't need to escape any ctl chars. */
218 wo
->neg_chap
= 0; /* Set to 1 on server */
219 wo
->neg_upap
= 0; /* Set to 1 on server */
220 wo
->chap_mdtype
= CHAP_DIGEST_MD5
;
221 wo
->neg_magicnumber
= 1;
222 wo
->neg_pcompression
= 1;
223 wo
->neg_accompression
= 1;
224 wo
->neg_lqr
= 0; /* no LQR implementation yet */
228 ao
->mru
= PPP_MAXMRU
;
229 ao
->neg_asyncmap
= 1;
230 ao
->asyncmap
= 0x00000000l
; /* Assume don't need to escape any ctl chars. */
231 ao
->neg_chap
= (CHAP_SUPPORT
!= 0);
232 ao
->chap_mdtype
= CHAP_DIGEST_MD5
;
233 ao
->neg_upap
= (PAP_SUPPORT
!= 0);
234 ao
->neg_magicnumber
= 1;
235 ao
->neg_pcompression
= 1;
236 ao
->neg_accompression
= 1;
237 ao
->neg_lqr
= 0; /* no LQR implementation yet */
238 ao
->neg_cbcp
= (CBCP_SUPPORT
!= 0);
241 * Set transmit escape for the flag and escape characters plus anything
242 * set for the allowable options.
244 memset(xmit_accm
[unit
], 0, sizeof(xmit_accm
[0]));
245 xmit_accm
[unit
][15] = 0x60;
246 xmit_accm
[unit
][0] = (u_char
)(ao
->asyncmap
& 0xFF);
247 xmit_accm
[unit
][1] = (u_char
)((ao
->asyncmap
>> 8) & 0xFF);
248 xmit_accm
[unit
][2] = (u_char
)((ao
->asyncmap
>> 16) & 0xFF);
249 xmit_accm
[unit
][3] = (u_char
)((ao
->asyncmap
>> 24) & 0xFF);
250 LCPDEBUG((LOG_INFO
, "lcp_init: xmit_accm=%X %X %X %X\n",
254 xmit_accm
[unit
][3]));
256 lcp_phase
[unit
] = PHASE_INITIALIZE
;
261 * lcp_open - LCP is allowed to come up.
263 void lcp_open(int unit
)
265 fsm
*f
= &lcp_fsm
[unit
];
266 lcp_options
*wo
= &lcp_wantoptions
[unit
];
270 f
->flags
|= OPT_PASSIVE
;
272 f
->flags
|= OPT_SILENT
;
275 lcp_phase
[unit
] = PHASE_ESTABLISH
;
280 * lcp_close - Take LCP down.
282 void lcp_close(int unit
, char *reason
)
284 fsm
*f
= &lcp_fsm
[unit
];
286 if (lcp_phase
[unit
] != PHASE_DEAD
)
287 lcp_phase
[unit
] = PHASE_TERMINATE
;
288 if (f
->state
== STOPPED
&& f
->flags
& (OPT_PASSIVE
|OPT_SILENT
)) {
290 * This action is not strictly according to the FSM in RFC1548,
291 * but it does mean that the program terminates if you do an
292 * lcp_close() in passive/silent mode when a connection hasn't
299 fsm_close(&lcp_fsm
[unit
], reason
);
304 * lcp_lowerup - The lower layer is up.
306 void lcp_lowerup(int unit
)
308 lcp_options
*wo
= &lcp_wantoptions
[unit
];
311 * Don't use A/C or protocol compression on transmission,
312 * but accept A/C and protocol compressed packets
313 * if we are going to ask for A/C and protocol compression.
315 ppp_set_xaccm(unit
, &xmit_accm
[unit
]);
316 ppp_send_config(unit
, PPP_MRU
, 0xffffffffl
, 0, 0);
317 ppp_recv_config(unit
, PPP_MRU
, 0x00000000l
,
318 wo
->neg_pcompression
, wo
->neg_accompression
);
319 peer_mru
[unit
] = PPP_MRU
;
320 lcp_allowoptions
[unit
].asyncmap
321 = (u_long
)xmit_accm
[unit
][0]
322 | ((u_long
)xmit_accm
[unit
][1] << 8)
323 | ((u_long
)xmit_accm
[unit
][2] << 16)
324 | ((u_long
)xmit_accm
[unit
][3] << 24);
325 LCPDEBUG((LOG_INFO
, "lcp_lowerup: asyncmap=%X %X %X %X\n",
329 xmit_accm
[unit
][0]));
331 fsm_lowerup(&lcp_fsm
[unit
]);
336 * lcp_lowerdown - The lower layer is down.
338 void lcp_lowerdown(int unit
)
340 fsm_lowerdown(&lcp_fsm
[unit
]);
344 * lcp_sprotrej - Send a Protocol-Reject for some protocol.
346 void lcp_sprotrej(int unit
, u_char
*p
, int len
)
349 * Send back the protocol and the information field of the
350 * rejected packet. We only get here if LCP is in the OPENED state.
353 fsm_sdata(&lcp_fsm
[unit
], PROTREJ
, ++lcp_fsm
[unit
].id
,
359 /**********************************/
360 /*** LOCAL FUNCTION DEFINITIONS ***/
361 /**********************************/
363 * lcp_input - Input LCP packet.
365 static void lcp_input(int unit
, u_char
*p
, int len
)
367 fsm
*f
= &lcp_fsm
[unit
];
369 fsm_input(f
, p
, len
);
374 * lcp_extcode - Handle a LCP-specific code.
376 static int lcp_extcode(fsm
*f
, int code
, u_char id
, u_char
*inp
, int len
)
382 lcp_rprotrej(f
, inp
, len
);
386 if (f
->state
!= OPENED
)
388 LCPDEBUG((LOG_INFO
, "lcp: Echo-Request, Rcvd id %d\n", id
));
390 PUTLONG(lcp_gotoptions
[f
->unit
].magicnumber
, magp
);
391 fsm_sdata(f
, ECHOREP
, id
, inp
, len
);
395 lcp_received_echo_reply(f
, id
, inp
, len
);
409 * lcp_rprotrej - Receive an Protocol-Reject.
411 * Figure out which protocol is rejected and inform it.
413 static void lcp_rprotrej(fsm
*f
, u_char
*inp
, int len
)
416 struct protent
*protp
;
419 if (len
< sizeof (u_short
)) {
421 "lcp_rprotrej: Rcvd short Protocol-Reject packet!\n"));
428 "lcp_rprotrej: Rcvd Protocol-Reject packet for %x!\n",
432 * Protocol-Reject packets received in any state other than the LCP
433 * OPENED state SHOULD be silently discarded.
435 if( f
->state
!= OPENED
){
436 LCPDEBUG((LOG_INFO
, "Protocol-Reject discarded: LCP in state %d\n",
442 * Upcall the proper Protocol-Reject routine.
444 for (i
= 0; (protp
= ppp_protocols
[i
]) != NULL
; ++i
)
445 if (protp
->protocol
== prot
&& protp
->enabled_flag
) {
446 (*protp
->protrej
)(f
->unit
);
450 LCPDEBUG((LOG_WARNING
, "Protocol-Reject for unsupported protocol 0x%x\n",
456 * lcp_protrej - A Protocol-Reject was received.
458 static void lcp_protrej(int unit
)
464 LCPDEBUG((LOG_WARNING
,
465 "lcp_protrej: Received Protocol-Reject for LCP!\n"));
466 fsm_protreject(&lcp_fsm
[unit
]);
471 * lcp_resetci - Reset our CI.
473 static void lcp_resetci(fsm
*f
)
475 lcp_wantoptions
[f
->unit
].magicnumber
= magic();
476 lcp_wantoptions
[f
->unit
].numloops
= 0;
477 lcp_gotoptions
[f
->unit
] = lcp_wantoptions
[f
->unit
];
478 peer_mru
[f
->unit
] = PPP_MRU
;
484 * lcp_cilen - Return length of our CI.
486 static int lcp_cilen(fsm
*f
)
488 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
490 #define LENCIVOID(neg) ((neg) ? CILEN_VOID : 0)
491 #define LENCICHAP(neg) ((neg) ? CILEN_CHAP : 0)
492 #define LENCISHORT(neg) ((neg) ? CILEN_SHORT : 0)
493 #define LENCILONG(neg) ((neg) ? CILEN_LONG : 0)
494 #define LENCILQR(neg) ((neg) ? CILEN_LQR: 0)
495 #define LENCICBCP(neg) ((neg) ? CILEN_CBCP: 0)
497 * NB: we only ask for one of CHAP and UPAP, even if we will
500 return (LENCISHORT(go
->neg_mru
&& go
->mru
!= PPP_DEFMRU
) +
501 LENCILONG(go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFFl
) +
502 LENCICHAP(go
->neg_chap
) +
503 LENCISHORT(!go
->neg_chap
&& go
->neg_upap
) +
504 LENCILQR(go
->neg_lqr
) +
505 LENCICBCP(go
->neg_cbcp
) +
506 LENCILONG(go
->neg_magicnumber
) +
507 LENCIVOID(go
->neg_pcompression
) +
508 LENCIVOID(go
->neg_accompression
));
513 * lcp_addci - Add our desired CIs to a packet.
515 static void lcp_addci(fsm
*f
, u_char
*ucp
, int *lenp
)
517 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
518 u_char
*start_ucp
= ucp
;
520 #define ADDCIVOID(opt, neg) \
522 LCPDEBUG((LOG_INFO, "lcp_addci: opt=%d\n", opt)); \
524 PUTCHAR(CILEN_VOID, ucp); \
526 #define ADDCISHORT(opt, neg, val) \
528 LCPDEBUG((LOG_INFO, "lcp_addci: INT opt=%d %X\n", opt, val)); \
530 PUTCHAR(CILEN_SHORT, ucp); \
531 PUTSHORT(val, ucp); \
533 #define ADDCICHAP(opt, neg, val, digest) \
535 LCPDEBUG((LOG_INFO, "lcp_addci: CHAP opt=%d %X\n", opt, val)); \
537 PUTCHAR(CILEN_CHAP, ucp); \
538 PUTSHORT(val, ucp); \
539 PUTCHAR(digest, ucp); \
541 #define ADDCILONG(opt, neg, val) \
543 LCPDEBUG((LOG_INFO, "lcp_addci: L opt=%d %lX\n", opt, val)); \
545 PUTCHAR(CILEN_LONG, ucp); \
548 #define ADDCILQR(opt, neg, val) \
550 LCPDEBUG((LOG_INFO, "lcp_addci: LQR opt=%d %lX\n", opt, val)); \
552 PUTCHAR(CILEN_LQR, ucp); \
553 PUTSHORT(PPP_LQR, ucp); \
556 #define ADDCICHAR(opt, neg, val) \
558 LCPDEBUG((LOG_INFO, "lcp_addci: CHAR opt=%d %X '%z'\n", opt, val, val)); \
560 PUTCHAR(CILEN_CHAR, ucp); \
564 ADDCISHORT(CI_MRU
, go
->neg_mru
&& go
->mru
!= PPP_DEFMRU
, go
->mru
);
565 ADDCILONG(CI_ASYNCMAP
, go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFFl
,
567 ADDCICHAP(CI_AUTHTYPE
, go
->neg_chap
, PPP_CHAP
, go
->chap_mdtype
);
568 ADDCISHORT(CI_AUTHTYPE
, !go
->neg_chap
&& go
->neg_upap
, PPP_PAP
);
569 ADDCILQR(CI_QUALITY
, go
->neg_lqr
, go
->lqr_period
);
570 ADDCICHAR(CI_CALLBACK
, go
->neg_cbcp
, CBCP_OPT
);
571 ADDCILONG(CI_MAGICNUMBER
, go
->neg_magicnumber
, go
->magicnumber
);
572 ADDCIVOID(CI_PCOMPRESSION
, go
->neg_pcompression
);
573 ADDCIVOID(CI_ACCOMPRESSION
, go
->neg_accompression
);
575 if (ucp
- start_ucp
!= *lenp
) {
576 /* this should never happen, because peer_mtu should be 1500 */
577 LCPDEBUG((LOG_ERR
, "Bug in lcp_addci: wrong length\n"));
583 * lcp_ackci - Ack our CIs.
584 * This should not modify any state if the Ack is bad.
590 static int lcp_ackci(fsm
*f
, u_char
*p
, int len
)
592 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
593 u_char cilen
, citype
, cichar
;
598 * CIs must be in exactly the same order that we sent.
599 * Check packet length and CI length at each step.
600 * If we find any deviations, then this packet is bad.
602 #define ACKCIVOID(opt, neg) \
604 if ((len -= CILEN_VOID) < 0) \
606 GETCHAR(citype, p); \
608 if (cilen != CILEN_VOID || \
612 #define ACKCISHORT(opt, neg, val) \
614 if ((len -= CILEN_SHORT) < 0) \
616 GETCHAR(citype, p); \
618 if (cilen != CILEN_SHORT || \
621 GETSHORT(cishort, p); \
622 if (cishort != val) \
625 #define ACKCICHAR(opt, neg, val) \
627 if ((len -= CILEN_CHAR) < 0) \
629 GETCHAR(citype, p); \
631 if (cilen != CILEN_CHAR || \
634 GETCHAR(cichar, p); \
638 #define ACKCICHAP(opt, neg, val, digest) \
640 if ((len -= CILEN_CHAP) < 0) \
642 GETCHAR(citype, p); \
644 if (cilen != CILEN_CHAP || \
647 GETSHORT(cishort, p); \
648 if (cishort != val) \
650 GETCHAR(cichar, p); \
651 if (cichar != digest) \
654 #define ACKCILONG(opt, neg, val) \
656 if ((len -= CILEN_LONG) < 0) \
658 GETCHAR(citype, p); \
660 if (cilen != CILEN_LONG || \
663 GETLONG(cilong, p); \
667 #define ACKCILQR(opt, neg, val) \
669 if ((len -= CILEN_LQR) < 0) \
671 GETCHAR(citype, p); \
673 if (cilen != CILEN_LQR || \
676 GETSHORT(cishort, p); \
677 if (cishort != PPP_LQR) \
679 GETLONG(cilong, p); \
684 ACKCISHORT(CI_MRU
, go
->neg_mru
&& go
->mru
!= PPP_DEFMRU
, go
->mru
);
685 ACKCILONG(CI_ASYNCMAP
, go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFFl
,
687 ACKCICHAP(CI_AUTHTYPE
, go
->neg_chap
, PPP_CHAP
, go
->chap_mdtype
);
688 ACKCISHORT(CI_AUTHTYPE
, !go
->neg_chap
&& go
->neg_upap
, PPP_PAP
);
689 ACKCILQR(CI_QUALITY
, go
->neg_lqr
, go
->lqr_period
);
690 ACKCICHAR(CI_CALLBACK
, go
->neg_cbcp
, CBCP_OPT
);
691 ACKCILONG(CI_MAGICNUMBER
, go
->neg_magicnumber
, go
->magicnumber
);
692 ACKCIVOID(CI_PCOMPRESSION
, go
->neg_pcompression
);
693 ACKCIVOID(CI_ACCOMPRESSION
, go
->neg_accompression
);
696 * If there are any remaining CIs, then this packet is bad.
700 LCPDEBUG((LOG_INFO
, "lcp_acki: Ack\n"));
703 LCPDEBUG((LOG_WARNING
, "lcp_acki: received bad Ack!\n"));
709 * lcp_nakci - Peer has sent a NAK for some of our CIs.
710 * This should not modify any state if the Nak is bad
711 * or if LCP is in the OPENED state.
717 static int lcp_nakci(fsm
*f
, u_char
*p
, int len
)
719 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
720 lcp_options
*wo
= &lcp_wantoptions
[f
->unit
];
721 u_char citype
, cichar
, *next
;
724 lcp_options no
; /* options we've seen Naks for */
725 lcp_options
try; /* options to request next time */
729 BZERO(&no
, sizeof(no
));
733 * Any Nak'd CIs must be in exactly the same order that we sent.
734 * Check packet length and CI length at each step.
735 * If we find any deviations, then this packet is bad.
737 #define NAKCIVOID(opt, neg, code) \
739 len >= CILEN_VOID && \
740 p[1] == CILEN_VOID && \
743 INCPTR(CILEN_VOID, p); \
747 #define NAKCICHAP(opt, neg, code) \
749 len >= CILEN_CHAP && \
750 p[1] == CILEN_CHAP && \
754 GETSHORT(cishort, p); \
755 GETCHAR(cichar, p); \
759 #define NAKCICHAR(opt, neg, code) \
761 len >= CILEN_CHAR && \
762 p[1] == CILEN_CHAR && \
766 GETCHAR(cichar, p); \
770 #define NAKCISHORT(opt, neg, code) \
772 len >= CILEN_SHORT && \
773 p[1] == CILEN_SHORT && \
775 len -= CILEN_SHORT; \
777 GETSHORT(cishort, p); \
781 #define NAKCILONG(opt, neg, code) \
783 len >= CILEN_LONG && \
784 p[1] == CILEN_LONG && \
788 GETLONG(cilong, p); \
792 #define NAKCILQR(opt, neg, code) \
794 len >= CILEN_LQR && \
795 p[1] == CILEN_LQR && \
799 GETSHORT(cishort, p); \
800 GETLONG(cilong, p); \
806 * We don't care if they want to send us smaller packets than
807 * we want. Therefore, accept any MRU less than what we asked for,
808 * but then ignore the new value when setting the MRU in the kernel.
809 * If they send us a bigger MRU than what we asked, accept it, up to
810 * the limit of the default MRU we'd get if we didn't negotiate.
812 if (go
->neg_mru
&& go
->mru
!= PPP_DEFMRU
) {
813 NAKCISHORT(CI_MRU
, neg_mru
,
814 if (cishort
<= wo
->mru
|| cishort
< PPP_DEFMRU
)
820 * Add any characters they want to our (receive-side) asyncmap.
822 if (go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFFl
) {
823 NAKCILONG(CI_ASYNCMAP
, neg_asyncmap
,
824 try.asyncmap
= go
->asyncmap
| cilong
;
829 * If they've nak'd our authentication-protocol, check whether
830 * they are proposing a different protocol, or a different
831 * hash algorithm for CHAP.
833 if ((go
->neg_chap
|| go
->neg_upap
)
834 && len
>= CILEN_SHORT
835 && p
[0] == CI_AUTHTYPE
&& p
[1] >= CILEN_SHORT
&& p
[1] <= len
) {
838 no
.neg_chap
= go
->neg_chap
;
839 no
.neg_upap
= go
->neg_upap
;
841 GETSHORT(cishort
, p
);
842 if (cishort
== PPP_PAP
&& cilen
== CILEN_SHORT
) {
844 * If we were asking for CHAP, they obviously don't want to do it.
845 * If we weren't asking for CHAP, then we were asking for PAP,
846 * in which case this Nak is bad.
852 } else if (cishort
== PPP_CHAP
&& cilen
== CILEN_CHAP
) {
856 * We were asking for CHAP/MD5; they must want a different
857 * algorithm. If they can't do MD5, we'll have to stop
860 if (cichar
!= go
->chap_mdtype
)
864 * Stop asking for PAP if we were asking for it.
871 * We don't recognize what they're suggesting.
872 * Stop asking for what we were asking for.
878 p
+= cilen
- CILEN_SHORT
;
883 * If they can't cope with our link quality protocol, we'll have
884 * to stop asking for LQR. We haven't got any other protocol.
885 * If they Nak the reporting period, take their value XXX ?
887 NAKCILQR(CI_QUALITY
, neg_lqr
,
888 if (cishort
!= PPP_LQR
)
891 try.lqr_period
= cilong
;
895 * Only implementing CBCP...not the rest of the callback options
897 NAKCICHAR(CI_CALLBACK
, neg_cbcp
,
902 * Check for a looped-back line.
904 NAKCILONG(CI_MAGICNUMBER
, neg_magicnumber
,
905 try.magicnumber
= magic();
910 * Peer shouldn't send Nak for protocol compression or
911 * address/control compression requests; they should send
912 * a Reject instead. If they send a Nak, treat it as a Reject.
914 NAKCIVOID(CI_PCOMPRESSION
, neg_pcompression
,
915 try.neg_pcompression
= 0;
917 NAKCIVOID(CI_ACCOMPRESSION
, neg_accompression
,
918 try.neg_accompression
= 0;
922 * There may be remaining CIs, if the peer is requesting negotiation
923 * on an option that we didn't include in our request packet.
924 * If we see an option that we requested, or one we've already seen
925 * in this packet, then this packet is bad.
926 * If we wanted to respond by starting to negotiate on the requested
927 * option(s), we could, but we don't, because except for the
928 * authentication type and quality protocol, if we are not negotiating
929 * an option, it is because we were told not to.
930 * For the authentication type, the Nak from the peer means
931 * `let me authenticate myself with you' which is a bit pointless.
932 * For the quality protocol, the Nak means `ask me to send you quality
933 * reports', but if we didn't ask for them, we don't want them.
934 * An option we don't recognize represents the peer asking to
935 * negotiate some option we don't support, so ignore it.
937 while (len
> CILEN_VOID
) {
940 if (cilen
< CILEN_VOID
|| (len
-= cilen
) < 0)
942 next
= p
+ cilen
- 2;
946 if ((go
->neg_mru
&& go
->mru
!= PPP_DEFMRU
)
947 || no
.neg_mru
|| cilen
!= CILEN_SHORT
)
949 GETSHORT(cishort
, p
);
950 if (cishort
< PPP_DEFMRU
)
954 if ((go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFFl
)
955 || no
.neg_asyncmap
|| cilen
!= CILEN_LONG
)
959 if (go
->neg_chap
|| no
.neg_chap
|| go
->neg_upap
|| no
.neg_upap
)
963 if (go
->neg_magicnumber
|| no
.neg_magicnumber
||
967 case CI_PCOMPRESSION
:
968 if (go
->neg_pcompression
|| no
.neg_pcompression
969 || cilen
!= CILEN_VOID
)
972 case CI_ACCOMPRESSION
:
973 if (go
->neg_accompression
|| no
.neg_accompression
974 || cilen
!= CILEN_VOID
)
978 if (go
->neg_lqr
|| no
.neg_lqr
|| cilen
!= CILEN_LQR
)
985 /* If there is still anything left, this packet is bad. */
990 * OK, the Nak is good. Now we can update state.
992 if (f
->state
!= OPENED
) {
994 if (++try.numloops
>= lcp_loopbackfail
) {
995 LCPDEBUG((LOG_NOTICE
, "Serial line is looped back.\n"));
996 lcp_close(f
->unit
, "Loopback detected");
1007 LCPDEBUG((LOG_WARNING
, "lcp_nakci: received bad Nak!\n"));
1013 * lcp_rejci - Peer has Rejected some of our CIs.
1014 * This should not modify any state if the Reject is bad
1015 * or if LCP is in the OPENED state.
1018 * 0 - Reject was bad.
1019 * 1 - Reject was good.
1021 static int lcp_rejci(fsm
*f
, u_char
*p
, int len
)
1023 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
1027 lcp_options
try; /* options to request next time */
1032 * Any Rejected CIs must be in exactly the same order that we sent.
1033 * Check packet length and CI length at each step.
1034 * If we find any deviations, then this packet is bad.
1036 #define REJCIVOID(opt, neg) \
1038 len >= CILEN_VOID && \
1039 p[1] == CILEN_VOID && \
1041 len -= CILEN_VOID; \
1042 INCPTR(CILEN_VOID, p); \
1044 LCPDEBUG((LOG_INFO, "lcp_rejci: void opt %d rejected\n", opt)); \
1046 #define REJCISHORT(opt, neg, val) \
1048 len >= CILEN_SHORT && \
1049 p[1] == CILEN_SHORT && \
1051 len -= CILEN_SHORT; \
1053 GETSHORT(cishort, p); \
1054 /* Check rejected value. */ \
1055 if (cishort != val) \
1058 LCPDEBUG((LOG_INFO,"lcp_rejci: short opt %d rejected\n", opt)); \
1060 #define REJCICHAP(opt, neg, val, digest) \
1062 len >= CILEN_CHAP && \
1063 p[1] == CILEN_CHAP && \
1065 len -= CILEN_CHAP; \
1067 GETSHORT(cishort, p); \
1068 GETCHAR(cichar, p); \
1069 /* Check rejected value. */ \
1070 if (cishort != val || cichar != digest) \
1074 LCPDEBUG((LOG_INFO,"lcp_rejci: chap opt %d rejected\n", opt)); \
1076 #define REJCILONG(opt, neg, val) \
1078 len >= CILEN_LONG && \
1079 p[1] == CILEN_LONG && \
1081 len -= CILEN_LONG; \
1083 GETLONG(cilong, p); \
1084 /* Check rejected value. */ \
1085 if (cilong != val) \
1088 LCPDEBUG((LOG_INFO,"lcp_rejci: long opt %d rejected\n", opt)); \
1090 #define REJCILQR(opt, neg, val) \
1092 len >= CILEN_LQR && \
1093 p[1] == CILEN_LQR && \
1097 GETSHORT(cishort, p); \
1098 GETLONG(cilong, p); \
1099 /* Check rejected value. */ \
1100 if (cishort != PPP_LQR || cilong != val) \
1103 LCPDEBUG((LOG_INFO,"lcp_rejci: LQR opt %d rejected\n", opt)); \
1105 #define REJCICBCP(opt, neg, val) \
1107 len >= CILEN_CBCP && \
1108 p[1] == CILEN_CBCP && \
1110 len -= CILEN_CBCP; \
1112 GETCHAR(cichar, p); \
1113 /* Check rejected value. */ \
1114 if (cichar != val) \
1117 LCPDEBUG((LOG_INFO,"lcp_rejci: Callback opt %d rejected\n", opt)); \
1120 REJCISHORT(CI_MRU
, neg_mru
, go
->mru
);
1121 REJCILONG(CI_ASYNCMAP
, neg_asyncmap
, go
->asyncmap
);
1122 REJCICHAP(CI_AUTHTYPE
, neg_chap
, PPP_CHAP
, go
->chap_mdtype
);
1123 if (!go
->neg_chap
) {
1124 REJCISHORT(CI_AUTHTYPE
, neg_upap
, PPP_PAP
);
1126 REJCILQR(CI_QUALITY
, neg_lqr
, go
->lqr_period
);
1127 REJCICBCP(CI_CALLBACK
, neg_cbcp
, CBCP_OPT
);
1128 REJCILONG(CI_MAGICNUMBER
, neg_magicnumber
, go
->magicnumber
);
1129 REJCIVOID(CI_PCOMPRESSION
, neg_pcompression
);
1130 REJCIVOID(CI_ACCOMPRESSION
, neg_accompression
);
1133 * If there are any remaining CIs, then this packet is bad.
1138 * Now we can update state.
1140 if (f
->state
!= OPENED
)
1145 LCPDEBUG((LOG_WARNING
, "lcp_rejci: received bad Reject!\n"));
1151 * lcp_reqci - Check the peer's requested CIs and send appropriate response.
1153 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
1154 * appropriately. If reject_if_disagree is non-zero, doesn't return
1155 * CONFNAK; returns CONFREJ if it can't return CONFACK.
1157 static int lcp_reqci(fsm
*f
,
1158 u_char
*inp
, /* Requested CIs */
1159 int *lenp
, /* Length of requested CIs */
1160 int reject_if_disagree
)
1162 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
1163 lcp_options
*ho
= &lcp_hisoptions
[f
->unit
];
1164 lcp_options
*ao
= &lcp_allowoptions
[f
->unit
];
1165 u_char
*cip
, *next
; /* Pointer to current and next CIs */
1166 int cilen
, citype
, cichar
; /* Parsed len, type, char value */
1167 u_short cishort
; /* Parsed short value */
1168 u32_t cilong
; /* Parse long value */
1169 int rc
= CONFACK
; /* Final packet return code */
1170 int orc
; /* Individual option return code */
1171 u_char
*p
; /* Pointer to next char to parse */
1172 u_char
*rejp
; /* Pointer to next char in reject frame */
1173 u_char
*nakp
; /* Pointer to next char in Nak frame */
1174 int l
= *lenp
; /* Length left */
1181 * Reset all his options.
1183 BZERO(ho
, sizeof(*ho
));
1186 * Process all his options.
1192 orc
= CONFACK
; /* Assume success */
1193 cip
= p
= next
; /* Remember begining of CI */
1194 if (l
< 2 || /* Not enough data for CI header or */
1195 p
[1] < 2 || /* CI length too small or */
1196 p
[1] > l
) { /* CI length too big? */
1197 LCPDEBUG((LOG_WARNING
, "lcp_reqci: bad CI length!\n"));
1198 orc
= CONFREJ
; /* Reject bad CI */
1199 cilen
= l
; /* Reject till end of packet */
1200 l
= 0; /* Don't loop again */
1204 GETCHAR(citype
, p
); /* Parse CI type */
1205 GETCHAR(cilen
, p
); /* Parse CI length */
1206 l
-= cilen
; /* Adjust remaining length */
1207 next
+= cilen
; /* Step to next CI */
1209 switch (citype
) { /* Check CI type */
1211 if (!ao
->neg_mru
) { /* Allow option? */
1212 LCPDEBUG((LOG_INFO
, "lcp_reqci: Reject MRU - not allowed\n"));
1213 orc
= CONFREJ
; /* Reject CI */
1215 } else if (cilen
!= CILEN_SHORT
) { /* Check CI length */
1216 LCPDEBUG((LOG_INFO
, "lcp_reqci: Reject MRU - bad length\n"));
1217 orc
= CONFREJ
; /* Reject CI */
1220 GETSHORT(cishort
, p
); /* Parse MRU */
1223 * He must be able to receive at least our minimum.
1224 * No need to check a maximum. If he sends a large number,
1225 * we'll just ignore it.
1227 if (cishort
< PPP_MINMRU
) {
1228 LCPDEBUG((LOG_INFO
, "lcp_reqci: Nak - MRU too small\n"));
1229 orc
= CONFNAK
; /* Nak CI */
1230 PUTCHAR(CI_MRU
, nakp
);
1231 PUTCHAR(CILEN_SHORT
, nakp
);
1232 PUTSHORT(PPP_MINMRU
, nakp
); /* Give him a hint */
1235 ho
->neg_mru
= 1; /* Remember he sent MRU */
1236 ho
->mru
= cishort
; /* And remember value */
1238 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " MRU %d", cishort
);
1239 traceNdx
= strlen(traceBuf
);
1244 if (!ao
->neg_asyncmap
) {
1245 LCPDEBUG((LOG_INFO
, "lcp_reqci: Reject ASYNCMAP not allowed\n"));
1248 } else if (cilen
!= CILEN_LONG
) {
1249 LCPDEBUG((LOG_INFO
, "lcp_reqci: Reject ASYNCMAP bad length\n"));
1256 * Asyncmap must have set at least the bits
1257 * which are set in lcp_allowoptions[unit].asyncmap.
1259 if ((ao
->asyncmap
& ~cilong
) != 0) {
1260 LCPDEBUG((LOG_INFO
, "lcp_reqci: Nak ASYNCMAP %lX missing %lX\n",
1261 cilong
, ao
->asyncmap
));
1263 PUTCHAR(CI_ASYNCMAP
, nakp
);
1264 PUTCHAR(CILEN_LONG
, nakp
);
1265 PUTLONG(ao
->asyncmap
| cilong
, nakp
);
1268 ho
->neg_asyncmap
= 1;
1269 ho
->asyncmap
= cilong
;
1271 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " ASYNCMAP=%lX", cilong
);
1272 traceNdx
= strlen(traceBuf
);
1277 if (cilen
< CILEN_SHORT
) {
1278 LCPDEBUG((LOG_INFO
, "lcp_reqci: Reject AUTHTYPE missing arg\n"));
1281 } else if (!(ao
->neg_upap
|| ao
->neg_chap
)) {
1283 * Reject the option if we're not willing to authenticate.
1285 LCPDEBUG((LOG_INFO
, "lcp_reqci: Reject AUTHTYPE not allowed\n"));
1289 GETSHORT(cishort
, p
);
1292 * Authtype must be UPAP or CHAP.
1294 * Note: if both ao->neg_upap and ao->neg_chap are set,
1295 * and the peer sends a Configure-Request with two
1296 * authenticate-protocol requests, one for CHAP and one
1297 * for UPAP, then we will reject the second request.
1298 * Whether we end up doing CHAP or UPAP depends then on
1299 * the ordering of the CIs in the peer's Configure-Request.
1302 if (cishort
== PPP_PAP
) {
1303 if (ho
->neg_chap
) { /* we've already accepted CHAP */
1304 LCPDEBUG((LOG_WARNING
, "lcp_reqci: Reject AUTHTYPE PAP already accepted\n"));
1307 } else if (cilen
!= CILEN_SHORT
) {
1308 LCPDEBUG((LOG_WARNING
, "lcp_reqci: Reject AUTHTYPE PAP bad len\n"));
1312 if (!ao
->neg_upap
) { /* we don't want to do PAP */
1313 LCPDEBUG((LOG_WARNING
, "lcp_reqci: Nak AUTHTYPE PAP not allowed\n"));
1314 orc
= CONFNAK
; /* NAK it and suggest CHAP */
1315 PUTCHAR(CI_AUTHTYPE
, nakp
);
1316 PUTCHAR(CILEN_CHAP
, nakp
);
1317 PUTSHORT(PPP_CHAP
, nakp
);
1318 PUTCHAR(ao
->chap_mdtype
, nakp
);
1323 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " PAP (%X)", cishort
);
1324 traceNdx
= strlen(traceBuf
);
1328 if (cishort
== PPP_CHAP
) {
1329 if (ho
->neg_upap
) { /* we've already accepted PAP */
1330 LCPDEBUG((LOG_WARNING
, "lcp_reqci: Reject AUTHTYPE CHAP accepted PAP\n"));
1333 } else if (cilen
!= CILEN_CHAP
) {
1334 LCPDEBUG((LOG_WARNING
, "lcp_reqci: Reject AUTHTYPE CHAP bad len\n"));
1338 if (!ao
->neg_chap
) { /* we don't want to do CHAP */
1339 LCPDEBUG((LOG_WARNING
, "lcp_reqci: Nak AUTHTYPE CHAP not allowed\n"));
1340 orc
= CONFNAK
; /* NAK it and suggest PAP */
1341 PUTCHAR(CI_AUTHTYPE
, nakp
);
1342 PUTCHAR(CILEN_SHORT
, nakp
);
1343 PUTSHORT(PPP_PAP
, nakp
);
1346 GETCHAR(cichar
, p
); /* get digest type*/
1347 if (cichar
!= CHAP_DIGEST_MD5
1349 && cichar
!= CHAP_MICROSOFT
1352 LCPDEBUG((LOG_WARNING
, "lcp_reqci: Nak AUTHTYPE CHAP digest=%d\n", cichar
));
1354 PUTCHAR(CI_AUTHTYPE
, nakp
);
1355 PUTCHAR(CILEN_CHAP
, nakp
);
1356 PUTSHORT(PPP_CHAP
, nakp
);
1357 PUTCHAR(ao
->chap_mdtype
, nakp
);
1361 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " CHAP %X,%d", cishort
, cichar
);
1362 traceNdx
= strlen(traceBuf
);
1364 ho
->chap_mdtype
= cichar
; /* save md type */
1370 * We don't recognize the protocol they're asking for.
1371 * Nak it with something we're willing to do.
1372 * (At this point we know ao->neg_upap || ao->neg_chap.)
1375 PUTCHAR(CI_AUTHTYPE
, nakp
);
1377 LCPDEBUG((LOG_WARNING
, "lcp_reqci: Nak AUTHTYPE %d req CHAP\n", cishort
));
1378 PUTCHAR(CILEN_CHAP
, nakp
);
1379 PUTSHORT(PPP_CHAP
, nakp
);
1380 PUTCHAR(ao
->chap_mdtype
, nakp
);
1383 LCPDEBUG((LOG_WARNING
, "lcp_reqci: Nak AUTHTYPE %d req PAP\n", cishort
));
1384 PUTCHAR(CILEN_SHORT
, nakp
);
1385 PUTSHORT(PPP_PAP
, nakp
);
1390 GETSHORT(cishort
, p
);
1393 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " QUALITY (%x %x)", cishort
, (unsigned int) cilong
);
1394 traceNdx
= strlen(traceBuf
);
1398 cilen
!= CILEN_LQR
) {
1404 * Check the protocol and the reporting period.
1405 * XXX When should we Nak this, and what with?
1407 if (cishort
!= PPP_LQR
) {
1409 PUTCHAR(CI_QUALITY
, nakp
);
1410 PUTCHAR(CILEN_LQR
, nakp
);
1411 PUTSHORT(PPP_LQR
, nakp
);
1412 PUTLONG(ao
->lqr_period
, nakp
);
1417 case CI_MAGICNUMBER
:
1418 if (!(ao
->neg_magicnumber
|| go
->neg_magicnumber
) ||
1419 cilen
!= CILEN_LONG
) {
1425 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " MAGICNUMBER (%lX)", cilong
);
1426 traceNdx
= strlen(traceBuf
);
1430 * He must have a different magic number.
1432 if (go
->neg_magicnumber
&&
1433 cilong
== go
->magicnumber
) {
1434 cilong
= magic(); /* Don't put magic() inside macro! */
1436 PUTCHAR(CI_MAGICNUMBER
, nakp
);
1437 PUTCHAR(CILEN_LONG
, nakp
);
1438 PUTLONG(cilong
, nakp
);
1441 ho
->neg_magicnumber
= 1;
1442 ho
->magicnumber
= cilong
;
1446 case CI_PCOMPRESSION
:
1448 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " PCOMPRESSION");
1449 traceNdx
= strlen(traceBuf
);
1451 if (!ao
->neg_pcompression
||
1452 cilen
!= CILEN_VOID
) {
1456 ho
->neg_pcompression
= 1;
1459 case CI_ACCOMPRESSION
:
1461 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " ACCOMPRESSION");
1462 traceNdx
= strlen(traceBuf
);
1464 if (!ao
->neg_accompression
||
1465 cilen
!= CILEN_VOID
) {
1469 ho
->neg_accompression
= 1;
1474 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " CI_MRRU");
1475 traceNdx
= strlen(traceBuf
);
1482 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " CI_SSNHF");
1483 traceNdx
= strlen(traceBuf
);
1490 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " CI_EPDISC");
1491 traceNdx
= strlen(traceBuf
);
1498 snprintf(&traceBuf
[traceNdx
], sizeof(traceBuf
), " unknown %d", citype
);
1499 traceNdx
= strlen(traceBuf
);
1507 if (traceNdx
>= 80 - 32) {
1508 LCPDEBUG((LOG_INFO
, "lcp_reqci: rcvd%s\n", traceBuf
));
1512 if (orc
== CONFACK
&& /* Good CI */
1513 rc
!= CONFACK
) /* but prior CI wasnt? */
1514 continue; /* Don't send this one */
1516 if (orc
== CONFNAK
) { /* Nak this CI? */
1517 if (reject_if_disagree
/* Getting fed up with sending NAKs? */
1518 && citype
!= CI_MAGICNUMBER
) {
1519 orc
= CONFREJ
; /* Get tough if so */
1522 if (rc
== CONFREJ
) /* Rejecting prior CI? */
1523 continue; /* Don't send this one */
1527 if (orc
== CONFREJ
) { /* Reject this CI */
1529 if (cip
!= rejp
) /* Need to move rejected CI? */
1530 BCOPY(cip
, rejp
, cilen
); /* Move it */
1531 INCPTR(cilen
, rejp
); /* Update output pointer */
1536 * If we wanted to send additional NAKs (for unsent CIs), the
1537 * code would go here. The extra NAKs would go at *nakp.
1538 * At present there are no cases where we want to ask the
1539 * peer to negotiate an option.
1544 *lenp
= (int)(next
- inp
);
1548 * Copy the Nak'd options from the nak_buffer to the caller's buffer.
1550 *lenp
= (int)(nakp
- nak_buffer
);
1551 BCOPY(nak_buffer
, inp
, *lenp
);
1554 *lenp
= (int)(rejp
- inp
);
1560 LCPDEBUG((LOG_INFO
, "lcp_reqci: %s\n", traceBuf
));
1563 LCPDEBUG((LOG_INFO
, "lcp_reqci: returning CONF%s.\n", CODENAME(rc
)));
1564 return (rc
); /* Return final code */
1569 * lcp_up - LCP has come UP.
1571 static void lcp_up(fsm
*f
)
1573 lcp_options
*wo
= &lcp_wantoptions
[f
->unit
];
1574 lcp_options
*ho
= &lcp_hisoptions
[f
->unit
];
1575 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
1576 lcp_options
*ao
= &lcp_allowoptions
[f
->unit
];
1578 if (!go
->neg_magicnumber
)
1579 go
->magicnumber
= 0;
1580 if (!ho
->neg_magicnumber
)
1581 ho
->magicnumber
= 0;
1584 * Set our MTU to the smaller of the MTU we wanted and
1585 * the MRU our peer wanted. If we negotiated an MRU,
1586 * set our MRU to the larger of value we wanted and
1587 * the value we got in the negotiation.
1589 ppp_send_config(f
->unit
, LWIP_MIN(ao
->mru
, (ho
->neg_mru
? ho
->mru
: PPP_MRU
)),
1590 (ho
->neg_asyncmap
? ho
->asyncmap
: 0xffffffffl
),
1591 ho
->neg_pcompression
, ho
->neg_accompression
);
1593 * If the asyncmap hasn't been negotiated, we really should
1594 * set the receive asyncmap to ffffffff, but we set it to 0
1595 * for backwards contemptibility.
1597 ppp_recv_config(f
->unit
, (go
->neg_mru
? LWIP_MAX(wo
->mru
, go
->mru
): PPP_MRU
),
1598 (go
->neg_asyncmap
? go
->asyncmap
: 0x00000000),
1599 go
->neg_pcompression
, go
->neg_accompression
);
1602 peer_mru
[f
->unit
] = ho
->mru
;
1604 lcp_echo_lowerup(f
->unit
); /* Enable echo messages */
1606 link_established(f
->unit
);
1611 * lcp_down - LCP has gone DOWN.
1613 * Alert other protocols.
1615 static void lcp_down(fsm
*f
)
1617 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
1619 lcp_echo_lowerdown(f
->unit
);
1623 ppp_send_config(f
->unit
, PPP_MRU
, 0xffffffffl
, 0, 0);
1624 ppp_recv_config(f
->unit
, PPP_MRU
,
1625 (go
->neg_asyncmap
? go
->asyncmap
: 0x00000000),
1626 go
->neg_pcompression
, go
->neg_accompression
);
1627 peer_mru
[f
->unit
] = PPP_MRU
;
1632 * lcp_starting - LCP needs the lower layer up.
1634 static void lcp_starting(fsm
*f
)
1636 link_required(f
->unit
);
1641 * lcp_finished - LCP has finished with the lower layer.
1643 static void lcp_finished(fsm
*f
)
1645 link_terminated(f
->unit
);
1651 * print_string - print a readable representation of a string using
1654 static void print_string(
1657 void (*printer
) (void *, char *, ...),
1664 for (; len
> 0; --len
) {
1666 if (' ' <= c
&& c
<= '~') {
1667 if (c
== '\\' || c
== '"')
1669 printer(arg
, "%c", c
);
1673 printer(arg
, "\\n");
1676 printer(arg
, "\\r");
1679 printer(arg
, "\\t");
1682 printer(arg
, "\\%.3o", c
);
1691 * lcp_printpkt - print the contents of an LCP packet.
1693 static char *lcp_codenames
[] = {
1694 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1695 "TermReq", "TermAck", "CodeRej", "ProtRej",
1696 "EchoReq", "EchoRep", "DiscReq"
1699 static int lcp_printpkt(
1702 void (*printer
) (void *, char *, ...),
1706 int code
, id
, len
, olen
;
1707 u_char
*pstart
, *optend
;
1711 if (plen
< HEADERLEN
)
1717 if (len
< HEADERLEN
|| len
> plen
)
1720 if (code
>= 1 && code
<= sizeof(lcp_codenames
) / sizeof(char *))
1721 printer(arg
, " %s", lcp_codenames
[code
-1]);
1723 printer(arg
, " code=0x%x", code
);
1724 printer(arg
, " id=0x%x", id
);
1731 /* print option list */
1736 if (olen
< 2 || olen
> len
) {
1744 if (olen
== CILEN_SHORT
) {
1746 GETSHORT(cishort
, p
);
1747 printer(arg
, "mru %d", cishort
);
1751 if (olen
== CILEN_LONG
) {
1754 printer(arg
, "asyncmap 0x%lx", cilong
);
1758 if (olen
>= CILEN_SHORT
) {
1760 printer(arg
, "auth ");
1761 GETSHORT(cishort
, p
);
1764 printer(arg
, "pap");
1767 printer(arg
, "chap");
1770 printer(arg
, "0x%x", cishort
);
1775 if (olen
>= CILEN_SHORT
) {
1777 printer(arg
, "quality ");
1778 GETSHORT(cishort
, p
);
1781 printer(arg
, "lqr");
1784 printer(arg
, "0x%x", cishort
);
1789 if (olen
>= CILEN_CHAR
) {
1791 printer(arg
, "callback ");
1792 GETSHORT(cishort
, p
);
1795 printer(arg
, "CBCP");
1798 printer(arg
, "0x%x", cishort
);
1802 case CI_MAGICNUMBER
:
1803 if (olen
== CILEN_LONG
) {
1806 printer(arg
, "magic 0x%x", cilong
);
1809 case CI_PCOMPRESSION
:
1810 if (olen
== CILEN_VOID
) {
1812 printer(arg
, "pcomp");
1815 case CI_ACCOMPRESSION
:
1816 if (olen
== CILEN_VOID
) {
1818 printer(arg
, "accomp");
1822 while (p
< optend
) {
1824 printer(arg
, " %.2x", code
);
1832 if (len
> 0 && *p
>= ' ' && *p
< 0x7f) {
1834 print_string((char*)p
, len
, printer
, arg
);
1845 printer(arg
, " magic=0x%x", cilong
);
1852 /* print the rest of the bytes in the packet */
1853 for (; len
> 0; --len
) {
1855 printer(arg
, " %.2x", code
);
1858 return (int)(p
- pstart
);
1863 * Time to shut down the link because there is nothing out there.
1866 static void LcpLinkFailure (fsm
*f
)
1868 if (f
->state
== OPENED
) {
1869 LCPDEBUG((LOG_INFO
, "No response to %d echo-requests\n", lcp_echos_pending
));
1870 LCPDEBUG((LOG_NOTICE
, "Serial link appears to be disconnected.\n"));
1871 lcp_close(f
->unit
, "Peer not responding");
1876 * Timer expired for the LCP echo requests from this process.
1879 static void LcpEchoCheck (fsm
*f
)
1881 LcpSendEchoRequest (f
);
1884 * Start the timer for the next interval.
1886 LWIP_ASSERT("lcp_echo_timer_running == 0", lcp_echo_timer_running
== 0);
1888 TIMEOUT (LcpEchoTimeout
, f
, lcp_echo_interval
);
1889 lcp_echo_timer_running
= 1;
1893 * LcpEchoTimeout - Timer expired on the LCP echo
1896 static void LcpEchoTimeout (void *arg
)
1898 if (lcp_echo_timer_running
!= 0) {
1899 lcp_echo_timer_running
= 0;
1900 LcpEchoCheck ((fsm
*) arg
);
1905 * LcpEchoReply - LCP has received a reply to the echo
1907 static void lcp_received_echo_reply (fsm
*f
, int id
, u_char
*inp
, int len
)
1913 /* Check the magic number - don't count replies from ourselves. */
1915 LCPDEBUG((LOG_WARNING
, "lcp: received short Echo-Reply, length %d\n", len
));
1918 GETLONG(magic
, inp
);
1919 if (lcp_gotoptions
[f
->unit
].neg_magicnumber
1920 && magic
== lcp_gotoptions
[f
->unit
].magicnumber
) {
1921 LCPDEBUG((LOG_WARNING
, "appear to have received our own echo-reply!\n"));
1925 /* Reset the number of outstanding echo frames */
1926 lcp_echos_pending
= 0;
1930 * LcpSendEchoRequest - Send an echo request frame to the peer
1933 static void LcpSendEchoRequest (fsm
*f
)
1936 u_char pkt
[4], *pktp
;
1939 * Detect the failure of the peer at this point.
1941 if (lcp_echo_fails
!= 0) {
1942 if (lcp_echos_pending
++ >= lcp_echo_fails
) {
1944 lcp_echos_pending
= 0;
1949 * Make and send the echo request frame.
1951 if (f
->state
== OPENED
) {
1952 lcp_magic
= lcp_gotoptions
[f
->unit
].magicnumber
;
1954 PUTLONG(lcp_magic
, pktp
);
1955 fsm_sdata(f
, ECHOREQ
, (u_char
)(lcp_echo_number
++ & 0xFF), pkt
, (int)(pktp
- pkt
));
1960 * lcp_echo_lowerup - Start the timer for the LCP frame
1963 static void lcp_echo_lowerup (int unit
)
1965 fsm
*f
= &lcp_fsm
[unit
];
1967 /* Clear the parameters for generating echo frames */
1968 lcp_echos_pending
= 0;
1969 lcp_echo_number
= 0;
1970 lcp_echo_timer_running
= 0;
1972 /* If a timeout interval is specified then start the timer */
1973 if (lcp_echo_interval
!= 0)
1978 * lcp_echo_lowerdown - Stop the timer for the LCP frame
1981 static void lcp_echo_lowerdown (int unit
)
1983 fsm
*f
= &lcp_fsm
[unit
];
1985 if (lcp_echo_timer_running
!= 0) {
1986 UNTIMEOUT (LcpEchoTimeout
, f
);
1987 lcp_echo_timer_running
= 0;
1991 #endif /* PPP_SUPPORT */