dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / cmd-inet / usr.bin / pppd / fsm.c
blobea48586e4cb1e938d9bcdd0a00b39916adbdf10a
1 /*
2 * fsm.c - {Link, IP} Control Protocol Finite State Machine.
4 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
5 * Use is subject to license terms.
7 * Copyright (c) 1989 Carnegie Mellon University.
8 * All rights reserved.
10 * Redistribution and use in source and binary forms are permitted
11 * provided that the above copyright notice and this paragraph are
12 * duplicated in all such forms and that any documentation,
13 * advertising materials, and other materials related to such
14 * distribution and use acknowledge that the software was developed
15 * by Carnegie Mellon University. The name of the
16 * University may not be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
20 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 #pragma ident "%Z%%M% %I% %E% SMI"
24 #define RCSID "$Id: fsm.c,v 1.17 1999/08/13 06:46:12 paulus Exp $"
27 * TODO:
28 * Randomize fsm id on link/init.
29 * Deal with variable outgoing MTU.
32 #include <stdio.h>
33 #include <string.h>
34 #include <sys/types.h>
35 #ifndef NO_DRAND48
36 #include <stdlib.h>
37 #endif /* NO_DRAND48 */
39 #include "pppd.h"
40 #include "fsm.h"
42 static const char rcsid[] = RCSID;
44 static void fsm_timeout __P((void *));
45 static void fsm_rconfreq __P((fsm *, int, u_char *, int));
46 static void fsm_rconfack __P((fsm *, int, u_char *, int));
47 static void fsm_rconfnakrej __P((fsm *, int, int, u_char *, int));
48 static void fsm_rtermreq __P((fsm *, int, u_char *, int));
49 static void fsm_rtermack __P((fsm *));
50 static void fsm_rcoderej __P((fsm *, u_char *, int));
51 static void fsm_sconfreq __P((fsm *, int));
53 #define PROTO_NAME(f) ((f)->callbacks->proto_name)
55 static int peer_mru[NUM_PPP];
57 const char *
58 fsm_state(int statenum)
60 static const char *fsm_states[] = { FSM__STATES };
61 static char buf[32];
63 if (statenum < 0 || statenum >= Dim(fsm_states)) {
64 (void) slprintf(buf, sizeof (buf), "unknown#%d", statenum);
65 return buf;
67 return fsm_states[statenum];
71 * fsm_init - Initialize fsm.
73 * Initialize fsm state.
75 void
76 fsm_init(f)
77 fsm *f;
79 f->state = INITIAL;
80 f->flags = 0;
81 f->id = (uchar_t)(drand48() * 0xFF); /* Start with random id */
82 f->timeouttime = DEFTIMEOUT;
83 f->maxconfreqtransmits = DEFMAXCONFREQS;
84 f->maxtermtransmits = DEFMAXTERMREQS;
85 f->maxnakloops = DEFMAXNAKLOOPS;
86 f->term_reason_len = 0;
91 * fsm_lowerup - The lower layer is up.
93 void
94 fsm_lowerup(f)
95 fsm *f;
97 switch( f->state ){
98 case INITIAL:
99 f->state = CLOSED;
100 break;
102 case STARTING:
103 if( f->flags & OPT_SILENT )
104 f->state = STOPPED;
105 else {
106 /* Send an initial configure-request */
107 fsm_sconfreq(f, 0);
108 f->state = REQSENT;
110 break;
112 default:
113 error("%s: Up event in state %s", PROTO_NAME(f), fsm_state(f->state));
119 * fsm_lowerdown - The lower layer is down.
121 * Cancel all timeouts and inform upper layers.
123 void
124 fsm_lowerdown(f)
125 fsm *f;
127 switch( f->state ){
128 case CLOSED:
129 f->state = INITIAL;
130 break;
132 case STOPPED:
133 f->state = STARTING;
134 if (f->callbacks->starting != NULL)
135 (*f->callbacks->starting)(f);
136 break;
138 case CLOSING:
139 f->state = INITIAL;
140 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
141 break;
143 case STOPPING:
144 case REQSENT:
145 case ACKRCVD:
146 case ACKSENT:
147 f->state = STARTING;
148 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
149 break;
151 case OPENED:
152 f->state = STARTING;
153 if (f->callbacks->down != NULL)
154 (*f->callbacks->down)(f);
155 break;
157 default:
158 dbglog("%s: Down event in state %s", PROTO_NAME(f),
159 fsm_state(f->state));
165 * fsm_open - Link is allowed to come up.
167 void
168 fsm_open(f)
169 fsm *f;
171 switch( f->state ){
172 case INITIAL:
173 f->state = STARTING;
174 if (f->callbacks->starting != NULL)
175 (*f->callbacks->starting)(f);
176 break;
178 case CLOSED:
179 if( f->flags & OPT_SILENT )
180 f->state = STOPPED;
181 else {
182 /* Send an initial configure-request */
183 fsm_sconfreq(f, 0);
184 f->state = REQSENT;
186 break;
188 case CLOSING:
189 f->state = STOPPING;
190 /*FALLTHROUGH*/
191 case STOPPING:
192 case STOPPED:
193 case OPENED:
194 if( f->flags & OPT_RESTART ){
195 fsm_lowerdown(f);
196 fsm_lowerup(f);
198 break;
200 case STARTING:
201 case REQSENT:
202 case ACKRCVD:
203 case ACKSENT:
204 /* explicitly do nothing here. */
205 break;
211 * fsm_close - Start closing connection.
213 * Cancel timeouts and either initiate close or possibly go directly to
214 * the CLOSED state.
216 void
217 fsm_close(f, reason)
218 fsm *f;
219 char *reason;
221 int prevstate = f->state;
223 f->term_reason = reason;
224 f->term_reason_len = (reason == NULL? 0: strlen(reason));
225 switch( f->state ){
226 case STARTING:
227 f->state = INITIAL;
228 if (f->callbacks->finished != NULL)
229 (*f->callbacks->finished)(f);
230 break;
232 case STOPPED:
233 f->state = CLOSED;
234 break;
236 case STOPPING:
237 f->state = CLOSING;
238 break;
240 case REQSENT:
241 case ACKRCVD:
242 case ACKSENT:
243 case OPENED:
244 f->state = CLOSING;
245 if (prevstate != OPENED )
246 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
247 else if (f->callbacks->down != NULL)
248 (*f->callbacks->down)(f); /* Inform upper layers we're down */
250 * Note that this-layer-down means "stop transmitting."
251 * This-layer-finished means "stop everything."
254 /* Init restart counter, send Terminate-Request */
255 f->retransmits = f->maxtermtransmits;
256 fsm_sdata(f, CODE_TERMREQ, f->reqid = ++f->id,
257 (u_char *) f->term_reason, f->term_reason_len);
258 TIMEOUT(fsm_timeout, f, f->timeouttime);
259 --f->retransmits;
260 break;
262 case INITIAL:
263 case CLOSED:
264 case CLOSING:
265 /* explicitly do nothing here. */
266 break;
272 * fsm_timeout - Timeout expired.
274 static void
275 fsm_timeout(arg)
276 void *arg;
278 fsm *f = (fsm *) arg;
280 switch (f->state) {
281 case CLOSING:
282 case STOPPING:
283 if( f->retransmits <= 0 ){
285 * We've waited for an ack long enough. Peer probably heard us.
287 f->state = (f->state == CLOSING)? CLOSED: STOPPED;
288 if (f->callbacks->finished != NULL)
289 (*f->callbacks->finished)(f);
290 } else {
291 /* Send Terminate-Request */
292 fsm_sdata(f, CODE_TERMREQ, f->reqid = ++f->id,
293 (u_char *) f->term_reason, f->term_reason_len);
294 TIMEOUT(fsm_timeout, f, f->timeouttime);
295 --f->retransmits;
297 break;
299 case REQSENT:
300 case ACKRCVD:
301 case ACKSENT:
302 if (f->retransmits <= 0) {
303 warn("%s: timeout sending Config-Requests\n", PROTO_NAME(f));
304 f->state = STOPPED;
305 if (!(f->flags & OPT_PASSIVE) && f->callbacks->finished != NULL)
306 (*f->callbacks->finished)(f);
308 } else {
309 /* Retransmit the configure-request */
310 if (f->callbacks->retransmit != NULL)
311 (*f->callbacks->retransmit)(f);
312 fsm_sconfreq(f, 1); /* Re-send Configure-Request */
313 if( f->state == ACKRCVD )
314 f->state = REQSENT;
316 break;
318 default:
319 fatal("%s: Timeout event in state %s!", PROTO_NAME(f),
320 fsm_state(f->state));
326 * fsm_input - Input packet.
328 void
329 fsm_input(f, inpacket, l)
330 fsm *f;
331 u_char *inpacket;
332 int l;
334 u_char *inp;
335 u_char code, id;
336 int len;
339 * Parse header (code, id and length).
340 * If packet too short, drop it.
342 inp = inpacket;
343 if (l < HEADERLEN) {
344 error("%s packet: discard; too small (%d < %d)", PROTO_NAME(f), l,
345 HEADERLEN);
346 return;
348 GETCHAR(code, inp);
349 GETCHAR(id, inp);
350 GETSHORT(len, inp);
351 if (len < HEADERLEN) {
352 error("%s packet: discard; invalid length (%d < %d)", PROTO_NAME(f),
353 len, HEADERLEN);
354 return;
356 if (len > l) {
357 error("%s packet: discard; truncated (%d > %d)", PROTO_NAME(f), len,
359 return;
361 len -= HEADERLEN; /* subtract header length */
363 if (f->state == INITIAL || f->state == STARTING) {
364 dbglog("%s: discarded packet in state %s", PROTO_NAME(f),
365 fsm_state(f->state));
366 return;
370 * Action depends on code.
372 switch (code) {
373 case CODE_CONFREQ:
374 fsm_rconfreq(f, id, inp, len);
375 break;
377 case CODE_CONFACK:
378 fsm_rconfack(f, id, inp, len);
379 break;
381 case CODE_CONFNAK:
382 case CODE_CONFREJ:
383 fsm_rconfnakrej(f, code, id, inp, len);
384 break;
386 case CODE_TERMREQ:
387 fsm_rtermreq(f, id, inp, len);
388 break;
390 case CODE_TERMACK:
391 fsm_rtermack(f);
392 break;
394 case CODE_CODEREJ:
395 fsm_rcoderej(f, inp, len);
396 break;
398 default:
399 if (f->callbacks->extcode == NULL ||
400 !(*f->callbacks->extcode)(f, code, id, inp, len))
401 fsm_sdata(f, CODE_CODEREJ, ++f->id, inpacket, len + HEADERLEN);
402 break;
408 * fsm_rconfreq - Receive Configure-Request.
410 static void
411 fsm_rconfreq(f, id, inp, len)
412 fsm *f;
413 u_char id;
414 u_char *inp;
415 int len;
417 int code, reject_if_disagree;
419 switch( f->state ){
420 case CLOSED:
421 /* Go away, we're closed */
422 fsm_sdata(f, CODE_TERMACK, id, NULL, 0);
423 return;
425 case CLOSING:
426 case STOPPING:
427 dbglog("%s: discarded Configure-Request in state %s", PROTO_NAME(f),
428 fsm_state(f->state));
429 return;
431 case OPENED:
432 /* Go down and restart negotiation */
433 if (f->callbacks->down != NULL)
434 (*f->callbacks->down)(f); /* Inform upper layers */
435 break;
438 #ifdef DEBUG
439 if (inp >= outpacket_buf && inp < outpacket_buf+PPP_MRU+PPP_HDRLEN)
440 fatal("bad pointer");
441 #endif
444 * Pass the requested configuration options
445 * to protocol-specific code for checking.
447 if (f->callbacks->reqci != NULL) { /* Check CI */
448 reject_if_disagree = (f->nakloops >= f->maxnakloops);
449 code = (*f->callbacks->reqci)(f, inp, &len, reject_if_disagree);
450 } else if (len > 0)
451 code = CODE_CONFREJ; /* Reject all CI */
452 else
453 code = CODE_CONFACK;
455 /* Allow NCP to do fancy footwork, such as reinitializing. */
456 if (code <= 0)
457 return;
459 if (f->state == OPENED || f->state == STOPPED)
460 fsm_sconfreq(f, 0); /* Send initial Configure-Request */
462 /* send the Ack, Nak or Rej to the peer */
463 fsm_sdata(f, code, id, inp, len);
465 if (code == CODE_CONFACK) {
466 /* RFC 1661 event RCR+ */
467 if (f->state == ACKRCVD) {
468 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
469 f->state = OPENED;
470 if (f->callbacks->up != NULL)
471 (*f->callbacks->up)(f); /* Inform upper layers */
472 } else
473 f->state = ACKSENT;
474 f->nakloops = 0;
476 } else {
477 /* RFC 1661 event RCR- */
478 /* (we sent CODE_CONFNAK or CODE_CONFREJ) */
479 if (f->state != ACKRCVD)
480 f->state = REQSENT;
481 if( code == CODE_CONFNAK )
482 ++f->nakloops;
488 * fsm_rconfack - Receive Configure-Ack.
490 static void
491 fsm_rconfack(f, id, inp, len)
492 fsm *f;
493 int id;
494 u_char *inp;
495 int len;
497 if (id != f->reqid || f->seen_ack) /* Expected id? */
498 return; /* Nope, toss... */
499 if( !(f->callbacks->ackci != NULL ? (*f->callbacks->ackci)(f, inp, len):
500 (len == 0)) ){
501 /* Ack is bad - ignore it */
502 error("Received bad configure-ack: %P", inp, len);
503 return;
505 f->seen_ack = 1;
507 switch (f->state) {
508 case CLOSED:
509 case STOPPED:
510 fsm_sdata(f, CODE_TERMACK, id, NULL, 0);
511 break;
513 case REQSENT:
514 f->state = ACKRCVD;
515 f->retransmits = f->maxconfreqtransmits;
516 break;
518 case ACKRCVD:
519 /* Huh? an extra valid Ack? oh well... */
520 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
521 fsm_sconfreq(f, 0);
522 f->state = REQSENT;
523 break;
525 case ACKSENT:
526 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
527 f->state = OPENED;
528 f->retransmits = f->maxconfreqtransmits;
529 if (f->callbacks->up != NULL)
530 (*f->callbacks->up)(f); /* Inform upper layers */
531 break;
533 case OPENED:
534 /* Go down and restart negotiation */
535 fsm_sconfreq(f, 0); /* Send initial Configure-Request */
536 f->state = REQSENT;
537 if (f->callbacks->down != NULL)
538 (*f->callbacks->down)(f); /* Inform upper layers */
539 break;
545 * fsm_rconfnakrej - Receive Configure-Nak or Configure-Reject.
547 static void
548 fsm_rconfnakrej(f, code, id, inp, len)
549 fsm *f;
550 int code, id;
551 u_char *inp;
552 int len;
554 int (*proc) __P((fsm *, u_char *, int));
555 int ret;
557 if (id != f->reqid || f->seen_ack) /* Expected id? */
558 return; /* Nope, toss... */
559 proc = (code == CODE_CONFNAK)? f->callbacks->nakci: f->callbacks->rejci;
560 if (proc == NULL || !(ret = proc(f, inp, len))) {
561 /* Nak/reject is bad - ignore it */
562 error("Received bad configure-nak/rej: %P", inp, len);
563 return;
565 f->seen_ack = 1;
567 switch (f->state) {
568 case CLOSED:
569 case STOPPED:
570 fsm_sdata(f, CODE_TERMACK, id, NULL, 0);
571 break;
573 case REQSENT:
574 case ACKSENT:
575 /* They didn't agree to what we wanted - try another request */
576 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
577 if (ret < 0)
578 f->state = STOPPED; /* kludge for stopping CCP */
579 else
580 fsm_sconfreq(f, 0); /* Send Configure-Request */
581 break;
583 case ACKRCVD:
584 /* Got a Nak/reject when we had already had an Ack?? oh well... */
585 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
586 fsm_sconfreq(f, 0);
587 f->state = REQSENT;
588 break;
590 case OPENED:
591 /* Go down and restart negotiation */
592 fsm_sconfreq(f, 0); /* Send initial Configure-Request */
593 f->state = REQSENT;
594 if (f->callbacks->down != NULL)
595 (*f->callbacks->down)(f); /* Inform upper layers */
596 break;
602 * fsm_rtermreq - Receive Terminate-Req.
604 static void
605 fsm_rtermreq(f, id, p, len)
606 fsm *f;
607 int id;
608 u_char *p;
609 int len;
611 switch (f->state) {
612 case ACKRCVD:
613 case ACKSENT:
614 f->state = REQSENT; /* Start over but keep trying */
615 break;
617 case OPENED:
618 if (len > 0) {
619 info("%s terminated by peer (%0.*v)", PROTO_NAME(f), len, p);
620 } else {
621 info("%s terminated by peer", PROTO_NAME(f));
623 f->state = STOPPING;
624 if (f->callbacks->down != NULL)
625 (*f->callbacks->down)(f); /* Inform upper layers */
626 f->retransmits = 0;
627 TIMEOUT(fsm_timeout, f, f->timeouttime);
628 break;
631 fsm_sdata(f, CODE_TERMACK, id, NULL, 0);
636 * fsm_rtermack - Receive Terminate-Ack.
638 static void
639 fsm_rtermack(f)
640 fsm *f;
642 switch (f->state) {
643 case CLOSING:
644 UNTIMEOUT(fsm_timeout, f);
645 f->state = CLOSED;
646 if (f->callbacks->finished != NULL)
647 (*f->callbacks->finished)(f);
648 break;
649 case STOPPING:
650 UNTIMEOUT(fsm_timeout, f);
651 f->state = STOPPED;
652 if (f->callbacks->finished != NULL)
653 (*f->callbacks->finished)(f);
654 break;
656 case ACKRCVD:
657 f->state = REQSENT;
658 break;
660 case OPENED:
661 fsm_sconfreq(f, 0);
662 f->state = REQSENT;
663 if (f->callbacks->down != NULL)
664 (*f->callbacks->down)(f); /* Inform upper layers */
665 break;
671 * fsm_rcoderej - Receive a Code-Reject.
673 static void
674 fsm_rcoderej(f, inp, len)
675 fsm *f;
676 u_char *inp;
677 int len;
679 u_char code, id;
680 int seriouserr;
682 if (len < HEADERLEN) {
683 error("%s: Code-Reject too short (%d < %d)", PROTO_NAME(f), len,
684 HEADERLEN);
685 return;
687 GETCHAR(code, inp);
688 GETCHAR(id, inp);
689 len -= 2;
690 warn("%s: Rcvd Code-Reject for %s id %d", PROTO_NAME(f),
691 code_name(code,0), id);
693 setbit(f->codemask, code);
695 /* Let the protocol know what happened. */
696 if (f->callbacks->codereject != NULL) {
697 seriouserr = (*f->callbacks->codereject)(f,code,id,inp,len);
698 } else {
700 * By default, it's RXJ- for well-known codes and RXJ+ for
701 * unknown ones.
703 seriouserr = (code >= CODE_CONFREQ && code <= CODE_CODEREJ);
706 if (seriouserr) {
707 /* RXJ- -- shut down the protocol. */
708 switch (f->state) {
709 case CLOSING:
710 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
711 /*FALLTHROUGH*/
712 case CLOSED:
713 f->state = CLOSED;
714 if (f->callbacks->finished != NULL)
715 (*f->callbacks->finished)(f);
716 break;
718 case STOPPING:
719 case REQSENT:
720 case ACKRCVD:
721 case ACKSENT:
722 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
723 f->state = STOPPED;
724 /*FALLTHROUGH*/
725 case STOPPED:
726 if (f->callbacks->finished != NULL)
727 (*f->callbacks->finished)(f);
728 break;
730 case OPENED:
731 f->state = STOPPING;
732 if (f->callbacks->down != NULL)
733 (*f->callbacks->down)(f);
735 if (f->term_reason == NULL) {
736 f->term_reason = "unacceptable Code-Reject received";
737 f->term_reason_len = strlen(f->term_reason);
740 /* Init restart counter, send Terminate-Request */
741 f->retransmits = f->maxtermtransmits;
742 fsm_sdata(f, CODE_TERMREQ, f->reqid = ++f->id,
743 (u_char *) f->term_reason, f->term_reason_len);
744 TIMEOUT(fsm_timeout, f, f->timeouttime);
745 --f->retransmits;
746 break;
748 default:
749 fatal("state error");
751 } else {
752 /* RXJ+ -- just back up from Ack-Rcvd to Req-Sent. */
753 if (f->state == ACKRCVD)
754 f->state = REQSENT;
760 * fsm_protreject - Peer doesn't speak this protocol.
762 * Treat this as a catastrophic error (RXJ-).
764 void
765 fsm_protreject(f)
766 fsm *f;
768 switch( f->state ){
769 case CLOSING:
770 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
771 /*FALLTHROUGH*/
772 case CLOSED:
773 f->state = CLOSED;
774 if (f->callbacks->finished != NULL)
775 (*f->callbacks->finished)(f);
776 break;
778 case STOPPING:
779 case REQSENT:
780 case ACKRCVD:
781 case ACKSENT:
782 UNTIMEOUT(fsm_timeout, f); /* Cancel timeout */
783 /*FALLTHROUGH*/
784 case STOPPED:
785 f->state = STOPPED;
786 if (f->callbacks->finished != NULL)
787 (*f->callbacks->finished)(f);
788 break;
790 case OPENED:
791 f->state = STOPPING;
792 if (f->callbacks->down != NULL)
793 (*f->callbacks->down)(f);
795 /* Init restart counter, send Terminate-Request */
796 f->retransmits = f->maxtermtransmits;
797 fsm_sdata(f, CODE_TERMREQ, f->reqid = ++f->id,
798 (u_char *) f->term_reason, f->term_reason_len);
799 TIMEOUT(fsm_timeout, f, f->timeouttime);
800 --f->retransmits;
801 break;
803 default:
804 dbglog("%s: Protocol-Reject in state %s", PROTO_NAME(f),
805 fsm_state(f->state));
811 * fsm_sconfreq - Send a Configure-Request.
813 static void
814 fsm_sconfreq(f, retransmit)
815 fsm *f;
816 int retransmit;
818 u_char *outp;
819 int cilen;
821 if( f->state != REQSENT && f->state != ACKRCVD && f->state != ACKSENT ){
822 /* Not currently negotiating - reset options */
823 if (f->callbacks->resetci != NULL)
824 (*f->callbacks->resetci)(f);
825 f->nakloops = 0;
828 if( !retransmit ){
829 /* New request - reset retransmission counter, use new ID */
830 f->retransmits = f->maxconfreqtransmits;
831 f->reqid = ++f->id;
834 f->seen_ack = 0;
837 * Make up the request packet
839 outp = outpacket_buf + PPP_HDRLEN + HEADERLEN;
840 if (f->callbacks->cilen != NULL) {
841 cilen = (*f->callbacks->cilen)(f);
842 if (cilen > peer_mru[f->unit] - HEADERLEN)
843 cilen = peer_mru[f->unit] - HEADERLEN;
844 } else {
845 cilen = peer_mru[f->unit] - HEADERLEN;
848 if (f->callbacks->addci != NULL)
849 (*f->callbacks->addci)(f, outp, &cilen);
850 else
851 cilen = 0;
853 /* send the request to our peer */
854 fsm_sdata(f, CODE_CONFREQ, f->reqid, outp, cilen);
856 /* start the retransmit timer */
857 --f->retransmits;
858 TIMEOUT(fsm_timeout, f, f->timeouttime);
863 * fsm_sdata - Send some data.
865 * Used for all packets sent to our peer by this module.
867 void
868 fsm_sdata(f, code, id, data, datalen)
869 fsm *f;
870 u_char code, id;
871 u_char *data;
872 int datalen;
874 u_char *outp;
875 int outlen;
877 if (isset(f->codemask,code)) {
878 dbglog("%s: Peer has rejected %s; not sending another",
879 PROTO_NAME(f), code_name(code,0));
880 return;
883 /* Adjust length to be smaller than MTU */
884 outp = outpacket_buf;
885 if (datalen > peer_mru[f->unit] - HEADERLEN)
886 datalen = peer_mru[f->unit] - HEADERLEN;
887 if (datalen && data != outp + PPP_HDRLEN + HEADERLEN)
888 BCOPY(data, outp + PPP_HDRLEN + HEADERLEN, datalen);
889 outlen = datalen + HEADERLEN;
890 MAKEHEADER(outp, f->protocol);
891 PUTCHAR(code, outp);
892 PUTCHAR(id, outp);
893 PUTSHORT(outlen, outp);
894 output(f->unit, outpacket_buf, outlen + PPP_HDRLEN);
898 * fsm_setpeermru - Set our idea of the peer's mru
900 * Used by routines in lcp.c which negotiate this value.
902 void
903 fsm_setpeermru(unit, mru)
904 int unit;
905 int mru;
907 if (unit >= NUM_PPP) {
908 dbglog("fsm_setpeermru: unit out of bounds");
909 } else {
910 peer_mru[unit] = mru;