o Remove bundle_LinkLost() and have the modem routines simply

call datalink_Down() where appropriate rather than
  modem_Hangup().
o Now, when something horrible happens (failed read/write, loss
  of carrier etc), we go offline and run any hangup scripts etc
  in a controlled manner - exactly the same as if someone says
  ``down'' at the prompt or sends us a HUP.
o -dedicated links that fail to make the modem raw close it,
  suffer the redial timeout then try to open it again.
o Add a ``carrier lost'' warning diagnostic.
This commit is contained in:
Brian Somers 1998-04-17 22:04:36 +00:00
parent 50e5c17d3b
commit 030e4ebba8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/MP/; revision=35254
5 changed files with 35 additions and 75 deletions

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bundle.c,v 1.1.2.49 1998/04/16 22:11:46 brian Exp $
* $Id: bundle.c,v 1.1.2.50 1998/04/16 23:06:53 brian Exp $
*/
#include <sys/types.h>
@ -748,25 +748,6 @@ bundle_SetRoute(struct bundle *bundle, int cmd, struct in_addr dst,
close(s);
}
void
bundle_LinkLost(struct bundle *bundle, struct physical *p, int staydown)
{
/*
* Locate the appropriate datalink, and Down it.
*
* The LayerFinish() called from the datalinks LCP will
* potentially Down our NCPs (if it's the last link).
*
* The LinkClosed() called when the datalink is finally in
* the CLOSED state MAY cause the entire datalink to be deleted
* and MAY cause a program exit.
*/
if (p->type == PHYS_STDIN || bundle->CleaningUp)
staydown = 1;
datalink_Down(p->dl, staydown);
}
void
bundle_LinkClosed(struct bundle *bundle, struct datalink *dl)
{

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bundle.h,v 1.1.2.28 1998/04/11 21:50:39 brian Exp $
* $Id: bundle.h,v 1.1.2.29 1998/04/16 00:25:50 brian Exp $
*/
#define PHASE_DEAD 0 /* Link is dead */
@ -107,7 +107,6 @@ extern void bundle_NewPhase(struct bundle *, u_int);
extern int bundle_LinkIsUp(const struct bundle *);
extern void bundle_SetRoute(struct bundle *, int, struct in_addr,
struct in_addr, struct in_addr, int);
extern void bundle_LinkLost(struct bundle *, struct physical *, int);
extern void bundle_Close(struct bundle *, const char *, int);
extern void bundle_Open(struct bundle *, const char *, int);
extern void bundle_LinkClosed(struct bundle *, struct datalink *);

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: datalink.c,v 1.1.2.37 1998/04/14 23:17:04 brian Exp $
* $Id: datalink.c,v 1.1.2.38 1998/04/16 00:25:56 brian Exp $
*/
#include <sys/types.h>
@ -67,6 +67,7 @@
#include "datalink.h"
static const char *datalink_State(struct datalink *);
static void datalink_LoginDone(struct datalink *);
static void
datalink_OpenTimeout(void *v)
@ -102,6 +103,13 @@ datalink_StartDialTimer(struct datalink *dl, int Timeout)
static void
datalink_HangupDone(struct datalink *dl)
{
if (dl->physical->type == PHYS_DEDICATED && !dl->bundle->CleaningUp &&
Physical_GetFD(dl->physical) != -1) {
/* Don't close our modem if the link is dedicated */
datalink_LoginDone(dl);
return;
}
modem_Close(dl->physical);
dl->phone.chosen = "N/A";
@ -167,8 +175,12 @@ datalink_LoginDone(struct datalink *dl)
dl->state = DATALINK_HANGUP;
modem_Offline(dl->physical);
chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, 1, NULL);
} else
} else {
if (dl->physical->type == PHYS_DEDICATED)
/* force a redial timeout */
modem_Close(dl->physical);
datalink_HangupDone(dl);
}
} else {
dl->dial_tries = -1;

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.77.2.49 1998/04/10 23:51:30 brian Exp $
* $Id: modem.c,v 1.77.2.50 1998/04/16 00:26:09 brian Exp $
*
* TODO:
*/
@ -79,7 +79,6 @@
#endif
#endif
static void modem_Hangup(struct physical *, int);
static void modem_DescriptorWrite(struct descriptor *, struct bundle *,
const fd_set *);
static void modem_DescriptorRead(struct descriptor *, struct bundle *,
@ -287,8 +286,7 @@ modem_Timeout(void *data)
if (to->modem->fd >= 0) {
if (ioctl(to->modem->fd, TIOCMGET, &to->modem->mbits) < 0) {
LogPrintf(LogPHASE, "ioctl error (%s)!\n", strerror(errno));
modem_Hangup(to->modem, 0);
bundle_LinkLost(to->bundle, to->modem, 0);
datalink_Down(to->modem->dl, 0);
return;
}
} else
@ -303,8 +301,8 @@ modem_Timeout(void *data)
*/
} else {
LogPrintf(LogDEBUG, "modem_Timeout: online -> offline\n");
modem_Hangup(to->modem, 0);
bundle_LinkLost(to->bundle, to->modem, 0);
LogPrintf(LogPHASE, "%s: Carrier lost\n", to->modem->link.name);
datalink_Down(to->modem->dl, 0);
}
}
else
@ -520,22 +518,18 @@ modem_Open(struct physical *modem, struct bundle *bundle)
strncpy(tmpDeviceList, modem->cfg.devlist, sizeof tmpDeviceList - 1);
tmpDeviceList[sizeof tmpDeviceList - 1] = '\0';
for(tmpDevice=strtok(tmpDeviceList, ", "); tmpDevice && (modem->fd < 0);
for(tmpDevice=strtok(tmpDeviceList, ", "); tmpDevice && modem->fd < 0;
tmpDevice=strtok(NULL,", ")) {
modem_SetDevice(modem, tmpDevice);
if (*modem->name.full == '/') {
if (modem_lock(modem, bundle->unit) == -1)
modem->fd = -1;
else {
if (modem_lock(modem, bundle->unit) != -1) {
modem->fd = ID0open(modem->name.full, O_RDWR | O_NONBLOCK);
if (modem->fd < 0) {
LogPrintf(LogERROR, "modem_Open failed: %s: %s\n", modem->name.full,
strerror(errno));
modem_Unlock(modem);
modem->fd = -1;
}
else {
} else {
modem_Found(modem, bundle);
LogPrintf(LogDEBUG, "modem_Open: Modem is %s\n", modem->name.full);
}
@ -712,24 +706,12 @@ modem_PhysicalClose(struct physical *modem)
LogPrintf(LogDEBUG, "modem_PhysicalClose\n");
close(modem->fd);
modem->fd = -1;
StopTimer(&modem->link.Timer);
bundle_SetTtyCommandMode(modem->dl->bundle, modem->dl);
throughput_stop(&modem->link.throughput);
throughput_log(&modem->link.throughput, LogPHASE, "Modem");
}
static int force_hack;
static void
modem_Hangup(struct physical *modem, int dedicated_force)
{
/* We're about to close (pre hangup script) */
force_hack = dedicated_force;
if (modem->fd >= 0) {
StopTimer(&modem->link.Timer);
throughput_stop(&modem->link.throughput);
bundle_SetTtyCommandMode(modem->dl->bundle, modem->dl);
}
}
void
modem_Offline(struct physical *modem)
{
@ -757,9 +739,6 @@ modem_Close(struct physical *modem)
LogPrintf(LogDEBUG, "Close modem\n");
if (modem->link.Timer.load)
modem_Hangup(modem, force_hack);
if (!isatty(modem->fd)) {
modem_PhysicalClose(modem);
*modem->name.full = '\0';
@ -768,18 +747,9 @@ modem_Close(struct physical *modem)
}
if (modem->fd >= 0) {
if (force_hack || modem->type != PHYS_DEDICATED) {
tcflush(modem->fd, TCIOFLUSH);
modem_Unraw(modem);
modem_LogicalClose(modem);
} else {
/*
* If we are working as dedicated mode, never close it until we are
* directed to quit program.
*/
modem->mbits |= TIOCM_DTR;
ioctl(modem->fd, TIOCMSET, &modem->mbits);
}
tcflush(modem->fd, TCIOFLUSH);
modem_Unraw(modem);
modem_LogicalClose(modem);
}
}
@ -827,8 +797,7 @@ modem_DescriptorWrite(struct descriptor *d, struct bundle *bundle,
if (errno != EAGAIN) {
LogPrintf(LogERROR, "modem write (%d): %s\n", modem->fd,
strerror(errno));
modem_Hangup(modem, 0);
bundle_LinkLost(bundle, modem, 0);
datalink_Down(modem->dl, 0);
}
}
}
@ -929,10 +898,9 @@ modem_DescriptorRead(struct descriptor *d, struct bundle *bundle,
nointr_usleep(10000);
n = Physical_Read(p, rbuff, sizeof rbuff);
if (p->type == PHYS_STDIN && n <= 0) {
modem_Hangup(p, 0);
bundle_LinkLost(bundle, p, 1);
} else
if (p->type == PHYS_STDIN && n <= 0)
datalink_Down(p->dl, 0);
else
LogDumpBuff(LogASYNC, "ReadFromModem", rbuff, n);
if (p->link.lcp.fsm.state <= ST_CLOSED) {

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: timer.c,v 1.27.2.3 1998/04/06 09:12:37 brian Exp $
* $Id: timer.c,v 1.27.2.4 1998/04/07 00:54:22 brian Exp $
*
* TODO:
*/
@ -137,7 +137,7 @@ StopTimerNoBlock(struct pppTimer * tp)
if (t->next)
t->next->rest += tp->rest;
} else
LogPrintf(LogERROR, "Oops, timer not found!!\n");
LogPrintf(LogERROR, "Oops, %s timer not found!!\n", tp->name);
tp->next = NULL;
tp->state = TIMER_STOPPED;