2005-01-07 01:45:51 +00:00
|
|
|
/*-
|
1995-10-26 20:31:59 +00:00
|
|
|
* Copyright (c) 1984, 1985, 1986, 1987, 1993
|
2006-03-25 17:28:42 +00:00
|
|
|
* The Regents of the University of California.
|
|
|
|
* Copyright (c) 1995, Mike Mitchell
|
|
|
|
* Copyright (c) 2004-2006 Robert N. M. Watson
|
|
|
|
* All rights reserved.
|
1995-10-26 20:31:59 +00: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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* 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.
|
|
|
|
*
|
1995-11-04 09:03:47 +00:00
|
|
|
* @(#)ipx_usrreq.c
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-11 05:37:42 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1997-12-15 20:31:25 +00:00
|
|
|
#include "opt_ipx.h"
|
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
#include <sys/param.h>
|
1996-11-24 08:25:48 +00:00
|
|
|
#include <sys/kernel.h>
|
2002-04-30 01:54:54 +00:00
|
|
|
#include <sys/lock.h>
|
1995-10-26 20:31:59 +00:00
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/protosw.h>
|
2002-04-30 01:54:54 +00:00
|
|
|
#include <sys/signalvar.h>
|
1995-10-26 20:31:59 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
2002-04-30 01:54:54 +00:00
|
|
|
#include <sys/sx.h>
|
1996-11-24 08:25:48 +00:00
|
|
|
#include <sys/sysctl.h>
|
2002-04-30 01:54:54 +00:00
|
|
|
#include <sys/systm.h>
|
1995-10-26 20:31:59 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
|
1995-10-31 00:38:57 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
#include <netipx/ipx.h>
|
|
|
|
#include <netipx/ipx_if.h>
|
1995-10-31 00:38:57 +00:00
|
|
|
#include <netipx/ipx_ip.h>
|
2002-04-30 01:54:54 +00:00
|
|
|
#include <netipx/ipx_pcb.h>
|
|
|
|
#include <netipx/ipx_var.h>
|
1995-10-26 20:31:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* IPX protocol implementation.
|
|
|
|
*/
|
|
|
|
|
1998-02-09 06:11:36 +00:00
|
|
|
static int ipxsendspace = IPXSNDQ;
|
1996-11-24 08:25:48 +00:00
|
|
|
SYSCTL_INT(_net_ipx_ipx, OID_AUTO, ipxsendspace, CTLFLAG_RW,
|
|
|
|
&ipxsendspace, 0, "");
|
1998-02-09 06:11:36 +00:00
|
|
|
static int ipxrecvspace = IPXRCVQ;
|
1996-11-24 08:25:48 +00:00
|
|
|
SYSCTL_INT(_net_ipx_ipx, OID_AUTO, ipxrecvspace, CTLFLAG_RW,
|
|
|
|
&ipxrecvspace, 0, "");
|
|
|
|
|
2006-04-01 15:15:05 +00:00
|
|
|
static void ipx_usr_abort(struct socket *so);
|
2001-09-12 08:38:13 +00:00
|
|
|
static int ipx_attach(struct socket *so, int proto, struct thread *td);
|
|
|
|
static int ipx_bind(struct socket *so, struct sockaddr *nam, struct thread *td);
|
1997-08-16 19:16:27 +00:00
|
|
|
static int ipx_connect(struct socket *so, struct sockaddr *nam,
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td);
|
Chance protocol switch method pru_detach() so that it returns void
rather than an error. Detaches do not "fail", they other occur or
the protocol flags SS_PROTOREF to take ownership of the socket.
soclose() no longer looks at so_pcb to see if it's NULL, relying
entirely on the protocol to decide whether it's time to free the
socket or not using SS_PROTOREF. so_pcb is now entirely owned and
managed by the protocol code. Likewise, no longer test so_pcb in
other socket functions, such as soreceive(), which have no business
digging into protocol internals.
Protocol detach routines no longer try to free the socket on detach,
this is performed in the socket code if the protocol permits it.
In rts_detach(), no longer test for rp != NULL in detach, and
likewise in other protocols that don't permit a NULL so_pcb, reduce
the incidence of testing for it during detach.
netinet and netinet6 are not fully updated to this change, which
will be in an upcoming commit. In their current state they may leak
memory or panic.
MFC after: 3 months
2006-04-01 15:42:02 +00:00
|
|
|
static void ipx_detach(struct socket *so);
|
1997-04-05 20:05:11 +00:00
|
|
|
static int ipx_disconnect(struct socket *so);
|
|
|
|
static int ipx_send(struct socket *so, int flags, struct mbuf *m,
|
2005-01-02 15:13:59 +00:00
|
|
|
struct sockaddr *addr, struct mbuf *control,
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td);
|
1997-04-05 20:05:11 +00:00
|
|
|
static int ipx_shutdown(struct socket *so);
|
2001-09-12 08:38:13 +00:00
|
|
|
static int ripx_attach(struct socket *so, int proto, struct thread *td);
|
1997-05-10 09:58:58 +00:00
|
|
|
static int ipx_output(struct ipxpcb *ipxp, struct mbuf *m0);
|
2006-07-21 17:11:15 +00:00
|
|
|
static void ipx_usr_close(struct socket *so);
|
1997-04-05 20:05:11 +00:00
|
|
|
|
1997-05-10 09:58:58 +00:00
|
|
|
struct pr_usrreqs ipx_usrreqs = {
|
2004-11-08 14:44:54 +00:00
|
|
|
.pru_abort = ipx_usr_abort,
|
|
|
|
.pru_attach = ipx_attach,
|
|
|
|
.pru_bind = ipx_bind,
|
|
|
|
.pru_connect = ipx_connect,
|
|
|
|
.pru_control = ipx_control,
|
|
|
|
.pru_detach = ipx_detach,
|
|
|
|
.pru_disconnect = ipx_disconnect,
|
|
|
|
.pru_peeraddr = ipx_peeraddr,
|
|
|
|
.pru_send = ipx_send,
|
|
|
|
.pru_shutdown = ipx_shutdown,
|
|
|
|
.pru_sockaddr = ipx_sockaddr,
|
2006-07-21 17:11:15 +00:00
|
|
|
.pru_close = ipx_usr_close,
|
1997-04-05 20:05:11 +00:00
|
|
|
};
|
|
|
|
|
1997-05-10 09:58:58 +00:00
|
|
|
struct pr_usrreqs ripx_usrreqs = {
|
2004-11-08 14:44:54 +00:00
|
|
|
.pru_abort = ipx_usr_abort,
|
|
|
|
.pru_attach = ripx_attach,
|
|
|
|
.pru_bind = ipx_bind,
|
|
|
|
.pru_connect = ipx_connect,
|
|
|
|
.pru_control = ipx_control,
|
|
|
|
.pru_detach = ipx_detach,
|
|
|
|
.pru_disconnect = ipx_disconnect,
|
|
|
|
.pru_peeraddr = ipx_peeraddr,
|
|
|
|
.pru_send = ipx_send,
|
|
|
|
.pru_shutdown = ipx_shutdown,
|
|
|
|
.pru_sockaddr = ipx_sockaddr,
|
2006-07-21 17:11:15 +00:00
|
|
|
.pru_close = ipx_usr_close,
|
1997-04-05 20:05:11 +00:00
|
|
|
};
|
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
|
|
|
* This may also be called for raw listeners.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ipx_input(m, ipxp)
|
|
|
|
struct mbuf *m;
|
|
|
|
register struct ipxpcb *ipxp;
|
|
|
|
{
|
|
|
|
register struct ipx *ipx = mtod(m, struct ipx *);
|
|
|
|
struct ifnet *ifp = m->m_pkthdr.rcvif;
|
1996-04-13 14:37:22 +00:00
|
|
|
struct sockaddr_ipx ipx_ipx;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2005-01-03 12:54:31 +00:00
|
|
|
KASSERT(ipxp != NULL, ("ipx_input: NULL ipxpcb"));
|
2005-01-09 05:13:14 +00:00
|
|
|
IPX_LOCK_ASSERT(ipxp);
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
|
|
|
* Construct sockaddr format source address.
|
|
|
|
* Stuff source address and datagram in user buffer.
|
|
|
|
*/
|
1996-04-13 14:37:22 +00:00
|
|
|
ipx_ipx.sipx_len = sizeof(ipx_ipx);
|
|
|
|
ipx_ipx.sipx_family = AF_IPX;
|
1995-10-26 20:31:59 +00:00
|
|
|
ipx_ipx.sipx_addr = ipx->ipx_sna;
|
1996-04-13 14:37:22 +00:00
|
|
|
ipx_ipx.sipx_zero[0] = '\0';
|
|
|
|
ipx_ipx.sipx_zero[1] = '\0';
|
1997-05-10 09:58:58 +00:00
|
|
|
if (ipx_neteqnn(ipx->ipx_sna.x_net, ipx_zeronet) && ifp != NULL) {
|
1995-10-26 20:31:59 +00:00
|
|
|
register struct ifaddr *ifa;
|
|
|
|
|
2005-01-02 15:13:59 +00:00
|
|
|
for (ifa = TAILQ_FIRST(&ifp->if_addrhead); ifa != NULL;
|
2001-02-04 13:13:25 +00:00
|
|
|
ifa = TAILQ_NEXT(ifa, ifa_link)) {
|
1995-10-26 20:31:59 +00:00
|
|
|
if (ifa->ifa_addr->sa_family == AF_IPX) {
|
|
|
|
ipx_ipx.sipx_addr.x_net =
|
|
|
|
IA_SIPX(ifa)->sipx_addr.x_net;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ipxp->ipxp_rpt = ipx->ipx_pt;
|
2005-01-02 15:29:29 +00:00
|
|
|
if ((ipxp->ipxp_flags & IPXP_RAWIN) == 0) {
|
1997-05-10 09:58:58 +00:00
|
|
|
m->m_len -= sizeof(struct ipx);
|
|
|
|
m->m_pkthdr.len -= sizeof(struct ipx);
|
|
|
|
m->m_data += sizeof(struct ipx);
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
2005-01-02 15:29:29 +00:00
|
|
|
if (sbappendaddr(&ipxp->ipxp_socket->so_rcv,
|
|
|
|
(struct sockaddr *)&ipx_ipx, m, NULL) == 0)
|
|
|
|
m_freem(m);
|
|
|
|
else
|
|
|
|
sorwakeup(ipxp->ipxp_socket);
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Drop connection, reporting
|
|
|
|
* the specified error.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ipx_drop(ipxp, errno)
|
|
|
|
register struct ipxpcb *ipxp;
|
|
|
|
int errno;
|
|
|
|
{
|
|
|
|
struct socket *so = ipxp->ipxp_socket;
|
|
|
|
|
2005-01-09 05:13:14 +00:00
|
|
|
IPX_LIST_LOCK_ASSERT();
|
|
|
|
IPX_LOCK_ASSERT(ipxp);
|
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
1997-05-10 09:58:58 +00:00
|
|
|
* someday, in the IPX world
|
1995-10-26 20:31:59 +00:00
|
|
|
* we will generate error protocol packets
|
|
|
|
* announcing that the socket has gone away.
|
1997-05-10 09:58:58 +00:00
|
|
|
*
|
|
|
|
* XXX Probably never. IPX does not have error packets.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
/*if (TCPS_HAVERCVDSYN(tp->t_state)) {
|
|
|
|
tp->t_state = TCPS_CLOSED;
|
1997-05-10 09:58:58 +00:00
|
|
|
tcp_output(tp);
|
1995-10-26 20:31:59 +00:00
|
|
|
}*/
|
|
|
|
so->so_error = errno;
|
|
|
|
ipx_pcbdisconnect(ipxp);
|
|
|
|
soisdisconnected(so);
|
|
|
|
}
|
|
|
|
|
1997-05-10 09:58:58 +00:00
|
|
|
static int
|
1995-10-26 20:31:59 +00:00
|
|
|
ipx_output(ipxp, m0)
|
|
|
|
struct ipxpcb *ipxp;
|
|
|
|
struct mbuf *m0;
|
|
|
|
{
|
|
|
|
register struct ipx *ipx;
|
|
|
|
register struct socket *so;
|
|
|
|
register int len = 0;
|
|
|
|
register struct route *ro;
|
1999-12-19 01:55:37 +00:00
|
|
|
struct mbuf *m;
|
1995-10-26 20:31:59 +00:00
|
|
|
struct mbuf *mprev = NULL;
|
|
|
|
|
2005-01-09 05:13:14 +00:00
|
|
|
IPX_LOCK_ASSERT(ipxp);
|
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
|
|
|
* Calculate data length.
|
|
|
|
*/
|
1997-05-10 09:58:58 +00:00
|
|
|
for (m = m0; m != NULL; m = m->m_next) {
|
1995-10-26 20:31:59 +00:00
|
|
|
mprev = m;
|
|
|
|
len += m->m_len;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Make sure packet is actually of even length.
|
|
|
|
*/
|
2005-01-02 15:13:59 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
if (len & 1) {
|
|
|
|
m = mprev;
|
|
|
|
if ((m->m_flags & M_EXT) == 0 &&
|
|
|
|
(m->m_len + m->m_data < &m->m_dat[MLEN])) {
|
1999-08-28 18:21:55 +00:00
|
|
|
mtod(m, char*)[m->m_len++] = 0;
|
1995-10-26 20:31:59 +00:00
|
|
|
} else {
|
2003-02-19 05:47:46 +00:00
|
|
|
struct mbuf *m1 = m_get(M_DONTWAIT, MT_DATA);
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-05-10 09:58:58 +00:00
|
|
|
if (m1 == NULL) {
|
1995-10-26 20:31:59 +00:00
|
|
|
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 IPX header
|
|
|
|
* and addresses and length put into network format.
|
|
|
|
*/
|
|
|
|
m = m0;
|
|
|
|
if (ipxp->ipxp_flags & IPXP_RAWOUT) {
|
|
|
|
ipx = mtod(m, struct ipx *);
|
|
|
|
} else {
|
2003-02-19 05:47:46 +00:00
|
|
|
M_PREPEND(m, sizeof(struct ipx), M_DONTWAIT);
|
1997-05-10 09:58:58 +00:00
|
|
|
if (m == NULL)
|
1995-10-26 20:31:59 +00:00
|
|
|
return (ENOBUFS);
|
|
|
|
ipx = mtod(m, struct ipx *);
|
|
|
|
ipx->ipx_tc = 0;
|
|
|
|
ipx->ipx_pt = ipxp->ipxp_dpt;
|
|
|
|
ipx->ipx_sna = ipxp->ipxp_laddr;
|
|
|
|
ipx->ipx_dna = ipxp->ipxp_faddr;
|
1997-05-10 09:58:58 +00:00
|
|
|
len += sizeof(struct ipx);
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ipx->ipx_len = htons((u_short)len);
|
|
|
|
|
1999-08-28 18:21:55 +00:00
|
|
|
if (ipxp->ipxp_flags & IPXP_CHECKSUM) {
|
1995-10-26 20:31:59 +00:00
|
|
|
ipx->ipx_sum = ipx_cksum(m, len);
|
|
|
|
} else
|
|
|
|
ipx->ipx_sum = 0xffff;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Output datagram.
|
|
|
|
*/
|
|
|
|
so = ipxp->ipxp_socket;
|
2002-05-31 11:52:35 +00:00
|
|
|
if (so->so_options & SO_DONTROUTE)
|
1997-05-10 09:58:58 +00:00
|
|
|
return (ipx_outputfl(m, (struct route *)NULL,
|
2002-05-31 11:52:35 +00:00
|
|
|
(so->so_options & SO_BROADCAST) | IPX_ROUTETOIF));
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
ro = &ipxp->ipxp_route;
|
|
|
|
#ifdef ancient_history
|
|
|
|
/*
|
|
|
|
* I think that this will all be handled in ipx_pcbconnect!
|
|
|
|
*/
|
1997-05-10 09:58:58 +00:00
|
|
|
if (ro->ro_rt != NULL) {
|
1995-10-26 20:31:59 +00:00
|
|
|
if(ipx_neteq(ipxp->ipxp_lastdst, ipx->ipx_dna)) {
|
|
|
|
/*
|
|
|
|
* This assumes we have no GH type routes
|
|
|
|
*/
|
|
|
|
if (ro->ro_rt->rt_flags & RTF_HOST) {
|
|
|
|
if (!ipx_hosteq(ipxp->ipxp_lastdst, ipx->ipx_dna))
|
|
|
|
goto re_route;
|
|
|
|
|
|
|
|
}
|
|
|
|
if ((ro->ro_rt->rt_flags & RTF_GATEWAY) == 0) {
|
|
|
|
register struct ipx_addr *dst =
|
|
|
|
&satoipx_addr(ro->ro_dst);
|
|
|
|
dst->x_host = ipx->ipx_dna.x_host;
|
|
|
|
}
|
2005-01-02 15:13:59 +00:00
|
|
|
/*
|
1995-10-26 20:31:59 +00:00
|
|
|
* Otherwise, we go through the same gateway
|
|
|
|
* and dst is already set up.
|
|
|
|
*/
|
|
|
|
} else {
|
|
|
|
re_route:
|
|
|
|
RTFREE(ro->ro_rt);
|
1997-05-10 09:58:58 +00:00
|
|
|
ro->ro_rt = NULL;
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ipxp->ipxp_lastdst = ipx->ipx_dna;
|
|
|
|
#endif /* ancient_history */
|
2002-05-31 11:52:35 +00:00
|
|
|
return (ipx_outputfl(m, ro, so->so_options & SO_BROADCAST));
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
1996-11-24 08:25:48 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
int
|
1998-08-23 03:07:17 +00:00
|
|
|
ipx_ctloutput(so, sopt)
|
1995-10-26 20:31:59 +00:00
|
|
|
struct socket *so;
|
1998-08-23 03:07:17 +00:00
|
|
|
struct sockopt *sopt;
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
|
|
|
struct ipxpcb *ipxp = sotoipxpcb(so);
|
1998-08-23 03:07:17 +00:00
|
|
|
int mask, error, optval;
|
|
|
|
short soptval;
|
|
|
|
struct ipx ioptval;
|
2005-01-09 05:15:59 +00:00
|
|
|
long seq;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2006-03-25 17:28:42 +00:00
|
|
|
KASSERT(ipxp != NULL, ("ipx_ctloutput: ipxp == NULL"));
|
1998-08-23 03:07:17 +00:00
|
|
|
error = 0;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1998-08-23 03:07:17 +00:00
|
|
|
switch (sopt->sopt_dir) {
|
|
|
|
case SOPT_GET:
|
|
|
|
switch (sopt->sopt_name) {
|
1995-10-26 20:31:59 +00:00
|
|
|
case SO_ALL_PACKETS:
|
|
|
|
mask = IPXP_ALL_PACKETS;
|
|
|
|
goto get_flags;
|
|
|
|
|
|
|
|
case SO_HEADERS_ON_INPUT:
|
|
|
|
mask = IPXP_RAWIN;
|
|
|
|
goto get_flags;
|
1999-08-28 18:21:55 +00:00
|
|
|
|
|
|
|
case SO_IPX_CHECKSUM:
|
|
|
|
mask = IPXP_CHECKSUM;
|
|
|
|
goto get_flags;
|
2005-01-02 15:13:59 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
case SO_HEADERS_ON_OUTPUT:
|
|
|
|
mask = IPXP_RAWOUT;
|
|
|
|
get_flags:
|
2005-01-09 05:15:59 +00:00
|
|
|
/* Unlocked read. */
|
1998-08-23 03:07:17 +00:00
|
|
|
soptval = ipxp->ipxp_flags & mask;
|
|
|
|
error = sooptcopyout(sopt, &soptval, sizeof soptval);
|
1995-10-26 20:31:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SO_DEFAULT_HEADERS:
|
1998-08-23 03:07:17 +00:00
|
|
|
ioptval.ipx_len = 0;
|
|
|
|
ioptval.ipx_sum = 0;
|
|
|
|
ioptval.ipx_tc = 0;
|
2005-01-09 05:15:59 +00:00
|
|
|
IPX_LOCK(ipxp);
|
1998-08-23 03:07:17 +00:00
|
|
|
ioptval.ipx_pt = ipxp->ipxp_dpt;
|
|
|
|
ioptval.ipx_dna = ipxp->ipxp_faddr;
|
|
|
|
ioptval.ipx_sna = ipxp->ipxp_laddr;
|
2005-01-09 05:15:59 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
1998-08-23 03:07:17 +00:00
|
|
|
error = sooptcopyout(sopt, &soptval, sizeof soptval);
|
1995-10-26 20:31:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SO_SEQNO:
|
2005-01-09 05:15:59 +00:00
|
|
|
IPX_LIST_LOCK();
|
|
|
|
seq = ipx_pexseq;
|
1998-08-23 03:07:17 +00:00
|
|
|
ipx_pexseq++;
|
2005-01-09 05:15:59 +00:00
|
|
|
IPX_LIST_UNLOCK();
|
|
|
|
error = sooptcopyout(sopt, &seq, sizeof seq);
|
1995-10-26 20:31:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1998-08-23 03:07:17 +00:00
|
|
|
case SOPT_SET:
|
|
|
|
switch (sopt->sopt_name) {
|
1995-10-26 20:31:59 +00:00
|
|
|
case SO_ALL_PACKETS:
|
|
|
|
mask = IPXP_ALL_PACKETS;
|
|
|
|
goto set_head;
|
|
|
|
|
|
|
|
case SO_HEADERS_ON_INPUT:
|
|
|
|
mask = IPXP_RAWIN;
|
|
|
|
goto set_head;
|
|
|
|
|
1999-08-28 18:21:55 +00:00
|
|
|
case SO_IPX_CHECKSUM:
|
|
|
|
mask = IPXP_CHECKSUM;
|
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
case SO_HEADERS_ON_OUTPUT:
|
|
|
|
mask = IPXP_RAWOUT;
|
|
|
|
set_head:
|
1998-08-23 03:07:17 +00:00
|
|
|
error = sooptcopyin(sopt, &optval, sizeof optval,
|
|
|
|
sizeof optval);
|
|
|
|
if (error)
|
|
|
|
break;
|
2005-01-09 05:15:59 +00:00
|
|
|
IPX_LOCK(ipxp);
|
1998-08-23 03:07:17 +00:00
|
|
|
if (optval)
|
|
|
|
ipxp->ipxp_flags |= mask;
|
|
|
|
else
|
|
|
|
ipxp->ipxp_flags &= ~mask;
|
2005-01-09 05:15:59 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
1995-10-26 20:31:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SO_DEFAULT_HEADERS:
|
1998-08-23 03:07:17 +00:00
|
|
|
error = sooptcopyin(sopt, &ioptval, sizeof ioptval,
|
|
|
|
sizeof ioptval);
|
|
|
|
if (error)
|
|
|
|
break;
|
2005-01-09 05:15:59 +00:00
|
|
|
/* Unlocked write. */
|
1998-08-23 03:07:17 +00:00
|
|
|
ipxp->ipxp_dpt = ioptval.ipx_pt;
|
1995-10-26 20:31:59 +00:00
|
|
|
break;
|
|
|
|
#ifdef IPXIP
|
|
|
|
case SO_IPXIP_ROUTE:
|
1998-08-23 03:07:17 +00:00
|
|
|
error = ipxip_route(so, sopt);
|
1995-10-26 20:31:59 +00:00
|
|
|
break;
|
|
|
|
#endif /* IPXIP */
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2006-04-01 15:15:05 +00:00
|
|
|
static void
|
1997-04-05 20:05:11 +00:00
|
|
|
ipx_usr_abort(so)
|
1995-10-26 20:31:59 +00:00
|
|
|
struct socket *so;
|
|
|
|
{
|
|
|
|
|
2006-07-21 17:11:15 +00:00
|
|
|
/* XXXRW: Possibly ipx_disconnect() here? */
|
1997-04-05 20:05:11 +00:00
|
|
|
soisdisconnected(so);
|
|
|
|
}
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
ipx_attach(so, proto, td)
|
1997-04-05 20:05:11 +00:00
|
|
|
struct socket *so;
|
|
|
|
int proto;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
1997-04-05 20:05:11 +00:00
|
|
|
{
|
2006-04-11 23:15:47 +00:00
|
|
|
#ifdef INVARIANTS
|
1997-04-05 20:05:11 +00:00
|
|
|
struct ipxpcb *ipxp = sotoipxpcb(so);
|
2006-04-11 23:15:47 +00:00
|
|
|
#endif
|
2005-01-09 05:13:14 +00:00
|
|
|
int error;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2006-03-25 17:28:42 +00:00
|
|
|
KASSERT(ipxp == NULL, ("ipx_attach: ipxp != NULL"));
|
|
|
|
error = soreserve(so, ipxsendspace, ipxrecvspace);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
2005-01-09 05:13:14 +00:00
|
|
|
IPX_LIST_LOCK();
|
2004-12-30 17:49:40 +00:00
|
|
|
error = ipx_pcballoc(so, &ipxpcb_list, td);
|
2005-01-09 05:13:14 +00:00
|
|
|
IPX_LIST_UNLOCK();
|
1997-04-05 20:05:11 +00:00
|
|
|
return (error);
|
|
|
|
}
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
ipx_bind(so, nam, td)
|
1997-04-05 20:05:11 +00:00
|
|
|
struct socket *so;
|
1997-08-16 19:16:27 +00:00
|
|
|
struct sockaddr *nam;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
1997-04-05 20:05:11 +00:00
|
|
|
{
|
|
|
|
struct ipxpcb *ipxp = sotoipxpcb(so);
|
2005-01-09 05:13:14 +00:00
|
|
|
int error;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2006-03-25 17:28:42 +00:00
|
|
|
KASSERT(ipxp != NULL, ("ipx_bind: ipxp == NULL"));
|
2005-01-09 05:13:14 +00:00
|
|
|
IPX_LIST_LOCK();
|
|
|
|
IPX_LOCK(ipxp);
|
|
|
|
error = ipx_pcbbind(ipxp, nam, td);
|
|
|
|
IPX_UNLOCK(ipxp);
|
|
|
|
IPX_LIST_UNLOCK();
|
|
|
|
return (error);
|
1997-04-05 20:05:11 +00:00
|
|
|
}
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2006-07-21 17:11:15 +00:00
|
|
|
static void
|
|
|
|
ipx_usr_close(so)
|
|
|
|
struct socket *so;
|
|
|
|
{
|
|
|
|
|
|
|
|
/* XXXRW: Possibly ipx_disconnect() here? */
|
|
|
|
soisdisconnected(so);
|
|
|
|
}
|
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
ipx_connect(so, nam, td)
|
1997-04-05 20:05:11 +00:00
|
|
|
struct socket *so;
|
1997-08-16 19:16:27 +00:00
|
|
|
struct sockaddr *nam;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
1997-04-05 20:05:11 +00:00
|
|
|
{
|
|
|
|
struct ipxpcb *ipxp = sotoipxpcb(so);
|
2005-01-09 05:13:14 +00:00
|
|
|
int error;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2006-03-25 17:28:42 +00:00
|
|
|
KASSERT(ipxp != NULL, ("ipx_connect: ipxp == NULL"));
|
2005-01-09 05:13:14 +00:00
|
|
|
IPX_LIST_LOCK();
|
|
|
|
IPX_LOCK(ipxp);
|
|
|
|
if (!ipx_nullhost(ipxp->ipxp_faddr)) {
|
|
|
|
error = EISCONN;
|
|
|
|
goto out;
|
|
|
|
}
|
2001-09-12 08:38:13 +00:00
|
|
|
error = ipx_pcbconnect(ipxp, nam, td);
|
2002-05-31 11:52:35 +00:00
|
|
|
if (error == 0)
|
1997-04-05 20:05:11 +00:00
|
|
|
soisconnected(so);
|
2005-01-09 05:13:14 +00:00
|
|
|
out:
|
|
|
|
IPX_UNLOCK(ipxp);
|
|
|
|
IPX_LIST_UNLOCK();
|
1997-04-05 20:05:11 +00:00
|
|
|
return (error);
|
|
|
|
}
|
1995-10-26 20:31:59 +00:00
|
|
|
|
Chance protocol switch method pru_detach() so that it returns void
rather than an error. Detaches do not "fail", they other occur or
the protocol flags SS_PROTOREF to take ownership of the socket.
soclose() no longer looks at so_pcb to see if it's NULL, relying
entirely on the protocol to decide whether it's time to free the
socket or not using SS_PROTOREF. so_pcb is now entirely owned and
managed by the protocol code. Likewise, no longer test so_pcb in
other socket functions, such as soreceive(), which have no business
digging into protocol internals.
Protocol detach routines no longer try to free the socket on detach,
this is performed in the socket code if the protocol permits it.
In rts_detach(), no longer test for rp != NULL in detach, and
likewise in other protocols that don't permit a NULL so_pcb, reduce
the incidence of testing for it during detach.
netinet and netinet6 are not fully updated to this change, which
will be in an upcoming commit. In their current state they may leak
memory or panic.
MFC after: 3 months
2006-04-01 15:42:02 +00:00
|
|
|
static void
|
1997-04-05 20:05:11 +00:00
|
|
|
ipx_detach(so)
|
|
|
|
struct socket *so;
|
|
|
|
{
|
|
|
|
struct ipxpcb *ipxp = sotoipxpcb(so);
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2006-07-21 17:11:15 +00:00
|
|
|
/* XXXRW: Should assert detached. */
|
2006-03-25 17:28:42 +00:00
|
|
|
KASSERT(ipxp != NULL, ("ipx_detach: ipxp == NULL"));
|
2005-01-09 05:13:14 +00:00
|
|
|
IPX_LIST_LOCK();
|
|
|
|
IPX_LOCK(ipxp);
|
1997-04-05 20:05:11 +00:00
|
|
|
ipx_pcbdetach(ipxp);
|
2006-03-25 17:28:42 +00:00
|
|
|
ipx_pcbfree(ipxp);
|
2005-01-09 05:13:14 +00:00
|
|
|
IPX_LIST_UNLOCK();
|
1997-04-05 20:05:11 +00:00
|
|
|
}
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
static int
|
|
|
|
ipx_disconnect(so)
|
|
|
|
struct socket *so;
|
|
|
|
{
|
|
|
|
struct ipxpcb *ipxp = sotoipxpcb(so);
|
2005-01-09 05:13:14 +00:00
|
|
|
int error;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2006-03-25 17:28:42 +00:00
|
|
|
KASSERT(ipxp != NULL, ("ipx_disconnect: ipxp == NULL"));
|
2005-01-09 05:13:14 +00:00
|
|
|
IPX_LIST_LOCK();
|
|
|
|
IPX_LOCK(ipxp);
|
|
|
|
error = 0;
|
|
|
|
if (ipx_nullhost(ipxp->ipxp_faddr)) {
|
|
|
|
error = ENOTCONN;
|
|
|
|
goto out;
|
|
|
|
}
|
1997-04-05 20:05:11 +00:00
|
|
|
ipx_pcbdisconnect(ipxp);
|
|
|
|
soisdisconnected(so);
|
2005-01-09 05:13:14 +00:00
|
|
|
out:
|
|
|
|
IPX_UNLOCK(ipxp);
|
|
|
|
IPX_LIST_UNLOCK();
|
1997-04-05 20:05:11 +00:00
|
|
|
return (0);
|
|
|
|
}
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
int
|
|
|
|
ipx_peeraddr(so, nam)
|
|
|
|
struct socket *so;
|
1997-08-16 19:16:27 +00:00
|
|
|
struct sockaddr **nam;
|
1997-04-05 20:05:11 +00:00
|
|
|
{
|
|
|
|
struct ipxpcb *ipxp = sotoipxpcb(so);
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2006-03-25 17:28:42 +00:00
|
|
|
KASSERT(ipxp != NULL, ("ipx_peeraddr: ipxp == NULL"));
|
2005-01-02 15:25:59 +00:00
|
|
|
ipx_setpeeraddr(ipxp, nam);
|
1997-04-05 20:05:11 +00:00
|
|
|
return (0);
|
|
|
|
}
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
ipx_send(so, flags, m, nam, control, td)
|
1997-04-05 20:05:11 +00:00
|
|
|
struct socket *so;
|
|
|
|
int flags;
|
|
|
|
struct mbuf *m;
|
1997-08-16 19:16:27 +00:00
|
|
|
struct sockaddr *nam;
|
1997-04-05 20:05:11 +00:00
|
|
|
struct mbuf *control;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
1997-04-05 20:05:11 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct ipxpcb *ipxp = sotoipxpcb(so);
|
|
|
|
struct ipx_addr laddr;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2006-03-25 17:28:42 +00:00
|
|
|
KASSERT(ipxp != NULL, ("ipxp_send: ipxp == NULL"));
|
2005-01-09 05:13:14 +00:00
|
|
|
/*
|
|
|
|
* Attempt to only acquire the necessary locks: if the socket is
|
|
|
|
* already connected, we don't need to hold the IPX list lock to be
|
|
|
|
* used by ipx_pcbconnect() and ipx_pcbdisconnect(), just the IPX
|
|
|
|
* pcb lock.
|
|
|
|
*/
|
1997-05-10 09:58:58 +00:00
|
|
|
if (nam != NULL) {
|
2005-01-09 05:13:14 +00:00
|
|
|
IPX_LIST_LOCK();
|
|
|
|
IPX_LOCK(ipxp);
|
1997-04-05 20:05:11 +00:00
|
|
|
laddr = ipxp->ipxp_laddr;
|
|
|
|
if (!ipx_nullhost(ipxp->ipxp_faddr)) {
|
2005-01-09 05:13:14 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
|
|
|
IPX_LIST_UNLOCK();
|
1997-04-05 20:05:11 +00:00
|
|
|
error = EISCONN;
|
|
|
|
goto send_release;
|
|
|
|
}
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
1997-04-05 20:05:11 +00:00
|
|
|
* Must block input while temporarily connected.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
error = ipx_pcbconnect(ipxp, nam, td);
|
1997-04-05 20:05:11 +00:00
|
|
|
if (error) {
|
2005-01-09 05:13:14 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
|
|
|
IPX_LIST_UNLOCK();
|
1997-04-05 20:05:11 +00:00
|
|
|
goto send_release;
|
|
|
|
}
|
|
|
|
} else {
|
2005-01-09 05:13:14 +00:00
|
|
|
IPX_LOCK(ipxp);
|
1997-04-05 20:05:11 +00:00
|
|
|
if (ipx_nullhost(ipxp->ipxp_faddr)) {
|
2005-01-09 05:13:14 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
1997-04-05 20:05:11 +00:00
|
|
|
error = ENOTCONN;
|
|
|
|
goto send_release;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
error = ipx_output(ipxp, m);
|
|
|
|
m = NULL;
|
1997-05-10 09:58:58 +00:00
|
|
|
if (nam != NULL) {
|
1997-04-05 20:05:11 +00:00
|
|
|
ipx_pcbdisconnect(ipxp);
|
1999-02-06 10:48:11 +00:00
|
|
|
ipxp->ipxp_laddr = laddr;
|
2005-01-09 05:13:14 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
|
|
|
IPX_LIST_UNLOCK();
|
|
|
|
} else
|
|
|
|
IPX_UNLOCK(ipxp);
|
1997-04-05 20:05:11 +00:00
|
|
|
|
|
|
|
send_release:
|
1995-10-26 20:31:59 +00:00
|
|
|
if (m != NULL)
|
|
|
|
m_freem(m);
|
|
|
|
return (error);
|
|
|
|
}
|
1996-11-24 08:25:48 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
static int
|
|
|
|
ipx_shutdown(so)
|
|
|
|
struct socket *so;
|
|
|
|
{
|
2006-03-25 17:28:42 +00:00
|
|
|
|
|
|
|
KASSERT(so->so_pcb != NULL, ("ipx_shutdown: so_pcb == NULL"));
|
1997-04-05 20:05:11 +00:00
|
|
|
socantsendmore(so);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
int
|
1997-04-05 20:05:11 +00:00
|
|
|
ipx_sockaddr(so, nam)
|
1995-10-26 20:31:59 +00:00
|
|
|
struct socket *so;
|
1997-08-16 19:16:27 +00:00
|
|
|
struct sockaddr **nam;
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
|
|
|
struct ipxpcb *ipxp = sotoipxpcb(so);
|
|
|
|
|
2006-03-25 17:28:42 +00:00
|
|
|
KASSERT(ipxp != NULL, ("ipx_sockaddr: ipxp == NULL"));
|
2005-01-02 15:25:59 +00:00
|
|
|
ipx_setsockaddr(ipxp, nam);
|
1997-04-05 20:05:11 +00:00
|
|
|
return (0);
|
|
|
|
}
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
ripx_attach(so, proto, td)
|
1997-04-05 20:05:11 +00:00
|
|
|
struct socket *so;
|
|
|
|
int proto;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
1997-04-05 20:05:11 +00:00
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
struct ipxpcb *ipxp = sotoipxpcb(so);
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2006-03-25 17:28:42 +00:00
|
|
|
KASSERT(ipxp == NULL, ("ripx_attach: ipxp != NULL"));
|
2002-04-01 21:31:13 +00:00
|
|
|
if (td != NULL && (error = suser(td)) != 0)
|
1997-05-01 06:21:31 +00:00
|
|
|
return (error);
|
2005-01-09 05:13:14 +00:00
|
|
|
/*
|
|
|
|
* We hold the IPX list lock for the duration as address parameters
|
|
|
|
* of the IPX pcb are changed. Since no one else holds a reference
|
|
|
|
* to the ipxpcb yet, we don't need the ipxpcb lock here.
|
|
|
|
*/
|
|
|
|
IPX_LIST_LOCK();
|
2004-12-30 17:49:40 +00:00
|
|
|
error = ipx_pcballoc(so, &ipxrawpcb_list, td);
|
1997-04-05 20:05:11 +00:00
|
|
|
if (error)
|
2005-01-09 05:13:14 +00:00
|
|
|
goto out;
|
|
|
|
ipxp = sotoipxpcb(so);
|
1997-04-05 20:05:11 +00:00
|
|
|
error = soreserve(so, ipxsendspace, ipxrecvspace);
|
|
|
|
if (error)
|
2005-01-09 05:13:14 +00:00
|
|
|
goto out;
|
1997-04-05 20:05:11 +00:00
|
|
|
ipxp->ipxp_faddr.x_host = ipx_broadhost;
|
|
|
|
ipxp->ipxp_flags = IPXP_RAWIN | IPXP_RAWOUT;
|
2005-01-09 05:13:14 +00:00
|
|
|
out:
|
|
|
|
IPX_LIST_UNLOCK();
|
1995-10-26 20:31:59 +00:00
|
|
|
return (error);
|
|
|
|
}
|