Deleted Added
full compact
tcp_output.c (274376) tcp_output.c (274421)
1/*-
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
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

--- 16 unchanged lines hidden (view full) ---

25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)tcp_output.c 8.4 (Berkeley) 5/24/95
30 */
31
32#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
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

--- 16 unchanged lines hidden (view full) ---

25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)tcp_output.c 8.4 (Berkeley) 5/24/95
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD: head/sys/netinet/tcp_output.c 274376 2014-11-11 12:05:59Z hselasky $");
33__FBSDID("$FreeBSD: head/sys/netinet/tcp_output.c 274421 2014-11-12 09:57:15Z glebius $");
34
35#include "opt_inet.h"
36#include "opt_inet6.h"
37#include "opt_ipsec.h"
38#include "opt_tcpdebug.h"
39
40#include <sys/param.h>
41#include <sys/systm.h>

--- 275 unchanged lines hidden (view full) ---

317 * up sending the packet without recording
318 * that we sent the FIN bit.
319 *
320 * We can't just blindly clear the FIN bit,
321 * because if we don't have any more data
322 * to send then the probe will be the FIN
323 * itself.
324 */
34
35#include "opt_inet.h"
36#include "opt_inet6.h"
37#include "opt_ipsec.h"
38#include "opt_tcpdebug.h"
39
40#include <sys/param.h>
41#include <sys/systm.h>

--- 275 unchanged lines hidden (view full) ---

317 * up sending the packet without recording
318 * that we sent the FIN bit.
319 *
320 * We can't just blindly clear the FIN bit,
321 * because if we don't have any more data
322 * to send then the probe will be the FIN
323 * itself.
324 */
325 if (off < so->so_snd.sb_cc)
325 if (off < sbused(&so->so_snd))
326 flags &= ~TH_FIN;
327 sendwin = 1;
328 } else {
329 tcp_timer_activate(tp, TT_PERSIST, 0);
330 tp->t_rxtshift = 0;
331 }
332 }
333

--- 9 unchanged lines hidden (view full) ---

343 * be set to snd_una, the offset will be 0, and the length may
344 * wind up 0.
345 *
346 * If sack_rxmit is true we are retransmitting from the scoreboard
347 * in which case len is already set.
348 */
349 if (sack_rxmit == 0) {
350 if (sack_bytes_rxmt == 0)
326 flags &= ~TH_FIN;
327 sendwin = 1;
328 } else {
329 tcp_timer_activate(tp, TT_PERSIST, 0);
330 tp->t_rxtshift = 0;
331 }
332 }
333

--- 9 unchanged lines hidden (view full) ---

