Mega update to sort out bad implementations

of reconnect & -background.

o   Fix reconnect anomolies.
o   Make reconnect apply to failed LQR hangups (& mention in man page).
o   Make reconnect effective in -background mode.
o   Listen on socket in -background mode.
o   Try all phone numbers in -background mode.
o   Insist on system arg in -background mode.
o   Make a control-connection close command exit in -background mode.
o   Output status message to stdout on exit of parent in -background mode.
o   Don't notify parent of success too soon.
o   Describe termination EX_* code.
o   Miscelaneous diagnostic corrections.
o   Remove redundant connect_time from modem.c.
o   Don't repeatedly DownConnection().
This commit is contained in:
Brian Somers 1997-05-19 02:00:16 +00:00
parent fdc984f7b6
commit 6efd9292f6
13 changed files with 125 additions and 95 deletions

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: chap.c,v 1.13 1997/03/24 16:01:42 ache Exp $
* $Id: chap.c,v 1.14 1997/05/10 01:22:06 brian Exp $
*
* TODO:
*/
@ -212,6 +212,7 @@ struct mbuf *bp;
*/
ChapOutput(CHAP_FAILURE, chp->id, "Invalid!!", 9);
LcpClose();
reconnectCount = 0;
break;
}
}

View File

@ -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.45 1997/05/10 23:46:29 ache Exp $
* $Id: command.c,v 1.46 1997/05/14 01:18:50 brian Exp $
*
*/
#include <sys/types.h>
@ -108,6 +108,8 @@ IsInteractive()
if (mode & MODE_DDIAL)
mes = "Working in dedicated dial mode.";
else if (mode & MODE_BACKGROUND)
mes = "Working in background mode.";
else if (mode & MODE_AUTO)
mes = "Working in auto mode.";
else if (mode & MODE_DIRECT)
@ -630,7 +632,9 @@ static int
CloseCommand()
{
LcpClose();
lostCarrier = 0;
reconnectCount = 0;
if (mode & MODE_BACKGROUND)
Cleanup(EX_NORMAL);
return(1);
}

View File

@ -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.15 1997/04/21 01:01:45 brian Exp $
* $Id: ip.c,v 1.16 1997/05/10 01:22:11 brian Exp $
*
* TODO:
* o Return ICMP message for filterd packet
@ -45,7 +45,7 @@ static void IdleTimeout()
{
LogPrintf(LOG_PHASE_BIT, "Idle timer expired.\n");
LcpClose();
lostCarrier = 0;
reconnectCount = 0;
}
/*

View File

@ -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.15 1997/05/10 15:37:40 brian Exp $
* $Id: ipcp.c,v 1.16 1997/05/10 23:46:29 ache Exp $
*
* TODO:
* o More RFC1772 backwoard compatibility
@ -245,6 +245,7 @@ struct fsm *fp;
{
LogPrintf(LOG_LCP_BIT, "%s: LayerFinish.\n", fp->name);
LcpClose();
reconnectCount = 0;
NewPhase(PHASE_TERMINATE);
}

View File

@ -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.17 1997/05/11 00:41:30 ache Exp $
* $Id: lcp.c,v 1.18 1997/05/11 00:44:37 ache Exp $
*
* TODO:
* o Validate magic number received from peer.
@ -124,18 +124,11 @@ int new;
IpcpOpen();
CcpUp();
CcpOpen();
if (mode & MODE_BACKGROUND && BGFiledes[1] != -1) {
char c = EX_NORMAL;
if (write(BGFiledes[1],&c,1) == 1)
LogPrintf(LOG_PHASE_BIT,"Parent notified of success.\n");
else
LogPrintf(LOG_PHASE_BIT,"Failed to notify parent of success.\n");
close(BGFiledes[1]);
BGFiledes[1] = -1;
}
break;
case PHASE_DEAD:
if (mode & (MODE_DIRECT|MODE_BACKGROUND))
if (mode & MODE_DIRECT)
Cleanup(EX_DEAD);
if (mode & MODE_BACKGROUND && !reconnectRequired)
Cleanup(EX_DEAD);
break;
}

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: lqr.c,v 1.10 1997/05/07 23:40:31 brian Exp $
* $Id: lqr.c,v 1.11 1997/05/09 16:16:31 jdp Exp $
*
* o LQR based on RFC1333
*
@ -111,6 +111,7 @@ SendLqrReport()
LogPrintf(LOG_PHASE_BIT, "** 1 Too many ECHO packets are lost. **\n");
lqmmethod = 0; /* Prevent rcursion via LcpClose() */
LcpClose();
reconnectRequired = 1;
} else {
bp = mballoc(sizeof(struct lqrdata), MB_LQR);
HdlcOutput(PRI_LINK, PROTO_LQR, bp);
@ -121,6 +122,7 @@ SendLqrReport()
LogPrintf(LOG_PHASE_BIT, "** 2 Too many ECHO packets are lost. **\n");
lqmmethod = 0; /* Prevent rcursion via LcpClose() */
LcpClose();
reconnectRequired = 1;
} else
SendEchoReq();
}

