diff options
Diffstat (limited to 'usr.sbin/ppp/datalink.c')
-rw-r--r-- | usr.sbin/ppp/datalink.c | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/usr.sbin/ppp/datalink.c b/usr.sbin/ppp/datalink.c index 80a5f5e..4313fd5 100644 --- a/usr.sbin/ppp/datalink.c +++ b/usr.sbin/ppp/datalink.c @@ -120,6 +120,7 @@ datalink_HangupDone(struct datalink *dl) return; } + chat_Destroy(&dl->chat); physical_Close(dl->physical); dl->phone.chosen = "N/A"; @@ -202,6 +203,8 @@ datalink_ChoosePhoneNumber(struct datalink *dl) static void datalink_LoginDone(struct datalink *dl) { + chat_Destroy(&dl->chat); + if (!dl->script.packetmode) { dl->dial.tries = -1; dl->dial.incs = 0; @@ -210,9 +213,8 @@ datalink_LoginDone(struct datalink *dl) dl->dial.tries = 0; log_Printf(LogWARN, "datalink_LoginDone: Not connected.\n"); if (dl->script.run) { - datalink_NewState(dl, DATALINK_HANGUP); - physical_Offline(dl->physical); - chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, 1, NULL); + datalink_NewState(dl, DATALINK_LOGOUT); + chat_Init(&dl->chat, dl->physical, dl->cfg.script.logout, NULL); } else { physical_StopDeviceTimer(dl->physical); if (dl->physical->type == PHYS_DEDICATED) @@ -270,7 +272,7 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, dl->physical->name.full); if (dl->script.run) { datalink_NewState(dl, DATALINK_DIAL); - chat_Init(&dl->chat, dl->physical, dl->cfg.script.dial, 1, + chat_Init(&dl->chat, dl->physical, dl->cfg.script.dial, *dl->cfg.script.dial ? datalink_ChoosePhoneNumber(dl) : ""); if (!(dl->physical->type & (PHYS_DDIAL|PHYS_DEDICATED)) && @@ -320,7 +322,7 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, case CARRIER_OK: if (dl->script.run) { datalink_NewState(dl, DATALINK_LOGIN); - chat_Init(&dl->chat, dl->physical, dl->cfg.script.login, 0, NULL); + chat_Init(&dl->chat, dl->physical, dl->cfg.script.login, NULL); } else datalink_LoginDone(dl); return datalink_UpdateSet(d, r, w, e, n); @@ -329,7 +331,7 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, physical_Offline(dl->physical); /* Is this required ? */ if (dl->script.run) { datalink_NewState(dl, DATALINK_HANGUP); - chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, 1, NULL); + chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, NULL); } else datalink_HangupDone(dl); return datalink_UpdateSet(d, r, w, e, n); @@ -337,12 +339,12 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, case DATALINK_HANGUP: case DATALINK_DIAL: + case DATALINK_LOGOUT: case DATALINK_LOGIN: result = descriptor_UpdateSet(&dl->chat.desc, r, w, e, n); switch (dl->chat.state) { case CHAT_DONE: /* script succeeded */ - chat_Destroy(&dl->chat); switch(dl->state) { case DATALINK_HANGUP: datalink_HangupDone(dl); @@ -350,6 +352,11 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, case DATALINK_DIAL: datalink_NewState(dl, DATALINK_CARRIER); return datalink_UpdateSet(d, r, w, e, n); + case DATALINK_LOGOUT: + datalink_NewState(dl, DATALINK_HANGUP); + physical_Offline(dl->physical); + chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, NULL); + return datalink_UpdateSet(d, r, w, e, n); case DATALINK_LOGIN: dl->phone.alt = NULL; datalink_LoginDone(dl); @@ -359,17 +366,16 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, case CHAT_FAILED: /* Going down - script failed */ log_Printf(LogWARN, "Chat script failed\n"); - chat_Destroy(&dl->chat); switch(dl->state) { case DATALINK_HANGUP: datalink_HangupDone(dl); break; case DATALINK_DIAL: + case DATALINK_LOGOUT: case DATALINK_LOGIN: datalink_NewState(dl, DATALINK_HANGUP); - physical_Offline(dl->physical); /* Is this required ? */ - chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, - 1, NULL); + physical_Offline(dl->physical); + chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, NULL); return datalink_UpdateSet(d, r, w, e, n); } break; @@ -406,6 +412,7 @@ datalink_IsSet(struct descriptor *d, const fd_set *fdset) case DATALINK_HANGUP: case DATALINK_DIAL: + case DATALINK_LOGOUT: case DATALINK_LOGIN: return descriptor_IsSet(&dl->chat.desc, fdset); @@ -432,6 +439,7 @@ datalink_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset) case DATALINK_HANGUP: case DATALINK_DIAL: + case DATALINK_LOGOUT: case DATALINK_LOGIN: descriptor_Read(&dl->chat.desc, bundle, fdset); break; @@ -462,6 +470,7 @@ datalink_Write(struct descriptor *d, struct bundle *bundle, const fd_set *fdset) case DATALINK_HANGUP: case DATALINK_DIAL: + case DATALINK_LOGOUT: case DATALINK_LOGIN: result = descriptor_Write(&dl->chat.desc, bundle, fdset); break; @@ -497,10 +506,14 @@ datalink_ComeDown(struct datalink *dl, int how) datalink_NewState(dl, DATALINK_READY); } else if (dl->state != DATALINK_CLOSED && dl->state != DATALINK_HANGUP) { physical_Offline(dl->physical); - chat_Destroy(&dl->chat); if (dl->script.run && dl->state != DATALINK_OPENING) { - datalink_NewState(dl, DATALINK_HANGUP); - chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, 1, NULL); + if (dl->state == DATALINK_LOGOUT) { + datalink_NewState(dl, DATALINK_HANGUP); + chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, NULL); + } else { + datalink_NewState(dl, DATALINK_LOGOUT); + chat_Init(&dl->chat, dl->physical, dl->cfg.script.logout, NULL); + } } else datalink_HangupDone(dl); } @@ -756,6 +769,7 @@ datalink_Create(const char *name, struct bundle *bundle, int type) *dl->cfg.script.dial = '\0'; *dl->cfg.script.login = '\0'; + *dl->cfg.script.logout = '\0'; *dl->cfg.script.hangup = '\0'; *dl->cfg.phone.list = '\0'; *dl->phone.list = '\0'; @@ -806,7 +820,9 @@ datalink_Create(const char *name, struct bundle *bundle, int type) pap_Init(&dl->pap, dl->physical); chap_Init(&dl->chap, dl->physical); cbcp_Init(&dl->cbcp, dl->physical); - chat_Init(&dl->chat, dl->physical, NULL, 1, NULL); + + memset(&dl->chat, '\0', sizeof dl->chat); /* Force buf{start,end} reset */ + chat_Init(&dl->chat, dl->physical, NULL, NULL); log_Printf(LogPHASE, "%s: Created in %s state\n", dl->name, datalink_State(dl)); @@ -868,7 +884,9 @@ datalink_Clone(struct datalink *odl, const char *name) sizeof dl->physical->async.cfg); cbcp_Init(&dl->cbcp, dl->physical); - chat_Init(&dl->chat, dl->physical, NULL, 1, NULL); + + memset(&dl->chat, '\0', sizeof dl->chat); /* Force buf{start,end} reset */ + chat_Init(&dl->chat, dl->physical, NULL, NULL); log_Printf(LogPHASE, "%s: Cloned in %s state\n", dl->name, datalink_State(dl)); @@ -1084,6 +1102,8 @@ datalink_Show(struct cmdargs const *arg) arg->cx->cfg.script.dial); prompt_Printf(arg->prompt, " Login Script: %s\n", arg->cx->cfg.script.login); + prompt_Printf(arg->prompt, " Logout Script: %s\n", + arg->cx->cfg.script.logout); prompt_Printf(arg->prompt, " Hangup Script: %s\n", arg->cx->cfg.script.hangup); return 0; @@ -1193,6 +1213,7 @@ static const char *states[] = { "hangup", "dial", "carrier", + "logout", "login", "ready", "lcp", @@ -1301,7 +1322,9 @@ iov2datalink(struct bundle *bundle, struct iovec *iov, int *niov, int maxiov, dl->chap.auth.cfg.fsm = copy; cbcp_Init(&dl->cbcp, dl->physical); - chat_Init(&dl->chat, dl->physical, NULL, 1, NULL); + + memset(&dl->chat, '\0', sizeof dl->chat); /* Force buf{start,end} reset */ + chat_Init(&dl->chat, dl->physical, NULL, NULL); log_Printf(LogPHASE, "%s: Transferred in %s state\n", dl->name, datalink_State(dl)); |