From f0003f34563b650e7d94531962fc8f09b2a5f5ec Mon Sep 17 00:00:00 2001 From: brian Date: Fri, 26 Nov 1999 22:44:33 +0000 Subject: 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. --- usr.sbin/ppp/command.c | 4 +-- usr.sbin/ppp/defs.h | 3 +-- usr.sbin/ppp/ether.c | 26 ++++++++++++++++---- usr.sbin/ppp/ether.h | 2 ++ usr.sbin/ppp/exec.c | 3 +++ usr.sbin/ppp/i4b.c | 21 +++++++++++++--- usr.sbin/ppp/i4b.h | 2 ++ usr.sbin/ppp/physical.c | 12 ++++++--- usr.sbin/ppp/physical.h | 18 ++++++++------ usr.sbin/ppp/ppp.8 | 65 ++++++++++++++++++++++++++++++++----------------- usr.sbin/ppp/ppp.8.m4 | 65 ++++++++++++++++++++++++++++++++----------------- usr.sbin/ppp/tcp.c | 3 +++ usr.sbin/ppp/tty.c | 20 +++++++++------ usr.sbin/ppp/tty.h | 2 ++ usr.sbin/ppp/udp.c | 3 +++ 15 files changed, 173 insertions(+), 76 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c index 0b7d925..a905f83 100644 --- a/usr.sbin/ppp/command.c +++ b/usr.sbin/ppp/command.c @@ -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; diff --git a/usr.sbin/ppp/defs.h b/usr.sbin/ppp/defs.h index 7c03dea..4ee2660 100644 --- a/usr.sbin/ppp/defs.h +++ b/usr.sbin/ppp/defs.h @@ -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" diff --git a/usr.sbin/ppp/ether.c b/usr.sbin/ppp/ether.c index b25cfbf..b06a3c2 100644 --- a/usr.sbin/ppp/ether.c +++ b/usr.sbin/ppp/ether.c @@ -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 */ diff --git a/usr.sbin/ppp/ether.h b/usr.sbin/ppp/ether.h index a2e96c7..16c9a9e 100644 --- a/usr.sbin/ppp/ether.h +++ b/usr.sbin/ppp/ether.h @@ -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 *); diff --git a/usr.sbin/ppp/exec.c b/usr.sbin/ppp/exec.c index 80f8343..d1f3f64 100644 --- a/usr.sbin/ppp/exec.c +++ b/usr.sbin/ppp/exec.c @@ -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; } } diff --git a/usr.sbin/ppp/i4b.c b/usr.sbin/ppp/i4b.c index eae596c..8046a45 100644 --- a/usr.sbin/ppp/i4b.c +++ b/usr.sbin/ppp/i4b.c @@ -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'' */ diff --git a/usr.sbin/ppp/i4b.h b/usr.sbin/ppp/i4b.h index 4375ca33..984535c 100644 --- a/usr.sbin/ppp/i4b.h +++ b/usr.sbin/ppp/i4b.h @@ -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 *); diff --git a/usr.sbin/ppp/physical.c b/usr.sbin/ppp/physical.c index f8915c9..e402633 100644 --- a/usr.sbin/ppp/physical.c +++ b/usr.sbin/ppp/physical.c @@ -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) diff --git a/usr.sbin/ppp/physical.h b/usr.sbin/ppp/physical.h index c05f28b..c5aaea8 100644 --- a/usr.sbin/ppp/physical.h +++ b/usr.sbin/ppp/physical.h @@ -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; }; diff --git a/usr.sbin/ppp/ppp.8 b/usr.sbin/ppp/ppp.8 index 7337192..6d54595 100644 --- a/usr.sbin/ppp/ppp.8 +++ b/usr.sbin/ppp/ppp.8 @@ -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 diff --git a/usr.sbin/ppp/ppp.8.m4 b/usr.sbin/ppp/ppp.8.m4 index 7337192..6d54595 100644 --- a/usr.sbin/ppp/ppp.8.m4 +++ b/usr.sbin/ppp/ppp.8.m4 @@ -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 diff --git a/usr.sbin/ppp/tcp.c b/usr.sbin/ppp/tcp.c index c6cb16d..20ab45b 100644 --- a/usr.sbin/ppp/tcp.c +++ b/usr.sbin/ppp/tcp.c @@ -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; } } diff --git a/usr.sbin/ppp/tty.c b/usr.sbin/ppp/tty.c index 54093b1..13e7a1a 100644 --- a/usr.sbin/ppp/tty.c +++ b/usr.sbin/ppp/tty.c @@ -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); diff --git a/usr.sbin/ppp/tty.h b/usr.sbin/ppp/tty.h index 9f37dd5..f3f0d53 100644 --- a/usr.sbin/ppp/tty.h +++ b/usr.sbin/ppp/tty.h @@ -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 *); diff --git a/usr.sbin/ppp/udp.c b/usr.sbin/ppp/udp.c index d7a2228..9260003 100644 --- a/usr.sbin/ppp/udp.c +++ b/usr.sbin/ppp/udp.c @@ -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; } -- cgit v1.1