1995-01-31 06:29:58 +00:00
|
|
|
/*
|
|
|
|
* PPP Link Control Protocol (LCP) Module
|
|
|
|
*
|
|
|
|
* Written by Toshiharu OHNO (tony-o@iij.ad.jp)
|
|
|
|
*
|
|
|
|
* Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that the above copyright notice and this paragraph are
|
|
|
|
* duplicated in all such forms and that any documentation,
|
|
|
|
* advertising materials, and other materials related to such
|
|
|
|
* distribution and use acknowledge that the software was developed
|
|
|
|
* by the Internet Initiative Japan, Inc. The name of the
|
|
|
|
* IIJ may not be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
1995-05-30 03:57:47 +00:00
|
|
|
*
|
1998-05-29 18:32:41 +00:00
|
|
|
* $Id: lcp.c,v 1.57 1998/05/21 21:46:00 brian Exp $
|
1995-05-30 03:57:47 +00:00
|
|
|
*
|
1995-01-31 06:29:58 +00:00
|
|
|
* TODO:
|
|
|
|
* o Limit data field length by MRU
|
|
|
|
*/
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-04-23 03:23:03 +00:00
|
|
|
#include <sys/types.h>
|
1998-01-21 02:15:33 +00:00
|
|
|
#include <netinet/in.h>
|
1998-04-23 03:23:03 +00:00
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
1998-04-28 01:25:46 +00:00
|
|
|
#include <sys/un.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
|
1997-09-22 02:51:24 +00:00
|
|
|
#include <signal.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
1997-11-22 03:37:54 +00:00
|
|
|
#include "command.h"
|
1997-10-26 01:04:02 +00:00
|
|
|
#include "mbuf.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "defs.h"
|
|
|
|
#include "timer.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "fsm.h"
|
1998-04-23 03:23:03 +00:00
|
|
|
#include "iplist.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "lcp.h"
|
1998-01-29 23:11:44 +00:00
|
|
|
#include "throughput.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "lcpproto.h"
|
1998-03-20 19:48:28 +00:00
|
|
|
#include "descriptor.h"
|
1998-03-13 00:44:26 +00:00
|
|
|
#include "lqr.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "hdlc.h"
|
1996-01-11 17:48:59 +00:00
|
|
|
#include "ccp.h"
|
1998-01-29 00:44:16 +00:00
|
|
|
#include "async.h"
|
1998-01-30 19:46:07 +00:00
|
|
|
#include "link.h"
|
1998-01-29 00:49:32 +00:00
|
|
|
#include "physical.h"
|
1998-02-10 03:23:50 +00:00
|
|
|
#include "prompt.h"
|
1998-04-23 03:23:03 +00:00
|
|
|
#include "slcompress.h"
|
|
|
|
#include "ipcp.h"
|
|
|
|
#include "filter.h"
|
|
|
|
#include "mp.h"
|
1998-04-24 19:16:15 +00:00
|
|
|
#include "chat.h"
|
1995-02-26 12:18:08 +00:00
|
|
|
#include "auth.h"
|
1997-10-26 01:04:02 +00:00
|
|
|
#include "chap.h"
|
1998-04-24 19:16:15 +00:00
|
|
|
#include "datalink.h"
|
1998-04-23 03:23:03 +00:00
|
|
|
#include "bundle.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-12-03 10:23:54 +00:00
|
|
|
/* for received LQRs */
|
|
|
|
struct lqrreq {
|
|
|
|
u_char type;
|
|
|
|
u_char length;
|
|
|
|
u_short proto; /* Quality protocol */
|
|
|
|
u_long period; /* Reporting interval */
|
|
|
|
};
|
|
|
|
|
1998-04-30 23:53:56 +00:00
|
|
|
static int LcpLayerUp(struct fsm *);
|
1997-06-09 03:27:43 +00:00
|
|
|
static void LcpLayerDown(struct fsm *);
|
|
|
|
static void LcpLayerStart(struct fsm *);
|
|
|
|
static void LcpLayerFinish(struct fsm *);
|
1998-01-31 02:48:30 +00:00
|
|
|
static void LcpInitRestartCounter(struct fsm *);
|
|
|
|
static void LcpSendConfigReq(struct fsm *);
|
1998-03-20 19:47:10 +00:00
|
|
|
static void LcpSentTerminateReq(struct fsm *);
|
|
|
|
static void LcpSendTerminateAck(struct fsm *, u_char);
|
1998-03-13 21:08:05 +00:00
|
|
|
static void LcpDecodeConfig(struct fsm *, u_char *, int, int,
|
|
|
|
struct fsm_decode *);
|
1998-02-06 02:24:29 +00:00
|
|
|
|
|
|
|
static struct fsm_callbacks lcp_Callbacks = {
|
1998-02-27 01:22:39 +00:00
|
|
|
LcpLayerUp,
|
|
|
|
LcpLayerDown,
|
|
|
|
LcpLayerStart,
|
|
|
|
LcpLayerFinish,
|
1998-02-06 02:24:29 +00:00
|
|
|
LcpInitRestartCounter,
|
|
|
|
LcpSendConfigReq,
|
1998-03-20 19:47:10 +00:00
|
|
|
LcpSentTerminateReq,
|
1998-02-06 02:24:29 +00:00
|
|
|
LcpSendTerminateAck,
|
1998-02-21 01:45:26 +00:00
|
|
|
LcpDecodeConfig,
|
1998-05-01 19:26:12 +00:00
|
|
|
fsm_NullRecvResetReq,
|
|
|
|
fsm_NullRecvResetAck
|
1998-02-06 02:24:29 +00:00
|
|
|
};
|
1998-01-31 02:48:30 +00:00
|
|
|
|
1998-04-30 23:53:56 +00:00
|
|
|
static const char *lcp_TimerNames[] =
|
|
|
|
{"LCP restart", "LCP openmode", "LCP stopped"};
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-11-22 03:37:54 +00:00
|
|
|
static const char *cftypes[] = {
|
1997-11-14 15:39:15 +00:00
|
|
|
/* Check out the latest ``Assigned numbers'' rfc (rfc1700.txt) */
|
|
|
|
"???",
|
|
|
|
"MRU", /* 1: Maximum-Receive-Unit */
|
|
|
|
"ACCMAP", /* 2: Async-Control-Character-Map */
|
|
|
|
"AUTHPROTO", /* 3: Authentication-Protocol */
|
|
|
|
"QUALPROTO", /* 4: Quality-Protocol */
|
|
|
|
"MAGICNUM", /* 5: Magic-Number */
|
|
|
|
"RESERVED", /* 6: RESERVED */
|
|
|
|
"PROTOCOMP", /* 7: Protocol-Field-Compression */
|
|
|
|
"ACFCOMP", /* 8: Address-and-Control-Field-Compression */
|
|
|
|
"FCSALT", /* 9: FCS-Alternatives */
|
|
|
|
"SDP", /* 10: Self-Describing-Pad */
|
|
|
|
"NUMMODE", /* 11: Numbered-Mode */
|
|
|
|
"MULTIPROC", /* 12: Multi-Link-Procedure */
|
|
|
|
"CALLBACK", /* 13: Callback */
|
|
|
|
"CONTIME", /* 14: Connect-Time */
|
|
|
|
"COMPFRAME", /* 15: Compound-Frames */
|
|
|
|
"NDE", /* 16: Nominal-Data-Encapsulation */
|
1998-04-23 03:23:03 +00:00
|
|
|
"MRRU", /* 17: Multilink-MRRU */
|
|
|
|
"SHORTSEQ", /* 18: Multilink-Short-Sequence-Number-Header */
|
1998-05-29 18:32:41 +00:00
|
|
|
"ENDDISC", /* 19: Multilink-Endpoint-Discriminator */
|
1997-11-14 15:39:15 +00:00
|
|
|
"PROPRIETRY", /* 20: Proprietary */
|
|
|
|
"DCEID", /* 21: DCE-Identifier */
|
|
|
|
"MULTIPP", /* 22: Multi-Link-Plus-Procedure */
|
|
|
|
"LDBACP", /* 23: Link Discriminator for BACP */
|
1995-01-31 06:29:58 +00:00
|
|
|
};
|
|
|
|
|
1997-12-24 09:29:17 +00:00
|
|
|
#define NCFTYPES (sizeof cftypes/sizeof cftypes[0])
|
1997-11-14 15:39:15 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
int
|
1998-03-13 21:07:14 +00:00
|
|
|
lcp_ReportStatus(struct cmdargs const *arg)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-15 23:58:30 +00:00
|
|
|
struct link *l;
|
|
|
|
struct lcp *lcp;
|
|
|
|
|
|
|
|
if (!(l = command_ChooseLink(arg)))
|
|
|
|
return -1;
|
|
|
|
lcp = &l->lcp;
|
1998-04-03 19:21:56 +00:00
|
|
|
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "%s: %s [%s]\n", l->name, lcp->fsm.name,
|
1998-04-03 19:21:56 +00:00
|
|
|
State2Nam(lcp->fsm.state));
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt,
|
1998-04-05 19:02:49 +00:00
|
|
|
" his side: MRU %d, ACCMAP %08lx, PROTOCOMP %s, ACFCOMP %s,\n"
|
1998-04-23 03:23:03 +00:00
|
|
|
" MAGIC %08lx, MRRU %u, SHORTSEQ %s, REJECT %04x\n",
|
1998-04-03 19:21:56 +00:00
|
|
|
lcp->his_mru, (u_long)lcp->his_accmap,
|
1998-04-05 19:02:49 +00:00
|
|
|
lcp->his_protocomp ? "on" : "off",
|
|
|
|
lcp->his_acfcomp ? "on" : "off",
|
1998-04-23 03:23:03 +00:00
|
|
|
(u_long)lcp->his_magic, lcp->his_mrru,
|
|
|
|
lcp->his_shortseq ? "on" : "off", lcp->his_reject);
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt,
|
1998-04-05 19:02:49 +00:00
|
|
|
" my side: MRU %d, ACCMAP %08lx, PROTOCOMP %s, ACFCOMP %s,\n"
|
1998-04-23 03:23:03 +00:00
|
|
|
" MAGIC %08lx, MRRU %u, SHORTSEQ %s, REJECT %04x\n",
|
1998-04-03 19:21:56 +00:00
|
|
|
lcp->want_mru, (u_long)lcp->want_accmap,
|
1998-04-05 19:02:49 +00:00
|
|
|
lcp->want_protocomp ? "on" : "off",
|
|
|
|
lcp->want_acfcomp ? "on" : "off",
|
1998-04-23 03:23:03 +00:00
|
|
|
(u_long)lcp->want_magic, lcp->want_mrru,
|
|
|
|
lcp->want_shortseq ? "on" : "off", lcp->my_reject);
|
1998-04-03 19:24:07 +00:00
|
|
|
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "\n Defaults: MRU = %d, ", lcp->cfg.mru);
|
|
|
|
prompt_Printf(arg->prompt, "ACCMAP = %08lx\n", (u_long)lcp->cfg.accmap);
|
|
|
|
prompt_Printf(arg->prompt, " LQR period = %us, ",
|
|
|
|
lcp->cfg.lqrperiod);
|
|
|
|
prompt_Printf(arg->prompt, "Open Mode = %s",
|
1998-04-03 19:24:07 +00:00
|
|
|
lcp->cfg.openmode == OPEN_PASSIVE ? "passive" : "active");
|
|
|
|
if (lcp->cfg.openmode > 0)
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, " (delay %ds)", lcp->cfg.openmode);
|
|
|
|
prompt_Printf(arg->prompt, "\n FSM retry = %us\n",
|
|
|
|
lcp->cfg.fsmretry);
|
1998-04-16 00:26:21 +00:00
|
|
|
prompt_Printf(arg->prompt, "\n Negotiation:\n");
|
|
|
|
prompt_Printf(arg->prompt, " ACFCOMP = %s\n",
|
|
|
|
command_ShowNegval(lcp->cfg.acfcomp));
|
|
|
|
prompt_Printf(arg->prompt, " CHAP = %s\n",
|
|
|
|
command_ShowNegval(lcp->cfg.chap));
|
|
|
|
prompt_Printf(arg->prompt, " LQR = %s\n",
|
|
|
|
command_ShowNegval(lcp->cfg.lqr));
|
|
|
|
prompt_Printf(arg->prompt, " PAP = %s\n",
|
|
|
|
command_ShowNegval(lcp->cfg.pap));
|
|
|
|
prompt_Printf(arg->prompt, " PROTOCOMP = %s\n",
|
|
|
|
command_ShowNegval(lcp->cfg.protocomp));
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1998-01-11 17:50:49 +00:00
|
|
|
static u_int32_t
|
1997-11-22 03:37:54 +00:00
|
|
|
GenerateMagic(void)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Generate random number which will be used as magic number */
|
1997-10-26 01:04:02 +00:00
|
|
|
randinit();
|
1998-04-23 03:23:03 +00:00
|
|
|
return random();
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-04-30 23:53:56 +00:00
|
|
|
lcp_SetupCallbacks(struct lcp *lcp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-04-30 23:53:56 +00:00
|
|
|
lcp->fsm.fn = &lcp_Callbacks;
|
|
|
|
lcp->fsm.FsmTimer.name = lcp_TimerNames[0];
|
|
|
|
lcp->fsm.OpenTimer.name = lcp_TimerNames[1];
|
|
|
|
lcp->fsm.StoppedTimer.name = lcp_TimerNames[2];
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
void
|
1998-04-03 19:21:56 +00:00
|
|
|
lcp_Init(struct lcp *lcp, struct bundle *bundle, struct link *l,
|
1998-02-27 01:22:39 +00:00
|
|
|
const struct fsm_parent *parent)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Initialise ourselves */
|
1998-04-03 19:21:56 +00:00
|
|
|
int mincode = parent ? 1 : LCP_MINMPCODE;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
fsm_Init(&lcp->fsm, "LCP", PROTO_LCP, mincode, LCP_MAXCODE, 10, LogLCP,
|
1998-04-30 23:53:56 +00:00
|
|
|
bundle, l, parent, &lcp_Callbacks, lcp_TimerNames);
|
1998-04-03 19:24:07 +00:00
|
|
|
|
|
|
|
lcp->cfg.mru = DEF_MRU;
|
|
|
|
lcp->cfg.accmap = 0;
|
|
|
|
lcp->cfg.openmode = 1;
|
|
|
|
lcp->cfg.lqrperiod = DEF_LQRPERIOD;
|
|
|
|
lcp->cfg.fsmretry = DEF_FSMRETRY;
|
|
|
|
|
1998-04-16 00:26:21 +00:00
|
|
|
lcp->cfg.acfcomp = NEG_ENABLED|NEG_ACCEPTED;
|
|
|
|
lcp->cfg.chap = NEG_ACCEPTED;
|
|
|
|
lcp->cfg.lqr = NEG_ACCEPTED;
|
|
|
|
lcp->cfg.pap = NEG_ACCEPTED;
|
|
|
|
lcp->cfg.protocomp = NEG_ENABLED|NEG_ACCEPTED;
|
|
|
|
|
1998-04-03 19:24:07 +00:00
|
|
|
lcp_Setup(lcp, lcp->cfg.openmode);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1998-02-21 01:45:26 +00:00
|
|
|
void
|
|
|
|
lcp_Setup(struct lcp *lcp, int openmode)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-02-21 01:45:26 +00:00
|
|
|
lcp->fsm.open_mode = openmode;
|
1998-02-27 21:46:26 +00:00
|
|
|
lcp->fsm.maxconfig = 10;
|
1998-02-21 01:45:26 +00:00
|
|
|
|
|
|
|
lcp->his_mru = DEF_MRU;
|
1998-04-23 03:23:03 +00:00
|
|
|
lcp->his_mrru = 0;
|
1998-02-21 01:45:26 +00:00
|
|
|
lcp->his_magic = 0;
|
|
|
|
lcp->his_lqrperiod = 0;
|
|
|
|
lcp->his_acfcomp = 0;
|
|
|
|
lcp->his_auth = 0;
|
1998-04-23 03:23:03 +00:00
|
|
|
lcp->his_shortseq = 0;
|
1998-02-21 01:45:26 +00:00
|
|
|
|
1998-04-03 19:24:07 +00:00
|
|
|
lcp->want_mru = lcp->cfg.mru;
|
1998-04-23 03:23:03 +00:00
|
|
|
lcp->want_mrru = lcp->fsm.bundle->ncp.mp.cfg.mrru;
|
|
|
|
lcp->want_shortseq = IsEnabled(lcp->fsm.bundle->ncp.mp.cfg.shortseq) ? 1 : 0;
|
1998-04-16 00:26:21 +00:00
|
|
|
lcp->want_acfcomp = IsEnabled(lcp->cfg.acfcomp) ? 1 : 0;
|
1998-02-21 01:45:26 +00:00
|
|
|
|
1998-04-03 19:26:12 +00:00
|
|
|
if (lcp->fsm.parent) {
|
|
|
|
lcp->his_accmap = 0xffffffff;
|
|
|
|
lcp->want_accmap = lcp->cfg.accmap;
|
|
|
|
lcp->his_protocomp = 0;
|
1998-04-16 00:26:21 +00:00
|
|
|
lcp->want_protocomp = IsEnabled(lcp->cfg.protocomp) ? 1 : 0;
|
1998-04-03 19:26:12 +00:00
|
|
|
lcp->want_magic = GenerateMagic();
|
1998-04-16 00:26:21 +00:00
|
|
|
lcp->want_auth = IsEnabled(lcp->cfg.chap) ? PROTO_CHAP :
|
|
|
|
IsEnabled(lcp->cfg.pap) ? PROTO_PAP : 0;
|
|
|
|
lcp->want_lqrperiod = IsEnabled(lcp->cfg.lqr) ?
|
|
|
|
lcp->cfg.lqrperiod * 100 : 0;
|
1998-04-03 19:26:12 +00:00
|
|
|
} else {
|
|
|
|
lcp->his_accmap = lcp->want_accmap = 0;
|
|
|
|
lcp->his_protocomp = lcp->want_protocomp = 1;
|
|
|
|
lcp->want_magic = 0;
|
|
|
|
lcp->want_auth = 0;
|
|
|
|
lcp->want_lqrperiod = 0;
|
|
|
|
}
|
|
|
|
|
1998-02-21 01:45:26 +00:00
|
|
|
lcp->his_reject = lcp->my_reject = 0;
|
|
|
|
lcp->auth_iwait = lcp->auth_ineed = 0;
|
1998-04-03 19:21:56 +00:00
|
|
|
lcp->LcpFailedMagic = 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
static void
|
|
|
|
LcpInitRestartCounter(struct fsm * fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Set fsm timer load */
|
1998-04-03 19:24:07 +00:00
|
|
|
struct lcp *lcp = fsm2lcp(fp);
|
1997-12-03 10:23:54 +00:00
|
|
|
|
1998-04-03 19:24:07 +00:00
|
|
|
fp->FsmTimer.load = lcp->cfg.fsmretry * SECTICKS;
|
1998-01-29 00:44:16 +00:00
|
|
|
fp->restart = 5;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-01-30 19:46:07 +00:00
|
|
|
LcpSendConfigReq(struct fsm *fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Send config REQ please */
|
1998-01-30 19:46:07 +00:00
|
|
|
struct physical *p = link2physical(fp->link);
|
1998-02-08 11:05:01 +00:00
|
|
|
struct lcp *lcp = fsm2lcp(fp);
|
1998-04-23 03:23:03 +00:00
|
|
|
u_char buff[200];
|
1998-03-20 19:47:10 +00:00
|
|
|
struct lcp_opt *o;
|
1998-04-23 03:23:03 +00:00
|
|
|
struct mp *mp;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-01-30 19:46:07 +00:00
|
|
|
if (!p) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogERROR, "%s: LcpSendConfigReq: Not a physical link !\n",
|
1998-04-24 19:15:48 +00:00
|
|
|
fp->link->name);
|
1998-01-30 19:46:07 +00:00
|
|
|
return;
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-03-20 19:47:10 +00:00
|
|
|
o = (struct lcp_opt *)buff;
|
1998-05-01 19:26:12 +00:00
|
|
|
if (!physical_IsSync(p)) {
|
1997-12-03 10:23:54 +00:00
|
|
|
if (lcp->want_acfcomp && !REJECTED(lcp, TY_ACFCOMP))
|
1998-03-20 19:47:10 +00:00
|
|
|
INC_LCP_OPT(TY_ACFCOMP, 2, o);
|
1997-12-03 10:23:54 +00:00
|
|
|
|
|
|
|
if (lcp->want_protocomp && !REJECTED(lcp, TY_PROTOCOMP))
|
1998-03-20 19:47:10 +00:00
|
|
|
INC_LCP_OPT(TY_PROTOCOMP, 2, o);
|
1997-12-03 10:23:54 +00:00
|
|
|
|
1998-03-20 19:47:10 +00:00
|
|
|
if (!REJECTED(lcp, TY_ACCMAP)) {
|
|
|
|
*(u_int32_t *)o->data = htonl(lcp->want_accmap);
|
|
|
|
INC_LCP_OPT(TY_ACCMAP, 6, o);
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1997-12-03 10:23:54 +00:00
|
|
|
|
1998-03-20 19:47:10 +00:00
|
|
|
if (!REJECTED(lcp, TY_MRU)) {
|
|
|
|
*(u_short *)o->data = htons(lcp->want_mru);
|
|
|
|
INC_LCP_OPT(TY_MRU, 4, o);
|
|
|
|
}
|
1997-12-03 10:23:54 +00:00
|
|
|
|
1998-03-20 19:47:10 +00:00
|
|
|
if (lcp->want_magic && !REJECTED(lcp, TY_MAGICNUM)) {
|
|
|
|
*(u_int32_t *)o->data = htonl(lcp->want_magic);
|
|
|
|
INC_LCP_OPT(TY_MAGICNUM, 6, o);
|
|
|
|
}
|
1997-12-03 10:23:54 +00:00
|
|
|
|
1998-03-20 19:47:10 +00:00
|
|
|
if (lcp->want_lqrperiod && !REJECTED(lcp, TY_QUALPROTO)) {
|
|
|
|
*(u_short *)o->data = htons(PROTO_LQR);
|
|
|
|
*(u_long *)(o->data + 2) = htonl(lcp->want_lqrperiod);
|
|
|
|
INC_LCP_OPT(TY_QUALPROTO, 8, o);
|
|
|
|
}
|
1997-12-03 10:23:54 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
switch (lcp->want_auth) {
|
|
|
|
case PROTO_PAP:
|
1998-03-20 19:47:10 +00:00
|
|
|
*(u_short *)o->data = htons(PROTO_PAP);
|
|
|
|
INC_LCP_OPT(TY_AUTHPROTO, 4, o);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
1997-12-03 10:23:54 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
case PROTO_CHAP:
|
1998-03-20 19:47:10 +00:00
|
|
|
*(u_short *)o->data = htons(PROTO_CHAP);
|
1998-04-03 19:26:29 +00:00
|
|
|
o->data[2] = 0x05;
|
1998-03-20 19:47:10 +00:00
|
|
|
INC_LCP_OPT(TY_AUTHPROTO, 5, o);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1998-04-23 03:23:03 +00:00
|
|
|
if (lcp->want_mrru && !REJECTED(lcp, TY_MRRU)) {
|
|
|
|
*(u_short *)o->data = htons(lcp->want_mrru);
|
|
|
|
INC_LCP_OPT(TY_MRRU, 4, o);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-04-23 03:23:03 +00:00
|
|
|
if (lcp->want_shortseq && !REJECTED(lcp, TY_SHORTSEQ))
|
|
|
|
INC_LCP_OPT(TY_SHORTSEQ, 2, o);
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-04-23 03:23:03 +00:00
|
|
|
mp = &lcp->fsm.bundle->ncp.mp;
|
|
|
|
if (mp->cfg.enddisc.class != 0 && !REJECTED(lcp, TY_ENDDISC)) {
|
|
|
|
*o->data = mp->cfg.enddisc.class;
|
|
|
|
memcpy(o->data+1, mp->cfg.enddisc.address, mp->cfg.enddisc.len);
|
|
|
|
INC_LCP_OPT(TY_ENDDISC, mp->cfg.enddisc.len + 3, o);
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-05-01 19:26:12 +00:00
|
|
|
fsm_Output(fp, CODE_CONFIGREQ, fp->reqid, buff, (u_char *)o - buff);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
void
|
1998-03-13 21:07:14 +00:00
|
|
|
lcp_SendProtoRej(struct lcp *lcp, u_char *option, int count)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Don't understand `option' */
|
1998-05-01 19:26:12 +00:00
|
|
|
fsm_Output(&lcp->fsm, CODE_PROTOREJ, lcp->fsm.reqid, option, count);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1995-02-26 12:18:08 +00:00
|
|
|
static void
|
1998-03-20 19:47:10 +00:00
|
|
|
LcpSentTerminateReq(struct fsm * fp)
|
1995-02-26 12:18:08 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Term REQ just sent by FSM */
|
1995-02-26 12:18:08 +00:00
|
|
|
}
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
static void
|
1998-03-20 19:47:10 +00:00
|
|
|
LcpSendTerminateAck(struct fsm *fp, u_char id)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Send Term ACK please */
|
1998-05-01 19:26:12 +00:00
|
|
|
fsm_Output(fp, CODE_TERMACK, id, NULL, 0);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-01-30 19:46:07 +00:00
|
|
|
LcpLayerStart(struct fsm *fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* We're about to start up ! */
|
1998-03-13 21:07:14 +00:00
|
|
|
struct lcp *lcp = fsm2lcp(fp);
|
|
|
|
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "%s: LcpLayerStart\n", fp->link->name);
|
1998-03-13 21:07:14 +00:00
|
|
|
lcp->LcpFailedMagic = 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-01-30 19:46:07 +00:00
|
|
|
LcpLayerFinish(struct fsm *fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* We're now down */
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "%s: LcpLayerFinish\n", fp->link->name);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1998-04-30 23:53:56 +00:00
|
|
|
static int
|
1998-01-30 19:46:07 +00:00
|
|
|
LcpLayerUp(struct fsm *fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* We're now up */
|
1998-01-30 19:46:07 +00:00
|
|
|
struct physical *p = link2physical(fp->link);
|
1998-02-08 11:05:01 +00:00
|
|
|
struct lcp *lcp = fsm2lcp(fp);
|
1998-01-30 19:46:07 +00:00
|
|
|
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "%s: LcpLayerUp\n", fp->link->name);
|
1998-04-03 19:21:56 +00:00
|
|
|
async_SetLinkParams(&p->async, lcp);
|
1998-05-01 19:26:12 +00:00
|
|
|
lqr_Start(lcp);
|
1998-04-03 19:21:56 +00:00
|
|
|
hdlc_StartTimer(&p->hdlc);
|
1998-04-30 23:53:56 +00:00
|
|
|
return 1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
static void
|
1998-02-02 19:32:16 +00:00
|
|
|
LcpLayerDown(struct fsm *fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* About to come down */
|
1998-02-18 19:35:59 +00:00
|
|
|
struct physical *p = link2physical(fp->link);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "%s: LcpLayerDown\n", fp->link->name);
|
1998-02-18 19:35:59 +00:00
|
|
|
hdlc_StopTimer(&p->hdlc);
|
1998-05-01 19:26:12 +00:00
|
|
|
lqr_StopTimer(p);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-03-13 21:08:05 +00:00
|
|
|
LcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
|
|
|
|
struct fsm_decode *dec)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Deal with incoming PROTO_LCP */
|
1998-02-08 11:05:01 +00:00
|
|
|
struct lcp *lcp = fsm2lcp(fp);
|
1998-01-11 17:50:49 +00:00
|
|
|
int type, length, sz, pos;
|
1998-04-19 23:09:03 +00:00
|
|
|
u_int32_t magic, accmap;
|
1998-01-11 17:50:49 +00:00
|
|
|
u_short mtu, mru, *sp, proto;
|
1995-01-31 06:29:58 +00:00
|
|
|
struct lqrreq *req;
|
1997-12-03 10:23:54 +00:00
|
|
|
char request[20], desc[22];
|
1998-04-23 03:23:03 +00:00
|
|
|
struct mp *mp;
|
1998-04-24 19:16:15 +00:00
|
|
|
struct physical *p = link2physical(fp->link);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
while (plen >= sizeof(struct fsmconfig)) {
|
|
|
|
type = *cp;
|
|
|
|
length = cp[1];
|
1997-12-03 10:23:54 +00:00
|
|
|
|
1998-04-24 19:15:48 +00:00
|
|
|
if (length == 0) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "%s: LCP size zero\n", fp->link->name);
|
1998-04-24 19:15:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1997-12-03 10:23:54 +00:00
|
|
|
if (type < 0 || type >= NCFTYPES)
|
|
|
|
snprintf(request, sizeof request, " <%d>[%d]", type, length);
|
1995-01-31 06:29:58 +00:00
|
|
|
else
|
1997-12-03 10:23:54 +00:00
|
|
|
snprintf(request, sizeof request, " %s[%d]", cftypes[type], length);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
switch (type) {
|
1998-04-23 03:23:03 +00:00
|
|
|
case TY_MRRU:
|
|
|
|
mp = &lcp->fsm.bundle->ncp.mp;
|
|
|
|
sp = (u_short *)(cp + 2);
|
|
|
|
mru = htons(*sp);
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "%s %u\n", request, mru);
|
1998-04-23 03:23:03 +00:00
|
|
|
|
|
|
|
switch (mode_type) {
|
|
|
|
case MODE_REQ:
|
|
|
|
if (mp->cfg.mrru) {
|
|
|
|
if (REJECTED(lcp, TY_MRRU))
|
|
|
|
/* Ignore his previous reject so that we REQ next time */
|
|
|
|
lcp->his_reject &= ~(1 << type);
|
|
|
|
|
|
|
|
mtu = lcp->fsm.bundle->cfg.mtu;
|
|
|
|
if (mru < MIN_MRU || mru < mtu) {
|
|
|
|
/* Push him up to MTU or MIN_MRU */
|
|
|
|
lcp->his_mrru = mru < mtu ? mtu : MIN_MRU;
|
|
|
|
*sp = htons((u_short)lcp->his_mrru);
|
|
|
|
memcpy(dec->nakend, cp, 4);
|
|
|
|
dec->nakend += 4;
|
|
|
|
} else {
|
|
|
|
lcp->his_mrru = mtu ? mtu : mru;
|
|
|
|
memcpy(dec->ackend, cp, 4);
|
|
|
|
dec->ackend += 4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
goto reqreject;
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
|
|
|
if (mp->cfg.mrru) {
|
|
|
|
if (REJECTED(lcp, TY_MRRU))
|
|
|
|
/* Must have changed his mind ! */
|
|
|
|
lcp->his_reject &= ~(1 << type);
|
|
|
|
|
|
|
|
if (mru > MAX_MRU)
|
|
|
|
lcp->want_mrru = MAX_MRU;
|
|
|
|
else if (mru < MIN_MRU)
|
|
|
|
lcp->want_mrru = MIN_MRU;
|
|
|
|
else
|
|
|
|
lcp->want_mrru = mru;
|
|
|
|
}
|
|
|
|
/* else we honour our config and don't send the suggested REQ */
|
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
|
|
|
lcp->his_reject |= (1 << type);
|
1998-04-23 18:55:50 +00:00
|
|
|
lcp->want_mrru = 0; /* Ah well, no multilink :-( */
|
1998-04-23 03:23:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
case TY_MRU:
|
1997-08-25 00:29:32 +00:00
|
|
|
sp = (u_short *) (cp + 2);
|
1995-01-31 06:29:58 +00:00
|
|
|
mru = htons(*sp);
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "%s %d\n", request, mru);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-11-08 00:28:11 +00:00
|
|
|
switch (mode_type) {
|
1995-01-31 06:29:58 +00:00
|
|
|
case MODE_REQ:
|
1998-04-23 03:23:03 +00:00
|
|
|
mtu = lcp->fsm.bundle->cfg.mtu;
|
1998-04-23 18:55:50 +00:00
|
|
|
if (mru < MIN_MRU || (!lcp->want_mrru && mru < mtu)) {
|
1998-04-23 03:23:03 +00:00
|
|
|
/* Push him up to MTU or MIN_MRU */
|
|
|
|
lcp->his_mru = mru < mtu ? mtu : MIN_MRU;
|
|
|
|
*sp = htons((u_short)lcp->his_mru);
|
|
|
|
memcpy(dec->nakend, cp, 4);
|
|
|
|
dec->nakend += 4;
|
|
|
|
} else {
|
|
|
|
lcp->his_mru = mtu ? mtu : mru;
|
|
|
|
memcpy(dec->ackend, cp, 4);
|
|
|
|
dec->ackend += 4;
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
1998-04-23 03:23:03 +00:00
|
|
|
if (mru > MAX_MRU)
|
|
|
|
lcp->want_mru = MAX_MRU;
|
|
|
|
else if (mru < MIN_MRU)
|
|
|
|
lcp->want_mru = MIN_MRU;
|
|
|
|
else
|
|
|
|
lcp->want_mru = mru;
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->his_reject |= (1 << type);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1997-12-03 10:23:54 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
case TY_ACCMAP:
|
1998-04-19 23:09:03 +00:00
|
|
|
accmap = htonl(*(u_int32_t *)(cp + 2));
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "%s 0x%08lx\n", request, (u_long)accmap);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-11-08 00:28:11 +00:00
|
|
|
switch (mode_type) {
|
1995-01-31 06:29:58 +00:00
|
|
|
case MODE_REQ:
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->his_accmap = accmap;
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->ackend, cp, 6);
|
|
|
|
dec->ackend += 6;
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->want_accmap = accmap;
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->his_reject |= (1 << type);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1997-12-03 10:23:54 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
case TY_AUTHPROTO:
|
1997-08-25 00:29:32 +00:00
|
|
|
sp = (u_short *) (cp + 2);
|
1995-01-31 06:29:58 +00:00
|
|
|
proto = ntohs(*sp);
|
1997-12-07 23:55:29 +00:00
|
|
|
switch (proto) {
|
|
|
|
case PROTO_PAP:
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "%s 0x%04x (PAP)\n", request, proto);
|
1997-12-07 23:55:29 +00:00
|
|
|
break;
|
|
|
|
case PROTO_CHAP:
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "%s 0x%04x (CHAP 0x%02x)\n", request, proto, cp[4]);
|
1997-12-07 23:55:29 +00:00
|
|
|
break;
|
|
|
|
default:
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "%s 0x%04x\n", request, proto);
|
1997-12-07 23:55:29 +00:00
|
|
|
break;
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-11-08 00:28:11 +00:00
|
|
|
switch (mode_type) {
|
1995-01-31 06:29:58 +00:00
|
|
|
case MODE_REQ:
|
|
|
|
switch (proto) {
|
|
|
|
case PROTO_PAP:
|
|
|
|
if (length != 4) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, " Bad length!\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
goto reqreject;
|
|
|
|
}
|
1998-04-16 00:26:21 +00:00
|
|
|
if (IsAccepted(lcp->cfg.pap)) {
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->his_auth = proto;
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->ackend, cp, length);
|
|
|
|
dec->ackend += length;
|
1998-04-16 00:26:21 +00:00
|
|
|
} else if (IsAccepted(lcp->cfg.chap)) {
|
1998-03-13 21:08:05 +00:00
|
|
|
*dec->nakend++ = *cp;
|
|
|
|
*dec->nakend++ = 5;
|
|
|
|
*dec->nakend++ = (unsigned char) (PROTO_CHAP >> 8);
|
|
|
|
*dec->nakend++ = (unsigned char) PROTO_CHAP;
|
1998-04-03 19:26:29 +00:00
|
|
|
*dec->nakend++ = 0x05;
|
1995-01-31 06:29:58 +00:00
|
|
|
} else
|
|
|
|
goto reqreject;
|
|
|
|
break;
|
1997-12-03 10:23:54 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
case PROTO_CHAP:
|
|
|
|
if (length < 5) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, " Bad length!\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
goto reqreject;
|
|
|
|
}
|
1997-09-25 00:52:37 +00:00
|
|
|
#ifdef HAVE_DES
|
1998-04-16 00:26:21 +00:00
|
|
|
if (IsAccepted(lcp->cfg.chap) && (cp[4] == 0x05 || cp[4] == 0x80))
|
1997-09-25 00:52:37 +00:00
|
|
|
#else
|
1998-04-16 00:26:21 +00:00
|
|
|
if (IsAccepted(lcp->cfg.chap) && cp[4] == 0x05)
|
1997-09-25 00:52:37 +00:00
|
|
|
#endif
|
|
|
|
{
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->his_auth = proto;
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->ackend, cp, length);
|
|
|
|
dec->ackend += length;
|
1997-09-25 00:52:37 +00:00
|
|
|
#ifdef HAVE_DES
|
1998-04-03 19:26:29 +00:00
|
|
|
link2physical(fp->link)->dl->chap.using_MSChap = cp[4] == 0x80;
|
1997-09-25 00:52:37 +00:00
|
|
|
#endif
|
1998-04-16 00:26:21 +00:00
|
|
|
} else if (IsAccepted(lcp->cfg.pap)) {
|
1998-03-13 21:08:05 +00:00
|
|
|
*dec->nakend++ = *cp;
|
|
|
|
*dec->nakend++ = 4;
|
|
|
|
*dec->nakend++ = (unsigned char) (PROTO_PAP >> 8);
|
|
|
|
*dec->nakend++ = (unsigned char) PROTO_PAP;
|
1995-01-31 06:29:58 +00:00
|
|
|
} else
|
|
|
|
goto reqreject;
|
|
|
|
break;
|
1997-12-03 10:23:54 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
default:
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "%s 0x%04x - not recognised, NAK\n",
|
1997-12-07 23:55:29 +00:00
|
|
|
request, proto);
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend, cp, length);
|
|
|
|
dec->nakend += length;
|
1997-08-25 00:29:32 +00:00
|
|
|
break;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
1997-12-07 23:55:29 +00:00
|
|
|
switch (proto) {
|
|
|
|
case PROTO_PAP:
|
1998-04-16 00:26:21 +00:00
|
|
|
if (IsEnabled(lcp->cfg.pap))
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->want_auth = PROTO_PAP;
|
1997-12-07 23:55:29 +00:00
|
|
|
else {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "Peer will only send PAP (not enabled)\n");
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->his_reject |= (1 << type);
|
1997-12-07 23:55:29 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PROTO_CHAP:
|
1998-04-16 00:26:21 +00:00
|
|
|
if (IsEnabled(lcp->cfg.chap))
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->want_auth = PROTO_CHAP;
|
1997-12-07 23:55:29 +00:00
|
|
|
else {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "Peer will only send CHAP (not enabled)\n");
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->his_reject |= (1 << type);
|
1997-12-07 23:55:29 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* We've been NAK'd with something we don't understand :-( */
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->his_reject |= (1 << type);
|
1997-12-07 23:55:29 +00:00
|
|
|
break;
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->his_reject |= (1 << type);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1997-12-03 10:23:54 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
case TY_QUALPROTO:
|
1998-01-31 02:48:30 +00:00
|
|
|
req = (struct lqrreq *)cp;
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "%s proto %x, interval %ldms\n",
|
1998-04-25 10:49:52 +00:00
|
|
|
request, ntohs(req->proto), (long)ntohl(req->period) * 10);
|
1997-11-08 00:28:11 +00:00
|
|
|
switch (mode_type) {
|
1995-01-31 06:29:58 +00:00
|
|
|
case MODE_REQ:
|
1998-04-16 00:26:21 +00:00
|
|
|
if (ntohs(req->proto) != PROTO_LQR || !IsAccepted(lcp->cfg.lqr))
|
1995-01-31 06:29:58 +00:00
|
|
|
goto reqreject;
|
|
|
|
else {
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->his_lqrperiod = ntohl(req->period);
|
|
|
|
if (lcp->his_lqrperiod < 500)
|
|
|
|
lcp->his_lqrperiod = 500;
|
|
|
|
req->period = htonl(lcp->his_lqrperiod);
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->ackend, cp, length);
|
|
|
|
dec->ackend += length;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->his_reject |= (1 << type);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1997-12-03 10:23:54 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
case TY_MAGICNUM:
|
1998-04-19 23:09:03 +00:00
|
|
|
magic = ntohl(*(u_int32_t *)(cp + 2));
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "%s 0x%08lx\n", request, (u_long)magic);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-11-08 00:28:11 +00:00
|
|
|
switch (mode_type) {
|
1995-01-31 06:29:58 +00:00
|
|
|
case MODE_REQ:
|
1998-02-06 02:24:29 +00:00
|
|
|
if (lcp->want_magic) {
|
1997-06-01 03:43:26 +00:00
|
|
|
/* Validate magic number */
|
1998-02-06 02:24:29 +00:00
|
|
|
if (magic == lcp->want_magic) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "Magic is same (%08lx) - %d times\n",
|
1998-02-06 02:24:29 +00:00
|
|
|
(u_long)magic, ++lcp->LcpFailedMagic);
|
|
|
|
lcp->want_magic = GenerateMagic();
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend, cp, 6);
|
|
|
|
dec->nakend += 6;
|
1998-02-06 02:24:29 +00:00
|
|
|
ualarm(TICKUNIT * (4 + 4 * lcp->LcpFailedMagic), 0);
|
1997-09-22 02:51:24 +00:00
|
|
|
sigpause(0);
|
1997-08-25 00:29:32 +00:00
|
|
|
} else {
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->his_magic = magic;
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->ackend, cp, length);
|
|
|
|
dec->ackend += length;
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->LcpFailedMagic = 0;
|
1997-08-25 00:29:32 +00:00
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
} else {
|
|
|
|
goto reqreject;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, " Magic 0x%08lx is NAKed!\n", (u_long)magic);
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->want_magic = GenerateMagic();
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, " Magic 0x%08x is REJected!\n", magic);
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->want_magic = 0;
|
|
|
|
lcp->his_reject |= (1 << type);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1997-12-03 10:23:54 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
case TY_PROTOCOMP:
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "%s\n", request);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-11-08 00:28:11 +00:00
|
|
|
switch (mode_type) {
|
1995-01-31 06:29:58 +00:00
|
|
|
case MODE_REQ:
|
1998-04-16 00:26:21 +00:00
|
|
|
if (IsAccepted(lcp->cfg.protocomp)) {
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->his_protocomp = 1;
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->ackend, cp, 2);
|
|
|
|
dec->ackend += 2;
|
1997-08-25 00:29:32 +00:00
|
|
|
} else {
|
1995-01-31 06:29:58 +00:00
|
|
|
#ifdef OLDMST
|
|
|
|
/*
|
|
|
|
* MorningStar before v1.3 needs NAK
|
|
|
|
*/
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend, cp, 2);
|
|
|
|
dec->nakend += 2;
|
1995-01-31 06:29:58 +00:00
|
|
|
#else
|
1998-04-23 03:23:03 +00:00
|
|
|
goto reqreject;
|
1995-01-31 06:29:58 +00:00
|
|
|
#endif
|
1997-08-25 00:29:32 +00:00
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
|
|
|
case MODE_REJ:
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->want_protocomp = 0;
|
|
|
|
lcp->his_reject |= (1 << type);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1997-12-03 10:23:54 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
case TY_ACFCOMP:
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "%s\n", request);
|
1997-11-08 00:28:11 +00:00
|
|
|
switch (mode_type) {
|
1995-01-31 06:29:58 +00:00
|
|
|
case MODE_REQ:
|
1998-04-16 00:26:21 +00:00
|
|
|
if (IsAccepted(lcp->cfg.acfcomp)) {
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->his_acfcomp = 1;
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->ackend, cp, 2);
|
|
|
|
dec->ackend += 2;
|
1997-08-25 00:29:32 +00:00
|
|
|
} else {
|
1995-01-31 06:29:58 +00:00
|
|
|
#ifdef OLDMST
|
|
|
|
/*
|
|
|
|
* MorningStar before v1.3 needs NAK
|
|
|
|
*/
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend, cp, 2);
|
|
|
|
dec->nakend += 2;
|
1995-01-31 06:29:58 +00:00
|
|
|
#else
|
1998-04-23 03:23:03 +00:00
|
|
|
goto reqreject;
|
1995-01-31 06:29:58 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
|
|
|
case MODE_REJ:
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->want_acfcomp = 0;
|
|
|
|
lcp->his_reject |= (1 << type);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1997-12-03 10:23:54 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
case TY_SDP:
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "%s\n", request);
|
1998-01-29 00:44:16 +00:00
|
|
|
switch (mode_type) {
|
|
|
|
case MODE_REQ:
|
|
|
|
case MODE_NAK:
|
|
|
|
case MODE_REJ:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1998-04-23 03:23:03 +00:00
|
|
|
case TY_SHORTSEQ:
|
|
|
|
mp = &lcp->fsm.bundle->ncp.mp;
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "%s\n", request);
|
1998-04-23 03:23:03 +00:00
|
|
|
|
1997-11-08 00:28:11 +00:00
|
|
|
switch (mode_type) {
|
1995-01-31 06:29:58 +00:00
|
|
|
case MODE_REQ:
|
1998-04-23 18:55:50 +00:00
|
|
|
if (lcp->want_mrru && IsAccepted(mp->cfg.shortseq)) {
|
1998-04-23 03:23:03 +00:00
|
|
|
lcp->his_shortseq = 1;
|
|
|
|
memcpy(dec->ackend, cp, length);
|
|
|
|
dec->ackend += length;
|
|
|
|
} else
|
|
|
|
goto reqreject;
|
|
|
|
break;
|
1995-01-31 06:29:58 +00:00
|
|
|
case MODE_NAK:
|
1998-04-23 03:23:03 +00:00
|
|
|
/*
|
|
|
|
* He's trying to get us to ask for short sequence numbers.
|
|
|
|
* We ignore the NAK and honour our configuration file instead.
|
|
|
|
*/
|
|
|
|
break;
|
1995-01-31 06:29:58 +00:00
|
|
|
case MODE_REJ:
|
1998-04-23 03:23:03 +00:00
|
|
|
lcp->his_reject |= (1 << type);
|
1998-05-06 23:49:48 +00:00
|
|
|
lcp->want_shortseq = 0; /* For when we hit MP */
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1997-12-03 10:23:54 +00:00
|
|
|
|
1998-04-23 03:23:03 +00:00
|
|
|
case TY_ENDDISC:
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "%s %s\n", request,
|
1998-04-23 03:23:03 +00:00
|
|
|
mp_Enddisc(cp[2], cp + 3, length - 3));
|
|
|
|
switch (mode_type) {
|
|
|
|
case MODE_REQ:
|
1998-04-24 19:16:15 +00:00
|
|
|
if (!p) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, " ENDDISC rejected - not a physical link\n");
|
1998-04-24 19:16:15 +00:00
|
|
|
goto reqreject;
|
|
|
|
} else if (length-3 < sizeof p->dl->peer.enddisc.address &&
|
|
|
|
cp[2] <= MAX_ENDDISC_CLASS) {
|
|
|
|
p->dl->peer.enddisc.class = cp[2];
|
|
|
|
p->dl->peer.enddisc.len = length-3;
|
|
|
|
memcpy(p->dl->peer.enddisc.address, cp + 3, length - 3);
|
|
|
|
p->dl->peer.enddisc.address[length - 3] = '\0';
|
|
|
|
/* XXX: If mp->active, compare and NAK with mp->peer ? */
|
1998-04-23 03:23:03 +00:00
|
|
|
memcpy(dec->ackend, cp, length);
|
|
|
|
dec->ackend += length;
|
|
|
|
} else {
|
|
|
|
if (cp[2] > MAX_ENDDISC_CLASS)
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, " ENDDISC rejected - unrecognised class %d\n",
|
1998-04-23 03:23:03 +00:00
|
|
|
cp[2]);
|
|
|
|
else
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, " ENDDISC rejected - local max length is %d\n",
|
1998-04-24 19:16:15 +00:00
|
|
|
sizeof p->dl->peer.enddisc.address - 1);
|
1998-04-23 03:23:03 +00:00
|
|
|
goto reqreject;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MODE_NAK: /* Treat this as a REJ, we don't vary or disc */
|
|
|
|
case MODE_REJ:
|
|
|
|
lcp->his_reject |= (1 << type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
default:
|
1997-12-24 09:29:17 +00:00
|
|
|
sz = (sizeof desc - 2) / 2;
|
1997-12-03 10:23:54 +00:00
|
|
|
if (sz > length - 2)
|
|
|
|
sz = length - 2;
|
|
|
|
pos = 0;
|
|
|
|
desc[0] = sz ? ' ' : '\0';
|
|
|
|
for (pos = 0; sz--; pos++)
|
|
|
|
sprintf(desc+(pos<<1)+1, "%02x", cp[pos+2]);
|
|
|
|
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "%s%s\n", request, desc);
|
1997-12-03 10:23:54 +00:00
|
|
|
|
1997-11-08 00:28:11 +00:00
|
|
|
if (mode_type == MODE_REQ) {
|
1997-12-03 10:23:54 +00:00
|
|
|
reqreject:
|
1998-03-13 21:08:05 +00:00
|
|
|
if (length > sizeof dec->rej - (dec->rejend - dec->rej)) {
|
|
|
|
length = sizeof dec->rej - (dec->rejend - dec->rej);
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLCP, "Can't REJ length %d - trunating to %d\n",
|
1997-12-03 10:23:54 +00:00
|
|
|
cp[1], length);
|
|
|
|
}
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->rejend, cp, length);
|
|
|
|
dec->rejend += length;
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->my_reject |= (1 << type);
|
1997-12-03 10:23:54 +00:00
|
|
|
if (length != cp[1])
|
1998-04-23 03:23:03 +00:00
|
|
|
length = 0; /* force our way out of the loop */
|
1995-02-26 12:18:08 +00:00
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
plen -= length;
|
|
|
|
cp += length;
|
|
|
|
}
|
1998-04-16 00:26:21 +00:00
|
|
|
|
1998-04-25 10:49:52 +00:00
|
|
|
if (mode_type != MODE_NOP) {
|
1998-04-16 00:26:21 +00:00
|
|
|
if (dec->rejend != dec->rej) {
|
|
|
|
/* rejects are preferred */
|
|
|
|
dec->ackend = dec->ack;
|
|
|
|
dec->nakend = dec->nak;
|
|
|
|
} else if (dec->nakend != dec->nak)
|
|
|
|
/* then NAKs */
|
|
|
|
dec->ackend = dec->ack;
|
1998-04-25 10:49:52 +00:00
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-05-01 19:26:12 +00:00
|
|
|
lcp_Input(struct lcp *lcp, struct mbuf * bp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Got PROTO_LCP from link */
|
1998-05-01 19:26:12 +00:00
|
|
|
fsm_Input(&lcp->fsm, bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|