summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ppp/main.c
diff options
context:
space:
mode:
authoramurai <amurai@FreeBSD.org>1995-10-08 14:57:32 +0000
committeramurai <amurai@FreeBSD.org>1995-10-08 14:57:32 +0000
commitc3dd7bc8c4ca398805d9de9926b5c543e1583de2 (patch)
tree6191ac0c05a48855f47ca8021db27f90e9e9df2b /usr.sbin/ppp/main.c
parent99a5efe547ff58ca59949ed56537d97e3c60180e (diff)
downloadFreeBSD-src-c3dd7bc8c4ca398805d9de9926b5c543e1583de2.zip
FreeBSD-src-c3dd7bc8c4ca398805d9de9926b5c543e1583de2.tar.gz
1. Add a settable redial timer and logging of the process id in a file.
A settable redial timer helps to avoid the problem where both ends of a link want to dial at the same time and the line winds up busy for both ends. The process id is logged in /var/run/PPP.system where system is the name of the called system. When both ends of a link are running in demand dial mode, you need an easy way to get the pid of the ppp on the called end so it can be killed and re-started with -direct or pppd started to handle the incoming ppp session. 2. Add secret description for "set timeout" to man. Reviewed by: Atsushi Murai <amurai@spec.co.jp> Submitted by: John Capo <jc@irbs.com>
Diffstat (limited to 'usr.sbin/ppp/main.c')
-rw-r--r--usr.sbin/ppp/main.c93
1 files changed, 64 insertions, 29 deletions
diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c
index 6703085..42ef92e 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.9 1995/09/17 16:14:48 amurai Exp $
+ * $Id: main.c,v 1.10 1995/09/18 12:41:52 bde Exp $
*
* TODO:
* o Add commands for traffic summary, version display, etc.
@@ -25,6 +25,7 @@
*/
#include "fsm.h"
#include <fcntl.h>
+#include <paths.h>
#include <sys/time.h>
#include <termios.h>
#include <signal.h>
@@ -66,6 +67,7 @@ static struct termios comtio; /* Command level tty mode */
static int TermMode;
static int server, update;
struct sockaddr_in ifsin;
+char pid_filename[128];
static void
TtyInit()
@@ -148,8 +150,10 @@ int excode;
OsLinkdown();
OsCloseLink(1);
sleep(1);
- if (mode & MODE_AUTO)
+ if (mode & MODE_AUTO) {
DeleteIfRoutes(1);
+ unlink(pid_filename);
+ }
OsInterfaceDown(1);
LogPrintf(LOG_PHASE, "PPP Terminated.\n");
LogClose();
@@ -366,8 +370,22 @@ char **argv;
DupLog();
if (!(mode & MODE_DIRECT)) {
+ int fd;
+ char pid[32];
+
if (fork())
exit(0);
+
+ snprintf(pid_filename, sizeof (pid_filename), "%s/PPP.%s",
+ _PATH_VARRUN, dstsystem);
+ unlink(pid_filename);
+ sprintf(pid, "%d\n", getpid());
+
+ if ((fd = open(pid_filename, O_RDWR|O_CREAT, 0666)) != -1)
+ {
+ write(fd, pid, strlen(pid));
+ close(fd);
+ }
}
LogPrintf(LOG_PHASE, "Listening at %d.\n", port);
#ifdef DOTTYINIT
@@ -567,12 +585,20 @@ RedialTimeout()
static void
StartRedialTimer()
{
- LogPrintf(LOG_PHASE, "Enter pause for redialing.\n");
StopTimer(&RedialTimer);
- RedialTimer.state = TIMER_STOPPED;
- RedialTimer.load = REDIAL_PERIOD * SECTICKS;
- RedialTimer.func = RedialTimeout;
- StartTimer(&RedialTimer);
+
+ if (VarRedialTimeout) {
+ LogPrintf(LOG_PHASE, "Enter pause for redialing.\n");
+ RedialTimer.state = TIMER_STOPPED;
+
+ if (VarRedialTimeout > 0)
+ RedialTimer.load = VarRedialTimeout * SECTICKS;
+ else
+ RedialTimer.load = (random() % REDIAL_PERIOD) * SECTICKS;
+
+ RedialTimer.func = RedialTimeout;
+ StartTimer(&RedialTimer);
+ }
}
@@ -587,6 +613,7 @@ DoLoop()
u_char *cp;
u_char rbuff[MAX_MRU];
int dial_up;
+ int tries;
int qlen;
pid_t pgroup;
@@ -603,13 +630,11 @@ DoLoop()
fflush(stdout);
-#ifdef SIGALRM
timeout.tv_sec = 0;
-#else
timeout.tv_usec = 0;
-#endif
dial_up = FALSE; /* XXXX */
+ tries = 0;
for (;;) {
if ( modem )
IpStartOutput();
@@ -623,22 +648,30 @@ DoLoop()
#ifdef DEBUG
logprintf("going to dial: modem = %d\n", modem);
#endif
- modem = OpenModem(mode);
- if (modem < 0) {
- modem = 0; /* Set intial value for next OpenModem */
- StartRedialTimer();
- } else {
- if (DialModem()) {
- sleep(1); /* little pause to allow peer starts */
- ModemTimeout();
- PacketMode();
- dial_up = FALSE;
- } else {
- CloseModem();
- /* Dial failed. Keep quite during redial wait period. */
- StartRedialTimer();
- }
- }
+ modem = OpenModem(mode);
+ if (modem < 0) {
+ modem = 0; /* Set intial value for next OpenModem */
+ StartRedialTimer();
+ } else {
+ tries++;
+ LogPrintf(LOG_CHAT, "Dial attempt %u\n", tries);
+ if (DialModem()) {
+ sleep(1); /* little pause to allow peer starts */
+ ModemTimeout();
+ PacketMode();
+ dial_up = FALSE;
+ tries = 0;
+ } else {
+ CloseModem();
+ /* Dial failed. Keep quite during redial wait period. */
+ StartRedialTimer();
+
+ if (VarDialTries && tries >= VarDialTries) {
+ dial_up = FALSE;
+ tries = 0;
+ }
+ }
+ }
}
qlen = ModemQlen();
if (modem) {
@@ -682,9 +715,11 @@ DoLoop()
/*
* When SIGALRM timer is running, a select function will be
* return -1 and EINTR after a Time Service signal hundler
- * is done.
+ * is done. If the redial timer is not running and we are
+ * trying to dial, poll with a 0 value timer.
*/
- i = select(tun_in+10, &rfds, &wfds, &efds, NULL);
+ tp = (dial_up && RedialTimer.state != TIMER_RUNNING) ? &timeout : NULL;
+ i = select(tun_in+10, &rfds, &wfds, &efds, tp);
#endif
if ( i == 0 ) {
continue;
@@ -692,7 +727,7 @@ DoLoop()
if ( i < 0 ) {
if ( errno == EINTR ) {
- continue; /* Got SIGALRM, Do check a queue for dailing */
+ continue; /* Got SIGALRM, Do check a queue for dialing */
}
perror("select");
break;
OpenPOWER on IntegriCloud