From cd7bd93a816437fd4c82a178133c420f69bb3b20 Mon Sep 17 00:00:00 2001 From: Brian Somers Date: Sun, 5 Apr 1998 22:48:25 +0000 Subject: [PATCH] Add the `clone' and `remove' commands for creating and destroying links. --- usr.sbin/ppp/bundle.c | 24 ++++++++++++++++- usr.sbin/ppp/bundle.h | 6 ++++- usr.sbin/ppp/command.c | 46 ++++++++++++++++++++++++++++++--- usr.sbin/ppp/datalink.c | 57 ++++++++++++++++++++++++++++++++++++++++- usr.sbin/ppp/datalink.h | 3 ++- usr.sbin/ppp/hdlc.h | 8 +++--- usr.sbin/ppp/ppp.8 | 18 ++++++++++++- 7 files changed, 149 insertions(+), 13 deletions(-) diff --git a/usr.sbin/ppp/bundle.c b/usr.sbin/ppp/bundle.c index 2c087ec7504..2d68de8cf5a 100644 --- a/usr.sbin/ppp/bundle.c +++ b/usr.sbin/ppp/bundle.c @@ -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 @@ -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; + } +} diff --git a/usr.sbin/ppp/bundle.h b/usr.sbin/ppp/bundle.h index 4664121b2e4..5f8bce6ed24 100644 --- a/usr.sbin/ppp/bundle.h +++ b/usr.sbin/ppp/bundle.h @@ -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 *); diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c index b827ec98358..c2a362557ec 100644 --- a/usr.sbin/ppp/command.c +++ b/usr.sbin/ppp/command.c @@ -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 @@ -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, diff --git a/usr.sbin/ppp/datalink.c b/usr.sbin/ppp/datalink.c index dde112414c7..13f2f986f4e 100644 --- a/usr.sbin/ppp/datalink.c +++ b/usr.sbin/ppp/datalink.c @@ -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 @@ -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) { diff --git a/usr.sbin/ppp/datalink.h b/usr.sbin/ppp/datalink.h index 8e0a3f9f479..bb4028309ed 100644 --- a/usr.sbin/ppp/datalink.h +++ b/usr.sbin/ppp/datalink.h @@ -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); diff --git a/usr.sbin/ppp/hdlc.h b/usr.sbin/ppp/hdlc.h index 82e23514aa8..52bd528e954 100644 --- a/usr.sbin/ppp/hdlc.h +++ b/usr.sbin/ppp/hdlc.h @@ -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 *); diff --git a/usr.sbin/ppp/ppp.8 b/usr.sbin/ppp/ppp.8 index 8785abaed96..842fa3934ff 100644 --- a/usr.sbin/ppp/ppp.8 +++ b/usr.sbin/ppp/ppp.8 @@ -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