Move pppVars.physical into the bundle (for the moment).

This commit is contained in:
Brian Somers 1998-02-06 02:23:48 +00:00
parent 6f1bc4e5da
commit 2289f24698
11 changed files with 90 additions and 87 deletions

View File

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.36.2.2 1998/01/30 19:45:24 brian Exp $
# $Id: Makefile,v 1.36.2.3 1998/02/02 19:31:59 brian Exp $
PROG= ppp
SRCS= arp.c async.c auth.c bundle.c ccp.c chap.c chat.c command.c deflate.c \
@ -41,3 +41,5 @@ chap_ms.o alias_cmd.o loadalias.o:
.endif
.include <bsd.prog.mk>
STRIP=

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bundle.c,v 1.1.2.1 1998/02/02 19:32:01 brian Exp $
* $Id: bundle.c,v 1.1.2.2 1998/02/02 19:33:00 brian Exp $
*/
#include <sys/param.h>
@ -61,6 +61,7 @@
#include "route.h"
#include "lcp.h"
#include "ccp.h"
#include "modem.h"
static int
bundle_SetIpDevice(struct bundle *bundle, struct in_addr myaddr,
@ -430,6 +431,12 @@ bundle_Create(const char *prefix)
/* Clean out any leftover crud */
bundle_CleanInterface(&bundle);
bundle.physical = modem_Create("default");
if (bundle.physical == NULL) {
LogPrintf(LogERROR, "Cannot create modem device: %s\n", strerror(errno));
return NULL;
}
return &bundle;
}

View File

