Add the clone' and remove' commands for creating and destroying

links.
This commit is contained in:
Brian Somers 1998-04-05 22:48:25 +00:00
parent a3e274968f
commit cd7bd93a81
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/MP/; revision=35051
7 changed files with 149 additions and 13 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.37 1998/04/03 19:26:16 brian Exp $
* $Id: bundle.c,v 1.1.2.38 1998/04/04 13:01:19 brian Exp $
*/
#include <sys/param.h>
@ -993,3 +993,25 @@ bundle_SetTtyCommandMode(struct bundle *bundle, struct datalink *dl)
prompt_TtyCommandMode(p);
}
}
void
bundle_DatalinkClone(struct bundle *bundle, struct datalink *dl,
const char *name)
{
struct datalink *ndl = datalink_Clone(dl, name);
ndl->next = dl->next;
dl->next = ndl;
}
void
bundle_DatalinkRemove(struct bundle *bundle, struct datalink *dl)
{
struct datalink **dlp;
if (dl->state == DATALINK_CLOSED)
for (dlp = &bundle->links; *dlp; dlp = &(*dlp)->next)
if (*dlp == dl) {
*dlp = datalink_Destroy(dl);
break;
}
}

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.24 1998/04/03 19:25:24 brian Exp $
* $Id: bundle.h,v 1.1.2.25 1998/04/03 19:26:17 brian Exp $
*/
#define PHASE_DEAD 0 /* Link is dead */
@ -118,3 +118,7 @@ extern void bundle_DisplayPrompt(struct bundle *);
extern void bundle_WriteTermPrompt(struct bundle *, struct datalink *,
const char *, int);
extern void bundle_SetTtyCommandMode(struct bundle *, struct datalink *);
extern void bundle_DatalinkClone(struct bundle *, struct datalink *,
const char *);
extern void bundle_DatalinkRemove(struct bundle *, struct datalink *);

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.51 1998/04/03 19:26:19 brian Exp $
* $Id: command.c,v 1.131.2.52 1998/04/04 10:34:27 brian Exp $
*
*/
#include <sys/param.h>
@ -95,8 +95,6 @@ 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 *);
static int AliasEnable(struct cmdargs const *);
@ -171,6 +169,44 @@ IsInteractive(struct prompt *prompt)
return mode & MODE_INTER;
}
static int
CloneCommand(struct cmdargs const *arg)
{
int f;
if (arg->argc == 0)
return -1;
if (!arg->bundle->ncp.mp.active) {
LogPrintf(LogWARN, "clone: Only available in multilink mode\n");
return 1;
}
for (f = 0; f < arg->argc; f++)
bundle_DatalinkClone(arg->bundle, arg->cx, arg->argv[f]);
return 0;
}
static int
RemoveCommand(struct cmdargs const *arg)
{
if (arg->argc != 0)
return -1;
if (!arg->bundle->ncp.mp.active) {
LogPrintf(LogWARN, "remove: Only available in multilink mode\n");
return 1;
}
if (arg->cx->state != DATALINK_CLOSED) {
LogPrintf(LogWARN, "remove: Cannot delete links that aren't closed\n");
return 2;
}
bundle_DatalinkRemove(arg->bundle, arg->cx);
return 0;
}
static int
DialCommand(struct cmdargs const *arg)
{
@ -336,6 +372,8 @@ static struct cmdtab const Commands[] = {
"Allow ppp access", "allow users|modes ...."},
{"bg", "!bg", BgShellCommand, LOCAL_AUTH,
"Run a background command", "[!]bg command"},
{"clone", NULL, CloneCommand, LOCAL_AUTH | LOCAL_CX,
"Clone a link", "clone newname..."},
{"close", NULL, CloseCommand, LOCAL_AUTH | LOCAL_CX_OPT,
"Close connection", "close"},
{"delete", NULL, DeleteCommand, LOCAL_AUTH,
@ -362,6 +400,8 @@ static struct cmdtab const Commands[] = {
"Password for manipulation", "passwd LocalPassword"},
{"quit", "bye", QuitCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
"Quit PPP program", "quit|bye [all]"},
{"remove", NULL, RemoveCommand, LOCAL_AUTH | LOCAL_CX,
"Remove a link", "remove"},
{"save", NULL, SaveCommand, LOCAL_AUTH,
"Save settings", "save"},
{"set", "setup", SetCommand, LOCAL_AUTH | LOCAL_CX_OPT,

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.31 1998/04/03 19:25:27 brian Exp $
* $Id: datalink.c,v 1.1.2.32 1998/04/03 19:26:20 brian Exp $
*/
#include <sys/param.h>
@ -539,6 +539,61 @@ datalink_Create(const char *name, struct bundle *bundle,
return dl;
}
struct datalink *
datalink_Clone(struct datalink *odl, const char *name)
{
struct datalink *dl;
dl = (struct datalink *)malloc(sizeof(struct datalink));
if (dl == NULL)
return dl;
dl->desc.type = DATALINK_DESCRIPTOR;
dl->desc.next = NULL;
dl->desc.UpdateSet = datalink_UpdateSet;
dl->desc.IsSet = datalink_IsSet;
dl->desc.Read = datalink_Read;
dl->desc.Write = datalink_Write;
dl->state = DATALINK_CLOSED;
memcpy(&dl->cfg, &odl->cfg, sizeof dl->cfg);
mp_linkInit(&dl->mp);
*dl->phone.list = '\0';
dl->bundle = odl->bundle;
dl->next = NULL;
memset(&dl->dial_timer, '\0', sizeof dl->dial_timer);
dl->dial_tries = 0;
dl->reconnect_tries = 0;
dl->name = strdup(name);
dl->parent = odl->parent;
memcpy(&dl->fsmp, &odl->fsmp, sizeof dl->fsmp);
authinfo_Init(&dl->pap);
dl->pap.cfg.fsmretry = odl->pap.cfg.fsmretry;
authinfo_Init(&dl->chap.auth);
dl->chap.auth.cfg.fsmretry = odl->chap.auth.cfg.fsmretry;
if ((dl->physical = modem_Create(dl)) == NULL) {
free(dl->name);
free(dl);
return NULL;
}
memcpy(&dl->physical->cfg, &odl->physical->cfg, sizeof dl->physical->cfg);
memcpy(&dl->physical->link.lcp.cfg, &odl->physical->link.lcp.cfg,
sizeof dl->physical->link.lcp.cfg);
memcpy(&dl->physical->link.ccp.cfg, &odl->physical->link.ccp.cfg,
sizeof dl->physical->link.ccp.cfg);
memcpy(&dl->physical->async.cfg, &odl->physical->async.cfg,
sizeof dl->physical->async.cfg);
chat_Init(&dl->chat, dl->physical, NULL, 1, NULL);
LogPrintf(LogPHASE, "%s: Created in CLOSED state\n", dl->name);
return dl;
}
struct datalink *
datalink_Destroy(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: datalink.h,v 1.1.2.13 1998/04/03 19:21:18 brian Exp $
* $Id: datalink.h,v 1.1.2.14 1998/04/03 19:25:28 brian Exp $
*/
#define DATALINK_CLOSED (0)
@ -98,6 +98,7 @@ struct prompt;
extern struct datalink *datalink_Create(const char *name, struct bundle *,
const struct fsm_parent *);
extern struct datalink *datalink_Clone(struct datalink *, const char *);
extern struct datalink *datalink_Destroy(struct datalink *);
extern void datalink_Up(struct datalink *, int, int);
extern void datalink_Close(struct datalink *, int);

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: hdlc.h,v 1.14.2.7 1998/03/13 00:44:04 brian Exp $
* $Id: hdlc.h,v 1.14.2.8 1998/04/03 19:21:23 brian Exp $
*
* TODO:
*/
@ -94,7 +94,6 @@ struct hdlc {
u_int32_t seq_recv; /* last echo received */
} echo;
} lqm;
};
@ -103,11 +102,10 @@ extern void hdlc_StartTimer(struct hdlc *);
extern void hdlc_StopTimer(struct hdlc *);
extern int hdlc_ReportStatus(struct cmdargs const *);
extern const char *hdlc_Protocol2Nam(u_short);
extern void hdlc_DecodePacket(struct bundle *, u_short, struct mbuf *,
struct link *);
extern void HdlcInput(struct bundle *, struct mbuf *, struct physical *);
extern void HdlcOutput(struct link *, int, u_short, struct mbuf *bp);
extern u_short HdlcFcs(u_short, u_char *, int);
extern int ReportProtStatus(struct cmdargs const *);
extern u_char *HdlcDetect(struct physical *, u_char *, int);
extern void hdlc_DecodePacket(struct bundle *, u_short, struct mbuf *,
struct link *);

View File

@ -1,4 +1,4 @@
.\" $Id: ppp.8,v 1.97.2.11 1998/04/03 19:25:48 brian Exp $
.\" $Id: ppp.8,v 1.97.2.12 1998/04/03 19:26:26 brian Exp $
.Dd 20 September 1995
.Os FreeBSD
.Dt PPP 8
@ -1922,6 +1922,15 @@ will be replaced with the appropriate values. If you wish to pause
while the command executes, use the
.Dv shell
command instead.
.It clone Ar name...
Clone the specified link, creating one or more new links according to the
.Ar name
argument(s). This command must be used from the
.Dq link
command below. It is only available in multilink mode. Links may
be removed using the
.Dq remove
command below.
.It close
Close the current connection (but don't quit).
.It delete[!] Ar dest
@ -2021,6 +2030,13 @@ all argument is given,
.Nm
will exit despite the source of the command after closing all existing
connections.
.It remove
This command removes the given link (specified via the
.Dq link
command). It is only available in multilink mode. A link must be
in the
.Dv CLOSED
state before it is removed.
.It save
This option is not (yet) implemented.
.It set[up] Ar var value