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