natm_proto.c revision 165900
1274955Ssvnmir/*- 2274955Ssvnmir * Copyright (c) 1996 Charles D. Cranor and Washington University. 3353358Sdim * All rights reserved. 4353358Sdim * 5353358Sdim * Redistribution and use in source and binary forms, with or without 6274955Ssvnmir * modification, are permitted provided that the following conditions 7274955Ssvnmir * are met: 8274955Ssvnmir * 1. Redistributions of source code must retain the above copyright 9280031Sdim * notice, this list of conditions and the following disclaimer. 10280031Sdim * 2. Redistributions in binary form must reproduce the above copyright 11274955Ssvnmir * notice, this list of conditions and the following disclaimer in the 12274955Ssvnmir * documentation and/or other materials provided with the distribution. 13274955Ssvnmir * 3. All advertising materials mentioning features or use of this software 14274955Ssvnmir * must display the following acknowledgement: 15274955Ssvnmir * This product includes software developed by Charles D. Cranor and 16274955Ssvnmir * Washington University. 17274955Ssvnmir * 4. The name of the author may not be used to endorse or promote products 18274955Ssvnmir * derived from this software without specific prior written permission. 19274955Ssvnmir * 20274955Ssvnmir * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21274955Ssvnmir * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22274955Ssvnmir * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23274955Ssvnmir * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24274955Ssvnmir * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25274955Ssvnmir * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26274955Ssvnmir * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27274955Ssvnmir * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28274955Ssvnmir * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29274955Ssvnmir * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30274955Ssvnmir * 31274955Ssvnmir * $NetBSD: natm_proto.c,v 1.3 1996/09/18 00:56:41 chuck Exp $ 32274955Ssvnmir */ 33274955Ssvnmir 34274955Ssvnmir/* 35280031Sdim * protocol layer for access to native mode ATM 36274955Ssvnmir */ 37274955Ssvnmir 38274955Ssvnmir#include <sys/cdefs.h> 39274955Ssvnmir__FBSDID("$FreeBSD: head/sys/netnatm/natm_proto.c 165900 2007-01-08 22:30:39Z rwatson $"); 40274955Ssvnmir 41274955Ssvnmir#include <sys/param.h> 42274955Ssvnmir#include <sys/systm.h> 43274955Ssvnmir#include <sys/kernel.h> 44321369Sdim#include <sys/socket.h> 45321369Sdim#include <sys/protosw.h> 46274955Ssvnmir#include <sys/domain.h> 47274955Ssvnmir 48274955Ssvnmir#include <net/if.h> 49274955Ssvnmir#include <net/netisr.h> 50274955Ssvnmir 51274955Ssvnmir#include <netinet/in.h> 52274955Ssvnmir 53274955Ssvnmir#include <netnatm/natm.h> 54 55static void natm_init(void); 56 57static struct domain natmdomain; 58 59static struct protosw natmsw[] = { 60{ 61 .pr_type = SOCK_STREAM, 62 .pr_domain = &natmdomain, 63 .pr_protocol = PROTO_NATMAAL5, 64 .pr_flags = PR_CONNREQUIRED, 65 .pr_usrreqs = &natm_usrreqs 66}, 67{ 68 .pr_type = SOCK_DGRAM, 69 .pr_domain = &natmdomain, 70 .pr_protocol = PROTO_NATMAAL5, 71 .pr_flags = PR_CONNREQUIRED|PR_ATOMIC, 72 .pr_usrreqs = &natm_usrreqs 73}, 74{ 75 .pr_type = SOCK_STREAM, 76 .pr_domain = &natmdomain, 77 .pr_protocol = PROTO_NATMAAL0, 78 .pr_flags = PR_CONNREQUIRED, 79 .pr_usrreqs = &natm_usrreqs 80}, 81}; 82 83static struct domain natmdomain = { 84 .dom_family = AF_NATM, 85 .dom_name = "natm", 86 .dom_init = natm_init, 87 .dom_protosw = natmsw, 88 .dom_protoswNPROTOSW = &natmsw[sizeof(natmsw)/sizeof(natmsw[0])], 89}; 90 91static int natmqmaxlen = 1000 /* IFQ_MAXLEN */; /* max # of packets on queue */ 92static struct ifqueue natmintrq; 93#ifdef NATM_STAT 94u_int natm_sodropcnt; /* # mbufs dropped due to full sb */ 95u_int natm_sodropbytes; /* # of bytes dropped */ 96u_int natm_sookcnt; /* # mbufs ok */ 97u_int natm_sookbytes; /* # of bytes ok */ 98#endif 99 100static void 101natm_init(void) 102{ 103 LIST_INIT(&natm_pcbs); 104 bzero(&natmintrq, sizeof(natmintrq)); 105 natmintrq.ifq_maxlen = natmqmaxlen; 106 NATM_LOCK_INIT(); 107 mtx_init(&natmintrq.ifq_mtx, "natm_inq", NULL, MTX_DEF); 108 netisr_register(NETISR_NATM, natmintr, &natmintrq, NETISR_MPSAFE); 109} 110 111DOMAIN_SET(natm); 112