Change ``set cd'' so that its default value is device specific. The

default is still 1 second for ttys, but is now 6 seconds for i4b (ISDN)
devices and 5 seconds for ethernet (PPPoE) devices.
This commit is contained in:
Brian Somers 1999-11-26 22:44:33 +00:00
parent da2440e826
commit fdc29d54a4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=53733
15 changed files with 173 additions and 76 deletions

View File

@ -1777,8 +1777,8 @@ SetVariable(struct cmdargs const *arg)
} else
cx->physical->cfg.cd.necessity = CD_NOTREQUIRED;
} else {
cx->physical->cfg.cd.delay = DEF_CDDELAY;
cx->physical->cfg.cd.necessity = CD_VARIABLE;
cx->physical->cfg.cd.delay = 0;
cx->physical->cfg.cd.necessity = CD_DEFAULT;
}
break;

View File

@ -58,8 +58,7 @@
#define MIN_FSMRETRY 3 /* Minimum FSM retry frequency */
#define DEF_FSMRETRY 3 /* FSM retry frequency */
#define DEF_FSMTRIES 5 /* Default max retries */
#define DEF_FSMAUTHTRIES 3 /* Default max auth retries */
#define DEF_CDDELAY 1 /* Delay before checking for carrier */
#define DEF_FSMAUTHTRIES 3 /* Default max auth retries */
#define CONFFILE "ppp.conf"
#define LINKUPFILE "ppp.linkup"

View File

@ -273,6 +273,7 @@ ether_AwaitCarrier(struct physical *p)
static const struct device baseetherdevice = {
ETHER_DEVICE,
"ether",
{ CD_REQUIRED, DEF_ETHERCDDELAY },
ether_AwaitCarrier,
ether_RemoveFromSet,
NULL,
@ -584,13 +585,29 @@ ether_Create(struct physical *p)
return ether_Abandon(dev, p);
}
dev->timeout = p->cfg.cd.delay;
dev->connected = CARRIER_PENDING;
/* Hook things up so that we monitor dev->cs */
p->desc.UpdateSet = ether_UpdateSet;
p->desc.IsSet = ether_IsSet;
p->desc.Read = ether_DescriptorRead;
memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev);
switch (p->cfg.cd.necessity) {
case CD_VARIABLE:
dev->dev.cd.delay = p->cfg.cd.delay;
break;
case CD_REQUIRED:
dev->dev.cd = p->cfg.cd;
break;
case CD_NOTREQUIRED:
log_Printf(LogWARN, "%s: Carrier must be set, using ``set cd %d!''\n",
p->link.name, dev->dev.cd.delay);
case CD_DEFAULT:
break;
}
dev->timeout = dev->dev.cd.delay;
dev->connected = CARRIER_PENDING;
} else {
/* See if we're a netgraph socket */
struct sockaddr_ng ngsock;
@ -611,6 +628,7 @@ ether_Create(struct physical *p)
return NULL;
}
memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev);
dev->cs = -1;
dev->timeout = 0;
dev->connected = CARRIER_OK;
@ -619,8 +637,6 @@ ether_Create(struct physical *p)
}
if (dev) {
memcpy(&dev->dev, &baseetherdevice, sizeof dev->dev);
physical_SetupStack(p, dev->dev.name, PHYSICAL_FORCE_SYNCNOACF);
/* Moan about (and fix) invalid LCP configurations */

View File

@ -29,6 +29,8 @@
struct physical;
struct device;
#define DEF_ETHERCDDELAY 5 /* Default ``set cd'' value */
extern struct device *ether_Create(struct physical *);
extern struct device *ether_iov2device(int, struct physical *, struct iovec *,
int *, int, int *, int *);

View File

@ -67,6 +67,7 @@
static struct device execdevice = {
EXEC_DEVICE,
"exec",
{ CD_NOTREQUIRED, 0 },
NULL,
NULL,
NULL,
@ -160,6 +161,8 @@ exec_Create(struct physical *p)
waitpid(pid, &stat, 0);
log_Printf(LogDEBUG, "Using descriptor %d for child\n", p->fd);
physical_SetupStack(p, execdevice.name, PHYSICAL_FORCE_ASYNC);
if (p->cfg.cd.necessity != CD_DEFAULT)
log_Printf(LogWARN, "Carrier settings ignored\n");
return &execdevice;
}
}

