1 /* $NetBSD: lcp.c,v 1.2 2005/02/20 10:47:17 cube Exp $ */
4 * lcp.c - PPP Link Control Protocol.
6 * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * 3. The name "Carnegie Mellon University" must not be used to
21 * endorse or promote products derived from this software without
22 * prior written permission. For permission or any legal
23 * details, please contact
24 * Office of Technology Transfer
25 * Carnegie Mellon University
27 * Pittsburgh, PA 15213-3890
28 * (412) 268-4387, fax: (412) 268-7395
29 * tech-transfer@andrew.cmu.edu
31 * 4. Redistributions of any form whatsoever must retain the following
33 * "This product includes software developed by Computing Services
34 * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
36 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
37 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
38 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
39 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
40 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
41 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
42 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
45 #include <sys/cdefs.h>
48 #define RCSID "Id: lcp.c,v 1.76 2006/05/22 00:04:07 paulus Exp"
50 __RCSID("$NetBSD: lcp.c,v 1.2 2005/02/20 10:47:17 cube Exp $");
69 static const char rcsid
[] = RCSID
;
73 * When the link comes up we want to be able to wait for a short while,
74 * or until seeing some input from the peer, before starting to send
75 * configure-requests. We do this by delaying the fsm_lowerup call.
77 /* steal a bit in fsm flags word */
78 #define DELAYED_UP 0x100
80 static void lcp_delayed_up
__P((void *));
83 * LCP-related command-line options.
85 int lcp_echo_interval
= 0; /* Interval between LCP echo-requests */
86 int lcp_echo_fails
= 0; /* Tolerance to unanswered echo-requests */
87 bool lax_recv
= 0; /* accept control chars in asyncmap */
88 bool noendpoint
= 0; /* don't send/accept endpoint discriminator */
90 static int noopt
__P((char **));
93 static int setendpoint
__P((char **));
94 static void printendpoint
__P((option_t
*, void (*)(void *, char *, ...),
96 #endif /* HAVE_MULTILINK */
98 static option_t lcp_option_list
[] = {
100 { "-all", o_special_noarg
, (void *)noopt
,
101 "Don't request/allow any LCP options" },
103 { "noaccomp", o_bool
, &lcp_wantoptions
[0].neg_accompression
,
104 "Disable address/control compression",
105 OPT_A2CLR
, &lcp_allowoptions
[0].neg_accompression
},
106 { "-ac", o_bool
, &lcp_wantoptions
[0].neg_accompression
,
107 "Disable address/control compression",
108 OPT_ALIAS
| OPT_A2CLR
, &lcp_allowoptions
[0].neg_accompression
},
110 { "asyncmap", o_uint32
, &lcp_wantoptions
[0].asyncmap
,
111 "Set asyncmap (for received packets)",
112 OPT_OR
, &lcp_wantoptions
[0].neg_asyncmap
},
113 { "-as", o_uint32
, &lcp_wantoptions
[0].asyncmap
,
114 "Set asyncmap (for received packets)",
115 OPT_ALIAS
| OPT_OR
, &lcp_wantoptions
[0].neg_asyncmap
},
116 { "default-asyncmap", o_uint32
, &lcp_wantoptions
[0].asyncmap
,
117 "Disable asyncmap negotiation",
118 OPT_OR
| OPT_NOARG
| OPT_VAL(~0U) | OPT_A2CLR
,
119 &lcp_allowoptions
[0].neg_asyncmap
},
120 { "-am", o_uint32
, &lcp_wantoptions
[0].asyncmap
,
121 "Disable asyncmap negotiation",
122 OPT_ALIAS
| OPT_OR
| OPT_NOARG
| OPT_VAL(~0U) | OPT_A2CLR
,
123 &lcp_allowoptions
[0].neg_asyncmap
},
125 { "nomagic", o_bool
, &lcp_wantoptions
[0].neg_magicnumber
,
126 "Disable magic number negotiation (looped-back line detection)",
127 OPT_A2CLR
, &lcp_allowoptions
[0].neg_magicnumber
},
128 { "-mn", o_bool
, &lcp_wantoptions
[0].neg_magicnumber
,
129 "Disable magic number negotiation (looped-back line detection)",
130 OPT_ALIAS
| OPT_A2CLR
, &lcp_allowoptions
[0].neg_magicnumber
},
132 { "mru", o_int
, &lcp_wantoptions
[0].mru
,
133 "Set MRU (maximum received packet size) for negotiation",
134 OPT_PRIO
, &lcp_wantoptions
[0].neg_mru
},
135 { "default-mru", o_bool
, &lcp_wantoptions
[0].neg_mru
,
136 "Disable MRU negotiation (use default 1500)",
137 OPT_PRIOSUB
| OPT_A2CLR
, &lcp_allowoptions
[0].neg_mru
},
138 { "-mru", o_bool
, &lcp_wantoptions
[0].neg_mru
,
139 "Disable MRU negotiation (use default 1500)",
140 OPT_ALIAS
| OPT_PRIOSUB
| OPT_A2CLR
, &lcp_allowoptions
[0].neg_mru
},
142 { "mtu", o_int
, &lcp_allowoptions
[0].mru
,
143 "Set our MTU", OPT_LIMITS
, NULL
, MAXMRU
, MINMRU
},
145 { "nopcomp", o_bool
, &lcp_wantoptions
[0].neg_pcompression
,
146 "Disable protocol field compression",
147 OPT_A2CLR
, &lcp_allowoptions
[0].neg_pcompression
},
148 { "-pc", o_bool
, &lcp_wantoptions
[0].neg_pcompression
,
149 "Disable protocol field compression",
150 OPT_ALIAS
| OPT_A2CLR
, &lcp_allowoptions
[0].neg_pcompression
},
152 { "passive", o_bool
, &lcp_wantoptions
[0].passive
,
153 "Set passive mode", 1 },
154 { "-p", o_bool
, &lcp_wantoptions
[0].passive
,
155 "Set passive mode", OPT_ALIAS
| 1 },
157 { "silent", o_bool
, &lcp_wantoptions
[0].silent
,
158 "Set silent mode", 1 },
160 { "lcp-echo-failure", o_int
, &lcp_echo_fails
,
161 "Set number of consecutive echo failures to indicate link failure",
163 { "lcp-echo-interval", o_int
, &lcp_echo_interval
,
164 "Set time in seconds between LCP echo requests", OPT_PRIO
},
165 { "lcp-restart", o_int
, &lcp_fsm
[0].timeouttime
,
166 "Set time in seconds between LCP retransmissions", OPT_PRIO
},
167 { "lcp-max-terminate", o_int
, &lcp_fsm
[0].maxtermtransmits
,
168 "Set maximum number of LCP terminate-request transmissions", OPT_PRIO
},
169 { "lcp-max-configure", o_int
, &lcp_fsm
[0].maxconfreqtransmits
,
170 "Set maximum number of LCP configure-request transmissions", OPT_PRIO
},
171 { "lcp-max-failure", o_int
, &lcp_fsm
[0].maxnakloops
,
172 "Set limit on number of LCP configure-naks", OPT_PRIO
},
174 { "receive-all", o_bool
, &lax_recv
,
175 "Accept all received control characters", 1 },
177 #ifdef HAVE_MULTILINK
178 { "mrru", o_int
, &lcp_wantoptions
[0].mrru
,
179 "Maximum received packet size for multilink bundle",
180 OPT_PRIO
, &lcp_wantoptions
[0].neg_mrru
},
182 { "mpshortseq", o_bool
, &lcp_wantoptions
[0].neg_ssnhf
,
183 "Use short sequence numbers in multilink headers",
184 OPT_PRIO
| 1, &lcp_allowoptions
[0].neg_ssnhf
},
185 { "nompshortseq", o_bool
, &lcp_wantoptions
[0].neg_ssnhf
,
186 "Don't use short sequence numbers in multilink headers",
187 OPT_PRIOSUB
| OPT_A2CLR
, &lcp_allowoptions
[0].neg_ssnhf
},
189 { "endpoint", o_special
, (void *) setendpoint
,
190 "Endpoint discriminator for multilink",
191 OPT_PRIO
| OPT_A2PRINTER
, (void *) printendpoint
},
192 #endif /* HAVE_MULTILINK */
194 { "noendpoint", o_bool
, &noendpoint
,
195 "Don't send or accept multilink endpoint discriminator", 1 },
201 fsm lcp_fsm
[NUM_PPP
]; /* LCP fsm structure (global)*/
202 lcp_options lcp_wantoptions
[NUM_PPP
]; /* Options that we want to request */
203 lcp_options lcp_gotoptions
[NUM_PPP
]; /* Options that peer ack'd */
204 lcp_options lcp_allowoptions
[NUM_PPP
]; /* Options we allow peer to request */
205 lcp_options lcp_hisoptions
[NUM_PPP
]; /* Options that we ack'd */
207 /* Hook for LCP up */
208 void (*lcp_up_hook
) __P((void)) = NULL
;
210 /* Hook for LCP down */
211 void (*lcp_down_hook
) __P((void)) = NULL
;
213 /* Hook for sending an LCP echo request, argument is pending count */
214 void (*lcp_echo_hook
) __P((int)) = NULL
;
216 /* Hook for receiving an LCP echo reply, argument is whether it's ours */
217 void (*lcp_echoreply_hook
) __P((int)) = NULL
;
219 static int lcp_echos_pending
= 0; /* Number of outstanding echo msgs */
220 static int lcp_echo_number
= 0; /* ID number of next echo frame */
221 static int lcp_echo_timer_running
= 0; /* set if a timer is running */
223 static u_char nak_buffer
[PPP_MRU
]; /* where we construct a nak packet */
226 * Callbacks for fsm code. (CI = Configuration Information)
228 static void lcp_resetci
__P((fsm
*)); /* Reset our CI */
229 static int lcp_cilen
__P((fsm
*)); /* Return length of our CI */
230 static void lcp_addci
__P((fsm
*, u_char
*, int *)); /* Add our CI to pkt */
231 static int lcp_ackci
__P((fsm
*, u_char
*, int)); /* Peer ack'd our CI */
232 static int lcp_nakci
__P((fsm
*, u_char
*, int, int)); /* Peer nak'd our CI */
233 static int lcp_rejci
__P((fsm
*, u_char
*, int)); /* Peer rej'd our CI */
234 static int lcp_reqci
__P((fsm
*, u_char
*, int *, int)); /* Rcv peer CI */
235 static void lcp_up
__P((fsm
*)); /* We're UP */
236 static void lcp_down
__P((fsm
*)); /* We're DOWN */
237 static void lcp_starting
__P((fsm
*)); /* We need lower layer up */
238 static void lcp_finished
__P((fsm
*)); /* We need lower layer down */
239 static int lcp_extcode
__P((fsm
*, int, int, u_char
*, int));
240 static void lcp_rprotrej
__P((fsm
*, u_char
*, int));
243 * routines to send LCP echos to peer
246 static void lcp_echo_lowerup
__P((int));
247 static void lcp_echo_lowerdown
__P((int));
248 static void LcpEchoTimeout
__P((void *));
249 static void lcp_received_echo_reply
__P((fsm
*, int, u_char
*, int));
250 static void LcpSendEchoRequest
__P((fsm
*));
251 static void LcpLinkFailure
__P((fsm
*));
252 static void LcpEchoCheck
__P((fsm
*));
254 static fsm_callbacks lcp_callbacks
= { /* LCP callback routines */
255 lcp_resetci
, /* Reset our Configuration Information */
256 lcp_cilen
, /* Length of our Configuration Information */
257 lcp_addci
, /* Add our Configuration Information */
258 lcp_ackci
, /* ACK our Configuration Information */
259 lcp_nakci
, /* NAK our Configuration Information */
260 lcp_rejci
, /* Reject our Configuration Information */
261 lcp_reqci
, /* Request peer's Configuration Information */
262 lcp_up
, /* Called when fsm reaches OPENED state */
263 lcp_down
, /* Called when fsm leaves OPENED state */
264 lcp_starting
, /* Called when we want the lower layer up */
265 lcp_finished
, /* Called when we want the lower layer down */
266 NULL
, /* Called when Protocol-Reject received */
267 NULL
, /* Retransmission is necessary */
268 lcp_extcode
, /* Called to handle LCP-specific codes */
269 "LCP" /* String name of protocol */
273 * Protocol entry points.
274 * Some of these are called directly.
277 static void lcp_init
__P((int));
278 static void lcp_input
__P((int, u_char
*, int));
279 static void lcp_protrej
__P((int));
280 static int lcp_printpkt
__P((u_char
*, int,
281 void (*) __P((void *, char *, ...)), void *));
283 struct protent lcp_protent
= {
303 int lcp_loopbackfail
= DEFLOOPBACKFAIL
;
306 * Length of each type of configuration option (in octets)
310 #define CILEN_SHORT 4 /* CILEN_VOID + 2 */
311 #define CILEN_CHAP 5 /* CILEN_VOID + 2 + 1 */
312 #define CILEN_LONG 6 /* CILEN_VOID + 4 */
313 #define CILEN_LQR 8 /* CILEN_VOID + 2 + 4 */
316 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
317 (x) == CONFNAK ? "NAK" : "REJ")
320 * noopt - Disable all options (why?).
326 BZERO((char *) &lcp_wantoptions
[0], sizeof (struct lcp_options
));
327 BZERO((char *) &lcp_allowoptions
[0], sizeof (struct lcp_options
));
332 #ifdef HAVE_MULTILINK
337 if (str_to_epdisc(&lcp_wantoptions
[0].endpoint
, *argv
)) {
338 lcp_wantoptions
[0].neg_endpoint
= 1;
341 option_error("Can't parse '%s' as an endpoint discriminator", *argv
);
346 printendpoint(opt
, printer
, arg
)
348 void (*printer
) __P((void *, char *, ...));
351 printer(arg
, "%s", epdisc_to_str(&lcp_wantoptions
[0].endpoint
));
353 #endif /* HAVE_MULTILINK */
356 * lcp_init - Initialize LCP.
362 fsm
*f
= &lcp_fsm
[unit
];
363 lcp_options
*wo
= &lcp_wantoptions
[unit
];
364 lcp_options
*ao
= &lcp_allowoptions
[unit
];
367 f
->protocol
= PPP_LCP
;
368 f
->callbacks
= &lcp_callbacks
;
372 BZERO(wo
, sizeof(*wo
));
375 wo
->neg_asyncmap
= 1;
376 wo
->neg_magicnumber
= 1;
377 wo
->neg_pcompression
= 1;
378 wo
->neg_accompression
= 1;
380 BZERO(ao
, sizeof(*ao
));
383 ao
->neg_asyncmap
= 1;
385 ao
->chap_mdtype
= chap_mdtype_all
;
388 ao
->neg_magicnumber
= 1;
389 ao
->neg_pcompression
= 1;
390 ao
->neg_accompression
= 1;
391 ao
->neg_endpoint
= 1;
396 * lcp_open - LCP is allowed to come up.
402 fsm
*f
= &lcp_fsm
[unit
];
403 lcp_options
*wo
= &lcp_wantoptions
[unit
];
405 f
->flags
&= ~(OPT_PASSIVE
| OPT_SILENT
);
407 f
->flags
|= OPT_PASSIVE
;
409 f
->flags
|= OPT_SILENT
;
415 * lcp_close - Take LCP down.
418 lcp_close(unit
, reason
)
422 fsm
*f
= &lcp_fsm
[unit
];
424 if (phase
!= PHASE_DEAD
&& phase
!= PHASE_MASTER
)
425 new_phase(PHASE_TERMINATE
);
426 if (f
->state
== STOPPED
&& f
->flags
& (OPT_PASSIVE
|OPT_SILENT
)) {
428 * This action is not strictly according to the FSM in RFC1548,
429 * but it does mean that the program terminates if you do a
430 * lcp_close() in passive/silent mode when a connection hasn't
437 fsm_close(f
, reason
);
442 * lcp_lowerup - The lower layer is up.
448 lcp_options
*wo
= &lcp_wantoptions
[unit
];
449 fsm
*f
= &lcp_fsm
[unit
];
452 * Don't use A/C or protocol compression on transmission,
453 * but accept A/C and protocol compressed packets
454 * if we are going to ask for A/C and protocol compression.
456 if (ppp_send_config(unit
, PPP_MRU
, 0xffffffff, 0, 0) < 0
457 || ppp_recv_config(unit
, PPP_MRU
, (lax_recv
? 0: 0xffffffff),
458 wo
->neg_pcompression
, wo
->neg_accompression
) < 0)
460 peer_mru
[unit
] = PPP_MRU
;
462 if (listen_time
!= 0) {
463 f
->flags
|= DELAYED_UP
;
464 timeout(lcp_delayed_up
, f
, 0, listen_time
* 1000);
471 * lcp_lowerdown - The lower layer is down.
477 fsm
*f
= &lcp_fsm
[unit
];
479 if (f
->flags
& DELAYED_UP
)
480 f
->flags
&= ~DELAYED_UP
;
482 fsm_lowerdown(&lcp_fsm
[unit
]);
487 * lcp_delayed_up - Bring the lower layer up now.
495 if (f
->flags
& DELAYED_UP
) {
496 f
->flags
&= ~DELAYED_UP
;
503 * lcp_input - Input LCP packet.
506 lcp_input(unit
, p
, len
)
511 fsm
*f
= &lcp_fsm
[unit
];
513 if (f
->flags
& DELAYED_UP
) {
514 f
->flags
&= ~DELAYED_UP
;
517 fsm_input(f
, p
, len
);
521 * lcp_extcode - Handle a LCP-specific code.
524 lcp_extcode(f
, code
, id
, inp
, len
)
534 lcp_rprotrej(f
, inp
, len
);
538 if (f
->state
!= OPENED
)
541 PUTLONG(lcp_gotoptions
[f
->unit
].magicnumber
, magp
);
542 fsm_sdata(f
, ECHOREP
, id
, inp
, len
);
546 lcp_received_echo_reply(f
, id
, inp
, len
);
562 * lcp_rprotrej - Receive an Protocol-Reject.
564 * Figure out which protocol is rejected and inform it.
567 lcp_rprotrej(f
, inp
, len
)
573 struct protent
*protp
;
578 LCPDEBUG(("lcp_rprotrej: Rcvd short Protocol-Reject packet!"));
585 * Protocol-Reject packets received in any state other than the LCP
586 * OPENED state SHOULD be silently discarded.
588 if( f
->state
!= OPENED
){
589 LCPDEBUG(("Protocol-Reject discarded: LCP in state %d", f
->state
));
593 pname
= protocol_name(prot
);
596 * Upcall the proper Protocol-Reject routine.
598 for (i
= 0; (protp
= protocols
[i
]) != NULL
; ++i
)
599 if (protp
->protocol
== prot
&& protp
->enabled_flag
) {
601 dbglog("Protocol-Reject for 0x%x received", prot
);
603 dbglog("Protocol-Reject for '%s' (0x%x) received", pname
,
605 (*protp
->protrej
)(f
->unit
);
610 warn("Protocol-Reject for unsupported protocol 0x%x", prot
);
612 warn("Protocol-Reject for unsupported protocol '%s' (0x%x)", pname
,
618 * lcp_protrej - A Protocol-Reject was received.
628 error("Received Protocol-Reject for LCP!");
629 fsm_protreject(&lcp_fsm
[unit
]);
634 * lcp_sprotrej - Send a Protocol-Reject for some protocol.
637 lcp_sprotrej(unit
, p
, len
)
643 * Send back the protocol and the information field of the
644 * rejected packet. We only get here if LCP is in the OPENED state.
649 fsm_sdata(&lcp_fsm
[unit
], PROTREJ
, ++lcp_fsm
[unit
].id
,
655 * lcp_resetci - Reset our CI.
661 lcp_options
*wo
= &lcp_wantoptions
[f
->unit
];
662 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
663 lcp_options
*ao
= &lcp_allowoptions
[f
->unit
];
665 wo
->magicnumber
= magic();
671 go
->neg_endpoint
= 0;
674 ao
->neg_endpoint
= 0;
675 peer_mru
[f
->unit
] = PPP_MRU
;
681 * lcp_cilen - Return length of our CI.
687 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
689 #define LENCIVOID(neg) ((neg) ? CILEN_VOID : 0)
690 #define LENCICHAP(neg) ((neg) ? CILEN_CHAP : 0)
691 #define LENCISHORT(neg) ((neg) ? CILEN_SHORT : 0)
692 #define LENCILONG(neg) ((neg) ? CILEN_LONG : 0)
693 #define LENCILQR(neg) ((neg) ? CILEN_LQR: 0)
694 #define LENCICBCP(neg) ((neg) ? CILEN_CBCP: 0)
696 * NB: we only ask for one of CHAP, UPAP, or EAP, even if we will
697 * accept more than one. We prefer EAP first, then CHAP, then
700 return (LENCISHORT(go
->neg_mru
&& go
->mru
!= DEFMRU
) +
701 LENCILONG(go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFF) +
702 LENCISHORT(go
->neg_eap
) +
703 LENCICHAP(!go
->neg_eap
&& go
->neg_chap
) +
704 LENCISHORT(!go
->neg_eap
&& !go
->neg_chap
&& go
->neg_upap
) +
705 LENCILQR(go
->neg_lqr
) +
706 LENCICBCP(go
->neg_cbcp
) +
707 LENCILONG(go
->neg_magicnumber
) +
708 LENCIVOID(go
->neg_pcompression
) +
709 LENCIVOID(go
->neg_accompression
) +
710 LENCISHORT(go
->neg_mrru
) +
711 LENCIVOID(go
->neg_ssnhf
) +
712 (go
->neg_endpoint
? CILEN_CHAR
+ go
->endpoint
.length
: 0));
717 * lcp_addci - Add our desired CIs to a packet.
720 lcp_addci(f
, ucp
, lenp
)
725 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
726 u_char
*start_ucp
= ucp
;
728 #define ADDCIVOID(opt, neg) \
731 PUTCHAR(CILEN_VOID, ucp); \
733 #define ADDCISHORT(opt, neg, val) \
736 PUTCHAR(CILEN_SHORT, ucp); \
737 PUTSHORT(val, ucp); \
739 #define ADDCICHAP(opt, neg, val) \
741 PUTCHAR((opt), ucp); \
742 PUTCHAR(CILEN_CHAP, ucp); \
743 PUTSHORT(PPP_CHAP, ucp); \
744 PUTCHAR((CHAP_DIGEST(val)), ucp); \
746 #define ADDCILONG(opt, neg, val) \
749 PUTCHAR(CILEN_LONG, ucp); \
752 #define ADDCILQR(opt, neg, val) \
755 PUTCHAR(CILEN_LQR, ucp); \
756 PUTSHORT(PPP_LQR, ucp); \
759 #define ADDCICHAR(opt, neg, val) \
762 PUTCHAR(CILEN_CHAR, ucp); \
765 #define ADDCIENDP(opt, neg, class, val, len) \
769 PUTCHAR(CILEN_CHAR + len, ucp); \
770 PUTCHAR(class, ucp); \
771 for (i = 0; i < len; ++i) \
772 PUTCHAR(val[i], ucp); \
775 ADDCISHORT(CI_MRU
, go
->neg_mru
&& go
->mru
!= DEFMRU
, go
->mru
);
776 ADDCILONG(CI_ASYNCMAP
, go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFF,
778 ADDCISHORT(CI_AUTHTYPE
, go
->neg_eap
, PPP_EAP
);
779 ADDCICHAP(CI_AUTHTYPE
, !go
->neg_eap
&& go
->neg_chap
, go
->chap_mdtype
);
780 ADDCISHORT(CI_AUTHTYPE
, !go
->neg_eap
&& !go
->neg_chap
&& go
->neg_upap
,
782 ADDCILQR(CI_QUALITY
, go
->neg_lqr
, go
->lqr_period
);
783 ADDCICHAR(CI_CALLBACK
, go
->neg_cbcp
, CBCP_OPT
);
784 ADDCILONG(CI_MAGICNUMBER
, go
->neg_magicnumber
, go
->magicnumber
);
785 ADDCIVOID(CI_PCOMPRESSION
, go
->neg_pcompression
);
786 ADDCIVOID(CI_ACCOMPRESSION
, go
->neg_accompression
);
787 ADDCISHORT(CI_MRRU
, go
->neg_mrru
, go
->mrru
);
788 ADDCIVOID(CI_SSNHF
, go
->neg_ssnhf
);
789 ADDCIENDP(CI_EPDISC
, go
->neg_endpoint
, go
->endpoint
.class,
790 go
->endpoint
.value
, go
->endpoint
.length
);
792 if (ucp
- start_ucp
!= *lenp
) {
793 /* this should never happen, because peer_mtu should be 1500 */
794 error("Bug in lcp_addci: wrong length");
800 * lcp_ackci - Ack our CIs.
801 * This should not modify any state if the Ack is bad.
813 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
814 u_char cilen
, citype
, cichar
;
819 * CIs must be in exactly the same order that we sent.
820 * Check packet length and CI length at each step.
821 * If we find any deviations, then this packet is bad.
823 #define ACKCIVOID(opt, neg) \
825 if ((len -= CILEN_VOID) < 0) \
827 GETCHAR(citype, p); \
829 if (cilen != CILEN_VOID || \
833 #define ACKCISHORT(opt, neg, val) \
835 if ((len -= CILEN_SHORT) < 0) \
837 GETCHAR(citype, p); \
839 if (cilen != CILEN_SHORT || \
842 GETSHORT(cishort, p); \
843 if (cishort != val) \
846 #define ACKCICHAR(opt, neg, val) \
848 if ((len -= CILEN_CHAR) < 0) \
850 GETCHAR(citype, p); \
852 if (cilen != CILEN_CHAR || \
855 GETCHAR(cichar, p); \
859 #define ACKCICHAP(opt, neg, val) \
861 if ((len -= CILEN_CHAP) < 0) \
863 GETCHAR(citype, p); \
865 if (cilen != CILEN_CHAP || \
868 GETSHORT(cishort, p); \
869 if (cishort != PPP_CHAP) \
871 GETCHAR(cichar, p); \
872 if (cichar != (CHAP_DIGEST(val))) \
875 #define ACKCILONG(opt, neg, val) \
877 if ((len -= CILEN_LONG) < 0) \
879 GETCHAR(citype, p); \
881 if (cilen != CILEN_LONG || \
884 GETLONG(cilong, p); \
888 #define ACKCILQR(opt, neg, val) \
890 if ((len -= CILEN_LQR) < 0) \
892 GETCHAR(citype, p); \
894 if (cilen != CILEN_LQR || \
897 GETSHORT(cishort, p); \
898 if (cishort != PPP_LQR) \
900 GETLONG(cilong, p); \
904 #define ACKCIENDP(opt, neg, class, val, vlen) \
907 if ((len -= CILEN_CHAR + vlen) < 0) \
909 GETCHAR(citype, p); \
911 if (cilen != CILEN_CHAR + vlen || \
914 GETCHAR(cichar, p); \
915 if (cichar != class) \
917 for (i = 0; i < vlen; ++i) { \
918 GETCHAR(cichar, p); \
919 if (cichar != val[i]) \
924 ACKCISHORT(CI_MRU
, go
->neg_mru
&& go
->mru
!= DEFMRU
, go
->mru
);
925 ACKCILONG(CI_ASYNCMAP
, go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFF,
927 ACKCISHORT(CI_AUTHTYPE
, go
->neg_eap
, PPP_EAP
);
928 ACKCICHAP(CI_AUTHTYPE
, !go
->neg_eap
&& go
->neg_chap
, go
->chap_mdtype
);
929 ACKCISHORT(CI_AUTHTYPE
, !go
->neg_eap
&& !go
->neg_chap
&& go
->neg_upap
,
931 ACKCILQR(CI_QUALITY
, go
->neg_lqr
, go
->lqr_period
);
932 ACKCICHAR(CI_CALLBACK
, go
->neg_cbcp
, CBCP_OPT
);
933 ACKCILONG(CI_MAGICNUMBER
, go
->neg_magicnumber
, go
->magicnumber
);
934 ACKCIVOID(CI_PCOMPRESSION
, go
->neg_pcompression
);
935 ACKCIVOID(CI_ACCOMPRESSION
, go
->neg_accompression
);
936 ACKCISHORT(CI_MRRU
, go
->neg_mrru
, go
->mrru
);
937 ACKCIVOID(CI_SSNHF
, go
->neg_ssnhf
);
938 ACKCIENDP(CI_EPDISC
, go
->neg_endpoint
, go
->endpoint
.class,
939 go
->endpoint
.value
, go
->endpoint
.length
);
942 * If there are any remaining CIs, then this packet is bad.
948 LCPDEBUG(("lcp_acki: received bad Ack!"));
954 * lcp_nakci - Peer has sent a NAK for some of our CIs.
955 * This should not modify any state if the Nak is bad
956 * or if LCP is in the OPENED state.
963 lcp_nakci(f
, p
, len
, treat_as_reject
)
969 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
970 lcp_options
*wo
= &lcp_wantoptions
[f
->unit
];
971 u_char citype
, cichar
, *next
;
974 lcp_options no
; /* options we've seen Naks for */
975 lcp_options
try; /* options to request next time */
979 BZERO(&no
, sizeof(no
));
983 * Any Nak'd CIs must be in exactly the same order that we sent.
984 * Check packet length and CI length at each step.
985 * If we find any deviations, then this packet is bad.
987 #define NAKCIVOID(opt, neg) \
989 len >= CILEN_VOID && \
990 p[1] == CILEN_VOID && \
993 INCPTR(CILEN_VOID, p); \
997 #define NAKCICHAP(opt, neg, code) \
999 len >= CILEN_CHAP && \
1000 p[1] == CILEN_CHAP && \
1002 len -= CILEN_CHAP; \
1004 GETSHORT(cishort, p); \
1005 GETCHAR(cichar, p); \
1009 #define NAKCICHAR(opt, neg, code) \
1011 len >= CILEN_CHAR && \
1012 p[1] == CILEN_CHAR && \
1014 len -= CILEN_CHAR; \
1016 GETCHAR(cichar, p); \
1020 #define NAKCISHORT(opt, neg, code) \
1022 len >= CILEN_SHORT && \
1023 p[1] == CILEN_SHORT && \
1025 len -= CILEN_SHORT; \
1027 GETSHORT(cishort, p); \
1031 #define NAKCILONG(opt, neg, code) \
1033 len >= CILEN_LONG && \
1034 p[1] == CILEN_LONG && \
1036 len -= CILEN_LONG; \
1038 GETLONG(cilong, p); \
1042 #define NAKCILQR(opt, neg, code) \
1044 len >= CILEN_LQR && \
1045 p[1] == CILEN_LQR && \
1049 GETSHORT(cishort, p); \
1050 GETLONG(cilong, p); \
1054 #define NAKCIENDP(opt, neg) \
1056 len >= CILEN_CHAR && \
1058 p[1] >= CILEN_CHAR && \
1067 * NOTE! There must be no assignments to individual fields of *go in
1068 * the code below. Any such assignment is a BUG!
1071 * We don't care if they want to send us smaller packets than
1072 * we want. Therefore, accept any MRU less than what we asked for,
1073 * but then ignore the new value when setting the MRU in the kernel.
1074 * If they send us a bigger MRU than what we asked, accept it, up to
1075 * the limit of the default MRU we'd get if we didn't negotiate.
1077 if (go
->neg_mru
&& go
->mru
!= DEFMRU
) {
1078 NAKCISHORT(CI_MRU
, neg_mru
,
1079 if (cishort
<= wo
->mru
|| cishort
<= DEFMRU
)
1085 * Add any characters they want to our (receive-side) asyncmap.
1087 if (go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFF) {
1088 NAKCILONG(CI_ASYNCMAP
, neg_asyncmap
,
1089 try.asyncmap
= go
->asyncmap
| cilong
;
1094 * If they've nak'd our authentication-protocol, check whether
1095 * they are proposing a different protocol, or a different
1096 * hash algorithm for CHAP.
1098 if ((go
->neg_chap
|| go
->neg_upap
|| go
->neg_eap
)
1099 && len
>= CILEN_SHORT
1100 && p
[0] == CI_AUTHTYPE
&& p
[1] >= CILEN_SHORT
&& p
[1] <= len
) {
1103 no
.neg_chap
= go
->neg_chap
;
1104 no
.neg_upap
= go
->neg_upap
;
1105 no
.neg_eap
= go
->neg_eap
;
1107 GETSHORT(cishort
, p
);
1108 if (cishort
== PPP_PAP
&& cilen
== CILEN_SHORT
) {
1109 /* If we were asking for EAP, then we need to stop that. */
1113 /* If we were asking for CHAP, then we need to stop that. */
1114 else if (go
->neg_chap
)
1117 * If we weren't asking for CHAP or EAP, then we were asking for
1118 * PAP, in which case this Nak is bad.
1123 } else if (cishort
== PPP_CHAP
&& cilen
== CILEN_CHAP
) {
1125 /* Stop asking for EAP, if we were. */
1128 /* Try to set up to use their suggestion, if possible */
1129 if (CHAP_CANDIGEST(go
->chap_mdtype
, cichar
))
1130 try.chap_mdtype
= CHAP_MDTYPE_D(cichar
);
1131 } else if (go
->neg_chap
) {
1133 * We were asking for our preferred algorithm, they must
1134 * want something different.
1136 if (cichar
!= CHAP_DIGEST(go
->chap_mdtype
)) {
1137 if (CHAP_CANDIGEST(go
->chap_mdtype
, cichar
)) {
1138 /* Use their suggestion if we support it ... */
1139 try.chap_mdtype
= CHAP_MDTYPE_D(cichar
);
1141 /* ... otherwise, try our next-preferred algorithm. */
1142 try.chap_mdtype
&= ~(CHAP_MDTYPE(try.chap_mdtype
));
1143 if (try.chap_mdtype
== MDTYPE_NONE
) /* out of algos */
1148 * Whoops, they Nak'd our algorithm of choice
1149 * but then suggested it back to us.
1155 * Stop asking for PAP if we were asking for it.
1163 * If we were asking for EAP, and they're Conf-Naking EAP,
1164 * well, that's just strange. Nobody should do that.
1166 if (cishort
== PPP_EAP
&& cilen
== CILEN_SHORT
&& go
->neg_eap
)
1167 dbglog("Unexpected Conf-Nak for EAP");
1170 * We don't recognize what they're suggesting.
1171 * Stop asking for what we were asking for.
1175 else if (go
->neg_chap
)
1179 p
+= cilen
- CILEN_SHORT
;
1184 * If they can't cope with our link quality protocol, we'll have
1185 * to stop asking for LQR. We haven't got any other protocol.
1186 * If they Nak the reporting period, take their value XXX ?
1188 NAKCILQR(CI_QUALITY
, neg_lqr
,
1189 if (cishort
!= PPP_LQR
)
1192 try.lqr_period
= cilong
;
1196 * Only implementing CBCP...not the rest of the callback options
1198 NAKCICHAR(CI_CALLBACK
, neg_cbcp
,
1203 * Check for a looped-back line.
1205 NAKCILONG(CI_MAGICNUMBER
, neg_magicnumber
,
1206 try.magicnumber
= magic();
1211 * Peer shouldn't send Nak for protocol compression or
1212 * address/control compression requests; they should send
1213 * a Reject instead. If they send a Nak, treat it as a Reject.
1215 NAKCIVOID(CI_PCOMPRESSION
, neg_pcompression
);
1216 NAKCIVOID(CI_ACCOMPRESSION
, neg_accompression
);
1219 * Nak for MRRU option - accept their value if it is smaller
1220 * than the one we want.
1223 NAKCISHORT(CI_MRRU
, neg_mrru
,
1224 if (treat_as_reject
)
1226 else if (cishort
<= wo
->mrru
)
1232 * Nak for short sequence numbers shouldn't be sent, treat it
1235 NAKCIVOID(CI_SSNHF
, neg_ssnhf
);
1238 * Nak of the endpoint discriminator option is not permitted,
1239 * treat it like a reject.
1241 NAKCIENDP(CI_EPDISC
, neg_endpoint
);
1244 * There may be remaining CIs, if the peer is requesting negotiation
1245 * on an option that we didn't include in our request packet.
1246 * If we see an option that we requested, or one we've already seen
1247 * in this packet, then this packet is bad.
1248 * If we wanted to respond by starting to negotiate on the requested
1249 * option(s), we could, but we don't, because except for the
1250 * authentication type and quality protocol, if we are not negotiating
1251 * an option, it is because we were told not to.
1252 * For the authentication type, the Nak from the peer means
1253 * `let me authenticate myself with you' which is a bit pointless.
1254 * For the quality protocol, the Nak means `ask me to send you quality
1255 * reports', but if we didn't ask for them, we don't want them.
1256 * An option we don't recognize represents the peer asking to
1257 * negotiate some option we don't support, so ignore it.
1259 while (len
>= CILEN_VOID
) {
1262 if (cilen
< CILEN_VOID
|| (len
-= cilen
) < 0)
1264 next
= p
+ cilen
- 2;
1268 if ((go
->neg_mru
&& go
->mru
!= DEFMRU
)
1269 || no
.neg_mru
|| cilen
!= CILEN_SHORT
)
1271 GETSHORT(cishort
, p
);
1272 if (cishort
< DEFMRU
) {
1278 if ((go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFF)
1279 || no
.neg_asyncmap
|| cilen
!= CILEN_LONG
)
1283 if (go
->neg_chap
|| no
.neg_chap
|| go
->neg_upap
|| no
.neg_upap
||
1284 go
->neg_eap
|| no
.neg_eap
)
1287 case CI_MAGICNUMBER
:
1288 if (go
->neg_magicnumber
|| no
.neg_magicnumber
||
1289 cilen
!= CILEN_LONG
)
1292 case CI_PCOMPRESSION
:
1293 if (go
->neg_pcompression
|| no
.neg_pcompression
1294 || cilen
!= CILEN_VOID
)
1297 case CI_ACCOMPRESSION
:
1298 if (go
->neg_accompression
|| no
.neg_accompression
1299 || cilen
!= CILEN_VOID
)
1303 if (go
->neg_lqr
|| no
.neg_lqr
|| cilen
!= CILEN_LQR
)
1307 if (go
->neg_mrru
|| no
.neg_mrru
|| cilen
!= CILEN_SHORT
)
1311 if (go
->neg_ssnhf
|| no
.neg_ssnhf
|| cilen
!= CILEN_VOID
)
1316 if (go
->neg_endpoint
|| no
.neg_endpoint
|| cilen
< CILEN_CHAR
)
1324 * OK, the Nak is good. Now we can update state.
1325 * If there are any options left we ignore them.
1327 if (f
->state
!= OPENED
) {
1329 if (++try.numloops
>= lcp_loopbackfail
) {
1330 notice("Serial line is looped back.");
1331 status
= EXIT_LOOPBACK
;
1332 lcp_close(f
->unit
, "Loopback detected");
1342 LCPDEBUG(("lcp_nakci: received bad Nak!"));
1348 * lcp_rejci - Peer has Rejected some of our CIs.
1349 * This should not modify any state if the Reject is bad
1350 * or if LCP is in the OPENED state.
1353 * 0 - Reject was bad.
1354 * 1 - Reject was good.
1357 lcp_rejci(f
, p
, len
)
1362 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
1366 lcp_options
try; /* options to request next time */
1371 * Any Rejected CIs must be in exactly the same order that we sent.
1372 * Check packet length and CI length at each step.
1373 * If we find any deviations, then this packet is bad.
1375 #define REJCIVOID(opt, neg) \
1377 len >= CILEN_VOID && \
1378 p[1] == CILEN_VOID && \
1380 len -= CILEN_VOID; \
1381 INCPTR(CILEN_VOID, p); \
1384 #define REJCISHORT(opt, neg, val) \
1386 len >= CILEN_SHORT && \
1387 p[1] == CILEN_SHORT && \
1389 len -= CILEN_SHORT; \
1391 GETSHORT(cishort, p); \
1392 /* Check rejected value. */ \
1393 if (cishort != val) \
1397 #define REJCICHAP(opt, neg, val) \
1399 len >= CILEN_CHAP && \
1400 p[1] == CILEN_CHAP && \
1402 len -= CILEN_CHAP; \
1404 GETSHORT(cishort, p); \
1405 GETCHAR(cichar, p); \
1406 /* Check rejected value. */ \
1407 if ((cishort != PPP_CHAP) || (cichar != (CHAP_DIGEST(val)))) \
1410 try.neg_eap = try.neg_upap = 0; \
1412 #define REJCILONG(opt, neg, val) \
1414 len >= CILEN_LONG && \
1415 p[1] == CILEN_LONG && \
1417 len -= CILEN_LONG; \
1419 GETLONG(cilong, p); \
1420 /* Check rejected value. */ \
1421 if (cilong != val) \
1425 #define REJCILQR(opt, neg, val) \
1427 len >= CILEN_LQR && \
1428 p[1] == CILEN_LQR && \
1432 GETSHORT(cishort, p); \
1433 GETLONG(cilong, p); \
1434 /* Check rejected value. */ \
1435 if (cishort != PPP_LQR || cilong != val) \
1439 #define REJCICBCP(opt, neg, val) \
1441 len >= CILEN_CBCP && \
1442 p[1] == CILEN_CBCP && \
1444 len -= CILEN_CBCP; \
1446 GETCHAR(cichar, p); \
1447 /* Check rejected value. */ \
1448 if (cichar != val) \
1452 #define REJCIENDP(opt, neg, class, val, vlen) \
1454 len >= CILEN_CHAR + vlen && \
1456 p[1] == CILEN_CHAR + vlen) { \
1458 len -= CILEN_CHAR + vlen; \
1460 GETCHAR(cichar, p); \
1461 if (cichar != class) \
1463 for (i = 0; i < vlen; ++i) { \
1464 GETCHAR(cichar, p); \
1465 if (cichar != val[i]) \
1471 REJCISHORT(CI_MRU
, neg_mru
, go
->mru
);
1472 REJCILONG(CI_ASYNCMAP
, neg_asyncmap
, go
->asyncmap
);
1473 REJCISHORT(CI_AUTHTYPE
, neg_eap
, PPP_EAP
);
1475 REJCICHAP(CI_AUTHTYPE
, neg_chap
, go
->chap_mdtype
);
1476 if (!go
->neg_chap
) {
1477 REJCISHORT(CI_AUTHTYPE
, neg_upap
, PPP_PAP
);
1480 REJCILQR(CI_QUALITY
, neg_lqr
, go
->lqr_period
);
1481 REJCICBCP(CI_CALLBACK
, neg_cbcp
, CBCP_OPT
);
1482 REJCILONG(CI_MAGICNUMBER
, neg_magicnumber
, go
->magicnumber
);
1483 REJCIVOID(CI_PCOMPRESSION
, neg_pcompression
);
1484 REJCIVOID(CI_ACCOMPRESSION
, neg_accompression
);
1485 REJCISHORT(CI_MRRU
, neg_mrru
, go
->mrru
);
1486 REJCIVOID(CI_SSNHF
, neg_ssnhf
);
1487 REJCIENDP(CI_EPDISC
, neg_endpoint
, go
->endpoint
.class,
1488 go
->endpoint
.value
, go
->endpoint
.length
);
1491 * If there are any remaining CIs, then this packet is bad.
1496 * Now we can update state.
1498 if (f
->state
!= OPENED
)
1503 LCPDEBUG(("lcp_rejci: received bad Reject!"));
1509 * lcp_reqci - Check the peer's requested CIs and send appropriate response.
1511 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
1512 * appropriately. If reject_if_disagree is non-zero, doesn't return
1513 * CONFNAK; returns CONFREJ if it can't return CONFACK.
1516 lcp_reqci(f
, inp
, lenp
, reject_if_disagree
)
1518 u_char
*inp
; /* Requested CIs */
1519 int *lenp
; /* Length of requested CIs */
1520 int reject_if_disagree
;
1522 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
1523 lcp_options
*ho
= &lcp_hisoptions
[f
->unit
];
1524 lcp_options
*ao
= &lcp_allowoptions
[f
->unit
];
1525 u_char
*cip
, *next
; /* Pointer to current and next CIs */
1526 int cilen
, citype
, cichar
; /* Parsed len, type, char value */
1527 u_short cishort
; /* Parsed short value */
1528 u_int32_t cilong
; /* Parse long value */
1529 int rc
= CONFACK
; /* Final packet return code */
1530 int orc
; /* Individual option return code */
1531 u_char
*p
; /* Pointer to next char to parse */
1532 u_char
*rejp
; /* Pointer to next char in reject frame */
1533 u_char
*nakp
; /* Pointer to next char in Nak frame */
1534 int l
= *lenp
; /* Length left */
1537 * Reset all his options.
1539 BZERO(ho
, sizeof(*ho
));
1542 * Process all his options.
1548 orc
= CONFACK
; /* Assume success */
1549 cip
= p
= next
; /* Remember begining of CI */
1550 if (l
< 2 || /* Not enough data for CI header or */
1551 p
[1] < 2 || /* CI length too small or */
1552 p
[1] > l
) { /* CI length too big? */
1553 LCPDEBUG(("lcp_reqci: bad CI length!"));
1554 orc
= CONFREJ
; /* Reject bad CI */
1555 cilen
= l
; /* Reject till end of packet */
1556 l
= 0; /* Don't loop again */
1560 GETCHAR(citype
, p
); /* Parse CI type */
1561 GETCHAR(cilen
, p
); /* Parse CI length */
1562 l
-= cilen
; /* Adjust remaining length */
1563 next
+= cilen
; /* Step to next CI */
1565 switch (citype
) { /* Check CI type */
1567 if (!ao
->neg_mru
|| /* Allow option? */
1568 cilen
!= CILEN_SHORT
) { /* Check CI length */
1569 orc
= CONFREJ
; /* Reject CI */
1572 GETSHORT(cishort
, p
); /* Parse MRU */
1575 * He must be able to receive at least our minimum.
1576 * No need to check a maximum. If he sends a large number,
1577 * we'll just ignore it.
1579 if (cishort
< MINMRU
) {
1580 orc
= CONFNAK
; /* Nak CI */
1581 PUTCHAR(CI_MRU
, nakp
);
1582 PUTCHAR(CILEN_SHORT
, nakp
);
1583 PUTSHORT(MINMRU
, nakp
); /* Give him a hint */
1586 ho
->neg_mru
= 1; /* Remember he sent MRU */
1587 ho
->mru
= cishort
; /* And remember value */
1591 if (!ao
->neg_asyncmap
||
1592 cilen
!= CILEN_LONG
) {
1599 * Asyncmap must have set at least the bits
1600 * which are set in lcp_allowoptions[unit].asyncmap.
1602 if ((ao
->asyncmap
& ~cilong
) != 0) {
1604 PUTCHAR(CI_ASYNCMAP
, nakp
);
1605 PUTCHAR(CILEN_LONG
, nakp
);
1606 PUTLONG(ao
->asyncmap
| cilong
, nakp
);
1609 ho
->neg_asyncmap
= 1;
1610 ho
->asyncmap
= cilong
;
1614 if (cilen
< CILEN_SHORT
||
1615 !(ao
->neg_upap
|| ao
->neg_chap
|| ao
->neg_eap
)) {
1617 * Reject the option if we're not willing to authenticate.
1619 dbglog("No auth is possible");
1623 GETSHORT(cishort
, p
);
1626 * Authtype must be PAP, CHAP, or EAP.
1628 * Note: if more than one of ao->neg_upap, ao->neg_chap, and
1629 * ao->neg_eap are set, and the peer sends a Configure-Request
1630 * with two or more authenticate-protocol requests, then we will
1631 * reject the second request.
1632 * Whether we end up doing CHAP, UPAP, or EAP depends then on
1633 * the ordering of the CIs in the peer's Configure-Request.
1636 if (cishort
== PPP_PAP
) {
1637 /* we've already accepted CHAP or EAP */
1638 if (ho
->neg_chap
|| ho
->neg_eap
||
1639 cilen
!= CILEN_SHORT
) {
1640 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE PAP, rejecting..."));
1644 if (!ao
->neg_upap
) { /* we don't want to do PAP */
1645 orc
= CONFNAK
; /* NAK it and suggest CHAP or EAP */
1646 PUTCHAR(CI_AUTHTYPE
, nakp
);
1648 PUTCHAR(CILEN_SHORT
, nakp
);
1649 PUTSHORT(PPP_EAP
, nakp
);
1651 PUTCHAR(CILEN_CHAP
, nakp
);
1652 PUTSHORT(PPP_CHAP
, nakp
);
1653 PUTCHAR(CHAP_DIGEST(ao
->chap_mdtype
), nakp
);
1660 if (cishort
== PPP_CHAP
) {
1661 /* we've already accepted PAP or EAP */
1662 if (ho
->neg_upap
|| ho
->neg_eap
||
1663 cilen
!= CILEN_CHAP
) {
1664 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE CHAP, rejecting..."));
1668 if (!ao
->neg_chap
) { /* we don't want to do CHAP */
1669 orc
= CONFNAK
; /* NAK it and suggest EAP or PAP */
1670 PUTCHAR(CI_AUTHTYPE
, nakp
);
1671 PUTCHAR(CILEN_SHORT
, nakp
);
1673 PUTSHORT(PPP_EAP
, nakp
);
1675 PUTSHORT(PPP_PAP
, nakp
);
1679 GETCHAR(cichar
, p
); /* get digest type */
1680 if (!(CHAP_CANDIGEST(ao
->chap_mdtype
, cichar
))) {
1682 * We can't/won't do the requested type,
1683 * suggest something else.
1686 PUTCHAR(CI_AUTHTYPE
, nakp
);
1687 PUTCHAR(CILEN_CHAP
, nakp
);
1688 PUTSHORT(PPP_CHAP
, nakp
);
1689 PUTCHAR(CHAP_DIGEST(ao
->chap_mdtype
), nakp
);
1692 ho
->chap_mdtype
= CHAP_MDTYPE_D(cichar
); /* save md type */
1696 if (cishort
== PPP_EAP
) {
1697 /* we've already accepted CHAP or PAP */
1698 if (ho
->neg_chap
|| ho
->neg_upap
|| cilen
!= CILEN_SHORT
) {
1699 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE EAP, rejecting..."));
1703 if (!ao
->neg_eap
) { /* we don't want to do EAP */
1704 orc
= CONFNAK
; /* NAK it and suggest CHAP or PAP */
1705 PUTCHAR(CI_AUTHTYPE
, nakp
);
1707 PUTCHAR(CILEN_CHAP
, nakp
);
1708 PUTSHORT(PPP_CHAP
, nakp
);
1709 PUTCHAR(CHAP_DIGEST(ao
->chap_mdtype
), nakp
);
1711 PUTCHAR(CILEN_SHORT
, nakp
);
1712 PUTSHORT(PPP_PAP
, nakp
);
1721 * We don't recognize the protocol they're asking for.
1722 * Nak it with something we're willing to do.
1723 * (At this point we know ao->neg_upap || ao->neg_chap ||
1727 PUTCHAR(CI_AUTHTYPE
, nakp
);
1729 PUTCHAR(CILEN_SHORT
, nakp
);
1730 PUTSHORT(PPP_EAP
, nakp
);
1731 } else if (ao
->neg_chap
) {
1732 PUTCHAR(CILEN_CHAP
, nakp
);
1733 PUTSHORT(PPP_CHAP
, nakp
);
1734 PUTCHAR(CHAP_DIGEST(ao
->chap_mdtype
), nakp
);
1736 PUTCHAR(CILEN_SHORT
, nakp
);
1737 PUTSHORT(PPP_PAP
, nakp
);
1743 cilen
!= CILEN_LQR
) {
1748 GETSHORT(cishort
, p
);
1752 * Check the protocol and the reporting period.
1753 * XXX When should we Nak this, and what with?
1755 if (cishort
!= PPP_LQR
) {
1757 PUTCHAR(CI_QUALITY
, nakp
);
1758 PUTCHAR(CILEN_LQR
, nakp
);
1759 PUTSHORT(PPP_LQR
, nakp
);
1760 PUTLONG(ao
->lqr_period
, nakp
);
1765 case CI_MAGICNUMBER
:
1766 if (!(ao
->neg_magicnumber
|| go
->neg_magicnumber
) ||
1767 cilen
!= CILEN_LONG
) {
1774 * He must have a different magic number.
1776 if (go
->neg_magicnumber
&&
1777 cilong
== go
->magicnumber
) {
1778 cilong
= magic(); /* Don't put magic() inside macro! */
1780 PUTCHAR(CI_MAGICNUMBER
, nakp
);
1781 PUTCHAR(CILEN_LONG
, nakp
);
1782 PUTLONG(cilong
, nakp
);
1785 ho
->neg_magicnumber
= 1;
1786 ho
->magicnumber
= cilong
;
1790 case CI_PCOMPRESSION
:
1791 if (!ao
->neg_pcompression
||
1792 cilen
!= CILEN_VOID
) {
1796 ho
->neg_pcompression
= 1;
1799 case CI_ACCOMPRESSION
:
1800 if (!ao
->neg_accompression
||
1801 cilen
!= CILEN_VOID
) {
1805 ho
->neg_accompression
= 1;
1809 if (!ao
->neg_mrru
|| !multilink
||
1810 cilen
!= CILEN_SHORT
) {
1815 GETSHORT(cishort
, p
);
1816 /* possibly should insist on a minimum/maximum MRRU here */
1822 if (!ao
->neg_ssnhf
|| !multilink
||
1823 cilen
!= CILEN_VOID
) {
1831 if (!ao
->neg_endpoint
||
1832 cilen
< CILEN_CHAR
||
1833 cilen
> CILEN_CHAR
+ MAX_ENDP_LEN
) {
1838 cilen
-= CILEN_CHAR
;
1839 ho
->neg_endpoint
= 1;
1840 ho
->endpoint
.class = cichar
;
1841 ho
->endpoint
.length
= cilen
;
1842 BCOPY(p
, ho
->endpoint
.value
, cilen
);
1847 LCPDEBUG(("lcp_reqci: rcvd unknown option %d", citype
));
1853 if (orc
== CONFACK
&& /* Good CI */
1854 rc
!= CONFACK
) /* but prior CI wasnt? */
1855 continue; /* Don't send this one */
1857 if (orc
== CONFNAK
) { /* Nak this CI? */
1858 if (reject_if_disagree
/* Getting fed up with sending NAKs? */
1859 && citype
!= CI_MAGICNUMBER
) {
1860 orc
= CONFREJ
; /* Get tough if so */
1862 if (rc
== CONFREJ
) /* Rejecting prior CI? */
1863 continue; /* Don't send this one */
1867 if (orc
== CONFREJ
) { /* Reject this CI */
1869 if (cip
!= rejp
) /* Need to move rejected CI? */
1870 BCOPY(cip
, rejp
, cilen
); /* Move it */
1871 INCPTR(cilen
, rejp
); /* Update output pointer */
1876 * If we wanted to send additional NAKs (for unsent CIs), the
1877 * code would go here. The extra NAKs would go at *nakp.
1878 * At present there are no cases where we want to ask the
1879 * peer to negotiate an option.
1888 * Copy the Nak'd options from the nak_buffer to the caller's buffer.
1890 *lenp
= nakp
- nak_buffer
;
1891 BCOPY(nak_buffer
, inp
, *lenp
);
1898 LCPDEBUG(("lcp_reqci: returning CONF%s.", CODENAME(rc
)));
1899 return (rc
); /* Return final code */
1904 * lcp_up - LCP has come UP.
1910 lcp_options
*wo
= &lcp_wantoptions
[f
->unit
];
1911 lcp_options
*ho
= &lcp_hisoptions
[f
->unit
];
1912 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
1913 lcp_options
*ao
= &lcp_allowoptions
[f
->unit
];
1916 if (!go
->neg_magicnumber
)
1917 go
->magicnumber
= 0;
1918 if (!ho
->neg_magicnumber
)
1919 ho
->magicnumber
= 0;
1922 * Set our MTU to the smaller of the MTU we wanted and
1923 * the MRU our peer wanted. If we negotiated an MRU,
1924 * set our MRU to the larger of value we wanted and
1925 * the value we got in the negotiation.
1926 * Note on the MTU: the link MTU can be the MRU the peer wanted,
1927 * the interface MTU is set to the lowest of that, the
1928 * MTU we want to use, and our link MRU.
1930 mtu
= ho
->neg_mru
? ho
->mru
: PPP_MRU
;
1931 mru
= go
->neg_mru
? MAX(wo
->mru
, go
->mru
): PPP_MRU
;
1932 #ifdef HAVE_MULTILINK
1933 if (!(multilink
&& go
->neg_mrru
&& ho
->neg_mrru
))
1934 #endif /* HAVE_MULTILINK */
1935 netif_set_mtu(f
->unit
, MIN(MIN(mtu
, mru
), ao
->mru
));
1936 ppp_send_config(f
->unit
, mtu
,
1937 (ho
->neg_asyncmap
? ho
->asyncmap
: 0xffffffff),
1938 ho
->neg_pcompression
, ho
->neg_accompression
);
1939 ppp_recv_config(f
->unit
, mru
,
1940 (lax_recv
? 0: go
->neg_asyncmap
? go
->asyncmap
: 0xffffffff),
1941 go
->neg_pcompression
, go
->neg_accompression
);
1944 peer_mru
[f
->unit
] = ho
->mru
;
1946 if (lcp_up_hook
) (*lcp_up_hook
)();
1948 lcp_echo_lowerup(f
->unit
); /* Enable echo messages */
1950 link_established(f
->unit
);
1955 * lcp_down - LCP has gone DOWN.
1957 * Alert other protocols.
1963 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
1965 lcp_echo_lowerdown(f
->unit
);
1969 if (lcp_down_hook
) (*lcp_down_hook
)();
1971 ppp_send_config(f
->unit
, PPP_MRU
, 0xffffffff, 0, 0);
1972 ppp_recv_config(f
->unit
, PPP_MRU
,
1973 (go
->neg_asyncmap
? go
->asyncmap
: 0xffffffff),
1974 go
->neg_pcompression
, go
->neg_accompression
);
1975 peer_mru
[f
->unit
] = PPP_MRU
;
1980 * lcp_starting - LCP needs the lower layer up.
1986 link_required(f
->unit
);
1991 * lcp_finished - LCP has finished with the lower layer.
1997 link_terminated(f
->unit
);
2002 * lcp_printpkt - print the contents of an LCP packet.
2004 static char *lcp_codenames
[] = {
2005 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
2006 "TermReq", "TermAck", "CodeRej", "ProtRej",
2007 "EchoReq", "EchoRep", "DiscReq", "Ident",
2012 lcp_printpkt(p
, plen
, printer
, arg
)
2015 void (*printer
) __P((void *, char *, ...));
2018 int code
, id
, len
, olen
, i
;
2019 u_char
*pstart
, *optend
;
2023 if (plen
< HEADERLEN
)
2029 if (len
< HEADERLEN
|| len
> plen
)
2032 if (code
>= 1 && code
<= sizeof(lcp_codenames
) / sizeof(char *))
2033 printer(arg
, " %s", lcp_codenames
[code
-1]);
2035 printer(arg
, " code=0x%x", code
);
2036 printer(arg
, " id=0x%x", id
);
2043 /* print option list */
2048 if (olen
< 2 || olen
> len
) {
2056 if (olen
== CILEN_SHORT
) {
2058 GETSHORT(cishort
, p
);
2059 printer(arg
, "mru %d", cishort
);
2063 if (olen
== CILEN_LONG
) {
2066 printer(arg
, "asyncmap 0x%x", cilong
);
2070 if (olen
>= CILEN_SHORT
) {
2072 printer(arg
, "auth ");
2073 GETSHORT(cishort
, p
);
2076 printer(arg
, "pap");
2079 printer(arg
, "chap");
2083 printer(arg
, " MD5");
2087 case CHAP_MICROSOFT
:
2088 printer(arg
, " MS");
2092 case CHAP_MICROSOFT_V2
:
2093 printer(arg
, " MS-v2");
2101 printer(arg
, "eap");
2104 printer(arg
, "0x%x", cishort
);
2109 if (olen
>= CILEN_SHORT
) {
2111 printer(arg
, "quality ");
2112 GETSHORT(cishort
, p
);
2115 printer(arg
, "lqr");
2118 printer(arg
, "0x%x", cishort
);
2123 if (olen
>= CILEN_CHAR
) {
2125 printer(arg
, "callback ");
2126 GETCHAR(cishort
, p
);
2129 printer(arg
, "CBCP");
2132 printer(arg
, "0x%x", cishort
);
2136 case CI_MAGICNUMBER
:
2137 if (olen
== CILEN_LONG
) {
2140 printer(arg
, "magic 0x%x", cilong
);
2143 case CI_PCOMPRESSION
:
2144 if (olen
== CILEN_VOID
) {
2146 printer(arg
, "pcomp");
2149 case CI_ACCOMPRESSION
:
2150 if (olen
== CILEN_VOID
) {
2152 printer(arg
, "accomp");
2156 if (olen
== CILEN_SHORT
) {
2158 GETSHORT(cishort
, p
);
2159 printer(arg
, "mrru %d", cishort
);
2163 if (olen
== CILEN_VOID
) {
2165 printer(arg
, "ssnhf");
2169 #ifdef HAVE_MULTILINK
2170 if (olen
>= CILEN_CHAR
) {
2173 GETCHAR(epd
.class, p
);
2174 epd
.length
= olen
- CILEN_CHAR
;
2175 if (epd
.length
> MAX_ENDP_LEN
)
2176 epd
.length
= MAX_ENDP_LEN
;
2177 if (epd
.length
> 0) {
2178 BCOPY(p
, epd
.value
, epd
.length
);
2181 printer(arg
, "endpoint [%s]", epdisc_to_str(&epd
));
2184 printer(arg
, "endpoint");
2188 while (p
< optend
) {
2190 printer(arg
, " %.2x", code
);
2198 if (len
> 0 && *p
>= ' ' && *p
< 0x7f) {
2200 print_string((char *)p
, len
, printer
, arg
);
2211 printer(arg
, " magic=0x%x", cilong
);
2220 printer(arg
, " magic=0x%x", cilong
);
2223 if (code
== TIMEREM
) {
2227 printer(arg
, " seconds=%u", cilong
);
2232 print_string((char *)p
, len
, printer
, arg
);
2239 /* print the rest of the bytes in the packet */
2240 for (i
= 0; i
< len
&& i
< 32; ++i
) {
2242 printer(arg
, " %.2x", code
);
2245 printer(arg
, " ...");
2253 * Time to shut down the link because there is nothing out there.
2257 void LcpLinkFailure (f
)
2260 if (f
->state
== OPENED
) {
2261 info("No response to %d echo-requests", lcp_echos_pending
);
2262 notice("Serial link appears to be disconnected.");
2263 status
= EXIT_PEER_DEAD
;
2264 lcp_close(f
->unit
, "Peer not responding");
2269 * Timer expired for the LCP echo requests from this process.
2276 LcpSendEchoRequest (f
);
2277 if (f
->state
!= OPENED
)
2281 * Start the timer for the next interval.
2283 if (lcp_echo_timer_running
)
2284 warn("assertion lcp_echo_timer_running==0 failed");
2285 TIMEOUT (LcpEchoTimeout
, f
, lcp_echo_interval
);
2286 lcp_echo_timer_running
= 1;
2290 * LcpEchoTimeout - Timer expired on the LCP echo
2294 LcpEchoTimeout (arg
)
2297 if (lcp_echo_timer_running
!= 0) {
2298 lcp_echo_timer_running
= 0;
2299 LcpEchoCheck ((fsm
*) arg
);
2304 * LcpEchoReply - LCP has received a reply to the echo
2308 lcp_received_echo_reply (f
, id
, inp
, len
)
2316 /* Check the magic number - don't count replies from ourselves. */
2318 dbglog("lcp: received short Echo-Reply, length %d", len
);
2321 GETLONG(magic
, inp
);
2322 if (lcp_gotoptions
[f
->unit
].neg_magicnumber
2323 && magic
== lcp_gotoptions
[f
->unit
].magicnumber
) {
2324 warn("appear to have received our own echo-reply!");
2325 if (lcp_echoreply_hook
) (*lcp_echoreply_hook
)(1);
2328 if (lcp_echoreply_hook
) (*lcp_echoreply_hook
)(0);
2330 /* Reset the number of outstanding echo frames */
2331 lcp_echos_pending
= 0;
2335 * LcpSendEchoRequest - Send an echo request frame to the peer
2339 LcpSendEchoRequest (f
)
2342 u_int32_t lcp_magic
;
2343 u_char pkt
[4], *pktp
;
2346 * Detect the failure of the peer at this point.
2348 if (lcp_echo_fails
!= 0) {
2349 if (lcp_echos_pending
>= lcp_echo_fails
) {
2351 lcp_echos_pending
= 0;
2356 * Make and send the echo request frame.
2358 if (f
->state
== OPENED
) {
2359 if (lcp_echo_hook
) (*lcp_echo_hook
)(lcp_echos_pending
);
2360 lcp_magic
= lcp_gotoptions
[f
->unit
].magicnumber
;
2362 PUTLONG(lcp_magic
, pktp
);
2363 fsm_sdata(f
, ECHOREQ
, lcp_echo_number
++ & 0xFF, pkt
, pktp
- pkt
);
2364 ++lcp_echos_pending
;
2369 * lcp_echo_lowerup - Start the timer for the LCP frame
2373 lcp_echo_lowerup (unit
)
2376 fsm
*f
= &lcp_fsm
[unit
];
2378 /* Clear the parameters for generating echo frames */
2379 lcp_echos_pending
= 0;
2380 lcp_echo_number
= 0;
2381 lcp_echo_timer_running
= 0;
2383 /* If a timeout interval is specified then start the timer */
2384 if (lcp_echo_interval
!= 0)
2389 * lcp_echo_lowerdown - Stop the timer for the LCP frame
2393 lcp_echo_lowerdown (unit
)
2396 fsm
*f
= &lcp_fsm
[unit
];
2398 if (lcp_echo_timer_running
!= 0) {
2399 UNTIMEOUT (LcpEchoTimeout
, f
);
2400 lcp_echo_timer_running
= 0;