1998-01-29 00:44:16 +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.
|
|
|
|
*
|
1998-03-24 18:47:32 +00:00
|
|
|
* $Id: lcp.c,v 1.55.2.32 1998/03/20 19:48:06 brian Exp $
|
1998-01-29 00:44:16 +00:00
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* o Limit data field length by MRU
|
|
|
|
*/
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <net/if.h>
|
1998-03-02 17:25:30 +00:00
|
|
|
#include <sys/select.h>
|
1998-01-29 00:44:16 +00:00
|
|
|
#include <net/if_tun.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
1998-03-16 22:54:35 +00:00
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "command.h"
|
|
|
|
#include "mbuf.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "defs.h"
|
|
|
|
#include "timer.h"
|
|
|
|
#include "fsm.h"
|
|
|
|
#include "lcp.h"
|
1998-01-29 23:11:44 +00:00
|
|
|
#include "iplist.h"
|
|
|
|
#include "throughput.h"
|
1998-03-16 22:54:35 +00:00
|
|
|
#include "slcompress.h"
|
1998-01-29 00:44:16 +00:00
|
|
|
#include "ipcp.h"
|
|
|
|
#include "lcpproto.h"
|
1998-03-16 22:52:54 +00:00
|
|
|
#include "filter.h"
|
1998-03-20 19:48:28 +00:00
|
|
|
#include "descriptor.h"
|
1998-02-02 19:32:16 +00:00
|
|
|
#include "bundle.h"
|
1998-03-13 00:44:26 +00:00
|
|
|
#include "lqr.h"
|
1998-01-29 00:44:16 +00:00
|
|
|
#include "hdlc.h"
|
|
|
|
#include "ccp.h"
|
|
|
|
#include "loadalias.h"
|
|
|
|
#include "vars.h"
|
|
|
|
#include "auth.h"
|
|
|
|
#include "pap.h"
|
|
|
|
#include "chap.h"
|
|
|
|
#include "async.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "ip.h"
|
|
|
|
#include "modem.h"
|
|
|
|
#include "tun.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-03-13 21:07:14 +00:00
|
|
|
#include "chat.h"
|
|
|
|
#include "datalink.h"
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
/* for received LQRs */
|
|
|
|
struct lqrreq {
|
|
|
|
u_char type;
|
|
|
|
u_char length;
|
|
|
|
u_short proto; /* Quality protocol */
|
|
|
|
u_long period; /* Reporting interval */
|
|
|
|
};
|
|
|
|
|
|
|
|
static void LcpLayerUp(struct fsm *);
|
|
|
|
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,
|
|
|
|
NullRecvResetReq,
|
|
|
|
NullRecvResetAck
|
1998-02-06 02:24:29 +00:00
|
|
|
};
|
1998-01-31 02:48:30 +00:00
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
static const char *cftypes[] = {
|
|
|
|
/* 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 */
|
|
|
|
"MULTIMRRU", /* 17: Multilink-MRRU */
|
|
|
|
"MULTISSNH", /* 18: Multilink-Short-Sequence-Number-Header */
|
|
|
|
"MULTIED", /* 19: Multilink-Endpoint-Descriminator */
|
|
|
|
"PROPRIETRY", /* 20: Proprietary */
|
|
|
|
"DCEID", /* 21: DCE-Identifier */
|
|
|
|
"MULTIPP", /* 22: Multi-Link-Plus-Procedure */
|
|
|
|
"LDBACP", /* 23: Link Discriminator for BACP */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NCFTYPES (sizeof cftypes/sizeof cftypes[0])
|
|
|
|
|
|
|
|
int
|
1998-03-13 21:07:14 +00:00
|
|
|
lcp_ReportStatus(struct cmdargs const *arg)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-03-13 21:07:14 +00:00
|
|
|
prompt_Printf(&prompt, "%s [%s]\n", arg->cx->lcp.fsm.name,
|
1998-03-24 18:47:32 +00:00
|
|
|
State2Nam(arg->cx->lcp.fsm.state));
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt,
|
|
|
|
" his side: MRU %d, ACCMAP %08lx, PROTOCOMP %d, ACFCOMP %d,\n"
|
|
|
|
" MAGIC %08lx, REJECT %04x\n",
|
1998-03-13 21:07:14 +00:00
|
|
|
arg->cx->lcp.his_mru, (u_long)arg->cx->lcp.his_accmap,
|
|
|
|
arg->cx->lcp.his_protocomp, arg->cx->lcp.his_acfcomp,
|
|
|
|
(u_long)arg->cx->lcp.his_magic, arg->cx->lcp.his_reject);
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt,
|
|
|
|
" my side: MRU %d, ACCMAP %08lx, PROTOCOMP %d, ACFCOMP %d,\n"
|
|
|
|
" MAGIC %08lx, REJECT %04x\n",
|
1998-03-13 21:07:14 +00:00
|
|
|
arg->cx->lcp.want_mru, (u_long)arg->cx->lcp.want_accmap,
|
|
|
|
arg->cx->lcp.want_protocomp, arg->cx->lcp.want_acfcomp,
|
|
|
|
(u_long)arg->cx->lcp.want_magic, arg->cx->lcp.my_reject);
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "\nDefaults: MRU = %d, ACCMAP = %08lx\t",
|
|
|
|
VarMRU, (u_long)VarAccmap);
|
|
|
|
prompt_Printf(&prompt, "Open Mode: %s",
|
|
|
|
(VarOpenMode == OPEN_PASSIVE) ? "passive" : "active");
|
1998-01-29 00:44:16 +00:00
|
|
|
if (VarOpenMode > 0)
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, " (delay %d)", VarOpenMode);
|
|
|
|
prompt_Printf(&prompt, "\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u_int32_t
|
|
|
|
GenerateMagic(void)
|
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Generate random number which will be used as magic number */
|
1998-01-29 00:44:16 +00:00
|
|
|
randinit();
|
|
|
|
return (random());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-02-27 01:22:39 +00:00
|
|
|
lcp_Init(struct lcp *lcp, struct bundle *bundle, struct physical *physical,
|
|
|
|
const struct fsm_parent *parent)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Initialise ourselves */
|
1998-02-21 01:45:26 +00:00
|
|
|
fsm_Init(&lcp->fsm, "LCP", PROTO_LCP, LCP_MAXCODE, 10, LogLCP, bundle,
|
1998-02-27 01:22:39 +00:00
|
|
|
&physical->link, parent, &lcp_Callbacks);
|
1998-02-21 01:45:26 +00:00
|
|
|
lcp_Setup(lcp, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
lcp_Setup(struct lcp *lcp, int openmode)
|
|
|
|
{
|
|
|
|
struct physical *p = link2physical(lcp->fsm.link);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
hdlc_Init(&p->hdlc);
|
|
|
|
async_Init(&p->async);
|
|
|
|
|
|
|
|
lcp->his_mru = DEF_MRU;
|
|
|
|
lcp->his_accmap = 0xffffffff;
|
|
|
|
lcp->his_magic = 0;
|
|
|
|
lcp->his_lqrperiod = 0;
|
|
|
|
lcp->his_protocomp = 0;
|
|
|
|
lcp->his_acfcomp = 0;
|
|
|
|
lcp->his_auth = 0;
|
|
|
|
|
|
|
|
lcp->want_mru = VarMRU;
|
|
|
|
lcp->want_accmap = VarAccmap;
|
|
|
|
lcp->want_magic = GenerateMagic();
|
|
|
|
lcp->want_auth = Enabled(ConfChap) ? PROTO_CHAP :
|
|
|
|
Enabled(ConfPap) ? PROTO_PAP : 0;
|
|
|
|
lcp->want_lqrperiod = Enabled(ConfLqr) ? VarLqrTimeout * 100 : 0;
|
|
|
|
lcp->want_protocomp = Enabled(ConfProtocomp) ? 1 : 0;
|
|
|
|
lcp->want_acfcomp = Enabled(ConfAcfcomp) ? 1 : 0;
|
|
|
|
|
|
|
|
lcp->his_reject = lcp->my_reject = 0;
|
|
|
|
lcp->auth_iwait = lcp->auth_ineed = 0;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
LcpInitRestartCounter(struct fsm * fp)
|
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Set fsm timer load */
|
1998-01-29 00:44:16 +00:00
|
|
|
fp->FsmTimer.load = VarRetryTimeout * SECTICKS;
|
|
|
|
fp->restart = 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-01-30 19:46:07 +00:00
|
|
|
LcpSendConfigReq(struct fsm *fp)
|
1998-01-29 00:44:16 +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-03-20 19:47:10 +00:00
|
|
|
u_char buff[100];
|
|
|
|
struct lcp_opt *o;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-01-30 19:46:07 +00:00
|
|
|
if (!p) {
|
|
|
|
LogPrintf(LogERROR, "LcpSendConfigReq: Not a physical link !\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-03-20 19:47:10 +00:00
|
|
|
o = (struct lcp_opt *)buff;
|
1998-01-30 19:46:07 +00:00
|
|
|
if (!Physical_IsSync(p)) {
|
1998-02-06 02:24:29 +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);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-02-06 02:24:29 +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);
|
1998-01-29 00:44:16 +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);
|
|
|
|
}
|
1998-01-29 00:44:16 +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);
|
|
|
|
}
|
1998-01-29 00:44:16 +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);
|
|
|
|
}
|
1998-01-29 00:44:16 +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);
|
|
|
|
}
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-02-06 02:24:29 +00:00
|
|
|
switch (lcp->want_auth) {
|
1998-01-29 00:44:16 +00:00
|
|
|
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);
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROTO_CHAP:
|
1998-03-20 19:47:10 +00:00
|
|
|
*(u_short *)o->data = htons(PROTO_CHAP);
|
1998-01-29 00:44:16 +00:00
|
|
|
#ifdef HAVE_DES
|
|
|
|
if (VarMSChap)
|
1998-03-20 19:47:10 +00:00
|
|
|
o->data[2] = 0x80;
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
|
|
|
#endif
|
1998-03-20 19:47:10 +00:00
|
|
|
o->data[2] = 0x05;
|
|
|
|
INC_LCP_OPT(TY_AUTHPROTO, 5, o);
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
1998-03-20 19:47:10 +00:00
|
|
|
FsmOutput(fp, CODE_CONFIGREQ, fp->reqid, buff, (u_char *)o - buff);
|
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)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Don't understand `option' */
|
1998-03-13 21:07:14 +00:00
|
|
|
FsmOutput(&lcp->fsm, CODE_PROTOREJ, lcp->fsm.reqid, option, count);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-03-20 19:47:10 +00:00
|
|
|
LcpSentTerminateReq(struct fsm * fp)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Term REQ just sent by FSM */
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-03-20 19:47:10 +00:00
|
|
|
LcpSendTerminateAck(struct fsm *fp, u_char id)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Send Term ACK please */
|
1998-03-20 19:47:10 +00:00
|
|
|
FsmOutput(fp, CODE_TERMACK, id, NULL, 0);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-01-30 19:46:07 +00:00
|
|
|
LcpLayerStart(struct fsm *fp)
|
1998-01-29 00:44:16 +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-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogLCP, "LcpLayerStart\n");
|
1998-03-13 21:07:14 +00:00
|
|
|
lcp->LcpFailedMagic = 0;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-01-30 19:46:07 +00:00
|
|
|
LcpLayerFinish(struct fsm *fp)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* We're now down */
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogLCP, "LcpLayerFinish\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-01-30 19:46:07 +00:00
|
|
|
LcpLayerUp(struct fsm *fp)
|
1998-01-29 00:44:16 +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-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogLCP, "LcpLayerUp\n");
|
|
|
|
|
1998-01-30 19:46:07 +00:00
|
|
|
if (p) {
|
1998-02-06 02:24:29 +00:00
|
|
|
async_SetLinkParams(&p->async, lcp);
|
1998-03-13 00:44:26 +00:00
|
|
|
StartLqm(lcp);
|
1998-02-18 19:35:59 +00:00
|
|
|
hdlc_StartTimer(&p->hdlc);
|
1998-01-30 19:46:07 +00:00
|
|
|
} else
|
|
|
|
LogPrintf(LogERROR, "LcpLayerUp: Not a physical link !\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-02-02 19:32:16 +00:00
|
|
|
LcpLayerDown(struct fsm *fp)
|
1998-01-29 00:44:16 +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);
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogLCP, "LcpLayerDown\n");
|
1998-02-18 19:35:59 +00:00
|
|
|
hdlc_StopTimer(&p->hdlc);
|
1998-03-13 00:44:26 +00:00
|
|
|
StopLqrTimer(p);
|
1998-01-29 00:44:16 +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)
|
1998-01-29 00:44:16 +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-29 00:44:16 +00:00
|
|
|
int type, length, sz, pos;
|
|
|
|
u_int32_t *lp, magic, accmap;
|
|
|
|
u_short mtu, mru, *sp, proto;
|
|
|
|
struct lqrreq *req;
|
|
|
|
char request[20], desc[22];
|
|
|
|
|
|
|
|
while (plen >= sizeof(struct fsmconfig)) {
|
|
|
|
type = *cp;
|
|
|
|
length = cp[1];
|
|
|
|
|
|
|
|
if (type < 0 || type >= NCFTYPES)
|
|
|
|
snprintf(request, sizeof request, " <%d>[%d]", type, length);
|
|
|
|
else
|
|
|
|
snprintf(request, sizeof request, " %s[%d]", cftypes[type], length);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case TY_MRU:
|
|
|
|
sp = (u_short *) (cp + 2);
|
|
|
|
mru = htons(*sp);
|
|
|
|
LogPrintf(LogLCP, "%s %d\n", request, mru);
|
|
|
|
|
|
|
|
switch (mode_type) {
|
|
|
|
case MODE_REQ:
|
|
|
|
mtu = VarPrefMTU;
|
|
|
|
if (mtu == 0)
|
|
|
|
mtu = MAX_MTU;
|
|
|
|
if (mru > mtu) {
|
|
|
|
*sp = htons(mtu);
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend, cp, 4);
|
|
|
|
dec->nakend += 4;
|
1998-01-29 00:44:16 +00:00
|
|
|
} else if (mru < MIN_MRU) {
|
|
|
|
*sp = htons(MIN_MRU);
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend, cp, 4);
|
|
|
|
dec->nakend += 4;
|
1998-01-29 00:44:16 +00:00
|
|
|
} else {
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->his_mru = mru;
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->ackend, cp, 4);
|
|
|
|
dec->ackend += 4;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
|
|
|
if (mru >= MIN_MRU || mru <= MAX_MRU)
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->want_mru = mru;
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->his_reject |= (1 << type);
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TY_ACCMAP:
|
|
|
|
lp = (u_int32_t *) (cp + 2);
|
|
|
|
accmap = htonl(*lp);
|
|
|
|
LogPrintf(LogLCP, "%s 0x%08lx\n", request, (u_long)accmap);
|
|
|
|
|
|
|
|
switch (mode_type) {
|
|
|
|
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;
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->want_accmap = accmap;
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->his_reject |= (1 << type);
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TY_AUTHPROTO:
|
|
|
|
sp = (u_short *) (cp + 2);
|
|
|
|
proto = ntohs(*sp);
|
|
|
|
switch (proto) {
|
|
|
|
case PROTO_PAP:
|
|
|
|
LogPrintf(LogLCP, "%s 0x%04x (PAP)\n", request, proto);
|
|
|
|
break;
|
|
|
|
case PROTO_CHAP:
|
|
|
|
LogPrintf(LogLCP, "%s 0x%04x (CHAP 0x%02x)\n", request, proto, cp[4]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LogPrintf(LogLCP, "%s 0x%04x\n", request, proto);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (mode_type) {
|
|
|
|
case MODE_REQ:
|
|
|
|
switch (proto) {
|
|
|
|
case PROTO_PAP:
|
|
|
|
if (length != 4) {
|
|
|
|
LogPrintf(LogLCP, " Bad length!\n");
|
|
|
|
goto reqreject;
|
|
|
|
}
|
|
|
|
if (Acceptable(ConfPap)) {
|
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-01-29 00:44:16 +00:00
|
|
|
} else if (Acceptable(ConfChap)) {
|
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-01-29 00:44:16 +00:00
|
|
|
#ifdef HAVE_DES
|
|
|
|
if (VarMSChap)
|
1998-03-13 21:08:05 +00:00
|
|
|
*dec->nakend++ = 0x80;
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
|
|
|
#endif
|
1998-03-13 21:08:05 +00:00
|
|
|
*dec->nakend++ = 5;
|
1998-01-29 00:44:16 +00:00
|
|
|
} else
|
|
|
|
goto reqreject;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROTO_CHAP:
|
|
|
|
if (length < 5) {
|
|
|
|
LogPrintf(LogLCP, " Bad length!\n");
|
|
|
|
goto reqreject;
|
|
|
|
}
|
|
|
|
#ifdef HAVE_DES
|
|
|
|
if (Acceptable(ConfChap) && (cp[4] == 5 || cp[4] == 0x80))
|
|
|
|
#else
|
|
|
|
if (Acceptable(ConfChap) && cp[4] == 5)
|
|
|
|
#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;
|
1998-01-29 00:44:16 +00:00
|
|
|
#ifdef HAVE_DES
|
|
|
|
VarMSChap = cp[4] == 0x80;
|
|
|
|
#endif
|
|
|
|
} else if (Acceptable(ConfPap)) {
|
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;
|
1998-01-29 00:44:16 +00:00
|
|
|
} else
|
|
|
|
goto reqreject;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
LogPrintf(LogLCP, "%s 0x%04x - not recognised, NAK\n",
|
|
|
|
request, proto);
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend, cp, length);
|
|
|
|
dec->nakend += length;
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
|
|
|
switch (proto) {
|
|
|
|
case PROTO_PAP:
|
|
|
|
if (Enabled(ConfPap))
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->want_auth = PROTO_PAP;
|
1998-01-29 00:44:16 +00:00
|
|
|
else {
|
|
|
|
LogPrintf(LogLCP, "Peer will only send PAP (not enabled)\n");
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->his_reject |= (1 << type);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PROTO_CHAP:
|
|
|
|
if (Enabled(ConfChap))
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->want_auth = PROTO_CHAP;
|
1998-01-29 00:44:16 +00:00
|
|
|
else {
|
|
|
|
LogPrintf(LogLCP, "Peer will only send CHAP (not enabled)\n");
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->his_reject |= (1 << type);
|
1998-01-29 00:44:16 +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);
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->his_reject |= (1 << type);
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TY_QUALPROTO:
|
1998-01-31 02:48:30 +00:00
|
|
|
req = (struct lqrreq *)cp;
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogLCP, "%s proto %x, interval %dms\n",
|
|
|
|
request, ntohs(req->proto), ntohl(req->period) * 10);
|
|
|
|
switch (mode_type) {
|
|
|
|
case MODE_REQ:
|
|
|
|
if (ntohs(req->proto) != PROTO_LQR || !Acceptable(ConfLqr))
|
|
|
|
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;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->his_reject |= (1 << type);
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TY_MAGICNUM:
|
|
|
|
lp = (u_int32_t *) (cp + 2);
|
|
|
|
magic = ntohl(*lp);
|
|
|
|
LogPrintf(LogLCP, "%s 0x%08lx\n", request, (u_long)magic);
|
|
|
|
|
|
|
|
switch (mode_type) {
|
|
|
|
case MODE_REQ:
|
1998-02-06 02:24:29 +00:00
|
|
|
if (lcp->want_magic) {
|
1998-01-29 00:44:16 +00:00
|
|
|
/* Validate magic number */
|
1998-02-06 02:24:29 +00:00
|
|
|
if (magic == lcp->want_magic) {
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(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);
|
1998-01-29 00:44:16 +00:00
|
|
|
sigpause(0);
|
|
|
|
} 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;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->my_reject |= (1 << type);
|
1998-01-29 00:44:16 +00:00
|
|
|
goto reqreject;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
|
|
|
LogPrintf(LogLCP, " Magic 0x%08lx is NAKed!\n", (u_long)magic);
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->want_magic = GenerateMagic();
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
1998-02-04 01:03:51 +00:00
|
|
|
LogPrintf(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);
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TY_PROTOCOMP:
|
|
|
|
LogPrintf(LogLCP, "%s\n", request);
|
|
|
|
|
|
|
|
switch (mode_type) {
|
|
|
|
case MODE_REQ:
|
|
|
|
if (Acceptable(ConfProtocomp)) {
|
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;
|
1998-01-29 00:44:16 +00:00
|
|
|
} else {
|
|
|
|
#ifdef OLDMST
|
|
|
|
/*
|
|
|
|
* MorningStar before v1.3 needs NAK
|
|
|
|
*/
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend, cp, 2);
|
|
|
|
dec->nakend += 2;
|
1998-01-29 00:44:16 +00:00
|
|
|
#else
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->rejend, cp, 2);
|
|
|
|
dec->rejend += 2;
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->my_reject |= (1 << type);
|
1998-01-29 00:44:16 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
|
|
|
case MODE_REJ:
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->want_protocomp = 0;
|
|
|
|
lcp->his_reject |= (1 << type);
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TY_ACFCOMP:
|
|
|
|
LogPrintf(LogLCP, "%s\n", request);
|
|
|
|
switch (mode_type) {
|
|
|
|
case MODE_REQ:
|
|
|
|
if (Acceptable(ConfAcfcomp)) {
|
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;
|
1998-01-29 00:44:16 +00:00
|
|
|
} else {
|
|
|
|
#ifdef OLDMST
|
|
|
|
/*
|
|
|
|
* MorningStar before v1.3 needs NAK
|
|
|
|
*/
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend, cp, 2);
|
|
|
|
dec->nakend += 2;
|
1998-01-29 00:44:16 +00:00
|
|
|
#else
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->rejend, cp, 2);
|
|
|
|
dec->rejend += 2;
|
1998-02-06 02:24:29 +00:00
|
|
|
lcp->my_reject |= (1 << type);
|
1998-01-29 00:44:16 +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);
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TY_SDP:
|
|
|
|
LogPrintf(LogLCP, "%s\n", request);
|
|
|
|
switch (mode_type) {
|
|
|
|
case MODE_REQ:
|
|
|
|
case MODE_NAK:
|
|
|
|
case MODE_REJ:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
sz = (sizeof desc - 2) / 2;
|
|
|
|
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]);
|
|
|
|
|
|
|
|
LogPrintf(LogLCP, "%s%s\n", request, desc);
|
|
|
|
|
|
|
|
if (mode_type == MODE_REQ) {
|
|
|
|
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-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogLCP, "Can't REJ length %d - trunating to %d\n",
|
|
|
|
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);
|
1998-01-29 00:44:16 +00:00
|
|
|
if (length != cp[1])
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* to avoid inf. loop */
|
|
|
|
if (length == 0) {
|
|
|
|
LogPrintf(LogLCP, "LCP size zero\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
plen -= length;
|
|
|
|
cp += length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-03-13 21:07:14 +00:00
|
|
|
LcpInput(struct lcp *lcp, struct mbuf * bp)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Got PROTO_LCP from link */
|
1998-03-13 21:07:14 +00:00
|
|
|
FsmInput(&lcp->fsm, bp);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|