@ -23,9 +23,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bundle.h,v 1.1.2.2 1998/02/02 19:33:01 brian Exp $
* $Id: bundle.h,v 1.1.2.3 1998/02/04 01:03:19 brian Exp $
*/
struct physical;
struct bundle {
int unit; /* The tun number */
int ifIndex; /* The interface number */
@ -34,6 +36,8 @@ struct bundle {
char *ifname; /* The interface name */
int routing_seq; /* The current routing sequence number */
struct physical *physical; /* For the time being */
/* These really belong at the NCP level */
int linkup; /* We've called ppp.linkup */
struct in_addr if_mine; /* My configured interface address */

View File

@ -18,7 +18,7 @@
* Columbus, OH 43221
* (614)451-1883
*
* $Id: chat.c,v 1.44.2.2 1998/02/02 19:33:34 brian Exp $
* $Id: chat.c,v 1.44.2.3 1998/02/06 02:22:07 brian Exp $
*
* TODO:
* o Support more UUCP compatible control sequences.
@ -48,7 +48,6 @@
#include "timer.h"
#include "loadalias.h"
#include "vars.h"
#include "chat.h"
#include "modem.h"
#include "hdlc.h"
#include "throughput.h"
@ -57,6 +56,7 @@
#include "link.h"
#include "async.h"
#include "physical.h"
#include "chat.h"
#ifndef isblank
#define isblank(c) ((c) == '\t' || (c) == ' ')

View File

@ -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.7 1998/02/02 19:33:34 brian Exp $
* $Id: command.c,v 1.131.2.8 1998/02/06 02:22:10 brian Exp $
*
*/
#include <sys/param.h>
@ -195,12 +195,12 @@ DialCommand(struct cmdargs const *arg)
}
if (VarTerm)
fprintf(VarTerm, "Dial attempt %u of %d\n", ++tries, VarDialTries);
if (modem_Open(pppVars.physical, arg->bundle) < 0) {
if (modem_Open(arg->bundle->physical, arg->bundle) < 0) {
if (VarTerm)
fprintf(VarTerm, "Failed to open modem.\n");
break;
}
if ((res = modem_Dial(pppVars.physical, arg->bundle)) == EX_DONE) {
if ((res = modem_Dial(arg->bundle->physical, arg->bundle)) == EX_DONE) {
PacketMode(arg->bundle, VarOpenMode);
break;
} else if (res == EX_SIG)
@ -847,7 +847,7 @@ TerminalCommand(struct cmdargs const *arg)
}
if (!IsInteractive(1))
return (1);
if (modem_Open(pppVars.physical, arg->bundle) < 0) {
if (modem_Open(arg->bundle->physical, arg->bundle) < 0) {
if (VarTerm)
fprintf(VarTerm, "Failed to open modem.\n");
return (1);
@ -901,7 +901,7 @@ SetModemSpeed(struct cmdargs const *arg)
return -1;
}
if (strcasecmp(*arg->argv, "sync") == 0) {
Physical_SetSync(pppVars.physical);
Physical_SetSync(arg->bundle->physical);
return 0;
}
end = NULL;
@ -910,7 +910,7 @@ SetModemSpeed(struct cmdargs const *arg)
LogPrintf(LogWARN, "SetModemSpeed: Bad argument \"%s\"", *arg->argv);
return -1;
}
if (Physical_SetSpeed(pppVars.physical, speed))
if (Physical_SetSpeed(arg->bundle->physical, speed))
return 0;
LogPrintf(LogWARN, "%s: Invalid speed\n", *arg->argv);
} else
@ -1092,7 +1092,7 @@ SetServer(struct cmdargs const *arg)
static int
SetModemParity(struct cmdargs const *arg)
{
return arg->argc > 0 ? modem_SetParity(pppVars.physical, *arg->argv) : -1;
return arg->argc > 0 ? modem_SetParity(arg->bundle->physical, *arg->argv) : -1;
}
static int
@ -1374,13 +1374,13 @@ SetVariable(struct cmdargs const *arg)
break;
case VAR_DEVICE:
if (mode & MODE_INTER)
link_Close(physical2link(pppVars.physical), 0);
if (link_IsActive(physical2link(pppVars.physical)))
link_Close(physical2link(arg->bundle->physical), 0);
if (link_IsActive(physical2link(arg->bundle->physical)))
LogPrintf(LogWARN,
"Cannot change device to \"%s\" when \"%s\" is open\n",
argp, Physical_GetDevice(pppVars.physical));
argp, Physical_GetDevice(arg->bundle->physical));
else {
Physical_SetDevice(pppVars.physical, argp);
Physical_SetDevice(arg->bundle->physical, argp);
}
break;
case VAR_ACCMAP:
@ -1418,9 +1418,9 @@ SetCtsRts(struct cmdargs const *arg)
}
if (strcmp(*arg->argv, "on") == 0)
Physical_SetRtsCts(pppVars.physical, 1);
Physical_SetRtsCts(arg->bundle->physical, 1);
else if (strcmp(*arg->argv, "off") == 0)
Physical_SetRtsCts(pppVars.physical, 0);
Physical_SetRtsCts(arg->bundle->physical, 0);
else
return -1;
return 0;

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: link.c,v 1.1.2.1 1998/01/30 19:45:49 brian Exp $
* $Id: link.c,v 1.1.2.2 1998/02/06 02:22:43 brian Exp $
*
*/
@ -84,10 +84,8 @@ link_Dequeue(struct link *l)
for (bp = (struct mbuf *)0, pri = LINK_QUEUES - 1; pri >= 0; pri--)
if (l->Queue[pri].qlen) {
bp = Dequeue(l->Queue + pri);
if (pri > PRI_NORMAL)
LogPrintf(LogDEBUG, "link_Dequeue: Output from queue %d,"
" containing %d packets\n", pri, l->Queue[pri].qlen);
LogPrintf(LogDEBUG, "link_Dequeue: Dequeued from %d\n", pri);
LogPrintf(LogDEBUG, "link_Dequeue: Dequeued from queue %d,"
" containing %d more packets\n", pri, l->Queue[pri].qlen);
break;
}

View File

