Create `struct bundle' - the top level control structure.
This structure will eventually contain a list of NCPs (currently only IPCP is supported) and a list of physical `struct link's. It will also derive from a struct link itself. Make ModemTimeout() static - it's way to dangerous to be called from outside ! Bump version to 1.9. Our first MP release should be 2.0.
This commit is contained in:
parent
7308ec6890
commit
7a6f872047
@ -1,9 +1,9 @@
|
||||
# $Id: Makefile,v 1.36.2.1 1998/01/29 00:49:10 brian Exp $
|
||||
# $Id: Makefile,v 1.36.2.2 1998/01/30 19:45:24 brian Exp $
|
||||
|
||||
PROG= ppp
|
||||
SRCS= arp.c async.c auth.c ccp.c chap.c chat.c command.c deflate.c \
|
||||
SRCS= arp.c async.c auth.c bundle.c ccp.c chap.c chat.c command.c deflate.c \
|
||||
defs.c filter.c fsm.c hdlc.c id.c ip.c ipcp.c iplist.c lcp.c \
|
||||
link.c log.c lqr.c main.c mbuf.c modem.c os.c pap.c phase.c physical.c \
|
||||
link.c log.c lqr.c main.c mbuf.c modem.c pap.c phase.c physical.c \
|
||||
pred.c route.c server.c sig.c slcompress.c systems.c throughput.c \
|
||||
timer.c tun.c vars.c vjcomp.c
|
||||
CFLAGS+=-Wall -Wpointer-arith
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: async.c,v 1.15.2.1 1998/01/29 00:49:10 brian Exp $
|
||||
* $Id: async.c,v 1.15.2.2 1998/01/30 19:45:25 brian Exp $
|
||||
*
|
||||
*/
|
||||
#include <sys/param.h>
|
||||
@ -179,7 +179,8 @@ AsyncDecode(u_char c)
|
||||
}
|
||||
|
||||
void
|
||||
AsyncInput(u_char *buff, int cnt, struct physical *physical)
|
||||
AsyncInput(struct bundle *bundle, u_char *buff, int cnt,
|
||||
struct physical *physical)
|
||||
{
|
||||
struct mbuf *bp;
|
||||
|
||||
@ -189,12 +190,12 @@ AsyncInput(u_char *buff, int cnt, struct physical *physical)
|
||||
bp = mballoc(cnt, MB_ASYNC);
|
||||
memcpy(MBUF_CTOP(bp), buff, cnt);
|
||||
bp->cnt = cnt;
|
||||
HdlcInput(bp, physical);
|
||||
HdlcInput(bundle, bp, physical);
|
||||
} else {
|
||||
while (cnt > 0) {
|
||||
bp = AsyncDecode(*buff++);
|
||||
if (bp)
|
||||
HdlcInput(bp, physical);
|
||||
HdlcInput(bundle, bp, physical);
|
||||
cnt--;
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,10 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: async.h,v 1.2.4.1 1998/01/29 00:49:11 brian Exp $
|
||||
* $Id: async.h,v 1.2.4.2 1998/01/30 19:45:25 brian Exp $
|
||||
*/
|
||||
|
||||
extern void AsyncInit(void);
|
||||
extern void SetLinkParams(struct lcpstate *);
|
||||
extern void AsyncOutput(int, struct mbuf *, int, struct link *);
|
||||
extern void AsyncInput(u_char *, int, struct physical *);
|
||||
extern void AsyncInput(struct bundle *, u_char *, int, struct physical *);
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: auth.c,v 1.27.2.2 1998/01/29 23:11:31 brian Exp $
|
||||
* $Id: auth.c,v 1.27.2.3 1998/01/30 19:45:26 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
* o Implement check against with registered IP addresses.
|
||||
@ -103,8 +103,8 @@ LocalAuthValidate(const char *fname, const char *system, const char *key)
|
||||
}
|
||||
|
||||
int
|
||||
AuthValidate(const char *fname, const char *system, const char *key,
|
||||
struct physical *physical)
|
||||
AuthValidate(struct bundle *bundle, const char *fname, const char *system,
|
||||
const char *key, struct physical *physical)
|
||||
{
|
||||
FILE *fp;
|
||||
int n;
|
||||
@ -127,10 +127,10 @@ AuthValidate(const char *fname, const char *system, const char *key,
|
||||
ExpandString(vector[1], passwd, sizeof passwd, 0);
|
||||
if (strcmp(passwd, key) == 0) {
|
||||
CloseSecret(fp);
|
||||
if (n > 2 && !UseHisaddr(vector[2], 1))
|
||||
if (n > 2 && !UseHisaddr(bundle, vector[2], 1))
|
||||
return (0);
|
||||
IpcpInit(physical2link(physical)); /* XXX defer this - we may join an
|
||||
* existing bundle ! */
|
||||
/* XXX This should be deferred - we may join an existing bundle ! */
|
||||
IpcpInit(bundle, physical2link(physical));
|
||||
if (n > 3)
|
||||
SetLabel(vector[3]);
|
||||
return (1); /* Valid */
|
||||
@ -142,8 +142,8 @@ AuthValidate(const char *fname, const char *system, const char *key,
|
||||
}
|
||||
|
||||
char *
|
||||
AuthGetSecret(const char *fname, const char *system, int len, int setaddr,
|
||||
struct physical *physical)
|
||||
AuthGetSecret(struct bundle *bundle, const char *fname, const char *system,
|
||||
int len, int setaddr, struct physical *physical)
|
||||
{
|
||||
FILE *fp;
|
||||
int n;
|
||||
@ -167,9 +167,9 @@ AuthGetSecret(const char *fname, const char *system, int len, int setaddr,
|
||||
if (setaddr)
|
||||
memset(&IpcpInfo.DefHisAddress, '\0', sizeof IpcpInfo.DefHisAddress);
|
||||
if (n > 2 && setaddr)
|
||||
if (UseHisaddr(vector[2], 1))
|
||||
IpcpInit(physical2link(physical)); /* XXX defer this - we may join
|
||||
* an existing bundle ! */
|
||||
if (UseHisaddr(bundle, vector[2], 1))
|
||||
/* XXX This should be deferred - we may join an existing bundle ! */
|
||||
IpcpInit(bundle, physical2link(physical));
|
||||
else
|
||||
return NULL;
|
||||
if (n > 3)
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: auth.h,v 1.10 1997/11/22 03:37:24 brian Exp $
|
||||
* $Id: auth.h,v 1.10.2.1 1998/01/29 00:49:12 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -40,7 +40,7 @@ extern LOCAL_AUTH_VALID LocalAuthValidate(const char *, const char *, const char
|
||||
extern void StopAuthTimer(struct authinfo *);
|
||||
extern void StartAuthChallenge(struct authinfo *, struct physical *);
|
||||
extern void LocalAuthInit(void);
|
||||
extern int AuthValidate(const char *, const char *, const char *,
|
||||
struct physical *);
|
||||
extern char *AuthGetSecret(const char *, const char *, int, int,
|
||||
struct physical *);
|
||||
extern int AuthValidate(struct bundle *, const char *, const char *,
|
||||
const char *, struct physical *);
|
||||
extern char *AuthGetSecret(struct bundle *, const char *, const char *, int,
|
||||
int, struct physical *);
|
||||
|
550
usr.sbin/ppp/bundle.c
Normal file
550
usr.sbin/ppp/bundle.c
Normal file
@ -0,0 +1,550 @@
|
||||
/*-
|
||||
* Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <net/route.h>
|
||||
#include <net/if_dl.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "command.h"
|
||||
#include "mbuf.h"
|
||||
#include "log.h"
|
||||
#include "id.h"
|
||||
#include "defs.h"
|
||||
#include "timer.h"
|
||||
#include "fsm.h"
|
||||
#include "iplist.h"
|
||||
#include "throughput.h"
|
||||
#include "ipcp.h"
|
||||
#include "bundle.h"
|
||||
#include "loadalias.h"
|
||||
#include "vars.h"
|
||||
#include "arp.h"
|
||||
#include "systems.h"
|
||||
#include "route.h"
|
||||
#include "lcp.h"
|
||||
#include "ccp.h"
|
||||
|
||||
static int
|
||||
bundle_SetIpDevice(struct bundle *bundle, struct in_addr myaddr,
|
||||
struct in_addr hisaddr, struct in_addr netmask, int silent)
|
||||
{
|
||||
struct sockaddr_in *sock_in;
|
||||
int s;
|
||||
u_long mask, addr;
|
||||
struct ifaliasreq ifra;
|
||||
|
||||
/* If given addresses are alreay set, then ignore this request */
|
||||
if (bundle->if_mine.s_addr == myaddr.s_addr &&
|
||||
bundle->if_peer.s_addr == hisaddr.s_addr)
|
||||
return 0;
|
||||
|
||||
s = ID0socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
LogPrintf(LogERROR, "SetIpDevice: socket(): %s\n", strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
memset(&ifra, '\0', sizeof ifra);
|
||||
strncpy(ifra.ifra_name, bundle->ifname, sizeof ifra.ifra_name - 1);
|
||||
ifra.ifra_name[sizeof ifra.ifra_name - 1] = '\0';
|
||||
|
||||
/* If different address has been set, then delete it first */
|
||||
if (bundle->if_mine.s_addr != INADDR_ANY ||
|
||||
bundle->if_peer.s_addr != INADDR_ANY)
|
||||
if (ID0ioctl(s, SIOCDIFADDR, &ifra) < 0) {
|
||||
LogPrintf(LogERROR, "SetIpDevice: ioctl(SIOCDIFADDR): %s\n",
|
||||
strerror(errno));
|
||||
close(s);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Set interface address */
|
||||
sock_in = (struct sockaddr_in *)&ifra.ifra_addr;
|
||||
sock_in->sin_family = AF_INET;
|
||||
sock_in->sin_addr = myaddr;
|
||||
sock_in->sin_len = sizeof *sock_in;
|
||||
|
||||
/* Set destination address */
|
||||
sock_in = (struct sockaddr_in *)&ifra.ifra_broadaddr;
|
||||
sock_in->sin_family = AF_INET;
|
||||
sock_in->sin_addr = hisaddr;
|
||||
sock_in->sin_len = sizeof *sock_in;
|
||||
|
||||
addr = ntohl(myaddr.s_addr);
|
||||
if (IN_CLASSA(addr))
|
||||
mask = IN_CLASSA_NET;
|
||||
else if (IN_CLASSB(addr))
|
||||
mask = IN_CLASSB_NET;
|
||||
else
|
||||
mask = IN_CLASSC_NET;
|
||||
|
||||
/* if subnet mask is given, use it instead of class mask */
|
||||
if (netmask.s_addr != INADDR_ANY && (ntohl(netmask.s_addr) & mask) == mask)
|
||||
mask = ntohl(netmask.s_addr);
|
||||
|
||||
sock_in = (struct sockaddr_in *)&ifra.ifra_mask;
|
||||
sock_in->sin_family = AF_INET;
|
||||
sock_in->sin_addr.s_addr = htonl(mask);
|
||||
sock_in->sin_len = sizeof *sock_in;
|
||||
|
||||
if (ID0ioctl(s, SIOCAIFADDR, &ifra) < 0) {
|
||||
if (!silent)
|
||||
LogPrintf(LogERROR, "SetIpDevice: ioctl(SIOCAIFADDR): %s\n",
|
||||
strerror(errno));
|
||||
close(s);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
bundle->if_peer.s_addr = hisaddr.s_addr;
|
||||
bundle->if_mine.s_addr = myaddr.s_addr;
|
||||
|
||||
if (Enabled(ConfProxy))
|
||||
sifproxyarp(s, hisaddr);
|
||||
|
||||
close(s);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
bundle_CleanInterface(const struct bundle *bundle)
|
||||
{
|
||||
int s;
|
||||
struct ifreq ifrq;
|
||||
struct ifaliasreq ifra;
|
||||
|
||||
s = ID0socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
LogPrintf(LogERROR, "bundle_CleanInterface: socket(): %s\n",
|
||||
strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
strncpy(ifrq.ifr_name, bundle->ifname, sizeof ifrq.ifr_name - 1);
|
||||
ifrq.ifr_name[sizeof ifrq.ifr_name - 1] = '\0';
|
||||
while (ID0ioctl(s, SIOCGIFADDR, &ifrq) == 0) {
|
||||
memset(&ifra.ifra_mask, '\0', sizeof ifra.ifra_mask);
|
||||
strncpy(ifra.ifra_name, bundle->ifname, sizeof ifra.ifra_name - 1);
|
||||
ifra.ifra_name[sizeof ifra.ifra_name - 1] = '\0';
|
||||
ifra.ifra_addr = ifrq.ifr_addr;
|
||||
if (ID0ioctl(s, SIOCGIFDSTADDR, &ifrq) < 0) {
|
||||
if (ifra.ifra_addr.sa_family == AF_INET)
|
||||
LogPrintf(LogERROR,
|
||||
"bundle_CleanInterface: Can't get dst for %s on %s !\n",
|
||||
inet_ntoa(((struct sockaddr_in *)&ifra.ifra_addr)->sin_addr),
|
||||
bundle->ifname);
|
||||
return 0;
|
||||
}
|
||||
ifra.ifra_broadaddr = ifrq.ifr_dstaddr;
|
||||
if (ID0ioctl(s, SIOCDIFADDR, &ifra) < 0) {
|
||||
if (ifra.ifra_addr.sa_family == AF_INET)
|
||||
LogPrintf(LogERROR,
|
||||
"bundle_CleanInterface: Can't delete %s address on %s !\n",
|
||||
inet_ntoa(((struct sockaddr_in *)&ifra.ifra_addr)->sin_addr),
|
||||
bundle->ifname);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
bundle_TrySetIPaddress(struct bundle *bundle, struct in_addr myaddr,
|
||||
struct in_addr hisaddr)
|
||||
{
|
||||
return bundle_SetIpDevice(bundle, myaddr, hisaddr, ifnetmask, 1);
|
||||
}
|
||||
|
||||
int
|
||||
bundle_SetIPaddress(struct bundle *bundle, struct in_addr myaddr,
|
||||
struct in_addr hisaddr)
|
||||
{
|
||||
return bundle_SetIpDevice(bundle, myaddr, hisaddr, ifnetmask, 0);
|
||||
}
|
||||
|
||||
void
|
||||
bundle_Linkup(struct bundle *bundle)
|
||||
{
|
||||
if (bundle->linkup == 0) {
|
||||
char *s;
|
||||
|
||||
reconnectState = RECON_UNKNOWN;
|
||||
if (mode & MODE_BACKGROUND && BGFiledes[1] != -1) {
|
||||
char c = EX_NORMAL;
|
||||
|
||||
if (write(BGFiledes[1], &c, 1) == 1)
|
||||
LogPrintf(LogPHASE, "Parent notified of success.\n");
|
||||
else
|
||||
LogPrintf(LogPHASE, "Failed to notify parent of success.\n");
|
||||
close(BGFiledes[1]);
|
||||
BGFiledes[1] = -1;
|
||||
}
|
||||
|
||||
s = inet_ntoa(bundle->if_peer);
|
||||
if (LogIsKept(LogLINK))
|
||||
LogPrintf(LogLINK, "OsLinkup: %s\n", s);
|
||||
else
|
||||
LogPrintf(LogLCP, "OsLinkup: %s\n", s);
|
||||
|
||||
/*
|
||||
* XXX this stuff should really live in the FSM. Our config should
|
||||
* associate executable sections in files with events.
|
||||
*/
|
||||
if (SelectSystem(bundle, inet_ntoa(bundle->if_mine), LINKUPFILE) < 0) {
|
||||
if (GetLabel()) {
|
||||
if (SelectSystem(bundle, GetLabel(), LINKUPFILE) < 0)
|
||||
SelectSystem(bundle, "MYADDR", LINKUPFILE);
|
||||
} else
|
||||
SelectSystem(bundle, "MYADDR", LINKUPFILE);
|
||||
}
|
||||
bundle->linkup = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
bundle_LinkIsUp(const struct bundle *bundle)
|
||||
{
|
||||
return bundle->linkup;
|
||||
}
|
||||
|
||||
void
|
||||
bundle_Linkdown(struct bundle *bundle)
|
||||
{
|
||||
char *s = NULL;
|
||||
int Level;
|
||||
|
||||
if (bundle->linkup) {
|
||||
s = inet_ntoa(bundle->if_peer);
|
||||
Level = LogIsKept(LogLINK) ? LogLINK : LogIPCP;
|
||||
LogPrintf(Level, "OsLinkdown: %s\n", s);
|
||||
}
|
||||
|
||||
FsmClose(&IpcpInfo.fsm);
|
||||
FsmClose(&CcpInfo.fsm);
|
||||
|
||||
if (bundle->linkup) {
|
||||
/*
|
||||
* XXX this stuff should really live in the FSM. Our config should
|
||||
* associate executable sections in files with events.
|
||||
*/
|
||||
bundle->linkup = 0;
|
||||
if (SelectSystem(bundle, s, LINKDOWNFILE) < 0)
|
||||
if (GetLabel()) {
|
||||
if (SelectSystem(bundle, GetLabel(), LINKDOWNFILE) < 0)
|
||||
SelectSystem(bundle, "MYADDR", LINKDOWNFILE);
|
||||
} else
|
||||
SelectSystem(bundle, "MYADDR", LINKDOWNFILE);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
bundle_InterfaceDown(struct bundle *bundle)
|
||||
{
|
||||
struct ifreq ifrq;
|
||||
struct ifaliasreq ifra;
|
||||
int s;
|
||||
|
||||
s = ID0socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
LogPrintf(LogERROR, "OsInterfaceDown: socket: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (Enabled(ConfProxy))
|
||||
cifproxyarp(s, bundle->if_peer);
|
||||
|
||||
memset(&ifrq, '\0', sizeof ifrq);
|
||||
strncpy(ifrq.ifr_name, bundle->ifname, sizeof ifrq.ifr_name - 1);
|
||||
ifrq.ifr_name[sizeof ifrq.ifr_name - 1] = '\0';
|
||||
if (ID0ioctl(s, SIOCGIFFLAGS, &ifrq) < 0) {
|
||||
LogPrintf(LogERROR, "OsInterfaceDown: ioctl(SIOCGIFFLAGS): %s\n",
|
||||
strerror(errno));
|
||||
close(s);
|
||||
return -1;
|
||||
}
|
||||
ifrq.ifr_flags &= ~IFF_UP;
|
||||
if (ID0ioctl(s, SIOCSIFFLAGS, &ifrq) < 0) {
|
||||
LogPrintf(LogERROR, "OsInterfaceDown: ioctl(SIOCSIFFLAGS): %s\n",
|
||||
strerror(errno));
|
||||
close(s);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (bundle->if_mine.s_addr != INADDR_ANY ||
|
||||
bundle->if_peer.s_addr != INADDR_ANY) {
|
||||
memset(&ifra, '\0', sizeof ifra);
|
||||
strncpy(ifra.ifra_name, bundle->ifname, sizeof ifra.ifra_name - 1);
|
||||
ifra.ifra_name[sizeof ifra.ifra_name - 1] = '\0';
|
||||
if (ID0ioctl(s, SIOCDIFADDR, &ifra) < 0) {
|
||||
LogPrintf(LogERROR, "OsInterfaceDown: ioctl(SIOCDIFADDR): %s\n",
|
||||
strerror(errno));
|
||||
close(s);
|
||||
return -1;
|
||||
}
|
||||
bundle->if_mine.s_addr = bundle->if_peer.s_addr = INADDR_ANY;
|
||||
}
|
||||
|
||||
close(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Open tunnel device and returns its descriptor
|
||||
*/
|
||||
|
||||
#define MAX_TUN 256
|
||||
/*
|
||||
* MAX_TUN is set at 256 because that is the largest minor number
|
||||
* we can use (certainly with mknod(1) anyway. The search for a
|
||||
* device aborts when it reaches the first `Device not configured'
|
||||
* (ENXIO) or the third `No such file or directory' (ENOENT) error.
|
||||
*/
|
||||
struct bundle *
|
||||
bundle_Create(const char *prefix)
|
||||
{
|
||||
int s, enoentcount, err;
|
||||
struct ifreq ifrq;
|
||||
static struct bundle bundle; /* there can be only one */
|
||||
|
||||
if (bundle.ifname != NULL) { /* Already allocated ! */
|
||||
LogPrintf(LogERROR, "bundle_Create: There's only one BUNDLE !\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
err = ENOENT;
|
||||
enoentcount = 0;
|
||||
for (bundle.unit = 0; bundle.unit <= MAX_TUN; bundle.unit++) {
|
||||
snprintf(bundle.dev, sizeof bundle.dev, "%s%d", prefix, bundle.unit);
|
||||
bundle.tun_fd = ID0open(bundle.dev, O_RDWR);
|
||||
if (bundle.tun_fd >= 0)
|
||||
break;
|
||||
if (errno == ENXIO) {
|
||||
bundle.unit = MAX_TUN;
|
||||
err = errno;
|
||||
} else if (errno == ENOENT) {
|
||||
if (++enoentcount > 2)
|
||||
bundle.unit = MAX_TUN;
|
||||
} else
|
||||
err = errno;
|
||||
}
|
||||
|
||||
if (bundle.unit > MAX_TUN) {
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "No tunnel device is available (%s).\n", strerror(err));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LogSetTun(bundle.unit);
|
||||
|
||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
LogPrintf(LogERROR, "bundle_Create: socket(): %s\n", strerror(errno));
|
||||
close(bundle.tun_fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bundle.ifname = strrchr(bundle.dev, '/');
|
||||
if (bundle.ifname == NULL)
|
||||
bundle.ifname = bundle.dev;
|
||||
else
|
||||
bundle.ifname++;
|
||||
|
||||
/*
|
||||
* Now, bring up the interface.
|
||||
*/
|
||||
memset(&ifrq, '\0', sizeof ifrq);
|
||||
strncpy(ifrq.ifr_name, bundle.ifname, sizeof ifrq.ifr_name - 1);
|
||||
ifrq.ifr_name[sizeof ifrq.ifr_name - 1] = '\0';
|
||||
if (ID0ioctl(s, SIOCGIFFLAGS, &ifrq) < 0) {
|
||||
LogPrintf(LogERROR, "OpenTunnel: ioctl(SIOCGIFFLAGS): %s\n",
|
||||
strerror(errno));
|
||||
close(s);
|
||||
close(bundle.tun_fd);
|
||||
bundle.ifname = NULL;
|
||||
return NULL;
|
||||
}
|
||||
ifrq.ifr_flags |= IFF_UP;
|
||||
if (ID0ioctl(s, SIOCSIFFLAGS, &ifrq) < 0) {
|
||||
LogPrintf(LogERROR, "OpenTunnel: ioctl(SIOCSIFFLAGS): %s\n",
|
||||
strerror(errno));
|
||||
close(s);
|
||||
close(bundle.tun_fd);
|
||||
bundle.ifname = NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
close(s);
|
||||
|
||||
if ((bundle.ifIndex = GetIfIndex(bundle.ifname)) < 0) {
|
||||
LogPrintf(LogERROR, "OpenTunnel: Can't find ifindex.\n");
|
||||
close(bundle.tun_fd);
|
||||
bundle.ifname = NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "Using interface: %s\n", bundle.ifname);
|
||||
LogPrintf(LogPHASE, "Using interface: %s\n", bundle.ifname);
|
||||
|
||||
bundle.linkup = 0;
|
||||
bundle.if_mine.s_addr = bundle.if_peer.s_addr = INADDR_ANY;
|
||||
|
||||
/* Clean out any leftover crud */
|
||||
bundle_CleanInterface(&bundle);
|
||||
|
||||
return &bundle;
|
||||
}
|
||||
|
||||
struct rtmsg {
|
||||
struct rt_msghdr m_rtm;
|
||||
char m_space[64];
|
||||
};
|
||||
|
||||
void
|
||||
bundle_SetRoute(const struct bundle *bundle, int cmd, struct in_addr dst,
|
||||
struct in_addr gateway, struct in_addr mask, int bang)
|
||||
{
|
||||
struct rtmsg rtmes;
|
||||
int s, nb, wb;
|
||||
char *cp;
|
||||
const char *cmdstr;
|
||||
struct sockaddr_in rtdata;
|
||||
static int seqno;
|
||||
|
||||
if (bang)
|
||||
cmdstr = (cmd == RTM_ADD ? "Add!" : "Delete!");
|
||||
else
|
||||
cmdstr = (cmd == RTM_ADD ? "Add" : "Delete");
|
||||
s = ID0socket(PF_ROUTE, SOCK_RAW, 0);
|
||||
if (s < 0) {
|
||||
LogPrintf(LogERROR, "OsSetRoute: socket(): %s\n", strerror(errno));
|
||||
return;
|
||||
}
|
||||
memset(&rtmes, '\0', sizeof rtmes);
|
||||
rtmes.m_rtm.rtm_version = RTM_VERSION;
|
||||
rtmes.m_rtm.rtm_type = cmd;
|
||||
rtmes.m_rtm.rtm_addrs = RTA_DST;
|
||||
rtmes.m_rtm.rtm_seq = ++seqno;
|
||||
rtmes.m_rtm.rtm_pid = getpid();
|
||||
rtmes.m_rtm.rtm_flags = RTF_UP | RTF_GATEWAY | RTF_STATIC;
|
||||
|
||||
memset(&rtdata, '\0', sizeof rtdata);
|
||||
rtdata.sin_len = 16;
|
||||
rtdata.sin_family = AF_INET;
|
||||
rtdata.sin_port = 0;
|
||||
rtdata.sin_addr = dst;
|
||||
|
||||
cp = rtmes.m_space;
|
||||
memcpy(cp, &rtdata, 16);
|
||||
cp += 16;
|
||||
if (cmd == RTM_ADD)
|
||||
if (gateway.s_addr == INADDR_ANY) {
|
||||
/* Add a route through the interface */
|
||||
struct sockaddr_dl dl;
|
||||
const char *iname;
|
||||
int ilen;
|
||||
|
||||
iname = Index2Nam(bundle->ifIndex);
|
||||
ilen = strlen(iname);
|
||||
dl.sdl_len = sizeof dl - sizeof dl.sdl_data + ilen;
|
||||
dl.sdl_family = AF_LINK;
|
||||
dl.sdl_index = bundle->ifIndex;
|
||||
dl.sdl_type = 0;
|
||||
dl.sdl_nlen = ilen;
|
||||
dl.sdl_alen = 0;
|
||||
dl.sdl_slen = 0;
|
||||
strncpy(dl.sdl_data, iname, sizeof dl.sdl_data);
|
||||
memcpy(cp, &dl, dl.sdl_len);
|
||||
cp += dl.sdl_len;
|
||||
rtmes.m_rtm.rtm_addrs |= RTA_GATEWAY;
|
||||
} else {
|
||||
rtdata.sin_addr = gateway;
|
||||
memcpy(cp, &rtdata, 16);
|
||||
cp += 16;
|
||||
rtmes.m_rtm.rtm_addrs |= RTA_GATEWAY;
|
||||
}
|
||||
|
||||
if (dst.s_addr == INADDR_ANY)
|
||||
mask.s_addr = INADDR_ANY;
|
||||
|
||||
if (cmd == RTM_ADD || dst.s_addr == INADDR_ANY) {
|
||||
rtdata.sin_addr = mask;
|
||||
memcpy(cp, &rtdata, 16);
|
||||
cp += 16;
|
||||
rtmes.m_rtm.rtm_addrs |= RTA_NETMASK;
|
||||
}
|
||||
|
||||
nb = cp - (char *) &rtmes;
|
||||
rtmes.m_rtm.rtm_msglen = nb;
|
||||
wb = ID0write(s, &rtmes, nb);
|
||||
if (wb < 0) {
|
||||
LogPrintf(LogTCPIP, "OsSetRoute failure:\n");
|
||||
LogPrintf(LogTCPIP, "OsSetRoute: Cmd = %s\n", cmd);
|
||||
LogPrintf(LogTCPIP, "OsSetRoute: Dst = %s\n", inet_ntoa(dst));
|
||||
LogPrintf(LogTCPIP, "OsSetRoute: Gateway = %s\n", inet_ntoa(gateway));
|
||||
LogPrintf(LogTCPIP, "OsSetRoute: Mask = %s\n", inet_ntoa(mask));
|
||||
failed:
|
||||
if (cmd == RTM_ADD && (rtmes.m_rtm.rtm_errno == EEXIST ||
|
||||
(rtmes.m_rtm.rtm_errno == 0 && errno == EEXIST)))
|
||||
if (!bang)
|
||||
LogPrintf(LogWARN, "Add route failed: %s already exists\n",
|
||||
inet_ntoa(dst));
|
||||
else {
|
||||
rtmes.m_rtm.rtm_type = cmd = RTM_CHANGE;
|
||||
if ((wb = ID0write(s, &rtmes, nb)) < 0)
|
||||
goto failed;
|
||||
}
|
||||
else if (cmd == RTM_DELETE &&
|
||||
(rtmes.m_rtm.rtm_errno == ESRCH ||
|
||||
(rtmes.m_rtm.rtm_errno == 0 && errno == ESRCH))) {
|
||||
if (!bang)
|
||||
LogPrintf(LogWARN, "Del route failed: %s: Non-existent\n",
|
||||
inet_ntoa(dst));
|
||||
} else if (rtmes.m_rtm.rtm_errno == 0)
|
||||
LogPrintf(LogWARN, "%s route failed: %s: errno: %s\n", cmdstr,
|
||||
inet_ntoa(dst), strerror(errno));
|
||||
else
|
||||
LogPrintf(LogWARN, "%s route failed: %s: %s\n",
|
||||
cmdstr, inet_ntoa(dst), strerror(rtmes.m_rtm.rtm_errno));
|
||||
}
|
||||
LogPrintf(LogDEBUG, "wrote %d: cmd = %s, dst = %x, gateway = %x\n",
|
||||
wb, cmdstr, dst.s_addr, gateway.s_addr);
|
||||
close(s);
|
||||
}
|
51
usr.sbin/ppp/bundle.h
Normal file
51
usr.sbin/ppp/bundle.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*-
|
||||
* Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
struct bundle {
|
||||
int unit;
|
||||
int ifIndex;
|
||||
int tun_fd;
|
||||
char dev[20];
|
||||
char *ifname;
|
||||
|
||||
/* These belong at the NCP level */
|
||||
int linkup;
|
||||
struct in_addr if_mine, if_peer;
|
||||
};
|
||||
|
||||
extern struct bundle *bundle_Create(const char *dev);
|
||||
extern int bundle_InterfaceDown(struct bundle *);
|
||||
extern int bundle_SetIPaddress(struct bundle *, struct in_addr,
|
||||
struct in_addr);
|
||||
extern int bundle_TrySetIPaddress(struct bundle *, struct in_addr,
|
||||
struct in_addr);
|
||||
extern void bundle_Linkup(struct bundle *);
|
||||
extern int bundle_LinkIsUp(const struct bundle *);
|
||||
extern void bundle_Linkdown(struct bundle *);
|
||||
extern void bundle_SetRoute(const struct bundle *, int, struct in_addr,
|
||||
struct in_addr, struct in_addr, int);
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: ccp.c,v 1.30.2.3 1998/01/30 19:45:27 brian Exp $
|
||||
* $Id: ccp.c,v 1.30.2.4 1998/01/31 02:48:14 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
* o Support other compression protocols
|
||||
@ -46,7 +46,7 @@
|
||||
static void CcpSendConfigReq(struct fsm *);
|
||||
static void CcpSendTerminateReq(struct fsm *);
|
||||
static void CcpSendTerminateAck(struct fsm *);
|
||||
static void CcpDecodeConfig(u_char *, int, int);
|
||||
static void CcpDecodeConfig(struct bundle *, u_char *, int, int);
|
||||
static void CcpLayerStart(struct fsm *);
|
||||
static void CcpLayerFinish(struct fsm *);
|
||||
static void CcpLayerUp(struct fsm *);
|
||||
@ -65,7 +65,8 @@ struct ccpstate CcpInfo = {
|
||||
{0, 0, 0, NULL, NULL, NULL}, /* Open timer */
|
||||
{0, 0, 0, NULL, NULL, NULL}, /* Stopped timer */
|
||||
LogCCP,
|
||||
NULL,
|
||||
NULL, /* link */
|
||||
NULL, /* bundle */
|
||||
CcpLayerUp,
|
||||
CcpLayerDown,
|
||||
CcpLayerStart,
|
||||
@ -136,10 +137,10 @@ ReportCcpStatus(struct cmdargs const *arg)
|
||||
}
|
||||
|
||||
void
|
||||
CcpInit(struct link *l)
|
||||
CcpInit(struct bundle *bundle, struct link *l)
|
||||
{
|
||||
/* Initialise ourselves */
|
||||
FsmInit(&CcpInfo.fsm, l);
|
||||
FsmInit(&CcpInfo.fsm, bundle, l);
|
||||
CcpInfo.his_proto = CcpInfo.my_proto = -1;
|
||||
CcpInfo.reset_sent = CcpInfo.last_reset = -1;
|
||||
CcpInfo.in_algorithm = CcpInfo.out_algorithm = -1;
|
||||
@ -318,7 +319,7 @@ CcpOpen()
|
||||
}
|
||||
|
||||
static void
|
||||
CcpDecodeConfig(u_char *cp, int plen, int mode_type)
|
||||
CcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
|
||||
{
|
||||
/* Deal with incoming data */
|
||||
int type, length;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: ccp.h,v 1.14.2.3 1998/01/30 19:45:29 brian Exp $
|
||||
* $Id: ccp.h,v 1.14.2.4 1998/01/31 02:48:15 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -87,7 +87,7 @@ extern void CcpSendResetReq(struct fsm *);
|
||||
extern void CcpInput(struct mbuf *);
|
||||
extern void CcpUp(void);
|
||||
extern void CcpOpen(void);
|
||||
extern void CcpInit(struct link *);
|
||||
extern void CcpInit(struct bundle *, struct link *);
|
||||
extern int ReportCcpStatus(struct cmdargs const *);
|
||||
extern void CcpResetInput(u_char);
|
||||
extern int CcpOutput(struct link *, int, u_short, struct mbuf *);
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: chap.c,v 1.28.2.3 1998/01/30 19:45:29 brian Exp $
|
||||
* $Id: chap.c,v 1.28.2.4 1998/01/31 02:48:15 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -110,7 +110,8 @@ struct authinfo AuthChapInfo = {
|
||||
};
|
||||
|
||||
static void
|
||||
RecvChapTalk(struct fsmheader *chp, struct mbuf *bp, struct physical *physical)
|
||||
RecvChapTalk(struct bundle *bundle, struct fsmheader *chp, struct mbuf *bp,
|
||||
struct physical *physical)
|
||||
{
|
||||
int valsize, len;
|
||||
int arglen, keylen, namelen;
|
||||
@ -206,7 +207,7 @@ RecvChapTalk(struct fsmheader *chp, struct mbuf *bp, struct physical *physical)
|
||||
/*
|
||||
* Get a secret key corresponds to the peer
|
||||
*/
|
||||
keyp = AuthGetSecret(SECRETFILE, name, namelen,
|
||||
keyp = AuthGetSecret(bundle, SECRETFILE, name, namelen,
|
||||
chp->code == CHAP_RESPONSE,
|
||||
physical);
|
||||
if (keyp) {
|
||||
@ -246,7 +247,7 @@ RecvChapTalk(struct fsmheader *chp, struct mbuf *bp, struct physical *physical)
|
||||
login(&ut);
|
||||
Utmp = 1;
|
||||
}
|
||||
NewPhase(physical, PHASE_NETWORK);
|
||||
NewPhase(bundle, physical, PHASE_NETWORK);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -262,7 +263,7 @@ RecvChapTalk(struct fsmheader *chp, struct mbuf *bp, struct physical *physical)
|
||||
}
|
||||
|
||||
static void
|
||||
RecvChapResult(struct fsmheader *chp, struct mbuf *bp,
|
||||
RecvChapResult(struct bundle *bundle, struct fsmheader *chp, struct mbuf *bp,
|
||||
struct physical *physical)
|
||||
{
|
||||
int len;
|
||||
@ -273,7 +274,7 @@ RecvChapResult(struct fsmheader *chp, struct mbuf *bp,
|
||||
if (LcpInfo.auth_iwait == PROTO_CHAP) {
|
||||
LcpInfo.auth_iwait = 0;
|
||||
if (LcpInfo.auth_ineed == 0)
|
||||
NewPhase(physical, PHASE_NETWORK);
|
||||
NewPhase(bundle, physical, PHASE_NETWORK);
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -285,7 +286,7 @@ RecvChapResult(struct fsmheader *chp, struct mbuf *bp,
|
||||
}
|
||||
|
||||
void
|
||||
ChapInput(struct mbuf *bp, struct physical *physical)
|
||||
ChapInput(struct bundle *bundle, struct mbuf *bp, struct physical *physical)
|
||||
{
|
||||
int len = plength(bp);
|
||||
struct fsmheader *chp;
|
||||
@ -305,11 +306,11 @@ ChapInput(struct mbuf *bp, struct physical *physical)
|
||||
StopAuthTimer(&AuthChapInfo);
|
||||
/* Fall into.. */
|
||||
case CHAP_CHALLENGE:
|
||||
RecvChapTalk(chp, bp, physical);
|
||||
RecvChapTalk(bundle, chp, bp, physical);
|
||||
break;
|
||||
case CHAP_SUCCESS:
|
||||
case CHAP_FAILURE:
|
||||
RecvChapResult(chp, bp, physical);
|
||||
RecvChapResult(bundle, chp, bp, physical);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: chap.h,v 1.9 1997/10/26 12:42:08 brian Exp $
|
||||
* $Id: chap.h,v 1.9.2.1 1998/01/29 00:49:14 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -29,4 +29,4 @@ struct physical;
|
||||
|
||||
extern struct authinfo AuthChapInfo;
|
||||
|
||||
extern void ChapInput(struct mbuf *, struct physical *);
|
||||
extern void ChapInput(struct bundle *, struct mbuf *, struct physical *);
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: command.c,v 1.131.2.3 1998/01/30 19:45:32 brian Exp $
|
||||
* $Id: command.c,v 1.131.2.4 1998/01/31 02:48:16 brian Exp $
|
||||
*
|
||||
*/
|
||||
#include <sys/param.h>
|
||||
@ -66,7 +66,7 @@
|
||||
#include "vars.h"
|
||||
#include "systems.h"
|
||||
#include "chat.h"
|
||||
#include "os.h"
|
||||
#include "bundle.h"
|
||||
#include "server.h"
|
||||
#include "main.h"
|
||||
#include "route.h"
|
||||
@ -194,14 +194,13 @@ DialCommand(struct cmdargs const *arg)
|
||||
}
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "Dial attempt %u of %d\n", ++tries, VarDialTries);
|
||||
if (OpenModem(pppVars.physical) < 0) {
|
||||
if (OpenModem(arg->bundle, pppVars.physical) < 0) {
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "Failed to open modem.\n");
|
||||
break;
|
||||
}
|
||||
if ((res = DialModem(pppVars.physical)) == EX_DONE) {
|
||||
ModemTimeout(pppVars.physical);
|
||||
PacketMode(VarOpenMode);
|
||||
if ((res = DialModem(arg->bundle, pppVars.physical)) == EX_DONE) {
|
||||
PacketMode(arg->bundle, VarOpenMode);
|
||||
break;
|
||||
} else if (res == EX_SIG)
|
||||
return 1;
|
||||
@ -300,7 +299,7 @@ ShellCommand(struct cmdargs const *arg, int bg)
|
||||
if (strcasecmp(arg->argv[argc], "HISADDR") == 0)
|
||||
argv[argc] = strdup(inet_ntoa(IpcpInfo.his_ipaddr));
|
||||
else if (strcasecmp(arg->argv[argc], "INTERFACE") == 0)
|
||||
argv[argc] = strdup(IfDevName);
|
||||
argv[argc] = strdup(arg->bundle->ifname);
|
||||
else if (strcasecmp(arg->argv[argc], "MYADDR") == 0)
|
||||
argv[argc] = strdup(inet_ntoa(IpcpInfo.want_ipaddr));
|
||||
else
|
||||
@ -695,8 +694,8 @@ FindCommand(struct cmdtab const *cmds, const char *str, int *pmatch)
|
||||
}
|
||||
|
||||
static int
|
||||
FindExec(struct cmdtab const *cmds, int argc, char const *const *argv,
|
||||
const char *prefix)
|
||||
FindExec(struct bundle *bundle, struct cmdtab const *cmds, int argc,
|
||||
char const *const *argv, const char *prefix)
|
||||
{
|
||||
struct cmdtab const *cmd;
|
||||
int val = 1;
|
||||
@ -711,6 +710,7 @@ FindExec(struct cmdtab const *cmds, int argc, char const *const *argv,
|
||||
arg.argc = argc-1;
|
||||
arg.argv = argv+1;
|
||||
arg.data = cmd->args;
|
||||
arg.bundle = bundle;
|
||||
val = (cmd->func) (&arg);
|
||||
} else
|
||||
LogPrintf(LogWARN, "%s%s: Invalid command\n", prefix, *argv);
|
||||
@ -785,7 +785,8 @@ arghidden(int argc, char const *const *argv, int n)
|
||||
}
|
||||
|
||||
void
|
||||
RunCommand(int argc, char const *const *argv, const char *label)
|
||||
RunCommand(struct bundle *bundle, int argc, char const *const *argv,
|
||||
const char *label)
|
||||
{
|
||||
if (argc > 0) {
|
||||
if (LogIsKept(LogCOMMAND)) {
|
||||
@ -810,25 +811,25 @@ RunCommand(int argc, char const *const *argv, const char *label)
|
||||
}
|
||||
LogPrintf(LogCOMMAND, "%s\n", buf);
|
||||
}
|
||||
FindExec(Commands, argc, argv, "");
|
||||
FindExec(bundle, Commands, argc, argv, "");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DecodeCommand(char *buff, int nb, const char *label)
|
||||
DecodeCommand(struct bundle *bundle, char *buff, int nb, const char *label)
|
||||
{
|
||||
int argc;
|
||||
char **argv;
|
||||
|
||||
InterpretCommand(buff, nb, &argc, &argv);
|
||||
RunCommand(argc, (char const *const *)argv, label);
|
||||
RunCommand(bundle, argc, (char const *const *)argv, label);
|
||||
}
|
||||
|
||||
static int
|
||||
ShowCommand(struct cmdargs const *arg)
|
||||
{
|
||||
if (arg->argc > 0)
|
||||
FindExec(ShowCommands, arg->argc, arg->argv, "show ");
|
||||
FindExec(arg->bundle, ShowCommands, arg->argc, arg->argv, "show ");
|
||||
else if (VarTerm)
|
||||
fprintf(VarTerm, "Use ``show ?'' to get a arg->cmd.\n");
|
||||
else
|
||||
@ -847,7 +848,7 @@ TerminalCommand(struct cmdargs const *arg)
|
||||
}
|
||||
if (!IsInteractive(1))
|
||||
return (1);
|
||||
if (OpenModem(pppVars.physical) < 0) {
|
||||
if (OpenModem(arg->bundle, pppVars.physical) < 0) {
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "Failed to open modem.\n");
|
||||
return (1);
|
||||
@ -1210,7 +1211,8 @@ SetIdleTimeout(struct cmdargs const *arg)
|
||||
{
|
||||
if (arg->argc > 0) {
|
||||
VarIdleTimeout = atoi(arg->argv[0]);
|
||||
UpdateIdleTimer(); /* If we're connected, restart the idle timer */
|
||||
/* If we're connected, restart the idle timer */
|
||||
UpdateIdleTimer(arg->bundle);
|
||||
if (arg->argc > 1) {
|
||||
VarLqrTimeout = atoi(arg->argv[1]);
|
||||
if (VarLqrTimeout < 1)
|
||||
@ -1288,7 +1290,7 @@ SetInterfaceAddr(struct cmdargs const *arg)
|
||||
IpcpInfo.DefHisAddress.width = 0;
|
||||
}
|
||||
|
||||
if (hisaddr && !UseHisaddr(hisaddr, mode & MODE_AUTO))
|
||||
if (hisaddr && !UseHisaddr(arg->bundle, hisaddr, mode & MODE_AUTO))
|
||||
return 4;
|
||||
|
||||
return 0;
|
||||
@ -1519,7 +1521,7 @@ static int
|
||||
SetCommand(struct cmdargs const *arg)
|
||||
{
|
||||
if (arg->argc > 0)
|
||||
FindExec(SetCommands, arg->argc, arg->argv, "set ");
|
||||
FindExec(arg->bundle, SetCommands, arg->argc, arg->argv, "set ");
|
||||
else if (VarTerm)
|
||||
fprintf(VarTerm, "Use `set ?' to get a arg->cmd or `set ? <var>' for"
|
||||
" syntax help.\n");
|
||||
@ -1562,7 +1564,8 @@ AddCommand(struct cmdargs const *arg)
|
||||
gateway.s_addr = INADDR_ANY;
|
||||
else
|
||||
gateway = GetIpAddr(arg->argv[gw]);
|
||||
OsSetRoute(RTM_ADD, dest, gateway, netmask, arg->data ? 1 : 0);
|
||||
bundle_SetRoute(arg->bundle, RTM_ADD, dest, gateway, netmask,
|
||||
arg->data ? 1 : 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1573,7 +1576,7 @@ DeleteCommand(struct cmdargs const *arg)
|
||||
|
||||
if (arg->argc == 1)
|
||||
if(strcasecmp(arg->argv[0], "all") == 0)
|
||||
DeleteIfRoutes(0);
|
||||
DeleteIfRoutes(arg->bundle, 0);
|
||||
else {
|
||||
if (strcasecmp(arg->argv[0], "MYADDR") == 0)
|
||||
dest = IpcpInfo.want_ipaddr;
|
||||
@ -1582,7 +1585,8 @@ DeleteCommand(struct cmdargs const *arg)
|
||||
else
|
||||
dest = GetIpAddr(arg->argv[0]);
|
||||
none.s_addr = INADDR_ANY;
|
||||
OsSetRoute(RTM_DELETE, dest, none, none, arg->data ? 1 : 0);
|
||||
bundle_SetRoute(arg->bundle, RTM_DELETE, dest, none, none,
|
||||
arg->data ? 1 : 0);
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
@ -1625,10 +1629,10 @@ static int
|
||||
AliasCommand(struct cmdargs const *arg)
|
||||
{
|
||||
if (arg->argc > 0)
|
||||
FindExec(AliasCommands, arg->argc, arg->argv, "alias ");
|
||||
FindExec(arg->bundle, AliasCommands, arg->argc, arg->argv, "alias ");
|
||||
else if (VarTerm)
|
||||
fprintf(VarTerm, "Use `alias help' to get a arg->cmd or `alias help <option>'"
|
||||
" for syntax help.\n");
|
||||
fprintf(VarTerm, "Use `alias help' to get a arg->cmd or `alias help"
|
||||
" <option>' for syntax help.\n");
|
||||
else
|
||||
LogPrintf(LogWARN, "alias command must have arguments\n");
|
||||
|
||||
@ -1695,8 +1699,9 @@ static struct cmdtab const AllowCommands[] = {
|
||||
static int
|
||||
AllowCommand(struct cmdargs const *arg)
|
||||
{
|
||||
/* arg->bundle may be NULL (see ValidSystem()) ! */
|
||||
if (arg->argc > 0)
|
||||
FindExec(AllowCommands, arg->argc, arg->argv, "allow ");
|
||||
FindExec(arg->bundle, AllowCommands, arg->argc, arg->argv, "allow ");
|
||||
else if (VarTerm)
|
||||
fprintf(VarTerm, "Use `allow ?' to get a arg->cmd or `allow ? <cmd>' for"
|
||||
" syntax help.\n");
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: command.h,v 1.11 1997/11/13 14:43:15 brian Exp $
|
||||
* $Id: command.h,v 1.12 1997/11/22 03:37:29 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -27,6 +27,7 @@ struct cmdargs {
|
||||
int argc;
|
||||
char const *const *argv;
|
||||
const void *data;
|
||||
struct bundle *bundle;
|
||||
};
|
||||
|
||||
struct cmdtab {
|
||||
@ -58,5 +59,5 @@ extern int SetVariable(struct cmdargs const *);
|
||||
extern void Prompt(void);
|
||||
extern int IsInteractive(int);
|
||||
extern void InterpretCommand(char *, int, int *, char ***);
|
||||
extern void RunCommand(int, char const *const *, const char *label);
|
||||
extern void DecodeCommand(char *, int, const char *label);
|
||||
extern void RunCommand(struct bundle *, int, char const *const *, const char *);
|
||||
extern void DecodeCommand(struct bundle *, char *, int, const char *);
|
||||
|
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: defs.c,v 1.11 1998/01/21 02:15:14 brian Exp $
|
||||
* $Id: defs.c,v 1.11.4.1 1998/01/29 20:45:16 brian Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -46,8 +46,6 @@
|
||||
int mode = MODE_INTER;
|
||||
int BGFiledes[2] = { -1, -1 };
|
||||
int modem = -1;
|
||||
int tun_in = -1;
|
||||
int tun_out = -1;
|
||||
int netfd = -1;
|
||||
|
||||
static char dstsystem[50];
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: fsm.c,v 1.27.2.2 1998/01/30 19:45:39 brian Exp $
|
||||
* $Id: fsm.c,v 1.27.2.3 1998/01/31 02:48:18 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
* o Refer loglevel for log output
|
||||
@ -83,7 +83,7 @@ StoppedTimeout(void *v)
|
||||
}
|
||||
|
||||
void
|
||||
FsmInit(struct fsm * fp, struct link *l)
|
||||
FsmInit(struct fsm *fp, struct bundle *bundle, struct link *l)
|
||||
{
|
||||
LogPrintf(LogDEBUG, "FsmInit\n");
|
||||
fp->state = ST_INITIAL;
|
||||
@ -91,6 +91,7 @@ FsmInit(struct fsm * fp, struct link *l)
|
||||
fp->restart = 1;
|
||||
fp->maxconfig = 3;
|
||||
fp->link = l;
|
||||
fp->bundle = bundle;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -277,35 +278,29 @@ FsmSendTerminateReq(struct fsm * fp)
|
||||
}
|
||||
|
||||
static void
|
||||
FsmSendConfigAck(struct fsm * fp,
|
||||
struct fsmheader * lhp,
|
||||
u_char * option,
|
||||
int count)
|
||||
FsmSendConfigAck(struct fsm *fp, struct fsmheader *lhp,
|
||||
u_char *option, int count)
|
||||
{
|
||||
LogPrintf(fp->LogLevel, "SendConfigAck(%s)\n", StateNames[fp->state]);
|
||||
(fp->DecodeConfig) (option, count, MODE_NOP);
|
||||
(fp->DecodeConfig) (fp->bundle, option, count, MODE_NOP);
|
||||
FsmOutput(fp, CODE_CONFIGACK, lhp->id, option, count);
|
||||
}
|
||||
|
||||
static void
|
||||
FsmSendConfigRej(struct fsm * fp,
|
||||
struct fsmheader * lhp,
|
||||
u_char * option,
|
||||
int count)
|
||||
FsmSendConfigRej(struct fsm *fp, struct fsmheader *lhp,
|
||||
u_char *option, int count)
|
||||
{
|
||||
LogPrintf(fp->LogLevel, "SendConfigRej(%s)\n", StateNames[fp->state]);
|
||||
(fp->DecodeConfig) (option, count, MODE_NOP);
|
||||
(fp->DecodeConfig) (fp->bundle, option, count, MODE_NOP);
|
||||
FsmOutput(fp, CODE_CONFIGREJ, lhp->id, option, count);
|
||||
}
|
||||
|
||||
static void
|
||||
FsmSendConfigNak(struct fsm * fp,
|
||||
struct fsmheader * lhp,
|
||||
u_char * option,
|
||||
int count)
|
||||
FsmSendConfigNak(struct fsm *fp, struct fsmheader *lhp,
|
||||
u_char *option, int count)
|
||||
{
|
||||
LogPrintf(fp->LogLevel, "SendConfigNak(%s)\n", StateNames[fp->state]);
|
||||
(fp->DecodeConfig) (option, count, MODE_NOP);
|
||||
(fp->DecodeConfig) (fp->bundle, option, count, MODE_NOP);
|
||||
FsmOutput(fp, CODE_CONFIGNAK, lhp->id, option, count);
|
||||
}
|
||||
|
||||
@ -367,7 +362,7 @@ FsmInitRestartCounter(struct fsm * fp)
|
||||
* Actions when receive packets
|
||||
*/
|
||||
static void
|
||||
FsmRecvConfigReq(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
FsmRecvConfigReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
|
||||
/* RCR */
|
||||
{
|
||||
int plen, flen;
|
||||
@ -403,7 +398,7 @@ FsmRecvConfigReq(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
return;
|
||||
}
|
||||
|
||||
(fp->DecodeConfig) (MBUF_CTOP(bp), flen, MODE_REQ);
|
||||
(fp->DecodeConfig) (fp->bundle, MBUF_CTOP(bp), flen, MODE_REQ);
|
||||
|
||||
if (nakp == NakBuff && rejp == RejBuff)
|
||||
ackaction = 1;
|
||||
@ -487,7 +482,7 @@ FsmRecvConfigAck(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
}
|
||||
|
||||
static void
|
||||
FsmRecvConfigNak(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
FsmRecvConfigNak(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
|
||||
/* RCN */
|
||||
{
|
||||
int plen, flen;
|
||||
@ -519,7 +514,7 @@ FsmRecvConfigNak(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
return;
|
||||
}
|
||||
|
||||
(fp->DecodeConfig) (MBUF_CTOP(bp), flen, MODE_NAK);
|
||||
(fp->DecodeConfig) (fp->bundle, MBUF_CTOP(bp), flen, MODE_NAK);
|
||||
|
||||
switch (fp->state) {
|
||||
case ST_REQSENT:
|
||||
@ -597,7 +592,7 @@ FsmRecvTermAck(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
}
|
||||
|
||||
static void
|
||||
FsmRecvConfigRej(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
FsmRecvConfigRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
|
||||
/* RCJ */
|
||||
{
|
||||
int plen, flen;
|
||||
@ -630,7 +625,7 @@ FsmRecvConfigRej(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
||||
return;
|
||||
}
|
||||
|
||||
(fp->DecodeConfig) (MBUF_CTOP(bp), flen, MODE_REJ);
|
||||
(fp->DecodeConfig) (fp->bundle, MBUF_CTOP(bp), flen, MODE_REJ);
|
||||
|
||||
switch (fp->state) {
|
||||
case ST_REQSENT:
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: fsm.h,v 1.16.2.2 1998/01/30 19:45:40 brian Exp $
|
||||
* $Id: fsm.h,v 1.16.2.3 1998/01/31 02:48:18 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -70,9 +70,12 @@ struct fsm {
|
||||
struct pppTimer StoppedTimer;
|
||||
int LogLevel;
|
||||
|
||||
/* The link layer active with this FSM. */
|
||||
/* The link layer active with this FSM (may be our bundle below) */
|
||||
struct link *link;
|
||||
|
||||
/* Our high-level link */
|
||||
struct bundle *bundle;
|
||||
|
||||
void (*LayerUp) (struct fsm *); /* Layer is now up (tlu) */
|
||||
void (*LayerDown) (struct fsm *); /* About to come down (tld) */
|
||||
void (*LayerStart) (struct fsm *); /* Layer about to start up (tls) */
|
||||
@ -81,7 +84,8 @@ struct fsm {
|
||||
void (*SendConfigReq) (struct fsm *); /* Send REQ please */
|
||||
void (*SendTerminateReq) (struct fsm *); /* Term REQ just sent */
|
||||
void (*SendTerminateAck) (struct fsm *); /* Send Term ACK please */
|
||||
void (*DecodeConfig) (u_char *, int, int); /* Deal with incoming data */
|
||||
void (*DecodeConfig) (struct bundle *, u_char *, int, int);
|
||||
/* Deal with incoming data */
|
||||
};
|
||||
|
||||
struct fsmheader {
|
||||
@ -122,7 +126,7 @@ extern u_char *rejp;
|
||||
|
||||
extern char const *StateNames[];
|
||||
|
||||
extern void FsmInit(struct fsm *, struct link *);
|
||||
extern void FsmInit(struct fsm *, struct bundle *, struct link *);
|
||||
extern void FsmOutput(struct fsm *, u_int, u_int, u_char *, int);
|
||||
extern void FsmOpen(struct fsm *);
|
||||
extern void FsmUp(struct fsm *);
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: hdlc.c,v 1.28.2.3 1998/01/30 19:45:41 brian Exp $
|
||||
* $Id: hdlc.c,v 1.28.2.4 1998/01/31 02:48:19 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -367,7 +367,8 @@ Protocol2Nam(u_short proto)
|
||||
}
|
||||
|
||||
static void
|
||||
DecodePacket(u_short proto, struct mbuf * bp, struct link *l)
|
||||
DecodePacket(struct bundle *bundle, u_short proto, struct mbuf * bp,
|
||||
struct link *l)
|
||||
{
|
||||
struct physical *p = link2physical(l);
|
||||
u_char *cp;
|
||||
@ -391,7 +392,7 @@ DecodePacket(u_short proto, struct mbuf * bp, struct link *l)
|
||||
break;
|
||||
case PROTO_PAP:
|
||||
if (p)
|
||||
PapInput(bp, p);
|
||||
PapInput(bundle, bp, p);
|
||||
else {
|
||||
LogPrintf(LogERROR, "DecodePacket: PAP: Not a physical link !\n");
|
||||
pfree(bp);
|
||||
@ -408,7 +409,7 @@ DecodePacket(u_short proto, struct mbuf * bp, struct link *l)
|
||||
break;
|
||||
case PROTO_CHAP:
|
||||
if (p)
|
||||
ChapInput(bp, p);
|
||||
ChapInput(bundle, bp, p);
|
||||
else {
|
||||
LogPrintf(LogERROR, "DecodePacket: CHAP: Not a physical link !\n");
|
||||
pfree(bp);
|
||||
@ -421,7 +422,7 @@ DecodePacket(u_short proto, struct mbuf * bp, struct link *l)
|
||||
break;
|
||||
/* fall down */
|
||||
case PROTO_IP:
|
||||
IpInput(bp);
|
||||
IpInput(bundle, bp);
|
||||
break;
|
||||
case PROTO_IPCP:
|
||||
IpcpInput(bp);
|
||||
@ -473,7 +474,7 @@ HdlcErrorCheck()
|
||||
}
|
||||
|
||||
void
|
||||
HdlcInput(struct mbuf * bp, struct physical *physical)
|
||||
HdlcInput(struct bundle *bundle, struct mbuf * bp, struct physical *physical)
|
||||
{
|
||||
u_short fcs, proto;
|
||||
u_char *cp, addr, ctrl;
|
||||
@ -556,5 +557,5 @@ HdlcInput(struct mbuf * bp, struct physical *physical)
|
||||
link_ProtocolRecord(physical2link(physical), proto, PROTO_IN);
|
||||
HisLqrSave.SaveInPackets++;
|
||||
|
||||
DecodePacket(proto, bp, physical2link(physical));
|
||||
DecodePacket(bundle, proto, bp, physical2link(physical));
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: hdlc.h,v 1.14.2.1 1998/01/29 00:49:22 brian Exp $
|
||||
* $Id: hdlc.h,v 1.14.2.2 1998/01/30 19:45:42 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -63,7 +63,7 @@ struct link;
|
||||
|
||||
extern void HdlcInit(void);
|
||||
extern void HdlcErrorCheck(void);
|
||||
extern void HdlcInput(struct mbuf *, struct physical *);
|
||||
extern void HdlcInput(struct bundle *, struct mbuf *, struct physical *);
|
||||
extern void HdlcOutput(struct link *, int, u_short, struct mbuf *bp);
|
||||
extern u_short HdlcFcs(u_short, u_char *, int);
|
||||
extern int ReportHdlcStatus(struct cmdargs const *);
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: ip.c,v 1.38.2.3 1998/01/30 19:45:43 brian Exp $
|
||||
* $Id: ip.c,v 1.38.2.4 1998/01/31 02:48:19 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
* o Return ICMP message for filterd packet
|
||||
@ -56,7 +56,7 @@
|
||||
#include "loadalias.h"
|
||||
#include "vars.h"
|
||||
#include "filter.h"
|
||||
#include "os.h"
|
||||
#include "bundle.h"
|
||||
#include "iplist.h"
|
||||
#include "throughput.h"
|
||||
#include "ipcp.h"
|
||||
@ -97,9 +97,9 @@ StartIdleTimer()
|
||||
}
|
||||
|
||||
void
|
||||
UpdateIdleTimer()
|
||||
UpdateIdleTimer(const struct bundle *bundle)
|
||||
{
|
||||
if (OsLinkIsUp())
|
||||
if (bundle_LinkIsUp(bundle))
|
||||
StartIdleTimer();
|
||||
}
|
||||
|
||||
@ -382,8 +382,8 @@ PacketCheck(char *cp, int nb, int direction)
|
||||
}
|
||||
|
||||
void
|
||||
IpInput(struct mbuf * bp)
|
||||
{ /* IN: Pointer to IP pakcet */
|
||||
IpInput(struct bundle *bundle, struct mbuf * bp)
|
||||
{
|
||||
u_char *cp;
|
||||
struct mbuf *wp;
|
||||
int nb, nw;
|
||||
@ -428,7 +428,7 @@ IpInput(struct mbuf * bp)
|
||||
|
||||
nb = ntohs(((struct ip *) tun.data)->ip_len);
|
||||
nb += sizeof tun - sizeof tun.data;
|
||||
nw = write(tun_out, &tun, nb);
|
||||
nw = write(bundle->tun_fd, &tun, nb);
|
||||
if (nw != nb)
|
||||
if (nw == -1)
|
||||
LogPrintf(LogERROR, "IpInput: wrote %d, got %s\n", nb,
|
||||
@ -443,7 +443,7 @@ IpInput(struct mbuf * bp)
|
||||
frag = (struct tun_data *)
|
||||
((char *)fptr - sizeof tun + sizeof tun.data);
|
||||
nb += sizeof tun - sizeof tun.data;
|
||||
nw = write(tun_out, frag, nb);
|
||||
nw = write(bundle->tun_fd, frag, nb);
|
||||
if (nw != nb)
|
||||
if (nw == -1)
|
||||
LogPrintf(LogERROR, "IpInput: wrote %d, got %s\n", nb,
|
||||
@ -474,7 +474,7 @@ IpInput(struct mbuf * bp)
|
||||
}
|
||||
IpcpAddInOctets(nb);
|
||||
nb += sizeof tun - sizeof tun.data;
|
||||
nw = write(tun_out, &tun, nb);
|
||||
nw = write(bundle->tun_fd, &tun, nb);
|
||||
if (nw != nb)
|
||||
if (nw == -1)
|
||||
LogPrintf(LogERROR, "IpInput: wrote %d, got %s\n", nb, strerror(errno));
|
||||
|
@ -17,15 +17,15 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: ip.h,v 1.8.2.1 1998/01/29 00:49:23 brian Exp $
|
||||
* $Id: ip.h,v 1.8.2.2 1998/01/30 19:45:43 brian Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
extern void IpStartOutput(struct link *);
|
||||
extern int PacketCheck(char *, int, int);
|
||||
extern void IpEnqueue(int, char *, int);
|
||||
extern void IpInput(struct mbuf *);
|
||||
extern void IpInput(struct bundle *, struct mbuf *);
|
||||
extern void StartIdleTimer(void);
|
||||
extern void StopIdleTimer(void);
|
||||
extern void UpdateIdleTimer(void);
|
||||
extern void UpdateIdleTimer(const struct bundle *);
|
||||
extern int RemainingIdleTime(void);
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: ipcp.c,v 1.50.2.3 1998/01/30 19:45:44 brian Exp $
|
||||
* $Id: ipcp.c,v 1.50.2.4 1998/01/31 02:48:20 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
* o More RFC1772 backwoard compatibility
|
||||
@ -47,7 +47,7 @@
|
||||
#include "throughput.h"
|
||||
#include "ipcp.h"
|
||||
#include "slcompress.h"
|
||||
#include "os.h"
|
||||
#include "bundle.h"
|
||||
#include "phase.h"
|
||||
#include "loadalias.h"
|
||||
#include "vars.h"
|
||||
@ -73,7 +73,7 @@ static void IpcpInitRestartCounter(struct fsm *);
|
||||
static void IpcpSendConfigReq(struct fsm *);
|
||||
static void IpcpSendTerminateReq(struct fsm *);
|
||||
static void IpcpSendTerminateAck(struct fsm *);
|
||||
static void IpcpDecodeConfig(u_char *, int, int);
|
||||
static void IpcpDecodeConfig(struct bundle *, u_char *, int, int);
|
||||
|
||||
struct ipcpstate IpcpInfo = {
|
||||
{
|
||||
@ -87,7 +87,8 @@ struct ipcpstate IpcpInfo = {
|
||||
{0, 0, 0, NULL, NULL, NULL}, /* Open timer */
|
||||
{0, 0, 0, NULL, NULL, NULL}, /* Stopped timer */
|
||||
LogIPCP,
|
||||
NULL,
|
||||
NULL, /* link */
|
||||
NULL, /* bundle */
|
||||
IpcpLayerUp,
|
||||
IpcpLayerDown,
|
||||
IpcpLayerStart,
|
||||
@ -224,10 +225,10 @@ ShowInitVJ(struct cmdargs const *args)
|
||||
}
|
||||
|
||||
void
|
||||
IpcpInit(struct link *l)
|
||||
IpcpInit(struct bundle *bundle, struct link *l)
|
||||
{
|
||||
/* Initialise ourselves */
|
||||
FsmInit(&IpcpInfo.fsm, l);
|
||||
FsmInit(&IpcpInfo.fsm, bundle, l);
|
||||
if (iplist_isvalid(&IpcpInfo.DefHisChoice))
|
||||
iplist_setrandpos(&IpcpInfo.DefHisChoice);
|
||||
IpcpInfo.his_compproto = 0;
|
||||
@ -348,7 +349,7 @@ IpcpLayerDown(struct fsm * fp)
|
||||
}
|
||||
|
||||
static void
|
||||
IpcpLayerUp(struct fsm * fp)
|
||||
IpcpLayerUp(struct fsm *fp)
|
||||
{
|
||||
/* We're now up */
|
||||
char tbuff[100];
|
||||
@ -363,7 +364,8 @@ IpcpLayerUp(struct fsm * fp)
|
||||
|
||||
LogPrintf(LogIsKept(LogIPCP) ? LogIPCP : LogLINK, " %s hisaddr = %s\n",
|
||||
tbuff, inet_ntoa(IpcpInfo.his_ipaddr));
|
||||
if (OsSetIpaddress(IpcpInfo.want_ipaddr, IpcpInfo.his_ipaddr) < 0) {
|
||||
if (bundle_SetIPaddress(fp->bundle, IpcpInfo.want_ipaddr,
|
||||
IpcpInfo.his_ipaddr) < 0) {
|
||||
if (VarTerm)
|
||||
LogPrintf(LogERROR, "IpcpLayerUp: unable to set ip address\n");
|
||||
return;
|
||||
@ -372,7 +374,7 @@ IpcpLayerUp(struct fsm * fp)
|
||||
if (mode & MODE_ALIAS)
|
||||
VarPacketAliasSetAddress(IpcpInfo.want_ipaddr);
|
||||
#endif
|
||||
OsLinkup();
|
||||
bundle_Linkup(fp->bundle);
|
||||
throughput_start(&IpcpInfo.throughput);
|
||||
StartIdleTimer();
|
||||
}
|
||||
@ -417,7 +419,7 @@ AcceptableAddr(struct in_range *prange, struct in_addr ipaddr)
|
||||
}
|
||||
|
||||
static void
|
||||
IpcpDecodeConfig(u_char * cp, int plen, int mode_type)
|
||||
IpcpDecodeConfig(struct bundle *bundle, u_char * cp, int plen, int mode_type)
|
||||
{
|
||||
/* Deal with incoming PROTO_IPCP */
|
||||
int type, length;
|
||||
@ -452,10 +454,12 @@ IpcpDecodeConfig(u_char * cp, int plen, int mode_type)
|
||||
if (iplist_isvalid(&IpcpInfo.DefHisChoice)) {
|
||||
if (ipaddr.s_addr == INADDR_ANY ||
|
||||
iplist_ip2pos(&IpcpInfo.DefHisChoice, ipaddr) < 0 ||
|
||||
OsTrySetIpaddress(IpcpInfo.DefMyAddress.ipaddr, ipaddr) != 0) {
|
||||
bundle_TrySetIPaddress(bundle, IpcpInfo.DefMyAddress.ipaddr,
|
||||
ipaddr)) {
|
||||
LogPrintf(LogIPCP, "%s: Address invalid or already in use\n",
|
||||
inet_ntoa(ipaddr));
|
||||
IpcpInfo.his_ipaddr = ChooseHisAddr(IpcpInfo.DefMyAddress.ipaddr);
|
||||
IpcpInfo.his_ipaddr = ChooseHisAddr
|
||||
(bundle, IpcpInfo.DefMyAddress.ipaddr);
|
||||
if (IpcpInfo.his_ipaddr.s_addr == INADDR_ANY) {
|
||||
memcpy(rejp, cp, length);
|
||||
rejp += length;
|
||||
@ -701,7 +705,7 @@ IpcpInput(struct mbuf * bp)
|
||||
}
|
||||
|
||||
int
|
||||
UseHisaddr(const char *hisaddr, int setaddr)
|
||||
UseHisaddr(struct bundle *bundle, const char *hisaddr, int setaddr)
|
||||
{
|
||||
/* Use `hisaddr' for the peers address (set iface if `setaddr') */
|
||||
memset(&IpcpInfo.DefHisAddress, '\0', sizeof IpcpInfo.DefHisAddress);
|
||||
@ -710,7 +714,7 @@ UseHisaddr(const char *hisaddr, int setaddr)
|
||||
iplist_setsrc(&IpcpInfo.DefHisChoice, hisaddr);
|
||||
if (iplist_isvalid(&IpcpInfo.DefHisChoice)) {
|
||||
iplist_setrandpos(&IpcpInfo.DefHisChoice);
|
||||
IpcpInfo.his_ipaddr = ChooseHisAddr(IpcpInfo.want_ipaddr);
|
||||
IpcpInfo.his_ipaddr = ChooseHisAddr(bundle, IpcpInfo.want_ipaddr);
|
||||
if (IpcpInfo.his_ipaddr.s_addr == INADDR_ANY) {
|
||||
LogPrintf(LogWARN, "%s: None available !\n", IpcpInfo.DefHisChoice.src);
|
||||
return(0);
|
||||
@ -727,8 +731,8 @@ UseHisaddr(const char *hisaddr, int setaddr)
|
||||
&IpcpInfo.DefHisAddress.width) != 0) {
|
||||
IpcpInfo.his_ipaddr.s_addr = IpcpInfo.DefHisAddress.ipaddr.s_addr;
|
||||
|
||||
if (setaddr && OsSetIpaddress
|
||||
(IpcpInfo.DefMyAddress.ipaddr, IpcpInfo.DefHisAddress.ipaddr) < 0) {
|
||||
if (setaddr && bundle_SetIPaddress(bundle, IpcpInfo.DefMyAddress.ipaddr,
|
||||
IpcpInfo.DefHisAddress.ipaddr) < 0) {
|
||||
IpcpInfo.DefMyAddress.ipaddr.s_addr = INADDR_ANY;
|
||||
IpcpInfo.DefHisAddress.ipaddr.s_addr = INADDR_ANY;
|
||||
return 0;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: ipcp.h,v 1.18.2.5 1998/01/30 19:45:45 brian Exp $
|
||||
* $Id: ipcp.h,v 1.18.2.6 1998/01/31 02:48:21 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -74,7 +74,7 @@ struct ipcpstate {
|
||||
|
||||
extern struct ipcpstate IpcpInfo;
|
||||
|
||||
extern void IpcpInit(struct link *l);
|
||||
extern void IpcpInit(struct bundle *, struct link *l);
|
||||
extern void IpcpDefAddress(void);
|
||||
extern void IpcpUp(void);
|
||||
extern void IpcpOpen(void);
|
||||
@ -82,7 +82,7 @@ extern int ReportIpcpStatus(struct cmdargs const *);
|
||||
extern void IpcpInput(struct mbuf *);
|
||||
extern void IpcpAddInOctets(int);
|
||||
extern void IpcpAddOutOctets(int);
|
||||
extern int UseHisaddr(const char *, int);
|
||||
extern int UseHisaddr(struct bundle *, const char *, int);
|
||||
extern int SetInitVJ(struct cmdargs const *);
|
||||
extern int ShowInitVJ(struct cmdargs const *);
|
||||
extern void IpcpDown(void);
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: lcp.c,v 1.55.2.4 1998/01/30 19:45:47 brian Exp $
|
||||
* $Id: lcp.c,v 1.55.2.5 1998/01/31 02:48:21 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
* o Limit data field length by MRU
|
||||
@ -50,7 +50,7 @@
|
||||
#include "throughput.h"
|
||||
#include "ipcp.h"
|
||||
#include "lcpproto.h"
|
||||
#include "os.h"
|
||||
#include "bundle.h"
|
||||
#include "hdlc.h"
|
||||
#include "ccp.h"
|
||||
#include "lqr.h"
|
||||
@ -84,7 +84,7 @@ static void LcpInitRestartCounter(struct fsm *);
|
||||
static void LcpSendConfigReq(struct fsm *);
|
||||
static void LcpSendTerminateReq(struct fsm *);
|
||||
static void LcpSendTerminateAck(struct fsm *);
|
||||
static void LcpDecodeConfig(u_char *, int, int);
|
||||
static void LcpDecodeConfig(struct bundle *, u_char *, int, int);
|
||||
|
||||
struct lcpstate LcpInfo = {
|
||||
{
|
||||
@ -98,7 +98,8 @@ struct lcpstate LcpInfo = {
|
||||
{0, 0, 0, NULL, NULL, NULL}, /* Open timer */
|
||||
{0, 0, 0, NULL, NULL, NULL}, /* Stopped timer */
|
||||
LogLCP,
|
||||
NULL,
|
||||
NULL, /* link */
|
||||
NULL, /* bundle */
|
||||
LcpLayerUp,
|
||||
LcpLayerDown,
|
||||
LcpLayerStart,
|
||||
@ -194,10 +195,10 @@ GenerateMagic(void)
|
||||
}
|
||||
|
||||
void
|
||||
LcpInit(struct physical *physical)
|
||||
LcpInit(struct bundle *bundle, struct physical *physical)
|
||||
{
|
||||
/* Initialise ourselves */
|
||||
FsmInit(&LcpInfo.fsm, physical2link(physical));
|
||||
FsmInit(&LcpInfo.fsm, bundle, physical2link(physical));
|
||||
HdlcInit();
|
||||
|
||||
LcpInfo.his_mru = DEF_MRU;
|
||||
@ -392,7 +393,7 @@ LcpLayerStart(struct fsm *fp)
|
||||
|
||||
LogPrintf(LogLCP, "LcpLayerStart\n");
|
||||
if (p)
|
||||
NewPhase(p, PHASE_ESTABLISH);
|
||||
NewPhase(fp->bundle, p, PHASE_ESTABLISH);
|
||||
else
|
||||
LogPrintf(LogERROR, "LcpLayerStart: Not a physical link !\n");
|
||||
}
|
||||
@ -422,7 +423,7 @@ LcpLayerFinish(struct fsm *fp)
|
||||
|
||||
/* We're down at last. Lets tell background and direct mode to get out */
|
||||
if (p)
|
||||
NewPhase(p, PHASE_DEAD);
|
||||
NewPhase(fp->bundle, p, PHASE_DEAD);
|
||||
else
|
||||
LogPrintf(LogERROR, "LcpLayerFinish: Not a physical link !\n");
|
||||
Prompt();
|
||||
@ -438,7 +439,7 @@ LcpLayerUp(struct fsm *fp)
|
||||
SetLinkParams(&LcpInfo);
|
||||
|
||||
if (p) {
|
||||
NewPhase(p, PHASE_AUTHENTICATE);
|
||||
NewPhase(fp->bundle, p, PHASE_AUTHENTICATE);
|
||||
StartLqm(p);
|
||||
} else
|
||||
LogPrintf(LogERROR, "LcpLayerUp: Not a physical link !\n");
|
||||
@ -452,14 +453,14 @@ LcpLayerUp(struct fsm *fp)
|
||||
}
|
||||
|
||||
static void
|
||||
LcpLayerDown(struct fsm * fp)
|
||||
LcpLayerDown(struct fsm *fp)
|
||||
{
|
||||
/* About to come down */
|
||||
OsLinkdown();
|
||||
bundle_Linkdown(fp->bundle);
|
||||
|
||||
LogPrintf(LogLCP, "LcpLayerDown\n");
|
||||
/*
|
||||
* OsLinkdown() brings CCP & IPCP down, then waits 'till we go from
|
||||
* bundle_Linkdown() brings CCP & IPCP down, then waits 'till we go from
|
||||
* STOPPING to STOPPED. At this point, the FSM gives us a LayerFinish
|
||||
*/
|
||||
}
|
||||
@ -499,16 +500,18 @@ LcpClose(struct fsm *fp)
|
||||
struct physical *p = link2physical(fp->link);
|
||||
|
||||
if (p)
|
||||
NewPhase(p, PHASE_TERMINATE);
|
||||
NewPhase(fp->bundle, p, PHASE_TERMINATE);
|
||||
else
|
||||
LogPrintf(LogERROR, "LcpClose: Not a physical link !\n");
|
||||
|
||||
OsInterfaceDown(0);
|
||||
bundle_Linkdown(fp->bundle);
|
||||
if (!(mode & MODE_DAEMON))
|
||||
bundle_InterfaceDown(fp->bundle);
|
||||
FsmClose(fp);
|
||||
}
|
||||
|
||||
static void
|
||||
LcpDecodeConfig(u_char *cp, int plen, int mode_type)
|
||||
LcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
|
||||
{
|
||||
/* Deal with incoming PROTO_LCP */
|
||||
int type, length, sz, pos;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: lcp.h,v 1.16.2.2 1998/01/30 01:33:45 brian Exp $
|
||||
* $Id: lcp.h,v 1.16.2.3 1998/01/31 02:48:22 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -74,7 +74,7 @@ struct physical;
|
||||
|
||||
extern struct lcpstate LcpInfo;
|
||||
|
||||
extern void LcpInit(struct physical *);
|
||||
extern void LcpInit(struct bundle *, struct physical *);
|
||||
extern void LcpUp(void);
|
||||
extern void LcpSendProtoRej(u_char *, int);
|
||||
extern void LcpOpen(int);
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: main.c,v 1.121.2.3 1998/01/30 19:45:53 brian Exp $
|
||||
* $Id: main.c,v 1.121.2.4 1998/01/31 02:48:25 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
* o Add commands for traffic summary, version display, etc.
|
||||
@ -54,7 +54,7 @@
|
||||
#include "timer.h"
|
||||
#include "fsm.h"
|
||||
#include "modem.h"
|
||||
#include "os.h"
|
||||
#include "bundle.h"
|
||||
#include "hdlc.h"
|
||||
#include "lcp.h"
|
||||
#include "ccp.h"
|
||||
@ -93,7 +93,7 @@ static pid_t BGPid = 0;
|
||||
static char pid_filename[MAXPATHLEN];
|
||||
static int dial_up;
|
||||
|
||||
static void DoLoop(void);
|
||||
static void DoLoop(struct bundle *);
|
||||
static void TerminalStop(int);
|
||||
static const char *ex_desc(int);
|
||||
|
||||
@ -178,16 +178,18 @@ TtyOldMode()
|
||||
tcsetattr(netfd, TCSADRAIN, &oldtio);
|
||||
}
|
||||
|
||||
static struct bundle *CleanupBundle;
|
||||
|
||||
void
|
||||
Cleanup(int excode)
|
||||
{
|
||||
DropClient(1);
|
||||
ServerClose();
|
||||
OsInterfaceDown(1);
|
||||
bundle_InterfaceDown(CleanupBundle);
|
||||
link_Close(physical2link(pppVars.physical), 1); /* XXX gotta get a handle on
|
||||
* the logical link */
|
||||
nointr_sleep(1);
|
||||
DeleteIfRoutes(1);
|
||||
DeleteIfRoutes(CleanupBundle, 1);
|
||||
ID0unlink(pid_filename);
|
||||
if (mode & MODE_BACKGROUND && BGFiledes[1] != -1) {
|
||||
char c = EX_ERRDEAD;
|
||||
@ -353,6 +355,7 @@ main(int argc, char **argv)
|
||||
FILE *lockfile;
|
||||
char *name, *label;
|
||||
int nfds;
|
||||
struct bundle *bundle;
|
||||
|
||||
nfds = getdtablesize();
|
||||
if (nfds >= FD_SETSIZE)
|
||||
@ -411,14 +414,16 @@ main(int argc, char **argv)
|
||||
if (mode & MODE_INTER)
|
||||
VarLocalAuth = LOCAL_AUTH;
|
||||
|
||||
if (SelectSystem("default", CONFFILE) < 0 && VarTerm)
|
||||
fprintf(VarTerm, "Warning: No default entry is given in config file.\n");
|
||||
|
||||
if (OpenTunnel(&tunno) < 0) {
|
||||
LogPrintf(LogWARN, "OpenTunnel: %s\n", strerror(errno));
|
||||
if ((bundle = bundle_Create("/dev/tun")) == NULL) {
|
||||
LogPrintf(LogWARN, "bundle_Create: %s\n", strerror(errno));
|
||||
return EX_START;
|
||||
}
|
||||
CleanInterface(IfDevName);
|
||||
|
||||
CleanupBundle = bundle;
|
||||
|
||||
if (SelectSystem(bundle, "default", CONFFILE) < 0 && VarTerm)
|
||||
fprintf(VarTerm, "Warning: No default entry is given in config file.\n");
|
||||
|
||||
if ((mode & MODE_OUTGOING_DAEMON) && !(mode & MODE_DEDICATED))
|
||||
if (label == NULL) {
|
||||
if (VarTerm)
|
||||
@ -458,7 +463,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (label) {
|
||||
if (SelectSystem(label, CONFFILE) < 0) {
|
||||
if (SelectSystem(bundle, label, CONFFILE) < 0) {
|
||||
LogPrintf(LogWARN, "Destination system %s not found in conf file.\n",
|
||||
GetLabel());
|
||||
Cleanup(EX_START);
|
||||
@ -556,7 +561,7 @@ main(int argc, char **argv)
|
||||
|
||||
|
||||
do
|
||||
DoLoop();
|
||||
DoLoop(bundle);
|
||||
while (mode & MODE_DEDICATED);
|
||||
|
||||
Cleanup(EX_DONE);
|
||||
@ -567,7 +572,7 @@ main(int argc, char **argv)
|
||||
* Turn into packet mode, where we speak PPP.
|
||||
*/
|
||||
void
|
||||
PacketMode(int delay)
|
||||
PacketMode(struct bundle *bundle, int delay)
|
||||
{
|
||||
if (RawModem(pppVars.physical) < 0) {
|
||||
LogPrintf(LogWARN, "PacketMode: Not connected.\n");
|
||||
@ -575,9 +580,9 @@ PacketMode(int delay)
|
||||
}
|
||||
AsyncInit();
|
||||
VjInit(15);
|
||||
LcpInit(pppVars.physical);
|
||||
IpcpInit(physical2link(pppVars.physical));
|
||||
CcpInit(physical2link(pppVars.physical));
|
||||
LcpInit(bundle, pppVars.physical);
|
||||
IpcpInit(bundle, physical2link(pppVars.physical));
|
||||
CcpInit(bundle, physical2link(pppVars.physical));
|
||||
LcpUp();
|
||||
|
||||
LcpOpen(delay);
|
||||
@ -603,7 +608,7 @@ ShowHelp(void)
|
||||
}
|
||||
|
||||
static void
|
||||
ReadTty(void)
|
||||
ReadTty(struct bundle *bundle)
|
||||
{
|
||||
int n;
|
||||
char ch;
|
||||
@ -621,7 +626,7 @@ ReadTty(void)
|
||||
else
|
||||
linebuff[n] = '\0';
|
||||
if (n)
|
||||
DecodeCommand(linebuff, n, IsInteractive(0) ? NULL : "Client");
|
||||
DecodeCommand(bundle, linebuff, n, IsInteractive(0) ? NULL : "Client");
|
||||
Prompt();
|
||||
} else if (n <= 0) {
|
||||
LogPrintf(LogPHASE, "Client connection closed.\n");
|
||||
@ -656,7 +661,7 @@ ReadTty(void)
|
||||
* XXX: Should check carrier.
|
||||
*/
|
||||
if (LcpInfo.fsm.state <= ST_CLOSED)
|
||||
PacketMode(0);
|
||||
PacketMode(bundle, 0);
|
||||
break;
|
||||
case '.':
|
||||
TermMode = 1;
|
||||
@ -751,7 +756,7 @@ StartRedialTimer(int Timeout)
|
||||
#define ADDRSZ (IN_SIZE > UN_SIZE ? IN_SIZE : UN_SIZE)
|
||||
|
||||
static void
|
||||
DoLoop(void)
|
||||
DoLoop(struct bundle *bundle)
|
||||
{
|
||||
fd_set rfds, wfds, efds;
|
||||
int pri, i, n, wfd, nfds;
|
||||
@ -769,13 +774,13 @@ DoLoop(void)
|
||||
|
||||
if (mode & MODE_DIRECT) {
|
||||
LogPrintf(LogDEBUG, "Opening modem\n");
|
||||
if (OpenModem(pppVars.physical) < 0)
|
||||
if (OpenModem(bundle, pppVars.physical) < 0)
|
||||
return;
|
||||
LogPrintf(LogPHASE, "Packet mode enabled\n");
|
||||
PacketMode(VarOpenMode);
|
||||
PacketMode(bundle, VarOpenMode);
|
||||
} else if (mode & MODE_DEDICATED) {
|
||||
if (!link_IsActive(physical2link(pppVars.physical)))
|
||||
while (OpenModem(pppVars.physical) < 0)
|
||||
while (OpenModem(bundle, pppVars.physical) < 0)
|
||||
nointr_sleep(VarReconnectTimer);
|
||||
}
|
||||
fflush(VarTerm);
|
||||
@ -822,7 +827,7 @@ DoLoop(void)
|
||||
}
|
||||
reconnectState = RECON_ENVOKED;
|
||||
} else if (mode & MODE_DEDICATED)
|
||||
PacketMode(VarOpenMode);
|
||||
PacketMode(bundle, VarOpenMode);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -831,7 +836,7 @@ DoLoop(void)
|
||||
if (dial_up && RedialTimer.state != TIMER_RUNNING) {
|
||||
LogPrintf(LogDEBUG, "going to dial: modem = %d\n",
|
||||
Physical_GetFD(pppVars.physical));
|
||||
if (OpenModem(pppVars.physical) < 0) {
|
||||
if (OpenModem(bundle, pppVars.physical) < 0) {
|
||||
tries++;
|
||||
if (!(mode & MODE_DDIAL) && VarDialTries)
|
||||
LogPrintf(LogCHAT, "Failed to open modem (attempt %u of %d)\n",
|
||||
@ -856,9 +861,8 @@ DoLoop(void)
|
||||
else
|
||||
LogPrintf(LogCHAT, "Dial attempt %u\n", tries);
|
||||
|
||||
if ((res = DialModem(pppVars.physical)) == EX_DONE) {
|
||||
ModemTimeout(pppVars.physical);
|
||||
PacketMode(VarOpenMode);
|
||||
if ((res = DialModem(bundle, pppVars.physical)) == EX_DONE) {
|
||||
PacketMode(bundle, VarOpenMode);
|
||||
dial_up = 0;
|
||||
reconnectState = RECON_UNKNOWN;
|
||||
tries = 0;
|
||||
@ -924,10 +928,10 @@ DoLoop(void)
|
||||
#endif
|
||||
|
||||
/* If there are aren't many packets queued, look for some more. */
|
||||
if (qlen < 20 && tun_in >= 0) {
|
||||
if (tun_in + 1 > nfds)
|
||||
nfds = tun_in + 1;
|
||||
FD_SET(tun_in, &rfds);
|
||||
if (qlen < 20 && bundle->tun_fd >= 0) {
|
||||
if (bundle->tun_fd + 1 > nfds)
|
||||
nfds = bundle->tun_fd + 1;
|
||||
FD_SET(bundle->tun_fd, &rfds);
|
||||
}
|
||||
if (netfd >= 0) {
|
||||
if (netfd + 1 > nfds)
|
||||
@ -1010,7 +1014,7 @@ DoLoop(void)
|
||||
}
|
||||
if (netfd >= 0 && FD_ISSET(netfd, &rfds))
|
||||
/* something to read from tty */
|
||||
ReadTty();
|
||||
ReadTty(bundle);
|
||||
if (Physical_FD_ISSET(pppVars.physical, &wfds)) {
|
||||
/* ready to write into modem */
|
||||
link_StartOutput(physical2link(pppVars.physical));
|
||||
@ -1042,18 +1046,18 @@ DoLoop(void)
|
||||
Physical_Write(pppVars.physical, rbuff, cp - rbuff);
|
||||
Physical_Write(pppVars.physical, "\r\n", 2);
|
||||
}
|
||||
PacketMode(0);
|
||||
PacketMode(bundle, 0);
|
||||
} else
|
||||
write(fileno(VarTerm), rbuff, n);
|
||||
}
|
||||
} else {
|
||||
if (n > 0)
|
||||
AsyncInput(rbuff, n, pppVars.physical);
|
||||
AsyncInput(bundle, rbuff, n, pppVars.physical);
|
||||
}
|
||||
}
|
||||
if (tun_in >= 0 && FD_ISSET(tun_in, &rfds)) { /* something to read
|
||||
* from tun */
|
||||
n = read(tun_in, &tun, sizeof tun);
|
||||
if (bundle->tun_fd >= 0 && FD_ISSET(bundle->tun_fd, &rfds)) {
|
||||
/* something to read from tun */
|
||||
n = read(bundle->tun_fd, &tun, sizeof tun);
|
||||
if (n < 0) {
|
||||
LogPrintf(LogERROR, "read from tun: %s\n", strerror(errno));
|
||||
continue;
|
||||
@ -1080,7 +1084,7 @@ DoLoop(void)
|
||||
#endif
|
||||
bp = mballoc(n, MB_IPIN);
|
||||
memcpy(MBUF_CTOP(bp), rbuff, n);
|
||||
IpInput(bp);
|
||||
IpInput(bundle, bp);
|
||||
LogPrintf(LogDEBUG, "Looped back packet addressed to myself\n");
|
||||
}
|
||||
continue;
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: main.h,v 1.8 1997/11/22 03:37:39 brian Exp $
|
||||
* $Id: main.h,v 1.9 1998/01/20 22:47:41 brian Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -26,6 +26,6 @@ extern int tunno;
|
||||
|
||||
extern void Cleanup(int);
|
||||
extern void TtyTermMode(void);
|
||||
extern void PacketMode(int);
|
||||
extern void PacketMode(struct bundle *, int);
|
||||
extern void TtyOldMode(void);
|
||||
extern void TtyCommandMode(int);
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: modem.c,v 1.77.2.1 1998/01/29 00:49:26 brian Exp $
|
||||
* $Id: modem.c,v 1.77.2.2 1998/01/30 19:45:57 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -98,7 +98,7 @@ struct physical phys_modem = {
|
||||
|
||||
/* XXX-ML this should probably change when we add support for other
|
||||
types of devices */
|
||||
#define Online (modem->mbits & TIOCM_CD)
|
||||
#define Online(modem) ((modem)->mbits & TIOCM_CD)
|
||||
|
||||
static void CloseLogicalModem(struct physical *);
|
||||
|
||||
@ -217,43 +217,48 @@ DownConnection()
|
||||
LcpDown();
|
||||
}
|
||||
|
||||
struct timeoutArg {
|
||||
struct bundle *bundle;
|
||||
struct physical *modem;
|
||||
};
|
||||
|
||||
/*
|
||||
* ModemTimeout() watches DCD signal and notifies if it's status is changed.
|
||||
*
|
||||
*/
|
||||
void
|
||||
static void
|
||||
ModemTimeout(void *data)
|
||||
{
|
||||
struct physical *modem = data;
|
||||
int ombits = modem->mbits;
|
||||
struct timeoutArg *to = data;
|
||||
int ombits = to->modem->mbits;
|
||||
int change;
|
||||
|
||||
StopTimer(&modem->link.Timer);
|
||||
StartTimer(&modem->link.Timer);
|
||||
StopTimer(&to->modem->link.Timer);
|
||||
StartTimer(&to->modem->link.Timer);
|
||||
|
||||
if (modem->dev_is_modem) {
|
||||
if (modem->fd >= 0) {
|
||||
if (ioctl(modem->fd, TIOCMGET, &modem->mbits) < 0) {
|
||||
if (to->modem->dev_is_modem) {
|
||||
if (to->modem->fd >= 0) {
|
||||
if (ioctl(to->modem->fd, TIOCMGET, &to->modem->mbits) < 0) {
|
||||
LogPrintf(LogPHASE, "ioctl error (%s)!\n", strerror(errno));
|
||||
DownConnection();
|
||||
return;
|
||||
}
|
||||
} else
|
||||
modem->mbits = 0;
|
||||
change = ombits ^ modem->mbits;
|
||||
to->modem->mbits = 0;
|
||||
change = ombits ^ to->modem->mbits;
|
||||
if (change & TIOCM_CD) {
|
||||
if (modem->mbits & TIOCM_CD) {
|
||||
if (to->modem->mbits & TIOCM_CD) {
|
||||
LogPrintf(LogDEBUG, "ModemTimeout: offline -> online\n");
|
||||
/*
|
||||
* In dedicated mode, start packet mode immediate after we detected
|
||||
* carrier.
|
||||
*/
|
||||
#ifdef notyet
|
||||
if (modem->is_dedicated)
|
||||
PacketMode(VarOpenMode);
|
||||
if (to->modem->is_dedicated)
|
||||
PacketMode(to->bundle, VarOpenMode);
|
||||
#else
|
||||
if (mode & MODE_DEDICATED)
|
||||
PacketMode(VarOpenMode);
|
||||
PacketMode(to->bundle, VarOpenMode);
|
||||
#endif
|
||||
} else {
|
||||
LogPrintf(LogDEBUG, "ModemTimeout: online -> offline\n");
|
||||
@ -263,25 +268,28 @@ ModemTimeout(void *data)
|
||||
}
|
||||
else
|
||||
LogPrintf(LogDEBUG, "ModemTimeout: Still %sline\n",
|
||||
Online ? "on" : "off");
|
||||
} else if (!Online) {
|
||||
Online(to->modem) ? "on" : "off");
|
||||
} else if (!Online(to->modem)) {
|
||||
/* mbits was set to zero in OpenModem() */
|
||||
modem->mbits = TIOCM_CD;
|
||||
to->modem->mbits = TIOCM_CD;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
StartModemTimer(struct physical *modem)
|
||||
StartModemTimer(struct bundle *bundle, struct physical *modem)
|
||||
{
|
||||
struct pppTimer *ModemTimer;
|
||||
static struct timeoutArg to;
|
||||
|
||||
to.modem = modem;
|
||||
to.bundle = bundle;
|
||||
ModemTimer = &modem->link.Timer;
|
||||
|
||||
StopTimer(ModemTimer);
|
||||
ModemTimer->state = TIMER_STOPPED;
|
||||
ModemTimer->load = SECTICKS;
|
||||
ModemTimer->func = ModemTimeout;
|
||||
ModemTimer->arg = modem;
|
||||
ModemTimer->arg = &to;
|
||||
LogPrintf(LogDEBUG, "ModemTimer using ModemTimeout() - %p\n", ModemTimeout);
|
||||
StartTimer(ModemTimer);
|
||||
}
|
||||
@ -447,7 +455,7 @@ HaveModem(struct physical *modem)
|
||||
}
|
||||
|
||||
int
|
||||
OpenModem(struct physical *modem)
|
||||
OpenModem(struct bundle *bundle, struct physical *modem)
|
||||
{
|
||||
struct termios rstio;
|
||||
int oldflag;
|
||||
@ -627,7 +635,7 @@ OpenModem(struct physical *modem)
|
||||
}
|
||||
(void) fcntl(modem->fd, F_SETFL, oldflag & ~O_NONBLOCK);
|
||||
}
|
||||
StartModemTimer(modem);
|
||||
StartModemTimer(bundle, modem);
|
||||
|
||||
return (modem->fd);
|
||||
}
|
||||
@ -658,7 +666,7 @@ RawModem(struct physical *modem)
|
||||
#else
|
||||
!(mode & MODE_DIRECT) &&
|
||||
#endif
|
||||
modem->fd >= 0 && !Online) {
|
||||
modem->fd >= 0 && !Online(modem)) {
|
||||
LogPrintf(LogDEBUG, "RawModem: modem = %d, mbits = %x\n",
|
||||
modem->fd, modem->mbits);
|
||||
}
|
||||
@ -734,7 +742,7 @@ ModemHangup(struct link *l, int dedicated_force)
|
||||
return;
|
||||
}
|
||||
|
||||
if (modem->fd >= 0 && Online) {
|
||||
if (modem->fd >= 0 && Online(modem)) {
|
||||
modem->mbits &= ~TIOCM_DTR;
|
||||
tcgetattr(modem->fd, &tio);
|
||||
if (cfsetspeed(&tio, B0) == -1) {
|
||||
@ -842,7 +850,7 @@ ModemIsActive(struct link *l)
|
||||
}
|
||||
|
||||
int
|
||||
DialModem(struct physical *modem)
|
||||
DialModem(struct bundle *bundle, struct physical *modem)
|
||||
{
|
||||
char ScriptBuffer[SCRIPT_LEN];
|
||||
int excode;
|
||||
@ -854,9 +862,14 @@ DialModem(struct physical *modem)
|
||||
fprintf(VarTerm, "dial OK!\n");
|
||||
strncpy(ScriptBuffer, VarLoginScript, sizeof ScriptBuffer - 1);
|
||||
if ((excode = DoChat(modem, ScriptBuffer)) > 0) {
|
||||
struct timeoutArg to;
|
||||
|
||||
VarAltPhone = NULL;
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "login OK!\n");
|
||||
to.modem = pppVars.physical;
|
||||
to.bundle = bundle;
|
||||
ModemTimeout(&to);
|
||||
return EX_DONE;
|
||||
} else if (excode == -1)
|
||||
excode = EX_SIG;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: modem.h,v 1.16.2.1 1998/01/29 00:49:27 brian Exp $
|
||||
* $Id: modem.h,v 1.16.2.2 1998/01/30 19:45:59 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -23,11 +23,10 @@
|
||||
struct physical;
|
||||
|
||||
extern int RawModem(struct physical *);
|
||||
extern int OpenModem(struct physical *);
|
||||
extern int OpenModem(struct bundle *, struct physical *);
|
||||
extern int ModemSpeed(struct physical *);
|
||||
extern int DialModem(struct physical *);
|
||||
extern int DialModem(struct bundle *, struct physical *);
|
||||
extern speed_t IntToSpeed(int);
|
||||
extern void ModemTimeout(void *);
|
||||
extern void DownConnection(void);
|
||||
extern int ChangeParity(struct physical *, const char *);
|
||||
extern int ShowModemStatus(struct cmdargs const *);
|
||||
|
@ -1,412 +0,0 @@
|
||||
/*
|
||||
* PPP OS Layer Interface 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.
|
||||
*
|
||||
* $Id: os.c,v 1.42.2.1 1998/01/29 23:11:40 brian Exp $
|
||||
*
|
||||
*/
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "command.h"
|
||||
#include "mbuf.h"
|
||||
#include "log.h"
|
||||
#include "id.h"
|
||||
#include "defs.h"
|
||||
#include "timer.h"
|
||||
#include "fsm.h"
|
||||
#include "iplist.h"
|
||||
#include "throughput.h"
|
||||
#include "ipcp.h"
|
||||
#include "os.h"
|
||||
#include "loadalias.h"
|
||||
#include "vars.h"
|
||||
#include "arp.h"
|
||||
#include "systems.h"
|
||||
#include "route.h"
|
||||
#include "lcp.h"
|
||||
#include "ccp.h"
|
||||
|
||||
char *IfDevName;
|
||||
|
||||
static struct ifaliasreq ifra;
|
||||
static struct ifreq ifrq;
|
||||
static struct in_addr oldmine, oldhis;
|
||||
static int linkup;
|
||||
|
||||
enum set_method { SET_UP, SET_DOWN, SET_TRY };
|
||||
|
||||
static int
|
||||
SetIpDevice(struct in_addr myaddr,
|
||||
struct in_addr hisaddr,
|
||||
struct in_addr netmask,
|
||||
enum set_method how)
|
||||
{
|
||||
struct sockaddr_in *sock_in;
|
||||
int s;
|
||||
u_long mask, addr;
|
||||
|
||||
s = ID0socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
LogPrintf(LogERROR, "SetIpDevice: socket(): %s\n", strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
if (how == SET_DOWN) {
|
||||
if (Enabled(ConfProxy))
|
||||
cifproxyarp(s, oldhis);
|
||||
if (oldmine.s_addr == INADDR_ANY && oldhis.s_addr == INADDR_ANY) {
|
||||
close(s);
|
||||
return (0);
|
||||
}
|
||||
memset(&ifra.ifra_addr, '\0', sizeof ifra.ifra_addr);
|
||||
memset(&ifra.ifra_broadaddr, '\0', sizeof ifra.ifra_broadaddr);
|
||||
memset(&ifra.ifra_mask, '\0', sizeof ifra.ifra_mask);
|
||||
if (ID0ioctl(s, SIOCDIFADDR, &ifra) < 0) {
|
||||
LogPrintf(LogERROR, "SetIpDevice: ioctl(SIOCDIFADDR): %s\n",
|
||||
strerror(errno));
|
||||
close(s);
|
||||
return (-1);
|
||||
}
|
||||
oldmine.s_addr = oldhis.s_addr = INADDR_ANY;
|
||||
} else {
|
||||
/* If given addresses are alreay set, then ignore this request */
|
||||
if (oldmine.s_addr == myaddr.s_addr && oldhis.s_addr == hisaddr.s_addr) {
|
||||
close(s);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* If different address has been set, then delete it first.
|
||||
*/
|
||||
if (oldmine.s_addr || oldhis.s_addr) {
|
||||
memset(&ifra.ifra_addr, '\0', sizeof ifra.ifra_addr);
|
||||
memset(&ifra.ifra_broadaddr, '\0', sizeof ifra.ifra_broadaddr);
|
||||
memset(&ifra.ifra_mask, '\0', sizeof ifra.ifra_mask);
|
||||
if (ID0ioctl(s, SIOCDIFADDR, &ifra) < 0) {
|
||||
LogPrintf(LogERROR, "SetIpDevice: ioctl(SIOCDIFADDR): %s\n",
|
||||
strerror(errno));
|
||||
close(s);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set interface address */
|
||||
sock_in = (struct sockaddr_in *) & (ifra.ifra_addr);
|
||||
sock_in->sin_family = AF_INET;
|
||||
sock_in->sin_addr = myaddr;
|
||||
sock_in->sin_len = sizeof *sock_in;
|
||||
|
||||
/* Set destination address */
|
||||
sock_in = (struct sockaddr_in *) & (ifra.ifra_broadaddr);
|
||||
sock_in->sin_family = AF_INET;
|
||||
sock_in->sin_addr = hisaddr;
|
||||
sock_in->sin_len = sizeof *sock_in;
|
||||
|
||||
addr = ntohl(myaddr.s_addr);
|
||||
if (IN_CLASSA(addr))
|
||||
mask = IN_CLASSA_NET;
|
||||
else if (IN_CLASSB(addr))
|
||||
mask = IN_CLASSB_NET;
|
||||
else
|
||||
mask = IN_CLASSC_NET;
|
||||
|
||||
/*
|
||||
* if subnet mask is given, use it instead of class mask.
|
||||
*/
|
||||
if (netmask.s_addr && (ntohl(netmask.s_addr) & mask) == mask)
|
||||
mask = ntohl(netmask.s_addr);
|
||||
|
||||
sock_in = (struct sockaddr_in *) & (ifra.ifra_mask);
|
||||
sock_in->sin_family = AF_INET;
|
||||
sock_in->sin_addr.s_addr = htonl(mask);
|
||||
sock_in->sin_len = sizeof *sock_in;
|
||||
|
||||
if (ID0ioctl(s, SIOCAIFADDR, &ifra) < 0) {
|
||||
if (how != SET_TRY)
|
||||
LogPrintf(LogERROR, "SetIpDevice: ioctl(SIOCAIFADDR): %s\n",
|
||||
strerror(errno));
|
||||
close(s);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
oldhis.s_addr = hisaddr.s_addr;
|
||||
oldmine.s_addr = myaddr.s_addr;
|
||||
if (Enabled(ConfProxy))
|
||||
sifproxyarp(s, hisaddr);
|
||||
}
|
||||
close(s);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
CleanInterface(const char *name)
|
||||
{
|
||||
int s;
|
||||
|
||||
s = ID0socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
LogPrintf(LogERROR, "SetIpDevice: socket(): %s\n", strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
strncpy(ifrq.ifr_name, name, sizeof ifrq.ifr_name - 1);
|
||||
ifrq.ifr_name[sizeof ifrq.ifr_name - 1] = '\0';
|
||||
while (ID0ioctl(s, SIOCGIFADDR, &ifrq) == 0) {
|
||||
memset(&ifra.ifra_mask, '\0', sizeof ifra.ifra_mask);
|
||||
ifra.ifra_addr = ifrq.ifr_addr;
|
||||
if (ID0ioctl(s, SIOCGIFDSTADDR, &ifrq) < 0) {
|
||||
if (ifra.ifra_addr.sa_family == AF_INET)
|
||||
LogPrintf(LogERROR, "tun_configure: Can't get dst for %s on %s !\n",
|
||||
inet_ntoa(((struct sockaddr_in *)&ifra.ifra_addr)->sin_addr),
|
||||
name);
|
||||
return 0;
|
||||
}
|
||||
ifra.ifra_broadaddr = ifrq.ifr_dstaddr;
|
||||
if (ID0ioctl(s, SIOCDIFADDR, &ifra) < 0) {
|
||||
if (ifra.ifra_addr.sa_family == AF_INET)
|
||||
LogPrintf(LogERROR, "tun_configure: Can't delete %s address on %s !\n",
|
||||
inet_ntoa(((struct sockaddr_in *)&ifra.ifra_addr)->sin_addr),
|
||||
name);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
OsTrySetIpaddress(struct in_addr myaddr, struct in_addr hisaddr)
|
||||
{
|
||||
return (SetIpDevice(myaddr, hisaddr, ifnetmask, SET_TRY));
|
||||
}
|
||||
|
||||
int
|
||||
OsSetIpaddress(struct in_addr myaddr, struct in_addr hisaddr)
|
||||
{
|
||||
return (SetIpDevice(myaddr, hisaddr, ifnetmask, SET_UP));
|
||||
}
|
||||
|
||||
static struct in_addr peer_addr;
|
||||
|
||||
void
|
||||
OsLinkup()
|
||||
{
|
||||
char *s;
|
||||
|
||||
if (linkup == 0) {
|
||||
reconnectState = RECON_UNKNOWN;
|
||||
if (mode & MODE_BACKGROUND && BGFiledes[1] != -1) {
|
||||
char c = EX_NORMAL;
|
||||
|
||||
if (write(BGFiledes[1], &c, 1) == 1)
|
||||
LogPrintf(LogPHASE, "Parent notified of success.\n");
|
||||
else
|
||||
LogPrintf(LogPHASE, "Failed to notify parent of success.\n");
|
||||
close(BGFiledes[1]);
|
||||
BGFiledes[1] = -1;
|
||||
}
|
||||
peer_addr = IpcpInfo.his_ipaddr;
|
||||
s = (char *) inet_ntoa(peer_addr);
|
||||
if (LogIsKept(LogLINK))
|
||||
LogPrintf(LogLINK, "OsLinkup: %s\n", s);
|
||||
else
|
||||
LogPrintf(LogLCP, "OsLinkup: %s\n", s);
|
||||
|
||||
/*
|
||||
* XXX this stuff should really live in the FSM. Our config should
|
||||
* associate executable sections in files with events.
|
||||
*/
|
||||
if (SelectSystem(inet_ntoa(IpcpInfo.want_ipaddr), LINKUPFILE) < 0) {
|
||||
if (GetLabel()) {
|
||||
if (SelectSystem(GetLabel(), LINKUPFILE) < 0)
|
||||
SelectSystem("MYADDR", LINKUPFILE);
|
||||
} else
|
||||
SelectSystem("MYADDR", LINKUPFILE);
|
||||
}
|
||||
linkup = 1;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
OsLinkIsUp()
|
||||
{
|
||||
return linkup;
|
||||
}
|
||||
|
||||
void
|
||||
OsLinkdown()
|
||||
{
|
||||
char *s = NULL;
|
||||
int Level;
|
||||
|
||||
if (linkup) {
|
||||
s = inet_ntoa(peer_addr);
|
||||
Level = LogIsKept(LogLINK) ? LogLINK : LogIPCP;
|
||||
LogPrintf(Level, "OsLinkdown: %s\n", s);
|
||||
}
|
||||
|
||||
FsmClose(&IpcpInfo.fsm);
|
||||
FsmClose(&CcpInfo.fsm);
|
||||
|
||||
if (linkup) {
|
||||
/*
|
||||
* XXX this stuff should really live in the FSM. Our config should
|
||||
* associate executable sections in files with events.
|
||||
*/
|
||||
linkup = 0;
|
||||
if (SelectSystem(s, LINKDOWNFILE) < 0)
|
||||
if (GetLabel()) {
|
||||
if (SelectSystem(GetLabel(), LINKDOWNFILE) < 0)
|
||||
SelectSystem("MYADDR", LINKDOWNFILE);
|
||||
} else
|
||||
SelectSystem("MYADDR", LINKDOWNFILE);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
OsInterfaceDown(int final)
|
||||
{
|
||||
struct in_addr zeroaddr;
|
||||
int s;
|
||||
|
||||
OsLinkdown();
|
||||
if (!final && (mode & MODE_DAEMON))
|
||||
/*
|
||||
* We still want the interface alive - in case we're closing because of
|
||||
* an LQR problem (and are going to re-open)
|
||||
*/
|
||||
return (0);
|
||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
LogPrintf(LogERROR, "OsInterfaceDown: socket: %s\n", strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
ifrq.ifr_flags &= ~IFF_UP;
|
||||
if (ID0ioctl(s, SIOCSIFFLAGS, &ifrq) < 0) {
|
||||
LogPrintf(LogERROR, "OsInterfaceDown: ioctl(SIOCSIFFLAGS): %s\n",
|
||||
strerror(errno));
|
||||
close(s);
|
||||
return (-1);
|
||||
}
|
||||
zeroaddr.s_addr = INADDR_ANY;
|
||||
SetIpDevice(zeroaddr, zeroaddr, zeroaddr, SET_DOWN);
|
||||
|
||||
close(s);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Open tunnel device and returns its descriptor
|
||||
*/
|
||||
|
||||
#define MAX_TUN 256
|
||||
/* MAX_TUN is set at an arbitrarily large value *
|
||||
* as the loop aborts when it reaches the first *
|
||||
* 'Device not configured' (ENXIO), or the third *
|
||||
* 'No such file or directory' (ENOENT) error. */
|
||||
int
|
||||
OpenTunnel(int *ptun)
|
||||
{
|
||||
int s;
|
||||
char ifname[IFNAMSIZ];
|
||||
static char devname[14]; /* sufficient room for "/dev/tun65535" */
|
||||
unsigned unit, enoentcount = 0;
|
||||
int err;
|
||||
|
||||
err = ENOENT;
|
||||
for (unit = 0; unit <= MAX_TUN; unit++) {
|
||||
snprintf(devname, sizeof devname, "/dev/tun%d", unit);
|
||||
tun_out = ID0open(devname, O_RDWR);
|
||||
if (tun_out >= 0)
|
||||
break;
|
||||
if (errno == ENXIO) {
|
||||
unit = MAX_TUN;
|
||||
err = errno;
|
||||
} else if (errno == ENOENT) {
|
||||
enoentcount++;
|
||||
if (enoentcount > 2)
|
||||
unit = MAX_TUN;
|
||||
} else
|
||||
err = errno;
|
||||
}
|
||||
if (unit > MAX_TUN) {
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "No tunnel device is available (%s).\n", strerror(err));
|
||||
return -1;
|
||||
}
|
||||
*ptun = unit;
|
||||
|
||||
LogSetTun(unit);
|
||||
|
||||
/*
|
||||
* At first, name the interface.
|
||||
*/
|
||||
strncpy(ifname, devname + 5, IFNAMSIZ - 1);
|
||||
|
||||
memset(&ifra, '\0', sizeof ifra);
|
||||
memset(&ifrq, '\0', sizeof ifrq);
|
||||
|
||||
strncpy(ifrq.ifr_name, ifname, IFNAMSIZ - 1);
|
||||
strncpy(ifra.ifra_name, ifname, IFNAMSIZ - 1);
|
||||
|
||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
LogPrintf(LogERROR, "OpenTunnel: socket(): %s\n", strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Now, bring up the interface.
|
||||
*/
|
||||
if (ioctl(s, SIOCGIFFLAGS, &ifrq) < 0) {
|
||||
LogPrintf(LogERROR, "OpenTunnel: ioctl(SIOCGIFFLAGS): %s\n",
|
||||
strerror(errno));
|
||||
close(s);
|
||||
return (-1);
|
||||
}
|
||||
ifrq.ifr_flags |= IFF_UP;
|
||||
if (ID0ioctl(s, SIOCSIFFLAGS, &ifrq) < 0) {
|
||||
LogPrintf(LogERROR, "OpenTunnel: ioctl(SIOCSIFFLAGS): %s\n",
|
||||
strerror(errno));
|
||||
close(s);
|
||||
return (-1);
|
||||
}
|
||||
tun_in = tun_out;
|
||||
IfDevName = devname + 5;
|
||||
if (GetIfIndex(IfDevName) < 0) {
|
||||
LogPrintf(LogERROR, "OpenTunnel: Can't find ifindex.\n");
|
||||
close(s);
|
||||
return (-1);
|
||||
}
|
||||
if (VarTerm)
|
||||
fprintf(VarTerm, "Using interface: %s\n", IfDevName);
|
||||
LogPrintf(LogPHASE, "Using interface: %s\n", IfDevName);
|
||||
close(s);
|
||||
return (0);
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* 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. 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.
|
||||
*
|
||||
* $Id: os.h,v 1.13 1997/12/13 02:37:30 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
|
||||
extern char *IfDevName;
|
||||
|
||||
extern int OsSetIpaddress(struct in_addr, struct in_addr);
|
||||
extern int OsTrySetIpaddress(struct in_addr, struct in_addr);
|
||||
extern int OsInterfaceDown(int);
|
||||
extern int OpenTunnel(int *);
|
||||
extern void OsLinkup(void);
|
||||
extern int OsLinkIsUp(void);
|
||||
extern void OsLinkdown(void);
|
||||
extern int CleanInterface(const char *);
|
@ -18,7 +18,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: pap.c,v 1.20.2.3 1998/01/30 19:46:00 brian Exp $
|
||||
* $Id: pap.c,v 1.20.2.4 1998/01/31 02:48:27 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -117,7 +117,8 @@ SendPapCode(int id, int code, const char *message, struct physical *physical)
|
||||
* Validate given username and passwrd against with secret table
|
||||
*/
|
||||
static int
|
||||
PapValidate(u_char * name, u_char * key, struct physical *physical)
|
||||
PapValidate(struct bundle *bundle, u_char *name, u_char *key,
|
||||
struct physical *physical)
|
||||
{
|
||||
int nlen, klen;
|
||||
|
||||
@ -141,11 +142,11 @@ PapValidate(u_char * name, u_char * key, struct physical *physical)
|
||||
}
|
||||
#endif
|
||||
|
||||
return (AuthValidate(SECRETFILE, name, key, physical));
|
||||
return AuthValidate(bundle, SECRETFILE, name, key, physical);
|
||||
}
|
||||
|
||||
void
|
||||
PapInput(struct mbuf * bp, struct physical *physical)
|
||||
PapInput(struct bundle *bundle, struct mbuf *bp, struct physical *physical)
|
||||
{
|
||||
int len = plength(bp);
|
||||
struct fsmheader *php;
|
||||
@ -161,7 +162,7 @@ PapInput(struct mbuf * bp, struct physical *physical)
|
||||
switch (php->code) {
|
||||
case PAP_REQUEST:
|
||||
cp = (u_char *) (php + 1);
|
||||
if (PapValidate(cp, cp + *cp + 1, physical)) {
|
||||
if (PapValidate(bundle, cp, cp + *cp + 1, physical)) {
|
||||
SendPapCode(php->id, PAP_ACK, "Greetings!!", physical);
|
||||
LcpInfo.auth_ineed = 0;
|
||||
if (LcpInfo.auth_iwait == 0) {
|
||||
@ -181,7 +182,7 @@ PapInput(struct mbuf * bp, struct physical *physical)
|
||||
login(&ut);
|
||||
Utmp = 1;
|
||||
}
|
||||
NewPhase(physical, PHASE_NETWORK);
|
||||
NewPhase(bundle, physical, PHASE_NETWORK);
|
||||
}
|
||||
} else {
|
||||
SendPapCode(php->id, PAP_NAK, "Login incorrect", physical);
|
||||
@ -198,7 +199,7 @@ PapInput(struct mbuf * bp, struct physical *physical)
|
||||
if (LcpInfo.auth_iwait == PROTO_PAP) {
|
||||
LcpInfo.auth_iwait = 0;
|
||||
if (LcpInfo.auth_ineed == 0)
|
||||
NewPhase(physical, PHASE_NETWORK);
|
||||
NewPhase(bundle, physical, PHASE_NETWORK);
|
||||
}
|
||||
break;
|
||||
case PAP_NAK:
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: pap.h,v 1.5 1997/10/26 12:42:13 brian Exp $
|
||||
* $Id: pap.h,v 1.5.2.1 1998/01/29 00:49:28 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -26,4 +26,4 @@
|
||||
|
||||
extern struct authinfo AuthPapInfo;
|
||||
|
||||
extern void PapInput(struct mbuf *, struct physical *);
|
||||
extern void PapInput(struct bundle *, struct mbuf *, struct physical *);
|
||||
|
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: phase.c,v 1.6.4.4 1998/01/30 19:46:01 brian Exp $
|
||||
* $Id: phase.c,v 1.6.4.5 1998/01/31 02:48:28 brian Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -77,7 +77,7 @@ Auth2Nam(u_short auth)
|
||||
}
|
||||
|
||||
void
|
||||
NewPhase(struct physical *physical, int new)
|
||||
NewPhase(struct bundle *bundle, struct physical *physical, int new)
|
||||
{
|
||||
phase = new;
|
||||
LogPrintf(LogPHASE, "NewPhase: %s\n", PhaseNames[phase]);
|
||||
@ -94,11 +94,11 @@ NewPhase(struct physical *physical, int new)
|
||||
if (LcpInfo.want_auth == PROTO_CHAP)
|
||||
StartAuthChallenge(&AuthChapInfo, physical);
|
||||
} else
|
||||
NewPhase(physical, PHASE_NETWORK);
|
||||
NewPhase(bundle, physical, PHASE_NETWORK);
|
||||
break;
|
||||
|
||||
case PHASE_NETWORK:
|
||||
tun_configure(LcpInfo.his_mru, ModemSpeed(physical));
|
||||
tun_configure(bundle, LcpInfo.his_mru, ModemSpeed(physical));
|
||||
IpcpUp();
|
||||
IpcpOpen();
|
||||
CcpUp();
|
||||
|
@ -15,7 +15,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: phase.h,v 1.9 1998/01/21 02:15:24 brian Exp $
|
||||
* $Id: phase.h,v 1.9.2.1 1998/01/29 00:49:28 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -30,4 +30,4 @@ struct physical;
|
||||
|
||||
extern int phase; /* Curent phase */
|
||||
|
||||
extern void NewPhase(struct physical *physical, int);
|
||||
extern void NewPhase(struct bundle *, struct physical *physical, int);
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: route.c,v 1.42.2.2 1998/01/30 19:46:05 brian Exp $
|
||||
* $Id: route.c,v 1.42.2.3 1998/01/31 02:48:30 brian Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
@ -47,7 +47,7 @@
|
||||
#include "defs.h"
|
||||
#include "vars.h"
|
||||
#include "id.h"
|
||||
#include "os.h"
|
||||
#include "bundle.h"
|
||||
#include "iplist.h"
|
||||
#include "timer.h"
|
||||
#include "throughput.h"
|
||||
@ -57,130 +57,6 @@
|
||||
#include "ipcp.h"
|
||||
#include "route.h"
|
||||
|
||||
static int IfIndex;
|
||||
|
||||
struct rtmsg {
|
||||
struct rt_msghdr m_rtm;
|
||||
char m_space[64];
|
||||
};
|
||||
|
||||
static int seqno;
|
||||
|
||||
void
|
||||
OsSetRoute(int cmd,
|
||||
struct in_addr dst,
|
||||
struct in_addr gateway,
|
||||
struct in_addr mask,
|
||||
int bang)
|
||||
{
|
||||
struct rtmsg rtmes;
|
||||
int s, nb, wb;
|
||||
char *cp;
|
||||
const char *cmdstr;
|
||||
struct sockaddr_in rtdata;
|
||||
|
||||
if (bang)
|
||||
cmdstr = (cmd == RTM_ADD ? "Add!" : "Delete!");
|
||||
else
|
||||
cmdstr = (cmd == RTM_ADD ? "Add" : "Delete");
|
||||
s = ID0socket(PF_ROUTE, SOCK_RAW, 0);
|
||||
if (s < 0) {
|
||||
LogPrintf(LogERROR, "OsSetRoute: socket(): %s\n", strerror(errno));
|
||||
return;
|
||||
}
|
||||
memset(&rtmes, '\0', sizeof rtmes);
|
||||
rtmes.m_rtm.rtm_version = RTM_VERSION;
|
||||
rtmes.m_rtm.rtm_type = cmd;
|
||||
rtmes.m_rtm.rtm_addrs = RTA_DST;
|
||||
rtmes.m_rtm.rtm_seq = ++seqno;
|
||||
rtmes.m_rtm.rtm_pid = getpid();
|
||||
rtmes.m_rtm.rtm_flags = RTF_UP | RTF_GATEWAY | RTF_STATIC;
|
||||
|
||||
memset(&rtdata, '\0', sizeof rtdata);
|
||||
rtdata.sin_len = 16;
|
||||
rtdata.sin_family = AF_INET;
|
||||
rtdata.sin_port = 0;
|
||||
rtdata.sin_addr = dst;
|
||||
|
||||
cp = rtmes.m_space;
|
||||
memcpy(cp, &rtdata, 16);
|
||||
cp += 16;
|
||||
if (cmd == RTM_ADD)
|
||||
if (gateway.s_addr == INADDR_ANY) {
|
||||
/* Add a route through the interface */
|
||||
struct sockaddr_dl dl;
|
||||
const char *iname;
|
||||
int ilen;
|
||||
|
||||
iname = Index2Nam(IfIndex);
|
||||
ilen = strlen(iname);
|
||||
dl.sdl_len = sizeof dl - sizeof dl.sdl_data + ilen;
|
||||
dl.sdl_family = AF_LINK;
|
||||
dl.sdl_index = IfIndex;
|
||||
dl.sdl_type = 0;
|
||||
dl.sdl_nlen = ilen;
|
||||
dl.sdl_alen = 0;
|
||||
dl.sdl_slen = 0;
|
||||
strncpy(dl.sdl_data, iname, sizeof dl.sdl_data);
|
||||
|
||||
memcpy(cp, &dl, dl.sdl_len);
|
||||
cp += dl.sdl_len;
|
||||
rtmes.m_rtm.rtm_addrs |= RTA_GATEWAY;
|
||||
} else {
|
||||
rtdata.sin_addr = gateway;
|
||||
memcpy(cp, &rtdata, 16);
|
||||
cp += 16;
|
||||
rtmes.m_rtm.rtm_addrs |= RTA_GATEWAY;
|
||||
}
|
||||
|
||||
if (dst.s_addr == INADDR_ANY)
|
||||
mask.s_addr = INADDR_ANY;
|
||||
|
||||
if (cmd == RTM_ADD || dst.s_addr == INADDR_ANY) {
|
||||
rtdata.sin_addr = mask;
|
||||
memcpy(cp, &rtdata, 16);
|
||||
cp += 16;
|
||||
rtmes.m_rtm.rtm_addrs |= RTA_NETMASK;
|
||||
}
|
||||
|
||||
nb = cp - (char *) &rtmes;
|
||||
rtmes.m_rtm.rtm_msglen = nb;
|
||||
wb = ID0write(s, &rtmes, nb);
|
||||
if (wb < 0) {
|
||||
LogPrintf(LogTCPIP, "OsSetRoute failure:\n");
|
||||
LogPrintf(LogTCPIP, "OsSetRoute: Cmd = %s\n", cmd);
|
||||
LogPrintf(LogTCPIP, "OsSetRoute: Dst = %s\n", inet_ntoa(dst));
|
||||
LogPrintf(LogTCPIP, "OsSetRoute: Gateway = %s\n", inet_ntoa(gateway));
|
||||
LogPrintf(LogTCPIP, "OsSetRoute: Mask = %s\n", inet_ntoa(mask));
|
||||
failed:
|
||||
if (cmd == RTM_ADD && (rtmes.m_rtm.rtm_errno == EEXIST ||
|
||||
(rtmes.m_rtm.rtm_errno == 0 && errno == EEXIST)))
|
||||
if (!bang)
|
||||
LogPrintf(LogWARN, "Add route failed: %s already exists\n",
|
||||
inet_ntoa(dst));
|
||||
else {
|
||||
rtmes.m_rtm.rtm_type = cmd = RTM_CHANGE;
|
||||
if ((wb = ID0write(s, &rtmes, nb)) < 0)
|
||||
goto failed;
|
||||
}
|
||||
else if (cmd == RTM_DELETE &&
|
||||
(rtmes.m_rtm.rtm_errno == ESRCH ||
|
||||
(rtmes.m_rtm.rtm_errno == 0 && errno == ESRCH))) {
|
||||
if (!bang)
|
||||
LogPrintf(LogWARN, "Del route failed: %s: Non-existent\n",
|
||||
inet_ntoa(dst));
|
||||
} else if (rtmes.m_rtm.rtm_errno == 0)
|
||||
LogPrintf(LogWARN, "%s route failed: %s: errno: %s\n", cmdstr,
|
||||
inet_ntoa(dst), strerror(errno));
|
||||
else
|
||||
LogPrintf(LogWARN, "%s route failed: %s: %s\n",
|
||||
cmdstr, inet_ntoa(dst), strerror(rtmes.m_rtm.rtm_errno));
|
||||
}
|
||||
LogPrintf(LogDEBUG, "wrote %d: cmd = %s, dst = %x, gateway = %x\n",
|
||||
wb, cmdstr, dst.s_addr, gateway.s_addr);
|
||||
close(s);
|
||||
}
|
||||
|
||||
static void
|
||||
p_sockaddr(struct sockaddr *phost, struct sockaddr *pmask, int width)
|
||||
{
|
||||
@ -463,7 +339,7 @@ ShowRoute(struct cmdargs const *arg)
|
||||
* Delete routes associated with our interface
|
||||
*/
|
||||
void
|
||||
DeleteIfRoutes(int all)
|
||||
DeleteIfRoutes(const struct bundle *bundle, int all)
|
||||
{
|
||||
struct rt_msghdr *rtm;
|
||||
struct sockaddr *sa;
|
||||
@ -473,7 +349,7 @@ DeleteIfRoutes(int all)
|
||||
char *sp, *cp, *ep;
|
||||
int mib[6];
|
||||
|
||||
LogPrintf(LogDEBUG, "DeleteIfRoutes (%d)\n", IfIndex);
|
||||
LogPrintf(LogDEBUG, "DeleteIfRoutes (%d)\n", bundle->ifIndex);
|
||||
sa_none.s_addr = INADDR_ANY;
|
||||
|
||||
mib[0] = CTL_NET;
|
||||
@ -520,7 +396,7 @@ DeleteIfRoutes(int all)
|
||||
Index2Nam(rtm->rtm_index), rtm->rtm_flags,
|
||||
inet_ntoa(((struct sockaddr_in *) sa)->sin_addr));
|
||||
if (rtm->rtm_addrs & RTA_DST && rtm->rtm_addrs & RTA_GATEWAY &&
|
||||
rtm->rtm_index == IfIndex &&
|
||||
rtm->rtm_index == bundle->ifIndex &&
|
||||
(all || (rtm->rtm_flags & RTF_GATEWAY))) {
|
||||
sa_dst.s_addr = ((struct sockaddr_in *)sa)->sin_addr.s_addr;
|
||||
sa = (struct sockaddr *)((char *)sa + sa->sa_len);
|
||||
@ -528,7 +404,7 @@ DeleteIfRoutes(int all)
|
||||
if ((pass == 0 && (rtm->rtm_flags & RTF_WASCLONED)) ||
|
||||
(pass == 1 && !(rtm->rtm_flags & RTF_WASCLONED))) {
|
||||
LogPrintf(LogDEBUG, "DeleteIfRoutes: Remove it (pass %d)\n", pass);
|
||||
OsSetRoute(RTM_DELETE, sa_dst, sa_none, sa_none, 0);
|
||||
bundle_SetRoute(bundle, RTM_DELETE, sa_dst, sa_none, sa_none, 0);
|
||||
} else
|
||||
LogPrintf(LogDEBUG, "DeleteIfRoutes: Skip it (pass %d)\n", pass);
|
||||
} else
|
||||
@ -550,14 +426,14 @@ GetIfIndex(char *name)
|
||||
idx = 1;
|
||||
while (strcmp(got = Index2Nam(idx), "???"))
|
||||
if (!strcmp(got, name))
|
||||
return IfIndex = idx;
|
||||
return idx;
|
||||
else
|
||||
idx++;
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct in_addr
|
||||
ChooseHisAddr(const struct in_addr gw)
|
||||
ChooseHisAddr(struct bundle *bundle, const struct in_addr gw)
|
||||
{
|
||||
struct in_addr try;
|
||||
int f;
|
||||
@ -566,7 +442,7 @@ ChooseHisAddr(const struct in_addr gw)
|
||||
try = iplist_next(&IpcpInfo.DefHisChoice);
|
||||
LogPrintf(LogDEBUG, "ChooseHisAddr: Check item %d (%s)\n",
|
||||
f, inet_ntoa(try));
|
||||
if (OsTrySetIpaddress(gw, try) == 0) {
|
||||
if (bundle_TrySetIPaddress(bundle, gw, try) == 0) {
|
||||
LogPrintf(LogIPCP, "ChooseHisAddr: Selected IP address %s\n",
|
||||
inet_ntoa(try));
|
||||
break;
|
||||
|
@ -17,13 +17,12 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: route.h,v 1.9 1997/12/30 02:45:48 brian Exp $
|
||||
* $Id: route.h,v 1.10 1998/01/19 02:59:34 brian Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
extern int GetIfIndex(char *);
|
||||
extern int ShowRoute(struct cmdargs const *);
|
||||
extern void OsSetRoute(int, struct in_addr, struct in_addr, struct in_addr,int);
|
||||
extern void DeleteIfRoutes(int);
|
||||
extern struct in_addr ChooseHisAddr(const struct in_addr);
|
||||
extern void DeleteIfRoutes(const struct bundle *, int);
|
||||
extern struct in_addr ChooseHisAddr(struct bundle *, const struct in_addr);
|
||||
extern const char *Index2Nam(int);
|
||||
|
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: server.c,v 1.15 1997/12/24 09:29:14 brian Exp $
|
||||
* $Id: server.c,v 1.16 1998/01/21 02:15:27 brian Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -98,7 +98,7 @@ ServerLocalOpen(const char *name, mode_t mask)
|
||||
if (mask != (mode_t)-1)
|
||||
umask(mask);
|
||||
if (listen(s, 5) != 0) {
|
||||
LogPrintf(LogERROR, "Local: Unable to listen to socket - OS overload?\n");
|
||||
LogPrintf(LogERROR, "Local: Unable to listen to socket - BUNDLE overload?\n");
|
||||
close(s);
|
||||
ID0unlink(name);
|
||||
return 5;
|
||||
@ -145,7 +145,7 @@ ServerTcpOpen(int port)
|
||||
return 8;
|
||||
}
|
||||
if (listen(s, 5) != 0) {
|
||||
LogPrintf(LogERROR, "Tcp: Unable to listen to socket - OS overload?\n");
|
||||
LogPrintf(LogERROR, "Tcp: Unable to listen to socket - BUNDLE overload?\n");
|
||||
close(s);
|
||||
return 9;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: systems.c,v 1.34 1997/12/24 09:29:17 brian Exp $
|
||||
* $Id: systems.c,v 1.35 1998/01/21 02:15:28 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -169,6 +169,7 @@ static int userok;
|
||||
int
|
||||
AllowUsers(struct cmdargs const *arg)
|
||||
{
|
||||
/* arg->bundle may be NULL (see ValidSystem()) ! */
|
||||
int f;
|
||||
char *user;
|
||||
|
||||
@ -203,6 +204,7 @@ static int modeok;
|
||||
int
|
||||
AllowModes(struct cmdargs const *arg)
|
||||
{
|
||||
/* arg->bundle may be NULL (see ValidSystem()) ! */
|
||||
int f;
|
||||
int m;
|
||||
int allowed;
|
||||
@ -223,7 +225,8 @@ AllowModes(struct cmdargs const *arg)
|
||||
}
|
||||
|
||||
static int
|
||||
ReadSystem(const char *name, const char *file, int doexec)
|
||||
ReadSystem(struct bundle *bundle, const char *name, const char *file,
|
||||
int doexec)
|
||||
{
|
||||
FILE *fp;
|
||||
char *cp, *wp;
|
||||
@ -271,7 +274,7 @@ ReadSystem(const char *name, const char *file, int doexec)
|
||||
switch (DecodeCtrlCommand(cp+1, arg)) {
|
||||
case CTRL_INCLUDE:
|
||||
LogPrintf(LogCOMMAND, "%s: Including \"%s\"\n", filename, arg);
|
||||
n = ReadSystem(name, arg, doexec);
|
||||
n = ReadSystem(bundle, name, arg, doexec);
|
||||
LogPrintf(LogCOMMAND, "%s: Done include of \"%s\"\n", filename, arg);
|
||||
if (!n)
|
||||
return 0; /* got it */
|
||||
@ -299,7 +302,7 @@ ReadSystem(const char *name, const char *file, int doexec)
|
||||
olauth = VarLocalAuth;
|
||||
if (VarLocalAuth == LOCAL_NO_AUTH)
|
||||
VarLocalAuth = LOCAL_AUTH;
|
||||
RunCommand(argc, (char const *const *)argv, name);
|
||||
RunCommand(bundle, argc, (char const *const *)argv, name);
|
||||
VarLocalAuth = olauth;
|
||||
}
|
||||
} else if (*cp == '#' || *cp == '\n' || *cp == '\0') {
|
||||
@ -320,21 +323,25 @@ ReadSystem(const char *name, const char *file, int doexec)
|
||||
int
|
||||
ValidSystem(const char *name)
|
||||
{
|
||||
/*
|
||||
* Note: The ReadSystem() calls only result in calls to the Allow*
|
||||
* functions. arg->bundle will be set to NULL for these commands !
|
||||
*/
|
||||
if (ID0realuid() == 0)
|
||||
return userok = modeok = 1;
|
||||
userok = 0;
|
||||
modeok = 1;
|
||||
ReadSystem("default", CONFFILE, 0);
|
||||
ReadSystem(NULL, "default", CONFFILE, 0);
|
||||
if (name != NULL)
|
||||
ReadSystem(name, CONFFILE, 0);
|
||||
ReadSystem(NULL, name, CONFFILE, 0);
|
||||
return userok && modeok;
|
||||
}
|
||||
|
||||
int
|
||||
SelectSystem(const char *name, const char *file)
|
||||
SelectSystem(struct bundle *bundle, const char *name, const char *file)
|
||||
{
|
||||
userok = modeok = 1;
|
||||
return ReadSystem(name, file, 1);
|
||||
return ReadSystem(bundle, name, file, 1);
|
||||
}
|
||||
|
||||
int
|
||||
@ -350,7 +357,7 @@ LoadCommand(struct cmdargs const *arg)
|
||||
if (!ValidSystem(name)) {
|
||||
LogPrintf(LogERROR, "%s: Label not allowed\n", name);
|
||||
return 1;
|
||||
} else if (SelectSystem(name, CONFFILE) < 0) {
|
||||
} else if (SelectSystem(arg->bundle, name, CONFFILE) < 0) {
|
||||
LogPrintf(LogWARN, "%s: label not found.\n", name);
|
||||
return -1;
|
||||
} else
|
||||
|
@ -17,11 +17,11 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: systems.h,v 1.9 1997/11/11 22:58:14 brian Exp $
|
||||
* $Id: systems.h,v 1.10 1997/11/22 03:37:51 brian Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
extern int SelectSystem(const char *, const char *);
|
||||
extern int SelectSystem(struct bundle *bundle, const char *, const char *);
|
||||
extern int ValidSystem(const char *);
|
||||
extern FILE *OpenSecret(const char *);
|
||||
extern void CloseSecret(FILE *);
|
||||
|
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: tun.c,v 1.5 1998/01/11 17:53:27 brian Exp $
|
||||
* $Id: tun.c,v 1.6 1998/01/21 02:15:30 brian Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -45,10 +45,11 @@
|
||||
#include "defs.h"
|
||||
#include "loadalias.h"
|
||||
#include "vars.h"
|
||||
#include "bundle.h"
|
||||
#include "tun.h"
|
||||
|
||||
void
|
||||
tun_configure(int mtu, int speed)
|
||||
tun_configure(struct bundle *bundle, int mtu, int speed)
|
||||
{
|
||||
struct tuninfo info;
|
||||
|
||||
@ -60,7 +61,7 @@ tun_configure(int mtu, int speed)
|
||||
#ifdef __OpenBSD__
|
||||
info.flags = IFF_UP|IFF_POINTOPOINT;
|
||||
#endif
|
||||
if (ioctl(tun_out, TUNSIFINFO, &info) < 0)
|
||||
if (ioctl(bundle->tun_fd, TUNSIFINFO, &info) < 0)
|
||||
LogPrintf(LogERROR, "tun_configure: ioctl(TUNSIFINFO): %s\n",
|
||||
strerror(errno));
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id$
|
||||
* $Id: tun.h,v 1.3 1997/12/21 12:11:10 brian Exp $
|
||||
*/
|
||||
|
||||
struct tun_data {
|
||||
@ -41,4 +41,4 @@ struct tun_data {
|
||||
#define tun_check_header(f,proto) (1)
|
||||
#endif
|
||||
|
||||
extern void tun_configure(int, int);
|
||||
extern void tun_configure(struct bundle *, int, int);
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: vars.c,v 1.45 1998/01/21 02:15:31 brian Exp $
|
||||
* $Id: vars.c,v 1.45.2.1 1998/01/29 00:49:31 brian Exp $
|
||||
*
|
||||
*/
|
||||
#include <sys/param.h>
|
||||
@ -39,8 +39,8 @@
|
||||
#include "auth.h"
|
||||
#include "physical.h"
|
||||
|
||||
char VarVersion[] = "PPP Version 1.65";
|
||||
char VarLocalVersion[] = "$Date: 1998/01/21 02:15:31 $";
|
||||
char VarVersion[] = "PPP Version 1.90";
|
||||
char VarLocalVersion[] = "$Date: 1998/01/29 00:49:31 $";
|
||||
int Utmp = 0;
|
||||
int ipKeepAlive = 0;
|
||||
int reconnectState = RECON_UNKNOWN;
|
||||
|
Loading…
Reference in New Issue
Block a user