View File

@ -122,17 +122,17 @@ i4b_Timeout(void *data)
/* First time looking for carrier */
if (Online(dev))
log_Printf(LogPHASE, "%s: %s: CD detected\n", p->link.name, p->name.full);
else if (++dev->carrier_seconds >= p->cfg.cd.delay) {
else if (++dev->carrier_seconds >= dev->dev.cd.delay) {
log_Printf(LogPHASE, "%s: %s: No carrier"
" (increase ``set cd'' from %d ?)\n",
p->link.name, p->name.full, p->cfg.cd.delay);
p->link.name, p->name.full, dev->dev.cd.delay);
timer_Stop(&dev->Timer);
/* i4b_AwaitCarrier() will notice */
} else {
/* Keep waiting */
log_Printf(LogDEBUG, "%s: %s: Still no carrier (%d/%d)\n",
p->link.name, p->name.full, dev->carrier_seconds,
p->cfg.cd.delay);
dev->dev.cd.delay);
dev->mbits = -1;
}
} else {
@ -291,6 +291,7 @@ i4b_device2iov(struct device *d, struct iovec *iov, int *niov,
static struct device basei4bdevice = {
I4B_DEVICE,
"i4b",
{ CD_REQUIRED, DEF_I4BCDDELAY },
i4b_AwaitCarrier,
NULL,
i4b_Raw,
@ -373,6 +374,20 @@ i4b_Create(struct physical *p)
memset(&dev->Timer, '\0', sizeof dev->Timer);
dev->mbits = -1;
switch (p->cfg.cd.necessity) {
case CD_VARIABLE:
dev->dev.cd.delay = p->cfg.cd.delay;
break;
case CD_REQUIRED:
dev->dev.cd = p->cfg.cd;
break;
case CD_NOTREQUIRED:
log_Printf(LogWARN, "%s: Carrier must be set, using ``set cd %d!''\n",
p->link.name, dev->dev.cd.delay);
case CD_DEFAULT:
break;
}
oldflag = fcntl(p->fd, F_GETFL, 0);
if (oldflag < 0) {
/* Complete failure - parent doesn't continue trying to ``create'' */

View File

@ -29,6 +29,8 @@
struct physical;
struct device;
#define DEF_I4BCDDELAY 6 /* Default ``set cd'' value */
extern struct device *i4b_Create(struct physical *);
extern struct device *i4b_iov2device(int, struct physical *,
struct iovec *, int *, int, int *, int *);

View File

@ -188,8 +188,8 @@ physical_Create(struct datalink *dl, int type)
p->cfg.parity = CS8;
memcpy(p->cfg.devlist, MODEM_LIST, sizeof MODEM_LIST);
p->cfg.ndev = NMODEMS;
p->cfg.cd.necessity = CD_VARIABLE;
p->cfg.cd.delay = DEF_CDDELAY;
p->cfg.cd.necessity = CD_DEFAULT;
p->cfg.cd.delay = 0; /* reconfigured or device specific default */
lcp_Init(&p->link.lcp, dl->bundle, &p->link, &dl->fsmp);
ccp_Init(&p->link.ccp, dl->bundle, &p->link, &dl->fsmp);
@ -411,6 +411,7 @@ int
physical_ShowStatus(struct cmdargs const *arg)
{
struct physical *p = arg->cx->physical;
struct cd *cd;
const char *dev;
int n;
@ -476,9 +477,12 @@ physical_ShowStatus(struct cmdargs const *arg)
prompt_Printf(arg->prompt, ", CTS/RTS %s\n", (p->cfg.rts_cts ? "on" : "off"));
prompt_Printf(arg->prompt, " CD check delay: ");
if (p->cfg.cd.necessity == CD_NOTREQUIRED)
cd = p->handler ? &p->handler->cd : &p->cfg.cd;
if (cd->necessity == CD_NOTREQUIRED)
prompt_Printf(arg->prompt, "no cd");
else {
else if (p->cfg.cd.necessity == CD_DEFAULT) {
prompt_Printf(arg->prompt, "device specific");
} else {
prompt_Printf(arg->prompt, "%d second%s", p->cfg.cd.delay,
p->cfg.cd.delay == 1 ? "" : "s");
if (p->cfg.cd.necessity == CD_REQUIRED)

View File

@ -42,13 +42,20 @@ struct cmdargs;
#define CARRIER_LOST 3
/* A cd ``necessity'' value */
#define CD_VARIABLE 1
#define CD_REQUIRED 2
#define CD_NOTREQUIRED 3
#define CD_VARIABLE 0
#define CD_REQUIRED 1
#define CD_NOTREQUIRED 2
#define CD_DEFAULT 3
struct cd {
unsigned necessity : 2; /* A CD_ value */
int delay; /* Wait this many seconds after login script */
};
struct device {
int type;
const char *name;
struct cd cd;
int (*awaitcarrier)(struct physical *);
int (*removefromset)(struct physical *, fd_set *, fd_set *, fd_set *);
@ -97,10 +104,7 @@ struct physical {
char devlist[LINE_LEN]; /* NUL separated list of devices */
int ndev; /* number of devices in list */
struct {
unsigned necessity : 2; /* A CD_ value */
int delay; /* Wait this many seconds after login script */
} cd;
struct cd cd;
} cfg;
};

View File

@ -3598,22 +3598,51 @@ be agreeable with the peer), or if
is specified,
.Nm
will expect the peer to specify the number.
.It "set cd off|" Ns Ar seconds Ns Op \&!
.It set cd Oo
.No off| Ns Ar seconds Ns Op \&!
.Oc
Normally,
.Nm
checks for the existence of carrier one second after the login script is
complete. If it's not set,
checks for the existence of carrier depending on the type of device
that has been opened:
.Bl -tag -width XXX -offset XXX
.It Terminal Devices
Carrier is checked one second after the login script is complete. If it's
not set,
.Nm
assumes that this is because the device doesn't support carrier (which
is true for most
.Dq laplink
NULL-modem cables), logs the fact and stops checking
for carrier. However, some modems take some time to assert the carrier
signal, resulting in
for carrier.
.Pp
As ptys don't support the TIOCMGET ioctl, the tty device will switch all
carrier detection off when it detects that the device is a pty.
.It ISDN (i4b) Devices
Carrier is checked once per second for 6 seconds. If it's not set after
the sixth second, the connection attempt is considered to have failed and
the device is closed. Carrier is always required for i4b devices.
.It PPPoE (netgraph) Devices
Carrier is checked once per second for 5 seconds. If it's not set after
the fifth second, the connection attempt is considered to have failed and
the device is closed. Carrier is always required for PPPoE devices.
.El
.Pp
All other device types don't support carrier. Setting a carrier value will
result in a warning when the device is opened.
.Pp
Some modems take more than one second after connecting to assert the carrier
signal. If this delay isn't increased, this will result in
.Nm ppp Ns No s
inability to detect when the link is dropped.
inability to detect when the link is dropped, as
.Nm
assumes that the device isn't asserting carrier.
.Pp
The
.Dq set cd
command overrides the default carrier behaviour.
.Ar seconds
specifies the number of seconds that
specifies the maximum number of seconds that
.Nm
should wait after the dial script has finished before deciding if
carrier is available or not.
@ -3627,7 +3656,12 @@ will not check for carrier on the device, otherwise
will not proceed to the login script until either carrier is detected
or until
.Ar seconds
has elapsed.
has elapsed, at which point
.Nm
assumes that the device will not set carrier.
.Pp
If no arguments are given, carrier settings will go back to their default
values.
.Pp
If
.Ar seconds
@ -3639,21 +3673,6 @@ will
carrier. If carrier is not detected after
.Ar seconds
seconds, the link will be disconnected.
.Pp
For ISDN devices,
.Nm
will always insist on carrier (the value
.Dq off
is invalid). Carrier is raised by the i4brbchX device driver only after
the call has connected. It is therefore wise to set a reasonable value
such as
.Ar 6
seconds.
.Pp
Carrier
.Em require Ns No ment
is ignored for all other device types - as if set to
.Dq off .
.It set choked Op Ar timeout
This sets the number of seconds that
.Nm

View File

@ -3598,22 +3598,51 @@ be agreeable with the peer), or if
is specified,
.Nm
will expect the peer to specify the number.
.It "set cd off|" Ns Ar seconds Ns Op \&!
.It set cd Oo
.No off| Ns Ar seconds Ns Op \&!
.Oc
Normally,
.Nm
checks for the existence of carrier one second after the login script is
complete. If it's not set,
checks for the existence of carrier depending on the type of device
that has been opened:
.Bl -tag -width XXX -offset XXX
.It Terminal Devices
Carrier is checked one second after the login script is complete. If it's
not set,
.Nm
assumes that this is because the device doesn't support carrier (which
is true for most
.Dq laplink
NULL-modem cables), logs the fact and stops checking
for carrier. However, some modems take some time to assert the carrier
signal, resulting in
for carrier.
.Pp
As ptys don't support the TIOCMGET ioctl, the tty device will switch all
carrier detection off when it detects that the device is a pty.
.It ISDN (i4b) Devices
Carrier is checked once per second for 6 seconds. If it's not set after
the sixth second, the connection attempt is considered to have failed and
the device is closed. Carrier is always required for i4b devices.
.It PPPoE (netgraph) Devices
Carrier is checked once per second for 5 seconds. If it's not set after
the fifth second, the connection attempt is considered to have failed and
the device is closed. Carrier is always required for PPPoE devices.
.El
.Pp
All other device types don't support carrier. Setting a carrier value will
result in a warning when the device is opened.
.Pp
Some modems take more than one second after connecting to assert the carrier
signal. If this delay isn't increased, this will result in
.Nm ppp Ns No s
inability to detect when the link is dropped.
inability to detect when the link is dropped, as
.Nm
assumes that the device isn't asserting carrier.
.Pp
The
.Dq set cd
command overrides the default carrier behaviour.
.Ar seconds
specifies the number of seconds that
specifies the maximum number of seconds that
.Nm
should wait after the dial script has finished before deciding if
carrier is available or not.
@ -3627,7 +3656,12 @@ will not check for carrier on the device, otherwise
will not proceed to the login script until either carrier is detected
or until
.Ar seconds
has elapsed.
has elapsed, at which point
.Nm
assumes that the device will not set carrier.
.Pp
If no arguments are given, carrier settings will go back to their default
values.
.Pp
If
.Ar seconds
@ -3639,21 +3673,6 @@ will
carrier. If carrier is not detected after
.Ar seconds
seconds, the link will be disconnected.
.Pp
For ISDN devices,
.Nm
will always insist on carrier (the value
.Dq off
is invalid). Carrier is raised by the i4brbchX device driver only after
the call has connected. It is therefore wise to set a reasonable value
such as
.Ar 6
seconds.
.Pp
Carrier
.Em require Ns No ment
is ignored for all other device types - as if set to
.Dq off .
.It set choked Op Ar timeout
This sets the number of seconds that
.Nm

View File

@ -99,6 +99,7 @@ tcp_OpenConnection(const char *name, char *host, char *port)
static struct device tcpdevice = {
TCP_DEVICE,
"tcp",
{ CD_NOTREQUIRED, 0 },
NULL,
NULL,
NULL,
@ -187,6 +188,8 @@ tcp_Create(struct physical *p)
p->name.base = p->name.full;
}
physical_SetupStack(p, tcpdevice.name, PHYSICAL_FORCE_ASYNC);
if (p->cfg.cd.necessity != CD_DEFAULT)
log_Printf(LogWARN, "Carrier settings ignored\n");
return &tcpdevice;
}
}

View File

@ -109,8 +109,9 @@ tty_Timeout(void *data)
if (p->fd >= 0) {
if (ioctl(p->fd, TIOCMGET, &dev->mbits) < 0) {
/* we must be a pty ? */
log_Printf(LogDEBUG, "%s: ioctl error (%s)!\n", p->link.name,
strerror(errno));
if (p->cfg.cd.necessity != CD_DEFAULT)
log_Printf(LogWARN, "%s: Carrier ioctl not supported, "
"using ``set cd off''\n", p->link.name);
timer_Stop(&dev->Timer);
return;
}
@ -121,8 +122,8 @@ tty_Timeout(void *data)
/* First time looking for carrier */
if (Online(dev))
log_Printf(LogPHASE, "%s: %s: CD detected\n", p->link.name, p->name.full);
else if (++dev->carrier_seconds >= p->cfg.cd.delay) {
if (p->cfg.cd.necessity == CD_REQUIRED)
else if (++dev->carrier_seconds >= dev->dev.cd.delay) {
if (dev->dev.cd.necessity == CD_REQUIRED)
log_Printf(LogPHASE, "%s: %s: Required CD not detected\n",
p->link.name, p->name.full);
else {
@ -136,7 +137,7 @@ tty_Timeout(void *data)
/* Keep waiting */
log_Printf(LogDEBUG, "%s: %s: Still no carrier (%d/%d)\n",
p->link.name, p->name.full, dev->carrier_seconds,
p->cfg.cd.delay);
dev->dev.cd.delay);
dev->mbits = -1;
}
} else {
@ -176,7 +177,7 @@ tty_AwaitCarrier(struct physical *p)
{
struct ttydevice *dev = device2tty(p->handler);
if (p->cfg.cd.necessity == CD_NOTREQUIRED || physical_IsSync(p))
if (dev->dev.cd.necessity == CD_NOTREQUIRED || physical_IsSync(p))
return CARRIER_OK;
if (dev->mbits == -1) {
@ -187,7 +188,7 @@ tty_AwaitCarrier(struct physical *p)
return CARRIER_PENDING; /* Not yet ! */
}
return Online(dev) || !p->cfg.cd.necessity == CD_REQUIRED ?
return Online(dev) || !dev->dev.cd.necessity == CD_REQUIRED ?
CARRIER_OK : CARRIER_LOST;
}
@ -331,6 +332,7 @@ tty_device2iov(struct device *d, struct iovec *iov, int *niov,
static struct device basettydevice = {
TTY_DEVICE,
"tty",
{ CD_VARIABLE, DEF_TTYCDDELAY },
tty_AwaitCarrier,
NULL,
tty_Raw,
@ -407,6 +409,10 @@ tty_Create(struct physical *p)
tcgetattr(p->fd, &ios);
dev->ios = ios;
if (p->cfg.cd.necessity != CD_DEFAULT)
/* Any override is ok for the tty device */
dev->dev.cd = p->cfg.cd;
log_Printf(LogDEBUG, "%s: tty_Create: physical (get): fd = %d,"
" iflag = %lx, oflag = %lx, cflag = %lx\n", p->link.name, p->fd,
(u_long)ios.c_iflag, (u_long)ios.c_oflag, (u_long)ios.c_cflag);

View File

@ -29,6 +29,8 @@
struct physical;
struct device;
#define DEF_TTYCDDELAY 1 /* Default ``set cd'' value */
extern struct device *tty_Create(struct physical *);
extern struct device *tty_iov2device(int, struct physical *,
struct iovec *, int *, int, int *, int *);

View File

@ -132,6 +132,7 @@ udp_device2iov(struct device *d, struct iovec *iov, int *niov,
static const struct device baseudpdevice = {
UDP_DEVICE,
"udp",
{ CD_NOTREQUIRED, 0 },
NULL,
NULL,
NULL,
@ -282,6 +283,8 @@ udp_Create(struct physical *p)
if (dev) {
memcpy(&dev->dev, &baseudpdevice, sizeof dev->dev);
physical_SetupStack(p, dev->dev.name, PHYSICAL_FORCE_SYNC);
if (p->cfg.cd.necessity != CD_DEFAULT)
log_Printf(LogWARN, "Carrier settings ignored\n");
return &dev->dev;
}