2003-08-07 20:26:28 +04:00
|
|
|
/* $NetBSD: idrp_usrreq.c,v 1.12 2003/08/07 16:33:35 agc Exp $ */
|
1994-06-29 10:39:25 +04:00
|
|
|
|
1994-05-13 10:08:03 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-13 10:08:03 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1994-06-29 10:39:25 +04:00
|
|
|
* @(#)idrp_usrreq.c 8.1 (Berkeley) 6/10/93
|
1994-05-13 10:08:03 +04:00
|
|
|
*/
|
|
|
|
|
2001-11-13 03:56:55 +03:00
|
|
|
#include <sys/cdefs.h>
|
2003-08-07 20:26:28 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: idrp_usrreq.c,v 1.12 2003/08/07 16:33:35 agc Exp $");
|
2001-11-13 03:56:55 +03:00
|
|
|
|
1994-05-13 10:08:03 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
|
1996-09-08 18:28:08 +04:00
|
|
|
#include <net/raw_cb.h>
|
1994-05-13 10:08:03 +04:00
|
|
|
#include <net/route.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
|
|
|
|
#include <netiso/argo_debug.h>
|
|
|
|
#include <netiso/iso.h>
|
|
|
|
#include <netiso/clnp.h>
|
|
|
|
#include <netiso/clnl.h>
|
|
|
|
#include <netiso/iso_pcb.h>
|
|
|
|
#include <netiso/iso_var.h>
|
1996-02-14 01:07:57 +03:00
|
|
|
#include <netiso/idrp_var.h>
|
1994-05-13 10:08:03 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
#include <machine/stdarg.h>
|
|
|
|
|
1996-09-08 18:28:08 +04:00
|
|
|
LIST_HEAD(, rawcb) idrp_pcb;
|
|
|
|
struct isopcb idrp_isop;
|
1996-02-14 01:07:57 +03:00
|
|
|
static struct sockaddr_iso idrp_addrs[2] =
|
|
|
|
{{sizeof(idrp_addrs), AF_ISO,}, {sizeof(idrp_addrs[1]), AF_ISO,}};
|
1994-05-13 10:08:03 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* IDRP initialization
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
idrp_init()
|
|
|
|
{
|
|
|
|
extern struct clnl_protosw clnl_protox[256];
|
|
|
|
|
1996-09-08 18:28:08 +04:00
|
|
|
LIST_INIT(&idrp_pcb);
|
|
|
|
|
1994-05-13 10:08:03 +04:00
|
|
|
idrp_isop.isop_next = idrp_isop.isop_prev = &idrp_isop;
|
|
|
|
idrp_isop.isop_faddr = &idrp_isop.isop_sfaddr;
|
|
|
|
idrp_isop.isop_laddr = &idrp_isop.isop_sladdr;
|
|
|
|
idrp_isop.isop_sladdr = idrp_addrs[1];
|
|
|
|
idrp_isop.isop_sfaddr = idrp_addrs[1];
|
|
|
|
clnl_protox[ISO10747_IDRP].clnl_input = idrp_input;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CALLED FROM:
|
|
|
|
* tpclnp_input().
|
|
|
|
* FUNCTION and ARGUMENTS:
|
|
|
|
* Take a packet (m) from clnp, strip off the clnp header
|
|
|
|
* and mke suitable for the idrp socket.
|
1996-02-14 01:07:57 +03:00
|
|
|
* No return value.
|
1994-05-13 10:08:03 +04:00
|
|
|
*/
|
|
|
|
void
|
1996-02-14 01:07:57 +03:00
|
|
|
#if __STDC__
|
|
|
|
idrp_input(struct mbuf *m, ...)
|
|
|
|
#else
|
|
|
|
idrp_input(m, va_alist)
|
|
|
|
struct mbuf *m;
|
|
|
|
va_dcl
|
|
|
|
#endif
|
1994-05-13 10:08:03 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
struct sockaddr_iso *src, *dst;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, m);
|
|
|
|
src = va_arg(ap, struct sockaddr_iso *);
|
|
|
|
dst = va_arg(ap, struct sockaddr_iso *);
|
|
|
|
va_end(ap);
|
|
|
|
|
1994-05-13 10:08:03 +04:00
|
|
|
if (idrp_isop.isop_socket == 0) {
|
1996-02-14 01:07:57 +03:00
|
|
|
bad: m_freem(m);
|
1994-05-13 10:08:03 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
bzero(idrp_addrs[0].siso_data, sizeof(idrp_addrs[0].siso_data));
|
1996-02-14 01:07:57 +03:00
|
|
|
bcopy((caddr_t) & (src->siso_addr), (caddr_t) & idrp_addrs[0].siso_addr,
|
|
|
|
1 + src->siso_nlen);
|
1994-05-13 10:08:03 +04:00
|
|
|
bzero(idrp_addrs[1].siso_data, sizeof(idrp_addrs[1].siso_data));
|
1996-02-14 01:07:57 +03:00
|
|
|
bcopy((caddr_t) & (dst->siso_addr), (caddr_t) & idrp_addrs[1].siso_addr,
|
|
|
|
1 + dst->siso_nlen);
|
1994-05-13 10:08:03 +04:00
|
|
|
if (sbappendaddr(&idrp_isop.isop_socket->so_rcv,
|
1996-02-14 01:07:57 +03:00
|
|
|
sisotosa(idrp_addrs), m, (struct mbuf *) 0) == 0)
|
1994-05-13 10:08:03 +04:00
|
|
|
goto bad;
|
|
|
|
sorwakeup(idrp_isop.isop_socket);
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
int
|
|
|
|
#if __STDC__
|
|
|
|
idrp_output(struct mbuf *m, ...)
|
|
|
|
#else
|
|
|
|
idrp_output(m, va_alist)
|
|
|
|
struct mbuf *m;
|
|
|
|
va_dcl
|
|
|
|
#endif
|
1994-05-13 10:08:03 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct sockaddr_iso *siso;
|
1996-02-14 01:07:57 +03:00
|
|
|
int s = splsoftnet(), i;
|
|
|
|
va_list ap;
|
1996-09-08 18:28:08 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
va_start(ap, m);
|
1996-09-08 18:28:08 +04:00
|
|
|
siso = va_arg(ap, struct sockaddr_iso *);
|
1996-02-14 01:07:57 +03:00
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
bcopy((caddr_t) & (siso->siso_addr),
|
|
|
|
(caddr_t) & idrp_isop.isop_sfaddr.siso_addr, 1 + siso->siso_nlen);
|
1994-05-13 10:08:03 +04:00
|
|
|
siso++;
|
1996-02-14 01:07:57 +03:00
|
|
|
bcopy((caddr_t) & (siso->siso_addr),
|
|
|
|
(caddr_t) & idrp_isop.isop_sladdr.siso_addr, 1 + siso->siso_nlen);
|
1994-05-13 10:08:03 +04:00
|
|
|
i = clnp_output(m, idrp_isop, m->m_pkthdr.len, 0);
|
|
|
|
splx(s);
|
|
|
|
return (i);
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
u_long idrp_sendspace = 3072; /* really max datagram size */
|
|
|
|
u_long idrp_recvspace = 40 * 1024; /* 40 1K datagrams */
|
1994-05-13 10:08:03 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2003-06-30 02:28:00 +04:00
|
|
|
idrp_usrreq(so, req, m, nam, control, p)
|
1996-05-22 17:54:55 +04:00
|
|
|
struct socket *so;
|
|
|
|
int req;
|
|
|
|
struct mbuf *m, *nam, *control;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p;
|
1994-05-13 10:08:03 +04:00
|
|
|
{
|
1996-09-08 18:28:08 +04:00
|
|
|
struct rawcb *rp;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
if (req == PRU_CONTROL)
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
|
|
|
|
rp = sotorawcb(so);
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (req != PRU_SEND && req != PRU_SENDOOB && control)
|
|
|
|
panic("idrp_usrreq: unexpected control mbuf");
|
|
|
|
#endif
|
|
|
|
if (rp == 0 && req != PRU_ATTACH) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto release;
|
|
|
|
}
|
1994-05-13 10:08:03 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* Note: need to block idrp_input while changing the udp pcb queue
|
|
|
|
* and/or pcb addresses.
|
1994-05-13 10:08:03 +04:00
|
|
|
*/
|
|
|
|
switch (req) {
|
|
|
|
|
|
|
|
case PRU_ATTACH:
|
1996-09-08 18:28:08 +04:00
|
|
|
if (rp != 0) {
|
|
|
|
error = EISCONN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
|
|
|
|
error = soreserve(so, idrp_sendspace, idrp_recvspace);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
MALLOC(rp, struct rawcb *, sizeof(*rp), M_PCB, M_WAITOK);
|
|
|
|
if (rp == 0) {
|
|
|
|
error = ENOBUFS;
|
1994-05-13 10:08:03 +04:00
|
|
|
break;
|
|
|
|
}
|
1996-09-08 18:28:08 +04:00
|
|
|
bzero(rp, sizeof(*rp));
|
|
|
|
rp->rcb_socket = so;
|
|
|
|
LIST_INSERT_HEAD(&idrp_pcb, rp, rcb_list);
|
|
|
|
so->so_pcb = rp;
|
1994-05-13 10:08:03 +04:00
|
|
|
break;
|
|
|
|
|
1996-09-08 18:28:08 +04:00
|
|
|
case PRU_SEND:
|
|
|
|
if (control && control->m_len) {
|
|
|
|
m_freem(control);
|
|
|
|
m_freem(m);
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (nam == NULL) {
|
|
|
|
m_freem(m);
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* error checking here */
|
|
|
|
error = idrp_output(m, mtod(nam, struct sockaddr_iso *));
|
1994-05-13 10:08:03 +04:00
|
|
|
break;
|
|
|
|
|
1996-09-08 18:28:08 +04:00
|
|
|
case PRU_SENDOOB:
|
|
|
|
m_freem(control);
|
|
|
|
m_freem(m);
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
1994-05-13 10:08:03 +04:00
|
|
|
|
|
|
|
case PRU_DETACH:
|
1996-09-08 18:28:08 +04:00
|
|
|
raw_detach(rp);
|
1994-05-13 10:08:03 +04:00
|
|
|
break;
|
|
|
|
|
1996-09-08 18:28:08 +04:00
|
|
|
case PRU_SHUTDOWN:
|
|
|
|
socantsendmore(so);
|
|
|
|
break;
|
1994-05-13 10:08:03 +04:00
|
|
|
|
|
|
|
case PRU_SENSE:
|
|
|
|
/*
|
|
|
|
* stat: don't bother with a blocksize.
|
|
|
|
*/
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
default:
|
1996-09-08 18:28:08 +04:00
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
1994-05-13 10:08:03 +04:00
|
|
|
}
|
|
|
|
|
1996-09-08 18:28:08 +04:00
|
|
|
release:
|
1994-05-13 10:08:03 +04:00
|
|
|
return (error);
|
|
|
|
}
|