diff options
author | brian <brian@FreeBSD.org> | 1999-11-06 22:50:59 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1999-11-06 22:50:59 +0000 |
commit | cac81ba45e2e673e229f5ea7773bab9d5a35b735 (patch) | |
tree | 05464cda97fbc141305fb350e1211787d0b945dc /usr.sbin/ppp/physical.c | |
parent | 5e8870e5439ac382bd1d3732b119bf5cf81405b6 (diff) | |
download | FreeBSD-src-cac81ba45e2e673e229f5ea7773bab9d5a35b735.zip FreeBSD-src-cac81ba45e2e673e229f5ea7773bab9d5a35b735.tar.gz |
Support PPPoE
Help (lots) from: julian, archie
Facilities from: ahebert@pubnix.net
Diffstat (limited to 'usr.sbin/ppp/physical.c')
-rw-r--r-- | usr.sbin/ppp/physical.c | 102 |
1 files changed, 58 insertions, 44 deletions
diff --git a/usr.sbin/ppp/physical.c b/usr.sbin/ppp/physical.c index fee584a..97124e0 100644 --- a/usr.sbin/ppp/physical.c +++ b/usr.sbin/ppp/physical.c @@ -90,14 +90,15 @@ #ifndef NOI4B #include "i4b.h" #endif +#ifndef NONETGRAPH +#include "ether.h" +#endif #define PPPOTCPLINE "ppp" static int physical_DescriptorWrite(struct descriptor *, struct bundle *, const fd_set *); -static void physical_DescriptorRead(struct descriptor *, struct bundle *, - const fd_set *); static int physical_DeviceSize(void) @@ -107,14 +108,18 @@ physical_DeviceSize(void) struct { struct device *(*create)(struct physical *); - struct device *(*iov2device)(int, struct physical *, struct iovec *iov, - int *niov, int maxiov); + struct device *(*iov2device)(int, struct physical *, struct iovec *, + int *, int, int *, int *); int (*DeviceSize)(void); } devices[] = { #ifndef NOI4B { i4b_Create, i4b_iov2device, i4b_DeviceSize }, #endif { tty_Create, tty_iov2device, tty_DeviceSize }, +#ifndef NONETGRAPH + /* This must come before ``udp'' & ``tcp'' */ + { ether_Create, ether_iov2device, ether_DeviceSize }, +#endif { tcp_Create, tcp_iov2device, tcp_DeviceSize }, { udp_Create, udp_iov2device, udp_DeviceSize }, { exec_Create, exec_iov2device, exec_DeviceSize } @@ -129,6 +134,16 @@ physical_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, return physical_doUpdateSet(d, r, w, e, n, 0); } +void +physical_SetDescriptor(struct physical *p) +{ + p->desc.type = PHYSICAL_DESCRIPTOR; + p->desc.UpdateSet = physical_UpdateSet; + p->desc.IsSet = physical_IsSet; + p->desc.Read = physical_DescriptorRead; + p->desc.Write = physical_DescriptorWrite; +} + struct physical * physical_Create(struct datalink *dl, int type) { @@ -151,11 +166,7 @@ physical_Create(struct datalink *dl, int type) link_EmptyStack(&p->link); p->handler = NULL; - p->desc.type = PHYSICAL_DESCRIPTOR; - p->desc.UpdateSet = physical_UpdateSet; - p->desc.IsSet = physical_IsSet; - p->desc.Read = physical_DescriptorRead; - p->desc.Write = physical_DescriptorWrite; + physical_SetDescriptor(p); p->type = type; hdlc_Init(&p->hdlc, &p->link.lcp); @@ -480,7 +491,7 @@ physical_ShowStatus(struct cmdargs const *arg) return 0; } -static void +void physical_DescriptorRead(struct descriptor *d, struct bundle *bundle, const fd_set *fdset) { @@ -535,7 +546,7 @@ physical_DescriptorRead(struct descriptor *d, struct bundle *bundle, struct physical * iov2physical(struct datalink *dl, struct iovec *iov, int *niov, int maxiov, - int fd) + int fd, int *auxfd, int *nauxfd) { struct physical *p; int len, h, type; @@ -585,11 +596,10 @@ iov2physical(struct datalink *dl, struct iovec *iov, int *niov, int maxiov, type = (long)p->handler; p->handler = NULL; for (h = 0; h < NDEVICES && p->handler == NULL; h++) - p->handler = (*devices[h].iov2device)(type, p, iov, niov, maxiov); - + p->handler = (*devices[h].iov2device)(type, p, iov, niov, maxiov, + auxfd, nauxfd); if (p->handler == NULL) { - log_Printf(LogPHASE, "%s: Device %s, unknown link type\n", - p->link.name, p->name.full); + log_Printf(LogPHASE, "%s: Unknown link type\n", p->link.name); free(iov[(*niov)++].iov_base); physical_SetupStack(p, "unknown", PHYSICAL_NOFORCE); } else @@ -624,7 +634,7 @@ physical_MaxDeviceSize() int physical2iov(struct physical *p, struct iovec *iov, int *niov, int maxiov, - pid_t newpid) + int *auxfd, int *nauxfd, pid_t newpid) { struct device *h; int sz; @@ -674,7 +684,7 @@ physical2iov(struct physical *p, struct iovec *iov, int *niov, int maxiov, sz = physical_MaxDeviceSize(); if (p) { if (h) - (*h->device2iov)(h, iov, niov, maxiov, newpid); + (*h->device2iov)(h, iov, niov, maxiov, auxfd, nauxfd, newpid); else { iov[*niov].iov_base = malloc(sz); if (p->handler) @@ -801,28 +811,32 @@ physical_doUpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, int physical_RemoveFromSet(struct physical *p, fd_set *r, fd_set *w, fd_set *e) { - int sets; + if (p->handler && p->handler->removefromset) + return (*p->handler->removefromset)(p, r, w, e); + else { + int sets; - sets = 0; - if (p->fd >= 0) { - if (r && FD_ISSET(p->fd, r)) { - FD_CLR(p->fd, r); - log_Printf(LogTIMER, "%s: fdunset(r) %d\n", p->link.name, p->fd); - sets++; - } - if (e && FD_ISSET(p->fd, e)) { - FD_CLR(p->fd, e); - log_Printf(LogTIMER, "%s: fdunset(e) %d\n", p->link.name, p->fd); - sets++; - } - if (w && FD_ISSET(p->fd, w)) { - FD_CLR(p->fd, w); - log_Printf(LogTIMER, "%s: fdunset(w) %d\n", p->link.name, p->fd); - sets++; + sets = 0; + if (p->fd >= 0) { + if (r && FD_ISSET(p->fd, r)) { + FD_CLR(p->fd, r); + log_Printf(LogTIMER, "%s: fdunset(r) %d\n", p->link.name, p->fd); + sets++; + } + if (e && FD_ISSET(p->fd, e)) { + FD_CLR(p->fd, e); + log_Printf(LogTIMER, "%s: fdunset(e) %d\n", p->link.name, p->fd); + sets++; + } + if (w && FD_ISSET(p->fd, w)) { + FD_CLR(p->fd, w); + log_Printf(LogTIMER, "%s: fdunset(w) %d\n", p->link.name, p->fd); + sets++; + } } + + return sets; } - - return sets; } int @@ -929,7 +943,7 @@ physical_Found(struct physical *p) int physical_Open(struct physical *p, struct bundle *bundle) { - int devno, h, wasopen, err; + int devno, h, wasfd, err; char *dev; if (p->fd >= 0) @@ -939,7 +953,7 @@ physical_Open(struct physical *p, struct bundle *bundle) physical_SetDevice(p, ""); p->fd = STDIN_FILENO; for (h = 0; h < NDEVICES && p->handler == NULL && p->fd >= 0; h++) - p->handler = (*devices[h].create)(p); + p->handler = (*devices[h].create)(p); if (p->fd >= 0) { if (p->handler == NULL) { physical_SetupStack(p, "unknown", PHYSICAL_NOFORCE); @@ -961,10 +975,9 @@ physical_Open(struct physical *p, struct bundle *bundle) err = errno; } - wasopen = p->fd >= 0; + wasfd = p->fd; for (h = 0; h < NDEVICES && p->handler == NULL; h++) - if ((p->handler = (*devices[h].create)(p)) == NULL && - wasopen && p->fd == -1) + if ((p->handler = (*devices[h].create)(p)) == NULL && wasfd != p->fd) break; if (p->fd < 0) { @@ -974,7 +987,7 @@ physical_Open(struct physical *p, struct bundle *bundle) strerror(errno)); else log_Printf(LogWARN, "%s: Device (%s) must begin with a '/'," - " a '!' or be a host:port pair\n", p->link.name, + " a '!' or contain at least one ':'\n", p->link.name, p->name.full); } physical_Unlock(p); @@ -993,14 +1006,15 @@ void physical_SetupStack(struct physical *p, const char *who, int how) { link_EmptyStack(&p->link); - if (how == PHYSICAL_FORCE_SYNC || + if (how == PHYSICAL_FORCE_SYNC || how == PHYSICAL_FORCE_SYNCNOACF || (how == PHYSICAL_NOFORCE && physical_IsSync(p))) link_Stack(&p->link, &synclayer); else { link_Stack(&p->link, &asynclayer); link_Stack(&p->link, &hdlclayer); } - link_Stack(&p->link, &acflayer); + if (how != PHYSICAL_FORCE_SYNCNOACF) + link_Stack(&p->link, &acflayer); link_Stack(&p->link, &protolayer); link_Stack(&p->link, &lqrlayer); link_Stack(&p->link, &ccplayer); |