1995-01-31 06:29:58 +00:00
|
|
|
/*
|
|
|
|
* PPP IP Control Protocol (IPCP) Module
|
|
|
|
*
|
|
|
|
* Written by Toshiharu OHNO (tony-o@iij.ad.jp)
|
|
|
|
*
|
|
|
|
* Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that the above copyright notice and this paragraph are
|
|
|
|
* duplicated in all such forms and that any documentation,
|
|
|
|
* advertising materials, and other materials related to such
|
|
|
|
* distribution and use acknowledge that the software was developed
|
|
|
|
* by the Internet Initiative Japan, Inc. The name of the
|
|
|
|
* IIJ may not be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
1999-01-28 01:56:34 +00:00
|
|
|
* $Id: ipcp.c,v 1.68 1998/10/26 19:07:39 brian Exp $
|
1995-05-30 03:57:47 +00:00
|
|
|
*
|
1995-01-31 06:29:58 +00:00
|
|
|
* TODO:
|
1998-06-25 22:33:31 +00:00
|
|
|
* o More RFC1772 backward compatibility
|
1995-01-31 06:29:58 +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>
|
1998-10-26 19:07:39 +00:00
|
|
|
#include <net/route.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <netdb.h>
|
1998-02-07 20:50:08 +00:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <sys/sockio.h>
|
1998-04-28 01:25:46 +00:00
|
|
|
#include <sys/un.h>
|
1998-10-26 19:07:39 +00:00
|
|
|
#include <arpa/nameser.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
|
1998-04-17 22:05:37 +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>
|
1998-02-07 20:50:08 +00:00
|
|
|
#include <sys/errno.h>
|
1998-02-02 19:33:40 +00:00
|
|
|
#include <termios.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
1998-09-17 00:45:27 +00:00
|
|
|
#ifndef NOALIAS
|
|
|
|
#ifdef __OpenBSD__
|
|
|
|
#include "alias.h"
|
|
|
|
#else
|
|
|
|
#include <alias.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
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"
|
|
|
|
#include "lcpproto.h"
|
|
|
|
#include "lcp.h"
|
1997-12-13 02:37:33 +00:00
|
|
|
#include "iplist.h"
|
1998-01-29 23:11:44 +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"
|
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"
|
1997-10-26 01:04:02 +00:00
|
|
|
#include "vjcomp.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"
|
1999-01-28 01:56:34 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
#include "radius.h"
|
|
|
|
#endif
|
1998-04-03 19:21:56 +00:00
|
|
|
#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"
|
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-02-21 01:45:26 +00:00
|
|
|
#undef REJECTED
|
|
|
|
#define REJECTED(p, x) ((p)->peer_reject & (1<<(x)))
|
1998-04-17 22:05:37 +00:00
|
|
|
#define issep(ch) ((ch) == ' ' || (ch) == '\t')
|
|
|
|
#define isip(ch) (((ch) >= '0' && (ch) <= '9') || (ch) == '.')
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-01-29 23:11:44 +00:00
|
|
|
struct compreq {
|
|
|
|
u_short proto;
|
|
|
|
u_char slots;
|
|
|
|
u_char compcid;
|
|
|
|
};
|
1997-06-09 03:27:43 +00:00
|
|
|
|
1998-04-30 23:53:56 +00:00
|
|
|
static int IpcpLayerUp(struct fsm *);
|
1998-01-29 00:44:16 +00:00
|
|
|
static void IpcpLayerDown(struct fsm *);
|
1997-06-09 03:27:43 +00:00
|
|
|
static void IpcpLayerStart(struct fsm *);
|
|
|
|
static void IpcpLayerFinish(struct fsm *);
|
|
|
|
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 *);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-02-06 02:24:29 +00:00
|
|
|
static struct fsm_callbacks ipcp_Callbacks = {
|
1995-01-31 06:29:58 +00:00
|
|
|
IpcpLayerUp,
|
|
|
|
IpcpLayerDown,
|
|
|
|
IpcpLayerStart,
|
|
|
|
IpcpLayerFinish,
|
|
|
|
IpcpInitRestartCounter,
|
|
|
|
IpcpSendConfigReq,
|
1998-03-20 19:47:10 +00:00
|
|
|
IpcpSentTerminateReq,
|
1995-01-31 06:29:58 +00:00
|
|
|
IpcpSendTerminateAck,
|
|
|
|
IpcpDecodeConfig,
|
1998-05-01 19:26:12 +00:00
|
|
|
fsm_NullRecvResetReq,
|
|
|
|
fsm_NullRecvResetAck
|
1995-01-31 06:29:58 +00:00
|
|
|
};
|
|
|
|
|
1997-11-22 03:37:54 +00:00
|
|
|
static const char *cftypes[] = {
|
1997-11-14 15:39:15 +00:00
|
|
|
/* Check out the latest ``Assigned numbers'' rfc (rfc1700.txt) */
|
|
|
|
"???",
|
|
|
|
"IPADDRS", /* 1: IP-Addresses */ /* deprecated */
|
|
|
|
"COMPPROTO", /* 2: IP-Compression-Protocol */
|
|
|
|
"IPADDR", /* 3: IP-Address */
|
1995-01-31 06:29:58 +00:00
|
|
|
};
|
|
|
|
|
1997-12-24 09:29:17 +00:00
|
|
|
#define NCFTYPES (sizeof cftypes/sizeof cftypes[0])
|
1997-11-14 15:39:15 +00:00
|
|
|
|
1997-11-22 03:37:54 +00:00
|
|
|
static const char *cftypes128[] = {
|
1997-11-14 15:39:15 +00:00
|
|
|
/* Check out the latest ``Assigned numbers'' rfc (rfc1700.txt) */
|
|
|
|
"???",
|
|
|
|
"PRIDNS", /* 129: Primary DNS Server Address */
|
|
|
|
"PRINBNS", /* 130: Primary NBNS Server Address */
|
|
|
|
"SECDNS", /* 131: Secondary DNS Server Address */
|
|
|
|
"SECNBNS", /* 132: Secondary NBNS Server Address */
|
|
|
|
};
|
|
|
|
|
1997-12-24 09:29:17 +00:00
|
|
|
#define NCFTYPES128 (sizeof cftypes128/sizeof cftypes128[0])
|
1997-11-14 15:39:15 +00:00
|
|
|
|
1997-11-18 14:52:08 +00:00
|
|
|
void
|
1998-03-13 21:07:46 +00:00
|
|
|
ipcp_AddInOctets(struct ipcp *ipcp, int n)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-03-13 21:07:46 +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-03-13 21:07:46 +00:00
|
|
|
ipcp_AddOutOctets(struct ipcp *ipcp, int n)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-03-13 21:07:46 +00:00
|
|
|
throughput_addout(&ipcp->throughput, n);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1998-04-17 22:05:37 +00:00
|
|
|
static void
|
|
|
|
getdns(struct ipcp *ipcp, struct in_addr addr[2])
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-04-17 22:05:37 +00:00
|
|
|
FILE *fp;
|
1997-06-09 03:27:43 +00:00
|
|
|
|
1998-04-17 22:05:37 +00:00
|
|
|
addr[0].s_addr = addr[1].s_addr = INADDR_ANY;
|
|
|
|
if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
|
|
|
|
char buf[LINE_LEN], *cp, *end;
|
|
|
|
int n;
|
1997-11-18 14:52:08 +00:00
|
|
|
|
1998-04-17 22:05:37 +00:00
|
|
|
n = 0;
|
|
|
|
buf[sizeof buf - 1] = '\0';
|
|
|
|
while (fgets(buf, sizeof buf - 1, fp)) {
|
|
|
|
if (!strncmp(buf, "nameserver", 10) && issep(buf[10])) {
|
|
|
|
for (cp = buf + 11; issep(*cp); cp++)
|
|
|
|
;
|
|
|
|
for (end = cp; isip(*end); end++)
|
|
|
|
;
|
|
|
|
*end = '\0';
|
|
|
|
if (inet_aton(cp, addr+n) && ++n == 2)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (n == 1)
|
|
|
|
addr[1] = addr[0];
|
|
|
|
fclose(fp);
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1998-04-17 22:05:37 +00:00
|
|
|
static int
|
|
|
|
setdns(struct ipcp *ipcp, struct in_addr addr[2])
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-04-17 22:05:37 +00:00
|
|
|
FILE *fp;
|
|
|
|
char wbuf[LINE_LEN + 54];
|
|
|
|
int wlen;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-04-17 22:05:37 +00:00
|
|
|
if (addr[0].s_addr == INADDR_ANY || addr[1].s_addr == INADDR_ANY) {
|
|
|
|
struct in_addr old[2];
|
|
|
|
|
|
|
|
getdns(ipcp, old);
|
|
|
|
if (addr[0].s_addr == INADDR_ANY)
|
|
|
|
addr[0] = old[0];
|
|
|
|
if (addr[1].s_addr == INADDR_ANY)
|
|
|
|
addr[1] = old[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addr[0].s_addr == INADDR_ANY && addr[1].s_addr == INADDR_ANY) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "%s not modified: All nameservers NAKd\n",
|
1998-04-17 22:05:37 +00:00
|
|
|
_PATH_RESCONF);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
wlen = 0;
|
|
|
|
if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
|
|
|
|
char buf[LINE_LEN];
|
|
|
|
int len;
|
|
|
|
|
|
|
|
buf[sizeof buf - 1] = '\0';
|
|
|
|
while (fgets(buf, sizeof buf - 1, fp)) {
|
|
|
|
if (strncmp(buf, "nameserver", 10) || !issep(buf[10])) {
|
|
|
|
len = strlen(buf);
|
|
|
|
if (len > sizeof wbuf - wlen) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "%s: Can only cope with max file size %d\n",
|
1998-04-17 22:05:37 +00:00
|
|
|
_PATH_RESCONF, LINE_LEN);
|
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
memcpy(wbuf + wlen, buf, len);
|
|
|
|
wlen += len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addr[0].s_addr != INADDR_ANY) {
|
|
|
|
snprintf(wbuf + wlen, sizeof wbuf - wlen, "nameserver %s\n",
|
|
|
|
inet_ntoa(addr[0]));
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogIPCP, "Primary nameserver set to %s", wbuf + wlen + 11);
|
1998-04-17 22:05:37 +00:00
|
|
|
wlen += strlen(wbuf + wlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addr[1].s_addr != INADDR_ANY && addr[1].s_addr != addr[0].s_addr) {
|
|
|
|
snprintf(wbuf + wlen, sizeof wbuf - wlen, "nameserver %s\n",
|
|
|
|
inet_ntoa(addr[1]));
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogIPCP, "Secondary nameserver set to %s", wbuf + wlen + 11);
|
1998-04-17 22:05:37 +00:00
|
|
|
wlen += strlen(wbuf + wlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wlen) {
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
if ((fd = ID0open(_PATH_RESCONF, O_WRONLY|O_CREAT, 0644)) != -1) {
|
|
|
|
if (write(fd, wbuf, wlen) != wlen) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogERROR, "setdns: write(): %s\n", strerror(errno));
|
1998-04-17 22:05:37 +00:00
|
|
|
close(fd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (ftruncate(fd, wlen) == -1) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogERROR, "setdns: truncate(): %s\n", strerror(errno));
|
1998-04-17 22:05:37 +00:00
|
|
|
close(fd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
} else {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogERROR, "setdns: open(): %s\n", strerror(errno));
|
1998-04-17 22:05:37 +00:00
|
|
|
return 0;
|
1997-08-25 00:29:32 +00:00
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1998-04-17 22:05:37 +00:00
|
|
|
|
|
|
|
return 1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
int
|
1998-05-01 19:26:12 +00:00
|
|
|
ipcp_Show(struct cmdargs const *arg)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-05-05 23:30:13 +00:00
|
|
|
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) {
|
1998-04-16 00:26:21 +00:00
|
|
|
prompt_Printf(arg->prompt, " His side: %s, %s\n",
|
1998-05-05 23:30:13 +00:00
|
|
|
inet_ntoa(ipcp->peer_ip), vj2asc(ipcp->peer_compproto));
|
1998-04-16 00:26:21 +00:00
|
|
|
prompt_Printf(arg->prompt, " My side: %s, %s\n",
|
1998-05-05 23:30:13 +00:00
|
|
|
inet_ntoa(ipcp->my_ip), vj2asc(ipcp->my_compproto));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ipcp->route) {
|
|
|
|
prompt_Printf(arg->prompt, "\n");
|
1999-01-28 01:56:34 +00:00
|
|
|
route_ShowSticky(arg->prompt, ipcp->route, "Sticky routes", 1);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "\nDefaults:\n");
|
1998-04-25 00:09:14 +00:00
|
|
|
prompt_Printf(arg->prompt, " My Address: %s/%d",
|
1998-05-05 23:30:13 +00:00
|
|
|
inet_ntoa(ipcp->cfg.my_range.ipaddr), ipcp->cfg.my_range.width);
|
1998-04-25 00:09:14 +00:00
|
|
|
|
1998-05-05 23:30:13 +00:00
|
|
|
if (ipcp->cfg.HaveTriggerAddress)
|
1998-04-25 00:09:14 +00:00
|
|
|
prompt_Printf(arg->prompt, " (trigger with %s)",
|
1998-05-05 23:30:13 +00:00
|
|
|
inet_ntoa(ipcp->cfg.TriggerAddress));
|
1998-04-25 00:09:14 +00:00
|
|
|
prompt_Printf(arg->prompt, "\n VJ compression: %s (%d slots %s slot "
|
1998-05-05 23:30:13 +00:00
|
|
|
"compression)\n", command_ShowNegval(ipcp->cfg.vj.neg),
|
|
|
|
ipcp->cfg.vj.slots, ipcp->cfg.vj.slotcomp ? "with" : "without");
|
1998-04-25 00:09:14 +00:00
|
|
|
|
1998-05-05 23:30:13 +00:00
|
|
|
if (iplist_isvalid(&ipcp->cfg.peer_list))
|
1998-04-16 00:26:21 +00:00
|
|
|
prompt_Printf(arg->prompt, " His Address: %s\n",
|
1998-05-05 23:30:13 +00:00
|
|
|
ipcp->cfg.peer_list.src);
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
1998-04-16 00:26:21 +00:00
|
|
|
prompt_Printf(arg->prompt, " His Address: %s/%d\n",
|
1998-05-05 23:30:13 +00:00
|
|
|
inet_ntoa(ipcp->cfg.peer_range.ipaddr),
|
|
|
|
ipcp->cfg.peer_range.width);
|
1998-04-25 00:09:14 +00:00
|
|
|
|
1998-04-17 22:05:37 +00:00
|
|
|
prompt_Printf(arg->prompt, " DNS: %s, ",
|
1998-05-05 23:30:13 +00:00
|
|
|
inet_ntoa(ipcp->cfg.ns.dns[0]));
|
|
|
|
prompt_Printf(arg->prompt, "%s, %s\n", inet_ntoa(ipcp->cfg.ns.dns[1]),
|
|
|
|
command_ShowNegval(ipcp->cfg.ns.dns_neg));
|
1998-04-17 22:05:37 +00:00
|
|
|
prompt_Printf(arg->prompt, " NetBIOS NS: %s, ",
|
1998-05-05 23:30:13 +00:00
|
|
|
inet_ntoa(ipcp->cfg.ns.nbns[0]));
|
|
|
|
prompt_Printf(arg->prompt, "%s\n", inet_ntoa(ipcp->cfg.ns.nbns[1]));
|
1998-04-16 00:26:21 +00:00
|
|
|
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "\n");
|
1998-05-05 23:30:13 +00:00
|
|
|
throughput_disp(&ipcp->throughput, arg->prompt);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
1998-01-18 20:49:22 +00:00
|
|
|
|
|
|
|
int
|
1998-05-01 19:26:12 +00:00
|
|
|
ipcp_vjset(struct cmdargs const *arg)
|
1998-01-18 20:49:22 +00:00
|
|
|
{
|
1998-04-14 23:17:24 +00:00
|
|
|
if (arg->argc != arg->argn+2)
|
1998-01-18 20:49:22 +00:00
|
|
|
return -1;
|
1998-04-14 23:17:24 +00:00
|
|
|
if (!strcasecmp(arg->argv[arg->argn], "slots")) {
|
1998-01-18 20:49:22 +00:00
|
|
|
int slots;
|
|
|
|
|
1998-04-14 23:17:24 +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-04-16 00:26:21 +00:00
|
|
|
arg->bundle->ncp.ipcp.cfg.vj.slots = slots;
|
1998-01-18 20:49:22 +00:00
|
|
|
return 0;
|
1998-04-14 23:17:24 +00:00
|
|
|
} else if (!strcasecmp(arg->argv[arg->argn], "slotcomp")) {
|
|
|
|
if (!strcasecmp(arg->argv[arg->argn+1], "on"))
|
1998-04-16 00:26:21 +00:00
|
|
|
arg->bundle->ncp.ipcp.cfg.vj.slotcomp = 1;
|
1998-04-14 23:17:24 +00:00
|
|
|
else if (!strcasecmp(arg->argv[arg->argn+1], "off"))
|
1998-04-16 00:26:21 +00:00
|
|
|
arg->bundle->ncp.ipcp.cfg.vj.slotcomp = 0;
|
1998-01-18 20:49:22 +00:00
|
|
|
else
|
|
|
|
return 2;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
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-18 20:49:22 +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
|
|
|
|
1998-05-05 23:30:13 +00:00
|
|
|
ipcp->route = NULL;
|
1998-04-16 00:26:21 +00:00
|
|
|
ipcp->cfg.vj.slots = DEF_VJ_STATES;
|
|
|
|
ipcp->cfg.vj.slotcomp = 1;
|
1998-02-21 01:45:26 +00:00
|
|
|
memset(&ipcp->cfg.my_range, '\0', sizeof ipcp->cfg.my_range);
|
|
|
|
if (gethostname(name, sizeof name) == 0) {
|
|
|
|
hp = gethostbyname(name);
|
1998-10-22 02:32:50 +00:00
|
|
|
if (hp && hp->h_addrtype == AF_INET)
|
1998-02-21 01:45:26 +00:00
|
|
|
memcpy(&ipcp->cfg.my_range.ipaddr.s_addr, hp->h_addr, hp->h_length);
|
1998-01-18 20:49:22 +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-17 22:05:37 +00:00
|
|
|
ipcp->cfg.ns.dns[0].s_addr = INADDR_ANY;
|
|
|
|
ipcp->cfg.ns.dns[1].s_addr = INADDR_ANY;
|
|
|
|
ipcp->cfg.ns.dns_neg = 0;
|
|
|
|
ipcp->cfg.ns.nbns[0].s_addr = INADDR_ANY;
|
|
|
|
ipcp->cfg.ns.nbns[1].s_addr = INADDR_ANY;
|
1998-04-03 19:24:07 +00:00
|
|
|
|
|
|
|
ipcp->cfg.fsmretry = DEF_FSMRETRY;
|
1998-04-16 00:26:21 +00:00
|
|
|
ipcp->cfg.vj.neg = NEG_ENABLED|NEG_ACCEPTED;
|
1998-02-21 01:45:26 +00:00
|
|
|
|
1998-03-16 22:54:35 +00:00
|
|
|
memset(&ipcp->vj, '\0', sizeof ipcp->vj);
|
|
|
|
|
1998-04-21 01:02:32 +00:00
|
|
|
throughput_init(&ipcp->throughput);
|
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
|
|
|
}
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
void
|
1998-04-23 18:56:21 +00:00
|
|
|
ipcp_SetLink(struct ipcp *ipcp, struct link *l)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-04-23 18:56:21 +00:00
|
|
|
ipcp->fsm.link = l;
|
|
|
|
}
|
|
|
|
|
1998-02-21 01:45:26 +00:00
|
|
|
void
|
1999-01-28 01:56:34 +00:00
|
|
|
ipcp_Setup(struct ipcp *ipcp, u_int32_t mask)
|
1998-02-21 01:45:26 +00:00
|
|
|
{
|
1998-10-22 02:32:50 +00:00
|
|
|
struct iface *iface = ipcp->fsm.bundle->iface;
|
|
|
|
int pos, n;
|
1998-02-21 01:45:26 +00:00
|
|
|
|
|
|
|
ipcp->fsm.open_mode = 0;
|
1998-02-27 21:46:26 +00:00
|
|
|
ipcp->fsm.maxconfig = 10;
|
1999-01-28 01:56:34 +00:00
|
|
|
ipcp->ifmask.s_addr = mask == INADDR_NONE ? ipcp->cfg.netmask.s_addr : mask;
|
1998-02-21 01:45:26 +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 */
|
|
|
|
for (n = 0; n < iface->in_addrs; n++) {
|
|
|
|
pos = iplist_ip2pos(&ipcp->cfg.peer_list, iface->in_addr[n].brd);
|
|
|
|
if (pos != -1) {
|
|
|
|
ipcp->cfg.peer_range.ipaddr =
|
|
|
|
iplist_setcurpos(&ipcp->cfg.peer_list, pos);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (n == iface->in_addrs)
|
|
|
|
/* Ok, so none of 'em fit.... pick a random one */
|
1998-02-21 01:45:26 +00:00
|
|
|
ipcp->cfg.peer_range.ipaddr = iplist_setrandpos(&ipcp->cfg.peer_list);
|
1998-10-22 02:32:50 +00:00
|
|
|
|
1998-02-21 01:45:26 +00:00
|
|
|
ipcp->cfg.peer_range.mask.s_addr = INADDR_BROADCAST;
|
|
|
|
ipcp->cfg.peer_range.width = 32;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1995-07-08 08:28:10 +00:00
|
|
|
|
1998-02-21 01:45:26 +00:00
|
|
|
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-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogIPCP, "Using trigger address %s\n",
|
1998-02-21 01:45:26 +00:00
|
|
|
inet_ntoa(ipcp->cfg.TriggerAddress));
|
1998-10-22 02:32:50 +00:00
|
|
|
} else {
|
1998-04-03 19:25:07 +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
|
|
|
|
* connections that are bound to that IP (assuming we're not
|
|
|
|
* ``iface-alias''ing).
|
1998-04-03 19:25:07 +00:00
|
|
|
*/
|
1998-10-22 02:32:50 +00:00
|
|
|
for (n = 0; n < iface->in_addrs; n++)
|
|
|
|
if ((iface->in_addr[n].ifa.s_addr & ipcp->cfg.my_range.mask.s_addr) ==
|
|
|
|
(ipcp->cfg.my_range.ipaddr.s_addr & ipcp->cfg.my_range.mask.s_addr)) {
|
|
|
|
ipcp->my_ip = iface->in_addr[n].ifa;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (n == iface->in_addrs)
|
|
|
|
ipcp->my_ip = ipcp->cfg.my_range.ipaddr;
|
|
|
|
}
|
1998-01-29 23:11:44 +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-02-21 01:45:26 +00:00
|
|
|
ipcp->my_compproto = (PROTO_VJCOMP << 16) +
|
1998-04-16 00:26:21 +00:00
|
|
|
((ipcp->cfg.vj.slots - 1) << 8) +
|
|
|
|
ipcp->cfg.vj.slotcomp;
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
1998-02-21 01:45:26 +00:00
|
|
|
ipcp->my_compproto = 0;
|
1998-04-16 00:26:21 +00:00
|
|
|
sl_compress_init(&ipcp->vj.cslc, ipcp->cfg.vj.slots - 1);
|
1998-02-21 01:45:26 +00:00
|
|
|
|
|
|
|
ipcp->peer_reject = 0;
|
|
|
|
ipcp->my_reject = 0;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
1998-10-26 19:07:39 +00:00
|
|
|
static int
|
|
|
|
ipcp_doproxyall(struct bundle *bundle,
|
|
|
|
int (*proxyfun)(struct bundle *, struct in_addr, int), int s)
|
|
|
|
{
|
|
|
|
int n, ret;
|
|
|
|
struct sticky_route *rp;
|
|
|
|
struct in_addr addr;
|
|
|
|
struct ipcp *ipcp;
|
|
|
|
|
|
|
|
ipcp = &bundle->ncp.ipcp;
|
|
|
|
for (rp = ipcp->route; rp != NULL; rp = rp->next) {
|
|
|
|
if (ntohl(rp->mask.s_addr) == INADDR_BROADCAST)
|
|
|
|
continue;
|
|
|
|
n = INADDR_BROADCAST - ntohl(rp->mask.s_addr) - 1;
|
|
|
|
if (n > 0 && n <= 254 && rp->dst.s_addr != INADDR_ANY) {
|
|
|
|
addr = rp->dst;
|
|
|
|
while (n--) {
|
|
|
|
addr.s_addr = htonl(ntohl(addr.s_addr) + 1);
|
|
|
|
log_Printf(LogDEBUG, "ipcp_doproxyall: %s\n", inet_ntoa(addr));
|
|
|
|
ret = (*proxyfun)(bundle, addr, s);
|
|
|
|
if (!ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
1998-10-26 19:07:39 +00:00
|
|
|
static struct in_addr none = { INADDR_ANY };
|
1998-10-22 02:32:50 +00:00
|
|
|
struct in_addr mask, oaddr;
|
|
|
|
u_int32_t addr;
|
1998-02-07 20:50:08 +00:00
|
|
|
|
1998-10-22 02:32:50 +00:00
|
|
|
addr = htonl(myaddr.s_addr);
|
1999-01-28 01:56:34 +00:00
|
|
|
mask.s_addr = addr2mask(addr);
|
1998-02-07 20:50:08 +00:00
|
|
|
|
1999-01-28 01:56:34 +00:00
|
|
|
if (bundle->ncp.ipcp.ifmask.s_addr != INADDR_ANY &&
|
|
|
|
(ntohl(bundle->ncp.ipcp.ifmask.s_addr) & mask.s_addr) == mask.s_addr)
|
|
|
|
mask.s_addr = htonl(bundle->ncp.ipcp.ifmask.s_addr);
|
1998-10-22 02:32:50 +00:00
|
|
|
|
|
|
|
oaddr.s_addr = bundle->iface->in_addrs ?
|
|
|
|
bundle->iface->in_addr[0].ifa.s_addr : INADDR_ANY;
|
|
|
|
if (!iface_inAdd(bundle->iface, myaddr, mask, hisaddr,
|
|
|
|
IFACE_ADD_FIRST|IFACE_FORCE_ADD))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!Enabled(bundle, OPT_IFACEALIAS) && bundle->iface->in_addrs > 1
|
|
|
|
&& myaddr.s_addr != oaddr.s_addr)
|
|
|
|
/* Nuke the old one */
|
|
|
|
iface_inDelete(bundle->iface, oaddr);
|
1998-02-07 20:50:08 +00:00
|
|
|
|
1998-10-26 19:07:39 +00:00
|
|
|
if (bundle->ncp.ipcp.cfg.sendpipe > 0 || bundle->ncp.ipcp.cfg.recvpipe > 0)
|
|
|
|
bundle_SetRoute(bundle, RTM_CHANGE, hisaddr, myaddr, none, 0, 0);
|
|
|
|
|
1998-05-05 23:30:13 +00:00
|
|
|
if (Enabled(bundle, OPT_SROUTES))
|
|
|
|
route_Change(bundle, bundle->ncp.ipcp.route, myaddr, hisaddr);
|
|
|
|
|
1999-01-28 01:56:34 +00:00
|
|
|
#ifndef NORADIUS
|
|
|
|
if (bundle->radius.valid)
|
|
|
|
route_Change(bundle, bundle->radius.routes, myaddr, hisaddr);
|
|
|
|
#endif
|
|
|
|
|
1998-10-26 19:07:39 +00:00
|
|
|
if (Enabled(bundle, OPT_PROXY) || Enabled(bundle, OPT_PROXYALL)) {
|
1998-10-22 02:32:50 +00:00
|
|
|
int s = ID0socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
if (s < 0)
|
|
|
|
log_Printf(LogERROR, "ipcp_SetIPaddress: socket(): %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
else {
|
1998-10-26 19:07:39 +00:00
|
|
|
if (Enabled(bundle, OPT_PROXYALL))
|
|
|
|
ipcp_doproxyall(bundle, arp_SetProxy, s);
|
|
|
|
else if (Enabled(bundle, OPT_PROXY))
|
|
|
|
arp_SetProxy(bundle, hisaddr, s);
|
1998-10-22 02:32:50 +00:00
|
|
|
close(s);
|
|
|
|
}
|
|
|
|
}
|
1998-02-07 20:50:08 +00:00
|
|
|
|
1998-10-22 02:32:50 +00:00
|
|
|
return 0;
|
1998-02-07 20:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct in_addr
|
1998-10-22 02:32:50 +00:00
|
|
|
ChooseHisAddr(struct bundle *bundle, struct in_addr gw)
|
1998-02-07 20:50:08 +00:00
|
|
|
{
|
|
|
|
struct in_addr try;
|
1998-06-27 23:48:54 +00:00
|
|
|
u_long f;
|
1998-02-07 20:50:08 +00:00
|
|
|
|
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-06-27 23:48:54 +00:00
|
|
|
log_Printf(LogDEBUG, "ChooseHisAddr: Check item %ld (%s)\n",
|
1998-02-07 20:50:08 +00:00
|
|
|
f, inet_ntoa(try));
|
1998-03-13 21:08:05 +00:00
|
|
|
if (ipcp_SetIPaddress(bundle, gw, try, 1) == 0) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogIPCP, "Selected IP address %s\n", inet_ntoa(try));
|
1998-02-07 20:50:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-03-13 21:07:46 +00:00
|
|
|
if (f == bundle->ncp.ipcp.cfg.peer_list.nItems) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogDEBUG, "ChooseHisAddr: All addresses in use !\n");
|
1998-02-07 20:50:08 +00:00
|
|
|
try.s_addr = INADDR_ANY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return try;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-08-25 00:29:32 +00:00
|
|
|
IpcpInitRestartCounter(struct fsm * fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
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-08-07 18:42:51 +00:00
|
|
|
fp->restart = DEF_REQs;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-01-30 19:46:07 +00:00
|
|
|
IpcpSendConfigReq(struct fsm *fp)
|
1995-01-31 06:29:58 +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-04-17 22:05:37 +00:00
|
|
|
u_char buff[24];
|
1998-03-20 19:47:10 +00:00
|
|
|
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-05-01 19:26:12 +00:00
|
|
|
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-03-20 19:47:10 +00:00
|
|
|
INC_LCP_OPT(TY_IPADDR, 6, o);
|
1997-12-03 10:23:54 +00:00
|
|
|
}
|
|
|
|
|
1998-04-25 10:49:52 +00:00
|
|
|
if (ipcp->my_compproto && !REJECTED(ipcp, TY_COMPPROTO)) {
|
1998-02-06 02:24:29 +00:00
|
|
|
if (ipcp->heis1172) {
|
1998-09-04 18:26:00 +00:00
|
|
|
u_int16_t proto = PROTO_VJCOMP;
|
|
|
|
|
|
|
|
ua_htons(&proto, o->data);
|
1998-03-20 19:47:10 +00:00
|
|
|
INC_LCP_OPT(TY_COMPPROTO, 4, o);
|
1997-12-03 10:23:54 +00:00
|
|
|
} else {
|
1998-09-04 18:26:00 +00:00
|
|
|
ua_htonl(&ipcp->my_compproto, o->data);
|
1998-03-20 19:47:10 +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-03-20 19:47:10 +00:00
|
|
|
|
1998-04-17 22:05:37 +00:00
|
|
|
if (IsEnabled(ipcp->cfg.ns.dns_neg) &&
|
|
|
|
!REJECTED(ipcp, TY_PRIMARY_DNS - TY_ADJUST_NS) &&
|
|
|
|
!REJECTED(ipcp, TY_SECONDARY_DNS - TY_ADJUST_NS)) {
|
|
|
|
struct in_addr dns[2];
|
|
|
|
getdns(ipcp, dns);
|
1998-09-04 18:26:00 +00:00
|
|
|
memcpy(o->data, &dns[0].s_addr, 4);
|
1998-04-17 22:05:37 +00:00
|
|
|
INC_LCP_OPT(TY_PRIMARY_DNS, 6, o);
|
1998-09-04 18:26:00 +00:00
|
|
|
memcpy(o->data, &dns[1].s_addr, 4);
|
1998-04-17 22:05:37 +00:00
|
|
|
INC_LCP_OPT(TY_SECONDARY_DNS, 6, o);
|
|
|
|
}
|
|
|
|
|
1998-05-01 19:26:12 +00:00
|
|
|
fsm_Output(fp, CODE_CONFIGREQ, fp->reqid, buff, (u_char *)o - buff);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-03-20 19:47:10 +00:00
|
|
|
IpcpSentTerminateReq(struct fsm * fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Term REQ just sent by FSM */
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-03-20 19:47:10 +00:00
|
|
|
IpcpSendTerminateAck(struct fsm *fp, u_char id)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Send Term ACK please */
|
1998-05-01 19:26:12 +00:00
|
|
|
fsm_Output(fp, CODE_TERMACK, id, NULL, 0);
|
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-01-31 02:48:30 +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));
|
1998-02-07 20:50:08 +00:00
|
|
|
|
1998-05-29 18:32:11 +00:00
|
|
|
/* This is where we should be setting up the interface in AUTO mode */
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-02-07 20:50:08 +00:00
|
|
|
IpcpLayerFinish(struct fsm *fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +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
|
|
|
}
|
|
|
|
|
1998-02-08 19:29:45 +00:00
|
|
|
void
|
1998-05-01 19:26:12 +00:00
|
|
|
ipcp_CleanInterface(struct ipcp *ipcp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-10-22 02:32:50 +00:00
|
|
|
struct iface *iface = ipcp->fsm.bundle->iface;
|
1998-02-08 19:29:45 +00:00
|
|
|
|
1998-05-05 23:30:13 +00:00
|
|
|
route_Clean(ipcp->fsm.bundle, ipcp->route);
|
|
|
|
|
1998-10-26 19:07:39 +00:00
|
|
|
if (iface->in_addrs && (Enabled(ipcp->fsm.bundle, OPT_PROXY) ||
|
|
|
|
Enabled(ipcp->fsm.bundle, OPT_PROXYALL))) {
|
1998-10-22 02:32:50 +00:00
|
|
|
int s = ID0socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
|
if (s < 0)
|
|
|
|
log_Printf(LogERROR, "ipcp_CleanInterface: socket: %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
else {
|
1998-10-26 19:07:39 +00:00
|
|
|
if (Enabled(ipcp->fsm.bundle, OPT_PROXYALL))
|
|
|
|
ipcp_doproxyall(ipcp->fsm.bundle, arp_ClearProxy, s);
|
|
|
|
else if (Enabled(ipcp->fsm.bundle, OPT_PROXY))
|
|
|
|
arp_ClearProxy(ipcp->fsm.bundle, iface->in_addr[0].brd, s);
|
1998-10-22 02:32:50 +00:00
|
|
|
close(s);
|
|
|
|
}
|
1998-02-08 19:29:45 +00:00
|
|
|
}
|
|
|
|
|
1998-10-22 02:32:50 +00:00
|
|
|
iface_inClear(ipcp->fsm.bundle->iface, IFACE_CLEAR_ALL);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-02-06 02:24:29 +00:00
|
|
|
IpcpLayerDown(struct fsm *fp)
|
1995-01-31 06:29:58 +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;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-10-22 02:32:50 +00:00
|
|
|
if (ipcp->fsm.bundle->iface->in_addrs)
|
|
|
|
s = inet_ntoa(ipcp->fsm.bundle->iface->in_addr[0].ifa);
|
|
|
|
else
|
|
|
|
s = "Interface configuration error !";
|
1998-06-27 23:48:54 +00:00
|
|
|
log_Printf(LogIPCP, "%s: LayerDown: %s\n", fp->link->name, s);
|
1997-10-07 00:56:58 +00:00
|
|
|
|
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-06-15 19:05:51 +00:00
|
|
|
if (system_Select(fp->bundle, s, LINKDOWNFILE, NULL, NULL) < 0) {
|
1998-04-23 03:23:03 +00:00
|
|
|
if (bundle_GetLabel(fp->bundle)) {
|
1998-05-01 19:26:12 +00:00
|
|
|
if (system_Select(fp->bundle, bundle_GetLabel(fp->bundle),
|
1998-06-15 19:05:51 +00:00
|
|
|
LINKDOWNFILE, NULL, NULL) < 0)
|
|
|
|
system_Select(fp->bundle, "MYADDR", LINKDOWNFILE, NULL, NULL);
|
1998-02-07 20:50:08 +00:00
|
|
|
} else
|
1998-06-15 19:05:51 +00:00
|
|
|
system_Select(fp->bundle, "MYADDR", LINKDOWNFILE, NULL, NULL);
|
1998-04-25 10:49:52 +00:00
|
|
|
}
|
1997-10-07 00:56:58 +00:00
|
|
|
|
1999-01-28 01:56:34 +00:00
|
|
|
ipcp_Setup(ipcp, INADDR_NONE);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
1998-05-15 23:58:30 +00:00
|
|
|
int
|
|
|
|
ipcp_InterfaceUp(struct ipcp *ipcp)
|
|
|
|
{
|
|
|
|
if (ipcp_SetIPaddress(ipcp->fsm.bundle, ipcp->my_ip, ipcp->peer_ip, 0) < 0) {
|
1998-06-16 19:40:42 +00:00
|
|
|
log_Printf(LogERROR, "ipcp_InterfaceUp: unable to set ip address\n");
|
1998-05-15 23:58:30 +00:00
|
|
|
return 0;
|
1997-05-10 01:22:19 +00:00
|
|
|
}
|
1998-05-15 23:58:30 +00:00
|
|
|
|
1997-11-22 03:37:54 +00:00
|
|
|
#ifndef NOALIAS
|
1998-06-27 14:17:28 +00:00
|
|
|
if (ipcp->fsm.bundle->AliasEnabled)
|
|
|
|
PacketAliasSetAddress(ipcp->my_ip);
|
1997-11-22 03:37:54 +00:00
|
|
|
#endif
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-05-15 23:58:30 +00:00
|
|
|
return 1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1998-04-30 23:53:56 +00:00
|
|
|
static int
|
1998-02-02 19:32:16 +00:00
|
|
|
IpcpLayerUp(struct fsm *fp)
|
1995-01-31 06:29:58 +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-10-22 02:32:50 +00:00
|
|
|
char tbuff[16];
|
1998-01-29 00:44:16 +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-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-05-15 23:58:30 +00:00
|
|
|
if (!ipcp_InterfaceUp(ipcp))
|
1998-04-30 23:53:56 +00:00
|
|
|
return 0;
|
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-10-22 02:32:50 +00:00
|
|
|
if (system_Select(fp->bundle, tbuff, LINKUPFILE, NULL, NULL) < 0) {
|
1998-04-23 03:23:03 +00:00
|
|
|
if (bundle_GetLabel(fp->bundle)) {
|
1998-05-01 19:26:12 +00:00
|
|
|
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-02-07 20:50:08 +00:00
|
|
|
} else
|
1998-06-15 19:05:51 +00:00
|
|
|
system_Select(fp->bundle, "MYADDR", LINKUPFILE, NULL, NULL);
|
1998-04-25 10:49:52 +00:00
|
|
|
}
|
1998-02-07 20:50:08 +00:00
|
|
|
|
1998-05-23 22:24:50 +00:00
|
|
|
log_DisplayPrompts();
|
1998-04-30 23:53:56 +00:00
|
|
|
return 1;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
1998-10-22 02:32:50 +00:00
|
|
|
AcceptableAddr(const struct in_range *prange, struct in_addr ipaddr)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Is the given IP in the given range ? */
|
1997-05-10 15:37:40 +00:00
|
|
|
return (prange->ipaddr.s_addr & prange->mask.s_addr) ==
|
1997-08-25 00:29:32 +00:00
|
|
|
(ipaddr.s_addr & prange->mask.s_addr) && ipaddr.s_addr;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-03-13 21:08:05 +00:00
|
|
|
IpcpDecodeConfig(struct fsm *fp, u_char * cp, int plen, int mode_type,
|
|
|
|
struct fsm_decode *dec)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Deal with incoming PROTO_IPCP */
|
1998-10-22 02:32:50 +00:00
|
|
|
struct iface *iface = fp->bundle->iface;
|
1998-02-08 11:05:01 +00:00
|
|
|
struct ipcp *ipcp = fsm2ipcp(fp);
|
1998-10-22 02:32:50 +00:00
|
|
|
int type, length, gotdns, gotdnsnak, n;
|
1998-04-19 23:09:03 +00:00
|
|
|
u_int32_t compproto;
|
1995-01-31 06:29:58 +00:00
|
|
|
struct compreq *pcomp;
|
1998-04-17 22:05:37 +00:00
|
|
|
struct in_addr ipaddr, dstipaddr, have_ip, dns[2], dnsnak[2];
|
1998-03-13 21:08:05 +00:00
|
|
|
char tbuff[100], tbuff2[100];
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-04-17 22:05:37 +00:00
|
|
|
gotdns = 0;
|
|
|
|
gotdnsnak = 0;
|
|
|
|
dnsnak[0].s_addr = dnsnak[1].s_addr = INADDR_ANY;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
while (plen >= sizeof(struct fsmconfig)) {
|
|
|
|
type = *cp;
|
|
|
|
length = cp[1];
|
1998-04-24 19:15:48 +00:00
|
|
|
|
|
|
|
if (length == 0) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogIPCP, "%s: IPCP size zero\n", fp->link->name);
|
1998-04-24 19:15:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1997-11-14 15:39:15 +00:00
|
|
|
if (type < NCFTYPES)
|
1997-12-24 09:29:17 +00:00
|
|
|
snprintf(tbuff, sizeof tbuff, " %s[%d] ", cftypes[type], length);
|
1997-11-14 15:39:15 +00:00
|
|
|
else if (type > 128 && type < 128 + NCFTYPES128)
|
1997-12-24 09:29:17 +00:00
|
|
|
snprintf(tbuff, sizeof tbuff, " %s[%d] ", cftypes128[type-128], length);
|
1995-01-31 06:29:58 +00:00
|
|
|
else
|
1997-12-24 09:29:17 +00:00
|
|
|
snprintf(tbuff, sizeof tbuff, " <%d>[%d] ", 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-01 19:26:12 +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:
|
1998-02-21 01:45:26 +00:00
|
|
|
if (iplist_isvalid(&ipcp->cfg.peer_list)) {
|
1997-12-19 04:49:53 +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-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogIPCP, "%s: Address invalid or already in use\n",
|
1997-12-13 02:37:33 +00:00
|
|
|
inet_ntoa(ipaddr));
|
1998-10-22 02:32:50 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
for (n = 0; n < iface->in_addrs; n++)
|
|
|
|
if (iplist_ip2pos(&ipcp->cfg.peer_list, iface->in_addr[n].brd)
|
|
|
|
>=0) {
|
|
|
|
ipcp->peer_ip = iface->in_addr[n].brd;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n == iface->in_addrs)
|
1998-04-03 19:25:07 +00:00
|
|
|
/* 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;
|
1997-12-13 02:37:33 +00:00
|
|
|
} else {
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend, cp, 2);
|
1998-10-22 02:32:50 +00:00
|
|
|
memcpy(dec->nakend + 2, &ipcp->peer_ip.s_addr, length - 2);
|
1998-03-13 21:08:05 +00:00
|
|
|
dec->nakend += length;
|
1997-12-13 02:37:33 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1998-02-21 01:45:26 +00:00
|
|
|
} else if (!AcceptableAddr(&ipcp->cfg.peer_range, ipaddr)) {
|
1997-08-25 00:29:32 +00:00
|
|
|
/*
|
1998-04-03 19:25:07 +00:00
|
|
|
* If destination address is not acceptable, NAK with what we
|
1997-08-25 00:29:32 +00:00
|
|
|
* want to use.
|
|
|
|
*/
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend, cp, 2);
|
1998-10-22 02:32:50 +00:00
|
|
|
for (n = 0; n < iface->in_addrs; n++)
|
|
|
|
if ((iface->in_addr[n].brd.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, &iface->in_addr[n].brd.s_addr,
|
|
|
|
length - 2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n == iface->in_addrs)
|
|
|
|
memcpy(dec->nakend + 2, &ipcp->peer_ip.s_addr, length - 2);
|
|
|
|
|
1998-03-13 21:08:05 +00:00
|
|
|
dec->nakend += length;
|
1997-08-25 00:29:32 +00:00
|
|
|
break;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
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;
|
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:
|
1998-02-21 01:45:26 +00:00
|
|
|
if (AcceptableAddr(&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-02-21 01:45:26 +00:00
|
|
|
inet_ntoa(ipcp->my_ip));
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogIPCP, "%s --> %s\n", tbuff2, inet_ntoa(ipaddr));
|
1998-02-21 01:45:26 +00:00
|
|
|
ipcp->my_ip = ipaddr;
|
1997-12-13 02:37:33 +00:00
|
|
|
} else {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(log_IsKept(LogIPCP) ? LogIPCP : LogPHASE,
|
1998-04-03 19:25:07 +00:00
|
|
|
"%s: Unacceptable address!\n", inet_ntoa(ipaddr));
|
1998-05-01 19:26:12 +00:00
|
|
|
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-02-21 01:45:26 +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:
|
1998-09-04 18:26:00 +00:00
|
|
|
memcpy(&compproto, cp + 2, 4);
|
1998-05-01 19:26:12 +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-04-16 00:26:21 +00:00
|
|
|
if (!IsAccepted(ipcp->cfg.vj.neg)) {
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->rejend, cp, length);
|
|
|
|
dec->rejend += length;
|
1995-01-31 06:29:58 +00:00
|
|
|
} else {
|
1997-08-25 00:29:32 +00:00
|
|
|
pcomp = (struct compreq *) (cp + 2);
|
1995-01-31 06:29:58 +00:00
|
|
|
switch (length) {
|
1997-08-25 00:29:32 +00:00
|
|
|
case 4: /* RFC1172 */
|
1995-01-31 06:29:58 +00:00
|
|
|
if (ntohs(pcomp->proto) == PROTO_VJCOMP) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(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;
|
1995-01-31 06:29:58 +00:00
|
|
|
} else {
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend, cp, 2);
|
1995-01-31 06:29:58 +00:00
|
|
|
pcomp->proto = htons(PROTO_VJCOMP);
|
1998-03-13 21:08:05 +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 */
|
1995-01-31 06:29:58 +00:00
|
|
|
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;
|
1995-01-31 06:29:58 +00:00
|
|
|
} else {
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend, cp, 2);
|
1995-01-31 06:29:58 +00:00
|
|
|
pcomp->proto = htons(PROTO_VJCOMP);
|
1998-02-21 01:45:26 +00:00
|
|
|
pcomp->slots = DEF_VJ_STATES;
|
1995-01-31 06:29:58 +00:00
|
|
|
pcomp->compcid = 0;
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend+2, &pcomp, sizeof pcomp);
|
|
|
|
dec->nakend += length;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
1998-03-13 21:08:05 +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:
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogIPCP, "%s changing compproto: %08x --> %08x\n",
|
1998-02-21 01:45:26 +00:00
|
|
|
tbuff, ipcp->my_compproto, compproto);
|
|
|
|
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-02-21 01:45:26 +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-01 19:26:12 +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:
|
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;
|
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:
|
1997-12-24 09:29:17 +00:00
|
|
|
snprintf(tbuff2, sizeof tbuff2, "%s changing address: %s", tbuff,
|
1998-02-21 01:45:26 +00:00
|
|
|
inet_ntoa(ipcp->my_ip));
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogIPCP, "%s --> %s\n", tbuff2, inet_ntoa(ipaddr));
|
1998-02-21 01:45:26 +00:00
|
|
|
ipcp->my_ip = ipaddr;
|
|
|
|
ipcp->peer_ip = dstipaddr;
|
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-02-21 01:45:26 +00:00
|
|
|
ipcp->peer_reject |= (1 << type);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1996-10-06 13:32:37 +00:00
|
|
|
|
1998-04-17 22:05:37 +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-01 19:26:12 +00:00
|
|
|
log_Printf(LogIPCP, "%s %s\n", tbuff, inet_ntoa(ipaddr));
|
1998-04-17 22:05:37 +00:00
|
|
|
|
1997-11-08 00:28:11 +00:00
|
|
|
switch (mode_type) {
|
1996-10-06 13:32:37 +00:00
|
|
|
case MODE_REQ:
|
1998-04-17 22:05:37 +00:00
|
|
|
if (!IsAccepted(ipcp->cfg.ns.dns_neg)) {
|
|
|
|
ipcp->my_reject |= (1 << (type - TY_ADJUST_NS));
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->rejend, cp, length);
|
|
|
|
dec->rejend += length;
|
|
|
|
break;
|
|
|
|
}
|
1998-04-17 22:05:37 +00:00
|
|
|
if (!gotdns) {
|
|
|
|
dns[0] = ipcp->cfg.ns.dns[0];
|
|
|
|
dns[1] = ipcp->cfg.ns.dns[1];
|
|
|
|
if (dns[0].s_addr == INADDR_ANY && dns[1].s_addr == INADDR_ANY)
|
|
|
|
getdns(ipcp, dns);
|
|
|
|
gotdns = 1;
|
|
|
|
}
|
|
|
|
have_ip = dns[type == TY_PRIMARY_DNS ? 0 : 1];
|
1997-08-25 00:29:32 +00:00
|
|
|
|
1998-04-17 22:05:37 +00:00
|
|
|
if (ipaddr.s_addr != have_ip.s_addr) {
|
1996-10-06 13:32:37 +00:00
|
|
|
/*
|
1998-04-17 22:05:37 +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-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend, cp, 2); /* copy first two (type/length) */
|
1998-04-17 22:05:37 +00:00
|
|
|
memcpy(dec->nakend + 2, &have_ip.s_addr, length - 2);
|
1998-03-13 21:08:05 +00:00
|
|
|
dec->nakend += length;
|
1998-04-17 22:05:37 +00:00
|
|
|
} 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
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
case MODE_NAK: /* what does this mean?? */
|
1998-04-17 22:05:37 +00:00
|
|
|
if (IsEnabled(ipcp->cfg.ns.dns_neg)) {
|
|
|
|
gotdnsnak = 1;
|
1998-09-04 18:26:00 +00:00
|
|
|
memcpy(&dnsnak[type == TY_PRIMARY_DNS ? 0 : 1].s_addr, cp + 2, 4);
|
1998-04-17 22:05:37 +00:00
|
|
|
}
|
1996-10-06 13:32:37 +00:00
|
|
|
break;
|
1998-10-22 02:32:50 +00:00
|
|
|
|
1998-04-17 22:05:37 +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-04-17 22:05:37 +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-01 19:26:12 +00:00
|
|
|
log_Printf(LogIPCP, "%s %s\n", tbuff, inet_ntoa(ipaddr));
|
1998-04-17 22:05:37 +00:00
|
|
|
|
1997-11-08 00:28:11 +00:00
|
|
|
switch (mode_type) {
|
1996-10-06 13:32:37 +00:00
|
|
|
case MODE_REQ:
|
1998-04-17 22:05:37 +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) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogIPCP, "NBNS REQ - rejected - nbns not set\n");
|
1998-04-17 22:05:37 +00:00
|
|
|
ipcp->my_reject |= (1 << (type - TY_ADJUST_NS));
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->rejend, cp, length);
|
|
|
|
dec->rejend += length;
|
1996-10-06 13:32:37 +00:00
|
|
|
break;
|
1998-03-13 21:08:05 +00:00
|
|
|
}
|
1998-04-17 22:05:37 +00:00
|
|
|
|
|
|
|
if (ipaddr.s_addr != have_ip.s_addr) {
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->nakend, cp, 2);
|
1998-04-17 22:05:37 +00:00
|
|
|
memcpy(dec->nakend+2, &have_ip.s_addr, length);
|
1998-03-13 21:08:05 +00:00
|
|
|
dec->nakend += length;
|
1998-04-17 22:05:37 +00:00
|
|
|
} 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-01 19:26:12 +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-01 19:26:12 +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-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;
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
plen -= length;
|
|
|
|
cp += length;
|
|
|
|
}
|
1998-04-16 00:26:21 +00:00
|
|
|
|
1998-04-17 22:05:37 +00:00
|
|
|
if (gotdnsnak)
|
|
|
|
if (!setdns(ipcp, dnsnak)) {
|
|
|
|
ipcp->peer_reject |= (1 << (TY_PRIMARY_DNS - TY_ADJUST_NS));
|
|
|
|
ipcp->peer_reject |= (1 << (TY_SECONDARY_DNS - TY_ADJUST_NS));
|
|
|
|
}
|
|
|
|
|
1998-04-25 10:49:52 +00:00
|
|
|
if (mode_type != MODE_NOP) {
|
1998-04-16 00:26:21 +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;
|
1998-04-25 10:49:52 +00:00
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-05-21 01:26:10 +00:00
|
|
|
ipcp_Input(struct ipcp *ipcp, struct bundle *bundle, struct mbuf *bp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Got PROTO_IPCP from link */
|
1998-05-21 01:26:10 +00:00
|
|
|
if (bundle_Phase(bundle) == PHASE_NETWORK)
|
|
|
|
fsm_Input(&ipcp->fsm, bp);
|
|
|
|
else {
|
|
|
|
if (bundle_Phase(bundle) < PHASE_NETWORK)
|
|
|
|
log_Printf(LogIPCP, "%s: Error: Unexpected IPCP in phase %s (ignored)\n",
|
|
|
|
ipcp->fsm.link->name, bundle_PhaseName(bundle));
|
|
|
|
mbuf_Free(bp);
|
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
memset(&ipcp->cfg.peer_range, '\0', sizeof ipcp->cfg.peer_range);
|
|
|
|
iplist_reset(&ipcp->cfg.peer_list);
|
|
|
|
ipcp->peer_ip = ipcp->cfg.peer_range.ipaddr = hisaddr;
|
|
|
|
ipcp->cfg.peer_range.mask.s_addr = INADDR_BROADCAST;
|
|
|
|
ipcp->cfg.peer_range.width = 32;
|
|
|
|
|
|
|
|
if (ipcp_SetIPaddress(bundle, ipcp->cfg.my_range.ipaddr, hisaddr, 0) < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1; /* Ok */
|
|
|
|
}
|
|
|
|
|
1998-01-05 01:35:20 +00:00
|
|
|
int
|
1998-05-01 19:26:12 +00:00
|
|
|
ipcp_UseHisaddr(struct bundle *bundle, const char *hisaddr, int setaddr)
|
1998-01-05 01:35:20 +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-05 01:35:20 +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) {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "%s: None available !\n", ipcp->cfg.peer_list.src);
|
1998-01-05 01:35:20 +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-05 01:35:20 +00:00
|
|
|
} else {
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogWARN, "%s: Invalid range !\n", hisaddr);
|
1998-01-05 01:35:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1999-01-28 01:56:34 +00:00
|
|
|
} else if (ParseAddr(ipcp, hisaddr, &ipcp->cfg.peer_range.ipaddr,
|
1998-03-13 21:07:46 +00:00
|
|
|
&ipcp->cfg.peer_range.mask,
|
|
|
|
&ipcp->cfg.peer_range.width) != 0) {
|
|
|
|
ipcp->peer_ip.s_addr = ipcp->cfg.peer_range.ipaddr.s_addr;
|
1998-01-05 01:35:20 +00:00
|
|
|
|
1998-03-13 21:08:05 +00:00
|
|
|
if (setaddr && ipcp_SetIPaddress(bundle, ipcp->cfg.my_range.ipaddr,
|
1998-10-22 02:32:50 +00:00
|
|
|
ipcp->cfg.peer_range.ipaddr, 0) < 0)
|
1998-01-05 01:35:20 +00:00
|
|
|
return 0;
|
|
|
|
} else
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|