View File

@ -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.50 1997/05/14 01:18:51 brian Exp $
* $Id: main.c,v 1.51 1997/05/17 16:08:46 brian Exp $
*
* TODO:
* o Add commands for traffic summary, version display, etc.
@ -69,6 +69,7 @@ extern int aft_cmd;
extern int IsInteractive();
static void DoLoop(void);
static void TerminalStop();
static char *ex_desc();
static struct termios oldtio; /* Original tty mode */
static struct termios comtio; /* Command level tty mode */
@ -168,7 +169,7 @@ int excode;
OsLinkdown();
OsCloseLink(1);
sleep(1);
if (mode & (MODE_AUTO | MODE_BACKGROUND))
if (mode & MODE_AUTO)
DeleteIfRoutes(1);
(void)unlink(pid_filename);
(void)unlink(if_filename);
@ -181,7 +182,7 @@ int excode;
LogPrintf(LOG_PHASE_BIT,"Failed to notify parent of failure.\n");
close(BGFiledes[1]);
}
LogPrintf(LOG_PHASE_BIT, "PPP Terminated %d.\n",excode);
LogPrintf(LOG_PHASE_BIT, "PPP Terminated (%s).\n",ex_desc(excode));
LogClose();
if (server >= 0) {
close(server);
@ -223,6 +224,7 @@ int signo;
else {
LogPrintf(LOG_PHASE_BIT, "Signal %d, terminate.\n", signo);
LcpClose();
reconnectCount = 0;
Cleanup(EX_TERM);
}
}
@ -245,6 +247,19 @@ int signo;
kill(getpid(), signo);
}
static char *
ex_desc(int ex)
{
static char num[12];
static char *desc[] = { "normal", "start", "sock",
"modem", "dial", "dead", "done", "reboot", "errdead",
"hangup", "term", "nodial", "nologin" };
if (ex >= 0 && ex < sizeof(desc)/sizeof(*desc))
return desc[ex];
snprintf(num, sizeof num, "%d", ex);
return num;
}
void
Usage()
@ -266,7 +281,7 @@ ProcessArgs(int argc, char **argv)
if (strcmp(cp, "auto") == 0)
mode |= MODE_AUTO;
else if (strcmp(cp, "background") == 0)
mode |= MODE_BACKGROUND;
mode |= MODE_BACKGROUND|MODE_AUTO;
else if (strcmp(cp, "direct") == 0)
mode |= MODE_DIRECT;
else if (strcmp(cp, "dedicated") == 0)
@ -339,7 +354,7 @@ char **argv;
exit(EX_START);
}
if (mode & (MODE_AUTO|MODE_DIRECT|MODE_DEDICATED|MODE_BACKGROUND))
if (mode & (MODE_AUTO|MODE_DIRECT|MODE_DEDICATED))
mode &= ~MODE_INTER;
if (mode & MODE_INTER) {
printf("Interactive mode\n");
@ -347,14 +362,8 @@ char **argv;
} else if (mode & MODE_AUTO) {
printf("Automatic Dialer mode\n");
if (dstsystem == NULL) {
fprintf(stderr,
"Destination system must be specified in auto or ddial mode.\n");
exit(EX_START);
}
} else if (mode & MODE_BACKGROUND) {
printf("Background mode\n");
if (dstsystem == NULL) {
fprintf(stderr, "Destination system must be specified in background mode.\n");
fprintf(stderr, "Destination system must be specified in"
" auto, background or ddial mode.\n");
exit(EX_START);
}
}
@ -393,7 +402,8 @@ char **argv;
Cleanup(EX_START);
}
if ((mode & MODE_AUTO) && DefHisAddress.ipaddr.s_addr == INADDR_ANY) {
fprintf(stderr, "Must specify dstaddr with auto or ddial mode.\n");
fprintf(stderr, "Must specify dstaddr with"
" auto, background or ddial mode.\n");
Cleanup(EX_START);
}
}
@ -402,33 +412,31 @@ char **argv;
if (!(mode & MODE_INTER)) {
int port = SERVER_PORT + tunno;
if (mode & MODE_BACKGROUND) {
if (pipe (BGFiledes)) {
perror("pipe");
Cleanup(EX_SOCK);
}
}
else {
/*
* Create server socket and listen at there.
*/
server = socket(PF_INET, SOCK_STREAM, 0);
if (server < 0) {
perror("socket");
Cleanup(EX_SOCK);
}
ifsin.sin_family = AF_INET;
ifsin.sin_addr.s_addr = INADDR_ANY;
ifsin.sin_port = htons(port);
if (bind(server, (struct sockaddr *) &ifsin, sizeof(ifsin)) < 0) {
perror("bind");
if (errno == EADDRINUSE)
fprintf(stderr, "Wait for a while, then try again.\n");
Cleanup(EX_SOCK);
}
if (listen(server, 5) != 0) {
fprintf(stderr, "Unable to listen to socket - OS overload?\n");
}
/* Create server socket and listen at there. */
server = socket(PF_INET, SOCK_STREAM, 0);
if (server < 0) {
perror("socket");
Cleanup(EX_SOCK);
}
ifsin.sin_family = AF_INET;
ifsin.sin_addr.s_addr = INADDR_ANY;
ifsin.sin_port = htons(port);
if (bind(server, (struct sockaddr *) &ifsin, sizeof(ifsin)) < 0) {
perror("bind");
if (errno == EADDRINUSE)
fprintf(stderr, "Wait for a while, then try again.\n");
Cleanup(EX_SOCK);
}
if (listen(server, 5) != 0) {
fprintf(stderr, "Unable to listen to socket - OS overload?\n");
}
DupLog();
@ -447,12 +455,16 @@ char **argv;
/* Wait for our child to close its pipe before we exit. */
BGPid = bgpid;
close (BGFiledes[1]);
if (read(BGFiledes[0], &c, 1) != 1)
if (read(BGFiledes[0], &c, 1) != 1) {
printf("Child exit, no status.\n");
LogPrintf (LOG_PHASE_BIT, "Parent: Child exit, no status.\n");
else if (c == EX_NORMAL)
} else if (c == EX_NORMAL) {
printf("PPP enabled.\n");
LogPrintf (LOG_PHASE_BIT, "Parent: PPP enabled.\n");
else
} else {
printf("Child failed %d.\n",(int)c);
LogPrintf (LOG_PHASE_BIT, "Parent: Child failed %d.\n",(int)c);
}
close (BGFiledes[0]);
}
exit(c);
@ -728,7 +740,7 @@ DoLoop()
pgroup = getpgrp();
if (mode & (MODE_DIRECT|MODE_BACKGROUND)) {
if (mode & MODE_DIRECT) {
modem = OpenModem(mode);
LogPrintf(LOG_PHASE_BIT, "Packet mode enabled\n");
fflush(stderr);
@ -742,7 +754,7 @@ DoLoop()
timeout.tv_sec = 0;
timeout.tv_usec = 0;
lostCarrier = 0;
reconnectRequired = 0;
if (mode & MODE_BACKGROUND)
dial_up = TRUE; /* Bring the line up */
@ -763,19 +775,26 @@ DoLoop()
/*
* 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.
* back up.
*/
if (LcpFsm.state <= ST_CLOSED && dial_up != TRUE && lostCarrier)
if (lostCarrier <= VarReconnectTries) {
LogPrintf(LOG_PHASE_BIT, "Connection lost, re-establish (%d/%d)\n",
lostCarrier, VarReconnectTries);
StartRedialTimer(VarReconnectTimer);
dial_up = TRUE;
} else {
LogPrintf(LOG_PHASE_BIT, "Connection lost, maximum (%d) times\n",
VarReconnectTries);
lostCarrier = 0;
if (LcpFsm.state <= ST_CLOSED) {
if (dial_up != TRUE && reconnectRequired) {
if (++reconnectCount <= VarReconnectTries) {
LogPrintf(LOG_PHASE_BIT, "Connection lost, re-establish (%d/%d)\n",
reconnectCount, VarReconnectTries);
StartRedialTimer(VarReconnectTimer);
dial_up = TRUE;
} else {
if (VarReconnectTries)
LogPrintf(LOG_PHASE_BIT, "Connection lost, maximum (%d) times\n",
VarReconnectTries);
reconnectCount = 0;
if (mode & MODE_BACKGROUND)
Cleanup(EX_DEAD);
}
}
reconnectRequired = 0;
}
/*
* If Ip packet for output is enqueued and require dial up,

View File

@ -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.36 1997/05/10 03:39:54 brian Exp $
* $Id: modem.c,v 1.37 1997/05/14 01:14:32 brian Exp $
*
* TODO:
*/
@ -44,7 +44,6 @@
extern int DoChat();
static int mbits; /* Current DCD status */
static int connect_time; /* connection time */
static int connect_count;
static struct pppTimer ModemTimer;
@ -217,8 +216,6 @@ DownConnection()
CloseModem();
LcpDown();
}
lostCarrier++;
connect_time = 0;
}
/*
@ -228,28 +225,21 @@ DownConnection()
void
ModemTimeout()
{
static int waiting;
int ombits = mbits;
int change;
StopTimer(&ModemTimer);
if (Online)
connect_time++;
StartTimer(&ModemTimer);
if (dev_is_modem) {
if (modem < 0) {
if (!waiting)
if (modem >= 0) {
if (ioctl(modem, TIOCMGET, &mbits) < 0) {
LogPrintf(LOG_PHASE_BIT, "ioctl error (%s)!\n", strerror(errno));
DownConnection();
waiting = 1;
return;
}
waiting = 0;
if (ioctl(modem, TIOCMGET, &mbits) < 0) {
LogPrintf(LOG_PHASE_BIT, "ioctl error (%s)!\n", strerror(errno));
DownConnection();
return;
}
return;
}
} else
mbits = 0;
change = ombits ^ mbits;
if (change & TIOCM_CD) {
if (Online) {
@ -263,6 +253,7 @@ ModemTimeout()
if (mode & MODE_DEDICATED)
PacketMode();
} else {
reconnectRequired = 1;
DownConnection();
}
}
@ -272,7 +263,6 @@ ModemTimeout()
LogPrintf(LOG_PHASE_BIT, "Connected!\n");
mbits = TIOCM_CD;
connect_count++;
connect_time = 0;
} else if (uptime == 0) {
time(&uptime);
}
@ -282,7 +272,6 @@ ModemTimeout()
void
StartModemTimer()
{
connect_time = 0;
StopTimer(&ModemTimer);
ModemTimer.state = TIMER_STOPPED;
ModemTimer.load = SECTICKS;

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: os.c,v 1.15 1997/04/15 00:03:36 brian Exp $
* $Id: os.c,v 1.16 1997/05/04 02:39:04 ache Exp $
*
*/
#include "fsm.h"
@ -186,6 +186,15 @@ OsLinkup()
if (linkup == 0) {
if (setuid(0) < 0)
logprintf("setuid failed\n");
if (mode & MODE_BACKGROUND && BGFiledes[1] != -1) {
char c = EX_NORMAL;
if (write(BGFiledes[1],&c,1) == 1)
LogPrintf(LOG_PHASE_BIT,"Parent notified of success.\n");
else
LogPrintf(LOG_PHASE_BIT,"Failed to notify parent of success.\n");
close(BGFiledes[1]);
BGFiledes[1] = -1;
}
peer_addr = IpcpInfo.his_ipaddr;
s = (char *)inet_ntoa(peer_addr);
LogPrintf(LOG_LINK_BIT|LOG_LCP_BIT, "OsLinkup: %s\n", s);

View File

@ -18,7 +18,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id$
* $Id: pap.c,v 1.9 1997/02/22 16:10:40 peter Exp $
*
* TODO:
*/
@ -154,6 +154,7 @@ struct mbuf *bp;
} else {
SendPapCode(php->id, PAP_NAK, "Login incorrect");
LcpClose();
reconnectCount = 0;
}
break;
case PAP_ACK:
@ -175,6 +176,7 @@ struct mbuf *bp;
cp[len] = 0;
LogPrintf(LOG_PHASE_BIT, "Received PAP_NAK (%s)\n", cp);
LcpClose();
reconnectCount = 0;
break;
}
}

