diff options
Diffstat (limited to 'usr.sbin/ppp')
-rw-r--r-- | usr.sbin/ppp/Makefile | 10 | ||||
-rw-r--r-- | usr.sbin/ppp/README.changes | 2 | ||||
-rw-r--r-- | usr.sbin/ppp/bundle.c | 5 | ||||
-rw-r--r-- | usr.sbin/ppp/ccp.c | 4 | ||||
-rw-r--r-- | usr.sbin/ppp/datalink.c | 33 | ||||
-rw-r--r-- | usr.sbin/ppp/datalink.h | 16 | ||||
-rw-r--r-- | usr.sbin/ppp/deflate.c | 4 | ||||
-rw-r--r-- | usr.sbin/ppp/exec.c | 18 | ||||
-rw-r--r-- | usr.sbin/ppp/hdlc.c | 17 | ||||
-rw-r--r-- | usr.sbin/ppp/i4b.c | 406 | ||||
-rw-r--r-- | usr.sbin/ppp/i4b.h | 35 | ||||
-rw-r--r-- | usr.sbin/ppp/ip.c | 4 | ||||
-rw-r--r-- | usr.sbin/ppp/link.c | 3 | ||||
-rw-r--r-- | usr.sbin/ppp/pap.c | 4 | ||||
-rw-r--r-- | usr.sbin/ppp/physical.c | 21 | ||||
-rw-r--r-- | usr.sbin/ppp/physical.h | 19 | ||||
-rw-r--r-- | usr.sbin/ppp/ppp.8 | 51 | ||||
-rw-r--r-- | usr.sbin/ppp/ppp.8.m4 | 51 | ||||
-rw-r--r-- | usr.sbin/ppp/tcp.c | 4 | ||||
-rw-r--r-- | usr.sbin/ppp/tty.c | 139 | ||||
-rw-r--r-- | usr.sbin/ppp/tun.c | 4 | ||||
-rw-r--r-- | usr.sbin/ppp/udp.c | 4 | ||||
-rw-r--r-- | usr.sbin/ppp/vjcomp.c | 4 |
23 files changed, 683 insertions, 175 deletions
diff --git a/usr.sbin/ppp/Makefile b/usr.sbin/ppp/Makefile index 6971c69ddf01..9089135472b7 100644 --- a/usr.sbin/ppp/Makefile +++ b/usr.sbin/ppp/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.54 1999/05/12 09:48:38 brian Exp $ +# $Id: Makefile,v 1.55 1999/05/15 19:21:15 phk Exp $ MAINTAINER=brian@FreeBSD.org @@ -49,10 +49,16 @@ DPADD+= ${LIBRADIUS} .endif .endif +.if defined(NOI4B) +CFLAGS+=-DNOI4B +.else +SRCS+= i4b.c +.endif + .if defined(RELEASE_CRUNCH) # We must create these objects because crunchgen will link them, # and we don't want any unused symbols to spoil the final link. -CFLAGS+=-DNOALIAS -DNORADIUS +CFLAGS+=-DNOALIAS -DNORADIUS -DNOI4B OBJS+= alias_cmd.o chap_ms.o radius.o chap_ms.o alias_cmd.o radius.o: >null_${.PREFIX}.c diff --git a/usr.sbin/ppp/README.changes b/usr.sbin/ppp/README.changes index e4fcff8f8538..ea50741c3496 100644 --- a/usr.sbin/ppp/README.changes +++ b/usr.sbin/ppp/README.changes @@ -91,3 +91,5 @@ o The ``set weight'' command has been depricated. The ``set bandwidth'' command should now be used instead. o The ``set autoload'' command syntax and implementation have changed as the old implementation was mis-designed and dysfunctional. +o Ppp now waits either the full ``set cd'' time or until carrier is detected + before running the login script (whichever comes first). diff --git a/usr.sbin/ppp/bundle.c b/usr.sbin/ppp/bundle.c index 9d55dfec3565..ddb37366d428 100644 --- a/usr.sbin/ppp/bundle.c +++ b/usr.sbin/ppp/bundle.c @@ -23,14 +23,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: bundle.c,v 1.58 1999/07/27 23:43:58 brian Exp $ + * $Id: bundle.c,v 1.59 1999/08/05 10:32:07 brian Exp $ */ #include <sys/param.h> #include <sys/socket.h> #include <netinet/in.h> #include <net/if.h> -#include <net/if_tun.h> +#include <net/if_tun.h> /* For TUNSIFMODE & TUNSLMODE */ #include <arpa/inet.h> #include <net/route.h> #include <netinet/in_systm.h> @@ -43,7 +43,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sys/ioctl.h> #include <sys/uio.h> #include <sys/wait.h> #include <termios.h> diff --git a/usr.sbin/ppp/ccp.c b/usr.sbin/ppp/ccp.c index f29a5fc61b5f..67140569164b 100644 --- a/usr.sbin/ppp/ccp.c +++ b/usr.sbin/ppp/ccp.c @@ -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.49 1999/05/12 09:48:43 brian Exp $ + * $Id: ccp.c,v 1.50 1999/06/02 15:58:53 brian Exp $ * * TODO: * o Support other compression protocols @@ -30,7 +30,7 @@ #include <stdio.h> #include <stdlib.h> -#include <string.h> +#include <string.h> /* memcpy() on some archs */ #include <termios.h> #include "layer.h" diff --git a/usr.sbin/ppp/datalink.c b/usr.sbin/ppp/datalink.c index 4899b400d277..9e449e81fe16 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.41 1999/06/18 13:49:01 brian Exp $ + * $Id: datalink.c,v 1.42 1999/08/05 10:32:10 brian Exp $ */ #include <sys/param.h> @@ -175,7 +175,7 @@ datalink_HangupDone(struct datalink *dl) } } -static const char * +const char * datalink_ChoosePhoneNumber(struct datalink *dl) { char *phone; @@ -269,7 +269,8 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, if (dl->script.run) { datalink_NewState(dl, DATALINK_DIAL); chat_Init(&dl->chat, dl->physical, dl->cfg.script.dial, 1, - datalink_ChoosePhoneNumber(dl)); + *dl->cfg.script.dial ? + datalink_ChoosePhoneNumber(dl) : ""); if (!(dl->physical->type & (PHYS_DDIAL|PHYS_DEDICATED)) && dl->cfg.dial.max) log_Printf(LogCHAT, "%s: Dial attempt %u of %d\n", @@ -307,6 +308,25 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, } break; + case DATALINK_CARRIER: + /* Wait for carrier on the device */ + switch (physical_AwaitCarrier(dl->physical)) { + case CARRIER_PENDING: + log_Printf(LogDEBUG, "Waiting for carrier\n"); + return 0; /* A device timer is running to wake us up again */ + + case CARRIER_OK: + datalink_NewState(dl, DATALINK_LOGIN); + chat_Init(&dl->chat, dl->physical, dl->cfg.script.login, 0, NULL); + return datalink_UpdateSet(d, r, w, e, n); + + case CARRIER_LOST: + datalink_NewState(dl, DATALINK_HANGUP); + physical_Offline(dl->physical); /* Is this required ? */ + chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, 1, NULL); + return datalink_UpdateSet(d, r, w, e, n); + } + case DATALINK_HANGUP: case DATALINK_DIAL: case DATALINK_LOGIN: @@ -320,8 +340,7 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, datalink_HangupDone(dl); break; case DATALINK_DIAL: - datalink_NewState(dl, DATALINK_LOGIN); - chat_Init(&dl->chat, dl->physical, dl->cfg.script.login, 0, NULL); + datalink_NewState(dl, DATALINK_CARRIER); return datalink_UpdateSet(d, r, w, e, n); case DATALINK_LOGIN: dl->phone.alt = NULL; @@ -341,7 +360,8 @@ datalink_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, case DATALINK_LOGIN: datalink_NewState(dl, DATALINK_HANGUP); physical_Offline(dl->physical); /* Is this required ? */ - chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, 1, NULL); + chat_Init(&dl->chat, dl->physical, dl->cfg.script.hangup, + 1, NULL); return datalink_UpdateSet(d, r, w, e, n); } break; @@ -1164,6 +1184,7 @@ static const char *states[] = { "opening", "hangup", "dial", + "carrier", "login", "ready", "lcp", diff --git a/usr.sbin/ppp/datalink.h b/usr.sbin/ppp/datalink.h index edec3b4cd8a8..ef325c1e0077 100644 --- a/usr.sbin/ppp/datalink.h +++ b/usr.sbin/ppp/datalink.h @@ -23,19 +23,20 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: datalink.h,v 1.6 1999/02/06 02:54:45 brian Exp $ + * $Id: datalink.h,v 1.7 1999/03/04 17:42:15 brian Exp $ */ #define DATALINK_CLOSED (0) #define DATALINK_OPENING (1) #define DATALINK_HANGUP (2) #define DATALINK_DIAL (3) -#define DATALINK_LOGIN (4) -#define DATALINK_READY (5) -#define DATALINK_LCP (6) -#define DATALINK_AUTH (7) -#define DATALINK_CBCP (8) -#define DATALINK_OPEN (9) +#define DATALINK_CARRIER (4) +#define DATALINK_LOGIN (5) +#define DATALINK_READY (6) +#define DATALINK_LCP (7) +#define DATALINK_AUTH (8) +#define DATALINK_CBCP (9) +#define DATALINK_OPEN (10) #define DATALINK_MAXNAME (20) /* Maximum datalink::name length */ @@ -149,3 +150,4 @@ extern int datalink_RemoveFromSet(struct datalink *, fd_set *, fd_set *, fd_set *); extern int datalink_SetMode(struct datalink *, int); extern int datalink_GetDialTimeout(struct datalink *); +extern const char *datalink_ChoosePhoneNumber(struct datalink *); diff --git a/usr.sbin/ppp/deflate.c b/usr.sbin/ppp/deflate.c index b8ac7f0744af..55fcd8289aee 100644 --- a/usr.sbin/ppp/deflate.c +++ b/usr.sbin/ppp/deflate.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: deflate.c,v 1.13 1999/05/08 11:06:25 brian Exp $ + * $Id: deflate.c,v 1.14 1999/06/02 15:58:56 brian Exp $ */ #include <sys/types.h> @@ -37,8 +37,6 @@ #include "mbuf.h" #include "log.h" #include "timer.h" -#include "lqr.h" -#include "hdlc.h" #include "fsm.h" #include "lcp.h" #include "ccp.h" diff --git a/usr.sbin/ppp/exec.c b/usr.sbin/ppp/exec.c index 7f2ce7ae2c0d..c838800b7d5a 100644 --- a/usr.sbin/ppp/exec.c +++ b/usr.sbin/ppp/exec.c @@ -23,16 +23,11 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: exec.c,v 1.5 1999/06/05 21:35:50 brian Exp $ + * $Id: exec.c,v 1.6 1999/06/09 08:47:36 brian Exp $ */ #include <sys/param.h> #include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netdb.h> -#include <netinet/in_systm.h> -#include <netinet/ip.h> #include <sys/un.h> #include <errno.h> @@ -49,7 +44,6 @@ #include "defs.h" #include "mbuf.h" #include "log.h" -#include "sync.h" #include "timer.h" #include "lqr.h" #include "hdlc.h" @@ -59,20 +53,11 @@ #include "ccp.h" #include "link.h" #include "async.h" -#include "slcompress.h" -#include "iplist.h" -#include "ipcp.h" -#include "filter.h" #include "descriptor.h" #include "physical.h" #include "mp.h" -#ifndef NORADIUS -#include "radius.h" -#endif #include "chat.h" #include "command.h" -#include "bundle.h" -#include "prompt.h" #include "auth.h" #include "chap.h" #include "cbcp.h" @@ -91,6 +76,7 @@ static struct device execdevice = { NULL, NULL, NULL, + NULL, NULL }; diff --git a/usr.sbin/ppp/hdlc.c b/usr.sbin/ppp/hdlc.c index f9696455bbc6..4ffb7a8b7ae2 100644 --- a/usr.sbin/ppp/hdlc.c +++ b/usr.sbin/ppp/hdlc.c @@ -17,14 +17,11 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: hdlc.c,v 1.42 1999/05/08 11:06:36 brian Exp $ + * $Id: hdlc.c,v 1.43 1999/06/02 15:58:59 brian Exp $ * * TODO: */ #include <sys/param.h> -#include <netinet/in.h> -#include <netinet/in_systm.h> -#include <netinet/ip.h> #include <sys/un.h> #include <stdio.h> @@ -40,15 +37,8 @@ #include "fsm.h" #include "lqr.h" #include "hdlc.h" -#include "proto.h" -#include "iplist.h" #include "throughput.h" -#include "slcompress.h" -#include "ipcp.h" -#include "ip.h" -#include "vjcomp.h" #include "auth.h" -#include "pap.h" #include "lcp.h" #include "async.h" #include "ccp.h" @@ -61,11 +51,6 @@ #include "mp.h" #include "cbcp.h" #include "datalink.h" -#include "filter.h" -#ifndef NORADIUS -#include "radius.h" -#endif -#include "bundle.h" static u_int16_t const fcstab[256] = { /* 00 */ 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, diff --git a/usr.sbin/ppp/i4b.c b/usr.sbin/ppp/i4b.c new file mode 100644 index 000000000000..d83b5483b10a --- /dev/null +++ b/usr.sbin/ppp/i4b.c @@ -0,0 +1,406 @@ +/*- + * Copyright (c) 1999 Brian Somers <brian@Awfulhak.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id:$ + */ + +#include <sys/param.h> + +#include <sys/un.h> +#if defined(__OpenBSD__) || defined(__NetBSD__) +#include <sys/ioctl.h> +#endif + +#include <errno.h> +#include <fcntl.h> +#ifdef __FreeBSD__ +#include <machine/i4b_ioctl.h> +#include <machine/i4b_rbch_ioctl.h> +#else +#include <i4b/i4b_ioctl.h> +#include <i4b/i4b_rbch_ioctl.h> +#endif +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sysexits.h> +#include <sys/uio.h> +#include <termios.h> +#include <unistd.h> + +#include "layer.h" +#include "defs.h" +#include "mbuf.h" +#include "log.h" +#include "timer.h" +#include "lqr.h" +#include "hdlc.h" +#include "throughput.h" +#include "fsm.h" +#include "lcp.h" +#include "ccp.h" +#include "link.h" +#include "async.h" +#include "descriptor.h" +#include "physical.h" +#include "mp.h" +#include "chat.h" +#include "auth.h" +#include "chap.h" +#include "cbcp.h" +#include "datalink.h" +#include "main.h" +#include "i4b.h" + +#define Online(dev) ((dev)->mbits & TIOCM_CD) + +struct i4bdevice { + struct device dev; /* What struct physical knows about */ + struct pppTimer Timer; /* CD checks */ + int mbits; /* Current DCD status */ + int carrier_seconds; /* seconds before CD is *required* */ +}; + +#define device2i4b(d) ((d)->type == I4B_DEVICE ? (struct i4bdevice *)d : NULL) + +int +i4b_DeviceSize(void) +{ + return sizeof(struct i4bdevice); +} + +/* + * i4b_Timeout() watches the DCD signal and mentions it if it's status + * changes. + */ +static void +i4b_Timeout(void *data) +{ + struct physical *p = data; + struct i4bdevice *dev = device2i4b(p->handler); + int ombits, change; + + timer_Stop(&dev->Timer); + dev->Timer.load = SECTICKS; /* Once a second please */ + timer_Start(&dev->Timer); + ombits = dev->mbits; + + if (p->fd >= 0) { + if (ioctl(p->fd, TIOCMGET, &dev->mbits) < 0) { + log_Printf(LogPHASE, "%s: ioctl error (%s)!\n", p->link.name, + strerror(errno)); + datalink_Down(p->dl, CLOSE_NORMAL); + timer_Stop(&dev->Timer); + return; + } + } else + dev->mbits = 0; + + if (ombits == -1) { + /* 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) { + log_Printf(LogPHASE, "%s: %s: No carrier" + " (increase ``set cd'' from %d ?)\n", + p->link.name, p->name.full, p->cfg.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->mbits = -1; + } + } else { + change = ombits ^ dev->mbits; + if (change & TIOCM_CD) { + if (dev->mbits & TIOCM_CD) + log_Printf(LogDEBUG, "%s: offline -> online\n", p->link.name); + else { + log_Printf(LogDEBUG, "%s: online -> offline\n", p->link.name); + log_Printf(LogPHASE, "%s: Carrier lost\n", p->link.name); + datalink_Down(p->dl, CLOSE_NORMAL); + timer_Stop(&dev->Timer); + } + } else + log_Printf(LogDEBUG, "%s: Still %sline\n", p->link.name, + Online(dev) ? "on" : "off"); + } +} + +static void +i4b_StartTimer(struct physical *p) +{ + struct i4bdevice *dev = device2i4b(p->handler); + + timer_Stop(&dev->Timer); + dev->Timer.load = SECTICKS; + dev->Timer.func = i4b_Timeout; + dev->Timer.name = "i4b CD"; + dev->Timer.arg = p; + log_Printf(LogDEBUG, "%s: Using i4b_Timeout [%p]\n", + p->link.name, i4b_Timeout); + timer_Start(&dev->Timer); +} + +static int +i4b_AwaitCarrier(struct physical *p) +{ + struct i4bdevice *dev = device2i4b(p->handler); + + if (dev->mbits == -1) { + if (dev->Timer.state == TIMER_STOPPED) { + dev->carrier_seconds = 0; + i4b_StartTimer(p); + } + return CARRIER_PENDING; /* Not yet ! */ + } + + return Online(dev) ? CARRIER_OK : CARRIER_LOST; +} + +static int +i4b_Raw(struct physical *p) +{ + int oldflag; + + log_Printf(LogDEBUG, "%s: Entering i4b_Raw\n", p->link.name); + + oldflag = fcntl(p->fd, F_GETFL, 0); + if (oldflag < 0) + return 0; + fcntl(p->fd, F_SETFL, oldflag | O_NONBLOCK); + + return 1; +} + +static void +i4b_Offline(struct physical *p) +{ + struct i4bdevice *dev = device2i4b(p->handler); + + if (p->fd >= 0) { + timer_Stop(&dev->Timer); + if (Online(dev)) { + int dummy; + + dummy = 1; + ioctl(p->fd, TIOCCDTR, &dummy); + } + } +} + +static void +i4b_Cooked(struct physical *p) +{ + int oldflag; + + i4b_Offline(p); /* In case of emergency close()s */ + + if ((oldflag = fcntl(p->fd, F_GETFL, 0)) != -1) + fcntl(p->fd, F_SETFL, oldflag & ~O_NONBLOCK); +} + +static void +i4b_StopTimer(struct physical *p) +{ + struct i4bdevice *dev = device2i4b(p->handler); + + timer_Stop(&dev->Timer); +} + +static void +i4b_Free(struct physical *p) +{ + struct i4bdevice *dev = device2i4b(p->handler); + + i4b_Offline(p); /* In case of emergency close()s */ + free(dev); +} + +static int +i4b_Speed(struct physical *p) +{ + struct termios ios; + + if (tcgetattr(p->fd, &ios) == -1) + return 0; + + return SpeedToInt(cfgetispeed(&ios)); +} + +static const char * +i4b_OpenInfo(struct physical *p) +{ + struct i4bdevice *dev = device2i4b(p->handler); + static char buf[26]; + + if (Online(dev)) + snprintf(buf, sizeof buf, "carrier took %ds", dev->carrier_seconds); + else + *buf = '\0'; + + return buf; +} + +static void +i4b_device2iov(struct device *d, struct iovec *iov, int *niov, + int maxiov, pid_t newpid) +{ + struct i4bdevice *dev = device2i4b(d); + int sz = physical_MaxDeviceSize(); + + iov[*niov].iov_base = realloc(d, sz); + if (iov[*niov].iov_base == NULL) { + log_Printf(LogALERT, "Failed to allocate memory: %d\n", sz); + AbortProgram(EX_OSERR); + } + iov[*niov].iov_len = sz; + (*niov)++; + + if (dev->Timer.state != TIMER_STOPPED) { + timer_Stop(&dev->Timer); + dev->Timer.state = TIMER_RUNNING; + } +} + +static struct device basei4bdevice = { + I4B_DEVICE, + "i4b", + i4b_AwaitCarrier, + i4b_Raw, + i4b_Offline, + i4b_Cooked, + i4b_StopTimer, + i4b_Free, + NULL, + NULL, + i4b_device2iov, + i4b_Speed, + i4b_OpenInfo +}; + +struct device * +i4b_iov2device(int type, struct physical *p, struct iovec *iov, int *niov, + int maxiov) +{ + if (type == I4B_DEVICE) { + struct i4bdevice *dev = (struct i4bdevice *)iov[(*niov)++].iov_base; + + dev = realloc(dev, sizeof *dev); /* Reduce to the correct size */ + if (dev == NULL) { + log_Printf(LogALERT, "Failed to allocate memory: %d\n", + (int)(sizeof *dev)); + AbortProgram(EX_OSERR); + } + + /* Refresh function pointers etc */ + memcpy(&dev->dev, &basei4bdevice, sizeof dev->dev); + + physical_SetupStack(p, dev->dev.name, PHYSICAL_NOFORCE); + if (dev->Timer.state != TIMER_STOPPED) { + dev->Timer.state = TIMER_STOPPED; + p->handler = &dev->dev; /* For the benefit of StartTimer */ + i4b_StartTimer(p); + } + return &dev->dev; + } + + return NULL; +} + +struct device * +i4b_Create(struct physical *p) +{ + struct i4bdevice *dev; + int oldflag; + msg_vr_req_t req; + telno_t number; + + if (p->fd < 0 || ioctl(p->fd, I4B_RBCH_VR_REQ, &req)) + /* Don't want this */ + return NULL; + + /* + * We don't bother validating the version.... all versions of i4b that + * support I4B_RBCH_VR_REQ are fair game :-) + */ + + if (*p->name.full == '\0') { + physical_SetDevice(p, ttyname(p->fd)); + log_Printf(LogDEBUG, "%s: Input is an i4b version %d.%d.%d isdn " + "device (%s)\n", p->link.name, req.version, req.release, + req.step, p->name.full); + } else + log_Printf(LogDEBUG, "%s: Opened %s (i4b version %d.%d.%d)\n", + p->link.name, p->name.full, req.version, req.release, req.step); + + /* We're gonna return an i4bdevice (unless something goes horribly wrong) */ + + if ((dev = malloc(sizeof *dev)) == NULL) { + /* Complete failure - parent doesn't continue trying to ``create'' */ + close(p->fd); + p->fd = -1; + return NULL; + } + + memcpy(&dev->dev, &basei4bdevice, sizeof dev->dev); + memset(&dev->Timer, '\0', sizeof dev->Timer); + dev->mbits = -1; + + oldflag = fcntl(p->fd, F_GETFL, 0); + if (oldflag < 0) { + /* Complete failure - parent doesn't continue trying to ``create'' */ + + log_Printf(LogWARN, "%s: Open: Cannot get physical flags: %s\n", + p->link.name, strerror(errno)); + i4b_Cooked(p); + close(p->fd); + p->fd = -1; + free(dev); + return NULL; + } else + fcntl(p->fd, F_SETFL, oldflag & ~O_NONBLOCK); + + strncpy(number, datalink_ChoosePhoneNumber(p->dl), sizeof number - 1); + number[sizeof number - 1] = '\0'; + if (ioctl(p->fd, I4B_RBCH_DIALOUT, number) == -1) { + /* Complete failure - parent doesn't continue trying to ``create'' */ + + log_Printf(LogWARN, "%s: ioctl(I4B_RBCH_DIALOUT): %s\n", + p->link.name, strerror(errno)); + i4b_Cooked(p); + close(p->fd); + p->fd = -1; + free(dev); + return NULL; + } + + physical_SetupStack(p, dev->dev.name, PHYSICAL_FORCE_SYNC); + + return &dev->dev; +} diff --git a/usr.sbin/ppp/i4b.h b/usr.sbin/ppp/i4b.h new file mode 100644 index 000000000000..e9fa5110b66e --- /dev/null +++ b/usr.sbin/ppp/i4b.h @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 1999 Brian Somers <brian@Awfulhak.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id:$ + */ + +struct physical; +struct device; + +extern struct device *i4b_Create(struct physical *); +extern struct device *i4b_iov2device(int, struct physical *, + struct iovec *, int *, int); +extern int i4b_DeviceSize(void); diff --git a/usr.sbin/ppp/ip.c b/usr.sbin/ppp/ip.c index d670c29f1ad3..6d9332ecfc55 100644 --- a/usr.sbin/ppp/ip.c +++ b/usr.sbin/ppp/ip.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: ip.c,v 1.66 1999/08/02 11:53:16 brian Exp $ + * $Id: ip.c,v 1.67 1999/08/02 15:29:19 brian Exp $ * * TODO: * o Return ICMP message for filterd packet @@ -38,7 +38,6 @@ #include <errno.h> #include <stdio.h> -#include <stdlib.h> #include <string.h> #include <termios.h> #include <unistd.h> @@ -66,7 +65,6 @@ #include "radius.h" #endif #include "bundle.h" -#include "vjcomp.h" #include "tun.h" #include "ip.h" diff --git a/usr.sbin/ppp/link.c b/usr.sbin/ppp/link.c index e4ba819708c7..6c9739c7ac60 100644 --- a/usr.sbin/ppp/link.c +++ b/usr.sbin/ppp/link.c @@ -23,13 +23,12 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: link.c,v 1.11 1999/05/15 02:24:18 brian Exp $ + * $Id: link.c,v 1.12 1999/06/02 15:59:03 brian Exp $ * */ #include <sys/types.h> #include <netinet/in_systm.h> -#include <netdb.h> #include <sys/un.h> #include <netinet/in.h> #include <netinet/ip.h> diff --git a/usr.sbin/ppp/pap.c b/usr.sbin/ppp/pap.c index 2976f66f7850..ac7be8aa39a0 100644 --- a/usr.sbin/ppp/pap.c +++ b/usr.sbin/ppp/pap.c @@ -18,7 +18,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: pap.c,v 1.35 1999/05/08 11:07:20 brian Exp $ + * $Id: pap.c,v 1.36 1999/06/02 15:59:07 brian Exp $ * * TODO: */ @@ -29,7 +29,7 @@ #include <sys/un.h> #include <stdlib.h> -#include <string.h> +#include <string.h> /* strlen/memcpy */ #include <termios.h> #include "layer.h" diff --git a/usr.sbin/ppp/physical.c b/usr.sbin/ppp/physical.c index 05e1afddaac3..3e10f152fd56 100644 --- a/usr.sbin/ppp/physical.c +++ b/usr.sbin/ppp/physical.c @@ -16,15 +16,12 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: physical.c,v 1.18 1999/06/11 13:28:29 brian Exp $ + * $Id: physical.c,v 1.19 1999/08/05 10:32:13 brian Exp $ * */ #include <sys/param.h> -#include <sys/socket.h> #include <netinet/in.h> -#include <arpa/inet.h> -#include <netdb.h> #include <netinet/in_systm.h> #include <netinet/ip.h> #include <sys/un.h> @@ -37,7 +34,6 @@ #include <string.h> #include <sys/tty.h> /* TIOCOUTQ */ #include <sys/uio.h> -#include <sys/wait.h> #include <time.h> #include <unistd.h> #include <utmp.h> @@ -91,6 +87,9 @@ #include "udp.h" #include "exec.h" #include "tty.h" +#ifndef NOI4B +#include "i4b.h" +#endif static int physical_DescriptorWrite(struct descriptor *, struct bundle *, @@ -110,6 +109,9 @@ struct { int *niov, int maxiov); int (*DeviceSize)(void); } devices[] = { +#ifndef NOI4B + { i4b_Create, i4b_iov2device, i4b_DeviceSize }, +#endif { tty_Create, tty_iov2device, tty_DeviceSize }, { tcp_Create, tcp_iov2device, tcp_DeviceSize }, { udp_Create, udp_iov2device, udp_DeviceSize }, @@ -1002,3 +1004,12 @@ physical_StopDeviceTimer(struct physical *p) if (p->handler && p->handler->stoptimer) (*p->handler->stoptimer)(p); } + +int +physical_AwaitCarrier(struct physical *p) +{ + if (p->handler && p->handler->awaitcarrier) + return (*p->handler->awaitcarrier)(p); + + return CARRIER_OK; +} diff --git a/usr.sbin/ppp/physical.h b/usr.sbin/ppp/physical.h index 18212b35408b..6f4bbe64493b 100644 --- a/usr.sbin/ppp/physical.h +++ b/usr.sbin/ppp/physical.h @@ -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.12 1999/06/01 19:08:59 brian Exp $ + * $Id: physical.h,v 1.13 1999/06/05 21:35:52 brian Exp $ * */ @@ -28,15 +28,23 @@ struct bundle; struct ccp; struct cmdargs; -#define TTY_DEVICE 1 -#define TCP_DEVICE 2 -#define UDP_DEVICE 3 -#define EXEC_DEVICE 4 +/* Device types */ +#define I4B_DEVICE 1 +#define TTY_DEVICE 2 +#define TCP_DEVICE 3 +#define UDP_DEVICE 4 +#define EXEC_DEVICE 5 + +/* Returns from awaitcarrier() */ +#define CARRIER_PENDING 1 +#define CARRIER_OK 2 +#define CARRIER_LOST 3 struct device { int type; const char *name; + int (*awaitcarrier)(struct physical *); int (*raw)(struct physical *); void (*offline)(struct physical *); void (*cooked)(struct physical *); @@ -137,3 +145,4 @@ extern void physical_DeleteQueue(struct physical *); extern void physical_SetupStack(struct physical *, const char *, int); extern void physical_StopDeviceTimer(struct physical *); extern int physical_MaxDeviceSize(void); +extern int physical_AwaitCarrier(struct physical *); diff --git a/usr.sbin/ppp/ppp.8 b/usr.sbin/ppp/ppp.8 index e95c1470e9df..f62598ab2ed9 100644 --- a/usr.sbin/ppp/ppp.8 +++ b/usr.sbin/ppp/ppp.8 @@ -1,4 +1,4 @@ -.\" $Id: ppp.8,v 1.186 1999/08/03 16:14:38 brian Exp $ +.\" $Id: ppp.8,v 1.187 1999/08/05 10:32:14 brian Exp $ .Dd 20 September 1995 .nr XX \w'\fC00' .Os FreeBSD @@ -249,6 +249,13 @@ will open a TCP or UDP connection for transporting data rather than using a conventional serial device. UDP connections force .Nm into synchronous mode. +.It Supports PPP over ISDN +If +.Nm +is given a raw B-channel i4b device to open as a link, it's able to talk +to the +.Xr isdnd 8 +daemon to establish an ISDN connection. .It "Supports IETF draft Predictor-1 (rfc 1978) and DEFLATE (rfc 1979) compression." .Nm supports not only VJ-compression but also Predictor-1 and DEFLATE compression. @@ -3531,16 +3538,24 @@ checks for the existence of carrier 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 NULL-modem cables), logs the fact and stops checking +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 .Nm ppp Ns No s inability to detect when the link is dropped. -.Ar Seconds +.Ar seconds specifies the number of seconds that .Nm -should wait after the login script has finished before first checking for -carrier. +should wait after the dial script has finished before deciding if +carrier is available or not. +.Pp +.Nm +will not proceed to the login script until either carrier is detected +or until +.Ar seconds +has elapsed. .Pp If .Ar seconds @@ -3549,12 +3564,21 @@ is followed immediately by an exclaimation mark .Nm will .Em require -carrier. If carrier is not detected at the first check, the link will -be considered disconnected. +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. 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 when the link is not a tty device. +is ignored for all other device types. .It set choked Op Ar timeout This sets the number of seconds that .Nm @@ -3620,8 +3644,14 @@ This sets the device(s) to which .Nm will talk to the given .Dq value . -All serial device names are expected to begin with +.Pp +All ISDN and serial device names are expected to begin with .Pa /dev/ . +ISDN devices are usually called +.Pa i4brbchX +and serial devices are usually called +.Pa cuaaX . +.Pp If .Dq value does not begin with @@ -3629,7 +3659,7 @@ does not begin with it must either begin with an exclamation mark .Pq Dq \&! or be of the format -.Dq host:port . +.Dq host:port Ns Op Ns /proto . .Pp If it begins with an exclamation mark, the rest of the device name is treated as a program name, and that program is executed when the device @@ -4645,6 +4675,7 @@ This socket is used to pass links between different instances of .Xr getty 8 , .Xr inetd 8 , .Xr init 8 , +.Xr isdn 8 , .Xr named 8 , .Xr ping 8 , .Xr pppctl 8 , diff --git a/usr.sbin/ppp/ppp.8.m4 b/usr.sbin/ppp/ppp.8.m4 index e95c1470e9df..f62598ab2ed9 100644 --- a/usr.sbin/ppp/ppp.8.m4 +++ b/usr.sbin/ppp/ppp.8.m4 @@ -1,4 +1,4 @@ -.\" $Id: ppp.8,v 1.186 1999/08/03 16:14:38 brian Exp $ +.\" $Id: ppp.8,v 1.187 1999/08/05 10:32:14 brian Exp $ .Dd 20 September 1995 .nr XX \w'\fC00' .Os FreeBSD @@ -249,6 +249,13 @@ will open a TCP or UDP connection for transporting data rather than using a conventional serial device. UDP connections force .Nm into synchronous mode. +.It Supports PPP over ISDN +If +.Nm +is given a raw B-channel i4b device to open as a link, it's able to talk +to the +.Xr isdnd 8 +daemon to establish an ISDN connection. .It "Supports IETF draft Predictor-1 (rfc 1978) and DEFLATE (rfc 1979) compression." .Nm supports not only VJ-compression but also Predictor-1 and DEFLATE compression. @@ -3531,16 +3538,24 @@ checks for the existence of carrier 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 NULL-modem cables), logs the fact and stops checking +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 .Nm ppp Ns No s inability to detect when the link is dropped. -.Ar Seconds +.Ar seconds specifies the number of seconds that .Nm -should wait after the login script has finished before first checking for -carrier. +should wait after the dial script has finished before deciding if +carrier is available or not. +.Pp +.Nm +will not proceed to the login script until either carrier is detected +or until +.Ar seconds +has elapsed. .Pp If .Ar seconds @@ -3549,12 +3564,21 @@ is followed immediately by an exclaimation mark .Nm will .Em require -carrier. If carrier is not detected at the first check, the link will -be considered disconnected. +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. 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 when the link is not a tty device. +is ignored for all other device types. .It set choked Op Ar timeout This sets the number of seconds that .Nm @@ -3620,8 +3644,14 @@ This sets the device(s) to which .Nm will talk to the given .Dq value . -All serial device names are expected to begin with +.Pp +All ISDN and serial device names are expected to begin with .Pa /dev/ . +ISDN devices are usually called +.Pa i4brbchX +and serial devices are usually called +.Pa cuaaX . +.Pp If .Dq value does not begin with @@ -3629,7 +3659,7 @@ does not begin with it must either begin with an exclamation mark .Pq Dq \&! or be of the format -.Dq host:port . +.Dq host:port Ns Op Ns /proto . .Pp If it begins with an exclamation mark, the rest of the device name is treated as a program name, and that program is executed when the device @@ -4645,6 +4675,7 @@ This socket is used to pass links between different instances of .Xr getty 8 , .Xr inetd 8 , .Xr init 8 , +.Xr isdn 8 , .Xr named 8 , .Xr ping 8 , .Xr pppctl 8 , diff --git a/usr.sbin/ppp/tcp.c b/usr.sbin/ppp/tcp.c index 2277b3c9be26..2f09fdf4f45b 100644 --- a/usr.sbin/ppp/tcp.c +++ b/usr.sbin/ppp/tcp.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: tcp.c,v 1.3 1999/05/24 16:39:15 brian Exp $ + * $Id: tcp.c,v 1.4 1999/06/05 21:35:54 brian Exp $ */ #include <sys/types.h> @@ -44,7 +44,6 @@ #include "defs.h" #include "mbuf.h" #include "log.h" -#include "sync.h" #include "timer.h" #include "lqr.h" #include "hdlc.h" @@ -109,6 +108,7 @@ static struct device tcpdevice = { NULL, NULL, NULL, + NULL, NULL }; diff --git a/usr.sbin/ppp/tty.c b/usr.sbin/ppp/tty.c index 72b3bae79b77..4cf7192995bb 100644 --- a/usr.sbin/ppp/tty.c +++ b/usr.sbin/ppp/tty.c @@ -23,32 +23,20 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: tty.c,v 1.8 1999/05/27 08:42:49 brian Exp $ + * $Id: tty.c,v 1.9 1999/06/05 21:35:57 brian Exp $ */ #include <sys/param.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netdb.h> -#include <netinet/in_systm.h> -#include <netinet/ip.h> #include <sys/un.h> #if defined(__OpenBSD__) || defined(__NetBSD__) #include <sys/ioctl.h> -#include <util.h> -#else -#include <libutil.h> #endif #include <errno.h> #include <fcntl.h> -#include <paths.h> -#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sysexits.h> -#include <sys/wait.h> #include <sys/uio.h> #include <termios.h> #include <unistd.h> @@ -57,8 +45,6 @@ #include "defs.h" #include "mbuf.h" #include "log.h" -#include "id.h" -#include "sync.h" #include "timer.h" #include "lqr.h" #include "hdlc.h" @@ -68,20 +54,10 @@ #include "ccp.h" #include "link.h" #include "async.h" -#include "slcompress.h" -#include "iplist.h" -#include "ipcp.h" -#include "filter.h" #include "descriptor.h" #include "physical.h" #include "mp.h" -#ifndef NORADIUS -#include "radius.h" -#endif #include "chat.h" -#include "command.h" -#include "bundle.h" -#include "prompt.h" #include "auth.h" #include "chap.h" #include "cbcp.h" @@ -95,6 +71,7 @@ struct ttydevice { struct device dev; /* What struct physical knows about */ struct pppTimer Timer; /* CD checks */ int mbits; /* Current DCD status */ + int carrier_seconds; /* seconds before CD is *required* */ struct termios ios; /* To be able to reset from raw mode */ }; @@ -124,9 +101,9 @@ tty_Timeout(void *data) if (p->fd >= 0) { if (ioctl(p->fd, TIOCMGET, &dev->mbits) < 0) { - log_Printf(LogPHASE, "%s: ioctl error (%s)!\n", p->link.name, + /* we must be a pty ? */ + log_Printf(LogDEBUG, "%s: ioctl error (%s)!\n", p->link.name, strerror(errno)); - datalink_Down(p->dl, CLOSE_NORMAL); timer_Stop(&dev->Timer); return; } @@ -136,16 +113,24 @@ tty_Timeout(void *data) if (ombits == -1) { /* First time looking for carrier */ if (Online(dev)) - log_Printf(LogDEBUG, "%s: %s: CD detected\n", p->link.name, p->name.full); - else if (p->cfg.cd.required) { - log_Printf(LogPHASE, "%s: %s: Required CD not detected\n", - p->link.name, p->name.full); - datalink_Down(p->dl, CLOSE_NORMAL); - } else { - log_Printf(LogPHASE, "%s: %s doesn't support CD\n", - p->link.name, p->name.full); + 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.required) + log_Printf(LogPHASE, "%s: %s: Required CD not detected\n", + p->link.name, p->name.full); + else { + log_Printf(LogPHASE, "%s: %s doesn't support CD\n", + p->link.name, p->name.full); + dev->mbits = TIOCM_CD; /* Dodgy null-modem cable ? */ + } timer_Stop(&dev->Timer); - dev->mbits = TIOCM_CD; + /* tty_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->mbits = -1; } } else { change = ombits ^ dev->mbits; @@ -170,52 +155,66 @@ tty_StartTimer(struct physical *p) struct ttydevice *dev = device2tty(p->handler); timer_Stop(&dev->Timer); - dev->Timer.load = SECTICKS * p->cfg.cd.delay; + dev->Timer.load = SECTICKS; dev->Timer.func = tty_Timeout; dev->Timer.name = "tty CD"; dev->Timer.arg = p; log_Printf(LogDEBUG, "%s: Using tty_Timeout [%p]\n", p->link.name, tty_Timeout); - dev->mbits = -1; /* So we know it's the first time */ timer_Start(&dev->Timer); } static int +tty_AwaitCarrier(struct physical *p) +{ + struct ttydevice *dev = device2tty(p->handler); + + if (physical_IsSync(p)) + return CARRIER_OK; + + if (dev->mbits == -1) { + if (dev->Timer.state == TIMER_STOPPED) { + dev->carrier_seconds = 0; + tty_StartTimer(p); + } + return CARRIER_PENDING; /* Not yet ! */ + } + + return Online(dev) || !p->cfg.cd.required ? CARRIER_OK : CARRIER_LOST; +} + +static int tty_Raw(struct physical *p) { struct ttydevice *dev = device2tty(p->handler); struct termios ios; int oldflag; - if (physical_IsSync(p)) - return 1; - - log_Printf(LogDEBUG, "%s: Entering physical_Raw\n", p->link.name); + log_Printf(LogDEBUG, "%s: Entering tty_Raw\n", p->link.name); if (p->type != PHYS_DIRECT && p->fd >= 0 && !Online(dev)) log_Printf(LogDEBUG, "%s: Raw: descriptor = %d, mbits = %x\n", p->link.name, p->fd, dev->mbits); - tcgetattr(p->fd, &ios); - cfmakeraw(&ios); - if (p->cfg.rts_cts) - ios.c_cflag |= CLOCAL | CCTS_OFLOW | CRTS_IFLOW; - else - ios.c_cflag |= CLOCAL; + if (!physical_IsSync(p)) { + tcgetattr(p->fd, &ios); + cfmakeraw(&ios); + if (p->cfg.rts_cts) + ios.c_cflag |= CLOCAL | CCTS_OFLOW | CRTS_IFLOW; + else + ios.c_cflag |= CLOCAL; - if (p->type != PHYS_DEDICATED) - ios.c_cflag |= HUPCL; + if (p->type != PHYS_DEDICATED) + ios.c_cflag |= HUPCL; - tcsetattr(p->fd, TCSANOW, &ios); + tcsetattr(p->fd, TCSANOW, &ios); + } oldflag = fcntl(p->fd, F_GETFL, 0); if (oldflag < 0) return 0; fcntl(p->fd, F_SETFL, oldflag | O_NONBLOCK); - if (ioctl(p->fd, TIOCMGET, &dev->mbits) == 0) - tty_StartTimer(p); - return 1; } @@ -226,7 +225,7 @@ tty_Offline(struct physical *p) if (p->fd >= 0) { timer_Stop(&dev->Timer); - dev->mbits &= ~TIOCM_DTR; + dev->mbits &= ~TIOCM_DTR; /* XXX: Hmm, what's this supposed to do ? */ if (Online(dev)) { struct termios tio; @@ -249,12 +248,12 @@ tty_Cooked(struct physical *p) tty_Offline(p); /* In case of emergency close()s */ tcflush(p->fd, TCIOFLUSH); - if (!physical_IsSync(p)) { + + if (!physical_IsSync(p)) tcsetattr(p->fd, TCSAFLUSH, &dev->ios); - oldflag = fcntl(p->fd, F_GETFL, 0); - if (oldflag == 0) - fcntl(p->fd, F_SETFL, oldflag & ~O_NONBLOCK); - } + + if ((oldflag = fcntl(p->fd, F_GETFL, 0)) != -1) + fcntl(p->fd, F_SETFL, oldflag & ~O_NONBLOCK); } static void @@ -296,6 +295,7 @@ tty_OpenInfo(struct physical *p) else strcpy(buf, "no"); strcat(buf, " carrier"); + return buf; } @@ -323,6 +323,7 @@ tty_device2iov(struct device *d, struct iovec *iov, int *niov, static struct device basettydevice = { TTY_DEVICE, "tty", + tty_AwaitCarrier, tty_Raw, tty_Offline, tty_Cooked, @@ -393,6 +394,7 @@ tty_Create(struct physical *p) memcpy(&dev->dev, &basettydevice, sizeof dev->dev); memset(&dev->Timer, '\0', sizeof dev->Timer); + dev->mbits = -1; tcgetattr(p->fd, &ios); dev->ios = ios; @@ -424,22 +426,6 @@ tty_Create(struct physical *p) "cflag = %lx\n", p->link.name, (u_long)ios.c_iflag, (u_long)ios.c_oflag, (u_long)ios.c_cflag); - if (ioctl(p->fd, TIOCMGET, &dev->mbits) == -1) { - if (p->type != PHYS_DIRECT) { - /* Complete failure - parent doesn't continue trying to ``create'' */ - - log_Printf(LogWARN, "%s: Open: Cannot get physical status: %s\n", - p->link.name, strerror(errno)); - tty_Cooked(p); - close(p->fd); - p->fd = -1; - return NULL; - } else - dev->mbits = TIOCM_CD; - } - log_Printf(LogDEBUG, "%s: Open: physical control = %o\n", - p->link.name, dev->mbits); - oldflag = fcntl(p->fd, F_GETFL, 0); if (oldflag < 0) { /* Complete failure - parent doesn't continue trying to ``create'' */ @@ -449,6 +435,7 @@ tty_Create(struct physical *p) tty_Cooked(p); close(p->fd); p->fd = -1; + free(dev); return NULL; } else fcntl(p->fd, F_SETFL, oldflag & ~O_NONBLOCK); diff --git a/usr.sbin/ppp/tun.c b/usr.sbin/ppp/tun.c index b5a8b96ec735..d35490fa0752 100644 --- a/usr.sbin/ppp/tun.c +++ b/usr.sbin/ppp/tun.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: tun.c,v 1.14 1999/05/08 11:07:53 brian Exp $ + * $Id: tun.c,v 1.15 1999/08/05 10:32:16 brian Exp $ */ #include <sys/param.h> @@ -40,7 +40,9 @@ #include <errno.h> #include <string.h> +#if defined(__OpenBSD__) || defined(__NetBSD__) #include <sys/ioctl.h> +#endif #include <termios.h> #ifdef __NetBSD__ #include <stdio.h> diff --git a/usr.sbin/ppp/udp.c b/usr.sbin/ppp/udp.c index e9a4a4aee37e..33a2569dcd0b 100644 --- a/usr.sbin/ppp/udp.c +++ b/usr.sbin/ppp/udp.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: udp.c,v 1.2 1999/05/24 16:39:17 brian Exp $ + * $Id: udp.c,v 1.3 1999/06/05 21:35:59 brian Exp $ */ #include <sys/types.h> @@ -45,7 +45,6 @@ #include "defs.h" #include "mbuf.h" #include "log.h" -#include "sync.h" #include "timer.h" #include "lqr.h" #include "hdlc.h" @@ -137,6 +136,7 @@ static const struct device baseudpdevice = { NULL, NULL, NULL, + NULL, udp_Free, udp_Recvfrom, udp_Sendto, diff --git a/usr.sbin/ppp/vjcomp.c b/usr.sbin/ppp/vjcomp.c index a9783cefacf5..dfcbe40f7d1f 100644 --- a/usr.sbin/ppp/vjcomp.c +++ b/usr.sbin/ppp/vjcomp.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: vjcomp.c,v 1.30 1999/05/12 09:49:12 brian Exp $ + * $Id: vjcomp.c,v 1.31 1999/06/02 15:59:09 brian Exp $ * * TODO: */ @@ -28,7 +28,7 @@ #include <sys/un.h> #include <stdio.h> -#include <string.h> +#include <string.h> /* strlen/memcpy */ #include <termios.h> #include "layer.h" |