VirtualBox

source: vbox/trunk/src/VBox/Devices/Network/slirp/tcp_output.c@ 26404

Last change on this file since 26404 was 26404, checked in by vboxsync, 15 years ago

NAT: applied patch from xtracker 3993 (use BSD mbufs)

  • Property svn:eol-style set to native
File size: 22.1 KB
Line 
1/*
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)tcp_output.c 8.3 (Berkeley) 12/30/93
34 * tcp_output.c,v 1.3 1994/09/15 10:36:55 davidg Exp
35 */
36
37/*
38 * Changes and additions relating to SLiRP
39 * Copyright (c) 1995 Danny Gasparovski.
40 *
41 * Please read the file COPYRIGHT for the
42 * terms and conditions of the copyright.
43 */
44
45#include <slirp.h>
46
47/*
48 * Since this is only used in "stats socket", we give meaning
49 * names instead of the REAL names
50 */
51const char * const tcpstates[] =
52{
53/* "CLOSED", "LISTEN", "SYN_SENT", "SYN_RCVD", */
54 "REDIRECT", "LISTEN", "SYN_SENT", "SYN_RCVD",
55 "ESTABLISHED", "CLOSE_WAIT", "FIN_WAIT_1", "CLOSING",
56 "LAST_ACK", "FIN_WAIT_2", "TIME_WAIT",
57};
58
59static const u_char tcp_outflags[TCP_NSTATES] =
60{
61 TH_RST|TH_ACK, 0, TH_SYN, TH_SYN|TH_ACK,
62 TH_ACK, TH_ACK, TH_FIN|TH_ACK, TH_FIN|TH_ACK,
63 TH_FIN|TH_ACK, TH_ACK, TH_ACK,
64};
65
66
67#define MAX_TCPOPTLEN 32 /* max # bytes that go in options */
68
69/*
70 * Tcp output routine: figure out what should be sent and send it.
71 */
72int
73tcp_output(PNATState pData, register struct tcpcb *tp)
74{
75 register struct socket *so = tp->t_socket;
76 register long len, win;
77 int off, flags, error;
78 register struct mbuf *m = NULL;
79 register struct tcpiphdr *ti;
80 u_char opt[MAX_TCPOPTLEN];
81 unsigned optlen, hdrlen;
82 int idle, sendalot;
83 int size;
84
85 DEBUG_CALL("tcp_output");
86 DEBUG_ARG("tp = %lx", (long )tp);
87
88 /*
89 * Determine length of data that should be transmitted,
90 * and flags that will be used.
91 * If there is some data or critical controls (SYN, RST)
92 * to send, then transmit; otherwise, investigate further.
93 */
94 idle = (tp->snd_max == tp->snd_una);
95 if (idle && tp->t_idle >= tp->t_rxtcur)
96 /*
97 * We have been idle for "a while" and no acks are
98 * expected to clock out any data we send --
99 * slow start to get ack "clock" running again.
100 */
101 tp->snd_cwnd = tp->t_maxseg;
102
103again:
104 sendalot = 0;
105 off = tp->snd_nxt - tp->snd_una;
106 win = min(tp->snd_wnd, tp->snd_cwnd);
107
108 flags = tcp_outflags[tp->t_state];
109
110 DEBUG_MISC((dfd, " --- tcp_output flags = 0x%x\n",flags));
111
112 /*
113 * If in persist timeout with window of 0, send 1 byte.
114 * Otherwise, if window is small but nonzero
115 * and timer expired, we will send what we can
116 * and go to transmit state.
117 */
118 if (tp->t_force)
119 {
120 if (win == 0)
121 {
122 /*
123 * If we still have some data to send, then
124 * clear the FIN bit. Usually this would
125 * happen below when it realizes that we
126 * aren't sending all the data. However,
127 * if we have exactly 1 byte of unset data,
128 * then it won't clear the FIN bit below,
129 * and if we are in persist state, we wind
130 * up sending the packet without recording
131 * that we sent the FIN bit.
132 *
133 * We can't just blindly clear the FIN bit,
134 * because if we don't have any more data
135 * to send then the probe will be the FIN
136 * itself.
137 */
138 if (off < so->so_snd.sb_cc)
139 flags &= ~TH_FIN;
140 win = 1;
141 }
142 else
143 {
144 tp->t_timer[TCPT_PERSIST] = 0;
145 tp->t_rxtshift = 0;
146 }
147 }
148
149 len = min(so->so_snd.sb_cc, win) - off;
150 if (len < 0)
151 {
152 /*
153 * If FIN has been sent but not acked,
154 * but we haven't been called to retransmit,
155 * len will be -1. Otherwise, window shrank
156 * after we sent into it. If window shrank to 0,
157 * cancel pending retransmit and pull snd_nxt
158 * back to (closed) window. We will enter persist
159 * state below. If the window didn't close completely,
160 * just wait for an ACK.
161 */
162 len = 0;
163 if (win == 0)
164 {
165 tp->t_timer[TCPT_REXMT] = 0;
166 tp->snd_nxt = tp->snd_una;
167 }
168 }
169 if (len > tp->t_maxseg)
170 {
171 len = tp->t_maxseg;
172 sendalot = 1;
173 }
174 if (SEQ_LT(tp->snd_nxt + len, tp->snd_una + so->so_snd.sb_cc))
175 flags &= ~TH_FIN;
176
177 win = sbspace(&so->so_rcv);
178
179 /*
180 * Sender silly window avoidance. If connection is idle
181 * and can send all data, a maximum segment,
182 * at least a maximum default-size segment do it,
183 * or are forced, do it; otherwise don't bother.
184 * If peer's buffer is tiny, then send
185 * when window is at least half open.
186 * If retransmitting (possibly after persist timer forced us
187 * to send into a small window), then must resend.
188 */
189 if (len)
190 {
191 if (len == tp->t_maxseg)
192 goto send;
193 if ((1 || idle || tp->t_flags & TF_NODELAY) &&
194 len + off >= so->so_snd.sb_cc)
195 goto send;
196 if (tp->t_force)
197 goto send;
198 if (len >= tp->max_sndwnd / 2 && tp->max_sndwnd > 0)
199 goto send;
200 if (SEQ_LT(tp->snd_nxt, tp->snd_max))
201 goto send;
202 }
203
204 /*
205 * Compare available window to amount of window
206 * known to peer (as advertised window less
207 * next expected input). If the difference is at least two
208 * max size segments, or at least 50% of the maximum possible
209 * window, then want to send a window update to peer.
210 */
211 if (win > 0)
212 {
213 /*
214 * "adv" is the amount we can increase the window,
215 * taking into account that we are limited by
216 * TCP_MAXWIN << tp->rcv_scale.
217 */
218 long adv = min(win,
219 (long)TCP_MAXWIN << tp->rcv_scale) -
220 (tp->rcv_adv - tp->rcv_nxt);
221
222 if (adv >= (long) (2 * tp->t_maxseg))
223 goto send;
224 if (2 * adv >= (long) so->so_rcv.sb_datalen)
225 goto send;
226 }
227
228 /*
229 * Send if we owe peer an ACK.
230 */
231 if (tp->t_flags & TF_ACKNOW)
232 goto send;
233 if (flags & (TH_SYN|TH_RST))
234 goto send;
235 if (SEQ_GT(tp->snd_up, tp->snd_una))
236 goto send;
237 /*
238 * If our state indicates that FIN should be sent
239 * and we have not yet done so, or we're retransmitting the FIN,
240 * then we need to send.
241 */
242 if ( flags & TH_FIN
243 && ((tp->t_flags & TF_SENTFIN) == 0 || tp->snd_nxt == tp->snd_una))
244 goto send;
245
246 /*
247 * TCP window updates are not reliable, rather a polling protocol
248 * using ``persist'' packets is used to insure receipt of window
249 * updates. The three ``states'' for the output side are:
250 * idle not doing retransmits or persists
251 * persisting to move a small or zero window
252 * (re)transmitting and thereby not persisting
253 *
254 * tp->t_timer[TCPT_PERSIST]
255 * is set when we are in persist state.
256 * tp->t_force
257 * is set when we are called to send a persist packet.
258 * tp->t_timer[TCPT_REXMT]
259 * is set when we are retransmitting
260 * The output side is idle when both timers are zero.
261 *
262 * If send window is too small, there is data to transmit, and no
263 * retransmit or persist is pending, then go to persist state.
264 * If nothing happens soon, send when timer expires:
265 * if window is nonzero, transmit what we can,
266 * otherwise force out a byte.
267 */
268 if ( so->so_snd.sb_cc
269 && tp->t_timer[TCPT_REXMT] == 0
270 && tp->t_timer[TCPT_PERSIST] == 0)
271 {
272 tp->t_rxtshift = 0;
273 tcp_setpersist(tp);
274 }
275
276 /*
277 * No reason to send a segment, just return.
278 */
279 tcpstat.tcps_didnuttin++;
280
281 return (0);
282
283send:
284 /*
285 * Before ESTABLISHED, force sending of initial options
286 * unless TCP set not to do any options.
287 * NOTE: we assume that the IP/TCP header plus TCP options
288 * always fit in a single mbuf, leaving room for a maximum
289 * link header, i.e.
290 * max_linkhdr + sizeof (struct tcpiphdr) + optlen <= MHLEN
291 */
292 optlen = 0;
293 hdrlen = sizeof (struct tcpiphdr);
294 if (flags & TH_SYN)
295 {
296 tp->snd_nxt = tp->iss;
297 if ((tp->t_flags & TF_NOOPT) == 0)
298 {
299 u_int16_t mss;
300
301 opt[0] = TCPOPT_MAXSEG;
302 opt[1] = 4;
303 mss = RT_H2N_U16((u_int16_t) tcp_mss(pData, tp, 0));
304 memcpy((caddr_t)(opt + 2), (caddr_t)&mss, sizeof(mss));
305 optlen = 4;
306
307#if 0
308 if ( (tp->t_flags & TF_REQ_SCALE)
309 && ( (flags & TH_ACK) == 0
310 || (tp->t_flags & TF_RCVD_SCALE)))
311 {
312 *((u_int32_t *) (opt + optlen)) = RT_H2N_U32( TCPOPT_NOP << 24
313 | TCPOPT_WINDOW << 16
314 | TCPOLEN_WINDOW << 8
315 | tp->request_r_scale);
316 optlen += 4;
317 }
318#endif
319 }
320 }
321
322 /*
323 * Send a timestamp and echo-reply if this is a SYN and our side
324 * wants to use timestamps (TF_REQ_TSTMP is set) or both our side
325 * and our peer have sent timestamps in our SYN's.
326 */
327#if 0
328 if ( (tp->t_flags & (TF_REQ_TSTMP|TF_NOOPT)) == TF_REQ_TSTMP
329 && (flags & TH_RST) == 0
330 && ( (flags & (TH_SYN|TH_ACK)) == TH_SYN
331 || (tp->t_flags & TF_RCVD_TSTMP)))
332 {
333 u_int32_t *lp = (u_int32_t *)(opt + optlen);
334
335 /* Form timestamp option as shown in appendix A of RFC 1323. */
336 *lp++ = RT_H2N_U32_C(TCPOPT_TSTAMP_HDR);
337 *lp++ = RT_H2N_U32(tcp_now);
338 *lp = RT_H2N_U32(tp->ts_recent);
339 optlen += TCPOLEN_TSTAMP_APPA;
340 }
341#endif
342 hdrlen += optlen;
343
344 /*
345 * Adjust data length if insertion of options will
346 * bump the packet length beyond the t_maxseg length.
347 */
348 if (len > tp->t_maxseg - optlen)
349 {
350 len = tp->t_maxseg - optlen;
351 sendalot = 1;
352 }
353
354 /*
355 * Grab a header mbuf, attaching a copy of data to
356 * be transmitted, and initialize the header from
357 * the template for sends on this connection.
358 */
359 if (len)
360 {
361 if (tp->t_force && len == 1)
362 tcpstat.tcps_sndprobe++;
363 else if (SEQ_LT(tp->snd_nxt, tp->snd_max))
364 {
365 tcpstat.tcps_sndrexmitpack++;
366 tcpstat.tcps_sndrexmitbyte += len;
367 }
368 else
369 {
370 tcpstat.tcps_sndpack++;
371 tcpstat.tcps_sndbyte += len;
372 }
373
374#ifndef VBOX_WITH_SLIRP_BSD_MBUF
375 m = m_get(pData);
376#else
377 size = MCLBYTES;
378 if ((len + hdrlen + ETH_HLEN) < MSIZE)
379 size = MCLBYTES;
380 else if ((len + hdrlen + ETH_HLEN) < MCLBYTES)
381 size = MCLBYTES;
382 else if((len + hdrlen + ETH_HLEN) < MJUM9BYTES)
383 size = MJUM9BYTES;
384 else if ((len + hdrlen + ETH_HLEN) < MJUM16BYTES)
385 size = MJUM16BYTES;
386 else
387 AssertMsgFailed(("Unsupported size"));
388 m = m_getjcl(pData, M_NOWAIT, MT_HEADER, M_PKTHDR, size);
389#endif
390 if (m == NULL)
391 {
392/* error = ENOBUFS; */
393 error = 1;
394 goto out;
395 }
396 m->m_data += if_maxlinkhdr;
397#ifdef VBOX_WITH_SLIRP_BSD_MBUF
398 m->m_pkthdr.header = mtod(m, void *);
399#endif
400 m->m_len = hdrlen;
401
402 /*
403 * This will always succeed, since we make sure our mbufs
404 * are big enough to hold one MSS packet + header + ... etc.
405 */
406#if 0
407 if (len <= MHLEN - hdrlen - max_linkhdr)
408 {
409#endif
410 sbcopy(&so->so_snd, off, (int) len, mtod(m, caddr_t) + hdrlen);
411 m->m_len += len;
412#if 0
413 }
414 else
415 {
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 }
430 else
431 {
432 if (tp->t_flags & TF_ACKNOW)
433 tcpstat.tcps_sndacks++;
434 else if (flags & (TH_SYN|TH_FIN|TH_RST))
435 tcpstat.tcps_sndctrl++;
436 else if (SEQ_GT(tp->snd_up, tp->snd_una))
437 tcpstat.tcps_sndurg++;
438 else
439 tcpstat.tcps_sndwinup++;
440
441#ifndef VBOX_WITH_SLIRP_BSD_MBUF
442 m = m_get(pData);
443 if (m == NULL)
444 {
445/* error = ENOBUFS; */
446 error = 1;
447 goto out;
448 }
449#else
450 if ((hdrlen + ETH_HLEN) < MSIZE)
451 {
452 size = MCLBYTES;
453 }
454 else if ((hdrlen + ETH_HLEN) < MCLBYTES)
455 {
456 size = MCLBYTES;
457 }
458 else if((hdrlen + ETH_HLEN) < MJUM9BYTES)
459 {
460 size = MJUM9BYTES;
461 }
462 else if ((hdrlen + ETH_HLEN) < MJUM16BYTES)
463 {
464 size = MJUM16BYTES;
465 }
466 else
467 {
468 AssertMsgFailed(("Unsupported size"));
469 }
470 m = m_getjcl(pData, M_NOWAIT, MT_HEADER, M_PKTHDR, size);
471#endif
472 if (m == NULL)
473 {
474/* error = ENOBUFS; */
475 error = 1;
476 goto out;
477 }
478 m->m_data += if_maxlinkhdr;
479#ifdef VBOX_WITH_SLIRP_BSD_MBUF
480 m->m_pkthdr.header = mtod(m, void *);
481#endif
482 m->m_len = hdrlen;
483 }
484
485 ti = mtod(m, struct tcpiphdr *);
486
487 memcpy((caddr_t)ti, &tp->t_template, sizeof (struct tcpiphdr));
488
489 /*
490 * Fill in fields, remembering maximum advertised
491 * window for use in delaying messages about window sizes.
492 * If resending a FIN, be sure not to use a new sequence number.
493 */
494 if ( flags & TH_FIN
495 && tp->t_flags & TF_SENTFIN
496 && tp->snd_nxt == tp->snd_max)
497 tp->snd_nxt--;
498 /*
499 * If we are doing retransmissions, then snd_nxt will
500 * not reflect the first unsent octet. For ACK only
501 * packets, we do not want the sequence number of the
502 * retransmitted packet, we want the sequence number
503 * of the next unsent octet. So, if there is no data
504 * (and no SYN or FIN), use snd_max instead of snd_nxt
505 * when filling in ti_seq. But if we are in persist
506 * state, snd_max might reflect one byte beyond the
507 * right edge of the window, so use snd_nxt in that
508 * case, since we know we aren't doing a retransmission.
509 * (retransmit and persist are mutually exclusive...)
510 */
511 if (len || (flags & (TH_SYN|TH_FIN)) || tp->t_timer[TCPT_PERSIST])
512 ti->ti_seq = RT_H2N_U32(tp->snd_nxt);
513 else
514 ti->ti_seq = RT_H2N_U32(tp->snd_max);
515 ti->ti_ack = RT_H2N_U32(tp->rcv_nxt);
516 if (optlen)
517 {
518 memcpy((caddr_t)(ti + 1), (caddr_t)opt, optlen);
519 ti->ti_off = (sizeof (struct tcphdr) + optlen) >> 2;
520 }
521 ti->ti_flags = flags;
522 /*
523 * Calculate receive window. Don't shrink window,
524 * but avoid silly window syndrome.
525 */
526 if (win < (long)(so->so_rcv.sb_datalen / 4) && win < (long)tp->t_maxseg)
527 win = 0;
528 if (win > (long)TCP_MAXWIN << tp->rcv_scale)
529 win = (long)TCP_MAXWIN << tp->rcv_scale;
530 if (win < (long)(tp->rcv_adv - tp->rcv_nxt))
531 win = (long)(tp->rcv_adv - tp->rcv_nxt);
532 ti->ti_win = RT_H2N_U16((u_int16_t) (win>>tp->rcv_scale));
533
534#if 0
535 if (SEQ_GT(tp->snd_up, tp->snd_nxt))
536 {
537 ti->ti_urp = RT_H2N_U16((u_int16_t)(tp->snd_up - tp->snd_nxt));
538#else
539 if (SEQ_GT(tp->snd_up, tp->snd_una))
540 {
541 ti->ti_urp = RT_H2N_U16((u_int16_t)(tp->snd_up - RT_N2H_U32(ti->ti_seq)));
542#endif
543 ti->ti_flags |= TH_URG;
544 }
545 else
546 /*
547 * If no urgent pointer to send, then we pull
548 * the urgent pointer to the left edge of the send window
549 * so that it doesn't drift into the send window on sequence
550 * number wraparound.
551 */
552 tp->snd_up = tp->snd_una; /* drag it along */
553
554 /*
555 * Put TCP length in extended header, and then
556 * checksum extended header and data.
557 */
558 if (len + optlen)
559 ti->ti_len = RT_H2N_U16((u_int16_t)(sizeof (struct tcphdr)
560 + optlen + len));
561 ti->ti_sum = cksum(m, (int)(hdrlen + len));
562
563 /*
564 * In transmit state, time the transmission and arrange for
565 * the retransmit. In persist state, just set snd_max.
566 */
567 if (tp->t_force == 0 || tp->t_timer[TCPT_PERSIST] == 0)
568 {
569 tcp_seq startseq = tp->snd_nxt;
570
571 /*
572 * Advance snd_nxt over sequence space of this segment.
573 */
574 if (flags & (TH_SYN|TH_FIN))
575 {
576 if (flags & TH_SYN)
577 tp->snd_nxt++;
578 if (flags & TH_FIN)
579 {
580 tp->snd_nxt++;
581 tp->t_flags |= TF_SENTFIN;
582 }
583 }
584 tp->snd_nxt += len;
585 if (SEQ_GT(tp->snd_nxt, tp->snd_max))
586 {
587 tp->snd_max = tp->snd_nxt;
588 /*
589 * Time this transmission if not a retransmission and
590 * not currently timing anything.
591 */
592 if (tp->t_rtt == 0)
593 {
594 tp->t_rtt = 1;
595 tp->t_rtseq = startseq;
596 tcpstat.tcps_segstimed++;
597 }
598 }
599
600 /*
601 * Set retransmit timer if not currently set,
602 * and not doing an ack or a keep-alive probe.
603 * Initial value for retransmit timer is smoothed
604 * round-trip time + 2 * round-trip time variance.
605 * Initialize shift counter which is used for backoff
606 * of retransmit time.
607 */
608 if ( tp->t_timer[TCPT_REXMT] == 0
609 && tp->snd_nxt != tp->snd_una)
610 {
611 tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
612 if (tp->t_timer[TCPT_PERSIST])
613 {
614 tp->t_timer[TCPT_PERSIST] = 0;
615 tp->t_rxtshift = 0;
616 }
617 }
618 }
619 else
620 if (SEQ_GT(tp->snd_nxt + len, tp->snd_max))
621 tp->snd_max = tp->snd_nxt + len;
622
623 /*
624 * Fill in IP length and desired time to live and
625 * send to IP level. There should be a better way
626 * to handle ttl and tos; we could keep them in
627 * the template, but need a way to checksum without them.
628 */
629#ifndef VBOX_WITH_SLIRP_BSD_MBUF
630 Assert(m->m_len == (hdrlen + len));
631#else
632 M_ASSERTPKTHDR(m);
633 m->m_pkthdr.header = mtod(m, void *);
634#endif
635 m->m_len = hdrlen + len; /* XXX Needed? m_len should be correct */
636
637 {
638 ((struct ip *)ti)->ip_len = m->m_len;
639 ((struct ip *)ti)->ip_ttl = ip_defttl;
640 ((struct ip *)ti)->ip_tos = so->so_iptos;
641
642 /* #if BSD >= 43 */
643 /* Don't do IP options... */
644#if 0
645 error = ip_output(m, tp->t_inpcb->inp_options, &tp->t_inpcb->inp_route,
646 so->so_options & SO_DONTROUTE, 0);
647#endif
648#ifndef VBOX_WITH_SLIRP_BSD_MBUF
649 if(so->so_la != NULL)
650 m->m_la = so->so_la;
651#endif
652 error = ip_output(pData, so, m);
653
654#if 0
655/* #else */
656 error = ip_output(m, (struct mbuf *)0, &tp->t_inpcb->inp_route,
657 so->so_options & SO_DONTROUTE);
658/* #endif */
659#endif
660 }
661 if (error)
662 {
663out:
664#if 0
665 if (error == ENOBUFS)
666 {
667 tcp_quench(tp->t_inpcb, 0);
668 return (0);
669 }
670
671 if ( ( error == EHOSTUNREACH
672 || error == ENETDOWN)
673 && TCPS_HAVERCVDSYN(tp->t_state))
674 {
675 tp->t_softerror = error;
676 return (0);
677 }
678#endif
679 if (m != NULL)
680 m_free(pData, m);
681 return (error);
682 }
683 tcpstat.tcps_sndtotal++;
684
685 /*
686 * Data sent (as far as we can tell).
687 * If this advertises a larger window than any other segment,
688 * then remember the size of the advertised window.
689 * Any pending ACK has now been sent.
690 */
691 if (win > 0 && SEQ_GT(tp->rcv_nxt+win, tp->rcv_adv))
692 tp->rcv_adv = tp->rcv_nxt + win;
693 tp->last_ack_sent = tp->rcv_nxt;
694 tp->t_flags &= ~(TF_ACKNOW|TF_DELACK);
695 if (sendalot)
696 goto again;
697
698 return (0);
699}
700
701void
702tcp_setpersist(struct tcpcb *tp)
703{
704 int t = ((tp->t_srtt >> 2) + tp->t_rttvar) >> 1;
705
706#if 0
707 if (tp->t_timer[TCPT_REXMT])
708 panic("tcp_output REXMT");
709#endif
710 /*
711 * Start/restart persistence timer.
712 */
713 TCPT_RANGESET(tp->t_timer[TCPT_PERSIST],
714 t * tcp_backoff[tp->t_rxtshift],
715 TCPTV_PERSMIN, TCPTV_PERSMAX);
716 if (tp->t_rxtshift < TCP_MAXRXTSHIFT)
717 tp->t_rxtshift++;
718}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette