2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
30 * The Regents of the University of California. All rights reserved.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * @(#)tcp_output.c 8.4 (Berkeley) 5/24/95
61 * $FreeBSD: src/sys/netinet/tcp_output.c,v 1.39.2.10 2001/07/07 04:30:38 silby Exp $
67 #include <sys/param.h>
68 #include <sys/systm.h>
69 #include <sys/kernel.h>
70 #include <sys/sysctl.h>
72 #include <sys/domain.h>
73 #include <sys/protosw.h>
74 #include <sys/socket.h>
75 #include <sys/socketvar.h>
77 #include <net/route.h>
79 #include <netinet/in.h>
80 #include <netinet/in_systm.h>
81 #include <netinet/ip.h>
82 #include <netinet/in_pcb.h>
83 #include <netinet/ip_var.h>
85 #include <netinet6/in6_pcb.h>
86 #include <netinet/ip6.h>
87 #include <netinet6/ip6_var.h>
89 #include <netinet/tcp.h>
91 #include <netinet/tcp_fsm.h>
92 #include <netinet/tcp_seq.h>
93 #include <netinet/tcp_timer.h>
94 #include <netinet/tcp_var.h>
95 #include <netinet/tcpip.h>
97 #include <netinet/tcp_debug.h>
99 #include <sys/kdebug.h>
102 #include <netinet6/ipsec.h>
105 #define DBG_LAYER_BEG NETDBG_CODE(DBG_NETTCP, 1)
106 #define DBG_LAYER_END NETDBG_CODE(DBG_NETTCP, 3)
107 #define DBG_FNC_TCP_OUTPUT NETDBG_CODE(DBG_NETTCP, (4 << 8) | 1)
111 extern struct mbuf
*m_copypack();
114 static int path_mtu_discovery
= 1;
115 SYSCTL_INT(_net_inet_tcp
, OID_AUTO
, path_mtu_discovery
, CTLFLAG_RW
,
116 &path_mtu_discovery
, 1, "Enable Path MTU Discovery");
119 SYSCTL_INT(_net_inet_tcp
, OID_AUTO
, slowstart_flightsize
, CTLFLAG_RW
,
120 &ss_fltsz
, 1, "Slow start flight size");
122 int ss_fltsz_local
= 4; /* starts with four segments max */
123 SYSCTL_INT(_net_inet_tcp
, OID_AUTO
, local_slowstart_flightsize
, CTLFLAG_RW
,
124 &ss_fltsz_local
, 1, "Slow start flight size for local networks");
126 int tcp_do_newreno
= 0;
127 SYSCTL_INT(_net_inet_tcp
, OID_AUTO
, newreno
, CTLFLAG_RW
, &tcp_do_newreno
,
128 0, "Enable NewReno Algorithms");
130 int tcp_packet_chaining
= 50;
131 SYSCTL_INT(_net_inet_tcp
, OID_AUTO
, packetchain
, CTLFLAG_RW
, &tcp_packet_chaining
,
132 0, "Enable TCP output packet chaining");
134 struct mbuf
*m_copym_with_hdrs(struct mbuf
*, int, int, int, struct mbuf
**, int*);
135 static long packchain_newlist
= 0;
136 static long packchain_looped
= 0;
137 static long packchain_sent
= 0;
140 /* temporary: for testing */
142 extern int ipsec_bypass
;
145 extern int slowlink_wsize
; /* window correction for slow links */
146 extern u_long route_generation
;
147 extern int fw_enable
; /* firewall is on: disable packet chaining */
148 extern int ipsec_bypass
;
150 extern vm_size_t so_cache_zone_element_size
;
152 static __inline__ u_int16_t
153 get_socket_id(struct socket
* s
)
157 if (so_cache_zone_element_size
== 0) {
160 val
= (u_int16_t
)(((u_int32_t
)s
) / so_cache_zone_element_size
);
168 * Tcp output routine: figure out what should be sent and send it.
171 tcp_output(struct tcpcb
*tp
)
173 struct socket
*so
= tp
->t_inpcb
->inp_socket
;
174 long len
, recwin
, sendwin
;
175 int off
, flags
, error
;
176 register struct mbuf
*m
;
177 struct ip
*ip
= NULL
;
178 register struct ipovly
*ipov
= NULL
;
180 struct ip6_hdr
*ip6
= NULL
;
182 register struct tcphdr
*th
;
183 u_char opt
[TCP_MAXOLEN
];
184 unsigned ipoptlen
, optlen
, hdrlen
;
185 int idle
, sendalot
, howmuchsent
= 0;
190 int maxburst
= TCP_MAXBURST
;
191 struct rmxp_tao
*taop
;
192 struct rmxp_tao tao_noncached
;
195 struct mbuf
*m_last
= 0;
196 struct mbuf
*m_head
= 0;
197 struct mbuf
*packetlist
= 0;
198 struct mbuf
*lastpacket
= 0;
200 int isipv6
= tp
->t_inpcb
->inp_vflag
& INP_IPV6
;
202 short packchain_listadd
= 0;
203 u_int16_t socket_id
= get_socket_id(so
);
207 * Determine length of data that should be transmitted,
208 * and flags that will be used.
209 * If there is some data or critical controls (SYN, RST)
210 * to send, then transmit; otherwise, investigate further.
212 idle
= (tp
->t_flags
& TF_LASTIDLE
) || (tp
->snd_max
== tp
->snd_una
);
213 if (idle
&& tp
->t_rcvtime
>= tp
->t_rxtcur
) {
215 * We have been idle for "a while" and no acks are
216 * expected to clock out any data we send --
217 * slow start to get ack "clock" running again.
219 * Set the slow-start flight size depending on whether
220 * this is a local network or not.
224 (isipv6
&& in6_localaddr(&tp
->t_inpcb
->in6p_faddr
)) ||
227 in_localaddr(tp
->t_inpcb
->inp_faddr
)
232 tp
->snd_cwnd
= tp
->t_maxseg
* ss_fltsz_local
;
234 tp
->snd_cwnd
= tp
->t_maxseg
* ss_fltsz
;
236 tp
->t_flags
&= ~TF_LASTIDLE
;
238 if (tp
->t_flags
& TF_MORETOCOME
) {
239 tp
->t_flags
|= TF_LASTIDLE
;
244 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT
| DBG_FUNC_START
, 0,0,0,0,0);
249 KERNEL_DEBUG(DBG_LAYER_BEG
,
250 ((tp
->t_inpcb
->inp_fport
<< 16) | tp
->t_inpcb
->inp_lport
),
251 (((tp
->t_inpcb
->in6p_laddr
.s6_addr16
[0] & 0xffff) << 16) |
252 (tp
->t_inpcb
->in6p_faddr
.s6_addr16
[0] & 0xffff)),
259 KERNEL_DEBUG(DBG_LAYER_BEG
,
260 ((tp
->t_inpcb
->inp_fport
<< 16) | tp
->t_inpcb
->inp_lport
),
261 (((tp
->t_inpcb
->inp_laddr
.s_addr
& 0xffff) << 16) |
262 (tp
->t_inpcb
->inp_faddr
.s_addr
& 0xffff)),
265 * If the route generation id changed, we need to check that our
266 * local (source) IP address is still valid. If it isn't either
267 * return error or silently do nothing (assuming the address will
268 * come back before the TCP connection times out).
271 if ((tp
->t_inpcb
->inp_route
.ro_rt
!= NULL
&&
272 (tp
->t_inpcb
->inp_route
.ro_rt
->generation_id
!= route_generation
)) || (tp
->t_inpcb
->inp_route
.ro_rt
== NULL
)) {
273 /* check that the source address is still valid */
274 if (ifa_foraddr(tp
->t_inpcb
->inp_laddr
.s_addr
) == 0) {
275 if (tp
->t_state
>= TCPS_CLOSE_WAIT
) {
277 return(EADDRNOTAVAIL
);
280 /* set Retransmit timer if it wasn't set
281 * reset Persist timer and shift register as the
282 * adversed peer window may not be valid anymore
285 if (!tp
->t_timer
[TCPT_REXMT
]) {
286 tp
->t_timer
[TCPT_REXMT
] = tp
->t_rxtcur
;
287 if (tp
->t_timer
[TCPT_PERSIST
]) {
288 tp
->t_timer
[TCPT_PERSIST
] = 0;
294 error
= ip_output_list(packetlist
, packchain_listadd
, tp
->t_inpcb
->inp_options
, &tp
->t_inpcb
->inp_route
,
295 (so
->so_options
& SO_DONTROUTE
), 0);
298 if (so
->so_flags
& SOF_NOADDRAVAIL
)
299 return(EADDRNOTAVAIL
);
301 return(0); /* silently ignore and keep data in socket */
307 * If we've recently taken a timeout, snd_max will be greater than
308 * snd_nxt. There may be SACK information that allows us to avoid
309 * resending already delivered data. Adjust snd_nxt accordingly.
311 if (tp
->sack_enable
&& SEQ_LT(tp
->snd_nxt
, tp
->snd_max
))
314 off
= tp
->snd_nxt
- tp
->snd_una
;
315 sendwin
= min(tp
->snd_wnd
, tp
->snd_cwnd
);
317 if (tp
->t_flags
& TF_SLOWLINK
&& slowlink_wsize
> 0)
318 sendwin
= min(sendwin
, slowlink_wsize
);
320 flags
= tcp_outflags
[tp
->t_state
];
322 * Send any SACK-generated retransmissions. If we're explicitly trying
323 * to send out new data (when sendalot is 1), bypass this function.
324 * If we retransmit in fast recovery mode, decrement snd_cwnd, since
325 * we're replacing a (future) new transmission with a retransmission
326 * now, and we previously incremented snd_cwnd in tcp_input().
329 * Still in sack recovery , reset rxmit flag to zero.
335 if (tp
->sack_enable
&& IN_FASTRECOVERY(tp
) &&
336 (p
= tcp_sack_output(tp
, &sack_bytes_rxmt
))) {
339 cwin
= min(tp
->snd_wnd
, tp
->snd_cwnd
) - sack_bytes_rxmt
;
342 /* Do not retransmit SACK segments beyond snd_recover */
343 if (SEQ_GT(p
->end
, tp
->snd_recover
)) {
345 * (At least) part of sack hole extends beyond
346 * snd_recover. Check to see if we can rexmit data
349 if (SEQ_GEQ(p
->rxmit
, tp
->snd_recover
)) {
351 * Can't rexmit any more data for this hole.
352 * That data will be rexmitted in the next
353 * sack recovery episode, when snd_recover
354 * moves past p->rxmit.
357 goto after_sack_rexmit
;
359 /* Can rexmit part of the current hole */
360 len
= ((long)ulmin(cwin
,
361 tp
->snd_recover
- p
->rxmit
));
363 len
= ((long)ulmin(cwin
, p
->end
- p
->rxmit
));
364 off
= p
->rxmit
- tp
->snd_una
;
368 tcpstat
.tcps_sack_rexmits
++;
369 tcpstat
.tcps_sack_rexmit_bytes
+=
370 min(len
, tp
->t_maxseg
);
375 * Get standard flags, and add SYN or FIN if requested by 'hidden'
378 if (tp
->t_flags
& TF_NEEDFIN
)
380 if (tp
->t_flags
& TF_NEEDSYN
)
384 * If in persist timeout with window of 0, send 1 byte.
385 * Otherwise, if window is small but nonzero
386 * and timer expired, we will send what we can
387 * and go to transmit state.
392 * If we still have some data to send, then
393 * clear the FIN bit. Usually this would
394 * happen below when it realizes that we
395 * aren't sending all the data. However,
396 * if we have exactly 1 byte of unsent data,
397 * then it won't clear the FIN bit below,
398 * and if we are in persist state, we wind
399 * up sending the packet without recording
400 * that we sent the FIN bit.
402 * We can't just blindly clear the FIN bit,
403 * because if we don't have any more data
404 * to send then the probe will be the FIN
407 if (off
< so
->so_snd
.sb_cc
)
411 tp
->t_timer
[TCPT_PERSIST
] = 0;
417 * If snd_nxt == snd_max and we have transmitted a FIN, the
418 * offset will be > 0 even if so_snd.sb_cc is 0, resulting in
419 * a negative length. This can also occur when TCP opens up
420 * its congestion window while receiving additional duplicate
421 * acks after fast-retransmit because TCP will reset snd_nxt
422 * to snd_max after the fast-retransmit.
424 * In the normal retransmit-FIN-only case, however, snd_nxt will
425 * be set to snd_una, the offset will be 0, and the length may
428 * If sack_rxmit is true we are retransmitting from the scoreboard
429 * in which case len is already set.
431 if (sack_rxmit
== 0) {
432 if (sack_bytes_rxmt
== 0)
433 len
= ((long)ulmin(so
->so_snd
.sb_cc
, sendwin
) - off
);
438 * We are inside of a SACK recovery episode and are
439 * sending new data, having retransmitted all the
440 * data possible in the scoreboard.
442 len
= ((long)ulmin(so
->so_snd
.sb_cc
, tp
->snd_wnd
)
445 * Don't remove this (len > 0) check !
446 * We explicitly check for len > 0 here (although it
447 * isn't really necessary), to work around a gcc
448 * optimization issue - to force gcc to compute
449 * len above. Without this check, the computation
450 * of len is bungled by the optimizer.
453 cwin
= tp
->snd_cwnd
-
454 (tp
->snd_nxt
- tp
->sack_newdata
) -
458 len
= lmin(len
, cwin
);
464 * Lop off SYN bit if it has already been sent. However, if this
465 * is SYN-SENT state and if segment contains data and if we don't
466 * know that foreign host supports TAO, suppress sending segment.
468 if ((flags
& TH_SYN
) && SEQ_GT(tp
->snd_nxt
, tp
->snd_una
)) {
471 if (len
> 0 && tp
->t_state
== TCPS_SYN_SENT
) {
473 error
= ip_output_list(packetlist
, packchain_listadd
, tp
->t_inpcb
->inp_options
, &tp
->t_inpcb
->inp_route
,
474 (so
->so_options
& SO_DONTROUTE
), 0);
477 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT
| DBG_FUNC_END
, 0,0,0,0,0);
483 * Be careful not to send data and/or FIN on SYN segments.
484 * This measure is needed to prevent interoperability problems
485 * with not fully conformant TCP implementations.
487 if ((flags
& TH_SYN
) && (tp
->t_flags
& TF_NOOPT
)) {
494 * If FIN has been sent but not acked,
495 * but we haven't been called to retransmit,
496 * len will be < 0. Otherwise, window shrank
497 * after we sent into it. If window shrank to 0,
498 * cancel pending retransmit, pull snd_nxt back
499 * to (closed) window, and set the persist timer
500 * if it isn't already going. If the window didn't
501 * close completely, just wait for an ACK.
505 tp
->t_timer
[TCPT_REXMT
] = 0;
507 tp
->snd_nxt
= tp
->snd_una
;
508 if (tp
->t_timer
[TCPT_PERSIST
] == 0)
514 * len will be >= 0 after this point. Truncate to the maximum
515 * segment length and ensure that FIN is removed if the length
516 * no longer contains the last data byte.
518 if (len
> tp
->t_maxseg
) {
524 if (SEQ_LT(p
->rxmit
+ len
, tp
->snd_una
+ so
->so_snd
.sb_cc
))
527 if (SEQ_LT(tp
->snd_nxt
+ len
, tp
->snd_una
+ so
->so_snd
.sb_cc
))
531 if (tp
->t_flags
& TF_SLOWLINK
&& slowlink_wsize
> 0 ) /* Clips window size for slow links */
532 recwin
= min(sbspace(&so
->so_rcv
), slowlink_wsize
);
534 recwin
= sbspace(&so
->so_rcv
);
537 * Sender silly window avoidance. We transmit under the following
538 * conditions when len is non-zero:
540 * - We have a full segment
541 * - This is the last buffer in a write()/send() and we are
542 * either idle or running NODELAY
543 * - we've timed out (e.g. persist timer)
544 * - we have more then 1/2 the maximum send window's worth of
545 * data (receiver may be limited the window size)
546 * - we need to retransmit
549 if (len
== tp
->t_maxseg
)
551 if (!(tp
->t_flags
& TF_MORETOCOME
) &&
552 (idle
|| tp
->t_flags
& TF_NODELAY
) &&
553 (tp
->t_flags
& TF_NOPUSH
) == 0 &&
554 len
+ off
>= so
->so_snd
.sb_cc
)
558 if (len
>= tp
->max_sndwnd
/ 2 && tp
->max_sndwnd
> 0)
560 if (SEQ_LT(tp
->snd_nxt
, tp
->snd_max
)) /* retransmit case */
567 * Compare available window to amount of window
568 * known to peer (as advertised window less
569 * next expected input). If the difference is at least two
570 * max size segments, or at least 50% of the maximum possible
571 * window, then want to send a window update to peer.
572 * Skip this if the connection is in T/TCP half-open state.
574 if (recwin
> 0 && !(tp
->t_flags
& TF_NEEDSYN
)) {
576 * "adv" is the amount we can increase the window,
577 * taking into account that we are limited by
578 * TCP_MAXWIN << tp->rcv_scale.
580 long adv
= min(recwin
, (long)TCP_MAXWIN
<< tp
->rcv_scale
) -
581 (tp
->rcv_adv
- tp
->rcv_nxt
);
583 if (adv
>= (long) (2 * tp
->t_maxseg
))
585 if (2 * adv
>= (long) so
->so_rcv
.sb_hiwat
)
590 * Send if we owe the peer an ACK, RST, SYN, or urgent data. ACKNOW
591 * is also a catch-all for the retransmit timer timeout case.
593 if (tp
->t_flags
& TF_ACKNOW
)
595 if ((flags
& TH_RST
) ||
596 ((flags
& TH_SYN
) && (tp
->t_flags
& TF_NEEDSYN
) == 0))
598 if (SEQ_GT(tp
->snd_up
, tp
->snd_una
))
601 * If our state indicates that FIN should be sent
602 * and we have not yet done so, then we need to send.
604 if (flags
& TH_FIN
&&
605 ((tp
->t_flags
& TF_SENTFIN
) == 0 || tp
->snd_nxt
== tp
->snd_una
))
608 * In SACK, it is possible for tcp_output to fail to send a segment
609 * after the retransmission timer has been turned off. Make sure
610 * that the retransmission timer is set.
612 if (tp
->sack_enable
&& SEQ_GT(tp
->snd_max
, tp
->snd_una
) &&
613 tp
->t_timer
[TCPT_REXMT
] == 0 &&
614 tp
->t_timer
[TCPT_PERSIST
] == 0) {
615 tp
->t_timer
[TCPT_REXMT
] = tp
->t_rxtcur
;
619 * TCP window updates are not reliable, rather a polling protocol
620 * using ``persist'' packets is used to insure receipt of window
621 * updates. The three ``states'' for the output side are:
622 * idle not doing retransmits or persists
623 * persisting to move a small or zero window
624 * (re)transmitting and thereby not persisting
626 * tp->t_timer[TCPT_PERSIST]
627 * is set when we are in persist state.
629 * is set when we are called to send a persist packet.
630 * tp->t_timer[TCPT_REXMT]
631 * is set when we are retransmitting
632 * The output side is idle when both timers are zero.
634 * If send window is too small, there is data to transmit, and no
635 * retransmit or persist is pending, then go to persist state.
636 * If nothing happens soon, send when timer expires:
637 * if window is nonzero, transmit what we can,
638 * otherwise force out a byte.
640 if (so
->so_snd
.sb_cc
&& tp
->t_timer
[TCPT_REXMT
] == 0 &&
641 tp
->t_timer
[TCPT_PERSIST
] == 0) {
647 * If there is no reason to send a segment, just return.
648 * but if there is some packets left in the packet list, send them now.
651 error
= ip_output_list(packetlist
, packchain_listadd
, tp
->t_inpcb
->inp_options
, &tp
->t_inpcb
->inp_route
,
652 (so
->so_options
& SO_DONTROUTE
), 0);
654 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT
| DBG_FUNC_END
, 0,0,0,0,0);
659 * Before ESTABLISHED, force sending of initial options
660 * unless TCP set not to do any options.
661 * NOTE: we assume that the IP/TCP header plus TCP options
662 * always fit in a single mbuf, leaving room for a maximum
664 * max_linkhdr + sizeof (struct tcpiphdr) + optlen <= MCLBYTES
669 hdrlen
= sizeof (struct ip6_hdr
) + sizeof (struct tcphdr
);
672 hdrlen
= sizeof (struct tcpiphdr
);
673 if (flags
& TH_SYN
) {
674 tp
->snd_nxt
= tp
->iss
;
675 if ((tp
->t_flags
& TF_NOOPT
) == 0) {
678 opt
[0] = TCPOPT_MAXSEG
;
679 opt
[1] = TCPOLEN_MAXSEG
;
680 mss
= htons((u_short
) tcp_mssopt(tp
));
681 (void)memcpy(opt
+ 2, &mss
, sizeof(mss
));
682 optlen
= TCPOLEN_MAXSEG
;
684 if ((tp
->t_flags
& TF_REQ_SCALE
) &&
685 ((flags
& TH_ACK
) == 0 ||
686 (tp
->t_flags
& TF_RCVD_SCALE
))) {
687 *((u_int32_t
*)(opt
+ optlen
)) = htonl(
689 TCPOPT_WINDOW
<< 16 |
690 TCPOLEN_WINDOW
<< 8 |
691 tp
->request_r_scale
);
698 * Send a timestamp and echo-reply if this is a SYN and our side
699 * wants to use timestamps (TF_REQ_TSTMP is set) or both our side
700 * and our peer have sent timestamps in our SYN's.
702 if ((tp
->t_flags
& (TF_REQ_TSTMP
|TF_NOOPT
)) == TF_REQ_TSTMP
&&
703 (flags
& TH_RST
) == 0 &&
704 ((flags
& TH_ACK
) == 0 ||
705 (tp
->t_flags
& TF_RCVD_TSTMP
))) {
706 u_int32_t
*lp
= (u_int32_t
*)(opt
+ optlen
);
708 /* Form timestamp option as shown in appendix A of RFC 1323. */
709 *lp
++ = htonl(TCPOPT_TSTAMP_HDR
);
710 *lp
++ = htonl(tcp_now
);
711 *lp
= htonl(tp
->ts_recent
);
712 optlen
+= TCPOLEN_TSTAMP_APPA
;
715 if (tp
->sack_enable
&& ((tp
->t_flags
& TF_NOOPT
) == 0)) {
717 * Tack on the SACK permitted option *last*.
718 * And do padding of options after tacking this on.
719 * This is because of MSS, TS, WinScale and Signatures are
720 * all present, we have just 2 bytes left for the SACK
721 * permitted option, which is just enough.
724 * If this is the first SYN of connection (not a SYN
725 * ACK), include SACK permitted option. If this is a
726 * SYN ACK, include SACK permitted option if peer has
727 * already done so. This is only for active connect,
728 * since the syncache takes care of the passive connect.
730 if ((flags
& TH_SYN
) &&
731 (!(flags
& TH_ACK
) || (tp
->t_flags
& TF_SACK_PERMIT
))) {
733 bp
= (u_char
*)opt
+ optlen
;
735 *bp
++ = TCPOPT_SACK_PERMITTED
;
736 *bp
++ = TCPOLEN_SACK_PERMITTED
;
737 optlen
+= TCPOLEN_SACK_PERMITTED
;
741 * Send SACKs if necessary. This should be the last
742 * option processed. Only as many SACKs are sent as
743 * are permitted by the maximum options size.
745 * In general, SACK blocks consume 8*n+2 bytes.
746 * So a full size SACK blocks option is 34 bytes
747 * (to generate 4 SACK blocks). At a minimum,
748 * we need 10 bytes (to generate 1 SACK block).
749 * If TCP Timestamps (12 bytes) and TCP Signatures
750 * (18 bytes) are both present, we'll just have
751 * 10 bytes for SACK options 40 - (12 + 18).
753 if (TCPS_HAVEESTABLISHED(tp
->t_state
) &&
754 (tp
->t_flags
& TF_SACK_PERMIT
) && tp
->rcv_numsacks
> 0 &&
755 MAX_TCPOPTLEN
- optlen
- 2 >= TCPOLEN_SACK
) {
756 int nsack
, sackoptlen
, padlen
;
757 u_char
*bp
= (u_char
*)opt
+ optlen
;
760 nsack
= (MAX_TCPOPTLEN
- optlen
- 2) / TCPOLEN_SACK
;
761 nsack
= min(nsack
, tp
->rcv_numsacks
);
762 sackoptlen
= (2 + nsack
* TCPOLEN_SACK
);
765 * First we need to pad options so that the
766 * SACK blocks can start at a 4-byte boundary
767 * (sack option and length are at a 2 byte offset).
769 padlen
= (MAX_TCPOPTLEN
- optlen
- sackoptlen
) % 4;
774 tcpstat
.tcps_sack_send_blocks
++;
777 lp
= (u_int32_t
*)bp
;
778 for (i
= 0; i
< nsack
; i
++) {
779 struct sackblk sack
= tp
->sackblks
[i
];
780 *lp
++ = htonl(sack
.start
);
781 *lp
++ = htonl(sack
.end
);
783 optlen
+= sackoptlen
;
787 /* Pad TCP options to a 4 byte boundary */
788 if (optlen
< MAX_TCPOPTLEN
&& (optlen
% sizeof(u_int32_t
))) {
789 int pad
= sizeof(u_int32_t
) - (optlen
% sizeof(u_int32_t
));
790 u_char
*bp
= (u_char
*)opt
+ optlen
;
803 ipoptlen
= ip6_optlen(tp
->t_inpcb
);
807 if (tp
->t_inpcb
->inp_options
) {
808 ipoptlen
= tp
->t_inpcb
->inp_options
->m_len
-
809 offsetof(struct ipoption
, ipopt_list
);
814 if (ipsec_bypass
== 0)
815 ipoptlen
+= ipsec_hdrsiz_tcp(tp
);
819 * Adjust data length if insertion of options will
820 * bump the packet length beyond the t_maxopd length.
821 * Clear the FIN bit because we cut off the tail of
824 if (len
+ optlen
+ ipoptlen
> tp
->t_maxopd
) {
826 * If there is still more to send, don't close the connection.
829 len
= tp
->t_maxopd
- optlen
- ipoptlen
;
834 /*#ifdef DIAGNOSTIC*/
836 if (max_linkhdr
+ hdrlen
> MCLBYTES
)
837 panic("tcphdr too big");
839 if (max_linkhdr
+ hdrlen
> MHLEN
)
840 panic("tcphdr too big");
845 * Grab a header mbuf, attaching a copy of data to
846 * be transmitted, and initialize the header from
847 * the template for sends on this connection.
850 if (tp
->t_force
&& len
== 1)
851 tcpstat
.tcps_sndprobe
++;
852 else if (SEQ_LT(tp
->snd_nxt
, tp
->snd_max
)) {
853 tcpstat
.tcps_sndrexmitpack
++;
854 tcpstat
.tcps_sndrexmitbyte
+= len
;
856 tcpstat
.tcps_sndpack
++;
857 tcpstat
.tcps_sndbyte
+= len
;
860 if ((m
= m_copypack(so
->so_snd
.sb_mb
, off
,
861 (int)len
, max_linkhdr
+ hdrlen
)) == 0) {
866 * m_copypack left space for our hdr; use it.
872 * try to use the new interface that allocates all
873 * the necessary mbuf hdrs under 1 mbuf lock and
874 * avoids rescanning the socket mbuf list if
875 * certain conditions are met. This routine can't
876 * be used in the following cases...
877 * 1) the protocol headers exceed the capacity of
878 * of a single mbuf header's data area (no cluster attached)
879 * 2) the length of the data being transmitted plus
880 * the protocol headers fits into a single mbuf header's
881 * data area (no cluster attached)
885 if (MHLEN
< hdrlen
+ max_linkhdr
) {
886 MGETHDR(m
, M_DONTWAIT
, MT_HEADER
);
891 MCLGET(m
, M_DONTWAIT
);
892 if ((m
->m_flags
& M_EXT
) == 0) {
897 m
->m_data
+= max_linkhdr
;
901 if (len
<= MHLEN
- hdrlen
- max_linkhdr
) {
903 MGETHDR(m
, M_DONTWAIT
, MT_HEADER
);
908 m
->m_data
+= max_linkhdr
;
911 /* makes sure we still have data left to be sent at this point */
912 if (so
->so_snd
.sb_mb
== NULL
|| off
== -1) {
913 if (m
!= NULL
) m_freem(m
);
914 error
= 0; /* should we return an error? */
917 m_copydata(so
->so_snd
.sb_mb
, off
, (int) len
,
918 mtod(m
, caddr_t
) + hdrlen
);
922 m
->m_next
= m_copy(so
->so_snd
.sb_mb
, off
, (int) len
);
923 if (m
->m_next
== 0) {
930 * determine whether the mbuf pointer and offset passed back by the 'last' call
931 * to m_copym_with_hdrs are still valid... if the head of the socket chain has
932 * changed (due to an incoming ACK for instance), or the offset into the chain we
933 * just computed is different from the one last returned by m_copym_with_hdrs (perhaps
934 * we're re-transmitting a packet sent earlier), than we can't pass the mbuf pointer and
935 * offset into it as valid hints for m_copym_with_hdrs to use (if valid, these hints allow
936 * m_copym_with_hdrs to avoid rescanning from the beginning of the socket buffer mbuf list.
937 * setting the mbuf pointer to NULL is sufficient to disable the hint mechanism.
939 if (m_head
!= so
->so_snd
.sb_mb
|| last_off
!= off
)
941 last_off
= off
+ len
;
942 m_head
= so
->so_snd
.sb_mb
;
944 /* makes sure we still have data left to be sent at this point */
945 if (m_head
== NULL
) {
946 error
= 0; /* should we return an error? */
951 * m_copym_with_hdrs will always return the last mbuf pointer and the offset into it that
952 * it acted on to fullfill the current request, whether a valid 'hint' was passed in or not
954 if ((m
= m_copym_with_hdrs(so
->so_snd
.sb_mb
, off
, (int) len
, M_DONTWAIT
, &m_last
, &m_off
)) == NULL
) {
958 m
->m_data
+= max_linkhdr
;
964 * If we're sending everything we've got, set PUSH.
965 * (This will keep happy those implementations which only
966 * give data to the user when a buffer fills or
969 if (off
+ len
== so
->so_snd
.sb_cc
)
972 if (tp
->t_flags
& TF_ACKNOW
)
973 tcpstat
.tcps_sndacks
++;
974 else if (flags
& (TH_SYN
|TH_FIN
|TH_RST
))
975 tcpstat
.tcps_sndctrl
++;
976 else if (SEQ_GT(tp
->snd_up
, tp
->snd_una
))
977 tcpstat
.tcps_sndurg
++;
979 tcpstat
.tcps_sndwinup
++;
981 MGETHDR(m
, M_DONTWAIT
, MT_HEADER
);
987 if (isipv6
&& (MHLEN
< hdrlen
+ max_linkhdr
) &&
992 m
->m_data
+= max_linkhdr
;
995 m
->m_pkthdr
.rcvif
= 0;
998 ip6
= mtod(m
, struct ip6_hdr
*);
999 th
= (struct tcphdr
*)(ip6
+ 1);
1000 tcp_fillheaders(tp
, ip6
, th
);
1004 ip
= mtod(m
, struct ip
*);
1005 ipov
= (struct ipovly
*)ip
;
1006 th
= (struct tcphdr
*)(ip
+ 1);
1007 /* this picks up the pseudo header (w/o the length) */
1008 tcp_fillheaders(tp
, ip
, th
);
1012 * Fill in fields, remembering maximum advertised
1013 * window for use in delaying messages about window sizes.
1014 * If resending a FIN, be sure not to use a new sequence number.
1016 if (flags
& TH_FIN
&& tp
->t_flags
& TF_SENTFIN
&&
1017 tp
->snd_nxt
== tp
->snd_max
)
1020 * If we are doing retransmissions, then snd_nxt will
1021 * not reflect the first unsent octet. For ACK only
1022 * packets, we do not want the sequence number of the
1023 * retransmitted packet, we want the sequence number
1024 * of the next unsent octet. So, if there is no data
1025 * (and no SYN or FIN), use snd_max instead of snd_nxt
1026 * when filling in ti_seq. But if we are in persist
1027 * state, snd_max might reflect one byte beyond the
1028 * right edge of the window, so use snd_nxt in that
1029 * case, since we know we aren't doing a retransmission.
1030 * (retransmit and persist are mutually exclusive...)
1032 if (sack_rxmit
== 0) {
1033 if (len
|| (flags
& (TH_SYN
|TH_FIN
)) || tp
->t_timer
[TCPT_PERSIST
])
1034 th
->th_seq
= htonl(tp
->snd_nxt
);
1036 th
->th_seq
= htonl(tp
->snd_max
);
1038 th
->th_seq
= htonl(p
->rxmit
);
1040 tp
->sackhint
.sack_bytes_rexmit
+= len
;
1042 th
->th_ack
= htonl(tp
->rcv_nxt
);
1044 bcopy(opt
, th
+ 1, optlen
);
1045 th
->th_off
= (sizeof (struct tcphdr
) + optlen
) >> 2;
1047 th
->th_flags
= flags
;
1049 * Calculate receive window. Don't shrink window,
1050 * but avoid silly window syndrome.
1052 if (recwin
< (long)(so
->so_rcv
.sb_hiwat
/ 4) && recwin
< (long)tp
->t_maxseg
)
1054 if (recwin
< (long)(tp
->rcv_adv
- tp
->rcv_nxt
))
1055 recwin
= (long)(tp
->rcv_adv
- tp
->rcv_nxt
);
1056 if (tp
->t_flags
& TF_SLOWLINK
&& slowlink_wsize
> 0) {
1057 if (recwin
> (long)slowlink_wsize
)
1058 recwin
= slowlink_wsize
;
1059 th
->th_win
= htons((u_short
) (recwin
>>tp
->rcv_scale
));
1062 if (recwin
> (long)TCP_MAXWIN
<< tp
->rcv_scale
)
1063 recwin
= (long)TCP_MAXWIN
<< tp
->rcv_scale
;
1064 th
->th_win
= htons((u_short
) (recwin
>>tp
->rcv_scale
));
1068 * Adjust the RXWIN0SENT flag - indicate that we have advertised
1069 * a 0 window. This may cause the remote transmitter to stall. This
1070 * flag tells soreceive() to disable delayed acknowledgements when
1071 * draining the buffer. This can occur if the receiver is attempting
1072 * to read more data then can be buffered prior to transmitting on
1076 tp
->t_flags
|= TF_RXWIN0SENT
;
1078 tp
->t_flags
&= ~TF_RXWIN0SENT
;
1079 if (SEQ_GT(tp
->snd_up
, tp
->snd_nxt
)) {
1080 th
->th_urp
= htons((u_short
)(tp
->snd_up
- tp
->snd_nxt
));
1081 th
->th_flags
|= TH_URG
;
1084 * If no urgent pointer to send, then we pull
1085 * the urgent pointer to the left edge of the send window
1086 * so that it doesn't drift into the send window on sequence
1087 * number wraparound.
1089 tp
->snd_up
= tp
->snd_una
; /* drag it along */
1092 * Put TCP length in extended header, and then
1093 * checksum extended header and data.
1095 m
->m_pkthdr
.len
= hdrlen
+ len
; /* in6_cksum() need this */
1099 * ip6_plen is not need to be filled now, and will be filled
1102 th
->th_sum
= in6_cksum(m
, IPPROTO_TCP
, sizeof(struct ip6_hdr
),
1103 sizeof(struct tcphdr
) + optlen
+ len
);
1107 m
->m_pkthdr
.csum_flags
= CSUM_TCP
;
1108 m
->m_pkthdr
.csum_data
= offsetof(struct tcphdr
, th_sum
);
1110 th
->th_sum
= in_addword(th
->th_sum
,
1111 htons((u_short
)(optlen
+ len
)));
1115 * In transmit state, time the transmission and arrange for
1116 * the retransmit. In persist state, just set snd_max.
1118 if (tp
->t_force
== 0 || tp
->t_timer
[TCPT_PERSIST
] == 0) {
1119 tcp_seq startseq
= tp
->snd_nxt
;
1122 * Advance snd_nxt over sequence space of this segment.
1124 if (flags
& (TH_SYN
|TH_FIN
)) {
1127 if (flags
& TH_FIN
) {
1129 tp
->t_flags
|= TF_SENTFIN
;
1135 if (SEQ_GT(tp
->snd_nxt
, tp
->snd_max
)) {
1136 tp
->snd_max
= tp
->snd_nxt
;
1138 * Time this transmission if not a retransmission and
1139 * not currently timing anything.
1141 if (tp
->t_rtttime
== 0) {
1143 tp
->t_rtseq
= startseq
;
1144 tcpstat
.tcps_segstimed
++;
1149 * Set retransmit timer if not currently set,
1150 * and not doing an ack or a keep-alive probe.
1151 * Initial value for retransmit timer is smoothed
1152 * round-trip time + 2 * round-trip time variance.
1153 * Initialize shift counter which is used for backoff
1154 * of retransmit time.
1157 if (tp
->t_timer
[TCPT_REXMT
] == 0 &&
1158 ((sack_rxmit
&& tp
->snd_nxt
!= tp
->snd_max
) ||
1159 tp
->snd_nxt
!= tp
->snd_una
)) {
1160 if (tp
->t_timer
[TCPT_PERSIST
]) {
1161 tp
->t_timer
[TCPT_PERSIST
] = 0;
1164 tp
->t_timer
[TCPT_REXMT
] = tp
->t_rxtcur
;
1168 * Persist case, update snd_max but since we are in
1169 * persist mode (no window) we do not update snd_nxt.
1174 if (flags
& TH_FIN
) {
1176 tp
->t_flags
|= TF_SENTFIN
;
1178 if (SEQ_GT(tp
->snd_nxt
+ xlen
, tp
->snd_max
))
1179 tp
->snd_max
= tp
->snd_nxt
+ len
;
1186 if (so
->so_options
& SO_DEBUG
)
1187 tcp_trace(TA_OUTPUT
, tp
->t_state
, tp
, mtod(m
, void *), th
, 0);
1191 * Fill in IP length and desired time to live and
1192 * send to IP level. There should be a better way
1193 * to handle ttl and tos; we could keep them in
1194 * the template, but need a way to checksum without them.
1197 * m->m_pkthdr.len should have been set before cksum calcuration,
1198 * because in6_cksum() need it.
1203 * we separately set hoplimit for every segment, since the
1204 * user might want to change the value via setsockopt.
1205 * Also, desired default hop limit might be changed via
1206 * Neighbor Discovery.
1208 ip6
->ip6_hlim
= in6_selecthlim(tp
->t_inpcb
,
1209 tp
->t_inpcb
->in6p_route
.ro_rt
?
1210 tp
->t_inpcb
->in6p_route
.ro_rt
->rt_ifp
1213 /* TODO: IPv6 IP6TOS_ECT bit on */
1215 if (ipsec_bypass
== 0 && ipsec_setsocket(m
, so
) != 0) {
1221 m
->m_pkthdr
.socket_id
= socket_id
;
1222 error
= ip6_output(m
,
1223 tp
->t_inpcb
->in6p_outputopts
,
1224 &tp
->t_inpcb
->in6p_route
,
1225 (so
->so_options
& SO_DONTROUTE
), NULL
, NULL
, 0);
1230 ip
->ip_len
= m
->m_pkthdr
.len
;
1233 ip
->ip_ttl
= in6_selecthlim(tp
->t_inpcb
,
1234 tp
->t_inpcb
->in6p_route
.ro_rt
?
1235 tp
->t_inpcb
->in6p_route
.ro_rt
->rt_ifp
1239 ip
->ip_ttl
= tp
->t_inpcb
->inp_ip_ttl
; /* XXX */
1240 ip
->ip_tos
= tp
->t_inpcb
->inp_ip_tos
; /* XXX */
1245 KERNEL_DEBUG(DBG_LAYER_BEG
,
1246 ((tp
->t_inpcb
->inp_fport
<< 16) | tp
->t_inpcb
->inp_lport
),
1247 (((tp
->t_inpcb
->in6p_laddr
.s6_addr16
[0] & 0xffff) << 16) |
1248 (tp
->t_inpcb
->in6p_faddr
.s6_addr16
[0] & 0xffff)),
1254 KERNEL_DEBUG(DBG_LAYER_BEG
,
1255 ((tp
->t_inpcb
->inp_fport
<< 16) | tp
->t_inpcb
->inp_lport
),
1256 (((tp
->t_inpcb
->inp_laddr
.s_addr
& 0xffff) << 16) |
1257 (tp
->t_inpcb
->inp_faddr
.s_addr
& 0xffff)),
1262 * See if we should do MTU discovery. We do it only if the following
1264 * 1) we have a valid route to the destination
1265 * 2) the MTU is not locked (if it is, then discovery has been
1268 if (path_mtu_discovery
1269 && (rt
= tp
->t_inpcb
->inp_route
.ro_rt
)
1270 && rt
->rt_flags
& RTF_UP
1271 && !(rt
->rt_rmx
.rmx_locks
& RTV_MTU
)) {
1272 ip
->ip_off
|= IP_DF
;
1275 if (ipsec_bypass
== 0)
1276 ipsec_setsocket(m
, so
);
1280 * The socket is kept locked while sending out packets in ip_output, even if packet chaining is not active.
1283 m
->m_pkthdr
.socket_id
= socket_id
;
1285 m
->m_nextpkt
= NULL
;
1286 lastpacket
->m_nextpkt
= m
;
1288 packchain_listadd
++;
1291 m
->m_nextpkt
= NULL
;
1292 packchain_newlist
++;
1293 packetlist
= lastpacket
= m
;
1294 packchain_listadd
=0;
1297 if ((ipsec_bypass
== 0) || fw_enable
|| sendalot
== 0 || (tp
->t_state
!= TCPS_ESTABLISHED
) ||
1298 (tp
->snd_cwnd
<= (tp
->snd_wnd
/ 4)) ||
1299 (tp
->t_flags
& (TH_PUSH
| TF_ACKNOW
)) || tp
->t_force
!= 0 ||
1300 packchain_listadd
>= tcp_packet_chaining
) {
1301 lastpacket
->m_nextpkt
= 0;
1302 error
= ip_output_list(packetlist
, packchain_listadd
, tp
->t_inpcb
->inp_options
, &tp
->t_inpcb
->inp_route
,
1303 (so
->so_options
& SO_DONTROUTE
), 0);
1304 tp
->t_lastchain
= packchain_listadd
;
1313 tcpstat
.tcps_sndtotal
++;
1314 if (recwin
> 0 && SEQ_GT(tp
->rcv_nxt
+recwin
, tp
->rcv_adv
))
1315 tp
->rcv_adv
= tp
->rcv_nxt
+ recwin
;
1316 tp
->last_ack_sent
= tp
->rcv_nxt
;
1317 tp
->t_flags
&= ~(TF_ACKNOW
|TF_DELACK
);
1324 * We know that the packet was lost, so back out the
1325 * sequence number advance, if any.
1327 if (tp
->t_force
== 0 || tp
->t_timer
[TCPT_PERSIST
] == 0) {
1329 * No need to check for TH_FIN here because
1330 * the TF_SENTFIN flag handles that case.
1332 if ((flags
& TH_SYN
) == 0) {
1334 p
->rxmit
-= howmuchsent
;
1335 tp
->sackhint
.sack_bytes_rexmit
-= howmuchsent
;
1337 tp
->snd_nxt
-= howmuchsent
;
1342 if (error
== ENOBUFS
) {
1343 if (!tp
->t_timer
[TCPT_REXMT
] &&
1344 !tp
->t_timer
[TCPT_PERSIST
])
1345 tp
->t_timer
[TCPT_REXMT
] = tp
->t_rxtcur
;
1346 tcp_quench(tp
->t_inpcb
, 0);
1348 m_freem_list(packetlist
);
1349 tp
->t_lastchain
= 0;
1350 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT
| DBG_FUNC_END
, 0,0,0,0,0);
1353 if (error
== EMSGSIZE
) {
1355 * ip_output() will have already fixed the route
1356 * for us. tcp_mtudisc() will, as its last action,
1357 * initiate retransmission, so it is important to
1360 tcp_mtudisc(tp
->t_inpcb
, 0);
1362 m_freem_list(packetlist
);
1363 tp
->t_lastchain
= 0;
1364 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT
| DBG_FUNC_END
, 0,0,0,0,0);
1367 if ((error
== EHOSTUNREACH
|| error
== ENETDOWN
)
1368 && TCPS_HAVERCVDSYN(tp
->t_state
)) {
1369 tp
->t_softerror
= error
;
1371 m_freem_list(packetlist
);
1372 tp
->t_lastchain
= 0;
1373 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT
| DBG_FUNC_END
, 0,0,0,0,0);
1377 m_freem_list(packetlist
);
1378 tp
->t_lastchain
= 0;
1379 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT
| DBG_FUNC_END
, 0,0,0,0,0);
1383 tcpstat
.tcps_sndtotal
++;
1386 * Data sent (as far as we can tell).
1387 * If this advertises a larger window than any other segment,
1388 * then remember the size of the advertised window.
1389 * Any pending ACK has now been sent.
1391 if (recwin
> 0 && SEQ_GT(tp
->rcv_nxt
+recwin
, tp
->rcv_adv
))
1392 tp
->rcv_adv
= tp
->rcv_nxt
+ recwin
;
1393 tp
->last_ack_sent
= tp
->rcv_nxt
;
1394 tp
->t_flags
&= ~(TF_ACKNOW
|TF_DELACK
);
1396 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT
| DBG_FUNC_END
,0,0,0,0,0);
1397 if (sendalot
&& (!tcp_do_newreno
|| --maxburst
))
1404 register struct tcpcb
*tp
;
1406 int t
= ((tp
->t_srtt
>> 2) + tp
->t_rttvar
) >> 1;
1408 if (tp
->t_timer
[TCPT_REXMT
])
1409 panic("tcp_setpersist: retransmit pending");
1411 * Start/restart persistance timer.
1413 TCPT_RANGESET(tp
->t_timer
[TCPT_PERSIST
],
1414 t
* tcp_backoff
[tp
->t_rxtshift
],
1415 TCPTV_PERSMIN
, TCPTV_PERSMAX
);
1416 if (tp
->t_rxtshift
< TCP_MAXRXTSHIFT
)