Home | History | Annotate | Download | only in src

Lines Matching defs:ccp

28  * $FreeBSD: src/usr.sbin/ppp/ccp.c,v 1.78.26.1 2010/12/21 17:10:29 kensmith Exp $
60 #include "ccp.h"
108 {"CCP restart", "CCP openmode", "CCP stopped"};
163 struct ccp *ccp;
167 ccp = &l->ccp;
169 prompt_Printf(arg->prompt, "%s: %s [%s]\n", l->name, ccp->fsm.name,
170 State2Nam(ccp->fsm.state));
171 if (ccp->fsm.state == ST_OPENED) {
173 protoname(ccp->my_proto), protoname(ccp->his_proto));
175 ccp->uncompout, ccp->compout,
176 ccp->compin, ccp->uncompin);
179 if (ccp->in.algorithm != -1)
181 (*algorithm[ccp->in.algorithm]->Disp)(&ccp->in.opt));
183 if (ccp->out.algorithm != -1) {
184 o = &ccp->out.opt;
185 for (f = 0; f < ccp->out.algorithm; f++)
186 if (IsEnabled(ccp->cfg.neg[algorithm[f]->Neg]))
189 (*algorithm[ccp->out.algorithm]->Disp)(&(*o)->val));
194 " REQ%s, %u Term REQ%s\n", ccp->cfg.fsm.timeout,
195 ccp->cfg.fsm.maxreq, ccp->cfg.fsm.maxreq == 1 ? "" : "s",
196 ccp->cfg.fsm.maxtrm, ccp->cfg.fsm.maxtrm == 1 ? "" : "s");
198 prompt_Printf(arg->prompt, "incoming = %d, ", ccp->cfg.deflate.in.winsize);
199 prompt_Printf(arg->prompt, "outgoing = %d\n", ccp->cfg.deflate.out.winsize);
202 if (ccp->cfg.mppe.keybits)
203 prompt_Printf(arg->prompt, "%d bits, ", ccp->cfg.mppe.keybits);
206 switch (ccp->cfg.mppe.state) {
218 ccp->cfg.mppe.required ? ", required" : "");
222 command_ShowNegval(ccp->cfg.neg[CCP_NEG_DEFLATE]));
224 command_ShowNegval(ccp->cfg.neg[CCP_NEG_PRED1]));
226 command_ShowNegval(ccp->cfg.neg[CCP_NEG_DEFLATE24]));
229 command_ShowNegval(ccp->cfg.neg[CCP_NEG_MPPE]));
235 ccp_SetupCallbacks(struct ccp *ccp)
237 ccp->fsm.fn = &ccp_Callbacks;
238 ccp->fsm.FsmTimer.name = ccp_TimerNames[0];
239 ccp->fsm.OpenTimer.name = ccp_TimerNames[1];
240 ccp->fsm.StoppedTimer.name = ccp_TimerNames[2];
244 ccp_Init(struct ccp *ccp, struct bundle *bundle, struct link *l,
249 fsm_Init(&ccp->fsm, "CCP", PROTO_CCP, 1, CCP_MAXCODE, LogCCP,
252 ccp->cfg.deflate.in.winsize = 0;
253 ccp->cfg.deflate.out.winsize = 15;
254 ccp->cfg.fsm.timeout = DEF_FSMRETRY;
255 ccp->cfg.fsm.maxreq = DEF_FSMTRIES;
256 ccp->cfg.fsm.maxtrm = DEF_FSMTRIES;
257 ccp->cfg.neg[CCP_NEG_DEFLATE] = NEG_ENABLED|NEG_ACCEPTED;
258 ccp->cfg.neg[CCP_NEG_PRED1] = NEG_ENABLED|NEG_ACCEPTED;
259 ccp->cfg.neg[CCP_NEG_DEFLATE24] = 0;
261 ccp->cfg.mppe.keybits = 0;
262 ccp->cfg.mppe.state = MPPE_ANYSTATE;
263 ccp->cfg.mppe.required = 0;
264 ccp->cfg.neg[CCP_NEG_MPPE] = NEG_ENABLED|NEG_ACCEPTED;
267 ccp_Setup(ccp);
271 ccp_Setup(struct ccp *ccp)
274 ccp->fsm.open_mode = 0;
275 ccp->his_proto = ccp->my_proto = -1;
276 ccp->reset_sent = ccp->last_reset = -1;
277 ccp->in.algorithm = ccp->out.algorithm = -1;
278 ccp->in.state = ccp->out.state = NULL;
279 ccp->in.opt.hdr.id = -1;
280 ccp->out.opt = NULL;
281 ccp->his_reject = ccp->my_reject = 0;
282 ccp->uncompout = ccp->compout = 0;
283 ccp->uncompin = ccp->compin = 0;
287 * Is ccp *REQUIRED* ?
288 * We ask each of the configured ccp protocols if they're required and
291 * It's not possible for the peer to reject a required ccp protocol
294 * If ccp is required but not open, the NCP layer should not push
298 ccp_Required(struct ccp *ccp)
303 if (IsEnabled(ccp->cfg.neg[algorithm[f]->Neg]) &&
304 (*algorithm[f]->Required)(&ccp->fsm))
315 ccp_MTUOverhead(struct ccp *ccp)
317 if (ccp->fsm.state == ST_OPENED && ccp->out.algorithm >= 0)
318 return algorithm[ccp->out.algorithm]->o.MTUOverhead;
327 struct ccp *ccp = fsm2ccp(fp);
329 fp->FsmTimer.load = ccp->cfg.fsm.timeout * SECTICKS;
332 fp->restart = ccp->cfg.fsm.maxreq;
335 fp->restart = ccp->cfg.fsm.maxtrm;
347 struct ccp *ccp = fsm2ccp(fp);
354 o = &ccp->out.opt;
355 alloc = ccp->his_reject == 0 && ccp->out.opt == NULL;
356 ccp->my_proto = -1;
357 ccp->out.algorithm = -1;
359 if (IsEnabled(ccp->cfg.neg[algorithm[f]->Neg]) &&
360 !REJECTED(ccp, algorithm[f]->id) &&
364 for (o = &ccp->out.opt; *o != NULL; o = &(*o)->next)
370 log_Printf(LogERROR, "%s: Not enough memory for CCP REQ !\n",
378 (*algorithm[f]->o.OptInit)(fp->bundle, &(*o)->val, &ccp->cfg);
382 log_Printf(LogERROR, "%s: CCP REQ buffer overrun !\n", fp->link->name);
388 ccp->my_proto = (*o)->val.hdr.id;
389 ccp->out.algorithm = f;
402 struct ccp *ccp = fsm2ccp(fp);
404 ccp->reset_sent = fp->reqid;
405 ccp->last_reset = -1;
426 struct ccp *ccp = fsm2ccp(fp);
427 if (ccp->out.state == NULL)
429 return (*algorithm[ccp->out.algorithm]->o.Reset)(ccp->out.state);
436 struct ccp *ccp = fsm2ccp(fp);
439 fp->more.reqs = fp->more.naks = fp->more.rejs = ccp->cfg.fsm.maxreq * 3;
446 struct ccp *ccp = fsm2ccp(fp);
450 if (ccp->in.state != NULL) {
451 (*algorithm[ccp->in.algorithm]->i.Term)(ccp->in.state);
452 ccp->in.state = NULL;
453 ccp->in.algorithm = -1;
455 if (ccp->out.state != NULL) {
456 (*algorithm[ccp->out.algorithm]->o.Term)(ccp->out.state);
457 ccp->out.state = NULL;
458 ccp->out.algorithm = -1;
460 ccp->his_reject = ccp->my_reject = 0;
462 while (ccp->out.opt) {
463 next = ccp->out.opt->next;
464 free(ccp->out.opt);
465 ccp->out.opt = next;
467 ccp_Setup(ccp);
474 struct ccp *ccp = fsm2ccp(fp);
483 while (ccp->out.opt) {
484 next = ccp->out.opt->next;
485 free(ccp->out.opt);
486 ccp->out.opt = next;
489 if (ccp_Required(ccp)) {
491 log_Printf(LogLCP, "%s: Closing due to CCP completion\n", fp->link->name);
496 /* Called when CCP has reached the OPEN state */
501 struct ccp *ccp = fsm2ccp(fp);
506 if (IsEnabled(ccp->cfg.neg[algorithm[f]->Neg]) &&
507 (*algorithm[f]->Required)(&ccp->fsm) &&
508 (ccp->in.algorithm != (int)f || ccp->out.algorithm != (int)f)) {
516 ccp->his_proto = ccp->my_proto = -1;
524 if (ccp->in.state == NULL && ccp->in.algorithm >= 0 &&
525 ccp->in.algorithm < (int)NALGORITHMS) {
526 ccp->in.state = (*algorithm[ccp->in.algorithm]->i.Init)
527 (fp->bundle, &ccp->in.opt);
528 if (ccp->in.state == NULL) {
530 fp->link->name, protoname(ccp->his_proto));
531 ccp->his_proto = ccp->my_proto = -1;
537 o = &ccp->out.opt;
538 if (ccp->out.algorithm > 0)
539 for (f = 0; f < (unsigned)ccp->out.algorithm; f++)
540 if (IsEnabled(ccp->cfg.neg[algorithm[f]->Neg]))
543 if (ccp->out.state == NULL && ccp->out.algorithm >= 0 &&
544 ccp->out.algorithm < (int)NALGORITHMS) {
545 ccp->out.state = (*algorithm[ccp->out.algorithm]->o.Init)
547 if (ccp->out.state == NULL) {
549 fp->link->name, protoname(ccp->my_proto));
550 ccp->his_proto = ccp->my_proto = -1;
556 fp->more.reqs = fp->more.naks = fp->more.rejs = ccp->cfg.fsm.maxreq * 3;
559 fp->link->name, protoname(ccpccp->my_proto,
560 protoname(ccp->his_proto), ccp->his_proto);
570 struct ccp *ccp = fsm2ccp(fp);
576 ccp->in.algorithm = -1; /* In case we've received two REQs in a row */
596 ccp->my_reject |= (1 << opt->hdr.id);
604 if (IsAccepted(ccp->cfg.neg[algorithm[f]->Neg]) &&
606 ccp->in.algorithm == -1) {
607 memcpy(&ccp->in.opt, opt, opt->hdr.len);
608 switch ((*algorithm[f]->i.Set)(fp->bundle, &ccp->in.opt, &ccp->cfg)) {
610 fsm_rej(dec, &ccp->in.opt);
613 fsm_nak(dec, &ccp->in.opt);
616 fsm_ack(dec, &ccp->in.opt);
617 ccp->his_proto = opt->hdr.id;
618 ccp->in.algorithm = (int)f; /* This one'll do :-) */
626 for (o = ccp->out.opt; o != NULL; o = o->next)
634 if ((*algorithm[f]->o.Set)(fp->bundle, &o->val, &ccp->cfg) ==
636 ccp->my_proto = algorithm[f]->id;
638 ccp->his_reject |= (1 << opt->hdr.id);
639 ccp->my_proto = -1;
650 ccp->his_reject |= (1 << opt->hdr.id);
651 ccp->my_proto = -1;
665 if (ccp->in.state == NULL) {
666 ccp->his_proto = -1;
667 ccp->in.algorithm = -1;
679 fsm_Input(&l->ccp.fsm, bp);
682 log_Printf(LogCCP, "%s: Error: Unexpected CCP in phase %s (ignored)\n",
683 l->ccp.fsm.link->name, bundle_PhaseName(bundle));
693 struct ccp *ccp = fsm2ccp(fp);
695 if (ccp->reset_sent != -1) {
696 if (id != ccp->reset_sent) {
698 " ignored\n", fp->link->name, id, ccp->reset_sent);
702 } else if (id == ccp->last_reset)
711 ccp->last_reset = ccp->reset_sent;
712 ccp->reset_sent = -1;
713 if (ccp->in.state != NULL)
714 (*algorithm[ccp->in.algorithm]->i.Reset)(ccp->in.state);
722 if (l->ccp.fsm.state != ST_OPENED) {
723 if (ccp_Required(&l->ccp)) {
726 " required CCP layer\n", l->name);
730 } else if (l->ccp.out.state != NULL) {
731 bp = (*algorithm[l->ccp.out.algorithm]->o.Write)
732 (l->ccp.out.state, &l->ccp, l, pri, proto, bp);
755 if (l->ccp.fsm.state == ST_OPENED) {
758 if (l->ccp.reset_sent != -1)
760 fsm_Output(&l->ccp.fsm, CODE_RESETREQ, l->ccp.reset_sent, NULL, 0,
762 else if (l->ccp.in.state != NULL) {
763 bp = (*algorithm[l->ccp.in.algorithm]->i.Read)
764 (l->ccp.in.state, &l->ccp, proto, bp);
777 } else if (PROTO_COMPRESSIBLE(*proto) && l->ccp.in.state != NULL) {
779 (*algorithm[l->ccp.in.algorithm]->i.DictSetup)
780 (l->ccp.in.state, &l->ccp, *proto, bp);
788 ccp_Proto(struct ccp *ccp)
790 return !link2physical(ccp->fsm.link) || !ccp->fsm.bundle->ncp.mp.active ?
795 ccp_SetOpenMode(struct ccp *ccp)
800 if (IsEnabled(ccp->cfg.neg[f])) {
801 ccp->fsm.open_mode = 0;
805 ccp->fsm.open_mode = OPEN_PASSIVE; /* Go straight to ST_STOPPED ? */
808 if (IsAccepted(ccp->cfg.neg[f]))
811 return 0; /* No CCP at all */
826 struct layer ccplayer = { LAYER_CCP, "ccp", ccp_LayerPush, ccp_LayerPull };