diff options
author | brian <brian@cvs.openbsd.org> | 2000-09-14 22:02:51 +0000 |
---|---|---|
committer | brian <brian@cvs.openbsd.org> | 2000-09-14 22:02:51 +0000 |
commit | 033d1f63887f1e7a84d279e5939fa74662de3b2c (patch) | |
tree | bfe3c57ae8da718dd467cb50e7ef4a085c97d4eb | |
parent | aa39b29eabb6e830a1079ff469808cc068e346d0 (diff) |
Support PPPoATM, disabled for now as /usr/include/netnatm doesn't exist
Submitted by: Jakob Stoklund Olesen <stoklund@taxidriver.dk>
-rw-r--r-- | usr.sbin/ppp/ppp/Makefile | 9 | ||||
-rw-r--r-- | usr.sbin/ppp/ppp/atm.c | 232 | ||||
-rw-r--r-- | usr.sbin/ppp/ppp/atm.h | 35 | ||||
-rw-r--r-- | usr.sbin/ppp/ppp/physical.c | 10 | ||||
-rw-r--r-- | usr.sbin/ppp/ppp/physical.h | 3 |
5 files changed, 285 insertions, 4 deletions
diff --git a/usr.sbin/ppp/ppp/Makefile b/usr.sbin/ppp/ppp/Makefile index f851d7bea36..55dbcc3fdbb 100644 --- a/usr.sbin/ppp/ppp/Makefile +++ b/usr.sbin/ppp/ppp/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.17 2000/08/18 00:06:25 brian Exp $ +# $OpenBSD: Makefile,v 1.18 2000/09/14 22:02:49 brian Exp $ PROG= ppp SRCS= alias.c alias_cuseeme.c alias_db.c alias_ftp.c alias_irc.c \ @@ -22,6 +22,13 @@ BINOWN= root BINGRP= network MAN= ppp.8 +NOATM= /usr/include/netnatm required +.if defined(NOATM) +CFLAGS+=-DNOATM +.else +SRCS+= atm.c +.endif + .if defined(NOSUID) || defined(PPP_NOSUID) CFLAGS+=-DNOSUID .else diff --git a/usr.sbin/ppp/ppp/atm.c b/usr.sbin/ppp/ppp/atm.c new file mode 100644 index 00000000000..196dbb675b2 --- /dev/null +++ b/usr.sbin/ppp/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. + * + * $OpenBSD: atm.c,v 1.1 2000/09/14 22:02:50 brian Exp $ + */ + +#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/ppp/atm.h b/usr.sbin/ppp/ppp/atm.h new file mode 100644 index 00000000000..0621ee56073 --- /dev/null +++ b/usr.sbin/ppp/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. + * + * $OpenBSD: atm.h,v 1.1 2000/09/14 22:02:50 brian Exp $ + */ + +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/ppp/physical.c b/usr.sbin/ppp/ppp/physical.c index a590641d822..edfb231297a 100644 --- a/usr.sbin/ppp/ppp/physical.c +++ b/usr.sbin/ppp/ppp/physical.c @@ -16,7 +16,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $OpenBSD: physical.c,v 1.25 2000/08/18 00:02:11 brian Exp $ + * $OpenBSD: physical.c,v 1.26 2000/09/14 22:02:50 brian Exp $ * */ @@ -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/ppp/physical.h b/usr.sbin/ppp/ppp/physical.h index e4642bacf92..4816093b5a4 100644 --- a/usr.sbin/ppp/ppp/physical.h +++ b/usr.sbin/ppp/ppp/physical.h @@ -16,7 +16,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $OpenBSD: physical.h,v 1.16 2000/02/27 01:38:27 brian Exp $ + * $OpenBSD: physical.h,v 1.17 2000/09/14 22:02:50 brian Exp $ * */ @@ -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 |