tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / workbench / network / stacks / AROSTCP / bsdsocket / netinet / tcp_output.c
blobd1036e082cf7316655bfa4f56428e8cafa6f81b6
1 /*
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 2006 Pavel Fedin
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by the University of
17 * California, Berkeley and its contributors.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
34 * @(#)tcp_output.c 8.3 (Berkeley) 12/30/93
35 * $Id$
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/malloc.h>
41 #include <sys/mbuf.h>
42 #include <sys/socket.h>
43 #include <sys/socketvar.h>
44 #include <sys/protosw.h>
45 #include <sys/errno.h>
46 #include <sys/queue.h>
47 #include <sys/synch.h>
49 #include <net/route.h>
51 #include <netinet/in.h>
52 #include <netinet/in_systm.h>
53 #include <netinet/ip.h>
54 #include <netinet/in_pcb.h>
55 #include <netinet/ip_var.h>
56 #include <netinet/tcp.h>
57 #define TCPOUTFLAGS
58 #include <netinet/tcp_fsm.h>
59 #include <netinet/tcp_seq.h>
60 #include <netinet/tcp_timer.h>
61 #include <netinet/tcp_var.h>
62 #include <netinet/tcpip.h>
63 #ifdef TCPDEBUG
64 #include <netinet/tcp_debug.h>
65 #endif
67 #ifdef notyet
68 extern struct mbuf *m_copypack();
69 #endif
73 * Tcp output routine: figure out what should be sent and send it.
75 int
76 tcp_output(tp)
77 register struct tcpcb *tp;
79 register struct socket *so = tp->t_inpcb->inp_socket;
80 register long len, win;
81 int off, flags, error;
82 register struct mbuf *m;
83 register struct tcpiphdr *ti;
84 u_char opt[TCP_MAXOLEN];
85 unsigned optlen, hdrlen;
86 int idle, sendalot;
87 struct rmxp_tao *taop;
88 struct rmxp_tao tao_noncached;
91 * Determine length of data that should be transmitted,
92 * and flags that will be used.
93 * If there is some data or critical controls (SYN, RST)
94 * to send, then transmit; otherwise, investigate further.
96 idle = (tp->snd_max == tp->snd_una);
97 if (idle && tp->t_idle >= tp->t_rxtcur)
99 * We have been idle for "a while" and no acks are
100 * expected to clock out any data we send --
101 * slow start to get ack "clock" running again.
103 tp->snd_cwnd = tp->t_maxseg;
104 again:
105 sendalot = 0;
106 off = tp->snd_nxt - tp->snd_una;
107 win = MIN(tp->snd_wnd, tp->snd_cwnd);
109 flags = tcp_outflags[tp->t_state];
111 * Get standard flags, and add SYN or FIN if requested by 'hidden'
112 * state flags.
114 if (tp->t_flags & TF_NEEDFIN)
115 flags |= TH_FIN;
116 if (tp->t_flags & TF_NEEDSYN)
117 flags |= TH_SYN;
120 * If in persist timeout with window of 0, send 1 byte.
121 * Otherwise, if window is small but nonzero
122 * and timer expired, we will send what we can
123 * and go to transmit state.
125 if (tp->t_force) {
126 if (win == 0) {
128 * If we still have some data to send, then
129 * clear the FIN bit. Usually this would
130 * happen below when it realizes that we
131 * aren't sending all the data. However,
132 * if we have exactly 1 byte of unset data,
133 * then it won't clear the FIN bit below,
134 * and if we are in persist state, we wind
135 * up sending the packet without recording
136 * that we sent the FIN bit.
138 * We can't just blindly clear the FIN bit,
139 * because if we don't have any more data
140 * to send then the probe will be the FIN
141 * itself.
143 if (off < so->so_snd.sb_cc)
144 flags &= ~TH_FIN;
145 win = 1;
146 } else {
147 tp->t_timer[TCPT_PERSIST] = 0;
148 tp->t_rxtshift = 0;
152 len = MIN(so->so_snd.sb_cc, win) - off;
154 if ((taop = tcp_gettaocache(tp->t_inpcb)) == NULL) {
155 taop = &tao_noncached;
156 bzero(taop, sizeof(*taop));
160 * Lop off SYN bit if it has already been sent. However, if this
161 * is SYN-SENT state and if segment contains data and if we don't
162 * know that foreign host supports TAO, suppress sending segment.
164 if ((flags & TH_SYN) && SEQ_GT(tp->snd_nxt, tp->snd_una)) {
165 flags &= ~TH_SYN;
166 off--, len++;
167 if (len > 0 && tp->t_state == TCPS_SYN_SENT &&
168 taop->tao_ccsent == 0)
169 return 0;
172 if (len < 0) {
174 * If FIN has been sent but not acked,
175 * but we haven't been called to retransmit,
176 * len will be -1. Otherwise, window shrank
177 * after we sent into it. If window shrank to 0,
178 * cancel pending retransmit and pull snd_nxt
179 * back to (closed) window. We will enter persist
180 * state below. If the window didn't close completely,
181 * just wait for an ACK.
183 len = 0;
184 if (win == 0) {
185 tp->t_timer[TCPT_REXMT] = 0;
186 tp->snd_nxt = tp->snd_una;
189 if (len > tp->t_maxseg) {
190 len = tp->t_maxseg;
191 sendalot = 1;
193 if (SEQ_LT(tp->snd_nxt + len, tp->snd_una + so->so_snd.sb_cc))
194 flags &= ~TH_FIN;
196 win = sbspace(&so->so_rcv);
199 * Sender silly window avoidance. If connection is idle
200 * and can send all data, a maximum segment,
201 * at least a maximum default-size segment do it,
202 * or are forced, do it; otherwise don't bother.
203 * If peer's buffer is tiny, then send
204 * when window is at least half open.
205 * If retransmitting (possibly after persist timer forced us
206 * to send into a small window), then must resend.
208 if (len) {
209 if (len == tp->t_maxseg)
210 goto send;
211 if ((idle || tp->t_flags & TF_NODELAY) &&
212 (tp->t_flags & TF_NOPUSH) == 0 &&
213 len + off >= so->so_snd.sb_cc)
214 goto send;
215 if (tp->t_force)
216 goto send;
217 if (len >= tp->max_sndwnd / 2 && tp->max_sndwnd > 0)
218 goto send;
219 if (SEQ_LT(tp->snd_nxt, tp->snd_max))
220 goto send;
224 * Compare available window to amount of window
225 * known to peer (as advertised window less
226 * next expected input). If the difference is at least two
227 * max size segments, or at least 50% of the maximum possible
228 * window, then want to send a window update to peer.
230 if (win > 0) {
232 * "adv" is the amount we can increase the window,
233 * taking into account that we are limited by
234 * TCP_MAXWIN << tp->rcv_scale.
236 long adv = MIN(win, (long)TCP_MAXWIN << tp->rcv_scale) -
237 (tp->rcv_adv - tp->rcv_nxt);
239 if (adv >= (long) (2 * tp->t_maxseg))
240 goto send;
241 if (2 * adv >= (long) so->so_rcv.sb_hiwat)
242 goto send;
246 * Send if we owe peer an ACK.
248 if (tp->t_flags & TF_ACKNOW)
249 goto send;
250 if ((flags & TH_RST) ||
251 ((flags & TH_SYN) && (tp->t_flags & TF_NEEDSYN) == 0))
252 goto send;
253 if (SEQ_GT(tp->snd_up, tp->snd_una))
254 goto send;
256 * If our state indicates that FIN should be sent
257 * and we have not yet done so, or we're retransmitting the FIN,
258 * then we need to send.
260 if (flags & TH_FIN &&
261 ((tp->t_flags & TF_SENTFIN) == 0 || tp->snd_nxt == tp->snd_una))
262 goto send;
265 * TCP window updates are not reliable, rather a polling protocol
266 * using ``persist'' packets is used to insure receipt of window
267 * updates. The three ``states'' for the output side are:
268 * idle not doing retransmits or persists
269 * persisting to move a small or zero window
270 * (re)transmitting and thereby not persisting
272 * tp->t_timer[TCPT_PERSIST]
273 * is set when we are in persist state.
274 * tp->t_force
275 * is set when we are called to send a persist packet.
276 * tp->t_timer[TCPT_REXMT]
277 * is set when we are retransmitting
278 * The output side is idle when both timers are zero.
280 * If send window is too small, there is data to transmit, and no
281 * retransmit or persist is pending, then go to persist state.
282 * If nothing happens soon, send when timer expires:
283 * if window is nonzero, transmit what we can,
284 * otherwise force out a byte.
286 if (so->so_snd.sb_cc && tp->t_timer[TCPT_REXMT] == 0 &&
287 tp->t_timer[TCPT_PERSIST] == 0) {
288 tp->t_rxtshift = 0;
289 tcp_setpersist(tp);
293 * No reason to send a segment, just return.
295 return (0);
297 send:
299 * Before ESTABLISHED, force sending of initial options
300 * unless TCP set not to do any options.
301 * NOTE: we assume that the IP/TCP header plus TCP options
302 * always fit in a single mbuf, leaving room for a maximum
303 * link header, i.e.
304 * max_linkhdr + sizeof (struct tcpiphdr) + optlen <= MHLEN
306 optlen = 0;
307 hdrlen = sizeof (struct tcpiphdr);
308 if (flags & TH_SYN) {
309 tp->snd_nxt = tp->iss;
310 if ((tp->t_flags & TF_NOOPT) == 0) {
311 u_short mss;
313 opt[0] = TCPOPT_MAXSEG;
314 opt[1] = TCPOLEN_MAXSEG;
315 mss = htons((u_short) tcp_mssopt(tp));
316 (void)memcpy(opt + 2, &mss, sizeof(mss));
317 optlen = TCPOLEN_MAXSEG;
319 if ((tp->t_flags & TF_REQ_SCALE) &&
320 ((flags & TH_ACK) == 0 ||
321 (tp->t_flags & TF_RCVD_SCALE))) {
322 *((u_long *) (opt + optlen)) = htonl(
323 TCPOPT_NOP << 24 |
324 TCPOPT_WINDOW << 16 |
325 TCPOLEN_WINDOW << 8 |
326 tp->request_r_scale);
327 optlen += 4;
333 * Send a timestamp and echo-reply if this is a SYN and our side
334 * wants to use timestamps (TF_REQ_TSTMP is set) or both our side
335 * and our peer have sent timestamps in our SYN's.
337 if ((tp->t_flags & (TF_REQ_TSTMP|TF_NOOPT)) == TF_REQ_TSTMP &&
338 (flags & TH_RST) == 0 &&
339 ((flags & TH_ACK) == 0 ||
340 (tp->t_flags & TF_RCVD_TSTMP))) {
341 u_long *lp = (u_long *)(opt + optlen);
343 /* Form timestamp option as shown in appendix A of RFC 1323. */
344 *lp++ = htonl(TCPOPT_TSTAMP_HDR);
345 *lp++ = htonl(tcp_now);
346 *lp = htonl(tp->ts_recent);
347 optlen += TCPOLEN_TSTAMP_APPA;
351 * Send `CC-family' options if our side wants to use them (TF_REQ_CC),
352 * options are allowed (!TF_NOOPT) and it's not a RST.
354 if ((tp->t_flags & (TF_REQ_CC|TF_NOOPT)) == TF_REQ_CC &&
355 (flags & TH_RST) == 0) {
356 switch (flags & (TH_SYN|TH_ACK)) {
358 * This is a normal ACK, send CC if we received CC before
359 * from our peer.
361 case TH_ACK:
362 if (!(tp->t_flags & TF_RCVD_CC))
363 break;
364 /*FALLTHROUGH*/
367 * We can only get here in T/TCP's SYN_SENT* state, when
368 * we're a sending a non-SYN segment without waiting for
369 * the ACK of our SYN. A check above assures that we only
370 * do this if our peer understands T/TCP.
372 case 0:
374 u_int32_t *opt_ptr;
375 opt[optlen++] = TCPOPT_NOP;
376 opt[optlen++] = TCPOPT_NOP;
377 opt[optlen++] = TCPOPT_CC;
378 opt[optlen++] = TCPOLEN_CC;
379 opt_ptr = (u_int32_t *)&opt[optlen];
380 *opt_ptr = htonl(tp->cc_send);
382 optlen += 4;
384 break;
387 * This is our initial SYN, check whether we have to use
388 * CC or CC.new.
390 case TH_SYN:
392 u_int32_t *opt_ptr;
393 opt[optlen++] = TCPOPT_NOP;
394 opt[optlen++] = TCPOPT_NOP;
396 if (taop->tao_ccsent != 0 &&
397 CC_GEQ(tp->cc_send, taop->tao_ccsent)) {
398 opt[optlen++] = TCPOPT_CC;
399 taop->tao_ccsent = tp->cc_send;
400 } else {
401 opt[optlen++] = TCPOPT_CCNEW;
402 taop->tao_ccsent = 0;
404 opt[optlen++] = TCPOLEN_CC;
405 opt_ptr = (u_int32_t *)&opt[optlen];
406 *opt_ptr = htonl(tp->cc_send);
407 optlen += 4;
409 break;
412 * This is a SYN,ACK; send CC and CC.echo if we received
413 * CC from our peer.
415 case (TH_SYN|TH_ACK):
417 u_int32_t *opt_ptr;
418 if (tp->t_flags & TF_RCVD_CC) {
419 opt[optlen++] = TCPOPT_NOP;
420 opt[optlen++] = TCPOPT_NOP;
421 opt[optlen++] = TCPOPT_CC;
422 opt[optlen++] = TCPOLEN_CC;
423 opt_ptr = (u_int32_t *)&opt[optlen];
424 *opt_ptr = htonl(tp->cc_send);
425 optlen += 4;
426 opt[optlen++] = TCPOPT_NOP;
427 opt[optlen++] = TCPOPT_NOP;
428 opt[optlen++] = TCPOPT_CCECHO;
429 opt[optlen++] = TCPOLEN_CC;
430 opt_ptr = (u_int32_t *)&opt[optlen];
431 *opt_ptr = htonl(tp->cc_recv);
432 optlen += 4;
435 break;
439 hdrlen += optlen;
442 * Adjust data length if insertion of options will
443 * bump the packet length beyond the t_maxopd length.
444 * Clear the FIN bit because we cut off the tail of
445 * the segment.
447 if (len + optlen > tp->t_maxopd) {
449 * If there is still more to send, don't close the connection.
451 flags &= ~TH_FIN;
453 len = tp->t_maxopd - optlen;
454 sendalot = 1;
457 /*#ifdef DIAGNOSTIC*/
458 if (max_linkhdr + hdrlen > MHLEN)
459 panic("tcphdr too big");
460 /*#endif*/
463 * Grab a header mbuf, attaching a copy of data to
464 * be transmitted, and initialize the header from
465 * the template for sends on this connection.
467 if (len) {
468 if (tp->t_force && len == 1)
469 tcpstat.tcps_sndprobe++;
470 else if (SEQ_LT(tp->snd_nxt, tp->snd_max)) {
471 tcpstat.tcps_sndrexmitpack++;
472 tcpstat.tcps_sndrexmitbyte += len;
473 } else {
474 tcpstat.tcps_sndpack++;
475 tcpstat.tcps_sndbyte += len;
477 #ifdef notyet
478 if ((m = m_copypack(so->so_snd.sb_mb, off,
479 (int)len, max_linkhdr + hdrlen)) == 0) {
480 error = ENOBUFS;
481 goto out;
484 * m_copypack left space for our hdr; use it.
486 m->m_len += hdrlen;
487 m->m_data -= hdrlen;
488 #else
489 MGETHDR(m, M_DONTWAIT, MT_HEADER);
490 if (m == NULL) {
491 error = ENOBUFS;
492 goto out;
494 m->m_data += max_linkhdr;
495 m->m_len = hdrlen;
496 if (len <= MHLEN - hdrlen - max_linkhdr) {
497 m_copydata(so->so_snd.sb_mb, off, (int) len,
498 mtod(m, caddr_t) + hdrlen);
499 m->m_len += len;
500 } else {
501 m->m_next = m_copy(so->so_snd.sb_mb, off, (int) len);
502 if (m->m_next == 0)
503 len = 0;
505 #endif
507 * If we're sending everything we've got, set PUSH.
508 * (This will keep happy those implementations which only
509 * give data to the user when a buffer fills or
510 * a PUSH comes in.)
512 if (off + len == so->so_snd.sb_cc)
513 flags |= TH_PUSH;
514 } else {
515 if (tp->t_flags & TF_ACKNOW)
516 tcpstat.tcps_sndacks++;
517 else if (flags & (TH_SYN|TH_FIN|TH_RST))
518 tcpstat.tcps_sndctrl++;
519 else if (SEQ_GT(tp->snd_up, tp->snd_una))
520 tcpstat.tcps_sndurg++;
521 else
522 tcpstat.tcps_sndwinup++;
524 MGETHDR(m, M_DONTWAIT, MT_HEADER);
525 if (m == NULL) {
526 error = ENOBUFS;
527 goto out;
529 m->m_data += max_linkhdr;
530 m->m_len = hdrlen;
532 m->m_pkthdr.rcvif = (struct ifnet *)0;
533 ti = mtod(m, struct tcpiphdr *);
534 if (tp->t_template == 0)
535 panic("tcp_output");
536 (void)memcpy(ti, tp->t_template, sizeof (struct tcpiphdr));
539 * Fill in fields, remembering maximum advertised
540 * window for use in delaying messages about window sizes.
541 * If resending a FIN, be sure not to use a new sequence number.
543 if (flags & TH_FIN && tp->t_flags & TF_SENTFIN &&
544 tp->snd_nxt == tp->snd_max)
545 tp->snd_nxt--;
547 * If we are doing retransmissions, then snd_nxt will
548 * not reflect the first unsent octet. For ACK only
549 * packets, we do not want the sequence number of the
550 * retransmitted packet, we want the sequence number
551 * of the next unsent octet. So, if there is no data
552 * (and no SYN or FIN), use snd_max instead of snd_nxt
553 * when filling in ti_seq. But if we are in persist
554 * state, snd_max might reflect one byte beyond the
555 * right edge of the window, so use snd_nxt in that
556 * case, since we know we aren't doing a retransmission.
557 * (retransmit and persist are mutually exclusive...)
559 if (len || (flags & (TH_SYN|TH_FIN)) || tp->t_timer[TCPT_PERSIST])
560 ti->ti_seq = htonl(tp->snd_nxt);
561 else
562 ti->ti_seq = htonl(tp->snd_max);
563 ti->ti_ack = htonl(tp->rcv_nxt);
564 if (optlen) {
565 (void)memcpy(ti + 1, opt, optlen);
566 ti->ti_off = (sizeof (struct tcphdr) + optlen) >> 2;
568 ti->ti_flags = flags;
570 * Calculate receive window. Don't shrink window,
571 * but avoid silly window syndrome.
573 if (win < (long)(so->so_rcv.sb_hiwat / 4) && win < (long)tp->t_maxseg)
574 win = 0;
575 if (win > (long)TCP_MAXWIN << tp->rcv_scale)
576 win = (long)TCP_MAXWIN << tp->rcv_scale;
577 if (win < (long)(tp->rcv_adv - tp->rcv_nxt))
578 win = (long)(tp->rcv_adv - tp->rcv_nxt);
579 ti->ti_win = htons((u_short) (win>>tp->rcv_scale));
580 if (SEQ_GT(tp->snd_up, tp->snd_nxt)) {
581 ti->ti_urp = htons((u_short)(tp->snd_up - tp->snd_nxt));
582 ti->ti_flags |= TH_URG;
583 } else
585 * If no urgent pointer to send, then we pull
586 * the urgent pointer to the left edge of the send window
587 * so that it doesn't drift into the send window on sequence
588 * number wraparound.
590 tp->snd_up = tp->snd_una; /* drag it along */
593 * Put TCP length in extended header, and then
594 * checksum extended header and data.
596 if (len + optlen)
597 ti->ti_len = htons((u_short)(sizeof (struct tcphdr) +
598 optlen + len));
599 ti->ti_sum = in_cksum(m, (int)(hdrlen + len));
602 * In transmit state, time the transmission and arrange for
603 * the retransmit. In persist state, just set snd_max.
605 if (tp->t_force == 0 || tp->t_timer[TCPT_PERSIST] == 0) {
606 tcp_seq startseq = tp->snd_nxt;
609 * Advance snd_nxt over sequence space of this segment.
611 if (flags & (TH_SYN|TH_FIN)) {
612 if (flags & TH_SYN)
613 tp->snd_nxt++;
614 if (flags & TH_FIN) {
615 tp->snd_nxt++;
616 tp->t_flags |= TF_SENTFIN;
619 tp->snd_nxt += len;
620 if (SEQ_GT(tp->snd_nxt, tp->snd_max)) {
621 tp->snd_max = tp->snd_nxt;
623 * Time this transmission if not a retransmission and
624 * not currently timing anything.
626 if (tp->t_rtt == 0) {
627 tp->t_rtt = 1;
628 tp->t_rtseq = startseq;
629 tcpstat.tcps_segstimed++;
634 * Set retransmit timer if not currently set,
635 * and not doing an ack or a keep-alive probe.
636 * Initial value for retransmit timer is smoothed
637 * round-trip time + 2 * round-trip time variance.
638 * Initialize shift counter which is used for backoff
639 * of retransmit time.
641 if (tp->t_timer[TCPT_REXMT] == 0 &&
642 tp->snd_nxt != tp->snd_una) {
643 tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
644 if (tp->t_timer[TCPT_PERSIST]) {
645 tp->t_timer[TCPT_PERSIST] = 0;
646 tp->t_rxtshift = 0;
649 } else
650 if (SEQ_GT(tp->snd_nxt + len, tp->snd_max))
651 tp->snd_max = tp->snd_nxt + len;
653 #ifdef TCPDEBUG
655 * Trace.
657 if (so->so_options & SO_DEBUG)
658 tcp_trace(TA_OUTPUT, tp->t_state, tp, ti, 0);
659 #endif
662 * Fill in IP length and desired time to live and
663 * send to IP level. There should be a better way
664 * to handle ttl and tos; we could keep them in
665 * the template, but need a way to checksum without them.
667 m->m_pkthdr.len = hdrlen + len;
668 #ifdef TUBA
669 if (tp->t_tuba_pcb)
670 error = tuba_output(m, tp);
671 else
672 #endif
674 ((struct ip *)ti)->ip_len = m->m_pkthdr.len;
675 ((struct ip *)ti)->ip_ttl = tp->t_inpcb->inp_ip.ip_ttl; /* XXX */
676 ((struct ip *)ti)->ip_tos = tp->t_inpcb->inp_ip.ip_tos; /* XXX */
677 #if BSD >= 43
678 error = ip_output(m, tp->t_inpcb->inp_options, &tp->t_inpcb->inp_route,
679 so->so_options & SO_DONTROUTE, 0);
680 #else
681 error = ip_output(m, (struct mbuf *)0, &tp->t_inpcb->inp_route,
682 so->so_options & SO_DONTROUTE);
683 #endif
685 if (error) {
686 out:
687 if (error == ENOBUFS) {
688 tcp_quench(tp->t_inpcb, 0);
689 return (0);
691 if ((error == EHOSTUNREACH || error == ENETDOWN)
692 && TCPS_HAVERCVDSYN(tp->t_state)) {
693 tp->t_softerror = error;
694 return (0);
696 return (error);
698 tcpstat.tcps_sndtotal++;
701 * Data sent (as far as we can tell).
702 * If this advertises a larger window than any other segment,
703 * then remember the size of the advertised window.
704 * Any pending ACK has now been sent.
706 if (win > 0 && SEQ_GT(tp->rcv_nxt+win, tp->rcv_adv))
707 tp->rcv_adv = tp->rcv_nxt + win;
708 tp->last_ack_sent = tp->rcv_nxt;
709 tp->t_flags &= ~(TF_ACKNOW|TF_DELACK);
710 if (sendalot)
711 goto again;
712 return (0);
715 void
716 tcp_setpersist(tp)
717 register struct tcpcb *tp;
719 register int t = ((tp->t_srtt >> 2) + tp->t_rttvar) >> 1;
721 if (tp->t_timer[TCPT_REXMT])
722 panic("tcp_output REXMT");
724 * Start/restart persistance timer.
726 TCPT_RANGESET(tp->t_timer[TCPT_PERSIST],
727 t * tcp_backoff[tp->t_rxtshift],
728 TCPTV_PERSMIN, TCPTV_PERSMAX);
729 if (tp->t_rxtshift < TCP_MAXRXTSHIFT)
730 tp->t_rxtshift++;