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
39 #include <sys/param.h>
40 #include <sys/systm.h>
42 #include <sys/malloc.h>
44 #include <sys/mutex.h>
46 #include <sys/protosw.h>
47 #include <sys/socket.h>
48 #include <sys/socketvar.h>
50 #include <net/route.h>
51 #include <netinet/tcp_fsm.h>
53 #include <netipx/ipx.h>
54 #include <netipx/ipx_pcb.h>
55 #include <netipx/ipx_var.h>
56 #include <netipx/spx.h>
57 #include <netipx/spx_timer.h>
58 #include <netipx/spx_var.h>
59 #include <netipx/spx_debug.h>
62 * SPX protocol implementation.
64 static u_short spx_iss;
65 static u_short spx_newchecks[50];
66 static int spx_hardnosed;
67 static int spx_use_delack = 0;
68 static int traceallspxs = 0;
69 static struct spx spx_savesi;
70 static struct spx_istat spx_istat;
72 /* Following was struct spxstat spxstat; */
74 #define spxstat spx_istat.newstats
77 static int spx_backoff[SPX_MAXRXTSHIFT+1] =
78 { 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 };
80 static struct spxpcb *spx_close(struct spxpcb *cb);
81 static struct spxpcb *spx_disconnect(struct spxpcb *cb);
82 static struct spxpcb *spx_drop(struct spxpcb *cb, int errno);
83 static int spx_output(struct spxpcb *cb, struct mbuf *m0);
84 static int spx_reass(struct spxpcb *cb, struct spx *si);
85 static void spx_setpersist(struct spxpcb *cb);
86 static void spx_template(struct spxpcb *cb);
87 static struct spxpcb *spx_timers(struct spxpcb *cb, int timer);
88 static struct spxpcb *spx_usrclosed(struct spxpcb *cb);
90 static int spx_usr_abort(struct socket *so);
91 static int spx_accept(struct socket *so, struct sockaddr **nam);
92 static int spx_attach(struct socket *so, int proto, struct thread *td);
93 static int spx_bind(struct socket *so, struct sockaddr *nam, struct thread *td);
94 static int spx_connect(struct socket *so, struct sockaddr *nam,
96 static int spx_detach(struct socket *so);
97 static int spx_usr_disconnect(struct socket *so);
98 static int spx_listen(struct socket *so, struct thread *td);
99 static int spx_rcvd(struct socket *so, int flags);
100 static int spx_rcvoob(struct socket *so, struct mbuf *m, int flags);
101 static int spx_send(struct socket *so, int flags, struct mbuf *m,
102 struct sockaddr *addr, struct mbuf *control,
104 static int spx_shutdown(struct socket *so);
105 static int spx_sp_attach(struct socket *so, int proto, struct thread *td);
107 struct pr_usrreqs spx_usrreqs = {
108 spx_usr_abort, spx_accept, spx_attach, spx_bind,
109 spx_connect, pru_connect2_notsupp, ipx_control, spx_detach,
110 spx_usr_disconnect, spx_listen, ipx_peeraddr, spx_rcvd,
111 spx_rcvoob, spx_send, pru_sense_null, spx_shutdown,
112 ipx_sockaddr, sosend, soreceive, sopoll
115 struct pr_usrreqs spx_usrreq_sps = {
116 spx_usr_abort, spx_accept, spx_sp_attach, spx_bind,
117 spx_connect, pru_connect2_notsupp, ipx_control, spx_detach,
118 spx_usr_disconnect, spx_listen, ipx_peeraddr, spx_rcvd,
119 spx_rcvoob, spx_send, pru_sense_null, spx_shutdown,
120 ipx_sockaddr, sosend, soreceive, sopoll
127 spx_iss = 1; /* WRONG !! should fish it out of TODR */
132 register struct mbuf *m;
133 register struct ipxpcb *ipxp;
135 register struct spxpcb *cb;
136 register struct spx *si = mtod(m, struct spx *);
137 register struct socket *so;
141 spxstat.spxs_rcvtotal++;
143 panic("No ipxpcb in spx_input\n");
147 cb = ipxtospxpcb(ipxp);
151 if (m->m_len < sizeof(*si)) {
152 if ((m = m_pullup(m, sizeof(*si))) == NULL) {
153 spxstat.spxs_rcvshort++;
156 si = mtod(m, struct spx *);
158 si->si_seq = ntohs(si->si_seq);
159 si->si_ack = ntohs(si->si_ack);
160 si->si_alo = ntohs(si->si_alo);
162 so = ipxp->ipxp_socket;
164 if (so->so_options & SO_DEBUG || traceallspxs) {
165 ostate = cb->s_state;
168 if (so->so_options & SO_ACCEPTCONN) {
169 struct spxpcb *ocb = cb;
171 so = sonewconn(so, 0);
176 * This is ugly, but ....
178 * Mark socket as temporary until we're
179 * committed to keeping it. The code at
180 * ``drop'' and ``dropwithreset'' check the
181 * flag dropsocket to see if the temporary
182 * socket created here should be discarded.
183 * We mark the socket as discardable until
184 * we're committed to it below in TCPS_LISTEN.
187 ipxp = (struct ipxpcb *)so->so_pcb;
188 ipxp->ipxp_laddr = si->si_dna;
189 cb = ipxtospxpcb(ipxp);
190 cb->s_mtu = ocb->s_mtu; /* preserve sockopts */
191 cb->s_flags = ocb->s_flags; /* preserve sockopts */
192 cb->s_flags2 = ocb->s_flags2; /* preserve sockopts */
193 cb->s_state = TCPS_LISTEN;
197 * Packet received on connection.
198 * reset idle time and keep-alive timer;
201 cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
203 switch (cb->s_state) {
206 struct sockaddr_ipx *sipx, ssipx;
207 struct ipx_addr laddr;
210 * If somebody here was carying on a conversation
211 * and went away, and his pen pal thinks he can
212 * still talk, we get the misdirected packet.
214 if (spx_hardnosed && (si->si_did != 0 || si->si_seq != 0)) {
219 bzero(sipx, sizeof *sipx);
220 sipx->sipx_len = sizeof(*sipx);
221 sipx->sipx_family = AF_IPX;
222 sipx->sipx_addr = si->si_sna;
223 laddr = ipxp->ipxp_laddr;
224 if (ipx_nullhost(laddr))
225 ipxp->ipxp_laddr = si->si_dna;
226 if (ipx_pcbconnect(ipxp, (struct sockaddr *)sipx, &thread0)) {
227 ipxp->ipxp_laddr = laddr;
232 dropsocket = 0; /* committed to socket */
233 cb->s_did = si->si_sid;
234 cb->s_rack = si->si_ack;
235 cb->s_ralo = si->si_alo;
236 #define THREEWAYSHAKE
238 cb->s_state = TCPS_SYN_RECEIVED;
239 cb->s_force = 1 + SPXT_KEEP;
240 spxstat.spxs_accepts++;
241 cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
245 * This state means that we have heard a response
246 * to our acceptance of their connection
247 * It is probably logically unnecessary in this
250 case TCPS_SYN_RECEIVED: {
251 if (si->si_did != cb->s_sid) {
256 ipxp->ipxp_fport = si->si_sport;
257 cb->s_timer[SPXT_REXMT] = 0;
258 cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
260 cb->s_state = TCPS_ESTABLISHED;
261 spxstat.spxs_accepts++;
266 * This state means that we have gotten a response
267 * to our attempt to establish a connection.
268 * We fill in the data from the other side,
269 * telling us which port to respond to, instead of the well-
270 * known one we might have sent to in the first place.
271 * We also require that this is a response to our
275 if (si->si_did != cb->s_sid) {
279 spxstat.spxs_connects++;
280 cb->s_did = si->si_sid;
281 cb->s_rack = si->si_ack;
282 cb->s_ralo = si->si_alo;
283 cb->s_dport = ipxp->ipxp_fport = si->si_sport;
284 cb->s_timer[SPXT_REXMT] = 0;
285 cb->s_flags |= SF_ACKNOW;
287 cb->s_state = TCPS_ESTABLISHED;
288 /* Use roundtrip time of connection request for initial rtt */
290 cb->s_srtt = cb->s_rtt << 3;
291 cb->s_rttvar = cb->s_rtt << 1;
292 SPXT_RANGESET(cb->s_rxtcur,
293 ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1,
294 SPXTV_MIN, SPXTV_REXMTMAX);
298 if (so->so_options & SO_DEBUG || traceallspxs)
299 spx_trace(SA_INPUT, (u_char)ostate, cb, &spx_savesi, 0);
301 m->m_len -= sizeof(struct ipx);
302 m->m_pkthdr.len -= sizeof(struct ipx);
303 m->m_data += sizeof(struct ipx);
305 if (spx_reass(cb, si)) {
308 if (cb->s_force || (cb->s_flags & (SF_ACKNOW|SF_WIN|SF_RXT)))
309 spx_output(cb, (struct mbuf *)NULL);
310 cb->s_flags &= ~(SF_WIN|SF_RXT);
316 si->si_seq = ntohs(si->si_seq);
317 si->si_ack = ntohs(si->si_ack);
318 si->si_alo = ntohs(si->si_alo);
320 if (cb->s_ipxpcb->ipxp_socket->so_options & SO_DEBUG || traceallspxs)
321 spx_trace(SA_DROP, (u_char)ostate, cb, &spx_savesi, 0);
326 if (cb == 0 || cb->s_ipxpcb->ipxp_socket->so_options & SO_DEBUG ||
328 spx_trace(SA_DROP, (u_char)ostate, cb, &spx_savesi, 0);
332 static int spxrexmtthresh = 3;
335 * This is structurally similar to the tcp reassembly routine
336 * but its function is somewhat different: It merely queues
337 * packets up, and suppresses duplicates.
341 register struct spxpcb *cb;
342 register struct spx *si;
344 register struct spx_q *q;
345 register struct mbuf *m;
346 register struct socket *so = cb->s_ipxpcb->ipxp_socket;
347 char packetp = cb->s_flags & SF_HI;
354 * Update our news from them.
356 if (si->si_cc & SPX_SA)
357 cb->s_flags |= (spx_use_delack ? SF_DELACK : SF_ACKNOW);
358 if (SSEQ_GT(si->si_alo, cb->s_ralo))
359 cb->s_flags |= SF_WIN;
360 if (SSEQ_LEQ(si->si_ack, cb->s_rack)) {
361 if ((si->si_cc & SPX_SP) && cb->s_rack != (cb->s_smax + 1)) {
362 spxstat.spxs_rcvdupack++;
364 * If this is a completely duplicate ack
365 * and other conditions hold, we assume
366 * a packet has been dropped and retransmit
367 * it exactly as in tcp_input().
369 if (si->si_ack != cb->s_rack ||
370 si->si_alo != cb->s_ralo)
372 else if (++cb->s_dupacks == spxrexmtthresh) {
373 u_short onxt = cb->s_snxt;
374 int cwnd = cb->s_cwnd;
376 cb->s_snxt = si->si_ack;
378 cb->s_force = 1 + SPXT_REXMT;
379 spx_output(cb, (struct mbuf *)NULL);
380 cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
382 if (cwnd >= 4 * CUNIT)
383 cb->s_cwnd = cwnd / 2;
384 if (SSEQ_GT(onxt, cb->s_snxt))
394 * If our correspondent acknowledges data we haven't sent
395 * TCP would drop the packet after acking. We'll be a little
398 if (SSEQ_GT(si->si_ack, (cb->s_smax + 1))) {
399 spxstat.spxs_rcvacktoomuch++;
400 si->si_ack = cb->s_smax + 1;
402 spxstat.spxs_rcvackpack++;
404 * If transmit timer is running and timed sequence
405 * number was acked, update smoothed round trip time.
406 * See discussion of algorithm in tcp_input.c
408 if (cb->s_rtt && SSEQ_GT(si->si_ack, cb->s_rtseq)) {
409 spxstat.spxs_rttupdated++;
410 if (cb->s_srtt != 0) {
411 register short delta;
412 delta = cb->s_rtt - (cb->s_srtt >> 3);
413 if ((cb->s_srtt += delta) <= 0)
417 delta -= (cb->s_rttvar >> 2);
418 if ((cb->s_rttvar += delta) <= 0)
422 * No rtt measurement yet
424 cb->s_srtt = cb->s_rtt << 3;
425 cb->s_rttvar = cb->s_rtt << 1;
429 SPXT_RANGESET(cb->s_rxtcur,
430 ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1,
431 SPXTV_MIN, SPXTV_REXMTMAX);
434 * If all outstanding data is acked, stop retransmit
435 * timer and remember to restart (more output or persist).
436 * If there is more data to be acked, restart retransmit
437 * timer, using current (possibly backed-off) value;
439 if (si->si_ack == cb->s_smax + 1) {
440 cb->s_timer[SPXT_REXMT] = 0;
441 cb->s_flags |= SF_RXT;
442 } else if (cb->s_timer[SPXT_PERSIST] == 0)
443 cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
445 * When new data is acked, open the congestion window.
446 * If the window gives us less than ssthresh packets
447 * in flight, open exponentially (maxseg at a time).
448 * Otherwise open linearly (maxseg^2 / cwnd at a time).
451 if (cb->s_cwnd > cb->s_ssthresh)
452 incr = max(incr * incr / cb->s_cwnd, 1);
453 cb->s_cwnd = min(cb->s_cwnd + incr, cb->s_cwmx);
455 * Trim Acked data from output queue.
457 while ((m = so->so_snd.sb_mb) != NULL) {
458 if (SSEQ_LT((mtod(m, struct spx *))->si_seq, si->si_ack))
459 sbdroprecord(&so->so_snd);
464 cb->s_rack = si->si_ack;
466 if (SSEQ_LT(cb->s_snxt, cb->s_rack))
467 cb->s_snxt = cb->s_rack;
468 if (SSEQ_LT(cb->s_swl1, si->si_seq) || ((cb->s_swl1 == si->si_seq &&
469 (SSEQ_LT(cb->s_swl2, si->si_ack))) ||
470 (cb->s_swl2 == si->si_ack && SSEQ_LT(cb->s_ralo, si->si_alo)))) {
471 /* keep track of pure window updates */
472 if ((si->si_cc & SPX_SP) && cb->s_swl2 == si->si_ack
473 && SSEQ_LT(cb->s_ralo, si->si_alo)) {
474 spxstat.spxs_rcvwinupd++;
475 spxstat.spxs_rcvdupack--;
477 cb->s_ralo = si->si_alo;
478 cb->s_swl1 = si->si_seq;
479 cb->s_swl2 = si->si_ack;
480 cb->s_swnd = (1 + si->si_alo - si->si_ack);
481 if (cb->s_swnd > cb->s_smxw)
482 cb->s_smxw = cb->s_swnd;
483 cb->s_flags |= SF_WIN;
486 * If this packet number is higher than that which
487 * we have allocated refuse it, unless urgent
489 if (SSEQ_GT(si->si_seq, cb->s_alo)) {
490 if (si->si_cc & SPX_SP) {
491 spxstat.spxs_rcvwinprobe++;
494 spxstat.spxs_rcvpackafterwin++;
495 if (si->si_cc & SPX_OB) {
496 if (SSEQ_GT(si->si_seq, cb->s_alo + 60)) {
499 } /* else queue this packet; */
501 /*register struct socket *so = cb->s_ipxpcb->ipxp_socket;
502 if (so->so_state && SS_NOFDREF) {
512 * If this is a system packet, we don't need to
513 * queue it up, and won't update acknowledge #
515 if (si->si_cc & SPX_SP) {
519 * We have already seen this packet, so drop.
521 if (SSEQ_LT(si->si_seq, cb->s_ack)) {
523 spxstat.spxs_rcvduppack++;
524 if (si->si_seq == cb->s_ack - 1)
529 * Loop through all packets queued up to insert in
530 * appropriate sequence.
532 for (q = cb->s_q.si_next; q != &cb->s_q; q = q->si_next) {
533 if (si->si_seq == SI(q)->si_seq) {
534 spxstat.spxs_rcvduppack++;
537 if (SSEQ_LT(si->si_seq, SI(q)->si_seq)) {
538 spxstat.spxs_rcvoopack++;
542 insque(si, q->si_prev);
544 * If this packet is urgent, inform process
546 if (si->si_cc & SPX_OB) {
547 cb->s_iobc = ((char *)si)[1 + sizeof(*si)];
549 cb->s_oobflags |= SF_IOOB;
552 #define SPINC sizeof(struct spxhdr)
554 * Loop through all packets queued up to update acknowledge
555 * number, and present all acknowledged data to user;
556 * If in packet interface mode, show packet headers.
558 for (q = cb->s_q.si_next; q != &cb->s_q; q = q->si_next) {
559 if (SI(q)->si_seq == cb->s_ack) {
562 if (SI(q)->si_cc & SPX_OB) {
563 cb->s_oobflags &= ~SF_IOOB;
564 if (so->so_rcv.sb_cc)
565 so->so_oobmark = so->so_rcv.sb_cc;
567 so->so_state |= SS_RCVATMARK;
572 spxstat.spxs_rcvpack++;
574 if (cb->s_flags2 & SF_NEWCALL) {
575 struct spxhdr *sp = mtod(m, struct spxhdr *);
576 u_char dt = sp->spx_dt;
578 if (dt != cb->s_rhdr.spx_dt) {
580 m_getclr(M_DONTWAIT, MT_CONTROL);
585 cb->s_rhdr.spx_dt = dt;
586 mm->m_len = 5; /*XXX*/
589 *(u_char *)(&s[2]) = dt;
590 sbappend(&so->so_rcv, mm);
593 if (sp->spx_cc & SPX_OB) {
594 MCHTYPE(m, MT_OOBDATA);
597 so->so_state &= ~SS_RCVATMARK;
602 m->m_pkthdr.len -= SPINC;
604 if ((sp->spx_cc & SPX_EM) || packetp) {
605 sbappendrecord(&so->so_rcv, m);
608 sbappend(&so->so_rcv, m);
612 sbappendrecord(&so->so_rcv, m);
614 cb->s_rhdr = *mtod(m, struct spxhdr *);
617 m->m_pkthdr.len -= SPINC;
618 sbappend(&so->so_rcv, m);
629 spx_ctlinput(cmd, arg_as_sa, dummy)
631 struct sockaddr *arg_as_sa; /* XXX should be swapped with dummy */
634 caddr_t arg = (/* XXX */ caddr_t)arg_as_sa;
636 struct sockaddr_ipx *sipx;
638 if (cmd < 0 || cmd > PRC_NCMDS)
648 case PRC_HOSTUNREACH:
649 sipx = (struct sockaddr_ipx *)arg;
650 if (sipx->sipx_family != AF_IPX)
652 na = &sipx->sipx_addr;
663 register struct ipxpcb *ipxp;
665 register struct spxpcb *cb = (struct spxpcb *)(ipxp->ipxp_pcb);
666 register struct mbuf *m;
667 register struct spx *si;
671 struct mbuf *firstbad, *m0;
675 * The notification that we have sent
676 * too much is bad news -- we will
677 * have to go through queued up so far
678 * splitting ones which are too big and
679 * reassigning sequence numbers and checksums.
680 * we should then retransmit all packets from
681 * one above the offending packet to the last one
682 * we had sent (or our allocation)
683 * then the offending one so that the any queued
684 * data at our destination will be discarded.
686 ep = (struct ipx_errp *)ipxp->ipxp_notify_param;
687 sb = &ipxp->ipxp_socket->so_snd;
688 cb->s_mtu = ep->ipx_err_param;
689 badseq = SI(&ep->ipx_err_ipx)->si_seq;
690 for (m = sb->sb_mb; m != NULL; m = m->m_act) {
691 si = mtod(m, struct spx *);
692 if (si->si_seq == badseq)
699 /* calculate length */
700 for (m0 = m, len = 0; m != NULL; m = m->m_next)
702 if (len > cb->s_mtu) {
712 register struct spxpcb *cb;
715 struct socket *so = cb->s_ipxpcb->ipxp_socket;
716 register struct mbuf *m;
717 register struct spx *si = (struct spx *)NULL;
718 register struct sockbuf *sb = &so->so_snd;
719 int len = 0, win, rcv_win;
720 short span, off, recordp = 0;
722 int error = 0, sendalot;
732 * Make sure that packet isn't too big.
734 for (m = m0; m != NULL; m = m->m_next) {
737 if (m->m_flags & M_EOR)
740 datalen = (cb->s_flags & SF_HO) ?
741 len - sizeof(struct spxhdr) : len;
743 if (cb->s_flags & SF_PI) {
747 int oldEM = cb->s_cc & SPX_EM;
752 * Here we are only being called
753 * from usrreq(), so it is OK to
756 m = m_copym(m0, 0, mtu, M_TRYWAIT);
757 if (cb->s_flags & SF_NEWCALL) {
761 mm->m_flags &= ~M_EOR;
765 error = spx_output(cb, m);
778 * Force length even, by adding a "garbage byte" if
783 if (M_TRAILINGSPACE(m) >= 1)
786 struct mbuf *m1 = m_get(M_DONTWAIT, MT_DATA);
793 *(mtod(m1, u_char *)) = 0;
797 m = m_gethdr(M_DONTWAIT, MT_HEADER);
803 * Fill in mbuf with extended SP header
804 * and addresses and length put into network format.
806 MH_ALIGN(m, sizeof(struct spx));
807 m->m_len = sizeof(struct spx);
809 si = mtod(m, struct spx *);
810 si->si_i = *cb->s_ipx;
811 si->si_s = cb->s_shdr;
812 if ((cb->s_flags & SF_PI) && (cb->s_flags & SF_HO)) {
813 register struct spxhdr *sh;
814 if (m0->m_len < sizeof(*sh)) {
815 if((m0 = m_pullup(m0, sizeof(*sh))) == NULL) {
822 sh = mtod(m0, struct spxhdr *);
823 si->si_dt = sh->spx_dt;
824 si->si_cc |= sh->spx_cc & SPX_EM;
825 m0->m_len -= sizeof(*sh);
826 m0->m_data += sizeof(*sh);
830 if ((cb->s_flags2 & SF_NEWCALL) && recordp) {
834 if (cb->s_oobflags & SF_SOOB) {
837 * make sure OB packets convey exactly 1 byte.
838 * If the packet is 1 byte or larger, we
839 * have already guaranted there to be at least
840 * one garbage byte for the checksum, and
841 * extra bytes shouldn't hurt!
843 if (len > sizeof(*si)) {
845 len = (1 + sizeof(*si));
848 si->si_len = htons((u_short)len);
849 m->m_pkthdr.len = ((len - 1) | 1) + 1;
851 * queue stuff up for output
853 sbappendrecord(sb, m);
857 idle = (cb->s_smax == (cb->s_rack - 1));
861 off = cb->s_snxt - cb->s_rack;
862 win = min(cb->s_swnd, (cb->s_cwnd / CUNIT));
865 * If in persist timeout with window of 0, send a probe.
866 * Otherwise, if window is small but nonzero
867 * and timer expired, send what we can and go into
870 if (cb->s_force == 1 + SPXT_PERSIST) {
872 cb->s_timer[SPXT_PERSIST] = 0;
876 span = cb->s_seq - cb->s_rack;
877 len = min(span, win) - off;
881 * Window shrank after we went into it.
882 * If window shrank to 0, cancel pending
883 * restransmission and pull s_snxt back
884 * to (closed) window. We will enter persist
885 * state below. If the widndow didn't close completely,
886 * just wait for an ACK.
890 cb->s_timer[SPXT_REXMT] = 0;
891 cb->s_snxt = cb->s_rack;
896 rcv_win = sbspace(&so->so_rcv);
899 * Send if we owe peer an ACK.
901 if (cb->s_oobflags & SF_SOOB) {
903 * must transmit this out of band packet
905 cb->s_oobflags &= ~ SF_SOOB;
907 spxstat.spxs_sndurg++;
910 if (cb->s_flags & SF_ACKNOW)
912 if (cb->s_state < TCPS_ESTABLISHED)
915 * Silly window can't happen in spx.
916 * Code from tcp deleted.
921 * Compare available window to amount of window
922 * known to peer (as advertised window less
923 * next expected input.) If the difference is at least two
924 * packets or at least 35% of the mximum possible window,
925 * then want to send a window update to peer.
928 u_short delta = 1 + cb->s_alo - cb->s_ack;
929 int adv = rcv_win - (delta * cb->s_mtu);
931 if ((so->so_rcv.sb_cc == 0 && adv >= (2 * cb->s_mtu)) ||
932 (100 * adv / so->so_rcv.sb_hiwat >= 35)) {
933 spxstat.spxs_sndwinup++;
934 cb->s_flags |= SF_ACKNOW;
940 * Many comments from tcp_output.c are appropriate here
942 * If send window is too small, there is data to transmit, and no
943 * retransmit or persist is pending, then go to persist state.
944 * If nothing happens soon, send when timer expires:
945 * if window is nonzero, transmit what we can,
946 * otherwise send a probe.
948 if (so->so_snd.sb_cc && cb->s_timer[SPXT_REXMT] == 0 &&
949 cb->s_timer[SPXT_PERSIST] == 0) {
954 * No reason to send a packet, just return.
961 * Find requested packet.
965 cb->s_want = cb->s_snxt;
966 for (m = sb->sb_mb; m != NULL; m = m->m_act) {
967 si = mtod(m, struct spx *);
968 if (SSEQ_LEQ(cb->s_snxt, si->si_seq))
973 if (si->si_seq == cb->s_snxt)
976 spxstat.spxs_sndvoid++, si = 0;
984 alo = cb->s_ack - 1 + (rcv_win / ((short)cb->s_mtu));
985 if (SSEQ_LT(alo, cb->s_alo))
990 * must make a copy of this packet for
991 * ipx_output to monkey with
993 m = m_copy(dtom(si), 0, (int)M_COPYALL);
997 si = mtod(m, struct spx *);
998 if (SSEQ_LT(si->si_seq, cb->s_smax))
999 spxstat.spxs_sndrexmitpack++;
1001 spxstat.spxs_sndpack++;
1002 } else if (cb->s_force || cb->s_flags & SF_ACKNOW) {
1004 * Must send an acknowledgement or a probe
1007 spxstat.spxs_sndprobe++;
1008 if (cb->s_flags & SF_ACKNOW)
1009 spxstat.spxs_sndacks++;
1010 m = m_gethdr(M_DONTWAIT, MT_HEADER);
1014 * Fill in mbuf with extended SP header
1015 * and addresses and length put into network format.
1017 MH_ALIGN(m, sizeof(struct spx));
1018 m->m_len = sizeof(*si);
1019 m->m_pkthdr.len = sizeof(*si);
1020 si = mtod(m, struct spx *);
1021 si->si_i = *cb->s_ipx;
1022 si->si_s = cb->s_shdr;
1023 si->si_seq = cb->s_smax + 1;
1024 si->si_len = htons(sizeof(*si));
1025 si->si_cc |= SPX_SP;
1028 if (so->so_options & SO_DEBUG || traceallspxs)
1029 spx_trace(SA_OUTPUT, cb->s_state, cb, si, 0);
1033 * Stuff checksum and output datagram.
1035 if ((si->si_cc & SPX_SP) == 0) {
1036 if (cb->s_force != (1 + SPXT_PERSIST) ||
1037 cb->s_timer[SPXT_PERSIST] == 0) {
1039 * If this is a new packet and we are not currently
1040 * timing anything, time this one.
1042 if (SSEQ_LT(cb->s_smax, si->si_seq)) {
1043 cb->s_smax = si->si_seq;
1044 if (cb->s_rtt == 0) {
1045 spxstat.spxs_segstimed++;
1046 cb->s_rtseq = si->si_seq;
1051 * Set rexmt timer if not currently set,
1052 * Initial value for retransmit timer is smoothed
1053 * round-trip time + 2 * round-trip time variance.
1054 * Initialize shift counter which is used for backoff
1055 * of retransmit time.
1057 if (cb->s_timer[SPXT_REXMT] == 0 &&
1058 cb->s_snxt != cb->s_rack) {
1059 cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
1060 if (cb->s_timer[SPXT_PERSIST]) {
1061 cb->s_timer[SPXT_PERSIST] = 0;
1065 } else if (SSEQ_LT(cb->s_smax, si->si_seq)) {
1066 cb->s_smax = si->si_seq;
1068 } else if (cb->s_state < TCPS_ESTABLISHED) {
1070 cb->s_rtt = 1; /* Time initial handshake */
1071 if (cb->s_timer[SPXT_REXMT] == 0)
1072 cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
1076 * Do not request acks when we ack their data packets or
1077 * when we do a gratuitous window update.
1079 if (((si->si_cc & SPX_SP) == 0) || cb->s_force)
1080 si->si_cc |= SPX_SA;
1081 si->si_seq = htons(si->si_seq);
1082 si->si_alo = htons(alo);
1083 si->si_ack = htons(cb->s_ack);
1086 si->si_sum = ipx_cksum(m, ntohs(si->si_len));
1088 si->si_sum = 0xffff;
1091 if (so->so_options & SO_DEBUG || traceallspxs)
1092 spx_trace(SA_OUTPUT, cb->s_state, cb, si, 0);
1094 if (so->so_options & SO_DONTROUTE)
1095 error = ipx_outputfl(m, (struct route *)NULL, IPX_ROUTETOIF);
1097 error = ipx_outputfl(m, &cb->s_ipxpcb->ipxp_route, 0);
1102 spxstat.spxs_sndtotal++;
1104 * Data sent (as far as we can tell).
1105 * If this advertises a larger window than any other segment,
1106 * then remember the size of the advertized window.
1107 * Any pending ACK has now been sent.
1110 cb->s_flags &= ~(SF_ACKNOW|SF_DELACK);
1111 if (SSEQ_GT(alo, cb->s_alo))
1119 static int spx_do_persist_panics = 0;
1123 register struct spxpcb *cb;
1125 register int t = ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1;
1127 if (cb->s_timer[SPXT_REXMT] && spx_do_persist_panics)
1128 panic("spx_output REXMT");
1130 * Start/restart persistance timer.
1132 SPXT_RANGESET(cb->s_timer[SPXT_PERSIST],
1133 t*spx_backoff[cb->s_rxtshift],
1134 SPXTV_PERSMIN, SPXTV_PERSMAX);
1135 if (cb->s_rxtshift < SPX_MAXRXTSHIFT)
1140 spx_ctloutput(so, sopt)
1142 struct sockopt *sopt;
1144 struct ipxpcb *ipxp = sotoipxpcb(so);
1145 register struct spxpcb *cb;
1153 if (sopt->sopt_level != IPXPROTO_SPX) {
1154 /* This will have to be changed when we do more general
1155 stacking of protocols */
1156 return (ipx_ctloutput(so, sopt));
1161 cb = ipxtospxpcb(ipxp);
1163 switch (sopt->sopt_dir) {
1165 switch (sopt->sopt_name) {
1166 case SO_HEADERS_ON_INPUT:
1170 case SO_HEADERS_ON_OUTPUT:
1173 soptval = cb->s_flags & mask;
1174 error = sooptcopyout(sopt, &soptval, sizeof soptval);
1178 usoptval = cb->s_mtu;
1179 error = sooptcopyout(sopt, &usoptval, sizeof usoptval);
1182 case SO_LAST_HEADER:
1183 error = sooptcopyout(sopt, &cb->s_rhdr,
1187 case SO_DEFAULT_HEADERS:
1188 error = sooptcopyout(sopt, &cb->s_shdr,
1193 error = ENOPROTOOPT;
1198 switch (sopt->sopt_name) {
1199 /* XXX why are these shorts on get and ints on set?
1200 that doesn't make any sense... */
1201 case SO_HEADERS_ON_INPUT:
1205 case SO_HEADERS_ON_OUTPUT:
1208 error = sooptcopyin(sopt, &optval, sizeof optval,
1213 if (cb->s_flags & SF_PI) {
1215 cb->s_flags |= mask;
1217 cb->s_flags &= ~mask;
1218 } else error = EINVAL;
1222 error = sooptcopyin(sopt, &usoptval, sizeof usoptval,
1226 cb->s_mtu = usoptval;
1231 error = sooptcopyin(sopt, &optval, sizeof optval,
1236 cb->s_flags2 |= SF_NEWCALL;
1239 cb->s_flags2 &= ~SF_NEWCALL;
1245 case SO_DEFAULT_HEADERS:
1249 error = sooptcopyin(sopt, &sp, sizeof sp,
1253 cb->s_dt = sp.spx_dt;
1254 cb->s_cc = sp.spx_cc & SPX_EM;
1259 error = ENOPROTOOPT;
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.
1291 struct sockaddr **nam;
1293 struct ipxpcb *ipxp;
1294 struct sockaddr_ipx *sipx, ssipx;
1296 ipxp = sotoipxpcb(so);
1298 bzero(sipx, sizeof *sipx);
1299 sipx->sipx_len = sizeof *sipx;
1300 sipx->sipx_family = AF_IPX;
1301 sipx->sipx_addr = ipxp->ipxp_faddr;
1302 *nam = dup_sockaddr((struct sockaddr *)sipx, 0);
1307 spx_attach(so, proto, td)
1314 struct ipxpcb *ipxp;
1319 ipxp = sotoipxpcb(so);
1320 cb = ipxtospxpcb(ipxp);
1325 error = ipx_pcballoc(so, &ipxpcb, td);
1327 goto spx_attach_end;
1328 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
1329 error = soreserve(so, (u_long) 3072, (u_long) 3072);
1331 goto spx_attach_end;
1333 ipxp = sotoipxpcb(so);
1335 MALLOC(cb, struct spxpcb *, sizeof *cb, M_PCB, M_NOWAIT | M_ZERO);
1339 goto spx_attach_end;
1343 mm = m_getclr(M_DONTWAIT, MT_HEADER);
1347 goto spx_attach_end;
1349 cb->s_ipx = mtod(mm, struct ipx *);
1350 cb->s_state = TCPS_LISTEN;
1353 cb->s_q.si_next = cb->s_q.si_prev = &cb->s_q;
1354 cb->s_ipxpcb = ipxp;
1355 cb->s_mtu = 576 - sizeof(struct spx);
1356 cb->s_cwnd = sbspace(sb) * CUNIT / cb->s_mtu;
1357 cb->s_ssthresh = cb->s_cwnd;
1358 cb->s_cwmx = sbspace(sb) * CUNIT / (2 * sizeof(struct spx));
1359 /* Above is recomputed when connecting to account
1360 for changed buffering or mtu's */
1361 cb->s_rtt = SPXTV_SRTTBASE;
1362 cb->s_rttvar = SPXTV_SRTTDFLT << 2;
1363 SPXT_RANGESET(cb->s_rxtcur,
1364 ((SPXTV_SRTTBASE >> 2) + (SPXTV_SRTTDFLT << 2)) >> 1,
1365 SPXTV_MIN, SPXTV_REXMTMAX);
1366 ipxp->ipxp_pcb = (caddr_t)cb;
1373 spx_bind(so, nam, td)
1375 struct sockaddr *nam;
1378 struct ipxpcb *ipxp;
1380 ipxp = sotoipxpcb(so);
1382 return (ipx_pcbbind(ipxp, nam, td));
1386 * Initiate connection to peer.
1387 * Enter SYN_SENT state, and mark socket as connecting.
1388 * Start keep-alive timer, setup prototype header,
1389 * Send initial system packet requesting connection.
1392 spx_connect(so, nam, td)
1394 struct sockaddr *nam;
1399 struct ipxpcb *ipxp;
1402 ipxp = sotoipxpcb(so);
1403 cb = ipxtospxpcb(ipxp);
1406 if (ipxp->ipxp_lport == 0) {
1407 error = ipx_pcbbind(ipxp, (struct sockaddr *)NULL, td);
1409 goto spx_connect_end;
1411 error = ipx_pcbconnect(ipxp, nam, td);
1413 goto spx_connect_end;
1415 spxstat.spxs_connattempt++;
1416 cb->s_state = TCPS_SYN_SENT;
1419 cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
1420 cb->s_force = 1 + SPXTV_KEEP;
1422 * Other party is required to respond to
1423 * the port I send from, but he is not
1424 * required to answer from where I am sending to,
1425 * so allow wildcarding.
1426 * original port I am sending to is still saved in
1429 ipxp->ipxp_fport = 0;
1430 error = spx_output(cb, (struct mbuf *)NULL);
1441 struct ipxpcb *ipxp;
1444 ipxp = sotoipxpcb(so);
1445 cb = ipxtospxpcb(ipxp);
1450 if (cb->s_state > TCPS_LISTEN)
1459 * We may decide later to implement connection closing
1460 * handshaking at the spx level optionally.
1461 * here is the hook to do it:
1464 spx_usr_disconnect(so)
1468 struct ipxpcb *ipxp;
1471 ipxp = sotoipxpcb(so);
1472 cb = ipxtospxpcb(ipxp);
1486 struct ipxpcb *ipxp;
1490 ipxp = sotoipxpcb(so);
1491 cb = ipxtospxpcb(ipxp);
1493 if (ipxp->ipxp_lport == 0)
1494 error = ipx_pcbbind(ipxp, (struct sockaddr *)NULL, td);
1496 cb->s_state = TCPS_LISTEN;
1501 * After a receive, possibly send acknowledgment
1502 * updating allocation.
1510 struct ipxpcb *ipxp;
1513 ipxp = sotoipxpcb(so);
1514 cb = ipxtospxpcb(ipxp);
1517 cb->s_flags |= SF_RVD;
1518 spx_output(cb, (struct mbuf *)NULL);
1519 cb->s_flags &= ~SF_RVD;
1525 spx_rcvoob(so, m, flags)
1530 struct ipxpcb *ipxp;
1533 ipxp = sotoipxpcb(so);
1534 cb = ipxtospxpcb(ipxp);
1536 if ((cb->s_oobflags & SF_IOOB) || so->so_oobmark ||
1537 (so->so_state & SS_RCVATMARK)) {
1539 *mtod(m, caddr_t) = cb->s_iobc;
1546 spx_send(so, flags, m, addr, controlp, td)
1550 struct sockaddr *addr;
1551 struct mbuf *controlp;
1556 struct ipxpcb *ipxp;
1560 ipxp = sotoipxpcb(so);
1561 cb = ipxtospxpcb(ipxp);
1564 if (flags & PRUS_OOB) {
1565 if (sbspace(&so->so_snd) < -512) {
1569 cb->s_oobflags |= SF_SOOB;
1571 if (controlp != NULL) {
1572 u_short *p = mtod(controlp, u_short *);
1574 if ((p[0] == 5) && (p[1] == 1)) { /* XXXX, for testing */
1575 cb->s_shdr.spx_dt = *(u_char *)(&p[2]);
1581 error = spx_output(cb, m);
1584 if (controlp != NULL)
1598 struct ipxpcb *ipxp;
1602 ipxp = sotoipxpcb(so);
1603 cb = ipxtospxpcb(ipxp);
1607 cb = spx_usrclosed(cb);
1609 error = spx_output(cb, (struct mbuf *)NULL);
1615 spx_sp_attach(so, proto, td)
1621 struct ipxpcb *ipxp;
1623 error = spx_attach(so, proto, td);
1625 ipxp = sotoipxpcb(so);
1626 ((struct spxpcb *)ipxp->ipxp_pcb)->s_flags |=
1627 (SF_HI | SF_HO | SF_PI);
1633 * Create template to be used to send spx packets on a connection.
1634 * Called after host entry created, fills
1635 * in a skeletal spx header (choosing connection id),
1636 * minimizing the amount of work necessary when the connection is used.
1640 register struct spxpcb *cb;
1642 register struct ipxpcb *ipxp = cb->s_ipxpcb;
1643 register struct ipx *ipx = cb->s_ipx;
1644 register struct sockbuf *sb = &(ipxp->ipxp_socket->so_snd);
1646 ipx->ipx_pt = IPXPROTO_SPX;
1647 ipx->ipx_sna = ipxp->ipxp_laddr;
1648 ipx->ipx_dna = ipxp->ipxp_faddr;
1649 cb->s_sid = htons(spx_iss);
1650 spx_iss += SPX_ISSINCR/2;
1652 cb->s_cwnd = (sbspace(sb) * CUNIT) / cb->s_mtu;
1653 cb->s_ssthresh = cb->s_cwnd; /* Try to expand fast to full complement
1655 cb->s_cwmx = (sbspace(sb) * CUNIT) / (2 * sizeof(struct spx));
1656 cb->s_cwmx = max(cb->s_cwmx, cb->s_cwnd);
1657 /* But allow for lots of little packets as well */
1661 * Close a SPIP control block:
1662 * discard spx control block itself
1663 * discard ipx protocol control block
1664 * wake up any sleepers
1666 static struct spxpcb *
1668 register struct spxpcb *cb;
1670 register struct spx_q *s;
1671 struct ipxpcb *ipxp = cb->s_ipxpcb;
1672 struct socket *so = ipxp->ipxp_socket;
1673 register struct mbuf *m;
1675 s = cb->s_q.si_next;
1676 while (s != &(cb->s_q)) {
1678 m = dtom(s->si_prev);
1682 m_free(dtom(cb->s_ipx));
1685 soisdisconnected(so);
1686 ipx_pcbdetach(ipxp);
1687 spxstat.spxs_closed++;
1688 return ((struct spxpcb *)NULL);
1692 * Someday we may do level 3 handshaking
1693 * to close a connection or send a xerox style error.
1694 * For now, just close.
1696 static struct spxpcb *
1698 register struct spxpcb *cb;
1700 return (spx_close(cb));
1703 static struct spxpcb *
1705 register struct spxpcb *cb;
1707 return (spx_close(cb));
1711 * Drop connection, reporting
1712 * the specified error.
1714 static struct spxpcb *
1716 register struct spxpcb *cb;
1719 struct socket *so = cb->s_ipxpcb->ipxp_socket;
1722 * someday, in the xerox world
1723 * we will generate error protocol packets
1724 * announcing that the socket has gone away.
1726 if (TCPS_HAVERCVDSYN(cb->s_state)) {
1727 spxstat.spxs_drops++;
1728 cb->s_state = TCPS_CLOSED;
1731 spxstat.spxs_conndrops++;
1732 so->so_error = errno;
1733 return (spx_close(cb));
1737 * Fast timeout routine for processing delayed acks
1742 register struct ipxpcb *ipxp;
1743 register struct spxpcb *cb;
1746 ipxp = ipxpcb.ipxp_next;
1748 for (; ipxp != &ipxpcb; ipxp = ipxp->ipxp_next)
1749 if ((cb = (struct spxpcb *)ipxp->ipxp_pcb) != NULL &&
1750 (cb->s_flags & SF_DELACK)) {
1751 cb->s_flags &= ~SF_DELACK;
1752 cb->s_flags |= SF_ACKNOW;
1753 spxstat.spxs_delack++;
1754 spx_output(cb, (struct mbuf *)NULL);
1760 * spx protocol timeout routine called every 500 ms.
1761 * Updates the timers in all active pcb's and
1762 * causes finite state machine actions if timers expire.
1767 register struct ipxpcb *ip, *ipnxt;
1768 register struct spxpcb *cb;
1773 * Search through tcb's and update active timers.
1775 ip = ipxpcb.ipxp_next;
1780 while (ip != &ipxpcb) {
1781 cb = ipxtospxpcb(ip);
1782 ipnxt = ip->ipxp_next;
1785 for (i = 0; i < SPXT_NTIMERS; i++) {
1786 if (cb->s_timer[i] && --cb->s_timer[i] == 0) {
1788 if (ipnxt->ipxp_prev != ip)
1798 spx_iss += SPX_ISSINCR/PR_SLOWHZ; /* increment iss */
1803 * SPX timer processing.
1805 static struct spxpcb *
1806 spx_timers(cb, timer)
1807 register struct spxpcb *cb;
1813 cb->s_force = 1 + timer;
1817 * 2 MSL timeout in shutdown went off. TCP deletes connection
1821 printf("spx: SPXT_2MSL went off for no reason\n");
1822 cb->s_timer[timer] = 0;
1826 * Retransmission timer went off. Message has not
1827 * been acked within retransmit interval. Back off
1828 * to a longer retransmit interval and retransmit one packet.
1831 if (++cb->s_rxtshift > SPX_MAXRXTSHIFT) {
1832 cb->s_rxtshift = SPX_MAXRXTSHIFT;
1833 spxstat.spxs_timeoutdrop++;
1834 cb = spx_drop(cb, ETIMEDOUT);
1837 spxstat.spxs_rexmttimeo++;
1838 rexmt = ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1;
1839 rexmt *= spx_backoff[cb->s_rxtshift];
1840 SPXT_RANGESET(cb->s_rxtcur, rexmt, SPXTV_MIN, SPXTV_REXMTMAX);
1841 cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
1843 * If we have backed off fairly far, our srtt
1844 * estimate is probably bogus. Clobber it
1845 * so we'll take the next rtt measurement as our srtt;
1846 * move the current srtt into rttvar to keep the current
1847 * retransmit times until then.
1849 if (cb->s_rxtshift > SPX_MAXRXTSHIFT / 4 ) {
1850 cb->s_rttvar += (cb->s_srtt >> 2);
1853 cb->s_snxt = cb->s_rack;
1855 * If timing a packet, stop the timer.
1859 * See very long discussion in tcp_timer.c about congestion
1860 * window and sstrhesh
1862 win = min(cb->s_swnd, (cb->s_cwnd/CUNIT)) / 2;
1866 cb->s_ssthresh = win * CUNIT;
1867 spx_output(cb, (struct mbuf *)NULL);
1871 * Persistance timer into zero window.
1872 * Force a probe to be sent.
1875 spxstat.spxs_persisttimeo++;
1877 spx_output(cb, (struct mbuf *)NULL);
1881 * Keep-alive timer went off; send something
1882 * or drop connection if idle for too long.
1885 spxstat.spxs_keeptimeo++;
1886 if (cb->s_state < TCPS_ESTABLISHED)
1888 if (cb->s_ipxpcb->ipxp_socket->so_options & SO_KEEPALIVE) {
1889 if (cb->s_idle >= SPXTV_MAXIDLE)
1891 spxstat.spxs_keepprobe++;
1892 spx_output(cb, (struct mbuf *)NULL);
1895 cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
1898 spxstat.spxs_keepdrops++;
1899 cb = spx_drop(cb, ETIMEDOUT);