]> git.saurik.com Git - apple/xnu.git/blame - bsd/netat/at_proto.c
xnu-1228.tar.gz
[apple/xnu.git] / bsd / netat / at_proto.c
CommitLineData
1c79356b 1/*
2d21ac55 2 * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
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>
91447636 45#include <kern/locks.h>
1c79356b
A
46
47#include <sys/sysctl.h>
48
49#include <net/if.h>
50
2d21ac55 51#include <netat/sysglue.h>
1c79356b 52#include <netat/appletalk.h>
2d21ac55 53#include <netat/at_pcb.h>
1c79356b
A
54#include <netat/at_var.h>
55#include <netat/ddp.h>
56
1c79356b 57
1c79356b
A
58/*
59 * Dummy usrreqs struct created by Ted for FreeBSD 3.x integration.
60 * Fill in supported functions as appropriate.
61 */
62struct 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,
91447636 67 ddp_pru_sockaddr, sosend, soreceive, pru_sopoll_notsupp
1c79356b
A
68};
69
0c530ab8
A
70extern struct domain atalkdomain;
71extern void atalk_dominit(void);
72
1c79356b
A
73struct 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,
91447636 78 /*sysctl*/ 0, &ddp_usrreqs,
0c530ab8
A
79 0, 0, 0, /*lock, unlock, getlock */
80 {0, 0}, 0, {0} /* filters */
1c79356b
A
81 }
82};
83
84struct domain atalkdomain =
0c530ab8
A
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] */
1c79356b
A
98};
99
91447636
A
100struct domain * atalkdom = &atalkdomain;
101lck_mtx_t *atalk_mutex = NULL;
102
2d21ac55
A
103lck_mtx_t *atalk_cluster_lock = NULL;
104static lck_attr_t *atalk_lock_attr;
105static lck_grp_t *atalk_lock_grp;
106static lck_grp_attr_t *atalk_lock_grp_attr;
107
0c530ab8
A
108static int at_saved_lock, at_saved_unlock;
109
2d21ac55 110SYSCTL_NODE(_net, PF_APPLETALK, appletalk, CTLFLAG_RW|CTLFLAG_LOCKED, 0, "AppleTalk Family");
1c79356b 111
91447636 112void
0c530ab8 113atalk_dominit(void)
91447636
A
114{
115 atalk_mutex = atalkdom->dom_mtx;
2d21ac55
A
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);
91447636
A
122}
123
124void
125atalk_lock()
126{
0c530ab8
A
127 int lr_saved;
128 lr_saved = (unsigned int) __builtin_return_address(0);
129
91447636
A
130 lck_mtx_assert(atalkdom->dom_mtx, LCK_MTX_ASSERT_NOTOWNED);
131 lck_mtx_lock(atalkdom->dom_mtx);
0c530ab8 132 at_saved_lock = lr_saved;
91447636
A
133}
134
135void
136atalk_unlock()
137{
0c530ab8
A
138 int lr_saved;
139 lr_saved = (unsigned int) __builtin_return_address(0);
140
91447636 141 lck_mtx_assert(atalkdom->dom_mtx, LCK_MTX_ASSERT_OWNED);
0c530ab8 142 at_saved_unlock = lr_saved;
91447636
A
143 lck_mtx_unlock(atalkdom->dom_mtx);
144
145}
146
147
148
149
150