Introduce the ``link'' command for controlling

individual links.
This commit is contained in:
Brian Somers 1998-02-17 19:28:01 +00:00
parent c5a5a6ca93
commit aef795cc3b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/MP/; revision=33508
9 changed files with 212 additions and 149 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.10 1998/02/16 19:09:37 brian Exp $
* $Id: bundle.c,v 1.1.2.11 1998/02/17 01:05:33 brian Exp $
*/
#include <sys/param.h>
@ -92,6 +92,9 @@ bundle_PhaseName(struct bundle *bundle)
void
bundle_NewPhase(struct bundle *bundle, struct physical *physical, u_int new)
{
if (new == bundle->phase)
return;
if (new <= PHASE_NETWORK)
LogPrintf(LogPHASE, "bundle_NewPhase: %s\n", PhaseNames[new]);
@ -606,8 +609,7 @@ bundle_LayerFinish(struct bundle *bundle, struct fsm *fp)
} else if (fp == &IpcpInfo.fsm) {
struct datalink *dl;
if (fp->bundle->phase != PHASE_TERMINATE)
bundle_NewPhase(bundle, NULL, PHASE_TERMINATE);
bundle_NewPhase(bundle, NULL, PHASE_TERMINATE);
for (dl = bundle->links; dl; dl = dl->next)
datalink_Close(dl, 1);
@ -630,6 +632,7 @@ bundle_Open(struct bundle *bundle, const char *name)
if (name != NULL)
break;
}
bundle_NewPhase(bundle, NULL, PHASE_ESTABLISH);
}
struct datalink *
@ -692,3 +695,15 @@ bundle_FillQueues(struct bundle *bundle)
return total;
}
int
bundle_ShowLinks(struct cmdargs const *arg)
{
struct datalink *dl;
prompt_Printf(&prompt, "The following links are defined:\n");
for (dl = arg->bundle->links; dl; dl = dl->next)
prompt_Printf(&prompt, "\t%s\n", dl->name);
return 0;
}

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.7 1998/02/08 19:29:43 brian Exp $
* $Id: bundle.h,v 1.1.2.8 1998/02/15 23:59:40 brian Exp $
*/
#define PHASE_DEAD 0 /* Link is dead */
@ -72,3 +72,4 @@ extern struct datalink *bundle2datalink(struct bundle *, const char *);
extern int bundle_UpdateSet(struct bundle *, fd_set *, fd_set *, fd_set *,
int *);
extern int bundle_FillQueues(struct bundle *);
extern int bundle_ShowLinks(struct cmdargs const *);

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.131.2.20 1998/02/16 19:10:57 brian Exp $
* $Id: command.c,v 1.131.2.21 1998/02/17 01:05:36 brian Exp $
*
*/
#include <sys/param.h>
@ -83,22 +83,23 @@
struct in_addr ifnetmask;
static const char *HIDDEN = "********";
static int ShowCommand(struct cmdargs const *arg);
static int TerminalCommand(struct cmdargs const *arg);
static int QuitCommand(struct cmdargs const *arg);
static int CloseCommand(struct cmdargs const *arg);
static int DialCommand(struct cmdargs const *arg);
static int DownCommand(struct cmdargs const *arg);
static int AllowCommand(struct cmdargs const *arg);
static int SetCommand(struct cmdargs const *arg);
static int AddCommand(struct cmdargs const *arg);
static int DeleteCommand(struct cmdargs const *arg);
static int BgShellCommand(struct cmdargs const *arg);
static int FgShellCommand(struct cmdargs const *arg);
static int ShowCommand(struct cmdargs const *);
static int TerminalCommand(struct cmdargs const *);
static int QuitCommand(struct cmdargs const *);
static int CloseCommand(struct cmdargs const *);
static int DialCommand(struct cmdargs const *);
static int DownCommand(struct cmdargs const *);
static int AllowCommand(struct cmdargs const *);
static int SetCommand(struct cmdargs const *);
static int LinkCommand(struct cmdargs const *);
static int AddCommand(struct cmdargs const *);
static int DeleteCommand(struct cmdargs const *);
static int BgShellCommand(struct cmdargs const *);
static int FgShellCommand(struct cmdargs const *);
#ifndef NOALIAS
static int AliasCommand(struct cmdargs const *arg);
static int AliasEnable(struct cmdargs const *arg);
static int AliasOption(struct cmdargs const *arg);
static int AliasCommand(struct cmdargs const *);
static int AliasEnable(struct cmdargs const *);
static int AliasOption(struct cmdargs const *);
#endif
static int
@ -108,7 +109,7 @@ HelpCommand(struct cmdargs const *arg)
int n, cmax, dmax, cols;
if (arg->argc > 0) {
for (cmd = arg->cmd; cmd->name; cmd++)
for (cmd = arg->cmdtab; cmd->name; cmd++)
if (strcasecmp(cmd->name, *arg->argv) == 0 &&
(cmd->lauth & VarLocalAuth)) {
prompt_Printf(&prompt, "%s\n", cmd->syntax);
@ -117,7 +118,7 @@ HelpCommand(struct cmdargs const *arg)
return -1;
}
cmax = dmax = 0;
for (cmd = arg->cmd; cmd->func; cmd++)
for (cmd = arg->cmdtab; cmd->func; cmd++)
if (cmd->name && (cmd->lauth & VarLocalAuth)) {
if ((n = strlen(cmd->name)) > cmax)
cmax = n;
@ -127,7 +128,7 @@ HelpCommand(struct cmdargs const *arg)
cols = 80 / (dmax + cmax + 3);
n = 0;
for (cmd = arg->cmd; cmd->func; cmd++)
for (cmd = arg->cmdtab; cmd->func; cmd++)
if (cmd->name && (cmd->lauth & VarLocalAuth)) {
prompt_Printf(&prompt, " %-*.*s: %-*.*s",
cmax, cmax, cmd->name, dmax, dmax, cmd->helpmes);
@ -363,17 +364,19 @@ static struct cmdtab const Commands[] = {
"Enable option", "enable option .."},
{"passwd", NULL, LocalAuthCommand, LOCAL_NO_AUTH,
"Password for manipulation", "passwd LocalPassword"},
{"link", NULL, LinkCommand, LOCAL_AUTH,
"Link specific commands", "link name command ..."},
{"load", NULL, LoadCommand, LOCAL_AUTH,
"Load settings", "load [remote]"},
{"save", NULL, SaveCommand, LOCAL_AUTH,
"Save settings", "save"},
{"set", "setup", SetCommand, LOCAL_AUTH,
{"set", "setup", SetCommand, LOCAL_AUTH | LOCAL_CX_OPT,
"Set parameters", "set[up] var value"},
{"shell", "!", FgShellCommand, LOCAL_AUTH,
"Run a subshell", "shell|! [sh command]"},
{"show", NULL, ShowCommand, LOCAL_AUTH,
"Show status and stats", "show var"},
{"term", NULL, TerminalCommand, LOCAL_AUTH,
{"term", NULL, TerminalCommand, LOCAL_AUTH | LOCAL_CX,
"Enter terminal mode", "term"},
#ifndef NOALIAS
{"alias", NULL, AliasCommand, LOCAL_AUTH,
@ -513,34 +516,31 @@ ShowPreferredMTU(struct cmdargs const *arg)
static int
ShowReconnect(struct cmdargs const *arg)
{
struct datalink *dl = bundle2datalink(arg->bundle, NULL);
prompt_Printf(&prompt, "%s: Reconnect Timer: %d, %d tries\n",
dl->name, dl->reconnect_timeout, dl->max_reconnect);
arg->cx->name, arg->cx->reconnect_timeout,
arg->cx->max_reconnect);
return 0;
}
static int
ShowRedial(struct cmdargs const *arg)
{
struct datalink *dl = bundle2datalink(arg->bundle, NULL);
prompt_Printf(&prompt, " Redial Timer: ");
if (dl->dial_timeout >= 0)
prompt_Printf(&prompt, " %d seconds, ", dl->dial_timeout);
if (arg->cx->dial_timeout >= 0)
prompt_Printf(&prompt, " %d seconds, ", arg->cx->dial_timeout);
else
prompt_Printf(&prompt, " Random 0 - %d seconds, ", DIAL_TIMEOUT);
prompt_Printf(&prompt, " Redial Next Timer: ");
if (dl->dial_next_timeout >= 0)
prompt_Printf(&prompt, " %d seconds, ", dl->dial_next_timeout);
if (arg->cx->dial_next_timeout >= 0)
prompt_Printf(&prompt, " %d seconds, ", arg->cx->dial_next_timeout);
else
prompt_Printf(&prompt, " Random 0 - %d seconds, ", DIAL_TIMEOUT);
if (dl->max_dial)
prompt_Printf(&prompt, "%d dial tries", dl->max_dial);
if (arg->cx->max_dial)
prompt_Printf(&prompt, "%d dial tries", arg->cx->max_dial);
prompt_Printf(&prompt, "\n");
@ -587,13 +587,15 @@ static struct cmdtab const ShowCommands[] = {
"Show IPCP status", "show ipcp"},
{"lcp", NULL, ReportLcpStatus, LOCAL_AUTH,
"Show LCP status", "show lcp"},
{"links", "link", bundle_ShowLinks, LOCAL_AUTH,
"Show available link names", "show links"},
{"loopback", NULL, ShowLoopback, LOCAL_AUTH,
"Show loopback setting", "show loopback"},
{"log", NULL, ShowLogLevel, LOCAL_AUTH,
"Show log levels", "show log"},
{"mem", NULL, ShowMemMap, LOCAL_AUTH,
"Show memory map", "show mem"},
{"modem", NULL, modem_ShowStatus, LOCAL_AUTH,
{"modem", NULL, modem_ShowStatus, LOCAL_AUTH | LOCAL_CX,
"Show modem setups", "show modem"},
{"mru", NULL, ShowInitialMRU, LOCAL_AUTH,
"Show Initial MRU", "show mru"},
@ -607,9 +609,9 @@ static struct cmdtab const ShowCommands[] = {
"Show Output filters", "show ofilter option .."},
{"proto", NULL, Physical_ReportProtocolStatus, LOCAL_AUTH,
"Show protocol summary", "show proto"},
{"reconnect", NULL, ShowReconnect, LOCAL_AUTH,
{"reconnect", NULL, ShowReconnect, LOCAL_AUTH | LOCAL_CX,
"Show reconnect timer", "show reconnect"},
{"redial", NULL, ShowRedial, LOCAL_AUTH,
{"redial", NULL, ShowRedial, LOCAL_AUTH | LOCAL_CX,
"Show Redial timeout", "show redial"},
{"route", NULL, ShowRoute, LOCAL_AUTH,
"Show routing table", "show route"},
@ -658,7 +660,7 @@ FindCommand(struct cmdtab const *cmds, const char *str, int *pmatch)
static int
FindExec(struct bundle *bundle, struct cmdtab const *cmds, int argc,
char const *const *argv, const char *prefix)
char const *const *argv, const char *prefix, struct datalink *cx)
{
struct cmdtab const *cmd;
int val = 1;
@ -669,12 +671,27 @@ FindExec(struct bundle *bundle, struct cmdtab const *cmds, int argc,
if (nmatch > 1)
LogPrintf(LogWARN, "%s%s: Ambiguous command\n", prefix, *argv);
else if (cmd && (cmd->lauth & VarLocalAuth)) {
arg.cmd = cmds;
arg.argc = argc-1;
arg.argv = argv+1;
arg.data = cmd->args;
arg.bundle = bundle;
val = (cmd->func) (&arg);
if ((cmd->lauth & LOCAL_CX) && !cx)
/* We've got no context, but we require it */
cx = bundle2datalink(bundle, NULL);
if ((cmd->lauth & LOCAL_CX) && !cx)
LogPrintf(LogWARN, "%s%s: No context (use the `link' command)\n",
prefix, *argv);
else {
if (cx && !(cmd->lauth & (LOCAL_CX|LOCAL_CX_OPT))) {
LogPrintf(LogWARN, "%s%s: Redundant context (%s) ignored\n",
prefix, *argv, cx->name);
cx = NULL;
}
arg.cmdtab = cmds;
arg.cmd = cmd;
arg.argc = argc-1;
arg.argv = argv+1;
arg.bundle = bundle;
arg.cx = cx;
val = (cmd->func) (&arg);
}
} else
LogPrintf(LogWARN, "%s%s: Invalid command\n", prefix, *argv);
@ -747,7 +764,7 @@ RunCommand(struct bundle *bundle, int argc, char const *const *argv,
}
LogPrintf(LogCOMMAND, "%s\n", buf);
}
FindExec(bundle, Commands, argc, argv, "");
FindExec(bundle, Commands, argc, argv, "", NULL);
}
}
@ -767,7 +784,7 @@ ShowCommand(struct cmdargs const *arg)
if (!prompt_Active(&prompt))
LogPrintf(LogWARN, "show: Cannot show without a prompt\n");
else if (arg->argc > 0)
FindExec(arg->bundle, ShowCommands, arg->argc, arg->argv, "show ");
FindExec(arg->bundle, ShowCommands, arg->argc, arg->argv, "show ", arg->cx);
else if (prompt_Active(&prompt))
prompt_Printf(&prompt, "Use ``show ?'' to get a list.\n");
else
@ -779,8 +796,6 @@ ShowCommand(struct cmdargs const *arg)
static int
TerminalCommand(struct cmdargs const *arg)
{
struct datalink *dl = bundle2datalink(arg->bundle, NULL);
if (LcpInfo.fsm.state > ST_CLOSED) {
prompt_Printf(&prompt, "LCP state is [%s]\n",
StateNames[LcpInfo.fsm.state]);
@ -790,7 +805,7 @@ TerminalCommand(struct cmdargs const *arg)
if (!IsInteractive(1))
return (1);
datalink_Up(dl, 0, 0);
datalink_Up(arg->cx, 0, 0);
prompt_Printf(&prompt, "Entering terminal mode.\n");
prompt_Printf(&prompt, "Type `~?' for help.\n");
prompt_TtyTermMode(&prompt);
@ -859,10 +874,8 @@ static int
SetReconnect(struct cmdargs const *arg)
{
if (arg->argc == 2) {
struct datalink *dl = bundle2datalink(arg->bundle, NULL);
dl->reconnect_timeout = atoi(arg->argv[0]);
dl->max_reconnect = (mode & MODE_DIRECT) ? 0 : atoi(arg->argv[1]);
arg->cx->reconnect_timeout = atoi(arg->argv[0]);
arg->cx->max_reconnect = (mode & MODE_DIRECT) ? 0 : atoi(arg->argv[1]);
return 0;
}
return -1;
@ -871,7 +884,6 @@ SetReconnect(struct cmdargs const *arg)
static int
SetRedialTimeout(struct cmdargs const *arg)
{
struct datalink *dl = bundle2datalink(arg->bundle, NULL);
int timeout;
int tries;
char *dot;
@ -879,13 +891,13 @@ SetRedialTimeout(struct cmdargs const *arg)
if (arg->argc == 1 || arg->argc == 2) {
if (strncasecmp(arg->argv[0], "random", 6) == 0 &&
(arg->argv[0][6] == '\0' || arg->argv[0][6] == '.')) {
dl->dial_timeout = -1;
arg->cx->dial_timeout = -1;
randinit();
} else {
timeout = atoi(arg->argv[0]);
if (timeout >= 0)
dl->dial_timeout = timeout;
arg->cx->dial_timeout = timeout;
else {
LogPrintf(LogWARN, "Invalid redial timeout\n");
return -1;
@ -895,25 +907,26 @@ SetRedialTimeout(struct cmdargs const *arg)
dot = strchr(arg->argv[0], '.');
if (dot) {
if (strcasecmp(++dot, "random") == 0) {
dl->dial_next_timeout = -1;
arg->cx->dial_next_timeout = -1;
randinit();
} else {
timeout = atoi(dot);
if (timeout >= 0)
dl->dial_next_timeout = timeout;
arg->cx->dial_next_timeout = timeout;
else {
LogPrintf(LogWARN, "Invalid next redial timeout\n");
return -1;
}
}
} else
dl->dial_next_timeout = DIAL_NEXT_TIMEOUT; /* Default next timeout */
/* Default next timeout */
arg->cx->dial_next_timeout = DIAL_NEXT_TIMEOUT;
if (arg->argc == 2) {
tries = atoi(arg->argv[1]);
if (tries >= 0) {
dl->max_dial = tries;
arg->cx->max_dial = tries;
} else {
LogPrintf(LogWARN, "Invalid retry value\n");
return 1;
@ -1279,19 +1292,29 @@ SetNBNS(struct cmdargs const *arg)
#endif /* MS_EXT */
int
static int
SetVariable(struct cmdargs const *arg)
{
struct datalink *dl = bundle2datalink(arg->bundle, NULL);
u_long map;
const char *argp;
int param = (int)arg->data;
int param = (int)arg->cmd->args;
struct datalink *cx = arg->cx;
if (arg->argc > 0)
argp = *arg->argv;
else
argp = "";
if ((arg->cmd->lauth & LOCAL_CX) && !cx) {
LogPrintf(LogWARN, "set %s: No context (use the `link' command)\n",
arg->cmd->name);
return 1;
} else if (cx && !(arg->cmd->lauth & (LOCAL_CX|LOCAL_CX_OPT))) {
LogPrintf(LogWARN, "set %s: Redundant context (%s) ignored\n",
arg->cmd->name, cx->name);
cx = NULL;
}
switch (param) {
case VAR_AUTHKEY:
strncpy(VarAuthKey, argp, sizeof VarAuthKey - 1);
@ -1303,24 +1326,18 @@ SetVariable(struct cmdargs const *arg)
break;
case VAR_DIAL:
if (!(mode & (MODE_DIRECT|MODE_DEDICATED))) {
strncpy(dl->script.dial, argp, sizeof dl->script.dial - 1);
dl->script.dial[sizeof dl->script.dial - 1] = '\0';
strncpy(cx->script.dial, argp, sizeof cx->script.dial - 1);
cx->script.dial[sizeof cx->script.dial - 1] = '\0';
}
break;
case VAR_LOGIN:
if (!(mode & (MODE_DIRECT|MODE_DEDICATED))) {
strncpy(dl->script.login, argp, sizeof dl->script.login - 1);
dl->script.login[sizeof dl->script.login - 1] = '\0';
strncpy(cx->script.login, argp, sizeof cx->script.login - 1);
cx->script.login[sizeof cx->script.login - 1] = '\0';
}
break;
case VAR_DEVICE:
if (link_IsActive(&arg->bundle->links->physical->link))
LogPrintf(LogWARN,
"Cannot change device to \"%s\" when \"%s\" is open\n",
argp, Physical_GetDevice(bundle2physical(arg->bundle, NULL)));
else {
Physical_SetDevice(bundle2physical(arg->bundle, NULL), argp);
}
modem_SetDeviceName(cx->physical, argp);
break;
case VAR_ACCMAP:
sscanf(argp, "%lx", &map);
@ -1336,8 +1353,8 @@ SetVariable(struct cmdargs const *arg)
break;
case VAR_HANGUP:
if (!(mode & (MODE_DIRECT|MODE_DEDICATED))) {
strncpy(dl->script.hangup, argp, sizeof dl->script.hangup - 1);
dl->script.hangup[sizeof dl->script.hangup - 1] = '\0';
strncpy(cx->script.hangup, argp, sizeof cx->script.hangup - 1);
cx->script.hangup[sizeof cx->script.hangup - 1] = '\0';
}
break;
#ifdef HAVE_DES
@ -1386,7 +1403,7 @@ SetOpenMode(struct cmdargs const *arg)
}
static struct cmdtab const SetCommands[] = {
{"accmap", NULL, SetVariable, LOCAL_AUTH,
{"accmap", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
"Set accmap value", "set accmap hex-value", (const void *) VAR_ACCMAP},
{"afilter", NULL, SetAfilter, LOCAL_AUTH,
"Set keep Alive filter", "set afilter ..."},
@ -1394,21 +1411,22 @@ static struct cmdtab const SetCommands[] = {
"Set authentication key", "set authkey|key key", (const void *) VAR_AUTHKEY},
{"authname", NULL, SetVariable, LOCAL_AUTH,
"Set authentication name", "set authname name", (const void *) VAR_AUTHNAME},
{"ctsrts", NULL, SetCtsRts, LOCAL_AUTH,
{"ctsrts", NULL, SetCtsRts, LOCAL_AUTH | LOCAL_CX,
"Use CTS/RTS modem signalling", "set ctsrts [on|off]"},
{"device", "line", SetVariable, LOCAL_AUTH, "Set modem device name",
"set device|line device-name[,device-name]", (const void *) VAR_DEVICE},
{"device", "line", SetVariable, LOCAL_AUTH | LOCAL_CX,
"Set modem device name", "set device|line device-name[,device-name]",
(const void *) VAR_DEVICE},
{"dfilter", NULL, SetDfilter, LOCAL_AUTH,
"Set demand filter", "set dfilter ..."},
{"dial", NULL, SetVariable, LOCAL_AUTH,
{"dial", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
"Set dialing script", "set dial chat-script", (const void *) VAR_DIAL},
#ifdef HAVE_DES
{"encrypt", NULL, SetVariable, LOCAL_AUTH, "Set CHAP encryption algorithm",
"set encrypt MSChap|MD5", (const void *) VAR_ENC},
#endif
{"escape", NULL, SetEscape, LOCAL_AUTH,
{"escape", NULL, SetEscape, LOCAL_AUTH | LOCAL_CX,
"Set escape characters", "set escape hex-digit ..."},
{"hangup", NULL, SetVariable, LOCAL_AUTH,
{"hangup", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
"Set hangup script", "set hangup chat-script", (const void *) VAR_HANGUP},
{"ifaddr", NULL, SetInterfaceAddr, LOCAL_AUTH, "Set destination address",
"set ifaddr [src-addr [dst-addr [netmask [trg-addr]]]]"},
@ -1418,7 +1436,7 @@ static struct cmdtab const SetCommands[] = {
"Set loopback facility", "set loopback on|off"},
{"log", NULL, SetLogLevel, LOCAL_AUTH,
"Set log level", "set log [local] [+|-]value..."},
{"login", NULL, SetVariable, LOCAL_AUTH,
{"login", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX,
"Set login script", "set login chat-script", (const void *) VAR_LOGIN},
{"mru", NULL, SetInitialMRU, LOCAL_AUTH,
"Set Initial MRU value", "set mru value"},
@ -1432,21 +1450,21 @@ static struct cmdtab const SetCommands[] = {
#endif
{"ofilter", NULL, SetOfilter, LOCAL_AUTH,
"Set output filter", "set ofilter ..."},
{"openmode", NULL, SetOpenMode, LOCAL_AUTH,
{"openmode", NULL, SetOpenMode, LOCAL_AUTH | LOCAL_CX,
"Set open mode", "set openmode [active|passive]"},
{"parity", NULL, SetModemParity, LOCAL_AUTH,
{"parity", NULL, SetModemParity, LOCAL_AUTH | LOCAL_CX,
"Set modem parity", "set parity [odd|even|none]"},
{"phone", NULL, SetVariable, LOCAL_AUTH, "Set telephone number(s)",
"set phone phone1[:phone2[...]]", (const void *) VAR_PHONE},
{"reconnect", NULL, SetReconnect, LOCAL_AUTH,
{"reconnect", NULL, SetReconnect, LOCAL_AUTH | LOCAL_CX,
"Set Reconnect timeout", "set reconnect value ntries"},
{"redial", NULL, SetRedialTimeout, LOCAL_AUTH, "Set Redial timeout",
"set redial value|random[.value|random] [dial_attempts]"},
{"redial", NULL, SetRedialTimeout, LOCAL_AUTH | LOCAL_CX,
"Set Redial timeout", "set redial value|random[.value|random] [attempts]"},
{"stopped", NULL, SetStoppedTimeout, LOCAL_AUTH, "Set STOPPED timeouts",
"set stopped [LCPseconds [IPCPseconds [CCPseconds]]]"},
{"server", "socket", SetServer, LOCAL_AUTH,
"Set server port", "set server|socket TcpPort|LocalName|none [mask]"},
{"speed", NULL, SetModemSpeed, LOCAL_AUTH,
{"speed", NULL, SetModemSpeed, LOCAL_AUTH | LOCAL_CX,
"Set modem speed", "set speed value"},
{"timeout", NULL, SetIdleTimeout, LOCAL_AUTH,
"Set Idle timeout", "set timeout value"},
@ -1461,7 +1479,7 @@ static int
SetCommand(struct cmdargs const *arg)
{
if (arg->argc > 0)
FindExec(arg->bundle, SetCommands, arg->argc, arg->argv, "set ");
FindExec(arg->bundle, SetCommands, arg->argc, arg->argv, "set ", arg->cx);
else if (prompt_Active(&prompt))
prompt_Printf(&prompt, "Use `set ?' to get a list or `set ? <var>' for"
" syntax help.\n");
@ -1505,7 +1523,7 @@ AddCommand(struct cmdargs const *arg)
else
gateway = GetIpAddr(arg->argv[gw]);
bundle_SetRoute(arg->bundle, RTM_ADD, dest, gateway, netmask,
arg->data ? 1 : 0);
arg->cmd->args ? 1 : 0);
return 0;
}
@ -1526,7 +1544,7 @@ DeleteCommand(struct cmdargs const *arg)
dest = GetIpAddr(arg->argv[0]);
none.s_addr = INADDR_ANY;
bundle_SetRoute(arg->bundle, RTM_DELETE, dest, none, none,
arg->data ? 1 : 0);
arg->cmd->args ? 1 : 0);
}
else
return -1;
@ -1569,7 +1587,7 @@ static int
AliasCommand(struct cmdargs const *arg)
{
if (arg->argc > 0)
FindExec(arg->bundle, AliasCommands, arg->argc, arg->argv, "alias ");
FindExec(arg->bundle, AliasCommands, arg->argc, arg->argv, "alias ", arg->cx);
else if (prompt_Active(&prompt))
prompt_Printf(&prompt, "Use `alias help' to get a list or `alias help"
" <option>' for syntax help.\n");
@ -1607,7 +1625,7 @@ AliasEnable(struct cmdargs const *arg)
static int
AliasOption(struct cmdargs const *arg)
{
unsigned param = (unsigned)arg->data;
unsigned param = (unsigned)arg->cmd->args;
if (arg->argc == 1)
if (strcasecmp(arg->argv[0], "yes") == 0) {
if (mode & MODE_ALIAS) {
@ -1641,7 +1659,7 @@ AllowCommand(struct cmdargs const *arg)
{
/* arg->bundle may be NULL (see ValidSystem()) ! */
if (arg->argc > 0)
FindExec(arg->bundle, AllowCommands, arg->argc, arg->argv, "allow ");
FindExec(arg->bundle, AllowCommands, arg->argc, arg->argv, "allow ", arg->cx);
else if (prompt_Active(&prompt))
prompt_Printf(&prompt, "Use `allow ?' to get a list or `allow ? <cmd>' for"
" syntax help.\n");
@ -1650,3 +1668,22 @@ AllowCommand(struct cmdargs const *arg)
return 0;
}
static int
LinkCommand(struct cmdargs const *arg)
{
if (arg->argc > 1) {
struct datalink *cx = bundle2datalink(arg->bundle, arg->argv[0]);
if (cx)
FindExec(arg->bundle, Commands, arg->argc - 1, arg->argv + 1, "", cx);
else {
LogPrintf(LogWARN, "link: %s: Invalid link name\n", arg->argv[0]);
return 1;
}
} else {
LogPrintf(LogWARN, "Usage: %s\n", arg->cmd->syntax);
return 2;
}
return 0;
}

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: command.h,v 1.12.2.2 1998/02/07 20:49:33 brian Exp $
* $Id: command.h,v 1.12.2.3 1998/02/10 03:23:11 brian Exp $
*
* TODO:
*/
@ -23,11 +23,12 @@
struct cmdtab;
struct cmdargs {
struct cmdtab const *cmd;
struct cmdtab const *cmdtab; /* The entire command table */
struct cmdtab const *cmd; /* This command entry */
int argc;
char const *const *argv;
const void *data;
struct bundle *bundle;
struct datalink *cx;
};
struct cmdtab {
@ -55,7 +56,6 @@ struct cmdtab {
extern struct in_addr ifnetmask;
extern int aft_cmd;
extern int SetVariable(struct cmdargs const *);
extern int IsInteractive(int);
extern void InterpretCommand(char *, int, int *, char ***);
extern void RunCommand(struct bundle *, int, char const *const *, const char *);

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.5 1998/02/16 19:10:59 brian Exp $
* $Id: datalink.c,v 1.1.2.6 1998/02/17 01:05:38 brian Exp $
*/
#include <sys/param.h>
@ -101,7 +101,7 @@ datalink_HangupDone(struct datalink *dl)
bundle_LinkClosed(dl->bundle, dl);
datalink_StartDialTimer(dl, dl->dial_timeout);
} else {
LogPrintf(LogPHASE, "%s: Entering OPENING state\n", dl->name);
LogPrintf(LogPHASE, "%s: Re-entering OPENING state\n", dl->name);
dl->state = DATALINK_OPENING;
if (dl->dial_tries < 0) {
datalink_StartDialTimer(dl, dl->reconnect_timeout);

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.17 1998/02/16 19:09:58 brian Exp $
* $Id: modem.c,v 1.77.2.18 1998/02/17 01:05:18 brian Exp $
*
* TODO:
*/
@ -465,6 +465,20 @@ modem_Found(struct physical *modem)
LogPrintf(LogPHASE, "Connected!\n");
}
void
modem_SetDeviceName(struct physical *modem, const char *name)
{
if (name == NULL)
name = "";
if (link_IsActive(&modem->link))
LogPrintf(LogWARN,
"Cannot change device to \"%s\" when \"%s\" is open\n",
name, Physical_GetDevice(modem));
else
Physical_SetDevice(modem, name);
}
int
modem_Open(struct physical *modem, struct bundle *bundle)
{
@ -485,16 +499,9 @@ modem_Open(struct physical *modem, struct bundle *bundle)
mode & MODE_DIRECT
#endif
) {
struct cmdargs arg;
arg.cmd = NULL;
arg.data = (const void *)VAR_DEVICE;
arg.bundle = bundle;
if (isatty(STDIN_FILENO)) {
LogPrintf(LogDEBUG, "modem_Open(direct): Modem is a tty\n");
cp = ttyname(STDIN_FILENO);
arg.argc = 1;
arg.argv = (char const *const *)&cp;
SetVariable(&arg);
modem_SetDeviceName(modem, ttyname(STDIN_FILENO));
if (modem_lock(modem, bundle->unit) == -1) {
close(STDIN_FILENO);
return -1;
@ -503,9 +510,7 @@ modem_Open(struct physical *modem, struct bundle *bundle)
modem_Found(modem);
} else {
LogPrintf(LogDEBUG, "modem_Open(direct): Modem is not a tty\n");
arg.argc = 0;
arg.argv = NULL;
SetVariable(&arg);
modem_SetDeviceName(modem, NULL);
/* We don't call modem_Timeout() with this type of connection */
modem_Found(modem);
return modem->fd = STDIN_FILENO;
@ -671,8 +676,11 @@ modem_Raw(struct physical *modem, struct bundle *bundle)
struct termios rstio;
int oldflag;
LogPrintf(LogDEBUG, "Entering modem_Raw\n");
if (!isatty(modem->fd) || Physical_IsSync(modem))
return (0);
return 0;
if (
#ifdef notyet
!modem->is_direct &&
@ -888,8 +896,6 @@ int
modem_ShowStatus(struct cmdargs const *arg)
{
const char *dev;
struct physical *modem = bundle2physical(arg->bundle, NULL);
struct datalink *dl = bundle2datalink(arg->bundle, NULL);
#ifdef TIOCOUTQ
int nb;
#endif
@ -897,12 +903,12 @@ modem_ShowStatus(struct cmdargs const *arg)
dev = *VarDevice ? VarDevice : "network";
prompt_Printf(&prompt, "device: %s speed: ", dev);
if (Physical_IsSync(modem))
if (Physical_IsSync(arg->cx->physical))
prompt_Printf(&prompt, "sync\n");
else
prompt_Printf(&prompt, "%d\n", modem->speed);
prompt_Printf(&prompt, "%d\n", arg->cx->physical->speed);
switch (modem->parity & CSIZE) {
switch (arg->cx->physical->parity & CSIZE) {
case CS7:
prompt_Printf(&prompt, "cs7, ");
break;
@ -910,33 +916,37 @@ modem_ShowStatus(struct cmdargs const *arg)
prompt_Printf(&prompt, "cs8, ");
break;
}
if (modem->parity & PARENB) {
if (modem->parity & PARODD)
if (arg->cx->physical->parity & PARENB) {
if (arg->cx->physical->parity & PARODD)
prompt_Printf(&prompt, "odd parity, ");
else
prompt_Printf(&prompt, "even parity, ");
} else
prompt_Printf(&prompt, "no parity, ");
prompt_Printf(&prompt, "CTS/RTS %s.\n", (modem->rts_cts ? "on" : "off"));
prompt_Printf(&prompt, "CTS/RTS %s.\n",
(arg->cx->physical->rts_cts ? "on" : "off"));
if (LogIsKept(LogDEBUG))
prompt_Printf(&prompt, "fd = %d, modem control = %o\n", modem->fd, modem->mbits);
prompt_Printf(&prompt, "connect count: %d\n", modem->connect_count);
prompt_Printf(&prompt, "fd = %d, modem control = %o\n",
arg->cx->physical->fd, arg->cx->physical->mbits);
prompt_Printf(&prompt, "connect count: %d\n",
arg->cx->physical->connect_count);
#ifdef TIOCOUTQ
if (modem->fd >= 0)
if (ioctl(modem->fd, TIOCOUTQ, &nb) >= 0)
if (arg->cx->physical->fd >= 0)
if (ioctl(arg->cx->physical->fd, TIOCOUTQ, &nb) >= 0)
prompt_Printf(&prompt, "outq: %d\n", nb);
else
prompt_Printf(&prompt, "outq: ioctl probe failed: %s\n", strerror(errno));
#endif
prompt_Printf(&prompt, "outqlen: %d\n", link_QueueLen(&modem->link));
prompt_Printf(&prompt, "DialScript = %s\n", dl->script.dial);
prompt_Printf(&prompt, "LoginScript = %s\n", dl->script.login);
prompt_Printf(&prompt, "PhoneNumber(s) = %s\n", dl->script.hangup);
prompt_Printf(&prompt, "outqlen: %d\n",
link_QueueLen(&arg->cx->physical->link));
prompt_Printf(&prompt, "DialScript = %s\n", arg->cx->script.dial);
prompt_Printf(&prompt, "LoginScript = %s\n", arg->cx->script.login);
prompt_Printf(&prompt, "PhoneNumber(s) = %s\n", arg->cx->script.hangup);
prompt_Printf(&prompt, "\n");
throughput_disp(&modem->link.throughput);
throughput_disp(&arg->cx->physical->link.throughput);
return 0;
}

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: modem.h,v 1.16.2.6 1998/02/13 05:10:21 brian Exp $
* $Id: modem.h,v 1.16.2.7 1998/02/16 00:00:51 brian Exp $
*
* TODO:
*/
@ -31,3 +31,4 @@ extern int modem_SetParity(struct physical *, const char *);
extern int modem_ShowStatus(struct cmdargs const *);
extern void modem_Close(struct physical *);
extern void modem_Offline(struct physical *);
extern void modem_SetDeviceName(struct physical *, const char *);

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: prompt.c,v 1.1.2.3 1998/02/16 00:00:58 brian Exp $
* $Id: prompt.c,v 1.1.2.4 1998/02/17 01:05:47 brian Exp $
*/
#include <sys/param.h>
@ -113,27 +113,24 @@ static void
prompt_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
{
struct prompt *p = descriptor2prompt(d);
struct physical *physical;
struct datalink *dl;
struct datalink *dl = NULL;
int n;
char ch;
static int ttystate;
char linebuff[LINE_LEN];
if (p->TermMode) {
physical = bundle2physical(bundle, NULL);
dl = bundle2datalink(bundle, NULL);
if (!link_IsActive(&physical->link)) {
if (dl->state == DATALINK_CLOSED) {
prompt_Printf(p, "Exiting terminal mode.\n");
prompt_TtyCommandMode(&prompt);
prompt_nonewline = 0;
prompt_Display(&prompt, bundle);
}
/* Otherwise, we're not yet active (still OPENING) */
return;
if (dl->state == DATALINK_CLOSED) {
prompt_Printf(p, "Exiting terminal mode.\n");
prompt_TtyCommandMode(&prompt);
prompt_nonewline = 0;
prompt_Display(&prompt, bundle);
}
if (dl->state != DATALINK_OPEN)
return;
}
LogPrintf(LogDEBUG, "descriptor2prompt; %p -> %p\n", d, p);

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.42.2.7 1998/02/16 19:11:10 brian Exp $
* $Id: vars.h,v 1.42.2.8 1998/02/17 01:05:22 brian Exp $
*
* TODO:
*/
@ -69,6 +69,8 @@ struct pppvars {
#define LOCAL_AUTH 0x01
#define LOCAL_NO_AUTH 0x02
#define LOCAL_DENY 0x03
#define LOCAL_CX 0x04 /* OR'd value - require a context */
#define LOCAL_CX_OPT 0x08 /* OR'd value - optional context */
u_char lauth; /* Local Authorized status */
/* The rest are just default initialized in vars.c */