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