]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netiso/clnp_raw.c
264196757d1d68972274ca82ed0886292b339eea
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) 1991, 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 * @(#)clnp_raw.c 8.1 (Berkeley) 6/10/93
57 /***********************************************************
58 Copyright IBM Corporation 1987
62 Permission to use, copy, modify, and distribute this software and its
63 documentation for any purpose and without fee is hereby granted,
64 provided that the above copyright notice appear in all copies and that
65 both that copyright notice and this permission notice appear in
66 supporting documentation, and that the name of IBM not be
67 used in advertising or publicity pertaining to distribution of the
68 software without specific, written prior permission.
70 IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
71 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
72 IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
73 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
74 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
75 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
78 ******************************************************************/
81 * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
84 #include <sys/param.h>
86 #include <sys/domain.h>
87 #include <sys/protosw.h>
88 #include <sys/socket.h>
89 #include <sys/socketvar.h>
90 #include <sys/errno.h>
92 #include <sys/malloc.h>
95 #include <net/route.h>
96 #include <net/raw_cb.h>
98 #include <netiso/iso.h>
99 #include <netiso/iso_pcb.h>
100 #include <netiso/clnp.h>
101 #include <netiso/clnp_stat.h>
102 #include <netiso/argo_debug.h>
104 #include <netiso/tp_user.h> /* XXX -- defines SOL_NETWORK */
106 struct sockproto rclnp_proto
= { PF_ISO
, 0 };
108 * FUNCTION: rclnp_input
110 * PURPOSE: Setup generic address an protocol structures for
111 * raw input routine, then pass them along with the
118 * NOTES: The protocol field of rclnp_proto is set to zero indicating
121 rclnp_input(m
, src
, dst
, hdrlen
)
122 struct mbuf
*m
; /* ptr to packet */
123 struct sockaddr_iso
*src
; /* ptr to src address */
124 struct sockaddr_iso
*dst
; /* ptr to dest address */
125 int hdrlen
; /* length (in bytes) of clnp header */
128 if (trollctl
.tr_ops
& TR_CHUCK
) {
134 raw_input(m
, &rclnp_proto
, (struct sockaddr
*)src
, (struct sockaddr
*)dst
);
138 * FUNCTION: rclnp_output
140 * PURPOSE: Prepare to send a raw clnp packet. Setup src and dest
141 * addresses, count the number of bytes to send, and
144 * RETURNS: success - 0
145 * failure - an appropriate error code
152 struct mbuf
*m0
; /* packet to send */
153 struct socket
*so
; /* socket to send from */
155 register struct mbuf
*m
; /* used to scan a chain */
156 int len
= 0; /* store length of chain here */
157 struct rawisopcb
*rp
= sotorawisopcb(so
); /* ptr to raw cb */
158 int error
; /* return value of function */
159 int flags
; /* flags for clnp_output */
161 if (0 == (m0
->m_flags
& M_PKTHDR
))
164 * Set up src address. If user has bound socket to an address, use it.
165 * Otherwise, do not specify src (clnp_output will fill it in).
167 if (rp
->risop_rcb
.rcb_laddr
) {
168 if (rp
->risop_isop
.isop_sladdr
.siso_family
!= AF_ISO
) {
171 return(EAFNOSUPPORT
);
174 /* set up dest address */
175 if (rp
->risop_rcb
.rcb_faddr
== 0)
177 rp
->risop_isop
.isop_sfaddr
=
178 *(struct sockaddr_iso
*)rp
->risop_rcb
.rcb_faddr
;
179 rp
->risop_isop
.isop_faddr
= &rp
->risop_isop
.isop_sfaddr
;
181 /* get flags and ship it off */
182 flags
= rp
->risop_flags
& CLNP_VFLAGS
;
184 error
= clnp_output(m0
, &rp
->risop_isop
, m0
->m_pkthdr
.len
,
191 * FUNCTION: rclnp_ctloutput
193 * PURPOSE: Raw clnp socket option processing
194 * All options are stored inside an mbuf.
196 * RETURNS: success - 0
197 * failure - unix error code
199 * SIDE EFFECTS: If the options mbuf does not exist, it the mbuf passed
204 rclnp_ctloutput(op
, so
, level
, optname
, m
)
205 int op
; /* type of operation */
206 struct socket
*so
; /* ptr to socket */
207 int level
; /* level of option */
208 int optname
; /* name of option */
209 struct mbuf
**m
; /* ptr to ptr to option data */
212 register struct rawisopcb
*rp
= sotorawisopcb(so
);/* raw cb ptr */
215 printf("rclnp_ctloutput: op = x%x, level = x%x, name = x%x\n",
218 printf("rclnp_ctloutput: %d bytes of mbuf data\n", (*m
)->m_len
);
219 dump_buf(mtod((*m
), caddr_t
), (*m
)->m_len
);
224 if (level
!= SOL_NETWORK
)
229 #endif /* SOL_NETWORK */
232 case CLNPOPT_FLAGS
: {
235 * Insure that the data passed has exactly one short in it
237 if ((*m
== NULL
) || ((*m
)->m_len
!= sizeof(short))) {
243 * Don't allow invalid flags to be set
245 usr_flags
= (*mtod((*m
), short *));
247 if ((usr_flags
& (CLNP_VFLAGS
)) != usr_flags
) {
250 rp
->risop_flags
|= usr_flags
;
255 if (error
= clnp_set_opts(&rp
->risop_isop
.isop_options
, m
))
257 rp
->risop_isop
.isop_optindex
= m_get(M_WAIT
, MT_SOOPTS
);
258 (void) clnp_opt_sanity(rp
->risop_isop
.isop_options
,
259 mtod(rp
->risop_isop
.isop_options
, caddr_t
),
260 rp
->risop_isop
.isop_options
->m_len
,
261 mtod(rp
->risop_isop
.isop_optindex
,
262 struct clnp_optidx
*));
269 /* commented out to keep hi C quiet */
281 if (op
== PRCO_SETOPT
) {
282 /* note: m_freem does not barf is *m is NULL */
291 clnp_usrreq(so
, req
, m
, nam
, control
)
292 register struct socket
*so
;
294 struct mbuf
*m
, *nam
, *control
;
296 register int error
= 0;
297 register struct rawisopcb
*rp
= sotorawisopcb(so
);
299 rp
= sotorawisopcb(so
);
305 MALLOC(rp
, struct rawisopcb
*, sizeof *rp
, M_PCB
, M_WAITOK
);
308 bzero((caddr_t
)rp
, sizeof *rp
);
309 so
->so_pcb
= (caddr_t
)rp
;
315 if (rp
->risop_isop
.isop_options
)
316 m_freem(rp
->risop_isop
.isop_options
);
317 if (rp
->risop_isop
.isop_route
.ro_rt
)
318 RTFREE(rp
->risop_isop
.isop_route
.ro_rt
);
319 if (rp
->risop_rcb
.rcb_laddr
)
320 rp
->risop_rcb
.rcb_laddr
= 0;
321 /* free clnp cached hdr if necessary */
322 if (rp
->risop_isop
.isop_clnpcache
!= NULL
) {
323 struct clnp_cache
*clcp
=
324 mtod(rp
->risop_isop
.isop_clnpcache
, struct clnp_cache
*);
325 if (clcp
->clc_hdr
!= NULL
) {
326 m_free(clcp
->clc_hdr
);
328 m_free(rp
->risop_isop
.isop_clnpcache
);
330 if (rp
->risop_isop
.isop_optindex
!= NULL
)
331 m_free(rp
->risop_isop
.isop_optindex
);
337 struct sockaddr_iso
*addr
= mtod(nam
, struct sockaddr_iso
*);
339 if (nam
->m_len
!= sizeof(*addr
))
342 (addr
->siso_family
!= AF_ISO
) ||
343 (addr
->siso_addr
.isoa_len
&&
344 ifa_ifwithaddr((struct sockaddr
*)addr
) == 0))
345 return (EADDRNOTAVAIL
);
346 rp
->risop_isop
.isop_sladdr
= *addr
;
347 rp
->risop_rcb
.rcb_laddr
= (struct sockaddr
*)
348 (rp
->risop_isop
.isop_laddr
= &rp
->risop_isop
.isop_sladdr
);
353 struct sockaddr_iso
*addr
= mtod(nam
, struct sockaddr_iso
*);
355 if ((nam
->m_len
> sizeof(*addr
)) || (addr
->siso_len
> sizeof(*addr
)))
358 return (EADDRNOTAVAIL
);
359 if (addr
->siso_family
!= AF_ISO
)
360 rp
->risop_isop
.isop_sfaddr
= *addr
;
361 rp
->risop_rcb
.rcb_faddr
= (struct sockaddr
*)
362 (rp
->risop_isop
.isop_faddr
= &rp
->risop_isop
.isop_sfaddr
);
367 error
= raw_usrreq(so
, req
, m
, nam
, control
);
369 if (error
&& req
== PRU_ATTACH
&& so
->so_pcb
)
370 FREE((caddr_t
)rp
, M_PCB
);