1 /* $NetBSD: iso_proto.c,v 1.27 2008/04/23 09:57:59 plunky Exp $ */
4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
31 * @(#)iso_proto.c 8.2 (Berkeley) 2/9/95
34 /***********************************************************
35 Copyright IBM Corporation 1987
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.
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
55 ******************************************************************/
58 * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
61 * iso_proto.c : protocol switch tables in the ISO domain
63 * ISO protocol family includes TP, CLTP, CLNP, 8208
64 * TP and CLNP are implemented here.
67 #include <sys/cdefs.h>
68 __KERNEL_RCSID(0, "$NetBSD: iso_proto.c,v 1.27 2008/04/23 09:57:59 plunky Exp $");
71 #include <sys/param.h>
72 #include <sys/socket.h>
73 #include <sys/protosw.h>
74 #include <sys/domain.h>
77 #include <net/radix.h>
79 #include <netiso/iso.h>
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>
89 const int isoctlerrmap
[PRC_NCMDS
] = {
91 0, EMSGSIZE
, EHOSTDOWN
, EHOSTUNREACH
,
92 EHOSTUNREACH
, EHOSTUNREACH
, ECONNREFUSED
, ECONNREFUSED
,
93 EMSGSIZE
, EHOSTUNREACH
, 0, 0,
98 DOMAIN_DEFINE(isodomain
); /* forward declare and add to link set */
100 /* Wrappers to acquire kernel_lock. */
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
)
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
114 PR_WRAP_CTLOUTPUT(rclnp_ctloutput
)
115 PR_WRAP_CTLOUTPUT(tp_ctloutput
)
117 #define rclnp_ctloutput rclnp_ctloutput_wrapper
118 #define tp_ctloutput tp_ctloutput_wrapper
120 PR_WRAP_CTLINPUT(esis_ctlinput
)
121 PR_WRAP_CTLINPUT(tpclnp_ctlinput
)
123 #define esis_ctlinput esis_ctlinput_wrapper
124 #define tpclnp_ctlinput tpclnp_ctlinput_wrapper
126 const struct protosw isosw
[] = {
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.
135 { .pr_type
= SOCK_DGRAM
,
136 .pr_domain
= &isodomain
,
137 .pr_protocol
= ISOPROTO_CLTP
,
138 .pr_flags
= PR_ATOMIC
| PR_ADDR
,
140 .pr_output
= cltp_output
,
143 .pr_usrreq
= cltp_usrreq
,
144 .pr_init
= cltp_init
,
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.
158 { .pr_type
= SOCK_DGRAM
,
159 .pr_domain
= &isodomain
,
160 .pr_protocol
= ISOPROTO_CLNP
,
163 .pr_output
= clnp_output
,
166 .pr_usrreq
= clnp_usrreq
,
167 .pr_init
= clnp_init
,
169 .pr_slowtimo
= clnp_slowtimo
,
170 .pr_drain
= clnp_drain
,
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
,
181 .pr_ctloutput
= rclnp_ctloutput
,
182 .pr_usrreq
= clnp_usrreq
,
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
,
196 .pr_ctlinput
= esis_ctlinput
,
198 .pr_usrreq
= esis_usrreq
,
199 .pr_init
= esis_init
,
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
,
214 .pr_usrreq
= esis_usrreq
,
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
,
230 .pr_usrreq
= idrp_usrreq
,
231 .pr_init
= idrp_init
,
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
,
244 .pr_ctlinput
= tpclnp_ctlinput
,
245 .pr_ctloutput
= tp_ctloutput
,
246 .pr_usrreq
= tp_usrreq
,
248 .pr_fasttimo
= tp_fasttimo
,
249 .pr_slowtimo
= tp_slowtimo
,
250 .pr_drain
= tp_drain
,
254 extern struct ifqueue clnlintrq
;
256 struct domain isodomain
= {
257 .dom_family
= PF_ISO
,
258 .dom_name
= "iso-domain",
260 .dom_externalize
= 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
277 sockaddr_iso_cmp(const struct sockaddr
*sa1
, const struct sockaddr
*sa2
)
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
;
284 siso1
= satocsiso(sa1
);
285 siso2
= satocsiso(sa2
);
287 len
= MIN(siso1
->siso_len
, siso2
->siso_len
);
288 /* No siso_nlen present? */
290 return siso1
->siso_len
- siso2
->siso_len
;
292 nlen
= MIN(siso1
->siso_nlen
, siso2
->siso_nlen
);
293 if (nlen
> addrofs
&&
294 (rc
= memcmp(siso1
->siso_data
, siso2
->siso_data
, nlen
)) != 0)
297 return siso1
->siso_nlen
- siso2
->siso_nlen
;