diff options
author | brian <brian@FreeBSD.org> | 1997-04-21 01:02:02 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1997-04-21 01:02:02 +0000 |
commit | ad4ab187936a54f3a8329d804592f12284e6c176 (patch) | |
tree | 7b87206f10e0b3c6831b1d1b453f11c55a48e172 /usr.sbin | |
parent | ca8a9db2701fdcbcc35546f2de8867e0b669e7bc (diff) | |
download | FreeBSD-src-ad4ab187936a54f3a8329d804592f12284e6c176.zip FreeBSD-src-ad4ab187936a54f3a8329d804592f12284e6c176.tar.gz |
Add a reconnect capability directing ppp to re-establish
the connection after an unexpected loss of carrier:
set reconnect timer ntries
The man page warns against using this command when your
timeout value is slightly more than the other sides :{}
Suggested by: burton@bsampley.vip.best.com (Burton Sampley)
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ppp/command.c | 44 | ||||
-rw-r--r-- | usr.sbin/ppp/defs.h | 4 | ||||
-rw-r--r-- | usr.sbin/ppp/ip.c | 3 | ||||
-rw-r--r-- | usr.sbin/ppp/main.c | 20 | ||||
-rw-r--r-- | usr.sbin/ppp/modem.c | 3 | ||||
-rw-r--r-- | usr.sbin/ppp/ppp.8 | 35 | ||||
-rw-r--r-- | usr.sbin/ppp/ppp.8.m4 | 35 | ||||
-rw-r--r-- | usr.sbin/ppp/vars.c | 7 | ||||
-rw-r--r-- | usr.sbin/ppp/vars.h | 7 |
9 files changed, 136 insertions, 22 deletions
diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c index 5a69566..032fd2a 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.37 1997/04/09 17:35:52 ache Exp $ + * $Id: command.c,v 1.38 1997/04/14 23:48:12 brian Exp $ * */ #include <sys/types.h> @@ -365,6 +365,13 @@ static int ShowLogList() return(1); } +static int ShowReconnect() +{ + printf(" Reconnect Timer: %d, %d tries\n", + VarReconnectTimer, VarReconnectTries); + return(1); +} + static int ShowRedial() { printf(" Redial Timer: "); @@ -441,12 +448,14 @@ struct cmdtab const ShowCommands[] = { "Show Output filters", StrOption}, { "proto", NULL, ReportProtStatus, LOCAL_AUTH, "Show protocol summary", StrNull}, + { "reconnect",NULL, ShowReconnect, LOCAL_AUTH, + "Show Reconnect timer ntries", StrNull}, + { "redial", NULL, ShowRedial, LOCAL_AUTH, + "Show Redial timeout value", StrNull}, { "route", NULL, ShowRoute, LOCAL_AUTH, "Show routing table", StrNull}, { "timeout", NULL, ShowTimeout, LOCAL_AUTH, "Show Idle timeout value", StrNull}, - { "redial", NULL, ShowRedial, LOCAL_AUTH, - "Show Redial timeout value", StrNull}, #ifdef MSEXT { "msext", NULL, ShowMSExt, LOCAL_AUTH, "Show MS PPP extentions", StrNull}, @@ -630,7 +639,8 @@ DownCommand() return(1); } -static int SetModemSpeed(list, argc, argv) +static int +SetModemSpeed(list, argc, argv) struct cmdtab *list; int argc; char **argv; @@ -652,7 +662,22 @@ char **argv; return(1); } -static int SetRedialTimeout(list, argc, argv) +static int +SetReconnect(list, argc, argv) +struct cmdtab *list; +int argc; +char **argv; +{ + if (argc == 2) { + VarReconnectTimer = atoi(argv[0]); + VarReconnectTries = atoi(argv[1]); + } else + printf("Usage: %s %s\n", list->name, list->syntax); + return(1); +} + +static int +SetRedialTimeout(list, argc, argv) struct cmdtab *list; int argc; char **argv; @@ -727,7 +752,8 @@ char **argv; return(1); } -static int SetModemParity(list, argc, argv) +static int +SetModemParity(list, argc, argv) struct cmdtab *list; int argc; char **argv; @@ -1075,12 +1101,14 @@ struct cmdtab const SetCommands[] = { "Set modem parity", "[odd|even|none]"}, { "phone", NULL, SetVariable, LOCAL_AUTH, "Set telephone number(s)", "phone1[:phone2[...]]", (void *)VAR_PHONE }, + { "reconnect",NULL, SetReconnect, LOCAL_AUTH, + "Set Reconnect timeout", "value ntries"}, + { "redial", NULL, SetRedialTimeout, LOCAL_AUTH, + "Set Redial timeout", "value|random[.value|random] [dial_attempts]"}, { "speed", NULL, SetModemSpeed, LOCAL_AUTH, "Set modem speed", "speed"}, { "timeout", NULL, SetIdleTimeout, LOCAL_AUTH, "Set Idle timeout", StrValue}, - { "redial", NULL, SetRedialTimeout, LOCAL_AUTH, - "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 5a9533f..edcc665 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.10 1997/02/22 16:10:10 peter Exp $ + * $Id: defs.h,v 1.11 1997/04/14 23:48:13 brian Exp $ * * TODO: */ @@ -46,6 +46,8 @@ #define SERVER_PORT 3000 /* Base server port no. */ #define MODEM_CTSRTS TRUE /* Default (true): use CTS/RTS signals */ +#define RECONNECT_TIMER 3 /* Default timer for carrier loss */ +#define RECONNECT_TRIES 0 /* Default retries on carrier loss */ #define REDIAL_PERIOD 30 /* Default Hold time to redial */ #define NEXT_REDIAL_PERIOD 3 /* Default Hold time to next number redial */ diff --git a/usr.sbin/ppp/ip.c b/usr.sbin/ppp/ip.c index 1e66473..8d13cc5 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$ + * $Id: ip.c,v 1.14 1997/02/22 16:10:18 peter Exp $ * * TODO: * o Return ICMP message for filterd packet @@ -45,6 +45,7 @@ static void IdleTimeout() { LogPrintf(LOG_PHASE_BIT, "Idle timer expired.\n"); LcpClose(); + lostCarrier = 0; } /* diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c index bb876af..f1e1d00 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.43 1997/04/13 00:54:43 brian Exp $ + * $Id: main.c,v 1.44 1997/04/14 23:48:15 brian Exp $ * * TODO: * o Add commands for traffic summary, version display, etc. @@ -735,6 +735,7 @@ DoLoop() timeout.tv_sec = 0; timeout.tv_usec = 0; + lostCarrier = 0; if (mode & MODE_BACKGROUND) dial_up = TRUE; /* Bring the line up */ @@ -752,11 +753,24 @@ DoLoop() if (mode & MODE_DDIAL && LcpFsm.state <= ST_CLOSED) dial_up = TRUE; + /* + * If we lost carrier and want to re-establish the connection + * due to the "set reconnect" value, we'd better bring the line + * back up now. + */ + if (LcpFsm.state <= ST_CLOSED && dial_up != TRUE + && lostCarrier && lostCarrier <= VarReconnectTries) { + LogPrintf(LOG_PHASE_BIT, "Connection lost, re-establish (%d/%d)\n", + lostCarrier, VarReconnectTries); + StartRedialTimer(VarReconnectTimer); + dial_up = TRUE; + } + /* - * If Ip packet for output is enqueued and require dial up, + * If Ip packet for output is enqueued and require dial up, * Just do it! */ - if ( dial_up && RedialTimer.state != TIMER_RUNNING ) { /* XXX */ + if ( dial_up && RedialTimer.state != TIMER_RUNNING ) { #ifdef DEBUG logprintf("going to dial: modem = %d\n", modem); #endif diff --git a/usr.sbin/ppp/modem.c b/usr.sbin/ppp/modem.c index ead30ac..fb0bb3c 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.32 1997/03/31 22:51:00 brian Exp $ + * $Id: modem.c,v 1.33 1997/04/13 00:54:44 brian Exp $ * * TODO: */ @@ -218,6 +218,7 @@ DownConnection() CloseModem(); LcpDown(); } + lostCarrier++; connect_time = 0; } diff --git a/usr.sbin/ppp/ppp.8 b/usr.sbin/ppp/ppp.8 index 26ad29e..f4431ee 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.28 1997/04/13 00:54:45 brian Exp $ +.\" $Id: ppp.8,v 1.29 1997/04/14 23:48:17 brian Exp $ .Dd 20 September 1995 .Os FreeBSD .Dt PPP 8 @@ -441,13 +441,44 @@ 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. +At some locations, the serial link may not be reliable, and carrier +may be lost at inappropriate times. It is possible to have +.Nm +redial should carrier be unexpectedly lost during a session. +.Bd -literal -offset indent +set reconnect timeout ntries +.Ed + +This command tells ppp to re-establish the connection +.Ar ntries +times on loss of carrier with a pause of +.Ar timeout +seconds before each try. For example, +.Bd -literal -offset indent +set reconnect 3 5 +.Ed + +tells +.Nm +that on an unexpected loss of carrier, it should wait +.Ar 3 +seconds before attempting to reconnect. This may happen up to +.Ar 5 +times before +.Nm +gives up. The default value of ntries is zero (no redial). Care +should be taken with this option. If the local timeout is slightly +longer than the remote timeout, the reconnect feature will always be +triggered (up to the given number of times) after the remote side +times out and hangs up. + If the .Fl background 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. +command is honoured, as is the reconnect tries value. To terminate the program, type diff --git a/usr.sbin/ppp/ppp.8.m4 b/usr.sbin/ppp/ppp.8.m4 index 26ad29e..f4431ee 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.28 1997/04/13 00:54:45 brian Exp $ +.\" $Id: ppp.8,v 1.29 1997/04/14 23:48:17 brian Exp $ .Dd 20 September 1995 .Os FreeBSD .Dt PPP 8 @@ -441,13 +441,44 @@ 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. +At some locations, the serial link may not be reliable, and carrier +may be lost at inappropriate times. It is possible to have +.Nm +redial should carrier be unexpectedly lost during a session. +.Bd -literal -offset indent +set reconnect timeout ntries +.Ed + +This command tells ppp to re-establish the connection +.Ar ntries +times on loss of carrier with a pause of +.Ar timeout +seconds before each try. For example, +.Bd -literal -offset indent +set reconnect 3 5 +.Ed + +tells +.Nm +that on an unexpected loss of carrier, it should wait +.Ar 3 +seconds before attempting to reconnect. This may happen up to +.Ar 5 +times before +.Nm +gives up. The default value of ntries is zero (no redial). Care +should be taken with this option. If the local timeout is slightly +longer than the remote timeout, the reconnect feature will always be +triggered (up to the given number of times) after the remote side +times out and hangs up. + If the .Fl background 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. +command is honoured, as is the reconnect tries value. To terminate the program, type diff --git a/usr.sbin/ppp/vars.c b/usr.sbin/ppp/vars.c index c976892..cbbad62 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.12 1997/02/22 16:11:00 peter Exp $ + * $Id: vars.c,v 1.13 1997/04/14 23:48:19 brian Exp $ * */ #include "fsm.h" @@ -29,7 +29,7 @@ #include "defs.h" char VarVersion[] = "Version 0.94"; -char VarLocalVersion[] = "$Date: 1997/02/22 16:11:00 $"; +char VarLocalVersion[] = "$Date: 1997/04/14 23:48:19 $"; /* * Order of conf option is important. See vars.h. @@ -50,7 +50,8 @@ struct confdesc pppConfs[] = { struct pppvars pppVars = { DEF_MRU, 0, MODEM_SPEED, CS8, MODEM_CTSRTS, 180, 30, 3, - REDIAL_PERIOD, NEXT_REDIAL_PERIOD, 1, MODEM_DEV, OPEN_PASSIVE, LOCAL_NO_AUTH, + RECONNECT_TIMER, RECONNECT_TRIES, 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 57c27b9..06691de 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.10 1997/02/22 16:11:02 peter Exp $ + * $Id: vars.h,v 1.11 1997/04/14 23:48:20 brian Exp $ * * TODO: */ @@ -62,6 +62,8 @@ struct pppvars { int idle_timeout; /* Idle timeout value */ int lqr_timeout; /* LQR timeout value */ int retry_timeout; /* Retry timeout value */ + int reconnect_timer; /* Timeout before reconnect on carrier loss */ + int reconnect_tries; /* Attempt reconnect on carrier loss */ int redial_timeout; /* Redial timeout value */ int redial_next_timeout; /* Redial next timeout value */ int dial_tries; /* Dial attempts before giving up, 0 == forever */ @@ -101,6 +103,8 @@ struct pppvars { #define VarPhoneCopy pppVars.phone_copy #define VarNextPhone pppVars.next_phone #define VarShortHost pppVars.shostname +#define VarReconnectTimer pppVars.reconnect_timer +#define VarReconnectTries pppVars.reconnect_tries #define VarRedialTimeout pppVars.redial_timeout #define VarRedialNextTimeout pppVars.redial_next_timeout #define VarDialTries pppVars.dial_tries @@ -111,4 +115,5 @@ extern struct pppvars pppVars; int ipInOctets, ipOutOctets, ipKeepAlive; int ipConnectSecs, ipIdleSecs; +int lostCarrier; #endif |