2 * Copyright (c) 1995, Mike Mitchell
3 * Copyright (c) 1984, 1985, 1986, 1987, 1993
4 * The Regents of the University of California. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the University of
17 * California, Berkeley and its contributors.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * $FreeBSD: src/sys/netipx/spx_usrreq.c,v 1.27.2.1 2001/02/22 09:44:18 bp Exp $
37 * $DragonFly: src/sys/netproto/ipx/spx_usrreq.c,v 1.18 2006/12/22 23:57:54 swildner Exp $
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/malloc.h>
46 #include <sys/protosw.h>
47 #include <sys/socket.h>
48 #include <sys/socketvar.h>
49 #include <sys/thread2.h>
51 #include <net/route.h>
52 #include <netinet/tcp_fsm.h>
58 #include "spx_timer.h"
60 #include "spx_debug.h"
63 * SPX protocol implementation.
65 static u_short spx_iss;
66 static u_short spx_newchecks[50];
67 static int spx_hardnosed;
68 static int spx_use_delack = 0;
69 static int traceallspxs = 0;
70 static struct spx spx_savesi;
71 static struct spx_istat spx_istat;
73 /* Following was struct spxstat spxstat; */
75 #define spxstat spx_istat.newstats
78 static int spx_backoff[SPX_MAXRXTSHIFT+1] =
79 { 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 };
81 static struct spxpcb *spx_close(struct spxpcb *cb);
82 static struct spxpcb *spx_disconnect(struct spxpcb *cb);
83 static struct spxpcb *spx_drop(struct spxpcb *cb, int errno);
84 static int spx_output(struct spxpcb *cb, struct mbuf *m0);
85 static int spx_reass(struct spxpcb *cb, struct spx *si, struct mbuf *si_m);
86 static void spx_setpersist(struct spxpcb *cb);
87 static void spx_template(struct spxpcb *cb);
88 static struct spxpcb *spx_timers(struct spxpcb *cb, int timer);
89 static struct spxpcb *spx_usrclosed(struct spxpcb *cb);
91 static int spx_usr_abort(struct socket *so);
92 static int spx_accept(struct socket *so, struct sockaddr **nam);
93 static int spx_attach(struct socket *so, int proto,
94 struct pru_attach_info *ai);
95 static int spx_bind(struct socket *so, struct sockaddr *nam,
97 static int spx_connect(struct socket *so, struct sockaddr *nam,
99 static int spx_detach(struct socket *so);
100 static int spx_usr_disconnect(struct socket *so);
101 static int spx_listen(struct socket *so, struct thread *td);
102 static int spx_rcvd(struct socket *so, int flags);
103 static int spx_rcvoob(struct socket *so, struct mbuf *m, int flags);
104 static int spx_send(struct socket *so, int flags, struct mbuf *m,
105 struct sockaddr *addr, struct mbuf *control,
107 static int spx_shutdown(struct socket *so);
108 static int spx_sp_attach(struct socket *so, int proto,
109 struct pru_attach_info *ai);
111 struct pr_usrreqs spx_usrreqs = {
112 spx_usr_abort, spx_accept, spx_attach, spx_bind,
113 spx_connect, pru_connect2_notsupp, ipx_control, spx_detach,
114 spx_usr_disconnect, spx_listen, ipx_peeraddr, spx_rcvd,
115 spx_rcvoob, spx_send, pru_sense_null, spx_shutdown,
116 ipx_sockaddr, sosend, soreceive, sopoll
119 struct pr_usrreqs spx_usrreq_sps = {
120 spx_usr_abort, spx_accept, spx_sp_attach, spx_bind,
121 spx_connect, pru_connect2_notsupp, ipx_control, spx_detach,
122 spx_usr_disconnect, spx_listen, ipx_peeraddr, spx_rcvd,
123 spx_rcvoob, spx_send, pru_sense_null, spx_shutdown,
124 ipx_sockaddr, sosend, soreceive, sopoll
127 static MALLOC_DEFINE(M_SPX_Q, "ipx_spx_q", "IPX Packet Management");
133 spx_iss = 1; /* WRONG !! should fish it out of TODR */
137 spx_input(struct mbuf *m, struct ipxpcb *ipxp)
145 spxstat.spxs_rcvtotal++;
147 panic("No ipxpcb in spx_input\n");
151 cb = ipxtospxpcb(ipxp);
155 if (m->m_len < sizeof(struct spx)) {
156 if ((m = m_pullup(m, sizeof(*si))) == NULL) {
157 spxstat.spxs_rcvshort++;
161 si = mtod(m, struct spx *);
162 si->si_seq = ntohs(si->si_seq);
163 si->si_ack = ntohs(si->si_ack);
164 si->si_alo = ntohs(si->si_alo);
166 so = ipxp->ipxp_socket;
168 if (so->so_options & SO_DEBUG || traceallspxs) {
169 ostate = cb->s_state;
172 if (so->so_options & SO_ACCEPTCONN) {
173 struct spxpcb *ocb = cb;
175 so = sonewconn(so, 0);
180 * This is ugly, but ....
182 * Mark socket as temporary until we're
183 * committed to keeping it. The code at
184 * ``drop'' and ``dropwithreset'' check the
185 * flag dropsocket to see if the temporary
186 * socket created here should be discarded.
187 * We mark the socket as discardable until
188 * we're committed to it below in TCPS_LISTEN.
191 ipxp = (struct ipxpcb *)so->so_pcb;
192 ipxp->ipxp_laddr = si->si_dna;
193 cb = ipxtospxpcb(ipxp);
194 cb->s_mtu = ocb->s_mtu; /* preserve sockopts */
195 cb->s_flags = ocb->s_flags; /* preserve sockopts */
196 cb->s_flags2 = ocb->s_flags2; /* preserve sockopts */
197 cb->s_state = TCPS_LISTEN;
201 * Packet received on connection.
202 * reset idle time and keep-alive timer;
205 cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
207 switch (cb->s_state) {
210 struct sockaddr_ipx *sipx, ssipx;
211 struct ipx_addr laddr;
214 * If somebody here was carying on a conversation
215 * and went away, and his pen pal thinks he can
216 * still talk, we get the misdirected packet.
218 if (spx_hardnosed && (si->si_did != 0 || si->si_seq != 0)) {
223 bzero(sipx, sizeof *sipx);
224 sipx->sipx_len = sizeof(*sipx);
225 sipx->sipx_family = AF_IPX;
226 sipx->sipx_addr = si->si_sna;
227 laddr = ipxp->ipxp_laddr;
228 if (ipx_nullhost(laddr))
229 ipxp->ipxp_laddr = si->si_dna;
230 if (ipx_pcbconnect(ipxp, (struct sockaddr *)sipx, &thread0)) {
231 ipxp->ipxp_laddr = laddr;
236 dropsocket = 0; /* committed to socket */
237 cb->s_did = si->si_sid;
238 cb->s_rack = si->si_ack;
239 cb->s_ralo = si->si_alo;
240 #define THREEWAYSHAKE
242 cb->s_state = TCPS_SYN_RECEIVED;
243 cb->s_force = 1 + SPXT_KEEP;
244 spxstat.spxs_accepts++;
245 cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
249 * This state means that we have heard a response
250 * to our acceptance of their connection
251 * It is probably logically unnecessary in this
254 case TCPS_SYN_RECEIVED: {
255 if (si->si_did != cb->s_sid) {
260 ipxp->ipxp_fport = si->si_sport;
261 cb->s_timer[SPXT_REXMT] = 0;
262 cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
264 cb->s_state = TCPS_ESTABLISHED;
265 spxstat.spxs_accepts++;
270 * This state means that we have gotten a response
271 * to our attempt to establish a connection.
272 * We fill in the data from the other side,
273 * telling us which port to respond to, instead of the well-
274 * known one we might have sent to in the first place.
275 * We also require that this is a response to our
279 if (si->si_did != cb->s_sid) {
283 spxstat.spxs_connects++;
284 cb->s_did = si->si_sid;
285 cb->s_rack = si->si_ack;
286 cb->s_ralo = si->si_alo;
287 cb->s_dport = ipxp->ipxp_fport = si->si_sport;
288 cb->s_timer[SPXT_REXMT] = 0;
289 cb->s_flags |= SF_ACKNOW;
291 cb->s_state = TCPS_ESTABLISHED;
292 /* Use roundtrip time of connection request for initial rtt */
294 cb->s_srtt = cb->s_rtt << 3;
295 cb->s_rttvar = cb->s_rtt << 1;
296 SPXT_RANGESET(cb->s_rxtcur,
297 ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1,
298 SPXTV_MIN, SPXTV_REXMTMAX);
302 if (so->so_options & SO_DEBUG || traceallspxs)
303 spx_trace(SA_INPUT, (u_char)ostate, cb, &spx_savesi, 0);
305 m->m_len -= sizeof(struct ipx);
306 m->m_pkthdr.len -= sizeof(struct ipx);
307 m->m_data += sizeof(struct ipx);
309 if (spx_reass(cb, si, m)) {
312 if (cb->s_force || (cb->s_flags & (SF_ACKNOW|SF_WIN|SF_RXT)))
313 spx_output(cb, (struct mbuf *)NULL);
314 cb->s_flags &= ~(SF_WIN|SF_RXT);
320 si->si_seq = ntohs(si->si_seq);
321 si->si_ack = ntohs(si->si_ack);
322 si->si_alo = ntohs(si->si_alo);
324 if (cb->s_ipxpcb->ipxp_socket->so_options & SO_DEBUG || traceallspxs)
325 spx_trace(SA_DROP, (u_char)ostate, cb, &spx_savesi, 0);
330 if (cb == 0 || cb->s_ipxpcb->ipxp_socket->so_options & SO_DEBUG ||
332 spx_trace(SA_DROP, (u_char)ostate, cb, &spx_savesi, 0);
336 static int spxrexmtthresh = 3;
339 * This is structurally similar to the tcp reassembly routine
340 * but its function is somewhat different: It merely queues
341 * packets up, and suppresses duplicates.
344 spx_reass(struct spxpcb *cb, struct spx *si, struct mbuf *si_m)
349 struct socket *so = cb->s_ipxpcb->ipxp_socket;
350 char packetp = cb->s_flags & SF_HI;
357 * Update our news from them.
359 if (si->si_cc & SPX_SA)
360 cb->s_flags |= (spx_use_delack ? SF_DELACK : SF_ACKNOW);
361 if (SSEQ_GT(si->si_alo, cb->s_ralo))
362 cb->s_flags |= SF_WIN;
363 if (SSEQ_LEQ(si->si_ack, cb->s_rack)) {
364 if ((si->si_cc & SPX_SP) && cb->s_rack != (cb->s_smax + 1)) {
365 spxstat.spxs_rcvdupack++;
367 * If this is a completely duplicate ack
368 * and other conditions hold, we assume
369 * a packet has been dropped and retransmit
370 * it exactly as in tcp_input().
372 if (si->si_ack != cb->s_rack ||
373 si->si_alo != cb->s_ralo)
375 else if (++cb->s_dupacks == spxrexmtthresh) {
376 u_short onxt = cb->s_snxt;
377 int cwnd = cb->s_cwnd;
379 cb->s_snxt = si->si_ack;
381 cb->s_force = 1 + SPXT_REXMT;
382 spx_output(cb, (struct mbuf *)NULL);
383 cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
385 if (cwnd >= 4 * CUNIT)
386 cb->s_cwnd = cwnd / 2;
387 if (SSEQ_GT(onxt, cb->s_snxt))
397 * If our correspondent acknowledges data we haven't sent
398 * TCP would drop the packet after acking. We'll be a little
401 if (SSEQ_GT(si->si_ack, (cb->s_smax + 1))) {
402 spxstat.spxs_rcvacktoomuch++;
403 si->si_ack = cb->s_smax + 1;
405 spxstat.spxs_rcvackpack++;
407 * If transmit timer is running and timed sequence
408 * number was acked, update smoothed round trip time.
409 * See discussion of algorithm in tcp_input.c
411 if (cb->s_rtt && SSEQ_GT(si->si_ack, cb->s_rtseq)) {
412 spxstat.spxs_rttupdated++;
413 if (cb->s_srtt != 0) {
415 delta = cb->s_rtt - (cb->s_srtt >> 3);
416 if ((cb->s_srtt += delta) <= 0)
420 delta -= (cb->s_rttvar >> 2);
421 if ((cb->s_rttvar += delta) <= 0)
425 * No rtt measurement yet
427 cb->s_srtt = cb->s_rtt << 3;
428 cb->s_rttvar = cb->s_rtt << 1;
432 SPXT_RANGESET(cb->s_rxtcur,
433 ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1,
434 SPXTV_MIN, SPXTV_REXMTMAX);
437 * If all outstanding data is acked, stop retransmit
438 * timer and remember to restart (more output or persist).
439 * If there is more data to be acked, restart retransmit
440 * timer, using current (possibly backed-off) value;
442 if (si->si_ack == cb->s_smax + 1) {
443 cb->s_timer[SPXT_REXMT] = 0;
444 cb->s_flags |= SF_RXT;
445 } else if (cb->s_timer[SPXT_PERSIST] == 0)
446 cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
448 * When new data is acked, open the congestion window.
449 * If the window gives us less than ssthresh packets
450 * in flight, open exponentially (maxseg at a time).
451 * Otherwise open linearly (maxseg^2 / cwnd at a time).
454 if (cb->s_cwnd > cb->s_ssthresh)
455 incr = max(incr * incr / cb->s_cwnd, 1);
456 cb->s_cwnd = min(cb->s_cwnd + incr, cb->s_cwmx);
458 * Trim Acked data from output queue.
460 while ((m = so->so_snd.sb_mb) != NULL) {
461 if (SSEQ_LT((mtod(m, struct spx *))->si_seq, si->si_ack))
462 sbdroprecord(&so->so_snd);
467 cb->s_rack = si->si_ack;
469 if (SSEQ_LT(cb->s_snxt, cb->s_rack))
470 cb->s_snxt = cb->s_rack;
471 if (SSEQ_LT(cb->s_swl1, si->si_seq) || ((cb->s_swl1 == si->si_seq &&
472 (SSEQ_LT(cb->s_swl2, si->si_ack))) ||
473 (cb->s_swl2 == si->si_ack && SSEQ_LT(cb->s_ralo, si->si_alo)))) {
474 /* keep track of pure window updates */
475 if ((si->si_cc & SPX_SP) && cb->s_swl2 == si->si_ack
476 && SSEQ_LT(cb->s_ralo, si->si_alo)) {
477 spxstat.spxs_rcvwinupd++;
478 spxstat.spxs_rcvdupack--;
480 cb->s_ralo = si->si_alo;
481 cb->s_swl1 = si->si_seq;
482 cb->s_swl2 = si->si_ack;
483 cb->s_swnd = (1 + si->si_alo - si->si_ack);
484 if (cb->s_swnd > cb->s_smxw)
485 cb->s_smxw = cb->s_swnd;
486 cb->s_flags |= SF_WIN;
489 * If this packet number is higher than that which
490 * we have allocated refuse it, unless urgent
492 if (SSEQ_GT(si->si_seq, cb->s_alo)) {
493 if (si->si_cc & SPX_SP) {
494 spxstat.spxs_rcvwinprobe++;
497 spxstat.spxs_rcvpackafterwin++;
498 if (si->si_cc & SPX_OB) {
499 if (SSEQ_GT(si->si_seq, cb->s_alo + 60)) {
502 } /* else queue this packet; */
504 /*register struct socket *so = cb->s_ipxpcb->ipxp_socket;
505 if (so->so_state && SS_NOFDREF) {
515 * If this is a system packet, we don't need to
516 * queue it up, and won't update acknowledge #
518 if (si->si_cc & SPX_SP) {
522 * We have already seen this packet, so drop.
524 if (SSEQ_LT(si->si_seq, cb->s_ack)) {
526 spxstat.spxs_rcvduppack++;
527 if (si->si_seq == cb->s_ack - 1)
532 * Loop through all packets queued up to insert in
533 * appropriate sequence.
535 for (q = cb->s_q.si_next; q != &cb->s_q; q = q->si_next) {
536 if (si->si_seq == SI(q)->si_seq) {
537 spxstat.spxs_rcvduppack++;
540 if (SSEQ_LT(si->si_seq, SI(q)->si_seq)) {
541 spxstat.spxs_rcvoopack++;
545 nq = kmalloc(sizeof(struct spx_q), M_SPX_Q, M_INTNOWAIT);
550 insque(nq, q->si_prev);
553 * If this packet is urgent, inform process
555 if (si->si_cc & SPX_OB) {
556 cb->s_iobc = ((char *)si)[1 + sizeof(*si)];
558 cb->s_oobflags |= SF_IOOB;
561 #define SPINC sizeof(struct spxhdr)
563 * Loop through all packets queued up to update acknowledge
564 * number, and present all acknowledged data to user;
565 * If in packet interface mode, show packet headers.
567 for (q = cb->s_q.si_next; q != &cb->s_q; q = q->si_next) {
568 if (SI(q)->si_seq == cb->s_ack) {
571 if (SI(q)->si_cc & SPX_OB) {
572 cb->s_oobflags &= ~SF_IOOB;
573 if (so->so_rcv.sb_cc)
574 so->so_oobmark = so->so_rcv.sb_cc;
576 so->so_state |= SS_RCVATMARK;
583 spxstat.spxs_rcvpack++;
585 if (cb->s_flags2 & SF_NEWCALL) {
586 struct spxhdr *sp = mtod(m, struct spxhdr *);
587 u_char dt = sp->spx_dt;
589 if (dt != cb->s_rhdr.spx_dt) {
591 m_getclr(MB_DONTWAIT, MT_CONTROL);
596 cb->s_rhdr.spx_dt = dt;
597 mm->m_len = 5; /*XXX*/
600 *(u_char *)(&s[2]) = dt;
601 sbappend(&so->so_rcv, mm);
604 if (sp->spx_cc & SPX_OB) {
605 m_chtype(m, MT_OOBDATA);
608 so->so_state &= ~SS_RCVATMARK;
613 m->m_pkthdr.len -= SPINC;
615 if ((sp->spx_cc & SPX_EM) || packetp) {
616 sbappendrecord(&so->so_rcv, m);
619 sbappend(&so->so_rcv, m);
623 sbappendrecord(&so->so_rcv, m);
625 cb->s_rhdr = *mtod(m, struct spxhdr *);
628 m->m_pkthdr.len -= SPINC;
629 sbappend(&so->so_rcv, m);
640 spx_ctlinput(int cmd, struct sockaddr *arg_as_sa, void *dummy)
642 caddr_t arg = (/* XXX */ caddr_t)arg_as_sa;
644 struct sockaddr_ipx *sipx;
646 if (cmd < 0 || cmd > PRC_NCMDS)
656 case PRC_HOSTUNREACH:
657 sipx = (struct sockaddr_ipx *)arg;
658 if (sipx->sipx_family != AF_IPX)
660 na = &sipx->sipx_addr;
670 spx_fixmtu(struct ipxpcb *ipxp)
672 struct spxpcb *cb = (struct spxpcb *)(ipxp->ipxp_pcb);
678 struct mbuf *firstbad, *m0;
682 * The notification that we have sent
683 * too much is bad news -- we will
684 * have to go through queued up so far
685 * splitting ones which are too big and
686 * reassigning sequence numbers and checksums.
687 * we should then retransmit all packets from
688 * one above the offending packet to the last one
689 * we had sent (or our allocation)
690 * then the offending one so that the any queued
691 * data at our destination will be discarded.
693 ep = (struct ipx_errp *)ipxp->ipxp_notify_param;
694 sb = &ipxp->ipxp_socket->so_snd;
695 cb->s_mtu = ep->ipx_err_param;
696 badseq = ep->ipx_err_ipx.si_seq;
697 for (m = sb->sb_mb; m != NULL; m = m->m_nextpkt) {
698 si = mtod(m, struct spx *);
699 if (si->si_seq == badseq)
706 /* calculate length */
707 for (m0 = m, len = 0; m != NULL; m = m->m_next)
709 if (len > cb->s_mtu) {
718 spx_output(struct spxpcb *cb, struct mbuf *m0)
720 struct socket *so = cb->s_ipxpcb->ipxp_socket;
721 struct mbuf *m = NULL;
722 struct spx *si = NULL;
723 struct sockbuf *sb = &so->so_snd;
724 int len = 0, win, rcv_win;
725 short span, off, recordp = 0;
727 int error = 0, sendalot;
737 * Make sure that packet isn't too big.
739 for (m = m0; m != NULL; m = m->m_next) {
742 if (m->m_flags & M_EOR)
745 datalen = (cb->s_flags & SF_HO) ?
746 len - sizeof(struct spxhdr) : len;
748 if (cb->s_flags & SF_PI) {
752 int oldEM = cb->s_cc & SPX_EM;
757 * Here we are only being called
758 * from usrreq(), so it is OK to
761 m = m_copym(m0, 0, mtu, MB_WAIT);
762 if (cb->s_flags & SF_NEWCALL) {
766 mm->m_flags &= ~M_EOR;
770 error = spx_output(cb, m);
783 * Force length even, by adding a "garbage byte" if
788 if (M_TRAILINGSPACE(m) >= 1)
791 struct mbuf *m1 = m_get(MB_DONTWAIT, MT_DATA);
798 *(mtod(m1, u_char *)) = 0;
802 m = m_gethdr(MB_DONTWAIT, MT_HEADER);
808 * Fill in mbuf with extended SP header
809 * and addresses and length put into network format.
811 MH_ALIGN(m, sizeof(struct spx));
812 m->m_len = sizeof(struct spx);
814 si = mtod(m, struct spx *);
815 si->si_i = *cb->s_ipx;
816 si->si_s = cb->s_shdr;
817 if ((cb->s_flags & SF_PI) && (cb->s_flags & SF_HO)) {
819 if (m0->m_len < sizeof(*sh)) {
820 if((m0 = m_pullup(m0, sizeof(*sh))) == NULL) {
827 sh = mtod(m0, struct spxhdr *);
828 si->si_dt = sh->spx_dt;
829 si->si_cc |= sh->spx_cc & SPX_EM;
830 m0->m_len -= sizeof(*sh);
831 m0->m_data += sizeof(*sh);
835 if ((cb->s_flags2 & SF_NEWCALL) && recordp) {
839 if (cb->s_oobflags & SF_SOOB) {
842 * make sure OB packets convey exactly 1 byte.
843 * If the packet is 1 byte or larger, we
844 * have already guaranted there to be at least
845 * one garbage byte for the checksum, and
846 * extra bytes shouldn't hurt!
848 if (len > sizeof(*si)) {
850 len = (1 + sizeof(*si));
853 si->si_len = htons((u_short)len);
854 m->m_pkthdr.len = ((len - 1) | 1) + 1;
856 * queue stuff up for output
858 sbappendrecord(sb, m);
862 idle = (cb->s_smax == (cb->s_rack - 1));
866 off = cb->s_snxt - cb->s_rack;
867 win = min(cb->s_swnd, (cb->s_cwnd / CUNIT));
870 * If in persist timeout with window of 0, send a probe.
871 * Otherwise, if window is small but nonzero
872 * and timer expired, send what we can and go into
875 if (cb->s_force == 1 + SPXT_PERSIST) {
877 cb->s_timer[SPXT_PERSIST] = 0;
881 span = cb->s_seq - cb->s_rack;
882 len = min(span, win) - off;
886 * Window shrank after we went into it.
887 * If window shrank to 0, cancel pending
888 * restransmission and pull s_snxt back
889 * to (closed) window. We will enter persist
890 * state below. If the widndow didn't close completely,
891 * just wait for an ACK.
895 cb->s_timer[SPXT_REXMT] = 0;
896 cb->s_snxt = cb->s_rack;
901 rcv_win = sbspace(&so->so_rcv);
904 * Send if we owe peer an ACK.
906 if (cb->s_oobflags & SF_SOOB) {
908 * must transmit this out of band packet
910 cb->s_oobflags &= ~ SF_SOOB;
912 spxstat.spxs_sndurg++;
915 if (cb->s_flags & SF_ACKNOW)
917 if (cb->s_state < TCPS_ESTABLISHED)
920 * Silly window can't happen in spx.
921 * Code from tcp deleted.
926 * Compare available window to amount of window
927 * known to peer (as advertised window less
928 * next expected input.) If the difference is at least two
929 * packets or at least 35% of the mximum possible window,
930 * then want to send a window update to peer.
933 u_short delta = 1 + cb->s_alo - cb->s_ack;
934 int adv = rcv_win - (delta * cb->s_mtu);
936 if ((so->so_rcv.sb_cc == 0 && adv >= (2 * cb->s_mtu)) ||
937 (100 * adv / so->so_rcv.sb_hiwat >= 35)) {
938 spxstat.spxs_sndwinup++;
939 cb->s_flags |= SF_ACKNOW;
945 * Many comments from tcp_output.c are appropriate here
947 * If send window is too small, there is data to transmit, and no
948 * retransmit or persist is pending, then go to persist state.
949 * If nothing happens soon, send when timer expires:
950 * if window is nonzero, transmit what we can,
951 * otherwise send a probe.
953 if (so->so_snd.sb_cc && cb->s_timer[SPXT_REXMT] == 0 &&
954 cb->s_timer[SPXT_PERSIST] == 0) {
959 * No reason to send a packet, just return.
966 * Find requested packet.
970 cb->s_want = cb->s_snxt;
971 for (m = sb->sb_mb; m != NULL; m = m->m_nextpkt) {
972 si = mtod(m, struct spx *);
973 if (SSEQ_LEQ(cb->s_snxt, si->si_seq))
978 if (si->si_seq == cb->s_snxt)
981 spxstat.spxs_sndvoid++, si = 0;
989 alo = cb->s_ack - 1 + (rcv_win / ((short)cb->s_mtu));
990 if (SSEQ_LT(alo, cb->s_alo))
995 * must make a copy of this packet for
996 * ipx_output to monkey with
998 m = m_copy(m, 0, (int)M_COPYALL);
1002 si = mtod(m, struct spx *);
1003 if (SSEQ_LT(si->si_seq, cb->s_smax))
1004 spxstat.spxs_sndrexmitpack++;
1006 spxstat.spxs_sndpack++;
1007 } else if (cb->s_force || cb->s_flags & SF_ACKNOW) {
1009 * Must send an acknowledgement or a probe
1012 spxstat.spxs_sndprobe++;
1013 if (cb->s_flags & SF_ACKNOW)
1014 spxstat.spxs_sndacks++;
1015 m = m_gethdr(MB_DONTWAIT, MT_HEADER);
1019 * Fill in mbuf with extended SP header
1020 * and addresses and length put into network format.
1022 MH_ALIGN(m, sizeof(struct spx));
1023 m->m_len = sizeof(*si);
1024 m->m_pkthdr.len = sizeof(*si);
1025 si = mtod(m, struct spx *);
1026 si->si_i = *cb->s_ipx;
1027 si->si_s = cb->s_shdr;
1028 si->si_seq = cb->s_smax + 1;
1029 si->si_len = htons(sizeof(*si));
1030 si->si_cc |= SPX_SP;
1033 if (so->so_options & SO_DEBUG || traceallspxs)
1034 spx_trace(SA_OUTPUT, cb->s_state, cb, si, 0);
1038 * Stuff checksum and output datagram.
1040 if ((si->si_cc & SPX_SP) == 0) {
1041 if (cb->s_force != (1 + SPXT_PERSIST) ||
1042 cb->s_timer[SPXT_PERSIST] == 0) {
1044 * If this is a new packet and we are not currently
1045 * timing anything, time this one.
1047 if (SSEQ_LT(cb->s_smax, si->si_seq)) {
1048 cb->s_smax = si->si_seq;
1049 if (cb->s_rtt == 0) {
1050 spxstat.spxs_segstimed++;
1051 cb->s_rtseq = si->si_seq;
1056 * Set rexmt timer if not currently set,
1057 * Initial value for retransmit timer is smoothed
1058 * round-trip time + 2 * round-trip time variance.
1059 * Initialize shift counter which is used for backoff
1060 * of retransmit time.
1062 if (cb->s_timer[SPXT_REXMT] == 0 &&
1063 cb->s_snxt != cb->s_rack) {
1064 cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
1065 if (cb->s_timer[SPXT_PERSIST]) {
1066 cb->s_timer[SPXT_PERSIST] = 0;
1070 } else if (SSEQ_LT(cb->s_smax, si->si_seq)) {
1071 cb->s_smax = si->si_seq;
1073 } else if (cb->s_state < TCPS_ESTABLISHED) {
1075 cb->s_rtt = 1; /* Time initial handshake */
1076 if (cb->s_timer[SPXT_REXMT] == 0)
1077 cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
1081 * Do not request acks when we ack their data packets or
1082 * when we do a gratuitous window update.
1084 if (((si->si_cc & SPX_SP) == 0) || cb->s_force)
1085 si->si_cc |= SPX_SA;
1086 si->si_seq = htons(si->si_seq);
1087 si->si_alo = htons(alo);
1088 si->si_ack = htons(cb->s_ack);
1091 si->si_sum = ipx_cksum(m, ntohs(si->si_len));
1093 si->si_sum = 0xffff;
1096 if (so->so_options & SO_DEBUG || traceallspxs)
1097 spx_trace(SA_OUTPUT, cb->s_state, cb, si, 0);
1099 if (so->so_options & SO_DONTROUTE)
1100 error = ipx_outputfl(m, (struct route *)NULL, IPX_ROUTETOIF);
1102 error = ipx_outputfl(m, &cb->s_ipxpcb->ipxp_route, 0);
1107 spxstat.spxs_sndtotal++;
1109 * Data sent (as far as we can tell).
1110 * If this advertises a larger window than any other segment,
1111 * then remember the size of the advertized window.
1112 * Any pending ACK has now been sent.
1115 cb->s_flags &= ~(SF_ACKNOW|SF_DELACK);
1116 if (SSEQ_GT(alo, cb->s_alo))
1124 static int spx_do_persist_panics = 0;
1127 spx_setpersist(struct spxpcb *cb)
1129 int t = ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1;
1131 if (cb->s_timer[SPXT_REXMT] && spx_do_persist_panics)
1132 panic("spx_output REXMT");
1134 * Start/restart persistance timer.
1136 SPXT_RANGESET(cb->s_timer[SPXT_PERSIST],
1137 t*spx_backoff[cb->s_rxtshift],
1138 SPXTV_PERSMIN, SPXTV_PERSMAX);
1139 if (cb->s_rxtshift < SPX_MAXRXTSHIFT)
1144 spx_ctloutput(struct socket *so, struct sockopt *sopt)
1146 struct ipxpcb *ipxp = sotoipxpcb(so);
1155 if (sopt->sopt_level != IPXPROTO_SPX) {
1156 /* This will have to be changed when we do more general
1157 stacking of protocols */
1158 return (ipx_ctloutput(so, sopt));
1163 cb = ipxtospxpcb(ipxp);
1165 switch (sopt->sopt_dir) {
1167 switch (sopt->sopt_name) {
1168 case SO_HEADERS_ON_INPUT:
1172 case SO_HEADERS_ON_OUTPUT:
1175 soptval = cb->s_flags & mask;
1176 error = sooptcopyout(sopt, &soptval, sizeof soptval);
1180 usoptval = cb->s_mtu;
1181 error = sooptcopyout(sopt, &usoptval, sizeof usoptval);
1184 case SO_LAST_HEADER:
1185 error = sooptcopyout(sopt, &cb->s_rhdr,
1189 case SO_DEFAULT_HEADERS:
1190 error = sooptcopyout(sopt, &cb->s_shdr,
1195 error = ENOPROTOOPT;
1200 switch (sopt->sopt_name) {
1201 /* XXX why are these shorts on get and ints on set?
1202 that doesn't make any sense... */
1203 case SO_HEADERS_ON_INPUT:
1207 case SO_HEADERS_ON_OUTPUT:
1210 error = sooptcopyin(sopt, &optval, sizeof optval,
1215 if (cb->s_flags & SF_PI) {
1217 cb->s_flags |= mask;
1219 cb->s_flags &= ~mask;
1220 } else error = EINVAL;
1224 error = sooptcopyin(sopt, &usoptval, sizeof usoptval,
1228 cb->s_mtu = usoptval;
1233 error = sooptcopyin(sopt, &optval, sizeof optval,
1238 cb->s_flags2 |= SF_NEWCALL;
1241 cb->s_flags2 &= ~SF_NEWCALL;
1247 case SO_DEFAULT_HEADERS:
1251 error = sooptcopyin(sopt, &sp, sizeof sp,
1255 cb->s_dt = sp.spx_dt;
1256 cb->s_cc = sp.spx_cc & SPX_EM;
1261 error = ENOPROTOOPT;
1269 spx_usr_abort(struct socket *so)
1271 struct ipxpcb *ipxp;
1274 ipxp = sotoipxpcb(so);
1275 cb = ipxtospxpcb(ipxp);
1278 spx_drop(cb, ECONNABORTED);
1284 * Accept a connection. Essentially all the work is
1285 * done at higher levels; just return the address
1286 * of the peer, storing through addr.
1289 spx_accept(struct socket *so, struct sockaddr **nam)
1291 struct ipxpcb *ipxp;
1292 struct sockaddr_ipx *sipx, ssipx;
1294 ipxp = sotoipxpcb(so);
1296 bzero(sipx, sizeof *sipx);
1297 sipx->sipx_len = sizeof *sipx;
1298 sipx->sipx_family = AF_IPX;
1299 sipx->sipx_addr = ipxp->ipxp_faddr;
1300 *nam = dup_sockaddr((struct sockaddr *)sipx);
1305 spx_attach(struct socket *so, int proto, struct pru_attach_info *ai)
1308 struct ipxpcb *ipxp;
1313 ipxp = sotoipxpcb(so);
1314 cb = ipxtospxpcb(ipxp);
1319 error = ipx_pcballoc(so, &ipxpcb);
1321 goto spx_attach_end;
1322 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
1323 error = soreserve(so, (u_long) 3072, (u_long) 3072,
1326 goto spx_attach_end;
1328 ipxp = sotoipxpcb(so);
1330 MALLOC(cb, struct spxpcb *, sizeof *cb, M_PCB, M_INTWAIT | M_ZERO);
1333 mm = m_getclr(MB_DONTWAIT, MT_HEADER);
1337 goto spx_attach_end;
1340 cb->s_ipx = mtod(mm, struct ipx *);
1341 cb->s_state = TCPS_LISTEN;
1344 cb->s_q.si_next = cb->s_q.si_prev = &cb->s_q;
1345 cb->s_ipxpcb = ipxp;
1346 cb->s_mtu = 576 - sizeof(struct spx);
1347 cb->s_cwnd = sbspace(sb) * CUNIT / cb->s_mtu;
1348 cb->s_ssthresh = cb->s_cwnd;
1349 cb->s_cwmx = sbspace(sb) * CUNIT / (2 * sizeof(struct spx));
1350 /* Above is recomputed when connecting to account
1351 for changed buffering or mtu's */
1352 cb->s_rtt = SPXTV_SRTTBASE;
1353 cb->s_rttvar = SPXTV_SRTTDFLT << 2;
1354 SPXT_RANGESET(cb->s_rxtcur,
1355 ((SPXTV_SRTTBASE >> 2) + (SPXTV_SRTTDFLT << 2)) >> 1,
1356 SPXTV_MIN, SPXTV_REXMTMAX);
1357 ipxp->ipxp_pcb = (caddr_t)cb;
1364 spx_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
1366 struct ipxpcb *ipxp;
1368 ipxp = sotoipxpcb(so);
1370 return (ipx_pcbbind(ipxp, nam, td));
1374 * Initiate connection to peer.
1375 * Enter SYN_SENT state, and mark socket as connecting.
1376 * Start keep-alive timer, setup prototype header,
1377 * Send initial system packet requesting connection.
1380 spx_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
1383 struct ipxpcb *ipxp;
1386 ipxp = sotoipxpcb(so);
1387 cb = ipxtospxpcb(ipxp);
1390 if (ipxp->ipxp_lport == 0) {
1391 error = ipx_pcbbind(ipxp, (struct sockaddr *)NULL, td);
1393 goto spx_connect_end;
1395 error = ipx_pcbconnect(ipxp, nam, td);
1397 goto spx_connect_end;
1399 spxstat.spxs_connattempt++;
1400 cb->s_state = TCPS_SYN_SENT;
1403 cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
1404 cb->s_force = 1 + SPXTV_KEEP;
1406 * Other party is required to respond to
1407 * the port I send from, but he is not
1408 * required to answer from where I am sending to,
1409 * so allow wildcarding.
1410 * original port I am sending to is still saved in
1413 ipxp->ipxp_fport = 0;
1414 error = spx_output(cb, (struct mbuf *)NULL);
1421 spx_detach(struct socket *so)
1423 struct ipxpcb *ipxp;
1426 ipxp = sotoipxpcb(so);
1427 cb = ipxtospxpcb(ipxp);
1432 if (cb->s_state > TCPS_LISTEN)
1441 * We may decide later to implement connection closing
1442 * handshaking at the spx level optionally.
1443 * here is the hook to do it:
1446 spx_usr_disconnect(struct socket *so)
1448 struct ipxpcb *ipxp;
1451 ipxp = sotoipxpcb(so);
1452 cb = ipxtospxpcb(ipxp);
1461 spx_listen(struct socket *so, struct thread *td)
1464 struct ipxpcb *ipxp;
1468 ipxp = sotoipxpcb(so);
1469 cb = ipxtospxpcb(ipxp);
1471 if (ipxp->ipxp_lport == 0)
1472 error = ipx_pcbbind(ipxp, (struct sockaddr *)NULL, td);
1474 cb->s_state = TCPS_LISTEN;
1479 * After a receive, possibly send acknowledgment
1480 * updating allocation.
1483 spx_rcvd(struct socket *so, int flags)
1485 struct ipxpcb *ipxp;
1488 ipxp = sotoipxpcb(so);
1489 cb = ipxtospxpcb(ipxp);
1492 cb->s_flags |= SF_RVD;
1493 spx_output(cb, (struct mbuf *)NULL);
1494 cb->s_flags &= ~SF_RVD;
1500 spx_rcvoob(struct socket *so, struct mbuf *m, int flags)
1502 struct ipxpcb *ipxp;
1505 ipxp = sotoipxpcb(so);
1506 cb = ipxtospxpcb(ipxp);
1508 if ((cb->s_oobflags & SF_IOOB) || so->so_oobmark ||
1509 (so->so_state & SS_RCVATMARK)) {
1511 *mtod(m, caddr_t) = cb->s_iobc;
1518 spx_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
1519 struct mbuf *controlp, struct thread *td)
1522 struct ipxpcb *ipxp;
1526 ipxp = sotoipxpcb(so);
1527 cb = ipxtospxpcb(ipxp);
1530 if (flags & PRUS_OOB) {
1531 if (sbspace(&so->so_snd) < -512) {
1535 cb->s_oobflags |= SF_SOOB;
1537 if (controlp != NULL) {
1538 u_short *p = mtod(controlp, u_short *);
1540 if ((p[0] == 5) && (p[1] == 1)) { /* XXXX, for testing */
1541 cb->s_shdr.spx_dt = *(u_char *)(&p[2]);
1547 error = spx_output(cb, m);
1550 if (controlp != NULL)
1559 spx_shutdown(struct socket *so)
1562 struct ipxpcb *ipxp;
1566 ipxp = sotoipxpcb(so);
1567 cb = ipxtospxpcb(ipxp);
1571 cb = spx_usrclosed(cb);
1573 error = spx_output(cb, (struct mbuf *)NULL);
1579 spx_sp_attach(struct socket *so, int proto, struct pru_attach_info *ai)
1582 struct ipxpcb *ipxp;
1584 error = spx_attach(so, proto, ai);
1586 ipxp = sotoipxpcb(so);
1587 ((struct spxpcb *)ipxp->ipxp_pcb)->s_flags |=
1588 (SF_HI | SF_HO | SF_PI);
1594 * Create template to be used to send spx packets on a connection.
1595 * Called after host entry created, fills
1596 * in a skeletal spx header (choosing connection id),
1597 * minimizing the amount of work necessary when the connection is used.
1600 spx_template(struct spxpcb *cb)
1602 struct ipxpcb *ipxp = cb->s_ipxpcb;
1603 struct ipx *ipx = cb->s_ipx;
1604 struct sockbuf *sb = &(ipxp->ipxp_socket->so_snd);
1606 ipx->ipx_pt = IPXPROTO_SPX;
1607 ipx->ipx_sna = ipxp->ipxp_laddr;
1608 ipx->ipx_dna = ipxp->ipxp_faddr;
1609 cb->s_sid = htons(spx_iss);
1610 spx_iss += SPX_ISSINCR/2;
1612 cb->s_cwnd = (sbspace(sb) * CUNIT) / cb->s_mtu;
1613 cb->s_ssthresh = cb->s_cwnd; /* Try to expand fast to full complement
1615 cb->s_cwmx = (sbspace(sb) * CUNIT) / (2 * sizeof(struct spx));
1616 cb->s_cwmx = max(cb->s_cwmx, cb->s_cwnd);
1617 /* But allow for lots of little packets as well */
1621 * Close a SPIP control block:
1622 * discard spx control block itself
1623 * discard ipx protocol control block
1624 * wake up any sleepers
1626 static struct spxpcb *
1627 spx_close(struct spxpcb *cb)
1631 struct ipxpcb *ipxp = cb->s_ipxpcb;
1632 struct socket *so = ipxp->ipxp_socket;
1635 q = cb->s_q.si_next;
1636 while (q != &(cb->s_q)) {
1644 m_free(cb->s_ipx_m);
1647 soisdisconnected(so);
1648 ipx_pcbdetach(ipxp);
1649 spxstat.spxs_closed++;
1650 return ((struct spxpcb *)NULL);
1654 * Someday we may do level 3 handshaking
1655 * to close a connection or send a xerox style error.
1656 * For now, just close.
1658 static struct spxpcb *
1659 spx_usrclosed(struct spxpcb *cb)
1661 return (spx_close(cb));
1664 static struct spxpcb *
1665 spx_disconnect(struct spxpcb *cb)
1667 return (spx_close(cb));
1671 * Drop connection, reporting
1672 * the specified error.
1674 static struct spxpcb *
1675 spx_drop(struct spxpcb *cb, int errno)
1677 struct socket *so = cb->s_ipxpcb->ipxp_socket;
1680 * someday, in the xerox world
1681 * we will generate error protocol packets
1682 * announcing that the socket has gone away.
1684 if (TCPS_HAVERCVDSYN(cb->s_state)) {
1685 spxstat.spxs_drops++;
1686 cb->s_state = TCPS_CLOSED;
1689 spxstat.spxs_conndrops++;
1690 so->so_error = errno;
1691 return (spx_close(cb));
1695 * Fast timeout routine for processing delayed acks
1700 struct ipxpcb *ipxp;
1704 ipxp = ipxpcb.ipxp_next;
1706 for (; ipxp != &ipxpcb; ipxp = ipxp->ipxp_next) {
1707 if ((cb = (struct spxpcb *)ipxp->ipxp_pcb) != NULL &&
1708 (cb->s_flags & SF_DELACK)) {
1709 cb->s_flags &= ~SF_DELACK;
1710 cb->s_flags |= SF_ACKNOW;
1711 spxstat.spxs_delack++;
1712 spx_output(cb, (struct mbuf *)NULL);
1720 * spx protocol timeout routine called every 500 ms.
1721 * Updates the timers in all active pcb's and
1722 * causes finite state machine actions if timers expire.
1727 struct ipxpcb *ip, *ipnxt;
1732 * Search through tcb's and update active timers.
1735 ip = ipxpcb.ipxp_next;
1740 while (ip != &ipxpcb) {
1741 cb = ipxtospxpcb(ip);
1742 ipnxt = ip->ipxp_next;
1745 for (i = 0; i < SPXT_NTIMERS; i++) {
1746 if (cb->s_timer[i] && --cb->s_timer[i] == 0) {
1748 if (ipnxt->ipxp_prev != ip)
1758 spx_iss += SPX_ISSINCR/PR_SLOWHZ; /* increment iss */
1763 * SPX timer processing.
1765 static struct spxpcb *
1766 spx_timers(struct spxpcb *cb, int timer)
1771 cb->s_force = 1 + timer;
1775 * 2 MSL timeout in shutdown went off. TCP deletes connection
1779 kprintf("spx: SPXT_2MSL went off for no reason\n");
1780 cb->s_timer[timer] = 0;
1784 * Retransmission timer went off. Message has not
1785 * been acked within retransmit interval. Back off
1786 * to a longer retransmit interval and retransmit one packet.
1789 if (++cb->s_rxtshift > SPX_MAXRXTSHIFT) {
1790 cb->s_rxtshift = SPX_MAXRXTSHIFT;
1791 spxstat.spxs_timeoutdrop++;
1792 cb = spx_drop(cb, ETIMEDOUT);
1795 spxstat.spxs_rexmttimeo++;
1796 rexmt = ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1;
1797 rexmt *= spx_backoff[cb->s_rxtshift];
1798 SPXT_RANGESET(cb->s_rxtcur, rexmt, SPXTV_MIN, SPXTV_REXMTMAX);
1799 cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
1801 * If we have backed off fairly far, our srtt
1802 * estimate is probably bogus. Clobber it
1803 * so we'll take the next rtt measurement as our srtt;
1804 * move the current srtt into rttvar to keep the current
1805 * retransmit times until then.
1807 if (cb->s_rxtshift > SPX_MAXRXTSHIFT / 4 ) {
1808 cb->s_rttvar += (cb->s_srtt >> 2);
1811 cb->s_snxt = cb->s_rack;
1813 * If timing a packet, stop the timer.
1817 * See very long discussion in tcp_timer.c about congestion
1818 * window and sstrhesh
1820 win = min(cb->s_swnd, (cb->s_cwnd/CUNIT)) / 2;
1824 cb->s_ssthresh = win * CUNIT;
1825 spx_output(cb, (struct mbuf *)NULL);
1829 * Persistance timer into zero window.
1830 * Force a probe to be sent.
1833 spxstat.spxs_persisttimeo++;
1835 spx_output(cb, (struct mbuf *)NULL);
1839 * Keep-alive timer went off; send something
1840 * or drop connection if idle for too long.
1843 spxstat.spxs_keeptimeo++;
1844 if (cb->s_state < TCPS_ESTABLISHED)
1846 if (cb->s_ipxpcb->ipxp_socket->so_options & SO_KEEPALIVE) {
1847 if (cb->s_idle >= SPXTV_MAXIDLE)
1849 spxstat.spxs_keepprobe++;
1850 spx_output(cb, (struct mbuf *)NULL);
1853 cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
1856 spxstat.spxs_keepdrops++;
1857 cb = spx_drop(cb, ETIMEDOUT);