diff --git a/usr.sbin/ppp/async.c b/usr.sbin/ppp/async.c index 482baa157a4c..8bf8d187144d 100644 --- a/usr.sbin/ppp/async.c +++ b/usr.sbin/ppp/async.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: async.c,v 1.15.2.4 1998/02/02 19:33:29 brian Exp $ + * $Id: async.c,v 1.15.2.5 1998/02/08 11:04:40 brian Exp $ * */ #include @@ -42,6 +42,7 @@ #include "async.h" #include "throughput.h" #include "link.h" +#include "descriptor.h" #include "physical.h" #define MODE_HUNT 0x01 diff --git a/usr.sbin/ppp/auth.c b/usr.sbin/ppp/auth.c index 0f2793da3943..e60098302f6c 100644 --- a/usr.sbin/ppp/auth.c +++ b/usr.sbin/ppp/auth.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: auth.c,v 1.27.2.5 1998/02/02 19:33:33 brian Exp $ + * $Id: auth.c,v 1.27.2.6 1998/02/07 20:49:18 brian Exp $ * * TODO: * o Implement check against with registered IP addresses. @@ -48,6 +48,7 @@ #include "hdlc.h" #include "async.h" #include "link.h" +#include "descriptor.h" #include "physical.h" #include "lcpproto.h" diff --git a/usr.sbin/ppp/bundle.c b/usr.sbin/ppp/bundle.c index b14230f5a29d..a15c091b5c9b 100644 --- a/usr.sbin/ppp/bundle.c +++ b/usr.sbin/ppp/bundle.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: bundle.c,v 1.1.2.5 1998/02/07 20:49:23 brian Exp $ + * $Id: bundle.c,v 1.1.2.6 1998/02/08 19:29:43 brian Exp $ */ #include @@ -64,6 +64,7 @@ #include "lcp.h" #include "ccp.h" #include "async.h" +#include "descriptor.h" #include "physical.h" #include "modem.h" #include "main.h" diff --git a/usr.sbin/ppp/chap.c b/usr.sbin/ppp/chap.c index 8da76a6d25fc..6ec99a87be86 100644 --- a/usr.sbin/ppp/chap.c +++ b/usr.sbin/ppp/chap.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: chap.c,v 1.28.2.6 1998/02/02 19:33:33 brian Exp $ + * $Id: chap.c,v 1.28.2.7 1998/02/07 20:49:30 brian Exp $ * * TODO: */ @@ -59,6 +59,7 @@ #include "async.h" #include "throughput.h" #include "link.h" +#include "descriptor.h" #include "physical.h" #include "bundle.h" diff --git a/usr.sbin/ppp/chat.c b/usr.sbin/ppp/chat.c index 767b1dcd0b86..d0d096e2d918 100644 --- a/usr.sbin/ppp/chat.c +++ b/usr.sbin/ppp/chat.c @@ -18,7 +18,7 @@ * Columbus, OH 43221 * (614)451-1883 * - * $Id: chat.c,v 1.44.2.3 1998/02/06 02:22:07 brian Exp $ + * $Id: chat.c,v 1.44.2.4 1998/02/06 02:23:30 brian Exp $ * * TODO: * o Support more UUCP compatible control sequences. @@ -55,6 +55,7 @@ #include "lcp.h" #include "link.h" #include "async.h" +#include "descriptor.h" #include "physical.h" #include "chat.h" diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c index 68cf14a764d9..6f0ca63360a5 100644 --- a/usr.sbin/ppp/command.c +++ b/usr.sbin/ppp/command.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: command.c,v 1.131.2.10 1998/02/06 02:24:09 brian Exp $ + * $Id: command.c,v 1.131.2.11 1998/02/07 20:49:32 brian Exp $ * */ #include @@ -75,6 +75,7 @@ #include "auth.h" #include "async.h" #include "link.h" +#include "descriptor.h" #include "physical.h" struct in_addr ifnetmask; diff --git a/usr.sbin/ppp/descriptor.h b/usr.sbin/ppp/descriptor.h new file mode 100644 index 000000000000..37a8fd4d8ca2 --- /dev/null +++ b/usr.sbin/ppp/descriptor.h @@ -0,0 +1,44 @@ +/*- + * Copyright (c) 1998 Brian Somers + * 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$ + */ + +#define PHYSICAL_DESCRIPTOR (1) + +struct descriptor { + int type; + struct descriptor *next; + + int (*UpdateSet)(struct descriptor *, fd_set *, fd_set *, fd_set *, int *); + int (*IsSet)(struct descriptor *, fd_set *); + void (*Read)(struct descriptor *, struct bundle *); + void (*Write)(struct descriptor *); +}; + +#define descriptor_UpdateSet(d, r, w, e, n) ((*(d)->UpdateSet)(d, r, w, e, n)) +#define descriptor_IsSet(d, s) ((*(d)->IsSet)(d, s)) +#define descriptor_Read(d, b) ((*(d)->Read)(d, b)) +#define descriptor_Write(d) ((*(d)->Write)(d)) diff --git a/usr.sbin/ppp/fsm.c b/usr.sbin/ppp/fsm.c index eff97ae79d03..b87bf28314dc 100644 --- a/usr.sbin/ppp/fsm.c +++ b/usr.sbin/ppp/fsm.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: fsm.c,v 1.27.2.7 1998/02/06 02:24:10 brian Exp $ + * $Id: fsm.c,v 1.27.2.8 1998/02/07 20:49:35 brian Exp $ * * TODO: * o Refer loglevel for log output @@ -47,6 +47,7 @@ #include "throughput.h" #include "async.h" #include "link.h" +#include "descriptor.h" #include "physical.h" #include "bundle.h" diff --git a/usr.sbin/ppp/hdlc.c b/usr.sbin/ppp/hdlc.c index 26baf00dc0f2..a26185db2861 100644 --- a/usr.sbin/ppp/hdlc.c +++ b/usr.sbin/ppp/hdlc.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: hdlc.c,v 1.28.2.6 1998/02/02 19:33:35 brian Exp $ + * $Id: hdlc.c,v 1.28.2.7 1998/02/07 20:49:36 brian Exp $ * * TODO: */ @@ -51,6 +51,7 @@ #include "modem.h" #include "ccp.h" #include "link.h" +#include "descriptor.h" #include "physical.h" static struct hdlcstat { @@ -559,3 +560,34 @@ HdlcInput(struct bundle *bundle, struct mbuf * bp, struct physical *physical) DecodePacket(bundle, proto, bp, physical2link(physical)); } + +/* + * Detect a HDLC frame + */ + +static const char *FrameHeaders[] = { + "\176\377\003\300\041", + "\176\377\175\043\300\041", + "\176\177\175\043\100\041", + "\176\175\337\175\043\300\041", + "\176\175\137\175\043\100\041", + NULL, +}; + +u_char * +HdlcDetect(struct physical *physical, u_char *cp, int n) +{ + const char *ptr, *fp, **hp; + + cp[n] = '\0'; /* be sure to null terminated */ + ptr = NULL; + for (hp = FrameHeaders; *hp; hp++) { + fp = *hp; + if (Physical_IsSync(physical)) + fp++; + ptr = strstr((char *) cp, fp); + if (ptr) + break; + } + return (u_char *)ptr; +} diff --git a/usr.sbin/ppp/hdlc.h b/usr.sbin/ppp/hdlc.h index 9eb29175d1ef..89bf74260f83 100644 --- a/usr.sbin/ppp/hdlc.h +++ b/usr.sbin/ppp/hdlc.h @@ -15,7 +15,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: hdlc.h,v 1.14.2.2 1998/01/30 19:45:42 brian Exp $ + * $Id: hdlc.h,v 1.14.2.3 1998/02/02 19:32:07 brian Exp $ * * TODO: */ @@ -68,3 +68,4 @@ extern void HdlcOutput(struct link *, int, u_short, struct mbuf *bp); extern u_short HdlcFcs(u_short, u_char *, int); extern int ReportHdlcStatus(struct cmdargs const *); extern int ReportProtStatus(struct cmdargs const *); +extern u_char *HdlcDetect(struct physical *, u_char *, int); diff --git a/usr.sbin/ppp/ipcp.c b/usr.sbin/ppp/ipcp.c index bbeb0f9da062..f444ae8c1178 100644 --- a/usr.sbin/ppp/ipcp.c +++ b/usr.sbin/ppp/ipcp.c @@ -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.10 1998/02/08 11:04:51 brian Exp $ + * $Id: ipcp.c,v 1.50.2.11 1998/02/08 19:29:44 brian Exp $ * * TODO: * o More RFC1772 backwoard compatibility @@ -62,6 +62,7 @@ #include "hdlc.h" #include "async.h" #include "link.h" +#include "descriptor.h" #include "physical.h" #include "id.h" #include "arp.h" diff --git a/usr.sbin/ppp/lcp.c b/usr.sbin/ppp/lcp.c index 36848ff61ae0..3b06f7423530 100644 --- a/usr.sbin/ppp/lcp.c +++ b/usr.sbin/ppp/lcp.c @@ -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.11 1998/02/07 20:49:44 brian Exp $ + * $Id: lcp.c,v 1.55.2.12 1998/02/08 11:04:54 brian Exp $ * * TODO: * o Limit data field length by MRU @@ -65,6 +65,7 @@ #include "modem.h" #include "tun.h" #include "link.h" +#include "descriptor.h" #include "physical.h" /* for received LQRs */ diff --git a/usr.sbin/ppp/lqr.c b/usr.sbin/ppp/lqr.c index b32f14dbad63..441f9cbbf471 100644 --- a/usr.sbin/ppp/lqr.c +++ b/usr.sbin/ppp/lqr.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: lqr.c,v 1.22.2.5 1998/02/02 19:33:37 brian Exp $ + * $Id: lqr.c,v 1.22.2.6 1998/02/07 20:49:50 brian Exp $ * * o LQR based on RFC1333 * @@ -43,6 +43,7 @@ #include "async.h" #include "throughput.h" #include "link.h" +#include "descriptor.h" #include "physical.h" #include "bundle.h" #include "lqr.h" diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c index 084506b1bb3a..072cf51de87d 100644 --- a/usr.sbin/ppp/main.c +++ b/usr.sbin/ppp/main.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: main.c,v 1.121.2.14 1998/02/08 11:07:31 brian Exp $ + * $Id: main.c,v 1.121.2.15 1998/02/08 19:29:45 brian Exp $ * * TODO: * o Add commands for traffic summary, version display, etc. @@ -76,6 +76,7 @@ #include "tun.h" #include "route.h" #include "link.h" +#include "descriptor.h" #include "physical.h" #ifndef O_NONBLOCK @@ -693,38 +694,6 @@ ReadTty(struct bundle *bundle) } } - -/* - * Here, we'll try to detect HDLC frame - */ - -static const char *FrameHeaders[] = { - "\176\377\003\300\041", - "\176\377\175\043\300\041", - "\176\177\175\043\100\041", - "\176\175\337\175\043\300\041", - "\176\175\137\175\043\100\041", - NULL, -}; - -static const u_char * -HdlcDetect(struct physical *physical, u_char * cp, int n) -{ - const char *ptr, *fp, **hp; - - cp[n] = '\0'; /* be sure to null terminated */ - ptr = NULL; - for (hp = FrameHeaders; *hp; hp++) { - fp = *hp; - if (Physical_IsSync(physical)) - fp++; - ptr = strstr((char *) cp, fp); - if (ptr) - break; - } - return ((const u_char *) ptr); -} - static struct pppTimer RedialTimer; static void @@ -901,16 +870,8 @@ DoLoop(struct bundle *bundle) qlen = link_QueueLen(physical2link(bundle->physical)); } - if (link_IsActive(physical2link(bundle->physical))) { - /* XXX-ML this should probably be abstracted */ - if (Physical_GetFD(bundle->physical) + 1 > nfds) - nfds = Physical_GetFD(bundle->physical) + 1; - Physical_FD_SET(bundle->physical, &rfds); - Physical_FD_SET(bundle->physical, &efds); - if (qlen > 0) { - Physical_FD_SET(bundle->physical, &wfds); - } - } + descriptor_UpdateSet(&bundle->physical->desc, &rfds, &wfds, &efds, &nfds); + if (server >= 0) { if (server + 1 > nfds) nfds = server + 1; @@ -975,7 +936,7 @@ DoLoop(struct bundle *bundle) break; } if ((netfd >= 0 && FD_ISSET(netfd, &efds)) || - (Physical_FD_ISSET(bundle->physical, &efds))) { + descriptor_IsSet(&bundle->physical->desc, &efds)) { LogPrintf(LogALERT, "Exception detected.\n"); break; } @@ -1016,50 +977,21 @@ DoLoop(struct bundle *bundle) IsInteractive(1); Prompt(bundle); } + if (netfd >= 0 && FD_ISSET(netfd, &rfds)) /* something to read from tty */ ReadTty(bundle); - if (Physical_FD_ISSET(bundle->physical, &wfds)) { + + if (descriptor_IsSet(&bundle->physical->desc, &wfds)) { /* ready to write into modem */ - link_StartOutput(physical2link(bundle->physical)); + descriptor_Write(&bundle->physical->desc); if (!link_IsActive(physical2link(bundle->physical))) dial_up = 1; } - if (Physical_FD_ISSET(bundle->physical, &rfds)) { - /* something to read from modem */ - if (LcpInfo.fsm.state <= ST_CLOSED) - nointr_usleep(10000); - n = Physical_Read(bundle->physical, rbuff, sizeof rbuff); - if ((mode & MODE_DIRECT) && n <= 0) { - reconnect(RECON_TRUE); - link_Close(&bundle->physical->link, bundle, 0); - } else - LogDumpBuff(LogASYNC, "ReadFromModem", rbuff, n); - if (LcpInfo.fsm.state <= ST_CLOSED) { - /* - * In dedicated mode, we just discard input until LCP is started. - */ - if (!(mode & MODE_DEDICATED)) { - cp = HdlcDetect(bundle->physical, rbuff, n); - if (cp) { - /* - * LCP packet is detected. Turn ourselves into packet mode. - */ - if (cp != rbuff) { - /* XXX missing return value checks */ - Physical_Write(bundle->physical, rbuff, cp - rbuff); - Physical_Write(bundle->physical, "\r\n", 2); - } - PacketMode(bundle, 0); - } else if (VarTerm) - write(fileno(VarTerm), rbuff, n); - } - } else { - if (n > 0) - async_Input(bundle, rbuff, n, bundle->physical); - } - } + if (descriptor_IsSet(&bundle->physical->desc, &rfds)) + descriptor_Read(&bundle->physical->desc, bundle); + if (bundle->tun_fd >= 0 && FD_ISSET(bundle->tun_fd, &rfds)) { /* something to read from tun */ n = read(bundle->tun_fd, &tun, sizeof tun); diff --git a/usr.sbin/ppp/modem.c b/usr.sbin/ppp/modem.c index 1fbfa47227e2..3413f4ab0b49 100644 --- a/usr.sbin/ppp/modem.c +++ b/usr.sbin/ppp/modem.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: modem.c,v 1.77.2.10 1998/02/07 22:22:45 brian Exp $ + * $Id: modem.c,v 1.77.2.11 1998/02/08 01:31:27 brian Exp $ * * TODO: */ @@ -66,6 +66,7 @@ /* We're defining a physical device, and thus need the real headers. */ #include "link.h" +#include "descriptor.h" #include "physical.h" @@ -79,6 +80,7 @@ static void modem_StartOutput(struct link *); static int modem_IsActive(struct link *); static void modem_Hangup(struct link *, int); static void modem_Destroy(struct link *); +static void modem_DescriptorRead(struct descriptor *, struct bundle *); struct physical * modem_Create(const char *name) @@ -100,6 +102,12 @@ modem_Create(const char *name) p->rts_cts = 1; p->speed = MODEM_SPEED; p->parity = CS8; + p->desc.type = PHYSICAL_DESCRIPTOR; + p->desc.UpdateSet = Physical_UpdateSet; + p->desc.IsSet = Physical_IsSet; + p->desc.Read = modem_DescriptorRead; + p->desc.Write = Physical_DescriptorWrite; + return p; } @@ -977,3 +985,41 @@ int mode; #endif +static void +modem_DescriptorRead(struct descriptor *d, struct bundle *bundle) +{ + struct physical *p = descriptor2physical(d); + u_char rbuff[MAX_MRU], *cp; + int n; + + LogPrintf(LogDEBUG, "descriptor2physical; %p -> %p\n", d, p); + + /* something to read from modem */ + if (LcpInfo.fsm.state <= ST_CLOSED) + nointr_usleep(10000); + + n = Physical_Read(p, rbuff, sizeof rbuff); + if ((mode & MODE_DIRECT) && n <= 0) { + reconnect(RECON_TRUE); + link_Close(&p->link, bundle, 0); + } else + LogDumpBuff(LogASYNC, "ReadFromModem", rbuff, n); + + if (LcpInfo.fsm.state <= ST_CLOSED) { + /* In dedicated mode, we just discard input until LCP is started */ + if (!(mode & MODE_DEDICATED)) { + cp = HdlcDetect(p, rbuff, n); + if (cp) { + /* LCP packet is detected. Turn ourselves into packet mode */ + if (cp != rbuff) { + /* XXX missing return value checks */ + Physical_Write(p, rbuff, cp - rbuff); + Physical_Write(p, "\r\n", 2); + } + PacketMode(bundle, 0); + } else if (VarTerm) + write(fileno(VarTerm), rbuff, n); + } + } else if (n > 0) + async_Input(bundle, rbuff, n, p); +} diff --git a/usr.sbin/ppp/pap.c b/usr.sbin/ppp/pap.c index 79f45938550a..5ce19e004fb5 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.20.2.6 1998/02/02 19:33:39 brian Exp $ + * $Id: pap.c,v 1.20.2.7 1998/02/07 20:50:01 brian Exp $ * * TODO: */ @@ -54,6 +54,7 @@ #include "async.h" #include "throughput.h" #include "link.h" +#include "descriptor.h" #include "physical.h" #include "bundle.h" diff --git a/usr.sbin/ppp/physical.c b/usr.sbin/ppp/physical.c index 4d6fc45ac6f5..9fc9fbdf27ab 100644 --- a/usr.sbin/ppp/physical.c +++ b/usr.sbin/ppp/physical.c @@ -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.4 1998/02/06 02:22:27 brian Exp $ + * $Id: physical.c,v 1.1.2.5 1998/02/06 02:23:47 brian Exp $ * */ @@ -49,10 +49,12 @@ #include "async.h" #include "link.h" +#include "descriptor.h" #include "physical.h" #include "vars.h" #include "bundle.h" +#include "log.h" /* External calls - should possibly be moved inline */ extern int IntToSpeed(int); @@ -174,3 +176,46 @@ Physical_ReportProtocolStatus(struct cmdargs const *arg) link_ReportProtocolStatus(&arg->bundle->physical->link); return 0; } + +int +Physical_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, + int *n) +{ + struct physical *p = descriptor2physical(d); + int sets; + + LogPrintf(LogDEBUG, "descriptor2physical; %p -> %p\n", d, p); + + if (p->fd >= 0) { + if (*n < p->fd + 1) + *n = p->fd + 1; + FD_SET(p->fd, r); + FD_SET(p->fd, e); + if (link_QueueLen(&p->link)) { + FD_SET(p->fd, w); + sets = 3; + } else + sets = 2; + } else + sets = 0; + + return sets; +} + +int +Physical_IsSet(struct descriptor *d, fd_set *fdset) +{ + struct physical *p = descriptor2physical(d); + + LogPrintf(LogDEBUG, "descriptor2physical; %p -> %p\n", d, p); + return p->fd >= 0 && FD_ISSET(p->fd, fdset); +} + +void +Physical_DescriptorWrite(struct descriptor *d) +{ + struct physical *p = descriptor2physical(d); + + LogPrintf(LogDEBUG, "descriptor2physical; %p -> %p\n", d, p); + link_StartOutput(&p->link); +} diff --git a/usr.sbin/ppp/physical.h b/usr.sbin/ppp/physical.h index c98245876d5d..a21e9ddc9edd 100644 --- a/usr.sbin/ppp/physical.h +++ b/usr.sbin/ppp/physical.h @@ -16,12 +16,13 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: physical.h,v 1.1.2.4 1998/02/06 02:22:28 brian Exp $ + * $Id: physical.h,v 1.1.2.5 1998/02/06 02:24:29 brian Exp $ * */ struct physical { struct link link; + struct descriptor desc; struct async async; /* Our async state */ int fd; /* File descriptor for this device */ int mbits; /* Current DCD status */ @@ -44,8 +45,16 @@ struct physical { struct termios ios; /* To be able to reset from raw mode */ }; -#define physical2link(p) ((struct link *)p) -#define link2physical(l) (l->type == PHYSICAL_LINK ? (struct physical *)l : 0) +#define field2phys(fp, name) \ + ((struct physical *)((char *)fp - (int)(&((struct physical *)0)->name))) + +#define physical2link(p) (&(p)->link) +#define link2physical(l) \ + ((l)->type == PHYSICAL_LINK ? field2phys(l, link) : NULL) + +#define physical2descriptor(p) (&(p)->desc) +#define descriptor2physical(d) \ + ((d)->type == PHYSICAL_DESCRIPTOR ? field2phys(d, desc) : NULL) int Physical_GetFD(struct physical *); int Physical_IsATTY(struct physical *); @@ -77,3 +86,6 @@ void Physical_DupAndClose(struct physical *); ssize_t Physical_Read(struct physical *phys, void *buf, size_t nbytes); ssize_t Physical_Write(struct physical *phys, const void *buf, size_t nbytes); int Physical_ReportProtocolStatus(struct cmdargs const *); +int Physical_UpdateSet(struct descriptor *, fd_set *, fd_set *, fd_set *, int *); +int Physical_IsSet(struct descriptor *, fd_set *); +void Physical_DescriptorWrite(struct descriptor *); diff --git a/usr.sbin/ppp/vars.c b/usr.sbin/ppp/vars.c index b06bdc2ef282..be9fc4834e9f 100644 --- a/usr.sbin/ppp/vars.c +++ b/usr.sbin/ppp/vars.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: vars.c,v 1.45.2.3 1998/02/02 19:33:40 brian Exp $ + * $Id: vars.c,v 1.45.2.4 1998/02/06 02:22:52 brian Exp $ * */ #include @@ -41,10 +41,11 @@ #include "async.h" #include "throughput.h" #include "link.h" +#include "descriptor.h" #include "physical.h" char VarVersion[] = "PPP Version 1.90"; -char VarLocalVersion[] = "$Date: 1998/02/02 19:33:40 $"; +char VarLocalVersion[] = "$Date: 1998/02/06 02:22:52 $"; int Utmp = 0; int ipKeepAlive = 0; int reconnectState = RECON_UNKNOWN;