2 * Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
3 * based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
4 * Internet Initiative Japan, Inc (IIJ)
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * $FreeBSD: src/usr.sbin/ppp/ccp.c,v 1.54.2.7 2002/09/01 02:12:22 brian Exp $
29 * $DragonFly: src/usr.sbin/ppp/ccp.c,v 1.2 2003/06/17 04:30:00 dillon Exp $
32 #include <sys/param.h>
33 #include <netinet/in.h>
34 #include <netinet/in_systm.h>
35 #include <netinet/ip.h>
36 #include <sys/socket.h>
42 #include <string.h> /* memcpy() on some archs */
55 #include "throughput.h"
57 #include "slcompress.h"
65 #include "descriptor.h"
81 static void CcpSendConfigReq(struct fsm
*);
82 static void CcpSentTerminateReq(struct fsm
*);
83 static void CcpSendTerminateAck(struct fsm
*, u_char
);
84 static void CcpDecodeConfig(struct fsm
*, u_char
*, u_char
*, int,
86 static void CcpLayerStart(struct fsm
*);
87 static void CcpLayerFinish(struct fsm
*);
88 static int CcpLayerUp(struct fsm
*);
89 static void CcpLayerDown(struct fsm
*);
90 static void CcpInitRestartCounter(struct fsm
*, int);
91 static int CcpRecvResetReq(struct fsm
*);
92 static void CcpRecvResetAck(struct fsm
*, u_char
);
94 static struct fsm_callbacks ccp_Callbacks
= {
99 CcpInitRestartCounter
,
108 static const char * const ccp_TimerNames
[] =
109 {"CCP restart", "CCP openmode", "CCP stopped"};
114 static char const * const cftypes
[] = {
115 /* Check out the latest ``Compression Control Protocol'' rfc (1962) */
117 "PRED1", /* 1: Predictor type 1 */
118 "PRED2", /* 2: Predictor type 2 */
119 "PUDDLE", /* 3: Puddle Jumber */
120 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
121 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
122 "HWPPC", /* 16: Hewlett-Packard PPC */
123 "STAC", /* 17: Stac Electronics LZS (rfc1974) */
124 "MPPE", /* 18: Microsoft PPC (rfc2118) and */
125 /* Microsoft PPE (draft-ietf-pppext-mppe) */
126 "GAND", /* 19: Gandalf FZA (rfc1993) */
127 "V42BIS", /* 20: ARG->DATA.42bis compression */
128 "BSD", /* 21: BSD LZW Compress */
130 "LZS-DCP", /* 23: LZS-DCP Compression Protocol (rfc1967) */
131 "MAGNALINK/DEFLATE",/* 24: Magnalink Variable Resource (rfc1975) */
132 /* 24: Deflate (according to pppd-2.3.*) */
133 "DCE", /* 25: Data Circuit-Terminating Equip (rfc1976) */
134 "DEFLATE", /* 26: Deflate (rfc1979) */
137 if (proto
< 0 || proto
> sizeof cftypes
/ sizeof *cftypes
||
138 cftypes
[proto
] == NULL
) {
141 return HexStr(proto
, NULL
, 0);
144 return cftypes
[proto
];
147 /* We support these algorithms, and Req them in the given order */
148 static const struct ccp_algorithm
* const algorithm
[] = {
151 &PppdDeflateAlgorithm
157 #define NALGORITHMS (sizeof algorithm/sizeof algorithm[0])
160 ccp_ReportStatus(struct cmdargs
const *arg
)
167 l
= command_ChooseLink(arg
);
170 prompt_Printf(arg
->prompt
, "%s: %s [%s]\n", l
->name
, ccp
->fsm
.name
,
171 State2Nam(ccp
->fsm
.state
));
172 if (ccp
->fsm
.state
== ST_OPENED
) {
173 prompt_Printf(arg
->prompt
, " My protocol = %s, His protocol = %s\n",
174 protoname(ccp
->my_proto
), protoname(ccp
->his_proto
));
175 prompt_Printf(arg
->prompt
, " Output: %ld --> %ld, Input: %ld --> %ld\n",
176 ccp
->uncompout
, ccp
->compout
,
177 ccp
->compin
, ccp
->uncompin
);
180 if (ccp
->in
.algorithm
!= -1)
181 prompt_Printf(arg
->prompt
, "\n Input Options: %s\n",
182 (*algorithm
[ccp
->in
.algorithm
]->Disp
)(&ccp
->in
.opt
));
184 if (ccp
->out
.algorithm
!= -1) {
186 for (f
= 0; f
< ccp
->out
.algorithm
; f
++)
187 if (IsEnabled(ccp
->cfg
.neg
[algorithm
[f
]->Neg
]))
189 prompt_Printf(arg
->prompt
, " Output Options: %s\n",
190 (*algorithm
[ccp
->out
.algorithm
]->Disp
)(&(*o
)->val
));
193 prompt_Printf(arg
->prompt
, "\n Defaults: ");
194 prompt_Printf(arg
->prompt
, "FSM retry = %us, max %u Config"
195 " REQ%s, %u Term REQ%s\n", ccp
->cfg
.fsm
.timeout
,
196 ccp
->cfg
.fsm
.maxreq
, ccp
->cfg
.fsm
.maxreq
== 1 ? "" : "s",
197 ccp
->cfg
.fsm
.maxtrm
, ccp
->cfg
.fsm
.maxtrm
== 1 ? "" : "s");
198 prompt_Printf(arg
->prompt
, " deflate windows: ");
199 prompt_Printf(arg
->prompt
, "incoming = %d, ", ccp
->cfg
.deflate
.in
.winsize
);
200 prompt_Printf(arg
->prompt
, "outgoing = %d\n", ccp
->cfg
.deflate
.out
.winsize
);
202 prompt_Printf(arg
->prompt
, " MPPE: ");
203 if (ccp
->cfg
.mppe
.keybits
)
204 prompt_Printf(arg
->prompt
, "%d bits, ", ccp
->cfg
.mppe
.keybits
);
206 prompt_Printf(arg
->prompt
, "any bits, ");
207 switch (ccp
->cfg
.mppe
.state
) {
209 prompt_Printf(arg
->prompt
, "stateful");
212 prompt_Printf(arg
->prompt
, "stateless");
215 prompt_Printf(arg
->prompt
, "any state");
218 prompt_Printf(arg
->prompt
, "%s\n",
219 ccp
->cfg
.mppe
.required
? ", required" : "");
222 prompt_Printf(arg
->prompt
, "\n DEFLATE: %s\n",
223 command_ShowNegval(ccp
->cfg
.neg
[CCP_NEG_DEFLATE
]));
224 prompt_Printf(arg
->prompt
, " PREDICTOR1: %s\n",
225 command_ShowNegval(ccp
->cfg
.neg
[CCP_NEG_PRED1
]));
226 prompt_Printf(arg
->prompt
, " DEFLATE24: %s\n",
227 command_ShowNegval(ccp
->cfg
.neg
[CCP_NEG_DEFLATE24
]));
229 prompt_Printf(arg
->prompt
, " MPPE: %s\n",
230 command_ShowNegval(ccp
->cfg
.neg
[CCP_NEG_MPPE
]));
236 ccp_SetupCallbacks(struct ccp
*ccp
)
238 ccp
->fsm
.fn
= &ccp_Callbacks
;
239 ccp
->fsm
.FsmTimer
.name
= ccp_TimerNames
[0];
240 ccp
->fsm
.OpenTimer
.name
= ccp_TimerNames
[1];
241 ccp
->fsm
.StoppedTimer
.name
= ccp_TimerNames
[2];
245 ccp_Init(struct ccp
*ccp
, struct bundle
*bundle
, struct link
*l
,
246 const struct fsm_parent
*parent
)
248 /* Initialise ourselves */
250 fsm_Init(&ccp
->fsm
, "CCP", PROTO_CCP
, 1, CCP_MAXCODE
, LogCCP
,
251 bundle
, l
, parent
, &ccp_Callbacks
, ccp_TimerNames
);
253 ccp
->cfg
.deflate
.in
.winsize
= 0;
254 ccp
->cfg
.deflate
.out
.winsize
= 15;
255 ccp
->cfg
.fsm
.timeout
= DEF_FSMRETRY
;
256 ccp
->cfg
.fsm
.maxreq
= DEF_FSMTRIES
;
257 ccp
->cfg
.fsm
.maxtrm
= DEF_FSMTRIES
;
258 ccp
->cfg
.neg
[CCP_NEG_DEFLATE
] = NEG_ENABLED
|NEG_ACCEPTED
;
259 ccp
->cfg
.neg
[CCP_NEG_PRED1
] = NEG_ENABLED
|NEG_ACCEPTED
;
260 ccp
->cfg
.neg
[CCP_NEG_DEFLATE24
] = 0;
262 ccp
->cfg
.mppe
.keybits
= 0;
263 ccp
->cfg
.mppe
.state
= MPPE_ANYSTATE
;
264 ccp
->cfg
.mppe
.required
= 0;
265 ccp
->cfg
.neg
[CCP_NEG_MPPE
] = NEG_ENABLED
|NEG_ACCEPTED
;
272 ccp_Setup(struct ccp
*ccp
)
274 /* Set ourselves up for a startup */
275 ccp
->fsm
.open_mode
= 0;
276 ccp
->his_proto
= ccp
->my_proto
= -1;
277 ccp
->reset_sent
= ccp
->last_reset
= -1;
278 ccp
->in
.algorithm
= ccp
->out
.algorithm
= -1;
279 ccp
->in
.state
= ccp
->out
.state
= NULL
;
280 ccp
->in
.opt
.hdr
.id
= -1;
282 ccp
->his_reject
= ccp
->my_reject
= 0;
283 ccp
->uncompout
= ccp
->compout
= 0;
284 ccp
->uncompin
= ccp
->compin
= 0;
288 * Is ccp *REQUIRED* ?
289 * We ask each of the configured ccp protocols if they're required and
290 * return TRUE if they are.
292 * It's not possible for the peer to reject a required ccp protocol
293 * without our state machine bringing the supporting lcp layer down.
295 * If ccp is required but not open, the NCP layer should not push
296 * any data into the link.
299 ccp_Required(struct ccp
*ccp
)
303 for (f
= 0; f
< NALGORITHMS
; f
++)
304 if (IsEnabled(ccp
->cfg
.neg
[algorithm
[f
]->Neg
]) &&
305 (*algorithm
[f
]->Required
)(&ccp
->fsm
))
312 * Report whether it's possible to increase a packet's size after
313 * compression (and by how much).
316 ccp_MTUOverhead(struct ccp
*ccp
)
318 if (ccp
->fsm
.state
== ST_OPENED
&& ccp
->out
.algorithm
>= 0)
319 return algorithm
[ccp
->out
.algorithm
]->o
.MTUOverhead
;
325 CcpInitRestartCounter(struct fsm
*fp
, int what
)
327 /* Set fsm timer load */
328 struct ccp
*ccp
= fsm2ccp(fp
);
330 fp
->FsmTimer
.load
= ccp
->cfg
.fsm
.timeout
* SECTICKS
;
333 fp
->restart
= ccp
->cfg
.fsm
.maxreq
;
336 fp
->restart
= ccp
->cfg
.fsm
.maxtrm
;
345 CcpSendConfigReq(struct fsm
*fp
)
347 /* Send config REQ please */
348 struct ccp
*ccp
= fsm2ccp(fp
);
350 u_char
*cp
, buff
[100];
355 alloc
= ccp
->his_reject
== 0 && ccp
->out
.opt
== NULL
;
357 ccp
->out
.algorithm
= -1;
358 for (f
= 0; f
< NALGORITHMS
; f
++)
359 if (IsEnabled(ccp
->cfg
.neg
[algorithm
[f
]->Neg
]) &&
360 !REJECTED(ccp
, algorithm
[f
]->id
) &&
361 (*algorithm
[f
]->Usable
)(fp
)) {
364 for (o
= &ccp
->out
.opt
; *o
!= NULL
; o
= &(*o
)->next
)
365 if ((*o
)->val
.hdr
.id
== algorithm
[f
]->id
&& (*o
)->algorithm
== f
)
368 if (alloc
|| *o
== NULL
) {
369 *o
= (struct ccp_opt
*)malloc(sizeof(struct ccp_opt
));
370 (*o
)->val
.hdr
.id
= algorithm
[f
]->id
;
371 (*o
)->val
.hdr
.len
= 2;
374 (*algorithm
[f
]->o
.OptInit
)(fp
->bundle
, &(*o
)->val
, &ccp
->cfg
);
377 if (cp
+ (*o
)->val
.hdr
.len
> buff
+ sizeof buff
) {
378 log_Printf(LogERROR
, "%s: CCP REQ buffer overrun !\n", fp
->link
->name
);
381 memcpy(cp
, &(*o
)->val
, (*o
)->val
.hdr
.len
);
382 cp
+= (*o
)->val
.hdr
.len
;
384 ccp
->my_proto
= (*o
)->val
.hdr
.id
;
385 ccp
->out
.algorithm
= f
;
391 fsm_Output(fp
, CODE_CONFIGREQ
, fp
->reqid
, buff
, cp
- buff
, MB_CCPOUT
);
395 ccp_SendResetReq(struct fsm
*fp
)
397 /* We can't read our input - ask peer to reset */
398 struct ccp
*ccp
= fsm2ccp(fp
);
400 ccp
->reset_sent
= fp
->reqid
;
401 ccp
->last_reset
= -1;
402 fsm_Output(fp
, CODE_RESETREQ
, fp
->reqid
, NULL
, 0, MB_CCPOUT
);
406 CcpSentTerminateReq(struct fsm
*fp
)
408 /* Term REQ just sent by FSM */
412 CcpSendTerminateAck(struct fsm
*fp
, u_char id
)
414 /* Send Term ACK please */
415 fsm_Output(fp
, CODE_TERMACK
, id
, NULL
, 0, MB_CCPOUT
);
419 CcpRecvResetReq(struct fsm
*fp
)
421 /* Got a reset REQ, reset outgoing dictionary */
422 struct ccp
*ccp
= fsm2ccp(fp
);
423 if (ccp
->out
.state
== NULL
)
425 return (*algorithm
[ccp
->out
.algorithm
]->o
.Reset
)(ccp
->out
.state
);
429 CcpLayerStart(struct fsm
*fp
)
431 /* We're about to start up ! */
432 struct ccp
*ccp
= fsm2ccp(fp
);
434 log_Printf(LogCCP
, "%s: LayerStart.\n", fp
->link
->name
);
435 fp
->more
.reqs
= fp
->more
.naks
= fp
->more
.rejs
= ccp
->cfg
.fsm
.maxreq
* 3;
439 CcpLayerDown(struct fsm
*fp
)
441 /* About to come down */
442 struct ccp
*ccp
= fsm2ccp(fp
);
443 struct ccp_opt
*next
;
445 log_Printf(LogCCP
, "%s: LayerDown.\n", fp
->link
->name
);
446 if (ccp
->in
.state
!= NULL
) {
447 (*algorithm
[ccp
->in
.algorithm
]->i
.Term
)(ccp
->in
.state
);
448 ccp
->in
.state
= NULL
;
449 ccp
->in
.algorithm
= -1;
451 if (ccp
->out
.state
!= NULL
) {
452 (*algorithm
[ccp
->out
.algorithm
]->o
.Term
)(ccp
->out
.state
);
453 ccp
->out
.state
= NULL
;
454 ccp
->out
.algorithm
= -1;
456 ccp
->his_reject
= ccp
->my_reject
= 0;
458 while (ccp
->out
.opt
) {
459 next
= ccp
->out
.opt
->next
;
467 CcpLayerFinish(struct fsm
*fp
)
470 struct ccp
*ccp
= fsm2ccp(fp
);
471 struct ccp_opt
*next
;
473 log_Printf(LogCCP
, "%s: LayerFinish.\n", fp
->link
->name
);
476 * Nuke options that may be left over from sending a REQ but never
479 while (ccp
->out
.opt
) {
480 next
= ccp
->out
.opt
->next
;
485 if (ccp_Required(ccp
)) {
486 if (fp
->link
->lcp
.fsm
.state
== ST_OPENED
)
487 log_Printf(LogLCP
, "%s: Closing due to CCP completion\n", fp
->link
->name
);
488 fsm_Close(&fp
->link
->lcp
.fsm
);
492 /* Called when CCP has reached the OPEN state */
494 CcpLayerUp(struct fsm
*fp
)
497 struct ccp
*ccp
= fsm2ccp(fp
);
501 for (f
= fail
= 0; f
< NALGORITHMS
; f
++)
502 if (IsEnabled(ccp
->cfg
.neg
[algorithm
[f
]->Neg
]) &&
503 (*algorithm
[f
]->Required
)(&ccp
->fsm
) &&
504 (ccp
->in
.algorithm
!= f
|| ccp
->out
.algorithm
!= f
)) {
505 /* Blow it all away - we haven't negotiated a required algorithm */
506 log_Printf(LogWARN
, "%s: Failed to negotiate (required) %s\n",
507 fp
->link
->name
, protoname(algorithm
[f
]->id
));
512 ccp
->his_proto
= ccp
->my_proto
= -1;
514 fsm_Close(&fp
->link
->lcp
.fsm
);
518 log_Printf(LogCCP
, "%s: LayerUp.\n", fp
->link
->name
);
520 if (ccp
->in
.state
== NULL
&& ccp
->in
.algorithm
>= 0 &&
521 ccp
->in
.algorithm
< NALGORITHMS
) {
522 ccp
->in
.state
= (*algorithm
[ccp
->in
.algorithm
]->i
.Init
)
523 (fp
->bundle
, &ccp
->in
.opt
);
524 if (ccp
->in
.state
== NULL
) {
525 log_Printf(LogERROR
, "%s: %s (in) initialisation failure\n",
526 fp
->link
->name
, protoname(ccp
->his_proto
));
527 ccp
->his_proto
= ccp
->my_proto
= -1;
534 for (f
= 0; f
< ccp
->out
.algorithm
; f
++)
535 if (IsEnabled(ccp
->cfg
.neg
[algorithm
[f
]->Neg
]))
538 if (ccp
->out
.state
== NULL
&& ccp
->out
.algorithm
>= 0 &&
539 ccp
->out
.algorithm
< NALGORITHMS
) {
540 ccp
->out
.state
= (*algorithm
[ccp
->out
.algorithm
]->o
.Init
)
541 (fp
->bundle
, &(*o
)->val
);
542 if (ccp
->out
.state
== NULL
) {
543 log_Printf(LogERROR
, "%s: %s (out) initialisation failure\n",
544 fp
->link
->name
, protoname(ccp
->my_proto
));
545 ccp
->his_proto
= ccp
->my_proto
= -1;
551 fp
->more
.reqs
= fp
->more
.naks
= fp
->more
.rejs
= ccp
->cfg
.fsm
.maxreq
* 3;
553 log_Printf(LogCCP
, "%s: Out = %s[%d], In = %s[%d]\n",
554 fp
->link
->name
, protoname(ccp
->my_proto
), ccp
->my_proto
,
555 protoname(ccp
->his_proto
), ccp
->his_proto
);
561 CcpDecodeConfig(struct fsm
*fp
, u_char
*cp
, u_char
*end
, int mode_type
,
562 struct fsm_decode
*dec
)
564 /* Deal with incoming data */
565 struct ccp
*ccp
= fsm2ccp(fp
);
570 if (mode_type
== MODE_REQ
)
571 ccp
->in
.algorithm
= -1; /* In case we've received two REQs in a row */
573 while (end
- cp
>= sizeof(opt
->hdr
)) {
574 if ((opt
= fsm_readopt(&cp
)) == NULL
)
577 for (f
= NALGORITHMS
-1; f
> -1; f
--)
578 if (algorithm
[f
]->id
== opt
->hdr
.id
)
581 disp
= f
== -1 ? "" : (*algorithm
[f
]->Disp
)(opt
);
585 log_Printf(LogCCP
, " %s[%d] %s\n", protoname(opt
->hdr
.id
),
589 /* Don't understand that :-( */
590 if (mode_type
== MODE_REQ
) {
591 ccp
->my_reject
|= (1 << opt
->hdr
.id
);
599 if (IsAccepted(ccp
->cfg
.neg
[algorithm
[f
]->Neg
]) &&
600 (*algorithm
[f
]->Usable
)(fp
) &&
601 ccp
->in
.algorithm
== -1) {
602 memcpy(&ccp
->in
.opt
, opt
, opt
->hdr
.len
);
603 switch ((*algorithm
[f
]->i
.Set
)(fp
->bundle
, &ccp
->in
.opt
, &ccp
->cfg
)) {
605 fsm_rej(dec
, &ccp
->in
.opt
);
608 fsm_nak(dec
, &ccp
->in
.opt
);
611 fsm_ack(dec
, &ccp
->in
.opt
);
612 ccp
->his_proto
= opt
->hdr
.id
;
613 ccp
->in
.algorithm
= f
; /* This one'll do :-) */
621 for (o
= ccp
->out
.opt
; o
!= NULL
; o
= o
->next
)
622 if (o
->val
.hdr
.id
== opt
->hdr
.id
)
625 log_Printf(LogCCP
, "%s: Warning: Ignoring peer NAK of unsent"
626 " option\n", fp
->link
->name
);
628 memcpy(&o
->val
, opt
, opt
->hdr
.len
);
629 if ((*algorithm
[f
]->o
.Set
)(fp
->bundle
, &o
->val
, &ccp
->cfg
) ==
631 ccp
->my_proto
= algorithm
[f
]->id
;
633 ccp
->his_reject
|= (1 << opt
->hdr
.id
);
635 if (algorithm
[f
]->Required(fp
)) {
636 log_Printf(LogWARN
, "%s: Cannot understand peers (required)"
637 " %s negotiation\n", fp
->link
->name
,
638 protoname(algorithm
[f
]->id
));
639 fsm_Close(&fp
->link
->lcp
.fsm
);
645 ccp
->his_reject
|= (1 << opt
->hdr
.id
);
647 if (algorithm
[f
]->Required(fp
)) {
648 log_Printf(LogWARN
, "%s: Peer rejected (required) %s negotiation\n",
649 fp
->link
->name
, protoname(algorithm
[f
]->id
));
650 fsm_Close(&fp
->link
->lcp
.fsm
);
657 if (mode_type
!= MODE_NOP
) {
658 fsm_opt_normalise(dec
);
659 if (dec
->rejend
!= dec
->rej
|| dec
->nakend
!= dec
->nak
) {
660 if (ccp
->in
.state
== NULL
) {
662 ccp
->in
.algorithm
= -1;
669 ccp_Input(struct bundle
*bundle
, struct link
*l
, struct mbuf
*bp
)
671 /* Got PROTO_CCP from link */
672 m_settype(bp
, MB_CCPIN
);
673 if (bundle_Phase(bundle
) == PHASE_NETWORK
)
674 fsm_Input(&l
->ccp
.fsm
, bp
);
676 if (bundle_Phase(bundle
) < PHASE_NETWORK
)
677 log_Printf(LogCCP
, "%s: Error: Unexpected CCP in phase %s (ignored)\n",
678 l
->ccp
.fsm
.link
->name
, bundle_PhaseName(bundle
));
685 CcpRecvResetAck(struct fsm
*fp
, u_char id
)
687 /* Got a reset ACK, reset incoming dictionary */
688 struct ccp
*ccp
= fsm2ccp(fp
);
690 if (ccp
->reset_sent
!= -1) {
691 if (id
!= ccp
->reset_sent
) {
692 log_Printf(LogCCP
, "%s: Incorrect ResetAck (id %d, not %d)"
693 " ignored\n", fp
->link
->name
, id
, ccp
->reset_sent
);
696 /* Whaddaya know - a correct reset ack */
697 } else if (id
== ccp
->last_reset
)
698 log_Printf(LogCCP
, "%s: Duplicate ResetAck (resetting again)\n",
701 log_Printf(LogCCP
, "%s: Unexpected ResetAck (id %d) ignored\n",
706 ccp
->last_reset
= ccp
->reset_sent
;
707 ccp
->reset_sent
= -1;
708 if (ccp
->in
.state
!= NULL
)
709 (*algorithm
[ccp
->in
.algorithm
]->i
.Reset
)(ccp
->in
.state
);
713 ccp_LayerPush(struct bundle
*b
, struct link
*l
, struct mbuf
*bp
,
714 int pri
, u_short
*proto
)
716 if (PROTO_COMPRESSIBLE(*proto
)) {
717 if (l
->ccp
.fsm
.state
!= ST_OPENED
) {
718 if (ccp_Required(&l
->ccp
)) {
719 /* The NCP layer shouldn't have let this happen ! */
720 log_Printf(LogERROR
, "%s: Unexpected attempt to use an unopened and"
721 " required CCP layer\n", l
->name
);
725 } else if (l
->ccp
.out
.state
!= NULL
) {
726 bp
= (*algorithm
[l
->ccp
.out
.algorithm
]->o
.Write
)
727 (l
->ccp
.out
.state
, &l
->ccp
, l
, pri
, proto
, bp
);
730 m_settype(bp
, MB_ICOMPDOUT
);
733 m_settype(bp
, MB_COMPDOUT
);
743 ccp_LayerPull(struct bundle
*b
, struct link
*l
, struct mbuf
*bp
, u_short
*proto
)
746 * If proto isn't PROTO_[I]COMPD, we still want to pass it to the
747 * decompression routines so that the dictionary's updated
749 if (l
->ccp
.fsm
.state
== ST_OPENED
) {
750 if (*proto
== PROTO_COMPD
|| *proto
== PROTO_ICOMPD
) {
751 /* Decompress incoming data */
752 if (l
->ccp
.reset_sent
!= -1)
753 /* Send another REQ and put the packet in the bit bucket */
754 fsm_Output(&l
->ccp
.fsm
, CODE_RESETREQ
, l
->ccp
.reset_sent
, NULL
, 0,
756 else if (l
->ccp
.in
.state
!= NULL
) {
757 bp
= (*algorithm
[l
->ccp
.in
.algorithm
]->i
.Read
)
758 (l
->ccp
.in
.state
, &l
->ccp
, proto
, bp
);
761 m_settype(bp
, MB_ICOMPDIN
);
764 m_settype(bp
, MB_COMPDIN
);
771 } else if (PROTO_COMPRESSIBLE(*proto
) && l
->ccp
.in
.state
!= NULL
) {
772 /* Add incoming Network Layer traffic to our dictionary */
773 (*algorithm
[l
->ccp
.in
.algorithm
]->i
.DictSetup
)
774 (l
->ccp
.in
.state
, &l
->ccp
, *proto
, bp
);
782 ccp_Proto(struct ccp
*ccp
)
784 return !link2physical(ccp
->fsm
.link
) || !ccp
->fsm
.bundle
->ncp
.mp
.active
?
785 PROTO_COMPD
: PROTO_ICOMPD
;
789 ccp_SetOpenMode(struct ccp
*ccp
)
793 for (f
= 0; f
< CCP_NEG_TOTAL
; f
++)
794 if (IsEnabled(ccp
->cfg
.neg
[f
])) {
795 ccp
->fsm
.open_mode
= 0;
799 ccp
->fsm
.open_mode
= OPEN_PASSIVE
; /* Go straight to ST_STOPPED ? */
801 for (f
= 0; f
< CCP_NEG_TOTAL
; f
++)
802 if (IsAccepted(ccp
->cfg
.neg
[f
]))
805 return 0; /* No CCP at all */
809 ccp_DefaultUsable(struct fsm
*fp
)
815 ccp_DefaultRequired(struct fsm
*fp
)
820 struct layer ccplayer
= { LAYER_CCP
, "ccp", ccp_LayerPush
, ccp_LayerPull
};