]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/at_proto.c
2849b11677117b6b1580dfb69c397178a67cf480
[apple/xnu.git] / bsd / netat / at_proto.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * Copyright (c) 1998 Apple Computer, Inc.
32 */
33
34 /* at_proto.c
35 */
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/ioctl.h>
40 #include <sys/errno.h>
41 #include <sys/malloc.h>
42 #include <sys/socket.h>
43 #include <sys/socketvar.h>
44 #include <sys/protosw.h>
45 #include <sys/domain.h>
46 #include <sys/mbuf.h>
47 #include <kern/locks.h>
48
49 #include <sys/sysctl.h>
50
51 #include <net/if.h>
52
53 #include <netat/appletalk.h>
54 #include <netat/at_var.h>
55 #include <netat/ddp.h>
56
57
58 extern int ddp_pru_abort(struct socket *so);
59
60 extern int ddp_pru_attach(struct socket *so, int proto,
61 struct proc *p);
62 extern int ddp_pru_bind(struct socket *so, struct sockaddr *nam,
63 struct proc *p);
64 extern int ddp_pru_connect(struct socket *so, struct sockaddr *nam,
65 struct proc *p);
66
67 extern int ddp_pru_control(struct socket *so, u_long cmd, caddr_t data,
68 struct ifnet *ifp, struct proc *p);
69 extern int ddp_pru_detach(struct socket *so);
70 extern int ddp_pru_disconnect(struct socket *so);
71
72 extern int ddp_pru_peeraddr(struct socket *so,
73 struct sockaddr **nam);
74
75 extern int ddp_pru_send(struct socket *so, int flags, struct mbuf *m,
76 struct sockaddr *addr, struct mbuf *control,
77 struct proc *p);
78
79 extern int ddp_pru_shutdown(struct socket *so);
80 extern int ddp_pru_sockaddr(struct socket *so,
81 struct sockaddr **nam);
82
83 /*
84 * Dummy usrreqs struct created by Ted for FreeBSD 3.x integration.
85 * Fill in supported functions as appropriate.
86 */
87 struct pr_usrreqs ddp_usrreqs = {
88 ddp_pru_abort, pru_accept_notsupp, ddp_pru_attach, ddp_pru_bind,
89 ddp_pru_connect, pru_connect2_notsupp, ddp_pru_control, ddp_pru_detach,
90 ddp_pru_disconnect, pru_listen_notsupp, ddp_pru_peeraddr, pru_rcvd_notsupp,
91 pru_rcvoob_notsupp, ddp_pru_send, pru_sense_null, ddp_pru_shutdown,
92 ddp_pru_sockaddr, sosend, soreceive, pru_sopoll_notsupp
93 };
94
95 extern struct domain atalkdomain;
96 extern void atalk_dominit(void);
97
98 struct protosw atalksw[] = {
99 { SOCK_RAW, &atalkdomain, /*protocol*/ 0, PR_ATOMIC|PR_ADDR,
100 /*input*/ 0, /*output*/ 0, /*clinput*/ 0, ddp_ctloutput,
101 /*ousrreq*/ 0,
102 ddp_init, /*fastto*/ 0, /*slowto*/ 0, /*drain*/ 0,
103 /*sysctl*/ 0, &ddp_usrreqs,
104 0, 0, 0, /*lock, unlock, getlock */
105 {0, 0}, 0, {0} /* filters */
106 }
107 };
108
109 struct domain atalkdomain =
110 { AF_APPLETALK,
111 "appletalk",
112 atalk_dominit,
113 0,
114 0,
115 atalksw,
116 0,
117 0, /* dom_rtattach */
118 0, 0, /* dom_rtoffset, dom_maxrtkey */
119 DDP_X_HDR_SIZE, 0,
120 0, /* domain global mutex */
121 0, /* domain flags */
122 {0, 0} /*reserved[2] */
123 };
124
125 struct domain * atalkdom = &atalkdomain;
126 lck_mtx_t *atalk_mutex = NULL;
127
128 static int at_saved_lock, at_saved_unlock;
129
130 SYSCTL_NODE(_net, PF_APPLETALK, appletalk, CTLFLAG_RW, 0, "AppleTalk Family");
131
132 void
133 atalk_dominit(void)
134 {
135 atalk_mutex = atalkdom->dom_mtx;
136 }
137
138 void
139 atalk_lock()
140 {
141 int lr_saved;
142 lr_saved = (unsigned int) __builtin_return_address(0);
143
144 lck_mtx_assert(atalkdom->dom_mtx, LCK_MTX_ASSERT_NOTOWNED);
145 lck_mtx_lock(atalkdom->dom_mtx);
146 at_saved_lock = lr_saved;
147 }
148
149 void
150 atalk_unlock()
151 {
152 int lr_saved;
153 lr_saved = (unsigned int) __builtin_return_address(0);
154
155 lck_mtx_assert(atalkdom->dom_mtx, LCK_MTX_ASSERT_OWNED);
156 at_saved_unlock = lr_saved;
157 lck_mtx_unlock(atalkdom->dom_mtx);
158
159 }
160
161
162
163
164