]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netiso/cltp_usrreq.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1989, 1993
24 * The Regents of the University of California. All rights reserved.
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
29 * 1. Redistributions of source code must retain the above copyright
30 * notice, this list of conditions and the following disclaimer.
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in the
33 * documentation and/or other materials provided with the distribution.
34 * 3. All advertising materials mentioning features or use of this software
35 * must display the following acknowledgement:
36 * This product includes software developed by the University of
37 * California, Berkeley and its contributors.
38 * 4. Neither the name of the University nor the names of its contributors
39 * may be used to endorse or promote products derived from this software
40 * without specific prior written permission.
42 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
43 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
46 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
48 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
51 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54 * @(#)cltp_usrreq.c 8.1 (Berkeley) 6/10/93
57 #ifndef CLTPOVAL_SRC /* XXX -- till files gets changed */
58 #include <sys/param.h>
59 #include <sys/malloc.h>
61 #include <sys/protosw.h>
62 #include <sys/socket.h>
63 #include <sys/socketvar.h>
64 #include <sys/errno.h>
68 #include <net/route.h>
70 #include <netiso/argo_debug.h>
71 #include <netiso/iso.h>
72 #include <netiso/iso_pcb.h>
73 #include <netiso/iso_var.h>
74 #include <netiso/clnp.h>
75 #include <netiso/cltp_var.h>
79 * CLTP protocol implementation.
80 * Per ISO 8602, December, 1987.
85 cltb
.isop_next
= cltb
.isop_prev
= &cltb
;
92 cltp_input(m0
, srcsa
, dstsa
, cons_channel
, output
)
94 struct sockaddr
*srcsa
, *dstsa
;
98 register struct isopcb
*isop
;
99 register struct mbuf
*m
= m0
;
100 register u_char
*up
= mtod(m
, u_char
*);
101 register struct sockaddr_iso
*src
= (struct sockaddr_iso
*)srcsa
;
102 int len
, hdrlen
= *up
+ 1, dlen
= 0;
103 u_char
*uplim
= up
+ hdrlen
;
106 for (len
= 0; m
; m
= m
->m_next
)
108 up
+= 2; /* skip header */
109 while (up
< uplim
) switch (*up
) { /* process options */
111 src
->siso_tlen
= up
[1];
112 src
->siso_len
= up
[1] + TSEL(src
) - (caddr_t
)src
;
113 if (src
->siso_len
< sizeof(*src
))
114 src
->siso_len
= sizeof(*src
);
115 else if (src
->siso_len
> sizeof(*src
)) {
116 MGET(m
, M_DONTWAIT
, MT_SONAME
);
119 m
->m_len
= src
->siso_len
;
120 src
= mtod(m
, struct sockaddr_iso
*);
121 bcopy((caddr_t
)srcsa
, (caddr_t
)src
, srcsa
->sa_len
);
123 bcopy((caddr_t
)up
+ 2, TSEL(src
), up
[1]);
124 up
+= 2 + src
->siso_tlen
;
128 dtsap
= 2 + (caddr_t
)up
;
134 if (iso_check_csum(m0
, len
)) {
135 cltpstat
.cltps_badsum
++;
142 printf("clts: unknown option (%x)\n", up
[0]);
143 cltpstat
.cltps_hdrops
++;
146 if (dlen
== 0 || src
->siso_tlen
== 0)
148 for (isop
= cltb
.isop_next
;; isop
= isop
->isop_next
) {
150 cltpstat
.cltps_noport
++;
153 if (isop
->isop_laddr
&&
154 bcmp(TSEL(isop
->isop_laddr
), dtsap
, dlen
) == 0)
160 if (sbappendaddr(&isop
->isop_socket
->so_rcv
, (struct sockaddr
*)src
,
161 m
, (struct mbuf
*)0) == 0)
163 cltpstat
.cltps_ipackets
++;
164 sorwakeup(isop
->isop_socket
);
167 if (src
!= (struct sockaddr_iso
*)srcsa
)
175 * Notify a cltp user of an asynchronous error;
176 * just wake up so that he can collect error status.
179 register struct isopcb
*isop
;
182 sorwakeup(isop
->isop_socket
);
183 sowwakeup(isop
->isop_socket
);
186 cltp_ctlinput(cmd
, sa
)
190 extern u_char inetctlerrmap
[];
191 struct sockaddr_iso
*siso
;
194 if ((unsigned)cmd
> PRC_NCMDS
)
196 if (sa
->sa_family
!= AF_ISO
&& sa
->sa_family
!= AF_CCITT
)
198 siso
= (struct sockaddr_iso
*)sa
;
199 if (siso
== 0 || siso
->siso_nlen
== 0)
204 case PRC_REDIRECT_NET
:
205 case PRC_REDIRECT_HOST
:
206 case PRC_REDIRECT_TOSNET
:
207 case PRC_REDIRECT_TOSHOST
:
208 iso_pcbnotify(&cltb
, siso
,
209 (int)inetctlerrmap
[cmd
], iso_rtchange
);
213 if (inetctlerrmap
[cmd
] == 0)
215 iso_pcbnotify(&cltb
, siso
, (int)inetctlerrmap
[cmd
],
221 register struct isopcb
*isop
;
222 register struct mbuf
*m
;
225 register struct sockaddr_iso
*siso
;
226 int hdrlen
, error
= 0, docsum
;
229 if (isop
->isop_laddr
== 0 || isop
->isop_faddr
== 0) {
234 * Calculate data length and get a mbuf for CLTP header.
236 hdrlen
= 2 + 2 + isop
->isop_laddr
->siso_tlen
237 + 2 + isop
->isop_faddr
->siso_tlen
;
238 if (docsum
= /*isop->isop_flags & CLNP_NO_CKSUM*/ cltp_cksum
)
240 M_PREPEND(m
, hdrlen
, M_WAIT
);
241 len
= m
->m_pkthdr
.len
;
243 * Fill in mbuf with extended CLTP header
245 up
= mtod(m
, u_char
*);
247 up
[1] = UD_TPDU_type
;
248 up
[2] = CLTPOVAL_SRC
;
249 up
[3] = (siso
= isop
->isop_laddr
)->siso_tlen
;
251 bcopy(TSEL(siso
), (caddr_t
)up
, siso
->siso_tlen
);
252 up
+= siso
->siso_tlen
;
253 up
[0] = CLTPOVAL_DST
;
254 up
[1] = (siso
= isop
->isop_faddr
)->siso_tlen
;
256 bcopy(TSEL(siso
), (caddr_t
)up
, siso
->siso_tlen
);
258 * Stuff checksum and output datagram.
261 up
+= siso
->siso_tlen
;
262 up
[0] = CLTPOVAL_CSM
;
264 iso_gen_csum(m
, 2 + up
- mtod(m
, u_char
*), len
);
266 cltpstat
.cltps_opackets
++;
267 return (tpclnp_output(isop
, m
, len
, !docsum
));
273 u_long cltp_sendspace
= 9216; /* really max datagram size */
274 u_long cltp_recvspace
= 40 * (1024 + sizeof(struct sockaddr_iso
));
275 /* 40 1K datagrams */
279 cltp_usrreq(so
, req
, m
, nam
, control
)
282 struct mbuf
*m
, *nam
, *control
;
284 register struct isopcb
*isop
= sotoisopcb(so
);
287 if (req
== PRU_CONTROL
)
288 return (iso_control(so
, (int)m
, (caddr_t
)nam
,
289 (struct ifnet
*)control
));
290 if ((isop
== NULL
&& req
!= PRU_ATTACH
) ||
291 (control
&& control
->m_len
)) {
302 error
= iso_pcballoc(so
, &cltb
);
305 error
= soreserve(so
, cltp_sendspace
, cltp_recvspace
);
315 error
= iso_pcbbind(isop
, nam
);
323 if (isop
->isop_faddr
) {
327 error
= iso_pcbconnect(isop
, nam
);
341 if (isop
->isop_faddr
== 0) {
345 iso_pcbdisconnect(isop
);
346 so
->so_state
&= ~SS_ISCONNECTED
; /* XXX */
355 if (isop
->isop_faddr
) {
360 * Must block input while temporarily connected.
363 error
= iso_pcbconnect(isop
, nam
);
369 if (isop
->isop_faddr
== 0) {
374 error
= cltp_output(isop
, m
);
377 iso_pcbdisconnect(isop
);
383 soisdisconnected(so
);
388 if (isop
->isop_laddr
)
389 bcopy((caddr_t
)isop
->isop_laddr
, mtod(m
, caddr_t
),
390 nam
->m_len
= isop
->isop_laddr
->siso_len
);
394 if (isop
->isop_faddr
)
395 bcopy((caddr_t
)isop
->isop_faddr
, mtod(m
, caddr_t
),
396 nam
->m_len
= isop
->isop_faddr
->siso_len
);
401 * stat: don't bother with a blocksize.
415 return (EOPNOTSUPP
); /* do not free mbuf's */
418 panic("cltp_usrreq");