Deleted Added
full compact
ccp.c (43693) ccp.c (44305)
1/*
2 * PPP Compression Control Protocol (CCP) Module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1994, 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 Compression Control Protocol (CCP) Module
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1994, 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: ccp.c,v 1.41 1999/01/28 01:56:30 brian Exp $
20 * $Id: ccp.c,v 1.42 1999/02/06 02:54:44 brian Exp $
21 *
22 * TODO:
23 * o Support other compression protocols
24 */
25#include <sys/param.h>
26#include <netinet/in.h>
27#include <netinet/in_systm.h>
28#include <netinet/ip.h>

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

65static void CcpSentTerminateReq(struct fsm *);
66static void CcpSendTerminateAck(struct fsm *, u_char);
67static void CcpDecodeConfig(struct fsm *, u_char *, int, int,
68 struct fsm_decode *);
69static void CcpLayerStart(struct fsm *);
70static void CcpLayerFinish(struct fsm *);
71static int CcpLayerUp(struct fsm *);
72static void CcpLayerDown(struct fsm *);
21 *
22 * TODO:
23 * o Support other compression protocols
24 */
25#include <sys/param.h>
26#include <netinet/in.h>
27#include <netinet/in_systm.h>
28#include <netinet/ip.h>

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

65static void CcpSentTerminateReq(struct fsm *);
66static void CcpSendTerminateAck(struct fsm *, u_char);
67static void CcpDecodeConfig(struct fsm *, u_char *, int, int,
68 struct fsm_decode *);
69static void CcpLayerStart(struct fsm *);
70static void CcpLayerFinish(struct fsm *);
71static int CcpLayerUp(struct fsm *);
72static void CcpLayerDown(struct fsm *);
73static void CcpInitRestartCounter(struct fsm *);
73static void CcpInitRestartCounter(struct fsm *, int);
74static void CcpRecvResetReq(struct fsm *);
75static void CcpRecvResetAck(struct fsm *, u_char);
76
77static struct fsm_callbacks ccp_Callbacks = {
78 CcpLayerUp,
79 CcpLayerDown,
80 CcpLayerStart,
81 CcpLayerFinish,

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

145 State2Nam(ccp->fsm.state));
146 prompt_Printf(arg->prompt, " My protocol = %s, His protocol = %s\n",
147 protoname(ccp->my_proto), protoname(ccp->his_proto));
148 prompt_Printf(arg->prompt, " Output: %ld --> %ld, Input: %ld --> %ld\n",
149 ccp->uncompout, ccp->compout,
150 ccp->compin, ccp->uncompin);
151
152 prompt_Printf(arg->prompt, "\n Defaults: ");
74static void CcpRecvResetReq(struct fsm *);
75static void CcpRecvResetAck(struct fsm *, u_char);
76
77static struct fsm_callbacks ccp_Callbacks = {
78 CcpLayerUp,
79 CcpLayerDown,
80 CcpLayerStart,
81 CcpLayerFinish,

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

145 State2Nam(ccp->fsm.state));
146 prompt_Printf(arg->prompt, " My protocol = %s, His protocol = %s\n",
147 protoname(ccp->my_proto), protoname(ccp->his_proto));
148 prompt_Printf(arg->prompt, " Output: %ld --> %ld, Input: %ld --> %ld\n",
149 ccp->uncompout, ccp->compout,
150 ccp->compin, ccp->uncompin);
151
152 prompt_Printf(arg->prompt, "\n Defaults: ");
153 prompt_Printf(arg->prompt, "FSM retry = %us\n", ccp->cfg.fsmretry);
153 prompt_Printf(arg->prompt, "FSM retry = %us, max %u Config"
154 " REQ%s, %u Term REQ%s\n", ccp->cfg.fsm.timeout,
155 ccp->cfg.fsm.maxreq, ccp->cfg.fsm.maxreq == 1 ? "" : "s",
156 ccp->cfg.fsm.maxtrm, ccp->cfg.fsm.maxtrm == 1 ? "" : "s");
154 prompt_Printf(arg->prompt, " deflate windows: ");
155 prompt_Printf(arg->prompt, "incoming = %d, ", ccp->cfg.deflate.in.winsize);
156 prompt_Printf(arg->prompt, "outgoing = %d\n", ccp->cfg.deflate.out.winsize);
157 prompt_Printf(arg->prompt, " DEFLATE: %s\n",
158 command_ShowNegval(ccp->cfg.neg[CCP_NEG_DEFLATE]));
159 prompt_Printf(arg->prompt, " PREDICTOR1: %s\n",
160 command_ShowNegval(ccp->cfg.neg[CCP_NEG_PRED1]));
161 prompt_Printf(arg->prompt, " DEFLATE24: %s\n",

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

173}
174
175void
176ccp_Init(struct ccp *ccp, struct bundle *bundle, struct link *l,
177 const struct fsm_parent *parent)
178{
179 /* Initialise ourselves */
180
157 prompt_Printf(arg->prompt, " deflate windows: ");
158 prompt_Printf(arg->prompt, "incoming = %d, ", ccp->cfg.deflate.in.winsize);
159 prompt_Printf(arg->prompt, "outgoing = %d\n", ccp->cfg.deflate.out.winsize);
160 prompt_Printf(arg->prompt, " DEFLATE: %s\n",
161 command_ShowNegval(ccp->cfg.neg[CCP_NEG_DEFLATE]));
162 prompt_Printf(arg->prompt, " PREDICTOR1: %s\n",
163 command_ShowNegval(ccp->cfg.neg[CCP_NEG_PRED1]));
164 prompt_Printf(arg->prompt, " DEFLATE24: %s\n",

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

176}
177
178void
179ccp_Init(struct ccp *ccp, struct bundle *bundle, struct link *l,
180 const struct fsm_parent *parent)
181{
182 /* Initialise ourselves */
183
181 fsm_Init(&ccp->fsm, "CCP", PROTO_CCP, 1, CCP_MAXCODE, 10, LogCCP,
184 fsm_Init(&ccp->fsm, "CCP", PROTO_CCP, 1, CCP_MAXCODE, LogCCP,
182 bundle, l, parent, &ccp_Callbacks, ccp_TimerNames);
183
184 ccp->cfg.deflate.in.winsize = 0;
185 ccp->cfg.deflate.out.winsize = 15;
185 bundle, l, parent, &ccp_Callbacks, ccp_TimerNames);
186
187 ccp->cfg.deflate.in.winsize = 0;
188 ccp->cfg.deflate.out.winsize = 15;
186 ccp->cfg.fsmretry = DEF_FSMRETRY;
189 ccp->cfg.fsm.timeout = DEF_FSMRETRY;
190 ccp->cfg.fsm.maxreq = DEF_FSMTRIES;
191 ccp->cfg.fsm.maxtrm = DEF_FSMTRIES;
187 ccp->cfg.neg[CCP_NEG_DEFLATE] = NEG_ENABLED|NEG_ACCEPTED;
188 ccp->cfg.neg[CCP_NEG_PRED1] = NEG_ENABLED|NEG_ACCEPTED;
189 ccp->cfg.neg[CCP_NEG_DEFLATE24] = 0;
190
191 ccp_Setup(ccp);
192}
193
194void
195ccp_Setup(struct ccp *ccp)
196{
197 /* Set ourselves up for a startup */
198 ccp->fsm.open_mode = 0;
192 ccp->cfg.neg[CCP_NEG_DEFLATE] = NEG_ENABLED|NEG_ACCEPTED;
193 ccp->cfg.neg[CCP_NEG_PRED1] = NEG_ENABLED|NEG_ACCEPTED;
194 ccp->cfg.neg[CCP_NEG_DEFLATE24] = 0;
195
196 ccp_Setup(ccp);
197}
198
199void
200ccp_Setup(struct ccp *ccp)
201{
202 /* Set ourselves up for a startup */
203 ccp->fsm.open_mode = 0;
199 ccp->fsm.maxconfig = 10;
200 ccp->his_proto = ccp->my_proto = -1;
201 ccp->reset_sent = ccp->last_reset = -1;
202 ccp->in.algorithm = ccp->out.algorithm = -1;
203 ccp->in.state = ccp->out.state = NULL;
204 ccp->in.opt.id = -1;
205 ccp->out.opt = NULL;
206 ccp->his_reject = ccp->my_reject = 0;
207 ccp->uncompout = ccp->compout = 0;
208 ccp->uncompin = ccp->compin = 0;
209}
210
211static void
204 ccp->his_proto = ccp->my_proto = -1;
205 ccp->reset_sent = ccp->last_reset = -1;
206 ccp->in.algorithm = ccp->out.algorithm = -1;
207 ccp->in.state = ccp->out.state = NULL;
208 ccp->in.opt.id = -1;
209 ccp->out.opt = NULL;
210 ccp->his_reject = ccp->my_reject = 0;
211 ccp->uncompout = ccp->compout = 0;
212 ccp->uncompin = ccp->compin = 0;
213}
214
215static void
212CcpInitRestartCounter(struct fsm *fp)
216CcpInitRestartCounter(struct fsm *fp, int what)
213{
214 /* Set fsm timer load */
215 struct ccp *ccp = fsm2ccp(fp);
216
217{
218 /* Set fsm timer load */
219 struct ccp *ccp = fsm2ccp(fp);
220
217 fp->FsmTimer.load = ccp->cfg.fsmretry * SECTICKS;
218 fp->restart = DEF_REQs;
221 fp->FsmTimer.load = ccp->cfg.fsm.timeout * SECTICKS;
222 switch (what) {
223 case FSM_REQ_TIMER:
224 fp->restart = ccp->cfg.fsm.maxreq;
225 break;
226 case FSM_TRM_TIMER:
227 fp->restart = ccp->cfg.fsm.maxtrm;
228 break;
229 default:
230 fp->restart = 1;
231 break;
232 }
219}
220
221static void
222CcpSendConfigReq(struct fsm *fp)
223{
224 /* Send config REQ please */
225 struct ccp *ccp = fsm2ccp(fp);
226 struct ccp_opt **o;

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

299 if (ccp->out.state != NULL)
300 (*algorithm[ccp->out.algorithm]->o.Reset)(ccp->out.state);
301}
302
303static void
304CcpLayerStart(struct fsm *fp)
305{
306 /* We're about to start up ! */
233}
234
235static void
236CcpSendConfigReq(struct fsm *fp)
237{
238 /* Send config REQ please */
239 struct ccp *ccp = fsm2ccp(fp);
240 struct ccp_opt **o;

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

313 if (ccp->out.state != NULL)
314 (*algorithm[ccp->out.algorithm]->o.Reset)(ccp->out.state);
315}
316
317static void
318CcpLayerStart(struct fsm *fp)
319{
320 /* We're about to start up ! */
321 struct ccp *ccp = fsm2ccp(fp);
322
307 log_Printf(LogCCP, "%s: LayerStart.\n", fp->link->name);
323 log_Printf(LogCCP, "%s: LayerStart.\n", fp->link->name);
324 fp->more.reqs = fp->more.naks = fp->more.rejs = ccp->cfg.fsm.maxreq * 3;
308}
309
310static void
311CcpLayerDown(struct fsm *fp)
312{
313 /* About to come down */
314 struct ccp *ccp = fsm2ccp(fp);
315 struct ccp_opt *next;

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

345/*
346 * Called when CCP has reached the OPEN state
347 */
348static int
349CcpLayerUp(struct fsm *fp)
350{
351 /* We're now up */
352 struct ccp *ccp = fsm2ccp(fp);
325}
326
327static void
328CcpLayerDown(struct fsm *fp)
329{
330 /* About to come down */
331 struct ccp *ccp = fsm2ccp(fp);
332 struct ccp_opt *next;

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

362/*
363 * Called when CCP has reached the OPEN state
364 */
365static int
366CcpLayerUp(struct fsm *fp)
367{
368 /* We're now up */
369 struct ccp *ccp = fsm2ccp(fp);
370
353 log_Printf(LogCCP, "%s: LayerUp.\n", fp->link->name);
371 log_Printf(LogCCP, "%s: LayerUp.\n", fp->link->name);
372
354 if (ccp->in.state == NULL && ccp->in.algorithm >= 0 &&
355 ccp->in.algorithm < NALGORITHMS) {
356 ccp->in.state = (*algorithm[ccp->in.algorithm]->i.Init)(&ccp->in.opt);
357 if (ccp->in.state == NULL) {
358 log_Printf(LogERROR, "%s: %s (in) initialisation failure\n",
359 fp->link->name, protoname(ccp->his_proto));
360 ccp->his_proto = ccp->my_proto = -1;
361 fsm_Close(fp);
373 if (ccp->in.state == NULL && ccp->in.algorithm >= 0 &&
374 ccp->in.algorithm < NALGORITHMS) {
375 ccp->in.state = (*algorithm[ccp->in.algorithm]->i.Init)(&ccp->in.opt);
376 if (ccp->in.state == NULL) {
377 log_Printf(LogERROR, "%s: %s (in) initialisation failure\n",
378 fp->link->name, protoname(ccp->his_proto));
379 ccp->his_proto = ccp->my_proto = -1;
380 fsm_Close(fp);
381 return 0;
362 }
363 }
364
365 if (ccp->out.state == NULL && ccp->out.algorithm >= 0 &&
366 ccp->out.algorithm < NALGORITHMS) {
367 ccp->out.state = (*algorithm[ccp->out.algorithm]->o.Init)
368 (&ccp->out.opt->val);
369 if (ccp->out.state == NULL) {
370 log_Printf(LogERROR, "%s: %s (out) initialisation failure\n",
371 fp->link->name, protoname(ccp->my_proto));
372 ccp->his_proto = ccp->my_proto = -1;
373 fsm_Close(fp);
382 }
383 }
384
385 if (ccp->out.state == NULL && ccp->out.algorithm >= 0 &&
386 ccp->out.algorithm < NALGORITHMS) {
387 ccp->out.state = (*algorithm[ccp->out.algorithm]->o.Init)
388 (&ccp->out.opt->val);
389 if (ccp->out.state == NULL) {
390 log_Printf(LogERROR, "%s: %s (out) initialisation failure\n",
391 fp->link->name, protoname(ccp->my_proto));
392 ccp->his_proto = ccp->my_proto = -1;
393 fsm_Close(fp);
394 return 0;
374 }
375 }
376
395 }
396 }
397
398 fp->more.reqs = fp->more.naks = fp->more.rejs = ccp->cfg.fsm.maxreq * 3;
399
377 log_Printf(LogCCP, "%s: Out = %s[%d], In = %s[%d]\n",
378 fp->link->name, protoname(ccp->my_proto), ccp->my_proto,
379 protoname(ccp->his_proto), ccp->his_proto);
400 log_Printf(LogCCP, "%s: Out = %s[%d], In = %s[%d]\n",
401 fp->link->name, protoname(ccp->my_proto), ccp->my_proto,
402 protoname(ccp->his_proto), ccp->his_proto);
403
380 return 1;
381}
382
383static void
384CcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
385 struct fsm_decode *dec)
386{
387 /* Deal with incoming data */

--- 226 unchanged lines hidden ---
404 return 1;
405}
406
407static void
408CcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
409 struct fsm_decode *dec)
410{
411 /* Deal with incoming data */

--- 226 unchanged lines hidden ---