Deleted Added
full compact
fsm.c (6060) fsm.c (6735)
1/*
2 * PPP Finite State Machine for LCP/IPCP
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.
1/*
2 * PPP Finite State Machine for LCP/IPCP
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 *
19 *
20 * $Id:$
20 * $Id:$
21 *
21 *
22 * TODO:
23 * o Refer loglevel for log output
24 * o Better option log display
25 */
26#include "fsm.h"
27#include "hdlc.h"
28#include "lqr.h"
29#include "lcpproto.h"

--- 194 unchanged lines hidden (view full) ---

224static void
225FsmSendConfigAck(fp, lhp, option, count)
226struct fsm *fp;
227struct fsmheader *lhp;
228u_char *option;
229int count;
230{
231 LogPrintf(LOG_LCP, "%s: SendConfigAck(%s)\n", fp->name, StateNames[fp->state]);
22 * TODO:
23 * o Refer loglevel for log output
24 * o Better option log display
25 */
26#include "fsm.h"
27#include "hdlc.h"
28#include "lqr.h"
29#include "lcpproto.h"

--- 194 unchanged lines hidden (view full) ---

224static void
225FsmSendConfigAck(fp, lhp, option, count)
226struct fsm *fp;
227struct fsmheader *lhp;
228u_char *option;
229int count;
230{
231 LogPrintf(LOG_LCP, "%s: SendConfigAck(%s)\n", fp->name, StateNames[fp->state]);
232 (fp->DecodeConfig)(option, count, MODE_NOP);
232 FsmOutput(fp, CODE_CONFIGACK, lhp->id, option, count);
233}
234
235static void
236FsmSendConfigRej(fp, lhp, option, count)
237struct fsm *fp;
238struct fsmheader *lhp;
239u_char *option;
240int count;
241{
242 LogPrintf(LOG_LCP, "%s: SendConfigRej(%s)\n", fp->name, StateNames[fp->state]);
233 FsmOutput(fp, CODE_CONFIGACK, lhp->id, option, count);
234}
235
236static void
237FsmSendConfigRej(fp, lhp, option, count)
238struct fsm *fp;
239struct fsmheader *lhp;
240u_char *option;
241int count;
242{
243 LogPrintf(LOG_LCP, "%s: SendConfigRej(%s)\n", fp->name, StateNames[fp->state]);
244 (fp->DecodeConfig)(option, count, MODE_NOP);
243 FsmOutput(fp, CODE_CONFIGREJ, lhp->id, option, count);
244}
245
246static void
247FsmSendConfigNak(fp, lhp, option, count)
248struct fsm *fp;
249struct fsmheader *lhp;
250u_char *option;
251int count;
252{
253 LogPrintf(LOG_LCP, "%s: SendConfigNak(%s)\n",
254 fp->name, StateNames[fp->state]);
245 FsmOutput(fp, CODE_CONFIGREJ, lhp->id, option, count);
246}
247
248static void
249FsmSendConfigNak(fp, lhp, option, count)
250struct fsm *fp;
251struct fsmheader *lhp;
252u_char *option;
253int count;
254{
255 LogPrintf(LOG_LCP, "%s: SendConfigNak(%s)\n",
256 fp->name, StateNames[fp->state]);
257 (fp->DecodeConfig)(option, count, MODE_NOP);
255 FsmOutput(fp, CODE_CONFIGNAK, lhp->id, option, count);
256}
257
258/*
259 * Timeout actions
260 */
261void
262FsmTimeout(fp)

--- 50 unchanged lines hidden (view full) ---

313 * Actions when receive packets
314 */
315void
316FsmRecvConfigReq(fp, lhp, bp) /* RCR */
317struct fsm *fp;
318struct fsmheader *lhp;
319struct mbuf *bp;
320{
258 FsmOutput(fp, CODE_CONFIGNAK, lhp->id, option, count);
259}
260
261/*
262 * Timeout actions
263 */
264void
265FsmTimeout(fp)

--- 50 unchanged lines hidden (view full) ---

316 * Actions when receive packets
317 */
318void
319FsmRecvConfigReq(fp, lhp, bp) /* RCR */
320struct fsm *fp;
321struct fsmheader *lhp;
322struct mbuf *bp;
323{
321 int plen;
324 int plen, flen;
322 int ackaction = 0;
323
324 plen = plength(bp);
325 int ackaction = 0;
326
327 plen = plength(bp);
325 if (plen < sizeof(struct fsmconfig)) {
326logprintf("** plen = %d\n", plen);
328 flen = ntohs(lhp->length) - sizeof(*lhp);
329 if (plen < flen) {
330 logprintf("** plen (%d) < flen (%d)\n", plen, flen);
327 pfree(bp);
328 return;
329 }
330
331 pfree(bp);
332 return;
333 }
334
335
331 /*
332 * Check and process easy case
333 */
334 switch (fp->state) {
335 case ST_INITIAL:
336 case ST_STARTING:
337 LogPrintf(LOG_LCP, "%s: Oops, RCR in %s.\n",
338 fp->name, StateNames[fp->state]);

--- 5 unchanged lines hidden (view full) ---

344 return;
345 case ST_CLOSING:
346 case ST_STOPPING:
347logprintf("## state = %d\n", fp->state);
348 pfree(bp);
349 return;
350 }
351
336 /*
337 * Check and process easy case
338 */
339 switch (fp->state) {
340 case ST_INITIAL:
341 case ST_STARTING:
342 LogPrintf(LOG_LCP, "%s: Oops, RCR in %s.\n",
343 fp->name, StateNames[fp->state]);

--- 5 unchanged lines hidden (view full) ---

349 return;
350 case ST_CLOSING:
351 case ST_STOPPING:
352logprintf("## state = %d\n", fp->state);
353 pfree(bp);
354 return;
355 }
356
352 (fp->DecodeConfig)(bp, MODE_REQ);
357 (fp->DecodeConfig)(MBUF_CTOP(bp), flen, MODE_REQ);
353
354 if (nakp == NakBuff && rejp == RejBuff)
355 ackaction = 1;
356
357 switch (fp->state) {
358 case ST_OPENED:
359 (fp->LayerDown)(fp);
360 FsmSendConfigReq(fp);

--- 74 unchanged lines hidden (view full) ---

435}
436
437void
438FsmRecvConfigNak(fp, lhp, bp) /* RCN */
439struct fsm *fp;
440struct fsmheader *lhp;
441struct mbuf *bp;
442{
358
359 if (nakp == NakBuff && rejp == RejBuff)
360 ackaction = 1;
361
362 switch (fp->state) {
363 case ST_OPENED:
364 (fp->LayerDown)(fp);
365 FsmSendConfigReq(fp);

--- 74 unchanged lines hidden (view full) ---

440}
441
442void
443FsmRecvConfigNak(fp, lhp, bp) /* RCN */
444struct fsm *fp;
445struct fsmheader *lhp;
446struct mbuf *bp;
447{
443 int plen;
448 int plen, flen;
444
445 plen = plength(bp);
449
450 plen = plength(bp);
446 if (plen < sizeof(struct fsmconfig)) {
451 flen = ntohs(lhp->length) - sizeof(*lhp);
452 if (plen < flen) {
447 pfree(bp);
448 return;
449 }
450
451 /*
452 * Check and process easy case
453 */
454 switch (fp->state) {

--- 9 unchanged lines hidden (view full) ---

464 pfree(bp);
465 return;
466 case ST_CLOSING:
467 case ST_STOPPING:
468 pfree(bp);
469 return;
470 }
471
453 pfree(bp);
454 return;
455 }
456
457 /*
458 * Check and process easy case
459 */
460 switch (fp->state) {

--- 9 unchanged lines hidden (view full) ---

470 pfree(bp);
471 return;
472 case ST_CLOSING:
473 case ST_STOPPING:
474 pfree(bp);
475 return;
476 }
477
472 (fp->DecodeConfig)(bp, MODE_NAK);
478 (fp->DecodeConfig)(MBUF_CTOP(bp), flen, MODE_NAK);
473
474 switch (fp->state) {
475 case ST_REQSENT:
476 case ST_ACKSENT:
477 FsmInitRestartCounter(fp);
478 FsmSendConfigReq(fp);
479 break;
480 case ST_OPENED:

--- 70 unchanged lines hidden (view full) ---

551}
552
553void
554FsmRecvConfigRej(fp, lhp, bp) /* RCJ */
555struct fsm *fp;
556struct fsmheader *lhp;
557struct mbuf *bp;
558{
479
480 switch (fp->state) {
481 case ST_REQSENT:
482 case ST_ACKSENT:
483 FsmInitRestartCounter(fp);
484 FsmSendConfigReq(fp);
485 break;
486 case ST_OPENED:

--- 70 unchanged lines hidden (view full) ---

557}
558
559void
560FsmRecvConfigRej(fp, lhp, bp) /* RCJ */
561struct fsm *fp;
562struct fsmheader *lhp;
563struct mbuf *bp;
564{
559 int plen;
565 int plen, flen;
560
561 plen = plength(bp);
566
567 plen = plength(bp);
562 if (plen < sizeof(struct fsmconfig)) {
568 flen = ntohs(lhp->length) - sizeof(*lhp);
569 if (plen < flen) {
563 pfree(bp);
564 return;
565 }
566 LogPrintf(LOG_LCP, "%s: RecvConfigRej.\n", fp->name);
567
568 /*
569 * Check and process easy case
570 */

--- 10 unchanged lines hidden (view full) ---

581 pfree(bp);
582 return;
583 case ST_CLOSING:
584 case ST_STOPPING:
585 pfree(bp);
586 return;
587 }
588
570 pfree(bp);
571 return;
572 }
573 LogPrintf(LOG_LCP, "%s: RecvConfigRej.\n", fp->name);
574
575 /*
576 * Check and process easy case
577 */

--- 10 unchanged lines hidden (view full) ---

588 pfree(bp);
589 return;
590 case ST_CLOSING:
591 case ST_STOPPING:
592 pfree(bp);
593 return;
594 }
595
589 (fp->DecodeConfig)(bp, MODE_REJ);
596 (fp->DecodeConfig)(MBUF_CTOP(bp), flen, MODE_REJ);
590
591 switch (fp->state) {
592 case ST_REQSENT:
593 case ST_ACKSENT:
594 FsmInitRestartCounter(fp);
595 FsmSendConfigReq(fp);
596 break;
597 case ST_OPENED:

--- 188 unchanged lines hidden (view full) ---

786 return;
787 }
788
789 bp->offset += sizeof(struct fsmheader);
790 bp->cnt -= sizeof(struct fsmheader);
791
792 codep = FsmCodes + lhp->code - 1;
793 LogPrintf(LOG_LCP, "%s: Received %s (%d) state = %s (%d)\n",
597
598 switch (fp->state) {
599 case ST_REQSENT:
600 case ST_ACKSENT:
601 FsmInitRestartCounter(fp);
602 FsmSendConfigReq(fp);
603 break;
604 case ST_OPENED:

--- 188 unchanged lines hidden (view full) ---

793 return;
794 }
795
796 bp->offset += sizeof(struct fsmheader);
797 bp->cnt -= sizeof(struct fsmheader);
798
799 codep = FsmCodes + lhp->code - 1;
800 LogPrintf(LOG_LCP, "%s: Received %s (%d) state = %s (%d)\n",
794 fp->name, codep->name, lhp->code, StateNames[fp->state], fp->state);
801 fp->name, codep->name, lhp->id, StateNames[fp->state], fp->state);
795#ifdef DEBUG
796 LogMemory();
797#endif
798 (codep->action)(fp, lhp, bp);
799#ifdef DEBUG
800 LogMemory();
801#endif
802}
802#ifdef DEBUG
803 LogMemory();
804#endif
805 (codep->action)(fp, lhp, bp);
806#ifdef DEBUG
807 LogMemory();
808#endif
809}