1 /* $NetBSD: iso_proto.c,v 1.28 2008/04/24 11:38:38 ad Exp $ */
2
3 /*-
4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. 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 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * @(#)iso_proto.c 8.2 (Berkeley) 2/9/95
32 */
33
34 /***********************************************************
35 Copyright IBM Corporation 1987
36
37 All Rights Reserved
38
39 Permission to use, copy, modify, and distribute this software and its
40 documentation for any purpose and without fee is hereby granted,
41 provided that the above copyright notice appear in all copies and that
42 both that copyright notice and this permission notice appear in
43 supporting documentation, and that the name of IBM not be
44 used in advertising or publicity pertaining to distribution of the
45 software without specific, written prior permission.
46
47 IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
48 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
49 IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
50 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
51 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
52 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
53 SOFTWARE.
54
55 ******************************************************************/
56
57 /*
58 * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
59 */
60 /*
61 * iso_proto.c : protocol switch tables in the ISO domain
62 *
63 * ISO protocol family includes TP, CLTP, CLNP, 8208
64 * TP and CLNP are implemented here.
65 */
66
67 #include <sys/cdefs.h>
68 __KERNEL_RCSID(0, "$NetBSD: iso_proto.c,v 1.28 2008/04/24 11:38:38 ad Exp $");
69
70
71 #include <sys/param.h>
72 #include <sys/socket.h>
73 #include <sys/protosw.h>
74 #include <sys/domain.h>
75 #include <sys/mbuf.h>
76
77 #include <net/radix.h>
78
79 #include <netiso/iso.h>
80
81 #include <netiso/clnp.h>
82 #include <netiso/tp_param.h>
83 #include <netiso/tp_var.h>
84 #include <netiso/esis.h>
85 #include <netiso/idrp_var.h>
86 #include <netiso/iso_pcb.h>
87 #include <netiso/cltp_var.h>
88
89 const int isoctlerrmap[PRC_NCMDS] = {
90 0, 0, 0, 0,
91 0, EMSGSIZE, EHOSTDOWN, EHOSTUNREACH,
92 EHOSTUNREACH, EHOSTUNREACH, ECONNREFUSED, ECONNREFUSED,
93 EMSGSIZE, EHOSTUNREACH, 0, 0,
94 0, 0, 0, 0,
95 ENOPROTOOPT
96 };
97
98 DOMAIN_DEFINE(isodomain); /* forward declare and add to link set */
99
100 /* Wrappers to acquire kernel_lock. */
101
102 PR_WRAP_USRREQ(cltp_usrreq)
103 PR_WRAP_USRREQ(clnp_usrreq)
104 PR_WRAP_USRREQ(idrp_usrreq)
105 PR_WRAP_USRREQ(tp_usrreq)
106 PR_WRAP_USRREQ(esis_usrreq)
107
108 #define cltp_usrreq cltp_usrreq_wrapper
109 #define clnp_usrreq clnp_usrreq_wrapper
110 #define idrp_usrreq idrp_usrreq_wrapper
111 #define tp_usrreq tp_usrreq_wrapper
112 #define esis_usrreq esis_usrreq_wrapper
113
114 PR_WRAP_CTLOUTPUT(rclnp_ctloutput)
115 PR_WRAP_CTLOUTPUT(tp_ctloutput)
116
117 #define rclnp_ctloutput rclnp_ctloutput_wrapper
118 #define tp_ctloutput tp_ctloutput_wrapper
119
120 PR_WRAP_CTLINPUT(esis_ctlinput)
121 PR_WRAP_CTLINPUT(tpclnp_ctlinput)
122
123 #define esis_ctlinput esis_ctlinput_wrapper
124 #define tpclnp_ctlinput tpclnp_ctlinput_wrapper
125
126 const struct protosw isosw[] = {
127 /*
128 * We need a datagram entry through which net mgmt programs can get
129 * to the iso_control procedure (iso ioctls). Thus, a minimal
130 * SOCK_DGRAM interface is provided here.
131 * THIS ONE MUST BE FIRST: Kludge city : socket() says if(!proto) call
132 * pffindtype, which gets the first entry that matches the type.
133 * sigh.
134 */
135 { .pr_type = SOCK_DGRAM,
136 .pr_domain = &isodomain,
137 .pr_protocol = ISOPROTO_CLTP,
138 .pr_flags = PR_ATOMIC | PR_ADDR,
139 .pr_input = 0,
140 .pr_output = cltp_output,
141 .pr_ctlinput = 0,
142 .pr_ctloutput = 0,
143 .pr_usrreq = cltp_usrreq,
144 .pr_init = cltp_init,
145 .pr_fasttimo = 0,
146 .pr_slowtimo = 0,
147 .pr_drain = 0
148 },
149
150 /*
151 * A datagram interface for clnp cannot co-exist with TP/CLNP
152 * because CLNP has no way to discriminate incoming TP packets from
153 * packets coming in for any other higher layer protocol.
154 * Old way: set it up so that pffindproto(... dgm, clnp) fails.
155 * New way: let pffindproto work (for x.25, thank you) but create
156 * a clnp_usrreq() that returns error on PRU_ATTACH.
157 */
158 { .pr_type = SOCK_DGRAM,
159 .pr_domain = &isodomain,
160 .pr_protocol = ISOPROTO_CLNP,
161 .pr_flags = 0,
162 .pr_input = 0,
163 .pr_output = clnp_output,
164 .pr_ctlinput = 0,
165 .pr_ctloutput = 0,
166 .pr_usrreq = clnp_usrreq,
167 .pr_init = clnp_init,
168 .pr_fasttimo = 0,
169 .pr_slowtimo = clnp_slowtimo,
170 .pr_drain = clnp_drain,
171 },
172
173 /* raw clnp */
174 { .pr_type = SOCK_RAW,
175 .pr_domain = &isodomain,
176 .pr_protocol = ISOPROTO_RAW,
177 .pr_flags = PR_ATOMIC | PR_ADDR,
178 .pr_input = rclnp_input,
179 .pr_output = rclnp_output,
180 .pr_ctlinput = 0,
181 .pr_ctloutput = rclnp_ctloutput,
182 .pr_usrreq = clnp_usrreq,
183 .pr_init = 0,
184 .pr_fasttimo = 0,
185 .pr_slowtimo = 0,
186 .pr_drain = 0
187 },
188
189 /* ES-IS protocol */
190 { .pr_type = SOCK_DGRAM,
191 .pr_domain = &isodomain,
192 .pr_protocol = ISOPROTO_ESIS,
193 .pr_flags = PR_ATOMIC | PR_ADDR,
194 .pr_input = esis_input,
195 .pr_output = 0,
196 .pr_ctlinput = esis_ctlinput,
197 .pr_ctloutput = 0,
198 .pr_usrreq = esis_usrreq,
199 .pr_init = esis_init,
200 .pr_fasttimo = 0,
201 .pr_slowtimo = 0,
202 .pr_drain = 0
203 },
204
205 /* ISOPROTO_INTRAISIS */
206 { .pr_type = SOCK_DGRAM,
207 .pr_domain = &isodomain,
208 .pr_protocol = ISOPROTO_INTRAISIS,
209 .pr_flags = PR_ATOMIC | PR_ADDR,
210 .pr_input = isis_input,
211 .pr_output = 0,
212 .pr_ctlinput = 0,
213 .pr_ctloutput = 0,
214 .pr_usrreq = esis_usrreq,
215 .pr_init = 0,
216 .pr_fasttimo = 0,
217 .pr_slowtimo = 0,
218 .pr_drain = 0
219 },
220
221 /* ISOPROTO_IDRP */
222 { .pr_type = SOCK_DGRAM,
223 .pr_domain = &isodomain,
224 .pr_protocol = ISOPROTO_IDRP,
225 .pr_flags = PR_ATOMIC | PR_ADDR,
226 .pr_input = idrp_input,
227 .pr_output = 0,
228 .pr_ctlinput = 0,
229 .pr_ctloutput = 0,
230 .pr_usrreq = idrp_usrreq,
231 .pr_init = idrp_init,
232 .pr_fasttimo = 0,
233 .pr_slowtimo = 0,
234 .pr_drain = 0
235 },
236
237 /* ISOPROTO_TP */
238 { .pr_type = SOCK_SEQPACKET,
239 .pr_domain = &isodomain,
240 .pr_protocol = ISOPROTO_TP,
241 .pr_flags = PR_CONNREQUIRED | PR_WANTRCVD | PR_LISTEN | PR_ABRTACPTDIS,
242 .pr_input = tpclnp_input,
243 .pr_output = 0,
244 .pr_ctlinput = tpclnp_ctlinput,
245 .pr_ctloutput = tp_ctloutput,
246 .pr_usrreq = tp_usrreq,
247 .pr_init = tp_init,
248 .pr_fasttimo = tp_fasttimo,
249 .pr_slowtimo = tp_slowtimo,
250 .pr_drain = tp_drain,
251 },
252 };
253
254 extern struct ifqueue clnlintrq;
255
256 struct domain isodomain = {
257 .dom_family = PF_ISO,
258 .dom_name = "iso-domain",
259 .dom_init = NULL,
260 .dom_externalize = NULL,
261 .dom_dispose = NULL,
262 .dom_protosw = isosw,
263 .dom_protoswNPROTOSW = &isosw[sizeof(isosw) / sizeof(isosw[0])],
264 .dom_rtattach = rn_inithead, /* rtattach */
265 .dom_rtoffset = 48, /* rtoffset */
266 .dom_maxrtkey = sizeof(struct sockaddr_iso), /* maxkeylen */
267 .dom_ifattach = NULL,
268 .dom_ifdetach = NULL,
269 .dom_ifqueues = { &clnlintrq, NULL }, /* ifqueues */
270 .dom_link = { NULL },
271 .dom_mowner = MOWNER_INIT("",""),
272 .dom_rtcache = LIST_HEAD_INITIALIZER(isodomain.dom_rtcache),
273 .dom_sockaddr_cmp = sockaddr_iso_cmp
274 };
275
276 int
277 sockaddr_iso_cmp(const struct sockaddr *sa1, const struct sockaddr *sa2)
278 {
279 int rc;
280 uint_fast8_t len, nlen;
281 const uint_fast8_t addrofs = offsetof(struct sockaddr_iso, siso_data);
282 const struct sockaddr_iso *siso1, *siso2;
283
284 siso1 = satocsiso(sa1);
285 siso2 = satocsiso(sa2);
286
287 len = MIN(siso1->siso_len, siso2->siso_len);
288 /* No siso_nlen present? */
289 if (len < addrofs)
290 return siso1->siso_len - siso2->siso_len;
291
292 nlen = MIN(siso1->siso_nlen, siso2->siso_nlen);
293 if (nlen > addrofs &&
294 (rc = memcmp(siso1->siso_data, siso2->siso_data, nlen)) != 0)
295 return rc;
296
297 return siso1->siso_nlen - siso2->siso_nlen;
298 }
Cache object: 7dbf92da0ed2e6fe8dd55848fbe38de3
|