@ -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.7 1998/02/06 02:22:17 brian Exp $
* $Id: main.c,v 1.121.2.8 1998/02/06 02:22:45 brian Exp $
*
* TODO:
* o Add commands for traffic summary, version display, etc.
@ -186,8 +186,7 @@ Cleanup(int excode)
DropClient(1);
ServerClose();
bundle_InterfaceDown(CleanupBundle);
link_Close(physical2link(pppVars.physical), 1); /* XXX gotta get a handle on
* the logical link */
link_Close(physical2link(CleanupBundle->physical), 1);
nointr_sleep(1);
DeleteIfRoutes(CleanupBundle, 1);
ID0unlink(pid_filename);
@ -202,7 +201,7 @@ Cleanup(int excode)
}
LogPrintf(LogPHASE, "PPP Terminated (%s).\n", ex_desc(excode));
TtyOldMode();
link_Destroy(physical2link(pppVars.physical));
link_Destroy(physical2link(CleanupBundle->physical));
LogClose();
exit(excode);
@ -372,12 +371,6 @@ main(int argc, char **argv)
name = strrchr(argv[0], '/');
LogOpen(name ? name + 1 : argv[0]);
pppVars.physical = modem_Create("modem");
if (pppVars.physical == NULL) {
LogPrintf(LogERROR, "Cannot create modem device: %s\n", strerror(errno));
return 1;
}
tcgetattr(STDIN_FILENO, &oldtio); /* Save original tty mode */
argc--;
@ -413,11 +406,6 @@ main(int argc, char **argv)
return 1;
}
if (!GetShortHost())
return 1;
IsInteractive(1);
IpcpDefAddress();
if (mode & MODE_INTER)
VarLocalAuth = LOCAL_AUTH;
@ -426,6 +414,11 @@ main(int argc, char **argv)
return EX_START;
}
if (!GetShortHost())
return 1;
IsInteractive(1);
IpcpDefAddress();
CleanupBundle = bundle;
if (SelectSystem(bundle, "default", CONFFILE) < 0 && VarTerm)
@ -581,13 +574,13 @@ main(int argc, char **argv)
void
PacketMode(struct bundle *bundle, int delay)
{
if (modem_Raw(pppVars.physical) < 0) {
if (modem_Raw(bundle->physical) < 0) {
LogPrintf(LogWARN, "PacketMode: Not connected.\n");
return;
}
LcpInit(bundle, pppVars.physical);
IpcpInit(bundle, physical2link(pppVars.physical));
CcpInit(bundle, physical2link(pppVars.physical));
LcpInit(bundle, bundle->physical);
IpcpInit(bundle, physical2link(bundle->physical));
CcpInit(bundle, physical2link(bundle->physical));
LcpUp();
LcpOpen(delay);
@ -653,7 +646,7 @@ ReadTty(struct bundle *bundle)
ttystate++;
else
/* XXX missing return value check */
Physical_Write(pppVars.physical, &ch, n);
Physical_Write(bundle->physical, &ch, n);
break;
case 1:
switch (ch) {
@ -684,7 +677,7 @@ ReadTty(struct bundle *bundle)
break;
}
default:
if (Physical_Write(pppVars.physical, &ch, n) < 0)
if (Physical_Write(bundle->physical, &ch, n) < 0)
LogPrintf(LogERROR, "error writing to modem.\n");
break;
}
@ -779,13 +772,13 @@ DoLoop(struct bundle *bundle)
if (mode & MODE_DIRECT) {
LogPrintf(LogDEBUG, "Opening modem\n");
if (modem_Open(pppVars.physical, bundle) < 0)
if (modem_Open(bundle->physical, bundle) < 0)
return;
LogPrintf(LogPHASE, "Packet mode enabled\n");
PacketMode(bundle, VarOpenMode);
} else if (mode & MODE_DEDICATED) {
if (!link_IsActive(physical2link(pppVars.physical)))
while (modem_Open(pppVars.physical, bundle) < 0)
if (!link_IsActive(physical2link(bundle->physical)))
while (modem_Open(bundle->physical, bundle) < 0)
nointr_sleep(VarReconnectTimer);
}
fflush(VarTerm);
@ -840,8 +833,8 @@ DoLoop(struct bundle *bundle)
*/
if (dial_up && RedialTimer.state != TIMER_RUNNING) {
LogPrintf(LogDEBUG, "going to dial: modem = %d\n",
Physical_GetFD(pppVars.physical));
if (modem_Open(pppVars.physical, bundle) < 0) {
Physical_GetFD(bundle->physical));
if (modem_Open(bundle->physical, bundle) < 0) {
tries++;
if (!(mode & MODE_DDIAL) && VarDialTries)
LogPrintf(LogCHAT, "Failed to open modem (attempt %u of %d)\n",
@ -866,7 +859,7 @@ DoLoop(struct bundle *bundle)
else
LogPrintf(LogCHAT, "Dial attempt %u\n", tries);
if ((res = modem_Dial(pppVars.physical, bundle)) == EX_DONE) {
if ((res = modem_Dial(bundle->physical, bundle)) == EX_DONE) {
PacketMode(bundle, VarOpenMode);
dial_up = 0;
reconnectState = RECON_UNKNOWN;
@ -896,20 +889,20 @@ DoLoop(struct bundle *bundle)
}
}
qlen = link_QueueLen(physical2link(pppVars.physical));
qlen = link_QueueLen(physical2link(bundle->physical));
if (qlen == 0) {
IpStartOutput(physical2link(pppVars.physical));
qlen = link_QueueLen(physical2link(pppVars.physical));
IpStartOutput(physical2link(bundle->physical));
qlen = link_QueueLen(physical2link(bundle->physical));
}
if (link_IsActive(physical2link(pppVars.physical))) {
if (link_IsActive(physical2link(bundle->physical))) {
/* XXX-ML this should probably be abstracted */
if (Physical_GetFD(pppVars.physical) + 1 > nfds)
nfds = Physical_GetFD(pppVars.physical) + 1;
Physical_FD_SET(pppVars.physical, &rfds);
Physical_FD_SET(pppVars.physical, &efds);
if (Physical_GetFD(bundle->physical) + 1 > nfds)
nfds = Physical_GetFD(bundle->physical) + 1;
Physical_FD_SET(bundle->physical, &rfds);
Physical_FD_SET(bundle->physical, &efds);
if (qlen > 0) {
Physical_FD_SET(pppVars.physical, &wfds);
Physical_FD_SET(bundle->physical, &wfds);
}
}
if (server >= 0) {
@ -976,7 +969,7 @@ DoLoop(struct bundle *bundle)
break;
}
if ((netfd >= 0 && FD_ISSET(netfd, &efds)) ||
(Physical_FD_ISSET(pppVars.physical, &efds))) {
(Physical_FD_ISSET(bundle->physical, &efds))) {
LogPrintf(LogALERT, "Exception detected.\n");
break;
}
@ -1020,17 +1013,17 @@ DoLoop(struct bundle *bundle)
if (netfd >= 0 && FD_ISSET(netfd, &rfds))
/* something to read from tty */
ReadTty(bundle);
if (Physical_FD_ISSET(pppVars.physical, &wfds)) {
if (Physical_FD_ISSET(bundle->physical, &wfds)) {
/* ready to write into modem */
link_StartOutput(physical2link(pppVars.physical));
if (!link_IsActive(physical2link(pppVars.physical)))
link_StartOutput(physical2link(bundle->physical));
if (!link_IsActive(physical2link(bundle->physical)))
dial_up = 1;
}
if (Physical_FD_ISSET(pppVars.physical, &rfds)) {
if (Physical_FD_ISSET(bundle->physical, &rfds)) {
/* something to read from modem */
if (LcpInfo.fsm.state <= ST_CLOSED)
nointr_usleep(10000);
n = Physical_Read(pppVars.physical, rbuff, sizeof rbuff);
n = Physical_Read(bundle->physical, rbuff, sizeof rbuff);
if ((mode & MODE_DIRECT) && n <= 0) {
LcpDown();
} else
@ -1041,15 +1034,15 @@ DoLoop(struct bundle *bundle)
* In dedicated mode, we just discard input until LCP is started.
*/
if (!(mode & MODE_DEDICATED)) {
cp = HdlcDetect(pppVars.physical, rbuff, n);
cp = HdlcDetect(bundle->physical, rbuff, n);
if (cp) {
/*
* LCP packet is detected. Turn ourselves into packet mode.
*/
if (cp != rbuff) {
/* XXX missing return value checks */
Physical_Write(pppVars.physical, rbuff, cp - rbuff);
Physical_Write(pppVars.physical, "\r\n", 2);
Physical_Write(bundle->physical, rbuff, cp - rbuff);
Physical_Write(bundle->physical, "\r\n", 2);
}
PacketMode(bundle, 0);
} else
@ -1057,7 +1050,7 @@ DoLoop(struct bundle *bundle)
}
} else {
if (n > 0)
async_Input(bundle, rbuff, n, pppVars.physical);
async_Input(bundle, rbuff, n, bundle->physical);
}
}
if (bundle->tun_fd >= 0 && FD_ISSET(bundle->tun_fd, &rfds)) {

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: mbuf.c,v 1.13 1998/01/21 02:15:21 brian Exp $
* $Id: mbuf.c,v 1.13.2.1 1998/01/30 19:45:54 brian Exp $
*
*/
#include <sys/param.h>
@ -179,7 +179,7 @@ Dequeue(struct mqueue *q)
{
struct mbuf *bp;
LogPrintf(LogDEBUG, "Dequeue: len = %d\n", q->qlen);
LogPrintf(LogDEBUG, "Dequeue: queue len = %d\n", q->qlen);
bp = q->top;
if (bp) {
q->top = q->top->pnext;

View File

@ -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.5 1998/02/06 02:22:21 brian Exp $
* $Id: modem.c,v 1.77.2.6 1998/02/06 02:22:48 brian Exp $
*
* TODO:
*/
@ -60,6 +60,7 @@
#include "chat.h"
#include "throughput.h"
#include "async.h"
#include "bundle.h"
#undef mode
@ -472,6 +473,7 @@ modem_Open(struct physical *modem, struct bundle *bundle)
struct cmdargs arg;
arg.cmd = NULL;
arg.data = (const void *)VAR_DEVICE;
arg.bundle = bundle;
if (isatty(STDIN_FILENO)) {
LogPrintf(LogDEBUG, "modem_Open(direct): Modem is a tty\n");
cp = ttyname(STDIN_FILENO);
@ -824,15 +826,12 @@ modem_StartOutput(struct link *l)
if (modem->out) {
nb = modem->out->cnt;
/* Eh ? Removed 980130
if (nb > 1600)
nb = 1600;
*/
nw = write(modem->fd, MBUF_CTOP(modem->out), nb);
LogPrintf(LogDEBUG, "modem_StartOutput: wrote: %d(%d)\n", nw, nb);
LogDumpBuff(LogDEBUG, "modem_StartOutput: modem write",
MBUF_CTOP(modem->out), nb);
LogPrintf(LogDEBUG, "modem_StartOutput: wrote: %d(%d) to %d\n",
nw, nb, modem->fd);
if (nw > 0) {
LogDumpBuff(LogDEBUG, "modem_StartOutput: modem write",
MBUF_CTOP(modem->out), nw);
modem->out->cnt -= nw;
modem->out->offset += nw;
if (modem->out->cnt == 0) {
@ -843,7 +842,7 @@ modem_StartOutput(struct link *l)
if (errno != EAGAIN) {
LogPrintf(LogERROR, "modem write (%d): %s\n", modem->fd,
strerror(errno));
reconnect(RECON_TRUE);
reconnect(RECON_TRUE);
LcpDown();
}
}
@ -874,7 +873,7 @@ modem_Dial(struct physical *modem, struct bundle *bundle)
VarAltPhone = NULL;
if (VarTerm)
fprintf(VarTerm, "login OK!\n");
to.modem = pppVars.physical;
to.modem = modem;
to.bundle = bundle;
modem_Timeout(&to);
return EX_DONE;
@ -899,7 +898,7 @@ int
modem_ShowStatus(struct cmdargs const *arg)
{
const char *dev;
struct physical *modem = pppVars.physical;
struct physical *modem = arg->bundle->physical;
#ifdef TIOCOUTQ
int nb;
#endif

View File

@ -16,7 +16,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: physical.c,v 1.1.2.3 1998/02/02 19:33:39 brian Exp $
* $Id: physical.c,v 1.1.2.4 1998/02/06 02:22:27 brian Exp $
*
*/
@ -52,6 +52,7 @@
#include "physical.h"
#include "vars.h"
#include "bundle.h"
/* External calls - should possibly be moved inline */
extern int IntToSpeed(int);
@ -170,6 +171,6 @@ Physical_Write(struct physical *phys, const void *buf, size_t nbytes) {
int
Physical_ReportProtocolStatus(struct cmdargs const *arg)
{
link_ReportProtocolStatus(&pppVars.physical->link);
link_ReportProtocolStatus(&arg->bundle->physical->link);
return 0;
}

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: vars.h,v 1.42 1998/01/21 02:15:32 brian Exp $
* $Id: vars.h,v 1.42.2.1 1998/01/29 00:49:31 brian Exp $
*
* TODO:
*/
@ -79,9 +79,8 @@ struct pppvars {
#define LOCAL_DENY 0x03
u_char lauth; /* Local Authorized status */
FILE *termfp; /* The terminal */
struct physical *physical; /* Active physical device */
/* The rest are just default initialized in vars.c */
/* The rest are just default initialized in vars.c */
#define DIALUP_REQ 0x01
#define DIALUP_DONE 0x02
char dial_script[SCRIPT_LEN]; /* Dial script */