VirtualBox

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

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

NAT: slirp file headers

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

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