VirtualBox

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

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

Automated rebranding to Oracle copyright/license strings via filemuncher

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