diff options
author | brian <brian@FreeBSD.org> | 2000-09-14 22:02:54 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 2000-09-14 22:02:54 +0000 |
commit | 54bef4135c4762d88857503b7c16ba80db3a44c5 (patch) | |
tree | 212a2a7c0be379a39011d29bfb9d5eef0977bf6e /usr.sbin | |
parent | 066132400fc6fa22008b2e4fb25387e3bf8bc7ff (diff) | |
download | FreeBSD-src-54bef4135c4762d88857503b7c16ba80db3a44c5.zip FreeBSD-src-54bef4135c4762d88857503b7c16ba80db3a44c5.tar.gz |
Support PPPoATM, disabled for now as /usr/include/netnatm doesn't exist
Submitted by: Jakob Stoklund Olesen <stoklund@taxidriver.dk>
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ppp/Makefile | 7 | ||||
-rw-r--r-- | usr.sbin/ppp/atm.c | 232 | ||||
-rw-r--r-- | usr.sbin/ppp/atm.h | 35 | ||||
-rw-r--r-- | usr.sbin/ppp/physical.c | 8 | ||||
-rw-r--r-- | usr.sbin/ppp/physical.h | 1 |
5 files changed, 282 insertions, 1 deletions
diff --git a/usr.sbin/ppp/Makefile b/usr.sbin/ppp/Makefile index 2dc6da0..c79621a 100644 --- a/usr.sbin/ppp/Makefile +++ b/usr.sbin/ppp/Makefile @@ -41,6 +41,13 @@ DPADD+= ${LIBALIAS} .endif .endif +NOATM= /usr/include/netnatm required +.if defined(NOATM) || defined(RELEASE_CRUNCH) +CFLAGS+=-DNOATM +.else +SRCS+= atm.c +.endif + .if defined(NOSUID) || defined(PPP_NOSUID) CFLAGS+=-DNOSUID .else diff --git a/usr.sbin/ppp/atm.c b/usr.sbin/ppp/atm.c new file mode 100644 index 0000000..2b77dd5 --- /dev/null +++ b/usr.sbin/ppp/atm.c @@ -0,0 +1,232 @@ +/*- + * Copyright (c) 2000 Jakob Stoklund Olesen <stoklund@taxidriver.dk> + * 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. + * + * $FreeBSD$ + */ + +#include <sys/types.h> +#include <sys/socket.h> +#include <net/if.h> +#include <netnatm/natm.h> + +#include <errno.h> +#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 "main.h" +#include "atm.h" + +/* String identifying PPPoA */ +#define PPPOA "PPPoA" +#define PPPOA_LEN (sizeof(PPPOA)-1) + +struct atmdevice { + struct device dev; /* What struct physical knows about */ +}; + +#define device2atm(d) ((d)->type == ATM_DEVICE ? (struct atmdevice *)d : NULL) + +int +atm_DeviceSize(void) +{ + return sizeof(struct atmdevice); +} + +static ssize_t +atm_Sendto(struct physical *p, const void *v, size_t n) +{ + ssize_t ret = write(p->fd, v, n); + if (ret<0) { + log_Printf(LogDEBUG, "atm_Sendto(%d): %s\n", n, strerror(errno)); + return ret; + } + return ret; +} + +static ssize_t +atm_Recvfrom(struct physical *p, void *v, size_t n) +{ + ssize_t ret = read(p->fd, (char*)v, n); + if (ret<0) { + log_Printf(LogDEBUG, "atm_Recvfrom(%d): %s\n", n, strerror(errno)); + return ret; + } + return ret; +} + +static void +atm_Free(struct physical *p) +{ + struct atmdevice *dev = device2atm(p->handler); + + free(dev); +} + +static void +atm_device2iov(struct device *d, struct iovec *iov, int *niov, + int maxiov, int *auxfd, int *nauxfd) +{ + 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)++; +} + +static const struct device baseatmdevice = { + ATM_DEVICE, + "atm", + { CD_NOTREQUIRED, 0 }, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + atm_Free, + atm_Recvfrom, + atm_Sendto, + atm_device2iov, + NULL, + NULL +}; + +struct device * +atm_iov2device(int type, struct physical *p, struct iovec *iov, int *niov, + int maxiov, int *auxfd, int *nauxfd) +{ + if (type == ATM_DEVICE) { + struct atmdevice *dev = (struct atmdevice *)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, &baseatmdevice, sizeof dev->dev); + + physical_SetupStack(p, dev->dev.name, PHYSICAL_FORCE_SYNCNOACF); + return &dev->dev; + } + + return NULL; +} + +static struct atmdevice * +atm_CreateDevice(struct physical *p, const char *iface, unsigned vpi, unsigned vci) +{ + struct atmdevice *dev; + struct sockaddr_natm sock; + + if ((dev = calloc (1, sizeof *dev)) == NULL) { + log_Printf(LogWARN, "%s: Cannot allocate an atm device: %s\n", + p->link.name, strerror(errno)); + return NULL; + } + + sock.snatm_len = sizeof sock; + sock.snatm_family = AF_NATM; + strncpy (sock.snatm_if, iface, IFNAMSIZ); + sock.snatm_vpi = vpi; + sock.snatm_vci = vci; + + log_Printf(LogPHASE, "%s: Connecting to %s:%u.%u\n", p->link.name, + iface, vpi, vci); + + p->fd = socket(PF_NATM, SOCK_DGRAM, PROTO_NATMAAL5); + if (p->fd >= 0) { + log_Printf(LogDEBUG, "%s: Opened atm socket %s\n", p->link.name, + p->name.full); + if (connect(p->fd, (struct sockaddr *)&sock, sizeof sock) == 0) + return dev; + else + log_Printf(LogWARN, "%s: connect: %s\n", p->name.full, strerror(errno)); + } else + log_Printf(LogWARN, "%s: socket: %s\n", p->name.full, strerror(errno)); + + close(p->fd); + p->fd = -1; + free(dev); + + return NULL; +} + +struct device * +atm_Create(struct physical *p) +{ + struct atmdevice *dev; + + dev = NULL; + if (p->fd < 0 && !strncasecmp (p->name.full, PPPOA, PPPOA_LEN) + && p->name.full[PPPOA_LEN] == ':') { + char iface[25]; + unsigned vci, vpi; + + if (sscanf (p->name.full + PPPOA_LEN + 1, "%25[A-Za-z0-9]:%u.%u", iface, + &vpi, &vci) != 3) { + log_Printf (LogWARN, "Malformed ATM device name \'%s\', PPPoA:if:vpi.vci expected\n", p->name.full); + return NULL; + } + + dev = atm_CreateDevice(p, iface, vpi, vci); + } + + if (dev) { + memcpy(&dev->dev, &baseatmdevice, sizeof dev->dev); + physical_SetupStack(p, dev->dev.name, PHYSICAL_FORCE_SYNCNOACF); + if (p->cfg.cd.necessity != CD_DEFAULT) + log_Printf(LogWARN, "Carrier settings ignored\n"); + return &dev->dev; + } + + return NULL; +} diff --git a/usr.sbin/ppp/atm.h b/usr.sbin/ppp/atm.h new file mode 100644 index 0000000..3fbc0c5 --- /dev/null +++ b/usr.sbin/ppp/atm.h @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2000 Jakob Stoklund Olesen <stoklund@taxidriver.dk> + * 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. + * + * $FreeBSD$ + */ + +struct physical; +struct device; + +extern struct device *atm_Create(struct physical *); +extern struct device *atm_iov2device(int, struct physical *, + struct iovec *, int *, int, int *, int *); +extern int atm_DeviceSize(void); diff --git a/usr.sbin/ppp/physical.c b/usr.sbin/ppp/physical.c index 30fed48..e605131 100644 --- a/usr.sbin/ppp/physical.c +++ b/usr.sbin/ppp/physical.c @@ -96,7 +96,9 @@ #ifndef NONETGRAPH #include "ether.h" #endif - +#ifndef NOATM +#include "atm.h" +#endif #define PPPOTCPLINE "ppp" @@ -123,6 +125,10 @@ struct { /* This must come before ``udp'' & ``tcp'' */ { ether_Create, ether_iov2device, ether_DeviceSize }, #endif +#ifndef NOATM + /* and so must this */ + { atm_Create, atm_iov2device, atm_DeviceSize }, +#endif { tcp_Create, tcp_iov2device, tcp_DeviceSize }, { udp_Create, udp_iov2device, udp_DeviceSize }, { exec_Create, exec_iov2device, exec_DeviceSize } diff --git a/usr.sbin/ppp/physical.h b/usr.sbin/ppp/physical.h index 74ce890..90b8e7f 100644 --- a/usr.sbin/ppp/physical.h +++ b/usr.sbin/ppp/physical.h @@ -35,6 +35,7 @@ struct cmdargs; #define UDP_DEVICE 4 #define ETHER_DEVICE 5 #define EXEC_DEVICE 6 +#define ATM_DEVICE 7 /* Returns from awaitcarrier() */ #define CARRIER_PENDING 1 |