1995-10-26 20:31:59 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1995, Mike Mitchell
|
|
|
|
* Copyright (c) 1984, 1985, 1986, 1987, 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.
|
|
|
|
* 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
|
|
|
|
*
|
1998-08-23 03:07:17 +00:00
|
|
|
* $Id: ipx_usrreq.c,v 1.19 1998/02/09 06:10:25 eivind Exp $
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
|
1997-12-15 20:31:25 +00:00
|
|
|
#include "opt_ipx.h"
|
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1996-11-24 08:25:48 +00:00
|
|
|
#include <sys/kernel.h>
|
1995-10-26 20:31:59 +00:00
|
|
|
#include <sys/mbuf.h>
|
1997-05-01 06:21:31 +00:00
|
|
|
#include <sys/proc.h>
|
1995-10-26 20:31:59 +00:00
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
1996-11-24 08:25:48 +00:00
|
|
|
#include <sys/sysctl.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_pcb.h>
|
|
|
|
#include <netipx/ipx_if.h>
|
|
|
|
#include <netipx/ipx_var.h>
|
1995-10-31 00:38:57 +00:00
|
|
|
#include <netipx/ipx_ip.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, "");
|
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
static int ipx_usr_abort(struct socket *so);
|
1997-05-01 06:21:31 +00:00
|
|
|
static int ipx_attach(struct socket *so, int proto, struct proc *p);
|
1997-08-16 19:16:27 +00:00
|
|
|
static int ipx_bind(struct socket *so, struct sockaddr *nam, struct proc *p);
|
|
|
|
static int ipx_connect(struct socket *so, struct sockaddr *nam,
|
|
|
|
struct proc *p);
|
1997-04-05 20:05:11 +00:00
|
|
|
static int ipx_detach(struct socket *so);
|
|
|
|
static int ipx_disconnect(struct socket *so);
|
|
|
|
static int ipx_send(struct socket *so, int flags, struct mbuf *m,
|
1997-08-16 19:16:27 +00:00
|
|
|
struct sockaddr *addr, struct mbuf *control,
|
|
|
|
struct proc *p);
|
1997-04-05 20:05:11 +00:00
|
|
|
static int ipx_shutdown(struct socket *so);
|
1997-05-01 06:21:31 +00:00
|
|
|
static int ripx_attach(struct socket *so, int proto, struct proc *p);
|
1997-05-10 09:58:58 +00:00
|
|
|
static int ipx_output(struct ipxpcb *ipxp, struct mbuf *m0);
|
1997-04-05 20:05:11 +00:00
|
|
|
|
1997-05-10 09:58:58 +00:00
|
|
|
struct pr_usrreqs ipx_usrreqs = {
|
1997-04-05 20:05:11 +00:00
|
|
|
ipx_usr_abort, pru_accept_notsupp, ipx_attach, ipx_bind,
|
|
|
|
ipx_connect, pru_connect2_notsupp, ipx_control, ipx_detach,
|
|
|
|
ipx_disconnect, pru_listen_notsupp, ipx_peeraddr, pru_rcvd_notsupp,
|
|
|
|
pru_rcvoob_notsupp, ipx_send, pru_sense_null, ipx_shutdown,
|
1997-09-14 03:10:42 +00:00
|
|
|
ipx_sockaddr, sosend, soreceive, sopoll
|
1997-04-05 20:05:11 +00:00
|
|
|
};
|
|
|
|
|
1997-05-10 09:58:58 +00:00
|
|
|
struct pr_usrreqs ripx_usrreqs = {
|
1997-04-05 20:05:11 +00:00
|
|
|
ipx_usr_abort, pru_accept_notsupp, ripx_attach, ipx_bind,
|
|
|
|
ipx_connect, pru_connect2_notsupp, ipx_control, ipx_detach,
|
|
|
|
ipx_disconnect, pru_listen_notsupp, ipx_peeraddr, pru_rcvd_notsupp,
|
|
|
|
pru_rcvoob_notsupp, ipx_send, pru_sense_null, ipx_shutdown,
|
1997-09-14 03:10:42 +00:00
|
|
|
ipx_sockaddr, sosend, soreceive, sopoll
|
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
|
|
|
|
1997-05-10 09:58:58 +00:00
|
|
|
if (ipxp == NULL)
|
1995-10-26 20:31:59 +00:00
|
|
|
panic("No ipxpcb");
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
1997-05-10 09:58:58 +00:00
|
|
|
for (ifa = ifp->if_addrhead.tqh_first; ifa != NULL;
|
1996-12-13 21:29:07 +00:00
|
|
|
ifa = ifa->ifa_link.tqe_next) {
|
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;
|
1997-05-10 09:58:58 +00:00
|
|
|
if (!(ipxp->ipxp_flags & IPXP_RAWIN) ) {
|
|
|
|
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
|
|
|
}
|
|
|
|
if (sbappendaddr(&ipxp->ipxp_socket->so_rcv, (struct sockaddr *)&ipx_ipx,
|
1997-05-10 09:58:58 +00:00
|
|
|
m, (struct mbuf *)NULL) == 0)
|
1995-10-26 20:31:59 +00:00
|
|
|
goto bad;
|
|
|
|
sorwakeup(ipxp->ipxp_socket);
|
|
|
|
return;
|
|
|
|
bad:
|
|
|
|
m_freem(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ipx_abort(ipxp)
|
|
|
|
struct ipxpcb *ipxp;
|
|
|
|
{
|
|
|
|
struct socket *so = ipxp->ipxp_socket;
|
|
|
|
|
|
|
|
ipx_pcbdisconnect(ipxp);
|
|
|
|
soisdisconnected(so);
|
|
|
|
}
|
1997-05-10 09:58:58 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
/*
|
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 mbuf *m;
|
|
|
|
register struct ipx *ipx;
|
|
|
|
register struct socket *so;
|
|
|
|
register int len = 0;
|
|
|
|
register struct route *ro;
|
|
|
|
struct mbuf *mprev = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (len & 1) {
|
|
|
|
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);
|
|
|
|
|
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 {
|
1997-05-10 09:58:58 +00:00
|
|
|
M_PREPEND(m, sizeof(struct ipx), M_DONTWAIT);
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (ipxcksum) {
|
|
|
|
ipx->ipx_sum = 0;
|
|
|
|
len = ((len - 1) | 1) + 1;
|
|
|
|
ipx->ipx_sum = ipx_cksum(m, len);
|
|
|
|
} else
|
|
|
|
ipx->ipx_sum = 0xffff;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Output datagram.
|
|
|
|
*/
|
|
|
|
so = ipxp->ipxp_socket;
|
|
|
|
if (so->so_options & SO_DONTROUTE)
|
1997-05-10 09:58:58 +00:00
|
|
|
return (ipx_outputfl(m, (struct route *)NULL,
|
1995-10-26 20:31:59 +00:00
|
|
|
(so->so_options & SO_BROADCAST) | IPX_ROUTETOIF));
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* 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 */
|
|
|
|
return (ipx_outputfl(m, ro, so->so_options & SO_BROADCAST));
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
register struct mbuf *m;
|
|
|
|
struct ipxpcb *ipxp = sotoipxpcb(so);
|
1998-08-23 03:07:17 +00:00
|
|
|
int mask, error, optval;
|
|
|
|
short soptval;
|
|
|
|
struct ipx ioptval;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1998-08-23 03:07:17 +00:00
|
|
|
error = 0;
|
1995-10-26 20:31:59 +00:00
|
|
|
if (ipxp == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
case SO_HEADERS_ON_OUTPUT:
|
|
|
|
mask = IPXP_RAWOUT;
|
|
|
|
get_flags:
|
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;
|
|
|
|
ioptval.ipx_pt = ipxp->ipxp_dpt;
|
|
|
|
ioptval.ipx_dna = ipxp->ipxp_faddr;
|
|
|
|
ioptval.ipx_sna = ipxp->ipxp_laddr;
|
|
|
|
error = sooptcopyout(sopt, &soptval, sizeof soptval);
|
1995-10-26 20:31:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SO_SEQNO:
|
1998-08-23 03:07:17 +00:00
|
|
|
error = sooptcopyout(sopt, &ipx_pexseq,
|
|
|
|
sizeof ipx_pexseq);
|
|
|
|
ipx_pexseq++;
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
if (optval)
|
|
|
|
ipxp->ipxp_flags |= mask;
|
|
|
|
else
|
|
|
|
ipxp->ipxp_flags &= ~mask;
|
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;
|
|
|
|
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 */
|
1997-12-15 20:31:25 +00:00
|
|
|
#ifdef IPTUNNEL
|
|
|
|
#if 0
|
|
|
|
case SO_IPXTUNNEL_ROUTE:
|
1998-08-23 03:07:17 +00:00
|
|
|
error = ipxtun_route(so, sopt);
|
1995-10-26 20:31:59 +00:00
|
|
|
break;
|
1997-12-15 20:31:25 +00:00
|
|
|
#endif
|
1995-10-26 20:31:59 +00:00
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
static int
|
|
|
|
ipx_usr_abort(so)
|
1995-10-26 20:31:59 +00:00
|
|
|
struct socket *so;
|
|
|
|
{
|
1997-04-05 20:05:11 +00:00
|
|
|
int s;
|
1995-10-26 20:31:59 +00:00
|
|
|
struct ipxpcb *ipxp = sotoipxpcb(so);
|
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
s = splnet();
|
|
|
|
ipx_pcbdetach(ipxp);
|
|
|
|
splx(s);
|
|
|
|
sofree(so);
|
|
|
|
soisdisconnected(so);
|
|
|
|
return (0);
|
|
|
|
}
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
static int
|
1997-05-01 06:21:31 +00:00
|
|
|
ipx_attach(so, proto, p)
|
1997-04-05 20:05:11 +00:00
|
|
|
struct socket *so;
|
|
|
|
int proto;
|
1997-05-01 06:21:31 +00:00
|
|
|
struct proc *p;
|
1997-04-05 20:05:11 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
int s;
|
|
|
|
struct ipxpcb *ipxp = sotoipxpcb(so);
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
if (ipxp != NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
s = splnet();
|
1997-05-01 06:21:31 +00:00
|
|
|
error = ipx_pcballoc(so, &ipxpcb, p);
|
1997-04-05 20:05:11 +00:00
|
|
|
splx(s);
|
|
|
|
if (error == 0)
|
|
|
|
error = soreserve(so, ipxsendspace, ipxrecvspace);
|
|
|
|
return (error);
|
|
|
|
}
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
static int
|
1997-05-01 06:21:31 +00:00
|
|
|
ipx_bind(so, nam, p)
|
1997-04-05 20:05:11 +00:00
|
|
|
struct socket *so;
|
1997-08-16 19:16:27 +00:00
|
|
|
struct sockaddr *nam;
|
1997-05-01 06:21:31 +00:00
|
|
|
struct proc *p;
|
1997-04-05 20:05:11 +00:00
|
|
|
{
|
|
|
|
struct ipxpcb *ipxp = sotoipxpcb(so);
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-05-01 06:21:31 +00:00
|
|
|
return (ipx_pcbbind(ipxp, nam, p));
|
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
|
1997-05-01 06:21:31 +00:00
|
|
|
ipx_connect(so, nam, p)
|
1997-04-05 20:05:11 +00:00
|
|
|
struct socket *so;
|
1997-08-16 19:16:27 +00:00
|
|
|
struct sockaddr *nam;
|
1997-05-01 06:21:31 +00:00
|
|
|
struct proc *p;
|
1997-04-05 20:05:11 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
int s;
|
|
|
|
struct ipxpcb *ipxp = sotoipxpcb(so);
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
if (!ipx_nullhost(ipxp->ipxp_faddr))
|
|
|
|
return (EISCONN);
|
|
|
|
s = splnet();
|
1997-05-01 06:21:31 +00:00
|
|
|
error = ipx_pcbconnect(ipxp, nam, p);
|
1997-04-05 20:05:11 +00:00
|
|
|
splx(s);
|
|
|
|
if (error == 0)
|
|
|
|
soisconnected(so);
|
|
|
|
return (error);
|
|
|
|
}
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
static int
|
|
|
|
ipx_detach(so)
|
|
|
|
struct socket *so;
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
struct ipxpcb *ipxp = sotoipxpcb(so);
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
if (ipxp == NULL)
|
|
|
|
return (ENOTCONN);
|
|
|
|
s = splnet();
|
|
|
|
ipx_pcbdetach(ipxp);
|
|
|
|
splx(s);
|
|
|
|
return (0);
|
|
|
|
}
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
static int
|
|
|
|
ipx_disconnect(so)
|
|
|
|
struct socket *so;
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
struct ipxpcb *ipxp = sotoipxpcb(so);
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
if (ipx_nullhost(ipxp->ipxp_faddr))
|
|
|
|
return (ENOTCONN);
|
|
|
|
s = splnet();
|
|
|
|
ipx_pcbdisconnect(ipxp);
|
|
|
|
splx(s);
|
|
|
|
soisdisconnected(so);
|
|
|
|
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
|
|
|
|
1997-08-16 19:16:27 +00:00
|
|
|
ipx_setpeeraddr(ipxp, nam); /* XXX what if alloc fails? */
|
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
|
1997-05-01 06:21:31 +00:00
|
|
|
ipx_send(so, flags, m, nam, control, p)
|
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;
|
1997-05-01 06:21:31 +00:00
|
|
|
struct proc *p;
|
1997-04-05 20:05:11 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct ipxpcb *ipxp = sotoipxpcb(so);
|
|
|
|
struct ipx_addr laddr;
|
|
|
|
int s = 0;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-05-10 09:58:58 +00:00
|
|
|
if (nam != NULL) {
|
1997-04-05 20:05:11 +00:00
|
|
|
laddr = ipxp->ipxp_laddr;
|
|
|
|
if (!ipx_nullhost(ipxp->ipxp_faddr)) {
|
|
|
|
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
|
|
|
*/
|
1997-04-05 20:05:11 +00:00
|
|
|
s = splnet();
|
1997-05-01 06:21:31 +00:00
|
|
|
error = ipx_pcbconnect(ipxp, nam, p);
|
1997-04-05 20:05:11 +00:00
|
|
|
if (error) {
|
|
|
|
splx(s);
|
|
|
|
goto send_release;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ipx_nullhost(ipxp->ipxp_faddr)) {
|
|
|
|
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);
|
|
|
|
splx(s);
|
|
|
|
ipxp->ipxp_laddr.x_host = laddr.x_host;
|
|
|
|
ipxp->ipxp_laddr.x_port = laddr.x_port;
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
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;
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
1997-08-16 19:16:27 +00:00
|
|
|
ipx_setsockaddr(ipxp, nam); /* XXX what if alloc fails? */
|
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
|
1997-05-01 06:21:31 +00:00
|
|
|
ripx_attach(so, proto, p)
|
1997-04-05 20:05:11 +00:00
|
|
|
struct socket *so;
|
|
|
|
int proto;
|
1997-05-01 06:21:31 +00:00
|
|
|
struct proc *p;
|
1997-04-05 20:05:11 +00:00
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
int s;
|
|
|
|
struct ipxpcb *ipxp = sotoipxpcb(so);
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-05-10 09:58:58 +00:00
|
|
|
if (p != NULL && (error = suser(p->p_ucred, &p->p_acflag)) != 0)
|
1997-05-01 06:21:31 +00:00
|
|
|
return (error);
|
1997-04-05 20:05:11 +00:00
|
|
|
s = splnet();
|
1997-05-01 06:21:31 +00:00
|
|
|
error = ipx_pcballoc(so, &ipxrawpcb, p);
|
1997-04-05 20:05:11 +00:00
|
|
|
splx(s);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
error = soreserve(so, ipxsendspace, ipxrecvspace);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
ipxp = sotoipxpcb(so);
|
|
|
|
ipxp->ipxp_faddr.x_host = ipx_broadhost;
|
|
|
|
ipxp->ipxp_flags = IPXP_RAWIN | IPXP_RAWOUT;
|
1995-10-26 20:31:59 +00:00
|
|
|
return (error);
|
|
|
|
}
|