Deleted Added
full compact
lcp.c (44106) lcp.c (44305)
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.67 1999/01/28 01:56:32 brian Exp $
20 * $Id: lcp.c,v 1.68 1999/02/18 00:52:14 brian Exp $
21 *
22 * TODO:
23 * o Limit data field length by MRU
24 */
25
26#include <sys/param.h>
27#include <netinet/in.h>
28#include <netinet/in_systm.h>

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

76 u_short proto; /* Quality protocol */
77 u_int32_t period; /* Reporting interval */
78};
79
80static int LcpLayerUp(struct fsm *);
81static void LcpLayerDown(struct fsm *);
82static void LcpLayerStart(struct fsm *);
83static void LcpLayerFinish(struct fsm *);
21 *
22 * TODO:
23 * o Limit data field length by MRU
24 */
25
26#include <sys/param.h>
27#include <netinet/in.h>
28#include <netinet/in_systm.h>

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

76 u_short proto; /* Quality protocol */
77 u_int32_t period; /* Reporting interval */
78};
79
80static int LcpLayerUp(struct fsm *);
81static void LcpLayerDown(struct fsm *);
82static void LcpLayerStart(struct fsm *);
83static void LcpLayerFinish(struct fsm *);
84static void LcpInitRestartCounter(struct fsm *);
84static void LcpInitRestartCounter(struct fsm *, int);
85static void LcpSendConfigReq(struct fsm *);
86static void LcpSentTerminateReq(struct fsm *);
87static void LcpSendTerminateAck(struct fsm *, u_char);
88static void LcpDecodeConfig(struct fsm *, u_char *, int, int,
89 struct fsm_decode *);
90
91static struct fsm_callbacks lcp_Callbacks = {
92 LcpLayerUp,

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

166 prompt_Printf(arg->prompt, "\n Defaults: MRU = %d, ", lcp->cfg.mru);
167 prompt_Printf(arg->prompt, "ACCMAP = %08lx\n", (u_long)lcp->cfg.accmap);
168 prompt_Printf(arg->prompt, " LQR period = %us, ",
169 lcp->cfg.lqrperiod);
170 prompt_Printf(arg->prompt, "Open Mode = %s",
171 lcp->cfg.openmode == OPEN_PASSIVE ? "passive" : "active");
172 if (lcp->cfg.openmode > 0)
173 prompt_Printf(arg->prompt, " (delay %ds)", lcp->cfg.openmode);
85static void LcpSendConfigReq(struct fsm *);
86static void LcpSentTerminateReq(struct fsm *);
87static void LcpSendTerminateAck(struct fsm *, u_char);
88static void LcpDecodeConfig(struct fsm *, u_char *, int, int,
89 struct fsm_decode *);
90
91static struct fsm_callbacks lcp_Callbacks = {
92 LcpLayerUp,

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

166 prompt_Printf(arg->prompt, "\n Defaults: MRU = %d, ", lcp->cfg.mru);
167 prompt_Printf(arg->prompt, "ACCMAP = %08lx\n", (u_long)lcp->cfg.accmap);
168 prompt_Printf(arg->prompt, " LQR period = %us, ",
169 lcp->cfg.lqrperiod);
170 prompt_Printf(arg->prompt, "Open Mode = %s",
171 lcp->cfg.openmode == OPEN_PASSIVE ? "passive" : "active");
172 if (lcp->cfg.openmode > 0)
173 prompt_Printf(arg->prompt, " (delay %ds)", lcp->cfg.openmode);
174 prompt_Printf(arg->prompt, "\n FSM retry = %us\n",
175 lcp->cfg.fsmretry);
174 prompt_Printf(arg->prompt, "\n FSM retry = %us, max %u Config"
175 " REQ%s, %u Term REQ%s\n", lcp->cfg.fsm.timeout,
176 lcp->cfg.fsm.maxreq, lcp->cfg.fsm.maxreq == 1 ? "" : "s",
177 lcp->cfg.fsm.maxtrm, lcp->cfg.fsm.maxtrm == 1 ? "" : "s");
176 prompt_Printf(arg->prompt, "\n Negotiation:\n");
177 prompt_Printf(arg->prompt, " ACFCOMP = %s\n",
178 command_ShowNegval(lcp->cfg.acfcomp));
179 prompt_Printf(arg->prompt, " CHAP = %s\n",
180 command_ShowNegval(lcp->cfg.chap05));
181#ifdef HAVE_DES
182 prompt_Printf(arg->prompt, " MSCHAP = %s\n",
183 command_ShowNegval(lcp->cfg.chap80nt));

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

213
214void
215lcp_Init(struct lcp *lcp, struct bundle *bundle, struct link *l,
216 const struct fsm_parent *parent)
217{
218 /* Initialise ourselves */
219 int mincode = parent ? 1 : LCP_MINMPCODE;
220
178 prompt_Printf(arg->prompt, "\n Negotiation:\n");
179 prompt_Printf(arg->prompt, " ACFCOMP = %s\n",
180 command_ShowNegval(lcp->cfg.acfcomp));
181 prompt_Printf(arg->prompt, " CHAP = %s\n",
182 command_ShowNegval(lcp->cfg.chap05));
183#ifdef HAVE_DES
184 prompt_Printf(arg->prompt, " MSCHAP = %s\n",
185 command_ShowNegval(lcp->cfg.chap80nt));

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

215
216void
217lcp_Init(struct lcp *lcp, struct bundle *bundle, struct link *l,
218 const struct fsm_parent *parent)
219{
220 /* Initialise ourselves */
221 int mincode = parent ? 1 : LCP_MINMPCODE;
222
221 fsm_Init(&lcp->fsm, "LCP", PROTO_LCP, mincode, LCP_MAXCODE, 10, LogLCP,
223 fsm_Init(&lcp->fsm, "LCP", PROTO_LCP, mincode, LCP_MAXCODE, LogLCP,
222 bundle, l, parent, &lcp_Callbacks, lcp_TimerNames);
223
224 lcp->cfg.mru = DEF_MRU;
225 lcp->cfg.accmap = 0;
226 lcp->cfg.openmode = 1;
227 lcp->cfg.lqrperiod = DEF_LQRPERIOD;
224 bundle, l, parent, &lcp_Callbacks, lcp_TimerNames);
225
226 lcp->cfg.mru = DEF_MRU;
227 lcp->cfg.accmap = 0;
228 lcp->cfg.openmode = 1;
229 lcp->cfg.lqrperiod = DEF_LQRPERIOD;
228 lcp->cfg.fsmretry = DEF_FSMRETRY;
230 lcp->cfg.fsm.timeout = DEF_FSMRETRY;
231 lcp->cfg.fsm.maxreq = DEF_FSMTRIES;
232 lcp->cfg.fsm.maxtrm = DEF_FSMTRIES;
229
230 lcp->cfg.acfcomp = NEG_ENABLED|NEG_ACCEPTED;
231 lcp->cfg.chap05 = NEG_ACCEPTED;
232#ifdef HAVE_DES
233 lcp->cfg.chap80nt = NEG_ACCEPTED;
234 lcp->cfg.chap80lm = NEG_ACCEPTED;
235#endif
236 lcp->cfg.lqr = NEG_ACCEPTED;
237 lcp->cfg.pap = NEG_ACCEPTED;
238 lcp->cfg.protocomp = NEG_ENABLED|NEG_ACCEPTED;
239
240 lcp_Setup(lcp, lcp->cfg.openmode);
241}
242
243void
244lcp_Setup(struct lcp *lcp, int openmode)
245{
246 lcp->fsm.open_mode = openmode;
233
234 lcp->cfg.acfcomp = NEG_ENABLED|NEG_ACCEPTED;
235 lcp->cfg.chap05 = NEG_ACCEPTED;
236#ifdef HAVE_DES
237 lcp->cfg.chap80nt = NEG_ACCEPTED;
238 lcp->cfg.chap80lm = NEG_ACCEPTED;
239#endif
240 lcp->cfg.lqr = NEG_ACCEPTED;
241 lcp->cfg.pap = NEG_ACCEPTED;
242 lcp->cfg.protocomp = NEG_ENABLED|NEG_ACCEPTED;
243
244 lcp_Setup(lcp, lcp->cfg.openmode);
245}
246
247void
248lcp_Setup(struct lcp *lcp, int openmode)
249{
250 lcp->fsm.open_mode = openmode;
247 lcp->fsm.maxconfig = 10;
248
249 lcp->his_mru = lcp->fsm.bundle->cfg.mtu;
250 if (!lcp->his_mru || lcp->his_mru > DEF_MRU)
251 lcp->his_mru = DEF_MRU;
252 lcp->his_mrru = 0;
253 lcp->his_magic = 0;
254 lcp->his_lqrperiod = 0;
255 lcp->his_acfcomp = 0;

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

306 }
307
308 lcp->his_reject = lcp->my_reject = 0;
309 lcp->auth_iwait = lcp->auth_ineed = 0;
310 lcp->LcpFailedMagic = 0;
311}
312
313static void
251
252 lcp->his_mru = lcp->fsm.bundle->cfg.mtu;
253 if (!lcp->his_mru || lcp->his_mru > DEF_MRU)
254 lcp->his_mru = DEF_MRU;
255 lcp->his_mrru = 0;
256 lcp->his_magic = 0;
257 lcp->his_lqrperiod = 0;
258 lcp->his_acfcomp = 0;

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

309 }
310
311 lcp->his_reject = lcp->my_reject = 0;
312 lcp->auth_iwait = lcp->auth_ineed = 0;
313 lcp->LcpFailedMagic = 0;
314}
315
316static void
314LcpInitRestartCounter(struct fsm * fp)
317LcpInitRestartCounter(struct fsm *fp, int what)
315{
316 /* Set fsm timer load */
317 struct lcp *lcp = fsm2lcp(fp);
318
318{
319 /* Set fsm timer load */
320 struct lcp *lcp = fsm2lcp(fp);
321
319 fp->FsmTimer.load = lcp->cfg.fsmretry * SECTICKS;
320 fp->restart = DEF_REQs;
322 fp->FsmTimer.load = lcp->cfg.fsm.timeout * SECTICKS;
323 switch (what) {
324 case FSM_REQ_TIMER:
325 fp->restart = lcp->cfg.fsm.maxreq;
326 break;
327 case FSM_TRM_TIMER:
328 fp->restart = lcp->cfg.fsm.maxtrm;
329 break;
330 default:
331 fp->restart = 1;
332 break;
333 }
321}
322
323static void
324LcpSendConfigReq(struct fsm *fp)
325{
326 /* Send config REQ please */
327 struct physical *p = link2physical(fp->link);
328 struct lcp *lcp = fsm2lcp(fp);

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

424void
425lcp_SendProtoRej(struct lcp *lcp, u_char *option, int count)
426{
427 /* Don't understand `option' */
428 fsm_Output(&lcp->fsm, CODE_PROTOREJ, lcp->fsm.reqid, option, count);
429}
430
431static void
334}
335
336static void
337LcpSendConfigReq(struct fsm *fp)
338{
339 /* Send config REQ please */
340 struct physical *p = link2physical(fp->link);
341 struct lcp *lcp = fsm2lcp(fp);

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

437void
438lcp_SendProtoRej(struct lcp *lcp, u_char *option, int count)
439{
440 /* Don't understand `option' */
441 fsm_Output(&lcp->fsm, CODE_PROTOREJ, lcp->fsm.reqid, option, count);
442}
443
444static void
432LcpSentTerminateReq(struct fsm * fp)
445LcpSentTerminateReq(struct fsm *fp)
433{
434 /* Term REQ just sent by FSM */
435}
436
437static void
438LcpSendTerminateAck(struct fsm *fp, u_char id)
439{
440 /* Send Term ACK please */

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

449static void
450LcpLayerStart(struct fsm *fp)
451{
452 /* We're about to start up ! */
453 struct lcp *lcp = fsm2lcp(fp);
454
455 log_Printf(LogLCP, "%s: LayerStart\n", fp->link->name);
456 lcp->LcpFailedMagic = 0;
446{
447 /* Term REQ just sent by FSM */
448}
449
450static void
451LcpSendTerminateAck(struct fsm *fp, u_char id)
452{
453 /* Send Term ACK please */

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

462static void
463LcpLayerStart(struct fsm *fp)
464{
465 /* We're about to start up ! */
466 struct lcp *lcp = fsm2lcp(fp);
467
468 log_Printf(LogLCP, "%s: LayerStart\n", fp->link->name);
469 lcp->LcpFailedMagic = 0;
470 fp->more.reqs = fp->more.naks = fp->more.rejs = lcp->cfg.fsm.maxreq * 3;
457}
458
459static void
460LcpLayerFinish(struct fsm *fp)
461{
462 /* We're now down */
463 log_Printf(LogLCP, "%s: LayerFinish\n", fp->link->name);
464}

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

469 /* We're now up */
470 struct physical *p = link2physical(fp->link);
471 struct lcp *lcp = fsm2lcp(fp);
472
473 log_Printf(LogLCP, "%s: LayerUp\n", fp->link->name);
474 async_SetLinkParams(&p->async, lcp);
475 lqr_Start(lcp);
476 hdlc_StartTimer(&p->hdlc);
471}
472
473static void
474LcpLayerFinish(struct fsm *fp)
475{
476 /* We're now down */
477 log_Printf(LogLCP, "%s: LayerFinish\n", fp->link->name);
478}

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

483 /* We're now up */
484 struct physical *p = link2physical(fp->link);
485 struct lcp *lcp = fsm2lcp(fp);
486
487 log_Printf(LogLCP, "%s: LayerUp\n", fp->link->name);
488 async_SetLinkParams(&p->async, lcp);
489 lqr_Start(lcp);
490 hdlc_StartTimer(&p->hdlc);
491 fp->more.reqs = fp->more.naks = fp->more.rejs = lcp->cfg.fsm.maxreq * 3;
492
477 return 1;
478}
479
480static void
481LcpLayerDown(struct fsm *fp)
482{
483 /* About to come down */
484 struct physical *p = link2physical(fp->link);

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

759#endif
760 } else {
761#ifndef HAVE_DES
762 if (cp[4] == 0x80)
763 log_Printf(LogLCP, "Peer will only send MSCHAP (not available"
764 " without DES)\n");
765 else
766#endif
493 return 1;
494}
495
496static void
497LcpLayerDown(struct fsm *fp)
498{
499 /* About to come down */
500 struct physical *p = link2physical(fp->link);

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

775#endif
776 } else {
777#ifndef HAVE_DES
778 if (cp[4] == 0x80)
779 log_Printf(LogLCP, "Peer will only send MSCHAP (not available"
780 " without DES)\n");
781 else
782#endif
767 log_Printf(LogLCP, "Peer will only send %s (not supported)\n",
768 Auth2Nam(PROTO_CHAP, cp[4]));
783 log_Printf(LogLCP, "Peer will only send %s (not %s)\n",
784 Auth2Nam(PROTO_CHAP, cp[4]),
785#ifdef HAVE_DES
786 cp[4] == 0x80 ? "configured" :
787#endif
788 "supported");
769 lcp->his_reject |= (1 << type);
770 }
771 break;
772 default:
773 /* We've been NAK'd with something we don't understand :-( */
774 lcp->his_reject |= (1 << type);
775 break;
776 }

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

1057 cp[2]);
1058 else
1059 log_Printf(LogLCP, " ENDDISC rejected - local max length is %ld\n",
1060 (long)(sizeof p->dl->peer.enddisc.address - 1));
1061 goto reqreject;
1062 }
1063 break;
1064
789 lcp->his_reject |= (1 << type);
790 }
791 break;
792 default:
793 /* We've been NAK'd with something we don't understand :-( */
794 lcp->his_reject |= (1 << type);
795 break;
796 }

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

