2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
32 * The Regents of the University of California. All rights reserved.
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by the University of
45 * California, Berkeley and its contributors.
46 * 4. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * @(#)tcp_output.c 8.4 (Berkeley) 5/24/95
63 * $FreeBSD: src/sys/netinet/tcp_output.c,v 1.39.2.10 2001/07/07 04:30:38 silby Exp $
69 #include <sys/param.h>
70 #include <sys/systm.h>
71 #include <sys/kernel.h>
72 #include <sys/sysctl.h>
74 #include <sys/domain.h>
75 #include <sys/protosw.h>
76 #include <sys/socket.h>
77 #include <sys/socketvar.h>
79 #include <net/route.h>
81 #include <netinet/in.h>
82 #include <netinet/in_systm.h>
83 #include <netinet/ip.h>
84 #include <netinet/in_pcb.h>
85 #include <netinet/ip_var.h>
87 #include <netinet6/in6_pcb.h>
88 #include <netinet/ip6.h>
89 #include <netinet6/ip6_var.h>
91 #include <netinet/tcp.h>
93 #include <netinet/tcp_fsm.h>
94 #include <netinet/tcp_seq.h>
95 #include <netinet/tcp_timer.h>
96 #include <netinet/tcp_var.h>
97 #include <netinet/tcpip.h>
99 #include <netinet/tcp_debug.h>
101 #include <sys/kdebug.h>
104 #include <netinet6/ipsec.h>
107 #define DBG_LAYER_BEG NETDBG_CODE(DBG_NETTCP, 1)
108 #define DBG_LAYER_END NETDBG_CODE(DBG_NETTCP, 3)
109 #define DBG_FNC_TCP_OUTPUT NETDBG_CODE(DBG_NETTCP, (4 << 8) | 1)
113 extern struct mbuf
*m_copypack();
116 static int path_mtu_discovery
= 1;
117 SYSCTL_INT(_net_inet_tcp
, OID_AUTO
, path_mtu_discovery
, CTLFLAG_RW
,
118 &path_mtu_discovery
, 1, "Enable Path MTU Discovery");
121 SYSCTL_INT(_net_inet_tcp
, OID_AUTO
, slowstart_flightsize
, CTLFLAG_RW
,
122 &ss_fltsz
, 1, "Slow start flight size");
124 int ss_fltsz_local
= 4; /* starts with four segments max */
125 SYSCTL_INT(_net_inet_tcp
, OID_AUTO
, local_slowstart_flightsize
, CTLFLAG_RW
,
126 &ss_fltsz_local
, 1, "Slow start flight size for local networks");
128 int tcp_do_newreno
= 0;
129 SYSCTL_INT(_net_inet_tcp
, OID_AUTO
, newreno
, CTLFLAG_RW
, &tcp_do_newreno
,
130 0, "Enable NewReno Algorithms");
132 int tcp_packet_chaining
= 50;
133 SYSCTL_INT(_net_inet_tcp
, OID_AUTO
, packetchain
, CTLFLAG_RW
, &tcp_packet_chaining
,
134 0, "Enable TCP output packet chaining");
136 struct mbuf
*m_copym_with_hdrs(struct mbuf
*, int, int, int, struct mbuf
**, int*);
137 static long packchain_newlist
= 0;
138 static long packchain_looped
= 0;
139 static long packchain_sent
= 0;
142 /* temporary: for testing */
144 extern int ipsec_bypass
;
147 extern int slowlink_wsize
; /* window correction for slow links */
148 extern u_long route_generation
;
149 extern int fw_enable
; /* firewall is on: disable packet chaining */
150 extern int ipsec_bypass
;
152 extern vm_size_t so_cache_zone_element_size
;
154 static __inline__ u_int16_t
155 get_socket_id(struct socket
* s
)
159 if (so_cache_zone_element_size
== 0) {
162 val
= (u_int16_t
)(((u_int32_t
)s
) / so_cache_zone_element_size
);
170 * Tcp output routine: figure out what should be sent and send it.
173 tcp_output(struct tcpcb
*tp
)
175 struct socket
*so
= tp
->t_inpcb
->inp_socket
;
176 long len
, recwin
, sendwin
;
177 int off
, flags
, error
;
178 register struct mbuf
*m
;
179 struct ip
*ip
= NULL
;
180 register struct ipovly
*ipov
= NULL
;
182 struct ip6_hdr
*ip6
= NULL
;
184 register struct tcphdr
*th
;
185 u_char opt
[TCP_MAXOLEN
];
186 unsigned ipoptlen
, optlen
, hdrlen
;
187 int idle
, sendalot
, howmuchsent
= 0;
192 int maxburst
= TCP_MAXBURST
;
193 struct rmxp_tao
*taop
;
194 struct rmxp_tao tao_noncached
;
197 struct mbuf
*m_last
= 0;
198 struct mbuf
*m_head
= 0;
199 struct mbuf
*packetlist
= 0;
200 struct mbuf
*lastpacket
= 0;
202 int isipv6
= tp
->t_inpcb
->inp_vflag
& INP_IPV6
;
204 short packchain_listadd
= 0;
205 u_int16_t socket_id
= get_socket_id(so
);
209 * Determine length of data that should be transmitted,
210 * and flags that will be used.
211 * If there is some data or critical controls (SYN, RST)
212 * to send, then transmit; otherwise, investigate further.
214 idle
= (tp
->t_flags
& TF_LASTIDLE
) || (tp
->snd_max
== tp
->snd_una
);
215 if (idle
&& tp
->t_rcvtime
>= tp
->t_rxtcur
) {
217 * We have been idle for "a while" and no acks are
218 * expected to clock out any data we send --
219 * slow start to get ack "clock" running again.
221 * Set the slow-start flight size depending on whether
222 * this is a local network or not.
226 (isipv6
&& in6_localaddr(&tp
->t_inpcb
->in6p_faddr
)) ||
229 in_localaddr(tp
->t_inpcb
->inp_faddr
)
234 tp
->snd_cwnd
= tp
->t_maxseg
* ss_fltsz_local
;
236 tp
->snd_cwnd
= tp
->t_maxseg
* ss_fltsz
;
238 tp
->t_flags
&= ~TF_LASTIDLE
;
240 if (tp
->t_flags
& TF_MORETOCOME
) {
241 tp
->t_flags
|= TF_LASTIDLE
;
246 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT
| DBG_FUNC_START
, 0,0,0,0,0);
251 KERNEL_DEBUG(DBG_LAYER_BEG
,
252 ((tp
->t_inpcb
->inp_fport
<< 16) | tp
->t_inpcb
->inp_lport
),
253 (((tp
->t_inpcb
->in6p_laddr
.s6_addr16
[0] & 0xffff) << 16) |
254 (tp
->t_inpcb
->in6p_faddr
.s6_addr16
[0] & 0xffff)),
261 KERNEL_DEBUG(DBG_LAYER_BEG
,
262 ((tp
->t_inpcb
->inp_fport
<< 16) | tp
->t_inpcb
->inp_lport
),
263 (((tp
->t_inpcb
->inp_laddr
.s_addr
& 0xffff) << 16) |
264 (tp
->t_inpcb
->inp_faddr
.s_addr
& 0xffff)),
267 * If the route generation id changed, we need to check that our
268 * local (source) IP address is still valid. If it isn't either
269 * return error or silently do nothing (assuming the address will
270 * come back before the TCP connection times out).
273 if ((tp
->t_inpcb
->inp_route
.ro_rt
!= NULL
&&
274 (tp
->t_inpcb
->inp_route
.ro_rt
->generation_id
!= route_generation
)) || (tp
->t_inpcb
->inp_route
.ro_rt
== NULL
)) {
275 /* check that the source address is still valid */
276 if (ifa_foraddr(tp
->t_inpcb
->inp_laddr
.s_addr
) == 0) {
277 if (tp
->t_state
>= TCPS_CLOSE_WAIT
) {
279 return(EADDRNOTAVAIL
);
282 /* set Retransmit timer if it wasn't set
283 * reset Persist timer and shift register as the
284 * adversed peer window may not be valid anymore
287 if (!tp
->t_timer
[TCPT_REXMT
]) {
288 tp
->t_timer
[TCPT_REXMT
] = tp
->t_rxtcur
;
289 if (tp
->t_timer
[TCPT_PERSIST
]) {
290 tp
->t_timer
[TCPT_PERSIST
] = 0;
296 error
= ip_output_list(packetlist
, packchain_listadd
, tp
->t_inpcb
->inp_options
, &tp
->t_inpcb
->inp_route
,
297 (so
->so_options
& SO_DONTROUTE
), 0);
300 if (so
->so_flags
& SOF_NOADDRAVAIL
)
301 return(EADDRNOTAVAIL
);
303 return(0); /* silently ignore and keep data in socket */
309 * If we've recently taken a timeout, snd_max will be greater than
310 * snd_nxt. There may be SACK information that allows us to avoid
311 * resending already delivered data. Adjust snd_nxt accordingly.
313 if (tp
->sack_enable
&& SEQ_LT(tp
->snd_nxt
, tp
->snd_max
))
316 off
= tp
->snd_nxt
- tp
->snd_una
;
317 sendwin
= min(tp
->snd_wnd
, tp
->snd_cwnd
);
319 if (tp
->t_flags
& TF_SLOWLINK
&& slowlink_wsize
> 0)
320 sendwin
= min(sendwin
, slowlink_wsize
);
322 flags
= tcp_outflags
[tp
->t_state
];
324 * Send any SACK-generated retransmissions. If we're explicitly trying
325 * to send out new data (when sendalot is 1), bypass this function.
326 * If we retransmit in fast recovery mode, decrement snd_cwnd, since
327 * we're replacing a (future) new transmission with a retransmission
328 * now, and we previously incremented snd_cwnd in tcp_input().
331 * Still in sack recovery , reset rxmit flag to zero.
337 if (tp
->sack_enable
&& IN_FASTRECOVERY(tp
) &&
338 (p
= tcp_sack_output(tp
, &sack_bytes_rxmt
))) {
341 cwin
= min(tp
->snd_wnd
, tp
->snd_cwnd
) - sack_bytes_rxmt
;
344 /* Do not retransmit SACK segments beyond snd_recover */
345 if (SEQ_GT(p
->end
, tp
->snd_recover
)) {
347 * (At least) part of sack hole extends beyond
348 * snd_recover. Check to see if we can rexmit data
351 if (SEQ_GEQ(p
->rxmit
, tp
->snd_recover
)) {
353 * Can't rexmit any more data for this hole.
354 * That data will be rexmitted in the next
355 * sack recovery episode, when snd_recover
356 * moves past p->rxmit.
359 goto after_sack_rexmit
;
361 /* Can rexmit part of the current hole */
362 len
= ((long)ulmin(cwin
,
363 tp
->snd_recover
- p
->rxmit
));
365 len
= ((long)ulmin(cwin
, p
->end
- p
->rxmit
));
366 off
= p
->rxmit
- tp
->snd_una
;
370 tcpstat
.tcps_sack_rexmits
++;
371 tcpstat
.tcps_sack_rexmit_bytes
+=
372 min(len
, tp
->t_maxseg
);
377 * Get standard flags, and add SYN or FIN if requested by 'hidden'
380 if (tp
->t_flags
& TF_NEEDFIN
)
382 if (tp
->t_flags
& TF_NEEDSYN
)
386 * If in persist timeout with window of 0, send 1 byte.
387 * Otherwise, if window is small but nonzero
388 * and timer expired, we will send what we can
389 * and go to transmit state.
394 * If we still have some data to send, then
395 * clear the FIN bit. Usually this would
396 * happen below when it realizes that we
397 * aren't sending all the data. However,
398 * if we have exactly 1 byte of unsent data,
399 * then it won't clear the FIN bit below,
400 * and if we are in persist state, we wind
401 * up sending the packet without recording
402 * that we sent the FIN bit.
404 * We can't just blindly clear the FIN bit,
405 * because if we don't have any more data
406 * to send then the probe will be the FIN
409 if (off
< so
->so_snd
.sb_cc
)
413 tp
->t_timer
[TCPT_PERSIST
] = 0;
419 * If snd_nxt == snd_max and we have transmitted a FIN, the
420 * offset will be > 0 even if so_snd.sb_cc is 0, resulting in
421 * a negative length. This can also occur when TCP opens up
422 * its congestion window while receiving additional duplicate
423 * acks after fast-retransmit because TCP will reset snd_nxt
424 * to snd_max after the fast-retransmit.
426 * In the normal retransmit-FIN-only case, however, snd_nxt will
427 * be set to snd_una, the offset will be 0, and the length may
430 * If sack_rxmit is true we are retransmitting from the scoreboard
431 * in which case len is already set.
433 if (sack_rxmit
== 0) {
434 if (sack_bytes_rxmt
== 0)
435 len
= ((long)ulmin(so
->so_snd
.sb_cc
, sendwin
) - off
);
440 * We are inside of a SACK recovery episode and are
441 * sending new data, having retransmitted all the
442 * data possible in the scoreboard.
444 len
= ((long)ulmin(so
->so_snd
.sb_cc
, tp
->snd_wnd
)
447 * Don't remove this (len > 0) check !
448 * We explicitly check for len > 0 here (although it
449 * isn't really necessary), to work around a gcc
450 * optimization issue - to force gcc to compute
451 * len above. Without this check, the computation
452 * of len is bungled by the optimizer.
455 cwin
= tp
->snd_cwnd
-
456 (tp
->snd_nxt
- tp
->sack_newdata
) -
460 len
= lmin(len
, cwin
);
466 * Lop off SYN bit if it has already been sent. However, if this
467 * is SYN-SENT state and if segment contains data and if we don't
468 * know that foreign host supports TAO, suppress sending segment.
470 if ((flags
& TH_SYN
) && SEQ_GT(tp
->snd_nxt
, tp
->snd_una
)) {
473 if (len
> 0 && tp
->t_state
== TCPS_SYN_SENT
) {
475 error
= ip_output_list(packetlist
, packchain_listadd
, tp
->t_inpcb
->inp_options
, &tp
->t_inpcb
->inp_route
,
476 (so
->so_options
& SO_DONTROUTE
), 0);
479 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT
| DBG_FUNC_END
, 0,0,0,0,0);
485 * Be careful not to send data and/or FIN on SYN segments.
486 * This measure is needed to prevent interoperability problems
487 * with not fully conformant TCP implementations.
489 if ((flags
& TH_SYN
) && (tp
->t_flags
& TF_NOOPT
)) {
496 * If FIN has been sent but not acked,
497 * but we haven't been called to retransmit,
498 * len will be < 0. Otherwise, window shrank
499 * after we sent into it. If window shrank to 0,
500 * cancel pending retransmit, pull snd_nxt back
501 * to (closed) window, and set the persist timer
502 * if it isn't already going. If the window didn't
503 * close completely, just wait for an ACK.
507 tp
->t_timer
[TCPT_REXMT
] = 0;
509 tp
->snd_nxt
= tp
->snd_una
;
510 if (tp
->t_timer
[TCPT_PERSIST
] == 0)
516 * len will be >= 0 after this point. Truncate to the maximum
517 * segment length and ensure that FIN is removed if the length
518 * no longer contains the last data byte.
520 if (len
> tp
->t_maxseg
) {
526 if (SEQ_LT(p
->rxmit
+ len
, tp
->snd_una
+ so
->so_snd
.sb_cc
))
529 if (SEQ_LT(tp
->snd_nxt
+ len
, tp
->snd_una
+ so
->so_snd
.sb_cc
))
533 if (tp
->t_flags
& TF_SLOWLINK
&& slowlink_wsize
> 0 ) /* Clips window size for slow links */
534 recwin
= min(sbspace(&so
->so_rcv
), slowlink_wsize
);
536 recwin
= sbspace(&so
->so_rcv
);
539 * Sender silly window avoidance. We transmit under the following
540 * conditions when len is non-zero:
542 * - We have a full segment
543 * - This is the last buffer in a write()/send() and we are
544 * either idle or running NODELAY
545 * - we've timed out (e.g. persist timer)
546 * - we have more then 1/2 the maximum send window's worth of
547 * data (receiver may be limited the window size)
548 * - we need to retransmit
551 if (len
== tp
->t_maxseg
)
553 if (!(tp
->t_flags
& TF_MORETOCOME
) &&
554 (idle
|| tp
->t_flags
& TF_NODELAY
) &&
555 (tp
->t_flags
& TF_NOPUSH
) == 0 &&
556 len
+ off
>= so
->so_snd
.sb_cc
)
560 if (len
>= tp
->max_sndwnd
/ 2 && tp
->max_sndwnd
> 0)
562 if (SEQ_LT(tp
->snd_nxt
, tp
->snd_max
)) /* retransmit case */
569 * Compare available window to amount of window
570 * known to peer (as advertised window less
571 * next expected input). If the difference is at least two
572 * max size segments, or at least 50% of the maximum possible
573 * window, then want to send a window update to peer.
574 * Skip this if the connection is in T/TCP half-open state.
576 if (recwin
> 0 && !(tp
->t_flags
& TF_NEEDSYN
)) {
578 * "adv" is the amount we can increase the window,
579 * taking into account that we are limited by
580 * TCP_MAXWIN << tp->rcv_scale.
582 long adv
= min(recwin
, (long)TCP_MAXWIN
<< tp
->rcv_scale
) -
583 (tp
->rcv_adv
- tp
->rcv_nxt
);
585 if (adv
>= (long) (2 * tp
->t_maxseg
))
587 if (2 * adv
>= (long) so
->so_rcv
.sb_hiwat
)
592 * Send if we owe the peer an ACK, RST, SYN, or urgent data. ACKNOW
593 * is also a catch-all for the retransmit timer timeout case.
595 if (tp
->t_flags
& TF_ACKNOW
)
597 if ((flags
& TH_RST
) ||
598 ((flags
& TH_SYN
) && (tp
->t_flags
& TF_NEEDSYN
) == 0))
600 if (SEQ_GT(tp
->snd_up
, tp
->snd_una
))
603 * If our state indicates that FIN should be sent
604 * and we have not yet done so, then we need to send.
606 if (flags
& TH_FIN
&&
607 ((tp
->t_flags
& TF_SENTFIN
) == 0 || tp
->snd_nxt
== tp
->snd_una
))
610 * In SACK, it is possible for tcp_output to fail to send a segment
611 * after the retransmission timer has been turned off. Make sure
612 * that the retransmission timer is set.
614 if (tp
->sack_enable
&& SEQ_GT(tp
->snd_max
, tp
->snd_una
) &&
615 tp
->t_timer
[TCPT_REXMT
] == 0 &&
616 tp
->t_timer
[TCPT_PERSIST
] == 0) {
617 tp
->t_timer
[TCPT_REXMT
] = tp
->t_rxtcur
;
621 * TCP window updates are not reliable, rather a polling protocol
622 * using ``persist'' packets is used to insure receipt of window
623 * updates. The three ``states'' for the output side are:
624 * idle not doing retransmits or persists
625 * persisting to move a small or zero window
626 * (re)transmitting and thereby not persisting
628 * tp->t_timer[TCPT_PERSIST]
629 * is set when we are in persist state.
631 * is set when we are called to send a persist packet.
632 * tp->t_timer[TCPT_REXMT]
633 * is set when we are retransmitting
634 * The output side is idle when both timers are zero.
636 * If send window is too small, there is data to transmit, and no
637 * retransmit or persist is pending, then go to persist state.
638 * If nothing happens soon, send when timer expires:
639 * if window is nonzero, transmit what we can,
640 * otherwise force out a byte.
642 if (so
->so_snd
.sb_cc
&& tp
->t_timer
[TCPT_REXMT
] == 0 &&
643 tp
->t_timer
[TCPT_PERSIST
] == 0) {
649 * If there is no reason to send a segment, just return.
650 * but if there is some packets left in the packet list, send them now.
653 error
= ip_output_list(packetlist
, packchain_listadd
, tp
->t_inpcb
->inp_options
, &tp
->t_inpcb
->inp_route
,
654 (so
->so_options
& SO_DONTROUTE
), 0);
656 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT
| DBG_FUNC_END
, 0,0,0,0,0);
661 * Before ESTABLISHED, force sending of initial options
662 * unless TCP set not to do any options.
663 * NOTE: we assume that the IP/TCP header plus TCP options
664 * always fit in a single mbuf, leaving room for a maximum
666 * max_linkhdr + sizeof (struct tcpiphdr) + optlen <= MCLBYTES
671 hdrlen
= sizeof (struct ip6_hdr
) + sizeof (struct tcphdr
);
674 hdrlen
= sizeof (struct tcpiphdr
);
675 if (flags
& TH_SYN
) {
676 tp
->snd_nxt
= tp
->iss
;
677 if ((tp
->t_flags
& TF_NOOPT
) == 0) {
680 opt
[0] = TCPOPT_MAXSEG
;
681 opt
[1] = TCPOLEN_MAXSEG
;
682 mss
= htons((u_short
) tcp_mssopt(tp
));
683 (void)memcpy(opt
+ 2, &mss
, sizeof(mss
));
684 optlen
= TCPOLEN_MAXSEG
;
686 if ((tp
->t_flags
& TF_REQ_SCALE
) &&
687 ((flags
& TH_ACK
) == 0 ||
688 (tp
->t_flags
& TF_RCVD_SCALE
))) {
689 *((u_int32_t
*)(opt
+ optlen
)) = htonl(
691 TCPOPT_WINDOW
<< 16 |
692 TCPOLEN_WINDOW
<< 8 |
693 tp
->request_r_scale
);
700 * Send a timestamp and echo-reply if this is a SYN and our side
701 * wants to use timestamps (TF_REQ_TSTMP is set) or both our side
702 * and our peer have sent timestamps in our SYN's.
704 if ((tp
->t_flags
& (TF_REQ_TSTMP
|TF_NOOPT
)) == TF_REQ_TSTMP
&&
705 (flags
& TH_RST
) == 0 &&
706 ((flags
& TH_ACK
) == 0 ||
707 (tp
->t_flags
& TF_RCVD_TSTMP
))) {
708 u_int32_t
*lp
= (u_int32_t
*)(opt
+ optlen
);
710 /* Form timestamp option as shown in appendix A of RFC 1323. */
711 *lp
++ = htonl(TCPOPT_TSTAMP_HDR
);
712 *lp
++ = htonl(tcp_now
);
713 *lp
= htonl(tp
->ts_recent
);
714 optlen
+= TCPOLEN_TSTAMP_APPA
;
717 if (tp
->sack_enable
&& ((tp
->t_flags
& TF_NOOPT
) == 0)) {
719 * Tack on the SACK permitted option *last*.
720 * And do padding of options after tacking this on.
721 * This is because of MSS, TS, WinScale and Signatures are
722 * all present, we have just 2 bytes left for the SACK
723 * permitted option, which is just enough.
726 * If this is the first SYN of connection (not a SYN
727 * ACK), include SACK permitted option. If this is a
728 * SYN ACK, include SACK permitted option if peer has
729 * already done so. This is only for active connect,
730 * since the syncache takes care of the passive connect.
732 if ((flags
& TH_SYN
) &&
733 (!(flags
& TH_ACK
) || (tp
->t_flags
& TF_SACK_PERMIT
))) {
735 bp
= (u_char
*)opt
+ optlen
;
737 *bp
++ = TCPOPT_SACK_PERMITTED
;
738 *bp
++ = TCPOLEN_SACK_PERMITTED
;
739 optlen
+= TCPOLEN_SACK_PERMITTED
;
743 * Send SACKs if necessary. This should be the last
744 * option processed. Only as many SACKs are sent as
745 * are permitted by the maximum options size.
747 * In general, SACK blocks consume 8*n+2 bytes.
748 * So a full size SACK blocks option is 34 bytes
749 * (to generate 4 SACK blocks). At a minimum,
750 * we need 10 bytes (to generate 1 SACK block).
751 * If TCP Timestamps (12 bytes) and TCP Signatures
752 * (18 bytes) are both present, we'll just have
753 * 10 bytes for SACK options 40 - (12 + 18).
755 if (TCPS_HAVEESTABLISHED(tp
->t_state
) &&
756 (tp
->t_flags
& TF_SACK_PERMIT
) && tp
->rcv_numsacks
> 0 &&
757 MAX_TCPOPTLEN
- optlen
- 2 >= TCPOLEN_SACK
) {
758 int nsack
, sackoptlen
, padlen
;
759 u_char
*bp
= (u_char
*)opt
+ optlen
;
762 nsack
= (MAX_TCPOPTLEN
- optlen
- 2) / TCPOLEN_SACK
;
763 nsack
= min(nsack
, tp
->rcv_numsacks
);
764 sackoptlen
= (2 + nsack
* TCPOLEN_SACK
);
767 * First we need to pad options so that the
768 * SACK blocks can start at a 4-byte boundary
769 * (sack option and length are at a 2 byte offset).
771 padlen
= (MAX_TCPOPTLEN
- optlen
- sackoptlen
) % 4;
776 tcpstat
.tcps_sack_send_blocks
++;
779 lp
= (u_int32_t
*)bp
;
780 for (i
= 0; i
< nsack
; i
++) {
781 struct sackblk sack
= tp
->sackblks
[i
];
782 *lp
++ = htonl(sack
.start
);
783 *lp
++ = htonl(sack
.end
);
785 optlen
+= sackoptlen
;
789 /* Pad TCP options to a 4 byte boundary */
790 if (optlen
< MAX_TCPOPTLEN
&& (optlen
% sizeof(u_int32_t
))) {
791 int pad
= sizeof(u_int32_t
) - (optlen
% sizeof(u_int32_t
));
792 u_char
*bp
= (u_char
*)opt
+ optlen
;
805 ipoptlen
= ip6_optlen(tp
->t_inpcb
);
809 if (tp
->t_inpcb
->inp_options
) {
810 ipoptlen
= tp
->t_inpcb
->inp_options
->m_len
-
811 offsetof(struct ipoption
, ipopt_list
);
816 if (ipsec_bypass
== 0)
817 ipoptlen
+= ipsec_hdrsiz_tcp(tp
);
821 * Adjust data length if insertion of options will
822 * bump the packet length beyond the t_maxopd length.
823 * Clear the FIN bit because we cut off the tail of
826 if (len
+ optlen
+ ipoptlen
> tp
->t_maxopd
) {
828 * If there is still more to send, don't close the connection.
831 len
= tp
->t_maxopd
- optlen
- ipoptlen
;
836 /*#ifdef DIAGNOSTIC*/
838 if (max_linkhdr
+ hdrlen
> MCLBYTES
)
839 panic("tcphdr too big");
841 if (max_linkhdr
+ hdrlen
> MHLEN
)
842 panic("tcphdr too big");
847 * Grab a header mbuf, attaching a copy of data to
848 * be transmitted, and initialize the header from
849 * the template for sends on this connection.
852 if (tp
->t_force
&& len
== 1)
853 tcpstat
.tcps_sndprobe
++;
854 else if (SEQ_LT(tp
->snd_nxt
, tp
->snd_max
)) {
855 tcpstat
.tcps_sndrexmitpack
++;
856 tcpstat
.tcps_sndrexmitbyte
+= len
;
858 tcpstat
.tcps_sndpack
++;
859 tcpstat
.tcps_sndbyte
+= len
;
862 if ((m
= m_copypack(so
->so_snd
.sb_mb
, off
,
863 (int)len
, max_linkhdr
+ hdrlen
)) == 0) {
868 * m_copypack left space for our hdr; use it.
874 * try to use the new interface that allocates all
875 * the necessary mbuf hdrs under 1 mbuf lock and
876 * avoids rescanning the socket mbuf list if
877 * certain conditions are met. This routine can't
878 * be used in the following cases...
879 * 1) the protocol headers exceed the capacity of
880 * of a single mbuf header's data area (no cluster attached)
881 * 2) the length of the data being transmitted plus
882 * the protocol headers fits into a single mbuf header's
883 * data area (no cluster attached)
887 if (MHLEN
< hdrlen
+ max_linkhdr
) {
888 MGETHDR(m
, M_DONTWAIT
, MT_HEADER
);
893 MCLGET(m
, M_DONTWAIT
);
894 if ((m
->m_flags
& M_EXT
) == 0) {
899 m
->m_data
+= max_linkhdr
;
903 if (len
<= MHLEN
- hdrlen
- max_linkhdr
) {
905 MGETHDR(m
, M_DONTWAIT
, MT_HEADER
);
910 m
->m_data
+= max_linkhdr
;
913 /* makes sure we still have data left to be sent at this point */
914 if (so
->so_snd
.sb_mb
== NULL
|| off
== -1) {
915 if (m
!= NULL
) m_freem(m
);
916 error
= 0; /* should we return an error? */
919 m_copydata(so
->so_snd
.sb_mb
, off
, (int) len
,
920 mtod(m
, caddr_t
) + hdrlen
);
924 m
->m_next
= m_copy(so
->so_snd
.sb_mb
, off
, (int) len
);
925 if (m
->m_next
== 0) {
932 * determine whether the mbuf pointer and offset passed back by the 'last' call
933 * to m_copym_with_hdrs are still valid... if the head of the socket chain has
934 * changed (due to an incoming ACK for instance), or the offset into the chain we
935 * just computed is different from the one last returned by m_copym_with_hdrs (perhaps
936 * we're re-transmitting a packet sent earlier), than we can't pass the mbuf pointer and
937 * offset into it as valid hints for m_copym_with_hdrs to use (if valid, these hints allow
938 * m_copym_with_hdrs to avoid rescanning from the beginning of the socket buffer mbuf list.
939 * setting the mbuf pointer to NULL is sufficient to disable the hint mechanism.
941 if (m_head
!= so
->so_snd
.sb_mb
|| last_off
!= off
)
943 last_off
= off
+ len
;
944 m_head
= so
->so_snd
.sb_mb
;
946 /* makes sure we still have data left to be sent at this point */
947 if (m_head
== NULL
) {
948 error
= 0; /* should we return an error? */
953 * m_copym_with_hdrs will always return the last mbuf pointer and the offset into it that
954 * it acted on to fullfill the current request, whether a valid 'hint' was passed in or not
956 if ((m
= m_copym_with_hdrs(so
->so_snd
.sb_mb
, off
, (int) len
, M_DONTWAIT
, &m_last
, &m_off
)) == NULL
) {
960 m
->m_data
+= max_linkhdr
;
966 * If we're sending everything we've got, set PUSH.
967 * (This will keep happy those implementations which only
968 * give data to the user when a buffer fills or
971 if (off
+ len
== so
->so_snd
.sb_cc
)
974 if (tp
->t_flags
& TF_ACKNOW
)
975 tcpstat
.tcps_sndacks
++;
976 else if (flags
& (TH_SYN
|TH_FIN
|TH_RST
))
977 tcpstat
.tcps_sndctrl
++;
978 else if (SEQ_GT(tp
->snd_up
, tp
->snd_una
))
979 tcpstat
.tcps_sndurg
++;
981 tcpstat
.tcps_sndwinup
++;
983 MGETHDR(m
, M_DONTWAIT
, MT_HEADER
);
989 if (isipv6
&& (MHLEN
< hdrlen
+ max_linkhdr
) &&
994 m
->m_data
+= max_linkhdr
;
997 m
->m_pkthdr
.rcvif
= 0;
1000 ip6
= mtod(m
, struct ip6_hdr
*);
1001 th
= (struct tcphdr
*)(ip6
+ 1);
1002 tcp_fillheaders(tp
, ip6
, th
);
1006 ip
= mtod(m
, struct ip
*);
1007 ipov
= (struct ipovly
*)ip
;
1008 th
= (struct tcphdr
*)(ip
+ 1);
1009 /* this picks up the pseudo header (w/o the length) */
1010 tcp_fillheaders(tp
, ip
, th
);
1014 * Fill in fields, remembering maximum advertised
1015 * window for use in delaying messages about window sizes.
1016 * If resending a FIN, be sure not to use a new sequence number.
1018 if (flags
& TH_FIN
&& tp
->t_flags
& TF_SENTFIN
&&
1019 tp
->snd_nxt
== tp
->snd_max
)
1022 * If we are doing retransmissions, then snd_nxt will
1023 * not reflect the first unsent octet. For ACK only
1024 * packets, we do not want the sequence number of the
1025 * retransmitted packet, we want the sequence number
1026 * of the next unsent octet. So, if there is no data
1027 * (and no SYN or FIN), use snd_max instead of snd_nxt
1028 * when filling in ti_seq. But if we are in persist
1029 * state, snd_max might reflect one byte beyond the
1030 * right edge of the window, so use snd_nxt in that
1031 * case, since we know we aren't doing a retransmission.
1032 * (retransmit and persist are mutually exclusive...)
1034 if (sack_rxmit
== 0) {
1035 if (len
|| (flags
& (TH_SYN
|TH_FIN
)) || tp
->t_timer
[TCPT_PERSIST
])
1036 th
->th_seq
= htonl(tp
->snd_nxt
);
1038 th
->th_seq
= htonl(tp
->snd_max
);
1040 th
->th_seq
= htonl(p
->rxmit
);
1042 tp
->sackhint
.sack_bytes_rexmit
+= len
;
1044 th
->th_ack
= htonl(tp
->rcv_nxt
);
1046 bcopy(opt
, th
+ 1, optlen
);
1047 th
->th_off
= (sizeof (struct tcphdr
) + optlen
) >> 2;
1049 th
->th_flags
= flags
;
1051 * Calculate receive window. Don't shrink window,
1052 * but avoid silly window syndrome.
1054 if (recwin
< (long)(so
->so_rcv
.sb_hiwat
/ 4) && recwin
< (long)tp
->t_maxseg
)
1056 if (recwin
< (long)(tp
->rcv_adv
- tp
->rcv_nxt
))
1057 recwin
= (long)(tp
->rcv_adv
- tp
->rcv_nxt
);
1058 if (tp
->t_flags
& TF_SLOWLINK
&& slowlink_wsize
> 0) {
1059 if (recwin
> (long)slowlink_wsize
)
1060 recwin
= slowlink_wsize
;
1061 th
->th_win
= htons((u_short
) (recwin
>>tp
->rcv_scale
));
1064 if (recwin
> (long)TCP_MAXWIN
<< tp
->rcv_scale
)
1065 recwin
= (long)TCP_MAXWIN
<< tp
->rcv_scale
;
1066 th
->th_win
= htons((u_short
) (recwin
>>tp
->rcv_scale
));
1070 * Adjust the RXWIN0SENT flag - indicate that we have advertised
1071 * a 0 window. This may cause the remote transmitter to stall. This
1072 * flag tells soreceive() to disable delayed acknowledgements when
1073 * draining the buffer. This can occur if the receiver is attempting
1074 * to read more data then can be buffered prior to transmitting on
1078 tp
->t_flags
|= TF_RXWIN0SENT
;
1080 tp
->t_flags
&= ~TF_RXWIN0SENT
;
1081 if (SEQ_GT(tp
->snd_up
, tp
->snd_nxt
)) {
1082 th
->th_urp
= htons((u_short
)(tp
->snd_up
- tp
->snd_nxt
));
1083 th
->th_flags
|= TH_URG
;
1086 * If no urgent pointer to send, then we pull
1087 * the urgent pointer to the left edge of the send window
1088 * so that it doesn't drift into the send window on sequence
1089 * number wraparound.
1091 tp
->snd_up
= tp
->snd_una
; /* drag it along */
1094 * Put TCP length in extended header, and then
1095 * checksum extended header and data.
1097 m
->m_pkthdr
.len
= hdrlen
+ len
; /* in6_cksum() need this */
1101 * ip6_plen is not need to be filled now, and will be filled
1104 th
->th_sum
= in6_cksum(m
, IPPROTO_TCP
, sizeof(struct ip6_hdr
),
1105 sizeof(struct tcphdr
) + optlen
+ len
);
1109 m
->m_pkthdr
.csum_flags
= CSUM_TCP
;
1110 m
->m_pkthdr
.csum_data
= offsetof(struct tcphdr
, th_sum
);
1112 th
->th_sum
= in_addword(th
->th_sum
,
1113 htons((u_short
)(optlen
+ len
)));
1117 * In transmit state, time the transmission and arrange for
1118 * the retransmit. In persist state, just set snd_max.
1120 if (tp
->t_force
== 0 || tp
->t_timer
[TCPT_PERSIST
] == 0) {
1121 tcp_seq startseq
= tp
->snd_nxt
;
1124 * Advance snd_nxt over sequence space of this segment.
1126 if (flags
& (TH_SYN
|TH_FIN
)) {
1129 if (flags
& TH_FIN
) {
1131 tp
->t_flags
|= TF_SENTFIN
;
1137 if (SEQ_GT(tp
->snd_nxt
, tp
->snd_max
)) {
1138 tp
->snd_max
= tp
->snd_nxt
;
1140 * Time this transmission if not a retransmission and
1141 * not currently timing anything.
1143 if (tp
->t_rtttime
== 0) {
1145 tp
->t_rtseq
= startseq
;
1146 tcpstat
.tcps_segstimed
++;
1151 * Set retransmit timer if not currently set,
1152 * and not doing an ack or a keep-alive probe.
1153 * Initial value for retransmit timer is smoothed
1154 * round-trip time + 2 * round-trip time variance.
1155 * Initialize shift counter which is used for backoff
1156 * of retransmit time.
1159 if (tp
->t_timer
[TCPT_REXMT
] == 0 &&
1160 ((sack_rxmit
&& tp
->snd_nxt
!= tp
->snd_max
) ||
1161 tp
->snd_nxt
!= tp
->snd_una
)) {
1162 if (tp
->t_timer
[TCPT_PERSIST
]) {
1163 tp
->t_timer
[TCPT_PERSIST
] = 0;
1166 tp
->t_timer
[TCPT_REXMT
] = tp
->t_rxtcur
;
1170 * Persist case, update snd_max but since we are in
1171 * persist mode (no window) we do not update snd_nxt.
1176 if (flags
& TH_FIN
) {
1178 tp
->t_flags
|= TF_SENTFIN
;
1180 if (SEQ_GT(tp
->snd_nxt
+ xlen
, tp
->snd_max
))
1181 tp
->snd_max
= tp
->snd_nxt
+ len
;
1188 if (so
->so_options
& SO_DEBUG
)
1189 tcp_trace(TA_OUTPUT
, tp
->t_state
, tp
, mtod(m
, void *), th
, 0);
1193 * Fill in IP length and desired time to live and
1194 * send to IP level. There should be a better way
1195 * to handle ttl and tos; we could keep them in
1196 * the template, but need a way to checksum without them.
1199 * m->m_pkthdr.len should have been set before cksum calcuration,
1200 * because in6_cksum() need it.
1205 * we separately set hoplimit for every segment, since the
1206 * user might want to change the value via setsockopt.
1207 * Also, desired default hop limit might be changed via
1208 * Neighbor Discovery.
1210 ip6
->ip6_hlim
= in6_selecthlim(tp
->t_inpcb
,
1211 tp
->t_inpcb
->in6p_route
.ro_rt
?
1212 tp
->t_inpcb
->in6p_route
.ro_rt
->rt_ifp
1215 /* TODO: IPv6 IP6TOS_ECT bit on */
1217 if (ipsec_bypass
== 0 && ipsec_setsocket(m
, so
) != 0) {
1223 m
->m_pkthdr
.socket_id
= socket_id
;
1224 error
= ip6_output(m
,
1225 tp
->t_inpcb
->in6p_outputopts
,
1226 &tp
->t_inpcb
->in6p_route
,
1227 (so
->so_options
& SO_DONTROUTE
), NULL
, NULL
, 0);
1232 ip
->ip_len
= m
->m_pkthdr
.len
;
1235 ip
->ip_ttl
= in6_selecthlim(tp
->t_inpcb
,
1236 tp
->t_inpcb
->in6p_route
.ro_rt
?
1237 tp
->t_inpcb
->in6p_route
.ro_rt
->rt_ifp
1241 ip
->ip_ttl
= tp
->t_inpcb
->inp_ip_ttl
; /* XXX */
1242 ip
->ip_tos
= tp
->t_inpcb
->inp_ip_tos
; /* XXX */
1247 KERNEL_DEBUG(DBG_LAYER_BEG
,
1248 ((tp
->t_inpcb
->inp_fport
<< 16) | tp
->t_inpcb
->inp_lport
),
1249 (((tp
->t_inpcb
->in6p_laddr
.s6_addr16
[0] & 0xffff) << 16) |
1250 (tp
->t_inpcb
->in6p_faddr
.s6_addr16
[0] & 0xffff)),
1256 KERNEL_DEBUG(DBG_LAYER_BEG
,
1257 ((tp
->t_inpcb
->inp_fport
<< 16) | tp
->t_inpcb
->inp_lport
),
1258 (((tp
->t_inpcb
->inp_laddr
.s_addr
& 0xffff) << 16) |
1259 (tp
->t_inpcb
->inp_faddr
.s_addr
& 0xffff)),
1264 * See if we should do MTU discovery. We do it only if the following
1266 * 1) we have a valid route to the destination
1267 * 2) the MTU is not locked (if it is, then discovery has been
1270 if (path_mtu_discovery
1271 && (rt
= tp
->t_inpcb
->inp_route
.ro_rt
)
1272 && rt
->rt_flags
& RTF_UP
1273 && !(rt
->rt_rmx
.rmx_locks
& RTV_MTU
)) {
1274 ip
->ip_off
|= IP_DF
;
1277 if (ipsec_bypass
== 0)
1278 ipsec_setsocket(m
, so
);
1282 * The socket is kept locked while sending out packets in ip_output, even if packet chaining is not active.
1285 m
->m_pkthdr
.socket_id
= socket_id
;
1287 m
->m_nextpkt
= NULL
;
1288 lastpacket
->m_nextpkt
= m
;
1290 packchain_listadd
++;
1293 m
->m_nextpkt
= NULL
;
1294 packchain_newlist
++;
1295 packetlist
= lastpacket
= m
;
1296 packchain_listadd
=0;
1299 if ((ipsec_bypass
== 0) || fw_enable
|| sendalot
== 0 || (tp
->t_state
!= TCPS_ESTABLISHED
) ||
1300 (tp
->snd_cwnd
<= (tp
->snd_wnd
/ 4)) ||
1301 (tp
->t_flags
& (TH_PUSH
| TF_ACKNOW
)) || tp
->t_force
!= 0 ||
1302 packchain_listadd
>= tcp_packet_chaining
) {
1303 lastpacket
->m_nextpkt
= 0;
1304 error
= ip_output_list(packetlist
, packchain_listadd
, tp
->t_inpcb
->inp_options
, &tp
->t_inpcb
->inp_route
,
1305 (so
->so_options
& SO_DONTROUTE
), 0);
1306 tp
->t_lastchain
= packchain_listadd
;
1315 tcpstat
.tcps_sndtotal
++;
1316 if (recwin
> 0 && SEQ_GT(tp
->rcv_nxt
+recwin
, tp
->rcv_adv
))
1317 tp
->rcv_adv
= tp
->rcv_nxt
+ recwin
;
1318 tp
->last_ack_sent
= tp
->rcv_nxt
;
1319 tp
->t_flags
&= ~(TF_ACKNOW
|TF_DELACK
);
1326 * We know that the packet was lost, so back out the
1327 * sequence number advance, if any.
1329 if (tp
->t_force
== 0 || tp
->t_timer
[TCPT_PERSIST
] == 0) {
1331 * No need to check for TH_FIN here because
1332 * the TF_SENTFIN flag handles that case.
1334 if ((flags
& TH_SYN
) == 0) {
1336 p
->rxmit
-= howmuchsent
;
1337 tp
->sackhint
.sack_bytes_rexmit
-= howmuchsent
;
1339 tp
->snd_nxt
-= howmuchsent
;
1344 if (error
== ENOBUFS
) {
1345 if (!tp
->t_timer
[TCPT_REXMT
] &&
1346 !tp
->t_timer
[TCPT_PERSIST
])
1347 tp
->t_timer
[TCPT_REXMT
] = tp
->t_rxtcur
;
1348 tcp_quench(tp
->t_inpcb
, 0);
1350 m_freem_list(packetlist
);
1351 tp
->t_lastchain
= 0;
1352 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT
| DBG_FUNC_END
, 0,0,0,0,0);
1355 if (error
== EMSGSIZE
) {
1357 * ip_output() will have already fixed the route
1358 * for us. tcp_mtudisc() will, as its last action,
1359 * initiate retransmission, so it is important to
1362 tcp_mtudisc(tp
->t_inpcb
, 0);
1364 m_freem_list(packetlist
);
1365 tp
->t_lastchain
= 0;
1366 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT
| DBG_FUNC_END
, 0,0,0,0,0);
1369 if ((error
== EHOSTUNREACH
|| error
== ENETDOWN
)
1370 && TCPS_HAVERCVDSYN(tp
->t_state
)) {
1371 tp
->t_softerror
= error
;
1373 m_freem_list(packetlist
);
1374 tp
->t_lastchain
= 0;
1375 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT
| DBG_FUNC_END
, 0,0,0,0,0);
1379 m_freem_list(packetlist
);
1380 tp
->t_lastchain
= 0;
1381 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT
| DBG_FUNC_END
, 0,0,0,0,0);
1385 tcpstat
.tcps_sndtotal
++;
1388 * Data sent (as far as we can tell).
1389 * If this advertises a larger window than any other segment,
1390 * then remember the size of the advertised window.
1391 * Any pending ACK has now been sent.
1393 if (recwin
> 0 && SEQ_GT(tp
->rcv_nxt
+recwin
, tp
->rcv_adv
))
1394 tp
->rcv_adv
= tp
->rcv_nxt
+ recwin
;
1395 tp
->last_ack_sent
= tp
->rcv_nxt
;
1396 tp
->t_flags
&= ~(TF_ACKNOW
|TF_DELACK
);
1398 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT
| DBG_FUNC_END
,0,0,0,0,0);
1399 if (sendalot
&& (!tcp_do_newreno
|| --maxburst
))
1406 register struct tcpcb
*tp
;
1408 int t
= ((tp
->t_srtt
>> 2) + tp
->t_rttvar
) >> 1;
1410 if (tp
->t_timer
[TCPT_REXMT
])
1411 panic("tcp_setpersist: retransmit pending");
1413 * Start/restart persistance timer.
1415 TCPT_RANGESET(tp
->t_timer
[TCPT_PERSIST
],
1416 t
* tcp_backoff
[tp
->t_rxtshift
],
1417 TCPTV_PERSMIN
, TCPTV_PERSMAX
);
1418 if (tp
->t_rxtshift
< TCP_MAXRXTSHIFT
)