summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/ppp/bundle.c65
-rw-r--r--usr.sbin/ppp/bundle.h12
-rw-r--r--usr.sbin/ppp/command.c12
-rw-r--r--usr.sbin/ppp/defs.h3
-rw-r--r--usr.sbin/ppp/ip.c74
-rw-r--r--usr.sbin/ppp/ip.h6
-rw-r--r--usr.sbin/ppp/ipcp.c4
-rw-r--r--usr.sbin/ppp/lcp.c3
-rw-r--r--usr.sbin/ppp/vars.c6
-rw-r--r--usr.sbin/ppp/vars.h4
10 files changed, 93 insertions, 96 deletions
diff --git a/usr.sbin/ppp/bundle.c b/usr.sbin/ppp/bundle.c
index f92453ac9138..5a32e68c9431 100644
--- a/usr.sbin/ppp/bundle.c
+++ b/usr.sbin/ppp/bundle.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: bundle.c,v 1.1.2.18 1998/03/01 01:07:39 brian Exp $
+ * $Id: bundle.c,v 1.1.2.19 1998/03/02 17:25:19 brian Exp $
*/
#include <sys/param.h>
@@ -184,6 +184,7 @@ bundle_LayerUp(void *v, struct fsm *fp)
/*
* The given fsm is now up
* If it's a datalink, enter network phase
+ * If it's the first NCP, start the idle timer.
* If it's an NCP, tell our background mode parent to go away.
*/
@@ -192,7 +193,8 @@ bundle_LayerUp(void *v, struct fsm *fp)
if (fp->proto == PROTO_LCP)
bundle_NewPhase(bundle, link2physical(fp->link), PHASE_NETWORK);
- if (fp == &IpcpInfo.fsm)
+ if (fp == &IpcpInfo.fsm) {
+ bundle_StartIdleTimer(bundle);
if (mode & MODE_BACKGROUND && BGFiledes[1] != -1) {
char c = EX_NORMAL;
@@ -203,6 +205,7 @@ bundle_LayerUp(void *v, struct fsm *fp)
close(BGFiledes[1]);
BGFiledes[1] = -1;
}
+ }
}
static void
@@ -210,9 +213,13 @@ bundle_LayerDown(void *v, struct fsm *fp)
{
/*
* The given FSM has been told to come down.
- * We don't do anything here, as the FSM will eventually
- * come up or down and will call LayerUp or LayerFinish.
+ * If it's our last NCP, stop the idle timer.
*/
+
+ struct bundle *bundle = (struct bundle *)v;
+
+ if (fp->proto == PROTO_IPCP)
+ bundle_StopIdleTimer(bundle);
}
static void
@@ -384,6 +391,8 @@ bundle_Create(const char *prefix)
bundle.fsm.LayerFinish = bundle_LayerFinish;
bundle.fsm.object = &bundle;
+ bundle.cfg.idle_timeout = NCP_IDLE_TIMEOUT;
+
bundle.links = datalink_Create("Modem", &bundle, &bundle.fsm);
if (bundle.links == NULL) {
LogPrintf(LogERROR, "Cannot create data link: %s\n", strerror(errno));
@@ -732,3 +741,51 @@ bundle_ShowLinks(struct cmdargs const *arg)
return 0;
}
+
+static void
+bundle_IdleTimeout(void *v)
+{
+ struct bundle *bundle = (struct bundle *)v;
+
+ LogPrintf(LogPHASE, "IPCP Idle timer expired.\n");
+ bundle_Close(bundle, NULL, 1);
+}
+
+/*
+ * Start Idle timer. If timeout is reached, we call bundle_Close() to
+ * close LCP and link.
+ */
+void
+bundle_StartIdleTimer(struct bundle *bundle)
+{
+ if (!(mode & (MODE_DEDICATED | MODE_DDIAL))) {
+ StopTimer(&bundle->IdleTimer);
+ bundle->IdleTimer.func = bundle_IdleTimeout;
+ bundle->IdleTimer.load = bundle->cfg.idle_timeout * SECTICKS;
+ bundle->IdleTimer.state = TIMER_STOPPED;
+ bundle->IdleTimer.arg = bundle;
+ StartTimer(&bundle->IdleTimer);
+ }
+}
+
+void
+bundle_SetIdleTimer(struct bundle *bundle, int value)
+{
+ bundle->cfg.idle_timeout = value;
+ if (bundle_LinkIsUp(bundle))
+ bundle_StartIdleTimer(bundle);
+}
+
+void
+bundle_StopIdleTimer(struct bundle *bundle)
+{
+ StopTimer(&bundle->IdleTimer);
+}
+
+int
+bundle_RemainingIdleTime(struct bundle *bundle)
+{
+ if (bundle->cfg.idle_timeout == 0 || bundle->IdleTimer.state != TIMER_RUNNING)
+ return -1;
+ return bundle->IdleTimer.rest / SECTICKS;
+}
diff --git a/usr.sbin/ppp/bundle.h b/usr.sbin/ppp/bundle.h
index c1d705f55e61..549c5f0f8ccd 100644
--- a/usr.sbin/ppp/bundle.h
+++ b/usr.sbin/ppp/bundle.h
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: bundle.h,v 1.1.2.11 1998/02/27 01:22:17 brian Exp $
+ * $Id: bundle.h,v 1.1.2.12 1998/03/01 01:07:39 brian Exp $
*/
#define PHASE_DEAD 0 /* Link is dead */
@@ -47,6 +47,12 @@ struct bundle {
struct fsm_parent fsm; /* Our callback functions */
struct datalink *links; /* Our data links */
+
+ struct {
+ int idle_timeout; /* NCP Idle timeout value */
+ } cfg;
+
+ struct pppTimer IdleTimer; /* timeout after cfg.idle_timeout */
};
extern struct bundle *bundle_Create(const char *);
@@ -66,6 +72,10 @@ extern int bundle_UpdateSet(struct bundle *, fd_set *, fd_set *, fd_set *,
int *);
extern int bundle_FillQueues(struct bundle *);
extern int bundle_ShowLinks(struct cmdargs const *);
+extern void bundle_StartIdleTimer(struct bundle *);
+extern void bundle_SetIdleTimer(struct bundle *, int);
+extern void bundle_StopIdleTimer(struct bundle *);
+extern int bundle_RemainingIdleTime(struct bundle *);
extern struct link *bundle2link(struct bundle *, const char *);
extern struct physical *bundle2physical(struct bundle *, const char *);
diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c
index 3fcc286ed46b..371dc25ea1e3 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.131.2.31 1998/03/06 00:34:42 brian Exp $
+ * $Id: command.c,v 1.131.2.32 1998/03/09 19:24:53 brian Exp $
*
*/
#include <sys/param.h>
@@ -444,9 +444,9 @@ ShowTimeout(struct cmdargs const *arg)
int remaining;
prompt_Printf(&prompt, " Idle Timer: %d secs LQR Timer: %d secs"
- " Retry Timer: %d secs\n", VarIdleTimeout, VarLqrTimeout,
- VarRetryTimeout);
- remaining = RemainingIdleTime();
+ " Retry Timer: %d secs\n", arg->bundle->cfg.idle_timeout,
+ VarLqrTimeout, VarRetryTimeout);
+ remaining = bundle_RemainingIdleTime(arg->bundle);
if (remaining != -1)
prompt_Printf(&prompt, " %d secs remaining\n", remaining);
@@ -1151,9 +1151,7 @@ static int
SetIdleTimeout(struct cmdargs const *arg)
{
if (arg->argc > 0) {
- VarIdleTimeout = atoi(arg->argv[0]);
- /* If we're connected, restart the idle timer */
- UpdateIdleTimer(arg->bundle);
+ bundle_SetIdleTimer(arg->bundle, atoi(arg->argv[0]));
if (arg->argc > 1) {
VarLqrTimeout = atoi(arg->argv[1]);
if (VarLqrTimeout < 1)
diff --git a/usr.sbin/ppp/defs.h b/usr.sbin/ppp/defs.h
index 86a42b04af40..77628ac7b094 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.29.2.4 1998/03/06 00:34:43 brian Exp $
+ * $Id: defs.h,v 1.29.2.5 1998/03/09 19:24:56 brian Exp $
*
* TODO:
*/
@@ -40,6 +40,7 @@
#define SCRIPT_LEN 512 /* Size of login scripts */
#define LINE_LEN SCRIPT_LEN /* Size of login scripts */
#define MAXARGS 40 /* How many args per config line */
+#define NCP_IDLE_TIMEOUT 180 /* Drop all links */
#define CONFFILE "ppp.conf"
#define LINKUPFILE "ppp.linkup"
diff --git a/usr.sbin/ppp/ip.c b/usr.sbin/ppp/ip.c
index 102f5aff4027..007b7fc560b4 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.38.2.8 1998/02/23 00:38:32 brian Exp $
+ * $Id: ip.c,v 1.38.2.9 1998/03/02 17:25:22 brian Exp $
*
* TODO:
* o Return ICMP message for filterd packet
@@ -67,69 +67,6 @@
#include "tun.h"
#include "ip.h"
-static struct pppTimer IdleTimer;
-
-static void
-IdleTimeout(void *v)
-{
- LogPrintf(LogPHASE, "Idle timer expired.\n");
- bundle_Close(LcpInfo.fsm.bundle, NULL, 1);
-}
-
-/*
- * Start Idle timer. If timeout is reached, we call bundle_Close() to
- * close LCP and link.
- */
-void
-StartIdleTimer()
-{
- static time_t IdleStarted;
-
- if (!(mode & (MODE_DEDICATED | MODE_DDIAL))) {
- StopTimer(&IdleTimer);
- IdleTimer.func = IdleTimeout;
- IdleTimer.load = VarIdleTimeout * SECTICKS;
- IdleTimer.state = TIMER_STOPPED;
- time(&IdleStarted);
- IdleTimer.arg = (void *)&IdleStarted;
- StartTimer(&IdleTimer);
- }
-}
-
-void
-UpdateIdleTimer(const struct bundle *bundle)
-{
- if (bundle_LinkIsUp(bundle))
- StartIdleTimer();
-}
-
-void
-StopIdleTimer()
-{
- StopTimer(&IdleTimer);
-}
-
-int
-RemainingIdleTime()
-{
- if (VarIdleTimeout == 0 || IdleTimer.state != TIMER_RUNNING ||
- IdleTimer.arg == NULL)
- return -1;
- return VarIdleTimeout - (time(NULL) - *(time_t *)IdleTimer.arg);
-}
-
-/*
- * If any IP layer traffic is detected, refresh IdleTimer.
- */
-static void
-RestartIdleTimer(void)
-{
- if (!(mode & (MODE_DEDICATED | MODE_DDIAL)) && ipKeepAlive) {
- time((time_t *)IdleTimer.arg);
- StartTimer(&IdleTimer);
- }
-}
-
static const u_short interactive_ports[32] = {
544, 513, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 21, 22, 23, 0, 0, 0, 0, 0, 0, 0, 543,
@@ -261,7 +198,8 @@ IcmpError(struct ip * pip, int code)
bp = mballoc(cnt, MB_IPIN);
memcpy(MBUF_CTOP(bp), ptr, cnt);
SendPppFrame(bp);
- RestartIdleTimer();
+ if (ipKeepAlive)
+ bundle_StartIdleTimer(bundle);
IpcpAddOutOctets(cnt);
}
#endif
@@ -483,7 +421,8 @@ IpInput(struct bundle *bundle, struct mbuf * bp)
}
pfree(bp);
- RestartIdleTimer();
+ if (ipKeepAlive)
+ bundle_StartIdleTimer(bundle);
}
static struct mqueue IpOutputQueues[PRI_FAST + 1];
@@ -525,7 +464,8 @@ IpStartOutput(struct link *l, struct bundle *bundle)
if (bp) {
cnt = plength(bp);
SendPppFrame(l, bp, bundle);
- RestartIdleTimer();
+ if (ipKeepAlive)
+ bundle_StartIdleTimer(bundle);
IpcpAddOutOctets(cnt);
break;
}
diff --git a/usr.sbin/ppp/ip.h b/usr.sbin/ppp/ip.h
index 9e04a96f3e05..5803a7dad6ef 100644
--- a/usr.sbin/ppp/ip.h
+++ b/usr.sbin/ppp/ip.h
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: ip.h,v 1.8.2.3 1998/02/02 19:32:07 brian Exp $
+ * $Id: ip.h,v 1.8.2.4 1998/02/23 00:38:33 brian Exp $
*
*/
@@ -25,8 +25,4 @@ extern void IpStartOutput(struct link *, struct bundle *);
extern int PacketCheck(char *, int, int);
extern void IpEnqueue(int, char *, int);
extern void IpInput(struct bundle *, struct mbuf *);
-extern void StartIdleTimer(void);
-extern void StopIdleTimer(void);
-extern void UpdateIdleTimer(const struct bundle *);
-extern int RemainingIdleTime(void);
extern int ip_QueueLen(void);
diff --git a/usr.sbin/ppp/ipcp.c b/usr.sbin/ppp/ipcp.c
index 58c618b5f076..ea19308d8716 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.50.2.17 1998/02/27 01:22:25 brian Exp $
+ * $Id: ipcp.c,v 1.50.2.18 1998/02/27 21:46:23 brian Exp $
*
* TODO:
* o More RFC1772 backwoard compatibility
@@ -510,7 +510,6 @@ IpcpLayerDown(struct fsm *fp)
throughput_stop(&ipcp->throughput);
throughput_log(&ipcp->throughput, LogIPCP, NULL);
-
/*
* XXX this stuff should really live in the FSM. Our config should
* associate executable sections in files with events.
@@ -567,7 +566,6 @@ IpcpLayerUp(struct fsm *fp)
SelectSystem(fp->bundle, "MYADDR", LINKUPFILE);
throughput_start(&ipcp->throughput);
- StartIdleTimer();
prompt_Display(&prompt, fp->bundle);
}
diff --git a/usr.sbin/ppp/lcp.c b/usr.sbin/ppp/lcp.c
index 3ac37e8de8ac..eb815810df38 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.55.2.23 1998/03/01 01:07:45 brian Exp $
+ * $Id: lcp.c,v 1.55.2.24 1998/03/02 17:25:27 brian Exp $
*
* TODO:
* o Limit data field length by MRU
@@ -383,7 +383,6 @@ LcpLayerStart(struct fsm *fp)
static void
StopAllTimers(void)
{
- StopIdleTimer();
StopLqrTimer();
}
diff --git a/usr.sbin/ppp/vars.c b/usr.sbin/ppp/vars.c
index 11db32fd51f5..92404f34f922 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.45.2.11 1998/02/17 01:05:20 brian Exp $
+ * $Id: vars.c,v 1.45.2.12 1998/03/06 00:34:46 brian Exp $
*
*/
#include <sys/param.h>
@@ -46,7 +46,7 @@
#include "prompt.h"
char VarVersion[] = "PPP Version 2.0-beta";
-char VarLocalVersion[] = "$Date: 1998/02/17 01:05:20 $";
+char VarLocalVersion[] = "$Date: 1998/03/06 00:34:46 $";
int Utmp = 0;
int ipKeepAlive = 0;
@@ -72,7 +72,7 @@ struct confdesc pppConfs[] = {
};
struct pppvars pppVars = {
- DEF_MRU, DEF_MTU, 0, 180, 30, 3, 1, 1, LOCAL_NO_AUTH
+ DEF_MRU, DEF_MTU, 0, 30, 3, 1, 1, LOCAL_NO_AUTH
};
int
diff --git a/usr.sbin/ppp/vars.h b/usr.sbin/ppp/vars.h
index 161fbf76a815..5dfe8256e043 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.42.2.10 1998/03/06 00:34:47 brian Exp $
+ * $Id: vars.h,v 1.42.2.11 1998/03/09 19:24:58 brian Exp $
*
* TODO:
*/
@@ -58,7 +58,6 @@ struct pppvars {
u_short var_mru; /* Initial MRU value */
u_short pref_mtu; /* Preferred MTU value */
int var_accmap; /* Initial ACCMAP value */
- int idle_timeout; /* Idle timeout value */
int lqr_timeout; /* LQR timeout value */
int retry_timeout; /* Retry timeout value */
int loopback; /* Turn around packets addressed to me */
@@ -89,7 +88,6 @@ struct pppvars {
#define VarPrefMTU pppVars.pref_mtu
#define VarOpenMode pppVars.open_mode
#define VarLocalAuth pppVars.lauth
-#define VarIdleTimeout pppVars.idle_timeout
#define VarLqrTimeout pppVars.lqr_timeout
#define VarRetryTimeout pppVars.retry_timeout
#define VarAuthKey pppVars.auth_key