summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorbrian <brian@cvs.openbsd.org>1998-01-20 22:46:33 +0000
committerbrian <brian@cvs.openbsd.org>1998-01-20 22:46:33 +0000
commit3d2201a7982c109e8fc6c5a6a83083f7c0a26303 (patch)
tree2d37ccc60ab36afd94ca01e70d677e7fcb350e71 /usr.sbin
parent9c88dd386e8011d11f46ffbeec2a412dc2c9edc5 (diff)
Allow an optional delay when specifying "set openmode active".
The delay defaults to 1 sec (as it always has) unless we've done a ~p in interactive mode or we've actually detected a HDLC frame. This is now cleanly implemented (via async timers) so that it is possible for LCP to come up despite the delay if an LCP REQ is received. This will hopefully solve situations with slow servers or slirp scenarios (where ECHO is left on the port for a second or so before the peer enters packet mode). Also, ~p in interactive mode no longer changes the value of the default openmode delay and -dedicated mode enters packet mode in the right state according to the value of openmode.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/ppp/ccp.c11
-rw-r--r--usr.sbin/ppp/command.c11
-rw-r--r--usr.sbin/ppp/fsm.c37
-rw-r--r--usr.sbin/ppp/fsm.h6
-rw-r--r--usr.sbin/ppp/ipcp.c9
-rw-r--r--usr.sbin/ppp/lcp.c16
-rw-r--r--usr.sbin/ppp/main.c22
-rw-r--r--usr.sbin/ppp/main.h4
-rw-r--r--usr.sbin/ppp/modem.c4
-rw-r--r--usr.sbin/ppp/ppp.821
-rw-r--r--usr.sbin/ppp/vars.c6
-rw-r--r--usr.sbin/ppp/vars.h4
12 files changed, 94 insertions, 57 deletions
diff --git a/usr.sbin/ppp/ccp.c b/usr.sbin/ppp/ccp.c
index 6b6a960858c..14e87012753 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.8 1998/01/10 01:55:13 brian Exp $
+ * $Id: ccp.c,v 1.9 1998/01/20 22:46:21 brian Exp $
*
* TODO:
* o Support other compression protocols
@@ -59,12 +59,13 @@ struct fsm CcpFsm = {
"CCP",
PROTO_CCP,
CCP_MAXCODE,
- OPEN_ACTIVE,
+ 0,
ST_INITIAL,
0, 0, 0,
0,
- {0, 0, 0, NULL, NULL, NULL},
- {0, 0, 0, NULL, NULL, NULL},
+ {0, 0, 0, NULL, NULL, NULL}, /* FSM timer */
+ {0, 0, 0, NULL, NULL, NULL}, /* Open timer */
+ {0, 0, 0, NULL, NULL, NULL}, /* Stopped timer */
LogCCP,
CcpLayerUp,
@@ -270,7 +271,7 @@ CcpOpen()
for (f = 0; f < NALGORITHMS; f++)
if (Enabled(algorithm[f]->Conf)) {
- CcpFsm.open_mode = OPEN_ACTIVE;
+ CcpFsm.open_mode = 0;
FsmOpen(&CcpFsm);
break;
}
diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c
index 0b7c0698f29..c36ea1a4d6c 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.23 1998/01/18 20:47:19 brian Exp $
+ * $Id: command.c,v 1.24 1998/01/20 22:46:23 brian Exp $
*
*/
#include <sys/param.h>
@@ -190,9 +190,8 @@ DialCommand(struct cmdargs const *arg)
break;
}
if ((res = DialModem()) == EX_DONE) {
- nointr_sleep(1);
ModemTimeout(NULL);
- PacketMode();
+ PacketMode(VarOpenMode);
break;
} else if (res == EX_SIG)
return 1;
@@ -1400,9 +1399,9 @@ static int
SetOpenMode(struct cmdargs const *arg)
{
if (arg->argc > 0) {
- if (strcmp(*arg->argv, "active") == 0)
- VarOpenMode = OPEN_ACTIVE;
- else if (strcmp(*arg->argv, "passive") == 0)
+ if (strcasecmp(*arg->argv, "active") == 0)
+ VarOpenMode = arg->argc > 1 ? atoi(arg->argv[1]) : 1;
+ else if (strcasecmp(*arg->argv, "passive") == 0)
VarOpenMode = OPEN_PASSIVE;
else
return -1;
diff --git a/usr.sbin/ppp/fsm.c b/usr.sbin/ppp/fsm.c
index 32b2c053263..4bc97622424 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.5 1998/01/10 01:55:15 brian Exp $
+ * $Id: fsm.c,v 1.6 1998/01/20 22:46:24 brian Exp $
*
* TODO:
* o Refer loglevel for log output
@@ -68,6 +68,11 @@ StoppedTimeout(void *v)
struct fsm *fp = (struct fsm *)v;
LogPrintf(fp->LogLevel, "Stopped timer expired\n");
+ if (fp->OpenTimer.state == TIMER_RUNNING) {
+ LogPrintf(LogWARN, "%s: aborting open delay due to stopped timer\n",
+ fp->name);
+ StopTimer(&fp->OpenTimer);
+ }
if (modem != -1)
DownConnection();
else
@@ -122,6 +127,19 @@ FsmOutput(struct fsm * fp, u_int code, u_int id, u_char * ptr, int count)
HdlcOutput(PRI_LINK, fp->proto, bp);
}
+static void
+FsmOpenNow(void *v)
+{
+ struct fsm *fp = (struct fsm *)v;
+
+ StopTimer(&fp->OpenTimer);
+ if (fp->state <= ST_STOPPED) {
+ FsmInitRestartCounter(fp);
+ FsmSendConfigReq(fp);
+ NewState(fp, ST_REQSENT);
+ }
+}
+
void
FsmOpen(struct fsm * fp)
{
@@ -135,11 +153,18 @@ FsmOpen(struct fsm * fp)
case ST_CLOSED:
if (fp->open_mode == OPEN_PASSIVE) {
NewState(fp, ST_STOPPED);
- } else {
- FsmInitRestartCounter(fp);
- FsmSendConfigReq(fp);
- NewState(fp, ST_REQSENT);
- }
+ } else if (fp->open_mode > 0) {
+ if (fp->open_mode > 1)
+ LogPrintf(LogPHASE, "Entering STOPPED state for %d seconds\n",
+ fp->open_mode);
+ NewState(fp, ST_STOPPED);
+ fp->OpenTimer.state = TIMER_STOPPED;
+ fp->OpenTimer.load = fp->open_mode * SECTICKS;
+ fp->OpenTimer.func = FsmOpenNow;
+ fp->OpenTimer.arg = (void *)fp;
+ StartTimer(&fp->OpenTimer);
+ } else
+ FsmOpenNow(fp);
break;
case ST_STOPPED: /* XXX: restart option */
case ST_REQSENT:
diff --git a/usr.sbin/ppp/fsm.h b/usr.sbin/ppp/fsm.h
index 8f17c7b588b..13872f208f3 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.3 1998/01/10 01:55:15 brian Exp $
+ * $Id: fsm.h,v 1.4 1998/01/20 22:46:25 brian Exp $
*
* TODO:
*/
@@ -43,8 +43,7 @@
#define MODE_NOP 3
#define MODE_ACK 4 /* pseudo mode for ccp negotiations */
-#define OPEN_ACTIVE 0
-#define OPEN_PASSIVE 1
+#define OPEN_PASSIVE -1
struct fsm {
const char *name; /* Name of protocol */
@@ -58,6 +57,7 @@ struct fsm {
int reqcode; /* Request code sent */
struct pppTimer FsmTimer; /* Restart Timer */
+ struct pppTimer OpenTimer; /* Delay before opening */
/*
* This timer times the ST_STOPPED state out after the given value
diff --git a/usr.sbin/ppp/ipcp.c b/usr.sbin/ppp/ipcp.c
index f0ba334a9c2..137611fbcdf 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.11 1998/01/18 20:47:20 brian Exp $
+ * $Id: ipcp.c,v 1.12 1998/01/20 22:46:25 brian Exp $
*
* TODO:
* o More RFC1772 backwoard compatibility
@@ -84,13 +84,14 @@ struct fsm IpcpFsm = {
"IPCP",
PROTO_IPCP,
IPCP_MAXCODE,
- OPEN_ACTIVE,
+ 0,
ST_INITIAL,
0, 0, 0,
0,
- {0, 0, 0, NULL, NULL, NULL},
- {0, 0, 0, NULL, NULL, NULL},
+ {0, 0, 0, NULL, NULL, NULL}, /* FSM timer */
+ {0, 0, 0, NULL, NULL, NULL}, /* Open timer */
+ {0, 0, 0, NULL, NULL, NULL}, /* Stopped timer */
LogIPCP,
IpcpLayerUp,
diff --git a/usr.sbin/ppp/lcp.c b/usr.sbin/ppp/lcp.c
index 8b915de11f7..edefcd306b3 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.6 1998/01/11 17:55:19 brian Exp $
+ * $Id: lcp.c,v 1.7 1998/01/20 22:46:26 brian Exp $
*
* TODO:
* o Validate magic number received from peer.
@@ -120,12 +120,13 @@ struct fsm LcpFsm = {
"LCP", /* Name of protocol */
PROTO_LCP, /* Protocol Number */
LCP_MAXCODE,
- OPEN_ACTIVE,
+ 1, /* Open mode delay */
ST_INITIAL, /* State of machine */
0, 0, 0,
0,
- {0, 0, 0, NULL, NULL, NULL},
- {0, 0, 0, NULL, NULL, NULL},
+ {0, 0, 0, NULL, NULL, NULL}, /* FSM timer */
+ {0, 0, 0, NULL, NULL, NULL}, /* Open timer */
+ {0, 0, 0, NULL, NULL, NULL}, /* Stopped timer */
LogLCP,
LcpLayerUp,
@@ -179,8 +180,11 @@ ReportLcpStatus(struct cmdargs const *arg)
lcp->want_acfcomp, (u_long)lcp->want_magic, lcp->my_reject);
fprintf(VarTerm, "\nDefaults: MRU = %d, ACCMAP = %08lx\t",
VarMRU, (u_long)VarAccmap);
- fprintf(VarTerm, "Open Mode: %s\n",
- (VarOpenMode == OPEN_ACTIVE) ? "active" : "passive");
+ fprintf(VarTerm, "Open Mode: %s",
+ (VarOpenMode == OPEN_PASSIVE) ? "passive" : "active");
+ if (VarOpenMode > 0)
+ fprintf(VarTerm, " (delay %d)", VarOpenMode);
+ fputc('\n', VarTerm);
return 0;
}
diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c
index 1a2a18b0d5c..5e0c7358ae6 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.13 1998/01/11 17:55:19 brian Exp $
+ * $Id: main.c,v 1.14 1998/01/20 22:46:27 brian Exp $
*
* TODO:
* o Add commands for traffic summary, version display, etc.
@@ -573,7 +573,7 @@ main(int argc, char **argv)
* Turn into packet mode, where we speak PPP.
*/
void
-PacketMode()
+PacketMode(int delay)
{
if (RawModem() < 0) {
LogPrintf(LogWARN, "PacketMode: Not connected.\n");
@@ -586,7 +586,7 @@ PacketMode()
CcpInit();
LcpUp();
- LcpOpen(VarOpenMode);
+ LcpOpen(delay);
if (mode & MODE_INTER)
TtyCommandMode(1);
if (VarTerm) {
@@ -660,10 +660,8 @@ ReadTty(void)
/*
* XXX: Should check carrier.
*/
- if (LcpFsm.state <= ST_CLOSED) {
- VarOpenMode = OPEN_ACTIVE;
- PacketMode();
- }
+ if (LcpFsm.state <= ST_CLOSED)
+ PacketMode(0);
break;
case '.':
TermMode = 1;
@@ -779,7 +777,7 @@ DoLoop(void)
if (OpenModem() < 0)
return;
LogPrintf(LogPHASE, "Packet mode enabled\n");
- PacketMode();
+ PacketMode(VarOpenMode);
} else if (mode & MODE_DEDICATED) {
if (modem < 0)
while (OpenModem() < 0)
@@ -829,8 +827,7 @@ DoLoop(void)
}
reconnectState = RECON_ENVOKED;
} else if (mode & MODE_DEDICATED)
- if (VarOpenMode == OPEN_ACTIVE)
- PacketMode();
+ PacketMode(VarOpenMode);
}
/*
@@ -864,9 +861,8 @@ DoLoop(void)
LogPrintf(LogCHAT, "Dial attempt %u\n", tries);
if ((res = DialModem()) == EX_DONE) {
- nointr_sleep(1); /* little pause to allow peer starts */
ModemTimeout(NULL);
- PacketMode();
+ PacketMode(VarOpenMode);
dial_up = 0;
reconnectState = RECON_UNKNOWN;
tries = 0;
@@ -1047,7 +1043,7 @@ DoLoop(void)
write(modem, rbuff, cp - rbuff);
write(modem, "\r\n", 2);
}
- PacketMode();
+ PacketMode(0);
} else
write(fileno(VarTerm), rbuff, n);
}
diff --git a/usr.sbin/ppp/main.h b/usr.sbin/ppp/main.h
index b44c699569c..d4439eaa563 100644
--- a/usr.sbin/ppp/main.h
+++ b/usr.sbin/ppp/main.h
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: main.h,v 1.1 1997/11/23 20:27:34 brian Exp $
+ * $Id: main.h,v 1.2 1998/01/20 22:46:28 brian Exp $
*
*/
@@ -26,6 +26,6 @@ extern int tunno;
extern void Cleanup(int);
extern void TtyTermMode(void);
-extern void PacketMode(void);
+extern void PacketMode(int);
extern void TtyOldMode(void);
extern void TtyCommandMode(int);
diff --git a/usr.sbin/ppp/modem.c b/usr.sbin/ppp/modem.c
index b1bb7808b4a..fd174918f48 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.8 1998/01/10 01:55:16 brian Exp $
+ * $Id: modem.c,v 1.9 1998/01/20 22:46:29 brian Exp $
*
* TODO:
*/
@@ -266,7 +266,7 @@ ModemTimeout(void *data)
* carrier.
*/
if (mode & MODE_DEDICATED)
- PacketMode();
+ PacketMode(VarOpenMode);
} else {
LogPrintf(LogDEBUG, "ModemTimeout: online -> offline\n");
reconnect(RECON_TRUE);
diff --git a/usr.sbin/ppp/ppp.8 b/usr.sbin/ppp/ppp.8
index 8d0e77281b8..cbd0c42c3f0 100644
--- a/usr.sbin/ppp/ppp.8
+++ b/usr.sbin/ppp/ppp.8
@@ -1,4 +1,4 @@
-.\" $Id: ppp.8,v 1.15 1998/01/18 20:47:21 brian Exp $
+.\" $Id: ppp.8,v 1.16 1998/01/20 22:46:30 brian Exp $
.Dd 20 September 1995
.Os OpenBSD
.Dt PPP 8
@@ -2254,16 +2254,23 @@ will be negotiated.
.It set nbns x.x.x.x y.y.y.y
This option allows the setting of the Microsoft NetBIOS DNS servers that
will be negotiated.
-.It set openmode active|passive
+.It set openmode active|passive Op delay
By default,
.Ar openmode
is always
-.Ar active .
+.Ar active
+with a one second
+.Ar delay .
That is,
.Nm
-will always initiate LCP/IPCP/CCP negotiation. If you want to wait
-for the peer to initiate negotiations, you may use the value
+will always initiate LCP/IPCP/CCP negotiation one second after the line
+comes up. If you want to wait for the peer to initiate negotiations, you
+can use the value
.Ar passive .
+If you want to initiate negotiations immediately or after more than one
+second, the appropriate
+.Ar delay
+may be specified here in seconds.
.It set parity odd|even|none|mark
This allows the line parity to be set. The default value is
.Ar none .
@@ -2328,6 +2335,10 @@ log all state transitions.
The default value is zero, where
.Nm
doesn't time out in the stopped state.
+.Pp
+This value should not be set to less than the openmode delay (see
+.Dq set openmode
+above).
.It set server|socket TcpPort|LocalName|none [password] [mask]
This command tells
.Nm
diff --git a/usr.sbin/ppp/vars.c b/usr.sbin/ppp/vars.c
index beb4cf451b5..efb528c23dd 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.5 1998/01/10 01:55:17 brian Exp $
+ * $Id: vars.c,v 1.6 1998/01/20 22:46:32 brian Exp $
*
*/
#include <sys/param.h>
@@ -39,7 +39,7 @@
#include "auth.h"
char VarVersion[] = "PPP Version 1.65";
-char VarLocalVersion[] = "$Date: 1998/01/10 01:55:17 $";
+char VarLocalVersion[] = "$Date: 1998/01/20 22:46:32 $";
int Utmp = 0;
int ipInOctets = 0;
int ipOutOctets = 0;
@@ -73,7 +73,7 @@ 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,
- OPEN_ACTIVE, LOCAL_NO_AUTH, 0
+ 1, LOCAL_NO_AUTH, 0
};
int
diff --git a/usr.sbin/ppp/vars.h b/usr.sbin/ppp/vars.h
index 49c3d038e9f..bfc24bbe999 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.5 1998/01/11 17:54:48 brian Exp $
+ * $Id: vars.h,v 1.6 1998/01/20 22:46:32 brian Exp $
*
* TODO:
*/
@@ -73,7 +73,7 @@ struct pppvars {
char modem_devlist[LINE_LEN]; /* Comma-separated list of devices */
char modem_dev[40]; /* Name of device / host:port */
const char *base_modem_dev; /* Pointer to base of modem_dev */
- int open_mode; /* LCP open mode */
+ int open_mode; /* Delay before first LCP REQ (-1 = passive) */
#define LOCAL_AUTH 0x01
#define LOCAL_NO_AUTH 0x02
#define LOCAL_DENY 0x03