VirtualBox

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

最後變更 在這個檔案從28023是 27797,由 vboxsync 提交於 15 年 前

misc compiler warning fixes, comment typos and other minor cleanups

  • 屬性 svn:eol-style 設為 native
檔案大小: 22.1 KB
 
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#ifdef VBOX_WITH_SLIRP_BSD_MBUF
84 int size;
85#endif
86
87 DEBUG_CALL("tcp_output");
88 DEBUG_ARG("tp = %lx", (long )tp);
89
90 /*
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.
95 */
96 idle = (tp->snd_max == tp->snd_una);
97 if (idle && tp->t_idle >= tp->t_rxtcur)
98 /*
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.
102 */
103 tp->snd_cwnd = tp->t_maxseg;
104
105again:
106 sendalot = 0;
107 off = tp->snd_nxt - tp->snd_una;
108 win = min(tp->snd_wnd, tp->snd_cwnd);
109
110 flags = tcp_outflags[tp->t_state];
111
112 DEBUG_MISC((dfd, " --- tcp_output flags = 0x%x\n",flags));
113
114 /*
115 * If in persist timeout with window of 0, send 1 byte.
116 * Otherwise, if window is small but nonzero
117 * and timer expired, we will send what we can
118 * and go to transmit state.
119 */
120 if (tp->t_force)
121 {
122 if (win == 0)
123 {
124 /*
125 * If we still have some data to send, then
126 * clear the FIN bit. Usually this would
127 * happen below when it realizes that we
128 * aren't sending all the data. However,
129 * if we have exactly 1 byte of unset data,
130 * then it won't clear the FIN bit below,
131 * and if we are in persist state, we wind
132 * up sending the packet without recording
133 * that we sent the FIN bit.
134 *
135 * We can't just blindly clear the FIN bit,
136 * because if we don't have any more data
137 * to send then the probe will be the FIN
138 * itself.
139 */
140 if (off < so->so_snd.sb_cc)
141 flags &= ~TH_FIN;
142 win = 1;
143 }
144 else
145 {
146 tp->t_timer[TCPT_PERSIST] = 0;
147 tp->t_rxtshift = 0;
148 }
149 }
150
151 len = min(so->so_snd.sb_cc, win) - off;
152 if (len < 0)
153 {
154 /*
155 * If FIN has been sent but not acked,
156 * but we haven't been called to retransmit,
157 * len will be -1. Otherwise, window shrank
158 * after we sent into it. If window shrank to 0,
159 * cancel pending retransmit and pull snd_nxt
160 * back to (closed) window. We will enter persist
161 * state below. If the window didn't close completely,
162 * just wait for an ACK.
163 */
164 len = 0;
165 if (win == 0)
166 {
167 tp->t_timer[TCPT_REXMT] = 0;
168 tp->snd_nxt = tp->snd_una;
169 }
170 }
171 if (len > tp->t_maxseg)
172 {
173 len = tp->t_maxseg;
174 sendalot = 1;
175 }
176 if (SEQ_LT(tp->snd_nxt + len, tp->snd_una + so->so_snd.sb_cc))
177 flags &= ~TH_FIN;
178
179 win = sbspace(&so->so_rcv);
180
181 /*
182 * Sender silly window avoidance. If connection is idle
183 * and can send all data, a maximum segment,
184 * at least a maximum default-size segment do it,
185 * or are forced, do it; otherwise don't bother.
186 * If peer's buffer is tiny, then send
187 * when window is at least half open.
188 * If retransmitting (possibly after persist timer forced us
189 * to send into a small window), then must resend.
190 */
191 if (len)
192 {
193 if (len == tp->t_maxseg)
194 goto send;
195 if ((1 || idle || tp->t_flags & TF_NODELAY) &&
196 len + off >= so->so_snd.sb_cc)
197 goto send;
198 if (tp->t_force)
199 goto send;
200 if (len >= tp->max_sndwnd / 2 && tp->max_sndwnd > 0)
201 goto send;
202 if (SEQ_LT(tp->snd_nxt, tp->snd_max))
203 goto send;
204 }
205
206 /*
207 * Compare available window to amount of window
208 * known to peer (as advertised window less
209 * next expected input). If the difference is at least two
210 * max size segments, or at least 50% of the maximum possible
211 * window, then want to send a window update to peer.
212 */
213 if (win > 0)
214 {
215 /*
216 * "adv" is the amount we can increase the window,
217 * taking into account that we are limited by
218 * TCP_MAXWIN << tp->rcv_scale.
219 */
220 long adv = min(win,
221 (long)TCP_MAXWIN << tp->rcv_scale) -
222 (tp->rcv_adv - tp->rcv_nxt);
223
224 if (adv >= (long) (2 * tp->t_maxseg))
225 goto send;
226 if (2 * adv >= (long) so->so_rcv.sb_datalen)
227 goto send;
228 }
229
230 /*
231 * Send if we owe peer an ACK.
232 */
233 if (tp->t_flags & TF_ACKNOW)
234 goto send;
235 if (flags & (TH_SYN|TH_RST))
236 goto send;
237 if (SEQ_GT(tp->snd_up, tp->snd_una))
238 goto send;
239 /*
240 * If our state indicates that FIN should be sent
241 * and we have not yet done so, or we're retransmitting the FIN,
242 * then we need to send.
243 */
244 if ( flags & TH_FIN
245 && ((tp->t_flags & TF_SENTFIN) == 0 || tp->snd_nxt == tp->snd_una))
246 goto send;
247
248 /*
249 * TCP window updates are not reliable, rather a polling protocol
250 * using ``persist'' packets is used to insure receipt of window
251 * updates. The three ``states'' for the output side are:
252 * idle not doing retransmits or persists
253 * persisting to move a small or zero window
254 * (re)transmitting and thereby not persisting
255 *
256 * tp->t_timer[TCPT_PERSIST]
257 * is set when we are in persist state.
258 * tp->t_force
259 * is set when we are called to send a persist packet.
260 * tp->t_timer[TCPT_REXMT]
261 * is set when we are retransmitting
262 * The output side is idle when both timers are zero.
263 *
264 * If send window is too small, there is data to transmit, and no
265 * retransmit or persist is pending, then go to persist state.
266 * If nothing happens soon, send when timer expires:
267 * if window is nonzero, transmit what we can,
268 * otherwise force out a byte.
269 */
270 if ( so->so_snd.sb_cc
271 && tp->t_timer[TCPT_REXMT] == 0
272 && tp->t_timer[TCPT_PERSIST] == 0)
273 {
274 tp->t_rxtshift = 0;
275 tcp_setpersist(tp);
276 }
277
278 /*
279 * No reason to send a segment, just return.
280 */
281 tcpstat.tcps_didnuttin++;
282
283 return (0);
284
285send:
286 /*
287 * Before ESTABLISHED, force sending of initial options
288 * unless TCP set not to do any options.
289 * NOTE: we assume that the IP/TCP header plus TCP options
290 * always fit in a single mbuf, leaving room for a maximum
291 * link header, i.e.
292 * max_linkhdr + sizeof (struct tcpiphdr) + optlen <= MHLEN
293 */
294 optlen = 0;
295 hdrlen = sizeof (struct tcpiphdr);
296 if (flags & TH_SYN)
297 {
298 tp->snd_nxt = tp->iss;
299 if ((tp->t_flags & TF_NOOPT) == 0)
300 {
301 u_int16_t mss;
302
303 opt[0] = TCPOPT_MAXSEG;
304 opt[1] = 4;
305 mss = RT_H2N_U16((u_int16_t) tcp_mss(pData, tp, 0));
306 memcpy((caddr_t)(opt + 2), (caddr_t)&mss, sizeof(mss));
307 optlen = 4;
308
309#if 0
310 if ( (tp->t_flags & TF_REQ_SCALE)
311 && ( (flags & TH_ACK) == 0
312 || (tp->t_flags & TF_RCVD_SCALE)))
313 {
314 *((u_int32_t *) (opt + optlen)) = RT_H2N_U32( TCPOPT_NOP << 24
315 | TCPOPT_WINDOW << 16
316 | TCPOLEN_WINDOW << 8
317 | tp->request_r_scale);
318 optlen += 4;
319 }
320#endif
321 }
322 }
323
324 /*
325 * Send a timestamp and echo-reply if this is a SYN and our side
326 * wants to use timestamps (TF_REQ_TSTMP is set) or both our side
327 * and our peer have sent timestamps in our SYN's.
328 */
329#if 0
330 if ( (tp->t_flags & (TF_REQ_TSTMP|TF_NOOPT)) == TF_REQ_TSTMP
331 && (flags & TH_RST) == 0
332 && ( (flags & (TH_SYN|TH_ACK)) == TH_SYN
333 || (tp->t_flags & TF_RCVD_TSTMP)))
334 {
335 u_int32_t *lp = (u_int32_t *)(opt + optlen);
336
337 /* Form timestamp option as shown in appendix A of RFC 1323. */
338 *lp++ = RT_H2N_U32_C(TCPOPT_TSTAMP_HDR);
339 *lp++ = RT_H2N_U32(tcp_now);
340 *lp = RT_H2N_U32(tp->ts_recent);
341 optlen += TCPOLEN_TSTAMP_APPA;
342 }
343#endif
344 hdrlen += optlen;
345
346 /*
347 * Adjust data length if insertion of options will
348 * bump the packet length beyond the t_maxseg length.
349 */
350 if (len > tp->t_maxseg - optlen)
351 {
352 len = tp->t_maxseg - optlen;
353 sendalot = 1;
354 }
355
356 /*
357 * Grab a header mbuf, attaching a copy of data to
358 * be transmitted, and initialize the header from
359 * the template for sends on this connection.
360 */
361 if (len)
362 {
363 if (tp->t_force && len == 1)
364 tcpstat.tcps_sndprobe++;
365 else if (SEQ_LT(tp->snd_nxt, tp->snd_max))
366 {
367 tcpstat.tcps_sndrexmitpack++;
368 tcpstat.tcps_sndrexmitbyte += len;
369 }
370 else
371 {
372 tcpstat.tcps_sndpack++;
373 tcpstat.tcps_sndbyte += len;
374 }
375
376#ifndef VBOX_WITH_SLIRP_BSD_MBUF
377 m = m_get(pData);
378#else
379 size = MCLBYTES;
380 if ((len + hdrlen + ETH_HLEN) < MSIZE)
381 size = MCLBYTES;
382 else if ((len + hdrlen + ETH_HLEN) < MCLBYTES)
383 size = MCLBYTES;
384 else if((len + hdrlen + ETH_HLEN) < MJUM9BYTES)
385 size = MJUM9BYTES;
386 else if ((len + hdrlen + ETH_HLEN) < MJUM16BYTES)
387 size = MJUM16BYTES;
388 else
389 AssertMsgFailed(("Unsupported size"));
390 m = m_getjcl(pData, M_NOWAIT, MT_HEADER, M_PKTHDR, size);
391#endif
392 if (m == NULL)
393 {
394/* error = ENOBUFS; */
395 error = 1;
396 goto out;
397 }
398 m->m_data += if_maxlinkhdr;
399#ifdef VBOX_WITH_SLIRP_BSD_MBUF
400 m->m_pkthdr.header = mtod(m, void *);
401#endif
402 m->m_len = hdrlen;
403
404 /*
405 * This will always succeed, since we make sure our mbufs
406 * are big enough to hold one MSS packet + header + ... etc.
407 */
408#if 0
409 if (len <= MHLEN - hdrlen - max_linkhdr)
410 {
411#endif
412 sbcopy(&so->so_snd, off, (int) len, mtod(m, caddr_t) + hdrlen);
413 m->m_len += len;
414#if 0
415 }
416 else
417 {
418 m->m_next = m_copy(so->so_snd.sb_mb, off, (int) len);
419 if (m->m_next == 0)
420 len = 0;
421 }
422#endif
423 /*
424 * If we're sending everything we've got, set PUSH.
425 * (This will keep happy those implementations which only
426 * give data to the user when a buffer fills or
427 * a PUSH comes in.)
428 */
429 if (off + len == so->so_snd.sb_cc)
430 flags |= TH_PUSH;
431 }
432 else
433 {
434 if (tp->t_flags & TF_ACKNOW)
435 tcpstat.tcps_sndacks++;
436 else if (flags & (TH_SYN|TH_FIN|TH_RST))
437 tcpstat.tcps_sndctrl++;
438 else if (SEQ_GT(tp->snd_up, tp->snd_una))
439 tcpstat.tcps_sndurg++;
440 else
441 tcpstat.tcps_sndwinup++;
442
443#ifndef VBOX_WITH_SLIRP_BSD_MBUF
444 m = m_get(pData);
445 if (m == NULL)
446 {
447/* error = ENOBUFS; */
448 error = 1;
449 goto out;
450 }
451#else
452 if ((hdrlen + ETH_HLEN) < MSIZE)
453 {
454 size = MCLBYTES;
455 }
456 else if ((hdrlen + ETH_HLEN) < MCLBYTES)
457 {
458 size = MCLBYTES;
459 }
460 else if((hdrlen + ETH_HLEN) < MJUM9BYTES)
461 {
462 size = MJUM9BYTES;
463 }
464 else if ((hdrlen + ETH_HLEN) < MJUM16BYTES)
465 {
466 size = MJUM16BYTES;
467 }
468 else
469 {
470 AssertMsgFailed(("Unsupported size"));
471 }
472 m = m_getjcl(pData, M_NOWAIT, MT_HEADER, M_PKTHDR, size);
473#endif
474 if (m == NULL)
475 {
476/* error = ENOBUFS; */
477 error = 1;
478 goto out;
479 }
480 m->m_data += if_maxlinkhdr;
481#ifdef VBOX_WITH_SLIRP_BSD_MBUF
482 m->m_pkthdr.header = mtod(m, void *);
483#endif
484 m->m_len = hdrlen;
485 }
486
487 ti = mtod(m, struct tcpiphdr *);
488
489 memcpy((caddr_t)ti, &tp->t_template, sizeof (struct tcpiphdr));
490
491 /*
492 * Fill in fields, remembering maximum advertised
493 * window for use in delaying messages about window sizes.
494 * If resending a FIN, be sure not to use a new sequence number.
495 */
496 if ( flags & TH_FIN
497 && tp->t_flags & TF_SENTFIN
498 && tp->snd_nxt == tp->snd_max)
499 tp->snd_nxt--;
500 /*
501 * If we are doing retransmissions, then snd_nxt will
502 * not reflect the first unsent octet. For ACK only
503 * packets, we do not want the sequence number of the
504 * retransmitted packet, we want the sequence number
505 * of the next unsent octet. So, if there is no data
506 * (and no SYN or FIN), use snd_max instead of snd_nxt
507 * when filling in ti_seq. But if we are in persist
508 * state, snd_max might reflect one byte beyond the
509 * right edge of the window, so use snd_nxt in that
510 * case, since we know we aren't doing a retransmission.
511 * (retransmit and persist are mutually exclusive...)
512 */
513 if (len || (flags & (TH_SYN|TH_FIN)) || tp->t_timer[TCPT_PERSIST])
514 ti->ti_seq = RT_H2N_U32(tp->snd_nxt);
515 else
516 ti->ti_seq = RT_H2N_U32(tp->snd_max);
517 ti->ti_ack = RT_H2N_U32(tp->rcv_nxt);
518 if (optlen)
519 {
520 memcpy((caddr_t)(ti + 1), (caddr_t)opt, optlen);
521 ti->ti_off = (sizeof (struct tcphdr) + optlen) >> 2;
522 }
523 ti->ti_flags = flags;
524 /*
525 * Calculate receive window. Don't shrink window,
526 * but avoid silly window syndrome.
527 */
528 if (win < (long)(so->so_rcv.sb_datalen / 4) && win < (long)tp->t_maxseg)
529 win = 0;
530 if (win > (long)TCP_MAXWIN << tp->rcv_scale)
531 win = (long)TCP_MAXWIN << tp->rcv_scale;
532 if (win < (long)(tp->rcv_adv - tp->rcv_nxt))
533 win = (long)(tp->rcv_adv - tp->rcv_nxt);
534 ti->ti_win = RT_H2N_U16((u_int16_t) (win>>tp->rcv_scale));
535
536#if 0
537 if (SEQ_GT(tp->snd_up, tp->snd_nxt))
538 {
539 ti->ti_urp = RT_H2N_U16((u_int16_t)(tp->snd_up - tp->snd_nxt));
540#else
541 if (SEQ_GT(tp->snd_up, tp->snd_una))
542 {
543 ti->ti_urp = RT_H2N_U16((u_int16_t)(tp->snd_up - RT_N2H_U32(ti->ti_seq)));
544#endif
545 ti->ti_flags |= TH_URG;
546 }
547 else
548 /*
549 * If no urgent pointer to send, then we pull
550 * the urgent pointer to the left edge of the send window
551 * so that it doesn't drift into the send window on sequence
552 * number wraparound.
553 */
554 tp->snd_up = tp->snd_una; /* drag it along */
555
556 /*
557 * Put TCP length in extended header, and then
558 * checksum extended header and data.
559 */
560 if (len + optlen)
561 ti->ti_len = RT_H2N_U16((u_int16_t)(sizeof (struct tcphdr)
562 + optlen + len));
563 ti->ti_sum = cksum(m, (int)(hdrlen + len));
564
565 /*
566 * In transmit state, time the transmission and arrange for
567 * the retransmit. In persist state, just set snd_max.
568 */
569 if (tp->t_force == 0 || tp->t_timer[TCPT_PERSIST] == 0)
570 {
571 tcp_seq startseq = tp->snd_nxt;
572
573 /*
574 * Advance snd_nxt over sequence space of this segment.
575 */
576 if (flags & (TH_SYN|TH_FIN))
577 {
578 if (flags & TH_SYN)
579 tp->snd_nxt++;
580 if (flags & TH_FIN)
581 {
582 tp->snd_nxt++;
583 tp->t_flags |= TF_SENTFIN;
584 }
585 }
586 tp->snd_nxt += len;
587 if (SEQ_GT(tp->snd_nxt, tp->snd_max))
588 {
589 tp->snd_max = tp->snd_nxt;
590 /*
591 * Time this transmission if not a retransmission and
592 * not currently timing anything.
593 */
594 if (tp->t_rtt == 0)
595 {
596 tp->t_rtt = 1;
597 tp->t_rtseq = startseq;
598 tcpstat.tcps_segstimed++;
599 }
600 }
601
602 /*
603 * Set retransmit timer if not currently set,
604 * and not doing an ack or a keep-alive probe.
605 * Initial value for retransmit timer is smoothed
606 * round-trip time + 2 * round-trip time variance.
607 * Initialize shift counter which is used for backoff
608 * of retransmit time.
609 */
610 if ( tp->t_timer[TCPT_REXMT] == 0
611 && tp->snd_nxt != tp->snd_una)
612 {
613 tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
614 if (tp->t_timer[TCPT_PERSIST])
615 {
616 tp->t_timer[TCPT_PERSIST] = 0;
617 tp->t_rxtshift = 0;
618 }
619 }
620 }
621 else
622 if (SEQ_GT(tp->snd_nxt + len, tp->snd_max))
623 tp->snd_max = tp->snd_nxt + len;
624
625 /*
626 * Fill in IP length and desired time to live and
627 * send to IP level. There should be a better way
628 * to handle ttl and tos; we could keep them in
629 * the template, but need a way to checksum without them.
630 */
631#ifndef VBOX_WITH_SLIRP_BSD_MBUF
632 Assert(m->m_len == (hdrlen + len));
633#else
634 M_ASSERTPKTHDR(m);
635 m->m_pkthdr.header = mtod(m, void *);
636#endif
637 m->m_len = hdrlen + len; /* XXX Needed? m_len should be correct */
638
639 {
640 ((struct ip *)ti)->ip_len = m->m_len;
641 ((struct ip *)ti)->ip_ttl = ip_defttl;
642 ((struct ip *)ti)->ip_tos = so->so_iptos;
643
644 /* #if BSD >= 43 */
645 /* Don't do IP options... */
646#if 0
647 error = ip_output(m, tp->t_inpcb->inp_options, &tp->t_inpcb->inp_route,
648 so->so_options & SO_DONTROUTE, 0);
649#endif
650#ifndef VBOX_WITH_SLIRP_BSD_MBUF
651 if(so->so_la != NULL)
652 m->m_la = so->so_la;
653#endif
654 error = ip_output(pData, so, m);
655
656#if 0
657/* #else */
658 error = ip_output(m, (struct mbuf *)0, &tp->t_inpcb->inp_route,
659 so->so_options & SO_DONTROUTE);
660/* #endif */
661#endif
662 }
663 if (error)
664 {
665out:
666#if 0
667 if (error == ENOBUFS)
668 {
669 tcp_quench(tp->t_inpcb, 0);
670 return (0);
671 }
672
673 if ( ( error == EHOSTUNREACH
674 || error == ENETDOWN)
675 && TCPS_HAVERCVDSYN(tp->t_state))
676 {
677 tp->t_softerror = error;
678 return (0);
679 }
680#endif
681 if (m != NULL)
682 m_free(pData, m);
683 return (error);
684 }
685 tcpstat.tcps_sndtotal++;
686
687 /*
688 * Data sent (as far as we can tell).
689 * If this advertises a larger window than any other segment,
690 * then remember the size of the advertised window.
691 * Any pending ACK has now been sent.
692 */
693 if (win > 0 && SEQ_GT(tp->rcv_nxt+win, tp->rcv_adv))
694 tp->rcv_adv = tp->rcv_nxt + win;
695 tp->last_ack_sent = tp->rcv_nxt;
696 tp->t_flags &= ~(TF_ACKNOW|TF_DELACK);
697 if (sendalot)
698 goto again;
699
700 return (0);
701}
702
703void
704tcp_setpersist(struct tcpcb *tp)
705{
706 int t = ((tp->t_srtt >> 2) + tp->t_rttvar) >> 1;
707
708#if 0
709 if (tp->t_timer[TCPT_REXMT])
710 panic("tcp_output REXMT");
711#endif
712 /*
713 * Start/restart persistence timer.
714 */
715 TCPT_RANGESET(tp->t_timer[TCPT_PERSIST],
716 t * tcp_backoff[tp->t_rxtshift],
717 TCPTV_PERSMIN, TCPTV_PERSMAX);
718 if (tp->t_rxtshift < TCP_MAXRXTSHIFT)
719 tp->t_rxtshift++;
720}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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