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 $
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/malloc.h>
45 #include <sys/protosw.h>
46 #include <sys/socket.h>
47 #include <sys/socketvar.h>
48 #include <sys/socketvar2.h>
50 #include <sys/thread2.h>
51 #include <sys/msgport2.h>
53 #include <net/route.h>
54 #include <netinet/tcp_fsm.h>
60 #include "spx_timer.h"
62 #include "spx_debug.h"
65 * SPX protocol implementation.
67 static u_short spx_iss;
68 static u_short spx_newchecks[50];
69 static int spx_hardnosed;
70 static int spx_use_delack = 0;
71 static int traceallspxs = 0;
72 static struct spx spx_savesi;
73 static struct spx_istat spx_istat;
75 /* Following was struct spxstat spxstat; */
77 #define spxstat spx_istat.newstats
80 static int spx_backoff[SPX_MAXRXTSHIFT+1] =
81 { 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 };
83 static struct spxpcb *spx_close(struct spxpcb *cb);
84 static struct spxpcb *spx_disconnect(struct spxpcb *cb);
85 static struct spxpcb *spx_drop(struct spxpcb *cb, int errno);
86 static int spx_output(struct spxpcb *cb, struct mbuf *m0);
87 static int spx_reass(struct spxpcb *cb, struct spx *si, struct mbuf *si_m);
88 static void spx_setpersist(struct spxpcb *cb);
89 static void spx_template(struct spxpcb *cb);
90 static struct spxpcb *spx_timers(struct spxpcb *cb, int timer);
91 static struct spxpcb *spx_usrclosed(struct spxpcb *cb);
93 static void spx_usr_abort(netmsg_t);
94 static void spx_accept(netmsg_t);
95 static void spx_attach(netmsg_t);
96 static void spx_bind(netmsg_t);
97 static void spx_connect(netmsg_t);
98 static void spx_detach(netmsg_t);
99 static void spx_usr_disconnect(netmsg_t);
100 static void spx_listen(netmsg_t);
101 static void spx_rcvd(netmsg_t);
102 static void spx_rcvoob(netmsg_t);
103 static void spx_send(netmsg_t);
104 static void spx_shutdown(netmsg_t);
105 static void spx_sp_attach(netmsg_t);
107 struct pr_usrreqs spx_usrreqs = {
108 .pru_abort = spx_usr_abort,
109 .pru_accept = spx_accept,
110 .pru_attach = spx_attach,
111 .pru_bind = spx_bind,
112 .pru_connect = spx_connect,
113 .pru_connect2 = pr_generic_notsupp,
114 .pru_control = ipx_control,
115 .pru_detach = spx_detach,
116 .pru_disconnect = spx_usr_disconnect,
117 .pru_listen = spx_listen,
118 .pru_peeraddr = ipx_peeraddr,
119 .pru_rcvd = spx_rcvd,
120 .pru_rcvoob = spx_rcvoob,
121 .pru_send = spx_send,
122 .pru_sense = pru_sense_null,
123 .pru_shutdown = spx_shutdown,
124 .pru_sockaddr = ipx_sockaddr,
125 .pru_sosend = sosend,
126 .pru_soreceive = soreceive
129 struct pr_usrreqs spx_usrreq_sps = {
130 .pru_abort = spx_usr_abort,
131 .pru_accept = spx_accept,
132 .pru_attach = spx_sp_attach,
133 .pru_bind = spx_bind,
134 .pru_connect = spx_connect,
135 .pru_connect2 = pr_generic_notsupp,
136 .pru_control = ipx_control,
137 .pru_detach = spx_detach,
138 .pru_disconnect = spx_usr_disconnect,
139 .pru_listen = spx_listen,
140 .pru_peeraddr = ipx_peeraddr,
141 .pru_rcvd = spx_rcvd,
142 .pru_rcvoob = spx_rcvoob,
143 .pru_send = spx_send,
144 .pru_sense = pru_sense_null,
145 .pru_shutdown = spx_shutdown,
146 .pru_sockaddr = ipx_sockaddr,
147 .pru_sosend = sosend,
148 .pru_soreceive = soreceive
151 static MALLOC_DEFINE(M_SPX_Q, "ipx_spx_q", "IPX Packet Management");
157 spx_iss = 1; /* WRONG !! should fish it out of TODR */
161 spx_input(struct mbuf *m, struct ipxpcb *ipxp)
169 spxstat.spxs_rcvtotal++;
171 panic("No ipxpcb in spx_input");
175 cb = ipxtospxpcb(ipxp);
179 if (m->m_len < sizeof(struct spx)) {
180 if ((m = m_pullup(m, sizeof(*si))) == NULL) {
181 spxstat.spxs_rcvshort++;
185 si = mtod(m, struct spx *);
186 si->si_seq = ntohs(si->si_seq);
187 si->si_ack = ntohs(si->si_ack);
188 si->si_alo = ntohs(si->si_alo);
190 so = ipxp->ipxp_socket;
192 if (so->so_options & SO_DEBUG || traceallspxs) {
193 ostate = cb->s_state;
196 if (so->so_options & SO_ACCEPTCONN) {
197 struct spxpcb *ocb = cb;
199 so = sonewconn(so, 0);
204 * This is ugly, but ....
206 * Mark socket as temporary until we're
207 * committed to keeping it. The code at
208 * ``drop'' and ``dropwithreset'' check the
209 * flag dropsocket to see if the temporary
210 * socket created here should be discarded.
211 * We mark the socket as discardable until
212 * we're committed to it below in TCPS_LISTEN.
215 ipxp = (struct ipxpcb *)so->so_pcb;
216 ipxp->ipxp_laddr = si->si_dna;
217 cb = ipxtospxpcb(ipxp);
218 cb->s_mtu = ocb->s_mtu; /* preserve sockopts */
219 cb->s_flags = ocb->s_flags; /* preserve sockopts */
220 cb->s_flags2 = ocb->s_flags2; /* preserve sockopts */
221 cb->s_state = TCPS_LISTEN;
225 * Packet received on connection.
226 * reset idle time and keep-alive timer;
229 cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
231 switch (cb->s_state) {
234 struct sockaddr_ipx *sipx, ssipx;
235 struct ipx_addr laddr;
238 * If somebody here was carying on a conversation
239 * and went away, and his pen pal thinks he can
240 * still talk, we get the misdirected packet.
242 if (spx_hardnosed && (si->si_did != 0 || si->si_seq != 0)) {
247 bzero(sipx, sizeof *sipx);
248 sipx->sipx_len = sizeof(*sipx);
249 sipx->sipx_family = AF_IPX;
250 sipx->sipx_addr = si->si_sna;
251 laddr = ipxp->ipxp_laddr;
252 if (ipx_nullhost(laddr))
253 ipxp->ipxp_laddr = si->si_dna;
254 if (ipx_pcbconnect(ipxp, (struct sockaddr *)sipx, &thread0)) {
255 ipxp->ipxp_laddr = laddr;
260 dropsocket = 0; /* committed to socket */
261 cb->s_did = si->si_sid;
262 cb->s_rack = si->si_ack;
263 cb->s_ralo = si->si_alo;
264 #define THREEWAYSHAKE
266 cb->s_state = TCPS_SYN_RECEIVED;
267 cb->s_force = 1 + SPXT_KEEP;
268 spxstat.spxs_accepts++;
269 cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
273 * This state means that we have heard a response
274 * to our acceptance of their connection
275 * It is probably logically unnecessary in this
278 case TCPS_SYN_RECEIVED: {
279 if (si->si_did != cb->s_sid) {
284 ipxp->ipxp_fport = si->si_sport;
285 cb->s_timer[SPXT_REXMT] = 0;
286 cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
288 cb->s_state = TCPS_ESTABLISHED;
289 spxstat.spxs_accepts++;
294 * This state means that we have gotten a response
295 * to our attempt to establish a connection.
296 * We fill in the data from the other side,
297 * telling us which port to respond to, instead of the well-
298 * known one we might have sent to in the first place.
299 * We also require that this is a response to our
303 if (si->si_did != cb->s_sid) {
307 spxstat.spxs_connects++;
308 cb->s_did = si->si_sid;
309 cb->s_rack = si->si_ack;
310 cb->s_ralo = si->si_alo;
311 cb->s_dport = ipxp->ipxp_fport = si->si_sport;
312 cb->s_timer[SPXT_REXMT] = 0;
313 cb->s_flags |= SF_ACKNOW;
315 cb->s_state = TCPS_ESTABLISHED;
316 /* Use roundtrip time of connection request for initial rtt */
318 cb->s_srtt = cb->s_rtt << 3;
319 cb->s_rttvar = cb->s_rtt << 1;
320 SPXT_RANGESET(cb->s_rxtcur,
321 ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1,
322 SPXTV_MIN, SPXTV_REXMTMAX);
326 if (so->so_options & SO_DEBUG || traceallspxs)
327 spx_trace(SA_INPUT, (u_char)ostate, cb, &spx_savesi, 0);
329 m->m_len -= sizeof(struct ipx);
330 m->m_pkthdr.len -= sizeof(struct ipx);
331 m->m_data += sizeof(struct ipx);
333 if (spx_reass(cb, si, m)) {
336 if (cb->s_force || (cb->s_flags & (SF_ACKNOW|SF_WIN|SF_RXT)))
337 spx_output(cb, NULL);
338 cb->s_flags &= ~(SF_WIN|SF_RXT);
344 si->si_seq = ntohs(si->si_seq);
345 si->si_ack = ntohs(si->si_ack);
346 si->si_alo = ntohs(si->si_alo);
348 if (cb->s_ipxpcb->ipxp_socket->so_options & SO_DEBUG || traceallspxs)
349 spx_trace(SA_DROP, (u_char)ostate, cb, &spx_savesi, 0);
354 if (cb == NULL || cb->s_ipxpcb->ipxp_socket->so_options & SO_DEBUG ||
356 spx_trace(SA_DROP, (u_char)ostate, cb, &spx_savesi, 0);
360 static int spxrexmtthresh = 3;
363 * This is structurally similar to the tcp reassembly routine
364 * but its function is somewhat different: It merely queues
365 * packets up, and suppresses duplicates.
368 spx_reass(struct spxpcb *cb, struct spx *si, struct mbuf *si_m)
370 struct spx_q *q, *nq, *q_temp;
372 struct socket *so = cb->s_ipxpcb->ipxp_socket;
373 char packetp = cb->s_flags & SF_HI;
380 * Update our news from them.
382 if (si->si_cc & SPX_SA)
383 cb->s_flags |= (spx_use_delack ? SF_DELACK : SF_ACKNOW);
384 if (SSEQ_GT(si->si_alo, cb->s_ralo))
385 cb->s_flags |= SF_WIN;
386 if (SSEQ_LEQ(si->si_ack, cb->s_rack)) {
387 if ((si->si_cc & SPX_SP) && cb->s_rack != (cb->s_smax + 1)) {
388 spxstat.spxs_rcvdupack++;
390 * If this is a completely duplicate ack
391 * and other conditions hold, we assume
392 * a packet has been dropped and retransmit
393 * it exactly as in tcp_input().
395 if (si->si_ack != cb->s_rack ||
396 si->si_alo != cb->s_ralo)
398 else if (++cb->s_dupacks == spxrexmtthresh) {
399 u_short onxt = cb->s_snxt;
400 int cwnd = cb->s_cwnd;
402 cb->s_snxt = si->si_ack;
404 cb->s_force = 1 + SPXT_REXMT;
405 spx_output(cb, NULL);
406 cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
408 if (cwnd >= 4 * CUNIT)
409 cb->s_cwnd = cwnd / 2;
410 if (SSEQ_GT(onxt, cb->s_snxt))
420 * If our correspondent acknowledges data we haven't sent
421 * TCP would drop the packet after acking. We'll be a little
424 if (SSEQ_GT(si->si_ack, (cb->s_smax + 1))) {
425 spxstat.spxs_rcvacktoomuch++;
426 si->si_ack = cb->s_smax + 1;
428 spxstat.spxs_rcvackpack++;
430 * If transmit timer is running and timed sequence
431 * number was acked, update smoothed round trip time.
432 * See discussion of algorithm in tcp_input.c
434 if (cb->s_rtt && SSEQ_GT(si->si_ack, cb->s_rtseq)) {
435 spxstat.spxs_rttupdated++;
436 if (cb->s_srtt != 0) {
438 delta = cb->s_rtt - (cb->s_srtt >> 3);
439 if ((cb->s_srtt += delta) <= 0)
443 delta -= (cb->s_rttvar >> 2);
444 if ((cb->s_rttvar += delta) <= 0)
448 * No rtt measurement yet
450 cb->s_srtt = cb->s_rtt << 3;
451 cb->s_rttvar = cb->s_rtt << 1;
455 SPXT_RANGESET(cb->s_rxtcur,
456 ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1,
457 SPXTV_MIN, SPXTV_REXMTMAX);
460 * If all outstanding data is acked, stop retransmit
461 * timer and remember to restart (more output or persist).
462 * If there is more data to be acked, restart retransmit
463 * timer, using current (possibly backed-off) value;
465 if (si->si_ack == cb->s_smax + 1) {
466 cb->s_timer[SPXT_REXMT] = 0;
467 cb->s_flags |= SF_RXT;
468 } else if (cb->s_timer[SPXT_PERSIST] == 0)
469 cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
471 * When new data is acked, open the congestion window.
472 * If the window gives us less than ssthresh packets
473 * in flight, open exponentially (maxseg at a time).
474 * Otherwise open linearly (maxseg^2 / cwnd at a time).
477 if (cb->s_cwnd > cb->s_ssthresh)
478 incr = max(incr * incr / cb->s_cwnd, 1);
479 cb->s_cwnd = min(cb->s_cwnd + incr, cb->s_cwmx);
481 * Trim Acked data from output queue.
483 while ((m = so->so_snd.ssb_mb) != NULL) {
484 if (SSEQ_LT((mtod(m, struct spx *))->si_seq, si->si_ack))
485 sbdroprecord(&so->so_snd.sb);
490 cb->s_rack = si->si_ack;
492 if (SSEQ_LT(cb->s_snxt, cb->s_rack))
493 cb->s_snxt = cb->s_rack;
494 if (SSEQ_LT(cb->s_swl1, si->si_seq) || ((cb->s_swl1 == si->si_seq &&
495 (SSEQ_LT(cb->s_swl2, si->si_ack))) ||
496 (cb->s_swl2 == si->si_ack && SSEQ_LT(cb->s_ralo, si->si_alo)))) {
497 /* keep track of pure window updates */
498 if ((si->si_cc & SPX_SP) && cb->s_swl2 == si->si_ack
499 && SSEQ_LT(cb->s_ralo, si->si_alo)) {
500 spxstat.spxs_rcvwinupd++;
501 spxstat.spxs_rcvdupack--;
503 cb->s_ralo = si->si_alo;
504 cb->s_swl1 = si->si_seq;
505 cb->s_swl2 = si->si_ack;
506 cb->s_swnd = (1 + si->si_alo - si->si_ack);
507 if (cb->s_swnd > cb->s_smxw)
508 cb->s_smxw = cb->s_swnd;
509 cb->s_flags |= SF_WIN;
512 * If this packet number is higher than that which
513 * we have allocated refuse it, unless urgent
515 if (SSEQ_GT(si->si_seq, cb->s_alo)) {
516 if (si->si_cc & SPX_SP) {
517 spxstat.spxs_rcvwinprobe++;
520 spxstat.spxs_rcvpackafterwin++;
521 if (si->si_cc & SPX_OB) {
522 if (SSEQ_GT(si->si_seq, cb->s_alo + 60)) {
525 } /* else queue this packet; */
527 /*register struct socket *so = cb->s_ipxpcb->ipxp_socket;
528 if (so->so_state && SS_NOFDREF) {
538 * If this is a system packet, we don't need to
539 * queue it up, and won't update acknowledge #
541 if (si->si_cc & SPX_SP) {
545 * We have already seen this packet, so drop.
547 if (SSEQ_LT(si->si_seq, cb->s_ack)) {
549 spxstat.spxs_rcvduppack++;
550 if (si->si_seq == cb->s_ack - 1)
555 * Loop through all packets queued up to insert in
556 * appropriate sequence.
558 LIST_FOREACH(q, &cb->s_q, sq_entry) {
559 if (si->si_seq == SI(q)->si_seq) {
560 spxstat.spxs_rcvduppack++;
563 if (SSEQ_LT(si->si_seq, SI(q)->si_seq)) {
564 spxstat.spxs_rcvoopack++;
568 nq = kmalloc(sizeof(struct spx_q), M_SPX_Q, M_INTNOWAIT);
574 LIST_INSERT_HEAD(&cb->s_q, nq, sq_entry);
576 LIST_INSERT_BEFORE(q, nq, sq_entry);
579 * If this packet is urgent, inform process
581 if (si->si_cc & SPX_OB) {
582 cb->s_iobc = ((char *)si)[1 + sizeof(*si)];
584 cb->s_oobflags |= SF_IOOB;
587 #define SPINC sizeof(struct spxhdr)
589 * Loop through all packets queued up to update acknowledge
590 * number, and present all acknowledged data to user;
591 * If in packet interface mode, show packet headers.
593 LIST_FOREACH_MUTABLE(q, &cb->s_q, sq_entry, q_temp) {
594 if (SI(q)->si_seq == cb->s_ack) {
597 if (SI(q)->si_cc & SPX_OB) {
598 cb->s_oobflags &= ~SF_IOOB;
599 if (so->so_rcv.ssb_cc)
600 so->so_oobmark = so->so_rcv.ssb_cc;
602 sosetstate(so, SS_RCVATMARK);
604 LIST_REMOVE(q, sq_entry);
607 spxstat.spxs_rcvpack++;
609 if (cb->s_flags2 & SF_NEWCALL) {
610 struct spxhdr *sp = mtod(m, struct spxhdr *);
611 u_char dt = sp->spx_dt;
613 if (dt != cb->s_rhdr.spx_dt) {
615 m_getclr(MB_DONTWAIT, MT_CONTROL);
620 cb->s_rhdr.spx_dt = dt;
621 mm->m_len = 5; /*XXX*/
624 *(u_char *)(&s[2]) = dt;
625 sbappend(&so->so_rcv.sb, mm);
628 if (sp->spx_cc & SPX_OB) {
629 m_chtype(m, MT_OOBDATA);
632 soclrstate(so, SS_RCVATMARK);
637 m->m_pkthdr.len -= SPINC;
639 if ((sp->spx_cc & SPX_EM) || packetp) {
640 sbappendrecord(&so->so_rcv.sb, m);
643 sbappend(&so->so_rcv.sb, m);
647 sbappendrecord(&so->so_rcv.sb, m);
649 cb->s_rhdr = *mtod(m, struct spxhdr *);
652 m->m_pkthdr.len -= SPINC;
653 sbappend(&so->so_rcv.sb, m);
664 spx_ctlinput(netmsg_t msg)
666 /*struct socket *so = msg->base.nm_so;*/
667 int cmd = msg->ctlinput.nm_cmd;
668 struct sockaddr *arg_as_sa = msg->ctlinput.nm_arg;
669 caddr_t arg = (/* XXX */ caddr_t)arg_as_sa;
671 struct sockaddr_ipx *sipx;
673 if (cmd < 0 || cmd > PRC_NCMDS)
681 case PRC_HOSTUNREACH:
682 sipx = (struct sockaddr_ipx *)arg;
683 if (sipx->sipx_family != AF_IPX)
685 na = &sipx->sipx_addr;
691 lwkt_replymsg(&msg->lmsg, 0);
695 spx_output(struct spxpcb *cb, struct mbuf *m0)
697 struct socket *so = cb->s_ipxpcb->ipxp_socket;
698 struct mbuf *m = NULL;
699 struct spx *si = NULL;
700 struct signalsockbuf *ssb = &so->so_snd;
701 int len = 0, win, rcv_win;
702 short span, off, recordp = 0;
704 int error = 0, sendalot;
714 * Make sure that packet isn't too big.
716 for (m = m0; m != NULL; m = m->m_next) {
719 if (m->m_flags & M_EOR)
722 datalen = (cb->s_flags & SF_HO) ?
723 len - sizeof(struct spxhdr) : len;
725 if (cb->s_flags & SF_PI) {
729 int oldEM = cb->s_cc & SPX_EM;
734 * Here we are only being called
735 * from usrreq(), so it is OK to
738 m = m_copym(m0, 0, mtu, MB_WAIT);
739 if (cb->s_flags & SF_NEWCALL) {
743 mm->m_flags &= ~M_EOR;
747 error = spx_output(cb, m);
760 * Force length even, by adding a "garbage byte" if
765 if (M_TRAILINGSPACE(m) >= 1)
768 struct mbuf *m1 = m_get(MB_DONTWAIT, MT_DATA);
775 *(mtod(m1, u_char *)) = 0;
779 m = m_gethdr(MB_DONTWAIT, MT_HEADER);
785 * Fill in mbuf with extended SP header
786 * and addresses and length put into network format.
788 MH_ALIGN(m, sizeof(struct spx));
789 m->m_len = sizeof(struct spx);
791 si = mtod(m, struct spx *);
792 si->si_i = *cb->s_ipx;
793 si->si_s = cb->s_shdr;
794 if ((cb->s_flags & SF_PI) && (cb->s_flags & SF_HO)) {
796 if (m0->m_len < sizeof(*sh)) {
797 if((m0 = m_pullup(m0, sizeof(*sh))) == NULL) {
804 sh = mtod(m0, struct spxhdr *);
805 si->si_dt = sh->spx_dt;
806 si->si_cc |= sh->spx_cc & SPX_EM;
807 m0->m_len -= sizeof(*sh);
808 m0->m_data += sizeof(*sh);
812 if ((cb->s_flags2 & SF_NEWCALL) && recordp) {
816 if (cb->s_oobflags & SF_SOOB) {
819 * make sure OB packets convey exactly 1 byte.
820 * If the packet is 1 byte or larger, we
821 * have already guaranted there to be at least
822 * one garbage byte for the checksum, and
823 * extra bytes shouldn't hurt!
825 if (len > sizeof(*si)) {
827 len = (1 + sizeof(*si));
830 si->si_len = htons((u_short)len);
831 m->m_pkthdr.len = ((len - 1) | 1) + 1;
833 * queue stuff up for output
835 sbappendrecord(&ssb->sb, m);
839 idle = (cb->s_smax == (cb->s_rack - 1));
843 off = cb->s_snxt - cb->s_rack;
844 win = min(cb->s_swnd, (cb->s_cwnd / CUNIT));
847 * If in persist timeout with window of 0, send a probe.
848 * Otherwise, if window is small but nonzero
849 * and timer expired, send what we can and go into
852 if (cb->s_force == 1 + SPXT_PERSIST) {
854 cb->s_timer[SPXT_PERSIST] = 0;
858 span = cb->s_seq - cb->s_rack;
859 len = min(span, win) - off;
863 * Window shrank after we went into it.
864 * If window shrank to 0, cancel pending
865 * restransmission and pull s_snxt back
866 * to (closed) window. We will enter persist
867 * state below. If the widndow didn't close completely,
868 * just wait for an ACK.
872 cb->s_timer[SPXT_REXMT] = 0;
873 cb->s_snxt = cb->s_rack;
878 rcv_win = ssb_space(&so->so_rcv);
881 * Send if we owe peer an ACK.
883 if (cb->s_oobflags & SF_SOOB) {
885 * must transmit this out of band packet
887 cb->s_oobflags &= ~ SF_SOOB;
889 spxstat.spxs_sndurg++;
892 if (cb->s_flags & SF_ACKNOW)
894 if (cb->s_state < TCPS_ESTABLISHED)
897 * Silly window can't happen in spx.
898 * Code from tcp deleted.
903 * Compare available window to amount of window
904 * known to peer (as advertised window less
905 * next expected input.) If the difference is at least two
906 * packets or at least 35% of the mximum possible window,
907 * then want to send a window update to peer.
910 u_short delta = 1 + cb->s_alo - cb->s_ack;
911 int adv = rcv_win - (delta * cb->s_mtu);
913 if ((so->so_rcv.ssb_cc == 0 && adv >= (2 * cb->s_mtu)) ||
914 (100 * adv / so->so_rcv.ssb_hiwat >= 35)) {
915 spxstat.spxs_sndwinup++;
916 cb->s_flags |= SF_ACKNOW;
922 * Many comments from tcp_output.c are appropriate here
924 * If send window is too small, there is data to transmit, and no
925 * retransmit or persist is pending, then go to persist state.
926 * If nothing happens soon, send when timer expires:
927 * if window is nonzero, transmit what we can,
928 * otherwise send a probe.
930 if (so->so_snd.ssb_cc && cb->s_timer[SPXT_REXMT] == 0 &&
931 cb->s_timer[SPXT_PERSIST] == 0) {
936 * No reason to send a packet, just return.
943 * Find requested packet.
947 cb->s_want = cb->s_snxt;
948 for (m = ssb->ssb_mb; m != NULL; m = m->m_nextpkt) {
949 si = mtod(m, struct spx *);
950 if (SSEQ_LEQ(cb->s_snxt, si->si_seq))
955 if (si->si_seq == cb->s_snxt)
958 spxstat.spxs_sndvoid++, si = NULL;
966 alo = cb->s_ack - 1 + (rcv_win / ((short)cb->s_mtu));
967 if (SSEQ_LT(alo, cb->s_alo))
972 * must make a copy of this packet for
973 * ipx_output to monkey with
975 m = m_copy(m, 0, (int)M_COPYALL);
979 si = mtod(m, struct spx *);
980 if (SSEQ_LT(si->si_seq, cb->s_smax))
981 spxstat.spxs_sndrexmitpack++;
983 spxstat.spxs_sndpack++;
984 } else if (cb->s_force || cb->s_flags & SF_ACKNOW) {
986 * Must send an acknowledgement or a probe
989 spxstat.spxs_sndprobe++;
990 if (cb->s_flags & SF_ACKNOW)
991 spxstat.spxs_sndacks++;
992 m = m_gethdr(MB_DONTWAIT, MT_HEADER);
996 * Fill in mbuf with extended SP header
997 * and addresses and length put into network format.
999 MH_ALIGN(m, sizeof(struct spx));
1000 m->m_len = sizeof(*si);
1001 m->m_pkthdr.len = sizeof(*si);
1002 si = mtod(m, struct spx *);
1003 si->si_i = *cb->s_ipx;
1004 si->si_s = cb->s_shdr;
1005 si->si_seq = cb->s_smax + 1;
1006 si->si_len = htons(sizeof(*si));
1007 si->si_cc |= SPX_SP;
1010 if (so->so_options & SO_DEBUG || traceallspxs)
1011 spx_trace(SA_OUTPUT, cb->s_state, cb, si, 0);
1015 * Stuff checksum and output datagram.
1017 if ((si->si_cc & SPX_SP) == 0) {
1018 if (cb->s_force != (1 + SPXT_PERSIST) ||
1019 cb->s_timer[SPXT_PERSIST] == 0) {
1021 * If this is a new packet and we are not currently
1022 * timing anything, time this one.
1024 if (SSEQ_LT(cb->s_smax, si->si_seq)) {
1025 cb->s_smax = si->si_seq;
1026 if (cb->s_rtt == 0) {
1027 spxstat.spxs_segstimed++;
1028 cb->s_rtseq = si->si_seq;
1033 * Set rexmt timer if not currently set,
1034 * Initial value for retransmit timer is smoothed
1035 * round-trip time + 2 * round-trip time variance.
1036 * Initialize shift counter which is used for backoff
1037 * of retransmit time.
1039 if (cb->s_timer[SPXT_REXMT] == 0 &&
1040 cb->s_snxt != cb->s_rack) {
1041 cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
1042 if (cb->s_timer[SPXT_PERSIST]) {
1043 cb->s_timer[SPXT_PERSIST] = 0;
1047 } else if (SSEQ_LT(cb->s_smax, si->si_seq)) {
1048 cb->s_smax = si->si_seq;
1050 } else if (cb->s_state < TCPS_ESTABLISHED) {
1052 cb->s_rtt = 1; /* Time initial handshake */
1053 if (cb->s_timer[SPXT_REXMT] == 0)
1054 cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
1058 * Do not request acks when we ack their data packets or
1059 * when we do a gratuitous window update.
1061 if (((si->si_cc & SPX_SP) == 0) || cb->s_force)
1062 si->si_cc |= SPX_SA;
1063 si->si_seq = htons(si->si_seq);
1064 si->si_alo = htons(alo);
1065 si->si_ack = htons(cb->s_ack);
1068 si->si_sum = ipx_cksum(m, ntohs(si->si_len));
1070 si->si_sum = 0xffff;
1073 if (so->so_options & SO_DEBUG || traceallspxs)
1074 spx_trace(SA_OUTPUT, cb->s_state, cb, si, 0);
1076 if (so->so_options & SO_DONTROUTE)
1077 error = ipx_outputfl(m, NULL, IPX_ROUTETOIF);
1079 error = ipx_outputfl(m, &cb->s_ipxpcb->ipxp_route, 0);
1084 spxstat.spxs_sndtotal++;
1086 * Data sent (as far as we can tell).
1087 * If this advertises a larger window than any other segment,
1088 * then remember the size of the advertized window.
1089 * Any pending ACK has now been sent.
1092 cb->s_flags &= ~(SF_ACKNOW|SF_DELACK);
1093 if (SSEQ_GT(alo, cb->s_alo))
1101 static int spx_do_persist_panics = 0;
1104 spx_setpersist(struct spxpcb *cb)
1106 int t = ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1;
1108 if (cb->s_timer[SPXT_REXMT] && spx_do_persist_panics)
1109 panic("spx_output REXMT");
1111 * Start/restart persistance timer.
1113 SPXT_RANGESET(cb->s_timer[SPXT_PERSIST],
1114 t*spx_backoff[cb->s_rxtshift],
1115 SPXTV_PERSMIN, SPXTV_PERSMAX);
1116 if (cb->s_rxtshift < SPX_MAXRXTSHIFT)
1121 spx_ctloutput(netmsg_t msg)
1123 struct socket *so = msg->base.nm_so;
1124 struct ipxpcb *ipxp = sotoipxpcb(so);
1125 struct sockopt *sopt = msg->ctloutput.nm_sopt;
1134 if (sopt->sopt_level != IPXPROTO_SPX) {
1135 /* This will have to be changed when we do more general
1136 stacking of protocols */
1138 /* msg now invalid */
1145 cb = ipxtospxpcb(ipxp);
1147 switch (sopt->sopt_dir) {
1149 switch (sopt->sopt_name) {
1150 case SO_HEADERS_ON_INPUT:
1154 case SO_HEADERS_ON_OUTPUT:
1157 soptval = cb->s_flags & mask;
1158 error = sooptcopyout(sopt, &soptval, sizeof soptval);
1162 usoptval = cb->s_mtu;
1163 error = sooptcopyout(sopt, &usoptval, sizeof usoptval);
1166 case SO_LAST_HEADER:
1167 error = sooptcopyout(sopt, &cb->s_rhdr,
1171 case SO_DEFAULT_HEADERS:
1172 error = sooptcopyout(sopt, &cb->s_shdr,
1177 error = ENOPROTOOPT;
1182 switch (sopt->sopt_name) {
1183 /* XXX why are these shorts on get and ints on set?
1184 that doesn't make any sense... */
1185 case SO_HEADERS_ON_INPUT:
1189 case SO_HEADERS_ON_OUTPUT:
1192 error = sooptcopyin(sopt, &optval, sizeof optval,
1197 if (cb->s_flags & SF_PI) {
1199 cb->s_flags |= mask;
1201 cb->s_flags &= ~mask;
1202 } else error = EINVAL;
1206 error = sooptcopyin(sopt, &usoptval, sizeof usoptval,
1210 cb->s_mtu = usoptval;
1215 error = sooptcopyin(sopt, &optval, sizeof optval,
1220 cb->s_flags2 |= SF_NEWCALL;
1223 cb->s_flags2 &= ~SF_NEWCALL;
1229 case SO_DEFAULT_HEADERS:
1233 error = sooptcopyin(sopt, &sp, sizeof sp,
1237 cb->s_dt = sp.spx_dt;
1238 cb->s_cc = sp.spx_cc & SPX_EM;
1243 error = ENOPROTOOPT;
1248 lwkt_replymsg(&msg->lmsg, error);
1252 * NOTE: (so) is referenced from soabort*() and netmsg_pru_abort()
1253 * will sofree() it when we return.
1256 spx_usr_abort(netmsg_t msg)
1258 struct socket *so = msg->base.nm_so;
1259 struct ipxpcb *ipxp;
1262 ipxp = sotoipxpcb(so);
1263 cb = ipxtospxpcb(ipxp);
1265 spx_drop(cb, ECONNABORTED);
1267 lwkt_replymsg(&msg->lmsg, 0);
1271 * Accept a connection. Essentially all the work is
1272 * done at higher levels; just return the address
1273 * of the peer, storing through addr.
1276 spx_accept(netmsg_t msg)
1278 struct socket *so = msg->base.nm_so;
1279 struct sockaddr **nam = msg->accept.nm_nam;
1280 struct ipxpcb *ipxp;
1281 struct sockaddr_ipx *sipx, ssipx;
1283 ipxp = sotoipxpcb(so);
1285 bzero(sipx, sizeof *sipx);
1286 sipx->sipx_len = sizeof *sipx;
1287 sipx->sipx_family = AF_IPX;
1288 sipx->sipx_addr = ipxp->ipxp_faddr;
1289 *nam = dup_sockaddr((struct sockaddr *)sipx);
1291 lwkt_replymsg(&msg->lmsg, 0);
1295 spx_attach_oncpu(struct socket *so, int proto, struct pru_attach_info *ai)
1297 struct ipxpcb *ipxp;
1300 struct signalsockbuf *ssb;
1303 ipxp = sotoipxpcb(so);
1304 cb = ipxtospxpcb(ipxp);
1309 goto spx_attach_end;
1311 error = ipx_pcballoc(so, &ipxpcb_list);
1313 goto spx_attach_end;
1314 if (so->so_snd.ssb_hiwat == 0 || so->so_rcv.ssb_hiwat == 0) {
1315 error = soreserve(so, (u_long) 3072, (u_long) 3072,
1318 goto spx_attach_end;
1320 ipxp = sotoipxpcb(so);
1322 cb = kmalloc(sizeof *cb, M_PCB, M_INTWAIT | M_ZERO);
1325 mm = m_getclr(MB_DONTWAIT, MT_HEADER);
1329 goto spx_attach_end;
1332 cb->s_ipx = mtod(mm, struct ipx *);
1333 cb->s_state = TCPS_LISTEN;
1336 LIST_INIT(&cb->s_q);
1337 cb->s_ipxpcb = ipxp;
1338 cb->s_mtu = 576 - sizeof(struct spx);
1339 cb->s_cwnd = ssb_space(ssb) * CUNIT / cb->s_mtu;
1340 cb->s_ssthresh = cb->s_cwnd;
1341 cb->s_cwmx = ssb_space(ssb) * CUNIT / (2 * sizeof(struct spx));
1342 /* Above is recomputed when connecting to account
1343 for changed buffering or mtu's */
1344 cb->s_rtt = SPXTV_SRTTBASE;
1345 cb->s_rttvar = SPXTV_SRTTDFLT << 2;
1346 SPXT_RANGESET(cb->s_rxtcur,
1347 ((SPXTV_SRTTBASE >> 2) + (SPXTV_SRTTDFLT << 2)) >> 1,
1348 SPXTV_MIN, SPXTV_REXMTMAX);
1349 ipxp->ipxp_pcb = (caddr_t)cb;
1356 spx_attach(netmsg_t msg)
1360 error = spx_attach_oncpu(msg->base.nm_so,
1361 msg->attach.nm_proto,
1363 lwkt_replymsg(&msg->lmsg, error);
1368 spx_bind(netmsg_t msg)
1370 struct socket *so = msg->base.nm_so;
1371 struct ipxpcb *ipxp;
1374 ipxp = sotoipxpcb(so);
1376 error = ipx_pcbbind(ipxp, msg->bind.nm_nam, msg->bind.nm_td);
1377 lwkt_replymsg(&msg->lmsg, error);
1381 * Initiate connection to peer.
1382 * Enter SYN_SENT state, and mark socket as connecting.
1383 * Start keep-alive timer, setup prototype header,
1384 * Send initial system packet requesting connection.
1387 spx_connect(netmsg_t msg)
1389 struct socket *so = msg->base.nm_so;
1390 struct sockaddr *nam = msg->connect.nm_nam;
1391 struct thread *td = msg->connect.nm_td;
1392 struct ipxpcb *ipxp;
1396 ipxp = sotoipxpcb(so);
1397 cb = ipxtospxpcb(ipxp);
1400 if (ipxp->ipxp_lport == 0) {
1401 error = ipx_pcbbind(ipxp, NULL, td);
1403 goto spx_connect_end;
1405 error = ipx_pcbconnect(ipxp, nam, td);
1407 goto spx_connect_end;
1409 spxstat.spxs_connattempt++;
1410 cb->s_state = TCPS_SYN_SENT;
1413 cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
1414 cb->s_force = 1 + SPXTV_KEEP;
1416 * Other party is required to respond to
1417 * the port I send from, but he is not
1418 * required to answer from where I am sending to,
1419 * so allow wildcarding.
1420 * original port I am sending to is still saved in
1423 ipxp->ipxp_fport = 0;
1424 error = spx_output(cb, NULL);
1427 lwkt_replymsg(&msg->lmsg, error);
1431 spx_detach(netmsg_t msg)
1433 struct socket *so = msg->base.nm_so;
1434 struct ipxpcb *ipxp;
1438 ipxp = sotoipxpcb(so);
1439 cb = ipxtospxpcb(ipxp);
1443 if (cb->s_state > TCPS_LISTEN)
1452 lwkt_replymsg(&msg->lmsg, error);
1456 * We may decide later to implement connection closing
1457 * handshaking at the spx level optionally.
1458 * here is the hook to do it:
1461 spx_usr_disconnect(netmsg_t msg)
1463 struct socket *so = msg->base.nm_so;
1464 struct ipxpcb *ipxp;
1467 ipxp = sotoipxpcb(so);
1468 cb = ipxtospxpcb(ipxp);
1474 lwkt_replymsg(&msg->lmsg, 0);
1478 spx_listen(netmsg_t msg)
1480 struct socket *so = msg->base.nm_so;
1481 struct ipxpcb *ipxp;
1486 ipxp = sotoipxpcb(so);
1487 cb = ipxtospxpcb(ipxp);
1489 if (ipxp->ipxp_lport == 0)
1490 error = ipx_pcbbind(ipxp, NULL, msg->listen.nm_td);
1492 cb->s_state = TCPS_LISTEN;
1493 lwkt_replymsg(&msg->lmsg, error);
1497 * After a receive, possibly send acknowledgment
1498 * updating allocation.
1501 spx_rcvd(netmsg_t msg)
1503 struct socket *so = msg->base.nm_so;
1504 struct ipxpcb *ipxp;
1507 ipxp = sotoipxpcb(so);
1508 cb = ipxtospxpcb(ipxp);
1511 cb->s_flags |= SF_RVD;
1512 spx_output(cb, NULL);
1513 cb->s_flags &= ~SF_RVD;
1516 lwkt_replymsg(&msg->lmsg, 0);
1520 spx_rcvoob(netmsg_t msg)
1522 struct mbuf *m = msg->rcvoob.nm_m;
1523 struct socket *so = msg->base.nm_so;
1524 struct ipxpcb *ipxp;
1528 ipxp = sotoipxpcb(so);
1529 cb = ipxtospxpcb(ipxp);
1531 if ((cb->s_oobflags & SF_IOOB) || so->so_oobmark ||
1532 (so->so_state & SS_RCVATMARK)) {
1534 *mtod(m, caddr_t) = cb->s_iobc;
1539 lwkt_replymsg(&msg->lmsg, error);
1543 spx_send(netmsg_t msg)
1545 struct socket *so = msg->base.nm_so;
1546 struct mbuf *m = msg->send.nm_m;
1547 struct mbuf *controlp = msg->send.nm_control;
1548 int flags = msg->send.nm_flags;
1549 struct ipxpcb *ipxp;
1554 ipxp = sotoipxpcb(so);
1555 cb = ipxtospxpcb(ipxp);
1558 if (flags & PRUS_OOB) {
1559 if (ssb_space(&so->so_snd) < -512) {
1563 cb->s_oobflags |= SF_SOOB;
1565 if (controlp != NULL) {
1566 u_short *p = mtod(controlp, u_short *);
1568 if ((p[0] == 5) && (p[1] == 1)) { /* XXXX, for testing */
1569 cb->s_shdr.spx_dt = *(u_char *)(&p[2]);
1575 error = spx_output(cb, m);
1578 if (controlp != NULL)
1583 lwkt_replymsg(&msg->lmsg, error);
1587 spx_shutdown(netmsg_t msg)
1589 struct socket *so = msg->base.nm_so;
1590 struct ipxpcb *ipxp;
1595 ipxp = sotoipxpcb(so);
1596 cb = ipxtospxpcb(ipxp);
1600 cb = spx_usrclosed(cb);
1602 error = spx_output(cb, NULL);
1604 lwkt_replymsg(&msg->lmsg, error);
1608 spx_sp_attach(netmsg_t msg)
1610 struct socket *so = msg->base.nm_so;
1611 struct ipxpcb *ipxp;
1614 error = spx_attach_oncpu(so, msg->attach.nm_proto, msg->attach.nm_ai);
1616 ipxp = sotoipxpcb(so);
1617 ((struct spxpcb *)ipxp->ipxp_pcb)->s_flags |=
1618 (SF_HI | SF_HO | SF_PI);
1620 lwkt_replymsg(&msg->lmsg, error);
1624 * Create template to be used to send spx packets on a connection.
1625 * Called after host entry created, fills
1626 * in a skeletal spx header (choosing connection id),
1627 * minimizing the amount of work necessary when the connection is used.
1630 spx_template(struct spxpcb *cb)
1632 struct ipxpcb *ipxp = cb->s_ipxpcb;
1633 struct ipx *ipx = cb->s_ipx;
1634 struct signalsockbuf *ssb = &(ipxp->ipxp_socket->so_snd);
1636 ipx->ipx_pt = IPXPROTO_SPX;
1637 ipx->ipx_sna = ipxp->ipxp_laddr;
1638 ipx->ipx_dna = ipxp->ipxp_faddr;
1639 cb->s_sid = htons(spx_iss);
1640 spx_iss += SPX_ISSINCR/2;
1642 cb->s_cwnd = (ssb_space(ssb) * CUNIT) / cb->s_mtu;
1643 cb->s_ssthresh = cb->s_cwnd; /* Try to expand fast to full complement
1645 cb->s_cwmx = (ssb_space(ssb) * CUNIT) / (2 * sizeof(struct spx));
1646 cb->s_cwmx = max(cb->s_cwmx, cb->s_cwnd);
1647 /* But allow for lots of little packets as well */
1651 * Close a SPIP control block:
1652 * discard spx control block itself
1653 * discard ipx protocol control block
1654 * wake up any sleepers
1656 static struct spxpcb *
1657 spx_close(struct spxpcb *cb)
1660 struct ipxpcb *ipxp = cb->s_ipxpcb;
1661 struct socket *so = ipxp->ipxp_socket;
1663 while (!LIST_EMPTY(&cb->s_q)) {
1664 q = LIST_FIRST(&cb->s_q);
1665 LIST_REMOVE(q, sq_entry);
1666 m_freem(q->si_mbuf);
1669 m_free(cb->s_ipx_m);
1672 soisdisconnected(so);
1673 ipx_pcbdetach(ipxp);
1674 spxstat.spxs_closed++;
1679 * Someday we may do level 3 handshaking
1680 * to close a connection or send a xerox style error.
1681 * For now, just close.
1683 static struct spxpcb *
1684 spx_usrclosed(struct spxpcb *cb)
1686 return (spx_close(cb));
1689 static struct spxpcb *
1690 spx_disconnect(struct spxpcb *cb)
1692 return (spx_close(cb));
1696 * Drop connection, reporting
1697 * the specified error.
1699 static struct spxpcb *
1700 spx_drop(struct spxpcb *cb, int errno)
1702 struct socket *so = cb->s_ipxpcb->ipxp_socket;
1705 * someday, in the xerox world
1706 * we will generate error protocol packets
1707 * announcing that the socket has gone away.
1709 if (TCPS_HAVERCVDSYN(cb->s_state)) {
1710 spxstat.spxs_drops++;
1711 cb->s_state = TCPS_CLOSED;
1714 spxstat.spxs_conndrops++;
1715 so->so_error = errno;
1716 return (spx_close(cb));
1720 * Fast timeout routine for processing delayed acks
1725 struct ipxpcb *ipxp;
1729 LIST_FOREACH(ipxp, &ipxpcb_list, ipxp_list) {
1730 if ((cb = (struct spxpcb *)ipxp->ipxp_pcb) != NULL &&
1731 (cb->s_flags & SF_DELACK)) {
1732 cb->s_flags &= ~SF_DELACK;
1733 cb->s_flags |= SF_ACKNOW;
1734 spxstat.spxs_delack++;
1735 spx_output(cb, NULL);
1742 * spx protocol timeout routine called every 500 ms.
1743 * Updates the timers in all active pcb's and
1744 * causes finite state machine actions if timers expire.
1749 struct ipxpcb *ip, *ip_temp;
1754 * Search through tcb's and update active timers.
1757 LIST_FOREACH_MUTABLE(ip, &ipxpcb_list, ipxp_list, ip_temp) {
1758 cb = ipxtospxpcb(ip);
1761 for (i = 0; i < SPXT_NTIMERS; i++) {
1762 if (cb->s_timer[i] && --cb->s_timer[i] == 0) {
1763 if (spx_timers(cb, i) == NULL)
1771 spx_iss += SPX_ISSINCR/PR_SLOWHZ; /* increment iss */
1776 * SPX timer processing.
1778 static struct spxpcb *
1779 spx_timers(struct spxpcb *cb, int timer)
1784 cb->s_force = 1 + timer;
1788 * 2 MSL timeout in shutdown went off. TCP deletes connection
1792 kprintf("spx: SPXT_2MSL went off for no reason\n");
1793 cb->s_timer[timer] = 0;
1797 * Retransmission timer went off. Message has not
1798 * been acked within retransmit interval. Back off
1799 * to a longer retransmit interval and retransmit one packet.
1802 if (++cb->s_rxtshift > SPX_MAXRXTSHIFT) {
1803 cb->s_rxtshift = SPX_MAXRXTSHIFT;
1804 spxstat.spxs_timeoutdrop++;
1805 cb = spx_drop(cb, ETIMEDOUT);
1808 spxstat.spxs_rexmttimeo++;
1809 rexmt = ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1;
1810 rexmt *= spx_backoff[cb->s_rxtshift];
1811 SPXT_RANGESET(cb->s_rxtcur, rexmt, SPXTV_MIN, SPXTV_REXMTMAX);
1812 cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
1814 * If we have backed off fairly far, our srtt
1815 * estimate is probably bogus. Clobber it
1816 * so we'll take the next rtt measurement as our srtt;
1817 * move the current srtt into rttvar to keep the current
1818 * retransmit times until then.
1820 if (cb->s_rxtshift > SPX_MAXRXTSHIFT / 4 ) {
1821 cb->s_rttvar += (cb->s_srtt >> 2);
1824 cb->s_snxt = cb->s_rack;
1826 * If timing a packet, stop the timer.
1830 * See very long discussion in tcp_timer.c about congestion
1831 * window and sstrhesh
1833 win = min(cb->s_swnd, (cb->s_cwnd/CUNIT)) / 2;
1837 cb->s_ssthresh = win * CUNIT;
1838 spx_output(cb, NULL);
1842 * Persistance timer into zero window.
1843 * Force a probe to be sent.
1846 spxstat.spxs_persisttimeo++;
1848 spx_output(cb, NULL);
1852 * Keep-alive timer went off; send something
1853 * or drop connection if idle for too long.
1856 spxstat.spxs_keeptimeo++;
1857 if (cb->s_state < TCPS_ESTABLISHED)
1859 if (cb->s_ipxpcb->ipxp_socket->so_options & SO_KEEPALIVE) {
1860 if (cb->s_idle >= SPXTV_MAXIDLE)
1862 spxstat.spxs_keepprobe++;
1863 spx_output(cb, NULL);
1866 cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
1869 spxstat.spxs_keepdrops++;
1870 cb = spx_drop(cb, ETIMEDOUT);