1995-01-31 06:29:58 +00:00
|
|
|
/*
|
|
|
|
* PPP IP Control Protocol (IPCP) 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.
|
|
|
|
*
|
1997-12-13 02:37:33 +00:00
|
|
|
* $Id: ipcp.c,v 1.41 1997/12/06 22:43:58 brian Exp $
|
1995-05-30 03:57:47 +00:00
|
|
|
*
|
1995-01-31 06:29:58 +00:00
|
|
|
* TODO:
|
|
|
|
* o More RFC1772 backwoard compatibility
|
|
|
|
*/
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <sys/param.h>
|
1995-01-31 06:29:58 +00:00
|
|
|
#include <netinet/in_systm.h>
|
1997-09-03 02:08:20 +00:00
|
|
|
#include <netinet/in.h>
|
1995-01-31 06:29:58 +00:00
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <sys/socket.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <netdb.h>
|
|
|
|
|
1997-09-03 02:08:20 +00:00
|
|
|
#include <limits.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1997-11-18 14:52:08 +00:00
|
|
|
#include <time.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#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"
|
1997-09-03 02:08:20 +00:00
|
|
|
#include "fsm.h"
|
|
|
|
#include "lcpproto.h"
|
|
|
|
#include "lcp.h"
|
1997-12-13 02:37:33 +00:00
|
|
|
#include "iplist.h"
|
1997-09-03 02:08:20 +00:00
|
|
|
#include "ipcp.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "slcompress.h"
|
|
|
|
#include "os.h"
|
|
|
|
#include "phase.h"
|
1997-05-26 00:44:10 +00:00
|
|
|
#include "loadalias.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "vars.h"
|
1997-10-26 01:04:02 +00:00
|
|
|
#include "vjcomp.h"
|
1997-10-26 12:42:13 +00:00
|
|
|
#include "ip.h"
|
1997-11-18 14:52:08 +00:00
|
|
|
#include "throughput.h"
|
1997-12-13 02:37:33 +00:00
|
|
|
#include "route.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
#ifndef NOMSEXT
|
|
|
|
struct in_addr ns_entries[2];
|
|
|
|
struct in_addr nbns_entries[2];
|
|
|
|
#endif
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
struct ipcpstate IpcpInfo;
|
1997-10-26 01:04:02 +00:00
|
|
|
struct in_range DefMyAddress;
|
|
|
|
struct in_range DefHisAddress;
|
1997-12-13 02:37:33 +00:00
|
|
|
struct iplist DefHisChoice;
|
1997-10-26 01:04:02 +00:00
|
|
|
struct in_addr TriggerAddress;
|
1997-08-19 01:10:24 +00:00
|
|
|
int HaveTriggerAddress;
|
1997-06-09 03:27:43 +00:00
|
|
|
|
|
|
|
static void IpcpSendConfigReq(struct fsm *);
|
|
|
|
static void IpcpSendTerminateAck(struct fsm *);
|
|
|
|
static void IpcpSendTerminateReq(struct fsm *);
|
|
|
|
static void IpcpDecodeConfig(u_char *, int, int);
|
|
|
|
static void IpcpLayerStart(struct fsm *);
|
|
|
|
static void IpcpLayerFinish(struct fsm *);
|
|
|
|
static void IpcpLayerUp(struct fsm *);
|
|
|
|
static void IpcpLayerDown(struct fsm *);
|
|
|
|
static void IpcpInitRestartCounter(struct fsm *);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
struct fsm IpcpFsm = {
|
|
|
|
"IPCP",
|
|
|
|
PROTO_IPCP,
|
|
|
|
IPCP_MAXCODE,
|
|
|
|
OPEN_ACTIVE,
|
|
|
|
ST_INITIAL,
|
|
|
|
0, 0, 0,
|
|
|
|
|
|
|
|
0,
|
1997-08-25 00:29:32 +00:00
|
|
|
{0, 0, 0, NULL, NULL, NULL},
|
|
|
|
{0, 0, 0, NULL, NULL, NULL},
|
1997-08-20 23:47:53 +00:00
|
|
|
LogIPCP,
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
IpcpLayerUp,
|
|
|
|
IpcpLayerDown,
|
|
|
|
IpcpLayerStart,
|
|
|
|
IpcpLayerFinish,
|
|
|
|
IpcpInitRestartCounter,
|
|
|
|
IpcpSendConfigReq,
|
|
|
|
IpcpSendTerminateReq,
|
|
|
|
IpcpSendTerminateAck,
|
|
|
|
IpcpDecodeConfig,
|
|
|
|
};
|
|
|
|
|
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) */
|
|
|
|
"???",
|
|
|
|
"IPADDRS", /* 1: IP-Addresses */ /* deprecated */
|
|
|
|
"COMPPROTO", /* 2: IP-Compression-Protocol */
|
|
|
|
"IPADDR", /* 3: IP-Address */
|
1995-01-31 06:29:58 +00:00
|
|
|
};
|
|
|
|
|
1997-11-14 15:39:15 +00:00
|
|
|
#define NCFTYPES (sizeof(cftypes)/sizeof(char *))
|
|
|
|
|
1997-11-22 03:37:54 +00:00
|
|
|
static const char *cftypes128[] = {
|
1997-11-14 15:39:15 +00:00
|
|
|
/* Check out the latest ``Assigned numbers'' rfc (rfc1700.txt) */
|
|
|
|
"???",
|
|
|
|
"PRIDNS", /* 129: Primary DNS Server Address */
|
|
|
|
"PRINBNS", /* 130: Primary NBNS Server Address */
|
|
|
|
"SECDNS", /* 131: Secondary DNS Server Address */
|
|
|
|
"SECNBNS", /* 132: Secondary NBNS Server Address */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NCFTYPES128 (sizeof(cftypes)/sizeof(char *))
|
|
|
|
|
1997-11-18 14:52:08 +00:00
|
|
|
struct pppThroughput throughput;
|
|
|
|
|
|
|
|
void
|
|
|
|
IpcpAddInOctets(int n)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-11-18 14:52:08 +00:00
|
|
|
throughput_addin(&throughput, n);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-11-18 14:52:08 +00:00
|
|
|
void
|
|
|
|
IpcpAddOutOctets(int n)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-11-18 14:52:08 +00:00
|
|
|
throughput_addout(&throughput, n);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-05-10 01:22:19 +00:00
|
|
|
int
|
1997-11-22 03:37:54 +00:00
|
|
|
ReportIpcpStatus(struct cmdargs const *arg)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
struct fsm *fp = &IpcpFsm;
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
if (!VarTerm)
|
|
|
|
return 1;
|
|
|
|
fprintf(VarTerm, "%s [%s]\n", fp->name, StateNames[fp->state]);
|
1997-12-03 10:23:54 +00:00
|
|
|
fprintf(VarTerm, " his side: %s, %s\n",
|
1997-12-04 18:49:35 +00:00
|
|
|
inet_ntoa(IpcpInfo.his_ipaddr), vj2asc(IpcpInfo.his_compproto));
|
1997-12-03 10:23:54 +00:00
|
|
|
fprintf(VarTerm, " my side: %s, %s\n",
|
1997-12-04 18:49:35 +00:00
|
|
|
inet_ntoa(IpcpInfo.want_ipaddr), vj2asc(IpcpInfo.want_compproto));
|
1997-09-03 02:08:20 +00:00
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, "Defaults:\n");
|
|
|
|
fprintf(VarTerm, " My Address: %s/%d\n",
|
1997-08-25 00:29:32 +00:00
|
|
|
inet_ntoa(DefMyAddress.ipaddr), DefMyAddress.width);
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, " His Address: %s/%d\n",
|
1997-08-25 00:29:32 +00:00
|
|
|
inet_ntoa(DefHisAddress.ipaddr), DefHisAddress.width);
|
1997-08-19 01:10:24 +00:00
|
|
|
if (HaveTriggerAddress)
|
1997-08-25 00:29:32 +00:00
|
|
|
fprintf(VarTerm, " Negotiation(trigger): %s\n", inet_ntoa(TriggerAddress));
|
1997-08-19 01:10:24 +00:00
|
|
|
else
|
1997-08-25 00:29:32 +00:00
|
|
|
fprintf(VarTerm, " Negotiation(trigger): MYADDR\n");
|
1997-06-09 03:27:43 +00:00
|
|
|
|
1997-11-18 14:52:08 +00:00
|
|
|
fprintf(VarTerm, "\n");
|
|
|
|
throughput_disp(&throughput, VarTerm);
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
return 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IpcpDefAddress()
|
|
|
|
{
|
|
|
|
struct hostent *hp;
|
|
|
|
char name[200];
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
memset(&DefMyAddress, '\0', sizeof(DefMyAddress));
|
|
|
|
memset(&DefHisAddress, '\0', sizeof(DefHisAddress));
|
1997-08-19 01:10:24 +00:00
|
|
|
TriggerAddress.s_addr = 0;
|
|
|
|
HaveTriggerAddress = 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
if (gethostname(name, sizeof(name)) == 0) {
|
1997-08-25 00:29:32 +00:00
|
|
|
hp = gethostbyname(name);
|
|
|
|
if (hp && hp->h_addrtype == AF_INET) {
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(&DefMyAddress.ipaddr.s_addr, hp->h_addr, hp->h_length);
|
1997-08-25 00:29:32 +00:00
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IpcpInit()
|
|
|
|
{
|
1997-12-13 02:37:33 +00:00
|
|
|
if (iplist_isvalid(&DefHisChoice))
|
|
|
|
iplist_setrandpos(&DefHisChoice);
|
1995-01-31 06:29:58 +00:00
|
|
|
FsmInit(&IpcpFsm);
|
1997-12-04 18:49:35 +00:00
|
|
|
memset(&IpcpInfo, '\0', sizeof(struct ipcpstate));
|
1997-11-11 22:58:14 +00:00
|
|
|
if ((mode & MODE_DEDICATED) && !GetLabel()) {
|
1997-12-04 18:49:35 +00:00
|
|
|
IpcpInfo.want_ipaddr.s_addr = IpcpInfo.his_ipaddr.s_addr = 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
} else {
|
1997-12-04 18:49:35 +00:00
|
|
|
IpcpInfo.want_ipaddr.s_addr = DefMyAddress.ipaddr.s_addr;
|
|
|
|
IpcpInfo.his_ipaddr.s_addr = DefHisAddress.ipaddr.s_addr;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1995-07-08 08:28:10 +00:00
|
|
|
|
|
|
|
/*
|
1997-09-03 02:08:20 +00:00
|
|
|
* Some implementations of PPP require that we send a
|
|
|
|
* *special* value as our address, even though the rfc specifies
|
|
|
|
* full negotiation (e.g. "0.0.0.0" or Not "0.0.0.0").
|
1995-07-08 08:28:10 +00:00
|
|
|
*/
|
1997-08-19 01:10:24 +00:00
|
|
|
if (HaveTriggerAddress) {
|
1997-12-04 18:49:35 +00:00
|
|
|
IpcpInfo.want_ipaddr.s_addr = TriggerAddress.s_addr;
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "Using trigger address %s\n", inet_ntoa(TriggerAddress));
|
1995-07-08 08:28:10 +00:00
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
if (Enabled(ConfVjcomp))
|
1997-12-04 18:49:35 +00:00
|
|
|
IpcpInfo.want_compproto = (PROTO_VJCOMP << 16) | ((MAX_STATES - 1) << 8) | 1;
|
1995-01-31 06:29:58 +00:00
|
|
|
else
|
1997-12-04 18:49:35 +00:00
|
|
|
IpcpInfo.want_compproto = 0;
|
|
|
|
IpcpInfo.heis1172 = 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
IpcpFsm.maxconfig = 10;
|
1997-11-18 14:52:08 +00:00
|
|
|
throughput_init(&throughput);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-08-25 00:29:32 +00:00
|
|
|
IpcpInitRestartCounter(struct fsm * fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1995-02-26 12:18:08 +00:00
|
|
|
fp->FsmTimer.load = VarRetryTimeout * SECTICKS;
|
1995-01-31 06:29:58 +00:00
|
|
|
fp->restart = 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-08-25 00:29:32 +00:00
|
|
|
IpcpSendConfigReq(struct fsm * fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
u_char *cp;
|
1997-12-03 10:23:54 +00:00
|
|
|
struct lcp_opt o;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
cp = ReqBuff;
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "IpcpSendConfigReq\n");
|
1997-12-04 18:49:35 +00:00
|
|
|
if (!DEV_IS_SYNC || !REJECTED(&IpcpInfo, TY_IPADDR)) {
|
1997-12-03 10:23:54 +00:00
|
|
|
o.id = TY_IPADDR;
|
|
|
|
o.len = 6;
|
1997-12-04 18:49:35 +00:00
|
|
|
*(u_long *)o.data = IpcpInfo.want_ipaddr.s_addr;
|
1997-12-03 10:23:54 +00:00
|
|
|
cp += LcpPutConf(LogIPCP, cp, &o, cftypes[o.id],
|
1997-12-04 18:49:35 +00:00
|
|
|
inet_ntoa(IpcpInfo.want_ipaddr));
|
1997-12-03 10:23:54 +00:00
|
|
|
}
|
|
|
|
|
1997-12-04 18:49:35 +00:00
|
|
|
if (IpcpInfo.want_compproto && !REJECTED(&IpcpInfo, TY_COMPPROTO)) {
|
1997-12-03 10:23:54 +00:00
|
|
|
const char *args;
|
|
|
|
o.id = TY_COMPPROTO;
|
1997-12-04 18:49:35 +00:00
|
|
|
if (IpcpInfo.heis1172) {
|
1997-12-03 10:23:54 +00:00
|
|
|
o.len = 4;
|
|
|
|
*(u_short *)o.data = htons(PROTO_VJCOMP);
|
|
|
|
args = "";
|
|
|
|
} else {
|
|
|
|
o.len = 6;
|
1997-12-04 18:49:35 +00:00
|
|
|
*(u_long *)o.data = htonl(IpcpInfo.want_compproto);
|
|
|
|
args = vj2asc(IpcpInfo.want_compproto);
|
1997-12-03 10:23:54 +00:00
|
|
|
}
|
|
|
|
cp += LcpPutConf(LogIPCP, cp, &o, cftypes[o.id], args);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
FsmOutput(fp, CODE_CONFIGREQ, fp->reqid++, ReqBuff, cp - ReqBuff);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-08-25 00:29:32 +00:00
|
|
|
IpcpSendTerminateReq(struct fsm * fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
/* XXX: No code yet */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-08-25 00:29:32 +00:00
|
|
|
IpcpSendTerminateAck(struct fsm * fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "IpcpSendTerminateAck\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
FsmOutput(fp, CODE_TERMACK, fp->reqid++, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-08-25 00:29:32 +00:00
|
|
|
IpcpLayerStart(struct fsm * fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "IpcpLayerStart.\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-08-25 00:29:32 +00:00
|
|
|
IpcpLayerFinish(struct fsm * fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "IpcpLayerFinish.\n");
|
1997-05-24 17:32:42 +00:00
|
|
|
reconnect(RECON_FALSE);
|
1995-01-31 06:29:58 +00:00
|
|
|
LcpClose();
|
|
|
|
NewPhase(PHASE_TERMINATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-08-25 00:29:32 +00:00
|
|
|
IpcpLayerDown(struct fsm * fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "IpcpLayerDown.\n");
|
1997-11-18 14:52:08 +00:00
|
|
|
throughput_stop(&throughput);
|
|
|
|
throughput_log(&throughput, LogIPCP, NULL);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called when IPCP has reached to OPEN state
|
|
|
|
*/
|
|
|
|
static void
|
1997-08-25 00:29:32 +00:00
|
|
|
IpcpLayerUp(struct fsm * fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
char tbuff[100];
|
|
|
|
|
1997-05-10 01:22:19 +00:00
|
|
|
Prompt();
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "IpcpLayerUp(%d).\n", fp->state);
|
1997-08-25 00:29:32 +00:00
|
|
|
snprintf(tbuff, sizeof(tbuff), "myaddr = %s ",
|
|
|
|
inet_ntoa(IpcpInfo.want_ipaddr));
|
1997-10-07 00:56:58 +00:00
|
|
|
|
|
|
|
if (IpcpInfo.his_compproto >> 16 == PROTO_VJCOMP)
|
|
|
|
VjInit((IpcpInfo.his_compproto >> 8) & 255);
|
|
|
|
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIsKept(LogIPCP) ? LogIPCP : LogLINK, " %s hisaddr = %s\n",
|
1997-08-25 00:29:32 +00:00
|
|
|
tbuff, inet_ntoa(IpcpInfo.his_ipaddr));
|
1997-12-13 02:37:33 +00:00
|
|
|
if (OsSetIpaddress(IpcpInfo.want_ipaddr, IpcpInfo.his_ipaddr) < 0) {
|
1997-06-09 03:27:43 +00:00
|
|
|
if (VarTerm)
|
|
|
|
LogPrintf(LogERROR, "IpcpLayerUp: unable to set ip address\n");
|
|
|
|
return;
|
1997-05-10 01:22:19 +00:00
|
|
|
}
|
1997-11-22 03:37:54 +00:00
|
|
|
#ifndef NOALIAS
|
1997-07-29 22:37:04 +00:00
|
|
|
if (mode & MODE_ALIAS)
|
1997-08-25 00:29:32 +00:00
|
|
|
VarPacketAliasSetAddress(IpcpInfo.want_ipaddr);
|
1997-11-22 03:37:54 +00:00
|
|
|
#endif
|
1995-01-31 06:29:58 +00:00
|
|
|
OsLinkup();
|
1997-11-18 14:52:08 +00:00
|
|
|
throughput_start(&throughput);
|
1995-01-31 06:29:58 +00:00
|
|
|
StartIdleTimer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IpcpUp()
|
|
|
|
{
|
|
|
|
FsmUp(&IpcpFsm);
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "IPCP Up event!!\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IpcpOpen()
|
|
|
|
{
|
|
|
|
FsmOpen(&IpcpFsm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1997-08-25 00:29:32 +00:00
|
|
|
AcceptableAddr(struct in_range * prange, struct in_addr ipaddr)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-08-31 22:59:49 +00:00
|
|
|
LogPrintf(LogDEBUG, "requested = %x\n", htonl(ipaddr.s_addr));
|
|
|
|
LogPrintf(LogDEBUG, "range = %x\n", htonl(prange->ipaddr.s_addr));
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogDEBUG, "/%x\n", htonl(prange->mask.s_addr));
|
|
|
|
LogPrintf(LogDEBUG, "%x, %x\n", htonl(prange->ipaddr.s_addr & prange->
|
1997-08-25 00:29:32 +00:00
|
|
|
mask.s_addr), htonl(ipaddr.s_addr & prange->mask.s_addr));
|
1997-05-10 15:37:40 +00:00
|
|
|
return (prange->ipaddr.s_addr & prange->mask.s_addr) ==
|
1997-08-25 00:29:32 +00:00
|
|
|
(ipaddr.s_addr & prange->mask.s_addr) && ipaddr.s_addr;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-11-08 00:28:11 +00:00
|
|
|
IpcpDecodeConfig(u_char * cp, int plen, int mode_type)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1995-02-26 12:18:08 +00:00
|
|
|
int type, length;
|
1995-01-31 06:29:58 +00:00
|
|
|
u_long *lp, compproto;
|
|
|
|
struct compreq *pcomp;
|
1996-10-06 13:32:37 +00:00
|
|
|
struct in_addr ipaddr, dstipaddr, dnsstuff, ms_info_req;
|
1995-01-31 06:29:58 +00:00
|
|
|
char tbuff[100];
|
1997-01-10 07:53:28 +00:00
|
|
|
char tbuff2[100];
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
ackp = AckBuff;
|
|
|
|
nakp = NakBuff;
|
|
|
|
rejp = RejBuff;
|
|
|
|
|
|
|
|
while (plen >= sizeof(struct fsmconfig)) {
|
|
|
|
type = *cp;
|
|
|
|
length = cp[1];
|
1997-11-14 15:39:15 +00:00
|
|
|
if (type < NCFTYPES)
|
1997-01-10 07:53:28 +00:00
|
|
|
snprintf(tbuff, sizeof(tbuff), " %s[%d] ", cftypes[type], length);
|
1997-11-14 15:39:15 +00:00
|
|
|
else if (type > 128 && type < 128 + NCFTYPES128)
|
1997-12-06 22:43:58 +00:00
|
|
|
snprintf(tbuff, sizeof(tbuff), " %s[%d] ", cftypes128[type-128], length);
|
1995-01-31 06:29:58 +00:00
|
|
|
else
|
1997-12-13 02:37:33 +00:00
|
|
|
snprintf(tbuff, sizeof(tbuff), " <%d>[%d] ", type, length);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case TY_IPADDR: /* RFC1332 */
|
1997-08-25 00:29:32 +00:00
|
|
|
lp = (u_long *) (cp + 2);
|
1995-01-31 06:29:58 +00:00
|
|
|
ipaddr.s_addr = *lp;
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "%s %s\n", tbuff, inet_ntoa(ipaddr));
|
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:
|
1997-12-13 02:37:33 +00:00
|
|
|
if (iplist_isvalid(&DefHisChoice)) {
|
|
|
|
if (iplist_ip2pos(&DefHisChoice, ipaddr) < 0 ||
|
|
|
|
OsTrySetIpaddress(DefMyAddress.ipaddr, ipaddr) != 0) {
|
|
|
|
LogPrintf(LogIPCP, "%s: Address invalid or already in use\n",
|
|
|
|
inet_ntoa(ipaddr));
|
|
|
|
IpcpInfo.his_ipaddr = ChooseHisAddr(DefMyAddress.ipaddr);
|
|
|
|
if (IpcpInfo.his_ipaddr.s_addr == INADDR_ANY) {
|
|
|
|
memcpy(rejp, cp, length);
|
|
|
|
rejp += length;
|
|
|
|
} else {
|
|
|
|
memcpy(nakp, cp, 2);
|
|
|
|
memcpy(nakp+2, &IpcpInfo.his_ipaddr.s_addr, length - 2);
|
|
|
|
nakp += length;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (!AcceptableAddr(&DefHisAddress, ipaddr)) {
|
1997-08-25 00:29:32 +00:00
|
|
|
/*
|
|
|
|
* If destination address is not acceptable, insist to use what we
|
|
|
|
* want to use.
|
|
|
|
*/
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(nakp, cp, 2);
|
1997-12-13 02:37:33 +00:00
|
|
|
memcpy(nakp+2, &IpcpInfo.his_ipaddr.s_addr, length - 2);
|
1997-08-25 00:29:32 +00:00
|
|
|
nakp += length;
|
|
|
|
break;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
IpcpInfo.his_ipaddr = ipaddr;
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(ackp, cp, length);
|
1995-01-31 06:29:58 +00:00
|
|
|
ackp += length;
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
|
|
|
if (AcceptableAddr(&DefMyAddress, ipaddr)) {
|
1997-12-13 02:37:33 +00:00
|
|
|
/* Use address suggested by peer */
|
1997-08-31 22:59:49 +00:00
|
|
|
snprintf(tbuff2, sizeof(tbuff2), "%s changing address: %s ", tbuff,
|
|
|
|
inet_ntoa(IpcpInfo.want_ipaddr));
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "%s --> %s\n", tbuff2, inet_ntoa(ipaddr));
|
1995-01-31 06:29:58 +00:00
|
|
|
IpcpInfo.want_ipaddr = ipaddr;
|
1997-12-13 02:37:33 +00:00
|
|
|
} else {
|
|
|
|
LogPrintf(LogIPCP, "%s: Unacceptable address!\n", inet_ntoa(ipaddr));
|
|
|
|
FsmClose(&IpcpFsm);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
|
|
|
IpcpInfo.his_reject |= (1 << type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TY_COMPPROTO:
|
1997-08-25 00:29:32 +00:00
|
|
|
lp = (u_long *) (cp + 2);
|
1995-01-31 06:29:58 +00:00
|
|
|
compproto = htonl(*lp);
|
1997-12-03 10:23:54 +00:00
|
|
|
LogPrintf(LogIPCP, "%s %s\n", tbuff, vj2asc(compproto));
|
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:
|
|
|
|
if (!Acceptable(ConfVjcomp)) {
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(rejp, cp, length);
|
1995-01-31 06:29:58 +00:00
|
|
|
rejp += length;
|
|
|
|
} else {
|
1997-08-25 00:29:32 +00:00
|
|
|
pcomp = (struct compreq *) (cp + 2);
|
1995-01-31 06:29:58 +00:00
|
|
|
switch (length) {
|
1997-08-25 00:29:32 +00:00
|
|
|
case 4: /* RFC1172 */
|
1995-01-31 06:29:58 +00:00
|
|
|
if (ntohs(pcomp->proto) == PROTO_VJCOMP) {
|
1997-06-25 19:30:05 +00:00
|
|
|
LogPrintf(LogWARN, "Peer is speaking RFC1172 compression protocol !\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
IpcpInfo.heis1172 = 1;
|
|
|
|
IpcpInfo.his_compproto = compproto;
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(ackp, cp, length);
|
1995-01-31 06:29:58 +00:00
|
|
|
ackp += length;
|
|
|
|
} else {
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(nakp, cp, 2);
|
1995-01-31 06:29:58 +00:00
|
|
|
pcomp->proto = htons(PROTO_VJCOMP);
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(nakp+2, &pcomp, 2);
|
1995-01-31 06:29:58 +00:00
|
|
|
nakp += length;
|
|
|
|
}
|
|
|
|
break;
|
1997-08-25 00:29:32 +00:00
|
|
|
case 6: /* RFC1332 */
|
1995-01-31 06:29:58 +00:00
|
|
|
if (ntohs(pcomp->proto) == PROTO_VJCOMP
|
1997-08-25 00:29:32 +00:00
|
|
|
&& pcomp->slots < MAX_STATES && pcomp->slots > 2) {
|
1995-01-31 06:29:58 +00:00
|
|
|
IpcpInfo.his_compproto = compproto;
|
|
|
|
IpcpInfo.heis1172 = 0;
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(ackp, cp, length);
|
1995-01-31 06:29:58 +00:00
|
|
|
ackp += length;
|
|
|
|
} else {
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(nakp, cp, 2);
|
1995-01-31 06:29:58 +00:00
|
|
|
pcomp->proto = htons(PROTO_VJCOMP);
|
|
|
|
pcomp->slots = MAX_STATES - 1;
|
|
|
|
pcomp->compcid = 0;
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(nakp+2, &pcomp, sizeof(pcomp));
|
1995-01-31 06:29:58 +00:00
|
|
|
nakp += length;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(rejp, cp, length);
|
1995-01-31 06:29:58 +00:00
|
|
|
rejp += length;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "%s changing compproto: %08x --> %08x\n",
|
1997-08-25 00:29:32 +00:00
|
|
|
tbuff, IpcpInfo.want_compproto, compproto);
|
1995-01-31 06:29:58 +00:00
|
|
|
IpcpInfo.want_compproto = compproto;
|
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
|
|
|
IpcpInfo.his_reject |= (1 << type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1997-08-25 00:29:32 +00:00
|
|
|
case TY_IPADDRS: /* RFC1172 */
|
|
|
|
lp = (u_long *) (cp + 2);
|
1995-01-31 06:29:58 +00:00
|
|
|
ipaddr.s_addr = *lp;
|
1997-08-25 00:29:32 +00:00
|
|
|
lp = (u_long *) (cp + 6);
|
1995-01-31 06:29:58 +00:00
|
|
|
dstipaddr.s_addr = *lp;
|
1997-08-31 22:59:49 +00:00
|
|
|
snprintf(tbuff2, sizeof(tbuff2), "%s %s,", tbuff, inet_ntoa(ipaddr));
|
|
|
|
LogPrintf(LogIPCP, "%s %s\n", tbuff2, inet_ntoa(dstipaddr));
|
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:
|
|
|
|
IpcpInfo.his_ipaddr = ipaddr;
|
|
|
|
IpcpInfo.want_ipaddr = dstipaddr;
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(ackp, cp, length);
|
1995-01-31 06:29:58 +00:00
|
|
|
ackp += length;
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
1997-08-31 22:59:49 +00:00
|
|
|
snprintf(tbuff2, sizeof(tbuff2), "%s changing address: %s", tbuff,
|
|
|
|
inet_ntoa(IpcpInfo.want_ipaddr));
|
|
|
|
LogPrintf(LogIPCP, "%s --> %s\n", tbuff2, inet_ntoa(ipaddr));
|
1995-01-31 06:29:58 +00:00
|
|
|
IpcpInfo.want_ipaddr = ipaddr;
|
|
|
|
IpcpInfo.his_ipaddr = dstipaddr;
|
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
|
|
|
IpcpInfo.his_reject |= (1 << type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1996-10-06 13:32:37 +00:00
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
/*
|
|
|
|
* MS extensions for MS's PPP
|
|
|
|
*/
|
1996-10-06 13:32:37 +00:00
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
#ifndef NOMSEXT
|
1997-08-25 00:29:32 +00:00
|
|
|
case TY_PRIMARY_DNS: /* MS PPP DNS negotiation hack */
|
1996-10-06 13:32:37 +00:00
|
|
|
case TY_SECONDARY_DNS:
|
1997-08-25 00:29:32 +00:00
|
|
|
if (!Enabled(ConfMSExt)) {
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "MS NS req - rejected - msext disabled\n");
|
1997-08-25 00:29:32 +00:00
|
|
|
IpcpInfo.my_reject |= (1 << type);
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(rejp, cp, length);
|
1996-10-06 13:32:37 +00:00
|
|
|
rejp += length;
|
|
|
|
break;
|
|
|
|
}
|
1997-11-08 00:28:11 +00:00
|
|
|
switch (mode_type) {
|
1996-10-06 13:32:37 +00:00
|
|
|
case MODE_REQ:
|
1997-08-25 00:29:32 +00:00
|
|
|
lp = (u_long *) (cp + 2);
|
1996-10-06 13:32:37 +00:00
|
|
|
dnsstuff.s_addr = *lp;
|
1997-08-25 00:29:32 +00:00
|
|
|
ms_info_req.s_addr = ns_entries[((type - TY_PRIMARY_DNS) ? 1 : 0)].s_addr;
|
|
|
|
if (dnsstuff.s_addr != ms_info_req.s_addr) {
|
|
|
|
|
1996-10-06 13:32:37 +00:00
|
|
|
/*
|
1997-08-25 00:29:32 +00:00
|
|
|
* So the client has got the DNS stuff wrong (first request) so
|
1997-08-31 22:59:49 +00:00
|
|
|
* we'll tell 'em how it is
|
1997-08-25 00:29:32 +00:00
|
|
|
*/
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(nakp, cp, 2); /* copy first two (type/length) */
|
1997-08-25 00:29:32 +00:00
|
|
|
LogPrintf(LogIPCP, "MS NS req %d:%s->%s - nak\n",
|
|
|
|
type,
|
|
|
|
inet_ntoa(dnsstuff),
|
|
|
|
inet_ntoa(ms_info_req));
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(nakp+2, &ms_info_req, length);
|
1996-10-06 13:32:37 +00:00
|
|
|
nakp += length;
|
|
|
|
break;
|
|
|
|
}
|
1997-08-25 00:29:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Otherwise they have it right (this time) so we send a ack packet
|
|
|
|
* back confirming it... end of story
|
|
|
|
*/
|
|
|
|
LogPrintf(LogIPCP, "MS NS req %d:%s ok - ack\n",
|
|
|
|
type,
|
|
|
|
inet_ntoa(ms_info_req));
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(ackp, cp, length);
|
1996-10-06 13:32:37 +00:00
|
|
|
ackp += length;
|
|
|
|
break;
|
1997-08-25 00:29:32 +00:00
|
|
|
case MODE_NAK: /* what does this mean?? */
|
|
|
|
LogPrintf(LogIPCP, "MS NS req %d - NAK??\n", type);
|
1996-10-06 13:32:37 +00:00
|
|
|
break;
|
1997-08-25 00:29:32 +00:00
|
|
|
case MODE_REJ: /* confused?? me to :) */
|
|
|
|
LogPrintf(LogIPCP, "MS NS req %d - REJ??\n", type);
|
1996-10-06 13:32:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
case TY_PRIMARY_NBNS: /* MS PPP NetBIOS nameserver hack */
|
1996-10-06 13:32:37 +00:00
|
|
|
case TY_SECONDARY_NBNS:
|
1997-08-25 00:29:32 +00:00
|
|
|
if (!Enabled(ConfMSExt)) {
|
|
|
|
LogPrintf(LogIPCP, "MS NBNS req - rejected - msext disabled\n");
|
|
|
|
IpcpInfo.my_reject |= (1 << type);
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(rejp, cp, length);
|
1997-08-25 00:29:32 +00:00
|
|
|
rejp += length;
|
|
|
|
break;
|
|
|
|
}
|
1997-11-08 00:28:11 +00:00
|
|
|
switch (mode_type) {
|
1996-10-06 13:32:37 +00:00
|
|
|
case MODE_REQ:
|
1997-08-25 00:29:32 +00:00
|
|
|
lp = (u_long *) (cp + 2);
|
1996-10-06 13:32:37 +00:00
|
|
|
dnsstuff.s_addr = *lp;
|
1997-08-25 00:29:32 +00:00
|
|
|
ms_info_req.s_addr = nbns_entries[((type - TY_PRIMARY_NBNS) ? 1 : 0)].s_addr;
|
|
|
|
if (dnsstuff.s_addr != ms_info_req.s_addr) {
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(nakp, cp, 2);
|
|
|
|
memcpy(nakp+2, &ms_info_req.s_addr, length);
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "MS NBNS req %d:%s->%s - nak\n",
|
1997-08-25 00:29:32 +00:00
|
|
|
type,
|
|
|
|
inet_ntoa(dnsstuff),
|
|
|
|
inet_ntoa(ms_info_req));
|
1996-10-06 13:32:37 +00:00
|
|
|
nakp += length;
|
|
|
|
break;
|
|
|
|
}
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "MS NBNS req %d:%s ok - ack\n",
|
1997-08-25 00:29:32 +00:00
|
|
|
type,
|
|
|
|
inet_ntoa(ms_info_req));
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(ackp, cp, length);
|
1996-10-06 13:32:37 +00:00
|
|
|
ackp += length;
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
1997-08-25 00:29:32 +00:00
|
|
|
LogPrintf(LogIPCP, "MS NBNS req %d - NAK??\n", type);
|
1996-10-06 13:32:37 +00:00
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
1997-08-25 00:29:32 +00:00
|
|
|
LogPrintf(LogIPCP, "MS NBNS req %d - REJ??\n", type);
|
1996-10-06 13:32:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
#endif
|
1996-10-06 13:32:37 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
default:
|
|
|
|
IpcpInfo.my_reject |= (1 << type);
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(rejp, cp, length);
|
1995-01-31 06:29:58 +00:00
|
|
|
rejp += length;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
plen -= length;
|
|
|
|
cp += length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-08-25 00:29:32 +00:00
|
|
|
IpcpInput(struct mbuf * bp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
FsmInput(&IpcpFsm, bp);
|
|
|
|
}
|