2001-06-13 21:52:19 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
|
|
|
|
* based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
|
|
|
|
* Internet Initiative Japan, Inc (IIJ)
|
|
|
|
* All rights reserved.
|
1995-01-31 06:29:58 +00:00
|
|
|
*
|
2001-06-13 21:52:19 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
1995-01-31 06:29:58 +00:00
|
|
|
*
|
2001-06-13 21:52:19 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
1995-01-31 06:29:58 +00:00
|
|
|
*
|
1999-08-28 01:35:59 +00:00
|
|
|
* $FreeBSD$
|
1995-01-31 06:29:58 +00:00
|
|
|
*/
|
2001-06-13 21:52:19 +00:00
|
|
|
|
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>
|
2001-05-11 23:42:03 +00:00
|
|
|
#include <net/if.h>
|
1998-10-26 19:07:39 +00:00
|
|
|
#include <net/route.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <netdb.h>
|
1998-05-21 21:49:08 +00:00
|
|
|
#include <sys/un.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
|
1999-04-26 08:54:25 +00:00
|
|
|
#include <errno.h>
|
1998-05-21 21:49:08 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <resolv.h>
|
1998-01-18 20:49:22 +00:00
|
|
|
#include <stdlib.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <string.h>
|
2000-03-14 01:47:27 +00:00
|
|
|
#include <sys/stat.h>
|
1998-05-21 21:49:08 +00:00
|
|
|
#include <termios.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
1999-08-19 18:15:52 +00:00
|
|
|
#ifndef NONAT
|
2000-03-14 01:47:02 +00:00
|
|
|
#ifdef LOCALNAT
|
1999-04-26 08:54:34 +00:00
|
|
|
#include "alias.h"
|
2000-03-14 01:47:02 +00:00
|
|
|
#else
|
|
|
|
#include <alias.h>
|
1998-09-17 00:45:27 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2000-03-14 01:47:02 +00:00
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
#include "layer.h"
|
1998-09-04 18:26:00 +00:00
|
|
|
#include "ua.h"
|
1998-06-15 19:06:25 +00:00
|
|
|
#include "defs.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 "timer.h"
|
1997-09-03 02:08:20 +00:00
|
|
|
#include "fsm.h"
|
1999-05-08 11:07:56 +00:00
|
|
|
#include "proto.h"
|
1997-12-13 02:37:33 +00:00
|
|
|
#include "iplist.h"
|
1998-05-21 21:49:08 +00:00
|
|
|
#include "throughput.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "slcompress.h"
|
1998-08-26 17:39:37 +00:00
|
|
|
#include "lqr.h"
|
|
|
|
#include "hdlc.h"
|
2000-07-19 02:10:35 +00:00
|
|
|
#include "lcp.h"
|
2001-08-14 16:05:52 +00:00
|
|
|
#include "ncpaddr.h"
|
|
|
|
#include "ip.h"
|
1998-05-21 21:49:08 +00:00
|
|
|
#include "ipcp.h"
|
|
|
|
#include "filter.h"
|
|
|
|
#include "descriptor.h"
|
1997-10-26 01:04:02 +00:00
|
|
|
#include "vjcomp.h"
|
1998-05-21 21:49:08 +00:00
|
|
|
#include "async.h"
|
|
|
|
#include "ccp.h"
|
|
|
|
#include "link.h"
|
|
|
|
#include "physical.h"
|
|
|
|
#include "mp.h"
|
1999-01-28 01:56:34 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
#include "radius.h"
|
|
|
|
#endif
|
2001-08-14 16:05:52 +00:00
|
|
|
#include "ipv6cp.h"
|
|
|
|
#include "ncp.h"
|
1998-05-21 21:49:08 +00:00
|
|
|
#include "bundle.h"
|
|
|
|
#include "id.h"
|
|
|
|
#include "arp.h"
|
|
|
|
#include "systems.h"
|
|
|
|
#include "prompt.h"
|
1997-12-13 02:37:33 +00:00
|
|
|
#include "route.h"
|
1998-10-22 02:32:50 +00:00
|
|
|
#include "iface.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
#undef REJECTED
|
|
|
|
#define REJECTED(p, x) ((p)->peer_reject & (1<<(x)))
|
|
|
|
#define issep(ch) ((ch) == ' ' || (ch) == '\t')
|
|
|
|
#define isip(ch) (((ch) >= '0' && (ch) <= '9') || (ch) == '.')
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
struct compreq {
|
|
|
|
u_short proto;
|
|
|
|
u_char slots;
|
|
|
|
u_char compcid;
|
|
|
|
};
|
1997-06-09 03:27:43 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
static int IpcpLayerUp(struct fsm *);
|
|
|
|
static void IpcpLayerDown(struct fsm *);
|
1997-06-09 03:27:43 +00:00
|
|
|
static void IpcpLayerStart(struct fsm *);
|
|
|
|
static void IpcpLayerFinish(struct fsm *);
|
Allow control over the number of ConfigREQ & TermREQ attempts
that are made in each of the FSMs (LCP, CCP & IPCP) and the
number of REQs/Challenges for PAP/CHAP by accepting more arguments
in the ``set {c,ip,l}cpretry'' and ``set {ch,p}apretry'' commands.
Change the non-convergence thresholds to 3 times the number of configured
REQ tries (rather than the previous fixed ``10''). We now notice
repeated NAKs and REJs rather than just REQs.
Don't suggest that CHAP 0x05 isn't supported when it's not configured.
Fix some bugs that expose themselves with smaller numbers of retries:
o Handle instantaneous disconnects (set device /dev/null) correctly
by stopping all fsm timers in fsm2initial.
o Don't forget to uu_unlock() devices that are files but are not
ttys (set device /dev/zero).
Fix a *HORRENDOUS* bug in RFC1661 (already fixed for an Open event in state
``Closed''):
According to the state transition table, a RCR+ or RCR- received in
the ``Stopped'' state are supposed to InitRestartCounter, SendConfigReq
and SendConfig{Ack,Nak}. However, in ``Stopped'', we haven't yet
done a TLS (or the last thing we did is a TLF). We must therefore
do the TLS at this point !
This was never noticed before because LCP and CCP used not use
LayerStart() for anything interesting, and IPCP tends to go into
Stopped then get a Down because of an LCP RTR rather than getting a
RCR again.
1999-02-26 21:28:14 +00:00
|
|
|
static void IpcpInitRestartCounter(struct fsm *, int);
|
1998-05-21 21:49:08 +00:00
|
|
|
static void IpcpSendConfigReq(struct fsm *);
|
|
|
|
static void IpcpSentTerminateReq(struct fsm *);
|
|
|
|
static void IpcpSendTerminateAck(struct fsm *, u_char);
|
|
|
|
static void IpcpDecodeConfig(struct fsm *, u_char *, int, int,
|
|
|
|
struct fsm_decode *);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
static struct fsm_callbacks ipcp_Callbacks = {
|
1995-01-31 06:29:58 +00:00
|
|
|
IpcpLayerUp,
|
|
|
|
IpcpLayerDown,
|
|
|
|
IpcpLayerStart,
|
|
|
|
IpcpLayerFinish,
|
|
|
|
IpcpInitRestartCounter,
|
|
|
|
IpcpSendConfigReq,
|
1998-05-21 21:49:08 +00:00
|
|
|
IpcpSentTerminateReq,
|
1995-01-31 06:29:58 +00:00
|
|
|
IpcpSendTerminateAck,
|
|
|
|
IpcpDecodeConfig,
|
1998-05-21 21:49:08 +00:00
|
|
|
fsm_NullRecvResetReq,
|
|
|
|
fsm_NullRecvResetAck
|
1995-01-31 06:29:58 +00:00
|
|
|
};
|
|
|
|
|
2000-03-14 01:46:54 +00:00
|
|
|
static const char *
|
|
|
|
protoname(int proto)
|
|
|
|
{
|
|
|
|
static struct {
|
|
|
|
int id;
|
|
|
|
const char *txt;
|
|
|
|
} cftypes[] = {
|
|
|
|
/* Check out the latest ``Assigned numbers'' rfc (rfc1700.txt) */
|
|
|
|
{ 1, "IPADDRS" }, /* IP-Addresses */ /* deprecated */
|
|
|
|
{ 2, "COMPPROTO" }, /* IP-Compression-Protocol */
|
|
|
|
{ 3, "IPADDR" }, /* IP-Address */
|
|
|
|
{ 129, "PRIDNS" }, /* 129: Primary DNS Server Address */
|
|
|
|
{ 130, "PRINBNS" }, /* 130: Primary NBNS Server Address */
|
|
|
|
{ 131, "SECDNS" }, /* 131: Secondary DNS Server Address */
|
|
|
|
{ 132, "SECNBNS" } /* 132: Secondary NBNS Server Address */
|
|
|
|
};
|
|
|
|
int f;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
2000-03-14 01:46:54 +00:00
|
|
|
for (f = 0; f < sizeof cftypes / sizeof *cftypes; f++)
|
|
|
|
if (cftypes[f].id == proto)
|
|
|
|
return cftypes[f].txt;
|
1997-11-14 15:39:15 +00:00
|
|
|
|
2000-03-14 01:46:54 +00:00
|
|
|
return NumStr(proto, NULL, 0);
|
|
|
|
}
|
1997-11-14 15:39:15 +00:00
|
|
|
|
1997-11-18 14:52:08 +00:00
|
|
|
void
|
1998-05-21 21:49:08 +00:00
|
|
|
ipcp_AddInOctets(struct ipcp *ipcp, int n)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
throughput_addin(&ipcp->throughput, n);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-11-18 14:52:08 +00:00
|
|
|
void
|
1998-05-21 21:49:08 +00:00
|
|
|
ipcp_AddOutOctets(struct ipcp *ipcp, int n)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
throughput_addout(&ipcp->throughput, n);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
2000-03-14 01:47:27 +00:00
|
|
|
void
|
|
|
|
ipcp_LoadDNS(struct ipcp *ipcp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
2000-03-14 01:47:27 +00:00
|
|
|
int fd;
|
|
|
|
|
|
|
|
ipcp->ns.dns[0].s_addr = ipcp->ns.dns[1].s_addr = INADDR_NONE;
|
|
|
|
|
|
|
|
if (ipcp->ns.resolv != NULL) {
|
|
|
|
free(ipcp->ns.resolv);
|
|
|
|
ipcp->ns.resolv = NULL;
|
|
|
|
}
|
|
|
|
if (ipcp->ns.resolv_nons != NULL) {
|
|
|
|
free(ipcp->ns.resolv_nons);
|
|
|
|
ipcp->ns.resolv_nons = NULL;
|
|
|
|
}
|
|
|
|
ipcp->ns.resolver = 0;
|
|
|
|
|
|
|
|
if ((fd = open(_PATH_RESCONF, O_RDONLY)) != -1) {
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (fstat(fd, &st) == 0) {
|
|
|
|
ssize_t got;
|
|
|
|
|
|
|
|
if ((ipcp->ns.resolv_nons = (char *)malloc(st.st_size + 1)) == NULL)
|
|
|
|
log_Printf(LogERROR, "Failed to malloc %lu for %s: %s\n",
|
|
|
|
(unsigned long)st.st_size, _PATH_RESCONF, strerror(errno));
|
|
|
|
else if ((ipcp->ns.resolv = (char *)malloc(st.st_size + 1)) == NULL) {
|
|
|
|
log_Printf(LogERROR, "Failed(2) to malloc %lu for %s: %s\n",
|
|
|
|
(unsigned long)st.st_size, _PATH_RESCONF, strerror(errno));
|
|
|
|
free(ipcp->ns.resolv_nons);
|
|
|
|
ipcp->ns.resolv_nons = NULL;
|
|
|
|
} else if ((got = read(fd, ipcp->ns.resolv, st.st_size)) != st.st_size) {
|
|
|
|
if (got == -1)
|
|
|
|
log_Printf(LogERROR, "Failed to read %s: %s\n",
|
|
|
|
_PATH_RESCONF, strerror(errno));
|
|
|
|
else
|
|
|
|
log_Printf(LogERROR, "Failed to read %s, got %lu not %lu\n",
|
|
|
|
_PATH_RESCONF, (unsigned long)got,
|
|
|
|
(unsigned long)st.st_size);
|
|
|
|
free(ipcp->ns.resolv_nons);
|
|
|
|
ipcp->ns.resolv_nons = NULL;
|
|
|
|
free(ipcp->ns.resolv);
|
|
|
|
ipcp->ns.resolv = NULL;
|
|
|
|
} else {
|
|
|
|
char *cp, *cp_nons, *ncp, ch;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
ipcp->ns.resolv[st.st_size] = '\0';
|
|
|
|
ipcp->ns.resolver = 1;
|
|
|
|
|
|
|
|
cp_nons = ipcp->ns.resolv_nons;
|
|
|
|
cp = ipcp->ns.resolv;
|
|
|
|
n = 0;
|
|
|
|
|
|
|
|
while ((ncp = strstr(cp, "nameserver")) != NULL) {
|
|
|
|
if (ncp != cp) {
|
|
|
|
memcpy(cp_nons, cp, ncp - cp);
|
|
|
|
cp_nons += ncp - cp;
|
|
|
|
}
|
|
|
|
if ((ncp != cp && ncp[-1] != '\n') || !issep(ncp[10])) {
|
|
|
|
memcpy(cp_nons, ncp, 9);
|
|
|
|
cp_nons += 9;
|
|
|
|
cp = ncp + 9; /* Can't match "nameserver" at cp... */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (cp = ncp + 11; issep(*cp); cp++) /* Skip whitespace */
|
|
|
|
;
|
|
|
|
|
|
|
|
for (ncp = cp; isip(*ncp); ncp++) /* Jump over IP */
|
|
|
|
;
|
1997-06-09 03:27:43 +00:00
|
|
|
|
2000-03-14 01:47:27 +00:00
|
|
|
ch = *ncp;
|
|
|
|
*ncp = '\0';
|
2001-08-14 16:05:52 +00:00
|
|
|
if (n < 2 && inet_aton(cp, ipcp->ns.dns))
|
2000-03-14 01:47:27 +00:00
|
|
|
n++;
|
|
|
|
*ncp = ch;
|
|
|
|
|
|
|
|
if ((cp = strchr(ncp, '\n')) == NULL) /* Point at next line */
|
|
|
|
cp = ncp + strlen(ncp);
|
|
|
|
else
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
strcpy(cp_nons, cp); /* Copy the end - including the NUL */
|
|
|
|
cp_nons += strlen(cp_nons) - 1;
|
|
|
|
while (cp_nons >= ipcp->ns.resolv_nons && *cp_nons == '\n')
|
|
|
|
*cp_nons-- = '\0';
|
|
|
|
if (n == 2 && ipcp->ns.dns[0].s_addr == INADDR_ANY) {
|
|
|
|
ipcp->ns.dns[0].s_addr = ipcp->ns.dns[1].s_addr;
|
|
|
|
ipcp->ns.dns[1].s_addr = INADDR_ANY;
|
|
|
|
}
|
2001-08-14 16:05:52 +00:00
|
|
|
bundle_AdjustDNS(ipcp->fsm.bundle);
|
1998-05-21 21:49:08 +00:00
|
|
|
}
|
2000-03-14 01:47:27 +00:00
|
|
|
} else
|
|
|
|
log_Printf(LogERROR, "Failed to stat opened %s: %s\n",
|
|
|
|
_PATH_RESCONF, strerror(errno));
|
|
|
|
|
|
|
|
close(fd);
|
1998-05-21 21:49:08 +00:00
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
2000-03-14 01:47:27 +00:00
|
|
|
int
|
|
|
|
ipcp_WriteDNS(struct ipcp *ipcp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
2000-03-14 01:47:27 +00:00
|
|
|
const char *paddr;
|
|
|
|
mode_t mask;
|
1998-05-21 21:49:08 +00:00
|
|
|
FILE *fp;
|
|
|
|
|
2000-03-14 01:47:27 +00:00
|
|
|
if (ipcp->ns.dns[0].s_addr == INADDR_ANY &&
|
|
|
|
ipcp->ns.dns[1].s_addr == INADDR_ANY) {
|
|
|
|
log_Printf(LogIPCP, "%s not modified: All nameservers NAKd\n",
|
1998-05-21 21:49:08 +00:00
|
|
|
_PATH_RESCONF);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-03-14 01:47:27 +00:00
|
|
|
if (ipcp->ns.dns[0].s_addr == INADDR_ANY) {
|
|
|
|
ipcp->ns.dns[0].s_addr = ipcp->ns.dns[1].s_addr;
|
|
|
|
ipcp->ns.dns[1].s_addr = INADDR_ANY;
|
1998-05-21 21:49:08 +00:00
|
|
|
}
|
|
|
|
|
2000-05-24 01:00:24 +00:00
|
|
|
mask = umask(022);
|
2000-03-14 01:47:27 +00:00
|
|
|
if ((fp = ID0fopen(_PATH_RESCONF, "w")) != NULL) {
|
|
|
|
umask(mask);
|
2000-05-25 16:12:55 +00:00
|
|
|
if (ipcp->ns.resolv_nons)
|
2000-05-24 01:00:24 +00:00
|
|
|
fputs(ipcp->ns.resolv_nons, fp);
|
2000-03-14 01:47:27 +00:00
|
|
|
paddr = inet_ntoa(ipcp->ns.dns[0]);
|
|
|
|
log_Printf(LogIPCP, "Primary nameserver set to %s\n", paddr);
|
|
|
|
fprintf(fp, "\nnameserver %s\n", paddr);
|
|
|
|
if (ipcp->ns.dns[1].s_addr != INADDR_ANY &&
|
|
|
|
ipcp->ns.dns[1].s_addr != INADDR_NONE &&
|
|
|
|
ipcp->ns.dns[1].s_addr != ipcp->ns.dns[0].s_addr) {
|
|
|
|
paddr = inet_ntoa(ipcp->ns.dns[1]);
|
|
|
|
log_Printf(LogIPCP, "Secondary nameserver set to %s\n", paddr);
|
|
|
|
fprintf(fp, "nameserver %s\n", paddr);
|
|
|
|
}
|
|
|
|
if (fclose(fp) == EOF) {
|
|
|
|
log_Printf(LogERROR, "write(): Failed updating %s: %s\n", _PATH_RESCONF,
|
|
|
|
strerror(errno));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
umask(mask);
|
1998-05-21 21:49:08 +00:00
|
|
|
|
2000-03-14 01:47:27 +00:00
|
|
|
return 1;
|
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
|
2000-03-14 01:47:27 +00:00
|
|
|
void
|
|
|
|
ipcp_RestoreDNS(struct ipcp *ipcp)
|
|
|
|
{
|
|
|
|
if (ipcp->ns.resolver) {
|
|
|
|
ssize_t got;
|
|
|
|
size_t len;
|
1998-05-21 21:49:08 +00:00
|
|
|
int fd;
|
|
|
|
|
2000-03-14 01:47:27 +00:00
|
|
|
if ((fd = ID0open(_PATH_RESCONF, O_WRONLY|O_TRUNC, 0644)) != -1) {
|
|
|
|
len = strlen(ipcp->ns.resolv);
|
|
|
|
if ((got = write(fd, ipcp->ns.resolv, len)) != len) {
|
|
|
|
if (got == -1)
|
|
|
|
log_Printf(LogERROR, "Failed rewriting %s: write: %s\n",
|
|
|
|
_PATH_RESCONF, strerror(errno));
|
|
|
|
else
|
|
|
|
log_Printf(LogERROR, "Failed rewriting %s: wrote %lu of %lu\n",
|
|
|
|
_PATH_RESCONF, (unsigned long)got, (unsigned long)len);
|
1998-05-21 21:49:08 +00:00
|
|
|
}
|
|
|
|
close(fd);
|
2000-03-14 01:47:27 +00:00
|
|
|
} else
|
|
|
|
log_Printf(LogERROR, "Failed rewriting %s: open: %s\n", _PATH_RESCONF,
|
|
|
|
strerror(errno));
|
|
|
|
} else if (remove(_PATH_RESCONF) == -1)
|
|
|
|
log_Printf(LogERROR, "Failed removing %s: %s\n", _PATH_RESCONF,
|
|
|
|
strerror(errno));
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
int
|
|
|
|
ipcp_Show(struct cmdargs const *arg)
|
|
|
|
{
|
|
|
|
struct ipcp *ipcp = &arg->bundle->ncp.ipcp;
|
|
|
|
|
|
|
|
prompt_Printf(arg->prompt, "%s [%s]\n", ipcp->fsm.name,
|
|
|
|
State2Nam(ipcp->fsm.state));
|
|
|
|
if (ipcp->fsm.state == ST_OPENED) {
|
|
|
|
prompt_Printf(arg->prompt, " His side: %s, %s\n",
|
|
|
|
inet_ntoa(ipcp->peer_ip), vj2asc(ipcp->peer_compproto));
|
|
|
|
prompt_Printf(arg->prompt, " My side: %s, %s\n",
|
|
|
|
inet_ntoa(ipcp->my_ip), vj2asc(ipcp->my_compproto));
|
2000-03-14 01:47:19 +00:00
|
|
|
prompt_Printf(arg->prompt, " Queued packets: %lu\n",
|
2001-08-14 16:05:52 +00:00
|
|
|
(unsigned long)ipcp_QueueLen(ipcp));
|
1998-05-21 21:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
prompt_Printf(arg->prompt, "\nDefaults:\n");
|
Allow control over the number of ConfigREQ & TermREQ attempts
that are made in each of the FSMs (LCP, CCP & IPCP) and the
number of REQs/Challenges for PAP/CHAP by accepting more arguments
in the ``set {c,ip,l}cpretry'' and ``set {ch,p}apretry'' commands.
Change the non-convergence thresholds to 3 times the number of configured
REQ tries (rather than the previous fixed ``10''). We now notice
repeated NAKs and REJs rather than just REQs.
Don't suggest that CHAP 0x05 isn't supported when it's not configured.
Fix some bugs that expose themselves with smaller numbers of retries:
o Handle instantaneous disconnects (set device /dev/null) correctly
by stopping all fsm timers in fsm2initial.
o Don't forget to uu_unlock() devices that are files but are not
ttys (set device /dev/zero).
Fix a *HORRENDOUS* bug in RFC1661 (already fixed for an Open event in state
``Closed''):
According to the state transition table, a RCR+ or RCR- received in
the ``Stopped'' state are supposed to InitRestartCounter, SendConfigReq
and SendConfig{Ack,Nak}. However, in ``Stopped'', we haven't yet
done a TLS (or the last thing we did is a TLF). We must therefore
do the TLS at this point !
This was never noticed before because LCP and CCP used not use
LayerStart() for anything interesting, and IPCP tends to go into
Stopped then get a Down because of an LCP RTR rather than getting a
RCR again.
1999-02-26 21:28:14 +00:00
|
|
|
prompt_Printf(arg->prompt, " FSM retry = %us, max %u Config"
|
|
|
|
" REQ%s, %u Term REQ%s\n", ipcp->cfg.fsm.timeout,
|
|
|
|
ipcp->cfg.fsm.maxreq, ipcp->cfg.fsm.maxreq == 1 ? "" : "s",
|
|
|
|
ipcp->cfg.fsm.maxtrm, ipcp->cfg.fsm.maxtrm == 1 ? "" : "s");
|
2001-08-14 16:05:52 +00:00
|
|
|
prompt_Printf(arg->prompt, " My Address: %s\n",
|
|
|
|
ncprange_ntoa(&ipcp->cfg.my_range));
|
1998-05-21 21:49:08 +00:00
|
|
|
if (ipcp->cfg.HaveTriggerAddress)
|
1999-03-03 23:00:41 +00:00
|
|
|
prompt_Printf(arg->prompt, " Trigger address: %s\n",
|
1998-05-21 21:49:08 +00:00
|
|
|
inet_ntoa(ipcp->cfg.TriggerAddress));
|
1999-03-03 23:00:41 +00:00
|
|
|
|
|
|
|
prompt_Printf(arg->prompt, " VJ compression: %s (%d slots %s slot "
|
1998-05-21 21:49:08 +00:00
|
|
|
"compression)\n", command_ShowNegval(ipcp->cfg.vj.neg),
|
|
|
|
ipcp->cfg.vj.slots, ipcp->cfg.vj.slotcomp ? "with" : "without");
|
|
|
|
|
|
|
|
if (iplist_isvalid(&ipcp->cfg.peer_list))
|
|
|
|
prompt_Printf(arg->prompt, " His Address: %s\n",
|
|
|
|
ipcp->cfg.peer_list.src);
|
|
|
|
else
|
2001-08-14 16:05:52 +00:00
|
|
|
prompt_Printf(arg->prompt, " His Address: %s\n",
|
|
|
|
ncprange_ntoa(&ipcp->cfg.peer_range));
|
1998-05-21 21:49:08 +00:00
|
|
|
|
2000-03-14 01:47:27 +00:00
|
|
|
prompt_Printf(arg->prompt, " DNS: %s",
|
|
|
|
ipcp->cfg.ns.dns[0].s_addr == INADDR_NONE ?
|
|
|
|
"none" : inet_ntoa(ipcp->cfg.ns.dns[0]));
|
|
|
|
if (ipcp->cfg.ns.dns[1].s_addr != INADDR_NONE)
|
2001-08-14 16:05:52 +00:00
|
|
|
prompt_Printf(arg->prompt, ", %s",
|
|
|
|
inet_ntoa(ipcp->cfg.ns.dns[1]));
|
2000-03-14 01:47:27 +00:00
|
|
|
prompt_Printf(arg->prompt, ", %s\n",
|
1998-05-21 21:49:08 +00:00
|
|
|
command_ShowNegval(ipcp->cfg.ns.dns_neg));
|
2000-03-14 01:47:27 +00:00
|
|
|
prompt_Printf(arg->prompt, " Resolver DNS: %s",
|
|
|
|
ipcp->ns.dns[0].s_addr == INADDR_NONE ?
|
|
|
|
"none" : inet_ntoa(ipcp->ns.dns[0]));
|
|
|
|
if (ipcp->ns.dns[1].s_addr != INADDR_NONE &&
|
|
|
|
ipcp->ns.dns[1].s_addr != ipcp->ns.dns[0].s_addr)
|
2001-08-14 16:05:52 +00:00
|
|
|
prompt_Printf(arg->prompt, ", %s",
|
|
|
|
inet_ntoa(ipcp->ns.dns[1]));
|
2000-03-14 01:47:27 +00:00
|
|
|
prompt_Printf(arg->prompt, "\n NetBIOS NS: %s, ",
|
1998-05-21 21:49:08 +00:00
|
|
|
inet_ntoa(ipcp->cfg.ns.nbns[0]));
|
2001-08-14 16:05:52 +00:00
|
|
|
prompt_Printf(arg->prompt, "%s\n",
|
|
|
|
inet_ntoa(ipcp->cfg.ns.nbns[1]));
|
1999-09-04 00:00:21 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
throughput_disp(&ipcp->throughput, arg->prompt);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
1998-01-18 20:49:22 +00:00
|
|
|
|
|
|
|
int
|
1998-05-21 21:49:08 +00:00
|
|
|
ipcp_vjset(struct cmdargs const *arg)
|
1998-01-18 20:49:22 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
if (arg->argc != arg->argn+2)
|
1998-01-18 20:49:22 +00:00
|
|
|
return -1;
|
1998-05-21 21:49:08 +00:00
|
|
|
if (!strcasecmp(arg->argv[arg->argn], "slots")) {
|
1998-01-18 20:49:22 +00:00
|
|
|
int slots;
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
slots = atoi(arg->argv[arg->argn+1]);
|
1998-01-18 20:49:22 +00:00
|
|
|
if (slots < 4 || slots > 16)
|
|
|
|
return 1;
|
1998-05-21 21:49:08 +00:00
|
|
|
arg->bundle->ncp.ipcp.cfg.vj.slots = slots;
|
1998-01-18 20:49:22 +00:00
|
|
|
return 0;
|
1998-05-21 21:49:08 +00:00
|
|
|
} else if (!strcasecmp(arg->argv[arg->argn], "slotcomp")) {
|
|
|
|
if (!strcasecmp(arg->argv[arg->argn+1], "on"))
|
|
|
|
arg->bundle->ncp.ipcp.cfg.vj.slotcomp = 1;
|
|
|
|
else if (!strcasecmp(arg->argv[arg->argn+1], "off"))
|
|
|
|
arg->bundle->ncp.ipcp.cfg.vj.slotcomp = 0;
|
1998-01-18 20:49:22 +00:00
|
|
|
else
|
|
|
|
return 2;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
void
|
|
|
|
ipcp_Init(struct ipcp *ipcp, struct bundle *bundle, struct link *l,
|
|
|
|
const struct fsm_parent *parent)
|
1998-01-18 20:49:22 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
struct hostent *hp;
|
2001-08-14 16:05:52 +00:00
|
|
|
struct in_addr host;
|
2001-03-09 20:31:02 +00:00
|
|
|
char name[MAXHOSTNAMELEN];
|
1999-12-27 11:54:57 +00:00
|
|
|
static const char * const timer_names[] =
|
1998-05-21 21:49:08 +00:00
|
|
|
{"IPCP restart", "IPCP openmode", "IPCP stopped"};
|
|
|
|
|
Allow control over the number of ConfigREQ & TermREQ attempts
that are made in each of the FSMs (LCP, CCP & IPCP) and the
number of REQs/Challenges for PAP/CHAP by accepting more arguments
in the ``set {c,ip,l}cpretry'' and ``set {ch,p}apretry'' commands.
Change the non-convergence thresholds to 3 times the number of configured
REQ tries (rather than the previous fixed ``10''). We now notice
repeated NAKs and REJs rather than just REQs.
Don't suggest that CHAP 0x05 isn't supported when it's not configured.
Fix some bugs that expose themselves with smaller numbers of retries:
o Handle instantaneous disconnects (set device /dev/null) correctly
by stopping all fsm timers in fsm2initial.
o Don't forget to uu_unlock() devices that are files but are not
ttys (set device /dev/zero).
Fix a *HORRENDOUS* bug in RFC1661 (already fixed for an Open event in state
``Closed''):
According to the state transition table, a RCR+ or RCR- received in
the ``Stopped'' state are supposed to InitRestartCounter, SendConfigReq
and SendConfig{Ack,Nak}. However, in ``Stopped'', we haven't yet
done a TLS (or the last thing we did is a TLF). We must therefore
do the TLS at this point !
This was never noticed before because LCP and CCP used not use
LayerStart() for anything interesting, and IPCP tends to go into
Stopped then get a Down because of an LCP RTR rather than getting a
RCR again.
1999-02-26 21:28:14 +00:00
|
|
|
fsm_Init(&ipcp->fsm, "IPCP", PROTO_IPCP, 1, IPCP_MAXCODE, LogIPCP,
|
1998-05-21 21:49:08 +00:00
|
|
|
bundle, l, parent, &ipcp_Callbacks, timer_names);
|
|
|
|
|
|
|
|
ipcp->cfg.vj.slots = DEF_VJ_STATES;
|
|
|
|
ipcp->cfg.vj.slotcomp = 1;
|
|
|
|
memset(&ipcp->cfg.my_range, '\0', sizeof ipcp->cfg.my_range);
|
2001-08-14 16:05:52 +00:00
|
|
|
|
|
|
|
host.s_addr = htonl(INADDR_LOOPBACK);
|
|
|
|
ipcp->cfg.netmask.s_addr = INADDR_ANY;
|
1998-05-21 21:49:08 +00:00
|
|
|
if (gethostname(name, sizeof name) == 0) {
|
|
|
|
hp = gethostbyname(name);
|
2001-08-14 16:05:52 +00:00
|
|
|
if (hp && hp->h_addrtype == AF_INET && hp->h_length == sizeof host.s_addr)
|
|
|
|
memcpy(&host.s_addr, hp->h_addr, sizeof host.s_addr);
|
1998-01-18 20:49:22 +00:00
|
|
|
}
|
2001-08-14 16:05:52 +00:00
|
|
|
ncprange_setip4(&ipcp->cfg.my_range, host, ipcp->cfg.netmask);
|
|
|
|
ncprange_setip4(&ipcp->cfg.peer_range, ipcp->cfg.netmask, ipcp->cfg.netmask);
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
iplist_setsrc(&ipcp->cfg.peer_list, "");
|
|
|
|
ipcp->cfg.HaveTriggerAddress = 0;
|
|
|
|
|
2000-03-14 01:47:27 +00:00
|
|
|
ipcp->cfg.ns.dns[0].s_addr = INADDR_NONE;
|
|
|
|
ipcp->cfg.ns.dns[1].s_addr = INADDR_NONE;
|
1998-05-21 21:49:08 +00:00
|
|
|
ipcp->cfg.ns.dns_neg = 0;
|
|
|
|
ipcp->cfg.ns.nbns[0].s_addr = INADDR_ANY;
|
|
|
|
ipcp->cfg.ns.nbns[1].s_addr = INADDR_ANY;
|
|
|
|
|
Allow control over the number of ConfigREQ & TermREQ attempts
that are made in each of the FSMs (LCP, CCP & IPCP) and the
number of REQs/Challenges for PAP/CHAP by accepting more arguments
in the ``set {c,ip,l}cpretry'' and ``set {ch,p}apretry'' commands.
Change the non-convergence thresholds to 3 times the number of configured
REQ tries (rather than the previous fixed ``10''). We now notice
repeated NAKs and REJs rather than just REQs.
Don't suggest that CHAP 0x05 isn't supported when it's not configured.
Fix some bugs that expose themselves with smaller numbers of retries:
o Handle instantaneous disconnects (set device /dev/null) correctly
by stopping all fsm timers in fsm2initial.
o Don't forget to uu_unlock() devices that are files but are not
ttys (set device /dev/zero).
Fix a *HORRENDOUS* bug in RFC1661 (already fixed for an Open event in state
``Closed''):
According to the state transition table, a RCR+ or RCR- received in
the ``Stopped'' state are supposed to InitRestartCounter, SendConfigReq
and SendConfig{Ack,Nak}. However, in ``Stopped'', we haven't yet
done a TLS (or the last thing we did is a TLF). We must therefore
do the TLS at this point !
This was never noticed before because LCP and CCP used not use
LayerStart() for anything interesting, and IPCP tends to go into
Stopped then get a Down because of an LCP RTR rather than getting a
RCR again.
1999-02-26 21:28:14 +00:00
|
|
|
ipcp->cfg.fsm.timeout = DEF_FSMRETRY;
|
|
|
|
ipcp->cfg.fsm.maxreq = DEF_FSMTRIES;
|
|
|
|
ipcp->cfg.fsm.maxtrm = DEF_FSMTRIES;
|
1998-05-21 21:49:08 +00:00
|
|
|
ipcp->cfg.vj.neg = NEG_ENABLED|NEG_ACCEPTED;
|
|
|
|
|
|
|
|
memset(&ipcp->vj, '\0', sizeof ipcp->vj);
|
|
|
|
|
2000-03-14 01:47:27 +00:00
|
|
|
ipcp->ns.resolv = NULL;
|
|
|
|
ipcp->ns.resolv_nons = NULL;
|
|
|
|
ipcp->ns.writable = 1;
|
|
|
|
ipcp_LoadDNS(ipcp);
|
|
|
|
|
1999-08-05 10:32:16 +00:00
|
|
|
throughput_init(&ipcp->throughput, SAMPLE_PERIOD);
|
1998-08-26 17:39:37 +00:00
|
|
|
memset(ipcp->Queue, '\0', sizeof ipcp->Queue);
|
1999-01-28 01:56:34 +00:00
|
|
|
ipcp_Setup(ipcp, INADDR_NONE);
|
1998-01-18 20:49:22 +00:00
|
|
|
}
|
|
|
|
|
1999-09-04 00:00:21 +00:00
|
|
|
void
|
|
|
|
ipcp_Destroy(struct ipcp *ipcp)
|
|
|
|
{
|
2001-08-14 16:05:52 +00:00
|
|
|
throughput_destroy(&ipcp->throughput);
|
|
|
|
|
2000-03-14 01:47:27 +00:00
|
|
|
if (ipcp->ns.resolv != NULL) {
|
|
|
|
free(ipcp->ns.resolv);
|
|
|
|
ipcp->ns.resolv = NULL;
|
|
|
|
}
|
|
|
|
if (ipcp->ns.resolv_nons != NULL) {
|
|
|
|
free(ipcp->ns.resolv_nons);
|
|
|
|
ipcp->ns.resolv_nons = NULL;
|
|
|
|
}
|
1999-09-04 00:00:21 +00:00
|
|
|
}
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
void
|
1998-05-21 21:49:08 +00:00
|
|
|
ipcp_SetLink(struct ipcp *ipcp, struct link *l)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
ipcp->fsm.link = l;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-01-28 01:56:34 +00:00
|
|
|
ipcp_Setup(struct ipcp *ipcp, u_int32_t mask)
|
1998-05-21 21:49:08 +00:00
|
|
|
{
|
1998-10-22 02:32:50 +00:00
|
|
|
struct iface *iface = ipcp->fsm.bundle->iface;
|
2001-08-14 16:05:52 +00:00
|
|
|
struct ncpaddr ipaddr;
|
|
|
|
struct in_addr peer;
|
1998-10-22 02:32:50 +00:00
|
|
|
int pos, n;
|
1998-05-21 21:49:08 +00:00
|
|
|
|
|
|
|
ipcp->fsm.open_mode = 0;
|
1999-01-28 01:56:34 +00:00
|
|
|
ipcp->ifmask.s_addr = mask == INADDR_NONE ? ipcp->cfg.netmask.s_addr : mask;
|
1998-05-21 21:49:08 +00:00
|
|
|
|
|
|
|
if (iplist_isvalid(&ipcp->cfg.peer_list)) {
|
1998-10-22 02:32:50 +00:00
|
|
|
/* Try to give the peer a previously configured IP address */
|
2001-08-14 16:05:52 +00:00
|
|
|
for (n = 0; n < iface->addrs; n++) {
|
|
|
|
if (!ncpaddr_getip4(&iface->addr[n].peer, &peer))
|
|
|
|
continue;
|
|
|
|
if ((pos = iplist_ip2pos(&ipcp->cfg.peer_list, peer)) != -1) {
|
|
|
|
ncpaddr_setip4(&ipaddr, iplist_setcurpos(&ipcp->cfg.peer_list, pos));
|
1998-10-22 02:32:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-08-14 16:05:52 +00:00
|
|
|
if (n == iface->addrs)
|
1998-10-22 02:32:50 +00:00
|
|
|
/* Ok, so none of 'em fit.... pick a random one */
|
2001-08-14 16:05:52 +00:00
|
|
|
ncpaddr_setip4(&ipaddr, iplist_setrandpos(&ipcp->cfg.peer_list));
|
1998-10-22 02:32:50 +00:00
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
ncprange_sethost(&ipcp->cfg.peer_range, &ipaddr);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1995-07-08 08:28:10 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
ipcp->heis1172 = 0;
|
2001-07-28 11:32:08 +00:00
|
|
|
ipcp->peer_req = 0;
|
2001-08-14 16:05:52 +00:00
|
|
|
ncprange_getip4addr(&ipcp->cfg.peer_range, &ipcp->peer_ip);
|
1998-05-21 21:49:08 +00:00
|
|
|
ipcp->peer_compproto = 0;
|
|
|
|
|
|
|
|
if (ipcp->cfg.HaveTriggerAddress) {
|
|
|
|
/*
|
|
|
|
* 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").
|
|
|
|
*/
|
|
|
|
ipcp->my_ip = ipcp->cfg.TriggerAddress;
|
|
|
|
log_Printf(LogIPCP, "Using trigger address %s\n",
|
|
|
|
inet_ntoa(ipcp->cfg.TriggerAddress));
|
1998-10-22 02:32:50 +00:00
|
|
|
} else {
|
1998-05-21 21:49:08 +00:00
|
|
|
/*
|
1998-10-22 02:32:50 +00:00
|
|
|
* Otherwise, if we've used an IP number before and it's still within
|
|
|
|
* the network specified on the ``set ifaddr'' line, we really
|
|
|
|
* want to keep that IP number so that we can keep any existing
|
2001-08-14 16:05:52 +00:00
|
|
|
* connections that are bound to that IP.
|
1998-05-21 21:49:08 +00:00
|
|
|
*/
|
2001-08-14 16:05:52 +00:00
|
|
|
for (n = 0; n < iface->addrs; n++) {
|
|
|
|
ncprange_getaddr(&iface->addr[n].ifa, &ipaddr);
|
|
|
|
if (ncprange_contains(&ipcp->cfg.my_range, &ipaddr)) {
|
|
|
|
ncpaddr_getip4(&ipaddr, &ipcp->my_ip);
|
1998-10-22 02:32:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-08-14 16:05:52 +00:00
|
|
|
}
|
|
|
|
if (n == iface->addrs)
|
|
|
|
ncprange_getip4addr(&ipcp->cfg.my_range, &ipcp->my_ip);
|
1998-10-22 02:32:50 +00:00
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
|
1999-01-28 01:56:34 +00:00
|
|
|
if (IsEnabled(ipcp->cfg.vj.neg)
|
|
|
|
#ifndef NORADIUS
|
|
|
|
|| (ipcp->fsm.bundle->radius.valid && ipcp->fsm.bundle->radius.vj)
|
|
|
|
#endif
|
|
|
|
)
|
1998-05-21 21:49:08 +00:00
|
|
|
ipcp->my_compproto = (PROTO_VJCOMP << 16) +
|
|
|
|
((ipcp->cfg.vj.slots - 1) << 8) +
|
|
|
|
ipcp->cfg.vj.slotcomp;
|
|
|
|
else
|
|
|
|
ipcp->my_compproto = 0;
|
|
|
|
sl_compress_init(&ipcp->vj.cslc, ipcp->cfg.vj.slots - 1);
|
|
|
|
|
|
|
|
ipcp->peer_reject = 0;
|
|
|
|
ipcp->my_reject = 0;
|
2000-03-14 01:47:27 +00:00
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
/* Copy startup values into ipcp->ns.dns */
|
2000-03-14 01:47:27 +00:00
|
|
|
if (ipcp->cfg.ns.dns[0].s_addr != INADDR_NONE)
|
2001-08-14 16:05:52 +00:00
|
|
|
memcpy(ipcp->ns.dns, ipcp->cfg.ns.dns, sizeof ipcp->ns.dns);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
numaddresses(struct in_addr mask)
|
|
|
|
{
|
|
|
|
u_int32_t bit, haddr;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
haddr = ntohl(mask.s_addr);
|
|
|
|
bit = 1;
|
|
|
|
n = 1;
|
2000-03-14 01:47:27 +00:00
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
do {
|
|
|
|
if (!(haddr & bit))
|
|
|
|
n <<= 1;
|
|
|
|
} while (bit <<= 1);
|
|
|
|
|
|
|
|
return n;
|
1998-05-21 21:49:08 +00:00
|
|
|
}
|
|
|
|
|
1998-10-26 19:07:39 +00:00
|
|
|
static int
|
2001-08-14 16:05:52 +00:00
|
|
|
ipcp_proxyarp(struct ipcp *ipcp,
|
|
|
|
int (*proxyfun)(struct bundle *, struct in_addr, int),
|
|
|
|
const struct iface_addr *addr)
|
1998-10-26 19:07:39 +00:00
|
|
|
{
|
2001-08-14 16:05:52 +00:00
|
|
|
struct bundle *bundle = ipcp->fsm.bundle;
|
|
|
|
struct in_addr peer, mask, ip;
|
|
|
|
int n, ret, s;
|
|
|
|
|
|
|
|
if (!ncpaddr_getip4(&addr->peer, &peer)) {
|
|
|
|
log_Printf(LogERROR, "Oops, ipcp_proxyarp() called with unexpected addr\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((s = ID0socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
|
|
|
|
log_Printf(LogERROR, "ipcp_proxyarp: socket: %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
if (Enabled(bundle, OPT_PROXYALL)) {
|
|
|
|
ncprange_getip4mask(&addr->ifa, &mask);
|
|
|
|
if ((n = numaddresses(mask)) > 256) {
|
|
|
|
log_Printf(LogWARN, "%s: Too many addresses for proxyall\n",
|
|
|
|
ncprange_ntoa(&addr->ifa));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ip.s_addr = peer.s_addr & mask.s_addr;
|
|
|
|
if (n >= 4) {
|
|
|
|
ip.s_addr = htonl(ntohl(ip.s_addr) + 1);
|
|
|
|
n -= 2;
|
|
|
|
}
|
|
|
|
while (n) {
|
|
|
|
if (!((ip.s_addr ^ peer.s_addr) & mask.s_addr)) {
|
|
|
|
if (!(ret = (*proxyfun)(bundle, ip, s)))
|
|
|
|
break;
|
|
|
|
n--;
|
1998-10-26 19:07:39 +00:00
|
|
|
}
|
2001-08-14 16:05:52 +00:00
|
|
|
ip.s_addr = htonl(ntohl(ip.s_addr) + 1);
|
1998-10-26 19:07:39 +00:00
|
|
|
}
|
2001-08-14 16:05:52 +00:00
|
|
|
ret = !n;
|
|
|
|
} else if (Enabled(bundle, OPT_PROXY))
|
|
|
|
ret = (*proxyfun)(bundle, peer, s);
|
1998-10-26 19:07:39 +00:00
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
close(s);
|
|
|
|
|
|
|
|
return ret;
|
1998-10-26 19:07:39 +00:00
|
|
|
}
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
static int
|
2001-08-14 16:05:52 +00:00
|
|
|
ipcp_SetIPaddress(struct ipcp *ipcp, struct in_addr myaddr,
|
|
|
|
struct in_addr hisaddr)
|
1998-05-21 21:49:08 +00:00
|
|
|
{
|
2001-08-14 16:05:52 +00:00
|
|
|
struct bundle *bundle = ipcp->fsm.bundle;
|
|
|
|
struct ncpaddr myncpaddr, hisncpaddr;
|
|
|
|
struct ncprange myrange, dst;
|
|
|
|
struct in_addr mask;
|
|
|
|
|
|
|
|
ncpaddr_setip4(&hisncpaddr, hisaddr);
|
|
|
|
ncpaddr_setip4(&myncpaddr, myaddr);
|
|
|
|
ncprange_sethost(&myrange, &myncpaddr);
|
1998-05-21 21:49:08 +00:00
|
|
|
|
1999-03-03 23:00:41 +00:00
|
|
|
mask = addr2mask(myaddr);
|
1998-05-21 21:49:08 +00:00
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
if (ipcp->ifmask.s_addr != INADDR_ANY &&
|
|
|
|
(ipcp->ifmask.s_addr & mask.s_addr) == mask.s_addr)
|
|
|
|
ncprange_setip4mask(&myrange, ipcp->ifmask);
|
1998-10-22 02:32:50 +00:00
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
if (!iface_Add(bundle->iface, &bundle->ncp, &myrange, &hisncpaddr,
|
|
|
|
IFACE_ADD_FIRST|IFACE_FORCE_ADD|IFACE_SYSTEM))
|
|
|
|
return 0;
|
1998-10-22 02:32:50 +00:00
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
if (!Enabled(bundle, OPT_IFACEALIAS))
|
|
|
|
iface_Clear(bundle->iface, &bundle->ncp, AF_INET,
|
|
|
|
IFACE_CLEAR_ALIASES|IFACE_SYSTEM);
|
1998-05-21 21:49:08 +00:00
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
if (bundle->ncp.cfg.sendpipe > 0 || bundle->ncp.cfg.recvpipe > 0) {
|
|
|
|
ncprange_sethost(&dst, &hisncpaddr);
|
|
|
|
rt_Update(bundle, &dst);
|
|
|
|
}
|
1998-10-26 19:07:39 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
if (Enabled(bundle, OPT_SROUTES))
|
2001-08-14 16:05:52 +00:00
|
|
|
route_Change(bundle, bundle->ncp.route, &myncpaddr, &hisncpaddr);
|
1998-05-21 21:49:08 +00:00
|
|
|
|
1999-01-28 01:56:34 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
if (bundle->radius.valid)
|
2001-08-14 16:05:52 +00:00
|
|
|
route_Change(bundle, bundle->radius.routes, &myncpaddr, &hisncpaddr);
|
1999-01-28 01:56:34 +00:00
|
|
|
#endif
|
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
return 1; /* Ok */
|
1998-05-21 21:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct in_addr
|
1998-10-22 02:32:50 +00:00
|
|
|
ChooseHisAddr(struct bundle *bundle, struct in_addr gw)
|
1998-05-21 21:49:08 +00:00
|
|
|
{
|
|
|
|
struct in_addr try;
|
1998-06-27 23:48:54 +00:00
|
|
|
u_long f;
|
1998-05-21 21:49:08 +00:00
|
|
|
|
|
|
|
for (f = 0; f < bundle->ncp.ipcp.cfg.peer_list.nItems; f++) {
|
|
|
|
try = iplist_next(&bundle->ncp.ipcp.cfg.peer_list);
|
1998-06-27 23:48:54 +00:00
|
|
|
log_Printf(LogDEBUG, "ChooseHisAddr: Check item %ld (%s)\n",
|
1998-05-21 21:49:08 +00:00
|
|
|
f, inet_ntoa(try));
|
2001-08-14 16:05:52 +00:00
|
|
|
if (ipcp_SetIPaddress(&bundle->ncp.ipcp, gw, try)) {
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(LogIPCP, "Selected IP address %s\n", inet_ntoa(try));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (f == bundle->ncp.ipcp.cfg.peer_list.nItems) {
|
|
|
|
log_Printf(LogDEBUG, "ChooseHisAddr: All addresses in use !\n");
|
|
|
|
try.s_addr = INADDR_ANY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return try;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
Allow control over the number of ConfigREQ & TermREQ attempts
that are made in each of the FSMs (LCP, CCP & IPCP) and the
number of REQs/Challenges for PAP/CHAP by accepting more arguments
in the ``set {c,ip,l}cpretry'' and ``set {ch,p}apretry'' commands.
Change the non-convergence thresholds to 3 times the number of configured
REQ tries (rather than the previous fixed ``10''). We now notice
repeated NAKs and REJs rather than just REQs.
Don't suggest that CHAP 0x05 isn't supported when it's not configured.
Fix some bugs that expose themselves with smaller numbers of retries:
o Handle instantaneous disconnects (set device /dev/null) correctly
by stopping all fsm timers in fsm2initial.
o Don't forget to uu_unlock() devices that are files but are not
ttys (set device /dev/zero).
Fix a *HORRENDOUS* bug in RFC1661 (already fixed for an Open event in state
``Closed''):
According to the state transition table, a RCR+ or RCR- received in
the ``Stopped'' state are supposed to InitRestartCounter, SendConfigReq
and SendConfig{Ack,Nak}. However, in ``Stopped'', we haven't yet
done a TLS (or the last thing we did is a TLF). We must therefore
do the TLS at this point !
This was never noticed before because LCP and CCP used not use
LayerStart() for anything interesting, and IPCP tends to go into
Stopped then get a Down because of an LCP RTR rather than getting a
RCR again.
1999-02-26 21:28:14 +00:00
|
|
|
IpcpInitRestartCounter(struct fsm *fp, int what)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
/* Set fsm timer load */
|
|
|
|
struct ipcp *ipcp = fsm2ipcp(fp);
|
|
|
|
|
Allow control over the number of ConfigREQ & TermREQ attempts
that are made in each of the FSMs (LCP, CCP & IPCP) and the
number of REQs/Challenges for PAP/CHAP by accepting more arguments
in the ``set {c,ip,l}cpretry'' and ``set {ch,p}apretry'' commands.
Change the non-convergence thresholds to 3 times the number of configured
REQ tries (rather than the previous fixed ``10''). We now notice
repeated NAKs and REJs rather than just REQs.
Don't suggest that CHAP 0x05 isn't supported when it's not configured.
Fix some bugs that expose themselves with smaller numbers of retries:
o Handle instantaneous disconnects (set device /dev/null) correctly
by stopping all fsm timers in fsm2initial.
o Don't forget to uu_unlock() devices that are files but are not
ttys (set device /dev/zero).
Fix a *HORRENDOUS* bug in RFC1661 (already fixed for an Open event in state
``Closed''):
According to the state transition table, a RCR+ or RCR- received in
the ``Stopped'' state are supposed to InitRestartCounter, SendConfigReq
and SendConfig{Ack,Nak}. However, in ``Stopped'', we haven't yet
done a TLS (or the last thing we did is a TLF). We must therefore
do the TLS at this point !
This was never noticed before because LCP and CCP used not use
LayerStart() for anything interesting, and IPCP tends to go into
Stopped then get a Down because of an LCP RTR rather than getting a
RCR again.
1999-02-26 21:28:14 +00:00
|
|
|
fp->FsmTimer.load = ipcp->cfg.fsm.timeout * SECTICKS;
|
|
|
|
switch (what) {
|
|
|
|
case FSM_REQ_TIMER:
|
|
|
|
fp->restart = ipcp->cfg.fsm.maxreq;
|
|
|
|
break;
|
|
|
|
case FSM_TRM_TIMER:
|
|
|
|
fp->restart = ipcp->cfg.fsm.maxtrm;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fp->restart = 1;
|
|
|
|
break;
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-05-21 21:49:08 +00:00
|
|
|
IpcpSendConfigReq(struct fsm *fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
/* Send config REQ please */
|
|
|
|
struct physical *p = link2physical(fp->link);
|
|
|
|
struct ipcp *ipcp = fsm2ipcp(fp);
|
|
|
|
u_char buff[24];
|
|
|
|
struct lcp_opt *o;
|
|
|
|
|
|
|
|
o = (struct lcp_opt *)buff;
|
|
|
|
|
|
|
|
if ((p && !physical_IsSync(p)) || !REJECTED(ipcp, TY_IPADDR)) {
|
1998-09-04 18:26:00 +00:00
|
|
|
memcpy(o->data, &ipcp->my_ip.s_addr, 4);
|
1998-05-21 21:49:08 +00:00
|
|
|
INC_LCP_OPT(TY_IPADDR, 6, o);
|
1997-12-03 10:23:54 +00:00
|
|
|
}
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
if (ipcp->my_compproto && !REJECTED(ipcp, TY_COMPPROTO)) {
|
|
|
|
if (ipcp->heis1172) {
|
1998-09-04 18:26:00 +00:00
|
|
|
u_int16_t proto = PROTO_VJCOMP;
|
|
|
|
|
|
|
|
ua_htons(&proto, o->data);
|
1998-05-21 21:49:08 +00:00
|
|
|
INC_LCP_OPT(TY_COMPPROTO, 4, o);
|
1997-12-03 10:23:54 +00:00
|
|
|
} else {
|
1999-02-02 20:27:12 +00:00
|
|
|
struct compreq req;
|
|
|
|
|
|
|
|
req.proto = htons(ipcp->my_compproto >> 16);
|
|
|
|
req.slots = (ipcp->my_compproto >> 8) & 255;
|
|
|
|
req.compcid = ipcp->my_compproto & 1;
|
|
|
|
memcpy(o->data, &req, 4);
|
1998-05-21 21:49:08 +00:00
|
|
|
INC_LCP_OPT(TY_COMPPROTO, 6, o);
|
1997-12-03 10:23:54 +00:00
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
if (IsEnabled(ipcp->cfg.ns.dns_neg)) {
|
|
|
|
if (!REJECTED(ipcp, TY_PRIMARY_DNS - TY_ADJUST_NS)) {
|
|
|
|
memcpy(o->data, &ipcp->ns.dns[0].s_addr, 4);
|
|
|
|
INC_LCP_OPT(TY_PRIMARY_DNS, 6, o);
|
|
|
|
}
|
2001-01-22 01:43:46 +00:00
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
if (!REJECTED(ipcp, TY_SECONDARY_DNS - TY_ADJUST_NS)) {
|
|
|
|
memcpy(o->data, &ipcp->ns.dns[1].s_addr, 4);
|
|
|
|
INC_LCP_OPT(TY_SECONDARY_DNS, 6, o);
|
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
}
|
|
|
|
|
1999-06-02 15:59:09 +00:00
|
|
|
fsm_Output(fp, CODE_CONFIGREQ, fp->reqid, buff, (u_char *)o - buff,
|
|
|
|
MB_IPCPOUT);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
Allow control over the number of ConfigREQ & TermREQ attempts
that are made in each of the FSMs (LCP, CCP & IPCP) and the
number of REQs/Challenges for PAP/CHAP by accepting more arguments
in the ``set {c,ip,l}cpretry'' and ``set {ch,p}apretry'' commands.
Change the non-convergence thresholds to 3 times the number of configured
REQ tries (rather than the previous fixed ``10''). We now notice
repeated NAKs and REJs rather than just REQs.
Don't suggest that CHAP 0x05 isn't supported when it's not configured.
Fix some bugs that expose themselves with smaller numbers of retries:
o Handle instantaneous disconnects (set device /dev/null) correctly
by stopping all fsm timers in fsm2initial.
o Don't forget to uu_unlock() devices that are files but are not
ttys (set device /dev/zero).
Fix a *HORRENDOUS* bug in RFC1661 (already fixed for an Open event in state
``Closed''):
According to the state transition table, a RCR+ or RCR- received in
the ``Stopped'' state are supposed to InitRestartCounter, SendConfigReq
and SendConfig{Ack,Nak}. However, in ``Stopped'', we haven't yet
done a TLS (or the last thing we did is a TLF). We must therefore
do the TLS at this point !
This was never noticed before because LCP and CCP used not use
LayerStart() for anything interesting, and IPCP tends to go into
Stopped then get a Down because of an LCP RTR rather than getting a
RCR again.
1999-02-26 21:28:14 +00:00
|
|
|
IpcpSentTerminateReq(struct fsm *fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
/* Term REQ just sent by FSM */
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-05-21 21:49:08 +00:00
|
|
|
IpcpSendTerminateAck(struct fsm *fp, u_char id)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
/* Send Term ACK please */
|
1999-06-02 15:59:09 +00:00
|
|
|
fsm_Output(fp, CODE_TERMACK, id, NULL, 0, MB_IPCPOUT);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-06-25 22:33:31 +00:00
|
|
|
IpcpLayerStart(struct fsm *fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
/* We're about to start up ! */
|
1998-06-25 22:33:31 +00:00
|
|
|
struct ipcp *ipcp = fsm2ipcp(fp);
|
|
|
|
|
1998-06-27 23:48:54 +00:00
|
|
|
log_Printf(LogIPCP, "%s: LayerStart.\n", fp->link->name);
|
1998-06-25 22:33:31 +00:00
|
|
|
throughput_start(&ipcp->throughput, "IPCP throughput",
|
|
|
|
Enabled(fp->bundle, OPT_THROUGHPUT));
|
Allow control over the number of ConfigREQ & TermREQ attempts
that are made in each of the FSMs (LCP, CCP & IPCP) and the
number of REQs/Challenges for PAP/CHAP by accepting more arguments
in the ``set {c,ip,l}cpretry'' and ``set {ch,p}apretry'' commands.
Change the non-convergence thresholds to 3 times the number of configured
REQ tries (rather than the previous fixed ``10''). We now notice
repeated NAKs and REJs rather than just REQs.
Don't suggest that CHAP 0x05 isn't supported when it's not configured.
Fix some bugs that expose themselves with smaller numbers of retries:
o Handle instantaneous disconnects (set device /dev/null) correctly
by stopping all fsm timers in fsm2initial.
o Don't forget to uu_unlock() devices that are files but are not
ttys (set device /dev/zero).
Fix a *HORRENDOUS* bug in RFC1661 (already fixed for an Open event in state
``Closed''):
According to the state transition table, a RCR+ or RCR- received in
the ``Stopped'' state are supposed to InitRestartCounter, SendConfigReq
and SendConfig{Ack,Nak}. However, in ``Stopped'', we haven't yet
done a TLS (or the last thing we did is a TLF). We must therefore
do the TLS at this point !
This was never noticed before because LCP and CCP used not use
LayerStart() for anything interesting, and IPCP tends to go into
Stopped then get a Down because of an LCP RTR rather than getting a
RCR again.
1999-02-26 21:28:14 +00:00
|
|
|
fp->more.reqs = fp->more.naks = fp->more.rejs = ipcp->cfg.fsm.maxreq * 3;
|
2001-07-28 11:32:08 +00:00
|
|
|
ipcp->peer_req = 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-05-21 21:49:08 +00:00
|
|
|
IpcpLayerFinish(struct fsm *fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
/* We're now down */
|
1998-06-25 22:33:31 +00:00
|
|
|
struct ipcp *ipcp = fsm2ipcp(fp);
|
|
|
|
|
1998-06-27 23:48:54 +00:00
|
|
|
log_Printf(LogIPCP, "%s: LayerFinish.\n", fp->link->name);
|
1998-06-25 22:33:31 +00:00
|
|
|
throughput_stop(&ipcp->throughput);
|
|
|
|
throughput_log(&ipcp->throughput, LogIPCP, NULL);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
/*
|
|
|
|
* Called from iface_Add() via ncp_IfaceAddrAdded()
|
|
|
|
*/
|
1998-05-21 21:49:08 +00:00
|
|
|
void
|
2001-08-14 16:05:52 +00:00
|
|
|
ipcp_IfaceAddrAdded(struct ipcp *ipcp, const struct iface_addr *addr)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
2001-08-14 16:05:52 +00:00
|
|
|
struct bundle *bundle = ipcp->fsm.bundle;
|
1998-05-21 21:49:08 +00:00
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
if (Enabled(bundle, OPT_PROXY) || Enabled(bundle, OPT_PROXYALL))
|
|
|
|
ipcp_proxyarp(ipcp, arp_SetProxy, addr);
|
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
/*
|
|
|
|
* Called from iface_Clear() and iface_Delete() via ncp_IfaceAddrDeleted()
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ipcp_IfaceAddrDeleted(struct ipcp *ipcp, const struct iface_addr *addr)
|
|
|
|
{
|
|
|
|
struct bundle *bundle = ipcp->fsm.bundle;
|
|
|
|
|
|
|
|
if (Enabled(bundle, OPT_PROXY) || Enabled(bundle, OPT_PROXYALL))
|
|
|
|
ipcp_proxyarp(ipcp, arp_ClearProxy, addr);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-05-21 21:49:08 +00:00
|
|
|
IpcpLayerDown(struct fsm *fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
/* About to come down */
|
|
|
|
struct ipcp *ipcp = fsm2ipcp(fp);
|
2001-08-14 16:05:52 +00:00
|
|
|
static int recursing;
|
|
|
|
char addr[16];
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1999-06-08 11:58:27 +00:00
|
|
|
if (!recursing++) {
|
2001-08-14 16:05:52 +00:00
|
|
|
snprintf(addr, sizeof addr, "%s", inet_ntoa(ipcp->my_ip));
|
|
|
|
log_Printf(LogIPCP, "%s: LayerDown: %s\n", fp->link->name, addr);
|
1997-10-07 00:56:58 +00:00
|
|
|
|
2000-08-28 22:44:54 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
radius_Account(&fp->bundle->radius, &fp->bundle->radacct,
|
|
|
|
fp->bundle->links, RAD_STOP, &ipcp->peer_ip, &ipcp->ifmask,
|
|
|
|
&ipcp->throughput);
|
|
|
|
#endif
|
|
|
|
|
1999-06-08 11:58:27 +00:00
|
|
|
/*
|
|
|
|
* XXX this stuff should really live in the FSM. Our config should
|
|
|
|
* associate executable sections in files with events.
|
|
|
|
*/
|
2001-08-14 16:05:52 +00:00
|
|
|
if (system_Select(fp->bundle, addr, LINKDOWNFILE, NULL, NULL) < 0) {
|
1999-06-08 11:58:27 +00:00
|
|
|
if (bundle_GetLabel(fp->bundle)) {
|
|
|
|
if (system_Select(fp->bundle, bundle_GetLabel(fp->bundle),
|
|
|
|
LINKDOWNFILE, NULL, NULL) < 0)
|
|
|
|
system_Select(fp->bundle, "MYADDR", LINKDOWNFILE, NULL, NULL);
|
|
|
|
} else
|
|
|
|
system_Select(fp->bundle, "MYADDR", LINKDOWNFILE, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
ipcp_Setup(ipcp, INADDR_NONE);
|
|
|
|
}
|
|
|
|
recursing--;
|
1998-05-21 21:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ipcp_InterfaceUp(struct ipcp *ipcp)
|
|
|
|
{
|
2001-08-14 16:05:52 +00:00
|
|
|
if (!ipcp_SetIPaddress(ipcp, ipcp->my_ip, ipcp->peer_ip)) {
|
1998-06-16 19:40:42 +00:00
|
|
|
log_Printf(LogERROR, "ipcp_InterfaceUp: unable to set ip address\n");
|
1998-05-21 21:49:08 +00:00
|
|
|
return 0;
|
1997-05-10 01:22:19 +00:00
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
|
2001-05-11 23:42:03 +00:00
|
|
|
if (!iface_SetFlags(ipcp->fsm.bundle->iface->name, IFF_UP)) {
|
|
|
|
log_Printf(LogERROR, "ipcp_InterfaceUp: Can't set the IFF_UP flag on %s\n",
|
|
|
|
ipcp->fsm.bundle->iface->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-08-19 18:15:52 +00:00
|
|
|
#ifndef NONAT
|
|
|
|
if (ipcp->fsm.bundle->NatEnabled)
|
1998-06-27 14:17:28 +00:00
|
|
|
PacketAliasSetAddress(ipcp->my_ip);
|
1997-11-22 03:37:54 +00:00
|
|
|
#endif
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
return 1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
static int
|
|
|
|
IpcpLayerUp(struct fsm *fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
/* We're now up */
|
|
|
|
struct ipcp *ipcp = fsm2ipcp(fp);
|
1998-10-22 02:32:50 +00:00
|
|
|
char tbuff[16];
|
1998-05-21 21:49:08 +00:00
|
|
|
|
1998-06-27 23:48:54 +00:00
|
|
|
log_Printf(LogIPCP, "%s: LayerUp.\n", fp->link->name);
|
1998-10-22 02:32:50 +00:00
|
|
|
snprintf(tbuff, sizeof tbuff, "%s", inet_ntoa(ipcp->my_ip));
|
|
|
|
log_Printf(LogIPCP, "myaddr %s hisaddr = %s\n",
|
|
|
|
tbuff, inet_ntoa(ipcp->peer_ip));
|
1998-05-21 21:49:08 +00:00
|
|
|
|
|
|
|
if (ipcp->peer_compproto >> 16 == PROTO_VJCOMP)
|
|
|
|
sl_compress_init(&ipcp->vj.cslc, (ipcp->peer_compproto >> 8) & 255);
|
|
|
|
|
|
|
|
if (!ipcp_InterfaceUp(ipcp))
|
|
|
|
return 0;
|
|
|
|
|
2000-08-28 22:44:54 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
radius_Account(&fp->bundle->radius, &fp->bundle->radacct, fp->bundle->links,
|
|
|
|
RAD_START, &ipcp->peer_ip, &ipcp->ifmask, &ipcp->throughput);
|
|
|
|
#endif
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
/*
|
|
|
|
* XXX this stuff should really live in the FSM. Our config should
|
|
|
|
* associate executable sections in files with events.
|
|
|
|
*/
|
1998-10-22 02:32:50 +00:00
|
|
|
if (system_Select(fp->bundle, tbuff, LINKUPFILE, NULL, NULL) < 0) {
|
1998-05-21 21:49:08 +00:00
|
|
|
if (bundle_GetLabel(fp->bundle)) {
|
|
|
|
if (system_Select(fp->bundle, bundle_GetLabel(fp->bundle),
|
1998-06-15 19:05:51 +00:00
|
|
|
LINKUPFILE, NULL, NULL) < 0)
|
|
|
|
system_Select(fp->bundle, "MYADDR", LINKUPFILE, NULL, NULL);
|
1998-05-21 21:49:08 +00:00
|
|
|
} else
|
1998-06-15 19:05:51 +00:00
|
|
|
system_Select(fp->bundle, "MYADDR", LINKUPFILE, NULL, NULL);
|
1998-05-21 21:49:08 +00:00
|
|
|
}
|
|
|
|
|
Allow control over the number of ConfigREQ & TermREQ attempts
that are made in each of the FSMs (LCP, CCP & IPCP) and the
number of REQs/Challenges for PAP/CHAP by accepting more arguments
in the ``set {c,ip,l}cpretry'' and ``set {ch,p}apretry'' commands.
Change the non-convergence thresholds to 3 times the number of configured
REQ tries (rather than the previous fixed ``10''). We now notice
repeated NAKs and REJs rather than just REQs.
Don't suggest that CHAP 0x05 isn't supported when it's not configured.
Fix some bugs that expose themselves with smaller numbers of retries:
o Handle instantaneous disconnects (set device /dev/null) correctly
by stopping all fsm timers in fsm2initial.
o Don't forget to uu_unlock() devices that are files but are not
ttys (set device /dev/zero).
Fix a *HORRENDOUS* bug in RFC1661 (already fixed for an Open event in state
``Closed''):
According to the state transition table, a RCR+ or RCR- received in
the ``Stopped'' state are supposed to InitRestartCounter, SendConfigReq
and SendConfig{Ack,Nak}. However, in ``Stopped'', we haven't yet
done a TLS (or the last thing we did is a TLF). We must therefore
do the TLS at this point !
This was never noticed before because LCP and CCP used not use
LayerStart() for anything interesting, and IPCP tends to go into
Stopped then get a Down because of an LCP RTR rather than getting a
RCR again.
1999-02-26 21:28:14 +00:00
|
|
|
fp->more.reqs = fp->more.naks = fp->more.rejs = ipcp->cfg.fsm.maxreq * 3;
|
1998-05-23 22:24:50 +00:00
|
|
|
log_DisplayPrompts();
|
Allow control over the number of ConfigREQ & TermREQ attempts
that are made in each of the FSMs (LCP, CCP & IPCP) and the
number of REQs/Challenges for PAP/CHAP by accepting more arguments
in the ``set {c,ip,l}cpretry'' and ``set {ch,p}apretry'' commands.
Change the non-convergence thresholds to 3 times the number of configured
REQ tries (rather than the previous fixed ``10''). We now notice
repeated NAKs and REJs rather than just REQs.
Don't suggest that CHAP 0x05 isn't supported when it's not configured.
Fix some bugs that expose themselves with smaller numbers of retries:
o Handle instantaneous disconnects (set device /dev/null) correctly
by stopping all fsm timers in fsm2initial.
o Don't forget to uu_unlock() devices that are files but are not
ttys (set device /dev/zero).
Fix a *HORRENDOUS* bug in RFC1661 (already fixed for an Open event in state
``Closed''):
According to the state transition table, a RCR+ or RCR- received in
the ``Stopped'' state are supposed to InitRestartCounter, SendConfigReq
and SendConfig{Ack,Nak}. However, in ``Stopped'', we haven't yet
done a TLS (or the last thing we did is a TLF). We must therefore
do the TLS at this point !
This was never noticed before because LCP and CCP used not use
LayerStart() for anything interesting, and IPCP tends to go into
Stopped then get a Down because of an LCP RTR rather than getting a
RCR again.
1999-02-26 21:28:14 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
return 1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
2001-05-22 09:03:30 +00:00
|
|
|
static void
|
|
|
|
ipcp_ValidateReq(struct ipcp *ipcp, struct in_addr ip, struct fsm_decode *dec)
|
|
|
|
{
|
|
|
|
struct bundle *bundle = ipcp->fsm.bundle;
|
|
|
|
struct iface *iface = bundle->iface;
|
2001-08-14 16:05:52 +00:00
|
|
|
struct in_addr myaddr, peer;
|
2001-05-22 09:03:30 +00:00
|
|
|
int n;
|
|
|
|
|
|
|
|
if (iplist_isvalid(&ipcp->cfg.peer_list)) {
|
2001-08-14 16:05:52 +00:00
|
|
|
ncprange_getip4addr(&ipcp->cfg.my_range, &myaddr);
|
2001-05-22 09:03:30 +00:00
|
|
|
if (ip.s_addr == INADDR_ANY ||
|
|
|
|
iplist_ip2pos(&ipcp->cfg.peer_list, ip) < 0 ||
|
2001-08-14 16:05:52 +00:00
|
|
|
!ipcp_SetIPaddress(ipcp, myaddr, ip)) {
|
2001-05-22 09:03:30 +00:00
|
|
|
log_Printf(LogIPCP, "%s: Address invalid or already in use\n",
|
|
|
|
inet_ntoa(ip));
|
|
|
|
/*
|
|
|
|
* If we've already had a valid address configured for the peer,
|
|
|
|
* try NAKing with that so that we don't have to upset things
|
|
|
|
* too much.
|
|
|
|
*/
|
2001-08-14 16:05:52 +00:00
|
|
|
for (n = 0; n < iface->addrs; n++) {
|
|
|
|
if (!ncpaddr_getip4(&iface->addr[n].peer, &peer))
|
|
|
|
continue;
|
|
|
|
if (iplist_ip2pos(&ipcp->cfg.peer_list, peer) >= 0) {
|
|
|
|
ipcp->peer_ip = peer;
|
2001-05-22 09:03:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-08-14 16:05:52 +00:00
|
|
|
}
|
2001-05-22 09:03:30 +00:00
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
if (n == iface->addrs) {
|
2001-05-22 09:03:30 +00:00
|
|
|
/* Just pick an IP number from our list */
|
2001-08-14 16:05:52 +00:00
|
|
|
ipcp->peer_ip = ChooseHisAddr(bundle, myaddr);
|
|
|
|
}
|
2001-05-22 09:03:30 +00:00
|
|
|
|
|
|
|
if (ipcp->peer_ip.s_addr == INADDR_ANY) {
|
|
|
|
*dec->rejend++ = TY_IPADDR;
|
|
|
|
*dec->rejend++ = 6;
|
|
|
|
memcpy(dec->rejend, &ip.s_addr, 4);
|
|
|
|
dec->rejend += 4;
|
|
|
|
} else {
|
|
|
|
*dec->nakend++ = TY_IPADDR;
|
|
|
|
*dec->nakend++ = 6;
|
|
|
|
memcpy(dec->nakend, &ipcp->peer_ip.s_addr, 4);
|
|
|
|
dec->nakend += 4;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2001-08-14 16:05:52 +00:00
|
|
|
} else if (!ncprange_containsip4(&ipcp->cfg.peer_range, ip)) {
|
2001-05-22 09:03:30 +00:00
|
|
|
/*
|
|
|
|
* If the destination address is not acceptable, NAK with what we
|
|
|
|
* want to use.
|
|
|
|
*/
|
|
|
|
*dec->nakend++ = TY_IPADDR;
|
|
|
|
*dec->nakend++ = 6;
|
2001-08-14 16:05:52 +00:00
|
|
|
for (n = 0; n < iface->addrs; n++)
|
|
|
|
if (ncprange_contains(&ipcp->cfg.peer_range, &iface->addr[n].peer)) {
|
2001-05-22 09:03:30 +00:00
|
|
|
/* We prefer the already-configured address */
|
2001-08-14 16:05:52 +00:00
|
|
|
ncpaddr_getip4addr(&iface->addr[n].peer, (u_int32_t *)dec->nakend);
|
2001-05-22 09:03:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
if (n == iface->addrs)
|
2001-05-22 09:03:30 +00:00
|
|
|
memcpy(dec->nakend, &ipcp->peer_ip.s_addr, 4);
|
|
|
|
|
|
|
|
dec->nakend += 4;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ipcp->peer_ip = ip;
|
|
|
|
*dec->ackend++ = TY_IPADDR;
|
|
|
|
*dec->ackend++ = 6;
|
|
|
|
memcpy(dec->ackend, &ip.s_addr, 4);
|
|
|
|
dec->ackend += 4;
|
|
|
|
}
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
static void
|
1999-05-09 20:02:29 +00:00
|
|
|
IpcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
|
1998-05-21 21:49:08 +00:00
|
|
|
struct fsm_decode *dec)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
/* Deal with incoming PROTO_IPCP */
|
2001-08-14 16:05:52 +00:00
|
|
|
struct ncpaddr ncpaddr;
|
1998-05-21 21:49:08 +00:00
|
|
|
struct ipcp *ipcp = fsm2ipcp(fp);
|
2001-07-28 11:32:08 +00:00
|
|
|
int type, length, gotdnsnak;
|
1998-05-21 21:49:08 +00:00
|
|
|
u_int32_t compproto;
|
1995-01-31 06:29:58 +00:00
|
|
|
struct compreq *pcomp;
|
2000-03-14 01:47:27 +00:00
|
|
|
struct in_addr ipaddr, dstipaddr, have_ip;
|
1998-05-21 21:49:08 +00:00
|
|
|
char tbuff[100], tbuff2[100];
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
gotdnsnak = 0;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
while (plen >= sizeof(struct fsmconfig)) {
|
|
|
|
type = *cp;
|
|
|
|
length = cp[1];
|
1998-05-21 21:49:08 +00:00
|
|
|
|
|
|
|
if (length == 0) {
|
|
|
|
log_Printf(LogIPCP, "%s: IPCP size zero\n", fp->link->name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-03-14 01:46:54 +00:00
|
|
|
snprintf(tbuff, sizeof tbuff, " %s[%d] ", protoname(type), length);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case TY_IPADDR: /* RFC1332 */
|
1998-09-04 18:26:00 +00:00
|
|
|
memcpy(&ipaddr.s_addr, cp + 2, 4);
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(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:
|
2001-07-28 11:32:08 +00:00
|
|
|
ipcp->peer_req = 1;
|
2001-05-22 09:03:30 +00:00
|
|
|
ipcp_ValidateReq(ipcp, ipaddr, dec);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
1998-10-22 02:32:50 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
case MODE_NAK:
|
2001-08-14 16:05:52 +00:00
|
|
|
if (ncprange_containsip4(&ipcp->cfg.my_range, ipaddr)) {
|
1997-12-13 02:37:33 +00:00
|
|
|
/* Use address suggested by peer */
|
1997-12-24 09:29:17 +00:00
|
|
|
snprintf(tbuff2, sizeof tbuff2, "%s changing address: %s ", tbuff,
|
1998-05-21 21:49:08 +00:00
|
|
|
inet_ntoa(ipcp->my_ip));
|
|
|
|
log_Printf(LogIPCP, "%s --> %s\n", tbuff2, inet_ntoa(ipaddr));
|
|
|
|
ipcp->my_ip = ipaddr;
|
2001-08-14 16:05:52 +00:00
|
|
|
ncpaddr_setip4(&ncpaddr, ipcp->my_ip);
|
|
|
|
bundle_AdjustFilters(fp->bundle, &ncpaddr, NULL);
|
1997-12-13 02:37:33 +00:00
|
|
|
} else {
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(log_IsKept(LogIPCP) ? LogIPCP : LogPHASE,
|
|
|
|
"%s: Unacceptable address!\n", inet_ntoa(ipaddr));
|
|
|
|
fsm_Close(&ipcp->fsm);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
1998-10-22 02:32:50 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
case MODE_REJ:
|
1998-05-21 21:49:08 +00:00
|
|
|
ipcp->peer_reject |= (1 << type);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1998-10-22 02:32:50 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
case TY_COMPPROTO:
|
1999-02-02 20:27:12 +00:00
|
|
|
pcomp = (struct compreq *)(cp + 2);
|
|
|
|
compproto = (ntohs(pcomp->proto) << 16) + (pcomp->slots << 8) +
|
|
|
|
pcomp->compcid;
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(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:
|
1998-05-21 21:49:08 +00:00
|
|
|
if (!IsAccepted(ipcp->cfg.vj.neg)) {
|
|
|
|
memcpy(dec->rejend, cp, length);
|
|
|
|
dec->rejend += length;
|
1995-01-31 06:29:58 +00:00
|
|
|
} else {
|
|
|
|
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) {
|
1999-02-02 20:27:12 +00:00
|
|
|
log_Printf(LogWARN, "Peer is speaking RFC1172 compression "
|
|
|
|
"protocol !\n");
|
1998-05-21 21:49:08 +00:00
|
|
|
ipcp->heis1172 = 1;
|
|
|
|
ipcp->peer_compproto = compproto;
|
|
|
|
memcpy(dec->ackend, cp, length);
|
|
|
|
dec->ackend += length;
|
1995-01-31 06:29:58 +00:00
|
|
|
} else {
|
1998-05-21 21:49:08 +00:00
|
|
|
memcpy(dec->nakend, cp, 2);
|
1995-01-31 06:29:58 +00:00
|
|
|
pcomp->proto = htons(PROTO_VJCOMP);
|
1998-05-21 21:49:08 +00:00
|
|
|
memcpy(dec->nakend+2, &pcomp, 2);
|
|
|
|
dec->nakend += length;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
1997-08-25 00:29:32 +00:00
|
|
|
case 6: /* RFC1332 */
|
1999-02-02 20:27:12 +00:00
|
|
|
if (ntohs(pcomp->proto) == PROTO_VJCOMP) {
|
|
|
|
if (pcomp->slots <= MAX_VJ_STATES
|
|
|
|
&& pcomp->slots >= MIN_VJ_STATES) {
|
|
|
|
/* Ok, we can do that */
|
|
|
|
ipcp->peer_compproto = compproto;
|
|
|
|
ipcp->heis1172 = 0;
|
|
|
|
memcpy(dec->ackend, cp, length);
|
|
|
|
dec->ackend += length;
|
|
|
|
} else {
|
|
|
|
/* Get as close as we can to what he wants */
|
|
|
|
ipcp->heis1172 = 0;
|
|
|
|
memcpy(dec->nakend, cp, 2);
|
|
|
|
pcomp->slots = pcomp->slots < MIN_VJ_STATES ?
|
|
|
|
MIN_VJ_STATES : MAX_VJ_STATES;
|
|
|
|
memcpy(dec->nakend+2, &pcomp, sizeof pcomp);
|
|
|
|
dec->nakend += length;
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
} else {
|
1999-02-02 20:27:12 +00:00
|
|
|
/* What we really want */
|
1998-05-21 21:49:08 +00:00
|
|
|
memcpy(dec->nakend, cp, 2);
|
1995-01-31 06:29:58 +00:00
|
|
|
pcomp->proto = htons(PROTO_VJCOMP);
|
1998-05-21 21:49:08 +00:00
|
|
|
pcomp->slots = DEF_VJ_STATES;
|
1999-02-02 20:27:12 +00:00
|
|
|
pcomp->compcid = 1;
|
1998-05-21 21:49:08 +00:00
|
|
|
memcpy(dec->nakend+2, &pcomp, sizeof pcomp);
|
|
|
|
dec->nakend += length;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
1998-05-21 21:49:08 +00:00
|
|
|
memcpy(dec->rejend, cp, length);
|
|
|
|
dec->rejend += length;
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
1998-10-22 02:32:50 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
case MODE_NAK:
|
1999-02-02 20:27:12 +00:00
|
|
|
if (ntohs(pcomp->proto) == PROTO_VJCOMP) {
|
|
|
|
if (pcomp->slots > MAX_VJ_STATES)
|
|
|
|
pcomp->slots = MAX_VJ_STATES;
|
|
|
|
else if (pcomp->slots < MIN_VJ_STATES)
|
|
|
|
pcomp->slots = MIN_VJ_STATES;
|
|
|
|
compproto = (ntohs(pcomp->proto) << 16) + (pcomp->slots << 8) +
|
|
|
|
pcomp->compcid;
|
|
|
|
} else
|
|
|
|
compproto = 0;
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(LogIPCP, "%s changing compproto: %08x --> %08x\n",
|
|
|
|
tbuff, ipcp->my_compproto, compproto);
|
1999-02-02 20:27:12 +00:00
|
|
|
ipcp->my_compproto = compproto;
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
1998-10-22 02:32:50 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
case MODE_REJ:
|
1998-05-21 21:49:08 +00:00
|
|
|
ipcp->peer_reject |= (1 << type);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1998-10-22 02:32:50 +00:00
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
case TY_IPADDRS: /* RFC1172 */
|
1998-09-04 18:26:00 +00:00
|
|
|
memcpy(&ipaddr.s_addr, cp + 2, 4);
|
|
|
|
memcpy(&dstipaddr.s_addr, cp + 6, 4);
|
1997-12-24 09:29:17 +00:00
|
|
|
snprintf(tbuff2, sizeof tbuff2, "%s %s,", tbuff, inet_ntoa(ipaddr));
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(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:
|
1999-05-08 11:07:56 +00:00
|
|
|
memcpy(dec->rejend, cp, length);
|
|
|
|
dec->rejend += length;
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
1998-10-22 02:32:50 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
case MODE_NAK:
|
|
|
|
case MODE_REJ:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1996-10-06 13:32:37 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
case TY_PRIMARY_DNS: /* DNS negotiation (rfc1877) */
|
1996-10-06 13:32:37 +00:00
|
|
|
case TY_SECONDARY_DNS:
|
1998-09-04 18:26:00 +00:00
|
|
|
memcpy(&ipaddr.s_addr, cp + 2, 4);
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(LogIPCP, "%s %s\n", tbuff, inet_ntoa(ipaddr));
|
|
|
|
|
1997-11-08 00:28:11 +00:00
|
|
|
switch (mode_type) {
|
1996-10-06 13:32:37 +00:00
|
|
|
case MODE_REQ:
|
1998-05-21 21:49:08 +00:00
|
|
|
if (!IsAccepted(ipcp->cfg.ns.dns_neg)) {
|
|
|
|
ipcp->my_reject |= (1 << (type - TY_ADJUST_NS));
|
|
|
|
memcpy(dec->rejend, cp, length);
|
|
|
|
dec->rejend += length;
|
|
|
|
break;
|
|
|
|
}
|
2001-08-14 16:05:52 +00:00
|
|
|
have_ip = ipcp->ns.dns[type == TY_PRIMARY_DNS ? 0 : 1];
|
2000-03-14 01:47:27 +00:00
|
|
|
|
|
|
|
if (type == TY_PRIMARY_DNS && ipaddr.s_addr != have_ip.s_addr &&
|
2001-08-14 16:05:52 +00:00
|
|
|
ipaddr.s_addr == ipcp->ns.dns[1].s_addr) {
|
2000-03-14 01:47:27 +00:00
|
|
|
/* Swap 'em 'round */
|
2001-08-14 16:05:52 +00:00
|
|
|
ipcp->ns.dns[0] = ipcp->ns.dns[1];
|
|
|
|
ipcp->ns.dns[1] = have_ip;
|
|
|
|
have_ip = ipcp->ns.dns[0];
|
1998-05-21 21:49:08 +00:00
|
|
|
}
|
1997-08-25 00:29:32 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
if (ipaddr.s_addr != have_ip.s_addr) {
|
1996-10-06 13:32:37 +00:00
|
|
|
/*
|
1998-05-21 21:49:08 +00:00
|
|
|
* 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
|
|
|
*/
|
1998-05-21 21:49:08 +00:00
|
|
|
memcpy(dec->nakend, cp, 2); /* copy first two (type/length) */
|
|
|
|
memcpy(dec->nakend + 2, &have_ip.s_addr, length - 2);
|
|
|
|
dec->nakend += length;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Otherwise they have it right (this time) so we send a ack packet
|
|
|
|
* back confirming it... end of story
|
|
|
|
*/
|
|
|
|
memcpy(dec->ackend, cp, length);
|
|
|
|
dec->ackend += length;
|
|
|
|
}
|
1996-10-06 13:32:37 +00:00
|
|
|
break;
|
1998-10-22 02:32:50 +00:00
|
|
|
|
2000-03-14 01:47:27 +00:00
|
|
|
case MODE_NAK:
|
1998-05-21 21:49:08 +00:00
|
|
|
if (IsEnabled(ipcp->cfg.ns.dns_neg)) {
|
|
|
|
gotdnsnak = 1;
|
2001-08-14 16:05:52 +00:00
|
|
|
memcpy(&ipcp->ns.dns[type == TY_PRIMARY_DNS ? 0 : 1].s_addr,
|
|
|
|
cp + 2, 4);
|
1998-05-21 21:49:08 +00:00
|
|
|
}
|
1996-10-06 13:32:37 +00:00
|
|
|
break;
|
1998-10-22 02:32:50 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
case MODE_REJ: /* Can't do much, stop asking */
|
|
|
|
ipcp->peer_reject |= (1 << (type - TY_ADJUST_NS));
|
1996-10-06 13:32:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
case TY_PRIMARY_NBNS: /* M$ NetBIOS nameserver hack (rfc1877) */
|
1996-10-06 13:32:37 +00:00
|
|
|
case TY_SECONDARY_NBNS:
|
1998-09-04 18:26:00 +00:00
|
|
|
memcpy(&ipaddr.s_addr, cp + 2, 4);
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(LogIPCP, "%s %s\n", tbuff, inet_ntoa(ipaddr));
|
|
|
|
|
1997-11-08 00:28:11 +00:00
|
|
|
switch (mode_type) {
|
1996-10-06 13:32:37 +00:00
|
|
|
case MODE_REQ:
|
1998-05-21 21:49:08 +00:00
|
|
|
have_ip.s_addr =
|
|
|
|
ipcp->cfg.ns.nbns[type == TY_PRIMARY_NBNS ? 0 : 1].s_addr;
|
|
|
|
|
|
|
|
if (have_ip.s_addr == INADDR_ANY) {
|
|
|
|
log_Printf(LogIPCP, "NBNS REQ - rejected - nbns not set\n");
|
|
|
|
ipcp->my_reject |= (1 << (type - TY_ADJUST_NS));
|
|
|
|
memcpy(dec->rejend, cp, length);
|
|
|
|
dec->rejend += length;
|
1996-10-06 13:32:37 +00:00
|
|
|
break;
|
1998-05-21 21:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ipaddr.s_addr != have_ip.s_addr) {
|
|
|
|
memcpy(dec->nakend, cp, 2);
|
|
|
|
memcpy(dec->nakend+2, &have_ip.s_addr, length);
|
|
|
|
dec->nakend += length;
|
|
|
|
} else {
|
|
|
|
memcpy(dec->ackend, cp, length);
|
|
|
|
dec->ackend += length;
|
|
|
|
}
|
1996-10-06 13:32:37 +00:00
|
|
|
break;
|
1998-10-22 02:32:50 +00:00
|
|
|
|
1996-10-06 13:32:37 +00:00
|
|
|
case MODE_NAK:
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(LogIPCP, "MS NBNS req %d - NAK??\n", type);
|
1996-10-06 13:32:37 +00:00
|
|
|
break;
|
1998-10-22 02:32:50 +00:00
|
|
|
|
1996-10-06 13:32:37 +00:00
|
|
|
case MODE_REJ:
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(LogIPCP, "MS NBNS req %d - REJ??\n", type);
|
1996-10-06 13:32:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
default:
|
1998-05-21 21:49:08 +00:00
|
|
|
if (mode_type != MODE_NOP) {
|
|
|
|
ipcp->my_reject |= (1 << type);
|
|
|
|
memcpy(dec->rejend, cp, length);
|
|
|
|
dec->rejend += length;
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
plen -= length;
|
|
|
|
cp += length;
|
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
|
2000-03-14 01:47:27 +00:00
|
|
|
if (gotdnsnak) {
|
|
|
|
if (ipcp->ns.writable) {
|
|
|
|
log_Printf(LogDEBUG, "Updating resolver\n");
|
|
|
|
if (!ipcp_WriteDNS(ipcp)) {
|
|
|
|
ipcp->peer_reject |= (1 << (TY_PRIMARY_DNS - TY_ADJUST_NS));
|
|
|
|
ipcp->peer_reject |= (1 << (TY_SECONDARY_DNS - TY_ADJUST_NS));
|
|
|
|
} else
|
2001-08-14 16:05:52 +00:00
|
|
|
bundle_AdjustDNS(fp->bundle);
|
2000-03-14 01:47:27 +00:00
|
|
|
} else {
|
|
|
|
log_Printf(LogDEBUG, "Not updating resolver (readonly)\n");
|
2001-08-14 16:05:52 +00:00
|
|
|
bundle_AdjustDNS(fp->bundle);
|
1998-05-21 21:49:08 +00:00
|
|
|
}
|
2000-03-14 01:47:27 +00:00
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
|
|
|
|
if (mode_type != MODE_NOP) {
|
2001-07-28 11:32:08 +00:00
|
|
|
if (mode_type == MODE_REQ && !ipcp->peer_req) {
|
|
|
|
if (dec->rejend == dec->rej && dec->nakend == dec->nak) {
|
|
|
|
/*
|
|
|
|
* Pretend the peer has requested an IP.
|
|
|
|
* We do this to ensure that we only send one NAK if the only
|
|
|
|
* reason for the NAK is because the peer isn't sending a
|
|
|
|
* TY_IPADDR REQ. This stops us from repeatedly trying to tell
|
|
|
|
* the peer that we have to have an IP address on their end.
|
|
|
|
*/
|
|
|
|
ipcp->peer_req = 1;
|
|
|
|
}
|
2001-05-22 09:03:30 +00:00
|
|
|
ipaddr.s_addr = INADDR_ANY;
|
|
|
|
ipcp_ValidateReq(ipcp, ipaddr, dec);
|
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
if (dec->rejend != dec->rej) {
|
|
|
|
/* rejects are preferred */
|
|
|
|
dec->ackend = dec->ack;
|
|
|
|
dec->nakend = dec->nak;
|
|
|
|
} else if (dec->nakend != dec->nak)
|
|
|
|
/* then NAKs */
|
|
|
|
dec->ackend = dec->ack;
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
extern struct mbuf *
|
|
|
|
ipcp_Input(struct bundle *bundle, struct link *l, struct mbuf *bp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
/* Got PROTO_IPCP from link */
|
1999-12-20 20:29:47 +00:00
|
|
|
m_settype(bp, MB_IPCPIN);
|
1998-05-21 21:49:08 +00:00
|
|
|
if (bundle_Phase(bundle) == PHASE_NETWORK)
|
1999-05-08 11:07:56 +00:00
|
|
|
fsm_Input(&bundle->ncp.ipcp.fsm, bp);
|
1998-05-21 21:49:08 +00:00
|
|
|
else {
|
|
|
|
if (bundle_Phase(bundle) < PHASE_NETWORK)
|
|
|
|
log_Printf(LogIPCP, "%s: Error: Unexpected IPCP in phase %s (ignored)\n",
|
1999-05-08 11:07:56 +00:00
|
|
|
l->name, bundle_PhaseName(bundle));
|
1999-12-20 20:29:47 +00:00
|
|
|
m_freem(bp);
|
1998-05-21 21:49:08 +00:00
|
|
|
}
|
1999-05-08 11:07:56 +00:00
|
|
|
return NULL;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1998-01-05 01:35:20 +00:00
|
|
|
|
1999-01-28 01:56:34 +00:00
|
|
|
int
|
|
|
|
ipcp_UseHisIPaddr(struct bundle *bundle, struct in_addr hisaddr)
|
|
|
|
{
|
|
|
|
struct ipcp *ipcp = &bundle->ncp.ipcp;
|
2001-08-14 16:05:52 +00:00
|
|
|
struct in_addr myaddr;
|
1999-01-28 01:56:34 +00:00
|
|
|
|
|
|
|
memset(&ipcp->cfg.peer_range, '\0', sizeof ipcp->cfg.peer_range);
|
|
|
|
iplist_reset(&ipcp->cfg.peer_list);
|
2001-08-14 16:05:52 +00:00
|
|
|
ipcp->peer_ip = hisaddr;
|
|
|
|
ncprange_setip4host(&ipcp->cfg.peer_range, hisaddr);
|
|
|
|
ncprange_getip4addr(&ipcp->cfg.my_range, &myaddr);
|
1999-01-28 01:56:34 +00:00
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
return ipcp_SetIPaddress(ipcp, myaddr, hisaddr);
|
1999-01-28 01:56:34 +00:00
|
|
|
}
|
|
|
|
|
1998-01-05 01:35:20 +00:00
|
|
|
int
|
1998-05-21 21:49:08 +00:00
|
|
|
ipcp_UseHisaddr(struct bundle *bundle, const char *hisaddr, int setaddr)
|
1998-01-05 01:35:20 +00:00
|
|
|
{
|
2001-08-14 16:05:52 +00:00
|
|
|
struct in_addr myaddr;
|
|
|
|
struct ncp *ncp = &bundle->ncp;
|
|
|
|
struct ipcp *ipcp = &ncp->ipcp;
|
|
|
|
struct ncpaddr ncpaddr;
|
1998-05-21 21:49:08 +00:00
|
|
|
|
|
|
|
/* Use `hisaddr' for the peers address (set iface if `setaddr') */
|
|
|
|
memset(&ipcp->cfg.peer_range, '\0', sizeof ipcp->cfg.peer_range);
|
|
|
|
iplist_reset(&ipcp->cfg.peer_list);
|
1998-01-05 01:35:20 +00:00
|
|
|
if (strpbrk(hisaddr, ",-")) {
|
1998-05-21 21:49:08 +00:00
|
|
|
iplist_setsrc(&ipcp->cfg.peer_list, hisaddr);
|
|
|
|
if (iplist_isvalid(&ipcp->cfg.peer_list)) {
|
|
|
|
iplist_setrandpos(&ipcp->cfg.peer_list);
|
|
|
|
ipcp->peer_ip = ChooseHisAddr(bundle, ipcp->my_ip);
|
|
|
|
if (ipcp->peer_ip.s_addr == INADDR_ANY) {
|
|
|
|
log_Printf(LogWARN, "%s: None available !\n", ipcp->cfg.peer_list.src);
|
1999-05-31 23:57:40 +00:00
|
|
|
return 0;
|
1998-01-05 01:35:20 +00:00
|
|
|
}
|
2001-08-14 16:05:52 +00:00
|
|
|
ncprange_setip4host(&ipcp->cfg.peer_range, ipcp->peer_ip);
|
1998-01-05 01:35:20 +00:00
|
|
|
} else {
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(LogWARN, "%s: Invalid range !\n", hisaddr);
|
1998-01-05 01:35:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2001-08-14 16:05:52 +00:00
|
|
|
} else if (ncprange_aton(&ipcp->cfg.peer_range, ncp, hisaddr) != 0) {
|
|
|
|
if (ncprange_family(&ipcp->cfg.my_range) != AF_INET) {
|
|
|
|
log_Printf(LogWARN, "%s: Not an AF_INET address !\n", hisaddr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ncprange_getip4addr(&ipcp->cfg.my_range, &myaddr);
|
|
|
|
ncprange_getip4addr(&ipcp->cfg.peer_range, &ipcp->peer_ip);
|
1998-01-05 01:35:20 +00:00
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
if (setaddr && !ipcp_SetIPaddress(ipcp, myaddr, ipcp->peer_ip))
|
1998-01-05 01:35:20 +00:00
|
|
|
return 0;
|
|
|
|
} else
|
|
|
|
return 0;
|
|
|
|
|
2001-08-14 16:05:52 +00:00
|
|
|
ncpaddr_setip4(&ncpaddr, ipcp->peer_ip);
|
|
|
|
bundle_AdjustFilters(bundle, NULL, &ncpaddr);
|
1999-05-31 23:57:40 +00:00
|
|
|
|
|
|
|
return 1; /* Ok */
|
1998-01-05 01:35:20 +00:00
|
|
|
}
|
1999-03-03 23:00:41 +00:00
|
|
|
|
|
|
|
struct in_addr
|
|
|
|
addr2mask(struct in_addr addr)
|
|
|
|
{
|
|
|
|
u_int32_t haddr = ntohl(addr.s_addr);
|
|
|
|
|
|
|
|
haddr = IN_CLASSA(haddr) ? IN_CLASSA_NET :
|
|
|
|
IN_CLASSB(haddr) ? IN_CLASSB_NET :
|
|
|
|
IN_CLASSC_NET;
|
|
|
|
addr.s_addr = htonl(haddr);
|
|
|
|
|
|
|
|
return addr;
|
|
|
|
}
|
2001-08-14 16:05:52 +00:00
|
|
|
|
|
|
|
size_t
|
|
|
|
ipcp_QueueLen(struct ipcp *ipcp)
|
|
|
|
{
|
|
|
|
struct mqueue *q;
|
|
|
|
size_t result;
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
for (q = ipcp->Queue; q < ipcp->Queue + IPCP_QUEUES(ipcp); q++)
|
|
|
|
result += q->len;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ipcp_PushPacket(struct ipcp *ipcp, struct link *l)
|
|
|
|
{
|
|
|
|
struct bundle *bundle = ipcp->fsm.bundle;
|
|
|
|
struct mqueue *queue;
|
|
|
|
struct mbuf *bp;
|
|
|
|
int m_len;
|
|
|
|
u_int32_t secs = 0;
|
|
|
|
unsigned alivesecs = 0;
|
|
|
|
|
|
|
|
if (ipcp->fsm.state != ST_OPENED)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If ccp is not open but is required, do nothing.
|
|
|
|
*/
|
|
|
|
if (l->ccp.fsm.state != ST_OPENED && ccp_Required(&l->ccp)) {
|
|
|
|
log_Printf(LogPHASE, "%s: Not transmitting... waiting for CCP\n", l->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
queue = ipcp->Queue + IPCP_QUEUES(ipcp) - 1;
|
|
|
|
do {
|
|
|
|
if (queue->top) {
|
|
|
|
bp = m_dequeue(queue);
|
|
|
|
bp = mbuf_Read(bp, &secs, sizeof secs);
|
|
|
|
bp = m_pullup(bp);
|
|
|
|
m_len = m_length(bp);
|
|
|
|
if (!FilterCheck(MBUF_CTOP(bp), AF_INET, &bundle->filter.alive,
|
|
|
|
&alivesecs)) {
|
|
|
|
if (secs == 0)
|
|
|
|
secs = alivesecs;
|
|
|
|
bundle_StartIdleTimer(bundle, secs);
|
|
|
|
}
|
|
|
|
link_PushPacket(l, bp, bundle, 0, PROTO_IP);
|
|
|
|
ipcp_AddOutOctets(ipcp, m_len);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} while (queue-- != ipcp->Queue);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|