[390] in linux-net channel archive
Small hack for ppp idle shutdown
daemon@ATHENA.MIT.EDU (Bjorn Ekwall)
Tue May 30 05:13:16 1995
From: bj0rn@blox.se (Bjorn Ekwall)
To: callahan@maths.ox.ac.uk (Michael Callahan),
longyear@netcom.com (Al Longyear), linux-net@vger.rutgers.edu
Date: Tue, 30 May 1995 09:45:30 +0200 (CET)
Hi!
Here is a small hack that I'm using to make my ppp-connections
go down automatically after a period of IP-inactivity.
The added option to pppd is "ipidle <seconds>", as in "ipidle 600".
It's not the world's most beautiful hack, but it's usable...
Since I'm also playing with kernel requested activities, such as
automatic module loading, this pppd-option seemed like a good idea to me...
Greetings,
Bjorn Ekwall == bj0rn@blox.se
(This patch works on both ppp-2.1.2b and c)
--- lcp.c.org Mon May 29 23:51:13 1995
+++ lcp.c Tue May 30 08:56:17 1995
@@ -64,6 +64,12 @@
u_long lcp_echo_fails = 0;
/*
+ * IP activity watchdog
+ */
+u_long ipidle_time = 0;
+static void ipidle_up IPidle_watch __ARGS((fsm *));
+
+/*
* Callbacks for fsm code. (CI = Configuration Information)
*/
static void lcp_resetci __ARGS((fsm *)); /* Reset our CI */
@@ -1307,6 +1313,10 @@
ipcp_lowerup(f->unit); /* Enable IPCP */
lcp_echo_lowerup(f->unit); /* Enable echo messages */
+ /* If a timeout interval is specified then start the IP watchdog */
+ if (ipidle_time != 0)
+ IPidle_watch (f);
+
link_established(f->unit);
}
@@ -1505,6 +1515,37 @@
lcp_close(f->unit);
phase = PHASE_TERMINATE;
}
+}
+
+/*
+ * Timer expired for the IP watchdog.
+ */
+
+static void
+IPidle_watch (f)
+ fsm *f;
+{
+#ifdef __linux__
+ struct ppp_ddinfo ddinfo;
+ u_long latest;
+/*
+ * Read the time since the last IP activity.
+ */
+ if (ioctl (fd, PPPIOCGTIME, &ddinfo) < 0) {
+ syslog (LOG_ERR, "ioctl(PPPIOCGTIME): %m");
+ die (1);
+ }
+/*
+ * Choose the most recent IP activity.
+ */
+ latest = ddinfo.ip_rjiffies < ddinfo.ip_sjiffies ? ddinfo.ip_rjiffies
+ : ddinfo.ip_sjiffies;
+ if (latest >= ipidle_time * HZ)
+ kill(getpid(), 1); /* easy way out... */
+
+ else /* Check every 30 seconds */
+ TIMEOUT (IPidle_watch, (caddr_t) f, (u_long)30);
+#endif /* __linux__ */
}
/*
--- options.c.org Tue May 30 00:29:22 1995
+++ options.c Tue May 30 00:35:16 1995
@@ -120,6 +120,7 @@
static int setipcpaccl __ARGS((void));
static int setipcpaccr __ARGS((void));
static int setlcpechointv __ARGS((char **));
+static int setipidletime __ARGS((char **));
static int setlcpechofails __ARGS((char **));
static int number_option __ARGS((char *, long *, int));
@@ -149,6 +150,7 @@
extern int persist;
extern int uselogin;
extern u_long lcp_echo_interval;
+extern u_long ipidle_time;
extern u_long lcp_echo_fails;
extern char our_name[];
extern char remote_name[];
@@ -210,6 +212,7 @@
{"proxyarp", 0, setproxyarp}, /* Add proxy ARP entry */
{"persist", 0, setpersist}, /* Keep on reopening connection after close */
{"login", 0, setdologin}, /* Use system password database for UPAP */
+ {"ipidle", 1, setipidletime}, /* timeout for IP non-activity */
{"noipdefault", 0, setnoipdflt}, /* Don't use name for default IP adrs */
{"lcp-echo-failure", 1, setlcpechofails}, /* consecutive echo failures */
{"lcp-echo-interval", 1, setlcpechointv}, /* time for lcp echo events */
@@ -1349,6 +1352,17 @@
{
uselogin = 1;
return 1;
+}
+
+/*
+ * Function to set the IP activity watchdog
+ */
+
+static int
+setipidletime(argv)
+ char **argv;
+{
+ return int_option(*argv, &ipidle_time);
}
/*