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-08-20 23:47:53 +00:00
|
|
|
* $Id: ipcp.c,v 1.24 1997/08/19 01:10:20 brian Exp $
|
1995-05-30 03:57:47 +00:00
|
|
|
*
|
1995-01-31 06:29:58 +00:00
|
|
|
* TODO:
|
|
|
|
* o More RFC1772 backwoard compatibility
|
|
|
|
*/
|
|
|
|
#include "fsm.h"
|
|
|
|
#include "lcpproto.h"
|
|
|
|
#include "lcp.h"
|
|
|
|
#include "ipcp.h"
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#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"
|
|
|
|
|
|
|
|
extern void PutConfValue();
|
|
|
|
extern void Prompt();
|
|
|
|
extern struct in_addr ifnetmask;
|
|
|
|
|
|
|
|
struct ipcpstate IpcpInfo;
|
1997-08-19 01:10:24 +00:00
|
|
|
struct in_range DefMyAddress, DefHisAddress;
|
|
|
|
struct in_addr TriggerAddress;
|
|
|
|
int HaveTriggerAddress;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
#ifndef NOMSEXT
|
1996-10-06 13:32:37 +00:00
|
|
|
struct in_addr ns_entries[2], nbns_entries[2];
|
1997-06-09 03:27:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
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
|
|
|
|
1995-03-11 15:18:55 +00:00
|
|
|
struct pppTimer IpcpReportTimer;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
static int lastInOctets, lastOutOctets;
|
|
|
|
|
|
|
|
#define REJECTED(p, x) (p->his_reject & (1<<x))
|
|
|
|
|
|
|
|
struct fsm IpcpFsm = {
|
|
|
|
"IPCP",
|
|
|
|
PROTO_IPCP,
|
|
|
|
IPCP_MAXCODE,
|
|
|
|
OPEN_ACTIVE,
|
|
|
|
ST_INITIAL,
|
|
|
|
0, 0, 0,
|
|
|
|
|
|
|
|
0,
|
|
|
|
{ 0, 0, 0, NULL, NULL, NULL },
|
1997-08-20 23:47:53 +00:00
|
|
|
{ 0, 0, 0, NULL, NULL, NULL },
|
|
|
|
LogIPCP,
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
IpcpLayerUp,
|
|
|
|
IpcpLayerDown,
|
|
|
|
IpcpLayerStart,
|
|
|
|
IpcpLayerFinish,
|
|
|
|
IpcpInitRestartCounter,
|
|
|
|
IpcpSendConfigReq,
|
|
|
|
IpcpSendTerminateReq,
|
|
|
|
IpcpSendTerminateAck,
|
|
|
|
IpcpDecodeConfig,
|
|
|
|
};
|
|
|
|
|
|
|
|
static char *cftypes[] = {
|
|
|
|
"???", "IPADDRS", "COMPPROTO", "IPADDR",
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function called every second. Updates connection period and idle period,
|
|
|
|
* also update LQR information.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
IpcpReportFunc()
|
|
|
|
{
|
|
|
|
ipConnectSecs++;
|
|
|
|
if (lastInOctets == ipInOctets && lastOutOctets == ipOutOctets)
|
|
|
|
ipIdleSecs++;
|
|
|
|
lastInOctets = ipInOctets;
|
|
|
|
lastOutOctets = ipOutOctets;
|
|
|
|
StopTimer(&IpcpReportTimer);
|
|
|
|
IpcpReportTimer.state = TIMER_STOPPED;
|
|
|
|
StartTimer(&IpcpReportTimer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
IpcpStartReport()
|
|
|
|
{
|
|
|
|
ipIdleSecs = ipConnectSecs = 0;
|
|
|
|
StopTimer(&IpcpReportTimer);
|
|
|
|
IpcpReportTimer.state = TIMER_STOPPED;
|
|
|
|
IpcpReportTimer.load = SECTICKS;
|
|
|
|
IpcpReportTimer.func = IpcpReportFunc;
|
|
|
|
StartTimer(&IpcpReportTimer);
|
|
|
|
}
|
|
|
|
|
1997-05-10 01:22:19 +00:00
|
|
|
int
|
1995-01-31 06:29:58 +00:00
|
|
|
ReportIpcpStatus()
|
|
|
|
{
|
|
|
|
struct ipcpstate *icp = &IpcpInfo;
|
|
|
|
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]);
|
|
|
|
fprintf(VarTerm, " his side: %s, %lx\n",
|
1995-01-31 06:29:58 +00:00
|
|
|
inet_ntoa(icp->his_ipaddr), icp->his_compproto);
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, " my side: %s, %lx\n",
|
1995-01-31 06:29:58 +00:00
|
|
|
inet_ntoa(icp->want_ipaddr), icp->want_compproto);
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, "connected: %d secs, idle: %d secs\n\n", ipConnectSecs, ipIdleSecs);
|
|
|
|
fprintf(VarTerm, "Defaults:\n");
|
|
|
|
fprintf(VarTerm, " My Address: %s/%d\n",
|
1995-01-31 06:29:58 +00:00
|
|
|
inet_ntoa(DefMyAddress.ipaddr), DefMyAddress.width);
|
1997-06-09 03:27:43 +00:00
|
|
|
fprintf(VarTerm, " His Address: %s/%d\n",
|
1995-01-31 06:29:58 +00:00
|
|
|
inet_ntoa(DefHisAddress.ipaddr), DefHisAddress.width);
|
1997-08-19 01:10:24 +00:00
|
|
|
if (HaveTriggerAddress)
|
|
|
|
fprintf(VarTerm, " Negotiation(trigger): %s\n", inet_ntoa(TriggerAddress));
|
|
|
|
else
|
|
|
|
fprintf(VarTerm, " Negotiation(trigger): MYADDR\n");
|
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];
|
|
|
|
|
|
|
|
bzero(&DefMyAddress, sizeof(DefMyAddress));
|
|
|
|
bzero(&DefHisAddress, 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) {
|
|
|
|
hp = gethostbyname(name);
|
|
|
|
if (hp && hp->h_addrtype == AF_INET) {
|
|
|
|
bcopy(hp->h_addr, (char *)&DefMyAddress.ipaddr.s_addr, hp->h_length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IpcpInit()
|
|
|
|
{
|
|
|
|
struct ipcpstate *icp = &IpcpInfo;
|
|
|
|
|
|
|
|
FsmInit(&IpcpFsm);
|
|
|
|
bzero(icp, sizeof(struct ipcpstate));
|
|
|
|
if ((mode & MODE_DEDICATED) && !dstsystem) {
|
|
|
|
icp->want_ipaddr.s_addr = icp->his_ipaddr.s_addr = 0;
|
|
|
|
} else {
|
|
|
|
icp->want_ipaddr.s_addr = DefMyAddress.ipaddr.s_addr;
|
|
|
|
icp->his_ipaddr.s_addr = DefHisAddress.ipaddr.s_addr;
|
|
|
|
}
|
1995-07-08 08:28:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Some implementation of PPP are:
|
|
|
|
* Starting a negotiaion by require sending *special* value as my address,
|
|
|
|
* even though standard of PPP is defined full negotiation based.
|
|
|
|
* (e.g. "0.0.0.0" or Not "0.0.0.0")
|
|
|
|
*/
|
1997-08-19 01:10:24 +00:00
|
|
|
if (HaveTriggerAddress) {
|
|
|
|
icp->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))
|
|
|
|
icp->want_compproto = (PROTO_VJCOMP << 16) | ((MAX_STATES - 1) << 8);
|
|
|
|
else
|
|
|
|
icp->want_compproto = 0;
|
|
|
|
icp->heis1172 = 0;
|
|
|
|
IpcpFsm.maxconfig = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
IpcpInitRestartCounter(fp)
|
|
|
|
struct fsm *fp;
|
|
|
|
{
|
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
|
|
|
|
IpcpSendConfigReq(fp)
|
|
|
|
struct fsm *fp;
|
|
|
|
{
|
|
|
|
u_char *cp;
|
|
|
|
struct ipcpstate *icp = &IpcpInfo;
|
|
|
|
|
|
|
|
cp = ReqBuff;
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "IpcpSendConfigReq\n");
|
1995-02-26 12:18:08 +00:00
|
|
|
if (!DEV_IS_SYNC || !REJECTED(icp, TY_IPADDR))
|
|
|
|
PutConfValue(&cp, cftypes, TY_IPADDR, 6, ntohl(icp->want_ipaddr.s_addr));
|
1995-01-31 06:29:58 +00:00
|
|
|
if (icp->want_compproto && !REJECTED(icp, TY_COMPPROTO)) {
|
|
|
|
if (icp->heis1172)
|
|
|
|
PutConfValue(&cp, cftypes, TY_COMPPROTO, 4, icp->want_compproto >> 16);
|
|
|
|
else
|
|
|
|
PutConfValue(&cp, cftypes, TY_COMPPROTO, 6, icp->want_compproto);
|
|
|
|
}
|
|
|
|
FsmOutput(fp, CODE_CONFIGREQ, fp->reqid++, ReqBuff, cp - ReqBuff);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
IpcpSendTerminateReq(fp)
|
|
|
|
struct fsm *fp;
|
|
|
|
{
|
|
|
|
/* XXX: No code yet */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
IpcpSendTerminateAck(fp)
|
|
|
|
struct fsm *fp;
|
|
|
|
{
|
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
|
|
|
|
IpcpLayerStart(fp)
|
|
|
|
struct fsm *fp;
|
|
|
|
{
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "IpcpLayerStart.\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
IpcpLayerFinish(fp)
|
|
|
|
struct fsm *fp;
|
|
|
|
{
|
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
|
|
|
|
IpcpLayerDown(fp)
|
|
|
|
struct fsm *fp;
|
|
|
|
{
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "IpcpLayerDown.\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
StopTimer(&IpcpReportTimer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called when IPCP has reached to OPEN state
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
IpcpLayerUp(fp)
|
|
|
|
struct fsm *fp;
|
|
|
|
{
|
|
|
|
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-01-10 07:53:28 +00:00
|
|
|
snprintf(tbuff, sizeof(tbuff), "myaddr = %s ",
|
|
|
|
inet_ntoa(IpcpInfo.want_ipaddr));
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIsKept(LogIPCP) ? LogIPCP : LogLINK, " %s hisaddr = %s\n",
|
1997-06-09 03:27:43 +00:00
|
|
|
tbuff, inet_ntoa(IpcpInfo.his_ipaddr));
|
1997-05-10 01:22:19 +00:00
|
|
|
if (OsSetIpaddress(IpcpInfo.want_ipaddr, IpcpInfo.his_ipaddr, ifnetmask) < 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-07-29 22:37:04 +00:00
|
|
|
if (mode & MODE_ALIAS)
|
|
|
|
VarSetPacketAliasAddress(IpcpInfo.want_ipaddr);
|
1995-01-31 06:29:58 +00:00
|
|
|
OsLinkup();
|
|
|
|
IpcpStartReport();
|
|
|
|
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
|
|
|
|
AcceptableAddr(prange, ipaddr)
|
|
|
|
struct in_range *prange;
|
|
|
|
struct in_addr ipaddr;
|
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogDEBUG, "requested = %x ", htonl(ipaddr.s_addr));
|
|
|
|
LogPrintf(LogDEBUG, "range = %x", htonl(prange->ipaddr.s_addr));
|
|
|
|
LogPrintf(LogDEBUG, "/%x\n", htonl(prange->mask.s_addr));
|
|
|
|
LogPrintf(LogDEBUG, "%x, %x\n", htonl(prange->ipaddr.s_addr & prange->
|
|
|
|
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) ==
|
|
|
|
(ipaddr.s_addr & prange->mask.s_addr) && ipaddr.s_addr;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1995-02-26 12:18:08 +00:00
|
|
|
IpcpDecodeConfig(cp, plen, mode)
|
|
|
|
u_char *cp;
|
|
|
|
int plen;
|
1995-01-31 06:29:58 +00:00
|
|
|
int mode;
|
|
|
|
{
|
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)) {
|
|
|
|
if (plen < 0)
|
|
|
|
break;
|
|
|
|
type = *cp;
|
|
|
|
length = cp[1];
|
|
|
|
if (type <= TY_IPADDR)
|
1997-01-10 07:53:28 +00:00
|
|
|
snprintf(tbuff, sizeof(tbuff), " %s[%d] ", cftypes[type], length);
|
1995-01-31 06:29:58 +00:00
|
|
|
else
|
1997-01-10 07:53:28 +00:00
|
|
|
snprintf(tbuff, sizeof(tbuff), " ");
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case TY_IPADDR: /* RFC1332 */
|
|
|
|
lp = (u_long *)(cp + 2);
|
|
|
|
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
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case MODE_REQ:
|
|
|
|
if (!AcceptableAddr(&DefHisAddress, ipaddr)) {
|
|
|
|
/*
|
|
|
|
* If destination address is not acceptable, insist to use
|
|
|
|
* what we want to use.
|
|
|
|
*/
|
|
|
|
bcopy(cp, nakp, 2);
|
|
|
|
bcopy(&IpcpInfo.his_ipaddr.s_addr, nakp+2, length);
|
|
|
|
nakp += length;
|
|
|
|
break;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
IpcpInfo.his_ipaddr = ipaddr;
|
|
|
|
bcopy(cp, ackp, length);
|
|
|
|
ackp += length;
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
|
|
|
if (AcceptableAddr(&DefMyAddress, ipaddr)) {
|
|
|
|
/*
|
|
|
|
* Use address suggested by peer.
|
|
|
|
*/
|
1997-01-10 07:53:28 +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;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
|
|
|
IpcpInfo.his_reject |= (1 << type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TY_COMPPROTO:
|
|
|
|
lp = (u_long *)(cp + 2);
|
|
|
|
compproto = htonl(*lp);
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "%s %08x\n", tbuff, compproto);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case MODE_REQ:
|
|
|
|
if (!Acceptable(ConfVjcomp)) {
|
|
|
|
bcopy(cp, rejp, length);
|
|
|
|
rejp += length;
|
|
|
|
} else {
|
|
|
|
pcomp = (struct compreq *)(cp + 2);
|
|
|
|
switch (length) {
|
|
|
|
case 4: /* RFC1172 */
|
|
|
|
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;
|
|
|
|
bcopy(cp, ackp, length);
|
|
|
|
ackp += length;
|
|
|
|
} else {
|
|
|
|
bcopy(cp, nakp, 2);
|
|
|
|
pcomp->proto = htons(PROTO_VJCOMP);
|
|
|
|
bcopy(&pcomp, nakp + 2, 2);
|
|
|
|
nakp += length;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6: /* RFC1332 */
|
|
|
|
if (ntohs(pcomp->proto) == PROTO_VJCOMP
|
|
|
|
&& pcomp->slots < MAX_STATES && pcomp->slots > 2) {
|
|
|
|
IpcpInfo.his_compproto = compproto;
|
|
|
|
IpcpInfo.heis1172 = 0;
|
|
|
|
bcopy(cp, ackp, length);
|
|
|
|
ackp += length;
|
|
|
|
} else {
|
|
|
|
bcopy(cp, nakp, 2);
|
|
|
|
pcomp->proto = htons(PROTO_VJCOMP);
|
|
|
|
pcomp->slots = MAX_STATES - 1;
|
|
|
|
pcomp->compcid = 0;
|
|
|
|
bcopy(&pcomp, nakp + 2, sizeof(pcomp));
|
|
|
|
nakp += length;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bcopy(cp, rejp, length);
|
|
|
|
rejp += length;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "%s changing compproto: %08x --> %08x\n",
|
1995-01-31 06:29:58 +00:00
|
|
|
tbuff, IpcpInfo.want_compproto, compproto);
|
|
|
|
IpcpInfo.want_compproto = compproto;
|
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
|
|
|
IpcpInfo.his_reject |= (1 << type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TY_IPADDRS: /* RFC1172 */
|
|
|
|
lp = (u_long *)(cp + 2);
|
|
|
|
ipaddr.s_addr = *lp;
|
|
|
|
lp = (u_long *)(cp + 6);
|
|
|
|
dstipaddr.s_addr = *lp;
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "%s %s, ", tbuff, inet_ntoa(ipaddr));
|
|
|
|
LogPrintf(LogIPCP, "%s\n", inet_ntoa(dstipaddr));
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case MODE_REQ:
|
|
|
|
IpcpInfo.his_ipaddr = ipaddr;
|
|
|
|
IpcpInfo.want_ipaddr = dstipaddr;
|
|
|
|
bcopy(cp, ackp, length);
|
|
|
|
ackp += length;
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "%s changing address: %s ",
|
1995-01-31 06:29:58 +00:00
|
|
|
tbuff, inet_ntoa(IpcpInfo.want_ipaddr));
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "--> %s\n", 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
|
|
|
|
|
|
|
/*
|
|
|
|
* MS extensions for MS's PPP
|
|
|
|
*/
|
|
|
|
|
1997-06-09 03:27:43 +00:00
|
|
|
#ifndef NOMSEXT
|
1996-10-06 13:32:37 +00:00
|
|
|
case TY_PRIMARY_DNS: /* MS PPP DNS negotiation hack */
|
|
|
|
case TY_SECONDARY_DNS:
|
|
|
|
if( !Enabled( ConfMSExt ) ) {
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "MS NS req - rejected - msext disabled\n");
|
1996-10-06 13:32:37 +00:00
|
|
|
IpcpInfo.my_reject |= ( 1 << type );
|
|
|
|
bcopy(cp, rejp, length);
|
|
|
|
rejp += length;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch( mode ){
|
|
|
|
case MODE_REQ:
|
|
|
|
lp = (u_long *)(cp + 2);
|
|
|
|
dnsstuff.s_addr = *lp;
|
|
|
|
ms_info_req.s_addr = ns_entries[((type - TY_PRIMARY_DNS)?1:0)].s_addr;
|
|
|
|
if( dnsstuff.s_addr != ms_info_req.s_addr )
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
So the client has got the DNS stuff wrong (first request)
|
|
|
|
so well tell 'em how it is
|
|
|
|
*/
|
|
|
|
bcopy( cp, nakp, 2 ); /* copy first two (type/length) */
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf( LogIPCP, "MS NS req %d:%s->%s - nak\n",
|
1996-10-06 13:32:37 +00:00
|
|
|
type,
|
|
|
|
inet_ntoa( dnsstuff ),
|
|
|
|
inet_ntoa( ms_info_req ));
|
|
|
|
bcopy( &ms_info_req, nakp+2, length );
|
|
|
|
nakp += length;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
Otherwise they have it right (this time) so we send
|
|
|
|
a ack packet back confirming it... end of story
|
|
|
|
*/
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf( LogIPCP, "MS NS req %d:%s ok - ack\n",
|
1996-10-06 13:32:37 +00:00
|
|
|
type,
|
|
|
|
inet_ntoa( ms_info_req ));
|
|
|
|
bcopy( cp, ackp, length );
|
|
|
|
ackp += length;
|
|
|
|
break;
|
|
|
|
case MODE_NAK: /* what does this mean?? */
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "MS NS req %d - NAK??\n", type );
|
1996-10-06 13:32:37 +00:00
|
|
|
break;
|
|
|
|
case MODE_REJ: /* confused?? me to :) */
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "MS NS req %d - REJ??\n", type );
|
1996-10-06 13:32:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TY_PRIMARY_NBNS: /* MS PPP NetBIOS nameserver hack */
|
|
|
|
case TY_SECONDARY_NBNS:
|
|
|
|
if( !Enabled( ConfMSExt ) ) {
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf( LogIPCP, "MS NBNS req - rejected - msext disabled\n" );
|
1996-10-06 13:32:37 +00:00
|
|
|
IpcpInfo.my_reject |= ( 1 << type );
|
|
|
|
bcopy( cp, rejp, length );
|
|
|
|
rejp += length;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch( mode ){
|
|
|
|
case MODE_REQ:
|
|
|
|
lp = (u_long *)(cp + 2);
|
|
|
|
dnsstuff.s_addr = *lp;
|
|
|
|
ms_info_req.s_addr = nbns_entries[((type - TY_PRIMARY_NBNS)?1:0)].s_addr;
|
|
|
|
if( dnsstuff.s_addr != ms_info_req.s_addr )
|
|
|
|
{
|
|
|
|
bcopy( cp, nakp, 2 );
|
|
|
|
bcopy( &ms_info_req.s_addr , nakp+2, length );
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "MS NBNS req %d:%s->%s - nak\n",
|
1996-10-06 13:32:37 +00:00
|
|
|
type,
|
|
|
|
inet_ntoa( dnsstuff ),
|
|
|
|
inet_ntoa( ms_info_req ));
|
|
|
|
nakp += length;
|
|
|
|
break;
|
|
|
|
}
|
1997-08-20 23:47:53 +00:00
|
|
|
LogPrintf(LogIPCP, "MS NBNS req %d:%s ok - ack\n",
|
1996-10-06 13:32:37 +00:00
|
|
|
type,
|
|
|
|
inet_ntoa( ms_info_req ));
|
|
|
|
bcopy( cp, ackp, length );
|
|
|
|
ackp += length;
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
1997-08-20 23:47:53 +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-20 23:47:53 +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);
|
|
|
|
bcopy(cp, rejp, length);
|
|
|
|
rejp += length;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
plen -= length;
|
|
|
|
cp += length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IpcpInput(struct mbuf *bp)
|
|
|
|
{
|
|
|
|
FsmInput(&IpcpFsm, bp);
|
|
|
|
}
|