summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1999-10-25 13:49:44 +0000
committerbrian <brian@FreeBSD.org>1999-10-25 13:49:44 +0000
commitfaf44b90cf2e4d2d75fff652e8cb0061ebab8994 (patch)
treeb36fb5cffe5612b95ee430fdf57bd17fca7266f3 /usr.sbin
parent6d6b73fcc1ed1fbea8e5b101a078ef2894fd5c1b (diff)
downloadFreeBSD-src-faf44b90cf2e4d2d75fff652e8cb0061ebab8994.zip
FreeBSD-src-faf44b90cf2e4d2d75fff652e8cb0061ebab8994.tar.gz
Introduce ``set logout''; another chat script. This is in preparation
for the abstraction of ``set dial'' and ``set hangup''.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/ppp/chat.c4
-rw-r--r--usr.sbin/ppp/chat.h2
-rw-r--r--usr.sbin/ppp/command.c8
-rw-r--r--usr.sbin/ppp/datalink.c57
-rw-r--r--usr.sbin/ppp/datalink.h22
-rw-r--r--usr.sbin/ppp/ppp.86
-rw-r--r--usr.sbin/ppp/ppp.8.m46
7 files changed, 73 insertions, 32 deletions
diff --git a/usr.sbin/ppp/chat.c b/usr.sbin/ppp/chat.c
index 86fd40b..f3bc7d6 100644
--- a/usr.sbin/ppp/chat.c
+++ b/usr.sbin/ppp/chat.c
@@ -531,7 +531,7 @@ chat_Write(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
}
void
-chat_Init(struct chat *c, struct physical *p, const char *data, int emptybuf,
+chat_Init(struct chat *c, struct physical *p, const char *data,
const char *phone)
{
c->desc.type = CHAT_DESCRIPTOR;
@@ -556,7 +556,7 @@ chat_Init(struct chat *c, struct physical *p, const char *data, int emptybuf,
c->argptr = NULL;
c->nargptr = NULL;
- if (emptybuf)
+ if (c->bufstart == NULL)
c->bufstart = c->bufend = c->buf;
c->TimeoutSec = 30;
diff --git a/usr.sbin/ppp/chat.h b/usr.sbin/ppp/chat.h
index 0356627..90d625d 100644
--- a/usr.sbin/ppp/chat.h
+++ b/usr.sbin/ppp/chat.h
@@ -76,6 +76,6 @@ struct chat {
((d)->type == CHAT_DESCRIPTOR ? (struct chat *)(d) : NULL)
#define VECSIZE(v) (sizeof(v) / sizeof(v[0]))
-extern void chat_Init(struct chat *, struct physical *, const char *, int,
+extern void chat_Init(struct chat *, struct physical *, const char *,
const char *);
extern void chat_Destroy(struct chat *);
diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c
index 599e91c..3c0bc51 100644
--- a/usr.sbin/ppp/command.c
+++ b/usr.sbin/ppp/command.c
@@ -123,6 +123,7 @@
#define VAR_PARITY 31
#define VAR_CRTSCTS 32
#define VAR_URGENTPORTS 33
+#define VAR_LOGOUT 34
/* ``accept|deny|disable|enable'' masks */
#define NEG_HISMASK (1)
@@ -1595,6 +1596,11 @@ SetVariable(struct cmdargs const *arg)
cx->cfg.script.hangup[sizeof cx->cfg.script.hangup - 1] = '\0';
break;
+ case VAR_LOGOUT:
+ strncpy(cx->cfg.script.logout, argp, sizeof cx->cfg.script.logout - 1);
+ cx->cfg.script.logout[sizeof cx->cfg.script.logout - 1] = '\0';
+ break;
+
case VAR_IDLETIMEOUT:
if (arg->argc > arg->argn+2)
err = "Too many idle timeout values\n";
@@ -1894,6 +1900,8 @@ static struct cmdtab const SetCommands[] = {
"ipcp|lcp|lqm|phase|physical|sync|tcp/ip|timer|tun..."},
{"login", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
"login script", "set login chat-script", (const void *) VAR_LOGIN},
+ {"logout", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
+ "logout script", "set logout chat-script", (const void *) VAR_LOGOUT},
{"lqrperiod", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX_OPT,
"LQR period", "set lqrperiod value", (const void *)VAR_LQRPERIOD},
{"mode", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX, "mode value",
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));
diff --git a/usr.sbin/ppp/datalink.h b/usr.sbin/ppp/datalink.h
index 962f5d3..8101849 100644
--- a/usr.sbin/ppp/datalink.h
+++ b/usr.sbin/ppp/datalink.h
@@ -31,12 +31,13 @@
#define DATALINK_HANGUP (2)
#define DATALINK_DIAL (3)
#define DATALINK_CARRIER (4)
-#define DATALINK_LOGIN (5)
-#define DATALINK_READY (6)
-#define DATALINK_LCP (7)
-#define DATALINK_AUTH (8)
-#define DATALINK_CBCP (9)
-#define DATALINK_OPEN (10)
+#define DATALINK_LOGOUT (5)
+#define DATALINK_LOGIN (6)
+#define DATALINK_READY (7)
+#define DATALINK_LCP (8)
+#define DATALINK_AUTH (9)
+#define DATALINK_CBCP (10)
+#define DATALINK_OPEN (11)
#define DATALINK_MAXNAME (20) /* Maximum datalink::name length */
@@ -65,10 +66,11 @@ struct datalink {
struct {
struct {
- char dial[SCRIPT_LEN]; /* dial */
- char login[SCRIPT_LEN]; /* login */
- char hangup[SCRIPT_LEN]; /* hangup */
- } script;
+ char dial[SCRIPT_LEN];
+ char login[SCRIPT_LEN];
+ char logout[SCRIPT_LEN];
+ char hangup[SCRIPT_LEN];
+ } script; /* various chat scripts */
struct {
char list[SCRIPT_LEN]; /* Telephone Numbers */
} phone;
diff --git a/usr.sbin/ppp/ppp.8 b/usr.sbin/ppp/ppp.8
index 4970a1b..95d1949 100644
--- a/usr.sbin/ppp/ppp.8
+++ b/usr.sbin/ppp/ppp.8
@@ -1982,7 +1982,8 @@ Generate a CCP packet trace.
.It Li Chat
Generate
.Sq dial ,
-.Sq login
+.Sq login ,
+.Sq logout
and
.Sq hangup
chat script trace logs.
@@ -4135,6 +4136,9 @@ This
compliments the dial-script. If both are specified, the login
script will be executed after the dial script. Escape sequences
available in the dial script are also available here.
+.It set logout Ar chat-script
+This specifies the chat script that will be used to logout
+before the hangup script is called. It should not normally be necessary.
.It set lqrperiod Ar frequency
This command sets the
.Ar frequency
diff --git a/usr.sbin/ppp/ppp.8.m4 b/usr.sbin/ppp/ppp.8.m4
index 4970a1b..95d1949 100644
--- a/usr.sbin/ppp/ppp.8.m4
+++ b/usr.sbin/ppp/ppp.8.m4
@@ -1982,7 +1982,8 @@ Generate a CCP packet trace.
.It Li Chat
Generate
.Sq dial ,
-.Sq login
+.Sq login ,
+.Sq logout
and
.Sq hangup
chat script trace logs.
@@ -4135,6 +4136,9 @@ This
compliments the dial-script. If both are specified, the login
script will be executed after the dial script. Escape sequences
available in the dial script are also available here.
+.It set logout Ar chat-script
+This specifies the chat script that will be used to logout
+before the hangup script is called. It should not normally be necessary.
.It set lqrperiod Ar frequency
This command sets the
.Ar frequency
OpenPOWER on IntegriCloud