1998-01-29 00:44:16 +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.
|
|
|
|
*
|
1998-04-03 19:26:02 +00:00
|
|
|
* $Id: ipcp.c,v 1.50.2.30 1998/04/03 19:25:04 brian Exp $
|
1998-01-29 00:44:16 +00:00
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* o More RFC1772 backwoard compatibility
|
|
|
|
*/
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netdb.h>
|
1998-02-07 20:50:08 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <sys/sockio.h>
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1998-02-07 20:50:08 +00:00
|
|
|
#include <sys/errno.h>
|
1998-02-02 19:33:40 +00:00
|
|
|
#include <termios.h>
|
1998-01-29 00:44:16 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "command.h"
|
|
|
|
#include "mbuf.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "defs.h"
|
|
|
|
#include "timer.h"
|
|
|
|
#include "fsm.h"
|
|
|
|
#include "lcpproto.h"
|
|
|
|
#include "lcp.h"
|
|
|
|
#include "iplist.h"
|
1998-01-29 23:11:44 +00:00
|
|
|
#include "throughput.h"
|
1998-01-29 00:44:16 +00:00
|
|
|
#include "slcompress.h"
|
1998-03-16 22:54:35 +00:00
|
|
|
#include "ipcp.h"
|
1998-03-16 22:52:54 +00:00
|
|
|
#include "filter.h"
|
1998-03-20 19:48:28 +00:00
|
|
|
#include "descriptor.h"
|
1998-01-29 00:44:16 +00:00
|
|
|
#include "loadalias.h"
|
|
|
|
#include "vars.h"
|
|
|
|
#include "vjcomp.h"
|
|
|
|
#include "ip.h"
|
|
|
|
#include "route.h"
|
1998-03-13 00:44:26 +00:00
|
|
|
#include "lqr.h"
|
1998-01-30 19:46:07 +00:00
|
|
|
#include "hdlc.h"
|
1998-02-02 19:33:40 +00:00
|
|
|
#include "async.h"
|
1998-04-03 19:21:56 +00:00
|
|
|
#include "ccp.h"
|
1998-01-30 19:46:07 +00:00
|
|
|
#include "link.h"
|
1998-01-29 00:49:32 +00:00
|
|
|
#include "physical.h"
|
1998-04-03 19:21:56 +00:00
|
|
|
#include "mp.h"
|
|
|
|
#include "bundle.h"
|
1998-02-07 20:50:08 +00:00
|
|
|
#include "id.h"
|
|
|
|
#include "arp.h"
|
|
|
|
#include "systems.h"
|
1998-02-10 03:23:50 +00:00
|
|
|
#include "prompt.h"
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-02-21 01:45:26 +00:00
|
|
|
#undef REJECTED
|
|
|
|
#define REJECTED(p, x) ((p)->peer_reject & (1<<(x)))
|
|
|
|
|
1998-01-29 23:11:44 +00:00
|
|
|
struct compreq {
|
|
|
|
u_short proto;
|
|
|
|
u_char slots;
|
|
|
|
u_char compcid;
|
|
|
|
};
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
static void IpcpLayerUp(struct fsm *);
|
|
|
|
static void IpcpLayerDown(struct fsm *);
|
1998-01-31 02:48:30 +00:00
|
|
|
static void IpcpLayerStart(struct fsm *);
|
|
|
|
static void IpcpLayerFinish(struct fsm *);
|
1998-01-29 00:44:16 +00:00
|
|
|
static void IpcpInitRestartCounter(struct fsm *);
|
1998-01-31 02:48:30 +00:00
|
|
|
static void IpcpSendConfigReq(struct fsm *);
|
1998-03-20 19:47:10 +00:00
|
|
|
static void IpcpSentTerminateReq(struct fsm *);
|
|
|
|
static void IpcpSendTerminateAck(struct fsm *, u_char);
|
1998-03-13 21:08:05 +00:00
|
|
|
static void IpcpDecodeConfig(struct fsm *, u_char *, int, int,
|
|
|
|
struct fsm_decode *);
|
1998-02-06 02:24:29 +00:00
|
|
|
|
|
|
|
static struct fsm_callbacks ipcp_Callbacks = {
|
1998-02-27 01:22:39 +00:00
|
|
|
IpcpLayerUp,
|
|
|
|
IpcpLayerDown,
|
|
|
|
IpcpLayerStart,
|
|
|
|
IpcpLayerFinish,
|
1998-02-06 02:24:29 +00:00
|
|
|
IpcpInitRestartCounter,
|
|
|
|
IpcpSendConfigReq,
|
1998-03-20 19:47:10 +00:00
|
|
|
IpcpSentTerminateReq,
|
1998-02-06 02:24:29 +00:00
|
|
|
IpcpSendTerminateAck,
|
|
|
|
IpcpDecodeConfig,
|
1998-02-21 01:45:26 +00:00
|
|
|
NullRecvResetReq,
|
|
|
|
NullRecvResetAck
|
1998-02-06 02:24:29 +00:00
|
|
|
};
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
static const char *cftypes[] = {
|
|
|
|
/* Check out the latest ``Assigned numbers'' rfc (rfc1700.txt) */
|
|
|
|
"???",
|
|
|
|
"IPADDRS", /* 1: IP-Addresses */ /* deprecated */
|
|
|
|
"COMPPROTO", /* 2: IP-Compression-Protocol */
|
|
|
|
"IPADDR", /* 3: IP-Address */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NCFTYPES (sizeof cftypes/sizeof cftypes[0])
|
|
|
|
|
|
|
|
static const char *cftypes128[] = {
|
|
|
|
/* 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 cftypes128/sizeof cftypes128[0])
|
|
|
|
|
|
|
|
void
|
1998-03-13 21:07:46 +00:00
|
|
|
ipcp_AddInOctets(struct ipcp *ipcp, int n)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-03-13 21:07:46 +00:00
|
|
|
throughput_addin(&ipcp->throughput, n);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-03-13 21:07:46 +00:00
|
|
|
ipcp_AddOutOctets(struct ipcp *ipcp, int n)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-03-13 21:07:46 +00:00
|
|
|
throughput_addout(&ipcp->throughput, n);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ReportIpcpStatus(struct cmdargs const *arg)
|
|
|
|
{
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "%s [%s]\n", arg->bundle->ncp.ipcp.fsm.name,
|
1998-03-24 18:47:32 +00:00
|
|
|
State2Nam(arg->bundle->ncp.ipcp.fsm.state));
|
1998-03-13 21:07:46 +00:00
|
|
|
if (arg->bundle->ncp.ipcp.fsm.state == ST_OPENED) {
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, " His side: %s, %s\n",
|
1998-03-13 21:07:46 +00:00
|
|
|
inet_ntoa(arg->bundle->ncp.ipcp.peer_ip),
|
|
|
|
vj2asc(arg->bundle->ncp.ipcp.peer_compproto));
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, " My side: %s, %s\n",
|
1998-03-13 21:07:46 +00:00
|
|
|
inet_ntoa(arg->bundle->ncp.ipcp.my_ip),
|
|
|
|
vj2asc(arg->bundle->ncp.ipcp.my_compproto));
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "\nDefaults:\n");
|
|
|
|
prompt_Printf(arg->prompt, " My Address: %s/%d\n",
|
1998-03-13 21:07:46 +00:00
|
|
|
inet_ntoa(arg->bundle->ncp.ipcp.cfg.my_range.ipaddr),
|
|
|
|
arg->bundle->ncp.ipcp.cfg.my_range.width);
|
|
|
|
if (iplist_isvalid(&arg->bundle->ncp.ipcp.cfg.peer_list))
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, " His Address: %s\n",
|
1998-03-13 21:07:46 +00:00
|
|
|
arg->bundle->ncp.ipcp.cfg.peer_list.src);
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, " His Address: %s/%d\n",
|
1998-03-13 21:07:46 +00:00
|
|
|
inet_ntoa(arg->bundle->ncp.ipcp.cfg.peer_range.ipaddr),
|
|
|
|
arg->bundle->ncp.ipcp.cfg.peer_range.width);
|
|
|
|
if (arg->bundle->ncp.ipcp.cfg.HaveTriggerAddress)
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, " Negotiation(trigger): %s\n",
|
1998-03-13 21:07:46 +00:00
|
|
|
inet_ntoa(arg->bundle->ncp.ipcp.cfg.TriggerAddress));
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, " Negotiation(trigger): MYADDR\n");
|
|
|
|
prompt_Printf(arg->prompt, " Initial VJ slots: %d\n",
|
1998-03-13 21:07:46 +00:00
|
|
|
arg->bundle->ncp.ipcp.cfg.VJInitSlots);
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, " Initial VJ compression: %s\n",
|
1998-03-13 21:07:46 +00:00
|
|
|
arg->bundle->ncp.ipcp.cfg.VJInitComp ? "on" : "off");
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "\n");
|
|
|
|
throughput_disp(&arg->bundle->ncp.ipcp.throughput, arg->prompt);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1998-03-13 21:07:46 +00:00
|
|
|
SetInitVJ(struct cmdargs const *arg)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-03-13 21:07:46 +00:00
|
|
|
if (arg->argc != 2)
|
1998-01-29 00:44:16 +00:00
|
|
|
return -1;
|
1998-03-13 21:07:46 +00:00
|
|
|
if (!strcasecmp(arg->argv[0], "slots")) {
|
1998-01-29 00:44:16 +00:00
|
|
|
int slots;
|
|
|
|
|
1998-03-13 21:07:46 +00:00
|
|
|
slots = atoi(arg->argv[1]);
|
1998-01-29 00:44:16 +00:00
|
|
|
if (slots < 4 || slots > 16)
|
|
|
|
return 1;
|
1998-03-13 21:07:46 +00:00
|
|
|
arg->bundle->ncp.ipcp.cfg.VJInitSlots = slots;
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
1998-03-13 21:07:46 +00:00
|
|
|
} else if (!strcasecmp(arg->argv[0], "slotcomp")) {
|
|
|
|
if (!strcasecmp(arg->argv[1], "on"))
|
|
|
|
arg->bundle->ncp.ipcp.cfg.VJInitComp = 1;
|
|
|
|
else if (!strcasecmp(arg->argv[1], "off"))
|
|
|
|
arg->bundle->ncp.ipcp.cfg.VJInitComp = 0;
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
|
|
|
return 2;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-02-27 01:22:39 +00:00
|
|
|
ipcp_Init(struct ipcp *ipcp, struct bundle *bundle, struct link *l,
|
|
|
|
const struct fsm_parent *parent)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-02-21 01:45:26 +00:00
|
|
|
struct hostent *hp;
|
|
|
|
char name[MAXHOSTNAMELEN];
|
1998-04-03 19:21:56 +00:00
|
|
|
static const char *timer_names[] =
|
|
|
|
{"IPCP restart", "IPCP openmode", "IPCP stopped"};
|
1998-02-21 01:45:26 +00:00
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
fsm_Init(&ipcp->fsm, "IPCP", PROTO_IPCP, 1, IPCP_MAXCODE, 10, LogIPCP,
|
|
|
|
bundle, l, parent, &ipcp_Callbacks, timer_names);
|
1998-02-21 01:45:26 +00:00
|
|
|
|
|
|
|
ipcp->cfg.VJInitSlots = DEF_VJ_STATES;
|
|
|
|
ipcp->cfg.VJInitComp = 1;
|
|
|
|
memset(&ipcp->cfg.my_range, '\0', sizeof ipcp->cfg.my_range);
|
|
|
|
if (gethostname(name, sizeof name) == 0) {
|
|
|
|
hp = gethostbyname(name);
|
|
|
|
if (hp && hp->h_addrtype == AF_INET) {
|
|
|
|
memcpy(&ipcp->cfg.my_range.ipaddr.s_addr, hp->h_addr, hp->h_length);
|
|
|
|
ipcp->cfg.peer_range.mask.s_addr = INADDR_BROADCAST;
|
|
|
|
ipcp->cfg.peer_range.width = 32;
|
|
|
|
}
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
1998-03-13 21:08:05 +00:00
|
|
|
ipcp->cfg.netmask.s_addr = INADDR_ANY;
|
1998-02-21 01:45:26 +00:00
|
|
|
memset(&ipcp->cfg.peer_range, '\0', sizeof ipcp->cfg.peer_range);
|
|
|
|
iplist_setsrc(&ipcp->cfg.peer_list, "");
|
|
|
|
ipcp->cfg.HaveTriggerAddress = 0;
|
|
|
|
|
1998-04-03 19:24:07 +00:00
|
|
|
#ifndef NOMSEXT
|
1998-02-21 01:45:26 +00:00
|
|
|
ipcp->cfg.ns_entries[0].s_addr = INADDR_ANY;
|
|
|
|
ipcp->cfg.ns_entries[1].s_addr = INADDR_ANY;
|
|
|
|
ipcp->cfg.nbns_entries[0].s_addr = INADDR_ANY;
|
|
|
|
ipcp->cfg.nbns_entries[1].s_addr = INADDR_ANY;
|
1998-04-03 19:24:07 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
ipcp->cfg.fsmretry = DEF_FSMRETRY;
|
1998-02-21 01:45:26 +00:00
|
|
|
|
1998-03-16 22:54:35 +00:00
|
|
|
memset(&ipcp->vj, '\0', sizeof ipcp->vj);
|
|
|
|
|
1998-02-21 01:45:26 +00:00
|
|
|
ipcp->my_ifip.s_addr = INADDR_ANY;
|
|
|
|
ipcp->peer_ifip.s_addr = INADDR_ANY;
|
|
|
|
|
|
|
|
ipcp_Setup(ipcp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ipcp_Setup(struct ipcp *ipcp)
|
|
|
|
{
|
|
|
|
int pos;
|
|
|
|
|
|
|
|
ipcp->fsm.open_mode = 0;
|
1998-02-27 21:46:26 +00:00
|
|
|
ipcp->fsm.maxconfig = 10;
|
1998-02-21 01:45:26 +00:00
|
|
|
|
|
|
|
if (iplist_isvalid(&ipcp->cfg.peer_list)) {
|
|
|
|
if (ipcp->my_ifip.s_addr != INADDR_ANY &&
|
|
|
|
(pos = iplist_ip2pos(&ipcp->cfg.peer_list, ipcp->my_ifip)) != -1)
|
|
|
|
ipcp->cfg.peer_range.ipaddr = iplist_setcurpos(&ipcp->cfg.peer_list, pos);
|
|
|
|
else
|
|
|
|
ipcp->cfg.peer_range.ipaddr = iplist_setrandpos(&ipcp->cfg.peer_list);
|
|
|
|
ipcp->cfg.peer_range.mask.s_addr = INADDR_BROADCAST;
|
|
|
|
ipcp->cfg.peer_range.width = 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
ipcp->heis1172 = 0;
|
|
|
|
|
|
|
|
ipcp->peer_ip = ipcp->cfg.peer_range.ipaddr;
|
|
|
|
ipcp->peer_compproto = 0;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-02-21 01:45:26 +00:00
|
|
|
if (ipcp->cfg.HaveTriggerAddress) {
|
1998-04-03 19:25:07 +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").
|
|
|
|
*/
|
1998-02-21 01:45:26 +00:00
|
|
|
ipcp->my_ip = ipcp->cfg.TriggerAddress;
|
1998-01-29 23:11:44 +00:00
|
|
|
LogPrintf(LogIPCP, "Using trigger address %s\n",
|
1998-02-21 01:45:26 +00:00
|
|
|
inet_ntoa(ipcp->cfg.TriggerAddress));
|
1998-04-03 19:25:07 +00:00
|
|
|
} else if ((ipcp->my_ifip.s_addr & ipcp->cfg.my_range.mask.s_addr) ==
|
|
|
|
(ipcp->cfg.my_range.ipaddr.s_addr &
|
|
|
|
ipcp->cfg.my_range.mask.s_addr))
|
|
|
|
/*
|
|
|
|
* Otherwise, if we've been assigned an IP number before, we really
|
|
|
|
* want to keep the same IP number so that we can keep any existing
|
|
|
|
* connections that are bound to that IP.
|
|
|
|
*/
|
|
|
|
ipcp->my_ip = ipcp->my_ifip;
|
|
|
|
else
|
1998-02-21 01:45:26 +00:00
|
|
|
ipcp->my_ip = ipcp->cfg.my_range.ipaddr;
|
1998-01-29 23:11:44 +00:00
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
if (Enabled(ConfVjcomp))
|
1998-02-21 01:45:26 +00:00
|
|
|
ipcp->my_compproto = (PROTO_VJCOMP << 16) +
|
|
|
|
((ipcp->cfg.VJInitSlots - 1) << 8) +
|
|
|
|
ipcp->cfg.VJInitComp;
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
1998-02-21 01:45:26 +00:00
|
|
|
ipcp->my_compproto = 0;
|
1998-03-16 22:54:35 +00:00
|
|
|
sl_compress_init(&ipcp->vj.cslc, ipcp->cfg.VJInitSlots - 1);
|
1998-02-21 01:45:26 +00:00
|
|
|
|
|
|
|
ipcp->peer_reject = 0;
|
|
|
|
ipcp->my_reject = 0;
|
1998-01-29 23:11:44 +00:00
|
|
|
|
1998-02-21 01:45:26 +00:00
|
|
|
throughput_init(&ipcp->throughput);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
1998-02-07 20:50:08 +00:00
|
|
|
static int
|
1998-03-13 21:08:05 +00:00
|
|
|
ipcp_SetIPaddress(struct bundle *bundle, struct in_addr myaddr,
|
|
|
|
struct in_addr hisaddr, int silent)
|
1998-02-07 20:50:08 +00:00
|
|
|
{
|
|
|
|
struct sockaddr_in *sock_in;
|
|
|
|
int s;
|
|
|
|
u_long mask, addr;
|
|
|
|
struct ifaliasreq ifra;
|
|
|
|
|
|
|
|
/* If given addresses are alreay set, then ignore this request */
|
1998-03-13 21:08:05 +00:00
|
|
|
if (bundle->ncp.ipcp.my_ifip.s_addr == myaddr.s_addr &&
|
|
|
|
bundle->ncp.ipcp.peer_ifip.s_addr == hisaddr.s_addr)
|
1998-02-07 20:50:08 +00:00
|
|
|
return 0;
|
|
|
|
|
1998-03-13 21:08:05 +00:00
|
|
|
IpcpCleanInterface(&bundle->ncp.ipcp.fsm);
|
1998-02-08 19:29:45 +00:00
|
|
|
|
1998-02-07 20:50:08 +00:00
|
|
|
s = ID0socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
if (s < 0) {
|
|
|
|
LogPrintf(LogERROR, "SetIpDevice: socket(): %s\n", strerror(errno));
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&ifra, '\0', sizeof ifra);
|
|
|
|
strncpy(ifra.ifra_name, bundle->ifname, sizeof ifra.ifra_name - 1);
|
|
|
|
ifra.ifra_name[sizeof ifra.ifra_name - 1] = '\0';
|
|
|
|
|
|
|
|
/* Set interface address */
|
|
|
|
sock_in = (struct sockaddr_in *)&ifra.ifra_addr;
|
|
|
|
sock_in->sin_family = AF_INET;
|
|
|
|
sock_in->sin_addr = myaddr;
|
|
|
|
sock_in->sin_len = sizeof *sock_in;
|
|
|
|
|
|
|
|
/* Set destination address */
|
|
|
|
sock_in = (struct sockaddr_in *)&ifra.ifra_broadaddr;
|
|
|
|
sock_in->sin_family = AF_INET;
|
|
|
|
sock_in->sin_addr = hisaddr;
|
|
|
|
sock_in->sin_len = sizeof *sock_in;
|
|
|
|
|
|
|
|
addr = ntohl(myaddr.s_addr);
|
|
|
|
if (IN_CLASSA(addr))
|
|
|
|
mask = IN_CLASSA_NET;
|
|
|
|
else if (IN_CLASSB(addr))
|
|
|
|
mask = IN_CLASSB_NET;
|
|
|
|
else
|
|
|
|
mask = IN_CLASSC_NET;
|
|
|
|
|
|
|
|
/* if subnet mask is given, use it instead of class mask */
|
1998-03-13 21:08:05 +00:00
|
|
|
if (bundle->ncp.ipcp.cfg.netmask.s_addr != INADDR_ANY &&
|
|
|
|
(ntohl(bundle->ncp.ipcp.cfg.netmask.s_addr) & mask) == mask)
|
|
|
|
mask = ntohl(bundle->ncp.ipcp.cfg.netmask.s_addr);
|
1998-02-07 20:50:08 +00:00
|
|
|
|
|
|
|
sock_in = (struct sockaddr_in *)&ifra.ifra_mask;
|
|
|
|
sock_in->sin_family = AF_INET;
|
|
|
|
sock_in->sin_addr.s_addr = htonl(mask);
|
|
|
|
sock_in->sin_len = sizeof *sock_in;
|
|
|
|
|
|
|
|
if (ID0ioctl(s, SIOCAIFADDR, &ifra) < 0) {
|
|
|
|
if (!silent)
|
|
|
|
LogPrintf(LogERROR, "SetIpDevice: ioctl(SIOCAIFADDR): %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
close(s);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
1998-03-13 21:08:05 +00:00
|
|
|
bundle->ncp.ipcp.peer_ifip.s_addr = hisaddr.s_addr;
|
|
|
|
bundle->ncp.ipcp.my_ifip.s_addr = myaddr.s_addr;
|
1998-02-07 20:50:08 +00:00
|
|
|
|
|
|
|
if (Enabled(ConfProxy))
|
1998-03-13 21:08:05 +00:00
|
|
|
sifproxyarp(bundle, bundle->ncp.ipcp.peer_ifip, s);
|
1998-02-07 20:50:08 +00:00
|
|
|
|
|
|
|
close(s);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct in_addr
|
1998-03-13 21:08:05 +00:00
|
|
|
ChooseHisAddr(struct bundle *bundle, const struct in_addr gw)
|
1998-02-07 20:50:08 +00:00
|
|
|
{
|
|
|
|
struct in_addr try;
|
|
|
|
int f;
|
|
|
|
|
1998-03-13 21:07:46 +00:00
|
|
|
for (f = 0; f < bundle->ncp.ipcp.cfg.peer_list.nItems; f++) {
|
|
|
|
try = iplist_next(&bundle->ncp.ipcp.cfg.peer_list);
|
1998-02-07 20:50:08 +00:00
|
|
|
LogPrintf(LogDEBUG, "ChooseHisAddr: Check item %d (%s)\n",
|
|
|
|
f, inet_ntoa(try));
|
1998-03-13 21:08:05 +00:00
|
|
|
if (ipcp_SetIPaddress(bundle, gw, try, 1) == 0) {
|
1998-02-07 20:50:08 +00:00
|
|
|
LogPrintf(LogIPCP, "ChooseHisAddr: Selected IP address %s\n",
|
|
|
|
inet_ntoa(try));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-03-13 21:07:46 +00:00
|
|
|
if (f == bundle->ncp.ipcp.cfg.peer_list.nItems) {
|
1998-02-07 20:50:08 +00:00
|
|
|
LogPrintf(LogDEBUG, "ChooseHisAddr: All addresses in use !\n");
|
|
|
|
try.s_addr = INADDR_ANY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return try;
|
|
|
|
}
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
static void
|
|
|
|
IpcpInitRestartCounter(struct fsm * fp)
|
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Set fsm timer load */
|
1998-04-03 19:24:07 +00:00
|
|
|
struct ipcp *ipcp = fsm2ipcp(fp);
|
|
|
|
|
|
|
|
fp->FsmTimer.load = ipcp->cfg.fsmretry * SECTICKS;
|
1998-01-29 00:44:16 +00:00
|
|
|
fp->restart = 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-01-30 19:46:07 +00:00
|
|
|
IpcpSendConfigReq(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 ipcp *ipcp = fsm2ipcp(fp);
|
1998-03-20 19:47:10 +00:00
|
|
|
u_char buff[12];
|
|
|
|
struct lcp_opt *o;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-03-20 19:47:10 +00:00
|
|
|
o = (struct lcp_opt *)buff;
|
1998-03-13 21:08:05 +00:00
|
|
|
|
1998-02-06 02:24:29 +00:00
|
|
|
if ((p && !Physical_IsSync(p)) || !REJECTED(ipcp, TY_IPADDR)) {
|
1998-03-20 19:47:10 +00:00
|
|
|
*(u_int32_t *)o->data = ipcp->my_ip.s_addr;
|
|
|
|
INC_LCP_OPT(TY_IPADDR, 6, o);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
1998-03-20 19:47:10 +00:00
|
|
|
if (ipcp->my_compproto && !REJECTED(ipcp, TY_COMPPROTO))
|
1998-02-06 02:24:29 +00:00
|
|
|
if (ipcp->heis1172) {
|
1998-03-20 19:47:10 +00:00
|
|
|
*(u_short *)o->data = htons(PROTO_VJCOMP);
|
|
|
|
INC_LCP_OPT(TY_COMPPROTO, 4, o);
|
1998-01-29 00:44:16 +00:00
|
|
|
} else {
|
1998-03-20 19:47:10 +00:00
|
|
|
*(u_long *)o->data = htonl(ipcp->my_compproto);
|
|
|
|
INC_LCP_OPT(TY_COMPPROTO, 6, o);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-03-20 19:47:10 +00:00
|
|
|
IpcpSentTerminateReq(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
|
|
|
IpcpSendTerminateAck(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
|
|
|
|
IpcpLayerStart(struct fsm * fp)
|
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* We're about to start up ! */
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogIPCP, "IpcpLayerStart.\n");
|
1998-02-07 20:50:08 +00:00
|
|
|
|
|
|
|
/* This is where we should be setting up the interface in AUTO mode */
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-02-07 20:50:08 +00:00
|
|
|
IpcpLayerFinish(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(LogIPCP, "IpcpLayerFinish.\n");
|
|
|
|
}
|
|
|
|
|
1998-02-08 19:29:45 +00:00
|
|
|
void
|
|
|
|
IpcpCleanInterface(struct fsm *fp)
|
|
|
|
{
|
|
|
|
struct ipcp *ipcp = fsm2ipcp(fp);
|
|
|
|
struct ifaliasreq ifra;
|
|
|
|
struct sockaddr_in *me, *peer;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = ID0socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
if (s < 0) {
|
|
|
|
LogPrintf(LogERROR, "IpcpCleanInterface: socket: %s\n", strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Enabled(ConfProxy))
|
1998-02-21 01:45:26 +00:00
|
|
|
cifproxyarp(fp->bundle, ipcp->peer_ifip, s);
|
1998-02-08 19:29:45 +00:00
|
|
|
|
1998-02-21 01:45:26 +00:00
|
|
|
if (ipcp->my_ifip.s_addr != INADDR_ANY ||
|
|
|
|
ipcp->peer_ifip.s_addr != INADDR_ANY) {
|
1998-02-08 19:29:45 +00:00
|
|
|
memset(&ifra, '\0', sizeof ifra);
|
|
|
|
strncpy(ifra.ifra_name, fp->bundle->ifname, sizeof ifra.ifra_name - 1);
|
|
|
|
ifra.ifra_name[sizeof ifra.ifra_name - 1] = '\0';
|
|
|
|
me = (struct sockaddr_in *)&ifra.ifra_addr;
|
|
|
|
peer = (struct sockaddr_in *)&ifra.ifra_broadaddr;
|
|
|
|
me->sin_family = peer->sin_family = AF_INET;
|
|
|
|
me->sin_len = peer->sin_len = sizeof(struct sockaddr_in);
|
1998-02-21 01:45:26 +00:00
|
|
|
me->sin_addr = ipcp->my_ifip;
|
|
|
|
peer->sin_addr = ipcp->peer_ifip;
|
1998-02-08 19:29:45 +00:00
|
|
|
if (ID0ioctl(s, SIOCDIFADDR, &ifra) < 0) {
|
|
|
|
LogPrintf(LogERROR, "IpcpCleanInterface: ioctl(SIOCDIFADDR): %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
close(s);
|
|
|
|
}
|
1998-02-21 01:45:26 +00:00
|
|
|
ipcp->my_ifip.s_addr = ipcp->peer_ifip.s_addr = INADDR_ANY;
|
1998-02-08 19:29:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
close(s);
|
|
|
|
}
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
static void
|
1998-02-06 02:24:29 +00:00
|
|
|
IpcpLayerDown(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-08 11:05:01 +00:00
|
|
|
struct ipcp *ipcp = fsm2ipcp(fp);
|
1998-02-07 20:50:08 +00:00
|
|
|
const char *s;
|
|
|
|
|
1998-02-21 01:45:26 +00:00
|
|
|
s = inet_ntoa(ipcp->peer_ifip);
|
1998-02-07 20:50:08 +00:00
|
|
|
LogPrintf(LogIsKept(LogLINK) ? LogLINK : LogIPCP, "IpcpLayerDown: %s\n", s);
|
|
|
|
|
1998-02-06 02:24:29 +00:00
|
|
|
throughput_stop(&ipcp->throughput);
|
|
|
|
throughput_log(&ipcp->throughput, LogIPCP, NULL);
|
1998-02-07 20:50:08 +00:00
|
|
|
/*
|
|
|
|
* XXX this stuff should really live in the FSM. Our config should
|
|
|
|
* associate executable sections in files with events.
|
|
|
|
*/
|
1998-04-03 19:26:02 +00:00
|
|
|
if (SelectSystem(fp->bundle, s, LINKDOWNFILE, NULL) < 0)
|
1998-02-07 20:50:08 +00:00
|
|
|
if (GetLabel()) {
|
1998-04-03 19:26:02 +00:00
|
|
|
if (SelectSystem(fp->bundle, GetLabel(), LINKDOWNFILE, NULL) < 0)
|
|
|
|
SelectSystem(fp->bundle, "MYADDR", LINKDOWNFILE, NULL);
|
1998-02-07 20:50:08 +00:00
|
|
|
} else
|
1998-04-03 19:26:02 +00:00
|
|
|
SelectSystem(fp->bundle, "MYADDR", LINKDOWNFILE, NULL);
|
1998-02-07 20:50:08 +00:00
|
|
|
|
1998-02-08 19:29:45 +00:00
|
|
|
if (!(mode & MODE_AUTO))
|
|
|
|
IpcpCleanInterface(fp);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-02-02 19:32:16 +00:00
|
|
|
IpcpLayerUp(struct fsm *fp)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* We're now up */
|
1998-02-08 11:05:01 +00:00
|
|
|
struct ipcp *ipcp = fsm2ipcp(fp);
|
1998-01-29 00:44:16 +00:00
|
|
|
char tbuff[100];
|
|
|
|
|
1998-03-20 19:47:10 +00:00
|
|
|
LogPrintf(LogIPCP, "IpcpLayerUp.\n");
|
1998-02-21 01:45:26 +00:00
|
|
|
snprintf(tbuff, sizeof tbuff, "myaddr = %s ", inet_ntoa(ipcp->my_ip));
|
1998-02-07 20:50:08 +00:00
|
|
|
LogPrintf(LogIsKept(LogIPCP) ? LogIPCP : LogLINK, " %s hisaddr = %s\n",
|
1998-02-21 01:45:26 +00:00
|
|
|
tbuff, inet_ntoa(ipcp->peer_ip));
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-02-21 01:45:26 +00:00
|
|
|
if (ipcp->peer_compproto >> 16 == PROTO_VJCOMP)
|
1998-03-16 22:54:35 +00:00
|
|
|
sl_compress_init(&ipcp->vj.cslc, (ipcp->peer_compproto >> 8) & 255);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-03-13 21:08:05 +00:00
|
|
|
if (ipcp_SetIPaddress(fp->bundle, ipcp->my_ip,
|
|
|
|
ipcp->peer_ip, 0) < 0) {
|
1998-02-10 03:23:50 +00:00
|
|
|
LogPrintf(LogERROR, "IpcpLayerUp: unable to set ip address\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
return;
|
|
|
|
}
|
1998-02-07 20:50:08 +00:00
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
#ifndef NOALIAS
|
|
|
|
if (mode & MODE_ALIAS)
|
1998-02-21 01:45:26 +00:00
|
|
|
VarPacketAliasSetAddress(ipcp->my_ip);
|
1998-01-29 00:44:16 +00:00
|
|
|
#endif
|
1998-02-07 20:50:08 +00:00
|
|
|
|
|
|
|
LogPrintf(LogIsKept(LogLINK) ? LogLINK : LogIPCP, "IpcpLayerUp: %s\n",
|
1998-02-21 01:45:26 +00:00
|
|
|
inet_ntoa(ipcp->peer_ifip));
|
1998-02-07 20:50:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX this stuff should really live in the FSM. Our config should
|
|
|
|
* associate executable sections in files with events.
|
|
|
|
*/
|
1998-04-03 19:26:02 +00:00
|
|
|
if (SelectSystem(fp->bundle, inet_ntoa(ipcp->my_ifip), LINKUPFILE, NULL) < 0)
|
1998-02-07 20:50:08 +00:00
|
|
|
if (GetLabel()) {
|
1998-04-03 19:26:02 +00:00
|
|
|
if (SelectSystem(fp->bundle, GetLabel(), LINKUPFILE, NULL) < 0)
|
|
|
|
SelectSystem(fp->bundle, "MYADDR", LINKUPFILE, NULL);
|
1998-02-07 20:50:08 +00:00
|
|
|
} else
|
1998-04-03 19:26:02 +00:00
|
|
|
SelectSystem(fp->bundle, "MYADDR", LINKUPFILE, NULL);
|
1998-02-07 20:50:08 +00:00
|
|
|
|
1998-04-03 19:21:56 +00:00
|
|
|
throughput_start(&ipcp->throughput, "IPCP throughput");
|
1998-04-03 19:26:02 +00:00
|
|
|
bundle_DisplayPrompt(fp->bundle);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1998-01-31 02:48:30 +00:00
|
|
|
AcceptableAddr(struct in_range *prange, struct in_addr ipaddr)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Is the given IP in the given range ? */
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogDEBUG, "requested = %x\n", htonl(ipaddr.s_addr));
|
|
|
|
LogPrintf(LogDEBUG, "range = %x\n", 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));
|
|
|
|
return (prange->ipaddr.s_addr & prange->mask.s_addr) ==
|
|
|
|
(ipaddr.s_addr & prange->mask.s_addr) && ipaddr.s_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-03-13 21:08:05 +00:00
|
|
|
IpcpDecodeConfig(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_IPCP */
|
1998-02-08 11:05:01 +00:00
|
|
|
struct ipcp *ipcp = fsm2ipcp(fp);
|
1998-01-29 00:44:16 +00:00
|
|
|
int type, length;
|
|
|
|
u_long *lp, compproto;
|
|
|
|
struct compreq *pcomp;
|
|
|
|
struct in_addr ipaddr, dstipaddr, dnsstuff, ms_info_req;
|
1998-03-13 21:08:05 +00:00
|
|
|
char tbuff[100], tbuff2[100];
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
while (plen >= sizeof(struct fsmconfig)) {
|
|
|
|
type = *cp;
|
|
|
|
length = cp[1];
|
|
|
|
if (type < NCFTYPES)
|
|
|
|
snprintf(tbuff, sizeof tbuff, " %s[%d] ", cftypes[type], length);
|
|
|
|
else if (type > 128 && type < 128 + NCFTYPES128)
|
|
|
|
snprintf(tbuff, sizeof tbuff, " %s[%d] ", cftypes128[type-128], length);
|
|
|
|
else
|
|
|
|
snprintf(tbuff, sizeof tbuff, " <%d>[%d] ", type, length);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case TY_IPADDR: /* RFC1332 */
|
|
|
|
lp = (u_long *) (cp + 2);
|
|
|
|
ipaddr.s_addr = *lp;
|
|
|
|
LogPrintf(LogIPCP, "%s %s\n", tbuff, inet_ntoa(ipaddr));
|
|
|
|
|
|
|
|
switch (mode_type) {
|
|
|
|
case MODE_REQ:
|
1998-02-21 01:45:26 +00:00
|
|
|
if (iplist_isvalid(&ipcp->cfg.peer_list)) {
|
1998-01-29 00:44:16 +00:00
|
|
|
if (ipaddr.s_addr == INADDR_ANY ||
|
1998-02-21 01:45:26 +00:00
|
|
|
iplist_ip2pos(&ipcp->cfg.peer_list, ipaddr) < 0 ||
|
1998-03-13 21:08:05 +00:00
|
|
|
ipcp_SetIPaddress(fp->bundle, ipcp->cfg.my_range.ipaddr,
|
|
|
|
ipaddr, 1)) {
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogIPCP, "%s: Address invalid or already in use\n",
|
|
|
|
inet_ntoa(ipaddr));
|
1998-04-03 19:25:07 +00:00
|
|
|
if (iplist_ip2pos(&ipcp->cfg.peer_list, ipcp->peer_ifip) >= 0)
|
|
|
|
/*
|
|
|
|
* If we've already got a valid address configured for the peer
|
|
|
|
* (in AUTO mode), try NAKing with that so that we don't
|
|
|
|
* have to upset things too much.
|
|
|
|
*/
|
|
|
|
ipcp->peer_ip = ipcp->peer_ifip;
|
|
|
|
else
|
|
|
|
/* Just pick an IP number from our list */
|
|
|
|
ipcp->peer_ip = ChooseHisAddr
|
|
|
|
(fp->bundle, ipcp->cfg.my_range.ipaddr);
|
|
|
|
|
1998-02-21 01:45:26 +00:00
|
|
|
if (ipcp->peer_ip.s_addr == INADDR_ANY) {
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->rejend, cp, length);
|
|
|
|
dec->rejend += length;
|
1998-01-29 00:44:16 +00:00
|
|
|
} else {
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend, cp, 2);
|
|
|
|
memcpy(dec->nakend+2, &ipcp->peer_ip.s_addr, length - 2);
|
|
|
|
dec->nakend += length;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1998-02-21 01:45:26 +00:00
|
|
|
} else if (!AcceptableAddr(&ipcp->cfg.peer_range, ipaddr)) {
|
1998-01-29 00:44:16 +00:00
|
|
|
/*
|
1998-04-03 19:25:07 +00:00
|
|
|
* If destination address is not acceptable, NAK with what we
|
1998-01-29 00:44:16 +00:00
|
|
|
* want to use.
|
|
|
|
*/
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend, cp, 2);
|
1998-04-03 19:25:07 +00:00
|
|
|
if ((ipcp->peer_ifip.s_addr & ipcp->cfg.peer_range.mask.s_addr) ==
|
|
|
|
(ipcp->cfg.peer_range.ipaddr.s_addr &
|
|
|
|
ipcp->cfg.peer_range.mask.s_addr))
|
|
|
|
/* We prefer the already-configured address */
|
|
|
|
memcpy(dec->nakend+2, &ipcp->peer_ifip.s_addr, length - 2);
|
|
|
|
else
|
|
|
|
memcpy(dec->nakend+2, &ipcp->peer_ip.s_addr, length - 2);
|
1998-03-13 21:08:05 +00:00
|
|
|
dec->nakend += length;
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
1998-02-21 01:45:26 +00:00
|
|
|
ipcp->peer_ip = ipaddr;
|
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:
|
1998-02-21 01:45:26 +00:00
|
|
|
if (AcceptableAddr(&ipcp->cfg.my_range, ipaddr)) {
|
1998-01-29 00:44:16 +00:00
|
|
|
/* Use address suggested by peer */
|
|
|
|
snprintf(tbuff2, sizeof tbuff2, "%s changing address: %s ", tbuff,
|
1998-02-21 01:45:26 +00:00
|
|
|
inet_ntoa(ipcp->my_ip));
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogIPCP, "%s --> %s\n", tbuff2, inet_ntoa(ipaddr));
|
1998-02-21 01:45:26 +00:00
|
|
|
ipcp->my_ip = ipaddr;
|
1998-01-29 00:44:16 +00:00
|
|
|
} else {
|
1998-04-03 19:25:07 +00:00
|
|
|
LogPrintf(LogIsKept(LogIPCP) ? LogIPCP : LogPHASE,
|
|
|
|
"%s: Unacceptable address!\n", inet_ntoa(ipaddr));
|
1998-02-06 02:24:29 +00:00
|
|
|
FsmClose(&ipcp->fsm);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
1998-02-21 01:45:26 +00:00
|
|
|
ipcp->peer_reject |= (1 << type);
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TY_COMPPROTO:
|
|
|
|
lp = (u_long *) (cp + 2);
|
|
|
|
compproto = htonl(*lp);
|
|
|
|
LogPrintf(LogIPCP, "%s %s\n", tbuff, vj2asc(compproto));
|
|
|
|
|
|
|
|
switch (mode_type) {
|
|
|
|
case MODE_REQ:
|
|
|
|
if (!Acceptable(ConfVjcomp)) {
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->rejend, cp, length);
|
|
|
|
dec->rejend += length;
|
1998-01-29 00:44:16 +00:00
|
|
|
} else {
|
|
|
|
pcomp = (struct compreq *) (cp + 2);
|
|
|
|
switch (length) {
|
|
|
|
case 4: /* RFC1172 */
|
|
|
|
if (ntohs(pcomp->proto) == PROTO_VJCOMP) {
|
|
|
|
LogPrintf(LogWARN, "Peer is speaking RFC1172 compression protocol !\n");
|
1998-02-06 02:24:29 +00:00
|
|
|
ipcp->heis1172 = 1;
|
1998-02-21 01:45:26 +00:00
|
|
|
ipcp->peer_compproto = compproto;
|
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 {
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend, cp, 2);
|
1998-01-29 00:44:16 +00:00
|
|
|
pcomp->proto = htons(PROTO_VJCOMP);
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend+2, &pcomp, 2);
|
|
|
|
dec->nakend += length;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6: /* RFC1332 */
|
|
|
|
if (ntohs(pcomp->proto) == PROTO_VJCOMP
|
1998-02-21 01:45:26 +00:00
|
|
|
&& pcomp->slots <= MAX_VJ_STATES
|
|
|
|
&& pcomp->slots >= MIN_VJ_STATES) {
|
|
|
|
ipcp->peer_compproto = compproto;
|
1998-02-06 02:24:29 +00:00
|
|
|
ipcp->heis1172 = 0;
|
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 {
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend, cp, 2);
|
1998-01-29 00:44:16 +00:00
|
|
|
pcomp->proto = htons(PROTO_VJCOMP);
|
1998-02-21 01:45:26 +00:00
|
|
|
pcomp->slots = DEF_VJ_STATES;
|
1998-01-29 00:44:16 +00:00
|
|
|
pcomp->compcid = 0;
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend+2, &pcomp, sizeof pcomp);
|
|
|
|
dec->nakend += length;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->rejend, cp, length);
|
|
|
|
dec->rejend += length;
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
|
|
|
LogPrintf(LogIPCP, "%s changing compproto: %08x --> %08x\n",
|
1998-02-21 01:45:26 +00:00
|
|
|
tbuff, ipcp->my_compproto, compproto);
|
|
|
|
ipcp->my_compproto = compproto;
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
1998-02-21 01:45:26 +00:00
|
|
|
ipcp->peer_reject |= (1 << type);
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TY_IPADDRS: /* RFC1172 */
|
|
|
|
lp = (u_long *) (cp + 2);
|
|
|
|
ipaddr.s_addr = *lp;
|
|
|
|
lp = (u_long *) (cp + 6);
|
|
|
|
dstipaddr.s_addr = *lp;
|
|
|
|
snprintf(tbuff2, sizeof tbuff2, "%s %s,", tbuff, inet_ntoa(ipaddr));
|
|
|
|
LogPrintf(LogIPCP, "%s %s\n", tbuff2, inet_ntoa(dstipaddr));
|
|
|
|
|
|
|
|
switch (mode_type) {
|
|
|
|
case MODE_REQ:
|
1998-02-21 01:45:26 +00:00
|
|
|
ipcp->peer_ip = ipaddr;
|
|
|
|
ipcp->my_ip = dstipaddr;
|
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:
|
|
|
|
snprintf(tbuff2, sizeof tbuff2, "%s changing address: %s", tbuff,
|
1998-02-21 01:45:26 +00:00
|
|
|
inet_ntoa(ipcp->my_ip));
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogIPCP, "%s --> %s\n", tbuff2, inet_ntoa(ipaddr));
|
1998-02-21 01:45:26 +00:00
|
|
|
ipcp->my_ip = ipaddr;
|
|
|
|
ipcp->peer_ip = dstipaddr;
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
1998-02-21 01:45:26 +00:00
|
|
|
ipcp->peer_reject |= (1 << type);
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MS extensions for MS's PPP
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NOMSEXT
|
|
|
|
case TY_PRIMARY_DNS: /* MS PPP DNS negotiation hack */
|
|
|
|
case TY_SECONDARY_DNS:
|
|
|
|
switch (mode_type) {
|
|
|
|
case MODE_REQ:
|
1998-03-13 21:08:05 +00:00
|
|
|
if (!Enabled(ConfMSExt)) {
|
|
|
|
LogPrintf(LogIPCP, "MS NS req - rejected - msext disabled\n");
|
|
|
|
ipcp->my_reject |= (1 << type);
|
|
|
|
memcpy(dec->rejend, cp, length);
|
|
|
|
dec->rejend += length;
|
|
|
|
break;
|
|
|
|
}
|
1998-01-29 00:44:16 +00:00
|
|
|
lp = (u_long *) (cp + 2);
|
|
|
|
dnsstuff.s_addr = *lp;
|
1998-02-21 01:45:26 +00:00
|
|
|
ms_info_req.s_addr = ipcp->cfg.ns_entries
|
1998-01-29 23:11:44 +00:00
|
|
|
[(type - TY_PRIMARY_DNS) ? 1 : 0].s_addr;
|
1998-01-29 00:44:16 +00:00
|
|
|
if (dnsstuff.s_addr != ms_info_req.s_addr) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* So the client has got the DNS stuff wrong (first request) so
|
|
|
|
* we'll tell 'em how it is
|
|
|
|
*/
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend, cp, 2); /* copy first two (type/length) */
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogIPCP, "MS NS req %d:%s->%s - nak\n",
|
1998-03-20 19:47:10 +00:00
|
|
|
type, inet_ntoa(dnsstuff), inet_ntoa(ms_info_req));
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend+2, &ms_info_req, length);
|
|
|
|
dec->nakend += length;
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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",
|
1998-03-20 19:47:10 +00:00
|
|
|
type, inet_ntoa(ms_info_req));
|
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: /* what does this mean?? */
|
|
|
|
LogPrintf(LogIPCP, "MS NS req %d - NAK??\n", type);
|
|
|
|
break;
|
|
|
|
case MODE_REJ: /* confused?? me to :) */
|
|
|
|
LogPrintf(LogIPCP, "MS NS req %d - REJ??\n", type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TY_PRIMARY_NBNS: /* MS PPP NetBIOS nameserver hack */
|
|
|
|
case TY_SECONDARY_NBNS:
|
|
|
|
switch (mode_type) {
|
|
|
|
case MODE_REQ:
|
1998-03-13 21:08:05 +00:00
|
|
|
if (!Enabled(ConfMSExt)) {
|
|
|
|
LogPrintf(LogIPCP, "MS NBNS req - rejected - msext disabled\n");
|
|
|
|
ipcp->my_reject |= (1 << type);
|
|
|
|
memcpy(dec->rejend, cp, length);
|
|
|
|
dec->rejend += length;
|
|
|
|
break;
|
|
|
|
}
|
1998-01-29 00:44:16 +00:00
|
|
|
lp = (u_long *) (cp + 2);
|
|
|
|
dnsstuff.s_addr = *lp;
|
1998-02-21 01:45:26 +00:00
|
|
|
ms_info_req.s_addr = ipcp->cfg.nbns_entries
|
1998-01-29 23:11:44 +00:00
|
|
|
[(type - TY_PRIMARY_NBNS) ? 1 : 0].s_addr;
|
1998-01-29 00:44:16 +00:00
|
|
|
if (dnsstuff.s_addr != ms_info_req.s_addr) {
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend, cp, 2);
|
|
|
|
memcpy(dec->nakend+2, &ms_info_req.s_addr, length);
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogIPCP, "MS NBNS req %d:%s->%s - nak\n",
|
1998-03-20 19:47:10 +00:00
|
|
|
type, inet_ntoa(dnsstuff), inet_ntoa(ms_info_req));
|
1998-03-13 21:08:05 +00:00
|
|
|
dec->nakend += length;
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
LogPrintf(LogIPCP, "MS NBNS req %d:%s ok - ack\n",
|
1998-03-20 19:47:10 +00:00
|
|
|
type, inet_ntoa(ms_info_req));
|
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:
|
|
|
|
LogPrintf(LogIPCP, "MS NBNS req %d - NAK??\n", type);
|
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
|
|
|
LogPrintf(LogIPCP, "MS NBNS req %d - REJ??\n", type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
default:
|
1998-03-13 21:08:05 +00:00
|
|
|
if (mode_type != MODE_NOP) {
|
|
|
|
ipcp->my_reject |= (1 << type);
|
|
|
|
memcpy(dec->rejend, cp, length);
|
|
|
|
dec->rejend += length;
|
|
|
|
}
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
plen -= length;
|
|
|
|
cp += length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-03-13 21:07:46 +00:00
|
|
|
IpcpInput(struct ipcp *ipcp, struct mbuf * bp)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Got PROTO_IPCP from link */
|
1998-03-13 21:07:46 +00:00
|
|
|
FsmInput(&ipcp->fsm, bp);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1998-02-02 19:32:16 +00:00
|
|
|
UseHisaddr(struct bundle *bundle, const char *hisaddr, int setaddr)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-03-13 21:07:46 +00:00
|
|
|
struct ipcp *ipcp = &bundle->ncp.ipcp;
|
|
|
|
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Use `hisaddr' for the peers address (set iface if `setaddr') */
|
1998-03-13 21:07:46 +00:00
|
|
|
memset(&ipcp->cfg.peer_range, '\0', sizeof ipcp->cfg.peer_range);
|
|
|
|
iplist_reset(&ipcp->cfg.peer_list);
|
1998-01-29 00:44:16 +00:00
|
|
|
if (strpbrk(hisaddr, ",-")) {
|
1998-03-13 21:07:46 +00:00
|
|
|
iplist_setsrc(&ipcp->cfg.peer_list, hisaddr);
|
|
|
|
if (iplist_isvalid(&ipcp->cfg.peer_list)) {
|
|
|
|
iplist_setrandpos(&ipcp->cfg.peer_list);
|
1998-03-13 21:08:05 +00:00
|
|
|
ipcp->peer_ip = ChooseHisAddr(bundle, ipcp->my_ip);
|
1998-03-13 21:07:46 +00:00
|
|
|
if (ipcp->peer_ip.s_addr == INADDR_ANY) {
|
|
|
|
LogPrintf(LogWARN, "%s: None available !\n",
|
|
|
|
ipcp->cfg.peer_list.src);
|
1998-01-29 00:44:16 +00:00
|
|
|
return(0);
|
|
|
|
}
|
1998-03-13 21:07:46 +00:00
|
|
|
ipcp->cfg.peer_range.ipaddr.s_addr = ipcp->peer_ip.s_addr;
|
|
|
|
ipcp->cfg.peer_range.mask.s_addr = INADDR_BROADCAST;
|
|
|
|
ipcp->cfg.peer_range.width = 32;
|
1998-01-29 00:44:16 +00:00
|
|
|
} else {
|
|
|
|
LogPrintf(LogWARN, "%s: Invalid range !\n", hisaddr);
|
|
|
|
return 0;
|
|
|
|
}
|
1998-03-13 21:07:46 +00:00
|
|
|
} else if (ParseAddr(ipcp, 1, &hisaddr, &ipcp->cfg.peer_range.ipaddr,
|
|
|
|
&ipcp->cfg.peer_range.mask,
|
|
|
|
&ipcp->cfg.peer_range.width) != 0) {
|
|
|
|
ipcp->peer_ip.s_addr = ipcp->cfg.peer_range.ipaddr.s_addr;
|
|
|
|
|
1998-03-13 21:08:05 +00:00
|
|
|
if (setaddr && ipcp_SetIPaddress(bundle, ipcp->cfg.my_range.ipaddr,
|
|
|
|
ipcp->cfg.peer_range.ipaddr, 0) < 0) {
|
1998-03-13 21:07:46 +00:00
|
|
|
ipcp->cfg.my_range.ipaddr.s_addr = INADDR_ANY;
|
|
|
|
ipcp->cfg.peer_range.ipaddr.s_addr = INADDR_ANY;
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|