tcp_output.c revision 1.20.2.1 1 /* $NetBSD: tcp_output.c,v 1.20.2.1 1997/11/08 06:31:31 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1982, 1986, 1988, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
22 *
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
33 * SUCH DAMAGE.
34 *
35 * @(#)tcp_output.c 8.3 (Berkeley) 12/30/93
36 */
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/malloc.h>
41 #include <sys/mbuf.h>
42 #include <sys/protosw.h>
43 #include <sys/socket.h>
44 #include <sys/socketvar.h>
45 #include <sys/errno.h>
46
47 #include <net/if.h>
48 #include <net/route.h>
49
50 #include <netinet/in.h>
51 #include <netinet/in_systm.h>
52 #include <netinet/ip.h>
53 #include <netinet/in_pcb.h>
54 #include <netinet/ip_var.h>
55 #include <netinet/tcp.h>
56 #define TCPOUTFLAGS
57 #include <netinet/tcp_fsm.h>
58 #include <netinet/tcp_seq.h>
59 #include <netinet/tcp_timer.h>
60 #include <netinet/tcp_var.h>
61 #include <netinet/tcpip.h>
62 #include <netinet/tcp_debug.h>
63
64 #ifdef TUBA
65 #include <netiso/iso.h>
66 #include <netiso/tuba_table.h>
67 #endif
68
69 #ifdef notyet
70 extern struct mbuf *m_copypack();
71 #endif
72
73 #define MAX_TCPOPTLEN 32 /* max # bytes that go in options */
74
75 static __inline void tcp_segsize __P((struct tcpcb *, int *, int *));
76 static __inline void
77 tcp_segsize(tp, txsegsizep, rxsegsizep)
78 struct tcpcb *tp;
79 int *txsegsizep, *rxsegsizep;
80 {
81 struct inpcb *inp = tp->t_inpcb;
82 struct rtentry *rt;
83 struct ifnet *ifp;
84 int size;
85
86 if ((rt = in_pcbrtentry(inp)) == NULL) {
87 size = tcp_mssdflt;
88 goto out;
89 }
90
91 ifp = rt->rt_ifp;
92
93 if (rt->rt_rmx.rmx_mtu != 0)
94 size = rt->rt_rmx.rmx_mtu - sizeof(struct tcpiphdr);
95 else if (ip_mtudisc || in_localaddr(inp->inp_faddr) ||
96 ifp->if_flags & IFF_LOOPBACK)
97 size = ifp->if_mtu - sizeof(struct tcpiphdr);
98 else
99 size = tcp_mssdflt;
100
101 out:
102 *txsegsizep = min(tp->t_peermss, size);
103 *rxsegsizep = min(tp->t_ourmss, size);
104
105 if (*txsegsizep != tp->t_segsz) {
106 tp->snd_cwnd = (tp->snd_cwnd / tp->t_segsz) * *txsegsizep;
107 tp->snd_ssthresh = (tp->snd_ssthresh / tp->t_segsz) *
108 *txsegsizep;
109 tp->t_segsz = *txsegsizep;
110 }
111 }
112
113 /*
114 * Tcp output routine: figure out what should be sent and send it.
115 */
116 int
117 tcp_output(tp)
118 register struct tcpcb *tp;
119 {
120 register struct socket *so = tp->t_inpcb->inp_socket;
121 register long len, win;
122 int off, flags, error;
123 register struct mbuf *m;
124 register struct tcpiphdr *ti;
125 u_char opt[MAX_TCPOPTLEN];
126 unsigned optlen, hdrlen;
127 int idle, sendalot, txsegsize, rxsegsize;
128
129 tcp_segsize(tp, &txsegsize, &rxsegsize);
130
131 /*
132 * Determine length of data that should be transmitted,
133 * and flags that will be used.
134 * If there is some data or critical controls (SYN, RST)
135 * to send, then transmit; otherwise, investigate further.
136 */
137 idle = (tp->snd_max == tp->snd_una);
138 if (idle && tp->t_idle >= tp->t_rxtcur)
139 /*
140 * We have been idle for "a while" and no acks are
141 * expected to clock out any data we send --
142 * slow start to get ack "clock" running again.
143 */
144 tp->snd_cwnd = txsegsize;
145 again:
146 sendalot = 0;
147 off = tp->snd_nxt - tp->snd_una;
148 win = min(tp->snd_wnd, tp->snd_cwnd);
149
150 flags = tcp_outflags[tp->t_state];
151 /*
152 * If in persist timeout with window of 0, send 1 byte.
153 * Otherwise, if window is small but nonzero
154 * and timer expired, we will send what we can
155 * and go to transmit state.
156 */
157 if (tp->t_force) {
158 if (win == 0) {
159 /*
160 * If we still have some data to send, then
161 * clear the FIN bit. Usually this would
162 * happen below when it realizes that we
163 * aren't sending all the data. However,
164 * if we have exactly 1 byte of unset data,
165 * then it won't clear the FIN bit below,
166 * and if we are in persist state, we wind
167 * up sending the packet without recording
168 * that we sent the FIN bit.
169 *
170 * We can't just blindly clear the FIN bit,
171 * because if we don't have any more data
172 * to send then the probe will be the FIN
173 * itself.
174 */
175 if (off < so->so_snd.sb_cc)
176 flags &= ~TH_FIN;
177 win = 1;
178 } else {
179 tp->t_timer[TCPT_PERSIST] = 0;
180 tp->t_rxtshift = 0;
181 }
182 }
183
184 if (win < so->so_snd.sb_cc) {
185 len = win - off;
186 flags &= ~TH_FIN;
187 } else
188 len = so->so_snd.sb_cc - off;
189
190 if (len < 0) {
191 /*
192 * If FIN has been sent but not acked,
193 * but we haven't been called to retransmit,
194 * len will be -1. Otherwise, window shrank
195 * after we sent into it. If window shrank to 0,
196 * cancel pending retransmit and pull snd_nxt
197 * back to (closed) window. We will enter persist
198 * state below. If the window didn't close completely,
199 * just wait for an ACK.
200 */
201 len = 0;
202 if (win == 0) {
203 tp->t_timer[TCPT_REXMT] = 0;
204 tp->snd_nxt = tp->snd_una;
205 }
206 }
207 if (len > txsegsize) {
208 len = txsegsize;
209 flags &= ~TH_FIN;
210 sendalot = 1;
211 }
212
213 win = sbspace(&so->so_rcv);
214
215 /*
216 * Sender silly window avoidance. If connection is idle
217 * and can send all data, a maximum segment,
218 * at least a maximum default-size segment do it,
219 * or are forced, do it; otherwise don't bother.
220 * If peer's buffer is tiny, then send
221 * when window is at least half open.
222 * If retransmitting (possibly after persist timer forced us
223 * to send into a small window), then must resend.
224 */
225 if (len) {
226 if (len == txsegsize)
227 goto send;
228 if ((idle || tp->t_flags & TF_NODELAY) &&
229 len + off >= so->so_snd.sb_cc)
230 goto send;
231 if (tp->t_force)
232 goto send;
233 if (len >= tp->max_sndwnd / 2)
234 goto send;
235 if (SEQ_LT(tp->snd_nxt, tp->snd_max))
236 goto send;
237 }
238
239 /*
240 * Compare available window to amount of window known to peer
241 * (as advertised window less next expected input). If the
242 * difference is at least twice the size of the largest segment
243 * we expect to receive (i.e. two segments) or at least 50% of
244 * the maximum possible window, then want to send a window update
245 * to peer.
246 */
247 if (win > 0) {
248 /*
249 * "adv" is the amount we can increase the window,
250 * taking into account that we are limited by
251 * TCP_MAXWIN << tp->rcv_scale.
252 */
253 long adv = min(win, (long)TCP_MAXWIN << tp->rcv_scale) -
254 (tp->rcv_adv - tp->rcv_nxt);
255
256 if (adv >= (long) (2 * rxsegsize))
257 goto send;
258 if (2 * adv >= (long) so->so_rcv.sb_hiwat)
259 goto send;
260 }
261
262 /*
263 * Send if we owe peer an ACK.
264 */
265 if (tp->t_flags & TF_ACKNOW)
266 goto send;
267 if (flags & (TH_SYN|TH_RST))
268 goto send;
269 if (SEQ_GT(tp->snd_up, tp->snd_una))
270 goto send;
271 /*
272 * If our state indicates that FIN should be sent
273 * and we have not yet done so, or we're retransmitting the FIN,
274 * then we need to send.
275 */
276 if (flags & TH_FIN &&
277 ((tp->t_flags & TF_SENTFIN) == 0 || tp->snd_nxt == tp->snd_una))
278 goto send;
279
280 /*
281 * TCP window updates are not reliable, rather a polling protocol
282 * using ``persist'' packets is used to insure receipt of window
283 * updates. The three ``states'' for the output side are:
284 * idle not doing retransmits or persists
285 * persisting to move a small or zero window
286 * (re)transmitting and thereby not persisting
287 *
288 * tp->t_timer[TCPT_PERSIST]
289 * is set when we are in persist state.
290 * tp->t_force
291 * is set when we are called to send a persist packet.
292 * tp->t_timer[TCPT_REXMT]
293 * is set when we are retransmitting
294 * The output side is idle when both timers are zero.
295 *
296 * If send window is too small, there is data to transmit, and no
297 * retransmit or persist is pending, then go to persist state.
298 * If nothing happens soon, send when timer expires:
299 * if window is nonzero, transmit what we can,
300 * otherwise force out a byte.
301 */
302 if (so->so_snd.sb_cc && tp->t_timer[TCPT_REXMT] == 0 &&
303 tp->t_timer[TCPT_PERSIST] == 0) {
304 tp->t_rxtshift = 0;
305 tcp_setpersist(tp);
306 }
307
308 /*
309 * No reason to send a segment, just return.
310 */
311 return (0);
312
313 send:
314 /*
315 * Before ESTABLISHED, force sending of initial options
316 * unless TCP set not to do any options.
317 * NOTE: we assume that the IP/TCP header plus TCP options
318 * always fit in a single mbuf, leaving room for a maximum
319 * link header, i.e.
320 * max_linkhdr + sizeof (struct tcpiphdr) + optlen <= MHLEN
321 */
322 optlen = 0;
323 hdrlen = sizeof (struct tcpiphdr);
324 if (flags & TH_SYN) {
325 tp->snd_nxt = tp->iss;
326 tp->t_ourmss = tcp_mss_to_advertise(tp);
327 if ((tp->t_flags & TF_NOOPT) == 0) {
328 opt[0] = TCPOPT_MAXSEG;
329 opt[1] = 4;
330 opt[2] = (tp->t_ourmss >> 8) & 0xff;
331 opt[3] = tp->t_ourmss & 0xff;
332 optlen = 4;
333
334 if ((tp->t_flags & TF_REQ_SCALE) &&
335 ((flags & TH_ACK) == 0 ||
336 (tp->t_flags & TF_RCVD_SCALE))) {
337 *((u_int32_t *) (opt + optlen)) = htonl(
338 TCPOPT_NOP << 24 |
339 TCPOPT_WINDOW << 16 |
340 TCPOLEN_WINDOW << 8 |
341 tp->request_r_scale);
342 optlen += 4;
343 }
344 }
345 }
346
347 /*
348 * Send a timestamp and echo-reply if this is a SYN and our side
349 * wants to use timestamps (TF_REQ_TSTMP is set) or both our side
350 * and our peer have sent timestamps in our SYN's.
351 */
352 if ((tp->t_flags & (TF_REQ_TSTMP|TF_NOOPT)) == TF_REQ_TSTMP &&
353 (flags & TH_RST) == 0 &&
354 ((flags & (TH_SYN|TH_ACK)) == TH_SYN ||
355 (tp->t_flags & TF_RCVD_TSTMP))) {
356 u_int32_t *lp = (u_int32_t *)(opt + optlen);
357
358 /* Form timestamp option as shown in appendix A of RFC 1323. */
359 *lp++ = htonl(TCPOPT_TSTAMP_HDR);
360 *lp++ = htonl(tcp_now);
361 *lp = htonl(tp->ts_recent);
362 optlen += TCPOLEN_TSTAMP_APPA;
363 }
364
365 hdrlen += optlen;
366
367 /*
368 * Adjust data length if insertion of options will
369 * bump the packet length beyond the txsegsize length.
370 */
371 if (len > txsegsize - optlen) {
372 len = txsegsize - optlen;
373 flags &= ~TH_FIN;
374 sendalot = 1;
375 }
376
377 #ifdef DIAGNOSTIC
378 if (max_linkhdr + hdrlen > MHLEN)
379 panic("tcphdr too big");
380 #endif
381
382 /*
383 * Grab a header mbuf, attaching a copy of data to
384 * be transmitted, and initialize the header from
385 * the template for sends on this connection.
386 */
387 if (len) {
388 if (tp->t_force && len == 1)
389 tcpstat.tcps_sndprobe++;
390 else if (SEQ_LT(tp->snd_nxt, tp->snd_max)) {
391 tcpstat.tcps_sndrexmitpack++;
392 tcpstat.tcps_sndrexmitbyte += len;
393 } else {
394 tcpstat.tcps_sndpack++;
395 tcpstat.tcps_sndbyte += len;
396 }
397 #ifdef notyet
398 if ((m = m_copypack(so->so_snd.sb_mb, off,
399 (int)len, max_linkhdr + hdrlen)) == 0) {
400 error = ENOBUFS;
401 goto out;
402 }
403 /*
404 * m_copypack left space for our hdr; use it.
405 */
406 m->m_len += hdrlen;
407 m->m_data -= hdrlen;
408 #else
409 MGETHDR(m, M_DONTWAIT, MT_HEADER);
410 if (m == NULL) {
411 error = ENOBUFS;
412 goto out;
413 }
414 m->m_data += max_linkhdr;
415 m->m_len = hdrlen;
416 if (len <= MHLEN - hdrlen - max_linkhdr) {
417 m_copydata(so->so_snd.sb_mb, off, (int) len,
418 mtod(m, caddr_t) + hdrlen);
419 m->m_len += len;
420 } else {
421 m->m_next = m_copy(so->so_snd.sb_mb, off, (int) len);
422 if (m->m_next == 0)
423 len = 0;
424 }
425 #endif
426 /*
427 * If we're sending everything we've got, set PUSH.
428 * (This will keep happy those implementations which only
429 * give data to the user when a buffer fills or
430 * a PUSH comes in.)
431 */
432 if (off + len == so->so_snd.sb_cc)
433 flags |= TH_PUSH;
434 } else {
435 if (tp->t_flags & TF_ACKNOW)
436 tcpstat.tcps_sndacks++;
437 else if (flags & (TH_SYN|TH_FIN|TH_RST))
438 tcpstat.tcps_sndctrl++;
439 else if (SEQ_GT(tp->snd_up, tp->snd_una))
440 tcpstat.tcps_sndurg++;
441 else
442 tcpstat.tcps_sndwinup++;
443
444 MGETHDR(m, M_DONTWAIT, MT_HEADER);
445 if (m == NULL) {
446 error = ENOBUFS;
447 goto out;
448 }
449 m->m_data += max_linkhdr;
450 m->m_len = hdrlen;
451 }
452 m->m_pkthdr.rcvif = (struct ifnet *)0;
453 ti = mtod(m, struct tcpiphdr *);
454 if (tp->t_template == 0)
455 panic("tcp_output");
456 bcopy((caddr_t)tp->t_template, (caddr_t)ti, sizeof (struct tcpiphdr));
457
458 /*
459 * Fill in fields, remembering maximum advertised
460 * window for use in delaying messages about window sizes.
461 * If resending a FIN, be sure not to use a new sequence number.
462 */
463 if (flags & TH_FIN && tp->t_flags & TF_SENTFIN &&
464 tp->snd_nxt == tp->snd_max)
465 tp->snd_nxt--;
466 /*
467 * If we are doing retransmissions, then snd_nxt will
468 * not reflect the first unsent octet. For ACK only
469 * packets, we do not want the sequence number of the
470 * retransmitted packet, we want the sequence number
471 * of the next unsent octet. So, if there is no data
472 * (and no SYN or FIN), use snd_max instead of snd_nxt
473 * when filling in ti_seq. But if we are in persist
474 * state, snd_max might reflect one byte beyond the
475 * right edge of the window, so use snd_nxt in that
476 * case, since we know we aren't doing a retransmission.
477 * (retransmit and persist are mutually exclusive...)
478 */
479 if (len || (flags & (TH_SYN|TH_FIN)) || tp->t_timer[TCPT_PERSIST])
480 ti->ti_seq = htonl(tp->snd_nxt);
481 else
482 ti->ti_seq = htonl(tp->snd_max);
483 ti->ti_ack = htonl(tp->rcv_nxt);
484 if (optlen) {
485 bcopy((caddr_t)opt, (caddr_t)(ti + 1), optlen);
486 ti->ti_off = (sizeof (struct tcphdr) + optlen) >> 2;
487 }
488 ti->ti_flags = flags;
489 /*
490 * Calculate receive window. Don't shrink window,
491 * but avoid silly window syndrome.
492 */
493 if (win < (long)(so->so_rcv.sb_hiwat / 4) && win < (long)rxsegsize)
494 win = 0;
495 if (win > (long)TCP_MAXWIN << tp->rcv_scale)
496 win = (long)TCP_MAXWIN << tp->rcv_scale;
497 if (win < (long)(tp->rcv_adv - tp->rcv_nxt))
498 win = (long)(tp->rcv_adv - tp->rcv_nxt);
499 ti->ti_win = htons((u_int16_t) (win>>tp->rcv_scale));
500 if (SEQ_GT(tp->snd_up, tp->snd_nxt)) {
501 u_int32_t urp = tp->snd_up - tp->snd_nxt;
502 if (urp > IP_MAXPACKET)
503 urp = IP_MAXPACKET;
504 ti->ti_urp = htons((u_int16_t)urp);
505 ti->ti_flags |= TH_URG;
506 } else
507 /*
508 * If no urgent pointer to send, then we pull
509 * the urgent pointer to the left edge of the send window
510 * so that it doesn't drift into the send window on sequence
511 * number wraparound.
512 */
513 tp->snd_up = tp->snd_una; /* drag it along */
514
515 /*
516 * Put TCP length in extended header, and then
517 * checksum extended header and data.
518 */
519 if (len + optlen)
520 ti->ti_len = htons((u_int16_t)(sizeof (struct tcphdr) +
521 optlen + len));
522 ti->ti_sum = in_cksum(m, (int)(hdrlen + len));
523
524 /*
525 * In transmit state, time the transmission and arrange for
526 * the retransmit. In persist state, just set snd_max.
527 */
528 if (tp->t_force == 0 || tp->t_timer[TCPT_PERSIST] == 0) {
529 tcp_seq startseq = tp->snd_nxt;
530
531 /*
532 * Advance snd_nxt over sequence space of this segment.
533 */
534 if (flags & (TH_SYN|TH_FIN)) {
535 if (flags & TH_SYN)
536 tp->snd_nxt++;
537 if (flags & TH_FIN) {
538 tp->snd_nxt++;
539 tp->t_flags |= TF_SENTFIN;
540 }
541 }
542 tp->snd_nxt += len;
543 if (SEQ_GT(tp->snd_nxt, tp->snd_max)) {
544 tp->snd_max = tp->snd_nxt;
545 /*
546 * Time this transmission if not a retransmission and
547 * not currently timing anything.
548 */
549 if (tp->t_rtt == 0) {
550 tp->t_rtt = 1;
551 tp->t_rtseq = startseq;
552 tcpstat.tcps_segstimed++;
553 }
554 }
555
556 /*
557 * Set retransmit timer if not currently set,
558 * and not doing an ack or a keep-alive probe.
559 * Initial value for retransmit timer is smoothed
560 * round-trip time + 2 * round-trip time variance.
561 * Initialize shift counter which is used for backoff
562 * of retransmit time.
563 */
564 if (tp->t_timer[TCPT_REXMT] == 0 &&
565 tp->snd_nxt != tp->snd_una) {
566 tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
567 if (tp->t_timer[TCPT_PERSIST]) {
568 tp->t_timer[TCPT_PERSIST] = 0;
569 tp->t_rxtshift = 0;
570 }
571 }
572 } else
573 if (SEQ_GT(tp->snd_nxt + len, tp->snd_max))
574 tp->snd_max = tp->snd_nxt + len;
575
576 /*
577 * Trace.
578 */
579 if (so->so_options & SO_DEBUG)
580 tcp_trace(TA_OUTPUT, tp->t_state, tp, ti, 0);
581
582 /*
583 * Fill in IP length and desired time to live and
584 * send to IP level. There should be a better way
585 * to handle ttl and tos; we could keep them in
586 * the template, but need a way to checksum without them.
587 */
588 m->m_pkthdr.len = hdrlen + len;
589 #ifdef TUBA
590 if (tp->t_tuba_pcb)
591 error = tuba_output(m, tp);
592 else
593 #endif
594 {
595 struct rtentry *rt;
596
597 ((struct ip *)ti)->ip_len = m->m_pkthdr.len;
598 ((struct ip *)ti)->ip_ttl = tp->t_inpcb->inp_ip.ip_ttl; /* XXX */
599 ((struct ip *)ti)->ip_tos = tp->t_inpcb->inp_ip.ip_tos; /* XXX */
600
601 if (ip_mtudisc && (rt = in_pcbrtentry(tp->t_inpcb)) != 0 &&
602 (rt->rt_rmx.rmx_locks & RTV_MTU) == 0)
603 ((struct ip *)ti)->ip_off |= IP_DF;
604
605 #if BSD >= 43
606 error = ip_output(m, tp->t_inpcb->inp_options, &tp->t_inpcb->inp_route,
607 so->so_options & SO_DONTROUTE, 0);
608 #else
609 error = ip_output(m, (struct mbuf *)0, &tp->t_inpcb->inp_route,
610 so->so_options & SO_DONTROUTE);
611 #endif
612 }
613 if (error) {
614 out:
615 if (error == ENOBUFS) {
616 tcp_quench(tp->t_inpcb, 0);
617 return (0);
618 }
619 if ((error == EHOSTUNREACH || error == ENETDOWN)
620 && TCPS_HAVERCVDSYN(tp->t_state)) {
621 tp->t_softerror = error;
622 return (0);
623 }
624 return (error);
625 }
626 tcpstat.tcps_sndtotal++;
627
628 /*
629 * Data sent (as far as we can tell).
630 * If this advertises a larger window than any other segment,
631 * then remember the size of the advertised window.
632 * Any pending ACK has now been sent.
633 */
634 if (win > 0 && SEQ_GT(tp->rcv_nxt+win, tp->rcv_adv))
635 tp->rcv_adv = tp->rcv_nxt + win;
636 tp->last_ack_sent = tp->rcv_nxt;
637 tp->t_flags &= ~(TF_ACKNOW|TF_DELACK);
638 if (sendalot)
639 goto again;
640 return (0);
641 }
642
643 void
644 tcp_setpersist(tp)
645 register struct tcpcb *tp;
646 {
647 register t = ((tp->t_srtt >> 2) + tp->t_rttvar) >> (1 + 2);
648
649 if (tp->t_timer[TCPT_REXMT])
650 panic("tcp_output REXMT");
651 /*
652 * Start/restart persistance timer.
653 */
654 TCPT_RANGESET(tp->t_timer[TCPT_PERSIST],
655 t * tcp_backoff[tp->t_rxtshift],
656 TCPTV_PERSMIN, TCPTV_PERSMAX);
657 if (tp->t_rxtshift < TCP_MAXRXTSHIFT)
658 tp->t_rxtshift++;
659 }
660