2 * lcp.c - PPP Link Control Protocol.
4 * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * 3. The name "Carnegie Mellon University" must not be used to
19 * endorse or promote products derived from this software without
20 * prior written permission. For permission or any legal
21 * details, please contact
22 * Office of Technology Transfer
23 * Carnegie Mellon University
25 * Pittsburgh, PA 15213-3890
26 * (412) 268-4387, fax: (412) 268-7395
27 * tech-transfer@andrew.cmu.edu
29 * 4. Redistributions of any form whatsoever must retain the following
31 * "This product includes software developed by Computing Services
32 * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
34 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
35 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
36 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
37 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
38 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
39 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
40 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
43 #define RCSID "$Id: lcp.c,v 1.71 2004/10/31 22:23:18 paulus Exp $"
59 static const char rcsid
[] = RCSID
;
62 * When the link comes up we want to be able to wait for a short while,
63 * or until seeing some input from the peer, before starting to send
64 * configure-requests. We do this by delaying the fsm_lowerup call.
66 /* steal a bit in fsm flags word */
67 #define DELAYED_UP 0x100
69 static void lcp_delayed_up
__P((void *));
72 * LCP-related command-line options.
74 int lcp_echo_interval
= 0; /* Interval between LCP echo-requests */
75 int lcp_echo_fails
= 0; /* Tolerance to unanswered echo-requests */
76 bool lax_recv
= 0; /* accept control chars in asyncmap */
77 bool noendpoint
= 0; /* don't send/accept endpoint discriminator */
79 static int noopt
__P((char **));
82 static int setendpoint
__P((char **));
83 static void printendpoint
__P((option_t
*, void (*)(void *, char *, ...),
85 #endif /* HAVE_MULTILINK */
87 static option_t lcp_option_list
[] = {
89 { "-all", o_special_noarg
, (void *)noopt
,
90 "Don't request/allow any LCP options" },
92 { "noaccomp", o_bool
, &lcp_wantoptions
[0].neg_accompression
,
93 "Disable address/control compression",
94 OPT_A2CLR
, &lcp_allowoptions
[0].neg_accompression
},
95 { "-ac", o_bool
, &lcp_wantoptions
[0].neg_accompression
,
96 "Disable address/control compression",
97 OPT_ALIAS
| OPT_A2CLR
, &lcp_allowoptions
[0].neg_accompression
},
99 { "asyncmap", o_uint32
, &lcp_wantoptions
[0].asyncmap
,
100 "Set asyncmap (for received packets)",
101 OPT_OR
, &lcp_wantoptions
[0].neg_asyncmap
},
102 { "-as", o_uint32
, &lcp_wantoptions
[0].asyncmap
,
103 "Set asyncmap (for received packets)",
104 OPT_ALIAS
| OPT_OR
, &lcp_wantoptions
[0].neg_asyncmap
},
105 { "default-asyncmap", o_uint32
, &lcp_wantoptions
[0].asyncmap
,
106 "Disable asyncmap negotiation",
107 OPT_OR
| OPT_NOARG
| OPT_VAL(~0U) | OPT_A2CLR
,
108 &lcp_allowoptions
[0].neg_asyncmap
},
109 { "-am", o_uint32
, &lcp_wantoptions
[0].asyncmap
,
110 "Disable asyncmap negotiation",
111 OPT_ALIAS
| OPT_OR
| OPT_NOARG
| OPT_VAL(~0U) | OPT_A2CLR
,
112 &lcp_allowoptions
[0].neg_asyncmap
},
114 { "nomagic", o_bool
, &lcp_wantoptions
[0].neg_magicnumber
,
115 "Disable magic number negotiation (looped-back line detection)",
116 OPT_A2CLR
, &lcp_allowoptions
[0].neg_magicnumber
},
117 { "-mn", o_bool
, &lcp_wantoptions
[0].neg_magicnumber
,
118 "Disable magic number negotiation (looped-back line detection)",
119 OPT_ALIAS
| OPT_A2CLR
, &lcp_allowoptions
[0].neg_magicnumber
},
121 { "mru", o_int
, &lcp_wantoptions
[0].mru
,
122 "Set MRU (maximum received packet size) for negotiation",
123 OPT_PRIO
, &lcp_wantoptions
[0].neg_mru
},
124 { "default-mru", o_bool
, &lcp_wantoptions
[0].neg_mru
,
125 "Disable MRU negotiation (use default 1500)",
126 OPT_PRIOSUB
| OPT_A2CLR
, &lcp_allowoptions
[0].neg_mru
},
127 { "-mru", o_bool
, &lcp_wantoptions
[0].neg_mru
,
128 "Disable MRU negotiation (use default 1500)",
129 OPT_ALIAS
| OPT_PRIOSUB
| OPT_A2CLR
, &lcp_allowoptions
[0].neg_mru
},
131 { "mtu", o_int
, &lcp_allowoptions
[0].mru
,
132 "Set our MTU", OPT_LIMITS
, NULL
, MAXMRU
, MINMRU
},
134 { "nopcomp", o_bool
, &lcp_wantoptions
[0].neg_pcompression
,
135 "Disable protocol field compression",
136 OPT_A2CLR
, &lcp_allowoptions
[0].neg_pcompression
},
137 { "-pc", o_bool
, &lcp_wantoptions
[0].neg_pcompression
,
138 "Disable protocol field compression",
139 OPT_ALIAS
| OPT_A2CLR
, &lcp_allowoptions
[0].neg_pcompression
},
141 { "passive", o_bool
, &lcp_wantoptions
[0].passive
,
142 "Set passive mode", 1 },
143 { "-p", o_bool
, &lcp_wantoptions
[0].passive
,
144 "Set passive mode", OPT_ALIAS
| 1 },
146 { "silent", o_bool
, &lcp_wantoptions
[0].silent
,
147 "Set silent mode", 1 },
149 { "lcp-echo-failure", o_int
, &lcp_echo_fails
,
150 "Set number of consecutive echo failures to indicate link failure",
152 { "lcp-echo-interval", o_int
, &lcp_echo_interval
,
153 "Set time in seconds between LCP echo requests", OPT_PRIO
},
154 { "lcp-restart", o_int
, &lcp_fsm
[0].timeouttime
,
155 "Set time in seconds between LCP retransmissions", OPT_PRIO
},
156 { "lcp-max-terminate", o_int
, &lcp_fsm
[0].maxtermtransmits
,
157 "Set maximum number of LCP terminate-request transmissions", OPT_PRIO
},
158 { "lcp-max-configure", o_int
, &lcp_fsm
[0].maxconfreqtransmits
,
159 "Set maximum number of LCP configure-request transmissions", OPT_PRIO
},
160 { "lcp-max-failure", o_int
, &lcp_fsm
[0].maxnakloops
,
161 "Set limit on number of LCP configure-naks", OPT_PRIO
},
163 { "receive-all", o_bool
, &lax_recv
,
164 "Accept all received control characters", 1 },
166 #ifdef HAVE_MULTILINK
167 { "mrru", o_int
, &lcp_wantoptions
[0].mrru
,
168 "Maximum received packet size for multilink bundle",
169 OPT_PRIO
, &lcp_wantoptions
[0].neg_mrru
},
171 { "mpshortseq", o_bool
, &lcp_wantoptions
[0].neg_ssnhf
,
172 "Use short sequence numbers in multilink headers",
173 OPT_PRIO
| 1, &lcp_allowoptions
[0].neg_ssnhf
},
174 { "nompshortseq", o_bool
, &lcp_wantoptions
[0].neg_ssnhf
,
175 "Don't use short sequence numbers in multilink headers",
176 OPT_PRIOSUB
| OPT_A2CLR
, &lcp_allowoptions
[0].neg_ssnhf
},
178 { "endpoint", o_special
, (void *) setendpoint
,
179 "Endpoint discriminator for multilink",
180 OPT_PRIO
| OPT_A2PRINTER
, (void *) printendpoint
},
181 #endif /* HAVE_MULTILINK */
183 { "noendpoint", o_bool
, &noendpoint
,
184 "Don't send or accept multilink endpoint discriminator", 1 },
190 fsm lcp_fsm
[NUM_PPP
]; /* LCP fsm structure (global)*/
191 lcp_options lcp_wantoptions
[NUM_PPP
]; /* Options that we want to request */
192 lcp_options lcp_gotoptions
[NUM_PPP
]; /* Options that peer ack'd */
193 lcp_options lcp_allowoptions
[NUM_PPP
]; /* Options we allow peer to request */
194 lcp_options lcp_hisoptions
[NUM_PPP
]; /* Options that we ack'd */
196 static int lcp_echos_pending
= 0; /* Number of outstanding echo msgs */
197 static int lcp_echo_number
= 0; /* ID number of next echo frame */
198 static int lcp_echo_timer_running
= 0; /* set if a timer is running */
200 static u_char nak_buffer
[PPP_MRU
]; /* where we construct a nak packet */
203 * Callbacks for fsm code. (CI = Configuration Information)
205 static void lcp_resetci
__P((fsm
*)); /* Reset our CI */
206 static int lcp_cilen
__P((fsm
*)); /* Return length of our CI */
207 static void lcp_addci
__P((fsm
*, u_char
*, int *)); /* Add our CI to pkt */
208 static int lcp_ackci
__P((fsm
*, u_char
*, int)); /* Peer ack'd our CI */
209 static int lcp_nakci
__P((fsm
*, u_char
*, int)); /* Peer nak'd our CI */
210 static int lcp_rejci
__P((fsm
*, u_char
*, int)); /* Peer rej'd our CI */
211 static int lcp_reqci
__P((fsm
*, u_char
*, int *, int)); /* Rcv peer CI */
212 static void lcp_up
__P((fsm
*)); /* We're UP */
213 static void lcp_down
__P((fsm
*)); /* We're DOWN */
214 static void lcp_starting
__P((fsm
*)); /* We need lower layer up */
215 static void lcp_finished
__P((fsm
*)); /* We need lower layer down */
216 static int lcp_extcode
__P((fsm
*, int, int, u_char
*, int));
217 static void lcp_rprotrej
__P((fsm
*, u_char
*, int));
220 * routines to send LCP echos to peer
223 static void lcp_echo_lowerup
__P((int));
224 static void lcp_echo_lowerdown
__P((int));
225 static void LcpEchoTimeout
__P((void *));
226 static void lcp_received_echo_reply
__P((fsm
*, int, u_char
*, int));
227 static void LcpSendEchoRequest
__P((fsm
*));
228 static void LcpLinkFailure
__P((fsm
*));
229 static void LcpEchoCheck
__P((fsm
*));
231 static fsm_callbacks lcp_callbacks
= { /* LCP callback routines */
232 lcp_resetci
, /* Reset our Configuration Information */
233 lcp_cilen
, /* Length of our Configuration Information */
234 lcp_addci
, /* Add our Configuration Information */
235 lcp_ackci
, /* ACK our Configuration Information */
236 lcp_nakci
, /* NAK our Configuration Information */
237 lcp_rejci
, /* Reject our Configuration Information */
238 lcp_reqci
, /* Request peer's Configuration Information */
239 lcp_up
, /* Called when fsm reaches OPENED state */
240 lcp_down
, /* Called when fsm leaves OPENED state */
241 lcp_starting
, /* Called when we want the lower layer up */
242 lcp_finished
, /* Called when we want the lower layer down */
243 NULL
, /* Called when Protocol-Reject received */
244 NULL
, /* Retransmission is necessary */
245 lcp_extcode
, /* Called to handle LCP-specific codes */
246 "LCP" /* String name of protocol */
250 * Protocol entry points.
251 * Some of these are called directly.
254 static void lcp_init
__P((int));
255 static void lcp_input
__P((int, u_char
*, int));
256 static void lcp_protrej
__P((int));
257 static int lcp_printpkt
__P((u_char
*, int,
258 void (*) __P((void *, char *, ...)), void *));
260 struct protent lcp_protent
= {
280 int lcp_loopbackfail
= DEFLOOPBACKFAIL
;
283 * Length of each type of configuration option (in octets)
287 #define CILEN_SHORT 4 /* CILEN_VOID + 2 */
288 #define CILEN_CHAP 5 /* CILEN_VOID + 2 + 1 */
289 #define CILEN_LONG 6 /* CILEN_VOID + 4 */
290 #define CILEN_LQR 8 /* CILEN_VOID + 2 + 4 */
293 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
294 (x) == CONFNAK ? "NAK" : "REJ")
297 * noopt - Disable all options (why?).
303 BZERO((char *) &lcp_wantoptions
[0], sizeof (struct lcp_options
));
304 BZERO((char *) &lcp_allowoptions
[0], sizeof (struct lcp_options
));
309 #ifdef HAVE_MULTILINK
314 if (str_to_epdisc(&lcp_wantoptions
[0].endpoint
, *argv
)) {
315 lcp_wantoptions
[0].neg_endpoint
= 1;
318 option_error("Can't parse '%s' as an endpoint discriminator", *argv
);
323 printendpoint(opt
, printer
, arg
)
325 void (*printer
) __P((void *, char *, ...));
328 printer(arg
, "%s", epdisc_to_str(&lcp_wantoptions
[0].endpoint
));
330 #endif /* HAVE_MULTILINK */
333 * lcp_init - Initialize LCP.
339 fsm
*f
= &lcp_fsm
[unit
];
340 lcp_options
*wo
= &lcp_wantoptions
[unit
];
341 lcp_options
*ao
= &lcp_allowoptions
[unit
];
344 f
->protocol
= PPP_LCP
;
345 f
->callbacks
= &lcp_callbacks
;
349 BZERO(wo
, sizeof(*wo
));
352 wo
->neg_asyncmap
= 1;
353 wo
->neg_magicnumber
= 1;
354 wo
->neg_pcompression
= 1;
355 wo
->neg_accompression
= 1;
357 BZERO(ao
, sizeof(*ao
));
360 ao
->neg_asyncmap
= 1;
362 ao
->chap_mdtype
= chap_mdtype_all
;
365 ao
->neg_magicnumber
= 1;
366 ao
->neg_pcompression
= 1;
367 ao
->neg_accompression
= 1;
371 ao
->neg_endpoint
= 1;
376 * lcp_open - LCP is allowed to come up.
382 fsm
*f
= &lcp_fsm
[unit
];
383 lcp_options
*wo
= &lcp_wantoptions
[unit
];
385 f
->flags
&= ~(OPT_PASSIVE
| OPT_SILENT
);
387 f
->flags
|= OPT_PASSIVE
;
389 f
->flags
|= OPT_SILENT
;
395 * lcp_close - Take LCP down.
398 lcp_close(unit
, reason
)
402 fsm
*f
= &lcp_fsm
[unit
];
404 if (phase
!= PHASE_DEAD
)
405 new_phase(PHASE_TERMINATE
);
406 if (f
->state
== STOPPED
&& f
->flags
& (OPT_PASSIVE
|OPT_SILENT
)) {
408 * This action is not strictly according to the FSM in RFC1548,
409 * but it does mean that the program terminates if you do a
410 * lcp_close() in passive/silent mode when a connection hasn't
417 fsm_close(f
, reason
);
422 * lcp_lowerup - The lower layer is up.
428 lcp_options
*wo
= &lcp_wantoptions
[unit
];
429 fsm
*f
= &lcp_fsm
[unit
];
432 * Don't use A/C or protocol compression on transmission,
433 * but accept A/C and protocol compressed packets
434 * if we are going to ask for A/C and protocol compression.
436 if (ppp_send_config(unit
, PPP_MRU
, 0xffffffff, 0, 0) < 0
437 || ppp_recv_config(unit
, PPP_MRU
, (lax_recv
? 0: 0xffffffff),
438 wo
->neg_pcompression
, wo
->neg_accompression
) < 0)
440 peer_mru
[unit
] = PPP_MRU
;
442 if (listen_time
!= 0) {
443 f
->flags
|= DELAYED_UP
;
444 timeout(lcp_delayed_up
, f
, 0, listen_time
* 1000);
451 * lcp_lowerdown - The lower layer is down.
457 fsm
*f
= &lcp_fsm
[unit
];
459 if (f
->flags
& DELAYED_UP
)
460 f
->flags
&= ~DELAYED_UP
;
462 fsm_lowerdown(&lcp_fsm
[unit
]);
467 * lcp_delayed_up - Bring the lower layer up now.
475 if (f
->flags
& DELAYED_UP
) {
476 f
->flags
&= ~DELAYED_UP
;
483 * lcp_input - Input LCP packet.
486 lcp_input(unit
, p
, len
)
491 fsm
*f
= &lcp_fsm
[unit
];
493 if (f
->flags
& DELAYED_UP
) {
494 f
->flags
&= ~DELAYED_UP
;
497 fsm_input(f
, p
, len
);
502 * lcp_extcode - Handle a LCP-specific code.
505 lcp_extcode(f
, code
, id
, inp
, len
)
515 lcp_rprotrej(f
, inp
, len
);
519 if (f
->state
!= OPENED
)
522 PUTLONG(lcp_gotoptions
[f
->unit
].magicnumber
, magp
);
523 fsm_sdata(f
, ECHOREP
, id
, inp
, len
);
527 lcp_received_echo_reply(f
, id
, inp
, len
);
541 * lcp_rprotrej - Receive an Protocol-Reject.
543 * Figure out which protocol is rejected and inform it.
546 lcp_rprotrej(f
, inp
, len
)
552 struct protent
*protp
;
556 LCPDEBUG(("lcp_rprotrej: Rcvd short Protocol-Reject packet!"));
563 * Protocol-Reject packets received in any state other than the LCP
564 * OPENED state SHOULD be silently discarded.
566 if( f
->state
!= OPENED
){
567 LCPDEBUG(("Protocol-Reject discarded: LCP in state %d", f
->state
));
572 * Upcall the proper Protocol-Reject routine.
574 for (i
= 0; (protp
= protocols
[i
]) != NULL
; ++i
)
575 if (protp
->protocol
== prot
&& protp
->enabled_flag
) {
576 (*protp
->protrej
)(f
->unit
);
580 warn("Protocol-Reject for unsupported protocol 0x%x", prot
);
585 * lcp_protrej - A Protocol-Reject was received.
595 error("Received Protocol-Reject for LCP!");
596 fsm_protreject(&lcp_fsm
[unit
]);
601 * lcp_sprotrej - Send a Protocol-Reject for some protocol.
604 lcp_sprotrej(unit
, p
, len
)
610 * Send back the protocol and the information field of the
611 * rejected packet. We only get here if LCP is in the OPENED state.
616 fsm_sdata(&lcp_fsm
[unit
], PROTREJ
, ++lcp_fsm
[unit
].id
,
622 * lcp_resetci - Reset our CI.
628 lcp_options
*wo
= &lcp_wantoptions
[f
->unit
];
629 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
630 lcp_options
*ao
= &lcp_allowoptions
[f
->unit
];
632 wo
->magicnumber
= magic();
638 go
->neg_endpoint
= 0;
641 ao
->neg_endpoint
= 0;
642 peer_mru
[f
->unit
] = PPP_MRU
;
648 * lcp_cilen - Return length of our CI.
654 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
656 #define LENCIVOID(neg) ((neg) ? CILEN_VOID : 0)
657 #define LENCICHAP(neg) ((neg) ? CILEN_CHAP : 0)
658 #define LENCISHORT(neg) ((neg) ? CILEN_SHORT : 0)
659 #define LENCILONG(neg) ((neg) ? CILEN_LONG : 0)
660 #define LENCILQR(neg) ((neg) ? CILEN_LQR: 0)
661 #define LENCICBCP(neg) ((neg) ? CILEN_CBCP: 0)
663 * NB: we only ask for one of CHAP, UPAP, or EAP, even if we will
664 * accept more than one. We prefer EAP first, then CHAP, then
667 return (LENCISHORT(go
->neg_mru
&& go
->mru
!= DEFMRU
) +
668 LENCILONG(go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFF) +
669 LENCISHORT(go
->neg_eap
) +
670 LENCICHAP(!go
->neg_eap
&& go
->neg_chap
) +
671 LENCISHORT(!go
->neg_eap
&& !go
->neg_chap
&& go
->neg_upap
) +
672 LENCILQR(go
->neg_lqr
) +
673 LENCICBCP(go
->neg_cbcp
) +
674 LENCILONG(go
->neg_magicnumber
) +
675 LENCIVOID(go
->neg_pcompression
) +
676 LENCIVOID(go
->neg_accompression
) +
677 LENCISHORT(go
->neg_mrru
) +
678 LENCIVOID(go
->neg_ssnhf
) +
679 (go
->neg_endpoint
? CILEN_CHAR
+ go
->endpoint
.length
: 0));
684 * lcp_addci - Add our desired CIs to a packet.
687 lcp_addci(f
, ucp
, lenp
)
692 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
693 u_char
*start_ucp
= ucp
;
695 #define ADDCIVOID(opt, neg) \
698 PUTCHAR(CILEN_VOID, ucp); \
700 #define ADDCISHORT(opt, neg, val) \
703 PUTCHAR(CILEN_SHORT, ucp); \
704 PUTSHORT(val, ucp); \
706 #define ADDCICHAP(opt, neg, val) \
708 PUTCHAR((opt), ucp); \
709 PUTCHAR(CILEN_CHAP, ucp); \
710 PUTSHORT(PPP_CHAP, ucp); \
711 PUTCHAR((CHAP_DIGEST(val)), ucp); \
713 #define ADDCILONG(opt, neg, val) \
716 PUTCHAR(CILEN_LONG, ucp); \
719 #define ADDCILQR(opt, neg, val) \
722 PUTCHAR(CILEN_LQR, ucp); \
723 PUTSHORT(PPP_LQR, ucp); \
726 #define ADDCICHAR(opt, neg, val) \
729 PUTCHAR(CILEN_CHAR, ucp); \
732 #define ADDCIENDP(opt, neg, class, val, len) \
736 PUTCHAR(CILEN_CHAR + len, ucp); \
737 PUTCHAR(class, ucp); \
738 for (i = 0; i < len; ++i) \
739 PUTCHAR(val[i], ucp); \
742 ADDCISHORT(CI_MRU
, go
->neg_mru
&& go
->mru
!= DEFMRU
, go
->mru
);
743 ADDCILONG(CI_ASYNCMAP
, go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFF,
745 ADDCISHORT(CI_AUTHTYPE
, go
->neg_eap
, PPP_EAP
);
746 ADDCICHAP(CI_AUTHTYPE
, !go
->neg_eap
&& go
->neg_chap
, go
->chap_mdtype
);
747 ADDCISHORT(CI_AUTHTYPE
, !go
->neg_eap
&& !go
->neg_chap
&& go
->neg_upap
,
749 ADDCILQR(CI_QUALITY
, go
->neg_lqr
, go
->lqr_period
);
750 ADDCICHAR(CI_CALLBACK
, go
->neg_cbcp
, CBCP_OPT
);
751 ADDCILONG(CI_MAGICNUMBER
, go
->neg_magicnumber
, go
->magicnumber
);
752 ADDCIVOID(CI_PCOMPRESSION
, go
->neg_pcompression
);
753 ADDCIVOID(CI_ACCOMPRESSION
, go
->neg_accompression
);
754 ADDCISHORT(CI_MRRU
, go
->neg_mrru
, go
->mrru
);
755 ADDCIVOID(CI_SSNHF
, go
->neg_ssnhf
);
756 ADDCIENDP(CI_EPDISC
, go
->neg_endpoint
, go
->endpoint
.class,
757 go
->endpoint
.value
, go
->endpoint
.length
);
759 if (ucp
- start_ucp
!= *lenp
) {
760 /* this should never happen, because peer_mtu should be 1500 */
761 error("Bug in lcp_addci: wrong length");
767 * lcp_ackci - Ack our CIs.
768 * This should not modify any state if the Ack is bad.
780 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
781 u_char cilen
, citype
, cichar
;
786 * CIs must be in exactly the same order that we sent.
787 * Check packet length and CI length at each step.
788 * If we find any deviations, then this packet is bad.
790 #define ACKCIVOID(opt, neg) \
792 if ((len -= CILEN_VOID) < 0) \
794 GETCHAR(citype, p); \
796 if (cilen != CILEN_VOID || \
800 #define ACKCISHORT(opt, neg, val) \
802 if ((len -= CILEN_SHORT) < 0) \
804 GETCHAR(citype, p); \
806 if (cilen != CILEN_SHORT || \
809 GETSHORT(cishort, p); \
810 if (cishort != val) \
813 #define ACKCICHAR(opt, neg, val) \
815 if ((len -= CILEN_CHAR) < 0) \
817 GETCHAR(citype, p); \
819 if (cilen != CILEN_CHAR || \
822 GETCHAR(cichar, p); \
826 #define ACKCICHAP(opt, neg, val) \
828 if ((len -= CILEN_CHAP) < 0) \
830 GETCHAR(citype, p); \
832 if (cilen != CILEN_CHAP || \
835 GETSHORT(cishort, p); \
836 if (cishort != PPP_CHAP) \
838 GETCHAR(cichar, p); \
839 if (cichar != (CHAP_DIGEST(val))) \
842 #define ACKCILONG(opt, neg, val) \
844 if ((len -= CILEN_LONG) < 0) \
846 GETCHAR(citype, p); \
848 if (cilen != CILEN_LONG || \
851 GETLONG(cilong, p); \
855 #define ACKCILQR(opt, neg, val) \
857 if ((len -= CILEN_LQR) < 0) \
859 GETCHAR(citype, p); \
861 if (cilen != CILEN_LQR || \
864 GETSHORT(cishort, p); \
865 if (cishort != PPP_LQR) \
867 GETLONG(cilong, p); \
871 #define ACKCIENDP(opt, neg, class, val, vlen) \
874 if ((len -= CILEN_CHAR + vlen) < 0) \
876 GETCHAR(citype, p); \
878 if (cilen != CILEN_CHAR + vlen || \
881 GETCHAR(cichar, p); \
882 if (cichar != class) \
884 for (i = 0; i < vlen; ++i) { \
885 GETCHAR(cichar, p); \
886 if (cichar != val[i]) \
891 ACKCISHORT(CI_MRU
, go
->neg_mru
&& go
->mru
!= DEFMRU
, go
->mru
);
892 ACKCILONG(CI_ASYNCMAP
, go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFF,
894 ACKCISHORT(CI_AUTHTYPE
, go
->neg_eap
, PPP_EAP
);
895 ACKCICHAP(CI_AUTHTYPE
, !go
->neg_eap
&& go
->neg_chap
, go
->chap_mdtype
);
896 ACKCISHORT(CI_AUTHTYPE
, !go
->neg_eap
&& !go
->neg_chap
&& go
->neg_upap
,
898 ACKCILQR(CI_QUALITY
, go
->neg_lqr
, go
->lqr_period
);
899 ACKCICHAR(CI_CALLBACK
, go
->neg_cbcp
, CBCP_OPT
);
900 ACKCILONG(CI_MAGICNUMBER
, go
->neg_magicnumber
, go
->magicnumber
);
901 ACKCIVOID(CI_PCOMPRESSION
, go
->neg_pcompression
);
902 ACKCIVOID(CI_ACCOMPRESSION
, go
->neg_accompression
);
903 ACKCISHORT(CI_MRRU
, go
->neg_mrru
, go
->mrru
);
904 ACKCIVOID(CI_SSNHF
, go
->neg_ssnhf
);
905 ACKCIENDP(CI_EPDISC
, go
->neg_endpoint
, go
->endpoint
.class,
906 go
->endpoint
.value
, go
->endpoint
.length
);
909 * If there are any remaining CIs, then this packet is bad.
915 LCPDEBUG(("lcp_acki: received bad Ack!"));
921 * lcp_nakci - Peer has sent a NAK for some of our CIs.
922 * This should not modify any state if the Nak is bad
923 * or if LCP is in the OPENED state.
935 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
936 lcp_options
*wo
= &lcp_wantoptions
[f
->unit
];
937 u_char citype
, cichar
, *next
;
940 lcp_options no
; /* options we've seen Naks for */
941 lcp_options
try; /* options to request next time */
945 BZERO(&no
, sizeof(no
));
949 * Any Nak'd CIs must be in exactly the same order that we sent.
950 * Check packet length and CI length at each step.
951 * If we find any deviations, then this packet is bad.
953 #define NAKCIVOID(opt, neg) \
955 len >= CILEN_VOID && \
956 p[1] == CILEN_VOID && \
959 INCPTR(CILEN_VOID, p); \
963 #define NAKCICHAP(opt, neg, code) \
965 len >= CILEN_CHAP && \
966 p[1] == CILEN_CHAP && \
970 GETSHORT(cishort, p); \
971 GETCHAR(cichar, p); \
975 #define NAKCICHAR(opt, neg, code) \
977 len >= CILEN_CHAR && \
978 p[1] == CILEN_CHAR && \
982 GETCHAR(cichar, p); \
986 #define NAKCISHORT(opt, neg, code) \
988 len >= CILEN_SHORT && \
989 p[1] == CILEN_SHORT && \
991 len -= CILEN_SHORT; \
993 GETSHORT(cishort, p); \
997 #define NAKCILONG(opt, neg, code) \
999 len >= CILEN_LONG && \
1000 p[1] == CILEN_LONG && \
1002 len -= CILEN_LONG; \
1004 GETLONG(cilong, p); \
1008 #define NAKCILQR(opt, neg, code) \
1010 len >= CILEN_LQR && \
1011 p[1] == CILEN_LQR && \
1015 GETSHORT(cishort, p); \
1016 GETLONG(cilong, p); \
1020 #define NAKCIENDP(opt, neg) \
1022 len >= CILEN_CHAR && \
1024 p[1] >= CILEN_CHAR && \
1033 * NOTE! There must be no assignments to individual fields of *go in
1034 * the code below. Any such assignment is a BUG!
1037 * We don't care if they want to send us smaller packets than
1038 * we want. Therefore, accept any MRU less than what we asked for,
1039 * but then ignore the new value when setting the MRU in the kernel.
1040 * If they send us a bigger MRU than what we asked, accept it, up to
1041 * the limit of the default MRU we'd get if we didn't negotiate.
1043 if (go
->neg_mru
&& go
->mru
!= DEFMRU
) {
1044 NAKCISHORT(CI_MRU
, neg_mru
,
1045 if (cishort
<= wo
->mru
|| cishort
<= DEFMRU
)
1051 * Add any characters they want to our (receive-side) asyncmap.
1053 if (go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFF) {
1054 NAKCILONG(CI_ASYNCMAP
, neg_asyncmap
,
1055 try.asyncmap
= go
->asyncmap
| cilong
;
1060 * If they've nak'd our authentication-protocol, check whether
1061 * they are proposing a different protocol, or a different
1062 * hash algorithm for CHAP.
1064 if ((go
->neg_chap
|| go
->neg_upap
|| go
->neg_eap
)
1065 && len
>= CILEN_SHORT
1066 && p
[0] == CI_AUTHTYPE
&& p
[1] >= CILEN_SHORT
&& p
[1] <= len
) {
1069 no
.neg_chap
= go
->neg_chap
;
1070 no
.neg_upap
= go
->neg_upap
;
1071 no
.neg_eap
= go
->neg_eap
;
1073 GETSHORT(cishort
, p
);
1074 if (cishort
== PPP_PAP
&& cilen
== CILEN_SHORT
) {
1075 /* If we were asking for EAP, then we need to stop that. */
1079 /* If we were asking for CHAP, then we need to stop that. */
1080 else if (go
->neg_chap
)
1083 * If we weren't asking for CHAP or EAP, then we were asking for
1084 * PAP, in which case this Nak is bad.
1089 } else if (cishort
== PPP_CHAP
&& cilen
== CILEN_CHAP
) {
1091 /* Stop asking for EAP, if we were. */
1094 /* Try to set up to use their suggestion, if possible */
1095 if (CHAP_CANDIGEST(go
->chap_mdtype
, cichar
))
1096 try.chap_mdtype
= CHAP_MDTYPE_D(cichar
);
1097 } else if (go
->neg_chap
) {
1099 * We were asking for our preferred algorithm, they must
1100 * want something different.
1102 if (cichar
!= CHAP_DIGEST(go
->chap_mdtype
)) {
1103 if (CHAP_CANDIGEST(go
->chap_mdtype
, cichar
)) {
1104 /* Use their suggestion if we support it ... */
1105 try.chap_mdtype
= CHAP_MDTYPE_D(cichar
);
1107 /* ... otherwise, try our next-preferred algorithm. */
1108 try.chap_mdtype
&= ~(CHAP_MDTYPE(try.chap_mdtype
));
1109 if (try.chap_mdtype
== MDTYPE_NONE
) /* out of algos */
1114 * Whoops, they Nak'd our algorithm of choice
1115 * but then suggested it back to us.
1121 * Stop asking for PAP if we were asking for it.
1129 * If we were asking for EAP, and they're Conf-Naking EAP,
1130 * well, that's just strange. Nobody should do that.
1132 if (cishort
== PPP_EAP
&& cilen
== CILEN_SHORT
&& go
->neg_eap
)
1133 dbglog("Unexpected Conf-Nak for EAP");
1136 * We don't recognize what they're suggesting.
1137 * Stop asking for what we were asking for.
1141 else if (go
->neg_chap
)
1145 p
+= cilen
- CILEN_SHORT
;
1150 * If they can't cope with our link quality protocol, we'll have
1151 * to stop asking for LQR. We haven't got any other protocol.
1152 * If they Nak the reporting period, take their value XXX ?
1154 NAKCILQR(CI_QUALITY
, neg_lqr
,
1155 if (cishort
!= PPP_LQR
)
1158 try.lqr_period
= cilong
;
1162 * Only implementing CBCP...not the rest of the callback options
1164 NAKCICHAR(CI_CALLBACK
, neg_cbcp
,
1169 * Check for a looped-back line.
1171 NAKCILONG(CI_MAGICNUMBER
, neg_magicnumber
,
1172 try.magicnumber
= magic();
1177 * Peer shouldn't send Nak for protocol compression or
1178 * address/control compression requests; they should send
1179 * a Reject instead. If they send a Nak, treat it as a Reject.
1181 NAKCIVOID(CI_PCOMPRESSION
, neg_pcompression
);
1182 NAKCIVOID(CI_ACCOMPRESSION
, neg_accompression
);
1185 * Nak for MRRU option - accept their value if it is smaller
1186 * than the one we want.
1189 NAKCISHORT(CI_MRRU
, neg_mrru
,
1190 if (cishort
<= wo
->mrru
)
1196 * Nak for short sequence numbers shouldn't be sent, treat it
1199 NAKCIVOID(CI_SSNHF
, neg_ssnhf
);
1202 * Nak of the endpoint discriminator option is not permitted,
1203 * treat it like a reject.
1205 NAKCIENDP(CI_EPDISC
, neg_endpoint
);
1208 * There may be remaining CIs, if the peer is requesting negotiation
1209 * on an option that we didn't include in our request packet.
1210 * If we see an option that we requested, or one we've already seen
1211 * in this packet, then this packet is bad.
1212 * If we wanted to respond by starting to negotiate on the requested
1213 * option(s), we could, but we don't, because except for the
1214 * authentication type and quality protocol, if we are not negotiating
1215 * an option, it is because we were told not to.
1216 * For the authentication type, the Nak from the peer means
1217 * `let me authenticate myself with you' which is a bit pointless.
1218 * For the quality protocol, the Nak means `ask me to send you quality
1219 * reports', but if we didn't ask for them, we don't want them.
1220 * An option we don't recognize represents the peer asking to
1221 * negotiate some option we don't support, so ignore it.
1223 while (len
>= CILEN_VOID
) {
1226 if (cilen
< CILEN_VOID
|| (len
-= cilen
) < 0)
1228 next
= p
+ cilen
- 2;
1232 if ((go
->neg_mru
&& go
->mru
!= DEFMRU
)
1233 || no
.neg_mru
|| cilen
!= CILEN_SHORT
)
1235 GETSHORT(cishort
, p
);
1236 if (cishort
< DEFMRU
) {
1242 if ((go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFF)
1243 || no
.neg_asyncmap
|| cilen
!= CILEN_LONG
)
1247 if (go
->neg_chap
|| no
.neg_chap
|| go
->neg_upap
|| no
.neg_upap
||
1248 go
->neg_eap
|| no
.neg_eap
)
1251 case CI_MAGICNUMBER
:
1252 if (go
->neg_magicnumber
|| no
.neg_magicnumber
||
1253 cilen
!= CILEN_LONG
)
1256 case CI_PCOMPRESSION
:
1257 if (go
->neg_pcompression
|| no
.neg_pcompression
1258 || cilen
!= CILEN_VOID
)
1261 case CI_ACCOMPRESSION
:
1262 if (go
->neg_accompression
|| no
.neg_accompression
1263 || cilen
!= CILEN_VOID
)
1267 if (go
->neg_lqr
|| no
.neg_lqr
|| cilen
!= CILEN_LQR
)
1271 if (go
->neg_mrru
|| no
.neg_mrru
|| cilen
!= CILEN_SHORT
)
1275 if (go
->neg_ssnhf
|| no
.neg_ssnhf
|| cilen
!= CILEN_VOID
)
1280 if (go
->neg_endpoint
|| no
.neg_endpoint
|| cilen
< CILEN_CHAR
)
1288 * OK, the Nak is good. Now we can update state.
1289 * If there are any options left we ignore them.
1291 if (f
->state
!= OPENED
) {
1293 if (++try.numloops
>= lcp_loopbackfail
) {
1294 notice("Serial line is looped back.");
1295 lcp_close(f
->unit
, "Loopback detected");
1296 status
= EXIT_LOOPBACK
;
1306 LCPDEBUG(("lcp_nakci: received bad Nak!"));
1312 * lcp_rejci - Peer has Rejected some of our CIs.
1313 * This should not modify any state if the Reject is bad
1314 * or if LCP is in the OPENED state.
1317 * 0 - Reject was bad.
1318 * 1 - Reject was good.
1321 lcp_rejci(f
, p
, len
)
1326 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
1330 lcp_options
try; /* options to request next time */
1335 * Any Rejected CIs must be in exactly the same order that we sent.
1336 * Check packet length and CI length at each step.
1337 * If we find any deviations, then this packet is bad.
1339 #define REJCIVOID(opt, neg) \
1341 len >= CILEN_VOID && \
1342 p[1] == CILEN_VOID && \
1344 len -= CILEN_VOID; \
1345 INCPTR(CILEN_VOID, p); \
1348 #define REJCISHORT(opt, neg, val) \
1350 len >= CILEN_SHORT && \
1351 p[1] == CILEN_SHORT && \
1353 len -= CILEN_SHORT; \
1355 GETSHORT(cishort, p); \
1356 /* Check rejected value. */ \
1357 if (cishort != val) \
1361 #define REJCICHAP(opt, neg, val) \
1363 len >= CILEN_CHAP && \
1364 p[1] == CILEN_CHAP && \
1366 len -= CILEN_CHAP; \
1368 GETSHORT(cishort, p); \
1369 GETCHAR(cichar, p); \
1370 /* Check rejected value. */ \
1371 if ((cishort != PPP_CHAP) || (cichar != (CHAP_DIGEST(val)))) \
1374 try.neg_eap = try.neg_upap = 0; \
1376 #define REJCILONG(opt, neg, val) \
1378 len >= CILEN_LONG && \
1379 p[1] == CILEN_LONG && \
1381 len -= CILEN_LONG; \
1383 GETLONG(cilong, p); \
1384 /* Check rejected value. */ \
1385 if (cilong != val) \
1389 #define REJCILQR(opt, neg, val) \
1391 len >= CILEN_LQR && \
1392 p[1] == CILEN_LQR && \
1396 GETSHORT(cishort, p); \
1397 GETLONG(cilong, p); \
1398 /* Check rejected value. */ \
1399 if (cishort != PPP_LQR || cilong != val) \
1403 #define REJCICBCP(opt, neg, val) \
1405 len >= CILEN_CBCP && \
1406 p[1] == CILEN_CBCP && \
1408 len -= CILEN_CBCP; \
1410 GETCHAR(cichar, p); \
1411 /* Check rejected value. */ \
1412 if (cichar != val) \
1416 #define REJCIENDP(opt, neg, class, val, vlen) \
1418 len >= CILEN_CHAR + vlen && \
1420 p[1] == CILEN_CHAR + vlen) { \
1422 len -= CILEN_CHAR + vlen; \
1424 GETCHAR(cichar, p); \
1425 if (cichar != class) \
1427 for (i = 0; i < vlen; ++i) { \
1428 GETCHAR(cichar, p); \
1429 if (cichar != val[i]) \
1435 REJCISHORT(CI_MRU
, neg_mru
, go
->mru
);
1436 REJCILONG(CI_ASYNCMAP
, neg_asyncmap
, go
->asyncmap
);
1437 REJCISHORT(CI_AUTHTYPE
, neg_eap
, PPP_EAP
);
1439 REJCICHAP(CI_AUTHTYPE
, neg_chap
, go
->chap_mdtype
);
1440 if (!go
->neg_chap
) {
1441 REJCISHORT(CI_AUTHTYPE
, neg_upap
, PPP_PAP
);
1444 REJCILQR(CI_QUALITY
, neg_lqr
, go
->lqr_period
);
1445 REJCICBCP(CI_CALLBACK
, neg_cbcp
, CBCP_OPT
);
1446 REJCILONG(CI_MAGICNUMBER
, neg_magicnumber
, go
->magicnumber
);
1447 REJCIVOID(CI_PCOMPRESSION
, neg_pcompression
);
1448 REJCIVOID(CI_ACCOMPRESSION
, neg_accompression
);
1449 REJCISHORT(CI_MRRU
, neg_mrru
, go
->mrru
);
1450 REJCIVOID(CI_SSNHF
, neg_ssnhf
);
1451 REJCIENDP(CI_EPDISC
, neg_endpoint
, go
->endpoint
.class,
1452 go
->endpoint
.value
, go
->endpoint
.length
);
1455 * If there are any remaining CIs, then this packet is bad.
1460 * Now we can update state.
1462 if (f
->state
!= OPENED
)
1467 LCPDEBUG(("lcp_rejci: received bad Reject!"));
1473 * lcp_reqci - Check the peer's requested CIs and send appropriate response.
1475 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
1476 * appropriately. If reject_if_disagree is non-zero, doesn't return
1477 * CONFNAK; returns CONFREJ if it can't return CONFACK.
1480 lcp_reqci(f
, inp
, lenp
, reject_if_disagree
)
1482 u_char
*inp
; /* Requested CIs */
1483 int *lenp
; /* Length of requested CIs */
1484 int reject_if_disagree
;
1486 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
1487 lcp_options
*ho
= &lcp_hisoptions
[f
->unit
];
1488 lcp_options
*ao
= &lcp_allowoptions
[f
->unit
];
1489 u_char
*cip
, *next
; /* Pointer to current and next CIs */
1490 int cilen
, citype
, cichar
; /* Parsed len, type, char value */
1491 u_short cishort
; /* Parsed short value */
1492 u_int32_t cilong
; /* Parse long value */
1493 int rc
= CONFACK
; /* Final packet return code */
1494 int orc
; /* Individual option return code */
1495 u_char
*p
; /* Pointer to next char to parse */
1496 u_char
*rejp
; /* Pointer to next char in reject frame */
1497 u_char
*nakp
; /* Pointer to next char in Nak frame */
1498 int l
= *lenp
; /* Length left */
1501 * Reset all his options.
1503 BZERO(ho
, sizeof(*ho
));
1506 * Process all his options.
1512 orc
= CONFACK
; /* Assume success */
1513 cip
= p
= next
; /* Remember begining of CI */
1514 if (l
< 2 || /* Not enough data for CI header or */
1515 p
[1] < 2 || /* CI length too small or */
1516 p
[1] > l
) { /* CI length too big? */
1517 LCPDEBUG(("lcp_reqci: bad CI length!"));
1518 orc
= CONFREJ
; /* Reject bad CI */
1519 cilen
= l
; /* Reject till end of packet */
1520 l
= 0; /* Don't loop again */
1524 GETCHAR(citype
, p
); /* Parse CI type */
1525 GETCHAR(cilen
, p
); /* Parse CI length */
1526 l
-= cilen
; /* Adjust remaining length */
1527 next
+= cilen
; /* Step to next CI */
1529 switch (citype
) { /* Check CI type */
1531 if (!ao
->neg_mru
|| /* Allow option? */
1532 cilen
!= CILEN_SHORT
) { /* Check CI length */
1533 orc
= CONFREJ
; /* Reject CI */
1536 GETSHORT(cishort
, p
); /* Parse MRU */
1539 * He must be able to receive at least our minimum.
1540 * No need to check a maximum. If he sends a large number,
1541 * we'll just ignore it.
1543 if (cishort
< MINMRU
) {
1544 orc
= CONFNAK
; /* Nak CI */
1545 PUTCHAR(CI_MRU
, nakp
);
1546 PUTCHAR(CILEN_SHORT
, nakp
);
1547 PUTSHORT(MINMRU
, nakp
); /* Give him a hint */
1550 ho
->neg_mru
= 1; /* Remember he sent MRU */
1551 ho
->mru
= cishort
; /* And remember value */
1555 if (!ao
->neg_asyncmap
||
1556 cilen
!= CILEN_LONG
) {
1563 * Asyncmap must have set at least the bits
1564 * which are set in lcp_allowoptions[unit].asyncmap.
1566 if ((ao
->asyncmap
& ~cilong
) != 0) {
1568 PUTCHAR(CI_ASYNCMAP
, nakp
);
1569 PUTCHAR(CILEN_LONG
, nakp
);
1570 PUTLONG(ao
->asyncmap
| cilong
, nakp
);
1573 ho
->neg_asyncmap
= 1;
1574 ho
->asyncmap
= cilong
;
1578 if (cilen
< CILEN_SHORT
||
1579 !(ao
->neg_upap
|| ao
->neg_chap
|| ao
->neg_eap
)) {
1581 * Reject the option if we're not willing to authenticate.
1583 dbglog("No auth is possible");
1587 GETSHORT(cishort
, p
);
1590 * Authtype must be PAP, CHAP, or EAP.
1592 * Note: if more than one of ao->neg_upap, ao->neg_chap, and
1593 * ao->neg_eap are set, and the peer sends a Configure-Request
1594 * with two or more authenticate-protocol requests, then we will
1595 * reject the second request.
1596 * Whether we end up doing CHAP, UPAP, or EAP depends then on
1597 * the ordering of the CIs in the peer's Configure-Request.
1600 if (cishort
== PPP_PAP
) {
1601 /* we've already accepted CHAP or EAP */
1602 if (ho
->neg_chap
|| ho
->neg_eap
||
1603 cilen
!= CILEN_SHORT
) {
1604 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE PAP, rejecting..."));
1608 if (!ao
->neg_upap
) { /* we don't want to do PAP */
1609 orc
= CONFNAK
; /* NAK it and suggest CHAP or EAP */
1610 PUTCHAR(CI_AUTHTYPE
, nakp
);
1612 PUTCHAR(CILEN_SHORT
, nakp
);
1613 PUTSHORT(PPP_EAP
, nakp
);
1615 PUTCHAR(CILEN_CHAP
, nakp
);
1616 PUTSHORT(PPP_CHAP
, nakp
);
1617 PUTCHAR(CHAP_DIGEST(ao
->chap_mdtype
), nakp
);
1624 if (cishort
== PPP_CHAP
) {
1625 /* we've already accepted PAP or EAP */
1626 if (ho
->neg_upap
|| ho
->neg_eap
||
1627 cilen
!= CILEN_CHAP
) {
1628 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE CHAP, rejecting..."));
1632 if (!ao
->neg_chap
) { /* we don't want to do CHAP */
1633 orc
= CONFNAK
; /* NAK it and suggest EAP or PAP */
1634 PUTCHAR(CI_AUTHTYPE
, nakp
);
1635 PUTCHAR(CILEN_SHORT
, nakp
);
1637 PUTSHORT(PPP_EAP
, nakp
);
1639 PUTSHORT(PPP_PAP
, nakp
);
1643 GETCHAR(cichar
, p
); /* get digest type */
1644 if (!(CHAP_CANDIGEST(ao
->chap_mdtype
, cichar
))) {
1646 * We can't/won't do the requested type,
1647 * suggest something else.
1650 PUTCHAR(CI_AUTHTYPE
, nakp
);
1651 PUTCHAR(CILEN_CHAP
, nakp
);
1652 PUTSHORT(PPP_CHAP
, nakp
);
1653 PUTCHAR(CHAP_DIGEST(ao
->chap_mdtype
), nakp
);
1656 ho
->chap_mdtype
= CHAP_MDTYPE_D(cichar
); /* save md type */
1660 if (cishort
== PPP_EAP
) {
1661 /* we've already accepted CHAP or PAP */
1662 if (ho
->neg_chap
|| ho
->neg_upap
|| cilen
!= CILEN_SHORT
) {
1663 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE EAP, rejecting..."));
1667 if (!ao
->neg_eap
) { /* we don't want to do EAP */
1668 orc
= CONFNAK
; /* NAK it and suggest CHAP or PAP */
1669 PUTCHAR(CI_AUTHTYPE
, nakp
);
1671 PUTCHAR(CILEN_CHAP
, nakp
);
1672 PUTSHORT(PPP_CHAP
, nakp
);
1673 PUTCHAR(CHAP_DIGEST(ao
->chap_mdtype
), nakp
);
1675 PUTCHAR(CILEN_SHORT
, nakp
);
1676 PUTSHORT(PPP_PAP
, nakp
);
1685 * We don't recognize the protocol they're asking for.
1686 * Nak it with something we're willing to do.
1687 * (At this point we know ao->neg_upap || ao->neg_chap ||
1691 PUTCHAR(CI_AUTHTYPE
, nakp
);
1693 PUTCHAR(CILEN_SHORT
, nakp
);
1694 PUTSHORT(PPP_EAP
, nakp
);
1695 } else if (ao
->neg_chap
) {
1696 PUTCHAR(CILEN_CHAP
, nakp
);
1697 PUTSHORT(PPP_CHAP
, nakp
);
1698 PUTCHAR(CHAP_DIGEST(ao
->chap_mdtype
), nakp
);
1700 PUTCHAR(CILEN_SHORT
, nakp
);
1701 PUTSHORT(PPP_PAP
, nakp
);
1707 cilen
!= CILEN_LQR
) {
1712 GETSHORT(cishort
, p
);
1716 * Check the protocol and the reporting period.
1717 * XXX When should we Nak this, and what with?
1719 if (cishort
!= PPP_LQR
) {
1721 PUTCHAR(CI_QUALITY
, nakp
);
1722 PUTCHAR(CILEN_LQR
, nakp
);
1723 PUTSHORT(PPP_LQR
, nakp
);
1724 PUTLONG(ao
->lqr_period
, nakp
);
1729 case CI_MAGICNUMBER
:
1730 if (!(ao
->neg_magicnumber
|| go
->neg_magicnumber
) ||
1731 cilen
!= CILEN_LONG
) {
1738 * He must have a different magic number.
1740 if (go
->neg_magicnumber
&&
1741 cilong
== go
->magicnumber
) {
1742 cilong
= magic(); /* Don't put magic() inside macro! */
1744 PUTCHAR(CI_MAGICNUMBER
, nakp
);
1745 PUTCHAR(CILEN_LONG
, nakp
);
1746 PUTLONG(cilong
, nakp
);
1749 ho
->neg_magicnumber
= 1;
1750 ho
->magicnumber
= cilong
;
1754 case CI_PCOMPRESSION
:
1755 if (!ao
->neg_pcompression
||
1756 cilen
!= CILEN_VOID
) {
1760 ho
->neg_pcompression
= 1;
1763 case CI_ACCOMPRESSION
:
1764 if (!ao
->neg_accompression
||
1765 cilen
!= CILEN_VOID
) {
1769 ho
->neg_accompression
= 1;
1773 if (!ao
->neg_mrru
|| !multilink
||
1774 cilen
!= CILEN_SHORT
) {
1779 GETSHORT(cishort
, p
);
1780 /* possibly should insist on a minimum/maximum MRRU here */
1786 if (!ao
->neg_ssnhf
|| !multilink
||
1787 cilen
!= CILEN_VOID
) {
1795 if (!ao
->neg_endpoint
||
1796 cilen
< CILEN_CHAR
||
1797 cilen
> CILEN_CHAR
+ MAX_ENDP_LEN
) {
1802 cilen
-= CILEN_CHAR
;
1803 ho
->neg_endpoint
= 1;
1804 ho
->endpoint
.class = cichar
;
1805 ho
->endpoint
.length
= cilen
;
1806 BCOPY(p
, ho
->endpoint
.value
, cilen
);
1811 LCPDEBUG(("lcp_reqci: rcvd unknown option %d", citype
));
1817 if (orc
== CONFACK
&& /* Good CI */
1818 rc
!= CONFACK
) /* but prior CI wasnt? */
1819 continue; /* Don't send this one */
1821 if (orc
== CONFNAK
) { /* Nak this CI? */
1822 if (reject_if_disagree
/* Getting fed up with sending NAKs? */
1823 && citype
!= CI_MAGICNUMBER
) {
1824 orc
= CONFREJ
; /* Get tough if so */
1826 if (rc
== CONFREJ
) /* Rejecting prior CI? */
1827 continue; /* Don't send this one */
1831 if (orc
== CONFREJ
) { /* Reject this CI */
1833 if (cip
!= rejp
) /* Need to move rejected CI? */
1834 BCOPY(cip
, rejp
, cilen
); /* Move it */
1835 INCPTR(cilen
, rejp
); /* Update output pointer */
1840 * If we wanted to send additional NAKs (for unsent CIs), the
1841 * code would go here. The extra NAKs would go at *nakp.
1842 * At present there are no cases where we want to ask the
1843 * peer to negotiate an option.
1852 * Copy the Nak'd options from the nak_buffer to the caller's buffer.
1854 *lenp
= nakp
- nak_buffer
;
1855 BCOPY(nak_buffer
, inp
, *lenp
);
1862 LCPDEBUG(("lcp_reqci: returning CONF%s.", CODENAME(rc
)));
1863 return (rc
); /* Return final code */
1868 * lcp_up - LCP has come UP.
1874 lcp_options
*wo
= &lcp_wantoptions
[f
->unit
];
1875 lcp_options
*ho
= &lcp_hisoptions
[f
->unit
];
1876 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
1877 lcp_options
*ao
= &lcp_allowoptions
[f
->unit
];
1880 if (!go
->neg_magicnumber
)
1881 go
->magicnumber
= 0;
1882 if (!ho
->neg_magicnumber
)
1883 ho
->magicnumber
= 0;
1886 * Set our MTU to the smaller of the MTU we wanted and
1887 * the MRU our peer wanted. If we negotiated an MRU,
1888 * set our MRU to the larger of value we wanted and
1889 * the value we got in the negotiation.
1890 * Note on the MTU: the link MTU can be the MRU the peer wanted,
1891 * the interface MTU is set to the lowest of that, the
1892 * MTU we want to use, and our link MRU.
1894 mtu
= ho
->neg_mru
? ho
->mru
: PPP_MRU
;
1895 mru
= go
->neg_mru
? MAX(wo
->mru
, go
->mru
): PPP_MRU
;
1896 #ifdef HAVE_MULTILINK
1897 if (!(multilink
&& go
->neg_mrru
&& ho
->neg_mrru
))
1898 #endif /* HAVE_MULTILINK */
1899 netif_set_mtu(f
->unit
, MIN(MIN(mtu
, mru
), ao
->mru
));
1900 ppp_send_config(f
->unit
, mtu
,
1901 (ho
->neg_asyncmap
? ho
->asyncmap
: 0xffffffff),
1902 ho
->neg_pcompression
, ho
->neg_accompression
);
1903 ppp_recv_config(f
->unit
, mru
,
1904 (lax_recv
? 0: go
->neg_asyncmap
? go
->asyncmap
: 0xffffffff),
1905 go
->neg_pcompression
, go
->neg_accompression
);
1908 peer_mru
[f
->unit
] = ho
->mru
;
1910 lcp_echo_lowerup(f
->unit
); /* Enable echo messages */
1912 link_established(f
->unit
);
1917 * lcp_down - LCP has gone DOWN.
1919 * Alert other protocols.
1925 lcp_options
*go
= &lcp_gotoptions
[f
->unit
];
1927 lcp_echo_lowerdown(f
->unit
);
1931 ppp_send_config(f
->unit
, PPP_MRU
, 0xffffffff, 0, 0);
1932 ppp_recv_config(f
->unit
, PPP_MRU
,
1933 (go
->neg_asyncmap
? go
->asyncmap
: 0xffffffff),
1934 go
->neg_pcompression
, go
->neg_accompression
);
1935 peer_mru
[f
->unit
] = PPP_MRU
;
1940 * lcp_starting - LCP needs the lower layer up.
1946 link_required(f
->unit
);
1951 * lcp_finished - LCP has finished with the lower layer.
1957 link_terminated(f
->unit
);
1962 * lcp_printpkt - print the contents of an LCP packet.
1964 static char *lcp_codenames
[] = {
1965 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1966 "TermReq", "TermAck", "CodeRej", "ProtRej",
1967 "EchoReq", "EchoRep", "DiscReq"
1971 lcp_printpkt(p
, plen
, printer
, arg
)
1974 void (*printer
) __P((void *, char *, ...));
1977 int code
, id
, len
, olen
, i
;
1978 u_char
*pstart
, *optend
;
1982 if (plen
< HEADERLEN
)
1988 if (len
< HEADERLEN
|| len
> plen
)
1991 if (code
>= 1 && code
<= sizeof(lcp_codenames
) / sizeof(char *))
1992 printer(arg
, " %s", lcp_codenames
[code
-1]);
1994 printer(arg
, " code=0x%x", code
);
1995 printer(arg
, " id=0x%x", id
);
2002 /* print option list */
2007 if (olen
< 2 || olen
> len
) {
2015 if (olen
== CILEN_SHORT
) {
2017 GETSHORT(cishort
, p
);
2018 printer(arg
, "mru %d", cishort
);
2022 if (olen
== CILEN_LONG
) {
2025 printer(arg
, "asyncmap 0x%x", cilong
);
2029 if (olen
>= CILEN_SHORT
) {
2031 printer(arg
, "auth ");
2032 GETSHORT(cishort
, p
);
2035 printer(arg
, "pap");
2038 printer(arg
, "chap");
2042 printer(arg
, " MD5");
2046 case CHAP_MICROSOFT
:
2047 printer(arg
, " MS");
2051 case CHAP_MICROSOFT_V2
:
2052 printer(arg
, " MS-v2");
2060 printer(arg
, "eap");
2063 printer(arg
, "0x%x", cishort
);
2068 if (olen
>= CILEN_SHORT
) {
2070 printer(arg
, "quality ");
2071 GETSHORT(cishort
, p
);
2074 printer(arg
, "lqr");
2077 printer(arg
, "0x%x", cishort
);
2082 if (olen
>= CILEN_CHAR
) {
2084 printer(arg
, "callback ");
2085 GETCHAR(cishort
, p
);
2088 printer(arg
, "CBCP");
2091 printer(arg
, "0x%x", cishort
);
2095 case CI_MAGICNUMBER
:
2096 if (olen
== CILEN_LONG
) {
2099 printer(arg
, "magic 0x%x", cilong
);
2102 case CI_PCOMPRESSION
:
2103 if (olen
== CILEN_VOID
) {
2105 printer(arg
, "pcomp");
2108 case CI_ACCOMPRESSION
:
2109 if (olen
== CILEN_VOID
) {
2111 printer(arg
, "accomp");
2115 if (olen
== CILEN_SHORT
) {
2117 GETSHORT(cishort
, p
);
2118 printer(arg
, "mrru %d", cishort
);
2122 if (olen
== CILEN_VOID
) {
2124 printer(arg
, "ssnhf");
2128 #ifdef HAVE_MULTILINK
2129 if (olen
>= CILEN_CHAR
) {
2132 GETCHAR(epd
.class, p
);
2133 epd
.length
= olen
- CILEN_CHAR
;
2134 if (epd
.length
> MAX_ENDP_LEN
)
2135 epd
.length
= MAX_ENDP_LEN
;
2136 if (epd
.length
> 0) {
2137 BCOPY(p
, epd
.value
, epd
.length
);
2140 printer(arg
, "endpoint [%s]", epdisc_to_str(&epd
));
2143 printer(arg
, "endpoint");
2147 while (p
< optend
) {
2149 printer(arg
, " %.2x", code
);
2157 if (len
> 0 && *p
>= ' ' && *p
< 0x7f) {
2159 print_string((char *)p
, len
, printer
, arg
);
2170 printer(arg
, " magic=0x%x", cilong
);
2177 /* print the rest of the bytes in the packet */
2178 for (i
= 0; i
< len
&& i
< 32; ++i
) {
2180 printer(arg
, " %.2x", code
);
2183 printer(arg
, " ...");
2191 * Time to shut down the link because there is nothing out there.
2195 void LcpLinkFailure (f
)
2198 if (f
->state
== OPENED
) {
2199 info("No response to %d echo-requests", lcp_echos_pending
);
2200 notice("Serial link appears to be disconnected.");
2201 lcp_close(f
->unit
, "Peer not responding");
2202 status
= EXIT_PEER_DEAD
;
2207 * Timer expired for the LCP echo requests from this process.
2214 LcpSendEchoRequest (f
);
2215 if (f
->state
!= OPENED
)
2219 * Start the timer for the next interval.
2221 if (lcp_echo_timer_running
)
2222 warn("assertion lcp_echo_timer_running==0 failed");
2223 TIMEOUT (LcpEchoTimeout
, f
, lcp_echo_interval
);
2224 lcp_echo_timer_running
= 1;
2228 * LcpEchoTimeout - Timer expired on the LCP echo
2232 LcpEchoTimeout (arg
)
2235 if (lcp_echo_timer_running
!= 0) {
2236 lcp_echo_timer_running
= 0;
2237 LcpEchoCheck ((fsm
*) arg
);
2242 * LcpEchoReply - LCP has received a reply to the echo
2246 lcp_received_echo_reply (f
, id
, inp
, len
)
2254 /* Check the magic number - don't count replies from ourselves. */
2256 dbglog("lcp: received short Echo-Reply, length %d", len
);
2259 GETLONG(magic
, inp
);
2260 if (lcp_gotoptions
[f
->unit
].neg_magicnumber
2261 && magic
== lcp_gotoptions
[f
->unit
].magicnumber
) {
2262 warn("appear to have received our own echo-reply!");
2266 /* Reset the number of outstanding echo frames */
2267 lcp_echos_pending
= 0;
2271 * LcpSendEchoRequest - Send an echo request frame to the peer
2275 LcpSendEchoRequest (f
)
2278 u_int32_t lcp_magic
;
2279 u_char pkt
[4], *pktp
;
2282 * Detect the failure of the peer at this point.
2284 if (lcp_echo_fails
!= 0) {
2285 if (lcp_echos_pending
>= lcp_echo_fails
) {
2287 lcp_echos_pending
= 0;
2292 * Make and send the echo request frame.
2294 if (f
->state
== OPENED
) {
2295 lcp_magic
= lcp_gotoptions
[f
->unit
].magicnumber
;
2297 PUTLONG(lcp_magic
, pktp
);
2298 fsm_sdata(f
, ECHOREQ
, lcp_echo_number
++ & 0xFF, pkt
, pktp
- pkt
);
2299 ++lcp_echos_pending
;
2304 * lcp_echo_lowerup - Start the timer for the LCP frame
2308 lcp_echo_lowerup (unit
)
2311 fsm
*f
= &lcp_fsm
[unit
];
2313 /* Clear the parameters for generating echo frames */
2314 lcp_echos_pending
= 0;
2315 lcp_echo_number
= 0;
2316 lcp_echo_timer_running
= 0;
2318 /* If a timeout interval is specified then start the timer */
2319 if (lcp_echo_interval
!= 0)
2324 * lcp_echo_lowerdown - Stop the timer for the LCP frame
2328 lcp_echo_lowerdown (unit
)
2331 fsm
*f
= &lcp_fsm
[unit
];
2333 if (lcp_echo_timer_running
!= 0) {
2334 UNTIMEOUT (LcpEchoTimeout
, f
);
2335 lcp_echo_timer_running
= 0;