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