lcp.c (31343) | lcp.c (31514) |
---|---|
1/* 2 * PPP Link Control Protocol (LCP) Module 3 * 4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp) 5 * 6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd. 7 * 8 * Redistribution and use in source and binary forms are permitted 9 * provided that the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by the Internet Initiative Japan, Inc. The name of the 14 * IIJ may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 * | 1/* 2 * PPP Link Control Protocol (LCP) Module 3 * 4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp) 5 * 6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd. 7 * 8 * Redistribution and use in source and binary forms are permitted 9 * provided that the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by the Internet Initiative Japan, Inc. The name of the 14 * IIJ may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 * |
20 * $Id: lcp.c,v 1.47 1997/11/18 14:52:05 brian Exp $ | 20 * $Id: lcp.c,v 1.48 1997/11/22 03:37:35 brian Exp $ |
21 * 22 * TODO: 23 * o Validate magic number received from peer. 24 * o Limit data field length by MRU 25 */ 26#include <sys/param.h> 27#include <sys/time.h> 28#include <sys/select.h> 29#include <sys/socket.h> 30#include <netinet/in.h> 31#include <arpa/inet.h> 32#include <net/if.h> 33#ifdef __FreeBSD__ 34#include <net/if_var.h> 35#endif 36#include <net/if_tun.h> 37 38#include <signal.h> | 21 * 22 * TODO: 23 * o Validate magic number received from peer. 24 * o Limit data field length by MRU 25 */ 26#include <sys/param.h> 27#include <sys/time.h> 28#include <sys/select.h> 29#include <sys/socket.h> 30#include <netinet/in.h> 31#include <arpa/inet.h> 32#include <net/if.h> 33#ifdef __FreeBSD__ 34#include <net/if_var.h> 35#endif 36#include <net/if_tun.h> 37 38#include <signal.h> |
39#include <stdarg.h> |
|
39#include <stdio.h> 40#include <stdlib.h> 41#include <string.h> 42#include <sys/time.h> 43#include <termios.h> 44#include <unistd.h> 45 46#include "command.h" --- 16 unchanged lines hidden (view full) --- 63#include "pap.h" 64#include "chap.h" 65#include "async.h" 66#include "main.h" 67#include "ip.h" 68#include "modem.h" 69#include "tun.h" 70 | 40#include <stdio.h> 41#include <stdlib.h> 42#include <string.h> 43#include <sys/time.h> 44#include <termios.h> 45#include <unistd.h> 46 47#include "command.h" --- 16 unchanged lines hidden (view full) --- 64#include "pap.h" 65#include "chap.h" 66#include "async.h" 67#include "main.h" 68#include "ip.h" 69#include "modem.h" 70#include "tun.h" 71 |
72/* for received LQRs */ 73struct lqrreq { 74 u_char type; 75 u_char length; 76 u_short proto; /* Quality protocol */ 77 u_long period; /* Reporting interval */ 78}; 79 |
|
71struct lcpstate LcpInfo; 72 73static void LcpSendConfigReq(struct fsm *); 74static void LcpSendTerminateReq(struct fsm *); 75static void LcpSendTerminateAck(struct fsm *); 76static void LcpDecodeConfig(u_char *, int, int); 77static void LcpInitRestartCounter(struct fsm *); 78static void LcpLayerUp(struct fsm *); 79static void LcpLayerDown(struct fsm *); 80static void LcpLayerStart(struct fsm *); 81static void LcpLayerFinish(struct fsm *); 82 | 80struct lcpstate LcpInfo; 81 82static void LcpSendConfigReq(struct fsm *); 83static void LcpSendTerminateReq(struct fsm *); 84static void LcpSendTerminateAck(struct fsm *); 85static void LcpDecodeConfig(u_char *, int, int); 86static void LcpInitRestartCounter(struct fsm *); 87static void LcpLayerUp(struct fsm *); 88static void LcpLayerDown(struct fsm *); 89static void LcpLayerStart(struct fsm *); 90static void LcpLayerFinish(struct fsm *); 91 |
83#define REJECTED(p, x) (p->his_reject & (1<<x)) 84 | |
85static const char *cftypes[] = { 86 /* Check out the latest ``Assigned numbers'' rfc (rfc1700.txt) */ 87 "???", 88 "MRU", /* 1: Maximum-Receive-Unit */ 89 "ACCMAP", /* 2: Async-Control-Character-Map */ 90 "AUTHPROTO", /* 3: Authentication-Protocol */ 91 "QUALPROTO", /* 4: Quality-Protocol */ 92 "MAGICNUM", /* 5: Magic-Number */ --- 125 unchanged lines hidden (view full) --- 218 219static void 220LcpInitRestartCounter(struct fsm * fp) 221{ 222 fp->FsmTimer.load = VarRetryTimeout * SECTICKS; 223 fp->restart = 5; 224} 225 | 92static const char *cftypes[] = { 93 /* Check out the latest ``Assigned numbers'' rfc (rfc1700.txt) */ 94 "???", 95 "MRU", /* 1: Maximum-Receive-Unit */ 96 "ACCMAP", /* 2: Async-Control-Character-Map */ 97 "AUTHPROTO", /* 3: Authentication-Protocol */ 98 "QUALPROTO", /* 4: Quality-Protocol */ 99 "MAGICNUM", /* 5: Magic-Number */ --- 125 unchanged lines hidden (view full) --- 225 226static void 227LcpInitRestartCounter(struct fsm * fp) 228{ 229 fp->FsmTimer.load = VarRetryTimeout * SECTICKS; 230 fp->restart = 5; 231} 232 |
226void 227PutConfValue(int level, u_char ** cpp, const char **types, u_char type, 228 int len, u_long val) | 233int 234LcpPutConf(int log, u_char *tgt, const struct lcp_opt *o, const char *nm, 235 const char *arg, ...) |
229{ | 236{ |
230 u_char *cp; 231 struct in_addr ina; | 237 va_list ap; 238 char buf[30]; |
232 | 239 |
233 cp = *cpp; 234 *cp++ = type; 235 *cp++ = len; 236 if (len == 6) { 237 if (type == TY_IPADDR) { 238 ina.s_addr = htonl(val); 239 LogPrintf(level, " %s [%d] %s\n", 240 types[type], len, inet_ntoa(ina)); 241 } else 242 LogPrintf(level, " %s [%d] %08x\n", types[type], len, val); 243 *cp++ = (val >> 24) & 0377; 244 *cp++ = (val >> 16) & 0377; 245 } else 246 LogPrintf(level, " %s [%d] %d\n", types[type], len, val); 247 *cp++ = (val >> 8) & 0377; 248 *cp++ = val & 0377; 249 *cpp = cp; | 240 va_start(ap, arg); 241 memcpy(tgt, o, o->len); 242 if (arg == NULL || *arg == '\0') 243 LogPrintf(log, " %s[%d]\n", nm, o->len); 244 else { 245 vsnprintf(buf, sizeof buf, arg, ap); 246 LogPrintf(log, " %s[%d] %s\n", nm, o->len, buf); 247 } 248 va_end(ap); 249 250 return o->len; |
250} 251 | 251} 252 |
253#define PUTN(ty) \ 254do { \ 255 o.id = ty; \ 256 o.len = 2; \ 257 cp += LcpPutConf(LogLCP, cp, &o, cftypes[o.id], NULL); \ 258} while (0) 259 260#define PUTHEXL(ty, arg) \ 261do { \ 262 o.id = ty; \ 263 o.len = 6; \ 264 *(u_long *)o.data = htonl(arg); \ 265 cp += LcpPutConf(LogLCP, cp, &o, cftypes[o.id], "0x%08x", (u_int)arg);\ 266} while (0) 267 268#define PUTACCMAP(arg) PUTHEXL(TY_ACCMAP, arg) 269#define PUTMAGIC(arg) PUTHEXL(TY_MAGICNUM, arg) 270 271#define PUTMRU(arg) \ 272do { \ 273 o.id = TY_MRU; \ 274 o.len = 4; \ 275 *(u_short *)o.data = htons(arg); \ 276 cp += LcpPutConf(LogLCP, cp, &o, cftypes[o.id], "%lu", arg); \ 277} while (0) 278 279#define PUTLQR(period) \ 280do { \ 281 o.id = TY_QUALPROTO; \ 282 o.len = 8; \ 283 *(u_short *)o.data = htons(PROTO_LQR); \ 284 *(u_long *)(o.data+2) = period; \ 285 cp += LcpPutConf(LogLCP, cp, &o, cftypes[o.id], "period %ld", period);\ 286} while (0) 287 288#define PUTPAP() \ 289do { \ 290 o.id = TY_AUTHPROTO; \ 291 o.len = 4; \ 292 *(u_short *)o.data = PROTO_PAP; \ 293 cp += LcpPutConf(LogLCP, cp, &o, cftypes[o.id], "PAP REQ"); \ 294} while (0) 295 296#define PUTCHAP(val) \ 297do { \ 298 o.id = TY_AUTHPROTO; \ 299 o.len = 5; \ 300 *(u_short *)o.data = PROTO_CHAP; \ 301 o.data[4] = val; \ 302 cp += LcpPutConf(LogLCP, cp, &o, cftypes[o.id], "CHAP REQ (0x%02x)", val);\ 303} while (0) 304 305#define PUTMD5CHAP() PUTCHAP(0x05) 306#define PUTMSCHAP() PUTCHAP(0x80) 307 |
|
252static void 253LcpSendConfigReq(struct fsm * fp) 254{ 255 u_char *cp; 256 struct lcpstate *lcp = &LcpInfo; | 308static void 309LcpSendConfigReq(struct fsm * fp) 310{ 311 u_char *cp; 312 struct lcpstate *lcp = &LcpInfo; |
257 struct lqrreq *req; | 313 struct lcp_opt o; |
258 259 LogPrintf(LogLCP, "LcpSendConfigReq\n"); 260 cp = ReqBuff; 261 if (!DEV_IS_SYNC) { | 314 315 LogPrintf(LogLCP, "LcpSendConfigReq\n"); 316 cp = ReqBuff; 317 if (!DEV_IS_SYNC) { |
262 if (lcp->want_acfcomp && !REJECTED(lcp, TY_ACFCOMP)) { 263 *cp++ = TY_ACFCOMP; 264 *cp++ = 2; 265 LogPrintf(LogLCP, " %s\n", cftypes[TY_ACFCOMP]); 266 } 267 if (lcp->want_protocomp && !REJECTED(lcp, TY_PROTOCOMP)) { 268 *cp++ = TY_PROTOCOMP; 269 *cp++ = 2; 270 LogPrintf(LogLCP, " %s\n", cftypes[TY_PROTOCOMP]); 271 } | 318 if (lcp->want_acfcomp && !REJECTED(lcp, TY_ACFCOMP)) 319 PUTN(TY_ACFCOMP); 320 321 if (lcp->want_protocomp && !REJECTED(lcp, TY_PROTOCOMP)) 322 PUTN(TY_PROTOCOMP); 323 |
272 if (!REJECTED(lcp, TY_ACCMAP)) | 324 if (!REJECTED(lcp, TY_ACCMAP)) |
273 PutConfValue(LogLCP, &cp, cftypes, TY_ACCMAP, 6, lcp->want_accmap); | 325 PUTACCMAP(lcp->want_accmap); |
274 } | 326 } |
327 |
|
275 if (!REJECTED(lcp, TY_MRU)) | 328 if (!REJECTED(lcp, TY_MRU)) |
276 PutConfValue(LogLCP, &cp, cftypes, TY_MRU, 4, lcp->want_mru); | 329 PUTMRU(lcp->want_mru); 330 |
277 if (lcp->want_magic && !REJECTED(lcp, TY_MAGICNUM)) | 331 if (lcp->want_magic && !REJECTED(lcp, TY_MAGICNUM)) |
278 PutConfValue(LogLCP, &cp, cftypes, TY_MAGICNUM, 6, lcp->want_magic); 279 if (lcp->want_lqrperiod && !REJECTED(lcp, TY_QUALPROTO)) { 280 req = (struct lqrreq *) cp; 281 req->type = TY_QUALPROTO; 282 req->length = sizeof(struct lqrreq); 283 req->proto = htons(PROTO_LQR); 284 req->period = htonl(lcp->want_lqrperiod); 285 cp += sizeof(struct lqrreq); 286 LogPrintf(LogLCP, " %s (%d)\n", cftypes[TY_QUALPROTO], lcp->want_lqrperiod); 287 } | 332 PUTMAGIC(lcp->want_magic); 333 334 if (lcp->want_lqrperiod && !REJECTED(lcp, TY_QUALPROTO)) 335 PUTLQR(lcp->want_lqrperiod); 336 |
288 switch (lcp->want_auth) { 289 case PROTO_PAP: | 337 switch (lcp->want_auth) { 338 case PROTO_PAP: |
290 PutConfValue(LogLCP, &cp, cftypes, TY_AUTHPROTO, 4, lcp->want_auth); | 339 PUTPAP(); |
291 break; | 340 break; |
341 |
|
292 case PROTO_CHAP: | 342 case PROTO_CHAP: |
293 PutConfValue(LogLCP, &cp, cftypes, TY_AUTHPROTO, 5, lcp->want_auth); | |
294#ifdef HAVE_DES | 343#ifdef HAVE_DES |
295 *cp++ = VarMSChap ? 0x80 : 0x05; /* Use MSChap vs. RFC 1994 (MD5) */ | 344 if (VarMSChap) 345 PUTMSCHAP(); /* Use MSChap */ 346 else |
296#else | 347#else |
297 *cp++ = 0x05; /* Use MD5 */ | 348 PUTMD5CHAP(); /* Use MD5 */ |
298#endif 299 break; 300 } 301 FsmOutput(fp, CODE_CONFIGREQ, fp->reqid++, ReqBuff, cp - ReqBuff); 302} 303 304void 305LcpSendProtoRej(u_char * option, int count) --- 109 unchanged lines hidden (view full) --- 415 FsmClose(&LcpFsm); 416 LcpFailedMagic = 0; 417} 418 419/* 420 * XXX: Should validate option length 421 */ 422static void | 349#endif 350 break; 351 } 352 FsmOutput(fp, CODE_CONFIGREQ, fp->reqid++, ReqBuff, cp - ReqBuff); 353} 354 355void 356LcpSendProtoRej(u_char * option, int count) --- 109 unchanged lines hidden (view full) --- 466 FsmClose(&LcpFsm); 467 LcpFailedMagic = 0; 468} 469 470/* 471 * XXX: Should validate option length 472 */ 473static void |
423LcpDecodeConfig(u_char * cp, int plen, int mode_type) | 474LcpDecodeConfig(u_char *cp, int plen, int mode_type) |
424{ | 475{ |
425 const char *request; 426 int type, length, mru, mtu; | 476 int type, length, mru, mtu, sz, pos; |
427 u_long *lp, magic, accmap; 428 u_short *sp, proto; 429 struct lqrreq *req; | 477 u_long *lp, magic, accmap; 478 u_short *sp, proto; 479 struct lqrreq *req; |
480 char request[20], desc[22]; |
|
430 431 ackp = AckBuff; 432 nakp = NakBuff; 433 rejp = RejBuff; 434 435 while (plen >= sizeof(struct fsmconfig)) { 436 type = *cp; 437 length = cp[1]; | 481 482 ackp = AckBuff; 483 nakp = NakBuff; 484 rejp = RejBuff; 485 486 while (plen >= sizeof(struct fsmconfig)) { 487 type = *cp; 488 length = cp[1]; |
438 if (type < NCFTYPES) 439 request = cftypes[type]; | 489 490 if (type < 0 || type >= NCFTYPES) 491 snprintf(request, sizeof request, " <%d>[%d]", type, length); |
440 else | 492 else |
441 request = "???"; | 493 snprintf(request, sizeof request, " %s[%d]", cftypes[type], length); |
442 443 switch (type) { 444 case TY_MRU: 445 sp = (u_short *) (cp + 2); 446 mru = htons(*sp); | 494 495 switch (type) { 496 case TY_MRU: 497 sp = (u_short *) (cp + 2); 498 mru = htons(*sp); |
447 LogPrintf(LogLCP, " %s %d\n", request, mru); | 499 LogPrintf(LogLCP, "%s %d\n", request, mru); |
448 449 switch (mode_type) { 450 case MODE_REQ: 451 mtu = VarPrefMTU; 452 if (mtu == 0) 453 mtu = MAX_MTU; 454 if (mru > mtu) { 455 *sp = htons(mtu); --- 13 unchanged lines hidden (view full) --- 469 if (mru >= MIN_MRU || mru <= MAX_MRU) 470 LcpInfo.want_mru = mru; 471 break; 472 case MODE_REJ: 473 LcpInfo.his_reject |= (1 << type); 474 break; 475 } 476 break; | 500 501 switch (mode_type) { 502 case MODE_REQ: 503 mtu = VarPrefMTU; 504 if (mtu == 0) 505 mtu = MAX_MTU; 506 if (mru > mtu) { 507 *sp = htons(mtu); --- 13 unchanged lines hidden (view full) --- 521 if (mru >= MIN_MRU || mru <= MAX_MRU) 522 LcpInfo.want_mru = mru; 523 break; 524 case MODE_REJ: 525 LcpInfo.his_reject |= (1 << type); 526 break; 527 } 528 break; |
529 |
|
477 case TY_ACCMAP: 478 lp = (u_long *) (cp + 2); 479 accmap = htonl(*lp); | 530 case TY_ACCMAP: 531 lp = (u_long *) (cp + 2); 532 accmap = htonl(*lp); |
480 LogPrintf(LogLCP, " %s %08x\n", request, accmap); | 533 LogPrintf(LogLCP, "%s 0x%08x\n", request, accmap); |
481 482 switch (mode_type) { 483 case MODE_REQ: 484 LcpInfo.his_accmap = accmap; 485 memcpy(ackp, cp, 6); 486 ackp += 6; 487 break; 488 case MODE_NAK: 489 LcpInfo.want_accmap = accmap; 490 break; 491 case MODE_REJ: 492 LcpInfo.his_reject |= (1 << type); 493 break; 494 } 495 break; | 534 535 switch (mode_type) { 536 case MODE_REQ: 537 LcpInfo.his_accmap = accmap; 538 memcpy(ackp, cp, 6); 539 ackp += 6; 540 break; 541 case MODE_NAK: 542 LcpInfo.want_accmap = accmap; 543 break; 544 case MODE_REJ: 545 LcpInfo.his_reject |= (1 << type); 546 break; 547 } 548 break; |
549 |
|
496 case TY_AUTHPROTO: 497 sp = (u_short *) (cp + 2); 498 proto = ntohs(*sp); | 550 case TY_AUTHPROTO: 551 sp = (u_short *) (cp + 2); 552 proto = ntohs(*sp); |
499 LogPrintf(LogLCP, " %s proto = %04x\n", request, proto); | 553 LogPrintf(LogLCP, "%s 0x%04x\n", request, proto); |
500 501 switch (mode_type) { 502 case MODE_REQ: 503 switch (proto) { 504 case PROTO_PAP: 505 if (length != 4) { | 554 555 switch (mode_type) { 556 case MODE_REQ: 557 switch (proto) { 558 case PROTO_PAP: 559 if (length != 4) { |
506 LogPrintf(LogLCP, " %s bad length (%d)\n", request, length); | 560 LogPrintf(LogLCP, " Bad length!\n"); |
507 goto reqreject; 508 } 509 if (Acceptable(ConfPap)) { 510 LcpInfo.his_auth = proto; 511 memcpy(ackp, cp, length); 512 ackp += length; 513 } else if (Acceptable(ConfChap)) { 514 *nakp++ = *cp; 515 *nakp++ = 5; 516 *nakp++ = (unsigned char) (PROTO_CHAP >> 8); 517 *nakp++ = (unsigned char) PROTO_CHAP; 518 *nakp++ = 5; 519 } else 520 goto reqreject; 521 break; | 561 goto reqreject; 562 } 563 if (Acceptable(ConfPap)) { 564 LcpInfo.his_auth = proto; 565 memcpy(ackp, cp, length); 566 ackp += length; 567 } else if (Acceptable(ConfChap)) { 568 *nakp++ = *cp; 569 *nakp++ = 5; 570 *nakp++ = (unsigned char) (PROTO_CHAP >> 8); 571 *nakp++ = (unsigned char) PROTO_CHAP; 572 *nakp++ = 5; 573 } else 574 goto reqreject; 575 break; |
576 |
|
522 case PROTO_CHAP: 523 if (length < 5) { | 577 case PROTO_CHAP: 578 if (length < 5) { |
524 LogPrintf(LogLCP, " %s bad length (%d)\n", request, length); | 579 LogPrintf(LogLCP, " Bad length!\n"); |
525 goto reqreject; 526 } 527#ifdef HAVE_DES 528 if (Acceptable(ConfChap) && (cp[4] == 5 || cp[4] == 0x80)) 529#else 530 if (Acceptable(ConfChap) && cp[4] == 5) 531#endif 532 { --- 6 unchanged lines hidden (view full) --- 539 } else if (Acceptable(ConfPap)) { 540 *nakp++ = *cp; 541 *nakp++ = 4; 542 *nakp++ = (unsigned char) (PROTO_PAP >> 8); 543 *nakp++ = (unsigned char) PROTO_PAP; 544 } else 545 goto reqreject; 546 break; | 580 goto reqreject; 581 } 582#ifdef HAVE_DES 583 if (Acceptable(ConfChap) && (cp[4] == 5 || cp[4] == 0x80)) 584#else 585 if (Acceptable(ConfChap) && cp[4] == 5) 586#endif 587 { --- 6 unchanged lines hidden (view full) --- 594 } else if (Acceptable(ConfPap)) { 595 *nakp++ = *cp; 596 *nakp++ = 4; 597 *nakp++ = (unsigned char) (PROTO_PAP >> 8); 598 *nakp++ = (unsigned char) PROTO_PAP; 599 } else 600 goto reqreject; 601 break; |
602 |
|
547 default: | 603 default: |
548 LogPrintf(LogLCP, " %s not implemented, NAK.\n", request); | 604 LogPrintf(LogLCP, " proto %d not implemented, NAK.\n", proto); |
549 memcpy(nakp, cp, length); 550 nakp += length; 551 break; 552 } 553 break; 554 case MODE_NAK: 555 break; 556 case MODE_REJ: 557 LcpInfo.his_reject |= (1 << type); 558 break; 559 } 560 break; | 605 memcpy(nakp, cp, length); 606 nakp += length; 607 break; 608 } 609 break; 610 case MODE_NAK: 611 break; 612 case MODE_REJ: 613 LcpInfo.his_reject |= (1 << type); 614 break; 615 } 616 break; |
617 |
|
561 case TY_QUALPROTO: 562 req = (struct lqrreq *) cp; | 618 case TY_QUALPROTO: 619 req = (struct lqrreq *) cp; |
563 LogPrintf(LogLCP, " %s proto: %x, interval: %dms\n", 564 request, ntohs(req->proto), ntohl(req->period) * 10); | 620 LogPrintf(LogLCP, "%s proto %x, interval %dms\n", 621 request, ntohs(req->proto), ntohl(req->period) * 10); |
565 switch (mode_type) { 566 case MODE_REQ: 567 if (ntohs(req->proto) != PROTO_LQR || !Acceptable(ConfLqr)) 568 goto reqreject; 569 else { 570 LcpInfo.his_lqrperiod = ntohl(req->period); 571 if (LcpInfo.his_lqrperiod < 500) 572 LcpInfo.his_lqrperiod = 500; --- 4 unchanged lines hidden (view full) --- 577 break; 578 case MODE_NAK: 579 break; 580 case MODE_REJ: 581 LcpInfo.his_reject |= (1 << type); 582 break; 583 } 584 break; | 622 switch (mode_type) { 623 case MODE_REQ: 624 if (ntohs(req->proto) != PROTO_LQR || !Acceptable(ConfLqr)) 625 goto reqreject; 626 else { 627 LcpInfo.his_lqrperiod = ntohl(req->period); 628 if (LcpInfo.his_lqrperiod < 500) 629 LcpInfo.his_lqrperiod = 500; --- 4 unchanged lines hidden (view full) --- 634 break; 635 case MODE_NAK: 636 break; 637 case MODE_REJ: 638 LcpInfo.his_reject |= (1 << type); 639 break; 640 } 641 break; |
642 |
|
585 case TY_MAGICNUM: 586 lp = (u_long *) (cp + 2); 587 magic = ntohl(*lp); | 643 case TY_MAGICNUM: 644 lp = (u_long *) (cp + 2); 645 magic = ntohl(*lp); |
588 LogPrintf(LogLCP, " %s %08x\n", request, magic); | 646 LogPrintf(LogLCP, "%s 0x%08x\n", request, magic); |
589 590 switch (mode_type) { 591 case MODE_REQ: 592 if (LcpInfo.want_magic) { 593 /* Validate magic number */ 594 if (magic == LcpInfo.want_magic) { 595 LogPrintf(LogLCP, "Magic is same (%08x) - %d times\n", 596 magic, ++LcpFailedMagic); --- 9 unchanged lines hidden (view full) --- 606 LcpFailedMagic = 0; 607 } 608 } else { 609 LcpInfo.my_reject |= (1 << type); 610 goto reqreject; 611 } 612 break; 613 case MODE_NAK: | 647 648 switch (mode_type) { 649 case MODE_REQ: 650 if (LcpInfo.want_magic) { 651 /* Validate magic number */ 652 if (magic == LcpInfo.want_magic) { 653 LogPrintf(LogLCP, "Magic is same (%08x) - %d times\n", 654 magic, ++LcpFailedMagic); --- 9 unchanged lines hidden (view full) --- 664 LcpFailedMagic = 0; 665 } 666 } else { 667 LcpInfo.my_reject |= (1 << type); 668 goto reqreject; 669 } 670 break; 671 case MODE_NAK: |
614 LogPrintf(LogLCP, " %s magic %08x has NAKed\n", request, magic); | 672 LogPrintf(LogLCP, " Magic 0x%08x is NAKed!\n", magic); |
615 LcpInfo.want_magic = GenerateMagic(); 616 break; 617 case MODE_REJ: | 673 LcpInfo.want_magic = GenerateMagic(); 674 break; 675 case MODE_REJ: |
618 LogPrintf(LogLCP, " %s magic has REJected\n", request); | 676 LogPrintf(LogLCP, " Magic 0x%80x is REJected!\n", magic); |
619 LcpInfo.want_magic = 0; 620 LcpInfo.his_reject |= (1 << type); 621 break; 622 } 623 break; | 677 LcpInfo.want_magic = 0; 678 LcpInfo.his_reject |= (1 << type); 679 break; 680 } 681 break; |
682 |
|
624 case TY_PROTOCOMP: | 683 case TY_PROTOCOMP: |
625 LogPrintf(LogLCP, " %s\n", request); | 684 LogPrintf(LogLCP, "%s\n", request); |
626 627 switch (mode_type) { 628 case MODE_REQ: 629 if (Acceptable(ConfProtocomp)) { 630 LcpInfo.his_protocomp = 1; 631 memcpy(ackp, cp, 2); 632 ackp += 2; 633 } else { --- 12 unchanged lines hidden (view full) --- 646 break; 647 case MODE_NAK: 648 case MODE_REJ: 649 LcpInfo.want_protocomp = 0; 650 LcpInfo.his_reject |= (1 << type); 651 break; 652 } 653 break; | 685 686 switch (mode_type) { 687 case MODE_REQ: 688 if (Acceptable(ConfProtocomp)) { 689 LcpInfo.his_protocomp = 1; 690 memcpy(ackp, cp, 2); 691 ackp += 2; 692 } else { --- 12 unchanged lines hidden (view full) --- 705 break; 706 case MODE_NAK: 707 case MODE_REJ: 708 LcpInfo.want_protocomp = 0; 709 LcpInfo.his_reject |= (1 << type); 710 break; 711 } 712 break; |
713 |
|
654 case TY_ACFCOMP: | 714 case TY_ACFCOMP: |
655 LogPrintf(LogLCP, " %s\n", request); | 715 LogPrintf(LogLCP, "%s\n", request); |
656 switch (mode_type) { 657 case MODE_REQ: 658 if (Acceptable(ConfAcfcomp)) { 659 LcpInfo.his_acfcomp = 1; 660 memcpy(ackp, cp, 2); 661 ackp += 2; 662 } else { 663#ifdef OLDMST --- 11 unchanged lines hidden (view full) --- 675 break; 676 case MODE_NAK: 677 case MODE_REJ: 678 LcpInfo.want_acfcomp = 0; 679 LcpInfo.his_reject |= (1 << type); 680 break; 681 } 682 break; | 716 switch (mode_type) { 717 case MODE_REQ: 718 if (Acceptable(ConfAcfcomp)) { 719 LcpInfo.his_acfcomp = 1; 720 memcpy(ackp, cp, 2); 721 ackp += 2; 722 } else { 723#ifdef OLDMST --- 11 unchanged lines hidden (view full) --- 735 break; 736 case MODE_NAK: 737 case MODE_REJ: 738 LcpInfo.want_acfcomp = 0; 739 LcpInfo.his_reject |= (1 << type); 740 break; 741 } 742 break; |
743 |
|
683 case TY_SDP: | 744 case TY_SDP: |
684 LogPrintf(LogLCP, " %s\n", request); | 745 LogPrintf(LogLCP, "%s\n", request); |
685 switch (mode_type) { 686 case MODE_REQ: 687 case MODE_NAK: 688 case MODE_REJ: 689 break; 690 } 691 break; | 746 switch (mode_type) { 747 case MODE_REQ: 748 case MODE_NAK: 749 case MODE_REJ: 750 break; 751 } 752 break; |
753 |
|
692 default: | 754 default: |
693 LogPrintf(LogLCP, " %s[02x]\n", request, type); | 755 sz = (sizeof(desc)-2)/2; 756 if (sz > length - 2) 757 sz = length - 2; 758 pos = 0; 759 desc[0] = sz ? ' ' : '\0'; 760 for (pos = 0; sz--; pos++) 761 sprintf(desc+(pos<<1)+1, "%02x", cp[pos+2]); 762 763 LogPrintf(LogLCP, "%s%s\n", request, desc); 764 |
694 if (mode_type == MODE_REQ) { | 765 if (mode_type == MODE_REQ) { |
695 reqreject: | 766reqreject: 767 if (length > sizeof(RejBuff) - (rejp - RejBuff)) { 768 length = sizeof(RejBuff) - (rejp - RejBuff); 769 LogPrintf(LogLCP, "Can't REJ length %d - trunating to %d\n", 770 cp[1], length); 771 } |
696 memcpy(rejp, cp, length); 697 rejp += length; 698 LcpInfo.my_reject |= (1 << type); | 772 memcpy(rejp, cp, length); 773 rejp += length; 774 LcpInfo.my_reject |= (1 << type); |
775 if (length != cp[1]) 776 return; |
|
699 } 700 break; 701 } 702 /* to avoid inf. loop */ 703 if (length == 0) { 704 LogPrintf(LogLCP, "LCP size zero\n"); 705 break; 706 } 707 plen -= length; 708 cp += length; 709 } 710} 711 712void 713LcpInput(struct mbuf * bp) 714{ 715 FsmInput(&LcpFsm, bp); 716} | 777 } 778 break; 779 } 780 /* to avoid inf. loop */ 781 if (length == 0) { 782 LogPrintf(LogLCP, "LCP size zero\n"); 783 break; 784 } 785 plen -= length; 786 cp += length; 787 } 788} 789 790void 791LcpInput(struct mbuf * bp) 792{ 793 FsmInput(&LcpFsm, bp); 794} |