+ /* Automatic sizing of send socket buffer. Increase the send socket buffer
+ * size if all of the following criteria are met
+ * 1. the receiver has enough buffer space for this data
+ * 2. send buffer is filled to 7/8th with data (so we actually
+ * have data to make use of it);
+ * 3. our send window (slow start and congestion controlled) is
+ * larger than sent but unacknowledged data in send buffer.
+ */
+ basertt = get_base_rtt(tp);
+ if (tcp_do_autosendbuf == 1 &&
+ !INP_WAIT_FOR_IF_FEEDBACK(tp->t_inpcb) && !IN_FASTRECOVERY(tp) &&
+ (so->so_snd.sb_flags & (SB_AUTOSIZE | SB_TRIM)) == SB_AUTOSIZE &&
+ tcp_cansbgrow(&so->so_snd)) {
+ if ((tp->snd_wnd / 4 * 5) >= so->so_snd.sb_hiwat &&
+ so->so_snd.sb_cc >= (so->so_snd.sb_hiwat / 8 * 7) &&
+ sendwin >= (so->so_snd.sb_cc -
+ (tp->snd_nxt - tp->snd_una))) {
+ /* Also increase the send buffer only if the
+ * round-trip time is not increasing because we do
+ * not want to contribute to latency by filling buffers.
+ * We also do not want to hold onto application's
+ * old data for too long. Interactive applications would
+ * rather discard old data.
+ */
+ if (tp->t_rttcur <=
+ (basertt + 25)) {
+ if (sbreserve(&so->so_snd,
+ min(so->so_snd.sb_hiwat + tcp_autosndbuf_inc,
+ tcp_autosndbuf_max)) == 1) {
+ so->so_snd.sb_idealsize = so->so_snd.sb_hiwat;
+ }
+ } else {
+ so->so_snd.sb_idealsize =
+ max(tcp_sendspace, so->so_snd.sb_hiwat -
+ (2 * tcp_autosndbuf_inc));
+ so->so_snd.sb_flags |= SB_TRIM;
+ }
+ }
+ }
+
+ /*
+ * Truncate to the maximum segment length or enable TCP Segmentation
+ * Offloading (if supported by hardware) and ensure that FIN is removed
+ * if the length no longer contains the last data byte.
+ *
+ * TSO may only be used if we are in a pure bulk sending state. The
+ * presence of TCP-MD5, SACK retransmits, SACK advertizements, ipfw rules
+ * and IP options prevent using TSO. With TSO the TCP header is the same
+ * (except for the sequence number) for all generated packets. This
+ * makes it impossible to transmit any options which vary per generated
+ * segment or packet.
+ *
+ * The length of TSO bursts is limited to TCP_MAXWIN. That limit and
+ * removal of FIN (if not already catched here) are handled later after
+ * the exact length of the TCP options are known.
+ */
+#if IPSEC