1 /* $NetBSD: clnp_raw.c,v 1.32 2008/08/09 13:52:05 dogcow 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 * @(#)clnp_raw.c 8.1 (Berkeley) 6/10/93
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 #include <sys/cdefs.h>
62 __KERNEL_RCSID(0, "$NetBSD: clnp_raw.c,v 1.32 2008/08/09 13:52:05 dogcow Exp $");
64 #include <sys/param.h>
66 #include <sys/domain.h>
67 #include <sys/protosw.h>
68 #include <sys/socket.h>
69 #include <sys/socketvar.h>
70 #include <sys/errno.h>
72 #include <sys/systm.h>
76 #include <net/route.h>
77 #include <net/raw_cb.h>
79 #include <netiso/iso.h>
80 #include <netiso/iso_pcb.h>
81 #include <netiso/clnp.h>
82 #include <netiso/clnp_stat.h>
83 #include <netiso/argo_debug.h>
85 #include <netiso/tp_user.h> /* XXX -- defines SOL_NETWORK */
87 #include <machine/stdarg.h>
89 struct sockproto rclnp_proto
= {PF_ISO
, 0};
92 * FUNCTION: rclnp_input
94 * PURPOSE: Setup generic address and protocol structures for
95 * raw input routine, then pass them along with the
102 * NOTES: The protocol field of rclnp_proto is set to zero
103 * indicating no protocol.
106 rclnp_input(struct mbuf
*m
, ...)
108 struct sockaddr_iso
*src
; /* ptr to src address */
109 struct sockaddr_iso
*dst
; /* ptr to dest address */
110 int hdrlen
; /* length (in bytes) of clnp header */
114 src
= va_arg(ap
, struct sockaddr_iso
*);
115 dst
= va_arg(ap
, struct sockaddr_iso
*);
116 hdrlen
= va_arg(ap
, int);
119 if (trollctl
.tr_ops
& TR_CHUCK
) {
125 raw_input(m
, &rclnp_proto
, sisotosa(src
), sisotosa(dst
));
129 * FUNCTION: rclnp_output
131 * PURPOSE: Prepare to send a raw clnp packet. Setup src and dest
132 * addresses, count the number of bytes to send, and
135 * RETURNS: success - 0
136 * failure - an appropriate error code
143 rclnp_output(struct mbuf
*m0
, ...)
145 struct socket
*so
; /* socket to send from */
146 struct rawisopcb
*rp
; /* ptr to raw cb */
147 int error
; /* return value of function */
148 int flags
; /* flags for clnp_output */
152 so
= va_arg(ap
, struct socket
*);
154 rp
= sotorawisopcb(so
);
156 if ((m0
->m_flags
& M_PKTHDR
) == 0)
159 * Set up src address. If user has bound socket to an address, use it.
160 * Otherwise, do not specify src (clnp_output will fill it in).
162 if (rp
->risop_rcb
.rcb_laddr
) {
163 if (rp
->risop_isop
.isop_sladdr
.siso_family
!= AF_ISO
) {
166 return (EAFNOSUPPORT
);
169 /* set up dest address */
170 if (rp
->risop_rcb
.rcb_faddr
== 0)
172 rp
->risop_isop
.isop_sfaddr
= *satosiso(rp
->risop_rcb
.rcb_faddr
);
173 rp
->risop_isop
.isop_faddr
= &rp
->risop_isop
.isop_sfaddr
;
175 /* get flags and ship it off */
176 flags
= rp
->risop_flags
& CLNP_VFLAGS
;
178 error
= clnp_output(m0
, &rp
->risop_isop
, m0
->m_pkthdr
.len
,
179 flags
| CLNP_NOCACHE
);
185 * FUNCTION: rclnp_ctloutput
187 * PURPOSE: Raw clnp socket option processing
188 * All options are stored inside a sockopt.
190 * RETURNS: success - 0
191 * failure - unix error code
199 int op
, /* type of operation */
200 struct socket
*so
, /* ptr to socket */
201 struct sockopt
*sopt
) /* socket options */
204 struct rawisopcb
*rp
= sotorawisopcb(so
); /* raw cb ptr */
207 if (argo_debug
[D_CTLOUTPUT
]) {
208 printf("rclnp_ctloutput: op = x%x, level = x%x, name = x%x\n",
209 op
, sopt
->sopt_level
, sopt
->sopt_name
);
210 printf("rclnp_ctloutput: %zu bytes of data\n", sopt
->sopt_size
);
211 dump_buf(sopt
->sopt_data
, sopt
->sopt_size
);
216 if (sopt
->sopt_level
!= SOL_NETWORK
)
222 switch (sopt
->sopt_name
) {
226 error
= sockopt_get(sopt
, &flags
, sizeof(flags
));
231 * Don't allow invalid flags to be set
233 if ((flags
& (CLNP_VFLAGS
)) != flags
)
236 rp
->risop_flags
|= flags
;
244 m
= sockopt_getmbuf(sopt
);
250 error
= clnp_set_opts(&rp
->risop_isop
.isop_options
, &m
);
254 rp
->risop_isop
.isop_optindex
= m_get(M_WAIT
, MT_SOOPTS
);
255 (void) clnp_opt_sanity(rp
->risop_isop
.isop_options
,
256 mtod(rp
->risop_isop
.isop_options
, void *),
257 rp
->risop_isop
.isop_options
->m_len
,
258 mtod(rp
->risop_isop
.isop_optindex
,
259 struct clnp_optidx
*));
267 /* commented out to keep hi C quiet */
268 switch (sopt
->sopt_name
) {
284 clnp_usrreq(struct socket
*so
, int req
, struct mbuf
*m
, struct mbuf
*nam
,
285 struct mbuf
*control
, struct lwp
*l
)
288 struct rawisopcb
*rp
= sotorawisopcb(so
);
291 p
= l
? l
->l_proc
: NULL
;
292 rp
= sotorawisopcb(so
);
301 rp
= malloc(sizeof(*rp
), M_PCB
, M_WAITOK
|M_ZERO
);
308 if (rp
->risop_isop
.isop_options
)
309 m_freem(rp
->risop_isop
.isop_options
);
310 rtcache_free(&rp
->risop_isop
.isop_route
);
311 if (rp
->risop_rcb
.rcb_laddr
)
312 rp
->risop_rcb
.rcb_laddr
= 0;
313 /* free clnp cached hdr if necessary */
314 if (rp
->risop_isop
.isop_clnpcache
!= NULL
) {
315 struct clnp_cache
*clcp
=
316 mtod(rp
->risop_isop
.isop_clnpcache
, struct clnp_cache
*);
317 if (clcp
->clc_hdr
!= NULL
) {
318 m_free(clcp
->clc_hdr
);
320 m_free(rp
->risop_isop
.isop_clnpcache
);
322 if (rp
->risop_isop
.isop_optindex
!= NULL
)
323 m_free(rp
->risop_isop
.isop_optindex
);
329 struct sockaddr_iso
*addr
= mtod(nam
, struct sockaddr_iso
*);
331 if (nam
->m_len
!= sizeof(*addr
))
333 if ((ifnet
.tqh_first
== 0) ||
334 (addr
->siso_family
!= AF_ISO
) ||
335 (addr
->siso_addr
.isoa_len
&&
336 ifa_ifwithaddr(sisotosa(addr
)) == 0))
337 return (EADDRNOTAVAIL
);
338 rp
->risop_isop
.isop_sladdr
= *addr
;
339 rp
->risop_rcb
.rcb_laddr
= sisotosa(
340 (rp
->risop_isop
.isop_laddr
= &rp
->risop_isop
.isop_sladdr
));
345 struct sockaddr_iso
*addr
= mtod(nam
, struct sockaddr_iso
*);
347 if ((nam
->m_len
> sizeof(*addr
)) || (addr
->siso_len
> sizeof(*addr
)))
349 if (ifnet
.tqh_first
== 0)
350 return (EADDRNOTAVAIL
);
352 /* copy the address */
353 if (addr
->siso_family
!= AF_ISO
)
354 rp
->risop_isop
.isop_sfaddr
= *addr
;
356 /* initialize address pointers */
357 rp
->risop_isop
.isop_faddr
= &rp
->risop_isop
.isop_sfaddr
;
358 rp
->risop_rcb
.rcb_faddr
= sisotosa(
359 rp
->risop_isop
.isop_faddr
);
361 /* address setup, mark socket connected */
367 error
= raw_usrreq(so
, req
, m
, nam
, control
, l
);
369 if (error
&& req
== PRU_ATTACH
&& so
->so_pcb
)
370 free((void *) rp
, M_PCB
);