diff options
author | brian <brian@FreeBSD.org> | 1997-05-24 17:32:42 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1997-05-24 17:32:42 +0000 |
commit | 81067cb46e8543e07d85f87008d4ccacf1eabee6 (patch) | |
tree | b216757aa8c78fa7bae8a9c15316cbeffdcce71f | |
parent | 16ff4223276d7d07622d8962c3924ef714ccff73 (diff) | |
download | FreeBSD-src-81067cb46e8543e07d85f87008d4ccacf1eabee6.zip FreeBSD-src-81067cb46e8543e07d85f87008d4ccacf1eabee6.tar.gz |
Fix the reconnect option, and add an explanation to vars.h
-rw-r--r-- | usr.sbin/ppp/chap.c | 4 | ||||
-rw-r--r-- | usr.sbin/ppp/command.c | 4 | ||||
-rw-r--r-- | usr.sbin/ppp/ip.c | 4 | ||||
-rw-r--r-- | usr.sbin/ppp/ipcp.c | 4 | ||||
-rw-r--r-- | usr.sbin/ppp/lcp.c | 4 | ||||
-rw-r--r-- | usr.sbin/ppp/lqr.c | 6 | ||||
-rw-r--r-- | usr.sbin/ppp/main.c | 13 | ||||
-rw-r--r-- | usr.sbin/ppp/modem.c | 4 | ||||
-rw-r--r-- | usr.sbin/ppp/os.c | 3 | ||||
-rw-r--r-- | usr.sbin/ppp/pap.c | 6 | ||||
-rw-r--r-- | usr.sbin/ppp/vars.h | 41 |
11 files changed, 65 insertions, 28 deletions
diff --git a/usr.sbin/ppp/chap.c b/usr.sbin/ppp/chap.c index 6467fb5..31ba182 100644 --- a/usr.sbin/ppp/chap.c +++ b/usr.sbin/ppp/chap.c @@ -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.14 1997/05/10 01:22:06 brian Exp $ + * $Id: chap.c,v 1.15 1997/05/19 01:59:57 brian Exp $ * * TODO: */ @@ -211,8 +211,8 @@ struct mbuf *bp; * Peer is not registerd, or response digest is wrong. */ ChapOutput(CHAP_FAILURE, chp->id, "Invalid!!", 9); + reconnect(RECON_FALSE); LcpClose(); - reconnectCount = 0; break; } } diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c index 8e0a216..22f5e24 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.47 1997/05/19 01:59:59 brian Exp $ + * $Id: command.c,v 1.48 1997/05/23 04:54:01 brian Exp $ * */ #include <sys/types.h> @@ -637,8 +637,8 @@ char **argv; static int CloseCommand() { + reconnect(RECON_FALSE); LcpClose(); - reconnectCount = 0; if (mode & MODE_BACKGROUND) Cleanup(EX_NORMAL); return(1); diff --git a/usr.sbin/ppp/ip.c b/usr.sbin/ppp/ip.c index 7248fc7..fe78e9b 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: ip.c,v 1.17 1997/05/19 02:00:00 brian Exp $ + * $Id: ip.c,v 1.18 1997/05/23 04:54:02 brian Exp $ * * TODO: * o Return ICMP message for filterd packet @@ -44,8 +44,8 @@ static struct pppTimer IdleTimer; static void IdleTimeout() { LogPrintf(LOG_PHASE_BIT, "Idle timer expired.\n"); + reconnect(RECON_FALSE); LcpClose(); - reconnectCount = 0; } /* diff --git a/usr.sbin/ppp/ipcp.c b/usr.sbin/ppp/ipcp.c index 5cfc6f7..2c414f3 100644 --- a/usr.sbin/ppp/ipcp.c +++ b/usr.sbin/ppp/ipcp.c @@ -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.17 1997/05/19 02:00:02 brian Exp $ + * $Id: ipcp.c,v 1.18 1997/05/23 04:54:02 brian Exp $ * * TODO: * o More RFC1772 backwoard compatibility @@ -244,8 +244,8 @@ IpcpLayerFinish(fp) struct fsm *fp; { LogPrintf(LOG_LCP_BIT, "%s: LayerFinish.\n", fp->name); + reconnect(RECON_FALSE); LcpClose(); - reconnectCount = 0; NewPhase(PHASE_TERMINATE); } diff --git a/usr.sbin/ppp/lcp.c b/usr.sbin/ppp/lcp.c index 2cfabd7..b121ce7 100644 --- a/usr.sbin/ppp/lcp.c +++ b/usr.sbin/ppp/lcp.c @@ -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.18 1997/05/11 00:44:37 ache Exp $ + * $Id: lcp.c,v 1.19 1997/05/19 02:00:04 brian Exp $ * * TODO: * o Validate magic number received from peer. @@ -128,7 +128,7 @@ int new; case PHASE_DEAD: if (mode & MODE_DIRECT) Cleanup(EX_DEAD); - if (mode & MODE_BACKGROUND && !reconnectRequired) + if (mode & MODE_BACKGROUND && reconnectState != RECON_TRUE) Cleanup(EX_DEAD); break; } diff --git a/usr.sbin/ppp/lqr.c b/usr.sbin/ppp/lqr.c index aafe340..b66f04e 100644 --- a/usr.sbin/ppp/lqr.c +++ b/usr.sbin/ppp/lqr.c @@ -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.11 1997/05/09 16:16:31 jdp Exp $ + * $Id: lqr.c,v 1.12 1997/05/19 02:00:05 brian Exp $ * * o LQR based on RFC1333 * @@ -110,8 +110,8 @@ SendLqrReport() */ LogPrintf(LOG_PHASE_BIT, "** 1 Too many ECHO packets are lost. **\n"); lqmmethod = 0; /* Prevent rcursion via LcpClose() */ + reconnect(RECON_TRUE); LcpClose(); - reconnectRequired = 1; } else { bp = mballoc(sizeof(struct lqrdata), MB_LQR); HdlcOutput(PRI_LINK, PROTO_LQR, bp); @@ -121,8 +121,8 @@ SendLqrReport() if (echoseq - gotseq > 5) { LogPrintf(LOG_PHASE_BIT, "** 2 Too many ECHO packets are lost. **\n"); lqmmethod = 0; /* Prevent rcursion via LcpClose() */ + reconnect(RECON_TRUE); LcpClose(); - reconnectRequired = 1; } else SendEchoReq(); } diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c index 0193d92..1ff814d 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.54 1997/05/23 04:54:03 brian Exp $ + * $Id: main.c,v 1.55 1997/05/23 05:22:48 brian Exp $ * * TODO: * o Add commands for traffic summary, version display, etc. @@ -223,8 +223,8 @@ int signo; } else { LogPrintf(LOG_PHASE_BIT, "Signal %d, terminate.\n", signo); + reconnect(RECON_FALSE); LcpClose(); - reconnectCount = 0; Cleanup(EX_TERM); } } @@ -756,7 +756,7 @@ DoLoop() timeout.tv_sec = 0; timeout.tv_usec = 0; - reconnectRequired = 0; + reconnectState = RECON_UNKNOWN; if (mode & MODE_BACKGROUND) dial_up = TRUE; /* Bring the line up */ @@ -780,7 +780,7 @@ DoLoop() * back up. */ if (LcpFsm.state <= ST_CLOSED) { - if (dial_up != TRUE && reconnectRequired) { + if (dial_up != TRUE && reconnectState == RECON_TRUE) { if (++reconnectCount <= VarReconnectTries) { LogPrintf(LOG_PHASE_BIT, "Connection lost, re-establish (%d/%d)\n", reconnectCount, VarReconnectTries); @@ -794,8 +794,8 @@ DoLoop() if (mode & MODE_BACKGROUND) Cleanup(EX_DEAD); } + reconnectState = RECON_ENVOKED; } - reconnectRequired = 0; } /* @@ -821,6 +821,7 @@ DoLoop() ModemTimeout(); PacketMode(); dial_up = FALSE; + reconnectState = RECON_UNKNOWN; tries = 0; } else { CloseModem(); @@ -834,6 +835,8 @@ DoLoop() /* I give up ! Can't get through :( */ StartRedialTimer(VarRedialTimeout); dial_up = FALSE; + reconnectState = RECON_UNKNOWN; + reconnectCount = 0; tries = 0; } else if (VarNextPhone == NULL) /* Dial failed. Keep quite during redial wait period. */ diff --git a/usr.sbin/ppp/modem.c b/usr.sbin/ppp/modem.c index f2c4dd0..faea048 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.37 1997/05/14 01:14:32 brian Exp $ + * $Id: modem.c,v 1.38 1997/05/19 02:00:08 brian Exp $ * * TODO: */ @@ -253,7 +253,7 @@ ModemTimeout() if (mode & MODE_DEDICATED) PacketMode(); } else { - reconnectRequired = 1; + reconnect(RECON_TRUE); DownConnection(); } } diff --git a/usr.sbin/ppp/os.c b/usr.sbin/ppp/os.c index 2bdab3e..fd2990e 100644 --- a/usr.sbin/ppp/os.c +++ b/usr.sbin/ppp/os.c @@ -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.16 1997/05/04 02:39:04 ache Exp $ + * $Id: os.c,v 1.17 1997/05/19 02:00:10 brian Exp $ * */ #include "fsm.h" @@ -186,6 +186,7 @@ OsLinkup() if (linkup == 0) { if (setuid(0) < 0) logprintf("setuid failed\n"); + reconnectState = RECON_UNKNOWN; if (mode & MODE_BACKGROUND && BGFiledes[1] != -1) { char c = EX_NORMAL; if (write(BGFiledes[1],&c,1) == 1) diff --git a/usr.sbin/ppp/pap.c b/usr.sbin/ppp/pap.c index db1c9aa..4159d12 100644 --- a/usr.sbin/ppp/pap.c +++ b/usr.sbin/ppp/pap.c @@ -18,7 +18,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: pap.c,v 1.9 1997/02/22 16:10:40 peter Exp $ + * $Id: pap.c,v 1.10 1997/05/19 02:00:12 brian Exp $ * * TODO: */ @@ -153,8 +153,8 @@ struct mbuf *bp; NewPhase(PHASE_NETWORK); } else { SendPapCode(php->id, PAP_NAK, "Login incorrect"); + reconnect(RECON_FALSE); LcpClose(); - reconnectCount = 0; } break; case PAP_ACK: @@ -175,8 +175,8 @@ struct mbuf *bp; len = *cp++; cp[len] = 0; LogPrintf(LOG_PHASE_BIT, "Received PAP_NAK (%s)\n", cp); + reconnect(RECON_FALSE); LcpClose(); - reconnectCount = 0; break; } } diff --git a/usr.sbin/ppp/vars.h b/usr.sbin/ppp/vars.h index 483121a..6d6f20f 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.13 1997/05/10 03:39:57 brian Exp $ + * $Id: vars.h,v 1.14 1997/05/19 02:00:16 brian Exp $ * * TODO: */ @@ -117,9 +117,42 @@ extern struct pppvars pppVars; int ipInOctets, ipOutOctets, ipKeepAlive; int ipConnectSecs, ipIdleSecs; + +#define RECON_TRUE (1) +#define RECON_FALSE (2) +#define RECON_UNKNOWN (3) +#define RECON_ENVOKED (3) +#define reconnect(x) \ + do \ + if (reconnectState == RECON_UNKNOWN) { \ + reconnectState = x; \ + if (x == RECON_FALSE) \ + reconnectCount = 0; \ + } \ + while(0) + +int reconnectState, reconnectCount; /* - * One of these should be set (reconnectRequired=1 or reconnectCount=0) - * every time LcpClose is called + * This is the logic behind the reconnect variables: + * We have four reconnect "states". We start off not requiring anything + * from the reconnect code (reconnectState == RECON_UNKNOWN). If the + * line is brought down (via LcpClose() or LcpDown()), we have to decide + * whether to set to RECON_TRUE or RECON_FALSE. It's only here that we + * know the correct action. Once we've decided, we don't want that + * decision to be overridden (hence the above reconnect() macro) - If we + * call LcpClose, the ModemTimeout() still gets to "notice" that the line + * is down. When it "notice"s, it should only set RECON_TRUE if a decision + * hasn't already been made. + * + * In main.c, when we notice we have RECON_TRUE, we must only action + * it once. The fourth "state" is where we're bringing the line up, + * but if we call LcpClose for any reason (failed PAP/CHAP etc) we + * don't want to set to RECON_{TRUE,FALSE}. + * + * If we get a connection or give up dialing, we go back to RECON_UNKNOWN. + * If we get give up dialing or reconnecting or if we chose to down the + * connection, we set reconnectCount back to zero. + * */ -int reconnectRequired, reconnectCount; + #endif |