summaryrefslogtreecommitdiffstats
path: root/sys/netnatm
diff options
context:
space:
mode:
authorkjc <kjc@FreeBSD.org>1997-05-09 07:48:14 +0000
committerkjc <kjc@FreeBSD.org>1997-05-09 07:48:14 +0000
commitc9ad0dc89ade9c422e01625c0484128d2de99a48 (patch)
tree6edcbc8fd96eaffbecad189a12afa0009e3c304f /sys/netnatm
downloadFreeBSD-src-c9ad0dc89ade9c422e01625c0484128d2de99a48.zip
FreeBSD-src-c9ad0dc89ade9c422e01625c0484128d2de99a48.tar.gz
import Chuck Cranor's ATM driver
Diffstat (limited to 'sys/netnatm')
-rw-r--r--sys/netnatm/natm.h161
-rw-r--r--sys/netnatm/natm_pcb.c194
-rw-r--r--sys/netnatm/natm_proto.c131
3 files changed, 486 insertions, 0 deletions
diff --git a/sys/netnatm/natm.h b/sys/netnatm/natm.h
new file mode 100644
index 0000000..2edfd57
--- /dev/null
+++ b/sys/netnatm/natm.h
@@ -0,0 +1,161 @@
+/* $NetBSD: natm.h,v 1.1 1996/07/04 03:20:12 chuck Exp $ */
+
+/*
+ *
+ * Copyright (c) 1996 Charles D. Cranor and Washington University.
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Charles D. Cranor and
+ * Washington University.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
+ */
+
+/*
+ * natm.h: native mode atm
+ */
+
+
+/*
+ * supported protocols
+ */
+
+#define PROTO_NATMAAL0 1
+#define PROTO_NATMAAL5 2
+
+/*
+ * sockaddr_natm
+ */
+
+struct sockaddr_natm {
+ u_int8_t snatm_len; /* length */
+ u_int8_t snatm_family; /* AF_NATM */
+ char snatm_if[IFNAMSIZ]; /* interface name */
+ u_int16_t snatm_vci; /* vci */
+ u_int8_t snatm_vpi; /* vpi */
+};
+
+
+#if defined(__FreeBSD__) && defined(KERNEL)
+
+#ifndef _KERNEL
+#define _KERNEL
+#endif
+
+#define SPLSOFTNET() splnet()
+
+#elif defined(__NetBSD__) || defined(__OpenBSD__)
+
+#define SPLSOFTNET() splsoftnet()
+
+#endif
+
+#ifdef _KERNEL
+
+/*
+ * natm protocol control block
+ */
+
+struct natmpcb {
+ LIST_ENTRY(natmpcb) pcblist; /* list pointers */
+ u_int npcb_inq; /* # of our pkts in proto q */
+ struct socket *npcb_socket; /* backpointer to socket */
+ struct ifnet *npcb_ifp; /* pointer to hardware */
+ struct in_addr ipaddr; /* remote IP address, if APCB_IP */
+ u_int16_t npcb_vci; /* VCI */
+ u_int8_t npcb_vpi; /* VPI */
+ u_int8_t npcb_flags; /* flags */
+};
+
+/* flags */
+#define NPCB_FREE 0x01 /* free (not on any list) */
+#define NPCB_CONNECTED 0x02 /* connected */
+#define NPCB_IP 0x04 /* used by IP */
+#define NPCB_DRAIN 0x08 /* destory as soon as inq == 0 */
+#define NPCB_RAW 0x10 /* in 'raw' mode? */
+
+/* flag arg to npcb_free */
+#define NPCB_REMOVE 0 /* remove from global list */
+#define NPCB_DESTROY 1 /* destroy and be free */
+
+/*
+ * NPCB_RAWCC is a hack which applies to connections in 'raw' mode. it
+ * is used to override the sbspace() macro when you *really* don't want
+ * to drop rcv data. the recv socket buffer size is raised to this value.
+ *
+ * XXX: socket buffering needs to be looked at.
+ */
+
+#define NPCB_RAWCC (1024*1024) /* 1MB */
+
+LIST_HEAD(npcblist, natmpcb);
+
+/* global data structures */
+
+struct npcblist natm_pcbs; /* global list of pcbs */
+extern struct ifqueue natmintrq; /* natm packet input queue */
+#define NATM_STAT
+#ifdef NATM_STAT
+extern u_int natm_sodropcnt,
+ natm_sodropbytes; /* account of droppage */
+extern u_int natm_sookcnt,
+ natm_sookbytes; /* account of ok */
+#endif
+
+/* atm_rawioctl: kernel's version of SIOCRAWATM [for internal use only!] */
+struct atm_rawioctl {
+ struct natmpcb *npcb;
+ int rawvalue;
+};
+#define SIOCXRAWATM _IOWR('a', 125, struct atm_rawioctl)
+
+/* external functions */
+
+/* natm_pcb.c */
+struct natmpcb *npcb_alloc __P((int));
+void npcb_free __P((struct natmpcb *, int));
+struct natmpcb *npcb_add __P((struct natmpcb *, struct ifnet *, int, int));
+
+/* natm.c */
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+int natm_usrreq __P((struct socket *, int, struct mbuf *,
+ struct mbuf *, struct mbuf *, struct proc *));
+#elif defined(__FreeBSD__)
+#if __FreeBSD__ > 2
+/*
+ * FreeBSD new usrreqs style appeared since 2.2. compatibility to old style
+ * has gone since 3.0.
+ */
+#define FREEBSD_USRREQS
+extern struct pr_usrreqs natm_usrreqs;
+#else /* !( __FreeBSD__ > 2) */
+int natm_usrreq __P((struct socket *, int, struct mbuf *,
+ struct mbuf *, struct mbuf *));
+#endif /* !( __FreeBSD__ > 2) */
+#endif
+int natm0_sysctl __P((int *, u_int, void *, size_t *, void *, size_t));
+int natm5_sysctl __P((int *, u_int, void *, size_t *, void *, size_t));
+void natmintr __P((void));
+
+#endif
diff --git a/sys/netnatm/natm_pcb.c b/sys/netnatm/natm_pcb.c
new file mode 100644
index 0000000..198a091
--- /dev/null
+++ b/sys/netnatm/natm_pcb.c
@@ -0,0 +1,194 @@
+/* $NetBSD: natm_pcb.c,v 1.4 1996/11/09 03:26:27 chuck Exp $ */
+
+/*
+ *
+ * Copyright (c) 1996 Charles D. Cranor and Washington University.
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Charles D. Cranor and
+ * Washington University.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
+ */
+
+/*
+ * atm_pcb.c: manage atm protocol control blocks and keep IP and NATM
+ * from trying to use each other's VCs.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/queue.h>
+#include <sys/socket.h>
+#include <sys/protosw.h>
+#include <sys/domain.h>
+#include <sys/mbuf.h>
+#include <sys/malloc.h>
+
+#include <net/if.h>
+#include <net/radix.h>
+#include <net/route.h>
+
+#include <netinet/in.h>
+
+#include <netnatm/natm.h>
+
+/*
+ * npcb_alloc: allocate a npcb [in the free state]
+ */
+
+struct natmpcb *npcb_alloc(wait)
+
+int wait;
+
+{
+ struct natmpcb *npcb;
+
+ MALLOC(npcb, struct natmpcb *, sizeof(*npcb), M_PCB, wait);
+
+#ifdef DIAGNOSTIC
+ if (wait == M_WAITOK && npcb == NULL) panic("npcb_alloc: malloc didn't wait");
+#endif
+
+ if (npcb) {
+ bzero(npcb, sizeof(*npcb));
+ npcb->npcb_flags = NPCB_FREE;
+ }
+ return(npcb);
+}
+
+
+/*
+ * npcb_free: free a npcb
+ */
+
+void npcb_free(npcb, op)
+
+struct natmpcb *npcb;
+int op;
+
+{
+ int s = splimp();
+
+ if ((npcb->npcb_flags & NPCB_FREE) == 0) {
+ LIST_REMOVE(npcb, pcblist);
+ npcb->npcb_flags = NPCB_FREE;
+ }
+ if (op == NPCB_DESTROY) {
+ if (npcb->npcb_inq) {
+ npcb->npcb_flags = NPCB_DRAIN; /* flag for distruction */
+ } else {
+ FREE(npcb, M_PCB); /* kill it! */
+ }
+ }
+
+ splx(s);
+}
+
+
+/*
+ * npcb_add: add or remove npcb from main list
+ * returns npcb if ok
+ */
+
+struct natmpcb *npcb_add(npcb, ifp, vci, vpi)
+
+struct natmpcb *npcb;
+struct ifnet *ifp;
+u_int16_t vci;
+u_int8_t vpi;
+
+{
+ struct natmpcb *cpcb = NULL; /* current pcb */
+ int s = splimp();
+
+
+ /*
+ * lookup required
+ */
+
+ for (cpcb = natm_pcbs.lh_first ; cpcb != NULL ;
+ cpcb = cpcb->pcblist.le_next) {
+ if (ifp == cpcb->npcb_ifp && vci == cpcb->npcb_vci && vpi == cpcb->npcb_vpi)
+ break;
+ }
+
+ /*
+ * add & something already there?
+ */
+
+ if (cpcb) {
+ cpcb = NULL;
+ goto done; /* fail */
+ }
+
+ /*
+ * need to allocate a pcb?
+ */
+
+ if (npcb == NULL) {
+ cpcb = npcb_alloc(M_NOWAIT); /* could be called from lower half */
+ if (cpcb == NULL)
+ goto done; /* fail */
+ } else {
+ cpcb = npcb;
+ }
+
+ cpcb->npcb_ifp = ifp;
+ cpcb->ipaddr.s_addr = 0;
+ cpcb->npcb_vci = vci;
+ cpcb->npcb_vpi = vpi;
+ cpcb->npcb_flags = NPCB_CONNECTED;
+
+ LIST_INSERT_HEAD(&natm_pcbs, cpcb, pcblist);
+
+done:
+ splx(s);
+ return(cpcb);
+}
+
+
+
+#ifdef DDB
+
+int npcb_dump __P((void));
+
+int npcb_dump()
+
+{
+ struct natmpcb *cpcb;
+
+ printf("npcb dump:\n");
+ for (cpcb = natm_pcbs.lh_first ; cpcb != NULL ;
+ cpcb = cpcb->pcblist.le_next) {
+ printf("if=%s, vci=%d, vpi=%d, IP=0x%x, sock=%p, flags=0x%x, inq=%d\n",
+ cpcb->npcb_ifp->if_xname, cpcb->npcb_vci, cpcb->npcb_vpi,
+ cpcb->ipaddr.s_addr, cpcb->npcb_socket,
+ cpcb->npcb_flags, cpcb->npcb_inq);
+ }
+ printf("done\n");
+ return(0);
+}
+
+#endif
diff --git a/sys/netnatm/natm_proto.c b/sys/netnatm/natm_proto.c
new file mode 100644
index 0000000..c0e0499
--- /dev/null
+++ b/sys/netnatm/natm_proto.c
@@ -0,0 +1,131 @@
+/* $NetBSD: natm_proto.c,v 1.3 1996/09/18 00:56:41 chuck Exp $ */
+
+/*
+ *
+ * Copyright (c) 1996 Charles D. Cranor and Washington University.
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Charles D. Cranor and
+ * Washington University.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
+ */
+
+/*
+ * protocol layer for access to native mode ATM
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/queue.h>
+#include <sys/socket.h>
+#include <sys/protosw.h>
+#include <sys/domain.h>
+#include <sys/mbuf.h>
+
+#include <net/if.h>
+#include <net/radix.h>
+#include <net/route.h>
+
+#include <netinet/in.h>
+
+#include <netnatm/natm.h>
+
+extern struct domain natmdomain;
+
+static void natm_init __P((void));
+
+struct protosw natmsw[] = {
+{ SOCK_STREAM, &natmdomain, PROTO_NATMAAL5, PR_CONNREQUIRED,
+ 0, 0, 0, 0,
+#ifdef FREEBSD_USRREQS
+ 0,
+#else
+ natm_usrreq,
+#endif
+ 0, 0, 0, 0,
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+ natm5_sysctl
+#elif defined(FREEBSD_USRREQS)
+ &natm_usrreqs
+#endif
+},
+{ SOCK_DGRAM, &natmdomain, PROTO_NATMAAL5, PR_CONNREQUIRED | PR_ATOMIC,
+ 0, 0, 0, 0,
+#ifdef FREEBSD_USRREQS
+ 0,
+#else
+ natm_usrreq,
+#endif
+ 0, 0, 0, 0,
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+ natm5_sysctl
+#elif defined(FREEBSD_USRREQS)
+ &natm_usrreqs
+#endif
+},
+{ SOCK_STREAM, &natmdomain, PROTO_NATMAAL0, PR_CONNREQUIRED,
+ 0, 0, 0, 0,
+#ifdef FREEBSD_USRREQS
+ 0,
+#else
+ natm_usrreq,
+#endif
+ 0, 0, 0, 0,
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+ natm0_sysctl
+#elif defined(FREEBSD_USRREQS)
+ &natm_usrreqs
+#endif
+},
+};
+
+struct domain natmdomain =
+ { AF_NATM, "natm", natm_init, 0, 0,
+ natmsw, &natmsw[sizeof(natmsw)/sizeof(natmsw[0])], 0,
+ 0, 0, 0};
+
+struct ifqueue natmintrq; /* natm packet input queue */
+int natmqmaxlen = IFQ_MAXLEN; /* max # of packets on queue */
+#ifdef NATM_STAT
+u_int natm_sodropcnt = 0; /* # mbufs dropped due to full sb */
+u_int natm_sodropbytes = 0; /* # of bytes dropped */
+u_int natm_sookcnt = 0; /* # mbufs ok */
+u_int natm_sookbytes = 0; /* # of bytes ok */
+#endif
+
+
+
+void natm_init()
+
+{
+ LIST_INIT(&natm_pcbs);
+ bzero(&natmintrq, sizeof(natmintrq));
+ natmintrq.ifq_maxlen = natmqmaxlen;
+}
+
+#if defined(__FreeBSD__)
+DOMAIN_SET(natm);
+#endif
OpenPOWER on IntegriCloud