Create struct async' and make it part of struct physical'.

This structure contains the asynchronous state of the physical
link.
Unfortunately, just about every .h file is included in every .c
file now.  Fixing this can be one of the last jobs.
This commit is contained in:
Brian Somers 1998-02-02 19:33:40 +00:00
parent 820de6eb8e
commit 6140ba1177
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/MP/; revision=33032
17 changed files with 113 additions and 90 deletions

View File

@ -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.2 1998/01/30 19:45:25 brian Exp $
* $Id: async.c,v 1.15.2.3 1998/02/02 19:32:00 brian Exp $
*
*/
#include <sys/param.h>
@ -44,49 +44,34 @@
#include "link.h"
#include "physical.h"
#define HDLCSIZE (MAX_MRU*2+6)
static struct async_state {
int mode;
int length;
u_char hbuff[HDLCSIZE]; /* recv buffer */
u_char xbuff[HDLCSIZE]; /* xmit buffer */
u_long my_accmap;
u_long his_accmap;
} AsyncState;
#define MODE_HUNT 0x01
#define MODE_ESC 0x02
void
AsyncInit()
async_Init(struct async *async)
{
struct async_state *stp = &AsyncState;
stp->mode = MODE_HUNT;
stp->length = 0;
stp->my_accmap = stp->his_accmap = 0xffffffff;
async->mode = MODE_HUNT;
async->length = 0;
async->my_accmap = async->his_accmap = 0xffffffff;
}
void
SetLinkParams(struct lcpstate *lcp)
async_SetLinkParams(struct async *async, struct lcpstate *lcp)
{
struct async_state *stp = &AsyncState;
stp->my_accmap = lcp->want_accmap;
stp->his_accmap = lcp->his_accmap;
async->my_accmap = lcp->want_accmap;
async->his_accmap = lcp->his_accmap;
}
/*
* Encode into async HDLC byte code if necessary
*/
static void
HdlcPutByte(u_char **cp, u_char c, int proto)
HdlcPutByte(struct async *async, u_char **cp, u_char c, int proto)
{
u_char *wp;
wp = *cp;
if ((c < 0x20 && (proto == PROTO_LCP || (AsyncState.his_accmap & (1 << c))))
if ((c < 0x20 && (proto == PROTO_LCP || (async->his_accmap & (1 << c))))
|| (c == HDLC_ESC) || (c == HDLC_SYN)) {
*wp++ = HDLC_ESC;
c ^= HDLC_XOR;
@ -100,9 +85,8 @@ HdlcPutByte(u_char **cp, u_char c, int proto)
}
void
AsyncOutput(int pri, struct mbuf *bp, int proto, struct link *l)
async_Output(int pri, struct mbuf *bp, int proto, struct physical *physical)
{
struct async_state *hs = &AsyncState;
u_char *cp, *sp, *ep;
struct mbuf *wp;
int cnt;
@ -111,14 +95,14 @@ AsyncOutput(int pri, struct mbuf *bp, int proto, struct link *l)
pfree(bp);
return;
}
cp = hs->xbuff;
cp = physical->async.xbuff;
ep = cp + HDLCSIZE - 10;
wp = bp;
*cp++ = HDLC_SYN;
while (wp) {
sp = MBUF_CTOP(wp);
for (cnt = wp->cnt; cnt > 0; cnt--) {
HdlcPutByte(&cp, *sp++, proto);
HdlcPutByte(&physical->async, &cp, *sp++, proto);
if (cp >= ep) {
pfree(bp);
return;
@ -128,59 +112,58 @@ AsyncOutput(int pri, struct mbuf *bp, int proto, struct link *l)
}
*cp++ = HDLC_SYN;
cnt = cp - hs->xbuff;
LogDumpBuff(LogASYNC, "WriteModem", hs->xbuff, cnt);
link_Write(l, pri, (char *)hs->xbuff, cnt);
link_AddOutOctets(l, cnt);
cnt = cp - physical->async.xbuff;
LogDumpBuff(LogASYNC, "WriteModem", physical->async.xbuff, cnt);
link_Write(physical2link(physical), pri, (char *)physical->async.xbuff, cnt);
link_AddOutOctets(physical2link(physical), cnt);
pfree(bp);
}
static struct mbuf *
AsyncDecode(u_char c)
async_Decode(struct async *async, u_char c)
{
struct async_state *hs = &AsyncState;
struct mbuf *bp;
if ((hs->mode & MODE_HUNT) && c != HDLC_SYN)
if ((async->mode & MODE_HUNT) && c != HDLC_SYN)
return NULL;
switch (c) {
case HDLC_SYN:
hs->mode &= ~MODE_HUNT;
if (hs->length) { /* packet is ready. */
bp = mballoc(hs->length, MB_ASYNC);
mbwrite(bp, hs->hbuff, hs->length);
hs->length = 0;
async->mode &= ~MODE_HUNT;
if (async->length) { /* packet is ready. */
bp = mballoc(async->length, MB_ASYNC);
mbwrite(bp, async->hbuff, async->length);
async->length = 0;
return bp;
}
break;
case HDLC_ESC:
if (!(hs->mode & MODE_ESC)) {
hs->mode |= MODE_ESC;
if (!(async->mode & MODE_ESC)) {
async->mode |= MODE_ESC;
break;
}
/* Fall into ... */
default:
if (hs->length >= HDLCSIZE) {
if (async->length >= HDLCSIZE) {
/* packet is too large, discard it */
LogPrintf(LogERROR, "Packet too large (%d), discarding.\n", hs->length);
hs->length = 0;
hs->mode = MODE_HUNT;
LogPrintf(LogERROR, "Packet too large (%d), discarding.\n", async->length);
async->length = 0;
async->mode = MODE_HUNT;
break;
}
if (hs->mode & MODE_ESC) {
if (async->mode & MODE_ESC) {
c ^= HDLC_XOR;
hs->mode &= ~MODE_ESC;
async->mode &= ~MODE_ESC;
}
hs->hbuff[hs->length++] = c;
async->hbuff[async->length++] = c;
break;
}
return NULL;
}
void
AsyncInput(struct bundle *bundle, u_char *buff, int cnt,
struct physical *physical)
async_Input(struct bundle *bundle, u_char *buff, int cnt,
struct physical *physical)
{
struct mbuf *bp;
@ -193,7 +176,7 @@ AsyncInput(struct bundle *bundle, u_char *buff, int cnt,
HdlcInput(bundle, bp, physical);
} else {
while (cnt > 0) {
bp = AsyncDecode(*buff++);
bp = async_Decode(&physical->async, *buff++);
if (bp)
HdlcInput(bundle, bp, physical);
cnt--;

View File

@ -23,10 +23,21 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: async.h,v 1.2.4.2 1998/01/30 19:45:25 brian Exp $
* $Id: async.h,v 1.2.4.3 1998/02/02 19:32:00 brian Exp $
*/
extern void AsyncInit(void);
extern void SetLinkParams(struct lcpstate *);
extern void AsyncOutput(int, struct mbuf *, int, struct link *);
extern void AsyncInput(struct bundle *, u_char *, int, struct physical *);
#define HDLCSIZE (MAX_MRU*2+6)
struct async {
int mode;
int length;
u_char hbuff[HDLCSIZE]; /* recv buffer */
u_char xbuff[HDLCSIZE]; /* xmit buffer */
u_long my_accmap;
u_long his_accmap;
};
extern void async_Init(struct async *);
extern void async_SetLinkParams(struct async *, struct lcpstate *);
extern void async_Output(int, struct mbuf *, int, struct physical *);
extern void async_Input(struct bundle *, u_char *, int, struct physical *);

View File

@ -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.3 1998/01/30 19:45:26 brian Exp $
* $Id: auth.c,v 1.27.2.4 1998/02/02 19:32:00 brian Exp $
*
* TODO:
* o Implement check against with registered IP addresses.
@ -28,6 +28,7 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include "command.h"
@ -43,6 +44,10 @@
#include "auth.h"
#include "chat.h"
#include "systems.h"
#include "lcp.h"
#include "hdlc.h"
#include "async.h"
#include "link.h"
#include "physical.h"
void

View File

@ -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.4 1998/01/31 02:48:15 brian Exp $
* $Id: chap.c,v 1.28.2.5 1998/02/02 19:32:03 brian Exp $
*
* TODO:
*/
@ -32,6 +32,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <time.h>
#include <unistd.h>
#ifdef __OpenBSD__
@ -56,6 +57,9 @@
#include "loadalias.h"
#include "vars.h"
#include "auth.h"
#include "async.h"
#include "throughput.h"
#include "link.h"
#include "physical.h"
static const char *chapcodes[] = {

View File

@ -18,7 +18,7 @@
* Columbus, OH 43221
* (614)451-1883
*
* $Id: chat.c,v 1.44 1998/01/21 02:15:13 brian Exp $
* $Id: chat.c,v 1.44.2.1 1998/01/29 00:49:14 brian Exp $
*
* TODO:
* o Support more UUCP compatible control sequences.
@ -50,6 +50,12 @@
#include "vars.h"
#include "chat.h"
#include "modem.h"
#include "hdlc.h"
#include "throughput.h"
#include "fsm.h"
#include "lcp.h"
#include "link.h"
#include "async.h"
#include "physical.h"
#ifndef isblank

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.5 1998/02/02 19:32:04 brian Exp $
* $Id: command.c,v 1.131.2.6 1998/02/02 19:32:30 brian Exp $
*
*/
#include <sys/param.h>
@ -74,6 +74,7 @@
#include "ip.h"
#include "slcompress.h"
#include "auth.h"
#include "async.h"
#include "link.h"
#include "physical.h"

View File

@ -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.3 1998/01/31 02:48:18 brian Exp $
* $Id: fsm.c,v 1.27.2.4 1998/02/02 19:32:05 brian Exp $
*
* TODO:
* o Refer loglevel for log output
@ -45,6 +45,7 @@
#include "loadalias.h"
#include "vars.h"
#include "throughput.h"
#include "async.h"
#include "link.h"
#include "physical.h"

View File

@ -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.4 1998/01/31 02:48:19 brian Exp $
* $Id: hdlc.c,v 1.28.2.5 1998/02/02 19:32:06 brian Exp $
*
* TODO:
*/
@ -237,7 +237,7 @@ HdlcOutput(struct link *l, int pri, u_short proto, struct mbuf *bp)
if (Physical_IsSync(p))
link_Output(l, pri, mhp); /* Send it raw */
else
AsyncOutput(pri, mhp, proto, l);
async_Output(pri, mhp, proto, p);
}
/* Check out the latest ``Assigned numbers'' rfc (rfc1700.txt) */

View File

@ -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.5 1998/02/02 19:32:08 brian Exp $
* $Id: ipcp.c,v 1.50.2.6 1998/02/02 19:32:31 brian Exp $
*
* TODO:
* o More RFC1772 backwoard compatibility
@ -33,6 +33,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include "command.h"
@ -56,6 +57,7 @@
#include "route.h"
#include "filter.h"
#include "hdlc.h"
#include "async.h"
#include "link.h"
#include "physical.h"
@ -252,6 +254,7 @@ IpcpInit(struct bundle *bundle, struct link *l)
IpcpInfo.VJInitComp;
else
IpcpInfo.want_compproto = 0;
VjInit(IpcpInfo.VJInitSlots - 1);
IpcpInfo.heis1172 = 0;
IpcpInfo.fsm.maxconfig = 10;

View File

@ -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.5 1998/01/31 02:48:21 brian Exp $
* $Id: lcp.c,v 1.55.2.6 1998/02/02 19:32:09 brian Exp $
*
* TODO:
* o Limit data field length by MRU
@ -200,6 +200,7 @@ LcpInit(struct bundle *bundle, struct physical *physical)
/* Initialise ourselves */
FsmInit(&LcpInfo.fsm, bundle, physical2link(physical));
HdlcInit();
async_Init(&physical->async);
LcpInfo.his_mru = DEF_MRU;
LcpInfo.his_accmap = 0xffffffff;
@ -436,9 +437,9 @@ LcpLayerUp(struct fsm *fp)
struct physical *p = link2physical(fp->link);
LogPrintf(LogLCP, "LcpLayerUp\n");
SetLinkParams(&LcpInfo);
if (p) {
async_SetLinkParams(&p->async, &LcpInfo);
NewPhase(fp->bundle, p, PHASE_AUTHENTICATE);
StartLqm(p);
} else

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: lqr.c,v 1.22.2.3 1998/01/30 19:45:51 brian Exp $
* $Id: lqr.c,v 1.22.2.4 1998/01/31 02:48:23 brian Exp $
*
* o LQR based on RFC1333
*
@ -29,6 +29,7 @@
#include <netinet/in.h>
#include <stdio.h>
#include <termios.h>
#include "command.h"
#include "mbuf.h"
@ -37,10 +38,13 @@
#include "timer.h"
#include "fsm.h"
#include "lcpproto.h"
#include "lcp.h"
#include "hdlc.h"
#include "async.h"
#include "throughput.h"
#include "link.h"
#include "physical.h"
#include "lqr.h"
#include "hdlc.h"
#include "lcp.h"
#include "loadalias.h"
#include "vars.h"

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.4 1998/01/31 02:48:25 brian Exp $
* $Id: main.c,v 1.121.2.5 1998/02/02 19:32:10 brian Exp $
*
* TODO:
* o Add commands for traffic summary, version display, etc.
@ -578,8 +578,6 @@ PacketMode(struct bundle *bundle, int delay)
LogPrintf(LogWARN, "PacketMode: Not connected.\n");
return;
}
AsyncInit();
VjInit(15);
LcpInit(bundle, pppVars.physical);
IpcpInit(bundle, physical2link(pppVars.physical));
CcpInit(bundle, physical2link(pppVars.physical));
@ -1052,7 +1050,7 @@ DoLoop(struct bundle *bundle)
}
} else {
if (n > 0)
AsyncInput(bundle, rbuff, n, pppVars.physical);
async_Input(bundle, rbuff, n, pppVars.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: modem.c,v 1.77.2.2 1998/01/30 19:45:57 brian Exp $
* $Id: modem.c,v 1.77.2.3 1998/02/02 19:32:11 brian Exp $
*
* TODO:
*/
@ -59,12 +59,11 @@
#include "main.h"
#include "chat.h"
#include "throughput.h"
#include "async.h"
#undef mode
/* We're defining a physical device, and thus need the real
headers. */
#define PHYSICAL_DEVICE
/* We're defining a physical device, and thus need the real headers. */
#include "link.h"
#include "physical.h"
@ -93,6 +92,7 @@ struct physical phys_modem = {
ModemIsActive,
ModemHangup
},
{ 0 },
-1
};

View File

@ -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.4 1998/01/31 02:48:27 brian Exp $
* $Id: pap.c,v 1.20.2.5 1998/02/02 19:32:12 brian Exp $
*
* TODO:
*/
@ -29,6 +29,7 @@
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <termios.h>
#include <unistd.h>
#ifdef __OpenBSD__
#include <util.h>
@ -51,6 +52,9 @@
#include "lcpproto.h"
#include "phase.h"
#include "auth.h"
#include "async.h"
#include "throughput.h"
#include "link.h"
#include "physical.h"
static const char *papcodes[] = { "???", "REQUEST", "ACK", "NAK" };

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.1 1998/01/29 00:49:29 brian Exp $
* $Id: physical.c,v 1.1.2.2 1998/01/30 19:46:02 brian Exp $
*
*/
@ -44,12 +44,13 @@
#include "hdlc.h"
#include "timer.h"
#include "throughput.h"
#include "fsm.h"
#include "lcp.h"
#include "async.h"
#include "link.h"
#define PHYSICAL_DEVICE
#include "physical.h"
#include "vars.h"
/* External calls - should possibly be moved inline */

View File

@ -16,13 +16,13 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: physical.h,v 1.1.2.1 1998/01/29 00:49:30 brian Exp $
* $Id: physical.h,v 1.1.2.2 1998/01/30 19:46:03 brian Exp $
*
*/
#ifdef PHYSICAL_DEVICE
struct physical {
struct link link;
struct async async; /* Our async state */
int fd; /* File descriptor for this device */
int mbits; /* Current DCD status */
unsigned dev_is_modem : 1; /* Is the device an actual modem?
@ -42,9 +42,6 @@ struct physical {
unsigned int speed; /* Modem speed */
struct termios ios; /* To be able to reset from raw mode */
};
#else
struct physical;
#endif
#define physical2link(p) ((struct link *)p)
#define link2physical(l) (l->type == PHYSICAL_LINK ? (struct physical *)l : 0)

View File

@ -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.2.1 1998/01/29 00:49:31 brian Exp $
* $Id: vars.c,v 1.45.2.2 1998/02/02 19:32:16 brian Exp $
*
*/
#include <sys/param.h>
@ -37,10 +37,14 @@
#include "loadalias.h"
#include "vars.h"
#include "auth.h"
#include "lcp.h"
#include "async.h"
#include "throughput.h"
#include "link.h"
#include "physical.h"
char VarVersion[] = "PPP Version 1.90";
char VarLocalVersion[] = "$Date: 1998/01/29 00:49:31 $";
char VarLocalVersion[] = "$Date: 1998/02/02 19:32:16 $";
int Utmp = 0;
int ipKeepAlive = 0;
int reconnectState = RECON_UNKNOWN;