aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorBrian Somers <brian@FreeBSD.org>1998-01-29 00:49:32 +0000
committerBrian Somers <brian@FreeBSD.org>1998-01-29 00:49:32 +0000
commit63b7346316afa0c20b6cf22506bcc53abc9f08f8 (patch)
tree0f029d822049c079452af8d60be4419d8bbace89 /usr.sbin
parent1ae349f52c53416e04f1d038a8210f1a9fa7db2c (diff)
downloadsrc-63b7346316afa0c20b6cf22506bcc53abc9f08f8.tar.gz
src-63b7346316afa0c20b6cf22506bcc53abc9f08f8.zip
Create a new MP branch for `multilink protocol'.
Do lots of initial shuffling and grouping. Submitted by: Eivind Eklund <perhaps@yes.no>
Notes
Notes: svn path=/cvs2svn/branches/MP/; revision=32863
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/ppp/Makefile6
-rw-r--r--usr.sbin/ppp/async.c19
-rw-r--r--usr.sbin/ppp/async.h6
-rw-r--r--usr.sbin/ppp/auth.c24
-rw-r--r--usr.sbin/ppp/auth.h15
-rw-r--r--usr.sbin/ppp/ccp.c12
-rw-r--r--usr.sbin/ppp/ccp.h8
-rw-r--r--usr.sbin/ppp/chap.c50
-rw-r--r--usr.sbin/ppp/chap.h6
-rw-r--r--usr.sbin/ppp/chat.c63
-rw-r--r--usr.sbin/ppp/chat.h4
-rw-r--r--usr.sbin/ppp/command.c62
-rw-r--r--usr.sbin/ppp/deflate.c7
-rw-r--r--usr.sbin/ppp/defs.h3
-rw-r--r--usr.sbin/ppp/fsm.c14
-rw-r--r--usr.sbin/ppp/fsm.h7
-rw-r--r--usr.sbin/ppp/hdlc.c34
-rw-r--r--usr.sbin/ppp/hdlc.h8
-rw-r--r--usr.sbin/ppp/ip.c8
-rw-r--r--usr.sbin/ppp/ip.h6
-rw-r--r--usr.sbin/ppp/ipcp.c15
-rw-r--r--usr.sbin/ppp/ipcp.h4
-rw-r--r--usr.sbin/ppp/lcp.c35
-rw-r--r--usr.sbin/ppp/lcp.h7
-rw-r--r--usr.sbin/ppp/lqr.c22
-rw-r--r--usr.sbin/ppp/lqr.h8
-rw-r--r--usr.sbin/ppp/main.c81
-rw-r--r--usr.sbin/ppp/modem.c457
-rw-r--r--usr.sbin/ppp/modem.h33
-rw-r--r--usr.sbin/ppp/pap.c34
-rw-r--r--usr.sbin/ppp/pap.h4
-rw-r--r--usr.sbin/ppp/phase.c11
-rw-r--r--usr.sbin/ppp/phase.h6
-rw-r--r--usr.sbin/ppp/physical.c171
-rw-r--r--usr.sbin/ppp/physical.h83
-rw-r--r--usr.sbin/ppp/pred.c7
-rw-r--r--usr.sbin/ppp/vars.c9
-rw-r--r--usr.sbin/ppp/vars.h13
-rw-r--r--usr.sbin/ppp/vjcomp.c6
-rw-r--r--usr.sbin/ppp/vjcomp.h6
40 files changed, 907 insertions, 467 deletions
diff --git a/usr.sbin/ppp/Makefile b/usr.sbin/ppp/Makefile
index 4969b34940e2..6a4bdf6f9133 100644
--- a/usr.sbin/ppp/Makefile
+++ b/usr.sbin/ppp/Makefile
@@ -1,12 +1,12 @@
-# $Id: Makefile,v 1.35 1998/01/17 14:21:21 brian Exp $
+# $Id: Makefile,v 1.36 1998/01/29 00:42:04 brian Exp $
PROG= ppp
SRCS= arp.c async.c auth.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 \
- log.c lqr.c main.c mbuf.c modem.c os.c pap.c phase.c \
+ log.c lqr.c main.c mbuf.c modem.c os.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
+CFLAGS+=-Wall -Wpointer-arith
LDADD+= -lmd -lcrypt -lutil -lz
DPADD+= ${LIBMD} ${LIBCRYPT} ${LIBUTIL} ${LIBZ}
MAN8= ppp.8
diff --git a/usr.sbin/ppp/async.c b/usr.sbin/ppp/async.c
index 835de42929d0..5c6b123007b5 100644
--- a/usr.sbin/ppp/async.c
+++ b/usr.sbin/ppp/async.c
@@ -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.14 1997/11/22 03:37:23 brian Exp $
+ * $Id: async.c,v 1.15 1998/01/21 02:15:08 brian Exp $
*
*/
#include <sys/param.h>
@@ -40,6 +40,7 @@
#include "loadalias.h"
#include "vars.h"
#include "async.h"
+#include "physical.h"
#define HDLCSIZE (MAX_MRU*2+6)
@@ -97,7 +98,7 @@ HdlcPutByte(u_char **cp, u_char c, int proto)
}
void
-AsyncOutput(int pri, struct mbuf *bp, int proto)
+AsyncOutput(int pri, struct mbuf *bp, int proto, struct physical *physical)
{
struct async_state *hs = &AsyncState;
u_char *cp, *sp, *ep;
@@ -127,8 +128,8 @@ AsyncOutput(int pri, struct mbuf *bp, int proto)
cnt = cp - hs->xbuff;
LogDumpBuff(LogASYNC, "WriteModem", hs->xbuff, cnt);
- WriteModem(pri, (char *) hs->xbuff, cnt);
- ModemAddOutOctets(cnt);
+ WriteModem(physical, pri, (char *) hs->xbuff, cnt);
+ ModemAddOutOctets(physical, cnt);
pfree(bp);
}
@@ -176,21 +177,21 @@ AsyncDecode(u_char c)
}
void
-AsyncInput(u_char *buff, int cnt)
+AsyncInput(u_char *buff, int cnt, struct physical *physical)
{
struct mbuf *bp;
- ModemAddInOctets(cnt);
- if (DEV_IS_SYNC) {
+ ModemAddInOctets(physical, cnt);
+ if (Physical_IsSync(physical)) {
bp = mballoc(cnt, MB_ASYNC);
memcpy(MBUF_CTOP(bp), buff, cnt);
bp->cnt = cnt;
- HdlcInput(bp);
+ HdlcInput(bp, physical);
} else {
while (cnt > 0) {
bp = AsyncDecode(*buff++);
if (bp)
- HdlcInput(bp);
+ HdlcInput(bp, physical);
cnt--;
}
}
diff --git a/usr.sbin/ppp/async.h b/usr.sbin/ppp/async.h
index 13fa6b9b9060..2680776321cd 100644
--- a/usr.sbin/ppp/async.h
+++ b/usr.sbin/ppp/async.h
@@ -23,10 +23,10 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id$
+ * $Id: async.h,v 1.2 1997/12/21 12:11:04 brian Exp $
*/
extern void AsyncInit(void);
extern void SetLinkParams(struct lcpstate *);
-extern void AsyncOutput(int, struct mbuf *, int);
-extern void AsyncInput(u_char *, int);
+extern void AsyncOutput(int, struct mbuf *, int, struct physical *);
+extern void AsyncInput(u_char *, int, struct physical *);
diff --git a/usr.sbin/ppp/auth.c b/usr.sbin/ppp/auth.c
index 4226a0a3980d..0b04487bae72 100644
--- a/usr.sbin/ppp/auth.c
+++ b/usr.sbin/ppp/auth.c
@@ -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.26 1998/01/05 01:35:17 brian Exp $
+ * $Id: auth.c,v 1.27 1998/01/21 02:15:09 brian Exp $
*
* TODO:
* o Implement check against with registered IP addresses.
@@ -25,6 +25,7 @@
#include <sys/param.h>
#include <netinet/in.h>
+#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
@@ -99,7 +100,8 @@ LocalAuthValidate(const char *fname, const char *system, const char *key)
}
int
-AuthValidate(const char *fname, const char *system, const char *key)
+AuthValidate(const char *fname, const char *system, const char *key,
+ struct physical *physical)
{
FILE *fp;
int n;
@@ -124,7 +126,7 @@ AuthValidate(const char *fname, const char *system, const char *key)
CloseSecret(fp);
if (n > 2 && !UseHisaddr(vector[2], 1))
return (0);
- IpcpInit();
+ IpcpInit(physical);
if (n > 3)
SetLabel(vector[3]);
return (1); /* Valid */
@@ -136,7 +138,8 @@ AuthValidate(const char *fname, const char *system, const char *key)
}
char *
-AuthGetSecret(const char *fname, const char *system, int len, int setaddr)
+AuthGetSecret(const char *fname, const char *system, int len, int setaddr,
+ struct physical *physical)
{
FILE *fp;
int n;
@@ -162,7 +165,7 @@ AuthGetSecret(const char *fname, const char *system, int len, int setaddr)
}
if (n > 2 && setaddr)
if (UseHisaddr(vector[2], 1))
- IpcpInit();
+ IpcpInit(physical);
else
return NULL;
if (n > 3)
@@ -184,15 +187,19 @@ AuthTimeout(void *vauthp)
StopTimer(tp);
if (--authp->retry > 0) {
StartTimer(tp);
- (authp->ChallengeFunc) (++authp->id);
+ (authp->ChallengeFunc) (++authp->id, authp->physical);
}
}
void
-StartAuthChallenge(struct authinfo *authp)
+StartAuthChallenge(struct authinfo *authp, struct physical *physical)
{
struct pppTimer *tp;
+ assert(authp->physical == NULL);
+
+ authp->physical = physical;
+
tp = &authp->authtimer;
StopTimer(tp);
tp->func = AuthTimeout;
@@ -202,11 +209,12 @@ StartAuthChallenge(struct authinfo *authp)
StartTimer(tp);
authp->retry = 3;
authp->id = 1;
- (authp->ChallengeFunc) (authp->id);
+ (authp->ChallengeFunc) (authp->id, physical);
}
void
StopAuthTimer(struct authinfo *authp)
{
StopTimer(&authp->authtimer);
+ authp->physical = NULL;
}
diff --git a/usr.sbin/ppp/auth.h b/usr.sbin/ppp/auth.h
index a0fa77968608..6a1c02144f38 100644
--- a/usr.sbin/ppp/auth.h
+++ b/usr.sbin/ppp/auth.h
@@ -15,11 +15,13 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: auth.h,v 1.9 1997/10/26 01:02:09 brian Exp $
+ * $Id: auth.h,v 1.10 1997/11/22 03:37:24 brian Exp $
*
* TODO:
*/
+struct physical;
+
typedef enum {
VALID,
INVALID,
@@ -27,15 +29,18 @@ typedef enum {
} LOCAL_AUTH_VALID;
struct authinfo {
- void (*ChallengeFunc) (int);
+ void (*ChallengeFunc) (int, struct physical *);
struct pppTimer authtimer;
int retry;
int id;
+ struct physical *physical;
};
extern LOCAL_AUTH_VALID LocalAuthValidate(const char *, const char *, const char *);
extern void StopAuthTimer(struct authinfo *);
-extern void StartAuthChallenge(struct authinfo *);
+extern void StartAuthChallenge(struct authinfo *, struct physical *);
extern void LocalAuthInit(void);
-extern int AuthValidate(const char *, const char *, const char *);
-extern char *AuthGetSecret(const char *, const char *, int, int);
+extern int AuthValidate(const char *, const char *, const char *,
+ struct physical *);
+extern char *AuthGetSecret(const char *, const char *, int, int,
+ struct physical *);
diff --git a/usr.sbin/ppp/ccp.c b/usr.sbin/ppp/ccp.c
index 5dfd94180210..0f852020c3e7 100644
--- a/usr.sbin/ppp/ccp.c
+++ b/usr.sbin/ppp/ccp.c
@@ -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.29 1998/01/20 22:47:34 brian Exp $
+ * $Id: ccp.c,v 1.30 1998/01/21 02:15:10 brian Exp $
*
* TODO:
* o Support other compression protocols
@@ -67,6 +67,8 @@ struct fsm CcpFsm = {
{0, 0, 0, NULL, NULL, NULL}, /* Stopped timer */
LogCCP,
+ NULL,
+
CcpLayerUp,
CcpLayerDown,
CcpLayerStart,
@@ -150,9 +152,9 @@ ccpstateInit(void)
}
void
-CcpInit()
+CcpInit(struct physical *physical)
{
- FsmInit(&CcpFsm);
+ FsmInit(&CcpFsm, physical);
ccpstateInit();
CcpFsm.maxconfig = 10;
}
@@ -404,10 +406,10 @@ CcpResetInput(u_char id)
}
int
-CcpOutput(int pri, u_short proto, struct mbuf *m)
+CcpOutput(struct physical *physical, int pri, u_short proto, struct mbuf *m)
{
if (out_algorithm >= 0 && out_algorithm < NALGORITHMS)
- return (*algorithm[out_algorithm]->o.Write)(pri, proto, m);
+ return (*algorithm[out_algorithm]->o.Write)(physical, pri, proto, m);
return 0;
}
diff --git a/usr.sbin/ppp/ccp.h b/usr.sbin/ppp/ccp.h
index d84a2afd7c14..5ac4fd4c4ac7 100644
--- a/usr.sbin/ppp/ccp.h
+++ b/usr.sbin/ppp/ccp.h
@@ -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.13 1998/01/10 01:55:09 brian Exp $
+ * $Id: ccp.h,v 1.14 1998/01/11 17:50:29 brian Exp $
*
* TODO:
*/
@@ -73,7 +73,7 @@ struct ccp_algorithm {
int (*Init)(void);
void (*Term)(void);
void (*Reset)(void);
- int (*Write)(int, u_short, struct mbuf *);
+ int (*Write)(struct physical *, int, u_short, struct mbuf *);
} o;
};
@@ -84,9 +84,9 @@ extern void CcpSendResetReq(struct fsm *);
extern void CcpInput(struct mbuf *);
extern void CcpUp(void);
extern void CcpOpen(void);
-extern void CcpInit(void);
+extern void CcpInit(struct physical *physical);
extern int ReportCcpStatus(struct cmdargs const *);
extern void CcpResetInput(u_char);
-extern int CcpOutput(int, u_short, struct mbuf *);
+extern int CcpOutput(struct physical *, int, u_short, struct mbuf *);
extern struct mbuf *CompdInput(u_short *, struct mbuf *);
extern void CcpDictSetup(u_short, struct mbuf *);
diff --git a/usr.sbin/ppp/chap.c b/usr.sbin/ppp/chap.c
index 28bd5e3b4492..7e1a9e461e5f 100644
--- a/usr.sbin/ppp/chap.c
+++ b/usr.sbin/ppp/chap.c
@@ -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.27 1997/12/07 23:55:25 brian Exp $
+ * $Id: chap.c,v 1.28 1997/12/24 09:28:53 brian Exp $
*
* TODO:
*/
@@ -56,13 +56,15 @@
#include "loadalias.h"
#include "vars.h"
#include "auth.h"
+#include "physical.h"
static const char *chapcodes[] = {
"???", "CHALLENGE", "RESPONSE", "SUCCESS", "FAILURE"
};
static void
-ChapOutput(u_int code, u_int id, const u_char * ptr, int count)
+ChapOutput(struct physical *physical, u_int code, u_int id,
+ const u_char * ptr, int count)
{
int plen;
struct fsmheader lh;
@@ -78,7 +80,7 @@ ChapOutput(u_int code, u_int id, const u_char * ptr, int count)
memcpy(MBUF_CTOP(bp) + sizeof(struct fsmheader), ptr, count);
LogDumpBp(LogDEBUG, "ChapOutput", bp);
LogPrintf(LogLCP, "ChapOutput: %s\n", chapcodes[code]);
- HdlcOutput(PRI_LINK, PROTO_CHAP, bp);
+ HdlcOutput(physical, PRI_LINK, PROTO_CHAP, bp);
}
@@ -86,7 +88,7 @@ static char challenge_data[80];
static int challenge_len;
static void
-SendChapChallenge(int chapid)
+SendChapChallenge(int chapid, struct physical *physical)
{
int len, i;
char *cp;
@@ -99,7 +101,8 @@ SendChapChallenge(int chapid)
len = strlen(VarAuthName);
memcpy(cp, VarAuthName, len);
cp += len;
- ChapOutput(CHAP_CHALLENGE, chapid, challenge_data, cp - challenge_data);
+ ChapOutput(physical, CHAP_CHALLENGE, chapid, challenge_data,
+ cp - challenge_data);
}
struct authinfo AuthChapInfo = {
@@ -107,7 +110,7 @@ struct authinfo AuthChapInfo = {
};
static void
-RecvChapTalk(struct fsmheader *chp, struct mbuf *bp)
+RecvChapTalk(struct fsmheader *chp, struct mbuf *bp, struct physical *physical)
{
int valsize, len;
int arglen, keylen, namelen;
@@ -146,7 +149,7 @@ RecvChapTalk(struct fsmheader *chp, struct mbuf *bp)
argp = malloc(1 + valsize + namelen + 16);
if (argp == NULL) {
- ChapOutput(CHAP_FAILURE, chp->id, "Out of memory!", 14);
+ ChapOutput(physical, CHAP_FAILURE, chp->id, "Out of memory!", 14);
return;
}
#ifdef HAVE_DES
@@ -173,7 +176,8 @@ RecvChapTalk(struct fsmheader *chp, struct mbuf *bp)
ap += 2 * keylen;
ChapMS(digest, answer + 2 * keylen, valsize);
LogDumpBuff(LogDEBUG, "answer", digest, 24);
- ChapOutput(CHAP_RESPONSE, chp->id, argp, namelen + MS_CHAP_RESPONSE_LEN + 1);
+ ChapOutput(physical, CHAP_RESPONSE, chp->id, argp,
+ namelen + MS_CHAP_RESPONSE_LEN + 1);
} else {
#endif
digest = argp;
@@ -192,7 +196,7 @@ RecvChapTalk(struct fsmheader *chp, struct mbuf *bp)
memcpy(digest + 16, name, namelen);
ap += namelen;
/* Send answer to the peer */
- ChapOutput(CHAP_RESPONSE, chp->id, argp, namelen + 17);
+ ChapOutput(physical, CHAP_RESPONSE, chp->id, argp, namelen + 17);
#ifdef HAVE_DES
}
#endif
@@ -202,7 +206,9 @@ RecvChapTalk(struct fsmheader *chp, struct mbuf *bp)
/*
* Get a secret key corresponds to the peer
*/
- keyp = AuthGetSecret(SECRETFILE, name, namelen, chp->code == CHAP_RESPONSE);
+ keyp = AuthGetSecret(SECRETFILE, name, namelen,
+ chp->code == CHAP_RESPONSE,
+ physical);
if (keyp) {
/*
* Compute correct digest value
@@ -223,8 +229,9 @@ RecvChapTalk(struct fsmheader *chp, struct mbuf *bp)
* Compare with the response
*/
if (memcmp(cp, cdigest, 16) == 0) {
- ChapOutput(CHAP_SUCCESS, chp->id, "Welcome!!", 10);
- if ((mode & MODE_DIRECT) && isatty(modem) && Enabled(ConfUtmp))
+ ChapOutput(physical, CHAP_SUCCESS, chp->id, "Welcome!!", 10);
+ if ((mode & MODE_DIRECT) && Physical_IsATTY(physical)
+ && Enabled(ConfUtmp))
if (Utmp)
LogPrintf(LogERROR, "Oops, already logged in on %s\n",
VarBaseDevice);
@@ -239,7 +246,7 @@ RecvChapTalk(struct fsmheader *chp, struct mbuf *bp)
login(&ut);
Utmp = 1;
}
- NewPhase(PHASE_NETWORK);
+ NewPhase(physical, PHASE_NETWORK);
break;
}
}
@@ -247,15 +254,16 @@ RecvChapTalk(struct fsmheader *chp, struct mbuf *bp)
/*
* Peer is not registerd, or response digest is wrong.
*/
- ChapOutput(CHAP_FAILURE, chp->id, "Invalid!!", 9);
+ ChapOutput(physical, CHAP_FAILURE, chp->id, "Invalid!!", 9);
reconnect(RECON_FALSE);
- LcpClose();
+ LcpClose(&LcpFsm);
break;
}
}
static void
-RecvChapResult(struct fsmheader *chp, struct mbuf *bp)
+RecvChapResult(struct fsmheader *chp, struct mbuf *bp,
+ struct physical *physical)
{
int len;
struct lcpstate *lcp = &LcpInfo;
@@ -266,19 +274,19 @@ RecvChapResult(struct fsmheader *chp, struct mbuf *bp)
if (lcp->auth_iwait == PROTO_CHAP) {
lcp->auth_iwait = 0;
if (lcp->auth_ineed == 0)
- NewPhase(PHASE_NETWORK);
+ NewPhase(physical, PHASE_NETWORK);
}
} else {
/*
- * Maybe, we shoud close LCP. Of cause, peer may take close action, too.
+ * Maybe, we should close LCP. Of cause, peer may take close action, too.
*/
;
}
}
void
-ChapInput(struct mbuf *bp)
+ChapInput(struct mbuf *bp, struct physical *physical)
{
int len = plength(bp);
struct fsmheader *chp;
@@ -298,11 +306,11 @@ ChapInput(struct mbuf *bp)
StopAuthTimer(&AuthChapInfo);
/* Fall into.. */
case CHAP_CHALLENGE:
- RecvChapTalk(chp, bp);
+ RecvChapTalk(chp, bp, physical);
break;
case CHAP_SUCCESS:
case CHAP_FAILURE:
- RecvChapResult(chp, bp);
+ RecvChapResult(chp, bp, physical);
break;
}
}
diff --git a/usr.sbin/ppp/chap.h b/usr.sbin/ppp/chap.h
index ba178b6dab80..e9fc820b5017 100644
--- a/usr.sbin/ppp/chap.h
+++ b/usr.sbin/ppp/chap.h
@@ -15,11 +15,13 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: chap.h,v 1.8 1997/10/26 01:02:19 brian Exp $
+ * $Id: chap.h,v 1.9 1997/10/26 12:42:08 brian Exp $
*
* TODO:
*/
+struct physical;
+
#define CHAP_CHALLENGE 1
#define CHAP_RESPONSE 2
#define CHAP_SUCCESS 3
@@ -27,4 +29,4 @@
extern struct authinfo AuthChapInfo;
-extern void ChapInput(struct mbuf *);
+extern void ChapInput(struct mbuf *, struct physical *);
diff --git a/usr.sbin/ppp/chat.c b/usr.sbin/ppp/chat.c
index 61d9877ebe22..202be939dd8c 100644
--- a/usr.sbin/ppp/chat.c
+++ b/usr.sbin/ppp/chat.c
@@ -18,7 +18,7 @@
* Columbus, OH 43221
* (614)451-1883
*
- * $Id: chat.c,v 1.43 1997/12/27 07:22:11 brian Exp $
+ * $Id: chat.c,v 1.44 1998/01/21 02:15:13 brian Exp $
*
* TODO:
* o Support more UUCP compatible control sequences.
@@ -50,6 +50,7 @@
#include "vars.h"
#include "chat.h"
#include "modem.h"
+#include "physical.h"
#ifndef isblank
#define isblank(c) ((c) == '\t' || (c) == ' ')
@@ -274,7 +275,7 @@ connect_log(const char *str, int single_p)
}
static void
-ExecStr(char *command, char *out, int olen)
+ExecStr(struct physical *physical, char *command, char *out, int olen)
{
pid_t pid;
int fids[2];
@@ -296,17 +297,15 @@ ExecStr(char *command, char *out, int olen)
signal(SIGTERM, SIG_DFL);
signal(SIGHUP, SIG_DFL);
signal(SIGALRM, SIG_DFL);
- if (modem == 2) {
- int nmodem;
- nmodem = dup(modem);
- close(modem);
- modem = nmodem;
+ /* XXX-ML This looks like it might need more encapsulation. */
+ if (Physical_GetFD(physical) == 2) {
+ Physical_DupAndClose(physical);
}
close(fids[0]);
dup2(fids[1], 2);
close(fids[1]);
- dup2(modem, 0);
- dup2(modem, 1);
+ dup2(Physical_GetFD(physical), 0);
+ dup2(Physical_GetFD(physical), 1);
if ((nb = open("/dev/tty", O_RDWR)) > 3) {
dup2(nb, 3);
close(nb);
@@ -360,7 +359,7 @@ ExecStr(char *command, char *out, int olen)
}
static int
-WaitforString(const char *estr)
+WaitforString(struct physical *physical, const char *estr)
{
struct timeval timeout;
char *s, *str, ch;
@@ -376,7 +375,7 @@ WaitforString(const char *estr)
clear_log();
if (*estr == '!') {
ExpandString(estr + 1, buff, sizeof buff, 0);
- ExecStr(buff, buff, sizeof buff);
+ ExecStr(physical, buff, buff, sizeof buff);
} else {
ExpandString(estr, buff, sizeof buff, 0);
}
@@ -402,11 +401,12 @@ WaitforString(const char *estr)
str[IBSIZE - 1] = 0;
LogPrintf(LogCHAT, "Truncating String to %d character: %s\n", IBSIZE, str);
}
- nfds = modem + 1;
+ /* XXX-ML - this look REALLY fishy. */
+ nfds = Physical_GetFD(physical) + 1;
s = str;
for (;;) {
FD_ZERO(&rfds);
- FD_SET(modem, &rfds);
+ FD_SET(Physical_GetFD(physical), &rfds);
/*
* Because it is not clear whether select() modifies timeout value, it is
@@ -437,8 +437,8 @@ WaitforString(const char *estr)
#endif
return (NOMATCH);
}
- if (FD_ISSET(modem, &rfds)) { /* got something */
- if (DEV_IS_SYNC) {
+ if (Physical_FD_ISSET(physical, &rfds)) { /* got something */
+ if (Physical_IsSync(physical)) {
int length;
if ((length = strlen(inbuff)) > IBSIZE) {
@@ -446,7 +446,9 @@ WaitforString(const char *estr)
memcpy(inbuff, &(inbuff[IBSIZE]), IBSIZE + 1);
length = strlen(inbuff);
}
- nb = read(modem, &(inbuff[length]), IBSIZE);
+ if (length + IBSIZE > sizeof(inbuff))
+ abort(); /* Bug & security problem */
+ nb = Physical_Read(physical, &(inbuff[length]), IBSIZE);
inbuff[nb + length] = 0;
connect_log(inbuff, 0);
if (strstr(inbuff, str)) {
@@ -467,7 +469,7 @@ WaitforString(const char *estr)
}
}
} else {
- if (read(modem, &ch, 1) < 0) {
+ if (Physical_Read(physical, &ch, 1) < 0) {
LogPrintf(LogERROR, "read error: %s\n", strerror(errno));
*inp = '\0';
return (NOMATCH);
@@ -514,7 +516,7 @@ WaitforString(const char *estr)
}
static void
-SendString(const char *str)
+SendString(struct physical *physical, const char *str)
{
char *cp;
int on;
@@ -532,7 +534,7 @@ SendString(const char *str)
} else {
if (*str == '!') {
ExpandString(str + 1, buff + 2, sizeof buff - 2, 0);
- ExecStr(buff + 2, buff + 2, sizeof buff - 2);
+ ExecStr(physical, buff + 2, buff + 2, sizeof buff - 2);
} else {
ExpandString(str, buff + 2, sizeof buff - 2, 1);
}
@@ -545,17 +547,18 @@ SendString(const char *str)
LogPrintf(LogCHAT, "Sending: %.*s\n", cp - buff - 1, buff + 2);
}
cp = buff;
- if (DEV_IS_SYNC)
+ if (Physical_IsSync(physical))
memcpy(buff, "\377\003", 2); /* Prepend HDLC header */
else
cp += 2;
on = strlen(cp);
- write(modem, cp, on);
+ /* XXX - missing return value check */
+ Physical_Write(physical, cp, on);
}
}
static int
-ExpectString(char *str)
+ExpectString(struct physical *physical, char *str)
{
char *minus;
int state;
@@ -581,7 +584,7 @@ ExpectString(char *str)
}
if (*minus == '-') { /* We have sub-send-expect. */
*minus = '\0'; /* XXX: Cheat with the const string */
- state = WaitforString(str);
+ state = WaitforString(physical, str);
*minus = '-'; /* XXX: Cheat with the const string */
minus++;
if (state != NOMATCH)
@@ -599,18 +602,18 @@ ExpectString(char *str)
}
if (*minus == '-') {
*minus = '\0'; /* XXX: Cheat with the const string */
- SendString(str);
+ SendString(physical, str);
*minus = '-'; /* XXX: Cheat with the const string */
str = ++minus;
} else {
- SendString(str);
+ SendString(physical, str);
return (MATCH);
}
} else {
/*
* Simple case. Wait for string.
*/
- return (WaitforString(str));
+ return (WaitforString(physical, str));
}
}
return (MATCH);
@@ -626,7 +629,7 @@ StopDial(int sig)
}
int
-DoChat(char *script)
+DoChat(struct physical *physical, char *script)
{
char *vector[MAXARGS];
char *const *argv;
@@ -658,14 +661,14 @@ DoChat(char *script)
while (*argv) {
if (strcmp(*argv, "P_ZERO") == 0 ||
strcmp(*argv, "P_ODD") == 0 || strcmp(*argv, "P_EVEN") == 0) {
- ChangeParity(*argv++);
+ ChangeParity(physical, *argv++);
continue;
}
- state = ExpectString(*argv++);
+ state = ExpectString(physical, *argv++);
switch (state) {
case MATCH:
if (*argv)
- SendString(*argv++);
+ SendString(physical, *argv++);
break;
case ABORT:
case NOMATCH:
diff --git a/usr.sbin/ppp/chat.h b/usr.sbin/ppp/chat.h
index 53f67fa4e254..c1beec2d158e 100644
--- a/usr.sbin/ppp/chat.h
+++ b/usr.sbin/ppp/chat.h
@@ -18,7 +18,7 @@
* Columbus, OH 43221
* (614)451-1883
*
- * $Id: chat.h,v 1.8 1997/10/26 01:02:23 brian Exp $
+ * $Id: chat.h,v 1.9 1997/11/22 03:37:27 brian Exp $
*
*/
@@ -26,4 +26,4 @@
extern char *ExpandString(const char *, char *, int, int);
extern int MakeArgs(char *, char **, int); /* Mangles the first arg ! */
-extern int DoChat(char *); /* passes arg to MakeArgs() */
+extern int DoChat(struct physical *, char *); /* passes arg to MakeArgs() */
diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c
index 622abf704415..b91904a22d28 100644
--- a/usr.sbin/ppp/command.c
+++ b/usr.sbin/ppp/command.c
@@ -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.130 1998/01/23 04:36:42 brian Exp $
+ * $Id: command.c,v 1.131 1998/01/27 23:14:49 brian Exp $
*
*/
#include <sys/param.h>
@@ -73,6 +73,7 @@
#include "ip.h"
#include "slcompress.h"
#include "auth.h"
+#include "physical.h"
struct in_addr ifnetmask;
static const char *HIDDEN = "********";
@@ -191,13 +192,13 @@ DialCommand(struct cmdargs const *arg)
}
if (VarTerm)
fprintf(VarTerm, "Dial attempt %u of %d\n", ++tries, VarDialTries);
- if (OpenModem() < 0) {
+ if (OpenModem(pppVars.physical) < 0) {
if (VarTerm)
fprintf(VarTerm, "Failed to open modem.\n");
break;
}
- if ((res = DialModem()) == EX_DONE) {
- ModemTimeout(NULL);
+ if ((res = DialModem(pppVars.physical)) == EX_DONE) {
+ ModemTimeout(pppVars.physical);
PacketMode(VarOpenMode);
break;
} else if (res == EX_SIG)
@@ -840,7 +841,7 @@ TerminalCommand(struct cmdargs const *arg)
}
if (!IsInteractive(1))
return (1);
- if (OpenModem() < 0) {
+ if (OpenModem(pppVars.physical) < 0) {
if (VarTerm)
fprintf(VarTerm, "Failed to open modem.\n");
return (1);
@@ -871,7 +872,7 @@ static int
CloseCommand(struct cmdargs const *arg)
{
reconnect(RECON_FALSE);
- LcpClose();
+ LcpClose(&LcpFsm);
return 0;
}
@@ -885,19 +886,29 @@ DownCommand(struct cmdargs const *arg)
static int
SetModemSpeed(struct cmdargs const *arg)
{
- int speed;
+ long speed;
+ char *end;
- if (arg->argc > 0) {
+ if (arg->argc > 0 && **arg->argv) {
+ if (arg->argc > 1) {
+ LogPrintf(LogWARN, "SetModemSpeed: Too many arguments");
+ return -1;
+ }
if (strcasecmp(*arg->argv, "sync") == 0) {
- VarSpeed = 0;
- return 0;
- }
- speed = atoi(*arg->argv);
- if (IntToSpeed(speed) != B0) {
- VarSpeed = speed;
+ Physical_SetSync(pppVars.physical);
return 0;
}
+ end = NULL;
+ speed = strtol(*arg->argv, &end, 10);
+ if (*end) {
+ LogPrintf(LogWARN, "SetModemSpeed: Bad argument \"%s\"", *arg->argv);
+ return -1;
+ }
+ if (Physical_SetSpeed(pppVars.physical, speed))
+ return 0;
LogPrintf(LogWARN, "%s: Invalid speed\n", *arg->argv);
+ } else {
+ LogPrintf(LogWARN, "SetModemSpeed: No speed specified\n");
}
return -1;
}
@@ -1075,7 +1086,7 @@ SetServer(struct cmdargs const *arg)
static int
SetModemParity(struct cmdargs const *arg)
{
- return arg->argc > 0 ? ChangeParity(*arg->argv) : -1;
+ return arg->argc > 0 ? ChangeParity(pppVars.physical, *arg->argv) : -1;
}
static int
@@ -1352,13 +1363,13 @@ SetVariable(struct cmdargs const *arg)
break;
case VAR_DEVICE:
if (mode & MODE_INTER)
- HangupModem(0);
- if (modem != -1)
- LogPrintf(LogWARN, "Cannot change device to \"%s\" when \"%s\" is open\n",
- argp, VarDevice);
+ HangupModem(pppVars.physical, 0);
+ if (Physical_IsActive(pppVars.physical))
+ LogPrintf(LogWARN,
+ "Cannot change device to \"%s\" when \"%s\" is open\n",
+ argp, Physical_GetDevice(pppVars.physical));
else {
- strncpy(VarDeviceList, argp, sizeof VarDeviceList - 1);
- VarDeviceList[sizeof VarDeviceList - 1] = '\0';
+ Physical_SetDevice(pppVars.physical, argp);
}
break;
case VAR_ACCMAP:
@@ -1390,10 +1401,15 @@ static int
SetCtsRts(struct cmdargs const *arg)
{
if (arg->argc > 0) {
+ if (arg->argc > 1) {
+ LogPrintf(LogWARN, "SetCtsRts: Too many arguments\n");
+ return -1;
+ }
+
if (strcmp(*arg->argv, "on") == 0)
- VarCtsRts = 1;
+ Physical_SetRtsCts(pppVars.physical, 1);
else if (strcmp(*arg->argv, "off") == 0)
- VarCtsRts = 0;
+ Physical_SetRtsCts(pppVars.physical, 0);
else
return -1;
return 0;
diff --git a/usr.sbin/ppp/deflate.c b/usr.sbin/ppp/deflate.c
index 1897d3a05c82..817ad170c863 100644
--- a/usr.sbin/ppp/deflate.c
+++ b/usr.sbin/ppp/deflate.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: deflate.c,v 1.5 1997/12/28 02:17:06 brian Exp $
+ * $Id: deflate.c,v 1.6 1998/01/10 01:55:09 brian Exp $
*/
#include <sys/param.h>
@@ -72,7 +72,8 @@ DeflateResetOutput(void)
}
static int
-DeflateOutput(int pri, u_short proto, struct mbuf *mp)
+DeflateOutput(struct physical *physical, int pri, u_short proto,
+ struct mbuf *mp)
{
u_char *wp, *rp;
int olen, ilen, len, res, flush;
@@ -184,7 +185,7 @@ DeflateOutput(int pri, u_short proto, struct mbuf *mp)
LogPrintf(LogDEBUG, "DeflateOutput: %d => %d bytes, proto 0x%04x\n",
ilen, olen, proto);
- HdlcOutput(PRI_NORMAL, PROTO_COMPD, mo_head);
+ HdlcOutput(physical, PRI_NORMAL, PROTO_COMPD, mo_head);
return 1;
}
diff --git a/usr.sbin/ppp/defs.h b/usr.sbin/ppp/defs.h
index da6422944a2b..cfe1e1e40318 100644
--- a/usr.sbin/ppp/defs.h
+++ b/usr.sbin/ppp/defs.h
@@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: defs.h,v 1.28 1997/11/22 03:37:29 brian Exp $
+ * $Id: defs.h,v 1.29 1997/12/27 13:45:48 brian Exp $
*
* TODO:
*/
@@ -83,7 +83,6 @@
extern int mode;
extern int BGFiledes[2];
-extern int modem;
extern int tun_in;
extern int tun_out;
extern int netfd;
diff --git a/usr.sbin/ppp/fsm.c b/usr.sbin/ppp/fsm.c
index a3a50d2245cf..4cbc6ae338e6 100644
--- a/usr.sbin/ppp/fsm.c
+++ b/usr.sbin/ppp/fsm.c
@@ -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.26 1998/01/10 01:55:09 brian Exp $
+ * $Id: fsm.c,v 1.27 1998/01/20 22:47:36 brian Exp $
*
* TODO:
* o Refer loglevel for log output
@@ -44,6 +44,7 @@
#include "modem.h"
#include "loadalias.h"
#include "vars.h"
+#include "physical.h"
u_char AckBuff[200];
u_char NakBuff[200];
@@ -73,20 +74,21 @@ StoppedTimeout(void *v)
fp->name);
StopTimer(&fp->OpenTimer);
}
- if (modem != -1)
+ if (Physical_IsActive(fp->physical))
DownConnection();
else
FsmDown(fp);
}
void
-FsmInit(struct fsm * fp)
+FsmInit(struct fsm * fp, struct physical *physical)
{
LogPrintf(LogDEBUG, "FsmInit\n");
fp->state = ST_INITIAL;
fp->reqid = 1;
fp->restart = 1;
fp->maxconfig = 3;
+ fp->physical = physical;
}
static void
@@ -124,7 +126,7 @@ FsmOutput(struct fsm * fp, u_int code, u_int id, u_char * ptr, int count)
if (count)
memcpy(MBUF_CTOP(bp) + sizeof(struct fsmheader), ptr, count);
LogDumpBp(LogDEBUG, "FsmOutput", bp);
- HdlcOutput(PRI_LINK, fp->proto, bp);
+ HdlcOutput(fp->physical, PRI_LINK, fp->proto, bp);
}
static void
@@ -663,7 +665,7 @@ FsmRecvProtoRej(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
switch (proto) {
case PROTO_LQR:
- StopLqr(LQM_LQR);
+ StopLqr(fp->physical, LQM_LQR);
break;
case PROTO_CCP:
fp = &CcpFsm;
@@ -756,7 +758,7 @@ FsmRecvResetReq(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
* output queue.... dump 'em to the priority queue so that they arrive
* at the peer before our ResetAck.
*/
- SequenceQueues();
+ SequenceQueues(fp->physical);
LogPrintf(fp->LogLevel, "SendResetAck(%d)\n", lhp->id);
FsmOutput(fp, CODE_RESETACK, lhp->id, NULL, 0);
pfree(bp);
diff --git a/usr.sbin/ppp/fsm.h b/usr.sbin/ppp/fsm.h
index 131c90100eba..347b451079b3 100644
--- a/usr.sbin/ppp/fsm.h
+++ b/usr.sbin/ppp/fsm.h
@@ -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.15 1998/01/20 22:47:37 brian Exp $
+ * $Id: fsm.h,v 1.16 1998/01/21 02:15:15 brian Exp $
*
* TODO:
*/
@@ -70,6 +70,9 @@ struct fsm {
struct pppTimer StoppedTimer;
int LogLevel;
+ /* The physical layer active with this FSM. */
+ struct physical *physical;
+
void (*LayerUp) (struct fsm *);
void (*LayerDown) (struct fsm *);
void (*LayerStart) (struct fsm *);
@@ -123,7 +126,7 @@ extern u_char *rejp;
extern char const *StateNames[];
-extern void FsmInit(struct fsm *);
+extern void FsmInit(struct fsm *, struct physical *);
extern void FsmOutput(struct fsm *, u_int, u_int, u_char *, int);
extern void FsmOpen(struct fsm *);
extern void FsmUp(struct fsm *);
diff --git a/usr.sbin/ppp/hdlc.c b/usr.sbin/ppp/hdlc.c
index ca51a647ea2e..d05128535f6b 100644
--- a/usr.sbin/ppp/hdlc.c
+++ b/usr.sbin/ppp/hdlc.c
@@ -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.27 1998/01/10 01:55:10 brian Exp $
+ * $Id: hdlc.c,v 1.28 1998/01/21 02:15:15 brian Exp $
*
* TODO:
*/
@@ -48,6 +48,7 @@
#include "vars.h"
#include "modem.h"
#include "ccp.h"
+#include "physical.h"
static struct hdlcstat {
int badfcs;
@@ -157,7 +158,8 @@ HdlcFcsBuf(u_short fcs, struct mbuf *m)
}
void
-HdlcOutput(int pri, u_short proto, struct mbuf * bp)
+HdlcOutput(struct physical *physical,
+ int pri, u_short proto, struct mbuf * bp)
{
struct mbuf *mhp, *mfcs;
struct protostat *statp;
@@ -167,10 +169,10 @@ HdlcOutput(int pri, u_short proto, struct mbuf * bp)
if ((proto & 0xfff1) == 0x21) /* Network Layer protocol */
if (CcpFsm.state == ST_OPENED)
- if (CcpOutput(pri, proto, bp))
+ if (CcpOutput(physical, pri, proto, bp))
return;
- if (DEV_IS_SYNC)
+ if (Physical_IsSync(physical))
mfcs = NULL;
else
mfcs = mballoc(2, MB_HDLCOUT);
@@ -220,7 +222,7 @@ HdlcOutput(int pri, u_short proto, struct mbuf * bp)
LqrDump("LqrOutput", lqr);
LqrChangeOrder(lqr, (struct lqrdata *) (MBUF_CTOP(bp)));
}
- if (!DEV_IS_SYNC) {
+ if (!Physical_IsSync(physical)) {
mfcs->cnt = 0;
fcs = HdlcFcsBuf(INITFCS, mhp);
fcs = ~fcs;
@@ -237,10 +239,10 @@ HdlcOutput(int pri, u_short proto, struct mbuf * bp)
LogPrintf(LogDEBUG, "HdlcOutput: proto = 0x%04x\n", proto);
- if (DEV_IS_SYNC)
- ModemOutput(pri, mhp);
+ if (Physical_IsSync(physical))
+ ModemOutput(physical, pri, mhp);
else
- AsyncOutput(pri, mhp, proto);
+ AsyncOutput(pri, mhp, proto, physical);
}
/* Check out the latest ``Assigned numbers'' rfc (rfc1700.txt) */
@@ -370,7 +372,7 @@ Protocol2Nam(u_short proto)
}
static void
-DecodePacket(u_short proto, struct mbuf * bp)
+DecodePacket(u_short proto, struct mbuf * bp, struct physical *physical)
{
u_char *cp;
@@ -392,14 +394,14 @@ DecodePacket(u_short proto, struct mbuf * bp)
LcpInput(bp);
break;
case PROTO_PAP:
- PapInput(bp);
+ PapInput(bp, physical);
break;
case PROTO_LQR:
HisLqrSave.SaveInLQRs++;
- LqrInput(bp);
+ LqrInput(physical, bp);
break;
case PROTO_CHAP:
- ChapInput(bp);
+ ChapInput(bp, physical);
break;
case PROTO_VJUNCOMP:
case PROTO_VJCOMP:
@@ -485,14 +487,14 @@ HdlcErrorCheck()
}
void
-HdlcInput(struct mbuf * bp)
+HdlcInput(struct mbuf * bp, struct physical *physical)
{
u_short fcs, proto;
u_char *cp, addr, ctrl;
struct protostat *statp;
LogDumpBp(LogHDLC, "HdlcInput:", bp);
- if (DEV_IS_SYNC)
+ if (Physical_IsSync(physical))
fcs = GOODFCS;
else
fcs = HdlcFcs(INITFCS, MBUF_CTOP(bp), bp->cnt);
@@ -507,7 +509,7 @@ HdlcInput(struct mbuf * bp)
pfree(bp);
return;
}
- if (!DEV_IS_SYNC)
+ if (!Physical_IsSync(physical))
bp->cnt -= 2; /* discard FCS part */
if (bp->cnt < 2) { /* XXX: raise this bar ? */
@@ -572,5 +574,5 @@ HdlcInput(struct mbuf * bp)
statp->in_count++;
HisLqrSave.SaveInPackets++;
- DecodePacket(proto, bp);
+ DecodePacket(proto, bp, physical);
}
diff --git a/usr.sbin/ppp/hdlc.h b/usr.sbin/ppp/hdlc.h
index caf991fa4006..2bcace512556 100644
--- a/usr.sbin/ppp/hdlc.h
+++ b/usr.sbin/ppp/hdlc.h
@@ -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.13 1997/12/03 10:23:48 brian Exp $
+ * $Id: hdlc.h,v 1.14 1998/01/21 02:15:15 brian Exp $
*
* TODO:
*/
@@ -57,10 +57,12 @@
extern u_char EscMap[33];
+struct physical;
+
extern void HdlcInit(void);
extern void HdlcErrorCheck(void);
-extern void HdlcInput(struct mbuf *);
-extern void HdlcOutput(int, u_short, struct mbuf *bp);
+extern void HdlcInput(struct mbuf *, struct physical *);
+extern void HdlcOutput(struct physical *, int, u_short, struct mbuf *bp);
extern u_short HdlcFcs(u_short, u_char *, int);
extern int ReportHdlcStatus(struct cmdargs const *);
extern int ReportProtStatus(struct cmdargs const *);
diff --git a/usr.sbin/ppp/ip.c b/usr.sbin/ppp/ip.c
index ddd520bf0ab8..56d10dd4e072 100644
--- a/usr.sbin/ppp/ip.c
+++ b/usr.sbin/ppp/ip.c
@@ -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.37 1998/01/11 17:53:18 brian Exp $
+ * $Id: ip.c,v 1.38 1998/01/21 02:15:16 brian Exp $
*
* TODO:
* o Return ICMP message for filterd packet
@@ -71,7 +71,7 @@ IdleTimeout(void *v)
{
LogPrintf(LogPHASE, "Idle timer expired.\n");
reconnect(RECON_FALSE);
- LcpClose();
+ LcpClose(&LcpFsm);
}
/*
@@ -514,7 +514,7 @@ IsIpEnqueued()
#endif
void
-IpStartOutput()
+IpStartOutput(struct physical *physical)
{
struct mqueue *queue;
struct mbuf *bp;
@@ -527,7 +527,7 @@ IpStartOutput()
bp = Dequeue(queue);
if (bp) {
cnt = plength(bp);
- SendPppFrame(bp);
+ SendPppFrame(physical, bp);
RestartIdleTimer();
IpcpAddOutOctets(cnt);
break;
diff --git a/usr.sbin/ppp/ip.h b/usr.sbin/ppp/ip.h
index 2f3d992d839b..a2cdcb20f1cd 100644
--- a/usr.sbin/ppp/ip.h
+++ b/usr.sbin/ppp/ip.h
@@ -17,11 +17,13 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: ip.h,v 1.7 1997/10/26 12:42:11 brian Exp $
+ * $Id: ip.h,v 1.8 1997/12/29 22:23:11 brian Exp $
*
*/
-extern void IpStartOutput(void);
+struct physical;
+
+extern void IpStartOutput(struct physical *);
extern int PacketCheck(char *, int, int);
extern void IpEnqueue(int, char *, int);
extern void IpInput(struct mbuf *);
diff --git a/usr.sbin/ppp/ipcp.c b/usr.sbin/ppp/ipcp.c
index 72c8eb1b7229..4885308753f7 100644
--- a/usr.sbin/ppp/ipcp.c
+++ b/usr.sbin/ppp/ipcp.c
@@ -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.49 1998/01/20 22:47:38 brian Exp $
+ * $Id: ipcp.c,v 1.50 1998/01/21 02:15:17 brian Exp $
*
* TODO:
* o More RFC1772 backwoard compatibility
@@ -55,6 +55,7 @@
#include "throughput.h"
#include "route.h"
#include "filter.h"
+#include "physical.h"
#ifndef NOMSEXT
struct in_addr ns_entries[2];
@@ -91,6 +92,8 @@ struct fsm IpcpFsm = {
{0, 0, 0, NULL, NULL, NULL}, /* Stopped timer */
LogIPCP,
+ NULL,
+
IpcpLayerUp,
IpcpLayerDown,
IpcpLayerStart,
@@ -228,11 +231,11 @@ ShowInitVJ(struct cmdargs const *args)
}
void
-IpcpInit()
+IpcpInit(struct physical *physical)
{
if (iplist_isvalid(&DefHisChoice))
iplist_setrandpos(&DefHisChoice);
- FsmInit(&IpcpFsm);
+ FsmInit(&IpcpFsm, physical);
memset(&IpcpInfo, '\0', sizeof IpcpInfo);
if ((mode & MODE_DEDICATED) && !GetLabel()) {
IpcpInfo.want_ipaddr.s_addr = IpcpInfo.his_ipaddr.s_addr = 0;
@@ -275,7 +278,7 @@ IpcpSendConfigReq(struct fsm * fp)
cp = ReqBuff;
LogPrintf(LogIPCP, "IpcpSendConfigReq\n");
- if (!DEV_IS_SYNC || !REJECTED(&IpcpInfo, TY_IPADDR)) {
+ if (!Physical_IsSync(fp->physical) || !REJECTED(&IpcpInfo, TY_IPADDR)) {
o.id = TY_IPADDR;
o.len = 6;
*(u_long *)o.data = IpcpInfo.want_ipaddr.s_addr;
@@ -324,8 +327,8 @@ IpcpLayerFinish(struct fsm * fp)
{
LogPrintf(LogIPCP, "IpcpLayerFinish.\n");
reconnect(RECON_FALSE);
- LcpClose();
- NewPhase(PHASE_TERMINATE);
+ LcpClose(&LcpFsm);
+ NewPhase(fp->physical, PHASE_TERMINATE);
}
static void
diff --git a/usr.sbin/ppp/ipcp.h b/usr.sbin/ppp/ipcp.h
index 5570f67695c0..7b55f022a20c 100644
--- a/usr.sbin/ppp/ipcp.h
+++ b/usr.sbin/ppp/ipcp.h
@@ -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.17 1998/01/11 17:50:33 brian Exp $
+ * $Id: ipcp.h,v 1.18 1998/01/18 20:49:19 brian Exp $
*
* TODO:
*/
@@ -70,7 +70,7 @@ extern struct in_addr TriggerAddress;
extern int HaveTriggerAddress;
extern struct fsm IpcpFsm;
-extern void IpcpInit(void);
+extern void IpcpInit(struct physical *physical);
extern void IpcpDefAddress(void);
extern void IpcpUp(void);
extern void IpcpOpen(void);
diff --git a/usr.sbin/ppp/lcp.c b/usr.sbin/ppp/lcp.c
index 815d00b0b9e4..5cd2d1130629 100644
--- a/usr.sbin/ppp/lcp.c
+++ b/usr.sbin/ppp/lcp.c
@@ -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.54 1998/01/20 22:47:40 brian Exp $
+ * $Id: lcp.c,v 1.55 1998/01/21 02:15:18 brian Exp $
*
* TODO:
* o Validate magic number received from peer.
@@ -64,6 +64,7 @@
#include "ip.h"
#include "modem.h"
#include "tun.h"
+#include "physical.h"
/* for received LQRs */
struct lqrreq {
@@ -127,6 +128,8 @@ struct fsm LcpFsm = {
{0, 0, 0, NULL, NULL, NULL}, /* Stopped timer */
LogLCP,
+ NULL,
+
LcpLayerUp,
LcpLayerDown,
LcpLayerStart,
@@ -197,11 +200,11 @@ GenerateMagic(void)
}
void
-LcpInit()
+LcpInit(struct physical *physical)
{
struct lcpstate *lcp = &LcpInfo;
- FsmInit(&LcpFsm);
+ FsmInit(&LcpFsm, physical);
HdlcInit();
memset(lcp, '\0', sizeof(struct lcpstate));
@@ -318,7 +321,7 @@ LcpSendConfigReq(struct fsm * fp)
LogPrintf(LogLCP, "LcpSendConfigReq\n");
cp = ReqBuff;
- if (!DEV_IS_SYNC) {
+ if (!Physical_IsSync(fp->physical)) {
if (lcp->want_acfcomp && !REJECTED(lcp, TY_ACFCOMP))
PUTN(TY_ACFCOMP);
@@ -381,7 +384,7 @@ static void
LcpLayerStart(struct fsm * fp)
{
LogPrintf(LogLCP, "LcpLayerStart\n");
- NewPhase(PHASE_ESTABLISH);
+ NewPhase(fp->physical, PHASE_ESTABLISH);
}
static void
@@ -398,13 +401,13 @@ static void
LcpLayerFinish(struct fsm * fp)
{
LogPrintf(LogLCP, "LcpLayerFinish\n");
- HangupModem(0);
+ HangupModem(fp->physical, 0);
StopAllTimers();
/* We're down at last. Lets tell background and direct mode to get out */
- NewPhase(PHASE_DEAD);
- LcpInit();
- IpcpInit();
- CcpInit();
+ NewPhase(fp->physical, PHASE_DEAD);
+ LcpInit(fp->physical);
+ IpcpInit(fp->physical);
+ CcpInit(fp->physical);
Prompt();
}
@@ -412,12 +415,12 @@ static void
LcpLayerUp(struct fsm * fp)
{
LogPrintf(LogLCP, "LcpLayerUp\n");
- tun_configure(LcpInfo.his_mru, ModemSpeed());
+ tun_configure(LcpInfo.his_mru, ModemSpeed(fp->physical));
SetLinkParams(&LcpInfo);
- NewPhase(PHASE_AUTHENTICATE);
+ NewPhase(fp->physical, PHASE_AUTHENTICATE);
- StartLqm();
+ StartLqm(fp->physical);
StopTimer(&LcpReportTimer);
LcpReportTimer.state = TIMER_STOPPED;
LcpReportTimer.load = 60 * SECTICKS;
@@ -462,11 +465,11 @@ LcpOpen(int open_mode)
}
void
-LcpClose()
+LcpClose(struct fsm *fp)
{
- NewPhase(PHASE_TERMINATE);
+ NewPhase(fp->physical, PHASE_TERMINATE);
OsInterfaceDown(0);
- FsmClose(&LcpFsm);
+ FsmClose(fp);
LcpFailedMagic = 0;
}
diff --git a/usr.sbin/ppp/lcp.h b/usr.sbin/ppp/lcp.h
index 5c594f8a6e28..e9cda02831ca 100644
--- a/usr.sbin/ppp/lcp.h
+++ b/usr.sbin/ppp/lcp.h
@@ -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.15 1997/12/04 18:49:28 brian Exp $
+ * $Id: lcp.h,v 1.16 1998/01/11 17:50:38 brian Exp $
*
* TODO:
*/
@@ -66,15 +66,16 @@ struct lcp_opt {
u_char data[MAX_LCP_OPT_LEN-2];
};
+struct physical;
extern struct lcpstate LcpInfo;
extern struct fsm LcpFsm;
-extern void LcpInit(void);
+extern void LcpInit(struct physical *);
extern void LcpUp(void);
extern void LcpSendProtoRej(u_char *, int);
extern void LcpOpen(int);
-extern void LcpClose(void);
+extern void LcpClose(struct fsm *);
extern void LcpDown(void);
extern int LcpPutConf(int, u_char *, const struct lcp_opt *, const char *,
const char *, ...);
diff --git a/usr.sbin/ppp/lqr.c b/usr.sbin/ppp/lqr.c
index 2820f105483e..4c4390823cef 100644
--- a/usr.sbin/ppp/lqr.c
+++ b/usr.sbin/ppp/lqr.c
@@ -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.21 1998/01/11 17:50:40 brian Exp $
+ * $Id: lqr.c,v 1.22 1998/01/21 02:15:19 brian Exp $
*
* o LQR based on RFC1333
*
@@ -112,6 +112,7 @@ static void
SendLqrReport(void *v)
{
struct mbuf *bp;
+ struct physical *physical = v;
StopTimer(&LqrTimer);
@@ -124,10 +125,10 @@ SendLqrReport(void *v)
LogPrintf(LogPHASE, "** 1 Too many ECHO packets are lost. **\n");
lqmmethod = 0; /* Prevent rcursion via LcpClose() */
reconnect(RECON_TRUE);
- LcpClose();
+ LcpClose(&LcpFsm);
} else {
bp = mballoc(sizeof(struct lqrdata), MB_LQR);
- HdlcOutput(PRI_LINK, PROTO_LQR, bp);
+ HdlcOutput(physical, PRI_LINK, PROTO_LQR, bp);
lqrsendcnt++;
}
} else if (lqmmethod & LQM_ECHO) {
@@ -135,7 +136,7 @@ SendLqrReport(void *v)
LogPrintf(LogPHASE, "** 2 Too many ECHO packets are lost. **\n");
lqmmethod = 0; /* Prevent rcursion via LcpClose() */
reconnect(RECON_TRUE);
- LcpClose();
+ LcpClose(&LcpFsm);
} else
SendEchoReq();
}
@@ -144,7 +145,7 @@ SendLqrReport(void *v)
}
void
-LqrInput(struct mbuf * bp)
+LqrInput(struct physical *physical, struct mbuf * bp)
{
int len;
u_char *cp;
@@ -184,7 +185,7 @@ LqrInput(struct mbuf * bp)
*/
if (LqrTimer.load == 0 || lastpeerin == HisLqrData.PeerInLQRs) {
lqmmethod |= LQM_LQR;
- SendLqrReport(0);
+ SendLqrReport(physical);
}
lastpeerin = HisLqrData.PeerInLQRs;
}
@@ -195,7 +196,7 @@ LqrInput(struct mbuf * bp)
* When LCP is reached to opened state, We'll start LQM activity.
*/
void
-StartLqm()
+StartLqm(struct physical *physical)
{
struct lcpstate *lcp = &LcpInfo;
int period;
@@ -220,7 +221,8 @@ StartLqm()
LqrTimer.state = TIMER_STOPPED;
LqrTimer.load = period * SECTICKS / 100;
LqrTimer.func = SendLqrReport;
- SendLqrReport(0);
+ LqrTimer.arg = physical;
+ SendLqrReport(physical);
StartTimer(&LqrTimer);
LogPrintf(LogLQM, "Will send LQR every %d.%d secs\n",
period / 100, period % 100);
@@ -236,7 +238,7 @@ StopLqrTimer()
}
void
-StopLqr(int method)
+StopLqr(struct physical *physical, int method)
{
LogPrintf(LogLQM, "StopLqr method = %x\n", method);
@@ -246,7 +248,7 @@ StopLqr(int method)
LogPrintf(LogLQM, "Stop sending LCP ECHO.\n");
lqmmethod &= ~method;
if (lqmmethod)
- SendLqrReport(0);
+ SendLqrReport(physical);
else
StopTimer(&LqrTimer);
}
diff --git a/usr.sbin/ppp/lqr.h b/usr.sbin/ppp/lqr.h
index fe85d3e6929f..93f89ebebaa9 100644
--- a/usr.sbin/ppp/lqr.h
+++ b/usr.sbin/ppp/lqr.h
@@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: lqr.h,v 1.11 1998/01/11 17:50:42 brian Exp $
+ * $Id: lqr.h,v 1.12 1998/01/21 02:15:20 brian Exp $
*
* TODO:
*/
@@ -57,8 +57,8 @@ extern struct lqrsave HisLqrSave;
extern void LqrDump(const char *, const struct lqrdata *);
extern void LqrChangeOrder(struct lqrdata *, struct lqrdata *);
-extern void StartLqm(void);
-extern void StopLqr(int);
+extern void StartLqm(struct physical *);
+extern void StopLqr(struct physical *, int);
extern void StopLqrTimer(void);
extern void RecvEchoLqr(struct mbuf *);
-extern void LqrInput(struct mbuf *);
+extern void LqrInput(struct physical *, struct mbuf *);
diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c
index 6418acabb216..488d13161ed0 100644
--- a/usr.sbin/ppp/main.c
+++ b/usr.sbin/ppp/main.c
@@ -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.120 1998/01/27 23:14:51 brian Exp $
+ * $Id: main.c,v 1.121 1998/01/29 00:42:05 brian Exp $
*
* TODO:
* o Add commands for traffic summary, version display, etc.
@@ -73,6 +73,7 @@
#include "pathnames.h"
#include "tun.h"
#include "route.h"
+#include "physical.h"
#ifndef O_NONBLOCK
#ifdef O_NDELAY
@@ -180,7 +181,8 @@ Cleanup(int excode)
DropClient(1);
ServerClose();
OsInterfaceDown(1);
- HangupModem(1);
+ HangupModem(pppVars.physical, 1); /* XXX must be expanded to
+ take all modems */
nointr_sleep(1);
DeleteIfRoutes(1);
ID0unlink(pid_filename);
@@ -222,7 +224,7 @@ CloseSession(int signo)
}
LogPrintf(LogPHASE, "Signal %d, terminate.\n", signo);
reconnect(RECON_FALSE);
- LcpClose();
+ LcpClose(&LcpFsm);
Cleanup(EX_TERM);
}
@@ -564,15 +566,15 @@ main(int argc, char **argv)
void
PacketMode(int delay)
{
- if (RawModem() < 0) {
+ if (RawModem(pppVars.physical) < 0) {
LogPrintf(LogWARN, "PacketMode: Not connected.\n");
return;
}
AsyncInit();
VjInit(15);
- LcpInit();
- IpcpInit();
- CcpInit();
+ LcpInit(pppVars.physical);
+ IpcpInit(pppVars.physical);
+ CcpInit(pppVars.physical);
LcpUp();
LcpOpen(delay);
@@ -637,7 +639,8 @@ ReadTty(void)
if (ch == '~')
ttystate++;
else
- write(modem, &ch, n);
+ /* XXX missing return value check */
+ Physical_Write(pppVars.physical, &ch, n);
break;
case 1:
switch (ch) {
@@ -668,7 +671,7 @@ ReadTty(void)
break;
}
default:
- if (write(modem, &ch, n) < 0)
+ if (Physical_Write(pppVars.physical, &ch, n) < 0)
LogPrintf(LogERROR, "error writing to modem.\n");
break;
}
@@ -693,7 +696,7 @@ static const char *FrameHeaders[] = {
};
static const u_char *
-HdlcDetect(u_char * cp, int n)
+HdlcDetect(struct physical *physical, u_char * cp, int n)
{
const char *ptr, *fp, **hp;
@@ -701,7 +704,7 @@ HdlcDetect(u_char * cp, int n)
ptr = NULL;
for (hp = FrameHeaders; *hp; hp++) {
fp = *hp;
- if (DEV_IS_SYNC)
+ if (Physical_IsSync(physical))
fp++;
ptr = strstr((char *) cp, fp);
if (ptr)
@@ -763,13 +766,13 @@ DoLoop(void)
if (mode & MODE_DIRECT) {
LogPrintf(LogDEBUG, "Opening modem\n");
- if (OpenModem() < 0)
+ if (OpenModem(pppVars.physical) < 0)
return;
LogPrintf(LogPHASE, "Packet mode enabled\n");
PacketMode(VarOpenMode);
} else if (mode & MODE_DEDICATED) {
- if (modem < 0)
- while (OpenModem() < 0)
+ if (!Physical_IsActive(pppVars.physical))
+ while (OpenModem(pppVars.physical) < 0)
nointr_sleep(VarReconnectTimer);
}
fflush(VarTerm);
@@ -823,8 +826,9 @@ DoLoop(void)
* If Ip packet for output is enqueued and require dial up, Just do it!
*/
if (dial_up && RedialTimer.state != TIMER_RUNNING) {
- LogPrintf(LogDEBUG, "going to dial: modem = %d\n", modem);
- if (OpenModem() < 0) {
+ LogPrintf(LogDEBUG, "going to dial: modem = %d\n",
+ Physical_GetFD(pppVars.physical));
+ if (OpenModem(pppVars.physical) < 0) {
tries++;
if (!(mode & MODE_DDIAL) && VarDialTries)
LogPrintf(LogCHAT, "Failed to open modem (attempt %u of %d)\n",
@@ -849,8 +853,8 @@ DoLoop(void)
else
LogPrintf(LogCHAT, "Dial attempt %u\n", tries);
- if ((res = DialModem()) == EX_DONE) {
- ModemTimeout(NULL);
+ if ((res = DialModem(pppVars.physical)) == EX_DONE) {
+ ModemTimeout(pppVars.physical);
PacketMode(VarOpenMode);
dial_up = 0;
reconnectState = RECON_UNKNOWN;
@@ -879,19 +883,20 @@ DoLoop(void)
}
}
}
- qlen = ModemQlen();
+ qlen = ModemQlen(pppVars.physical);
if (qlen == 0) {
- IpStartOutput();
- qlen = ModemQlen();
+ IpStartOutput(pppVars.physical);
+ qlen = ModemQlen(pppVars.physical);
}
- if (modem >= 0) {
- if (modem + 1 > nfds)
- nfds = modem + 1;
- FD_SET(modem, &rfds);
- FD_SET(modem, &efds);
+ if (Physical_IsActive(pppVars.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 (qlen > 0) {
- FD_SET(modem, &wfds);
+ Physical_FD_SET(pppVars.physical, &wfds);
}
}
if (server >= 0) {
@@ -957,7 +962,8 @@ DoLoop(void)
LogPrintf(LogERROR, "DoLoop: select(): %s\n", strerror(errno));
break;
}
- if ((netfd >= 0 && FD_ISSET(netfd, &efds)) || (modem >= 0 && FD_ISSET(modem, &efds))) {
+ if ((netfd >= 0 && FD_ISSET(netfd, &efds)) ||
+ (Physical_FD_ISSET(pppVars.physical, &efds))) {
LogPrintf(LogALERT, "Exception detected.\n");
break;
}
@@ -1001,17 +1007,17 @@ DoLoop(void)
if (netfd >= 0 && FD_ISSET(netfd, &rfds))
/* something to read from tty */
ReadTty();
- if (modem >= 0 && FD_ISSET(modem, &wfds)) {
+ if (Physical_FD_ISSET(pppVars.physical, &wfds)) {
/* ready to write into modem */
- ModemStartOutput(modem);
- if (modem < 0)
+ ModemStartOutput(pppVars.physical);
+ if (!Physical_IsActive(pppVars.physical))
dial_up = 1;
}
- if (modem >= 0 && FD_ISSET(modem, &rfds)) {
+ if (Physical_FD_ISSET(pppVars.physical, &rfds)) {
/* something to read from modem */
if (LcpFsm.state <= ST_CLOSED)
nointr_usleep(10000);
- n = read(modem, rbuff, sizeof rbuff);
+ n = Physical_Read(pppVars.physical, rbuff, sizeof rbuff);
if ((mode & MODE_DIRECT) && n <= 0) {
DownConnection();
} else
@@ -1022,14 +1028,15 @@ DoLoop(void)
* In dedicated mode, we just discard input until LCP is started.
*/
if (!(mode & MODE_DEDICATED)) {
- cp = HdlcDetect(rbuff, n);
+ cp = HdlcDetect(pppVars.physical, rbuff, n);
if (cp) {
/*
* LCP packet is detected. Turn ourselves into packet mode.
*/
if (cp != rbuff) {
- write(modem, rbuff, cp - rbuff);
- write(modem, "\r\n", 2);
+ /* XXX missing return value checks */
+ Physical_Write(pppVars.physical, rbuff, cp - rbuff);
+ Physical_Write(pppVars.physical, "\r\n", 2);
}
PacketMode(0);
} else
@@ -1037,7 +1044,7 @@ DoLoop(void)
}
} else {
if (n > 0)
- AsyncInput(rbuff, n);
+ AsyncInput(rbuff, n, pppVars.physical);
}
}
if (tun_in >= 0 && FD_ISSET(tun_in, &rfds)) { /* something to read
diff --git a/usr.sbin/ppp/modem.c b/usr.sbin/ppp/modem.c
index 2412755aa18c..9e20d712d6f0 100644
--- a/usr.sbin/ppp/modem.c
+++ b/usr.sbin/ppp/modem.c
@@ -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.76 1998/01/21 02:15:22 brian Exp $
+ * $Id: modem.c,v 1.77 1998/01/29 00:42:05 brian Exp $
*
* TODO:
*/
@@ -27,6 +27,7 @@
#include <arpa/inet.h>
#include <netdb.h>
+#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <paths.h>
@@ -37,6 +38,11 @@
#include <sys/tty.h>
#include <unistd.h>
#include <utmp.h>
+#ifdef __OpenBSD__
+#include <util.h>
+#else
+#include <libutil.h>
+#endif
#include "command.h"
#include "mbuf.h"
@@ -54,11 +60,14 @@
#include "main.h"
#include "chat.h"
#include "throughput.h"
-#ifdef __OpenBSD__
-#include <util.h>
-#else
-#include <libutil.h>
-#endif
+
+#undef mode
+
+/* We're defining a physical device, and thus need the real
+ headers. */
+#define PHYSICAL_DEVICE
+#include "physical.h"
+
#ifndef O_NONBLOCK
#ifdef O_NDELAY
@@ -66,18 +75,15 @@
#endif
#endif
-static int mbits; /* Current DCD status */
-static int connect_count;
-static struct pppTimer ModemTimer;
-
-#define Online (mbits & TIOCM_CD)
+struct physical phys_modem = {
+ -1
+};
-static struct mbuf *modemout;
-static struct mqueue OutputQueues[PRI_LINK + 1];
-static int dev_is_modem;
-static struct pppThroughput throughput;
+/* XXX-ML this should probably change when we add support for other
+ types of devices */
+#define Online (modem->mbits & TIOCM_CD)
-static void CloseLogicalModem(void);
+static void CloseLogicalModem(struct physical *);
void
Enqueue(struct mqueue * queue, struct mbuf * bp)
@@ -111,11 +117,11 @@ Dequeue(struct mqueue *queue)
}
void
-SequenceQueues()
+SequenceQueues(struct physical *phys)
{
LogPrintf(LogDEBUG, "SequenceQueues\n");
- while (OutputQueues[PRI_NORMAL].qlen)
- Enqueue(OutputQueues + PRI_LINK, Dequeue(OutputQueues + PRI_NORMAL));
+ while (phys->OutputQueues[PRI_NORMAL].qlen)
+ Enqueue(&phys->OutputQueues[PRI_LINK], Dequeue(&phys->OutputQueues[PRI_NORMAL]));
}
static struct speeds {
@@ -240,31 +246,37 @@ DownConnection()
void
ModemTimeout(void *data)
{
- int ombits = mbits;
+ struct physical *modem = data;
+ int ombits = modem->mbits;
int change;
- StopTimer(&ModemTimer);
- StartTimer(&ModemTimer);
+ StopTimer(&modem->DeviceTimer);
+ StartTimer(&modem->DeviceTimer);
- if (dev_is_modem) {
- if (modem >= 0) {
- if (ioctl(modem, TIOCMGET, &mbits) < 0) {
+ if (modem->dev_is_modem) {
+ if (modem->fd >= 0) {
+ if (ioctl(modem->fd, TIOCMGET, &modem->mbits) < 0) {
LogPrintf(LogPHASE, "ioctl error (%s)!\n", strerror(errno));
DownConnection();
return;
}
} else
- mbits = 0;
- change = ombits ^ mbits;
+ modem->mbits = 0;
+ change = ombits ^ modem->mbits;
if (change & TIOCM_CD) {
- if (Online) {
+ if (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);
+#else
if (mode & MODE_DEDICATED)
PacketMode(VarOpenMode);
+#endif
} else {
LogPrintf(LogDEBUG, "ModemTimeout: online -> offline\n");
reconnect(RECON_TRUE);
@@ -276,19 +288,24 @@ ModemTimeout(void *data)
Online ? "on" : "off");
} else if (!Online) {
/* mbits was set to zero in OpenModem() */
- mbits = TIOCM_CD;
+ modem->mbits = TIOCM_CD;
}
}
static void
-StartModemTimer(void)
+StartModemTimer(struct physical *modem)
{
- StopTimer(&ModemTimer);
- ModemTimer.state = TIMER_STOPPED;
- ModemTimer.load = SECTICKS;
- ModemTimer.func = ModemTimeout;
+ struct pppTimer *ModemTimer;
+
+ ModemTimer = &modem->DeviceTimer;
+
+ StopTimer(ModemTimer);
+ ModemTimer->state = TIMER_STOPPED;
+ ModemTimer->load = SECTICKS;
+ ModemTimer->func = ModemTimeout;
+ ModemTimer->arg = modem;
LogPrintf(LogDEBUG, "ModemTimer using ModemTimeout() - %p\n", ModemTimeout);
- StartTimer(&ModemTimer);
+ StartTimer(ModemTimer);
}
static struct parity {
@@ -310,25 +327,25 @@ GetParityValue(const char *str)
for (pp = validparity; pp->name; pp++) {
if (strcasecmp(pp->name, str) == 0 ||
strcasecmp(pp->name1, str) == 0) {
- return VarParity = pp->set;
+ return pp->set;
}
}
return (-1);
}
int
-ChangeParity(const char *str)
+ChangeParity(struct physical *modem, const char *str)
{
struct termios rstio;
int val;
val = GetParityValue(str);
if (val > 0) {
- VarParity = val;
- tcgetattr(modem, &rstio);
+ modem->parity = val;
+ tcgetattr(modem->fd, &rstio);
rstio.c_cflag &= ~(CSIZE | PARODD | PARENB);
rstio.c_cflag |= val;
- tcsetattr(modem, TCSADRAIN, &rstio);
+ tcsetattr(modem->fd, TCSADRAIN, &rstio);
return 0;
}
LogPrintf(LogWARN, "ChangeParity: %s: Invalid parity\n", str);
@@ -378,18 +395,23 @@ OpenConnection(char *host, char *port)
return (sock);
}
-static char fn[MAXPATHLEN];
-
static int
-LockModem(void)
+LockModem(struct physical *modem)
{
int res;
FILE *lockfile;
+ char fn[MAXPATHLEN];
if (*VarDevice != '/')
return 0;
- if (!(mode & MODE_DIRECT) && (res = ID0uu_lock(VarBaseDevice)) != UU_LOCK_OK) {
+ if (
+#ifdef notyet
+ !modem->is_direct &&
+#else
+ !(mode & MODE_DIRECT) &&
+#endif
+ (res = ID0uu_lock(VarBaseDevice)) != UU_LOCK_OK) {
if (res == UU_LOCK_INUSE)
LogPrintf(LogPHASE, "Modem %s is in use\n", VarDevice);
else
@@ -413,8 +435,10 @@ LockModem(void)
}
static void
-UnlockModem(void)
+UnlockModem(struct physical *modem)
{
+ char fn[MAXPATHLEN];
+
if (*VarDevice != '/')
return;
@@ -426,22 +450,26 @@ UnlockModem(void)
ID0unlink(fn);
#endif
- if (!(mode & MODE_DIRECT) && ID0uu_unlock(VarBaseDevice) == -1)
+ if (
+#ifdef notyet
+ !modem->is_direct &&
+#else
+ !(mode & MODE_DIRECT) &&
+#endif
+ ID0uu_unlock(VarBaseDevice) == -1)
LogPrintf(LogALERT, "Warning: Can't uu_unlock %s\n", fn);
}
static void
-HaveModem(void)
+HaveModem(struct physical *modem)
{
- throughput_start(&throughput);
- connect_count++;
+ throughput_start(&modem->throughput);
+ modem->connect_count++;
LogPrintf(LogPHASE, "Connected!\n");
}
-static struct termios modemios;
-
int
-OpenModem()
+OpenModem(struct physical *modem)
{
struct termios rstio;
int oldflag;
@@ -450,10 +478,16 @@ OpenModem()
char tmpDeviceList[sizeof VarDeviceList];
char *tmpDevice;
- if (modem >= 0)
+ if (modem->fd >= 0)
LogPrintf(LogDEBUG, "OpenModem: Modem is already open!\n");
/* We're going back into "term" mode */
- else if (mode & MODE_DIRECT) {
+ else if (
+#ifdef notyet
+ modem->is_direct
+#else
+ mode & MODE_DIRECT
+#endif
+ ) {
struct cmdargs arg;
arg.cmd = NULL;
arg.data = (const void *)VAR_DEVICE;
@@ -463,26 +497,26 @@ OpenModem()
arg.argc = 1;
arg.argv = (char const *const *)&cp;
SetVariable(&arg);
- if (LockModem() == -1) {
+ if (LockModem(modem) == -1) {
close(STDIN_FILENO);
return -1;
}
modem = STDIN_FILENO;
- HaveModem();
+ HaveModem(modem);
} else {
LogPrintf(LogDEBUG, "OpenModem(direct): Modem is not a tty\n");
arg.argc = 0;
arg.argv = NULL;
SetVariable(&arg);
/* We don't call ModemTimeout() with this type of connection */
- HaveModem();
- return modem = STDIN_FILENO;
+ HaveModem(modem);
+ return modem->fd = STDIN_FILENO;
}
} else {
strncpy(tmpDeviceList, VarDeviceList, sizeof tmpDeviceList - 1);
tmpDeviceList[sizeof tmpDeviceList - 1] = '\0';
- for(tmpDevice=strtok(tmpDeviceList, ","); tmpDevice && (modem < 0);
+ for(tmpDevice=strtok(tmpDeviceList, ","); tmpDevice && (modem->fd < 0);
tmpDevice=strtok(NULL,",")) {
strncpy(VarDevice, tmpDevice, sizeof VarDevice - 1);
VarDevice[sizeof VarDevice - 1]= '\0';
@@ -490,19 +524,19 @@ OpenModem()
VarBaseDevice = VarBaseDevice ? VarBaseDevice + 1 : "";
if (strncmp(VarDevice, "/dev/", 5) == 0) {
- if (LockModem() == -1) {
- modem = -1;
+ if (LockModem(modem) == -1) {
+ modem->fd = -1;
}
else {
- modem = ID0open(VarDevice, O_RDWR | O_NONBLOCK);
- if (modem < 0) {
+ modem->fd = ID0open(VarDevice, O_RDWR | O_NONBLOCK);
+ if (modem->fd < 0) {
LogPrintf(LogERROR, "OpenModem failed: %s: %s\n", VarDevice,
strerror(errno));
- UnlockModem();
- modem = -1;
+ UnlockModem(modem);
+ modem->fd = -1;
}
else {
- HaveModem();
+ HaveModem(modem);
LogPrintf(LogDEBUG, "OpenModem: Modem is %s\n", VarDevice);
}
}
@@ -514,11 +548,11 @@ OpenModem()
host = VarDevice;
port = cp + 1;
if (*host && *port) {
- modem = OpenConnection(host, port);
+ modem->fd = OpenConnection(host, port);
*cp = ':'; /* Don't destroy VarDevice */
- if (modem < 0)
+ if (modem->fd < 0)
return (-1);
- HaveModem();
+ HaveModem(modem);
LogPrintf(LogDEBUG, "OpenModem: Modem is socket %s\n", VarDevice);
} else {
*cp = ':'; /* Don't destroy VarDevice */
@@ -534,7 +568,8 @@ OpenModem()
}
}
- if (modem < 0) return modem;
+ if (modem->fd < 0)
+ return modem->fd;
}
/*
@@ -542,71 +577,89 @@ OpenModem()
* for further operation. In this implementation, we assume that modem is
* configuted to use CTS/RTS flow control.
*/
- mbits = 0;
- dev_is_modem = isatty(modem) || DEV_IS_SYNC;
- if (DEV_IS_SYNC)
+ modem->mbits = 0;
+ modem->dev_is_modem = isatty(modem->fd) || Physical_IsSync(modem);
+ if (Physical_IsSync(modem))
nointr_sleep(1);
- if (dev_is_modem && !DEV_IS_SYNC) {
- tcgetattr(modem, &rstio);
- modemios = rstio;
- LogPrintf(LogDEBUG, "OpenModem: modem = %d\n", modem);
+ if (modem->dev_is_modem && !Physical_IsSync(modem)) {
+ tcgetattr(modem->fd, &rstio);
+ modem->ios = rstio;
+ LogPrintf(LogDEBUG, "OpenModem: modem = %d\n", modem->fd);
LogPrintf(LogDEBUG, "OpenModem: modem (get): iflag = %x, oflag = %x,"
" cflag = %x\n", rstio.c_iflag, rstio.c_oflag, rstio.c_cflag);
cfmakeraw(&rstio);
- if (VarCtsRts)
+ if (modem->rts_cts)
rstio.c_cflag |= CLOCAL | CCTS_OFLOW | CRTS_IFLOW;
else {
rstio.c_cflag |= CLOCAL;
rstio.c_iflag |= IXOFF;
}
rstio.c_iflag |= IXON;
- if (!(mode & MODE_DEDICATED))
+ if (
+#ifdef notyet
+ !modem->is_dedicated
+#else
+ !(mode & MODE_DEDICATED)
+#endif
+ )
rstio.c_cflag |= HUPCL;
- if ((mode & MODE_DIRECT) == 0) {
+ if (
+#ifdef notyet
+ !modem->is_direct
+#else
+ !(mode & MODE_DIRECT)
+#endif
+ ) {
/*
* If we are working as direct mode, don't change tty speed.
*/
rstio.c_cflag &= ~(CSIZE | PARODD | PARENB);
- rstio.c_cflag |= VarParity;
- if (cfsetspeed(&rstio, IntToSpeed(VarSpeed)) == -1) {
+ rstio.c_cflag |= modem->parity;
+ if (cfsetspeed(&rstio, IntToSpeed(modem->speed)) == -1) {
LogPrintf(LogWARN, "Unable to set modem speed (modem %d to %d)\n",
- modem, VarSpeed);
+ modem->fd, modem->speed);
}
}
- tcsetattr(modem, TCSADRAIN, &rstio);
+ tcsetattr(modem->fd, TCSADRAIN, &rstio);
LogPrintf(LogDEBUG, "modem (put): iflag = %x, oflag = %x, cflag = %x\n",
rstio.c_iflag, rstio.c_oflag, rstio.c_cflag);
- if (!(mode & MODE_DIRECT))
- if (ioctl(modem, TIOCMGET, &mbits)) {
+ if (
+#ifdef notyet
+ !modem->is_direct
+#else
+ !(mode & MODE_DIRECT)
+#endif
+ )
+ if (ioctl(modem->fd, TIOCMGET, &modem->mbits)) {
LogPrintf(LogERROR, "OpenModem: Cannot get modem status: %s\n",
strerror(errno));
- CloseLogicalModem();
+ CloseLogicalModem(modem);
return (-1);
}
- LogPrintf(LogDEBUG, "OpenModem: modem control = %o\n", mbits);
+ LogPrintf(LogDEBUG, "OpenModem: modem control = %o\n", modem->mbits);
- oldflag = fcntl(modem, F_GETFL, 0);
+ oldflag = fcntl(modem->fd, F_GETFL, 0);
if (oldflag < 0) {
LogPrintf(LogERROR, "OpenModem: Cannot get modem flags: %s\n",
strerror(errno));
- CloseLogicalModem();
+ CloseLogicalModem(modem);
return (-1);
}
- (void) fcntl(modem, F_SETFL, oldflag & ~O_NONBLOCK);
+ (void) fcntl(modem->fd, F_SETFL, oldflag & ~O_NONBLOCK);
}
- StartModemTimer();
+ StartModemTimer(modem);
- return (modem);
+ return (modem->fd);
}
int
-ModemSpeed()
+ModemSpeed(struct physical *modem)
{
struct termios rstio;
- tcgetattr(modem, &rstio);
+ tcgetattr(modem->fd, &rstio);
return (SpeedToInt(cfgetispeed(&rstio)));
}
@@ -614,131 +667,150 @@ ModemSpeed()
* Put modem tty line into raw mode which is necessary in packet mode operation
*/
int
-RawModem()
+RawModem(struct physical *modem)
{
struct termios rstio;
int oldflag;
- if (!isatty(modem) || DEV_IS_SYNC)
+ if (!isatty(modem->fd) || Physical_IsSync(modem))
return (0);
- if (!(mode & MODE_DIRECT) && modem >= 0 && !Online) {
- LogPrintf(LogDEBUG, "RawModem: mode = %d, modem = %d, mbits = %x\n", mode, modem, mbits);
+ if (
+#ifdef notyet
+ !modem->is_direct &&
+#else
+ !(mode & MODE_DIRECT) &&
+#endif
+ modem->fd >= 0 && !Online) {
+ LogPrintf(LogDEBUG, "RawModem: modem = %d, mbits = %x\n",
+ modem->fd, modem->mbits);
}
- tcgetattr(modem, &rstio);
+ tcgetattr(modem->fd, &rstio);
cfmakeraw(&rstio);
- if (VarCtsRts)
+ if (modem->rts_cts)
rstio.c_cflag |= CLOCAL | CCTS_OFLOW | CRTS_IFLOW;
else
rstio.c_cflag |= CLOCAL;
- if (!(mode & MODE_DEDICATED))
+ if (
+#ifdef notyet
+ !modem->is_dedicated
+#else
+ !(mode & MODE_DEDICATED)
+#endif
+ )
rstio.c_cflag |= HUPCL;
- tcsetattr(modem, TCSADRAIN, &rstio);
- oldflag = fcntl(modem, F_GETFL, 0);
+ tcsetattr(modem->fd, TCSADRAIN, &rstio);
+ oldflag = fcntl(modem->fd, F_GETFL, 0);
if (oldflag < 0)
return (-1);
- (void) fcntl(modem, F_SETFL, oldflag | O_NONBLOCK);
+ (void) fcntl(modem->fd, F_SETFL, oldflag | O_NONBLOCK);
return (0);
}
static void
-UnrawModem(void)
+UnrawModem(struct physical *modem)
{
int oldflag;
- if (isatty(modem) && !DEV_IS_SYNC) {
- tcsetattr(modem, TCSAFLUSH, &modemios);
- oldflag = fcntl(modem, F_GETFL, 0);
+ if (isatty(modem->fd) && !Physical_IsSync(modem)) {
+ tcsetattr(modem->fd, TCSAFLUSH, &modem->ios);
+ oldflag = fcntl(modem->fd, F_GETFL, 0);
if (oldflag < 0)
return;
- (void) fcntl(modem, F_SETFL, oldflag & ~O_NONBLOCK);
+ (void) fcntl(modem->fd, F_SETFL, oldflag & ~O_NONBLOCK);
}
}
void
-ModemAddInOctets(int n)
+ModemAddInOctets(struct physical *modem, int n)
{
- throughput_addin(&throughput, n);
+ throughput_addin(&modem->throughput, n);
}
void
-ModemAddOutOctets(int n)
+ModemAddOutOctets(struct physical *modem, int n)
{
- throughput_addout(&throughput, n);
+ throughput_addout(&modem->throughput, n);
}
static void
-ClosePhysicalModem(void)
+ClosePhysicalModem(struct physical *modem)
{
LogPrintf(LogDEBUG, "ClosePhysicalModem\n");
- close(modem);
- modem = -1;
- throughput_log(&throughput, LogPHASE, "Modem");
+ close(modem->fd);
+ modem->fd = -1;
+ throughput_log(&modem->throughput, LogPHASE, "Modem");
}
void
-HangupModem(int flag)
+HangupModem(struct physical *modem, int flag)
{
struct termios tio;
LogPrintf(LogDEBUG, "Hangup modem (%s)\n", modem >= 0 ? "open" : "closed");
- if (modem < 0)
+ if (modem->fd < 0)
return;
- StopTimer(&ModemTimer);
- throughput_stop(&throughput);
+ StopTimer(&modem->DeviceTimer);
+ throughput_stop(&modem->throughput);
if (TermMode) {
LogPrintf(LogDEBUG, "HangupModem: Not in 'term' mode\n");
return;
}
- if (!isatty(modem)) {
- mbits &= ~TIOCM_DTR;
- ClosePhysicalModem();
+ if (!isatty(modem->fd)) {
+ modem->mbits &= ~TIOCM_DTR;
+ ClosePhysicalModem(modem);
return;
}
- if (modem >= 0 && Online) {
- mbits &= ~TIOCM_DTR;
- tcgetattr(modem, &tio);
+ if (modem->fd >= 0 && Online) {
+ modem->mbits &= ~TIOCM_DTR;
+ tcgetattr(modem->fd, &tio);
if (cfsetspeed(&tio, B0) == -1) {
LogPrintf(LogWARN, "Unable to set modem to speed 0\n");
}
- tcsetattr(modem, TCSANOW, &tio);
+ tcsetattr(modem->fd, TCSANOW, &tio);
nointr_sleep(1);
}
- if (modem >= 0) {
+ if (modem->fd >= 0) {
char ScriptBuffer[SCRIPT_LEN];
strncpy(ScriptBuffer, VarHangupScript, sizeof ScriptBuffer - 1);
ScriptBuffer[sizeof ScriptBuffer - 1] = '\0';
LogPrintf(LogDEBUG, "HangupModem: Script: %s\n", ScriptBuffer);
- if (flag || !(mode & MODE_DEDICATED)) {
- DoChat(ScriptBuffer);
- tcflush(modem, TCIOFLUSH);
- UnrawModem();
- CloseLogicalModem();
+ if (flag ||
+#ifdef notyet
+ !modem->is_dedicated
+#else
+ !(mode & MODE_DEDICATED)
+#endif
+ ) {
+ DoChat(modem, ScriptBuffer);
+ tcflush(modem->fd, TCIOFLUSH);
+ UnrawModem(modem);
+ CloseLogicalModem(modem);
} else {
/*
* If we are working as dedicated mode, never close it until we are
* directed to quit program.
*/
- mbits |= TIOCM_DTR;
- ioctl(modem, TIOCMSET, &mbits);
- DoChat(ScriptBuffer);
+ modem->mbits |= TIOCM_DTR;
+ ioctl(modem->fd, TIOCMSET, &modem->mbits);
+ DoChat(modem, ScriptBuffer);
}
}
}
static void
-CloseLogicalModem(void)
+CloseLogicalModem(struct physical *modem)
{
LogPrintf(LogDEBUG, "CloseLogicalModem\n");
- if (modem >= 0) {
- ClosePhysicalModem();
+ if (modem->fd >= 0) {
+ ClosePhysicalModem(modem);
if (Utmp) {
struct utmp ut;
strncpy(ut.ut_line, VarBaseDevice, sizeof ut.ut_line - 1);
@@ -750,7 +822,7 @@ CloseLogicalModem(void)
ut.ut_line);
Utmp = 0;
}
- UnlockModem();
+ UnlockModem(modem);
}
}
@@ -759,41 +831,45 @@ CloseLogicalModem(void)
* to the line when ModemStartOutput() is called.
*/
void
-WriteModem(int pri, const char *ptr, int count)
+WriteModem(struct physical *modem, int pri, const char *ptr, int count)
{
struct mbuf *bp;
+ assert(pri == PRI_NORMAL || pri == PRI_LINK);
+
bp = mballoc(count, MB_MODEM);
memcpy(MBUF_CTOP(bp), ptr, count);
/*
* Should be NORMAL and LINK only. All IP frames get here marked NORMAL.
*/
- Enqueue(&OutputQueues[pri], bp);
+ Enqueue(&modem->OutputQueues[pri], bp);
}
void
-ModemOutput(int pri, struct mbuf * bp)
+ModemOutput(struct physical *modem, int pri, struct mbuf * bp)
{
struct mbuf *wp;
int len;
+ assert(pri == PRI_NORMAL || pri == PRI_LINK);
+
len = plength(bp);
wp = mballoc(len, MB_MODEM);
mbread(bp, MBUF_CTOP(wp), len);
- Enqueue(&OutputQueues[pri], wp);
+ Enqueue(&modem->OutputQueues[pri], wp);
ModemStartOutput(modem);
}
int
-ModemQlen()
+ModemQlen(struct physical *phys)
{
struct mqueue *queue;
int len = 0;
int i;
for (i = PRI_NORMAL; i <= PRI_LINK; i++) {
- queue = &OutputQueues[i];
+ queue = &phys->OutputQueues[i];
len += queue->qlen;
}
return (len);
@@ -801,24 +877,24 @@ ModemQlen()
}
void
-ModemStartOutput(int fd)
+ModemStartOutput(struct physical *modem)
{
struct mqueue *queue;
int nb, nw;
int i;
- if (modemout == NULL && ModemQlen() == 0)
- IpStartOutput();
- if (modemout == NULL) {
+ if (modem->out == NULL) {
+ if (ModemQlen(modem) == 0)
+ IpStartOutput(modem);
i = PRI_LINK;
- for (queue = &OutputQueues[PRI_LINK]; queue >= OutputQueues; queue--) {
+ for (queue = &modem->OutputQueues[PRI_LINK]; queue >= &modem->OutputQueues[0]; queue--) {
if (queue->top) {
- modemout = Dequeue(queue);
+ modem->out = Dequeue(queue);
if (LogIsKept(LogDEBUG)) {
if (i > PRI_NORMAL) {
struct mqueue *q;
- q = &OutputQueues[0];
+ q = &modem->OutputQueues[0];
LogPrintf(LogDEBUG, "ModemStartOutput: Output from queue %d,"
" normal has %d\n", i, q->qlen);
}
@@ -829,24 +905,25 @@ ModemStartOutput(int fd)
i--;
}
}
- if (modemout) {
- nb = modemout->cnt;
+ if (modem->out) {
+ nb = modem->out->cnt;
if (nb > 1600)
nb = 1600;
- nw = write(fd, MBUF_CTOP(modemout), nb);
+ nw = write(modem->fd, MBUF_CTOP(modem->out), nb);
LogPrintf(LogDEBUG, "ModemStartOutput: wrote: %d(%d)\n", nw, nb);
LogDumpBuff(LogDEBUG, "ModemStartOutput: modem write",
- MBUF_CTOP(modemout), nb);
+ MBUF_CTOP(modem->out), nb);
if (nw > 0) {
- modemout->cnt -= nw;
- modemout->offset += nw;
- if (modemout->cnt == 0) {
- modemout = mbfree(modemout);
+ modem->out->cnt -= nw;
+ modem->out->offset += nw;
+ if (modem->out->cnt == 0) {
+ modem->out = mbfree(modem->out);
LogPrintf(LogDEBUG, "ModemStartOutput: mbfree\n");
}
} else if (nw < 0) {
if (errno != EAGAIN) {
- LogPrintf(LogERROR, "modem write (%d): %s\n", modem, strerror(errno));
+ LogPrintf(LogERROR, "modem write (%d): %s\n", modem->fd,
+ strerror(errno));
reconnect(RECON_TRUE);
DownConnection();
}
@@ -855,18 +932,18 @@ ModemStartOutput(int fd)
}
int
-DialModem()
+DialModem(struct physical *modem)
{
char ScriptBuffer[SCRIPT_LEN];
int excode;
strncpy(ScriptBuffer, VarDialScript, sizeof ScriptBuffer - 1);
ScriptBuffer[sizeof ScriptBuffer - 1] = '\0';
- if ((excode = DoChat(ScriptBuffer)) > 0) {
+ if ((excode = DoChat(modem, ScriptBuffer)) > 0) {
if (VarTerm)
fprintf(VarTerm, "dial OK!\n");
strncpy(ScriptBuffer, VarLoginScript, sizeof ScriptBuffer - 1);
- if ((excode = DoChat(ScriptBuffer)) > 0) {
+ if ((excode = DoChat(modem, ScriptBuffer)) > 0) {
VarAltPhone = NULL;
if (VarTerm)
fprintf(VarTerm, "login OK!\n");
@@ -877,14 +954,14 @@ DialModem()
LogPrintf(LogWARN, "DialModem: login failed.\n");
excode = EX_NOLOGIN;
}
- ModemTimeout(NULL); /* Dummy call to check modem status */
+ ModemTimeout(modem); /* Dummy call to check modem status */
} else if (excode == -1)
excode = EX_SIG;
else {
LogPrintf(LogWARN, "DialModem: dial failed.\n");
excode = EX_NODIAL;
}
- HangupModem(0);
+ HangupModem(modem, 0);
return (excode);
}
@@ -892,6 +969,7 @@ int
ShowModemStatus(struct cmdargs const *arg)
{
const char *dev;
+ struct physical *modem = pppVars.physical;
#ifdef TIOCOUTQ
int nb;
#endif
@@ -902,12 +980,12 @@ ShowModemStatus(struct cmdargs const *arg)
dev = *VarDevice ? VarDevice : "network";
fprintf(VarTerm, "device: %s speed: ", dev);
- if (DEV_IS_SYNC)
+ if (Physical_IsSync(modem))
fprintf(VarTerm, "sync\n");
else
- fprintf(VarTerm, "%d\n", VarSpeed);
+ fprintf(VarTerm, "%d\n", modem->speed);
- switch (VarParity & CSIZE) {
+ switch (modem->parity & CSIZE) {
case CS7:
fprintf(VarTerm, "cs7, ");
break;
@@ -915,33 +993,50 @@ ShowModemStatus(struct cmdargs const *arg)
fprintf(VarTerm, "cs8, ");
break;
}
- if (VarParity & PARENB) {
- if (VarParity & PARODD)
+ if (modem->parity & PARENB) {
+ if (modem->parity & PARODD)
fprintf(VarTerm, "odd parity, ");
else
fprintf(VarTerm, "even parity, ");
} else
fprintf(VarTerm, "no parity, ");
- fprintf(VarTerm, "CTS/RTS %s.\n", (VarCtsRts ? "on" : "off"));
+ fprintf(VarTerm, "CTS/RTS %s.\n", (modem->rts_cts ? "on" : "off"));
if (LogIsKept(LogDEBUG))
- fprintf(VarTerm, "fd = %d, modem control = %o\n", modem, mbits);
- fprintf(VarTerm, "connect count: %d\n", connect_count);
+ fprintf(VarTerm, "fd = %d, modem control = %o\n", modem->fd, modem->mbits);
+ fprintf(VarTerm, "connect count: %d\n", modem->connect_count);
#ifdef TIOCOUTQ
- if (modem >= 0)
- if (ioctl(modem, TIOCOUTQ, &nb) >= 0)
+ if (modem->fd >= 0)
+ if (ioctl(modem->fd, TIOCOUTQ, &nb) >= 0)
fprintf(VarTerm, "outq: %d\n", nb);
else
fprintf(VarTerm, "outq: ioctl probe failed: %s\n", strerror(errno));
#endif
- fprintf(VarTerm, "outqlen: %d\n", ModemQlen());
+ fprintf(VarTerm, "outqlen: %d\n", ModemQlen(modem));
fprintf(VarTerm, "DialScript = %s\n", VarDialScript);
fprintf(VarTerm, "LoginScript = %s\n", VarLoginScript);
fprintf(VarTerm, "PhoneNumber(s) = %s\n", VarPhoneList);
fprintf(VarTerm, "\n");
- throughput_disp(&throughput, VarTerm);
+ throughput_disp(&modem->throughput, VarTerm);
return 0;
}
+
+
+/* Dummy linker functions, to keep this quiet. Might end up a full
+ regression test later, right now it is just to be able to track
+ external symbols. */
+#ifdef TESTMAIN
+int main(void) {}
+
+void LogPrintf(int i, const char *a, ...) {}
+int LogIsKept(int garble) { return 0; }
+int Physical_IsSync(struct physical *phys) {return 0;}
+int DoChat(struct physical *a, char *b) {return 0;}
+
+int mode;
+
+#endif
+
diff --git a/usr.sbin/ppp/modem.h b/usr.sbin/ppp/modem.h
index e4b6dbb10587..be0e31a3261a 100644
--- a/usr.sbin/ppp/modem.h
+++ b/usr.sbin/ppp/modem.h
@@ -15,27 +15,30 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: modem.h,v 1.15 1998/01/10 01:55:11 brian Exp $
+ * $Id: modem.h,v 1.16 1998/01/21 02:15:23 brian Exp $
*
* TODO:
*/
-extern int RawModem(void);
-extern void WriteModem(int, const char *, int);
-extern void ModemStartOutput(int);
-extern int OpenModem(void);
-extern int ModemSpeed(void);
-extern int ModemQlen(void);
-extern int DialModem(void);
+struct physical;
+
+extern int RawModem(struct physical *);
+extern void WriteModem(struct physical *, int, const char *, int);
+extern void ModemStartOutput(struct physical *);
+extern int OpenModem(struct physical *);
+extern int ModemSpeed(struct physical *);
+extern int ModemQlen(struct physical *);
+extern int DialModem(struct physical *);
extern speed_t IntToSpeed(int);
-extern void ModemTimeout(void *v);
+extern void ModemTimeout(void *);
extern void DownConnection(void);
-extern void ModemOutput(int, struct mbuf *);
-extern int ChangeParity(const char *);
-extern void HangupModem(int);
+extern void ModemOutput(struct physical *modem, int, struct mbuf *);
+extern int ChangeParity(struct physical *, const char *);
+extern void HangupModem(struct physical *, int);
extern int ShowModemStatus(struct cmdargs const *);
extern void Enqueue(struct mqueue *, struct mbuf *);
extern struct mbuf *Dequeue(struct mqueue *);
-extern void SequenceQueues(void);
-extern void ModemAddInOctets(int);
-extern void ModemAddOutOctets(int);
+extern void SequenceQueues(struct physical *physical);
+extern void ModemAddInOctets(struct physical *modem, int);
+extern void ModemAddOutOctets(struct physical *modem, int);
+
diff --git a/usr.sbin/ppp/pap.c b/usr.sbin/ppp/pap.c
index ac2c763764e0..659595f70313 100644
--- a/usr.sbin/ppp/pap.c
+++ b/usr.sbin/ppp/pap.c
@@ -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.19 1997/11/22 03:37:43 brian Exp $
+ * $Id: pap.c,v 1.20 1997/12/24 09:29:11 brian Exp $
*
* TODO:
*/
@@ -51,11 +51,12 @@
#include "lcpproto.h"
#include "phase.h"
#include "auth.h"
+#include "physical.h"
static const char *papcodes[] = { "???", "REQUEST", "ACK", "NAK" };
static void
-SendPapChallenge(int papid)
+SendPapChallenge(int papid, struct physical *physical)
{
struct fsmheader lh;
struct mbuf *bp;
@@ -83,7 +84,7 @@ SendPapChallenge(int papid)
*cp++ = keylen;
memcpy(cp, VarAuthKey, keylen);
- HdlcOutput(PRI_LINK, PROTO_PAP, bp);
+ HdlcOutput(physical, PRI_LINK, PROTO_PAP, bp);
}
struct authinfo AuthPapInfo = {
@@ -91,7 +92,7 @@ struct authinfo AuthPapInfo = {
};
static void
-SendPapCode(int id, int code, const char *message)
+SendPapCode(int id, int code, const char *message, struct physical *physical)
{
struct fsmheader lh;
struct mbuf *bp;
@@ -109,14 +110,14 @@ SendPapCode(int id, int code, const char *message)
*cp++ = mlen;
memcpy(cp, message, mlen);
LogPrintf(LogPHASE, "PapOutput: %s\n", papcodes[code]);
- HdlcOutput(PRI_LINK, PROTO_PAP, bp);
+ HdlcOutput(physical, PRI_LINK, PROTO_PAP, bp);
}
/*
* Validate given username and passwrd against with secret table
*/
static int
-PapValidate(u_char * name, u_char * key)
+PapValidate(u_char * name, u_char * key, struct physical *physical)
{
int nlen, klen;
@@ -140,11 +141,11 @@ PapValidate(u_char * name, u_char * key)
}
#endif
- return (AuthValidate(SECRETFILE, name, key));
+ return (AuthValidate(SECRETFILE, name, key, physical));
}
void
-PapInput(struct mbuf * bp)
+PapInput(struct mbuf * bp, struct physical *physical)
{
int len = plength(bp);
struct fsmheader *php;
@@ -161,11 +162,12 @@ PapInput(struct mbuf * bp)
switch (php->code) {
case PAP_REQUEST:
cp = (u_char *) (php + 1);
- if (PapValidate(cp, cp + *cp + 1)) {
- SendPapCode(php->id, PAP_ACK, "Greetings!!");
+ if (PapValidate(cp, cp + *cp + 1, physical)) {
+ SendPapCode(php->id, PAP_ACK, "Greetings!!", physical);
lcp->auth_ineed = 0;
if (lcp->auth_iwait == 0) {
- if ((mode & MODE_DIRECT) && isatty(modem) && Enabled(ConfUtmp))
+ if ((mode & MODE_DIRECT) && Physical_IsATTY(physical) &&
+ Enabled(ConfUtmp))
if (Utmp)
LogPrintf(LogERROR, "Oops, already logged in on %s\n",
VarBaseDevice);
@@ -180,12 +182,12 @@ PapInput(struct mbuf * bp)
login(&ut);
Utmp = 1;
}
- NewPhase(PHASE_NETWORK);
+ NewPhase(physical, PHASE_NETWORK);
}
} else {
- SendPapCode(php->id, PAP_NAK, "Login incorrect");
+ SendPapCode(php->id, PAP_NAK, "Login incorrect", physical);
reconnect(RECON_FALSE);
- LcpClose();
+ LcpClose(&LcpFsm);
}
break;
case PAP_ACK:
@@ -197,7 +199,7 @@ PapInput(struct mbuf * bp)
if (lcp->auth_iwait == PROTO_PAP) {
lcp->auth_iwait = 0;
if (lcp->auth_ineed == 0)
- NewPhase(PHASE_NETWORK);
+ NewPhase(physical, PHASE_NETWORK);
}
break;
case PAP_NAK:
@@ -207,7 +209,7 @@ PapInput(struct mbuf * bp)
cp[len] = 0;
LogPrintf(LogPHASE, "Received PAP_NAK (%s)\n", cp);
reconnect(RECON_FALSE);
- LcpClose();
+ LcpClose(&LcpFsm);
break;
}
}
diff --git a/usr.sbin/ppp/pap.h b/usr.sbin/ppp/pap.h
index 6ef0792f18c5..84332bb7ac90 100644
--- a/usr.sbin/ppp/pap.h
+++ b/usr.sbin/ppp/pap.h
@@ -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.4 1997/10/26 01:03:29 brian Exp $
+ * $Id: pap.h,v 1.5 1997/10/26 12:42:13 brian Exp $
*
* TODO:
*/
@@ -26,4 +26,4 @@
extern struct authinfo AuthPapInfo;
-extern void PapInput(struct mbuf *);
+extern void PapInput(struct mbuf *, struct physical *);
diff --git a/usr.sbin/ppp/phase.c b/usr.sbin/ppp/phase.c
index 9522f8c25486..b05c1c7b6909 100644
--- a/usr.sbin/ppp/phase.c
+++ b/usr.sbin/ppp/phase.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id$
+ * $Id: phase.c,v 1.6 1997/12/21 12:11:07 brian Exp $
*/
#include <sys/param.h>
@@ -69,7 +69,7 @@ Auth2Nam(u_short auth)
}
void
-NewPhase(int new)
+NewPhase(struct physical *physical, int new)
{
struct lcpstate *lcp = &LcpInfo;
@@ -82,12 +82,13 @@ NewPhase(int new)
if (lcp->his_auth || lcp->want_auth) {
LogPrintf(LogPHASE, " his = %s, mine = %s\n",
Auth2Nam(lcp->his_auth), Auth2Nam(lcp->want_auth));
+ /* XXX-ML AuthPapInfo and AuthChapInfo must be allocated! */
if (lcp->his_auth == PROTO_PAP)
- StartAuthChallenge(&AuthPapInfo);
+ StartAuthChallenge(&AuthPapInfo, physical);
if (lcp->want_auth == PROTO_CHAP)
- StartAuthChallenge(&AuthChapInfo);
+ StartAuthChallenge(&AuthChapInfo, physical);
} else
- NewPhase(PHASE_NETWORK);
+ NewPhase(physical, PHASE_NETWORK);
break;
case PHASE_NETWORK:
IpcpUp();
diff --git a/usr.sbin/ppp/phase.h b/usr.sbin/ppp/phase.h
index 1ed568e86fb3..31a35b87ebd1 100644
--- a/usr.sbin/ppp/phase.h
+++ b/usr.sbin/ppp/phase.h
@@ -15,11 +15,13 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: phase.h,v 1.8 1997/10/26 01:03:32 brian Exp $
+ * $Id: phase.h,v 1.9 1998/01/21 02:15:24 brian Exp $
*
* TODO:
*/
+struct physical;
+
#define PHASE_DEAD 0 /* Link is dead */
#define PHASE_ESTABLISH 1 /* Establishing link */
#define PHASE_AUTHENTICATE 2 /* Being authenticated */
@@ -28,4 +30,4 @@
extern int phase; /* Curent phase */
-extern void NewPhase(int);
+extern void NewPhase(struct physical *physical, int);
diff --git a/usr.sbin/ppp/physical.c b/usr.sbin/ppp/physical.c
new file mode 100644
index 000000000000..7bb8ff02389d
--- /dev/null
+++ b/usr.sbin/ppp/physical.c
@@ -0,0 +1,171 @@
+/*
+ * Written by Eivind Eklund <eivind@yes.no>
+ * for Yes Interactive
+ *
+ * Copyright (C) 1998, Yes Interactive. All rights reserved.
+ *
+ * Redistribution and use in any form is permitted. Redistribution in
+ * source form should include the above copyright and this set of
+ * conditions, because large sections american law seems to have been
+ * created by a bunch of jerks on drugs that are now illegal, forcing
+ * me to include this copyright-stuff instead of placing this in the
+ * public domain. The name of of 'Yes Interactive' or 'Eivind Eklund'
+ * 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$
+ *
+ */
+
+#include <sys/param.h>
+#include <sys/tty.h>
+#include <sys/uio.h>
+
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+
+/* XXX Name space pollution from vars.h */
+#include <netinet/in.h>
+#include <alias.h>
+#include "defs.h"
+#include "command.h"
+#include "loadalias.h"
+
+/* XXX Name space pollution from hdlc.h */
+#include "mbuf.h"
+
+/* Name space pollution for physical.h */
+#include "hdlc.h"
+#include "timer.h"
+#include "throughput.h"
+
+#define PHYSICAL_DEVICE
+#include "physical.h"
+
+
+#include "vars.h"
+
+/* External calls - should possibly be moved inline */
+extern int IntToSpeed(int);
+
+
+int
+Physical_GetFD(struct physical *phys) {
+ return phys->fd;
+}
+
+int
+Physical_IsATTY(struct physical *phys) {
+ return isatty(phys->fd);
+}
+
+int
+Physical_IsActive(struct physical *phys) {
+ return phys->fd >= 0;
+}
+
+int
+Physical_IsSync(struct physical *phys) {
+ return phys->speed == 0;
+}
+
+int
+Physical_FD_ISSET(struct physical *phys, fd_set *set) {
+ return phys->fd >= 0 && FD_ISSET(phys->fd, set);
+}
+
+void
+Physical_FD_SET(struct physical *phys, fd_set *set) {
+ assert(phys->fd >= 0);
+ FD_SET(phys->fd, set);
+}
+
+
+/* XXX-ML - must be moved into the physical struct */
+const char *Physical_GetDevice(struct physical *phys) {
+ return VarDevice;
+}
+
+/* XXX-ML - must be moved into the physical struct */
+void
+Physical_SetDevice(struct physical *phys, const char *new_device_list) {
+ strncpy(VarDeviceList, new_device_list, sizeof VarDeviceList - 1);
+ VarDeviceList[sizeof VarDeviceList - 1] = '\0';
+}
+
+
+int
+Physical_SetSpeed(struct physical *phys, int speed) {
+ if (IntToSpeed(speed) != B0) {
+ phys->speed = speed;
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+void
+Physical_SetSync(struct physical *phys) {
+ phys->speed = 0;
+}
+
+
+int
+Physical_SetRtsCts(struct physical *phys, int enable) {
+ assert(enable == 0 || enable == 1);
+
+ phys->rts_cts = enable;
+ return 1;
+}
+
+void
+Physical_SetDedicated(struct physical *phys, int enable) {
+ assert(enable == 0 || enable == 1);
+
+ phys->is_dedicated = enable;
+}
+
+void
+Physical_SetDirect(struct physical *phys, int enable) {
+ assert(enable == 0 || enable == 1);
+
+ phys->is_direct = enable;
+}
+
+int
+Physical_IsDirect(struct physical *phys) {
+ return phys->is_direct;
+}
+
+int
+Physical_IsDedicated(struct physical *phys) {
+ return phys->is_dedicated;
+}
+
+
+void
+Physical_DupAndClose(struct physical *phys) {
+ int nmodem;
+
+ nmodem = dup(phys->fd);
+ close(phys->fd);
+ phys->fd = nmodem;
+}
+
+/* Encapsulation for a read on the FD. Avoids some exposure, and
+ concentrates control. */
+ssize_t
+Physical_Read(struct physical *phys, void *buf, size_t nbytes) {
+ return read(phys->fd, buf, nbytes);
+}
+
+ssize_t
+Physical_Write(struct physical *phys, const void *buf, size_t nbytes) {
+ return write(phys->fd, buf, nbytes);
+}
diff --git a/usr.sbin/ppp/physical.h b/usr.sbin/ppp/physical.h
new file mode 100644
index 000000000000..12c2af049080
--- /dev/null
+++ b/usr.sbin/ppp/physical.h
@@ -0,0 +1,83 @@
+/*
+ * Written by Eivind Eklund <eivind@yes.no>
+ * for Yes Interactive
+ *
+ * Copyright (C) 1998, Yes Interactive. All rights reserved.
+ *
+ * Redistribution and use in any form is permitted. Redistribution in
+ * source form should include the above copyright and this set of
+ * conditions, because large sections american law seems to have been
+ * created by a bunch of jerks on drugs that are now illegal, forcing
+ * me to include this copyright-stuff instead of placing this in the
+ * public domain. The name of of 'Yes Interactive' or 'Eivind Eklund'
+ * 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$
+ *
+ */
+
+struct physical;
+
+#ifdef PHYSICAL_DEVICE
+struct physical {
+ int fd; /* File descriptor for this device */
+ int mbits; /* Current DCD status */
+ unsigned dev_is_modem : 1; /* Is the device an actual modem?
+ Faked for sync devices, though...
+ (Possibly this should be
+ dev_is_not_tcp?) XXX-ML */
+
+ unsigned is_dedicated : 1; /* Dedicated mode? XXX-ML - not yet initialized */
+ unsigned is_direct : 1; /* Direct mode? XXX-ML - not yet initialized */
+ struct pppThroughput throughput;
+ struct mbuf *out;
+ int connect_count;
+ struct pppTimer DeviceTimer; /* Was ModemTimer */
+
+
+ /* XXX Shouldn't be tied up to a specific number like this. -EE. */
+ struct mqueue OutputQueues[PRI_LINK + 1];
+
+ /* XXX-ML Most of the below is device specific, and probably do not
+ belong in the generic physical struct. It comes from modem.c. */
+ unsigned rts_cts : 1; /* Is rts/cts enabled? */
+ unsigned int parity; /* What parity is enabled? (TTY flags) */
+ unsigned int speed; /* Modem speed */
+ struct termios ios; /* To be able to reset from raw mode */
+};
+#endif
+
+int Physical_GetFD(struct physical *);
+int Physical_IsATTY(struct physical *);
+int Physical_IsActive(struct physical *);
+int Physical_IsSync(struct physical *);
+int Physical_IsDedicated(struct physical *phys);
+int Physical_IsDirect(struct physical *phys);
+const char *Physical_GetDevice(struct physical *);
+
+
+void Physical_SetDevice(struct physical *phys, const char *new_device_list);
+int /* Was this speed OK? */
+Physical_SetSpeed(struct physical *phys, int speed);
+
+/* XXX-ML I'm not certain this is the right way to handle this, but we
+ can solve that later. */
+void Physical_SetSync(struct physical *phys);
+
+int /* Can this be set? (Might not be a relevant attribute for this
+ device, for instance) */
+Physical_SetRtsCts(struct physical *phys, int enable);
+
+void Physical_SetDedicated(struct physical *phys, int enable);
+void Physical_SetDirect(struct physical *phys, int enable);
+
+void Physical_FD_SET(struct physical *, fd_set *);
+int Physical_FD_ISSET(struct physical *, fd_set *);
+
+void Physical_DupAndClose(struct physical *);
+ssize_t Physical_Read(struct physical *phys, void *buf, size_t nbytes);
+ssize_t Physical_Write(struct physical *phys, const void *buf, size_t nbytes);
diff --git a/usr.sbin/ppp/pred.c b/usr.sbin/ppp/pred.c
index d5ff543b656d..019fc02a3462 100644
--- a/usr.sbin/ppp/pred.c
+++ b/usr.sbin/ppp/pred.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: pred.c,v 1.19 1997/12/21 12:11:08 brian Exp $
+ * $Id: pred.c,v 1.20 1998/01/14 01:47:50 brian Exp $
*/
#include <sys/param.h>
@@ -182,7 +182,8 @@ Pred1InitOutput(void)
}
static int
-Pred1Output(int pri, u_short proto, struct mbuf * bp)
+Pred1Output(struct physical *physical, int pri, u_short proto,
+ struct mbuf * bp)
{
struct mbuf *mwp;
u_char *cp, *wp, *hp;
@@ -218,7 +219,7 @@ Pred1Output(int pri, u_short proto, struct mbuf * bp)
*wp++ = fcs & 0377;
*wp++ = fcs >> 8;
mwp->cnt = wp - MBUF_CTOP(mwp);
- HdlcOutput(PRI_NORMAL, PROTO_COMPD, mwp);
+ HdlcOutput(physical, PRI_NORMAL, PROTO_COMPD, mwp);
return 1;
}
diff --git a/usr.sbin/ppp/vars.c b/usr.sbin/ppp/vars.c
index 7cbd3b80aa91..b5a599e2d805 100644
--- a/usr.sbin/ppp/vars.c
+++ b/usr.sbin/ppp/vars.c
@@ -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.44 1998/01/20 22:47:48 brian Exp $
+ * $Id: vars.c,v 1.45 1998/01/21 02:15:31 brian Exp $
*
*/
#include <sys/param.h>
@@ -37,9 +37,10 @@
#include "loadalias.h"
#include "vars.h"
#include "auth.h"
+#include "physical.h"
char VarVersion[] = "PPP Version 1.65";
-char VarLocalVersion[] = "$Date: 1998/01/20 22:47:48 $";
+char VarLocalVersion[] = "$Date: 1998/01/21 02:15:31 $";
int Utmp = 0;
int ipKeepAlive = 0;
int reconnectState = RECON_UNKNOWN;
@@ -66,11 +67,13 @@ struct confdesc pppConfs[] = {
{NULL},
};
+extern struct physical phys_modem;
+
struct pppvars pppVars = {
DEF_MRU, DEF_MTU, 0, MODEM_SPEED, CS8, MODEM_CTSRTS, 180, 30, 3,
RECONNECT_TIMER, RECONNECT_TRIES, REDIAL_PERIOD,
NEXT_REDIAL_PERIOD, 1, 1, MODEM_DEV, "", BASE_MODEM_DEV,
- 1, LOCAL_NO_AUTH, 0
+ 1, LOCAL_NO_AUTH, 0, &phys_modem
};
int
diff --git a/usr.sbin/ppp/vars.h b/usr.sbin/ppp/vars.h
index 70a406ae11b9..828c0ebcb294 100644
--- a/usr.sbin/ppp/vars.h
+++ b/usr.sbin/ppp/vars.h
@@ -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.41 1998/01/20 22:47:48 brian Exp $
+ * $Id: vars.h,v 1.42 1998/01/21 02:15:32 brian Exp $
*
* TODO:
*/
@@ -79,6 +79,9 @@ 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 */
#define DIALUP_REQ 0x01
#define DIALUP_DONE 0x02
char dial_script[SCRIPT_LEN]; /* Dial script */
@@ -105,9 +108,11 @@ struct pppvars {
#define VarDevice pppVars.modem_dev
#define VarDeviceList pppVars.modem_devlist
#define VarBaseDevice pppVars.base_modem_dev
-#define VarSpeed pppVars.modem_speed
-#define VarParity pppVars.modem_parity
-#define VarCtsRts pppVars.modem_ctsrts
+#if 0
+# define VarSpeed pppVars.modem_speed
+# define VarParity pppVars.modem_parity
+# define VarCtsRts pppVars.modem_ctsrts
+#endif
#define VarOpenMode pppVars.open_mode
#define VarLocalAuth pppVars.lauth
#define VarDialScript pppVars.dial_script
diff --git a/usr.sbin/ppp/vjcomp.c b/usr.sbin/ppp/vjcomp.c
index f9ef60db40fc..e1b327b8101e 100644
--- a/usr.sbin/ppp/vjcomp.c
+++ b/usr.sbin/ppp/vjcomp.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: vjcomp.c,v 1.15 1998/01/11 17:50:46 brian Exp $
+ * $Id: vjcomp.c,v 1.16 1998/01/21 02:15:33 brian Exp $
*
* TODO:
*/
@@ -51,7 +51,7 @@ VjInit(int max_state)
}
void
-SendPppFrame(struct mbuf * bp)
+SendPppFrame(struct physical *physical, struct mbuf * bp)
{
int type;
u_short proto;
@@ -80,7 +80,7 @@ SendPppFrame(struct mbuf * bp)
}
} else
proto = PROTO_IP;
- HdlcOutput(PRI_NORMAL, proto, bp);
+ HdlcOutput(physical, PRI_NORMAL, proto, bp);
}
static struct mbuf *
diff --git a/usr.sbin/ppp/vjcomp.h b/usr.sbin/ppp/vjcomp.h
index 615894cfc0c8..eb2abcbb6815 100644
--- a/usr.sbin/ppp/vjcomp.h
+++ b/usr.sbin/ppp/vjcomp.h
@@ -23,10 +23,12 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: vjcomp.h,v 1.4 1997/12/21 12:11:10 brian Exp $
+ * $Id: vjcomp.h,v 1.5 1998/01/11 17:50:49 brian Exp $
*/
+struct physical;
+
extern void VjInit(int);
-extern void SendPppFrame(struct mbuf *);
+extern void SendPppFrame(struct physical *physical, struct mbuf *);
extern struct mbuf *VjCompInput(struct mbuf *, int);
extern const char *vj2asc(u_int32_t);