summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ppp
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1997-10-29 01:19:51 +0000
committerbrian <brian@FreeBSD.org>1997-10-29 01:19:51 +0000
commit941e2045a2c71da41fadec9bfed70cb37decf91d (patch)
tree4c2bd79bb14d877ea218862c9460f1013baccc74 /usr.sbin/ppp
parentaddd7d2b5d469a8b3c11cfc9d397c0faad4ade9a (diff)
downloadFreeBSD-src-941e2045a2c71da41fadec9bfed70cb37decf91d.zip
FreeBSD-src-941e2045a2c71da41fadec9bfed70cb37decf91d.tar.gz
o Bump version to 1.3 to reflect major changes
o Report modem connect time properly o Report bytes in/out over physical media o Fix phases (TERMINATE is *higher than* DEAD) o Do a LayerFinish from LcpDown o Bring down IPCP & CCP when we enter PHASE_TERMINATE o Give a new prompt when we go to PHASE_DEAD o Stop the modem timer properly when idle o Treat sig 15 like an exiting carrier loss o Log (DEBUG) offline & online transitions
Diffstat (limited to 'usr.sbin/ppp')
-rw-r--r--usr.sbin/ppp/async.c6
-rw-r--r--usr.sbin/ppp/chat.c5
-rw-r--r--usr.sbin/ppp/ipcp.c3
-rw-r--r--usr.sbin/ppp/lcp.c18
-rw-r--r--usr.sbin/ppp/main.c8
-rw-r--r--usr.sbin/ppp/modem.c109
-rw-r--r--usr.sbin/ppp/modem.h5
-rw-r--r--usr.sbin/ppp/os.c21
-rw-r--r--usr.sbin/ppp/os.h5
-rw-r--r--usr.sbin/ppp/phase.c4
-rw-r--r--usr.sbin/ppp/vars.c6
11 files changed, 97 insertions, 93 deletions
diff --git a/usr.sbin/ppp/async.c b/usr.sbin/ppp/async.c
index 99ef1ad..aa93865 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.11 1997/08/25 00:29:05 brian Exp $
+ * $Id: async.c,v 1.12 1997/10/26 01:02:05 brian Exp $
*
*/
#include <sys/param.h>
@@ -129,7 +129,7 @@ AsyncOutput(int pri, struct mbuf *bp, int proto)
cnt = cp - hs->xbuff;
LogDumpBuff(LogASYNC, "WriteModem", hs->xbuff, cnt);
WriteModem(pri, (char *) hs->xbuff, cnt);
- OsAddOutOctets(cnt);
+ ModemAddOutOctets(cnt);
pfree(bp);
}
@@ -181,7 +181,7 @@ AsyncInput(u_char *buff, int cnt)
{
struct mbuf *bp;
- OsAddInOctets(cnt);
+ ModemAddInOctets(cnt);
if (DEV_IS_SYNC) {
bp = mballoc(cnt, MB_ASYNC);
memcpy(MBUF_CTOP(bp), buff, cnt);
diff --git a/usr.sbin/ppp/chat.c b/usr.sbin/ppp/chat.c
index d079f84..58d61b3 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.34 1997/10/24 22:36:27 brian Exp $
+ * $Id: chat.c,v 1.35 1997/10/26 01:02:22 brian Exp $
*
* TODO:
* o Support more UUCP compatible control sequences.
@@ -638,9 +638,6 @@ DoChat(char *script)
SendString(*argv++);
break;
case ABORT:
-#ifdef notdef
- HangupModem();
-#endif
case NOMATCH:
signal(SIGINT, oint);
return (NOMATCH);
diff --git a/usr.sbin/ppp/ipcp.c b/usr.sbin/ppp/ipcp.c
index c9942fe..6752d53 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.31 1997/10/26 01:02:54 brian Exp $
+ * $Id: ipcp.c,v 1.32 1997/10/26 12:42:11 brian Exp $
*
* TODO:
* o More RFC1772 backwoard compatibility
@@ -296,6 +296,7 @@ IpcpLayerDown(struct fsm * fp)
LogPrintf(LogIPCP, "%d octets in, %d octets out\n",
IpcpOctetsIn(), IpcpOctetsOut());
StopTimer(&IpcpReportTimer);
+ Prompt();
}
/*
diff --git a/usr.sbin/ppp/lcp.c b/usr.sbin/ppp/lcp.c
index 0d1e6a3..38e96e4 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.40 1997/10/26 01:02:57 brian Exp $
+ * $Id: lcp.c,v 1.41 1997/10/26 12:42:11 brian Exp $
*
* TODO:
* o Validate magic number received from peer.
@@ -311,12 +311,10 @@ static void
LcpLayerFinish(struct fsm * fp)
{
LogPrintf(LogLCP, "LcpLayerFinish\n");
- OsCloseLink(1);
- NewPhase(PHASE_DEAD);
+ HangupModem(0);
StopAllTimers();
- (void) OsInterfaceDown(0);
/* We're down at last. Lets tell background and direct mode to get out */
- NewPhase(PHASE_TERMINATE);
+ NewPhase(PHASE_DEAD);
LcpInit();
IpcpInit();
CcpInit();
@@ -363,13 +361,9 @@ void
LcpDown()
{ /* Sudden death */
LcpFailedMagic = 0;
- NewPhase(PHASE_DEAD);
- StopAllTimers();
FsmDown(&LcpFsm);
- /*
- * We now wait for the FsmDown() to result in a LcpLayerDown() (if we're
- * open).
- */
+ /* FsmDown() results in a LcpLayerDown() if we're currently open. */
+ LcpLayerFinish(&LcpFsm);
}
void
@@ -383,6 +377,8 @@ LcpOpen(int mode)
void
LcpClose()
{
+ NewPhase(PHASE_TERMINATE);
+ OsInterfaceDown(0);
FsmClose(&LcpFsm);
LcpFailedMagic = 0;
}
diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c
index ae27355..aeb4640 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.84 1997/10/24 22:36:30 brian Exp $
+ * $Id: main.c,v 1.85 1997/10/26 01:03:14 brian Exp $
*
* TODO:
* o Add commands for traffic summary, version display, etc.
@@ -173,14 +173,13 @@ TtyOldMode()
void
Cleanup(int excode)
{
- OsLinkdown();
- OsCloseLink(1);
+ OsInterfaceDown(1);
+ HangupModem(1);
nointr_sleep(1);
if (mode & MODE_AUTO)
DeleteIfRoutes(1);
(void) unlink(pid_filename);
(void) unlink(if_filename);
- OsInterfaceDown(1);
if (mode & MODE_BACKGROUND && BGFiledes[1] != -1) {
char c = EX_ERRDEAD;
@@ -800,7 +799,6 @@ DoLoop()
reconnectState = RECON_UNKNOWN;
tries = 0;
} else {
- CloseModem();
if (mode & MODE_BACKGROUND) {
if (VarNextPhone == NULL || res == EX_SIG)
Cleanup(EX_DIAL); /* Tried all numbers - no luck */
diff --git a/usr.sbin/ppp/modem.c b/usr.sbin/ppp/modem.c
index ea5db79..b551139 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.59 1997/10/24 22:36:31 brian Exp $
+ * $Id: modem.c,v 1.60 1997/10/26 01:03:24 brian Exp $
*
* TODO:
*/
@@ -76,6 +76,8 @@ static struct mbuf *modemout;
static struct mqueue OutputQueues[PRI_LINK + 1];
static int dev_is_modem;
+static void CloseLogicalModem(void);
+
void
Enqueue(struct mqueue * queue, struct mbuf * bp)
{
@@ -266,22 +268,13 @@ IntToSpeed(int nspeed)
}
static time_t uptime;
+u_long OctetsIn, OctetsOut;
void
DownConnection()
{
- char ScriptBuffer[200];
-
LogPrintf(LogPHASE, "Disconnected!\n");
- if (uptime)
- LogPrintf(LogPHASE, "Connect time: %d secs\n", time(NULL) - uptime);
- uptime = 0;
- strcpy(ScriptBuffer, VarHangupScript); /* arrays are the same size */
- DoChat(ScriptBuffer);
- if (!TermMode) {
- CloseModem();
- LcpDown();
- }
+ LcpDown();
}
/*
@@ -309,10 +302,7 @@ ModemTimeout()
change = ombits ^ mbits;
if (change & TIOCM_CD) {
if (Online) {
- time(&uptime);
- LogPrintf(LogPHASE, "*Connected!\n");
- connect_count++;
-
+ LogPrintf(LogDEBUG, "ModemTimeout: offline -> online\n");
/*
* In dedicated mode, start packet mode immediate after we detected
* carrier.
@@ -320,18 +310,17 @@ ModemTimeout()
if (mode & MODE_DEDICATED)
PacketMode();
} else {
+ LogPrintf(LogDEBUG, "ModemTimeout: online -> offline\n");
reconnect(RECON_TRUE);
DownConnection();
}
}
+ else
+ LogPrintf(LogDEBUG, "ModemTimeout: Still %sline\n",
+ Online ? "on" : "off");
} else if (!Online) {
/* mbits was set to zero in OpenModem() */
- time(&uptime);
- LogPrintf(LogPHASE, "Connected!\n");
mbits = TIOCM_CD;
- connect_count++;
- } else if (uptime == 0) {
- time(&uptime);
}
}
@@ -426,7 +415,7 @@ OpenConnection(char *host, char *port)
return (-1);
}
}
- LogPrintf(LogPHASE, "Connected to %s:%s\n", host, port);
+ LogPrintf(LogPHASE, "Connecting to %s:%s\n", host, port);
sock = socket(PF_INET, SOCK_STREAM, 0);
if (sock < 0) {
@@ -486,6 +475,15 @@ UnlockModem()
LogPrintf(LogALERT, "Warning: Can't uu_unlock %s\n", fn);
}
+static void
+HaveModem()
+{
+ time(&uptime);
+ OctetsIn = OctetsOut = 0;
+ connect_count++;
+ LogPrintf(LogPHASE, "Connected!\n");
+}
+
static struct termios modemios;
int
@@ -499,6 +497,7 @@ OpenModem(int mode)
LogPrintf(LogDEBUG, "OpenModem: Modem is already open!\n");
/* We're going back into "term" mode */
else if (mode & MODE_DIRECT) {
+ HaveModem();
if (isatty(0)) {
LogPrintf(LogDEBUG, "OpenModem(direct): Modem is a tty\n");
cp = ttyname(0);
@@ -511,6 +510,7 @@ OpenModem(int mode)
} else {
LogPrintf(LogDEBUG, "OpenModem(direct): Modem is not a tty\n");
SetVariable(0, 0, 0, VAR_DEVICE);
+ /* We don't call ModemTimeout() with this type of connection */
return modem = 0;
}
} else {
@@ -524,6 +524,7 @@ OpenModem(int mode)
UnlockModem();
return (-1);
}
+ HaveModem();
LogPrintf(LogDEBUG, "OpenModem: Modem is %s\n", VarDevice);
} else {
/* PPP over TCP */
@@ -537,6 +538,7 @@ OpenModem(int mode)
*cp = ':'; /* Don't destroy VarDevice */
if (modem < 0)
return (-1);
+ HaveModem();
LogPrintf(LogDEBUG, "OpenModem: Modem is socket %s\n", VarDevice);
} else {
*cp = ':'; /* Don't destroy VarDevice */
@@ -597,7 +599,8 @@ OpenModem(int mode)
if (ioctl(modem, TIOCMGET, &mbits)) {
LogPrintf(LogERROR, "OpenModem: Cannot get modem status: %s\n",
strerror(errno));
- CloseModem();
+ uptime = 0;
+ CloseLogicalModem();
return (-1);
}
LogPrintf(LogDEBUG, "OpenModem: modem control = %o\n", mbits);
@@ -606,7 +609,8 @@ OpenModem(int mode)
if (oldflag < 0) {
LogPrintf(LogERROR, "OpenModem: Cannot get modem flags: %s\n",
strerror(errno));
- CloseModem();
+ uptime = 0;
+ CloseLogicalModem();
return (-1);
}
(void) fcntl(modem, F_SETFL, oldflag & ~O_NONBLOCK);
@@ -670,15 +674,50 @@ UnrawModem(int modem)
}
}
+void ModemAddInOctets(int n)
+{
+ OctetsIn += n;
+}
+
+void ModemAddOutOctets(int n)
+{
+ OctetsOut += n;
+}
+
+static void
+ClosePhysicalModem()
+{
+ close(modem);
+ if (uptime) {
+ LogPrintf(LogPHASE, "Connect time: %d secs\n", time(NULL) - uptime);
+ LogPrintf(LogPHASE, "Modem: %d octets in, %d octets out\n",
+ OctetsIn, OctetsOut);
+ OctetsIn = OctetsOut = 0;
+ uptime = 0;
+ }
+ modem = -1; /* Mark modem as closed */
+}
+
void
HangupModem(int flag)
{
struct termios tio;
+ LogPrintf(LogDEBUG, "Hangup modem (%s), uptime %ld\n",
+ modem >= 0 ? "open" : "closed", (long)uptime);
+ StopTimer(&ModemTimer);
+
+ if (modem < 0)
+ return;
+
+ if (TermMode) {
+ LogPrintf(LogDEBUG, "HangupModem: Not in 'term' mode\n");
+ return;
+ }
+
if (!isatty(modem)) {
mbits &= ~TIOCM_DTR;
- close(modem);
- modem = -1; /* Mark as modem has closed */
+ ClosePhysicalModem();
return;
}
@@ -697,13 +736,6 @@ HangupModem(int flag)
* directed to quit program.
*/
if (modem >= 0 && (flag || !(mode & MODE_DEDICATED))) {
- ModemTimeout(); /* XXX */
- StopTimer(&ModemTimer); /* XXX */
-
- /*
- * ModemTimeout() may call DownConection() to close the modem resulting
- * in modem == -1.
- */
if (modem >= 0) {
char ScriptBuffer[200];
@@ -711,7 +743,7 @@ HangupModem(int flag)
DoChat(ScriptBuffer);
tcflush(modem, TCIOFLUSH);
UnrawModem(modem);
- CloseModem();
+ CloseLogicalModem();
}
} else if (modem >= 0) {
char ScriptBuffer[200];
@@ -729,11 +761,11 @@ HangupModem(int flag)
}
}
-void
-CloseModem()
+static void
+CloseLogicalModem()
{
if (modem >= 0) {
- close(modem);
+ ClosePhysicalModem();
if (Utmp) {
struct utmp ut;
strncpy(ut.ut_line, VarBaseDevice, sizeof(ut.ut_line)-1);
@@ -741,12 +773,11 @@ CloseModem()
if (logout(ut.ut_line))
logwtmp(ut.ut_line, "", "");
else
- LogPrintf(LogERROR, "CloseModem: No longer logged in on %s\n",
+ LogPrintf(LogERROR, "CloseLogicalModem: No longer logged in on %s\n",
ut.ut_line);
Utmp = 0;
}
UnlockModem();
- modem = -1;
}
}
diff --git a/usr.sbin/ppp/modem.h b/usr.sbin/ppp/modem.h
index 8ca3868..3281e41 100644
--- a/usr.sbin/ppp/modem.h
+++ b/usr.sbin/ppp/modem.h
@@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: modem.h,v 1.10 1997/10/26 01:03:25 brian Exp $
+ * $Id: modem.h,v 1.11 1997/10/26 12:42:13 brian Exp $
*
* TODO:
*/
@@ -26,7 +26,6 @@ extern void DownModem(int);
extern void WriteModem(int, char *, int);
extern void ModemStartOutput(int);
extern int OpenModem(int);
-extern void CloseModem(void);
extern int ModemSpeed(void);
extern int ModemQlen(void);
extern int DialModem(void);
@@ -39,3 +38,5 @@ extern void HangupModem(int);
extern int ShowModemStatus(void);
extern void Enqueue(struct mqueue *, struct mbuf *);
extern struct mbuf *Dequeue(struct mqueue *);
+extern void ModemAddInOctets(int);
+extern void ModemAddOutOctets(int);
diff --git a/usr.sbin/ppp/os.c b/usr.sbin/ppp/os.c
index 54c18cc..233c535 100644
--- a/usr.sbin/ppp/os.c
+++ b/usr.sbin/ppp/os.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: os.c,v 1.27 1997/09/03 02:08:20 brian Exp $
+ * $Id: os.c,v 1.28 1997/10/26 01:03:26 brian Exp $
*
*/
#include <sys/param.h>
@@ -240,13 +240,12 @@ OsLinkdown()
int Level;
if (linkup) {
- FsmDown(&CcpFsm); /* CCP must come down */
-
s = (char *) inet_ntoa(peer_addr);
Level = LogIsKept(LogLINK) ? LogLINK : LogIPCP;
LogPrintf(Level, "OsLinkdown: %s\n", s);
FsmDown(&IpcpFsm); /* IPCP must come down */
+ FsmDown(&CcpFsm); /* CCP must come down */
if (!(mode & MODE_AUTO))
DeleteIfRoutes(0);
@@ -393,19 +392,3 @@ OpenTunnel(int *ptun)
close(s);
return (0);
}
-
-void
-OsCloseLink(int flag)
-{
- HangupModem(flag);
-}
-
-void
-OsAddInOctets(int cnt)
-{
-}
-
-void
-OsAddOutOctets(int cnt)
-{
-}
diff --git a/usr.sbin/ppp/os.h b/usr.sbin/ppp/os.h
index 75c7ace..d95ce0d 100644
--- a/usr.sbin/ppp/os.h
+++ b/usr.sbin/ppp/os.h
@@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: os.h,v 1.8 1997/09/03 00:40:50 brian Exp $
+ * $Id: os.h,v 1.9 1997/10/26 01:03:27 brian Exp $
*
* TODO:
*/
@@ -26,11 +26,8 @@ int OsSetIpaddress(struct in_addr, struct in_addr, struct in_addr);
int OsInterfaceDown(int);
void OsSetInterfaceParams(int, int, int);
int OpenTunnel(int *);
-void OsCloseLink(int);
void OsLinkup(void);
int OsLinkIsUp(void);
void OsLinkdown(void);
void OsSetRoute(int, struct in_addr, struct in_addr, struct in_addr);
void DeleteIfRoutes(int);
-void OsAddInOctets(int);
-void OsAddOutOctets(int);
diff --git a/usr.sbin/ppp/phase.c b/usr.sbin/ppp/phase.c
index b1dc7e9..61d5698 100644
--- a/usr.sbin/ppp/phase.c
+++ b/usr.sbin/ppp/phase.c
@@ -1,5 +1,5 @@
/*
- * $Id: $
+ * $Id: phase.c,v 1.1 1997/10/26 01:03:31 brian Exp $
*/
#include <sys/param.h>
@@ -56,7 +56,7 @@ NewPhase(int new)
CcpUp();
CcpOpen();
break;
- case PHASE_TERMINATE:
+ case PHASE_DEAD:
if (mode & MODE_DIRECT)
Cleanup(EX_DEAD);
if (mode & MODE_BACKGROUND && reconnectState != RECON_TRUE)
diff --git a/usr.sbin/ppp/vars.c b/usr.sbin/ppp/vars.c
index cbd78e3..9041132 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.30 1997/09/22 23:59:16 brian Exp $
+ * $Id: vars.c,v 1.31 1997/10/26 01:03:58 brian Exp $
*
*/
#include <sys/param.h>
@@ -39,8 +39,8 @@
#include "auth.h"
#include "defs.h"
-char VarVersion[] = "PPP Version 1.2";
-char VarLocalVersion[] = "$Date: 1997/09/22 23:59:16 $";
+char VarVersion[] = "PPP Version 1.3";
+char VarLocalVersion[] = "$Date: 1997/10/26 01:03:58 $";
int Utmp = 0;
int ipInOctets = 0;
int ipOutOctets = 0;
OpenPOWER on IntegriCloud