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 || (unsigned)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];
356 alloc
= ccp
->his_reject
== 0 && ccp
->out
.opt
== NULL
;
358 ccp
->out
.algorithm
= -1;
359 for (f
= 0; f
< NALGORITHMS
; f
++)
360 if (IsEnabled(ccp
->cfg
.neg
[algorithm
[f
]->Neg
]) &&
361 !REJECTED(ccp
, algorithm
[f
]->id
) &&
362 (*algorithm
[f
]->Usable
)(fp
)) {
365 for (o
= &ccp
->out
.opt
; *o
!= NULL
; o
= &(*o
)->next
)
366 if ((*o
)->val
.hdr
.id
== algorithm
[f
]->id
&& (*o
)->algorithm
== (int)f
)
369 if (alloc
|| *o
== NULL
) {
370 *o
= (struct ccp_opt
*)malloc(sizeof(struct ccp_opt
));
371 (*o
)->val
.hdr
.id
= algorithm
[f
]->id
;
372 (*o
)->val
.hdr
.len
= 2;
375 (*algorithm
[f
]->o
.OptInit
)(fp
->bundle
, &(*o
)->val
, &ccp
->cfg
);
378 if (cp
+ (*o
)->val
.hdr
.len
> buff
+ sizeof buff
) {
379 log_Printf(LogERROR
, "%s: CCP REQ buffer overrun !\n", fp
->link
->name
);
382 memcpy(cp
, &(*o
)->val
, (*o
)->val
.hdr
.len
);
383 cp
+= (*o
)->val
.hdr
.len
;
385 ccp
->my_proto
= (*o
)->val
.hdr
.id
;
386 ccp
->out
.algorithm
= f
;
392 fsm_Output(fp
, CODE_CONFIGREQ
, fp
->reqid
, buff
, cp
- buff
, MB_CCPOUT
);
396 ccp_SendResetReq(struct fsm
*fp
)
398 /* We can't read our input - ask peer to reset */
399 struct ccp
*ccp
= fsm2ccp(fp
);
401 ccp
->reset_sent
= fp
->reqid
;
402 ccp
->last_reset
= -1;
403 fsm_Output(fp
, CODE_RESETREQ
, fp
->reqid
, NULL
, 0, MB_CCPOUT
);
407 CcpSentTerminateReq(struct fsm
*fp __unused
)
409 /* Term REQ just sent by FSM */
413 CcpSendTerminateAck(struct fsm
*fp
, u_char id
)
415 /* Send Term ACK please */
416 fsm_Output(fp
, CODE_TERMACK
, id
, NULL
, 0, MB_CCPOUT
);
420 CcpRecvResetReq(struct fsm
*fp
)
422 /* Got a reset REQ, reset outgoing dictionary */
423 struct ccp
*ccp
= fsm2ccp(fp
);
424 if (ccp
->out
.state
== NULL
)
426 return (*algorithm
[ccp
->out
.algorithm
]->o
.Reset
)(ccp
->out
.state
);
430 CcpLayerStart(struct fsm
*fp
)
432 /* We're about to start up ! */
433 struct ccp
*ccp
= fsm2ccp(fp
);
435 log_Printf(LogCCP
, "%s: LayerStart.\n", fp
->link
->name
);
436 fp
->more
.reqs
= fp
->more
.naks
= fp
->more
.rejs
= ccp
->cfg
.fsm
.maxreq
* 3;
440 CcpLayerDown(struct fsm
*fp
)
442 /* About to come down */
443 struct ccp
*ccp
= fsm2ccp(fp
);
444 struct ccp_opt
*next
;
446 log_Printf(LogCCP
, "%s: LayerDown.\n", fp
->link
->name
);
447 if (ccp
->in
.state
!= NULL
) {
448 (*algorithm
[ccp
->in
.algorithm
]->i
.Term
)(ccp
->in
.state
);
449 ccp
->in
.state
= NULL
;
450 ccp
->in
.algorithm
= -1;
452 if (ccp
->out
.state
!= NULL
) {
453 (*algorithm
[ccp
->out
.algorithm
]->o
.Term
)(ccp
->out
.state
);
454 ccp
->out
.state
= NULL
;
455 ccp
->out
.algorithm
= -1;
457 ccp
->his_reject
= ccp
->my_reject
= 0;
459 while (ccp
->out
.opt
) {
460 next
= ccp
->out
.opt
->next
;
468 CcpLayerFinish(struct fsm
*fp
)
471 struct ccp
*ccp
= fsm2ccp(fp
);
472 struct ccp_opt
*next
;
474 log_Printf(LogCCP
, "%s: LayerFinish.\n", fp
->link
->name
);
477 * Nuke options that may be left over from sending a REQ but never
480 while (ccp
->out
.opt
) {
481 next
= ccp
->out
.opt
->next
;
486 if (ccp_Required(ccp
)) {
487 if (fp
->link
->lcp
.fsm
.state
== ST_OPENED
)
488 log_Printf(LogLCP
, "%s: Closing due to CCP completion\n", fp
->link
->name
);
489 fsm_Close(&fp
->link
->lcp
.fsm
);
493 /* Called when CCP has reached the OPEN state */
495 CcpLayerUp(struct fsm
*fp
)
498 struct ccp
*ccp
= fsm2ccp(fp
);
502 for (f
= fail
= 0; f
< NALGORITHMS
; f
++)
503 if (IsEnabled(ccp
->cfg
.neg
[algorithm
[f
]->Neg
]) &&
504 (*algorithm
[f
]->Required
)(&ccp
->fsm
) &&
505 (ccp
->in
.algorithm
!= (int)f
|| ccp
->out
.algorithm
!= (int)f
)) {
506 /* Blow it all away - we haven't negotiated a required algorithm */
507 log_Printf(LogWARN
, "%s: Failed to negotiate (required) %s\n",
508 fp
->link
->name
, protoname(algorithm
[f
]->id
));
513 ccp
->his_proto
= ccp
->my_proto
= -1;
515 fsm_Close(&fp
->link
->lcp
.fsm
);
519 log_Printf(LogCCP
, "%s: LayerUp.\n", fp
->link
->name
);
521 if (ccp
->in
.state
== NULL
&& ccp
->in
.algorithm
>= 0 &&
522 ccp
->in
.algorithm
< (int)NALGORITHMS
) {
523 ccp
->in
.state
= (*algorithm
[ccp
->in
.algorithm
]->i
.Init
)
524 (fp
->bundle
, &ccp
->in
.opt
);
525 if (ccp
->in
.state
== NULL
) {
526 log_Printf(LogERROR
, "%s: %s (in) initialisation failure\n",
527 fp
->link
->name
, protoname(ccp
->his_proto
));
528 ccp
->his_proto
= ccp
->my_proto
= -1;
535 if (ccp
->out
.algorithm
> 0)
536 for (f
= 0; f
< (unsigned)ccp
->out
.algorithm
; f
++)
537 if (IsEnabled(ccp
->cfg
.neg
[algorithm
[f
]->Neg
]))
540 if (ccp
->out
.state
== NULL
&& ccp
->out
.algorithm
>= 0 &&
541 ccp
->out
.algorithm
< (int)NALGORITHMS
) {
542 ccp
->out
.state
= (*algorithm
[ccp
->out
.algorithm
]->o
.Init
)
543 (fp
->bundle
, &(*o
)->val
);
544 if (ccp
->out
.state
== NULL
) {
545 log_Printf(LogERROR
, "%s: %s (out) initialisation failure\n",
546 fp
->link
->name
, protoname(ccp
->my_proto
));
547 ccp
->his_proto
= ccp
->my_proto
= -1;
553 fp
->more
.reqs
= fp
->more
.naks
= fp
->more
.rejs
= ccp
->cfg
.fsm
.maxreq
* 3;
555 log_Printf(LogCCP
, "%s: Out = %s[%d], In = %s[%d]\n",
556 fp
->link
->name
, protoname(ccp
->my_proto
), ccp
->my_proto
,
557 protoname(ccp
->his_proto
), ccp
->his_proto
);
563 CcpDecodeConfig(struct fsm
*fp
, u_char
*cp
, u_char
*end
, int mode_type
,
564 struct fsm_decode
*dec
)
566 /* Deal with incoming data */
567 struct ccp
*ccp
= fsm2ccp(fp
);
572 if (mode_type
== MODE_REQ
)
573 ccp
->in
.algorithm
= -1; /* In case we've received two REQs in a row */
575 while (end
>= cp
+ sizeof(opt
->hdr
)) {
576 if ((opt
= fsm_readopt(&cp
)) == NULL
)
579 for (f
= NALGORITHMS
-1; f
> -1; f
--)
580 if (algorithm
[f
]->id
== opt
->hdr
.id
)
583 disp
= f
== -1 ? "" : (*algorithm
[f
]->Disp
)(opt
);
587 log_Printf(LogCCP
, " %s[%d] %s\n", protoname(opt
->hdr
.id
),
591 /* Don't understand that :-( */
592 if (mode_type
== MODE_REQ
) {
593 ccp
->my_reject
|= (1 << opt
->hdr
.id
);
601 if (IsAccepted(ccp
->cfg
.neg
[algorithm
[f
]->Neg
]) &&
602 (*algorithm
[f
]->Usable
)(fp
) &&
603 ccp
->in
.algorithm
== -1) {
604 memcpy(&ccp
->in
.opt
, opt
, opt
->hdr
.len
);
605 switch ((*algorithm
[f
]->i
.Set
)(fp
->bundle
, &ccp
->in
.opt
, &ccp
->cfg
)) {
607 fsm_rej(dec
, &ccp
->in
.opt
);
610 fsm_nak(dec
, &ccp
->in
.opt
);
613 fsm_ack(dec
, &ccp
->in
.opt
);
614 ccp
->his_proto
= opt
->hdr
.id
;
615 ccp
->in
.algorithm
= (int)f
; /* This one'll do :-) */
623 for (o
= ccp
->out
.opt
; o
!= NULL
; o
= o
->next
)
624 if (o
->val
.hdr
.id
== opt
->hdr
.id
)
627 log_Printf(LogCCP
, "%s: Warning: Ignoring peer NAK of unsent"
628 " option\n", fp
->link
->name
);
630 memcpy(&o
->val
, opt
, opt
->hdr
.len
);
631 if ((*algorithm
[f
]->o
.Set
)(fp
->bundle
, &o
->val
, &ccp
->cfg
) ==
633 ccp
->my_proto
= algorithm
[f
]->id
;
635 ccp
->his_reject
|= (1 << opt
->hdr
.id
);
637 if (algorithm
[f
]->Required(fp
)) {
638 log_Printf(LogWARN
, "%s: Cannot understand peers (required)"
639 " %s negotiation\n", fp
->link
->name
,
640 protoname(algorithm
[f
]->id
));
641 fsm_Close(&fp
->link
->lcp
.fsm
);
647 ccp
->his_reject
|= (1 << opt
->hdr
.id
);
649 if (algorithm
[f
]->Required(fp
)) {
650 log_Printf(LogWARN
, "%s: Peer rejected (required) %s negotiation\n",
651 fp
->link
->name
, protoname(algorithm
[f
]->id
));
652 fsm_Close(&fp
->link
->lcp
.fsm
);
659 if (mode_type
!= MODE_NOP
) {
660 fsm_opt_normalise(dec
);
661 if (dec
->rejend
!= dec
->rej
|| dec
->nakend
!= dec
->nak
) {
662 if (ccp
->in
.state
== NULL
) {
664 ccp
->in
.algorithm
= -1;
671 ccp_Input(struct bundle
*bundle
, struct link
*l
, struct mbuf
*bp
)
673 /* Got PROTO_CCP from link */
674 m_settype(bp
, MB_CCPIN
);
675 if (bundle_Phase(bundle
) == PHASE_NETWORK
)
676 fsm_Input(&l
->ccp
.fsm
, bp
);
678 if (bundle_Phase(bundle
) < PHASE_NETWORK
)
679 log_Printf(LogCCP
, "%s: Error: Unexpected CCP in phase %s (ignored)\n",
680 l
->ccp
.fsm
.link
->name
, bundle_PhaseName(bundle
));
687 CcpRecvResetAck(struct fsm
*fp
, u_char id
)
689 /* Got a reset ACK, reset incoming dictionary */
690 struct ccp
*ccp
= fsm2ccp(fp
);
692 if (ccp
->reset_sent
!= -1) {
693 if (id
!= ccp
->reset_sent
) {
694 log_Printf(LogCCP
, "%s: Incorrect ResetAck (id %d, not %d)"
695 " ignored\n", fp
->link
->name
, id
, ccp
->reset_sent
);
698 /* Whaddaya know - a correct reset ack */
699 } else if (id
== ccp
->last_reset
)
700 log_Printf(LogCCP
, "%s: Duplicate ResetAck (resetting again)\n",
703 log_Printf(LogCCP
, "%s: Unexpected ResetAck (id %d) ignored\n",
708 ccp
->last_reset
= ccp
->reset_sent
;
709 ccp
->reset_sent
= -1;
710 if (ccp
->in
.state
!= NULL
)
711 (*algorithm
[ccp
->in
.algorithm
]->i
.Reset
)(ccp
->in
.state
);
715 ccp_LayerPush(struct bundle
*b __unused
, struct link
*l
, struct mbuf
*bp
,
716 int pri
, u_short
*proto
)
718 if (PROTO_COMPRESSIBLE(*proto
)) {
719 if (l
->ccp
.fsm
.state
!= ST_OPENED
) {
720 if (ccp_Required(&l
->ccp
)) {
721 /* The NCP layer shouldn't have let this happen ! */
722 log_Printf(LogERROR
, "%s: Unexpected attempt to use an unopened and"
723 " required CCP layer\n", l
->name
);
727 } else if (l
->ccp
.out
.state
!= NULL
) {
728 bp
= (*algorithm
[l
->ccp
.out
.algorithm
]->o
.Write
)
729 (l
->ccp
.out
.state
, &l
->ccp
, l
, pri
, proto
, bp
);
732 m_settype(bp
, MB_ICOMPDOUT
);
735 m_settype(bp
, MB_COMPDOUT
);
745 ccp_LayerPull(struct bundle
*b __unused
, struct link
*l
, struct mbuf
*bp
,
749 * If proto isn't PROTO_[I]COMPD, we still want to pass it to the
750 * decompression routines so that the dictionary's updated
752 if (l
->ccp
.fsm
.state
== ST_OPENED
) {
753 if (*proto
== PROTO_COMPD
|| *proto
== PROTO_ICOMPD
) {
754 /* Decompress incoming data */
755 if (l
->ccp
.reset_sent
!= -1)
756 /* Send another REQ and put the packet in the bit bucket */
757 fsm_Output(&l
->ccp
.fsm
, CODE_RESETREQ
, l
->ccp
.reset_sent
, NULL
, 0,
759 else if (l
->ccp
.in
.state
!= NULL
) {
760 bp
= (*algorithm
[l
->ccp
.in
.algorithm
]->i
.Read
)
761 (l
->ccp
.in
.state
, &l
->ccp
, proto
, bp
);
764 m_settype(bp
, MB_ICOMPDIN
);
767 m_settype(bp
, MB_COMPDIN
);
774 } else if (PROTO_COMPRESSIBLE(*proto
) && l
->ccp
.in
.state
!= NULL
) {
775 /* Add incoming Network Layer traffic to our dictionary */
776 (*algorithm
[l
->ccp
.in
.algorithm
]->i
.DictSetup
)
777 (l
->ccp
.in
.state
, &l
->ccp
, *proto
, bp
);
785 ccp_Proto(struct ccp
*ccp
)
787 return !link2physical(ccp
->fsm
.link
) || !ccp
->fsm
.bundle
->ncp
.mp
.active
?
788 PROTO_COMPD
: PROTO_ICOMPD
;
792 ccp_SetOpenMode(struct ccp
*ccp
)
796 for (f
= 0; f
< CCP_NEG_TOTAL
; f
++)
797 if (IsEnabled(ccp
->cfg
.neg
[f
])) {
798 ccp
->fsm
.open_mode
= 0;
802 ccp
->fsm
.open_mode
= OPEN_PASSIVE
; /* Go straight to ST_STOPPED ? */
804 for (f
= 0; f
< CCP_NEG_TOTAL
; f
++)
805 if (IsAccepted(ccp
->cfg
.neg
[f
]))
808 return 0; /* No CCP at all */
812 ccp_DefaultUsable(struct fsm
*fp __unused
)
818 ccp_DefaultRequired(struct fsm
*fp __unused
)
823 struct layer ccplayer
= { LAYER_CCP
, "ccp", ccp_LayerPush
, ccp_LayerPull
};