o Add the `set mode' command for change a links current mode. It

is not possible to switch to or from dedicated or direct mode,
  but all other combinations are ok (eg. -auto -> -ddial).
o Cope with the fact that commands with optional context may not
  be able to obtain a link with command_ChooseLink() (if all links
  have been deleted for example).
o Allow `clone'ing in non-multilink mode.  We may for example want
  to configure two links in unilink mode and dial them both, using
  the one that comes up first.  It's also possible to rename
  ``deflink'' by cloning it, deleting the original, then setting
  the mode of the new link.
This commit is contained in:
Brian Somers 1998-05-15 23:58:30 +00:00
parent ea7229694b
commit dd0645c5b7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/MP/; revision=36088
16 changed files with 207 additions and 75 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.82 1998/05/11 23:39:27 brian Exp $
* $Id: bundle.c,v 1.1.2.83 1998/05/15 18:21:32 brian Exp $
*/
#include <sys/types.h>
@ -1375,3 +1375,35 @@ bundle_SendDatalink(struct datalink *dl, int s, struct sockaddr_un *sun)
while (niov--)
free(iov[niov].iov_base);
}
int
bundle_SetMode(struct bundle *bundle, struct datalink *dl, int mode)
{
int omode;
omode = dl->physical->type;
if (omode == mode)
return 1;
if (mode == PHYS_DEMAND && !(bundle->phys_type & PHYS_DEMAND))
/* Changing to demand-dial mode */
if (bundle->ncp.ipcp.peer_ip.s_addr == INADDR_ANY) {
log_Printf(LogWARN, "You must `set ifaddr' before changing mode to %s\n",
mode2Nam(mode));
return 0;
}
if (!datalink_SetMode(dl, mode))
return 0;
if (mode == PHYS_DEMAND && !(bundle->phys_type & PHYS_DEMAND))
ipcp_InterfaceUp(&bundle->ncp.ipcp);
bundle_GenPhysType(bundle);
if (omode == PHYS_DEMAND && !(bundle->phys_type & PHYS_DEMAND))
/* Changing from demand-dial mode */
ipcp_CleanInterface(&bundle->ncp.ipcp);
return 1;
}

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.38 1998/05/06 23:50:02 brian Exp $
* $Id: bundle.h,v 1.1.2.39 1998/05/10 10:21:11 brian Exp $
*/
#define PHASE_DEAD 0 /* Link is dead */
@ -152,3 +152,4 @@ extern void bundle_SetLabel(struct bundle *, const char *);
extern const char *bundle_GetLabel(struct bundle *);
extern void bundle_SendDatalink(struct datalink *, int, struct sockaddr_un *);
extern void bundle_ReceiveDatalink(struct bundle *, int, struct sockaddr_un *);
extern int bundle_SetMode(struct bundle *, struct datalink *, int);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: ccp.c,v 1.30.2.42 1998/05/01 19:23:57 brian Exp $
* $Id: ccp.c,v 1.30.2.43 1998/05/15 18:20:55 brian Exp $
*
* TODO:
* o Support other compression protocols
@ -132,8 +132,12 @@ static const struct ccp_algorithm *algorithm[] = {
int
ccp_ReportStatus(struct cmdargs const *arg)
{
struct link *l = command_ChooseLink(arg);
struct ccp *ccp = &l->ccp;
struct link *l;
struct ccp *ccp;
if (!(l = command_ChooseLink(arg)))
return -1;
ccp = &l->ccp;
prompt_Printf(arg->prompt, "%s: %s [%s]\n", l->name, ccp->fsm.name,
State2Nam(ccp->fsm.state));

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.82 1998/05/10 09:26:17 brian Exp $
* $Id: command.c,v 1.131.2.83 1998/05/15 18:20:58 brian Exp $
*
*/
#include <sys/types.h>
@ -104,6 +104,7 @@
#define VAR_IPCPRETRY 20
#define VAR_DNS 21
#define VAR_NBNS 22
#define VAR_MODE 23
/* ``accept|deny|disable|enable'' masks */
#define NEG_HISMASK (1)
@ -123,7 +124,7 @@
#define NEG_DNS 50
const char Version[] = "2.0-beta";
const char VersionDate[] = "$Date: 1998/05/10 09:26:17 $";
const char VersionDate[] = "$Date: 1998/05/15 18:20:58 $";
static int ShowCommand(struct cmdargs const *);
static int TerminalCommand(struct cmdargs const *);
@ -199,11 +200,6 @@ CloneCommand(struct cmdargs const *arg)
if (arg->argc == arg->argn)
return -1;
if (!arg->bundle->ncp.mp.cfg.mrru) {
log_Printf(LogWARN, "clone: Only available in multilink mode\n");
return 1;
}
namelist[sizeof namelist - 1] = '\0';
for (f = arg->argn; f < arg->argc; f++) {
strncpy(namelist, arg->argv[f], sizeof namelist - 1);
@ -522,6 +518,8 @@ ShowProtocolStats(struct cmdargs const *arg)
{
struct link *l = command_ChooseLink(arg);
if (!l)
return -1;
prompt_Printf(arg->prompt, "%s:\n", l->name);
link_ReportProtocolStatus(l, arg->prompt);
return 0;
@ -805,7 +803,12 @@ OpenCommand(struct cmdargs const *arg)
bundle_Open(arg->bundle, arg->cx ? arg->cx->name : NULL, PHYS_ALL);
else if (arg->argc == arg->argn+1 &&
!strcasecmp(arg->argv[arg->argn], "ccp")) {
struct fsm *fp = &command_ChooseLink(arg)->ccp.fsm;
struct link *l;
struct fsm *fp;
if (!(l = command_ChooseLink(arg)))
return -1;
fp = &l->ccp.fsm;
if (fp->link->lcp.fsm.state != ST_OPENED)
log_Printf(LogWARN, "open: LCP must be open before opening CCP\n");
@ -834,7 +837,12 @@ CloseCommand(struct cmdargs const *arg)
else if (arg->argc == arg->argn+1 &&
(!strcasecmp(arg->argv[arg->argn], "ccp") ||
!strcasecmp(arg->argv[arg->argn], "ccp!"))) {
struct fsm *fp = &command_ChooseLink(arg)->ccp.fsm;
struct link *l;
struct fsm *fp;
if (!(l = command_ChooseLink(arg)))
return -1;
fp = &l->ccp.fsm;
if (fp->state == ST_OPENED) {
fsm_Close(fp);
@ -1094,8 +1102,8 @@ SetInterfaceAddr(struct cmdargs const *arg)
ipcp->cfg.peer_range.width = 0;
}
if (hisaddr &&
!ipcp_UseHisaddr(arg->bundle, hisaddr, arg->bundle->phys_type & PHYS_DEMAND))
if (hisaddr && !ipcp_UseHisaddr(arg->bundle, hisaddr,
arg->bundle->phys_type & PHYS_DEMAND))
return 4;
return 0;
@ -1106,13 +1114,16 @@ SetVariable(struct cmdargs const *arg)
{
u_long ulong_val;
const char *argp;
int param = (int)arg->cmd->args;
int param = (int)arg->cmd->args, mode;
struct datalink *cx = arg->cx; /* AUTH_CX uses this */
const char *err = NULL;
struct link *l = command_ChooseLink(arg); /* AUTH_CX_OPT uses this */
int dummyint;
struct in_addr dummyaddr, *addr;
if (!l)
return -1;
if (arg->argc > arg->argn)
argp = arg->argv[arg->argn];
else
@ -1194,6 +1205,14 @@ SetVariable(struct cmdargs const *arg)
log_Printf(LogWARN, err);
}
break;
case VAR_MODE:
mode = Nam2mode(argp);
if (mode == PHYS_NONE || mode == PHYS_ALL) {
log_Printf(LogWARN, "%s: Invalid mode\n", argp);
return -1;
}
bundle_SetMode(arg->bundle, cx, mode);
break;
case VAR_MRRU:
if (bundle_Phase(arg->bundle) != PHASE_DEAD)
log_Printf(LogWARN, "mrru: Only changable at phase DEAD\n");
@ -1398,6 +1417,8 @@ static struct cmdtab const SetCommands[] = {
"Set login script", "set login chat-script", (const void *) VAR_LOGIN},
{"lqrperiod", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX_OPT,
"Set LQR period", "set lqrperiod value", (const void *)VAR_LQRPERIOD},
{"mode", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX, "Set mode value",
"set mode interactive|auto|ddial|background", (const void *)VAR_MODE},
{"mrru", NULL, SetVariable, LOCAL_AUTH, "Set MRRU value",
"set mrru value", (const void *)VAR_MRRU},
{"mru", NULL, SetVariable, LOCAL_AUTH | LOCAL_CX_OPT,
@ -1790,6 +1811,9 @@ NegotiateSet(struct cmdargs const *arg)
unsigned keep; /* Keep these bits */
unsigned add; /* Add these bits */
if (!l)
return -1;
if ((cmd = ident_cmd(arg->argv[arg->argn-2], &keep, &add)) == NULL)
return 1;

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.60 1998/05/15 18:21:02 brian Exp $
* $Id: datalink.c,v 1.1.2.61 1998/05/15 18:21:34 brian Exp $
*/
#include <sys/types.h>
@ -1073,3 +1073,17 @@ datalink_NextName(struct datalink *dl)
dl->physical->link.name = dl->name = name;
return oname;
}
int
datalink_SetMode(struct datalink *dl, int mode)
{
if (!physical_SetMode(dl->physical, mode))
return 0;
if (dl->physical->type & (PHYS_DIRECT|PHYS_DEDICATED))
dl->script.run = 0;
if (dl->physical->type == PHYS_DIRECT)
dl->reconnect_tries = 0;
if (mode & (PHYS_PERM|PHYS_1OFF) && dl->state <= DATALINK_READY)
datalink_Up(dl, 1, 1);
return 1;
}

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.23 1998/05/06 23:49:33 brian Exp $
* $Id: datalink.h,v 1.1.2.24 1998/05/15 18:21:35 brian Exp $
*/
#define DATALINK_CLOSED (0)
@ -126,3 +126,4 @@ extern const char *datalink_State(struct datalink *);
extern char *datalink_NextName(struct datalink *);
extern int datalink_RemoveFromSet(struct datalink *, fd_set *, fd_set *,
fd_set *);
extern int datalink_SetMode(struct datalink *, int);

View File

@ -23,11 +23,12 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: defs.c,v 1.11.4.10 1998/04/30 23:53:35 brian Exp $
* $Id: defs.c,v 1.11.4.11 1998/05/06 18:50:06 brian Exp $
*/
#include <stdlib.h>
#include <string.h>
#include <sys/errno.h>
#include <time.h>
#include <unistd.h>
@ -66,3 +67,48 @@ fullread(int fd, void *v, size_t n)
}
return total;
}
static struct {
int mode;
const char *name;
} modes[] = {
{ PHYS_MANUAL, "interactive" },
{ PHYS_DEMAND, "auto" },
{ PHYS_DIRECT, "direct" },
{ PHYS_DEDICATED, "dedicated" },
{ PHYS_PERM, "ddial" },
{ PHYS_1OFF, "background" },
{ PHYS_ALL, "*" },
{ 0, 0 }
};
const char *
mode2Nam(int mode)
{
int m;
for (m = 0; modes[m].mode; m++)
if (modes[m].mode == mode)
return modes[m].name;
return "unknown";
}
int
Nam2mode(const char *name)
{
int m, got, len;
len = strlen(name);
got = -1;
for (m = 0; modes[m].mode; m++)
if (!strncasecmp(name, modes[m].name, len)) {
if (modes[m].name[len] == '\0')
return modes[m].mode;
if (got != -1)
return 0;
got = m;
}
return got == -1 ? 0 : modes[got].mode;
}

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: defs.h,v 1.29.2.16 1998/05/01 19:20:03 brian Exp $
* $Id: defs.h,v 1.29.2.17 1998/05/01 19:24:26 brian Exp $
*
* TODO:
*/
@ -72,6 +72,7 @@
#define EX_NOLOGIN 13
/* physical::type values (OR'd in bundle::phys_type) */
#define PHYS_NONE 0
#define PHYS_MANUAL 1 /* Manual link */
#define PHYS_DEMAND 2 /* Dial-on-demand link (-auto) */
#define PHYS_DIRECT 4 /* Incoming link (-direct) */
@ -82,3 +83,5 @@
extern void randinit(void);
extern ssize_t fullread(int, void *, size_t);
extern const char *mode2Nam(int);
extern int Nam2mode(const char *);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: ipcp.c,v 1.50.2.50 1998/05/05 23:30:03 brian Exp $
* $Id: ipcp.c,v 1.50.2.51 1998/05/06 23:50:14 brian Exp $
*
* TODO:
* o More RFC1772 backwoard compatibility
@ -691,6 +691,22 @@ IpcpLayerDown(struct fsm *fp)
ipcp_CleanInterface(ipcp);
}
int
ipcp_InterfaceUp(struct ipcp *ipcp)
{
if (ipcp_SetIPaddress(ipcp->fsm.bundle, ipcp->my_ip, ipcp->peer_ip, 0) < 0) {
log_Printf(LogERROR, "IpcpLayerUp: unable to set ip address\n");
return 0;
}
#ifndef NOALIAS
if (alias_IsEnabled())
(*PacketAlias.SetAddress)(ipcp->my_ip);
#endif
return 1;
}
static int
IpcpLayerUp(struct fsm *fp)
{
@ -705,15 +721,8 @@ IpcpLayerUp(struct fsm *fp)
if (ipcp->peer_compproto >> 16 == PROTO_VJCOMP)
sl_compress_init(&ipcp->vj.cslc, (ipcp->peer_compproto >> 8) & 255);
if (ipcp_SetIPaddress(fp->bundle, ipcp->my_ip, ipcp->peer_ip, 0) < 0) {
log_Printf(LogERROR, "IpcpLayerUp: unable to set ip address\n");
if (!ipcp_InterfaceUp(ipcp))
return 0;
}
#ifndef NOALIAS
if (alias_IsEnabled())
(*PacketAlias.SetAddress)(ipcp->my_ip);
#endif
/*
* XXX this stuff should really live in the FSM. Our config should

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: ipcp.h,v 1.18.2.25 1998/05/01 19:24:53 brian Exp $
* $Id: ipcp.h,v 1.18.2.26 1998/05/05 23:30:05 brian Exp $
*
* TODO:
*/
@ -111,3 +111,4 @@ extern void ipcp_AddOutOctets(struct ipcp *, int);
extern int ipcp_UseHisaddr(struct bundle *, const char *, int);
extern int ipcp_vjset(struct cmdargs const *);
extern void ipcp_CleanInterface(struct ipcp *);
extern int ipcp_InterfaceUp(struct ipcp *);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: lcp.c,v 1.55.2.52 1998/05/01 19:24:55 brian Exp $
* $Id: lcp.c,v 1.55.2.53 1998/05/06 23:49:45 brian Exp $
*
* TODO:
* o Limit data field length by MRU
@ -132,8 +132,12 @@ static const char *cftypes[] = {
int
lcp_ReportStatus(struct cmdargs const *arg)
{
struct link *l = command_ChooseLink(arg);
struct lcp *lcp = &l->lcp;
struct link *l;
struct lcp *lcp;
if (!(l = command_ChooseLink(arg)))
return -1;
lcp = &l->lcp;
prompt_Printf(arg->prompt, "%s: %s [%s]\n", l->name, lcp->fsm.name,
State2Nam(lcp->fsm.state));

View File

@ -16,7 +16,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: physical.c,v 1.1.2.31 1998/05/10 22:20:14 brian Exp $
* $Id: physical.c,v 1.1.2.32 1998/05/15 18:21:43 brian Exp $
*
*/
@ -211,3 +211,16 @@ physical_Logout(struct physical *phys)
phys->Utmp = 0;
}
}
int
physical_SetMode(struct physical *p, int mode)
{
if (p->type & (PHYS_DIRECT|PHYS_DEDICATED)
|| mode & (PHYS_DIRECT|PHYS_DEDICATED)) {
log_Printf(LogWARN, "%s: Cannot change mode %s to %s\n", p->link.name,
mode2Nam(p->type), mode2Nam(mode));
return 0;
}
p->type = mode;
return 1;
}

View File

@ -16,7 +16,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: physical.h,v 1.1.2.24 1998/05/01 19:25:37 brian Exp $
* $Id: physical.h,v 1.1.2.25 1998/05/15 18:21:45 brian Exp $
*
*/
@ -98,3 +98,4 @@ extern void physical_Login(struct physical *, const char *);
extern void physical_Logout(struct physical *);
extern int physical_RemoveFromSet(struct physical *, fd_set *, fd_set *,
fd_set *);
extern int physical_SetMode(struct physical *, int);

View File

@ -1,4 +1,4 @@
.\" $Id: ppp.8,v 1.97.2.32 1998/05/13 19:06:27 brian Exp $
.\" $Id: ppp.8,v 1.97.2.33 1998/05/15 18:21:12 brian Exp $
.Dd 20 September 1995
.Os FreeBSD
.Dt PPP 8
@ -2682,6 +2682,16 @@ or
packets are sent. The default is 30 seconds. You must also use the
.Dq enable lqr
command if you wish to send LQR requests to the peer.
.It set mode Ar interactive|auto|ddial|background
This command allows you to change the
.Sq mode
of the specified link. This is normally only useful in multilink mode,
but may also be used in unilink mode.
.Pp
It is not possible to change a link that is
.Sq direct
or
.Sq dedicated .
.It set mrru Ar value
Setting this option enables Multilink PPP negotiations, also known as
Multilink Protocol or MP. There is no default MRRU (Maximum

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: systems.c,v 1.35.2.8 1998/04/30 23:53:56 brian Exp $
* $Id: systems.c,v 1.35.2.9 1998/05/01 19:26:01 brian Exp $
*
* TODO:
*/
@ -180,49 +180,19 @@ AllowUsers(struct cmdargs const *arg)
return 0;
}
static struct {
int mode;
const char *name;
} modes[] = {
{ PHYS_MANUAL, "interactive" },
{ PHYS_DEMAND, "auto" },
{ PHYS_DIRECT, "direct" },
{ PHYS_DEDICATED, "dedicated" },
{ PHYS_PERM, "ddial" },
{ PHYS_1OFF, "background" },
{ PHYS_ALL, "*" },
{ 0, 0 }
};
const char *
mode2Nam(int mode)
{
int m;
for (m = 0; modes[m].mode; m++)
if (modes[m].mode == mode)
return modes[m].name;
return "unknown";
}
int
AllowModes(struct cmdargs const *arg)
{
/* arg->bundle may be NULL (see system_IsValid()) ! */
int f;
int m;
int allowed;
int f, mode, allowed;
allowed = 0;
for (f = arg->argn; f < arg->argc; f++) {
for (m = 0; modes[m].mode; m++)
if (!strcasecmp(modes[m].name, arg->argv[f])) {
allowed |= modes[m].mode;
break;
}
if (modes[m].mode == 0)
mode = Nam2mode(arg->argv[f]);
if (mode == PHYS_NONE || mode == PHYS_ALL)
log_Printf(LogWARN, "allow modes: %s: Invalid mode\n", arg->argv[f]);
else
allowed |= mode;
}
modeok = modereq & allowed ? 1 : 0;

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: systems.h,v 1.10.2.4 1998/04/10 13:19:22 brian Exp $
* $Id: systems.h,v 1.10.2.5 1998/05/01 19:26:02 brian Exp $
*
*/
@ -34,4 +34,3 @@ extern int AllowUsers(struct cmdargs const *);
extern int AllowModes(struct cmdargs const *);
extern int LoadCommand(struct cmdargs const *);
extern int SaveCommand(struct cmdargs const *);
extern const char *mode2Nam(int);