2 * Copyright (c) 2004-2005 Robert N. M. Watson
3 * Copyright (c) 1995, Mike Mitchell
4 * Copyright (c) 1984, 1985, 1986, 1987, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
41 #include <sys/param.h>
43 #include <sys/malloc.h>
45 #include <sys/mutex.h>
47 #include <sys/protosw.h>
48 #include <sys/signalvar.h>
49 #include <sys/socket.h>
50 #include <sys/socketvar.h>
52 #include <sys/systm.h>
54 #include <net/route.h>
55 #include <netinet/tcp_fsm.h>
57 #include <netipx/ipx.h>
58 #include <netipx/ipx_pcb.h>
59 #include <netipx/ipx_var.h>
60 #include <netipx/spx.h>
61 #include <netipx/spx_debug.h>
62 #include <netipx/spx_timer.h>
63 #include <netipx/spx_var.h>
66 * SPX protocol implementation.
68 static u_short spx_iss;
69 static u_short spx_newchecks[50];
70 static int spx_hardnosed;
71 static int spx_use_delack = 0;
72 static int traceallspxs = 0;
73 static struct spx spx_savesi;
74 static struct spx_istat spx_istat;
76 /* Following was struct spxstat spxstat; */
78 #define spxstat spx_istat.newstats
81 static const int spx_backoff[SPX_MAXRXTSHIFT+1] =
82 { 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 };
84 static void spx_close(struct spxpcb *cb);
85 static void spx_disconnect(struct spxpcb *cb);
86 static void spx_drop(struct spxpcb *cb, int errno);
87 static int spx_output(struct spxpcb *cb, struct mbuf *m0);
88 static int spx_reass(struct spxpcb *cb, struct spx *si);
89 static void spx_setpersist(struct spxpcb *cb);
90 static void spx_template(struct spxpcb *cb);
91 static struct spxpcb *spx_timers(struct spxpcb *cb, int timer);
92 static void spx_usrclosed(struct spxpcb *cb);
94 static int spx_usr_abort(struct socket *so);
95 static int spx_accept(struct socket *so, struct sockaddr **nam);
96 static int spx_attach(struct socket *so, int proto, struct thread *td);
97 static int spx_bind(struct socket *so, struct sockaddr *nam, struct thread *td);
98 static int spx_connect(struct socket *so, struct sockaddr *nam,
100 static int spx_detach(struct socket *so);
101 static int spx_usr_disconnect(struct socket *so);
102 static int spx_listen(struct socket *so, int backlog, struct thread *td);
103 static int spx_rcvd(struct socket *so, int flags);
104 static int spx_rcvoob(struct socket *so, struct mbuf *m, int flags);
105 static int spx_send(struct socket *so, int flags, struct mbuf *m,
106 struct sockaddr *addr, struct mbuf *control,
108 static int spx_shutdown(struct socket *so);
109 static int spx_sp_attach(struct socket *so, int proto, struct thread *td);
111 struct pr_usrreqs spx_usrreqs = {
112 .pru_abort = spx_usr_abort,
113 .pru_accept = spx_accept,
114 .pru_attach = spx_attach,
115 .pru_bind = spx_bind,
116 .pru_connect = spx_connect,
117 .pru_control = ipx_control,
118 .pru_detach = spx_detach,
119 .pru_disconnect = spx_usr_disconnect,
120 .pru_listen = spx_listen,
121 .pru_peeraddr = ipx_peeraddr,
122 .pru_rcvd = spx_rcvd,
123 .pru_rcvoob = spx_rcvoob,
124 .pru_send = spx_send,
125 .pru_shutdown = spx_shutdown,
126 .pru_sockaddr = ipx_sockaddr,
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_control = ipx_control,
136 .pru_detach = spx_detach,
137 .pru_disconnect = spx_usr_disconnect,
138 .pru_listen = spx_listen,
139 .pru_peeraddr = ipx_peeraddr,
140 .pru_rcvd = spx_rcvd,
141 .pru_rcvoob = spx_rcvoob,
142 .pru_send = spx_send,
143 .pru_shutdown = spx_shutdown,
144 .pru_sockaddr = ipx_sockaddr,
151 spx_iss = 1; /* WRONG !! should fish it out of TODR */
156 register struct mbuf *m;
157 register struct ipxpcb *ipxp;
159 register struct spxpcb *cb;
160 register struct spx *si = mtod(m, struct spx *);
161 register struct socket *so;
165 spxstat.spxs_rcvtotal++;
166 KASSERT(ipxp != NULL, ("spx_input: NULL ipxpcb"));
169 * spx_input() assumes that the caller will hold both the pcb list
170 * lock and also the ipxp lock. spx_input() will release both before
171 * returning, and may in fact trade in the ipxp lock for another pcb
172 * lock following sonewconn().
174 IPX_LIST_LOCK_ASSERT();
175 IPX_LOCK_ASSERT(ipxp);
177 cb = ipxtospxpcb(ipxp);
181 if (m->m_len < sizeof(*si)) {
182 if ((m = m_pullup(m, sizeof(*si))) == NULL) {
185 spxstat.spxs_rcvshort++;
188 si = mtod(m, struct spx *);
190 si->si_seq = ntohs(si->si_seq);
191 si->si_ack = ntohs(si->si_ack);
192 si->si_alo = ntohs(si->si_alo);
194 so = ipxp->ipxp_socket;
196 if (so->so_options & SO_DEBUG || traceallspxs) {
197 ostate = cb->s_state;
200 if (so->so_options & SO_ACCEPTCONN) {
201 struct spxpcb *ocb = cb;
203 so = sonewconn(so, 0);
208 * This is ugly, but ....
210 * Mark socket as temporary until we're
211 * committed to keeping it. The code at
212 * ``drop'' and ``dropwithreset'' check the
213 * flag dropsocket to see if the temporary
214 * socket created here should be discarded.
215 * We mark the socket as discardable until
216 * we're committed to it below in TCPS_LISTEN.
220 ipxp = (struct ipxpcb *)so->so_pcb;
222 ipxp->ipxp_laddr = si->si_dna;
223 cb = ipxtospxpcb(ipxp);
224 cb->s_mtu = ocb->s_mtu; /* preserve sockopts */
225 cb->s_flags = ocb->s_flags; /* preserve sockopts */
226 cb->s_flags2 = ocb->s_flags2; /* preserve sockopts */
227 cb->s_state = TCPS_LISTEN;
231 * Packet received on connection.
232 * reset idle time and keep-alive timer;
235 cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
237 switch (cb->s_state) {
240 struct sockaddr_ipx *sipx, ssipx;
241 struct ipx_addr laddr;
244 * If somebody here was carying on a conversation
245 * and went away, and his pen pal thinks he can
246 * still talk, we get the misdirected packet.
248 if (spx_hardnosed && (si->si_did != 0 || si->si_seq != 0)) {
253 bzero(sipx, sizeof *sipx);
254 sipx->sipx_len = sizeof(*sipx);
255 sipx->sipx_family = AF_IPX;
256 sipx->sipx_addr = si->si_sna;
257 laddr = ipxp->ipxp_laddr;
258 if (ipx_nullhost(laddr))
259 ipxp->ipxp_laddr = si->si_dna;
260 if (ipx_pcbconnect(ipxp, (struct sockaddr *)sipx, &thread0)) {
261 ipxp->ipxp_laddr = laddr;
266 dropsocket = 0; /* committed to socket */
267 cb->s_did = si->si_sid;
268 cb->s_rack = si->si_ack;
269 cb->s_ralo = si->si_alo;
270 #define THREEWAYSHAKE
272 cb->s_state = TCPS_SYN_RECEIVED;
273 cb->s_force = 1 + SPXT_KEEP;
274 spxstat.spxs_accepts++;
275 cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
279 * This state means that we have heard a response
280 * to our acceptance of their connection
281 * It is probably logically unnecessary in this
284 case TCPS_SYN_RECEIVED: {
285 if (si->si_did != cb->s_sid) {
290 ipxp->ipxp_fport = si->si_sport;
291 cb->s_timer[SPXT_REXMT] = 0;
292 cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
294 cb->s_state = TCPS_ESTABLISHED;
295 spxstat.spxs_accepts++;
300 * This state means that we have gotten a response
301 * to our attempt to establish a connection.
302 * We fill in the data from the other side,
303 * telling us which port to respond to, instead of the well-
304 * known one we might have sent to in the first place.
305 * We also require that this is a response to our
309 if (si->si_did != cb->s_sid) {
313 spxstat.spxs_connects++;
314 cb->s_did = si->si_sid;
315 cb->s_rack = si->si_ack;
316 cb->s_ralo = si->si_alo;
317 cb->s_dport = ipxp->ipxp_fport = si->si_sport;
318 cb->s_timer[SPXT_REXMT] = 0;
319 cb->s_flags |= SF_ACKNOW;
321 cb->s_state = TCPS_ESTABLISHED;
322 /* Use roundtrip time of connection request for initial rtt */
324 cb->s_srtt = cb->s_rtt << 3;
325 cb->s_rttvar = cb->s_rtt << 1;
326 SPXT_RANGESET(cb->s_rxtcur,
327 ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1,
328 SPXTV_MIN, SPXTV_REXMTMAX);
332 if (so->so_options & SO_DEBUG || traceallspxs)
333 spx_trace(SA_INPUT, (u_char)ostate, cb, &spx_savesi, 0);
335 m->m_len -= sizeof(struct ipx);
336 m->m_pkthdr.len -= sizeof(struct ipx);
337 m->m_data += sizeof(struct ipx);
339 if (spx_reass(cb, si)) {
342 if (cb->s_force || (cb->s_flags & (SF_ACKNOW|SF_WIN|SF_RXT)))
343 spx_output(cb, NULL);
344 cb->s_flags &= ~(SF_WIN|SF_RXT);
354 KASSERT((so->so_qstate & SQ_INCOMP) != 0,
355 ("spx_input: nascent socket not SQ_INCOMP on soabort()"));
357 TAILQ_REMOVE(&head->so_incomp, so, so_list);
359 so->so_qstate &= ~SQ_INCOMP;
366 si->si_seq = ntohs(si->si_seq);
367 si->si_ack = ntohs(si->si_ack);
368 si->si_alo = ntohs(si->si_alo);
370 if (cb == NULL || cb->s_ipxpcb->ipxp_socket->so_options & SO_DEBUG ||
372 spx_trace(SA_DROP, (u_char)ostate, cb, &spx_savesi, 0);
377 if (cb == NULL || cb->s_ipxpcb->ipxp_socket->so_options & SO_DEBUG ||
379 spx_trace(SA_DROP, (u_char)ostate, cb, &spx_savesi, 0);
385 static int spxrexmtthresh = 3;
388 * This is structurally similar to the tcp reassembly routine
389 * but its function is somewhat different: It merely queues
390 * packets up, and suppresses duplicates.
394 register struct spxpcb *cb;
395 register struct spx *si;
397 register struct spx_q *q;
398 register struct mbuf *m;
399 register struct socket *so = cb->s_ipxpcb->ipxp_socket;
400 char packetp = cb->s_flags & SF_HI;
404 IPX_LOCK_ASSERT(cb->s_ipxpcb);
409 * Update our news from them.
411 if (si->si_cc & SPX_SA)
412 cb->s_flags |= (spx_use_delack ? SF_DELACK : SF_ACKNOW);
413 if (SSEQ_GT(si->si_alo, cb->s_ralo))
414 cb->s_flags |= SF_WIN;
415 if (SSEQ_LEQ(si->si_ack, cb->s_rack)) {
416 if ((si->si_cc & SPX_SP) && cb->s_rack != (cb->s_smax + 1)) {
417 spxstat.spxs_rcvdupack++;
419 * If this is a completely duplicate ack
420 * and other conditions hold, we assume
421 * a packet has been dropped and retransmit
422 * it exactly as in tcp_input().
424 if (si->si_ack != cb->s_rack ||
425 si->si_alo != cb->s_ralo)
427 else if (++cb->s_dupacks == spxrexmtthresh) {
428 u_short onxt = cb->s_snxt;
429 int cwnd = cb->s_cwnd;
431 cb->s_snxt = si->si_ack;
433 cb->s_force = 1 + SPXT_REXMT;
434 spx_output(cb, NULL);
435 cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
437 if (cwnd >= 4 * CUNIT)
438 cb->s_cwnd = cwnd / 2;
439 if (SSEQ_GT(onxt, cb->s_snxt))
449 * If our correspondent acknowledges data we haven't sent
450 * TCP would drop the packet after acking. We'll be a little
453 if (SSEQ_GT(si->si_ack, (cb->s_smax + 1))) {
454 spxstat.spxs_rcvacktoomuch++;
455 si->si_ack = cb->s_smax + 1;
457 spxstat.spxs_rcvackpack++;
459 * If transmit timer is running and timed sequence
460 * number was acked, update smoothed round trip time.
461 * See discussion of algorithm in tcp_input.c
463 if (cb->s_rtt && SSEQ_GT(si->si_ack, cb->s_rtseq)) {
464 spxstat.spxs_rttupdated++;
465 if (cb->s_srtt != 0) {
466 register short delta;
467 delta = cb->s_rtt - (cb->s_srtt >> 3);
468 if ((cb->s_srtt += delta) <= 0)
472 delta -= (cb->s_rttvar >> 2);
473 if ((cb->s_rttvar += delta) <= 0)
477 * No rtt measurement yet
479 cb->s_srtt = cb->s_rtt << 3;
480 cb->s_rttvar = cb->s_rtt << 1;
484 SPXT_RANGESET(cb->s_rxtcur,
485 ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1,
486 SPXTV_MIN, SPXTV_REXMTMAX);
489 * If all outstanding data is acked, stop retransmit
490 * timer and remember to restart (more output or persist).
491 * If there is more data to be acked, restart retransmit
492 * timer, using current (possibly backed-off) value;
494 if (si->si_ack == cb->s_smax + 1) {
495 cb->s_timer[SPXT_REXMT] = 0;
496 cb->s_flags |= SF_RXT;
497 } else if (cb->s_timer[SPXT_PERSIST] == 0)
498 cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
500 * When new data is acked, open the congestion window.
501 * If the window gives us less than ssthresh packets
502 * in flight, open exponentially (maxseg at a time).
503 * Otherwise open linearly (maxseg^2 / cwnd at a time).
506 if (cb->s_cwnd > cb->s_ssthresh)
507 incr = max(incr * incr / cb->s_cwnd, 1);
508 cb->s_cwnd = min(cb->s_cwnd + incr, cb->s_cwmx);
510 * Trim Acked data from output queue.
512 SOCKBUF_LOCK(&so->so_snd);
513 while ((m = so->so_snd.sb_mb) != NULL) {
514 if (SSEQ_LT((mtod(m, struct spx *))->si_seq, si->si_ack))
515 sbdroprecord_locked(&so->so_snd);
519 sowwakeup_locked(so);
520 cb->s_rack = si->si_ack;
522 if (SSEQ_LT(cb->s_snxt, cb->s_rack))
523 cb->s_snxt = cb->s_rack;
524 if (SSEQ_LT(cb->s_swl1, si->si_seq) || ((cb->s_swl1 == si->si_seq &&
525 (SSEQ_LT(cb->s_swl2, si->si_ack))) ||
526 (cb->s_swl2 == si->si_ack && SSEQ_LT(cb->s_ralo, si->si_alo)))) {
527 /* keep track of pure window updates */
528 if ((si->si_cc & SPX_SP) && cb->s_swl2 == si->si_ack
529 && SSEQ_LT(cb->s_ralo, si->si_alo)) {
530 spxstat.spxs_rcvwinupd++;
531 spxstat.spxs_rcvdupack--;
533 cb->s_ralo = si->si_alo;
534 cb->s_swl1 = si->si_seq;
535 cb->s_swl2 = si->si_ack;
536 cb->s_swnd = (1 + si->si_alo - si->si_ack);
537 if (cb->s_swnd > cb->s_smxw)
538 cb->s_smxw = cb->s_swnd;
539 cb->s_flags |= SF_WIN;
542 * If this packet number is higher than that which
543 * we have allocated refuse it, unless urgent
545 if (SSEQ_GT(si->si_seq, cb->s_alo)) {
546 if (si->si_cc & SPX_SP) {
547 spxstat.spxs_rcvwinprobe++;
550 spxstat.spxs_rcvpackafterwin++;
551 if (si->si_cc & SPX_OB) {
552 if (SSEQ_GT(si->si_seq, cb->s_alo + 60)) {
555 } /* else queue this packet; */
559 * XXXRW: This is broken on at least one count:
560 * spx_close() will free the ipxp and related parts,
561 * which are then touched by spx_input() after the
562 * return from spx_reass().
564 /*register struct socket *so = cb->s_ipxpcb->ipxp_socket;
565 if (so->so_state && SS_NOFDREF) {
576 * If this is a system packet, we don't need to
577 * queue it up, and won't update acknowledge #
579 if (si->si_cc & SPX_SP) {
583 * We have already seen this packet, so drop.
585 if (SSEQ_LT(si->si_seq, cb->s_ack)) {
587 spxstat.spxs_rcvduppack++;
588 if (si->si_seq == cb->s_ack - 1)
593 * Loop through all packets queued up to insert in
594 * appropriate sequence.
596 for (q = cb->s_q.si_next; q != &cb->s_q; q = q->si_next) {
597 if (si->si_seq == SI(q)->si_seq) {
598 spxstat.spxs_rcvduppack++;
601 if (SSEQ_LT(si->si_seq, SI(q)->si_seq)) {
602 spxstat.spxs_rcvoopack++;
606 insque(si, q->si_prev);
608 * If this packet is urgent, inform process
610 if (si->si_cc & SPX_OB) {
611 cb->s_iobc = ((char *)si)[1 + sizeof(*si)];
613 cb->s_oobflags |= SF_IOOB;
616 #define SPINC sizeof(struct spxhdr)
617 SOCKBUF_LOCK(&so->so_rcv);
619 * Loop through all packets queued up to update acknowledge
620 * number, and present all acknowledged data to user;
621 * If in packet interface mode, show packet headers.
623 for (q = cb->s_q.si_next; q != &cb->s_q; q = q->si_next) {
624 if (SI(q)->si_seq == cb->s_ack) {
627 if (SI(q)->si_cc & SPX_OB) {
628 cb->s_oobflags &= ~SF_IOOB;
629 if (so->so_rcv.sb_cc)
630 so->so_oobmark = so->so_rcv.sb_cc;
632 so->so_rcv.sb_state |= SBS_RCVATMARK;
637 spxstat.spxs_rcvpack++;
639 if (cb->s_flags2 & SF_NEWCALL) {
640 struct spxhdr *sp = mtod(m, struct spxhdr *);
641 u_char dt = sp->spx_dt;
643 if (dt != cb->s_rhdr.spx_dt) {
645 m_getclr(M_DONTWAIT, MT_CONTROL);
650 cb->s_rhdr.spx_dt = dt;
651 mm->m_len = 5; /*XXX*/
654 *(u_char *)(&s[2]) = dt;
655 sbappend_locked(&so->so_rcv, mm);
658 if (sp->spx_cc & SPX_OB) {
659 MCHTYPE(m, MT_OOBDATA);
662 so->so_rcv.sb_state &= ~SBS_RCVATMARK;
667 m->m_pkthdr.len -= SPINC;
669 if ((sp->spx_cc & SPX_EM) || packetp) {
670 sbappendrecord_locked(&so->so_rcv, m);
673 sbappend_locked(&so->so_rcv, m);
677 sbappendrecord_locked(&so->so_rcv, m);
679 cb->s_rhdr = *mtod(m, struct spxhdr *);
682 m->m_pkthdr.len -= SPINC;
683 sbappend_locked(&so->so_rcv, m);
689 sorwakeup_locked(so);
691 SOCKBUF_UNLOCK(&so->so_rcv);
696 spx_ctlinput(cmd, arg_as_sa, dummy)
698 struct sockaddr *arg_as_sa; /* XXX should be swapped with dummy */
701 caddr_t arg = (/* XXX */ caddr_t)arg_as_sa;
703 struct sockaddr_ipx *sipx;
705 if (cmd < 0 || cmd >= PRC_NCMDS)
715 case PRC_HOSTUNREACH:
716 sipx = (struct sockaddr_ipx *)arg;
717 if (sipx->sipx_family != AF_IPX)
719 na = &sipx->sipx_addr;
729 register struct spxpcb *cb;
732 struct socket *so = cb->s_ipxpcb->ipxp_socket;
733 register struct mbuf *m;
734 register struct spx *si = NULL;
735 register struct sockbuf *sb = &so->so_snd;
736 int len = 0, win, rcv_win;
737 short span, off, recordp = 0;
739 int error = 0, sendalot;
745 IPX_LOCK_ASSERT(cb->s_ipxpcb);
751 * Make sure that packet isn't too big.
753 for (m = m0; m != NULL; m = m->m_next) {
756 if (m->m_flags & M_EOR)
759 datalen = (cb->s_flags & SF_HO) ?
760 len - sizeof(struct spxhdr) : len;
762 if (cb->s_flags & SF_PI) {
766 int oldEM = cb->s_cc & SPX_EM;
771 * Here we are only being called
772 * from usrreq(), so it is OK to
775 m = m_copym(m0, 0, mtu, M_TRYWAIT);
776 if (cb->s_flags & SF_NEWCALL) {
780 mm->m_flags &= ~M_EOR;
784 error = spx_output(cb, m);
797 * Force length even, by adding a "garbage byte" if
802 if (M_TRAILINGSPACE(m) >= 1)
805 struct mbuf *m1 = m_get(M_DONTWAIT, MT_DATA);
812 *(mtod(m1, u_char *)) = 0;
816 m = m_gethdr(M_DONTWAIT, MT_DATA);
822 * Fill in mbuf with extended SP header
823 * and addresses and length put into network format.
825 MH_ALIGN(m, sizeof(struct spx));
826 m->m_len = sizeof(struct spx);
828 si = mtod(m, struct spx *);
829 si->si_i = *cb->s_ipx;
830 si->si_s = cb->s_shdr;
831 if ((cb->s_flags & SF_PI) && (cb->s_flags & SF_HO)) {
832 register struct spxhdr *sh;
833 if (m0->m_len < sizeof(*sh)) {
834 if((m0 = m_pullup(m0, sizeof(*sh))) == NULL) {
841 sh = mtod(m0, struct spxhdr *);
842 si->si_dt = sh->spx_dt;
843 si->si_cc |= sh->spx_cc & SPX_EM;
844 m0->m_len -= sizeof(*sh);
845 m0->m_data += sizeof(*sh);
849 if ((cb->s_flags2 & SF_NEWCALL) && recordp) {
853 if (cb->s_oobflags & SF_SOOB) {
856 * make sure OB packets convey exactly 1 byte.
857 * If the packet is 1 byte or larger, we
858 * have already guaranted there to be at least
859 * one garbage byte for the checksum, and
860 * extra bytes shouldn't hurt!
862 if (len > sizeof(*si)) {
864 len = (1 + sizeof(*si));
867 si->si_len = htons((u_short)len);
868 m->m_pkthdr.len = ((len - 1) | 1) + 1;
870 * queue stuff up for output
872 sbappendrecord(sb, m);
876 idle = (cb->s_smax == (cb->s_rack - 1));
880 off = cb->s_snxt - cb->s_rack;
881 win = min(cb->s_swnd, (cb->s_cwnd / CUNIT));
884 * If in persist timeout with window of 0, send a probe.
885 * Otherwise, if window is small but nonzero
886 * and timer expired, send what we can and go into
889 if (cb->s_force == 1 + SPXT_PERSIST) {
891 cb->s_timer[SPXT_PERSIST] = 0;
895 span = cb->s_seq - cb->s_rack;
896 len = min(span, win) - off;
900 * Window shrank after we went into it.
901 * If window shrank to 0, cancel pending
902 * restransmission and pull s_snxt back
903 * to (closed) window. We will enter persist
904 * state below. If the widndow didn't close completely,
905 * just wait for an ACK.
909 cb->s_timer[SPXT_REXMT] = 0;
910 cb->s_snxt = cb->s_rack;
915 rcv_win = sbspace(&so->so_rcv);
918 * Send if we owe peer an ACK.
920 if (cb->s_oobflags & SF_SOOB) {
922 * must transmit this out of band packet
924 cb->s_oobflags &= ~ SF_SOOB;
926 spxstat.spxs_sndurg++;
929 if (cb->s_flags & SF_ACKNOW)
931 if (cb->s_state < TCPS_ESTABLISHED)
934 * Silly window can't happen in spx.
935 * Code from tcp deleted.
940 * Compare available window to amount of window
941 * known to peer (as advertised window less
942 * next expected input.) If the difference is at least two
943 * packets or at least 35% of the mximum possible window,
944 * then want to send a window update to peer.
947 u_short delta = 1 + cb->s_alo - cb->s_ack;
948 int adv = rcv_win - (delta * cb->s_mtu);
950 if ((so->so_rcv.sb_cc == 0 && adv >= (2 * cb->s_mtu)) ||
951 (100 * adv / so->so_rcv.sb_hiwat >= 35)) {
952 spxstat.spxs_sndwinup++;
953 cb->s_flags |= SF_ACKNOW;
959 * Many comments from tcp_output.c are appropriate here
961 * If send window is too small, there is data to transmit, and no
962 * retransmit or persist is pending, then go to persist state.
963 * If nothing happens soon, send when timer expires:
964 * if window is nonzero, transmit what we can,
965 * otherwise send a probe.
967 if (so->so_snd.sb_cc && cb->s_timer[SPXT_REXMT] == 0 &&
968 cb->s_timer[SPXT_PERSIST] == 0) {
973 * No reason to send a packet, just return.
980 * Find requested packet.
984 cb->s_want = cb->s_snxt;
985 for (m = sb->sb_mb; m != NULL; m = m->m_act) {
986 si = mtod(m, struct spx *);
987 if (SSEQ_LEQ(cb->s_snxt, si->si_seq))
992 if (si->si_seq == cb->s_snxt)
995 spxstat.spxs_sndvoid++, si = 0;
1003 alo = cb->s_ack - 1 + (rcv_win / ((short)cb->s_mtu));
1004 if (SSEQ_LT(alo, cb->s_alo))
1009 * must make a copy of this packet for
1010 * ipx_output to monkey with
1012 m = m_copy(dtom(si), 0, (int)M_COPYALL);
1016 si = mtod(m, struct spx *);
1017 if (SSEQ_LT(si->si_seq, cb->s_smax))
1018 spxstat.spxs_sndrexmitpack++;
1020 spxstat.spxs_sndpack++;
1021 } else if (cb->s_force || cb->s_flags & SF_ACKNOW) {
1023 * Must send an acknowledgement or a probe
1026 spxstat.spxs_sndprobe++;
1027 if (cb->s_flags & SF_ACKNOW)
1028 spxstat.spxs_sndacks++;
1029 m = m_gethdr(M_DONTWAIT, MT_DATA);
1033 * Fill in mbuf with extended SP header
1034 * and addresses and length put into network format.
1036 MH_ALIGN(m, sizeof(struct spx));
1037 m->m_len = sizeof(*si);
1038 m->m_pkthdr.len = sizeof(*si);
1039 si = mtod(m, struct spx *);
1040 si->si_i = *cb->s_ipx;
1041 si->si_s = cb->s_shdr;
1042 si->si_seq = cb->s_smax + 1;
1043 si->si_len = htons(sizeof(*si));
1044 si->si_cc |= SPX_SP;
1047 if (so->so_options & SO_DEBUG || traceallspxs)
1048 spx_trace(SA_OUTPUT, cb->s_state, cb, si, 0);
1052 * Stuff checksum and output datagram.
1054 if ((si->si_cc & SPX_SP) == 0) {
1055 if (cb->s_force != (1 + SPXT_PERSIST) ||
1056 cb->s_timer[SPXT_PERSIST] == 0) {
1058 * If this is a new packet and we are not currently
1059 * timing anything, time this one.
1061 if (SSEQ_LT(cb->s_smax, si->si_seq)) {
1062 cb->s_smax = si->si_seq;
1063 if (cb->s_rtt == 0) {
1064 spxstat.spxs_segstimed++;
1065 cb->s_rtseq = si->si_seq;
1070 * Set rexmt timer if not currently set,
1071 * Initial value for retransmit timer is smoothed
1072 * round-trip time + 2 * round-trip time variance.
1073 * Initialize shift counter which is used for backoff
1074 * of retransmit time.
1076 if (cb->s_timer[SPXT_REXMT] == 0 &&
1077 cb->s_snxt != cb->s_rack) {
1078 cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
1079 if (cb->s_timer[SPXT_PERSIST]) {
1080 cb->s_timer[SPXT_PERSIST] = 0;
1084 } else if (SSEQ_LT(cb->s_smax, si->si_seq)) {
1085 cb->s_smax = si->si_seq;
1087 } else if (cb->s_state < TCPS_ESTABLISHED) {
1089 cb->s_rtt = 1; /* Time initial handshake */
1090 if (cb->s_timer[SPXT_REXMT] == 0)
1091 cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
1095 * Do not request acks when we ack their data packets or
1096 * when we do a gratuitous window update.
1098 if (((si->si_cc & SPX_SP) == 0) || cb->s_force)
1099 si->si_cc |= SPX_SA;
1100 si->si_seq = htons(si->si_seq);
1101 si->si_alo = htons(alo);
1102 si->si_ack = htons(cb->s_ack);
1105 si->si_sum = ipx_cksum(m, ntohs(si->si_len));
1107 si->si_sum = 0xffff;
1110 if (so->so_options & SO_DEBUG || traceallspxs)
1111 spx_trace(SA_OUTPUT, cb->s_state, cb, si, 0);
1113 if (so->so_options & SO_DONTROUTE)
1114 error = ipx_outputfl(m, NULL, IPX_ROUTETOIF);
1116 error = ipx_outputfl(m, &cb->s_ipxpcb->ipxp_route, 0);
1121 spxstat.spxs_sndtotal++;
1123 * Data sent (as far as we can tell).
1124 * If this advertises a larger window than any other segment,
1125 * then remember the size of the advertized window.
1126 * Any pending ACK has now been sent.
1129 cb->s_flags &= ~(SF_ACKNOW|SF_DELACK);
1130 if (SSEQ_GT(alo, cb->s_alo))
1138 static int spx_do_persist_panics = 0;
1142 register struct spxpcb *cb;
1144 register int t = ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1;
1146 IPX_LOCK_ASSERT(cb->s_ipxpcb);
1148 if (cb->s_timer[SPXT_REXMT] && spx_do_persist_panics)
1149 panic("spx_output REXMT");
1151 * Start/restart persistance timer.
1153 SPXT_RANGESET(cb->s_timer[SPXT_PERSIST],
1154 t*spx_backoff[cb->s_rxtshift],
1155 SPXTV_PERSMIN, SPXTV_PERSMAX);
1156 if (cb->s_rxtshift < SPX_MAXRXTSHIFT)
1161 spx_ctloutput(so, sopt)
1163 struct sockopt *sopt;
1165 struct ipxpcb *ipxp = sotoipxpcb(so);
1166 register struct spxpcb *cb;
1174 if (sopt->sopt_level != IPXPROTO_SPX) {
1175 /* This will have to be changed when we do more general
1176 stacking of protocols */
1177 return (ipx_ctloutput(so, sopt));
1182 cb = ipxtospxpcb(ipxp);
1184 switch (sopt->sopt_dir) {
1186 switch (sopt->sopt_name) {
1187 case SO_HEADERS_ON_INPUT:
1191 case SO_HEADERS_ON_OUTPUT:
1194 /* Unlocked read. */
1195 soptval = cb->s_flags & mask;
1196 error = sooptcopyout(sopt, &soptval, sizeof soptval);
1200 /* Unlocked read. */
1201 usoptval = cb->s_mtu;
1202 error = sooptcopyout(sopt, &usoptval, sizeof usoptval);
1205 case SO_LAST_HEADER:
1206 /* Unlocked read. */
1207 error = sooptcopyout(sopt, &cb->s_rhdr,
1211 case SO_DEFAULT_HEADERS:
1212 /* Unlocked read. */
1213 error = sooptcopyout(sopt, &cb->s_shdr,
1218 error = ENOPROTOOPT;
1223 switch (sopt->sopt_name) {
1224 /* XXX why are these shorts on get and ints on set?
1225 that doesn't make any sense... */
1226 case SO_HEADERS_ON_INPUT:
1230 case SO_HEADERS_ON_OUTPUT:
1233 error = sooptcopyin(sopt, &optval, sizeof optval,
1239 if (cb->s_flags & SF_PI) {
1241 cb->s_flags |= mask;
1243 cb->s_flags &= ~mask;
1244 } else error = EINVAL;
1249 error = sooptcopyin(sopt, &usoptval, sizeof usoptval,
1253 /* Unlocked write. */
1254 cb->s_mtu = usoptval;
1259 error = sooptcopyin(sopt, &optval, sizeof optval,
1265 cb->s_flags2 |= SF_NEWCALL;
1268 cb->s_flags2 &= ~SF_NEWCALL;
1275 case SO_DEFAULT_HEADERS:
1279 error = sooptcopyin(sopt, &sp, sizeof sp,
1284 cb->s_dt = sp.spx_dt;
1285 cb->s_cc = sp.spx_cc & SPX_EM;
1291 error = ENOPROTOOPT;
1302 struct ipxpcb *ipxp;
1305 ipxp = sotoipxpcb(so);
1306 cb = ipxtospxpcb(ipxp);
1310 spx_drop(cb, ECONNABORTED);
1316 * Accept a connection. Essentially all the work is
1317 * done at higher levels; just return the address
1318 * of the peer, storing through addr.
1323 struct sockaddr **nam;
1325 struct ipxpcb *ipxp;
1326 struct sockaddr_ipx *sipx, ssipx;
1328 ipxp = sotoipxpcb(so);
1330 bzero(sipx, sizeof *sipx);
1331 sipx->sipx_len = sizeof *sipx;
1332 sipx->sipx_family = AF_IPX;
1334 sipx->sipx_addr = ipxp->ipxp_faddr;
1336 *nam = sodupsockaddr((struct sockaddr *)sipx, M_WAITOK);
1341 spx_attach(so, proto, td)
1346 struct ipxpcb *ipxp;
1352 ipxp = sotoipxpcb(so);
1353 cb = ipxtospxpcb(ipxp);
1356 error = ipx_pcballoc(so, &ipxpcb_list, td);
1358 goto spx_attach_end;
1359 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
1360 error = soreserve(so, (u_long) 3072, (u_long) 3072);
1362 goto spx_attach_end;
1364 ipxp = sotoipxpcb(so);
1366 MALLOC(cb, struct spxpcb *, sizeof *cb, M_PCB, M_NOWAIT | M_ZERO);
1370 goto spx_attach_end;
1374 mm = m_getclr(M_DONTWAIT, MT_DATA);
1378 goto spx_attach_end;
1380 cb->s_ipx = mtod(mm, struct ipx *);
1381 cb->s_state = TCPS_LISTEN;
1384 cb->s_q.si_next = cb->s_q.si_prev = &cb->s_q;
1385 cb->s_ipxpcb = ipxp;
1386 cb->s_mtu = 576 - sizeof(struct spx);
1387 cb->s_cwnd = sbspace(sb) * CUNIT / cb->s_mtu;
1388 cb->s_ssthresh = cb->s_cwnd;
1389 cb->s_cwmx = sbspace(sb) * CUNIT / (2 * sizeof(struct spx));
1390 /* Above is recomputed when connecting to account
1391 for changed buffering or mtu's */
1392 cb->s_rtt = SPXTV_SRTTBASE;
1393 cb->s_rttvar = SPXTV_SRTTDFLT << 2;
1394 SPXT_RANGESET(cb->s_rxtcur,
1395 ((SPXTV_SRTTBASE >> 2) + (SPXTV_SRTTDFLT << 2)) >> 1,
1396 SPXTV_MIN, SPXTV_REXMTMAX);
1397 ipxp->ipxp_pcb = (caddr_t)cb;
1404 spx_bind(so, nam, td)
1406 struct sockaddr *nam;
1409 struct ipxpcb *ipxp;
1412 ipxp = sotoipxpcb(so);
1416 error = ipx_pcbbind(ipxp, nam, td);
1423 * Initiate connection to peer.
1424 * Enter SYN_SENT state, and mark socket as connecting.
1425 * Start keep-alive timer, setup prototype header,
1426 * Send initial system packet requesting connection.
1429 spx_connect(so, nam, td)
1431 struct sockaddr *nam;
1434 struct ipxpcb *ipxp;
1438 ipxp = sotoipxpcb(so);
1439 cb = ipxtospxpcb(ipxp);
1443 if (ipxp->ipxp_lport == 0) {
1444 error = ipx_pcbbind(ipxp, NULL, td);
1446 goto spx_connect_end;
1448 error = ipx_pcbconnect(ipxp, nam, td);
1450 goto spx_connect_end;
1452 spxstat.spxs_connattempt++;
1453 cb->s_state = TCPS_SYN_SENT;
1456 cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
1457 cb->s_force = 1 + SPXTV_KEEP;
1459 * Other party is required to respond to
1460 * the port I send from, but he is not
1461 * required to answer from where I am sending to,
1462 * so allow wildcarding.
1463 * original port I am sending to is still saved in
1466 ipxp->ipxp_fport = 0;
1467 error = spx_output(cb, NULL);
1478 struct ipxpcb *ipxp;
1481 ipxp = sotoipxpcb(so);
1482 cb = ipxtospxpcb(ipxp);
1486 if (cb->s_state > TCPS_LISTEN)
1495 * We may decide later to implement connection closing
1496 * handshaking at the spx level optionally.
1497 * here is the hook to do it:
1500 spx_usr_disconnect(so)
1503 struct ipxpcb *ipxp;
1506 ipxp = sotoipxpcb(so);
1507 cb = ipxtospxpcb(ipxp);
1517 spx_listen(so, backlog, td)
1523 struct ipxpcb *ipxp;
1527 ipxp = sotoipxpcb(so);
1528 cb = ipxtospxpcb(ipxp);
1533 error = solisten_proto_check(so);
1534 if (error == 0 && ipxp->ipxp_lport == 0)
1535 error = ipx_pcbbind(ipxp, NULL, td);
1537 cb->s_state = TCPS_LISTEN;
1538 solisten_proto(so, backlog);
1547 * After a receive, possibly send acknowledgment
1548 * updating allocation.
1555 struct ipxpcb *ipxp;
1558 ipxp = sotoipxpcb(so);
1559 cb = ipxtospxpcb(ipxp);
1562 cb->s_flags |= SF_RVD;
1563 spx_output(cb, NULL);
1564 cb->s_flags &= ~SF_RVD;
1570 spx_rcvoob(so, m, flags)
1575 struct ipxpcb *ipxp;
1578 ipxp = sotoipxpcb(so);
1579 cb = ipxtospxpcb(ipxp);
1581 SOCKBUF_LOCK(&so->so_rcv);
1582 if ((cb->s_oobflags & SF_IOOB) || so->so_oobmark ||
1583 (so->so_rcv.sb_state & SBS_RCVATMARK)) {
1584 SOCKBUF_UNLOCK(&so->so_rcv);
1586 /* Unlocked read. */
1587 *mtod(m, caddr_t) = cb->s_iobc;
1590 SOCKBUF_UNLOCK(&so->so_rcv);
1595 spx_send(so, flags, m, addr, controlp, td)
1599 struct sockaddr *addr;
1600 struct mbuf *controlp;
1604 struct ipxpcb *ipxp;
1608 ipxp = sotoipxpcb(so);
1609 cb = ipxtospxpcb(ipxp);
1612 if (flags & PRUS_OOB) {
1613 if (sbspace(&so->so_snd) < -512) {
1617 cb->s_oobflags |= SF_SOOB;
1619 if (controlp != NULL) {
1620 u_short *p = mtod(controlp, u_short *);
1622 if ((p[0] == 5) && (p[1] == 1)) { /* XXXX, for testing */
1623 cb->s_shdr.spx_dt = *(u_char *)(&p[2]);
1629 error = spx_output(cb, m);
1633 if (controlp != NULL)
1644 struct ipxpcb *ipxp;
1647 ipxp = sotoipxpcb(so);
1648 cb = ipxtospxpcb(ipxp);
1659 spx_sp_attach(so, proto, td)
1665 struct ipxpcb *ipxp;
1667 error = spx_attach(so, proto, td);
1669 ipxp = sotoipxpcb(so);
1670 ((struct spxpcb *)ipxp->ipxp_pcb)->s_flags |=
1671 (SF_HI | SF_HO | SF_PI);
1677 * Create template to be used to send spx packets on a connection.
1678 * Called after host entry created, fills
1679 * in a skeletal spx header (choosing connection id),
1680 * minimizing the amount of work necessary when the connection is used.
1684 register struct spxpcb *cb;
1686 register struct ipxpcb *ipxp = cb->s_ipxpcb;
1687 register struct ipx *ipx = cb->s_ipx;
1688 register struct sockbuf *sb = &(ipxp->ipxp_socket->so_snd);
1690 IPX_LOCK_ASSERT(ipxp);
1692 ipx->ipx_pt = IPXPROTO_SPX;
1693 ipx->ipx_sna = ipxp->ipxp_laddr;
1694 ipx->ipx_dna = ipxp->ipxp_faddr;
1695 cb->s_sid = htons(spx_iss);
1696 spx_iss += SPX_ISSINCR/2;
1698 cb->s_cwnd = (sbspace(sb) * CUNIT) / cb->s_mtu;
1699 cb->s_ssthresh = cb->s_cwnd; /* Try to expand fast to full complement
1701 cb->s_cwmx = (sbspace(sb) * CUNIT) / (2 * sizeof(struct spx));
1702 cb->s_cwmx = max(cb->s_cwmx, cb->s_cwnd);
1703 /* But allow for lots of little packets as well */
1707 * Close a SPIP control block:
1708 * discard spx control block itself
1709 * discard ipx protocol control block
1710 * wake up any sleepers
1711 * cb will always be invalid after this call.
1715 register struct spxpcb *cb;
1717 register struct spx_q *s;
1718 struct ipxpcb *ipxp = cb->s_ipxpcb;
1719 struct socket *so = ipxp->ipxp_socket;
1720 register struct mbuf *m;
1722 IPX_LIST_LOCK_ASSERT();
1723 IPX_LOCK_ASSERT(ipxp);
1725 s = cb->s_q.si_next;
1726 while (s != &(cb->s_q)) {
1728 m = dtom(s->si_prev);
1732 m_free(dtom(cb->s_ipx));
1734 ipxp->ipxp_pcb = NULL;
1735 soisdisconnected(so);
1736 ipx_pcbdetach(ipxp);
1737 spxstat.spxs_closed++;
1741 * Someday we may do level 3 handshaking
1742 * to close a connection or send a xerox style error.
1743 * For now, just close.
1744 * cb will always be invalid after this call.
1748 register struct spxpcb *cb;
1751 IPX_LIST_LOCK_ASSERT();
1752 IPX_LOCK_ASSERT(cb->s_ipxpcb);
1758 * cb will always be invalid after this call.
1762 register struct spxpcb *cb;
1765 IPX_LIST_LOCK_ASSERT();
1766 IPX_LOCK_ASSERT(cb->s_ipxpcb);
1772 * Drop connection, reporting
1773 * the specified error.
1774 * cb will always be invalid after this call.
1778 register struct spxpcb *cb;
1781 struct socket *so = cb->s_ipxpcb->ipxp_socket;
1783 IPX_LIST_LOCK_ASSERT();
1784 IPX_LOCK_ASSERT(cb->s_ipxpcb);
1787 * someday, in the xerox world
1788 * we will generate error protocol packets
1789 * announcing that the socket has gone away.
1791 if (TCPS_HAVERCVDSYN(cb->s_state)) {
1792 spxstat.spxs_drops++;
1793 cb->s_state = TCPS_CLOSED;
1796 spxstat.spxs_conndrops++;
1797 so->so_error = errno;
1802 * Fast timeout routine for processing delayed acks
1807 struct ipxpcb *ipxp;
1811 LIST_FOREACH(ipxp, &ipxpcb_list, ipxp_list) {
1813 if ((cb = (struct spxpcb *)ipxp->ipxp_pcb) != NULL &&
1814 (cb->s_flags & SF_DELACK)) {
1815 cb->s_flags &= ~SF_DELACK;
1816 cb->s_flags |= SF_ACKNOW;
1817 spxstat.spxs_delack++;
1818 spx_output(cb, NULL);
1826 * spx protocol timeout routine called every 500 ms.
1827 * Updates the timers in all active pcb's and
1828 * causes finite state machine actions if timers expire.
1833 struct ipxpcb *ip, *ip_temp;
1838 * Search through tcb's and update active timers. Note that timers
1839 * may free the ipxpcb, so be sure to handle that case.
1841 * spx_timers() may remove an ipxpcb entry, so we have to be ready to
1842 * continue despite that. The logic here is a bit obfuscated.
1845 LIST_FOREACH_SAFE(ip, &ipxpcb_list, ipxp_list, ip_temp) {
1846 cb = ipxtospxpcb(ip);
1849 IPX_LOCK(cb->s_ipxpcb);
1850 for (i = 0; i < SPXT_NTIMERS; i++) {
1851 if (cb->s_timer[i] && --cb->s_timer[i] == 0) {
1853 * spx_timers() returns (NULL) if it free'd
1856 cb = spx_timers(cb, i);
1865 IPX_UNLOCK(cb->s_ipxpcb);
1868 spx_iss += SPX_ISSINCR/PR_SLOWHZ; /* increment iss */
1873 * SPX timer processing.
1875 static struct spxpcb *
1876 spx_timers(cb, timer)
1877 register struct spxpcb *cb;
1883 IPX_LIST_LOCK_ASSERT();
1884 IPX_LOCK_ASSERT(cb->s_ipxpcb);
1886 cb->s_force = 1 + timer;
1890 * 2 MSL timeout in shutdown went off. TCP deletes connection
1894 printf("spx: SPXT_2MSL went off for no reason\n");
1895 cb->s_timer[timer] = 0;
1899 * Retransmission timer went off. Message has not
1900 * been acked within retransmit interval. Back off
1901 * to a longer retransmit interval and retransmit one packet.
1904 if (++cb->s_rxtshift > SPX_MAXRXTSHIFT) {
1905 cb->s_rxtshift = SPX_MAXRXTSHIFT;
1906 spxstat.spxs_timeoutdrop++;
1907 spx_drop(cb, ETIMEDOUT);
1911 spxstat.spxs_rexmttimeo++;
1912 rexmt = ((cb->s_srtt >> 2) + cb->s_rttvar) >> 1;
1913 rexmt *= spx_backoff[cb->s_rxtshift];
1914 SPXT_RANGESET(cb->s_rxtcur, rexmt, SPXTV_MIN, SPXTV_REXMTMAX);
1915 cb->s_timer[SPXT_REXMT] = cb->s_rxtcur;
1917 * If we have backed off fairly far, our srtt
1918 * estimate is probably bogus. Clobber it
1919 * so we'll take the next rtt measurement as our srtt;
1920 * move the current srtt into rttvar to keep the current
1921 * retransmit times until then.
1923 if (cb->s_rxtshift > SPX_MAXRXTSHIFT / 4 ) {
1924 cb->s_rttvar += (cb->s_srtt >> 2);
1927 cb->s_snxt = cb->s_rack;
1929 * If timing a packet, stop the timer.
1933 * See very long discussion in tcp_timer.c about congestion
1934 * window and sstrhesh
1936 win = min(cb->s_swnd, (cb->s_cwnd/CUNIT)) / 2;
1940 cb->s_ssthresh = win * CUNIT;
1941 spx_output(cb, NULL);
1945 * Persistance timer into zero window.
1946 * Force a probe to be sent.
1949 spxstat.spxs_persisttimeo++;
1951 spx_output(cb, NULL);
1955 * Keep-alive timer went off; send something
1956 * or drop connection if idle for too long.
1959 spxstat.spxs_keeptimeo++;
1960 if (cb->s_state < TCPS_ESTABLISHED)
1962 if (cb->s_ipxpcb->ipxp_socket->so_options & SO_KEEPALIVE) {
1963 if (cb->s_idle >= SPXTV_MAXIDLE)
1965 spxstat.spxs_keepprobe++;
1966 spx_output(cb, NULL);
1969 cb->s_timer[SPXT_KEEP] = SPXTV_KEEP;
1972 spxstat.spxs_keepdrops++;
1973 spx_drop(cb, ETIMEDOUT);