diff options
author | brian <brian@FreeBSD.org> | 1997-04-14 23:48:20 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1997-04-14 23:48:20 +0000 |
commit | aebb5d896e369a2c36a4602db4912e3242a873cb (patch) | |
tree | 1368af077c877d79f95a7b9f976e3af37d0df247 | |
parent | 387d65afaacec6f13404bfd4fd8e0f0d8ca76eef (diff) | |
download | FreeBSD-src-aebb5d896e369a2c36a4602db4912e3242a873cb.zip FreeBSD-src-aebb5d896e369a2c36a4602db4912e3242a873cb.tar.gz |
Make the next number redial ability configurable. The
"set redial pause [times]" command becomes
"set redial end-pause[.next-pause] [times]" and next-pause
defaults to 3 seconds. This keeps things backwards
compatable.
Suggested by: ache
-rw-r--r-- | usr.sbin/ppp/command.c | 43 | ||||
-rw-r--r-- | usr.sbin/ppp/defs.h | 7 | ||||
-rw-r--r-- | usr.sbin/ppp/main.c | 30 | ||||
-rw-r--r-- | usr.sbin/ppp/ppp.8 | 39 | ||||
-rw-r--r-- | usr.sbin/ppp/ppp.8.m4 | 39 | ||||
-rw-r--r-- | usr.sbin/ppp/vars.c | 6 | ||||
-rw-r--r-- | usr.sbin/ppp/vars.h | 4 |
7 files changed, 113 insertions, 55 deletions
diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c index decf4f5..5a69566 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.36 1997/03/24 16:01:46 ache Exp $ + * $Id: command.c,v 1.37 1997/04/09 17:35:52 ache Exp $ * */ #include <sys/types.h> @@ -376,6 +376,15 @@ static int ShowRedial() printf(" Random 0 - %d seconds, ", REDIAL_PERIOD); } + printf(" Redial Next Timer: "); + + if (VarRedialNextTimeout >= 0) { + printf(" %d seconds, ", VarRedialNextTimeout); + } + else { + printf(" Random 0 - %d seconds, ", REDIAL_PERIOD); + } + if (VarDialTries) printf("%d dial tries", VarDialTries); @@ -650,9 +659,11 @@ char **argv; { int timeout; int tries; + char *dot; if (argc == 1 || argc == 2 ) { - if (strcasecmp(argv[0], "random") == 0) { + if (strncasecmp(argv[0], "random", 6) == 0 && + (argv[0][6] == '\0' || argv[0][6] == '.')) { VarRedialTimeout = -1; printf("Using random redial timeout.\n"); if (!randinit) { @@ -672,6 +683,32 @@ char **argv; printf("Usage: %s %s\n", list->name, list->syntax); } } + + dot = index(argv[0],'.'); + if (dot) { + if (strcasecmp(++dot, "random") == 0) { + VarRedialNextTimeout = -1; + printf("Using random next redial timeout.\n"); + if (!randinit) { + randinit = 1; + if (srandomdev() < 0) + srandom((unsigned long)(time(NULL) ^ getpid())); + } + } + else { + timeout = atoi(dot); + if (timeout >= 0) { + VarRedialNextTimeout = timeout; + } + else { + printf("invalid next redial timeout\n"); + printf("Usage: %s %s\n", list->name, list->syntax); + } + } + } + else + VarRedialNextTimeout = NEXT_REDIAL_PERIOD; /* Default next timeout */ + if (argc == 2) { tries = atoi(argv[1]); @@ -1043,7 +1080,7 @@ struct cmdtab const SetCommands[] = { { "timeout", NULL, SetIdleTimeout, LOCAL_AUTH, "Set Idle timeout", StrValue}, { "redial", NULL, SetRedialTimeout, LOCAL_AUTH, - "Set Redial timeout", "value|random [dial_attempts]"}, + "Set Redial timeout", "value|random[.value|random] [dial_attempts]"}, #ifdef MSEXT { "ns", NULL, SetNS, LOCAL_AUTH, "Set NameServer", "pri-addr [sec-addr]"}, diff --git a/usr.sbin/ppp/defs.h b/usr.sbin/ppp/defs.h index f08b276..5a9533f 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$ + * $Id: defs.h,v 1.10 1997/02/22 16:10:10 peter Exp $ * * TODO: */ @@ -45,8 +45,9 @@ #define MODEM_SPEED B38400 /* tty speed */ #define SERVER_PORT 3000 /* Base server port no. */ -#define MODEM_CTSRTS TRUE /* Default (true): use CTS/RTS signals */ -#define REDIAL_PERIOD 30 /* Default Hold time to redial */ +#define MODEM_CTSRTS TRUE /* Default (true): use CTS/RTS signals */ +#define REDIAL_PERIOD 30 /* Default Hold time to redial */ +#define NEXT_REDIAL_PERIOD 3 /* Default Hold time to next number redial */ #define CONFFILE "ppp.conf" #define LINKFILE "ppp.linkup" diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c index 04a5d26..bb876af 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.42 1997/04/12 22:58:39 brian Exp $ + * $Id: main.c,v 1.43 1997/04/13 00:54:43 brian Exp $ * * TODO: * o Add commands for traffic summary, version display, etc. @@ -682,19 +682,22 @@ RedialTimeout() } static void -StartRedialTimer() +StartRedialTimer(Timeout) + int Timeout; { StopTimer(&RedialTimer); - if (VarRedialTimeout) { - LogPrintf(LOG_PHASE_BIT, "Enter pause for redialing.\n"); + if (Timeout) { RedialTimer.state = TIMER_STOPPED; - if (VarRedialTimeout > 0) - RedialTimer.load = VarRedialTimeout * SECTICKS; + if (Timeout > 0) + RedialTimer.load = Timeout * SECTICKS; else RedialTimer.load = (random() % REDIAL_PERIOD) * SECTICKS; + LogPrintf(LOG_PHASE_BIT, "Enter pause (%d) for redialing.\n", + RedialTimer.load / SECTICKS); + RedialTimer.func = RedialTimeout; StartTimer(&RedialTimer); } @@ -759,7 +762,7 @@ DoLoop() #endif modem = OpenModem(mode); if (modem < 0) { - StartRedialTimer(); + StartRedialTimer(VarRedialTimeout); } else { tries++; /* Tries are per number, not per list of numbers. */ if (VarDialTries) @@ -779,21 +782,18 @@ DoLoop() if (VarNextPhone == NULL) Cleanup(EX_DIAL); /* Tried all numbers - no luck */ else - sleep(1); /* Try all numbers in background mode */ + /* Try all numbers in background mode */ + StartRedialTimer(VarRedialNextTimeout); } else if (VarDialTries && tries >= VarDialTries) { /* I give up ! Can't get through :( */ - StartRedialTimer(); + StartRedialTimer(VarRedialTimeout); dial_up = FALSE; tries = 0; } else if (VarNextPhone == NULL) /* Dial failed. Keep quite during redial wait period. */ - StartRedialTimer(); + StartRedialTimer(VarRedialTimeout); else - /* - * Give the modem a chance to recover, then dial the next - * number in our list - */ - sleep(1); + StartRedialTimer(VarRedialNextTimeout); } } } diff --git a/usr.sbin/ppp/ppp.8 b/usr.sbin/ppp/ppp.8 index 3d47cd2..26ad29e 100644 --- a/usr.sbin/ppp/ppp.8 +++ b/usr.sbin/ppp/ppp.8 @@ -1,5 +1,5 @@ .\" manual page [] for ppp 0.94 beta2 + alpha -.\" $Id: ppp.8,v 1.27 1997/04/12 22:58:41 brian Exp $ +.\" $Id: ppp.8,v 1.28 1997/04/13 00:54:45 brian Exp $ .Dd 20 September 1995 .Os FreeBSD .Dt PPP 8 @@ -402,13 +402,21 @@ If the connect fails, the default behavior is to wait 30 seconds and then attempt to connect when another outgoing packet is detected. This behavior can be changed with .Bd -literal -offset indent -set redial seconds|random [dial_attempts] +set redial seconds|random[.nseconds|random] [dial_attempts] .Ed .Pp -Seconds is the number of seconds to wait before attempting +.Sq Seconds +is the number of seconds to wait before attempting to connect again. If the argument is .Sq random , the delay period is a random value between 0 and 30 seconds. +.Sq Nseconds +is the number of seconds to wait before attempting +to dial the next number in a list of numbers (see the +.Dq set phone +command). The default is 3 seconds. Again, if the argument is +.Sq random , +the delay period is a random value between 0 and 30 seconds. .Sq dial_attempts is the number of times to try to connect for each outgoing packet that is received. The previous value is unchanged if this parameter @@ -417,13 +425,14 @@ is omitted. If a value of zero is specified for .Nm ppp will keep trying until a connection is made. .Bd -literal -offset indent -set redial 10 4 +set redial 10.3 4 .Ed .Pp will attempt to connect 4 times for each outgoing packet that is -detected with a 10 second delay between each attempt. If multiple -phone numbers are specified, the total number of attempts is still -4 (it does not attempt each number 4 times). +detected with a 3 second delay between each number and a 10 second +delay after all numbers have been tried. If multiple phone numbers +are specified, the total number of attempts is still 4 (it does not +attempt each number 4 times). Modifying the dial delay is very useful when running .Nm @@ -432,12 +441,13 @@ dial mode on both ends of the link. If each end has the same timeout, both ends wind up calling each other at the same time if the link drops and both ends have packets queued. -The -.Dq set redial -command is ineffective if the +If the .Fl background -flag is specified. For background mode, all phone numbers are dialed -at most once until a connection is made. +flag is specified, all phone numbers are dialed at most once until +a connection is made. The next number redial period specified with +the +.Dq set redial +command is honoured. To terminate the program, type @@ -793,9 +803,8 @@ set phone "1234567:2345678" .Ed .Pp Here, the first number is attempted. If the connection fails, the second -number is attempted immediately. The redial timeout is ignored (although -the value of dial_attempts is not - see above). If the second number -also fails, the first is tried again after the redial timeout has expired. +number is attempted after the next number redial period. If the second number +also fails, the first is tried again after the redial period has expired. The selected phone number is substituted for the \\T string in the .Dq set dial command (see below). diff --git a/usr.sbin/ppp/ppp.8.m4 b/usr.sbin/ppp/ppp.8.m4 index 3d47cd2..26ad29e 100644 --- a/usr.sbin/ppp/ppp.8.m4 +++ b/usr.sbin/ppp/ppp.8.m4 @@ -1,5 +1,5 @@ .\" manual page [] for ppp 0.94 beta2 + alpha -.\" $Id: ppp.8,v 1.27 1997/04/12 22:58:41 brian Exp $ +.\" $Id: ppp.8,v 1.28 1997/04/13 00:54:45 brian Exp $ .Dd 20 September 1995 .Os FreeBSD .Dt PPP 8 @@ -402,13 +402,21 @@ If the connect fails, the default behavior is to wait 30 seconds and then attempt to connect when another outgoing packet is detected. This behavior can be changed with .Bd -literal -offset indent -set redial seconds|random [dial_attempts] +set redial seconds|random[.nseconds|random] [dial_attempts] .Ed .Pp -Seconds is the number of seconds to wait before attempting +.Sq Seconds +is the number of seconds to wait before attempting to connect again. If the argument is .Sq random , the delay period is a random value between 0 and 30 seconds. +.Sq Nseconds +is the number of seconds to wait before attempting +to dial the next number in a list of numbers (see the +.Dq set phone +command). The default is 3 seconds. Again, if the argument is +.Sq random , +the delay period is a random value between 0 and 30 seconds. .Sq dial_attempts is the number of times to try to connect for each outgoing packet that is received. The previous value is unchanged if this parameter @@ -417,13 +425,14 @@ is omitted. If a value of zero is specified for .Nm ppp will keep trying until a connection is made. .Bd -literal -offset indent -set redial 10 4 +set redial 10.3 4 .Ed .Pp will attempt to connect 4 times for each outgoing packet that is -detected with a 10 second delay between each attempt. If multiple -phone numbers are specified, the total number of attempts is still -4 (it does not attempt each number 4 times). +detected with a 3 second delay between each number and a 10 second +delay after all numbers have been tried. If multiple phone numbers +are specified, the total number of attempts is still 4 (it does not +attempt each number 4 times). Modifying the dial delay is very useful when running .Nm @@ -432,12 +441,13 @@ dial mode on both ends of the link. If each end has the same timeout, both ends wind up calling each other at the same time if the link drops and both ends have packets queued. -The -.Dq set redial -command is ineffective if the +If the .Fl background -flag is specified. For background mode, all phone numbers are dialed -at most once until a connection is made. +flag is specified, all phone numbers are dialed at most once until +a connection is made. The next number redial period specified with +the +.Dq set redial +command is honoured. To terminate the program, type @@ -793,9 +803,8 @@ set phone "1234567:2345678" .Ed .Pp Here, the first number is attempted. If the connection fails, the second -number is attempted immediately. The redial timeout is ignored (although -the value of dial_attempts is not - see above). If the second number -also fails, the first is tried again after the redial timeout has expired. +number is attempted after the next number redial period. If the second number +also fails, the first is tried again after the redial period has expired. The selected phone number is substituted for the \\T string in the .Dq set dial command (see below). diff --git a/usr.sbin/ppp/vars.c b/usr.sbin/ppp/vars.c index 85729b8..c976892 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$ + * $Id: vars.c,v 1.12 1997/02/22 16:11:00 peter Exp $ * */ #include "fsm.h" @@ -29,7 +29,7 @@ #include "defs.h" char VarVersion[] = "Version 0.94"; -char VarLocalVersion[] = "$Date: 1997/01/14 07:15:44 $"; +char VarLocalVersion[] = "$Date: 1997/02/22 16:11:00 $"; /* * Order of conf option is important. See vars.h. @@ -50,7 +50,7 @@ struct confdesc pppConfs[] = { struct pppvars pppVars = { DEF_MRU, 0, MODEM_SPEED, CS8, MODEM_CTSRTS, 180, 30, 3, - REDIAL_PERIOD, 1, MODEM_DEV, OPEN_PASSIVE, LOCAL_NO_AUTH, + REDIAL_PERIOD, NEXT_REDIAL_PERIOD, 1, MODEM_DEV, OPEN_PASSIVE, LOCAL_NO_AUTH, }; int diff --git a/usr.sbin/ppp/vars.h b/usr.sbin/ppp/vars.h index 5041ee9..57c27b9 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$ + * $Id: vars.h,v 1.10 1997/02/22 16:11:02 peter Exp $ * * TODO: */ @@ -63,6 +63,7 @@ struct pppvars { int lqr_timeout; /* LQR timeout value */ int retry_timeout; /* Retry timeout value */ int redial_timeout; /* Redial timeout value */ + int redial_next_timeout; /* Redial next timeout value */ int dial_tries; /* Dial attempts before giving up, 0 == forever */ char modem_dev[20]; /* Name of device */ int open_mode; /* LCP open mode */ @@ -101,6 +102,7 @@ struct pppvars { #define VarNextPhone pppVars.next_phone #define VarShortHost pppVars.shostname #define VarRedialTimeout pppVars.redial_timeout +#define VarRedialNextTimeout pppVars.redial_next_timeout #define VarDialTries pppVars.dial_tries #define DEV_IS_SYNC (VarSpeed == 0) |