1077 cp[2]);
1078 else
1079 log_Printf(LogLCP, " ENDDISC rejected - local max length is %ld\n",
1080 (long)(sizeof p->dl->peer.enddisc.address - 1));
1081 goto reqreject;
1082 }
1083 break;
1084
1065 case MODE_NAK: /* Treat this as a REJ, we don't vary or disc */
1085 case MODE_NAK: /* Treat this as a REJ, we don't vary our disc */
1066 case MODE_REJ:
1067 lcp->his_reject |= (1 << type);
1068 break;
1069 }
1070 break;
1071
1072 default:
1073 sz = (sizeof desc - 2) / 2;

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

1125 dec->nakend = dec->nak;
1126 } else if (dec->nakend != dec->nak)
1127 /* then NAKs */
1128 dec->ackend = dec->ack;
1129 }
1130}
1131
1132void
1086 case MODE_REJ:
1087 lcp->his_reject |= (1 << type);
1088 break;
1089 }
1090 break;
1091
1092 default:
1093 sz = (sizeof desc - 2) / 2;

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

1145 dec->nakend = dec->nak;
1146 } else if (dec->nakend != dec->nak)
1147 /* then NAKs */
1148 dec->ackend = dec->ack;
1149 }
1150}
1151
1152void
1133lcp_Input(struct lcp *lcp, struct mbuf * bp)
1153lcp_Input(struct lcp *lcp, struct mbuf *bp)
1134{
1135 /* Got PROTO_LCP from link */
1136 fsm_Input(&lcp->fsm, bp);
1137}
1154{
1155 /* Got PROTO_LCP from link */
1156 fsm_Input(&lcp->fsm, bp);
1157}