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-24 00:15:58 +00:00
|
|
|
* The Regents of the University of California.
|
2009-05-25 10:25:41 +00:00
|
|
|
* Copyright (c) 2004-2009 Robert N. M. Watson
|
2006-03-24 00:15:58 +00:00
|
|
|
* 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.
|
2007-01-08 22:14:00 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Copyright (c) 1995, Mike Mitchell
|
|
|
|
* 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.
|
1995-10-26 20:31:59 +00:00
|
|
|
* 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
|
|
|
* @(#)spx_usrreq.h
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-11 05:37:42 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
#include <sys/param.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/lock.h>
|
1997-09-02 01:19:47 +00:00
|
|
|
#include <sys/malloc.h>
|
1995-10-26 20:31:59 +00:00
|
|
|
#include <sys/mbuf.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/mutex.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>
|
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>
|
|
|
|
#include <sys/systm.h>
|
1995-10-26 20:31:59 +00:00
|
|
|
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <netinet/tcp_fsm.h>
|
|
|
|
|
|
|
|
#include <netipx/ipx.h>
|
|
|
|
#include <netipx/ipx_pcb.h>
|
|
|
|
#include <netipx/ipx_var.h>
|
|
|
|
#include <netipx/spx.h>
|
2002-04-30 01:54:54 +00:00
|
|
|
#include <netipx/spx_debug.h>
|
1995-10-26 20:31:59 +00:00
|
|
|
#include <netipx/spx_timer.h>
|
|
|
|
#include <netipx/spx_var.h>
|
|
|
|
|
2009-06-20 17:44:04 +00:00
|
|
|
#include <security/mac/mac_framework.h>
|
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
|
|
|
* SPX protocol implementation.
|
|
|
|
*/
|
2006-03-24 00:26:25 +00:00
|
|
|
static struct mtx spx_mtx; /* Protects only spx_iss. */
|
1998-02-09 06:11:36 +00:00
|
|
|
static u_short spx_iss;
|
2009-05-25 09:28:54 +00:00
|
|
|
u_short spx_newchecks[50];
|
1998-02-09 06:11:36 +00:00
|
|
|
static int spx_hardnosed;
|
|
|
|
static int traceallspxs = 0;
|
2009-05-25 09:28:54 +00:00
|
|
|
struct spx_istat spx_istat;
|
1997-05-10 09:58:58 +00:00
|
|
|
|
2006-03-24 00:26:25 +00:00
|
|
|
#define SPX_LOCK_INIT() mtx_init(&spx_mtx, "spx_mtx", NULL, MTX_DEF)
|
|
|
|
#define SPX_LOCK() mtx_lock(&spx_mtx)
|
|
|
|
#define SPX_UNLOCK() mtx_unlock(&spx_mtx)
|
|
|
|
|
2004-07-12 19:35:29 +00:00
|
|
|
static const int spx_backoff[SPX_MAXRXTSHIFT+1] =
|
1997-05-10 09:58:58 +00:00
|
|
|
{ 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 };
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2005-01-09 05:25:02 +00:00
|
|
|
static void spx_close(struct spxpcb *cb);
|
|
|
|
static void spx_disconnect(struct spxpcb *cb);
|
|
|
|
static void spx_drop(struct spxpcb *cb, int errno);
|
1997-05-10 09:58:58 +00:00
|
|
|
static void spx_setpersist(struct spxpcb *cb);
|
|
|
|
static void spx_template(struct spxpcb *cb);
|
2006-03-25 17:28:42 +00:00
|
|
|
static void spx_timers(struct spxpcb *cb, int timer);
|
2005-01-09 05:25:02 +00:00
|
|
|
static void spx_usrclosed(struct spxpcb *cb);
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2006-04-01 15:15:05 +00:00
|
|
|
static void spx_usr_abort(struct socket *so);
|
1997-08-16 19:16:27 +00:00
|
|
|
static int spx_accept(struct socket *so, struct sockaddr **nam);
|
2001-09-12 08:38:13 +00:00
|
|
|
static int spx_attach(struct socket *so, int proto, struct thread *td);
|
|
|
|
static int spx_bind(struct socket *so, struct sockaddr *nam, struct thread *td);
|
2006-07-21 17:11:15 +00:00
|
|
|
static void spx_usr_close(struct socket *so);
|
1997-08-16 19:16:27 +00:00
|
|
|
static int spx_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 spx_detach(struct socket *so);
|
2006-03-25 17:28:42 +00:00
|
|
|
static void spx_pcbdetach(struct ipxpcb *ipxp);
|
1997-04-05 20:05:11 +00:00
|
|
|
static int spx_usr_disconnect(struct socket *so);
|
2005-10-30 19:44:40 +00:00
|
|
|
static int spx_listen(struct socket *so, int backlog, struct thread *td);
|
1997-04-05 20:05:11 +00:00
|
|
|
static int spx_rcvd(struct socket *so, int flags);
|
|
|
|
static int spx_rcvoob(struct socket *so, struct mbuf *m, int flags);
|
|
|
|
static int spx_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 spx_shutdown(struct socket *so);
|
2001-09-12 08:38:13 +00:00
|
|
|
static int spx_sp_attach(struct socket *so, int proto, struct thread *td);
|
1997-04-05 20:05:11 +00:00
|
|
|
|
|
|
|
struct pr_usrreqs spx_usrreqs = {
|
2004-11-08 14:44:54 +00:00
|
|
|
.pru_abort = spx_usr_abort,
|
|
|
|
.pru_accept = spx_accept,
|
|
|
|
.pru_attach = spx_attach,
|
|
|
|
.pru_bind = spx_bind,
|
|
|
|
.pru_connect = spx_connect,
|
|
|
|
.pru_control = ipx_control,
|
|
|
|
.pru_detach = spx_detach,
|
|
|
|
.pru_disconnect = spx_usr_disconnect,
|
|
|
|
.pru_listen = spx_listen,
|
|
|
|
.pru_peeraddr = ipx_peeraddr,
|
|
|
|
.pru_rcvd = spx_rcvd,
|
|
|
|
.pru_rcvoob = spx_rcvoob,
|
|
|
|
.pru_send = spx_send,
|
|
|
|
.pru_shutdown = spx_shutdown,
|
|
|
|
.pru_sockaddr = ipx_sockaddr,
|
2006-07-21 17:11:15 +00:00
|
|
|
.pru_close = spx_usr_close,
|
1997-04-05 20:05:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct pr_usrreqs spx_usrreq_sps = {
|
2004-11-08 14:44:54 +00:00
|
|
|
.pru_abort = spx_usr_abort,
|
|
|
|
.pru_accept = spx_accept,
|
|
|
|
.pru_attach = spx_sp_attach,
|
|
|
|
.pru_bind = spx_bind,
|
|
|
|
.pru_connect = spx_connect,
|
|
|
|
.pru_control = ipx_control,
|
|
|
|
.pru_detach = spx_detach,
|
|
|
|
.pru_disconnect = spx_usr_disconnect,
|
|
|
|
.pru_listen = spx_listen,
|
|
|
|
.pru_peeraddr = ipx_peeraddr,
|
|
|
|
.pru_rcvd = spx_rcvd,
|
|
|
|
.pru_rcvoob = spx_rcvoob,
|
|
|
|
.pru_send = spx_send,
|
|
|
|
.pru_shutdown = spx_shutdown,
|
|
|
|
.pru_sockaddr = ipx_sockaddr,
|
2006-07-21 17:11:15 +00:00
|
|
|
.pru_close = spx_usr_close,
|
1997-04-05 20:05:11 +00:00
|
|
|
};
|
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
void
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_init(void)
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
|
|
|
|
2006-03-24 00:26:25 +00:00
|
|
|
SPX_LOCK_INIT();
|
1995-10-26 20:31:59 +00:00
|
|
|
spx_iss = 1; /* WRONG !! should fish it out of TODR */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_input(struct mbuf *m, struct ipxpcb *ipxp)
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
2006-03-24 00:15:58 +00:00
|
|
|
struct spxpcb *cb;
|
|
|
|
struct spx *si = mtod(m, struct spx *);
|
|
|
|
struct socket *so;
|
2006-03-23 19:58:12 +00:00
|
|
|
struct spx spx_savesi;
|
1995-10-26 20:31:59 +00:00
|
|
|
int dropsocket = 0;
|
|
|
|
short ostate = 0;
|
|
|
|
|
|
|
|
spxstat.spxs_rcvtotal++;
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(ipxp != NULL, ("spx_input: ipxpcb == NULL"));
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2005-01-09 05:31:16 +00:00
|
|
|
/*
|
|
|
|
* spx_input() assumes that the caller will hold both the pcb list
|
|
|
|
* lock and also the ipxp lock. spx_input() will release both before
|
|
|
|
* returning, and may in fact trade in the ipxp lock for another pcb
|
|
|
|
* lock following sonewconn().
|
|
|
|
*/
|
|
|
|
IPX_LIST_LOCK_ASSERT();
|
|
|
|
IPX_LOCK_ASSERT(ipxp);
|
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
cb = ipxtospxpcb(ipxp);
|
2006-03-25 17:28:42 +00:00
|
|
|
KASSERT(cb != NULL, ("spx_input: cb == NULL"));
|
|
|
|
|
|
|
|
if (ipxp->ipxp_flags & IPXP_DROPPED)
|
|
|
|
goto drop;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
|
|
|
if (m->m_len < sizeof(*si)) {
|
1997-05-10 09:58:58 +00:00
|
|
|
if ((m = m_pullup(m, sizeof(*si))) == NULL) {
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
|
|
|
IPX_LIST_UNLOCK();
|
1995-10-26 20:31:59 +00:00
|
|
|
spxstat.spxs_rcvshort++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
si = mtod(m, struct spx *);
|
|
|
|
}
|
|
|
|
si->si_seq = ntohs(si->si_seq);
|
|
|
|
si->si_ack = ntohs(si->si_ack);
|
|
|
|
si->si_alo = ntohs(si->si_alo);
|
|
|
|
|
|
|
|
so = ipxp->ipxp_socket;
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(so != NULL, ("spx_input: so == NULL"));
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2009-06-20 23:38:21 +00:00
|
|
|
#ifdef MAC
|
|
|
|
if (mac_socket_check_deliver(so, m) != 0)
|
|
|
|
goto drop;
|
|
|
|
#endif
|
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
if (so->so_options & SO_DEBUG || traceallspxs) {
|
|
|
|
ostate = cb->s_state;
|
|
|
|
spx_savesi = *si;
|
|
|
|
}
|
|
|
|
if (so->so_options & SO_ACCEPTCONN) {
|
|
|
|
struct spxpcb *ocb = cb;
|
|
|
|
|
|
|
|
so = sonewconn(so, 0);
|
2006-03-24 13:58:23 +00:00
|
|
|
if (so == NULL)
|
1995-10-26 20:31:59 +00:00
|
|
|
goto drop;
|
2006-03-24 13:58:23 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
|
|
|
* This is ugly, but ....
|
|
|
|
*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Mark socket as temporary until we're committed to keeping
|
|
|
|
* it. The code at ``drop'' and ``dropwithreset'' check the
|
|
|
|
* flag dropsocket to see if the temporary socket created
|
|
|
|
* here should be discarded. We mark the socket as
|
|
|
|
* discardable until we're committed to it below in
|
|
|
|
* TCPS_LISTEN.
|
2006-03-25 17:28:42 +00:00
|
|
|
*
|
|
|
|
* XXXRW: In the new world order of real kernel parallelism,
|
|
|
|
* temporarily allocating the socket when we're "not sure"
|
|
|
|
* seems like a bad idea, as we might race to remove it if
|
|
|
|
* the listen socket is closed...?
|
|
|
|
*
|
|
|
|
* We drop the lock of the listen socket ipxp, and acquire
|
|
|
|
* the lock of the new socket ippx.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
dropsocket++;
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
1995-10-26 20:31:59 +00:00
|
|
|
ipxp = (struct ipxpcb *)so->so_pcb;
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LOCK(ipxp);
|
1995-10-26 20:31:59 +00:00
|
|
|
ipxp->ipxp_laddr = si->si_dna;
|
|
|
|
cb = ipxtospxpcb(ipxp);
|
|
|
|
cb->s_mtu = ocb->s_mtu; /* preserve sockopts */
|
|
|
|
cb->s_flags = ocb->s_flags; /* preserve sockopts */
|
|
|
|
cb->s_flags2 = ocb->s_flags2; /* preserve sockopts */
|
|
|
|
cb->s_state = TCPS_LISTEN;
|
2002-05-31 11:52:35 +00:00
|
|
|
}
|
2006-03-24 13:58:23 +00:00
|
|
|
IPX_LOCK_ASSERT(ipxp);
|
1995-10-26 20:31:59 +00:00
|
|
|
|
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Packet received on connection. Reset idle time and keep-alive
|
|
|
|
* timer.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
cb->s_idle = 0;
|
|
|
|
cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
|
|
|
|
|
|
|
|
switch (cb->s_state) {
|
|
|
|
case TCPS_LISTEN:{
|
1997-08-16 19:16:27 +00:00
|
|
|
struct sockaddr_ipx *sipx, ssipx;
|
1995-10-26 20:31:59 +00:00
|
|
|
struct ipx_addr laddr;
|
|
|
|
|
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* If somebody here was carying on a conversation and went
|
|
|
|
* away, and his pen pal thinks he can still talk, we get the
|
|
|
|
* misdirected packet.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
if (spx_hardnosed && (si->si_did != 0 || si->si_seq != 0)) {
|
|
|
|
spx_istat.gonawy++;
|
|
|
|
goto dropwithreset;
|
|
|
|
}
|
1997-08-16 19:16:27 +00:00
|
|
|
sipx = &ssipx;
|
|
|
|
bzero(sipx, sizeof *sipx);
|
1995-10-26 20:31:59 +00:00
|
|
|
sipx->sipx_len = sizeof(*sipx);
|
|
|
|
sipx->sipx_family = AF_IPX;
|
|
|
|
sipx->sipx_addr = si->si_sna;
|
|
|
|
laddr = ipxp->ipxp_laddr;
|
|
|
|
if (ipx_nullhost(laddr))
|
|
|
|
ipxp->ipxp_laddr = si->si_dna;
|
2002-02-07 20:58:47 +00:00
|
|
|
if (ipx_pcbconnect(ipxp, (struct sockaddr *)sipx, &thread0)) {
|
1995-10-26 20:31:59 +00:00
|
|
|
ipxp->ipxp_laddr = laddr;
|
|
|
|
spx_istat.noconn++;
|
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
spx_template(cb);
|
|
|
|
dropsocket = 0; /* committed to socket */
|
|
|
|
cb->s_did = si->si_sid;
|
|
|
|
cb->s_rack = si->si_ack;
|
|
|
|
cb->s_ralo = si->si_alo;
|
|
|
|
#define THREEWAYSHAKE
|
|
|
|
#ifdef THREEWAYSHAKE
|
|
|
|
cb->s_state = TCPS_SYN_RECEIVED;
|
|
|
|
cb->s_force = 1 + SPXT_KEEP;
|
|
|
|
spxstat.spxs_accepts++;
|
|
|
|
cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
|
|
|
|
}
|
|
|
|
break;
|
2006-03-24 13:58:23 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
case TCPS_SYN_RECEIVED: {
|
2006-03-24 13:58:23 +00:00
|
|
|
/*
|
|
|
|
* This state means that we have heard a response to our
|
|
|
|
* acceptance of their connection. It is probably logically
|
|
|
|
* unnecessary in this implementation.
|
|
|
|
*/
|
1997-05-10 09:58:58 +00:00
|
|
|
if (si->si_did != cb->s_sid) {
|
1995-10-26 20:31:59 +00:00
|
|
|
spx_istat.wrncon++;
|
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
ipxp->ipxp_fport = si->si_sport;
|
|
|
|
cb->s_timer[SPXT_REXMT] = 0;
|
|
|
|
cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
|
|
|
|
soisconnected(so);
|
|
|
|
cb->s_state = TCPS_ESTABLISHED;
|
|
|
|
spxstat.spxs_accepts++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TCPS_SYN_SENT:
|
2006-03-24 13:58:23 +00:00
|
|
|
/*
|
|
|
|
* This state means that we have gotten a response to our
|
|
|
|
* attempt to establish a connection. We fill in the data
|
|
|
|
* from the other side, telling us which port to respond to,
|
|
|
|
* instead of the well-known one we might have sent to in the
|
|
|
|
* first place. We also require that this is a response to
|
|
|
|
* our connection id.
|
|
|
|
*/
|
1997-05-10 09:58:58 +00:00
|
|
|
if (si->si_did != cb->s_sid) {
|
1995-10-26 20:31:59 +00:00
|
|
|
spx_istat.notme++;
|
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
spxstat.spxs_connects++;
|
|
|
|
cb->s_did = si->si_sid;
|
|
|
|
cb->s_rack = si->si_ack;
|
|
|
|
cb->s_ralo = si->si_alo;
|
|
|
|
cb->s_dport = ipxp->ipxp_fport = si->si_sport;
|
|
|
|
cb->s_timer[SPXT_REXMT] = 0;
|
|
|
|
cb->s_flags |= SF_ACKNOW;
|
|
|
|
soisconnected(so);
|
|
|
|
cb->s_state = TCPS_ESTABLISHED;
|
2008-05-29 06:50:25 +00:00
|
|
|
|
2006-03-24 13:58:23 +00:00
|
|
|
/*
|
|
|
|
* Use roundtrip time of connection request for initial rtt.
|
|
|
|
*/
|
1995-10-26 20:31:59 +00:00
|
|
|
if (cb->s_rtt) {
|
|
|
|
cb->s_srtt = cb->s_rtt << 3;
|
|
|
|
cb->s_rttvar = cb->s_rtt << 1;
|
|
|
|
SPXT_RANGESET(cb->s_rxtcur,
|
|
|
|
((cb->s_srtt >> 2) + cb->s_rttvar) >> 1,
|
|
|
|
SPXTV_MIN, SPXTV_REXMTMAX);
|
|
|
|
cb->s_rtt = 0;
|
|
|
|
}
|
|
|
|
}
|
2006-03-24 13:58:23 +00:00
|
|
|
|
2002-05-31 11:52:35 +00:00
|
|
|
if (so->so_options & SO_DEBUG || traceallspxs)
|
1995-10-26 20:31:59 +00:00
|
|
|
spx_trace(SA_INPUT, (u_char)ostate, cb, &spx_savesi, 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
|
|
|
|
2009-06-20 18:24:25 +00:00
|
|
|
if (spx_reass(cb, m, si))
|
1997-05-10 09:58:58 +00:00
|
|
|
m_freem(m);
|
1995-10-26 20:31:59 +00:00
|
|
|
if (cb->s_force || (cb->s_flags & (SF_ACKNOW|SF_WIN|SF_RXT)))
|
2005-01-02 14:03:47 +00:00
|
|
|
spx_output(cb, NULL);
|
1995-10-26 20:31:59 +00:00
|
|
|
cb->s_flags &= ~(SF_WIN|SF_RXT);
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
|
|
|
IPX_LIST_UNLOCK();
|
1995-10-26 20:31:59 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
dropwithreset:
|
2006-03-24 13:58:23 +00:00
|
|
|
IPX_LOCK_ASSERT(ipxp);
|
2006-03-27 00:08:32 +00:00
|
|
|
if (cb == NULL || (cb->s_ipxpcb->ipxp_socket->so_options & SO_DEBUG ||
|
2006-03-25 17:28:42 +00:00
|
|
|
traceallspxs))
|
|
|
|
spx_trace(SA_DROP, (u_char)ostate, cb, &spx_savesi, 0);
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
2004-06-20 21:47:12 +00:00
|
|
|
if (dropsocket) {
|
|
|
|
struct socket *head;
|
|
|
|
ACCEPT_LOCK();
|
|
|
|
KASSERT((so->so_qstate & SQ_INCOMP) != 0,
|
|
|
|
("spx_input: nascent socket not SQ_INCOMP on soabort()"));
|
|
|
|
head = so->so_head;
|
|
|
|
TAILQ_REMOVE(&head->so_incomp, so, so_list);
|
|
|
|
head->so_incqlen--;
|
|
|
|
so->so_qstate &= ~SQ_INCOMP;
|
|
|
|
so->so_head = NULL;
|
|
|
|
ACCEPT_UNLOCK();
|
1997-05-10 09:58:58 +00:00
|
|
|
soabort(so);
|
2004-06-20 21:47:12 +00:00
|
|
|
}
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LIST_UNLOCK();
|
2008-05-26 22:54:38 +00:00
|
|
|
m_freem(m);
|
1995-10-26 20:31:59 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
drop:
|
2006-03-24 13:58:23 +00:00
|
|
|
IPX_LOCK_ASSERT(ipxp);
|
2006-03-25 17:28:42 +00:00
|
|
|
if (cb->s_ipxpcb->ipxp_socket->so_options & SO_DEBUG || traceallspxs)
|
1995-10-26 20:31:59 +00:00
|
|
|
spx_trace(SA_DROP, (u_char)ostate, cb, &spx_savesi, 0);
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
|
|
|
IPX_LIST_UNLOCK();
|
1995-10-26 20:31:59 +00:00
|
|
|
m_freem(m);
|
|
|
|
}
|
|
|
|
|
2009-05-25 11:50:58 +00:00
|
|
|
void
|
|
|
|
spx_ctlinput(int cmd, struct sockaddr *arg_as_sa, void *dummy)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Currently, nothing. */
|
|
|
|
}
|
|
|
|
|
2009-05-25 09:28:54 +00:00
|
|
|
int
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_output(struct spxpcb *cb, struct mbuf *m0)
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
|
|
|
struct socket *so = cb->s_ipxpcb->ipxp_socket;
|
2009-05-25 13:32:54 +00:00
|
|
|
struct mbuf *m = NULL;
|
2006-03-24 00:15:58 +00:00
|
|
|
struct spx *si = NULL;
|
|
|
|
struct sockbuf *sb = &so->so_snd;
|
1995-10-26 20:31:59 +00:00
|
|
|
int len = 0, win, rcv_win;
|
|
|
|
short span, off, recordp = 0;
|
|
|
|
u_short alo;
|
|
|
|
int error = 0, sendalot;
|
|
|
|
#ifdef notdef
|
|
|
|
int idle;
|
|
|
|
#endif
|
|
|
|
struct mbuf *mprev;
|
|
|
|
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LOCK_ASSERT(cb->s_ipxpcb);
|
|
|
|
|
1997-05-10 09:58:58 +00:00
|
|
|
if (m0 != NULL) {
|
1995-10-26 20:31:59 +00:00
|
|
|
int mtu = cb->s_mtu;
|
|
|
|
int datalen;
|
2006-03-24 13:58:23 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
|
|
|
* Make sure that packet isn't too big.
|
|
|
|
*/
|
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;
|
|
|
|
if (m->m_flags & M_EOR)
|
|
|
|
recordp = 1;
|
|
|
|
}
|
|
|
|
datalen = (cb->s_flags & SF_HO) ?
|
1997-05-10 09:58:58 +00:00
|
|
|
len - sizeof(struct spxhdr) : len;
|
1995-10-26 20:31:59 +00:00
|
|
|
if (datalen > mtu) {
|
|
|
|
if (cb->s_flags & SF_PI) {
|
|
|
|
m_freem(m0);
|
|
|
|
return (EMSGSIZE);
|
|
|
|
} else {
|
|
|
|
int oldEM = cb->s_cc & SPX_EM;
|
|
|
|
|
|
|
|
cb->s_cc &= ~SPX_EM;
|
|
|
|
while (len > mtu) {
|
2012-12-05 08:04:20 +00:00
|
|
|
m = m_copym(m0, 0, mtu, M_NOWAIT);
|
2006-03-27 00:48:21 +00:00
|
|
|
if (m == NULL) {
|
|
|
|
cb->s_cc |= oldEM;
|
|
|
|
m_freem(m0);
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
1995-10-26 20:31:59 +00:00
|
|
|
if (cb->s_flags & SF_NEWCALL) {
|
|
|
|
struct mbuf *mm = m;
|
|
|
|
spx_newchecks[7]++;
|
1997-05-10 09:58:58 +00:00
|
|
|
while (mm != NULL) {
|
1995-10-26 20:31:59 +00:00
|
|
|
mm->m_flags &= ~M_EOR;
|
|
|
|
mm = mm->m_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
error = spx_output(cb, m);
|
|
|
|
if (error) {
|
|
|
|
cb->s_cc |= oldEM;
|
|
|
|
m_freem(m0);
|
1997-05-10 09:58:58 +00:00
|
|
|
return (error);
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
|
|
|
m_adj(m0, mtu);
|
|
|
|
len -= mtu;
|
|
|
|
}
|
|
|
|
cb->s_cc |= oldEM;
|
|
|
|
}
|
|
|
|
}
|
2006-03-24 13:58:23 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
|
|
|
* Force length even, by adding a "garbage byte" if
|
|
|
|
* necessary.
|
|
|
|
*/
|
|
|
|
if (len & 1) {
|
|
|
|
m = mprev;
|
|
|
|
if (M_TRAILINGSPACE(m) >= 1)
|
|
|
|
m->m_len++;
|
|
|
|
else {
|
2012-12-05 08:04:20 +00:00
|
|
|
struct mbuf *m1 = m_get(M_NOWAIT, 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, u_char *)) = 0;
|
|
|
|
m->m_next = m1;
|
|
|
|
}
|
|
|
|
}
|
2012-12-05 08:04:20 +00:00
|
|
|
m = m_gethdr(M_NOWAIT, MT_DATA);
|
1997-05-10 09:58:58 +00:00
|
|
|
if (m == NULL) {
|
1995-10-26 20:31:59 +00:00
|
|
|
m_freem(m0);
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
2006-03-24 13:58:23 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Fill in mbuf with extended SP header and addresses and
|
|
|
|
* length put into network format.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
1997-05-10 09:58:58 +00:00
|
|
|
MH_ALIGN(m, sizeof(struct spx));
|
|
|
|
m->m_len = sizeof(struct spx);
|
1995-10-26 20:31:59 +00:00
|
|
|
m->m_next = m0;
|
|
|
|
si = mtod(m, struct spx *);
|
2009-05-25 11:50:58 +00:00
|
|
|
si->si_i = cb->s_ipx;
|
1995-10-26 20:31:59 +00:00
|
|
|
si->si_s = cb->s_shdr;
|
|
|
|
if ((cb->s_flags & SF_PI) && (cb->s_flags & SF_HO)) {
|
2006-03-24 00:15:58 +00:00
|
|
|
struct spxhdr *sh;
|
1997-05-10 09:58:58 +00:00
|
|
|
if (m0->m_len < sizeof(*sh)) {
|
1995-10-26 20:31:59 +00:00
|
|
|
if((m0 = m_pullup(m0, sizeof(*sh))) == NULL) {
|
1997-05-10 09:58:58 +00:00
|
|
|
m_free(m);
|
1995-10-26 20:31:59 +00:00
|
|
|
m_freem(m0);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
m->m_next = m0;
|
|
|
|
}
|
|
|
|
sh = mtod(m0, struct spxhdr *);
|
|
|
|
si->si_dt = sh->spx_dt;
|
|
|
|
si->si_cc |= sh->spx_cc & SPX_EM;
|
1997-05-10 09:58:58 +00:00
|
|
|
m0->m_len -= sizeof(*sh);
|
|
|
|
m0->m_data += sizeof(*sh);
|
|
|
|
len -= sizeof(*sh);
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
|
|
|
len += sizeof(*si);
|
|
|
|
if ((cb->s_flags2 & SF_NEWCALL) && recordp) {
|
1997-05-10 09:58:58 +00:00
|
|
|
si->si_cc |= SPX_EM;
|
1995-10-26 20:31:59 +00:00
|
|
|
spx_newchecks[8]++;
|
|
|
|
}
|
|
|
|
if (cb->s_oobflags & SF_SOOB) {
|
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Per jqj@cornell: Make sure OB packets convey
|
|
|
|
* exactly 1 byte. If the packet is 1 byte or
|
|
|
|
* larger, we have already guaranted there to be at
|
|
|
|
* least one garbage byte for the checksum, and extra
|
|
|
|
* bytes shouldn't hurt!
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
if (len > sizeof(*si)) {
|
|
|
|
si->si_cc |= SPX_OB;
|
|
|
|
len = (1 + sizeof(*si));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
si->si_len = htons((u_short)len);
|
|
|
|
m->m_pkthdr.len = ((len - 1) | 1) + 1;
|
2006-03-24 13:58:23 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Queue stuff up for output.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
sbappendrecord(sb, m);
|
|
|
|
cb->s_seq++;
|
|
|
|
}
|
|
|
|
#ifdef notdef
|
|
|
|
idle = (cb->s_smax == (cb->s_rack - 1));
|
|
|
|
#endif
|
|
|
|
again:
|
|
|
|
sendalot = 0;
|
|
|
|
off = cb->s_snxt - cb->s_rack;
|
1997-05-10 09:58:58 +00:00
|
|
|
win = min(cb->s_swnd, (cb->s_cwnd / CUNIT));
|
1995-10-26 20:31:59 +00:00
|
|
|
|
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* If in persist timeout with window of 0, send a probe. Otherwise,
|
2008-05-29 06:50:25 +00:00
|
|
|
* if window is small but non-zero and timer expired, send what we
|
|
|
|
* can and go into transmit state.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
if (cb->s_force == 1 + SPXT_PERSIST) {
|
|
|
|
if (win != 0) {
|
|
|
|
cb->s_timer[SPXT_PERSIST] = 0;
|
|
|
|
cb->s_rxtshift = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
span = cb->s_seq - cb->s_rack;
|
|
|
|
len = min(span, win) - off;
|
|
|
|
|
|
|
|
if (len < 0) {
|
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Window shrank after we went into it. If window shrank to
|
|
|
|
* 0, cancel pending restransmission and pull s_snxt back to
|
|
|
|
* (closed) window. We will enter persist state below. If
|
|
|
|
* the widndow didn't close completely, just wait for an ACK.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
len = 0;
|
|
|
|
if (win == 0) {
|
|
|
|
cb->s_timer[SPXT_REXMT] = 0;
|
|
|
|
cb->s_snxt = cb->s_rack;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (len > 1)
|
|
|
|
sendalot = 1;
|
|
|
|
rcv_win = sbspace(&so->so_rcv);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send if we owe peer an ACK.
|
|
|
|
*/
|
|
|
|
if (cb->s_oobflags & SF_SOOB) {
|
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Must transmit this out of band packet.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
cb->s_oobflags &= ~ SF_SOOB;
|
|
|
|
sendalot = 1;
|
|
|
|
spxstat.spxs_sndurg++;
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
if (cb->s_flags & SF_ACKNOW)
|
|
|
|
goto send;
|
|
|
|
if (cb->s_state < TCPS_ESTABLISHED)
|
|
|
|
goto send;
|
2006-03-24 13:58:23 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Silly window can't happen in spx. Code from TCP deleted.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
if (len)
|
|
|
|
goto send;
|
2006-03-24 13:58:23 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Compare available window to amount of window known to peer (as
|
|
|
|
* advertised window less next expected input.) If the difference is
|
|
|
|
* at least two packets or at least 35% of the mximum possible
|
|
|
|
* window, then want to send a window update to peer.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
if (rcv_win > 0) {
|
|
|
|
u_short delta = 1 + cb->s_alo - cb->s_ack;
|
|
|
|
int adv = rcv_win - (delta * cb->s_mtu);
|
2005-01-02 15:13:59 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
if ((so->so_rcv.sb_cc == 0 && adv >= (2 * cb->s_mtu)) ||
|
|
|
|
(100 * adv / so->so_rcv.sb_hiwat >= 35)) {
|
|
|
|
spxstat.spxs_sndwinup++;
|
|
|
|
cb->s_flags |= SF_ACKNOW;
|
|
|
|
goto send;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2006-03-24 13:58:23 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Many comments from tcp_output.c are appropriate here including ...
|
1995-10-26 20:31:59 +00:00
|
|
|
* If send window is too small, there is data to transmit, and no
|
2006-03-24 13:58:23 +00:00
|
|
|
* retransmit or persist is pending, then go to persist state. If
|
|
|
|
* nothing happens soon, send when timer expires: if window is
|
2008-05-29 06:50:25 +00:00
|
|
|
* non-zero, transmit what we can, otherwise send a probe.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
if (so->so_snd.sb_cc && cb->s_timer[SPXT_REXMT] == 0 &&
|
2006-03-25 17:28:42 +00:00
|
|
|
cb->s_timer[SPXT_PERSIST] == 0) {
|
|
|
|
cb->s_rxtshift = 0;
|
|
|
|
spx_setpersist(cb);
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
2006-03-24 13:58:23 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
|
|
|
* No reason to send a packet, just return.
|
|
|
|
*/
|
|
|
|
cb->s_outx = 1;
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
send:
|
|
|
|
/*
|
|
|
|
* Find requested packet.
|
|
|
|
*/
|
2009-05-25 11:52:33 +00:00
|
|
|
si = NULL;
|
2009-05-25 13:32:54 +00:00
|
|
|
m = NULL;
|
1995-10-26 20:31:59 +00:00
|
|
|
if (len > 0) {
|
|
|
|
cb->s_want = cb->s_snxt;
|
2009-05-25 09:57:18 +00:00
|
|
|
for (m = sb->sb_mb; m != NULL; m = m->m_nextpkt) {
|
1995-10-26 20:31:59 +00:00
|
|
|
si = mtod(m, struct spx *);
|
|
|
|
if (SSEQ_LEQ(cb->s_snxt, si->si_seq))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
found:
|
1997-05-10 09:58:58 +00:00
|
|
|
if (si != NULL) {
|
2009-05-25 13:32:54 +00:00
|
|
|
if (si->si_seq != cb->s_snxt) {
|
|
|
|
spxstat.spxs_sndvoid++;
|
|
|
|
si = NULL;
|
|
|
|
m = NULL;
|
|
|
|
} else
|
|
|
|
cb->s_snxt++;
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-24 13:58:23 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Update window.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
if (rcv_win < 0)
|
|
|
|
rcv_win = 0;
|
|
|
|
alo = cb->s_ack - 1 + (rcv_win / ((short)cb->s_mtu));
|
2005-01-02 15:13:59 +00:00
|
|
|
if (SSEQ_LT(alo, cb->s_alo))
|
1995-10-26 20:31:59 +00:00
|
|
|
alo = cb->s_alo;
|
|
|
|
|
2009-05-25 13:32:54 +00:00
|
|
|
if (m != NULL) {
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Must make a copy of this packet for ipx_output to monkey
|
|
|
|
* with.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
2009-05-25 13:32:54 +00:00
|
|
|
m = m_copy(m, 0, M_COPYALL);
|
2006-03-24 13:58:23 +00:00
|
|
|
if (m == NULL)
|
1995-10-26 20:31:59 +00:00
|
|
|
return (ENOBUFS);
|
|
|
|
si = mtod(m, struct spx *);
|
|
|
|
if (SSEQ_LT(si->si_seq, cb->s_smax))
|
|
|
|
spxstat.spxs_sndrexmitpack++;
|
|
|
|
else
|
|
|
|
spxstat.spxs_sndpack++;
|
|
|
|
} else if (cb->s_force || cb->s_flags & SF_ACKNOW) {
|
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Must send an acknowledgement or a probe.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
if (cb->s_force)
|
|
|
|
spxstat.spxs_sndprobe++;
|
|
|
|
if (cb->s_flags & SF_ACKNOW)
|
|
|
|
spxstat.spxs_sndacks++;
|
2012-12-05 08:04:20 +00:00
|
|
|
m = m_gethdr(M_NOWAIT, MT_DATA);
|
1997-05-10 09:58:58 +00:00
|
|
|
if (m == NULL)
|
1995-10-26 20:31:59 +00:00
|
|
|
return (ENOBUFS);
|
2006-03-24 13:58:23 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Fill in mbuf with extended SP header and addresses and
|
|
|
|
* length put into network format.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
1997-05-10 09:58:58 +00:00
|
|
|
MH_ALIGN(m, sizeof(struct spx));
|
|
|
|
m->m_len = sizeof(*si);
|
|
|
|
m->m_pkthdr.len = sizeof(*si);
|
1995-10-26 20:31:59 +00:00
|
|
|
si = mtod(m, struct spx *);
|
2009-05-25 11:50:58 +00:00
|
|
|
si->si_i = cb->s_ipx;
|
1995-10-26 20:31:59 +00:00
|
|
|
si->si_s = cb->s_shdr;
|
|
|
|
si->si_seq = cb->s_smax + 1;
|
1997-05-10 09:58:58 +00:00
|
|
|
si->si_len = htons(sizeof(*si));
|
1995-10-26 20:31:59 +00:00
|
|
|
si->si_cc |= SPX_SP;
|
|
|
|
} else {
|
|
|
|
cb->s_outx = 3;
|
2002-05-31 11:52:35 +00:00
|
|
|
if (so->so_options & SO_DEBUG || traceallspxs)
|
1995-10-26 20:31:59 +00:00
|
|
|
spx_trace(SA_OUTPUT, cb->s_state, cb, si, 0);
|
|
|
|
return (0);
|
|
|
|
}
|
2008-05-29 06:50:25 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
|
|
|
* Stuff checksum and output datagram.
|
|
|
|
*/
|
|
|
|
if ((si->si_cc & SPX_SP) == 0) {
|
|
|
|
if (cb->s_force != (1 + SPXT_PERSIST) ||
|
|
|
|
cb->s_timer[SPXT_PERSIST] == 0) {
|
|
|
|
/*
|
2005-01-02 15:13:59 +00:00
|
|
|
* If this is a new packet and we are not currently
|
1995-10-26 20:31:59 +00:00
|
|
|
* timing anything, time this one.
|
|
|
|
*/
|
|
|
|
if (SSEQ_LT(cb->s_smax, si->si_seq)) {
|
|
|
|
cb->s_smax = si->si_seq;
|
|
|
|
if (cb->s_rtt == 0) {
|
|
|
|
spxstat.spxs_segstimed++;
|
|
|
|
cb->s_rtseq = si->si_seq;
|
|
|
|
cb->s_rtt = 1;
|
|
|
|
}
|
|
|
|
}
|
2006-03-24 13:58:23 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Set rexmt timer if not currently set, initial
|
|
|
|
* value for retransmit timer is smoothed round-trip
|
|
|
|
* time + 2 * round-trip time variance. Initialize
|
|
|
|
* shift counter which is used for backoff of
|
|
|
|
* retransmit time.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
if (cb->s_timer[SPXT_REXMT] == 0 &&
|
|
|
|
cb->s_snxt != cb->s_rack) {
|
|
|
|
cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
|
|
|
|
if (cb->s_timer[SPXT_PERSIST]) {
|
|
|
|
cb->s_timer[SPXT_PERSIST] = 0;
|
|
|
|
cb->s_rxtshift = 0;
|
|
|
|
}
|
|
|
|
}
|
2006-03-24 13:58:23 +00:00
|
|
|
} else if (SSEQ_LT(cb->s_smax, si->si_seq))
|
1995-10-26 20:31:59 +00:00
|
|
|
cb->s_smax = si->si_seq;
|
|
|
|
} else if (cb->s_state < TCPS_ESTABLISHED) {
|
|
|
|
if (cb->s_rtt == 0)
|
|
|
|
cb->s_rtt = 1; /* Time initial handshake */
|
|
|
|
if (cb->s_timer[SPXT_REXMT] == 0)
|
|
|
|
cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
|
|
|
|
}
|
|
|
|
|
2006-03-24 13:58:23 +00:00
|
|
|
/*
|
|
|
|
* Do not request acks when we ack their data packets or when we do a
|
|
|
|
* gratuitous window update.
|
|
|
|
*/
|
|
|
|
if (((si->si_cc & SPX_SP) == 0) || cb->s_force)
|
|
|
|
si->si_cc |= SPX_SA;
|
|
|
|
si->si_seq = htons(si->si_seq);
|
|
|
|
si->si_alo = htons(alo);
|
|
|
|
si->si_ack = htons(cb->s_ack);
|
|
|
|
|
|
|
|
if (ipxcksum)
|
|
|
|
si->si_sum = ipx_cksum(m, ntohs(si->si_len));
|
|
|
|
else
|
|
|
|
si->si_sum = 0xffff;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2006-03-24 13:58:23 +00:00
|
|
|
cb->s_outx = 4;
|
|
|
|
if (so->so_options & SO_DEBUG || traceallspxs)
|
|
|
|
spx_trace(SA_OUTPUT, cb->s_state, cb, si, 0);
|
|
|
|
|
2009-06-20 17:44:04 +00:00
|
|
|
#ifdef MAC
|
|
|
|
mac_socket_create_mbuf(so, m);
|
|
|
|
#endif
|
|
|
|
|
2006-03-24 13:58:23 +00:00
|
|
|
if (so->so_options & SO_DONTROUTE)
|
|
|
|
error = ipx_outputfl(m, NULL, IPX_ROUTETOIF);
|
|
|
|
else
|
|
|
|
error = ipx_outputfl(m, &cb->s_ipxpcb->ipxp_route, 0);
|
|
|
|
if (error)
|
1995-10-26 20:31:59 +00:00
|
|
|
return (error);
|
|
|
|
spxstat.spxs_sndtotal++;
|
2006-03-24 13:58:23 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Data sent (as far as we can tell). If this advertises a larger
|
|
|
|
* window than any other segment, then remember the size of the
|
|
|
|
* advertized window. Any pending ACK has now been sent.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
cb->s_force = 0;
|
|
|
|
cb->s_flags &= ~(SF_ACKNOW|SF_DELACK);
|
|
|
|
if (SSEQ_GT(alo, cb->s_alo))
|
|
|
|
cb->s_alo = alo;
|
|
|
|
if (sendalot)
|
|
|
|
goto again;
|
|
|
|
cb->s_outx = 5;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-02-09 06:11:36 +00:00
|
|
|
static int spx_do_persist_panics = 0;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-05-10 09:58:58 +00:00
|
|
|
static void
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_setpersist(struct spxpcb *cb)
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
2006-03-24 00:15:58 +00:00
|
|
|
int t = ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LOCK_ASSERT(cb->s_ipxpcb);
|
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
if (cb->s_timer[SPXT_REXMT] && spx_do_persist_panics)
|
|
|
|
panic("spx_output REXMT");
|
2006-03-24 13:58:23 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
|
|
|
* Start/restart persistance timer.
|
|
|
|
*/
|
|
|
|
SPXT_RANGESET(cb->s_timer[SPXT_PERSIST],
|
|
|
|
t*spx_backoff[cb->s_rxtshift],
|
|
|
|
SPXTV_PERSMIN, SPXTV_PERSMAX);
|
|
|
|
if (cb->s_rxtshift < SPX_MAXRXTSHIFT)
|
|
|
|
cb->s_rxtshift++;
|
|
|
|
}
|
1997-05-10 09:58:58 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
int
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_ctloutput(struct socket *so, struct sockopt *sopt)
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
2006-03-25 14:44:05 +00:00
|
|
|
struct spxhdr spxhdr;
|
|
|
|
struct ipxpcb *ipxp;
|
2006-03-24 00:15:58 +00:00
|
|
|
struct spxpcb *cb;
|
1998-08-23 03:07:17 +00:00
|
|
|
int mask, error;
|
|
|
|
short soptval;
|
|
|
|
u_short usoptval;
|
|
|
|
int optval;
|
|
|
|
|
2006-03-25 17:28:42 +00:00
|
|
|
ipxp = sotoipxpcb(so);
|
|
|
|
KASSERT(ipxp != NULL, ("spx_ctloutput: ipxp == NULL"));
|
|
|
|
|
2006-03-24 13:58:23 +00:00
|
|
|
/*
|
|
|
|
* This will have to be changed when we do more general stacking of
|
|
|
|
* protocols.
|
|
|
|
*/
|
|
|
|
if (sopt->sopt_level != IPXPROTO_SPX)
|
1998-08-23 03:07:17 +00:00
|
|
|
return (ipx_ctloutput(so, sopt));
|
2006-03-25 14:44:05 +00:00
|
|
|
|
2006-03-25 17:28:42 +00:00
|
|
|
IPX_LOCK(ipxp);
|
|
|
|
if (ipxp->ipxp_flags & IPXP_DROPPED) {
|
|
|
|
IPX_UNLOCK(ipxp);
|
|
|
|
return (ECONNRESET);
|
|
|
|
}
|
2006-03-25 14:44:05 +00:00
|
|
|
|
|
|
|
IPX_LOCK(ipxp);
|
|
|
|
cb = ipxtospxpcb(ipxp);
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(cb != NULL, ("spx_ctloutput: cb == NULL"));
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2006-03-25 14:44:05 +00:00
|
|
|
error = 0;
|
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_HEADERS_ON_INPUT:
|
|
|
|
mask = SF_HI;
|
|
|
|
goto get_flags;
|
|
|
|
|
|
|
|
case SO_HEADERS_ON_OUTPUT:
|
|
|
|
mask = SF_HO;
|
|
|
|
get_flags:
|
1998-08-23 03:07:17 +00:00
|
|
|
soptval = cb->s_flags & mask;
|
2006-03-25 14:44:05 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
|
|
|
error = sooptcopyout(sopt, &soptval,
|
|
|
|
sizeof(soptval));
|
1995-10-26 20:31:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SO_MTU:
|
1998-08-23 03:07:17 +00:00
|
|
|
usoptval = cb->s_mtu;
|
2006-03-25 14:44:05 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
|
|
|
error = sooptcopyout(sopt, &usoptval,
|
|
|
|
sizeof(usoptval));
|
1995-10-26 20:31:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SO_LAST_HEADER:
|
2006-03-25 14:44:05 +00:00
|
|
|
spxhdr = cb->s_rhdr;
|
|
|
|
IPX_UNLOCK(ipxp);
|
|
|
|
error = sooptcopyout(sopt, &spxhdr, sizeof(spxhdr));
|
1995-10-26 20:31:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SO_DEFAULT_HEADERS:
|
2006-03-25 14:44:05 +00:00
|
|
|
spxhdr = cb->s_shdr;
|
|
|
|
IPX_UNLOCK(ipxp);
|
|
|
|
error = sooptcopyout(sopt, &spxhdr, sizeof(spxhdr));
|
1995-10-26 20:31:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2006-03-25 14:44:05 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
1998-08-23 03:07:17 +00:00
|
|
|
error = ENOPROTOOPT;
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1998-08-23 03:07:17 +00:00
|
|
|
case SOPT_SET:
|
2006-03-24 13:58:23 +00:00
|
|
|
/*
|
|
|
|
* XXX Why are these shorts on get and ints on set? That
|
|
|
|
* doesn't make any sense...
|
2006-03-25 17:28:42 +00:00
|
|
|
*
|
|
|
|
* XXXRW: Note, when we re-acquire the ipxp lock, we should
|
|
|
|
* re-check that it's not dropped.
|
2006-03-24 13:58:23 +00:00
|
|
|
*/
|
2006-03-25 14:44:05 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
1998-08-23 03:07:17 +00:00
|
|
|
switch (sopt->sopt_name) {
|
1995-10-26 20:31:59 +00:00
|
|
|
case SO_HEADERS_ON_INPUT:
|
|
|
|
mask = SF_HI;
|
|
|
|
goto set_head;
|
|
|
|
|
|
|
|
case SO_HEADERS_ON_OUTPUT:
|
|
|
|
mask = SF_HO;
|
|
|
|
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:31:16 +00:00
|
|
|
IPX_LOCK(ipxp);
|
1995-10-26 20:31:59 +00:00
|
|
|
if (cb->s_flags & SF_PI) {
|
1998-08-23 03:07:17 +00:00
|
|
|
if (optval)
|
1995-10-26 20:31:59 +00:00
|
|
|
cb->s_flags |= mask;
|
|
|
|
else
|
|
|
|
cb->s_flags &= ~mask;
|
|
|
|
} else error = EINVAL;
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
1995-10-26 20:31:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SO_MTU:
|
1998-08-23 03:07:17 +00:00
|
|
|
error = sooptcopyin(sopt, &usoptval, sizeof usoptval,
|
|
|
|
sizeof usoptval);
|
|
|
|
if (error)
|
|
|
|
break;
|
2005-01-09 05:31:16 +00:00
|
|
|
/* Unlocked write. */
|
1998-08-23 03:07:17 +00:00
|
|
|
cb->s_mtu = usoptval;
|
1995-10-26 20:31:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef SF_NEWCALL
|
|
|
|
case SO_NEWCALL:
|
1998-08-23 03:07:17 +00:00
|
|
|
error = sooptcopyin(sopt, &optval, sizeof optval,
|
|
|
|
sizeof optval);
|
|
|
|
if (error)
|
|
|
|
break;
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LOCK(ipxp);
|
1998-08-23 03:07:17 +00:00
|
|
|
if (optval) {
|
1995-10-26 20:31:59 +00:00
|
|
|
cb->s_flags2 |= SF_NEWCALL;
|
|
|
|
spx_newchecks[5]++;
|
|
|
|
} else {
|
|
|
|
cb->s_flags2 &= ~SF_NEWCALL;
|
|
|
|
spx_newchecks[6]++;
|
|
|
|
}
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
1995-10-26 20:31:59 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case SO_DEFAULT_HEADERS:
|
|
|
|
{
|
1998-08-23 03:07:17 +00:00
|
|
|
struct spxhdr sp;
|
|
|
|
|
|
|
|
error = sooptcopyin(sopt, &sp, sizeof sp,
|
|
|
|
sizeof sp);
|
|
|
|
if (error)
|
|
|
|
break;
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LOCK(ipxp);
|
1998-08-23 03:07:17 +00:00
|
|
|
cb->s_dt = sp.spx_dt;
|
|
|
|
cb->s_cc = sp.spx_cc & SPX_EM;
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1998-08-23 03:07:17 +00:00
|
|
|
error = ENOPROTOOPT;
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
|
|
|
break;
|
2006-03-25 14:44:05 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
panic("spx_ctloutput: bad socket option direction");
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
1998-08-23 03:07:17 +00:00
|
|
|
return (error);
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
|
|
|
|
2006-04-01 15:15:05 +00:00
|
|
|
static void
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_usr_abort(struct socket *so)
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
1997-04-05 20:05:11 +00:00
|
|
|
struct ipxpcb *ipxp;
|
|
|
|
struct spxpcb *cb;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
ipxp = sotoipxpcb(so);
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(ipxp != NULL, ("spx_usr_abort: ipxp == NULL"));
|
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
cb = ipxtospxpcb(ipxp);
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(cb != NULL, ("spx_usr_abort: cb == NULL"));
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LIST_LOCK();
|
|
|
|
IPX_LOCK(ipxp);
|
1997-04-05 20:05:11 +00:00
|
|
|
spx_drop(cb, ECONNABORTED);
|
2006-07-21 17:11:15 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
2005-01-09 05:31:16 +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
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Accept a connection. Essentially all the work is done at higher levels;
|
|
|
|
* just return the address of the peer, storing through addr.
|
1997-04-05 20:05:11 +00:00
|
|
|
*/
|
|
|
|
static int
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_accept(struct socket *so, struct sockaddr **nam)
|
1997-04-05 20:05:11 +00:00
|
|
|
{
|
|
|
|
struct ipxpcb *ipxp;
|
1997-08-16 19:16:27 +00:00
|
|
|
struct sockaddr_ipx *sipx, ssipx;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
ipxp = sotoipxpcb(so);
|
2006-03-26 19:51:44 +00:00
|
|
|
KASSERT(ipxp != NULL, ("spx_accept: ipxp == NULL"));
|
2006-03-24 13:58:23 +00:00
|
|
|
|
1997-08-16 19:16:27 +00:00
|
|
|
sipx = &ssipx;
|
|
|
|
bzero(sipx, sizeof *sipx);
|
|
|
|
sipx->sipx_len = sizeof *sipx;
|
1997-04-05 20:05:11 +00:00
|
|
|
sipx->sipx_family = AF_IPX;
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LOCK(ipxp);
|
1997-04-05 20:05:11 +00:00
|
|
|
sipx->sipx_addr = ipxp->ipxp_faddr;
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
|
|
|
*nam = sodupsockaddr((struct sockaddr *)sipx, M_WAITOK);
|
1997-04-05 20:05:11 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_attach(struct socket *so, int proto, struct thread *td)
|
1997-04-05 20:05:11 +00:00
|
|
|
{
|
|
|
|
struct ipxpcb *ipxp;
|
|
|
|
struct spxpcb *cb;
|
|
|
|
struct mbuf *mm;
|
|
|
|
struct sockbuf *sb;
|
2005-01-09 05:31:16 +00:00
|
|
|
int error;
|
1997-04-05 20:05:11 +00:00
|
|
|
|
|
|
|
ipxp = sotoipxpcb(so);
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(ipxp == NULL, ("spx_attach: ipxp != NULL"));
|
1997-04-05 20:05:11 +00:00
|
|
|
|
|
|
|
if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
|
|
|
|
error = soreserve(so, (u_long) 3072, (u_long) 3072);
|
1995-10-26 20:31:59 +00:00
|
|
|
if (error)
|
2006-03-25 15:03:29 +00:00
|
|
|
return (error);
|
1997-04-05 20:05:11 +00:00
|
|
|
}
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2008-10-23 15:53:51 +00:00
|
|
|
cb = malloc(sizeof *cb, M_PCB, M_NOWAIT | M_ZERO);
|
2006-03-25 15:03:29 +00:00
|
|
|
if (cb == NULL)
|
|
|
|
return (ENOBUFS);
|
2012-12-05 08:04:20 +00:00
|
|
|
mm = m_getclr(M_NOWAIT, MT_DATA);
|
1997-04-05 20:05:11 +00:00
|
|
|
if (mm == NULL) {
|
2008-10-23 15:53:51 +00:00
|
|
|
free(cb, M_PCB);
|
2006-03-25 15:03:29 +00:00
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
|
|
|
|
|
|
|
IPX_LIST_LOCK();
|
|
|
|
error = ipx_pcballoc(so, &ipxpcb_list, td);
|
|
|
|
if (error) {
|
|
|
|
IPX_LIST_UNLOCK();
|
|
|
|
m_free(mm);
|
2008-10-23 15:53:51 +00:00
|
|
|
free(cb, M_PCB);
|
2006-03-25 15:03:29 +00:00
|
|
|
return (error);
|
1997-04-05 20:05:11 +00:00
|
|
|
}
|
2006-03-25 15:03:29 +00:00
|
|
|
ipxp = sotoipxpcb(so);
|
2006-03-26 15:41:44 +00:00
|
|
|
ipxp->ipxp_flags |= IPXP_SPX;
|
2006-03-25 15:03:29 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
cb->s_state = TCPS_LISTEN;
|
|
|
|
cb->s_smax = -1;
|
|
|
|
cb->s_swl1 = -1;
|
2009-05-25 10:25:41 +00:00
|
|
|
spx_reass_init(cb);
|
1997-04-05 20:05:11 +00:00
|
|
|
cb->s_ipxpcb = ipxp;
|
1997-05-10 09:58:58 +00:00
|
|
|
cb->s_mtu = 576 - sizeof(struct spx);
|
2006-03-24 13:58:23 +00:00
|
|
|
sb = &so->so_snd;
|
1997-04-05 20:05:11 +00:00
|
|
|
cb->s_cwnd = sbspace(sb) * CUNIT / cb->s_mtu;
|
|
|
|
cb->s_ssthresh = cb->s_cwnd;
|
1997-05-10 09:58:58 +00:00
|
|
|
cb->s_cwmx = sbspace(sb) * CUNIT / (2 * sizeof(struct spx));
|
2008-05-29 06:50:25 +00:00
|
|
|
|
2006-03-24 13:58:23 +00:00
|
|
|
/*
|
|
|
|
* Above is recomputed when connecting to account for changed
|
|
|
|
* buffering or mtu's.
|
|
|
|
*/
|
1997-04-05 20:05:11 +00:00
|
|
|
cb->s_rtt = SPXTV_SRTTBASE;
|
|
|
|
cb->s_rttvar = SPXTV_SRTTDFLT << 2;
|
|
|
|
SPXT_RANGESET(cb->s_rxtcur,
|
|
|
|
((SPXTV_SRTTBASE >> 2) + (SPXTV_SRTTDFLT << 2)) >> 1,
|
|
|
|
SPXTV_MIN, SPXTV_REXMTMAX);
|
2005-01-02 15:13:59 +00:00
|
|
|
ipxp->ipxp_pcb = (caddr_t)cb;
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LIST_UNLOCK();
|
2006-03-25 17:28:42 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
spx_pcbdetach(struct ipxpcb *ipxp)
|
|
|
|
{
|
|
|
|
struct spxpcb *cb;
|
|
|
|
|
|
|
|
IPX_LOCK_ASSERT(ipxp);
|
|
|
|
|
|
|
|
cb = ipxtospxpcb(ipxp);
|
|
|
|
KASSERT(cb != NULL, ("spx_pcbdetach: cb == NULL"));
|
|
|
|
|
2009-05-25 10:25:41 +00:00
|
|
|
spx_reass_flush(cb);
|
2008-10-23 15:53:51 +00:00
|
|
|
free(cb, M_PCB);
|
2006-03-25 17:28:42 +00:00
|
|
|
ipxp->ipxp_pcb = NULL;
|
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
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
|
2005-01-02 15:13:59 +00:00
|
|
|
{
|
1997-04-05 20:05:11 +00:00
|
|
|
struct ipxpcb *ipxp;
|
2005-01-09 05:31:16 +00:00
|
|
|
int error;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
ipxp = sotoipxpcb(so);
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(ipxp != NULL, ("spx_bind: ipxp == NULL"));
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LIST_LOCK();
|
|
|
|
IPX_LOCK(ipxp);
|
2006-03-26 19:37:37 +00:00
|
|
|
if (ipxp->ipxp_flags & IPXP_DROPPED) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-01-09 05:31:16 +00:00
|
|
|
error = ipx_pcbbind(ipxp, nam, td);
|
2006-03-26 19:37:37 +00:00
|
|
|
out:
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
|
|
|
IPX_LIST_UNLOCK();
|
|
|
|
return (error);
|
2005-01-02 15:13:59 +00:00
|
|
|
}
|
|
|
|
|
2006-07-21 17:11:15 +00:00
|
|
|
static void
|
|
|
|
spx_usr_close(struct socket *so)
|
|
|
|
{
|
|
|
|
struct ipxpcb *ipxp;
|
|
|
|
struct spxpcb *cb;
|
|
|
|
|
|
|
|
ipxp = sotoipxpcb(so);
|
|
|
|
KASSERT(ipxp != NULL, ("spx_usr_close: ipxp == NULL"));
|
|
|
|
|
|
|
|
cb = ipxtospxpcb(ipxp);
|
|
|
|
KASSERT(cb != NULL, ("spx_usr_close: cb == NULL"));
|
|
|
|
|
|
|
|
IPX_LIST_LOCK();
|
|
|
|
IPX_LOCK(ipxp);
|
|
|
|
if (cb->s_state > TCPS_LISTEN)
|
|
|
|
spx_disconnect(cb);
|
|
|
|
else
|
|
|
|
spx_close(cb);
|
|
|
|
IPX_UNLOCK(ipxp);
|
|
|
|
IPX_LIST_UNLOCK();
|
|
|
|
}
|
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Initiate connection to peer. Enter SYN_SENT state, and mark socket as
|
|
|
|
* connecting. Start keep-alive timer, setup prototype header, send initial
|
|
|
|
* system packet requesting connection.
|
1997-04-05 20:05:11 +00:00
|
|
|
*/
|
|
|
|
static int
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
|
1997-04-05 20:05:11 +00:00
|
|
|
{
|
|
|
|
struct ipxpcb *ipxp;
|
|
|
|
struct spxpcb *cb;
|
2005-01-09 05:31:16 +00:00
|
|
|
int error;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
ipxp = sotoipxpcb(so);
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(ipxp != NULL, ("spx_connect: ipxp == NULL"));
|
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
cb = ipxtospxpcb(ipxp);
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(cb != NULL, ("spx_connect: cb == NULL"));
|
1997-04-05 20:05:11 +00:00
|
|
|
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LIST_LOCK();
|
|
|
|
IPX_LOCK(ipxp);
|
2006-03-26 19:37:37 +00:00
|
|
|
if (ipxp->ipxp_flags & IPXP_DROPPED) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto spx_connect_end;
|
|
|
|
}
|
1997-04-05 20:05:11 +00:00
|
|
|
if (ipxp->ipxp_lport == 0) {
|
2005-01-02 14:03:47 +00:00
|
|
|
error = ipx_pcbbind(ipxp, NULL, td);
|
1997-04-05 20:05:11 +00:00
|
|
|
if (error)
|
|
|
|
goto spx_connect_end;
|
|
|
|
}
|
2001-09-12 08:38:13 +00:00
|
|
|
error = ipx_pcbconnect(ipxp, nam, td);
|
1997-04-05 20:05:11 +00:00
|
|
|
if (error)
|
|
|
|
goto spx_connect_end;
|
|
|
|
soisconnecting(so);
|
|
|
|
spxstat.spxs_connattempt++;
|
|
|
|
cb->s_state = TCPS_SYN_SENT;
|
|
|
|
cb->s_did = 0;
|
|
|
|
spx_template(cb);
|
|
|
|
cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
|
|
|
|
cb->s_force = 1 + SPXTV_KEEP;
|
2008-05-29 06:50:25 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Other party is required to respond to the port I send from, but he
|
|
|
|
* is not required to answer from where I am sending to, so allow
|
|
|
|
* wildcarding. Original port I am sending to is still saved in
|
1997-04-05 20:05:11 +00:00
|
|
|
* cb->s_dport.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
1997-04-05 20:05:11 +00:00
|
|
|
ipxp->ipxp_fport = 0;
|
2005-01-02 14:03:47 +00:00
|
|
|
error = spx_output(cb, NULL);
|
1997-04-05 20:05:11 +00:00
|
|
|
spx_connect_end:
|
2005-01-09 05:31:16 +00:00
|
|
|
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
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_detach(struct socket *so)
|
1997-04-05 20:05:11 +00:00
|
|
|
{
|
|
|
|
struct ipxpcb *ipxp;
|
|
|
|
struct spxpcb *cb;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2006-07-21 17:11:15 +00:00
|
|
|
/*
|
|
|
|
* XXXRW: Should assert appropriately detached.
|
|
|
|
*/
|
1997-04-05 20:05:11 +00:00
|
|
|
ipxp = sotoipxpcb(so);
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(ipxp != NULL, ("spx_detach: ipxp == NULL"));
|
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
cb = ipxtospxpcb(ipxp);
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(cb != NULL, ("spx_detach: cb == NULL"));
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LIST_LOCK();
|
|
|
|
IPX_LOCK(ipxp);
|
2006-03-25 17:28:42 +00:00
|
|
|
spx_pcbdetach(ipxp);
|
2009-05-25 13:34:03 +00:00
|
|
|
ipx_pcbdetach(ipxp);
|
2006-03-25 17:28:42 +00:00
|
|
|
ipx_pcbfree(ipxp);
|
2005-01-09 05:31:16 +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
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* We may decide later to implement connection closing handshaking at the spx
|
|
|
|
* level optionally. Here is the hook to do it:
|
1997-04-05 20:05:11 +00:00
|
|
|
*/
|
|
|
|
static int
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_usr_disconnect(struct socket *so)
|
1997-04-05 20:05:11 +00:00
|
|
|
{
|
|
|
|
struct ipxpcb *ipxp;
|
|
|
|
struct spxpcb *cb;
|
2006-03-26 19:37:37 +00:00
|
|
|
int error;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
ipxp = sotoipxpcb(so);
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(ipxp != NULL, ("spx_usr_disconnect: ipxp == NULL"));
|
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
cb = ipxtospxpcb(ipxp);
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(cb != NULL, ("spx_usr_disconnect: cb == NULL"));
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LIST_LOCK();
|
|
|
|
IPX_LOCK(ipxp);
|
2006-03-26 19:37:37 +00:00
|
|
|
if (ipxp->ipxp_flags & IPXP_DROPPED) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
1997-04-05 20:05:11 +00:00
|
|
|
spx_disconnect(cb);
|
2006-03-26 19:37:37 +00:00
|
|
|
error = 0;
|
|
|
|
out:
|
2006-03-25 17:28:42 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LIST_UNLOCK();
|
2006-03-26 19:37:37 +00:00
|
|
|
return (error);
|
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
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_listen(struct socket *so, int backlog, struct thread *td)
|
1997-04-05 20:05:11 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct ipxpcb *ipxp;
|
|
|
|
struct spxpcb *cb;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
error = 0;
|
|
|
|
ipxp = sotoipxpcb(so);
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(ipxp != NULL, ("spx_listen: ipxp == NULL"));
|
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
cb = ipxtospxpcb(ipxp);
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(cb != NULL, ("spx_listen: cb == NULL"));
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LIST_LOCK();
|
|
|
|
IPX_LOCK(ipxp);
|
2006-03-26 19:37:37 +00:00
|
|
|
if (ipxp->ipxp_flags & IPXP_DROPPED) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
In the current world order, solisten() implements the state transition of
a socket from a regular socket to a listening socket able to accept new
connections. As part of this state transition, solisten() calls into the
protocol to update protocol-layer state. There were several bugs in this
implementation that could result in a race wherein a TCP SYN received
in the interval between the protocol state transition and the shortly
following socket layer transition would result in a panic in the TCP code,
as the socket would be in the TCPS_LISTEN state, but the socket would not
have the SO_ACCEPTCONN flag set.
This change does the following:
- Pushes the socket state transition from the socket layer solisten() to
to socket "library" routines called from the protocol. This permits
the socket routines to be called while holding the protocol mutexes,
preventing a race exposing the incomplete socket state transition to TCP
after the TCP state transition has completed. The check for a socket
layer state transition is performed by solisten_proto_check(), and the
actual transition is performed by solisten_proto().
- Holds the socket lock for the duration of the socket state test and set,
and over the protocol layer state transition, which is now possible as
the socket lock is acquired by the protocol layer, rather than vice
versa. This prevents additional state related races in the socket
layer.
This permits the dual transition of socket layer and protocol layer state
to occur while holding locks for both layers, making the two changes
atomic with respect to one another. Similar changes are likely require
elsewhere in the socket/protocol code.
Reported by: Peter Holm <peter@holm.cc>
Review and fixes from: emax, Antoine Brodin <antoine.brodin@laposte.net>
Philosophical head nod: gnn
2005-02-21 21:58:17 +00:00
|
|
|
SOCK_LOCK(so);
|
|
|
|
error = solisten_proto_check(so);
|
|
|
|
if (error == 0 && ipxp->ipxp_lport == 0)
|
2005-01-02 14:03:47 +00:00
|
|
|
error = ipx_pcbbind(ipxp, NULL, td);
|
In the current world order, solisten() implements the state transition of
a socket from a regular socket to a listening socket able to accept new
connections. As part of this state transition, solisten() calls into the
protocol to update protocol-layer state. There were several bugs in this
implementation that could result in a race wherein a TCP SYN received
in the interval between the protocol state transition and the shortly
following socket layer transition would result in a panic in the TCP code,
as the socket would be in the TCPS_LISTEN state, but the socket would not
have the SO_ACCEPTCONN flag set.
This change does the following:
- Pushes the socket state transition from the socket layer solisten() to
to socket "library" routines called from the protocol. This permits
the socket routines to be called while holding the protocol mutexes,
preventing a race exposing the incomplete socket state transition to TCP
after the TCP state transition has completed. The check for a socket
layer state transition is performed by solisten_proto_check(), and the
actual transition is performed by solisten_proto().
- Holds the socket lock for the duration of the socket state test and set,
and over the protocol layer state transition, which is now possible as
the socket lock is acquired by the protocol layer, rather than vice
versa. This prevents additional state related races in the socket
layer.
This permits the dual transition of socket layer and protocol layer state
to occur while holding locks for both layers, making the two changes
atomic with respect to one another. Similar changes are likely require
elsewhere in the socket/protocol code.
Reported by: Peter Holm <peter@holm.cc>
Review and fixes from: emax, Antoine Brodin <antoine.brodin@laposte.net>
Philosophical head nod: gnn
2005-02-21 21:58:17 +00:00
|
|
|
if (error == 0) {
|
1997-04-05 20:05:11 +00:00
|
|
|
cb->s_state = TCPS_LISTEN;
|
2005-10-30 19:44:40 +00:00
|
|
|
solisten_proto(so, backlog);
|
In the current world order, solisten() implements the state transition of
a socket from a regular socket to a listening socket able to accept new
connections. As part of this state transition, solisten() calls into the
protocol to update protocol-layer state. There were several bugs in this
implementation that could result in a race wherein a TCP SYN received
in the interval between the protocol state transition and the shortly
following socket layer transition would result in a panic in the TCP code,
as the socket would be in the TCPS_LISTEN state, but the socket would not
have the SO_ACCEPTCONN flag set.
This change does the following:
- Pushes the socket state transition from the socket layer solisten() to
to socket "library" routines called from the protocol. This permits
the socket routines to be called while holding the protocol mutexes,
preventing a race exposing the incomplete socket state transition to TCP
after the TCP state transition has completed. The check for a socket
layer state transition is performed by solisten_proto_check(), and the
actual transition is performed by solisten_proto().
- Holds the socket lock for the duration of the socket state test and set,
and over the protocol layer state transition, which is now possible as
the socket lock is acquired by the protocol layer, rather than vice
versa. This prevents additional state related races in the socket
layer.
This permits the dual transition of socket layer and protocol layer state
to occur while holding locks for both layers, making the two changes
atomic with respect to one another. Similar changes are likely require
elsewhere in the socket/protocol code.
Reported by: Peter Holm <peter@holm.cc>
Review and fixes from: emax, Antoine Brodin <antoine.brodin@laposte.net>
Philosophical head nod: gnn
2005-02-21 21:58:17 +00:00
|
|
|
}
|
|
|
|
SOCK_UNLOCK(so);
|
2006-03-26 19:37:37 +00:00
|
|
|
out:
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
|
|
|
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
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* After a receive, possibly send acknowledgment updating allocation.
|
1997-04-05 20:05:11 +00:00
|
|
|
*/
|
|
|
|
static int
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_rcvd(struct socket *so, int flags)
|
1997-04-05 20:05:11 +00:00
|
|
|
{
|
|
|
|
struct ipxpcb *ipxp;
|
|
|
|
struct spxpcb *cb;
|
2006-03-26 19:37:37 +00:00
|
|
|
int error;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
ipxp = sotoipxpcb(so);
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(ipxp != NULL, ("spx_rcvd: ipxp == NULL"));
|
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
cb = ipxtospxpcb(ipxp);
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(cb != NULL, ("spx_rcvd: cb == NULL"));
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LOCK(ipxp);
|
2006-03-26 19:37:37 +00:00
|
|
|
if (ipxp->ipxp_flags & IPXP_DROPPED) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
1997-04-05 20:05:11 +00:00
|
|
|
cb->s_flags |= SF_RVD;
|
2005-01-02 14:03:47 +00:00
|
|
|
spx_output(cb, NULL);
|
1997-04-05 20:05:11 +00:00
|
|
|
cb->s_flags &= ~SF_RVD;
|
2006-03-26 19:37:37 +00:00
|
|
|
error = 0;
|
|
|
|
out:
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
2006-03-26 19:37:37 +00:00
|
|
|
return (error);
|
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
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_rcvoob(struct socket *so, struct mbuf *m, int flags)
|
1997-04-05 20:05:11 +00:00
|
|
|
{
|
|
|
|
struct ipxpcb *ipxp;
|
|
|
|
struct spxpcb *cb;
|
2006-03-26 19:37:37 +00:00
|
|
|
int error;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
ipxp = sotoipxpcb(so);
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(ipxp != NULL, ("spx_rcvoob: ipxp == NULL"));
|
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
cb = ipxtospxpcb(ipxp);
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(cb != NULL, ("spx_rcvoob: cb == NULL"));
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2006-03-25 17:28:42 +00:00
|
|
|
IPX_LOCK(ipxp);
|
2006-03-26 19:37:37 +00:00
|
|
|
if (ipxp->ipxp_flags & IPXP_DROPPED) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-01-02 15:38:47 +00:00
|
|
|
SOCKBUF_LOCK(&so->so_rcv);
|
1997-04-05 20:05:11 +00:00
|
|
|
if ((cb->s_oobflags & SF_IOOB) || so->so_oobmark ||
|
2004-06-14 18:16:22 +00:00
|
|
|
(so->so_rcv.sb_state & SBS_RCVATMARK)) {
|
2005-01-02 15:38:47 +00:00
|
|
|
SOCKBUF_UNLOCK(&so->so_rcv);
|
1997-04-05 20:05:11 +00:00
|
|
|
m->m_len = 1;
|
|
|
|
*mtod(m, caddr_t) = cb->s_iobc;
|
2006-03-26 19:37:37 +00:00
|
|
|
error = 0;
|
|
|
|
goto out;
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
2005-01-02 15:38:47 +00:00
|
|
|
SOCKBUF_UNLOCK(&so->so_rcv);
|
2006-03-26 19:37:37 +00:00
|
|
|
error = EINVAL;
|
|
|
|
out:
|
2006-03-25 17:28:42 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
2006-03-26 19:37:37 +00:00
|
|
|
return (error);
|
1997-04-05 20:05:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
|
|
|
|
struct mbuf *controlp, struct thread *td)
|
1997-04-05 20:05:11 +00:00
|
|
|
{
|
|
|
|
struct ipxpcb *ipxp;
|
|
|
|
struct spxpcb *cb;
|
2006-03-26 19:37:37 +00:00
|
|
|
int error;
|
1997-04-05 20:05:11 +00:00
|
|
|
|
|
|
|
ipxp = sotoipxpcb(so);
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(ipxp != NULL, ("spx_send: ipxp == NULL"));
|
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
cb = ipxtospxpcb(ipxp);
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(cb != NULL, ("spx_send: cb == NULL"));
|
1997-04-05 20:05:11 +00:00
|
|
|
|
2006-03-24 13:58:23 +00:00
|
|
|
error = 0;
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LOCK(ipxp);
|
2006-03-26 19:37:37 +00:00
|
|
|
if (ipxp->ipxp_flags & IPXP_DROPPED) {
|
|
|
|
error = ECONNRESET;
|
|
|
|
goto spx_send_end;
|
|
|
|
}
|
1997-04-05 20:05:11 +00:00
|
|
|
if (flags & PRUS_OOB) {
|
|
|
|
if (sbspace(&so->so_snd) < -512) {
|
|
|
|
error = ENOBUFS;
|
|
|
|
goto spx_send_end;
|
|
|
|
}
|
|
|
|
cb->s_oobflags |= SF_SOOB;
|
|
|
|
}
|
1997-05-10 09:58:58 +00:00
|
|
|
if (controlp != NULL) {
|
1997-04-05 20:05:11 +00:00
|
|
|
u_short *p = mtod(controlp, u_short *);
|
|
|
|
spx_newchecks[2]++;
|
1997-05-10 09:58:58 +00:00
|
|
|
if ((p[0] == 5) && (p[1] == 1)) { /* XXXX, for testing */
|
1997-04-05 20:05:11 +00:00
|
|
|
cb->s_shdr.spx_dt = *(u_char *)(&p[2]);
|
|
|
|
spx_newchecks[3]++;
|
|
|
|
}
|
|
|
|
m_freem(controlp);
|
|
|
|
}
|
|
|
|
controlp = NULL;
|
|
|
|
error = spx_output(cb, m);
|
|
|
|
m = NULL;
|
|
|
|
spx_send_end:
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
1995-10-26 20:31:59 +00:00
|
|
|
if (controlp != NULL)
|
|
|
|
m_freem(controlp);
|
|
|
|
if (m != NULL)
|
|
|
|
m_freem(m);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
static int
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_shutdown(struct socket *so)
|
1997-04-05 20:05:11 +00:00
|
|
|
{
|
|
|
|
struct ipxpcb *ipxp;
|
|
|
|
struct spxpcb *cb;
|
2006-03-26 19:37:37 +00:00
|
|
|
int error;
|
1997-04-05 20:05:11 +00:00
|
|
|
|
|
|
|
ipxp = sotoipxpcb(so);
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(ipxp != NULL, ("spx_shutdown: ipxp == NULL"));
|
|
|
|
|
1997-04-05 20:05:11 +00:00
|
|
|
cb = ipxtospxpcb(ipxp);
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(cb != NULL, ("spx_shutdown: cb == NULL"));
|
1997-04-05 20:05:11 +00:00
|
|
|
|
|
|
|
socantsendmore(so);
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LIST_LOCK();
|
|
|
|
IPX_LOCK(ipxp);
|
2006-03-26 19:37:37 +00:00
|
|
|
if (ipxp->ipxp_flags & IPXP_DROPPED) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-01-09 05:25:02 +00:00
|
|
|
spx_usrclosed(cb);
|
2006-03-26 19:37:37 +00:00
|
|
|
error = 0;
|
|
|
|
out:
|
2006-03-25 17:28:42 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LIST_UNLOCK();
|
2006-03-26 19:37:37 +00:00
|
|
|
return (error);
|
1997-04-05 20:05:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_sp_attach(struct socket *so, int proto, struct thread *td)
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
1997-04-05 20:05:11 +00:00
|
|
|
struct ipxpcb *ipxp;
|
2006-03-25 15:03:29 +00:00
|
|
|
struct spxpcb *cb;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
KASSERT(so->so_pcb == NULL, ("spx_sp_attach: so_pcb != NULL"));
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
error = spx_attach(so, proto, td);
|
2006-03-25 15:03:29 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
ipxp = sotoipxpcb(so);
|
|
|
|
KASSERT(ipxp != NULL, ("spx_sp_attach: ipxp == NULL"));
|
|
|
|
|
|
|
|
cb = ipxtospxpcb(ipxp);
|
|
|
|
KASSERT(cb != NULL, ("spx_sp_attach: cb == NULL"));
|
|
|
|
|
|
|
|
IPX_LOCK(ipxp);
|
|
|
|
cb->s_flags |= (SF_HI | SF_HO | SF_PI);
|
|
|
|
IPX_UNLOCK(ipxp);
|
|
|
|
return (0);
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Create template to be used to send spx packets on a connection. Called
|
|
|
|
* after host entry created, fills in a skeletal spx header (choosing
|
|
|
|
* connection id), minimizing the amount of work necessary when the
|
|
|
|
* connection is used.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
1997-05-10 09:58:58 +00:00
|
|
|
static void
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_template(struct spxpcb *cb)
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
2006-03-24 00:15:58 +00:00
|
|
|
struct ipxpcb *ipxp = cb->s_ipxpcb;
|
|
|
|
struct sockbuf *sb = &(ipxp->ipxp_socket->so_snd);
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LOCK_ASSERT(ipxp);
|
|
|
|
|
2009-05-25 11:50:58 +00:00
|
|
|
cb->s_ipx.ipx_pt = IPXPROTO_SPX;
|
|
|
|
cb->s_ipx.ipx_sna = ipxp->ipxp_laddr;
|
|
|
|
cb->s_ipx.ipx_dna = ipxp->ipxp_faddr;
|
2006-03-24 00:26:25 +00:00
|
|
|
SPX_LOCK();
|
1995-10-26 20:31:59 +00:00
|
|
|
cb->s_sid = htons(spx_iss);
|
|
|
|
spx_iss += SPX_ISSINCR/2;
|
2006-03-24 00:26:25 +00:00
|
|
|
SPX_UNLOCK();
|
1995-10-26 20:31:59 +00:00
|
|
|
cb->s_alo = 1;
|
|
|
|
cb->s_cwnd = (sbspace(sb) * CUNIT) / cb->s_mtu;
|
2008-05-29 06:50:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to expand fast to full complement of large packets.
|
|
|
|
*/
|
2006-03-24 13:58:23 +00:00
|
|
|
cb->s_ssthresh = cb->s_cwnd;
|
1995-10-26 20:31:59 +00:00
|
|
|
cb->s_cwmx = (sbspace(sb) * CUNIT) / (2 * sizeof(struct spx));
|
2008-05-29 06:50:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* But allow for lots of little packets as well.
|
|
|
|
*/
|
1995-10-26 20:31:59 +00:00
|
|
|
cb->s_cwmx = max(cb->s_cwmx, cb->s_cwnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-03-25 17:28:42 +00:00
|
|
|
* Close a SPIP control block. Wake up any sleepers. We used to free any
|
2009-05-25 11:50:58 +00:00
|
|
|
* queued packets, but now we defer that until the pcb is discarded.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
2005-01-09 05:25:02 +00:00
|
|
|
void
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_close(struct spxpcb *cb)
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
|
|
|
struct ipxpcb *ipxp = cb->s_ipxpcb;
|
|
|
|
struct socket *so = ipxp->ipxp_socket;
|
|
|
|
|
2006-03-24 13:58:23 +00:00
|
|
|
KASSERT(ipxp != NULL, ("spx_close: ipxp == NULL"));
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LIST_LOCK_ASSERT();
|
|
|
|
IPX_LOCK_ASSERT(ipxp);
|
|
|
|
|
2006-03-25 17:28:42 +00:00
|
|
|
ipxp->ipxp_flags |= IPXP_DROPPED;
|
1995-10-26 20:31:59 +00:00
|
|
|
soisdisconnected(so);
|
|
|
|
spxstat.spxs_closed++;
|
|
|
|
}
|
1997-05-10 09:58:58 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Someday we may do level 3 handshaking to close a connection or send a
|
|
|
|
* xerox style error. For now, just close. cb will always be invalid after
|
|
|
|
* this call.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
2005-01-09 05:25:02 +00:00
|
|
|
static void
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_usrclosed(struct spxpcb *cb)
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
2005-01-09 05:25:02 +00:00
|
|
|
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LIST_LOCK_ASSERT();
|
|
|
|
IPX_LOCK_ASSERT(cb->s_ipxpcb);
|
|
|
|
|
2005-01-09 05:25:02 +00:00
|
|
|
spx_close(cb);
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
1997-05-10 09:58:58 +00:00
|
|
|
|
2005-01-09 05:25:02 +00:00
|
|
|
/*
|
|
|
|
* cb will always be invalid after this call.
|
|
|
|
*/
|
|
|
|
static void
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_disconnect(struct spxpcb *cb)
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
2005-01-09 05:25:02 +00:00
|
|
|
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LIST_LOCK_ASSERT();
|
|
|
|
IPX_LOCK_ASSERT(cb->s_ipxpcb);
|
|
|
|
|
2005-01-09 05:25:02 +00:00
|
|
|
spx_close(cb);
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
1997-05-10 09:58:58 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Drop connection, reporting the specified error. cb will always be invalid
|
|
|
|
* after this call.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
2005-01-09 05:25:02 +00:00
|
|
|
static void
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_drop(struct spxpcb *cb, int errno)
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
|
|
|
struct socket *so = cb->s_ipxpcb->ipxp_socket;
|
|
|
|
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LIST_LOCK_ASSERT();
|
|
|
|
IPX_LOCK_ASSERT(cb->s_ipxpcb);
|
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Someday, in the xerox world we will generate error protocol
|
|
|
|
* packets announcing that the socket has gone away.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
if (TCPS_HAVERCVDSYN(cb->s_state)) {
|
|
|
|
spxstat.spxs_drops++;
|
|
|
|
cb->s_state = TCPS_CLOSED;
|
1997-05-10 09:58:58 +00:00
|
|
|
/*tcp_output(cb);*/
|
1995-10-26 20:31:59 +00:00
|
|
|
} else
|
|
|
|
spxstat.spxs_conndrops++;
|
|
|
|
so->so_error = errno;
|
2005-01-09 05:25:02 +00:00
|
|
|
spx_close(cb);
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* Fast timeout routine for processing delayed acks.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
void
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_fasttimo(void)
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
2005-01-09 05:31:16 +00:00
|
|
|
struct ipxpcb *ipxp;
|
|
|
|
struct spxpcb *cb;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LIST_LOCK();
|
2004-12-30 17:49:40 +00:00
|
|
|
LIST_FOREACH(ipxp, &ipxpcb_list, ipxp_list) {
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LOCK(ipxp);
|
2006-03-26 15:41:44 +00:00
|
|
|
if (!(ipxp->ipxp_flags & IPXP_SPX) ||
|
|
|
|
(ipxp->ipxp_flags & IPXP_DROPPED)) {
|
|
|
|
IPX_UNLOCK(ipxp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
cb = ipxtospxpcb(ipxp);
|
|
|
|
if (cb->s_flags & SF_DELACK) {
|
|
|
|
cb->s_flags &= ~SF_DELACK;
|
|
|
|
cb->s_flags |= SF_ACKNOW;
|
|
|
|
spxstat.spxs_delack++;
|
|
|
|
spx_output(cb, NULL);
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
2004-12-30 17:49:40 +00:00
|
|
|
}
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LIST_UNLOCK();
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* spx protocol timeout routine called every 500 ms. Updates the timers in
|
|
|
|
* all active pcb's and causes finite state machine actions if timers expire.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
void
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_slowtimo(void)
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
2006-03-25 17:28:42 +00:00
|
|
|
struct ipxpcb *ipxp;
|
2005-01-09 05:31:16 +00:00
|
|
|
struct spxpcb *cb;
|
|
|
|
int i;
|
1995-10-26 20:31:59 +00:00
|
|
|
|
|
|
|
/*
|
2006-03-25 17:28:42 +00:00
|
|
|
* Search through tcb's and update active timers. Once, timers could
|
|
|
|
* free ipxp's, but now we do that only when detaching a socket.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LIST_LOCK();
|
2006-03-25 17:28:42 +00:00
|
|
|
LIST_FOREACH(ipxp, &ipxpcb_list, ipxp_list) {
|
|
|
|
IPX_LOCK(ipxp);
|
2006-03-26 15:41:44 +00:00
|
|
|
if (!(ipxp->ipxp_flags & IPXP_SPX) ||
|
|
|
|
(ipxp->ipxp_flags & IPXP_DROPPED)) {
|
2006-03-25 17:28:42 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
2004-12-30 17:49:40 +00:00
|
|
|
continue;
|
2006-03-25 17:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cb = (struct spxpcb *)ipxp->ipxp_pcb;
|
|
|
|
KASSERT(cb != NULL, ("spx_slowtimo: cb == NULL"));
|
1995-10-26 20:31:59 +00:00
|
|
|
for (i = 0; i < SPXT_NTIMERS; i++) {
|
|
|
|
if (cb->s_timer[i] && --cb->s_timer[i] == 0) {
|
2006-03-25 17:28:42 +00:00
|
|
|
spx_timers(cb, i);
|
|
|
|
if (ipxp->ipxp_flags & IPXP_DROPPED)
|
2005-01-02 14:46:18 +00:00
|
|
|
break;
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-25 17:28:42 +00:00
|
|
|
if (!(ipxp->ipxp_flags & IPXP_DROPPED)) {
|
2005-01-02 14:46:18 +00:00
|
|
|
cb->s_idle++;
|
|
|
|
if (cb->s_rtt)
|
|
|
|
cb->s_rtt++;
|
|
|
|
}
|
2006-03-25 17:28:42 +00:00
|
|
|
IPX_UNLOCK(ipxp);
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LIST_UNLOCK();
|
2006-03-24 00:26:25 +00:00
|
|
|
SPX_LOCK();
|
|
|
|
spx_iss += SPX_ISSINCR/PR_SLOWHZ; /* increment iss */
|
|
|
|
SPX_UNLOCK();
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
1997-05-10 09:58:58 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
|
|
|
* SPX timer processing.
|
|
|
|
*/
|
2006-03-25 17:28:42 +00:00
|
|
|
static void
|
2006-03-24 00:15:58 +00:00
|
|
|
spx_timers(struct spxpcb *cb, int timer)
|
1995-10-26 20:31:59 +00:00
|
|
|
{
|
|
|
|
long rexmt;
|
|
|
|
int win;
|
|
|
|
|
2005-01-09 05:31:16 +00:00
|
|
|
IPX_LIST_LOCK_ASSERT();
|
|
|
|
IPX_LOCK_ASSERT(cb->s_ipxpcb);
|
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
cb->s_force = 1 + timer;
|
|
|
|
switch (timer) {
|
|
|
|
case SPXT_2MSL:
|
2006-03-25 14:29:03 +00:00
|
|
|
/*
|
|
|
|
* 2 MSL timeout in shutdown went off. TCP deletes
|
|
|
|
* connection control block.
|
|
|
|
*/
|
1995-10-26 20:31:59 +00:00
|
|
|
printf("spx: SPXT_2MSL went off for no reason\n");
|
|
|
|
cb->s_timer[timer] = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SPXT_REXMT:
|
2006-03-25 14:29:03 +00:00
|
|
|
/*
|
|
|
|
* Retransmission timer went off. Message has not been acked
|
|
|
|
* within retransmit interval. Back off to a longer
|
|
|
|
* retransmit interval and retransmit one packet.
|
|
|
|
*/
|
1995-10-26 20:31:59 +00:00
|
|
|
if (++cb->s_rxtshift > SPX_MAXRXTSHIFT) {
|
|
|
|
cb->s_rxtshift = SPX_MAXRXTSHIFT;
|
|
|
|
spxstat.spxs_timeoutdrop++;
|
2005-01-09 05:25:02 +00:00
|
|
|
spx_drop(cb, ETIMEDOUT);
|
1995-10-26 20:31:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
spxstat.spxs_rexmttimeo++;
|
|
|
|
rexmt = ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1;
|
|
|
|
rexmt *= spx_backoff[cb->s_rxtshift];
|
|
|
|
SPXT_RANGESET(cb->s_rxtcur, rexmt, SPXTV_MIN, SPXTV_REXMTMAX);
|
|
|
|
cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
|
2006-03-24 13:58:23 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
2006-03-24 13:58:23 +00:00
|
|
|
* If we have backed off fairly far, our srtt estimate is
|
|
|
|
* probably bogus. Clobber it so we'll take the next rtt
|
|
|
|
* measurement as our srtt; move the current srtt into rttvar
|
|
|
|
* to keep the current retransmit times until then.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
if (cb->s_rxtshift > SPX_MAXRXTSHIFT / 4 ) {
|
|
|
|
cb->s_rttvar += (cb->s_srtt >> 2);
|
|
|
|
cb->s_srtt = 0;
|
|
|
|
}
|
|
|
|
cb->s_snxt = cb->s_rack;
|
2006-03-24 13:58:23 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
|
|
|
* If timing a packet, stop the timer.
|
|
|
|
*/
|
|
|
|
cb->s_rtt = 0;
|
2006-03-24 13:58:23 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
/*
|
|
|
|
* See very long discussion in tcp_timer.c about congestion
|
2006-03-24 13:58:23 +00:00
|
|
|
* window and sstrhesh.
|
1995-10-26 20:31:59 +00:00
|
|
|
*/
|
|
|
|
win = min(cb->s_swnd, (cb->s_cwnd/CUNIT)) / 2;
|
|
|
|
if (win < 2)
|
|
|
|
win = 2;
|
|
|
|
cb->s_cwnd = CUNIT;
|
|
|
|
cb->s_ssthresh = win * CUNIT;
|
2005-01-02 14:03:47 +00:00
|
|
|
spx_output(cb, NULL);
|
1995-10-26 20:31:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SPXT_PERSIST:
|
2006-03-24 13:58:23 +00:00
|
|
|
/*
|
|
|
|
* Persistance timer into zero window. Force a probe to be
|
|
|
|
* sent.
|
|
|
|
*/
|
1995-10-26 20:31:59 +00:00
|
|
|
spxstat.spxs_persisttimeo++;
|
|
|
|
spx_setpersist(cb);
|
2005-01-02 14:03:47 +00:00
|
|
|
spx_output(cb, NULL);
|
1995-10-26 20:31:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SPXT_KEEP:
|
2006-03-24 13:58:23 +00:00
|
|
|
/*
|
|
|
|
* Keep-alive timer went off; send something or drop
|
|
|
|
* connection if idle for too long.
|
|
|
|
*/
|
1995-10-26 20:31:59 +00:00
|
|
|
spxstat.spxs_keeptimeo++;
|
|
|
|
if (cb->s_state < TCPS_ESTABLISHED)
|
|
|
|
goto dropit;
|
|
|
|
if (cb->s_ipxpcb->ipxp_socket->so_options & SO_KEEPALIVE) {
|
|
|
|
if (cb->s_idle >= SPXTV_MAXIDLE)
|
|
|
|
goto dropit;
|
|
|
|
spxstat.spxs_keepprobe++;
|
2005-01-02 14:03:47 +00:00
|
|
|
spx_output(cb, NULL);
|
2002-05-31 11:52:35 +00:00
|
|
|
} else
|
1995-10-26 20:31:59 +00:00
|
|
|
cb->s_idle = 0;
|
|
|
|
cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
|
|
|
|
break;
|
2006-03-24 13:58:23 +00:00
|
|
|
|
1995-10-26 20:31:59 +00:00
|
|
|
dropit:
|
|
|
|
spxstat.spxs_keepdrops++;
|
2005-01-09 05:25:02 +00:00
|
|
|
spx_drop(cb, ETIMEDOUT);
|
1995-10-26 20:31:59 +00:00
|
|
|
break;
|
2006-03-25 14:29:03 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
panic("spx_timers: unknown timer %d", timer);
|
1995-10-26 20:31:59 +00:00
|
|
|
}
|
|
|
|
}
|