View File

@ -1,5 +1,5 @@
.\" manual page [] for ppp 0.94 beta2 + alpha
.\" $Id: ppp.8,v 1.32 1997/05/12 11:54:12 brian Exp $
.\" $Id: ppp.8,v 1.33 1997/05/13 09:31:05 brian Exp $
.Dd 20 September 1995
.Os FreeBSD
.Dt PPP 8
@ -472,6 +472,9 @@ 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.
NOTE: In this context, losing too many LQRs constitutes a loss of
carrier and will trigger a reconnect.
If the
.Fl background
flag is specified, all phone numbers are dialed at most once until

View File

@ -1,5 +1,5 @@
.\" manual page [] for ppp 0.94 beta2 + alpha
.\" $Id: ppp.8,v 1.32 1997/05/12 11:54:12 brian Exp $
.\" $Id: ppp.8,v 1.33 1997/05/13 09:31:05 brian Exp $
.Dd 20 September 1995
.Os FreeBSD
.Dt PPP 8
@ -472,6 +472,9 @@ 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.
NOTE: In this context, losing too many LQRs constitutes a loss of
carrier and will trigger a reconnect.
If the
.Fl background
flag is specified, all phone numbers are dialed at most once until

View File

@ -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.12 1997/04/21 01:02:02 brian Exp $
* $Id: vars.h,v 1.13 1997/05/10 03:39:57 brian Exp $
*
* TODO:
*/
@ -117,5 +117,9 @@ extern struct pppvars pppVars;
int ipInOctets, ipOutOctets, ipKeepAlive;
int ipConnectSecs, ipIdleSecs;
int lostCarrier;
/*
* One of these should be set (reconnectRequired=1 or reconnectCount=0)
* every time LcpClose is called
*/
int reconnectRequired, reconnectCount;
#endif