Lines Matching defs:f

55 #define PROTO_NAME(f)	((f)->callbacks->proto_name)
78 fsm_init(f)
79 fsm *f;
81 f->state = INITIAL;
82 f->flags = 0;
83 f->id = (uchar_t)(drand48() * 0xFF); /* Start with random id */
84 f->timeouttime = DEFTIMEOUT;
85 f->maxconfreqtransmits = DEFMAXCONFREQS;
86 f->maxtermtransmits = DEFMAXTERMREQS;
87 f->maxnakloops = DEFMAXNAKLOOPS;
88 f->term_reason_len = 0;
96 fsm_lowerup(f)
97 fsm *f;
99 switch( f->state ){
101 f->state = CLOSED;
105 if( f->flags & OPT_SILENT )
106 f->state = STOPPED;
109 fsm_sconfreq(f, 0);
110 f->state = REQSENT;
115 error("%s: Up event in state %s", PROTO_NAME(f), fsm_state(f->state));
126 fsm_lowerdown(f)
127 fsm *f;
129 switch( f->state ){
131 f->state = INITIAL;
135 f->state = STARTING;
136 if (f->callbacks->starting != NULL)
137 (*f->callbacks->starting)(f);
141 f->state = INITIAL;
142 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
149 f->state = STARTING;
150 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
154 f->state = STARTING;
155 if (f->callbacks->down != NULL)
156 (*f->callbacks->down)(f);
160 dbglog("%s: Down event in state %s", PROTO_NAME(f),
161 fsm_state(f->state));
170 fsm_open(f)
171 fsm *f;
173 switch( f->state ){
175 f->state = STARTING;
176 if (f->callbacks->starting != NULL)
177 (*f->callbacks->starting)(f);
181 if( f->flags & OPT_SILENT )
182 f->state = STOPPED;
185 fsm_sconfreq(f, 0);
186 f->state = REQSENT;
191 f->state = STOPPING;
196 if( f->flags & OPT_RESTART ){
197 fsm_lowerdown(f);
198 fsm_lowerup(f);
219 fsm_close(f, reason)
220 fsm *f;
223 int prevstate = f->state;
225 f->term_reason = reason;
226 f->term_reason_len = (reason == NULL? 0: strlen(reason));
227 switch( f->state ){
229 f->state = INITIAL;
230 if (f->callbacks->finished != NULL)
231 (*f->callbacks->finished)(f);
235 f->state = CLOSED;
239 f->state = CLOSING;
246 f->state = CLOSING;
248 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
249 else if (f->callbacks->down != NULL)
250 (*f->callbacks->down)(f); /* Inform upper layers we're down */
257 f->retransmits = f->maxtermtransmits;
258 fsm_sdata(f, CODE_TERMREQ, f->reqid = ++f->id,
259 (u_char *) f->term_reason, f->term_reason_len);
260 TIMEOUT(fsm_timeout, f, f->timeouttime);
261 --f->retransmits;
280 fsm *f = (fsm *) arg;
282 switch (f->state) {
285 if( f->retransmits <= 0 ){
289 f->state = (f->state == CLOSING)? CLOSED: STOPPED;
290 if (f->callbacks->finished != NULL)
291 (*f->callbacks->finished)(f);
294 fsm_sdata(f, CODE_TERMREQ, f->reqid = ++f->id,
295 (u_char *) f->term_reason, f->term_reason_len);
296 TIMEOUT(fsm_timeout, f, f->timeouttime);
297 --f->retransmits;
304 if (f->retransmits <= 0) {
305 warn("%s: timeout sending Config-Requests\n", PROTO_NAME(f));
306 f->state = STOPPED;
307 if (!(f->flags & OPT_PASSIVE) && f->callbacks->finished != NULL)
308 (*f->callbacks->finished)(f);
312 if (f->callbacks->retransmit != NULL)
313 (*f->callbacks->retransmit)(f);
314 fsm_sconfreq(f, 1); /* Re-send Configure-Request */
315 if( f->state == ACKRCVD )
316 f->state = REQSENT;
321 fatal("%s: Timeout event in state %s!", PROTO_NAME(f),
322 fsm_state(f->state));
331 fsm_input(f, inpacket, l)
332 fsm *f;
346 error("%s packet: discard; too small (%d < %d)", PROTO_NAME(f), l,
354 error("%s packet: discard; invalid length (%d < %d)", PROTO_NAME(f),
359 error("%s packet: discard; truncated (%d > %d)", PROTO_NAME(f), len,
365 if (f->state == INITIAL || f->state == STARTING) {
366 dbglog("%s: discarded packet in state %s", PROTO_NAME(f),
367 fsm_state(f->state));
376 fsm_rconfreq(f, id, inp, len);
380 fsm_rconfack(f, id, inp, len);
385 fsm_rconfnakrej(f, code, id, inp, len);
389 fsm_rtermreq(f, id, inp, len);
393 fsm_rtermack(f);
397 fsm_rcoderej(f, inp, len);
401 if (f->callbacks->extcode == NULL ||
402 !(*f->callbacks->extcode)(f, code, id, inp, len))
403 fsm_sdata(f, CODE_CODEREJ, ++f->id, inpacket, len + HEADERLEN);
413 fsm_rconfreq(f, id, inp, len)
414 fsm *f;
421 switch( f->state ){
424 fsm_sdata(f, CODE_TERMACK, id, NULL, 0);
429 dbglog("%s: discarded Configure-Request in state %s", PROTO_NAME(f),
430 fsm_state(f->state));
435 if (f->callbacks->down != NULL)
436 (*f->callbacks->down)(f); /* Inform upper layers */
449 if (f->callbacks->reqci != NULL) { /* Check CI */
450 reject_if_disagree = (f->nakloops >= f->maxnakloops);
451 code = (*f->callbacks->reqci)(f, inp, &len, reject_if_disagree);
461 if (f->state == OPENED || f->state == STOPPED)
462 fsm_sconfreq(f, 0); /* Send initial Configure-Request */
465 fsm_sdata(f, code, id, inp, len);
469 if (f->state == ACKRCVD) {
470 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
471 f->state = OPENED;
472 if (f->callbacks->up != NULL)
473 (*f->callbacks->up)(f); /* Inform upper layers */
475 f->state = ACKSENT;
476 f->nakloops = 0;
481 if (f->state != ACKRCVD)
482 f->state = REQSENT;
484 ++f->nakloops;
493 fsm_rconfack(f, id, inp, len)
494 fsm *f;
499 if (id != f->reqid || f->seen_ack) /* Expected id? */
501 if( !(f->callbacks->ackci != NULL ? (*f->callbacks->ackci)(f, inp, len):
507 f->seen_ack = 1;
509 switch (f->state) {
512 fsm_sdata(f, CODE_TERMACK, id, NULL, 0);
516 f->state = ACKRCVD;
517 f->retransmits = f->maxconfreqtransmits;
522 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
523 fsm_sconfreq(f, 0);
524 f->state = REQSENT;
528 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
529 f->state = OPENED;
530 f->retransmits = f->maxconfreqtransmits;
531 if (f->callbacks->up != NULL)
532 (*f->callbacks->up)(f); /* Inform upper layers */
537 fsm_sconfreq(f, 0); /* Send initial Configure-Request */
538 f->state = REQSENT;
539 if (f->callbacks->down != NULL)
540 (*f->callbacks->down)(f); /* Inform upper layers */
550 fsm_rconfnakrej(f, code, id, inp, len)
551 fsm *f;
559 if (id != f->reqid || f->seen_ack) /* Expected id? */
561 proc = (code == CODE_CONFNAK)? f->callbacks->nakci: f->callbacks->rejci;
562 if (proc == NULL || !(ret = proc(f, inp, len))) {
567 f->seen_ack = 1;
569 switch (f->state) {
572 fsm_sdata(f, CODE_TERMACK, id, NULL, 0);
578 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
580 f->state = STOPPED; /* kludge for stopping CCP */
582 fsm_sconfreq(f, 0); /* Send Configure-Request */
587 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
588 fsm_sconfreq(f, 0);
589 f->state = REQSENT;
594 fsm_sconfreq(f, 0); /* Send initial Configure-Request */
595 f->state = REQSENT;
596 if (f->callbacks->down != NULL)
597 (*f->callbacks->down)(f); /* Inform upper layers */
607 fsm_rtermreq(f, id, p, len)
608 fsm *f;
613 switch (f->state) {
616 f->state = REQSENT; /* Start over but keep trying */
621 info("%s terminated by peer (%0.*v)", PROTO_NAME(f), len, p);
623 info("%s terminated by peer", PROTO_NAME(f));
625 f->state = STOPPING;
626 if (f->callbacks->down != NULL)
627 (*f->callbacks->down)(f); /* Inform upper layers */
628 f->retransmits = 0;
629 TIMEOUT(fsm_timeout, f, f->timeouttime);
633 fsm_sdata(f, CODE_TERMACK, id, NULL, 0);
641 fsm_rtermack(f)
642 fsm *f;
644 switch (f->state) {
646 UNTIMEOUT(fsm_timeout, f);
647 f->state = CLOSED;
648 if (f->callbacks->finished != NULL)
649 (*f->callbacks->finished)(f);
652 UNTIMEOUT(fsm_timeout, f);
653 f->state = STOPPED;
654 if (f->callbacks->finished != NULL)
655 (*f->callbacks->finished)(f);
659 f->state = REQSENT;
663 fsm_sconfreq(f, 0);
664 f->state = REQSENT;
665 if (f->callbacks->down != NULL)
666 (*f->callbacks->down)(f); /* Inform upper layers */
676 fsm_rcoderej(f, inp, len)
677 fsm *f;
685 error("%s: Code-Reject too short (%d < %d)", PROTO_NAME(f), len,
692 warn("%s: Rcvd Code-Reject for %s id %d", PROTO_NAME(f),
695 setbit(f->codemask, code);
698 if (f->callbacks->codereject != NULL) {
699 seriouserr = (*f->callbacks->codereject)(f,code,id,inp,len);
710 switch (f->state) {
712 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
715 f->state = CLOSED;
716 if (f->callbacks->finished != NULL)
717 (*f->callbacks->finished)(f);
724 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
725 f->state = STOPPED;
728 if (f->callbacks->finished != NULL)
729 (*f->callbacks->finished)(f);
733 f->state = STOPPING;
734 if (f->callbacks->down != NULL)
735 (*f->callbacks->down)(f);
737 if (f->term_reason == NULL) {
738 f->term_reason = "unacceptable Code-Reject received";
739 f->term_reason_len = strlen(f->term_reason);
743 f->retransmits = f->maxtermtransmits;
744 fsm_sdata(f, CODE_TERMREQ, f->reqid = ++f->id,
745 (u_char *) f->term_reason, f->term_reason_len);
746 TIMEOUT(fsm_timeout, f, f->timeouttime);
747 --f->retransmits;
755 if (f->state == ACKRCVD)
756 f->state = REQSENT;
767 fsm_protreject(f)
768 fsm *f;
770 switch( f->state ){
772 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
775 f->state = CLOSED;
776 if (f->callbacks->finished != NULL)
777 (*f->callbacks->finished)(f);
784 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
787 f->state = STOPPED;
788 if (f->callbacks->finished != NULL)
789 (*f->callbacks->finished)(f);
793 f->state = STOPPING;
794 if (f->callbacks->down != NULL)
795 (*f->callbacks->down)(f);
798 f->retransmits = f->maxtermtransmits;
799 fsm_sdata(f, CODE_TERMREQ, f->reqid = ++f->id,
800 (u_char *) f->term_reason, f->term_reason_len);
801 TIMEOUT(fsm_timeout, f, f->timeouttime);
802 --f->retransmits;
806 dbglog("%s: Protocol-Reject in state %s", PROTO_NAME(f),
807 fsm_state(f->state));
816 fsm_sconfreq(f, retransmit)
817 fsm *f;
823 if( f->state != REQSENT && f->state != ACKRCVD && f->state != ACKSENT ){
825 if (f->callbacks->resetci != NULL)
826 (*f->callbacks->resetci)(f);
827 f->nakloops = 0;
832 f->retransmits = f->maxconfreqtransmits;
833 f->reqid = ++f->id;
836 f->seen_ack = 0;
842 if (f->callbacks->cilen != NULL) {
843 cilen = (*f->callbacks->cilen)(f);
844 if (cilen > peer_mru[f->unit] - HEADERLEN)
845 cilen = peer_mru[f->unit] - HEADERLEN;
847 cilen = peer_mru[f->unit] - HEADERLEN;
850 if (f->callbacks->addci != NULL)
851 (*f->callbacks->addci)(f, outp, &cilen);
856 fsm_sdata(f, CODE_CONFREQ, f->reqid, outp, cilen);
859 --f->retransmits;
860 TIMEOUT(fsm_timeout, f, f->timeouttime);
870 fsm_sdata(f, code, id, data, datalen)
871 fsm *f;
879 if (isset(f->codemask,code)) {
881 PROTO_NAME(f), code_name(code,0));
887 if (datalen > peer_mru[f->unit] - HEADERLEN)
888 datalen = peer_mru[f->unit] - HEADERLEN;
892 MAKEHEADER(outp, f->protocol);
896 output(f->unit, outpacket_buf, outlen + PPP_HDRLEN);