Mercurial > flash_v2
annotate packages/net/ppp/current/src/lcp.c @ 1694:5629b7c30ed2
Various patches from Matt Jerdonek and Oyvind Harboe:
* cdl/ppp.cdl:
* src/ipcp.c:
Add option to disallow negotiation of old-style VJ compression
* include/ppp.h:
Add structure to track ppp failure reasons
* include/pppd.h:
Fix compiler warning
* src/auth.c:
* src/lcp.c:
* src/pppd.c:
Add code to track ppp failure reasons
* src/chat.c:
Fixes to clear out buffer space to allow chat script to run
multiple times. Note: function is still not thread-safe
* src/sys-ecos.c:
Reset carrier detected bit when carrier lost
Reset ppp_tty control block when PPP started
* tests/windows_telnet.c:
* cdl/ppp.cdl:
Added windows_telnet example application. Connects to Windows PPP
server and waits for a telnet session.
| author | nickg |
|---|---|
| date | Fri, 23 Jul 2004 11:00:40 +0000 |
| parents | e0d88dc6a92f |
| children |
| rev | line source |
|---|---|
| 1586 | 1 //========================================================================== |
| 2 // | |
| 3 // src/lcp.c | |
| 4 // | |
| 5 //========================================================================== | |
| 6 //####ECOSGPLCOPYRIGHTBEGIN#### | |
| 7 // ------------------------------------------- | |
| 8 // This file is part of eCos, the Embedded Configurable Operating System. | |
| 9 // Portions created by Nick Garnett are | |
| 10 // Copyright (C) 2003 eCosCentric Ltd. | |
| 11 // | |
| 12 // eCos is free software; you can redistribute it and/or modify it under | |
| 13 // the terms of the GNU General Public License as published by the Free | |
| 14 // Software Foundation; either version 2 or (at your option) any later version. | |
| 15 // | |
| 16 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY | |
| 17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 18 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 19 // for more details. | |
| 20 // | |
| 21 // You should have received a copy of the GNU General Public License along | |
| 22 // with eCos; if not, write to the Free Software Foundation, Inc., | |
| 23 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
| 24 // | |
| 25 // As a special exception, if other files instantiate templates or use macros | |
| 26 // or inline functions from this file, or you compile this file and link it | |
| 27 // with other works to produce a work based on this file, this file does not | |
| 28 // by itself cause the resulting work to be covered by the GNU General Public | |
| 29 // License. However the source code for this file must still be made available | |
| 30 // in accordance with section (3) of the GNU General Public License. | |
| 31 // | |
| 32 // This exception does not invalidate any other reasons why a work based on | |
| 33 // this file might be covered by the GNU General Public License. | |
| 34 // | |
| 35 // ------------------------------------------- | |
| 36 //####ECOSGPLCOPYRIGHTEND#### | |
| 37 //####BSDCOPYRIGHTBEGIN#### | |
| 38 // | |
| 39 // ------------------------------------------- | |
| 40 // | |
| 41 // Portions of this software may have been derived from OpenBSD, | |
| 42 // FreeBSD or other sources, and are covered by the appropriate | |
| 43 // copyright disclaimers included herein. | |
| 44 // | |
| 45 // ------------------------------------------- | |
| 46 // | |
| 47 //####BSDCOPYRIGHTEND#### | |
| 48 //========================================================================== | |
| 49 | |
| 50 /* | |
| 51 * lcp.c - PPP Link Control Protocol. | |
| 52 * | |
| 53 * Copyright (c) 1989 Carnegie Mellon University. | |
| 54 * All rights reserved. | |
| 55 * | |
| 56 * Redistribution and use in source and binary forms are permitted | |
| 57 * provided that the above copyright notice and this paragraph are | |
| 58 * duplicated in all such forms and that any documentation, | |
| 59 * advertising materials, and other materials related to such | |
| 60 * distribution and use acknowledge that the software was developed | |
| 61 * by Carnegie Mellon University. The name of the | |
| 62 * University may not be used to endorse or promote products derived | |
| 63 * from this software without specific prior written permission. | |
| 64 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
| 65 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
| 66 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
| 67 */ | |
| 68 | |
| 69 #ifndef lint | |
| 70 //static char rcsid[] = "$FreeBSD: src/usr.sbin/pppd/lcp.c,v 1.9 1999/08/28 01:19:04 peter Exp $"; | |
| 71 #endif | |
| 72 | |
| 73 /* | |
| 74 * TODO: | |
| 75 */ | |
| 76 | |
| 77 #include <stdio.h> | |
| 78 #include <string.h> | |
| 79 #include <cyg/ppp/syslog.h> | |
| 80 #include <assert.h> | |
| 81 #include <sys/ioctl.h> | |
| 82 #include <sys/types.h> | |
| 83 #include <sys/socket.h> | |
| 84 #include <sys/time.h> | |
| 85 #include <netinet/in.h> | |
| 86 | |
| 87 #include "cyg/ppp/pppd.h" | |
| 88 #include "cyg/ppp/fsm.h" | |
| 89 #include "cyg/ppp/lcp.h" | |
| 90 #include "cyg/ppp/chap.h" | |
| 91 #include "cyg/ppp/magic.h" | |
| 92 | |
| 93 /* global vars */ | |
| 94 fsm lcp_fsm[NUM_PPP]; /* LCP fsm structure (global)*/ | |
| 95 lcp_options lcp_wantoptions[NUM_PPP]; /* Options that we want to request */ | |
| 96 lcp_options lcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */ | |
| 97 lcp_options lcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */ | |
| 98 lcp_options lcp_hisoptions[NUM_PPP]; /* Options that we ack'd */ | |
| 99 u_int32_t xmit_accm[NUM_PPP][8]; /* extended transmit ACCM */ | |
| 100 | |
| 101 static u_int32_t lcp_echos_pending = 0; /* Number of outstanding echo msgs */ | |
| 102 static u_int32_t lcp_echo_number = 0; /* ID number of next echo frame */ | |
| 103 static u_int32_t lcp_echo_timer_running = 0; /* TRUE if a timer is running */ | |
| 104 | |
| 105 static u_char nak_buffer[PPP_MRU]; /* where we construct a nak packet */ | |
| 106 | |
| 107 /* | |
| 108 * Callbacks for fsm code. (CI = Configuration Information) | |
| 109 */ | |
| 110 static void lcp_resetci __P((fsm *)); /* Reset our CI */ | |
| 111 static int lcp_cilen __P((fsm *)); /* Return length of our CI */ | |
| 112 static void lcp_addci __P((fsm *, u_char *, int *)); /* Add our CI to pkt */ | |
| 113 static int lcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */ | |
| 114 static int lcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */ | |
| 115 static int lcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */ | |
| 116 static int lcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv peer CI */ | |
| 117 static void lcp_up __P((fsm *)); /* We're UP */ | |
| 118 static void lcp_down __P((fsm *)); /* We're DOWN */ | |
| 119 static void lcp_starting __P((fsm *)); /* We need lower layer up */ | |
| 120 static void lcp_finished __P((fsm *)); /* We need lower layer down */ | |
| 121 static int lcp_extcode __P((fsm *, int, int, u_char *, int)); | |
| 122 static void lcp_rprotrej __P((fsm *, u_char *, int)); | |
| 123 | |
| 124 /* | |
| 125 * routines to send LCP echos to peer | |
| 126 */ | |
| 127 | |
| 128 static void lcp_echo_lowerup __P((int)); | |
| 129 static void lcp_echo_lowerdown __P((int)); | |
| 130 static void LcpEchoTimeout __P((void *)); | |
| 131 static void lcp_received_echo_reply __P((fsm *, int, u_char *, int)); | |
| 132 static void LcpSendEchoRequest __P((fsm *)); | |
| 133 static void LcpLinkFailure __P((fsm *)); | |
| 134 static void LcpEchoCheck __P((fsm *)); | |
| 135 | |
| 136 static fsm_callbacks lcp_callbacks = { /* LCP callback routines */ | |
| 137 lcp_resetci, /* Reset our Configuration Information */ | |
| 138 lcp_cilen, /* Length of our Configuration Information */ | |
| 139 lcp_addci, /* Add our Configuration Information */ | |
| 140 lcp_ackci, /* ACK our Configuration Information */ | |
| 141 lcp_nakci, /* NAK our Configuration Information */ | |
| 142 lcp_rejci, /* Reject our Configuration Information */ | |
| 143 lcp_reqci, /* Request peer's Configuration Information */ | |
| 144 lcp_up, /* Called when fsm reaches OPENED state */ | |
| 145 lcp_down, /* Called when fsm leaves OPENED state */ | |
| 146 lcp_starting, /* Called when we want the lower layer up */ | |
| 147 lcp_finished, /* Called when we want the lower layer down */ | |
| 148 NULL, /* Called when Protocol-Reject received */ | |
| 149 NULL, /* Retransmission is necessary */ | |
| 150 lcp_extcode, /* Called to handle LCP-specific codes */ | |
| 151 "LCP" /* String name of protocol */ | |
| 152 }; | |
| 153 | |
| 154 /* | |
| 155 * Protocol entry points. | |
| 156 * Some of these are called directly. | |
| 157 */ | |
| 158 | |
| 159 static void lcp_init __P((int)); | |
| 160 static void lcp_input __P((int, u_char *, int)); | |
| 161 static void lcp_protrej __P((int)); | |
| 162 static int lcp_printpkt __P((u_char *, int, | |
| 163 void (*) __P((void *, char *, ...)), void *)); | |
| 164 | |
| 165 struct protent lcp_protent = { | |
| 166 PPP_LCP, | |
| 167 lcp_init, | |
| 168 lcp_input, | |
| 169 lcp_protrej, | |
| 170 lcp_lowerup, | |
| 171 lcp_lowerdown, | |
| 172 lcp_open, | |
| 173 lcp_close, | |
| 174 lcp_printpkt, | |
| 175 NULL, | |
| 176 1, | |
| 177 "LCP", | |
| 178 NULL, | |
| 179 NULL, | |
| 180 NULL | |
| 181 }; | |
| 182 | |
| 183 int lcp_loopbackfail = DEFLOOPBACKFAIL; | |
| 184 | |
| 185 /* | |
| 186 * Length of each type of configuration option (in octets) | |
| 187 */ | |
| 188 #define CILEN_VOID 2 | |
| 189 #define CILEN_CHAR 3 | |
| 190 #define CILEN_SHORT 4 /* CILEN_VOID + sizeof(short) */ | |
| 191 #define CILEN_CHAP 5 /* CILEN_VOID + sizeof(short) + 1 */ | |
| 192 #define CILEN_LONG 6 /* CILEN_VOID + sizeof(long) */ | |
| 193 #define CILEN_LQR 8 /* CILEN_VOID + sizeof(short) + sizeof(long) */ | |
| 194 #define CILEN_CBCP 3 | |
| 195 | |
| 196 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \ | |
| 197 (x) == CONFNAK ? "NAK" : "REJ") | |
| 198 | |
| 199 | |
| 200 /* | |
| 201 * lcp_init - Initialize LCP. | |
| 202 */ | |
| 203 static void | |
| 204 lcp_init(unit) | |
| 205 int unit; | |
| 206 { | |
| 207 fsm *f = &lcp_fsm[unit]; | |
| 208 lcp_options *wo = &lcp_wantoptions[unit]; | |
| 209 lcp_options *ao = &lcp_allowoptions[unit]; | |
| 210 | |
| 211 f->unit = unit; | |
| 212 f->protocol = PPP_LCP; | |
| 213 f->callbacks = &lcp_callbacks; | |
| 214 | |
| 215 fsm_init(f); | |
| 216 | |
| 217 wo->passive = 0; | |
| 218 wo->silent = 0; | |
| 219 wo->restart = 0; /* Set to 1 in kernels or multi-line | |
| 220 implementations */ | |
| 221 wo->neg_mru = 1; | |
| 222 wo->mru = DEFMRU; | |
| 223 wo->neg_asyncmap = 0; | |
| 224 wo->asyncmap = 0; | |
| 225 wo->neg_chap = 0; /* Set to 1 on server */ | |
| 226 wo->neg_upap = 0; /* Set to 1 on server */ | |
| 227 wo->chap_mdtype = CHAP_DIGEST_MD5; | |
| 228 wo->neg_magicnumber = 1; | |
| 229 wo->neg_pcompression = 1; | |
| 230 wo->neg_accompression = 1; | |
| 231 wo->neg_lqr = 0; /* no LQR implementation yet */ | |
| 232 wo->neg_cbcp = 0; | |
| 233 | |
| 234 ao->neg_mru = 1; | |
| 235 ao->mru = MAXMRU; | |
| 236 ao->neg_asyncmap = 1; | |
| 237 ao->asyncmap = 0; | |
| 238 ao->neg_chap = 1; | |
| 239 ao->chap_mdtype = CHAP_DIGEST_MD5; | |
| 240 ao->neg_upap = 1; | |
| 241 ao->neg_magicnumber = 1; | |
| 242 ao->neg_pcompression = 1; | |
| 243 ao->neg_accompression = 1; | |
| 244 ao->neg_lqr = 0; /* no LQR implementation yet */ | |
| 245 #ifdef CBCP_SUPPORT | |
| 246 ao->neg_cbcp = 1; | |
| 247 #else | |
| 248 ao->neg_cbcp = 0; | |
| 249 #endif | |
| 250 | |
| 251 memset(xmit_accm[unit], 0, sizeof(xmit_accm[0])); | |
| 252 xmit_accm[unit][3] = 0x60000000; | |
| 253 } | |
| 254 | |
| 255 | |
| 256 /* | |
| 257 * lcp_open - LCP is allowed to come up. | |
| 258 */ | |
| 259 void | |
| 260 lcp_open(unit) | |
| 261 int unit; | |
| 262 { | |
| 263 fsm *f = &lcp_fsm[unit]; | |
| 264 lcp_options *wo = &lcp_wantoptions[unit]; | |
| 265 | |
| 266 f->flags = 0; | |
| 267 if (wo->passive) | |
| 268 f->flags |= OPT_PASSIVE; | |
| 269 if (wo->silent) | |
| 270 f->flags |= OPT_SILENT; | |
| 271 fsm_open(f); | |
| 272 } | |
| 273 | |
| 274 | |
| 275 /* | |
| 276 * lcp_close - Take LCP down. | |
| 277 */ | |
| 278 void | |
| 279 lcp_close(unit, reason) | |
| 280 int unit; | |
| 281 char *reason; | |
| 282 { | |
| 283 fsm *f = &lcp_fsm[unit]; | |
| 284 db_printf("%s()\n",__PRETTY_FUNCTION__); | |
| 285 | |
| 286 if (phase != PHASE_DEAD) | |
| 287 phase = PHASE_TERMINATE; | |
| 288 if (f->state == STOPPED && f->flags & (OPT_PASSIVE|OPT_SILENT)) { | |
| 289 /* | |
| 290 * This action is not strictly according to the FSM in RFC1548, | |
| 291 * but it does mean that the program terminates if you do a | |
| 292 * lcp_close() in passive/silent mode when a connection hasn't | |
| 293 * been established. | |
| 294 */ | |
| 295 f->state = CLOSED; | |
| 296 lcp_finished(f); | |
| 297 | |
| 298 } else | |
| 299 fsm_close(&lcp_fsm[unit], reason); | |
| 300 } | |
| 301 | |
| 302 | |
| 303 /* | |
| 304 * lcp_lowerup - The lower layer is up. | |
| 305 */ | |
| 306 void | |
| 307 lcp_lowerup(unit) | |
| 308 int unit; | |
| 309 { | |
| 310 lcp_options *wo = &lcp_wantoptions[unit]; | |
| 311 | |
| 312 /* | |
| 313 * Don't use A/C or protocol compression on transmission, | |
| 314 * but accept A/C and protocol compressed packets | |
| 315 * if we are going to ask for A/C and protocol compression. | |
| 316 */ | |
| 317 ppp_set_xaccm(unit, xmit_accm[unit]); | |
| 318 ppp_send_config(unit, PPP_MRU, 0xffffffff, 0, 0); | |
| 319 ppp_recv_config(unit, PPP_MRU, 0xffffffff, | |
| 320 wo->neg_pcompression, wo->neg_accompression); | |
| 321 peer_mru[unit] = PPP_MRU; | |
| 322 lcp_allowoptions[unit].asyncmap = xmit_accm[unit][0]; | |
| 323 | |
| 324 fsm_lowerup(&lcp_fsm[unit]); | |
| 325 } | |
| 326 | |
| 327 | |
| 328 /* | |
| 329 * lcp_lowerdown - The lower layer is down. | |
| 330 */ | |
| 331 void | |
| 332 lcp_lowerdown(unit) | |
| 333 int unit; | |
| 334 { | |
| 335 fsm_lowerdown(&lcp_fsm[unit]); | |
| 336 } | |
| 337 | |
| 338 | |
| 339 /* | |
| 340 * lcp_input - Input LCP packet. | |
| 341 */ | |
| 342 static void | |
| 343 lcp_input(unit, p, len) | |
| 344 int unit; | |
| 345 u_char *p; | |
| 346 int len; | |
| 347 { | |
| 348 fsm *f = &lcp_fsm[unit]; | |
| 349 | |
| 350 fsm_input(f, p, len); | |
| 351 } | |
| 352 | |
| 353 | |
| 354 /* | |
| 355 * lcp_extcode - Handle a LCP-specific code. | |
| 356 */ | |
| 357 static int | |
| 358 lcp_extcode(f, code, id, inp, len) | |
| 359 fsm *f; | |
| 360 int code, id; | |
| 361 u_char *inp; | |
| 362 int len; | |
| 363 { | |
| 364 u_char *magp; | |
| 365 | |
| 366 switch( code ){ | |
| 367 case PROTREJ: | |
| 368 lcp_rprotrej(f, inp, len); | |
| 369 break; | |
| 370 | |
| 371 case ECHOREQ: | |
| 372 if (f->state != OPENED) | |
| 373 break; | |
| 374 LCPDEBUG((LOG_INFO, "lcp: Echo-Request, Rcvd id %d", id)); | |
| 375 magp = inp; | |
| 376 PUTLONG(lcp_gotoptions[f->unit].magicnumber, magp); | |
| 377 fsm_sdata(f, ECHOREP, id, inp, len); | |
| 378 break; | |
| 379 | |
| 380 case ECHOREP: | |
| 381 lcp_received_echo_reply(f, id, inp, len); | |
| 382 break; | |
| 383 | |
| 384 case DISCREQ: | |
| 385 break; | |
| 386 | |
| 387 default: | |
| 388 return 0; | |
| 389 } | |
| 390 return 1; | |
| 391 } | |
| 392 | |
| 393 | |
| 394 /* | |
| 395 * lcp_rprotrej - Receive an Protocol-Reject. | |
| 396 * | |
| 397 * Figure out which protocol is rejected and inform it. | |
| 398 */ | |
| 399 static void | |
| 400 lcp_rprotrej(f, inp, len) | |
| 401 fsm *f; | |
| 402 u_char *inp; | |
| 403 int len; | |
| 404 { | |
| 405 int i; | |
| 406 struct protent *protp; | |
| 407 u_short prot; | |
| 408 | |
| 409 LCPDEBUG((LOG_INFO, "lcp_rprotrej.")); | |
| 410 | |
| 411 if (len < sizeof (u_short)) { | |
| 412 LCPDEBUG((LOG_INFO, | |
| 413 "lcp_rprotrej: Rcvd short Protocol-Reject packet!")); | |
| 414 return; | |
| 415 } | |
| 416 | |
| 417 GETSHORT(prot, inp); | |
| 418 | |
| 419 LCPDEBUG((LOG_INFO, | |
| 420 "lcp_rprotrej: Rcvd Protocol-Reject packet for %x!", | |
| 421 prot)); | |
| 422 | |
| 423 /* | |
| 424 * Protocol-Reject packets received in any state other than the LCP | |
| 425 * OPENED state SHOULD be silently discarded. | |
| 426 */ | |
| 427 if( f->state != OPENED ){ | |
| 428 LCPDEBUG((LOG_INFO, "Protocol-Reject discarded: LCP in state %d", | |
| 429 f->state)); | |
| 430 return; | |
| 431 } | |
| 432 | |
| 433 /* | |
| 434 * Upcall the proper Protocol-Reject routine. | |
| 435 */ | |
| 436 for (i = 0; (protp = protocols[i]) != NULL; ++i) | |
| 437 if (protp->protocol == prot && protp->enabled_flag) { | |
| 438 (*protp->protrej)(f->unit); | |
| 439 return; | |
| 440 } | |
| 441 | |
| 442 syslog(LOG_WARNING, "Protocol-Reject for unsupported protocol 0x%x", | |
| 443 prot); | |
| 444 } | |
| 445 | |
| 446 | |
| 447 /* | |
| 448 * lcp_protrej - A Protocol-Reject was received. | |
| 449 */ | |
| 450 /*ARGSUSED*/ | |
| 451 static void | |
| 452 lcp_protrej(unit) | |
| 453 int unit; | |
| 454 { | |
| 455 /* | |
| 456 * Can't reject LCP! | |
| 457 */ | |
| 458 LCPDEBUG((LOG_WARNING, | |
| 459 "lcp_protrej: Received Protocol-Reject for LCP!")); | |
| 460 fsm_protreject(&lcp_fsm[unit]); | |
| 461 } | |
| 462 | |
| 463 | |
| 464 /* | |
| 465 * lcp_sprotrej - Send a Protocol-Reject for some protocol. | |
| 466 */ | |
| 467 void | |
| 468 lcp_sprotrej(unit, p, len) | |
| 469 int unit; | |
| 470 u_char *p; | |
| 471 int len; | |
| 472 { | |
| 473 /* | |
| 474 * Send back the protocol and the information field of the | |
| 475 * rejected packet. We only get here if LCP is in the OPENED state. | |
| 476 */ | |
| 477 p += 2; | |
| 478 len -= 2; | |
| 479 | |
| 480 fsm_sdata(&lcp_fsm[unit], PROTREJ, ++lcp_fsm[unit].id, | |
| 481 p, len); | |
| 482 } | |
| 483 | |
| 484 | |
| 485 /* | |
| 486 * lcp_resetci - Reset our CI. | |
| 487 */ | |
| 488 static void | |
| 489 lcp_resetci(f) | |
| 490 fsm *f; | |
| 491 { | |
| 492 lcp_wantoptions[f->unit].magicnumber = magic(); | |
| 493 lcp_wantoptions[f->unit].numloops = 0; | |
| 494 lcp_gotoptions[f->unit] = lcp_wantoptions[f->unit]; | |
| 495 peer_mru[f->unit] = PPP_MRU; | |
| 496 auth_reset(f->unit); | |
| 497 } | |
| 498 | |
| 499 | |
| 500 /* | |
| 501 * lcp_cilen - Return length of our CI. | |
| 502 */ | |
| 503 static int | |
| 504 lcp_cilen(f) | |
| 505 fsm *f; | |
| 506 { | |
| 507 lcp_options *go = &lcp_gotoptions[f->unit]; | |
| 508 | |
| 509 #define LENCIVOID(neg) ((neg) ? CILEN_VOID : 0) | |
| 510 #define LENCICHAP(neg) ((neg) ? CILEN_CHAP : 0) | |
| 511 #define LENCISHORT(neg) ((neg) ? CILEN_SHORT : 0) | |
| 512 #define LENCILONG(neg) ((neg) ? CILEN_LONG : 0) | |
| 513 #define LENCILQR(neg) ((neg) ? CILEN_LQR: 0) | |
| 514 #define LENCICBCP(neg) ((neg) ? CILEN_CBCP: 0) | |
| 515 /* | |
| 516 * NB: we only ask for one of CHAP and UPAP, even if we will | |
| 517 * accept either. | |
| 518 */ | |
| 519 return (LENCISHORT(go->neg_mru && go->mru != DEFMRU) + | |
| 520 LENCILONG(go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) + | |
| 521 LENCICHAP(go->neg_chap) + | |
| 522 LENCISHORT(!go->neg_chap && go->neg_upap) + | |
| 523 LENCILQR(go->neg_lqr) + | |
| 524 LENCICBCP(go->neg_cbcp) + | |
| 525 LENCILONG(go->neg_magicnumber) + | |
| 526 LENCIVOID(go->neg_pcompression) + | |
| 527 LENCIVOID(go->neg_accompression)); | |
| 528 } | |
| 529 | |
| 530 | |
| 531 /* | |
| 532 * lcp_addci - Add our desired CIs to a packet. | |
| 533 */ | |
| 534 static void | |
| 535 lcp_addci(f, ucp, lenp) | |
| 536 fsm *f; | |
| 537 u_char *ucp; | |
| 538 int *lenp; | |
| 539 { | |
| 540 lcp_options *go = &lcp_gotoptions[f->unit]; | |
| 541 u_char *start_ucp = ucp; | |
| 542 | |
| 543 #define ADDCIVOID(opt, neg) \ | |
| 544 if (neg) { \ | |
| 545 PUTCHAR(opt, ucp); \ | |
| 546 PUTCHAR(CILEN_VOID, ucp); \ | |
| 547 } | |
| 548 #define ADDCISHORT(opt, neg, val) \ | |
| 549 if (neg) { \ | |
| 550 PUTCHAR(opt, ucp); \ | |
| 551 PUTCHAR(CILEN_SHORT, ucp); \ | |
| 552 PUTSHORT(val, ucp); \ | |
| 553 } | |
| 554 #define ADDCICHAP(opt, neg, val, digest) \ | |
| 555 if (neg) { \ | |
| 556 PUTCHAR(opt, ucp); \ | |
| 557 PUTCHAR(CILEN_CHAP, ucp); \ | |
| 558 PUTSHORT(val, ucp); \ | |
| 559 PUTCHAR(digest, ucp); \ | |
| 560 } | |
| 561 #define ADDCILONG(opt, neg, val) \ | |
| 562 if (neg) { \ | |
| 563 PUTCHAR(opt, ucp); \ | |
| 564 PUTCHAR(CILEN_LONG, ucp); \ | |
| 565 PUTLONG(val, ucp); \ | |
| 566 } | |
| 567 #define ADDCILQR(opt, neg, val) \ | |
| 568 if (neg) { \ | |
| 569 PUTCHAR(opt, ucp); \ | |
| 570 PUTCHAR(CILEN_LQR, ucp); \ | |
| 571 PUTSHORT(PPP_LQR, ucp); \ | |
| 572 PUTLONG(val, ucp); \ | |
| 573 } | |
| 574 #define ADDCICHAR(opt, neg, val) \ | |
| 575 if (neg) { \ | |
| 576 PUTCHAR(opt, ucp); \ | |
| 577 PUTCHAR(CILEN_CHAR, ucp); \ | |
| 578 PUTCHAR(val, ucp); \ | |
| 579 } | |
| 580 | |
| 581 ADDCISHORT(CI_MRU, go->neg_mru && go->mru != DEFMRU, go->mru); | |
| 582 ADDCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF, | |
| 583 go->asyncmap); | |
| 584 ADDCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype); | |
| 585 ADDCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP); | |
| 586 ADDCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period); | |
| 587 ADDCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT); | |
| 588 ADDCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber); | |
| 589 ADDCIVOID(CI_PCOMPRESSION, go->neg_pcompression); | |
| 590 ADDCIVOID(CI_ACCOMPRESSION, go->neg_accompression); | |
| 591 | |
| 592 if (ucp - start_ucp != *lenp) { | |
| 593 /* this should never happen, because peer_mtu should be 1500 */ | |
| 594 syslog(LOG_ERR, "Bug in lcp_addci: wrong length"); | |
| 595 } | |
| 596 } | |
| 597 | |
| 598 | |
| 599 /* | |
| 600 * lcp_ackci - Ack our CIs. | |
| 601 * This should not modify any state if the Ack is bad. | |
| 602 * | |
| 603 * Returns: | |
| 604 * 0 - Ack was bad. | |
| 605 * 1 - Ack was good. | |
| 606 */ | |
| 607 static int | |
| 608 lcp_ackci(f, p, len) | |
| 609 fsm *f; | |
| 610 u_char *p; | |
| 611 int len; | |
| 612 { | |
| 613 lcp_options *go = &lcp_gotoptions[f->unit]; | |
| 614 u_char cilen, citype, cichar; | |
| 615 u_short cishort; | |
| 616 u_int32_t cilong; | |
| 617 | |
| 618 /* | |
| 619 * CIs must be in exactly the same order that we sent. | |
| 620 * Check packet length and CI length at each step. | |
| 621 * If we find any deviations, then this packet is bad. | |
| 622 */ | |
| 623 #define ACKCIVOID(opt, neg) \ | |
| 624 if (neg) { \ | |
| 625 if ((len -= CILEN_VOID) < 0) \ | |
| 626 goto bad; \ | |
| 627 GETCHAR(citype, p); \ | |
| 628 GETCHAR(cilen, p); \ | |
| 629 if (cilen != CILEN_VOID || \ | |
| 630 citype != opt) \ | |
| 631 goto bad; \ | |
| 632 } | |
| 633 #define ACKCISHORT(opt, neg, val) \ | |
| 634 if (neg) { \ | |
| 635 if ((len -= CILEN_SHORT) < 0) \ | |
| 636 goto bad; \ | |
| 637 GETCHAR(citype, p); \ | |
| 638 GETCHAR(cilen, p); \ | |
| 639 if (cilen != CILEN_SHORT || \ | |
| 640 citype != opt) \ | |
| 641 goto bad; \ | |
| 642 GETSHORT(cishort, p); \ | |
| 643 if (cishort != val) \ | |
| 644 goto bad; \ | |
| 645 } | |
| 646 #define ACKCICHAR(opt, neg, val) \ | |
| 647 if (neg) { \ | |
| 648 if ((len -= CILEN_CHAR) < 0) \ | |
| 649 goto bad; \ | |
| 650 GETCHAR(citype, p); \ | |
| 651 GETCHAR(cilen, p); \ | |
| 652 if (cilen != CILEN_CHAR || \ | |
| 653 citype != opt) \ | |
| 654 goto bad; \ | |
| 655 GETCHAR(cichar, p); \ | |
| 656 if (cichar != val) \ | |
| 657 goto bad; \ | |
| 658 } | |
| 659 #define ACKCICHAP(opt, neg, val, digest) \ | |
| 660 if (neg) { \ | |
| 661 if ((len -= CILEN_CHAP) < 0) \ | |
| 662 goto bad; \ | |
| 663 GETCHAR(citype, p); \ | |
| 664 GETCHAR(cilen, p); \ | |
| 665 if (cilen != CILEN_CHAP || \ | |
| 666 citype != opt) \ | |
| 667 goto bad; \ | |
| 668 GETSHORT(cishort, p); \ | |
| 669 if (cishort != val) \ | |
| 670 goto bad; \ | |
| 671 GETCHAR(cichar, p); \ | |
| 672 if (cichar != digest) \ | |
| 673 goto bad; \ | |
| 674 } | |
| 675 #define ACKCILONG(opt, neg, val) \ | |
| 676 if (neg) { \ | |
| 677 if ((len -= CILEN_LONG) < 0) \ | |
| 678 goto bad; \ | |
| 679 GETCHAR(citype, p); \ | |
| 680 GETCHAR(cilen, p); \ | |
| 681 if (cilen != CILEN_LONG || \ | |
| 682 citype != opt) \ | |
| 683 goto bad; \ | |
| 684 GETLONG(cilong, p); \ | |
| 685 if (cilong != val) \ | |
| 686 goto bad; \ | |
| 687 } | |
| 688 #define ACKCILQR(opt, neg, val) \ | |
| 689 if (neg) { \ | |
| 690 if ((len -= CILEN_LQR) < 0) \ | |
| 691 goto bad; \ | |
| 692 GETCHAR(citype, p); \ | |
| 693 GETCHAR(cilen, p); \ | |
| 694 if (cilen != CILEN_LQR || \ | |
| 695 citype != opt) \ | |
| 696 goto bad; \ | |
| 697 GETSHORT(cishort, p); \ | |
| 698 if (cishort != PPP_LQR) \ | |
| 699 goto bad; \ | |
| 700 GETLONG(cilong, p); \ | |
| 701 if (cilong != val) \ | |
| 702 goto bad; \ | |
| 703 } | |
| 704 | |
| 705 ACKCISHORT(CI_MRU, go->neg_mru && go->mru != DEFMRU, go->mru); | |
| 706 ACKCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF, | |
| 707 go->asyncmap); | |
| 708 ACKCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype); | |
| 709 ACKCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP); | |
| 710 ACKCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period); | |
| 711 ACKCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT); | |
| 712 ACKCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber); | |
| 713 ACKCIVOID(CI_PCOMPRESSION, go->neg_pcompression); | |
| 714 ACKCIVOID(CI_ACCOMPRESSION, go->neg_accompression); | |
| 715 | |
| 716 /* | |
| 717 * If there are any remaining CIs, then this packet is bad. | |
| 718 */ | |
| 719 if (len != 0) | |
| 720 goto bad; | |
| 721 return (1); | |
| 722 bad: | |
| 723 LCPDEBUG((LOG_WARNING, "lcp_acki: received bad Ack!")); | |
| 724 return (0); | |
| 725 } | |
| 726 | |
| 727 | |
| 728 /* | |
| 729 * lcp_nakci - Peer has sent a NAK for some of our CIs. | |
| 730 * This should not modify any state if the Nak is bad | |
| 731 * or if LCP is in the OPENED state. | |
| 732 * | |
| 733 * Returns: | |
| 734 * 0 - Nak was bad. | |
| 735 * 1 - Nak was good. | |
| 736 */ | |
| 737 static int | |
| 738 lcp_nakci(f, p, len) | |
| 739 fsm *f; | |
| 740 u_char *p; | |
| 741 int len; | |
| 742 { | |
| 743 lcp_options *go = &lcp_gotoptions[f->unit]; | |
| 744 lcp_options *wo = &lcp_wantoptions[f->unit]; | |
| 745 u_char citype, cichar, *next; | |
| 746 u_short cishort; | |
| 747 u_int32_t cilong; | |
| 748 lcp_options no; /* options we've seen Naks for */ | |
| 749 lcp_options try; /* options to request next time */ | |
| 750 int looped_back = 0; | |
| 751 int cilen; | |
| 752 | |
| 753 BZERO(&no, sizeof(no)); | |
| 754 try = *go; | |
| 755 | |
| 756 /* | |
| 757 * Any Nak'd CIs must be in exactly the same order that we sent. | |
| 758 * Check packet length and CI length at each step. | |
| 759 * If we find any deviations, then this packet is bad. | |
| 760 */ | |
| 761 #define NAKCIVOID(opt, neg, code) \ | |
| 762 if (go->neg && \ | |
| 763 len >= CILEN_VOID && \ | |
| 764 p[1] == CILEN_VOID && \ | |
| 765 p[0] == opt) { \ | |
| 766 len -= CILEN_VOID; \ | |
| 767 INCPTR(CILEN_VOID, p); \ | |
| 768 no.neg = 1; \ | |
| 769 code \ | |
| 770 } | |
| 771 #define NAKCICHAP(opt, neg, code) \ | |
| 772 if (go->neg && \ | |
| 773 len >= CILEN_CHAP && \ | |
| 774 p[1] == CILEN_CHAP && \ | |
| 775 p[0] == opt) { \ | |
| 776 len -= CILEN_CHAP; \ | |
| 777 INCPTR(2, p); \ | |
| 778 GETSHORT(cishort, p); \ | |
| 779 GETCHAR(cichar, p); \ | |
| 780 no.neg = 1; \ | |
| 781 code \ | |
| 782 } | |
| 783 #define NAKCICHAR(opt, neg, code) \ | |
| 784 if (go->neg && \ | |
| 785 len >= CILEN_CHAR && \ | |
| 786 p[1] == CILEN_CHAR && \ | |
| 787 p[0] == opt) { \ | |
| 788 len -= CILEN_CHAR; \ | |
| 789 INCPTR(2, p); \ | |
| 790 GETCHAR(cichar, p); \ | |
| 791 no.neg = 1; \ | |
| 792 code \ | |
| 793 } | |
| 794 #define NAKCISHORT(opt, neg, code) \ | |
| 795 if (go->neg && \ | |
| 796 len >= CILEN_SHORT && \ | |
| 797 p[1] == CILEN_SHORT && \ | |
| 798 p[0] == opt) { \ | |
| 799 len -= CILEN_SHORT; \ | |
| 800 INCPTR(2, p); \ | |
| 801 GETSHORT(cishort, p); \ | |
| 802 no.neg = 1; \ | |
| 803 code \ | |
| 804 } | |
| 805 #define NAKCILONG(opt, neg, code) \ | |
| 806 if (go->neg && \ | |
| 807 len >= CILEN_LONG && \ | |
| 808 p[1] == CILEN_LONG && \ | |
| 809 p[0] == opt) { \ | |
| 810 len -= CILEN_LONG; \ | |
| 811 INCPTR(2, p); \ | |
| 812 GETLONG(cilong, p); \ | |
| 813 no.neg = 1; \ | |
| 814 code \ | |
| 815 } | |
| 816 #define NAKCILQR(opt, neg, code) \ | |
| 817 if (go->neg && \ | |
| 818 len >= CILEN_LQR && \ | |
| 819 p[1] == CILEN_LQR && \ | |
| 820 p[0] == opt) { \ | |
| 821 len -= CILEN_LQR; \ | |
| 822 INCPTR(2, p); \ | |
| 823 GETSHORT(cishort, p); \ | |
| 824 GETLONG(cilong, p); \ | |
| 825 no.neg = 1; \ | |
| 826 code \ | |
| 827 } | |
| 828 | |
| 829 /* | |
| 830 * We don't care if they want to send us smaller packets than | |
| 831 * we want. Therefore, accept any MRU less than what we asked for, | |
| 832 * but then ignore the new value when setting the MRU in the kernel. | |
| 833 * If they send us a bigger MRU than what we asked, accept it, up to | |
| 834 * the limit of the default MRU we'd get if we didn't negotiate. | |
| 835 */ | |
| 836 if (go->neg_mru && go->mru != DEFMRU) { | |
| 837 NAKCISHORT(CI_MRU, neg_mru, | |
| 838 if (cishort <= wo->mru || cishort <= DEFMRU) | |
| 839 try.mru = cishort; | |
| 840 ); | |
| 841 } | |
| 842 | |
| 843 /* | |
| 844 * Add any characters they want to our (receive-side) asyncmap. | |
| 845 */ | |
| 846 if (go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) { | |
| 847 NAKCILONG(CI_ASYNCMAP, neg_asyncmap, | |
| 848 try.asyncmap = go->asyncmap | cilong; | |
| 849 ); | |
| 850 } | |
| 851 | |
| 852 /* | |
| 853 * If they've nak'd our authentication-protocol, check whether | |
| 854 * they are proposing a different protocol, or a different | |
| 855 * hash algorithm for CHAP. | |
| 856 */ | |
| 857 if ((go->neg_chap || go->neg_upap) | |
| 858 && len >= CILEN_SHORT | |
| 859 && p[0] == CI_AUTHTYPE && p[1] >= CILEN_SHORT && p[1] <= len) { | |
| 860 cilen = p[1]; | |
| 861 len -= cilen; | |
| 862 no.neg_chap = go->neg_chap; | |
| 863 no.neg_upap = go->neg_upap; | |
| 864 INCPTR(2, p); | |
| 865 GETSHORT(cishort, p); | |
| 866 if (cishort == PPP_PAP && cilen == CILEN_SHORT) { | |
| 867 /* | |
| 868 * If we were asking for CHAP, they obviously don't want to do it. | |
| 869 * If we weren't asking for CHAP, then we were asking for PAP, | |
| 870 * in which case this Nak is bad. | |
| 871 */ | |
| 872 if (!go->neg_chap) | |
| 873 goto bad; | |
| 874 try.neg_chap = 0; | |
| 875 | |
| 876 } else if (cishort == PPP_CHAP && cilen == CILEN_CHAP) { | |
| 877 GETCHAR(cichar, p); | |
| 878 if (go->neg_chap) { | |
| 879 /* | |
| 880 * We were asking for CHAP/MD5; they must want a different | |
| 881 * algorithm. If they can't do MD5, we'll have to stop | |
| 882 * asking for CHAP. | |
| 883 */ | |
| 884 if (cichar != go->chap_mdtype) | |
| 885 try.neg_chap = 0; | |
| 886 } else { | |
| 887 /* | |
| 888 * Stop asking for PAP if we were asking for it. | |
| 889 */ | |
| 890 try.neg_upap = 0; | |
| 891 } | |
| 892 | |
| 893 } else { | |
| 894 /* | |
| 895 * We don't recognize what they're suggesting. | |
| 896 * Stop asking for what we were asking for. | |
| 897 */ | |
| 898 if (go->neg_chap) | |
| 899 try.neg_chap = 0; | |
| 900 else | |
| 901 try.neg_upap = 0; | |
| 902 p += cilen - CILEN_SHORT; | |
| 903 } | |
| 904 } | |
| 905 | |
| 906 /* | |
| 907 * If they can't cope with our link quality protocol, we'll have | |
| 908 * to stop asking for LQR. We haven't got any other protocol. | |
| 909 * If they Nak the reporting period, take their value XXX ? | |
| 910 */ | |
| 911 NAKCILQR(CI_QUALITY, neg_lqr, | |
| 912 if (cishort != PPP_LQR) | |
| 913 try.neg_lqr = 0; | |
| 914 else | |
| 915 try.lqr_period = cilong; | |
| 916 ); | |
| 917 | |
| 918 /* | |
| 919 * Only implementing CBCP...not the rest of the callback options | |
| 920 */ | |
| 921 NAKCICHAR(CI_CALLBACK, neg_cbcp, | |
| 922 try.neg_cbcp = 0; | |
| 923 ); | |
| 924 | |
| 925 /* | |
| 926 * Check for a looped-back line. | |
| 927 */ | |
| 928 NAKCILONG(CI_MAGICNUMBER, neg_magicnumber, | |
| 929 try.magicnumber = magic(); | |
| 930 looped_back = 1; | |
| 931 ); | |
| 932 | |
| 933 /* | |
| 934 * Peer shouldn't send Nak for protocol compression or | |
| 935 * address/control compression requests; they should send | |
| 936 * a Reject instead. If they send a Nak, treat it as a Reject. | |
| 937 */ | |
| 938 NAKCIVOID(CI_PCOMPRESSION, neg_pcompression, | |
| 939 try.neg_pcompression = 0; | |
| 940 ); | |
| 941 NAKCIVOID(CI_ACCOMPRESSION, neg_accompression, | |
| 942 try.neg_accompression = 0; | |
| 943 ); | |
| 944 | |
| 945 /* | |
| 946 * There may be remaining CIs, if the peer is requesting negotiation | |
| 947 * on an option that we didn't include in our request packet. | |
| 948 * If we see an option that we requested, or one we've already seen | |
| 949 * in this packet, then this packet is bad. | |
| 950 * If we wanted to respond by starting to negotiate on the requested | |
| 951 * option(s), we could, but we don't, because except for the | |
| 952 * authentication type and quality protocol, if we are not negotiating | |
| 953 * an option, it is because we were told not to. | |
| 954 * For the authentication type, the Nak from the peer means | |
| 955 * `let me authenticate myself with you' which is a bit pointless. | |
| 956 * For the quality protocol, the Nak means `ask me to send you quality | |
| 957 * reports', but if we didn't ask for them, we don't want them. | |
| 958 * An option we don't recognize represents the peer asking to | |
| 959 * negotiate some option we don't support, so ignore it. | |
| 960 */ | |
| 961 while (len > CILEN_VOID) { | |
| 962 GETCHAR(citype, p); | |
| 963 GETCHAR(cilen, p); | |
| 964 if (cilen < CILEN_VOID || (len -= cilen) < 0) | |
| 965 goto bad; | |
| 966 next = p + cilen - 2; | |
| 967 | |
| 968 switch (citype) { | |
| 969 case CI_MRU: | |
| 970 if ((go->neg_mru && go->mru != DEFMRU) | |
| 971 || no.neg_mru || cilen != CILEN_SHORT) | |
| 972 goto bad; | |
| 973 GETSHORT(cishort, p); | |
| 974 if (cishort < DEFMRU) | |
| 975 try.mru = cishort; | |
| 976 break; | |
| 977 case CI_ASYNCMAP: | |
| 978 if ((go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) | |
| 979 || no.neg_asyncmap || cilen != CILEN_LONG) | |
| 980 goto bad; | |
| 981 break; | |
| 982 case CI_AUTHTYPE: | |
| 983 if (go->neg_chap || no.neg_chap || go->neg_upap || no.neg_upap) | |
| 984 goto bad; | |
| 985 break; | |
| 986 case CI_MAGICNUMBER: | |
| 987 if (go->neg_magicnumber || no.neg_magicnumber || | |
| 988 cilen != CILEN_LONG) | |
| 989 goto bad; | |
| 990 break; | |
| 991 case CI_PCOMPRESSION: | |
| 992 if (go->neg_pcompression || no.neg_pcompression | |
| 993 || cilen != CILEN_VOID) | |
| 994 goto bad; | |
| 995 break; | |
| 996 case CI_ACCOMPRESSION: | |
| 997 if (go->neg_accompression || no.neg_accompression | |
| 998 || cilen != CILEN_VOID) | |
| 999 goto bad; | |
| 1000 break; | |
| 1001 case CI_QUALITY: | |
| 1002 if (go->neg_lqr || no.neg_lqr || cilen != CILEN_LQR) | |
| 1003 goto bad; | |
| 1004 break; | |
| 1005 } | |
| 1006 p = next; | |
| 1007 } | |
| 1008 | |
| 1009 /* If there is still anything left, this packet is bad. */ | |
| 1010 if (len != 0) | |
| 1011 goto bad; | |
| 1012 | |
| 1013 /* | |
| 1014 * OK, the Nak is good. Now we can update state. | |
| 1015 */ | |
| 1016 if (f->state != OPENED) { | |
| 1017 if (looped_back) { | |
| 1018 if (++try.numloops >= lcp_loopbackfail) { | |
| 1019 syslog(LOG_NOTICE, "Serial line is looped back."); | |
| 1020 lcp_close(f->unit, "Loopback detected"); | |
|
1694
5629b7c30ed2
Various patches from Matt Jerdonek and Oyvind Harboe:
nickg
parents:
1586
diff
changeset
|
1021 cyg_ppp_stats.loopback++; |
| 1586 | 1022 } |
| 1023 } else | |
| 1024 try.numloops = 0; | |
| 1025 *go = try; | |
| 1026 } | |
| 1027 | |
| 1028 return 1; | |
| 1029 | |
| 1030 bad: | |
| 1031 LCPDEBUG((LOG_WARNING, "lcp_nakci: received bad Nak!")); | |
| 1032 return 0; | |
| 1033 } | |
| 1034 | |
| 1035 | |
| 1036 /* | |
| 1037 * lcp_rejci - Peer has Rejected some of our CIs. | |
| 1038 * This should not modify any state if the Reject is bad | |
| 1039 * or if LCP is in the OPENED state. | |
| 1040 * | |
| 1041 * Returns: | |
| 1042 * 0 - Reject was bad. | |
| 1043 * 1 - Reject was good. | |
| 1044 */ | |
| 1045 static int | |
| 1046 lcp_rejci(f, p, len) | |
| 1047 fsm *f; | |
| 1048 u_char *p; | |
| 1049 int len; | |
| 1050 { | |
| 1051 lcp_options *go = &lcp_gotoptions[f->unit]; | |
| 1052 u_char cichar; | |
| 1053 u_short cishort; | |
| 1054 u_int32_t cilong; | |
| 1055 lcp_options try; /* options to request next time */ | |
| 1056 | |
| 1057 try = *go; | |
| 1058 | |
| 1059 /* | |
| 1060 * Any Rejected CIs must be in exactly the same order that we sent. | |
| 1061 * Check packet length and CI length at each step. | |
| 1062 * If we find any deviations, then this packet is bad. | |
| 1063 */ | |
| 1064 #define REJCIVOID(opt, neg) \ | |
| 1065 if (go->neg && \ | |
| 1066 len >= CILEN_VOID && \ | |
| 1067 p[1] == CILEN_VOID && \ | |
| 1068 p[0] == opt) { \ | |
| 1069 len -= CILEN_VOID; \ | |
| 1070 INCPTR(CILEN_VOID, p); \ | |
| 1071 try.neg = 0; \ | |
| 1072 LCPDEBUG((LOG_INFO, "lcp_rejci rejected void opt %d", opt)); \ | |
| 1073 } | |
| 1074 #define REJCISHORT(opt, neg, val) \ | |
| 1075 if (go->neg && \ | |
| 1076 len >= CILEN_SHORT && \ | |
| 1077 p[1] == CILEN_SHORT && \ | |
| 1078 p[0] == opt) { \ | |
| 1079 len -= CILEN_SHORT; \ | |
| 1080 INCPTR(2, p); \ | |
| 1081 GETSHORT(cishort, p); \ | |
| 1082 /* Check rejected value. */ \ | |
| 1083 if (cishort != val) \ | |
| 1084 goto bad; \ | |
| 1085 try.neg = 0; \ | |
| 1086 LCPDEBUG((LOG_INFO,"lcp_rejci rejected short opt %d", opt)); \ | |
| 1087 } | |
| 1088 #define REJCICHAP(opt, neg, val, digest) \ | |
| 1089 if (go->neg && \ | |
| 1090 len >= CILEN_CHAP && \ | |
| 1091 p[1] == CILEN_CHAP && \ | |
| 1092 p[0] == opt) { \ | |
| 1093 len -= CILEN_CHAP; \ | |
| 1094 INCPTR(2, p); \ | |
| 1095 GETSHORT(cishort, p); \ | |
| 1096 GETCHAR(cichar, p); \ | |
| 1097 /* Check rejected value. */ \ | |
| 1098 if (cishort != val || cichar != digest) \ | |
| 1099 goto bad; \ | |
| 1100 try.neg = 0; \ | |
| 1101 try.neg_upap = 0; \ | |
| 1102 LCPDEBUG((LOG_INFO,"lcp_rejci rejected chap opt %d", opt)); \ | |
| 1103 } | |
| 1104 #define REJCILONG(opt, neg, val) \ | |
| 1105 if (go->neg && \ | |
| 1106 len >= CILEN_LONG && \ | |
| 1107 p[1] == CILEN_LONG && \ | |
| 1108 p[0] == opt) { \ | |
| 1109 len -= CILEN_LONG; \ | |
| 1110 INCPTR(2, p); \ | |
| 1111 GETLONG(cilong, p); \ | |
| 1112 /* Check rejected value. */ \ | |
| 1113 if (cilong != val) \ | |
| 1114 goto bad; \ | |
| 1115 try.neg = 0; \ | |
| 1116 LCPDEBUG((LOG_INFO,"lcp_rejci rejected long opt %d", opt)); \ | |
| 1117 } | |
| 1118 #define REJCILQR(opt, neg, val) \ | |
| 1119 if (go->neg && \ | |
| 1120 len >= CILEN_LQR && \ | |
| 1121 p[1] == CILEN_LQR && \ | |
| 1122 p[0] == opt) { \ | |
| 1123 len -= CILEN_LQR; \ | |
| 1124 INCPTR(2, p); \ | |
| 1125 GETSHORT(cishort, p); \ | |
| 1126 GETLONG(cilong, p); \ | |
| 1127 /* Check rejected value. */ \ | |
| 1128 if (cishort != PPP_LQR || cilong != val) \ | |
| 1129 goto bad; \ | |
| 1130 try.neg = 0; \ | |
| 1131 LCPDEBUG((LOG_INFO,"lcp_rejci rejected LQR opt %d", opt)); \ | |
| 1132 } | |
| 1133 #define REJCICBCP(opt, neg, val) \ | |
| 1134 if (go->neg && \ | |
| 1135 len >= CILEN_CBCP && \ | |
| 1136 p[1] == CILEN_CBCP && \ | |
| 1137 p[0] == opt) { \ | |
| 1138 len -= CILEN_CBCP; \ | |
| 1139 INCPTR(2, p); \ | |
| 1140 GETCHAR(cichar, p); \ | |
| 1141 /* Check rejected value. */ \ | |
| 1142 if (cichar != val) \ | |
| 1143 goto bad; \ | |
| 1144 try.neg = 0; \ | |
| 1145 LCPDEBUG((LOG_INFO,"lcp_rejci rejected Callback opt %d", opt)); \ | |
| 1146 } | |
| 1147 | |
| 1148 REJCISHORT(CI_MRU, neg_mru, go->mru); | |
| 1149 REJCILONG(CI_ASYNCMAP, neg_asyncmap, go->asyncmap); | |
| 1150 REJCICHAP(CI_AUTHTYPE, neg_chap, PPP_CHAP, go->chap_mdtype); | |
| 1151 if (!go->neg_chap) { | |
| 1152 REJCISHORT(CI_AUTHTYPE, neg_upap, PPP_PAP); | |
| 1153 } | |
| 1154 REJCILQR(CI_QUALITY, neg_lqr, go->lqr_period); | |
| 1155 REJCICBCP(CI_CALLBACK, neg_cbcp, CBCP_OPT); | |
| 1156 REJCILONG(CI_MAGICNUMBER, neg_magicnumber, go->magicnumber); | |
| 1157 REJCIVOID(CI_PCOMPRESSION, neg_pcompression); | |
| 1158 REJCIVOID(CI_ACCOMPRESSION, neg_accompression); | |
| 1159 | |
| 1160 /* | |
| 1161 * If there are any remaining CIs, then this packet is bad. | |
| 1162 */ | |
| 1163 if (len != 0) | |
| 1164 goto bad; | |
| 1165 /* | |
| 1166 * Now we can update state. | |
| 1167 */ | |
| 1168 if (f->state != OPENED) | |
| 1169 *go = try; | |
| 1170 return 1; | |
| 1171 | |
| 1172 bad: | |
| 1173 LCPDEBUG((LOG_WARNING, "lcp_rejci: received bad Reject!")); | |
| 1174 return 0; | |
| 1175 } | |
| 1176 | |
| 1177 | |
| 1178 /* | |
| 1179 * lcp_reqci - Check the peer's requested CIs and send appropriate response. | |
| 1180 * | |
| 1181 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified | |
| 1182 * appropriately. If reject_if_disagree is non-zero, doesn't return | |
| 1183 * CONFNAK; returns CONFREJ if it can't return CONFACK. | |
| 1184 */ | |
| 1185 static int | |
| 1186 lcp_reqci(f, inp, lenp, reject_if_disagree) | |
| 1187 fsm *f; | |
| 1188 u_char *inp; /* Requested CIs */ | |
| 1189 int *lenp; /* Length of requested CIs */ | |
| 1190 int reject_if_disagree; | |
| 1191 { | |
| 1192 lcp_options *go = &lcp_gotoptions[f->unit]; | |
| 1193 lcp_options *ho = &lcp_hisoptions[f->unit]; | |
| 1194 lcp_options *ao = &lcp_allowoptions[f->unit]; | |
| 1195 u_char *cip, *next; /* Pointer to current and next CIs */ | |
| 1196 int cilen, citype, cichar; /* Parsed len, type, char value */ | |
| 1197 u_short cishort; /* Parsed short value */ | |
| 1198 u_int32_t cilong; /* Parse long value */ | |
| 1199 int rc = CONFACK; /* Final packet return code */ | |
| 1200 int orc; /* Individual option return code */ | |
| 1201 u_char *p; /* Pointer to next char to parse */ | |
| 1202 u_char *rejp; /* Pointer to next char in reject frame */ | |
| 1203 u_char *nakp; /* Pointer to next char in Nak frame */ | |
| 1204 int l = *lenp; /* Length left */ | |
| 1205 | |
| 1206 /* | |
| 1207 * Reset all his options. | |
| 1208 */ | |
| 1209 BZERO(ho, sizeof(*ho)); | |
| 1210 | |
| 1211 /* | |
| 1212 * Process all his options. | |
| 1213 */ | |
| 1214 next = inp; | |
| 1215 nakp = nak_buffer; | |
| 1216 rejp = inp; | |
| 1217 while (l) { | |
| 1218 orc = CONFACK; /* Assume success */ | |
| 1219 cip = p = next; /* Remember begining of CI */ | |
| 1220 if (l < 2 || /* Not enough data for CI header or */ | |
| 1221 p[1] < 2 || /* CI length too small or */ | |
| 1222 p[1] > l) { /* CI length too big? */ | |
| 1223 LCPDEBUG((LOG_WARNING, "lcp_reqci: bad CI length!")); | |
| 1224 orc = CONFREJ; /* Reject bad CI */ | |
| 1225 cilen = l; /* Reject till end of packet */ | |
| 1226 l = 0; /* Don't loop again */ | |
| 1227 citype = 0; | |
| 1228 goto endswitch; | |
| 1229 } | |
| 1230 GETCHAR(citype, p); /* Parse CI type */ | |
| 1231 GETCHAR(cilen, p); /* Parse CI length */ | |
| 1232 l -= cilen; /* Adjust remaining length */ | |
| 1233 next += cilen; /* Step to next CI */ | |
| 1234 | |
| 1235 switch (citype) { /* Check CI type */ | |
| 1236 case CI_MRU: | |
| 1237 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd MRU")); | |
| 1238 if (!ao->neg_mru || /* Allow option? */ | |
| 1239 cilen != CILEN_SHORT) { /* Check CI length */ | |
| 1240 orc = CONFREJ; /* Reject CI */ | |
| 1241 break; | |
| 1242 } | |
| 1243 GETSHORT(cishort, p); /* Parse MRU */ | |
| 1244 LCPDEBUG((LOG_INFO, "(%d)", cishort)); | |
| 1245 | |
| 1246 /* | |
| 1247 * He must be able to receive at least our minimum. | |
| 1248 * No need to check a maximum. If he sends a large number, | |
| 1249 * we'll just ignore it. | |
| 1250 */ | |
| 1251 if (cishort < MINMRU) { | |
| 1252 orc = CONFNAK; /* Nak CI */ | |
| 1253 PUTCHAR(CI_MRU, nakp); | |
| 1254 PUTCHAR(CILEN_SHORT, nakp); | |
| 1255 PUTSHORT(MINMRU, nakp); /* Give him a hint */ | |
| 1256 break; | |
| 1257 } | |
| 1258 ho->neg_mru = 1; /* Remember he sent MRU */ | |
| 1259 ho->mru = cishort; /* And remember value */ | |
| 1260 break; | |
| 1261 | |
| 1262 case CI_ASYNCMAP: | |
| 1263 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd ASYNCMAP")); | |
| 1264 if (!ao->neg_asyncmap || | |
| 1265 cilen != CILEN_LONG) { | |
| 1266 orc = CONFREJ; | |
| 1267 break; | |
| 1268 } | |
| 1269 GETLONG(cilong, p); | |
| 1270 LCPDEBUG((LOG_INFO, "(%x)", (unsigned int) cilong)); | |
| 1271 | |
| 1272 /* | |
| 1273 * Asyncmap must have set at least the bits | |
| 1274 * which are set in lcp_allowoptions[unit].asyncmap. | |
| 1275 */ | |
| 1276 if ((ao->asyncmap & ~cilong) != 0) { | |
| 1277 orc = CONFNAK; | |
| 1278 PUTCHAR(CI_ASYNCMAP, nakp); | |
| 1279 PUTCHAR(CILEN_LONG, nakp); | |
| 1280 PUTLONG(ao->asyncmap | cilong, nakp); | |
| 1281 break; | |
| 1282 } | |
| 1283 ho->neg_asyncmap = 1; | |
| 1284 ho->asyncmap = cilong; | |
| 1285 break; | |
| 1286 | |
| 1287 case CI_AUTHTYPE: | |
| 1288 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd AUTHTYPE")); | |
| 1289 | |
| 1290 if (cilen < CILEN_SHORT || | |
| 1291 !(ao->neg_upap || ao->neg_chap)) { | |
| 1292 /* | |
| 1293 * Reject the option if we're not willing to authenticate. | |
| 1294 */ | |
| 1295 orc = CONFREJ; | |
| 1296 break; | |
| 1297 } | |
| 1298 GETSHORT(cishort, p); | |
| 1299 LCPDEBUG((LOG_INFO, "(%x)", cishort)); | |
| 1300 | |
| 1301 /* | |
| 1302 * Authtype must be UPAP or CHAP. | |
| 1303 * | |
| 1304 * Note: if both ao->neg_upap and ao->neg_chap are set, | |
| 1305 * and the peer sends a Configure-Request with two | |
| 1306 * authenticate-protocol requests, one for CHAP and one | |
| 1307 * for UPAP, then we will reject the second request. | |
| 1308 * Whether we end up doing CHAP or UPAP depends then on | |
| 1309 * the ordering of the CIs in the peer's Configure-Request. | |
| 1310 */ | |
| 1311 | |
| 1312 if (cishort == PPP_PAP) { | |
| 1313 if (ho->neg_chap || /* we've already accepted CHAP */ | |
| 1314 cilen != CILEN_SHORT) { | |
| 1315 LCPDEBUG((LOG_WARNING, | |
| 1316 "lcp_reqci: rcvd AUTHTYPE PAP, rejecting...")); | |
| 1317 orc = CONFREJ; | |
| 1318 break; | |
| 1319 } | |
| 1320 if (!ao->neg_upap) { /* we don't want to do PAP */ | |
| 1321 orc = CONFNAK; /* NAK it and suggest CHAP */ | |
| 1322 PUTCHAR(CI_AUTHTYPE, nakp); | |
| 1323 PUTCHAR(CILEN_CHAP, nakp); | |
| 1324 PUTSHORT(PPP_CHAP, nakp); | |
| 1325 PUTCHAR(ao->chap_mdtype, nakp); | |
| 1326 break; | |
| 1327 } | |
| 1328 ho->neg_upap = 1; | |
| 1329 break; | |
| 1330 } | |
| 1331 if (cishort == PPP_CHAP) { | |
| 1332 if (ho->neg_upap || /* we've already accepted PAP */ | |
| 1333 cilen != CILEN_CHAP) { | |
| 1334 LCPDEBUG((LOG_INFO, | |
| 1335 "lcp_reqci: rcvd AUTHTYPE CHAP, rejecting...")); | |
| 1336 orc = CONFREJ; | |
| 1337 break; | |
| 1338 } | |
| 1339 if (!ao->neg_chap) { /* we don't want to do CHAP */ | |
| 1340 orc = CONFNAK; /* NAK it and suggest PAP */ | |
| 1341 PUTCHAR(CI_AUTHTYPE, nakp); | |
| 1342 PUTCHAR(CILEN_SHORT, nakp); | |
| 1343 PUTSHORT(PPP_PAP, nakp); | |
| 1344 break; | |
| 1345 } | |
| 1346 GETCHAR(cichar, p); /* get digest type*/ | |
| 1347 if (cichar != CHAP_DIGEST_MD5 | |
| 1348 #ifdef CHAPMS | |
| 1349 && cichar != CHAP_MICROSOFT | |
| 1350 #endif | |
| 1351 ) { | |
| 1352 orc = CONFNAK; | |
| 1353 PUTCHAR(CI_AUTHTYPE, nakp); | |
| 1354 PUTCHAR(CILEN_CHAP, nakp); | |
| 1355 PUTSHORT(PPP_CHAP, nakp); | |
| 1356 PUTCHAR(ao->chap_mdtype, nakp); | |
| 1357 break; | |
| 1358 } | |
| 1359 ho->chap_mdtype = cichar; /* save md type */ | |
| 1360 ho->neg_chap = 1; | |
| 1361 break; | |
| 1362 } | |
| 1363 | |
| 1364 /* | |
| 1365 * We don't recognize the protocol they're asking for. | |
| 1366 * Nak it with something we're willing to do. | |
| 1367 * (At this point we know ao->neg_upap || ao->neg_chap.) | |
| 1368 */ | |
| 1369 orc = CONFNAK; | |
| 1370 PUTCHAR(CI_AUTHTYPE, nakp); | |
| 1371 if (ao->neg_chap) { | |
| 1372 PUTCHAR(CILEN_CHAP, nakp); | |
| 1373 PUTSHORT(PPP_CHAP, nakp); | |
| 1374 PUTCHAR(ao->chap_mdtype, nakp); | |
| 1375 } else { | |
| 1376 PUTCHAR(CILEN_SHORT, nakp); | |
| 1377 PUTSHORT(PPP_PAP, nakp); | |
| 1378 } | |
| 1379 break; | |
| 1380 | |
| 1381 case CI_QUALITY: | |
| 1382 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd QUALITY")); | |
| 1383 if (!ao->neg_lqr || | |
| 1384 cilen != CILEN_LQR) { | |
| 1385 orc = CONFREJ; | |
| 1386 break; | |
| 1387 } | |
| 1388 | |
| 1389 GETSHORT(cishort, p); | |
| 1390 GETLONG(cilong, p); | |
| 1391 LCPDEBUG((LOG_INFO, "(%x %x)", cishort, (unsigned int) cilong)); | |
| 1392 | |
| 1393 /* | |
| 1394 * Check the protocol and the reporting period. | |
| 1395 * XXX When should we Nak this, and what with? | |
| 1396 */ | |
| 1397 if (cishort != PPP_LQR) { | |
| 1398 orc = CONFNAK; | |
| 1399 PUTCHAR(CI_QUALITY, nakp); | |
| 1400 PUTCHAR(CILEN_LQR, nakp); | |
| 1401 PUTSHORT(PPP_LQR, nakp); | |
| 1402 PUTLONG(ao->lqr_period, nakp); | |
| 1403 break; | |
| 1404 } | |
| 1405 break; | |
| 1406 | |
| 1407 case CI_MAGICNUMBER: | |
| 1408 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd MAGICNUMBER")); | |
| 1409 if (!(ao->neg_magicnumber || go->neg_magicnumber) || | |
| 1410 cilen != CILEN_LONG) { | |
| 1411 orc = CONFREJ; | |
| 1412 break; | |
| 1413 } | |
| 1414 GETLONG(cilong, p); | |
| 1415 LCPDEBUG((LOG_INFO, "(%x)", (unsigned int) cilong)); | |
| 1416 | |
| 1417 /* | |
| 1418 * He must have a different magic number. | |
| 1419 */ | |
| 1420 if (go->neg_magicnumber && | |
| 1421 cilong == go->magicnumber) { | |
| 1422 cilong = magic(); /* Don't put magic() inside macro! */ | |
| 1423 orc = CONFNAK; | |
| 1424 PUTCHAR(CI_MAGICNUMBER, nakp); | |
| 1425 PUTCHAR(CILEN_LONG, nakp); | |
| 1426 PUTLONG(cilong, nakp); | |
| 1427 break; | |
| 1428 } | |
| 1429 ho->neg_magicnumber = 1; | |
| 1430 ho->magicnumber = cilong; | |
| 1431 break; | |
| 1432 | |
| 1433 | |
| 1434 case CI_PCOMPRESSION: | |
| 1435 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd PCOMPRESSION")); | |
| 1436 if (!ao->neg_pcompression || | |
| 1437 cilen != CILEN_VOID) { | |
| 1438 orc = CONFREJ; | |
| 1439 break; | |
| 1440 } | |
| 1441 ho->neg_pcompression = 1; | |
| 1442 break; | |
| 1443 | |
| 1444 case CI_ACCOMPRESSION: | |
| 1445 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd ACCOMPRESSION")); | |
| 1446 if (!ao->neg_accompression || | |
| 1447 cilen != CILEN_VOID) { | |
| 1448 orc = CONFREJ; | |
| 1449 break; | |
| 1450 } | |
| 1451 ho->neg_accompression = 1; | |
| 1452 break; | |
| 1453 | |
| 1454 default: | |
| 1455 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd unknown option %d", | |
| 1456 citype)); | |
| 1457 orc = CONFREJ; | |
| 1458 break; | |
| 1459 } | |
| 1460 | |
| 1461 endswitch: | |
| 1462 LCPDEBUG((LOG_INFO, " (%s)", CODENAME(orc))); | |
| 1463 if (orc == CONFACK && /* Good CI */ | |
| 1464 rc != CONFACK) /* but prior CI wasnt? */ | |
| 1465 continue; /* Don't send this one */ | |
| 1466 | |
| 1467 if (orc == CONFNAK) { /* Nak this CI? */ | |
| 1468 if (reject_if_disagree /* Getting fed up with sending NAKs? */ | |
| 1469 && citype != CI_MAGICNUMBER) { | |
| 1470 orc = CONFREJ; /* Get tough if so */ | |
| 1471 } else { | |
| 1472 if (rc == CONFREJ) /* Rejecting prior CI? */ | |
| 1473 continue; /* Don't send this one */ | |
| 1474 rc = CONFNAK; | |
| 1475 } | |
| 1476 } | |
| 1477 if (orc == CONFREJ) { /* Reject this CI */ | |
| 1478 rc = CONFREJ; | |
| 1479 if (cip != rejp) /* Need to move rejected CI? */ | |
| 1480 BCOPY(cip, rejp, cilen); /* Move it */ | |
| 1481 INCPTR(cilen, rejp); /* Update output pointer */ | |
| 1482 } | |
| 1483 } | |
| 1484 | |
| 1485 /* | |
| 1486 * If we wanted to send additional NAKs (for unsent CIs), the | |
| 1487 * code would go here. The extra NAKs would go at *nakp. | |
| 1488 * At present there are no cases where we want to ask the | |
| 1489 * peer to negotiate an option. | |
| 1490 */ | |
| 1491 | |
| 1492 switch (rc) { | |
| 1493 case CONFACK: | |
| 1494 *lenp = next - inp; | |
| 1495 break; | |
| 1496 case CONFNAK: | |
| 1497 /* | |
| 1498 * Copy the Nak'd options from the nak_buffer to the caller's buffer. | |
| 1499 */ | |
| 1500 *lenp = nakp - nak_buffer; | |
| 1501 BCOPY(nak_buffer, inp, *lenp); | |
| 1502 break; | |
| 1503 case CONFREJ: | |
| 1504 *lenp = rejp - inp; | |
| 1505 break; | |
| 1506 } | |
| 1507 | |
| 1508 LCPDEBUG((LOG_INFO, "lcp_reqci: returning CONF%s.", CODENAME(rc))); | |
| 1509 return (rc); /* Return final code */ | |
| 1510 } | |
| 1511 | |
| 1512 | |
| 1513 /* | |
| 1514 * lcp_up - LCP has come UP. | |
| 1515 */ | |
| 1516 static void | |
| 1517 lcp_up(f) | |
| 1518 fsm *f; | |
| 1519 { | |
| 1520 lcp_options *wo = &lcp_wantoptions[f->unit]; | |
| 1521 lcp_options *ho = &lcp_hisoptions[f->unit]; | |
| 1522 lcp_options *go = &lcp_gotoptions[f->unit]; | |
| 1523 lcp_options *ao = &lcp_allowoptions[f->unit]; | |
| 1524 | |
| 1525 if (!go->neg_magicnumber) | |
| 1526 go->magicnumber = 0; | |
| 1527 if (!ho->neg_magicnumber) | |
| 1528 ho->magicnumber = 0; | |
| 1529 | |
| 1530 /* | |
| 1531 * Set our MTU to the smaller of the MTU we wanted and | |
| 1532 * the MRU our peer wanted. If we negotiated an MRU, | |
| 1533 * set our MRU to the larger of value we wanted and | |
| 1534 * the value we got in the negotiation. | |
| 1535 */ | |
| 1536 ppp_send_config(f->unit, MIN(ao->mru, (ho->neg_mru? ho->mru: PPP_MRU)), | |
| 1537 (ho->neg_asyncmap? ho->asyncmap: 0xffffffff), | |
| 1538 ho->neg_pcompression, ho->neg_accompression); | |
| 1539 ppp_recv_config(f->unit, (go->neg_mru? MAX(wo->mru, go->mru): PPP_MRU), | |
| 1540 (go->neg_asyncmap? go->asyncmap: 0xffffffff), | |
| 1541 go->neg_pcompression, go->neg_accompression); | |
| 1542 | |
| 1543 if (ho->neg_mru) | |
| 1544 peer_mru[f->unit] = ho->mru; | |
| 1545 | |
| 1546 lcp_echo_lowerup(f->unit); /* Enable echo messages */ | |
| 1547 | |
| 1548 link_established(f->unit); | |
| 1549 } | |
| 1550 | |
| 1551 | |
| 1552 /* | |
| 1553 * lcp_down - LCP has gone DOWN. | |
| 1554 * | |
| 1555 * Alert other protocols. | |
| 1556 */ | |
| 1557 static void | |
| 1558 lcp_down(f) | |
| 1559 fsm *f; | |
| 1560 { | |
| 1561 db_printf("%s()\n",__PRETTY_FUNCTION__); | |
| 1562 lcp_options *go = &lcp_gotoptions[f->unit]; | |
| 1563 | |
| 1564 lcp_echo_lowerdown(f->unit); | |
| 1565 | |
| 1566 link_down(f->unit); | |
| 1567 | |
| 1568 ppp_send_config(f->unit, PPP_MRU, 0xffffffff, 0, 0); | |
| 1569 ppp_recv_config(f->unit, PPP_MRU, | |
| 1570 (go->neg_asyncmap? go->asyncmap: 0xffffffff), | |
| 1571 go->neg_pcompression, go->neg_accompression); | |
| 1572 peer_mru[f->unit] = PPP_MRU; | |
| 1573 } | |
| 1574 | |
| 1575 | |
| 1576 /* | |
| 1577 * lcp_starting - LCP needs the lower layer up. | |
| 1578 */ | |
| 1579 static void | |
| 1580 lcp_starting(f) | |
| 1581 fsm *f; | |
| 1582 { | |
| 1583 link_required(f->unit); | |
| 1584 } | |
| 1585 | |
| 1586 | |
| 1587 /* | |
| 1588 * lcp_finished - LCP has finished with the lower layer. | |
| 1589 */ | |
| 1590 static void | |
| 1591 lcp_finished(f) | |
| 1592 fsm *f; | |
| 1593 { | |
| 1594 db_printf("%s()\n",__PRETTY_FUNCTION__); | |
| 1595 link_terminated(f->unit); | |
| 1596 } | |
| 1597 | |
| 1598 | |
| 1599 /* | |
| 1600 * lcp_printpkt - print the contents of an LCP packet. | |
| 1601 */ | |
| 1602 static char *lcp_codenames[] = { | |
| 1603 "ConfReq", "ConfAck", "ConfNak", "ConfRej", | |
| 1604 "TermReq", "TermAck", "CodeRej", "ProtRej", | |
| 1605 "EchoReq", "EchoRep", "DiscReq" | |
| 1606 }; | |
| 1607 | |
| 1608 static int | |
| 1609 lcp_printpkt(p, plen, printer, arg) | |
| 1610 u_char *p; | |
| 1611 int plen; | |
| 1612 void (*printer) __P((void *, char *, ...)); | |
| 1613 void *arg; | |
| 1614 { | |
| 1615 int code, id, len, olen; | |
| 1616 u_char *pstart, *optend; | |
| 1617 u_short cishort; | |
| 1618 u_int32_t cilong; | |
| 1619 | |
| 1620 if (plen < HEADERLEN) | |
| 1621 return 0; | |
| 1622 pstart = p; | |
| 1623 GETCHAR(code, p); | |
| 1624 GETCHAR(id, p); | |
| 1625 GETSHORT(len, p); | |
| 1626 if (len < HEADERLEN || len > plen) | |
| 1627 return 0; | |
| 1628 | |
| 1629 if (code >= 1 && code <= sizeof(lcp_codenames) / sizeof(char *)) | |
| 1630 printer(arg, " %s", lcp_codenames[code-1]); | |
| 1631 else | |
| 1632 printer(arg, " code=0x%x", code); | |
| 1633 printer(arg, " id=0x%x", id); | |
| 1634 len -= HEADERLEN; | |
| 1635 switch (code) { | |
| 1636 case CONFREQ: | |
| 1637 case CONFACK: | |
| 1638 case CONFNAK: | |
| 1639 case CONFREJ: | |
| 1640 /* print option list */ | |
| 1641 while (len >= 2) { | |
| 1642 GETCHAR(code, p); | |
| 1643 GETCHAR(olen, p); | |
| 1644 p -= 2; | |
| 1645 if (olen < 2 || olen > len) { | |
| 1646 break; | |
| 1647 } | |
| 1648 printer(arg, " <"); | |
| 1649 len -= olen; | |
| 1650 optend = p + olen; | |
| 1651 switch (code) { | |
| 1652 case CI_MRU: | |
| 1653 if (olen == CILEN_SHORT) { | |
| 1654 p += 2; | |
| 1655 GETSHORT(cishort, p); | |
| 1656 printer(arg, "mru %d", cishort); | |
| 1657 } | |
| 1658 break; | |
| 1659 case CI_ASYNCMAP: | |
| 1660 if (olen == CILEN_LONG) { | |
| 1661 p += 2; | |
| 1662 GETLONG(cilong, p); | |
| 1663 printer(arg, "asyncmap 0x%x", cilong); | |
| 1664 } | |
| 1665 break; | |
| 1666 case CI_AUTHTYPE: | |
| 1667 if (olen >= CILEN_SHORT) { | |
| 1668 p += 2; | |
| 1669 printer(arg, "auth "); | |
| 1670 GETSHORT(cishort, p); | |
| 1671 switch (cishort) { | |
| 1672 case PPP_PAP: | |
| 1673 printer(arg, "pap"); | |
| 1674 break; | |
| 1675 case PPP_CHAP: | |
| 1676 printer(arg, "chap"); | |
| 1677 break; | |
| 1678 default: | |
| 1679 printer(arg, "0x%x", cishort); | |
| 1680 } | |
| 1681 } | |
| 1682 break; | |
| 1683 case CI_QUALITY: | |
| 1684 if (olen >= CILEN_SHORT) { | |
| 1685 p += 2; | |
| 1686 printer(arg, "quality "); | |
| 1687 GETSHORT(cishort, p); | |
| 1688 switch (cishort) { | |
| 1689 case PPP_LQR: | |
| 1690 printer(arg, "lqr"); | |
| 1691 break; | |
| 1692 default: | |
| 1693 printer(arg, "0x%x", cishort); | |
| 1694 } | |
| 1695 } | |
| 1696 break; | |
| 1697 case CI_CALLBACK: | |
| 1698 if (olen >= CILEN_CHAR) { | |
| 1699 p += 2; | |
| 1700 printer(arg, "callback "); | |
| 1701 GETSHORT(cishort, p); | |
| 1702 switch (cishort) { | |
| 1703 case CBCP_OPT: | |
| 1704 printer(arg, "CBCP"); | |
| 1705 break; | |
| 1706 default: | |
| 1707 printer(arg, "0x%x", cishort); | |
| 1708 } | |
| 1709 } | |
| 1710 break; | |
| 1711 case CI_MAGICNUMBER: | |
| 1712 if (olen == CILEN_LONG) { | |
| 1713 p += 2; | |
| 1714 GETLONG(cilong, p); | |
| 1715 printer(arg, "magic 0x%x", cilong); | |
| 1716 } | |
| 1717 break; | |
| 1718 case CI_PCOMPRESSION: | |
| 1719 if (olen == CILEN_VOID) { | |
| 1720 p += 2; | |
| 1721 printer(arg, "pcomp"); | |
| 1722 } | |
| 1723 break; | |
| 1724 case CI_ACCOMPRESSION: | |
| 1725 if (olen == CILEN_VOID) { | |
| 1726 p += 2; | |
| 1727 printer(arg, "accomp"); | |
| 1728 } | |
| 1729 break; | |
| 1730 } | |
| 1731 while (p < optend) { | |
| 1732 GETCHAR(code, p); | |
| 1733 printer(arg, " %.2x", code); | |
| 1734 } | |
| 1735 printer(arg, ">"); | |
| 1736 } | |
| 1737 break; | |
| 1738 | |
| 1739 case TERMACK: | |
| 1740 case TERMREQ: | |
| 1741 if (len > 0 && *p >= ' ' && *p < 0x7f) { | |
| 1742 printer(arg, " "); | |
| 1743 print_string(p, len, printer, arg); | |
| 1744 p += len; | |
| 1745 len = 0; | |
| 1746 } | |
| 1747 break; | |
| 1748 | |
| 1749 case ECHOREQ: | |
| 1750 case ECHOREP: | |
| 1751 case DISCREQ: | |
| 1752 if (len >= 4) { | |
| 1753 GETLONG(cilong, p); | |
| 1754 printer(arg, " magic=0x%x", cilong); | |
| 1755 p += 4; | |
| 1756 len -= 4; | |
| 1757 } | |
| 1758 break; | |
| 1759 } | |
| 1760 | |
| 1761 /* print the rest of the bytes in the packet */ | |
| 1762 for (; len > 0; --len) { | |
| 1763 GETCHAR(code, p); | |
| 1764 printer(arg, " %.2x", code); | |
| 1765 } | |
| 1766 | |
| 1767 return p - pstart; | |
| 1768 } | |
| 1769 | |
| 1770 /* | |
| 1771 * Time to shut down the link because there is nothing out there. | |
| 1772 */ | |
| 1773 | |
| 1774 static | |
| 1775 void LcpLinkFailure (f) | |
| 1776 fsm *f; | |
| 1777 { | |
| 1778 if (f->state == OPENED) { | |
| 1779 syslog(LOG_INFO, "No response to %d echo-requests", lcp_echos_pending); | |
| 1780 syslog(LOG_NOTICE, "Serial link appears to be disconnected."); | |
| 1781 lcp_close(f->unit, "Peer not responding"); | |
|
1694
5629b7c30ed2
Various patches from Matt Jerdonek and Oyvind Harboe:
nickg
parents:
1586
diff
changeset
|
1782 cyg_ppp_stats.no_response++; |
| 1586 | 1783 } |
| 1784 } | |
| 1785 | |
| 1786 /* | |
| 1787 * Timer expired for the LCP echo requests from this process. | |
| 1788 */ | |
| 1789 | |
| 1790 static void | |
| 1791 LcpEchoCheck (f) | |
| 1792 fsm *f; | |
| 1793 { | |
| 1794 LcpSendEchoRequest (f); | |
| 1795 | |
| 1796 /* | |
| 1797 * Start the timer for the next interval. | |
| 1798 */ | |
| 1799 assert (lcp_echo_timer_running==0); | |
| 1800 TIMEOUT (LcpEchoTimeout, f, lcp_echo_interval); | |
| 1801 lcp_echo_timer_running = 1; | |
| 1802 } | |
| 1803 | |
| 1804 /* | |
| 1805 * LcpEchoTimeout - Timer expired on the LCP echo | |
| 1806 */ | |
| 1807 | |
| 1808 static void | |
| 1809 LcpEchoTimeout (arg) | |
| 1810 void *arg; | |
| 1811 { | |
| 1812 if (lcp_echo_timer_running != 0) { | |
| 1813 lcp_echo_timer_running = 0; | |
| 1814 LcpEchoCheck ((fsm *) arg); | |
| 1815 } | |
| 1816 } | |
| 1817 | |
| 1818 /* | |
| 1819 * LcpEchoReply - LCP has received a reply to the echo | |
| 1820 */ | |
| 1821 | |
| 1822 static void | |
| 1823 lcp_received_echo_reply (f, id, inp, len) | |
| 1824 fsm *f; | |
| 1825 int id; u_char *inp; int len; | |
| 1826 { | |
| 1827 u_int32_t magic; | |
| 1828 | |
| 1829 /* Check the magic number - don't count replies from ourselves. */ | |
| 1830 if (len < 4) { | |
| 1831 syslog(LOG_DEBUG, "lcp: received short Echo-Reply, length %d", len); | |
| 1832 return; | |
| 1833 } | |
| 1834 GETLONG(magic, inp); | |
| 1835 if (lcp_gotoptions[f->unit].neg_magicnumber | |
| 1836 && magic == lcp_gotoptions[f->unit].magicnumber) { | |
| 1837 syslog(LOG_WARNING, "appear to have received our own echo-reply!"); | |
| 1838 return; | |
| 1839 } | |
| 1840 | |
| 1841 /* Reset the number of outstanding echo frames */ | |
| 1842 lcp_echos_pending = 0; | |
| 1843 } | |
| 1844 | |
| 1845 /* | |
| 1846 * LcpSendEchoRequest - Send an echo request frame to the peer | |
| 1847 */ | |
| 1848 | |
| 1849 static void | |
| 1850 LcpSendEchoRequest (f) | |
| 1851 fsm *f; | |
| 1852 { | |
| 1853 u_int32_t lcp_magic; | |
| 1854 u_char pkt[4], *pktp; | |
| 1855 | |
| 1856 /* | |
| 1857 * Detect the failure of the peer at this point. | |
| 1858 */ | |
| 1859 if (lcp_echo_fails != 0) { | |
| 1860 if (lcp_echos_pending >= lcp_echo_fails) { | |
| 1861 LcpLinkFailure(f); | |
| 1862 lcp_echos_pending = 0; | |
| 1863 } | |
| 1864 } | |
| 1865 | |
| 1866 /* | |
| 1867 * Make and send the echo request frame. | |
| 1868 */ | |
| 1869 if (f->state == OPENED) { | |
| 1870 lcp_magic = lcp_gotoptions[f->unit].magicnumber; | |
| 1871 pktp = pkt; | |
| 1872 PUTLONG(lcp_magic, pktp); | |
| 1873 fsm_sdata(f, ECHOREQ, lcp_echo_number++ & 0xFF, pkt, pktp - pkt); | |
| 1874 ++lcp_echos_pending; | |
| 1875 } | |
| 1876 } | |
| 1877 | |
| 1878 /* | |
| 1879 * lcp_echo_lowerup - Start the timer for the LCP frame | |
| 1880 */ | |
| 1881 | |
| 1882 static void | |
| 1883 lcp_echo_lowerup (unit) | |
| 1884 int unit; | |
| 1885 { | |
| 1886 fsm *f = &lcp_fsm[unit]; | |
| 1887 | |
| 1888 /* Clear the parameters for generating echo frames */ | |
| 1889 lcp_echos_pending = 0; | |
| 1890 lcp_echo_number = 0; | |
| 1891 lcp_echo_timer_running = 0; | |
| 1892 | |
| 1893 /* If a timeout interval is specified then start the timer */ | |
| 1894 if (lcp_echo_interval != 0) | |
| 1895 LcpEchoCheck (f); | |
| 1896 } | |
| 1897 | |
| 1898 /* | |
| 1899 * lcp_echo_lowerdown - Stop the timer for the LCP frame | |
| 1900 */ | |
| 1901 | |
| 1902 static void | |
| 1903 lcp_echo_lowerdown (unit) | |
| 1904 int unit; | |
| 1905 { | |
| 1906 fsm *f = &lcp_fsm[unit]; | |
| 1907 | |
| 1908 if (lcp_echo_timer_running != 0) { | |
| 1909 UNTIMEOUT (LcpEchoTimeout, f); | |
| 1910 lcp_echo_timer_running = 0; | |
| 1911 } | |
| 1912 } |
