]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/at_proto.c
9ae6b7507e69db5ff06e3d94a173641ab70a95aa
[apple/xnu.git] / bsd / netat / at_proto.c
1 /*
2 * Copyright (c) 2006 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 void atalk_dominit();
83
84 /*
85 * Dummy usrreqs struct created by Ted for FreeBSD 3.x integration.
86 * Fill in supported functions as appropriate.
87 */
88 struct pr_usrreqs ddp_usrreqs = {
89 ddp_pru_abort, pru_accept_notsupp, ddp_pru_attach, ddp_pru_bind,
90 ddp_pru_connect, pru_connect2_notsupp, ddp_pru_control, ddp_pru_detach,
91 ddp_pru_disconnect, pru_listen_notsupp, ddp_pru_peeraddr, pru_rcvd_notsupp,
92 pru_rcvoob_notsupp, ddp_pru_send, pru_sense_null, ddp_pru_shutdown,
93 ddp_pru_sockaddr, sosend, soreceive, pru_sopoll_notsupp
94 };
95
96 struct domain atalkdomain;
97 struct protosw atalksw[] = {
98 { SOCK_RAW, &atalkdomain, /*protocol*/ 0, PR_ATOMIC|PR_ADDR,
99 /*input*/ 0, /*output*/ 0, /*clinput*/ 0, ddp_ctloutput,
100 /*ousrreq*/ 0,
101 ddp_init, /*fastto*/ 0, /*slowto*/ 0, /*drain*/ 0,
102 /*sysctl*/ 0, &ddp_usrreqs,
103 0, 0, 0
104 }
105 };
106
107 struct domain atalkdomain =
108 { AF_APPLETALK, "appletalk", atalk_dominit, 0, 0,
109 atalksw, 0,
110 0, 0, 0,
111 DDP_X_HDR_SIZE, 0
112 };
113
114 struct domain * atalkdom = &atalkdomain;
115 lck_mtx_t *atalk_mutex = NULL;
116
117 SYSCTL_NODE(_net, PF_APPLETALK, appletalk, CTLFLAG_RW, 0, "AppleTalk Family");
118
119 void
120 atalk_dominit()
121 {
122 atalk_mutex = atalkdom->dom_mtx;
123 }
124
125 void
126 atalk_lock()
127 {
128 int error = 0, lr, lr_saved;
129 #ifdef __ppc__
130 __asm__ volatile("mflr %0" : "=r" (lr));
131 lr_saved = lr;
132 #endif
133 lck_mtx_assert(atalkdom->dom_mtx, LCK_MTX_ASSERT_NOTOWNED);
134 lck_mtx_lock(atalkdom->dom_mtx);
135 }
136
137 void
138 atalk_unlock()
139 {
140 int error = 0, lr, lr_saved;
141 #ifdef __ppc__
142 __asm__ volatile("mflr %0" : "=r" (lr));
143 lr_saved = lr;
144 #endif
145 lck_mtx_assert(atalkdom->dom_mtx, LCK_MTX_ASSERT_OWNED);
146 lck_mtx_unlock(atalkdom->dom_mtx);
147
148 }
149
150
151
152
153