343 * be set to snd_una, the offset will be 0, and the length may
344 * wind up 0.
345 *
346 * If sack_rxmit is true we are retransmitting from the scoreboard
347 * in which case len is already set.
348 */
349 if (sack_rxmit == 0) {
350 if (sack_bytes_rxmt == 0)
351 len = ((long)ulmin(so->so_snd.sb_cc, sendwin) - off);
351 len = ((long)ulmin(sbavail(&so->so_snd), sendwin) -
352 off);
352 else {
353 long cwin;
354
355 /*
356 * We are inside of a SACK recovery episode and are
357 * sending new data, having retransmitted all the
358 * data possible in the scoreboard.
359 */
353 else {
354 long cwin;
355
356 /*
357 * We are inside of a SACK recovery episode and are
358 * sending new data, having retransmitted all the
359 * data possible in the scoreboard.
360 */
360 len = ((long)ulmin(so->so_snd.sb_cc, tp->snd_wnd)
361 - off);
361 len = ((long)ulmin(sbavail(&so->so_snd), tp->snd_wnd) -
362 off);
362 /*
363 * Don't remove this (len > 0) check !
364 * We explicitly check for len > 0 here (although it
365 * isn't really necessary), to work around a gcc
366 * optimization issue - to force gcc to compute
367 * len above. Without this check, the computation
368 * of len is bungled by the optimizer.
369 */

--- 82 unchanged lines hidden (view full) ---

452 * delay*bandwith product. However testing has shown this not
453 * to be much of an problem. At worst we are trading wasting
454 * of available bandwith (the non-use of it) for wasting some
455 * socket buffer memory.
456 *
457 * TODO: Shrink send buffer during idle periods together
458 * with congestion window. Requires another timer. Has to
459 * wait for upcoming tcp timer rewrite.
363 /*
364 * Don't remove this (len > 0) check !
365 * We explicitly check for len > 0 here (although it
366 * isn't really necessary), to work around a gcc
367 * optimization issue - to force gcc to compute
368 * len above. Without this check, the computation
369 * of len is bungled by the optimizer.
370 */

--- 82 unchanged lines hidden (view full) ---

453 * delay*bandwith product. However testing has shown this not
454 * to be much of an problem. At worst we are trading wasting
455 * of available bandwith (the non-use of it) for wasting some
456 * socket buffer memory.
457 *
458 * TODO: Shrink send buffer during idle periods together
459 * with congestion window. Requires another timer. Has to
460 * wait for upcoming tcp timer rewrite.
461 *
462 * XXXGL: should there be used sbused() or sbavail()?
460 */
461 if (V_tcp_do_autosndbuf && so->so_snd.sb_flags & SB_AUTOSIZE) {
462 if ((tp->snd_wnd / 4 * 5) >= so->so_snd.sb_hiwat &&
463 */
464 if (V_tcp_do_autosndbuf && so->so_snd.sb_flags & SB_AUTOSIZE) {
465 if ((tp->snd_wnd / 4 * 5) >= so->so_snd.sb_hiwat &&
463 so->so_snd.sb_cc >= (so->so_snd.sb_hiwat / 8 * 7) &&
464 so->so_snd.sb_cc < V_tcp_autosndbuf_max &&
465 sendwin >= (so->so_snd.sb_cc - (tp->snd_nxt - tp->snd_una))) {
466 sbused(&so->so_snd) >= (so->so_snd.sb_hiwat / 8 * 7) &&
467 sbused(&so->so_snd) < V_tcp_autosndbuf_max &&
468 sendwin >= (sbused(&so->so_snd) -
469 (tp->snd_nxt - tp->snd_una))) {
466 if (!sbreserve_locked(&so->so_snd,
467 min(so->so_snd.sb_hiwat + V_tcp_autosndbuf_inc,
468 V_tcp_autosndbuf_max), so, curthread))
469 so->so_snd.sb_flags &= ~SB_AUTOSIZE;
470 }
471 }
472
473 /*

--- 20 unchanged lines hidden (view full) ---

494#ifdef IPSEC
495 ipsec_optlen == 0 &&
496#endif
497 tp->t_inpcb->inp_options == NULL &&
498 tp->t_inpcb->in6p_options == NULL)
499 tso = 1;
500
501 if (sack_rxmit) {
470 if (!sbreserve_locked(&so->so_snd,
471 min(so->so_snd.sb_hiwat + V_tcp_autosndbuf_inc,
472 V_tcp_autosndbuf_max), so, curthread))
473 so->so_snd.sb_flags &= ~SB_AUTOSIZE;
474 }
475 }
476
477 /*

--- 20 unchanged lines hidden (view full) ---

498#ifdef IPSEC
499 ipsec_optlen == 0 &&
500#endif
501 tp->t_inpcb->inp_options == NULL &&
502 tp->t_inpcb->in6p_options == NULL)
503 tso = 1;
504
505 if (sack_rxmit) {
502 if (SEQ_LT(p->rxmit + len, tp->snd_una + so->so_snd.sb_cc))
506 if (SEQ_LT(p->rxmit + len, tp->snd_una + sbused(&so->so_snd)))
503 flags &= ~TH_FIN;
504 } else {
507 flags &= ~TH_FIN;
508 } else {
505 if (SEQ_LT(tp->snd_nxt + len, tp->snd_una + so->so_snd.sb_cc))
509 if (SEQ_LT(tp->snd_nxt + len, tp->snd_una +
510 sbused(&so->so_snd)))
506 flags &= ~TH_FIN;
507 }
508
509 recwin = sbspace(&so->so_rcv);
510
511 /*
512 * Sender silly window avoidance. We transmit under the following
513 * conditions when len is non-zero:

--- 13 unchanged lines hidden (view full) ---

527 * NOTE! on localhost connections an 'ack' from the remote
528 * end may occur synchronously with the output and cause
529 * us to flush a buffer queued with moretocome. XXX
530 *
531 * note: the len + off check is almost certainly unnecessary.
532 */
533 if (!(tp->t_flags & TF_MORETOCOME) && /* normal case */
534 (idle || (tp->t_flags & TF_NODELAY)) &&
511 flags &= ~TH_FIN;
512 }
513
514 recwin = sbspace(&so->so_rcv);
515
516 /*
517 * Sender silly window avoidance. We transmit under the following
518 * conditions when len is non-zero:

--- 13 unchanged lines hidden (view full) ---

532 * NOTE! on localhost connections an 'ack' from the remote
533 * end may occur synchronously with the output and cause
534 * us to flush a buffer queued with moretocome. XXX
535 *
536 * note: the len + off check is almost certainly unnecessary.
537 */
538 if (!(tp->t_flags & TF_MORETOCOME) && /* normal case */
539 (idle || (tp->t_flags & TF_NODELAY)) &&
535 len + off >= so->so_snd.sb_cc &&
540 len + off >= sbavail(&so->so_snd) &&
536 (tp->t_flags & TF_NOPUSH) == 0) {
537 goto send;
538 }
539 if (tp->t_flags & TF_FORCEDATA) /* typ. timeout case */
540 goto send;
541 if (len >= tp->max_sndwnd / 2 && tp->max_sndwnd > 0)
542 goto send;
543 if (SEQ_LT(tp->snd_nxt, tp->snd_max)) /* retransmit case */

--- 111 unchanged lines hidden (view full) ---

655 * The output side is idle when both timers are zero.
656 *
657 * If send window is too small, there is data to transmit, and no
658 * retransmit or persist is pending, then go to persist state.
659 * If nothing happens soon, send when timer expires:
660 * if window is nonzero, transmit what we can,
661 * otherwise force out a byte.
662 */
541 (tp->t_flags & TF_NOPUSH) == 0) {
542 goto send;
543 }
544 if (tp->t_flags & TF_FORCEDATA) /* typ. timeout case */
545 goto send;
546 if (len >= tp->max_sndwnd / 2 && tp->max_sndwnd > 0)
547 goto send;
548 if (SEQ_LT(tp->snd_nxt, tp->snd_max)) /* retransmit case */

--- 111 unchanged lines hidden (view full) ---

660 * The output side is idle when both timers are zero.
661 *
662 * If send window is too small, there is data to transmit, and no
663 * retransmit or persist is pending, then go to persist state.
664 * If nothing happens soon, send when timer expires:
665 * if window is nonzero, transmit what we can,
666 * otherwise force out a byte.
667 */
663 if (so->so_snd.sb_cc && !tcp_timer_active(tp, TT_REXMT) &&
668 if (sbavail(&so->so_snd) && !tcp_timer_active(tp, TT_REXMT) &&
664 !tcp_timer_active(tp, TT_PERSIST)) {
665 tp->t_rxtshift = 0;
666 tcp_setpersist(tp);
667 }
668
669 /*
670 * No reason to send a segment, just return.
671 */

--- 186 unchanged lines hidden (view full) ---

858 }
859
860 /*
861 * Prevent the last segment from being
862 * fractional unless the send sockbuf can be
863 * emptied:
864 */
865 max_len = (tp->t_maxopd - optlen);
669 !tcp_timer_active(tp, TT_PERSIST)) {
670 tp->t_rxtshift = 0;
671 tcp_setpersist(tp);
672 }
673
674 /*
675 * No reason to send a segment, just return.
676 */

--- 186 unchanged lines hidden (view full) ---

863 }
864
865 /*
866 * Prevent the last segment from being
867 * fractional unless the send sockbuf can be
868 * emptied:
869 */
870 max_len = (tp->t_maxopd - optlen);
866 if ((off + len) < so->so_snd.sb_cc) {
871 if ((off + len) < sbavail(&so->so_snd)) {
867 moff = len % max_len;
868 if (moff != 0) {
869 len -= moff;
870 sendalot = 1;
871 }
872 }
873
874 /*

--- 99 unchanged lines hidden (view full) ---

974 }
975
976 /*
977 * If we're sending everything we've got, set PUSH.
978 * (This will keep happy those implementations which only
979 * give data to the user when a buffer fills or
980 * a PUSH comes in.)
981 */
872 moff = len % max_len;
873 if (moff != 0) {
874 len -= moff;
875 sendalot = 1;
876 }
877 }
878
879 /*

--- 99 unchanged lines hidden (view full) ---

979 }
980
981 /*
982 * If we're sending everything we've got, set PUSH.
983 * (This will keep happy those implementations which only
984 * give data to the user when a buffer fills or
985 * a PUSH comes in.)
986 */
982 if (off + len == so->so_snd.sb_cc)
987 if (off + len == sbused(&so->so_snd))
983 flags |= TH_PUSH;
984 SOCKBUF_UNLOCK(&so->so_snd);
985 } else {
986 SOCKBUF_UNLOCK(&so->so_snd);
987 if (tp->t_flags & TF_ACKNOW)
988 TCPSTAT_INC(tcps_sndacks);
989 else if (flags & (TH_SYN|TH_FIN|TH_RST))
990 TCPSTAT_INC(tcps_sndctrl);

--- 689 unchanged lines hidden ---
988 flags |= TH_PUSH;
989 SOCKBUF_UNLOCK(&so->so_snd);
990 } else {
991 SOCKBUF_UNLOCK(&so->so_snd);
992 if (tp->t_flags & TF_ACKNOW)
993 TCPSTAT_INC(tcps_sndacks);
994 else if (flags & (TH_SYN|TH_FIN|TH_RST))
995 TCPSTAT_INC(tcps_sndctrl);

--- 689 unchanged lines hidden ---