2006-04-15 03:25:46 +04:00
|
|
|
/* $NetBSD: idp_usrreq.c,v 1.26 2006/04/14 23:25:46 christos Exp $ */
|
1994-06-29 10:39:25 +04:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
1994-05-13 10:10:16 +04:00
|
|
|
* Copyright (c) 1984, 1985, 1986, 1987, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* 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
|
1993-04-09 16:00:07 +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.
|
|
|
|
*
|
1998-03-01 05:20:01 +03:00
|
|
|
* @(#)idp_usrreq.c 8.2 (Berkeley) 1/9/95
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
2001-11-13 03:56:55 +03:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2006-04-15 03:25:46 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: idp_usrreq.c,v 1.26 2006/04/14 23:25:46 christos Exp $");
|
2001-11-13 03:56:55 +03:00
|
|
|
|
1998-07-05 10:49:00 +04:00
|
|
|
#include "opt_ns.h" /* NSIP: Xerox NS over IP */
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/param.h>
|
1996-02-14 01:13:43 +03:00
|
|
|
#include <sys/systm.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/stat.h>
|
1996-05-22 17:54:55 +04:00
|
|
|
#include <sys/proc.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/route.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <netns/ns.h>
|
|
|
|
#include <netns/ns_pcb.h>
|
|
|
|
#include <netns/ns_if.h>
|
1996-02-14 01:13:43 +03:00
|
|
|
#include <netns/ns_var.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <netns/idp.h>
|
|
|
|
#include <netns/idp_var.h>
|
|
|
|
#include <netns/ns_error.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:13:43 +03:00
|
|
|
#include <machine/stdarg.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
|
|
|
* IDP protocol implementation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct sockaddr_ns idp_ns = { sizeof(idp_ns), AF_NS };
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This may also be called for raw listeners.
|
|
|
|
*/
|
1996-02-14 01:13:43 +03:00
|
|
|
void
|
|
|
|
idp_input(struct mbuf *m, ...)
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nspcb *nsp;
|
|
|
|
struct idp *idp = mtod(m, struct idp *);
|
1993-04-09 16:00:07 +04:00
|
|
|
struct ifnet *ifp = m->m_pkthdr.rcvif;
|
1996-02-14 01:13:43 +03:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, m);
|
|
|
|
nsp = va_arg(ap, struct nspcb *);
|
|
|
|
va_end(ap);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
if (nsp==0)
|
|
|
|
panic("No nspcb");
|
|
|
|
/*
|
|
|
|
* Construct sockaddr format source address.
|
|
|
|
* Stuff source address and datagram in user buffer.
|
|
|
|
*/
|
|
|
|
idp_ns.sns_addr = idp->idp_sna;
|
|
|
|
if (ns_neteqnn(idp->idp_sna.x_net, ns_zeronet) && ifp) {
|
2000-03-30 16:51:13 +04:00
|
|
|
struct ifaddr *ifa;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1995-06-13 12:36:58 +04:00
|
|
|
for (ifa = ifp->if_addrlist.tqh_first; ifa != 0;
|
|
|
|
ifa = ifa->ifa_list.tqe_next) {
|
1993-04-09 16:00:07 +04:00
|
|
|
if (ifa->ifa_addr->sa_family == AF_NS) {
|
|
|
|
idp_ns.sns_addr.x_net =
|
|
|
|
IA_SNS(ifa)->sns_addr.x_net;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nsp->nsp_rpt = idp->idp_pt;
|
|
|
|
if ( ! (nsp->nsp_flags & NSP_RAWIN) ) {
|
|
|
|
m->m_len -= sizeof (struct idp);
|
|
|
|
m->m_pkthdr.len -= sizeof (struct idp);
|
|
|
|
m->m_data += sizeof (struct idp);
|
|
|
|
}
|
1995-06-13 12:36:58 +04:00
|
|
|
if (sbappendaddr(&nsp->nsp_socket->so_rcv, snstosa(&idp_ns), m,
|
|
|
|
(struct mbuf *)0) == 0)
|
1993-04-09 16:00:07 +04:00
|
|
|
goto bad;
|
|
|
|
sorwakeup(nsp->nsp_socket);
|
|
|
|
return;
|
|
|
|
bad:
|
|
|
|
m_freem(m);
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:13:43 +03:00
|
|
|
void
|
2004-04-19 04:10:48 +04:00
|
|
|
idp_abort(struct nspcb *nsp)
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
|
|
|
struct socket *so = nsp->nsp_socket;
|
|
|
|
|
|
|
|
ns_pcbdisconnect(nsp);
|
|
|
|
soisdisconnected(so);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Drop connection, reporting
|
|
|
|
* the specified error.
|
|
|
|
*/
|
1996-02-14 01:13:43 +03:00
|
|
|
void
|
2004-04-19 04:10:48 +04:00
|
|
|
idp_drop(struct nspcb *nsp, int errno)
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
|
|
|
struct socket *so = nsp->nsp_socket;
|
|
|
|
|
1996-02-14 01:13:43 +03:00
|
|
|
#if 0
|
1993-04-09 16:00:07 +04:00
|
|
|
/*
|
|
|
|
* someday, in the xerox world
|
|
|
|
* we will generate error protocol packets
|
|
|
|
* announcing that the socket has gone away.
|
|
|
|
*/
|
1996-02-14 01:13:43 +03:00
|
|
|
if (TCPS_HAVERCVDSYN(tp->t_state)) {
|
1993-04-09 16:00:07 +04:00
|
|
|
tp->t_state = TCPS_CLOSED;
|
|
|
|
(void) tcp_output(tp);
|
1996-02-14 01:13:43 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
so->so_error = errno;
|
|
|
|
ns_pcbdisconnect(nsp);
|
|
|
|
soisdisconnected(so);
|
|
|
|
}
|
|
|
|
|
1996-02-14 01:13:43 +03:00
|
|
|
int
|
|
|
|
idp_output(struct mbuf *m0, ...)
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:13:43 +03:00
|
|
|
struct nspcb *nsp;
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *m;
|
|
|
|
struct idp *idp;
|
|
|
|
int len = m0->m_pkthdr.len;
|
1993-04-09 16:00:07 +04:00
|
|
|
extern int idpcksum;
|
1996-02-14 01:13:43 +03:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, m0);
|
|
|
|
nsp = va_arg(ap, struct nspcb *);
|
|
|
|
va_end(ap);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure packet is actually of even length.
|
|
|
|
*/
|
2005-02-27 01:31:44 +03:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
if (len & 1) {
|
2006-04-15 03:25:46 +04:00
|
|
|
struct mbuf *mprev;
|
|
|
|
|
|
|
|
for (mprev = NULL, m = m0; m; m = m->m_next)
|
|
|
|
mprev = m;
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
m = mprev;
|
|
|
|
if ((m->m_flags & M_EXT) == 0 &&
|
|
|
|
(m->m_len + m->m_data < &m->m_dat[MLEN])) {
|
|
|
|
m->m_len++;
|
|
|
|
} else {
|
|
|
|
struct mbuf *m1 = m_get(M_DONTWAIT, MT_DATA);
|
|
|
|
|
|
|
|
if (m1 == 0) {
|
|
|
|
m_freem(m0);
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
|
|
|
m1->m_len = 1;
|
|
|
|
* mtod(m1, char *) = 0;
|
|
|
|
m->m_next = m1;
|
|
|
|
}
|
|
|
|
m0->m_pkthdr.len++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill in mbuf with extended IDP header
|
|
|
|
* and addresses and length put into network format.
|
|
|
|
*/
|
|
|
|
m = m0;
|
|
|
|
if (nsp->nsp_flags & NSP_RAWOUT) {
|
|
|
|
idp = mtod(m, struct idp *);
|
|
|
|
} else {
|
|
|
|
M_PREPEND(m, sizeof (struct idp), M_DONTWAIT);
|
|
|
|
if (m == 0)
|
|
|
|
return (ENOBUFS);
|
|
|
|
idp = mtod(m, struct idp *);
|
|
|
|
idp->idp_tc = 0;
|
|
|
|
idp->idp_pt = nsp->nsp_dpt;
|
|
|
|
idp->idp_sna = nsp->nsp_laddr;
|
|
|
|
idp->idp_dna = nsp->nsp_faddr;
|
|
|
|
len += sizeof (struct idp);
|
|
|
|
}
|
|
|
|
|
1997-07-18 23:30:33 +04:00
|
|
|
idp->idp_len = htons((u_int16_t)len);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
if (idpcksum) {
|
|
|
|
idp->idp_sum = 0;
|
|
|
|
len = ((len - 1) | 1) + 1;
|
|
|
|
idp->idp_sum = ns_cksum(m, len);
|
|
|
|
} else
|
|
|
|
idp->idp_sum = 0xffff;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use cached route for previous datagram if
|
|
|
|
* possible. If the previous net was the same
|
|
|
|
* and the interface was a broadcast medium, or
|
|
|
|
* if the previous destination was identical,
|
|
|
|
* then we are ok.
|
|
|
|
*
|
|
|
|
* NB: We don't handle broadcasts because that
|
|
|
|
* would require 3 subroutine calls.
|
|
|
|
*/
|
1996-09-08 18:48:21 +04:00
|
|
|
return (ns_output(m, &nsp->nsp_route,
|
|
|
|
nsp->nsp_socket->so_options & (SO_DONTROUTE | SO_BROADCAST)));
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
/* ARGSUSED */
|
1996-02-14 01:13:43 +03:00
|
|
|
int
|
2004-04-19 04:10:48 +04:00
|
|
|
idp_ctloutput(int req, struct socket *so, int level, int name,
|
|
|
|
struct mbuf **value)
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct mbuf *m;
|
1993-04-09 16:00:07 +04:00
|
|
|
struct nspcb *nsp = sotonspcb(so);
|
|
|
|
int mask, error = 0;
|
|
|
|
|
|
|
|
if (nsp == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
switch (req) {
|
|
|
|
|
|
|
|
case PRCO_GETOPT:
|
|
|
|
if (value==NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
m = m_get(M_DONTWAIT, MT_DATA);
|
|
|
|
if (m==NULL)
|
|
|
|
return (ENOBUFS);
|
|
|
|
switch (name) {
|
|
|
|
|
|
|
|
case SO_ALL_PACKETS:
|
|
|
|
mask = NSP_ALL_PACKETS;
|
|
|
|
goto get_flags;
|
|
|
|
|
|
|
|
case SO_HEADERS_ON_INPUT:
|
|
|
|
mask = NSP_RAWIN;
|
|
|
|
goto get_flags;
|
2005-02-27 01:31:44 +03:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
case SO_HEADERS_ON_OUTPUT:
|
|
|
|
mask = NSP_RAWOUT;
|
|
|
|
get_flags:
|
|
|
|
m->m_len = sizeof(short);
|
|
|
|
*mtod(m, short *) = nsp->nsp_flags & mask;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SO_DEFAULT_HEADERS:
|
|
|
|
m->m_len = sizeof(struct idp);
|
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct idp *idp = mtod(m, struct idp *);
|
1993-04-09 16:00:07 +04:00
|
|
|
idp->idp_len = 0;
|
|
|
|
idp->idp_sum = 0;
|
|
|
|
idp->idp_tc = 0;
|
|
|
|
idp->idp_pt = nsp->nsp_dpt;
|
|
|
|
idp->idp_dna = nsp->nsp_faddr;
|
|
|
|
idp->idp_sna = nsp->nsp_laddr;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SO_SEQNO:
|
|
|
|
m->m_len = sizeof(long);
|
|
|
|
*mtod(m, long *) = ns_pexseq++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
*value = m;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PRCO_SETOPT:
|
|
|
|
switch (name) {
|
|
|
|
int *ok;
|
|
|
|
|
|
|
|
case SO_ALL_PACKETS:
|
|
|
|
mask = NSP_ALL_PACKETS;
|
|
|
|
goto set_head;
|
|
|
|
|
|
|
|
case SO_HEADERS_ON_INPUT:
|
|
|
|
mask = NSP_RAWIN;
|
|
|
|
goto set_head;
|
|
|
|
|
|
|
|
case SO_HEADERS_ON_OUTPUT:
|
|
|
|
mask = NSP_RAWOUT;
|
|
|
|
set_head:
|
|
|
|
if (value && *value) {
|
|
|
|
ok = mtod(*value, int *);
|
|
|
|
if (*ok)
|
|
|
|
nsp->nsp_flags |= mask;
|
|
|
|
else
|
|
|
|
nsp->nsp_flags &= ~mask;
|
|
|
|
} else error = EINVAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SO_DEFAULT_HEADERS:
|
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct idp *idp
|
1993-04-09 16:00:07 +04:00
|
|
|
= mtod(*value, struct idp *);
|
|
|
|
nsp->nsp_dpt = idp->idp_pt;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#ifdef NSIP
|
|
|
|
|
|
|
|
case SO_NSIP_ROUTE:
|
|
|
|
error = nsip_route(*value);
|
|
|
|
break;
|
1994-05-13 10:10:16 +04:00
|
|
|
#endif /* NSIP */
|
1993-04-09 16:00:07 +04:00
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
if (value && *value)
|
|
|
|
m_freem(*value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1996-09-08 18:48:21 +04:00
|
|
|
u_long idp_sendspace = 2048;
|
|
|
|
u_long idp_recvspace = 2048;
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/*ARGSUSED*/
|
1996-02-14 01:13:43 +03:00
|
|
|
int
|
2004-04-19 04:10:48 +04:00
|
|
|
idp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
|
2005-12-11 15:16:03 +03:00
|
|
|
struct mbuf *control, struct lwp *l)
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
2000-03-30 16:51:13 +04:00
|
|
|
struct nspcb *nsp;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct proc *p;
|
1996-09-08 18:48:21 +04:00
|
|
|
int s;
|
1993-04-09 16:00:07 +04:00
|
|
|
int error = 0;
|
|
|
|
|
2005-12-11 15:16:03 +03:00
|
|
|
p = l ? l->l_proc : NULL;
|
1993-04-09 16:00:07 +04:00
|
|
|
if (req == PRU_CONTROL)
|
1998-03-01 05:20:01 +03:00
|
|
|
return (ns_control(so, (u_long)m, (caddr_t)nam,
|
1996-05-22 17:54:55 +04:00
|
|
|
(struct ifnet *)control, p));
|
1996-09-08 18:48:21 +04:00
|
|
|
|
2000-02-03 02:28:08 +03:00
|
|
|
if (req == PRU_PURGEIF) {
|
|
|
|
ns_purgeif((struct ifnet *)control);
|
2000-02-02 01:52:04 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1996-09-08 18:48:21 +04:00
|
|
|
s = splsoftnet();
|
|
|
|
nsp = sotonspcb(so);
|
|
|
|
if (nsp == 0 && req != PRU_ATTACH) {
|
1993-04-09 16:00:07 +04:00
|
|
|
error = EINVAL;
|
|
|
|
goto release;
|
|
|
|
}
|
1996-09-08 18:48:21 +04:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
switch (req) {
|
|
|
|
|
|
|
|
case PRU_ATTACH:
|
1996-09-08 18:48:21 +04:00
|
|
|
if (nsp != 0) {
|
|
|
|
error = EISCONN;
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
}
|
1996-09-08 18:48:21 +04:00
|
|
|
if ((error = soreserve(so, idp_sendspace, idp_recvspace)) ||
|
|
|
|
(error = ns_pcballoc(so, &nspcb)))
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PRU_DETACH:
|
|
|
|
ns_pcbdetach(nsp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PRU_BIND:
|
1996-05-22 17:54:55 +04:00
|
|
|
error = ns_pcbbind(nsp, nam, p);
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PRU_LISTEN:
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PRU_CONNECT:
|
|
|
|
error = ns_pcbconnect(nsp, nam);
|
1996-09-08 18:48:21 +04:00
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
soisconnected(so);
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PRU_CONNECT2:
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PRU_DISCONNECT:
|
|
|
|
soisdisconnected(so);
|
1996-09-08 18:48:21 +04:00
|
|
|
ns_pcbdisconnect(nsp);
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PRU_SHUTDOWN:
|
|
|
|
socantsendmore(so);
|
|
|
|
break;
|
|
|
|
|
1996-09-08 18:48:21 +04:00
|
|
|
case PRU_RCVD:
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
case PRU_SEND:
|
|
|
|
{
|
|
|
|
struct ns_addr laddr;
|
|
|
|
|
|
|
|
if (nam) {
|
|
|
|
laddr = nsp->nsp_laddr;
|
1996-09-08 18:48:21 +04:00
|
|
|
if ((so->so_state & SS_ISCONNECTED) != 0) {
|
1993-04-09 16:00:07 +04:00
|
|
|
error = EISCONN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
error = ns_pcbconnect(nsp, nam);
|
1996-09-08 18:48:21 +04:00
|
|
|
if (error)
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
} else {
|
1996-09-08 18:48:21 +04:00
|
|
|
if ((so->so_state & SS_ISCONNECTED) == 0) {
|
1993-04-09 16:00:07 +04:00
|
|
|
error = ENOTCONN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1996-02-14 01:13:43 +03:00
|
|
|
error = idp_output(m, nsp);
|
1993-04-09 16:00:07 +04:00
|
|
|
if (nam) {
|
|
|
|
ns_pcbdisconnect(nsp);
|
1996-09-08 18:48:21 +04:00
|
|
|
nsp->nsp_laddr = laddr;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PRU_SENSE:
|
|
|
|
/*
|
|
|
|
* stat: don't bother with a blocksize.
|
|
|
|
*/
|
1996-09-08 18:48:21 +04:00
|
|
|
splx(s);
|
1993-04-09 16:00:07 +04:00
|
|
|
return (0);
|
|
|
|
|
1996-09-08 18:48:21 +04:00
|
|
|
/*
|
|
|
|
* Not supported.
|
|
|
|
*/
|
|
|
|
case PRU_RCVOOB:
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
case PRU_SENDOOB:
|
1996-09-08 18:48:21 +04:00
|
|
|
m_freem(m);
|
|
|
|
error = EOPNOTSUPP;
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
|
1996-09-08 18:48:21 +04:00
|
|
|
case PRU_SOCKADDR:
|
|
|
|
ns_setsockaddr(nsp, nam);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PRU_PEERADDR:
|
|
|
|
ns_setpeeraddr(nsp, nam);
|
|
|
|
break;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
default:
|
|
|
|
panic("idp_usrreq");
|
|
|
|
}
|
1996-09-08 18:48:21 +04:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
release:
|
1996-09-08 18:48:21 +04:00
|
|
|
splx(s);
|
1993-04-09 16:00:07 +04:00
|
|
|
return (error);
|
|
|
|
}
|
1996-02-14 01:13:43 +03:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/*ARGSUSED*/
|
1996-02-14 01:13:43 +03:00
|
|
|
int
|
2004-04-19 04:10:48 +04:00
|
|
|
idp_raw_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
|
2005-12-11 15:16:03 +03:00
|
|
|
struct mbuf *control, struct lwp *l)
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
|
|
|
int error = 0;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct proc *p;
|
1993-04-09 16:00:07 +04:00
|
|
|
struct nspcb *nsp = sotonspcb(so);
|
|
|
|
|
2005-12-11 15:16:03 +03:00
|
|
|
p = l->l_proc;
|
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
switch (req) {
|
|
|
|
|
|
|
|
case PRU_ATTACH:
|
1996-05-22 17:54:55 +04:00
|
|
|
if (nsp != 0) {
|
|
|
|
error = EISCONN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (p == 0 || (error = suser(p->p_ucred, &p->p_acflag))) {
|
|
|
|
error = EACCES;
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
}
|
1996-09-08 18:48:21 +04:00
|
|
|
if ((error = soreserve(so, idp_sendspace, idp_recvspace)) ||
|
|
|
|
(error = ns_pcballoc(so, &nspcb)))
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
nsp = sotonspcb(so);
|
|
|
|
nsp->nsp_faddr.x_host = ns_broadhost;
|
|
|
|
nsp->nsp_flags = NSP_RAWIN | NSP_RAWOUT;
|
|
|
|
break;
|
1996-09-08 18:48:21 +04:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
default:
|
2005-12-11 15:16:03 +03:00
|
|
|
error = idp_usrreq(so, req, m, nam, control, l);
|
1996-09-08 18:48:21 +04:00
|
|
|
break;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|