1/*	$NetBSD: natm_proto.c,v 1.13 2008/04/24 11:38:39 ad Exp $	*/
2
3/*
4 * Copyright (c) 1996 Charles D. Cranor and Washington University.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28/*
29 * protocol layer for access to native mode ATM
30 */
31
32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: natm_proto.c,v 1.13 2008/04/24 11:38:39 ad Exp $");
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/kernel.h>
38#include <sys/queue.h>
39#include <sys/socket.h>
40#include <sys/protosw.h>
41#include <sys/domain.h>
42#include <sys/mbuf.h>
43
44#include <net/if.h>
45#include <net/radix.h>
46#include <net/route.h>
47
48#include <netinet/in.h>
49
50#include <netnatm/natm.h>
51
52DOMAIN_DEFINE(natmdomain);
53
54static void natm_init(void);
55
56struct npcblist natm_pcbs = LIST_HEAD_INITIALIZER(natm_pcbs);
57struct	ifqueue natmintrq;       	/* natm packet input queue */
58int	natmqmaxlen = IFQ_MAXLEN;	/* max # of packets on queue */
59
60PR_WRAP_USRREQ(natm_usrreq)
61
62#define	natm_usrreq	natm_usrreq_wrapper
63
64const struct protosw natmsw[] = {
65{ .pr_type = SOCK_STREAM,
66  .pr_domain = &natmdomain,
67  .pr_protocol = PROTO_NATMAAL5,
68  .pr_flags = PR_CONNREQUIRED,
69  .pr_input = 0,
70  .pr_output = 0,
71  .pr_ctlinput = 0,
72  .pr_ctloutput = 0,
73  .pr_usrreq = natm_usrreq,
74  .pr_init = 0,
75  .pr_fasttimo = 0,
76  .pr_slowtimo = 0,
77  .pr_drain = 0
78},
79{ .pr_type = SOCK_DGRAM,
80  .pr_domain = &natmdomain,
81  .pr_protocol = PROTO_NATMAAL5,
82  .pr_flags = PR_CONNREQUIRED | PR_ATOMIC,
83  .pr_input = 0,
84  .pr_output = 0,
85  .pr_ctlinput = 0,
86  .pr_ctloutput = 0,
87  .pr_usrreq = natm_usrreq,
88  .pr_init = 0,
89  .pr_fasttimo = 0,
90  .pr_slowtimo = 0,
91  .pr_drain = 0
92},
93{ .pr_type = SOCK_STREAM,
94  .pr_domain = &natmdomain,
95  .pr_protocol = PROTO_NATMAAL0,
96  .pr_flags = PR_CONNREQUIRED,
97  .pr_input = 0,
98  .pr_output = 0,
99  .pr_ctlinput = 0,
100  .pr_ctloutput = 0,
101  .pr_usrreq = natm_usrreq,
102  .pr_init = 0,
103  .pr_fasttimo = 0,
104  .pr_slowtimo = 0,
105  .pr_drain = 0
106},
107};
108
109struct domain natmdomain = {
110	.dom_family = PF_NATM,
111	.dom_name = "natm",
112	.dom_init = natm_init,
113	.dom_protosw = natmsw,
114	.dom_protoswNPROTOSW = &natmsw[sizeof(natmsw)/sizeof(natmsw[0])],
115	.dom_ifqueues = { &natmintrq, NULL },
116	.dom_rtcache = LIST_HEAD_INITIALIZER(natmdomain.dom_rtcache)
117};
118#ifdef NATM_STAT
119u_int natm_sodropcnt = 0;		/* # mbufs dropped due to full sb */
120u_int natm_sodropbytes = 0;		/* # of bytes dropped */
121u_int natm_sookcnt = 0;			/* # mbufs ok */
122u_int natm_sookbytes = 0;		/* # of bytes ok */
123#endif
124
125void natm_init(void)
126{
127	natmintrq.ifq_maxlen = natmqmaxlen;
128}
129