]> git.saurik.com Git - apple/xnu.git/blob - bsd/netinet/tcp_output.c
eb2fbd0b3c4b2e5d79967e8a04f71501d98650bc
[apple/xnu.git] / bsd / netinet / tcp_output.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
25 * The Regents of the University of California. All rights reserved.
26 *
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
29 * are met:
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * SUCH DAMAGE.
54 *
55 * @(#)tcp_output.c 8.4 (Berkeley) 5/24/95
56 * $FreeBSD: src/sys/netinet/tcp_output.c,v 1.39.2.10 2001/07/07 04:30:38 silby Exp $
57 */
58
59 #define _IP_VHL
60
61
62 #include <sys/param.h>
63 #include <sys/systm.h>
64 #include <sys/kernel.h>
65 #include <sys/sysctl.h>
66 #include <sys/mbuf.h>
67 #include <sys/domain.h>
68 #include <sys/protosw.h>
69 #include <sys/socket.h>
70 #include <sys/socketvar.h>
71
72 #include <net/route.h>
73
74 #include <netinet/in.h>
75 #include <netinet/in_systm.h>
76 #include <netinet/ip.h>
77 #include <netinet/in_pcb.h>
78 #include <netinet/ip_var.h>
79 #if INET6
80 #include <netinet6/in6_pcb.h>
81 #include <netinet/ip6.h>
82 #include <netinet6/ip6_var.h>
83 #endif
84 #include <netinet/tcp.h>
85 #define TCPOUTFLAGS
86 #include <netinet/tcp_fsm.h>
87 #include <netinet/tcp_seq.h>
88 #include <netinet/tcp_timer.h>
89 #include <netinet/tcp_var.h>
90 #include <netinet/tcpip.h>
91 #if TCPDEBUG
92 #include <netinet/tcp_debug.h>
93 #endif
94 #include <sys/kdebug.h>
95
96 #if IPSEC
97 #include <netinet6/ipsec.h>
98 #endif /*IPSEC*/
99
100 #define DBG_LAYER_BEG NETDBG_CODE(DBG_NETTCP, 1)
101 #define DBG_LAYER_END NETDBG_CODE(DBG_NETTCP, 3)
102 #define DBG_FNC_TCP_OUTPUT NETDBG_CODE(DBG_NETTCP, (4 << 8) | 1)
103
104
105 #ifdef notyet
106 extern struct mbuf *m_copypack();
107 #endif
108
109 static int path_mtu_discovery = 1;
110 SYSCTL_INT(_net_inet_tcp, OID_AUTO, path_mtu_discovery, CTLFLAG_RW,
111 &path_mtu_discovery, 1, "Enable Path MTU Discovery");
112
113 int ss_fltsz = 1;
114 SYSCTL_INT(_net_inet_tcp, OID_AUTO, slowstart_flightsize, CTLFLAG_RW,
115 &ss_fltsz, 1, "Slow start flight size");
116
117 int ss_fltsz_local = 4; /* starts with four segments max */
118 SYSCTL_INT(_net_inet_tcp, OID_AUTO, local_slowstart_flightsize, CTLFLAG_RW,
119 &ss_fltsz_local, 1, "Slow start flight size for local networks");
120
121 int tcp_do_newreno = 0;
122 SYSCTL_INT(_net_inet_tcp, OID_AUTO, newreno, CTLFLAG_RW, &tcp_do_newreno,
123 0, "Enable NewReno Algorithms");
124
125 int tcp_packet_chaining = 50;
126 SYSCTL_INT(_net_inet_tcp, OID_AUTO, packetchain, CTLFLAG_RW, &tcp_packet_chaining,
127 0, "Enable TCP output packet chaining");
128
129 struct mbuf *m_copym_with_hdrs(struct mbuf*, int, int, int, struct mbuf**, int*);
130 static long packchain_newlist = 0;
131 static long packchain_looped = 0;
132 static long packchain_sent = 0;
133
134
135 /* temporary: for testing */
136 #if IPSEC
137 extern int ipsec_bypass;
138 #endif
139
140 extern int slowlink_wsize; /* window correction for slow links */
141 extern u_long route_generation;
142 extern int fw_enable; /* firewall is on: disable packet chaining */
143 extern int ipsec_bypass;
144
145 extern vm_size_t so_cache_zone_element_size;
146
147 static __inline__ u_int16_t
148 get_socket_id(struct socket * s)
149 {
150 u_int16_t val;
151
152 if (so_cache_zone_element_size == 0) {
153 return (0);
154 }
155 val = (u_int16_t)(((u_int32_t)s) / so_cache_zone_element_size);
156 if (val == 0) {
157 val = 0xffff;
158 }
159 return (val);
160 }
161
162 /*
163 * Tcp output routine: figure out what should be sent and send it.
164 */
165 int
166 tcp_output(tp)
167 register struct tcpcb *tp;
168 {
169 register struct socket *so = tp->t_inpcb->inp_socket;
170 register long len, win;
171 int off, flags, error;
172 register struct mbuf *m;
173 struct ip *ip = NULL;
174 register struct ipovly *ipov = NULL;
175 #if INET6
176 struct ip6_hdr *ip6 = NULL;
177 #endif /* INET6 */
178 register struct tcphdr *th;
179 u_char opt[TCP_MAXOLEN];
180 unsigned ipoptlen, optlen, hdrlen;
181 int idle, sendalot, howmuchsent = 0;
182 int maxburst = TCP_MAXBURST;
183 struct rmxp_tao *taop;
184 struct rmxp_tao tao_noncached;
185 int last_off = 0;
186 int m_off;
187 struct mbuf *m_last = 0;
188 struct mbuf *m_head = 0;
189 struct mbuf *packetlist = 0;
190 struct mbuf *lastpacket = 0;
191 #if INET6
192 int isipv6 = tp->t_inpcb->inp_vflag & INP_IPV6 ;
193 #endif
194 short packchain_listadd = 0;
195 u_int16_t socket_id = get_socket_id(so);
196
197
198 /*
199 * Determine length of data that should be transmitted,
200 * and flags that will be used.
201 * If there is some data or critical controls (SYN, RST)
202 * to send, then transmit; otherwise, investigate further.
203 */
204 idle = (tp->snd_max == tp->snd_una);
205 if (idle && tp->t_rcvtime >= tp->t_rxtcur) {
206 /*
207 * We have been idle for "a while" and no acks are
208 * expected to clock out any data we send --
209 * slow start to get ack "clock" running again.
210 *
211 * Set the slow-start flight size depending on whether
212 * this is a local network or not.
213 */
214 if (
215 #if INET6
216 (isipv6 && in6_localaddr(&tp->t_inpcb->in6p_faddr)) ||
217 (!isipv6 &&
218 #endif
219 in_localaddr(tp->t_inpcb->inp_faddr)
220 #if INET6
221 )
222 #endif
223 )
224 tp->snd_cwnd = tp->t_maxseg * ss_fltsz_local;
225 else
226 tp->snd_cwnd = tp->t_maxseg * ss_fltsz;
227 }
228
229 again:
230 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT | DBG_FUNC_START, 0,0,0,0,0);
231
232 #if INET6
233 if (isipv6) {
234
235 KERNEL_DEBUG(DBG_LAYER_BEG,
236 ((tp->t_inpcb->inp_fport << 16) | tp->t_inpcb->inp_lport),
237 (((tp->t_inpcb->in6p_laddr.s6_addr16[0] & 0xffff) << 16) |
238 (tp->t_inpcb->in6p_faddr.s6_addr16[0] & 0xffff)),
239 sendalot,0,0);
240 }
241 else
242 #endif
243
244 {
245 KERNEL_DEBUG(DBG_LAYER_BEG,
246 ((tp->t_inpcb->inp_fport << 16) | tp->t_inpcb->inp_lport),
247 (((tp->t_inpcb->inp_laddr.s_addr & 0xffff) << 16) |
248 (tp->t_inpcb->inp_faddr.s_addr & 0xffff)),
249 sendalot,0,0);
250 /*
251 * If the route generation id changed, we need to check that our
252 * local (source) IP address is still valid. If it isn't either
253 * return error or silently do nothing (assuming the address will
254 * come back before the TCP connection times out).
255 */
256
257 if ((tp->t_inpcb->inp_route.ro_rt != NULL &&
258 (tp->t_inpcb->inp_route.ro_rt->generation_id != route_generation)) || (tp->t_inpcb->inp_route.ro_rt == NULL)) {
259 /* check that the source address is still valid */
260 if (ifa_foraddr(tp->t_inpcb->inp_laddr.s_addr) == 0) {
261 if (tp->t_state >= TCPS_CLOSE_WAIT) {
262 tcp_close(tp);
263 return(EADDRNOTAVAIL);
264 }
265
266 /* set Retransmit timer if it wasn't set
267 * reset Persist timer and shift register as the
268 * adversed peer window may not be valid anymore
269 */
270
271 if (!tp->t_timer[TCPT_REXMT]) {
272 tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
273 if (tp->t_timer[TCPT_PERSIST]) {
274 tp->t_timer[TCPT_PERSIST] = 0;
275 tp->t_rxtshift = 0;
276 }
277 }
278
279 if (packetlist) {
280 error = ip_output_list(packetlist, packchain_listadd, tp->t_inpcb->inp_options, &tp->t_inpcb->inp_route,
281 (so->so_options & SO_DONTROUTE), 0);
282 tp->t_lastchain = 0;
283 }
284 if (so->so_flags & SOF_NOADDRAVAIL)
285 return(EADDRNOTAVAIL);
286 else
287 return(0); /* silently ignore and keep data in socket */
288 }
289 }
290 }
291 sendalot = 0;
292 off = tp->snd_nxt - tp->snd_una;
293 win = min(tp->snd_wnd, tp->snd_cwnd);
294 if (tp->t_flags & TF_SLOWLINK && slowlink_wsize > 0)
295 win = min(win, slowlink_wsize);
296
297 flags = tcp_outflags[tp->t_state];
298 /*
299 * Get standard flags, and add SYN or FIN if requested by 'hidden'
300 * state flags.
301 */
302 if (tp->t_flags & TF_NEEDFIN)
303 flags |= TH_FIN;
304 if (tp->t_flags & TF_NEEDSYN)
305 flags |= TH_SYN;
306
307 /*
308 * If in persist timeout with window of 0, send 1 byte.
309 * Otherwise, if window is small but nonzero
310 * and timer expired, we will send what we can
311 * and go to transmit state.
312 */
313 if (tp->t_force) {
314 if (win == 0) {
315 /*
316 * If we still have some data to send, then
317 * clear the FIN bit. Usually this would
318 * happen below when it realizes that we
319 * aren't sending all the data. However,
320 * if we have exactly 1 byte of unsent data,
321 * then it won't clear the FIN bit below,
322 * and if we are in persist state, we wind
323 * up sending the packet without recording
324 * that we sent the FIN bit.
325 *
326 * We can't just blindly clear the FIN bit,
327 * because if we don't have any more data
328 * to send then the probe will be the FIN
329 * itself.
330 */
331 if (off < so->so_snd.sb_cc)
332 flags &= ~TH_FIN;
333 win = 1;
334 } else {
335 tp->t_timer[TCPT_PERSIST] = 0;
336 tp->t_rxtshift = 0;
337 }
338 }
339
340 len = (long)ulmin(so->so_snd.sb_cc, win) - off;
341
342 if ((taop = tcp_gettaocache(tp->t_inpcb)) == NULL) {
343 taop = &tao_noncached;
344 bzero(taop, sizeof(*taop));
345 }
346
347 /*
348 * Lop off SYN bit if it has already been sent. However, if this
349 * is SYN-SENT state and if segment contains data and if we don't
350 * know that foreign host supports TAO, suppress sending segment.
351 */
352 if ((flags & TH_SYN) && SEQ_GT(tp->snd_nxt, tp->snd_una)) {
353 flags &= ~TH_SYN;
354 off--, len++;
355 if (len > 0 && tp->t_state == TCPS_SYN_SENT &&
356 taop->tao_ccsent == 0) {
357 if (packetlist) {
358 error = ip_output_list(packetlist, packchain_listadd, tp->t_inpcb->inp_options, &tp->t_inpcb->inp_route,
359 (so->so_options & SO_DONTROUTE), 0);
360 tp->t_lastchain = 0;
361 }
362 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT | DBG_FUNC_END, 0,0,0,0,0);
363 return 0;
364 }
365 }
366
367 /*
368 * Be careful not to send data and/or FIN on SYN segments
369 * in cases when no CC option will be sent.
370 * This measure is needed to prevent interoperability problems
371 * with not fully conformant TCP implementations.
372 */
373 if ((flags & TH_SYN) &&
374 ((tp->t_flags & TF_NOOPT) || !(tp->t_flags & TF_REQ_CC) ||
375 ((flags & TH_ACK) && !(tp->t_flags & TF_RCVD_CC)))) {
376 len = 0;
377 flags &= ~TH_FIN;
378 }
379
380 if (len < 0) {
381 /*
382 * If FIN has been sent but not acked,
383 * but we haven't been called to retransmit,
384 * len will be -1. Otherwise, window shrank
385 * after we sent into it. If window shrank to 0,
386 * cancel pending retransmit, pull snd_nxt back
387 * to (closed) window, and set the persist timer
388 * if it isn't already going. If the window didn't
389 * close completely, just wait for an ACK.
390 */
391 len = 0;
392 if (win == 0) {
393 tp->t_timer[TCPT_REXMT] = 0;
394 tp->t_rxtshift = 0;
395 tp->snd_nxt = tp->snd_una;
396 if (tp->t_timer[TCPT_PERSIST] == 0)
397 tcp_setpersist(tp);
398 }
399 }
400 if (len > tp->t_maxseg) {
401 len = tp->t_maxseg;
402 howmuchsent += len;
403 sendalot = 1;
404 }
405 if (SEQ_LT(tp->snd_nxt + len, tp->snd_una + so->so_snd.sb_cc))
406 flags &= ~TH_FIN;
407
408 if (tp->t_flags & TF_SLOWLINK && slowlink_wsize > 0 ) /* Clips window size for slow links */
409 win = min(sbspace(&so->so_rcv), slowlink_wsize);
410 else
411 win = sbspace(&so->so_rcv);
412
413 /*
414 * Sender silly window avoidance. If connection is idle
415 * and can send all data, a maximum segment,
416 * at least a maximum default-size segment do it,
417 * or are forced, do it; otherwise don't bother.
418 * If peer's buffer is tiny, then send
419 * when window is at least half open.
420 * If retransmitting (possibly after persist timer forced us
421 * to send into a small window), then must resend.
422 */
423 if (len) {
424 if (len == tp->t_maxseg)
425 goto send;
426 if (!(tp->t_flags & TF_MORETOCOME) &&
427 (idle || tp->t_flags & TF_NODELAY) &&
428 (tp->t_flags & TF_NOPUSH) == 0 &&
429 len + off >= so->so_snd.sb_cc)
430 goto send;
431 if (tp->t_force)
432 goto send;
433 if (len >= tp->max_sndwnd / 2 && tp->max_sndwnd > 0)
434 goto send;
435 if (SEQ_LT(tp->snd_nxt, tp->snd_max))
436 goto send;
437 }
438
439 /*
440 * Compare available window to amount of window
441 * known to peer (as advertised window less
442 * next expected input). If the difference is at least two
443 * max size segments, or at least 50% of the maximum possible
444 * window, then want to send a window update to peer.
445 */
446 if (win > 0) {
447 /*
448 * "adv" is the amount we can increase the window,
449 * taking into account that we are limited by
450 * TCP_MAXWIN << tp->rcv_scale.
451 */
452 long adv = min(win, (long)TCP_MAXWIN << tp->rcv_scale) -
453 (tp->rcv_adv - tp->rcv_nxt);
454
455 if (adv >= (long) (2 * tp->t_maxseg))
456 goto send;
457 if (2 * adv >= (long) so->so_rcv.sb_hiwat)
458 goto send;
459 }
460
461 /*
462 * Send if we owe peer an ACK.
463 */
464 if (tp->t_flags & TF_ACKNOW)
465 goto send;
466 if ((flags & TH_RST) ||
467 ((flags & TH_SYN) && (tp->t_flags & TF_NEEDSYN) == 0))
468 goto send;
469 if (SEQ_GT(tp->snd_up, tp->snd_una))
470 goto send;
471 /*
472 * If our state indicates that FIN should be sent
473 * and we have not yet done so, or we're retransmitting the FIN,
474 * then we need to send.
475 */
476 if (flags & TH_FIN &&
477 ((tp->t_flags & TF_SENTFIN) == 0 || tp->snd_nxt == tp->snd_una))
478 goto send;
479
480 /*
481 * TCP window updates are not reliable, rather a polling protocol
482 * using ``persist'' packets is used to insure receipt of window
483 * updates. The three ``states'' for the output side are:
484 * idle not doing retransmits or persists
485 * persisting to move a small or zero window
486 * (re)transmitting and thereby not persisting
487 *
488 * tp->t_timer[TCPT_PERSIST]
489 * is set when we are in persist state.
490 * tp->t_force
491 * is set when we are called to send a persist packet.
492 * tp->t_timer[TCPT_REXMT]
493 * is set when we are retransmitting
494 * The output side is idle when both timers are zero.
495 *
496 * If send window is too small, there is data to transmit, and no
497 * retransmit or persist is pending, then go to persist state.
498 * If nothing happens soon, send when timer expires:
499 * if window is nonzero, transmit what we can,
500 * otherwise force out a byte.
501 */
502 if (so->so_snd.sb_cc && tp->t_timer[TCPT_REXMT] == 0 &&
503 tp->t_timer[TCPT_PERSIST] == 0) {
504 tp->t_rxtshift = 0;
505 tcp_setpersist(tp);
506 }
507
508 /*
509 * If there is no reason to send a segment, just return.
510 * but if there is some packets left in the packet list, send them now.
511 */
512 if (packetlist) {
513 error = ip_output_list(packetlist, packchain_listadd, tp->t_inpcb->inp_options, &tp->t_inpcb->inp_route,
514 (so->so_options & SO_DONTROUTE), 0);
515 }
516 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT | DBG_FUNC_END, 0,0,0,0,0);
517 return (0);
518
519 send:
520 /*
521 * Before ESTABLISHED, force sending of initial options
522 * unless TCP set not to do any options.
523 * NOTE: we assume that the IP/TCP header plus TCP options
524 * always fit in a single mbuf, leaving room for a maximum
525 * link header, i.e.
526 * max_linkhdr + sizeof (struct tcpiphdr) + optlen <= MCLBYTES
527 */
528 optlen = 0;
529 #if INET6
530 if (isipv6)
531 hdrlen = sizeof (struct ip6_hdr) + sizeof (struct tcphdr);
532 else
533 #endif
534 hdrlen = sizeof (struct tcpiphdr);
535 if (flags & TH_SYN) {
536 tp->snd_nxt = tp->iss;
537 if ((tp->t_flags & TF_NOOPT) == 0) {
538 u_short mss;
539
540 opt[0] = TCPOPT_MAXSEG;
541 opt[1] = TCPOLEN_MAXSEG;
542 mss = htons((u_short) tcp_mssopt(tp));
543 (void)memcpy(opt + 2, &mss, sizeof(mss));
544 optlen = TCPOLEN_MAXSEG;
545
546 if ((tp->t_flags & TF_REQ_SCALE) &&
547 ((flags & TH_ACK) == 0 ||
548 (tp->t_flags & TF_RCVD_SCALE))) {
549 *((u_int32_t *)(opt + optlen)) = htonl(
550 TCPOPT_NOP << 24 |
551 TCPOPT_WINDOW << 16 |
552 TCPOLEN_WINDOW << 8 |
553 tp->request_r_scale);
554 optlen += 4;
555 }
556 }
557 }
558
559 /*
560 * Send a timestamp and echo-reply if this is a SYN and our side
561 * wants to use timestamps (TF_REQ_TSTMP is set) or both our side
562 * and our peer have sent timestamps in our SYN's.
563 */
564 if ((tp->t_flags & (TF_REQ_TSTMP|TF_NOOPT)) == TF_REQ_TSTMP &&
565 (flags & TH_RST) == 0 &&
566 ((flags & TH_ACK) == 0 ||
567 (tp->t_flags & TF_RCVD_TSTMP))) {
568 u_int32_t *lp = (u_int32_t *)(opt + optlen);
569
570 /* Form timestamp option as shown in appendix A of RFC 1323. */
571 *lp++ = htonl(TCPOPT_TSTAMP_HDR);
572 *lp++ = htonl(tcp_now);
573 *lp = htonl(tp->ts_recent);
574 optlen += TCPOLEN_TSTAMP_APPA;
575 }
576
577 /*
578 * Send `CC-family' options if our side wants to use them (TF_REQ_CC),
579 * options are allowed (!TF_NOOPT) and it's not a RST.
580 */
581 if ((tp->t_flags & (TF_REQ_CC|TF_NOOPT)) == TF_REQ_CC &&
582 (flags & TH_RST) == 0) {
583 switch (flags & (TH_SYN|TH_ACK)) {
584 /*
585 * This is a normal ACK, send CC if we received CC before
586 * from our peer.
587 */
588 case TH_ACK:
589 if (!(tp->t_flags & TF_RCVD_CC))
590 break;
591 /*FALLTHROUGH*/
592
593 /*
594 * We can only get here in T/TCP's SYN_SENT* state, when
595 * we're a sending a non-SYN segment without waiting for
596 * the ACK of our SYN. A check above assures that we only
597 * do this if our peer understands T/TCP.
598 */
599 case 0:
600 opt[optlen++] = TCPOPT_NOP;
601 opt[optlen++] = TCPOPT_NOP;
602 opt[optlen++] = TCPOPT_CC;
603 opt[optlen++] = TCPOLEN_CC;
604 *(u_int32_t *)&opt[optlen] = htonl(tp->cc_send);
605
606 optlen += 4;
607 break;
608
609 /*
610 * This is our initial SYN, check whether we have to use
611 * CC or CC.new.
612 */
613 case TH_SYN:
614 opt[optlen++] = TCPOPT_NOP;
615 opt[optlen++] = TCPOPT_NOP;
616 opt[optlen++] = tp->t_flags & TF_SENDCCNEW ?
617 TCPOPT_CCNEW : TCPOPT_CC;
618 opt[optlen++] = TCPOLEN_CC;
619 *(u_int32_t *)&opt[optlen] = htonl(tp->cc_send);
620 optlen += 4;
621 break;
622
623 /*
624 * This is a SYN,ACK; send CC and CC.echo if we received
625 * CC from our peer.
626 */
627 case (TH_SYN|TH_ACK):
628 if (tp->t_flags & TF_RCVD_CC) {
629 opt[optlen++] = TCPOPT_NOP;
630 opt[optlen++] = TCPOPT_NOP;
631 opt[optlen++] = TCPOPT_CC;
632 opt[optlen++] = TCPOLEN_CC;
633 *(u_int32_t *)&opt[optlen] =
634 htonl(tp->cc_send);
635 optlen += 4;
636 opt[optlen++] = TCPOPT_NOP;
637 opt[optlen++] = TCPOPT_NOP;
638 opt[optlen++] = TCPOPT_CCECHO;
639 opt[optlen++] = TCPOLEN_CC;
640 *(u_int32_t *)&opt[optlen] =
641 htonl(tp->cc_recv);
642 optlen += 4;
643 }
644 break;
645 }
646 }
647
648 hdrlen += optlen;
649 #if INET6
650 if (isipv6)
651 ipoptlen = ip6_optlen(tp->t_inpcb);
652 else
653 #endif
654 {
655 if (tp->t_inpcb->inp_options) {
656 ipoptlen = tp->t_inpcb->inp_options->m_len -
657 offsetof(struct ipoption, ipopt_list);
658 } else {
659 ipoptlen = 0;
660 }
661 }
662 #if IPSEC
663 if (ipsec_bypass == 0)
664 ipoptlen += ipsec_hdrsiz_tcp(tp);
665 #endif
666
667 /*
668 * Adjust data length if insertion of options will
669 * bump the packet length beyond the t_maxopd length.
670 * Clear the FIN bit because we cut off the tail of
671 * the segment.
672 */
673 if (len + optlen + ipoptlen > tp->t_maxopd) {
674 /*
675 * If there is still more to send, don't close the connection.
676 */
677 flags &= ~TH_FIN;
678 len = tp->t_maxopd - optlen - ipoptlen;
679 howmuchsent += len;
680 sendalot = 1;
681 }
682
683 /*#ifdef DIAGNOSTIC*/
684 #if INET6
685 if (max_linkhdr + hdrlen > MCLBYTES)
686 panic("tcphdr too big");
687 #else
688 if (max_linkhdr + hdrlen > MHLEN)
689 panic("tcphdr too big");
690 #endif
691 /*#endif*/
692
693 /*
694 * Grab a header mbuf, attaching a copy of data to
695 * be transmitted, and initialize the header from
696 * the template for sends on this connection.
697 */
698 if (len) {
699 if (tp->t_force && len == 1)
700 tcpstat.tcps_sndprobe++;
701 else if (SEQ_LT(tp->snd_nxt, tp->snd_max)) {
702 tcpstat.tcps_sndrexmitpack++;
703 tcpstat.tcps_sndrexmitbyte += len;
704 } else {
705 tcpstat.tcps_sndpack++;
706 tcpstat.tcps_sndbyte += len;
707 }
708 #ifdef notyet
709 if ((m = m_copypack(so->so_snd.sb_mb, off,
710 (int)len, max_linkhdr + hdrlen)) == 0) {
711 error = ENOBUFS;
712 goto out;
713 }
714 /*
715 * m_copypack left space for our hdr; use it.
716 */
717 m->m_len += hdrlen;
718 m->m_data -= hdrlen;
719 #else
720 /*
721 * try to use the new interface that allocates all
722 * the necessary mbuf hdrs under 1 mbuf lock and
723 * avoids rescanning the socket mbuf list if
724 * certain conditions are met. This routine can't
725 * be used in the following cases...
726 * 1) the protocol headers exceed the capacity of
727 * of a single mbuf header's data area (no cluster attached)
728 * 2) the length of the data being transmitted plus
729 * the protocol headers fits into a single mbuf header's
730 * data area (no cluster attached)
731 */
732 m = NULL;
733 #if INET6
734 if (MHLEN < hdrlen + max_linkhdr) {
735 MGETHDR(m, M_DONTWAIT, MT_HEADER);
736 if (m == NULL) {
737 error = ENOBUFS;
738 goto out;
739 }
740 MCLGET(m, M_DONTWAIT);
741 if ((m->m_flags & M_EXT) == 0) {
742 m_freem(m);
743 error = ENOBUFS;
744 goto out;
745 }
746 m->m_data += max_linkhdr;
747 m->m_len = hdrlen;
748 }
749 #endif
750 if (len <= MHLEN - hdrlen - max_linkhdr) {
751 if (m == NULL) {
752 MGETHDR(m, M_DONTWAIT, MT_HEADER);
753 if (m == NULL) {
754 error = ENOBUFS;
755 goto out;
756 }
757 m->m_data += max_linkhdr;
758 m->m_len = hdrlen;
759 }
760 /* makes sure we still have data left to be sent at this point */
761 if (so->so_snd.sb_mb == NULL || off == -1) {
762 if (m != NULL) m_freem(m);
763 error = 0; /* should we return an error? */
764 goto out;
765 }
766 m_copydata(so->so_snd.sb_mb, off, (int) len,
767 mtod(m, caddr_t) + hdrlen);
768 m->m_len += len;
769 } else {
770 if (m != NULL) {
771 m->m_next = m_copy(so->so_snd.sb_mb, off, (int) len);
772 if (m->m_next == 0) {
773 (void) m_free(m);
774 error = ENOBUFS;
775 goto out;
776 }
777 } else {
778 /*
779 * determine whether the mbuf pointer and offset passed back by the 'last' call
780 * to m_copym_with_hdrs are still valid... if the head of the socket chain has
781 * changed (due to an incoming ACK for instance), or the offset into the chain we
782 * just computed is different from the one last returned by m_copym_with_hdrs (perhaps
783 * we're re-transmitting a packet sent earlier), than we can't pass the mbuf pointer and
784 * offset into it as valid hints for m_copym_with_hdrs to use (if valid, these hints allow
785 * m_copym_with_hdrs to avoid rescanning from the beginning of the socket buffer mbuf list.
786 * setting the mbuf pointer to NULL is sufficient to disable the hint mechanism.
787 */
788 if (m_head != so->so_snd.sb_mb || last_off != off)
789 m_last = NULL;
790 last_off = off + len;
791 m_head = so->so_snd.sb_mb;
792
793 /* makes sure we still have data left to be sent at this point */
794 if (m_head == NULL) {
795 error = 0; /* should we return an error? */
796 goto out;
797 }
798
799 /*
800 * m_copym_with_hdrs will always return the last mbuf pointer and the offset into it that
801 * it acted on to fullfill the current request, whether a valid 'hint' was passed in or not
802 */
803 if ((m = m_copym_with_hdrs(so->so_snd.sb_mb, off, (int) len, M_DONTWAIT, &m_last, &m_off)) == NULL) {
804 error = ENOBUFS;
805 goto out;
806 }
807 m->m_data += max_linkhdr;
808 m->m_len = hdrlen;
809 }
810 }
811 #endif
812 /*
813 * If we're sending everything we've got, set PUSH.
814 * (This will keep happy those implementations which only
815 * give data to the user when a buffer fills or
816 * a PUSH comes in.)
817 */
818 if (off + len == so->so_snd.sb_cc)
819 flags |= TH_PUSH;
820 } else {
821 if (tp->t_flags & TF_ACKNOW)
822 tcpstat.tcps_sndacks++;
823 else if (flags & (TH_SYN|TH_FIN|TH_RST))
824 tcpstat.tcps_sndctrl++;
825 else if (SEQ_GT(tp->snd_up, tp->snd_una))
826 tcpstat.tcps_sndurg++;
827 else
828 tcpstat.tcps_sndwinup++;
829
830 MGETHDR(m, M_DONTWAIT, MT_HEADER);
831 if (m == NULL) {
832 error = ENOBUFS;
833 goto out;
834 }
835 #if INET6
836 if (isipv6 && (MHLEN < hdrlen + max_linkhdr) &&
837 MHLEN >= hdrlen) {
838 MH_ALIGN(m, hdrlen);
839 } else
840 #endif
841 m->m_data += max_linkhdr;
842 m->m_len = hdrlen;
843 }
844 m->m_pkthdr.rcvif = 0;
845 #if INET6
846 if (isipv6) {
847 ip6 = mtod(m, struct ip6_hdr *);
848 th = (struct tcphdr *)(ip6 + 1);
849 tcp_fillheaders(tp, ip6, th);
850 } else
851 #endif /* INET6 */
852 {
853 ip = mtod(m, struct ip *);
854 ipov = (struct ipovly *)ip;
855 th = (struct tcphdr *)(ip + 1);
856 /* this picks up the pseudo header (w/o the length) */
857 tcp_fillheaders(tp, ip, th);
858 }
859
860 /*
861 * Fill in fields, remembering maximum advertised
862 * window for use in delaying messages about window sizes.
863 * If resending a FIN, be sure not to use a new sequence number.
864 */
865 if (flags & TH_FIN && tp->t_flags & TF_SENTFIN &&
866 tp->snd_nxt == tp->snd_max)
867 tp->snd_nxt--;
868 /*
869 * If we are doing retransmissions, then snd_nxt will
870 * not reflect the first unsent octet. For ACK only
871 * packets, we do not want the sequence number of the
872 * retransmitted packet, we want the sequence number
873 * of the next unsent octet. So, if there is no data
874 * (and no SYN or FIN), use snd_max instead of snd_nxt
875 * when filling in ti_seq. But if we are in persist
876 * state, snd_max might reflect one byte beyond the
877 * right edge of the window, so use snd_nxt in that
878 * case, since we know we aren't doing a retransmission.
879 * (retransmit and persist are mutually exclusive...)
880 */
881 if (len || (flags & (TH_SYN|TH_FIN)) || tp->t_timer[TCPT_PERSIST])
882 th->th_seq = htonl(tp->snd_nxt);
883 else
884 th->th_seq = htonl(tp->snd_max);
885 th->th_ack = htonl(tp->rcv_nxt);
886 if (optlen) {
887 bcopy(opt, th + 1, optlen);
888 th->th_off = (sizeof (struct tcphdr) + optlen) >> 2;
889 }
890 th->th_flags = flags;
891 /*
892 * Calculate receive window. Don't shrink window,
893 * but avoid silly window syndrome.
894 */
895 if (win < (long)(so->so_rcv.sb_hiwat / 4) && win < (long)tp->t_maxseg)
896 win = 0;
897 if (win < (long)(tp->rcv_adv - tp->rcv_nxt))
898 win = (long)(tp->rcv_adv - tp->rcv_nxt);
899 if (tp->t_flags & TF_SLOWLINK && slowlink_wsize > 0) {
900 if (win > (long)slowlink_wsize)
901 win = slowlink_wsize;
902 th->th_win = htons((u_short) (win>>tp->rcv_scale));
903 }
904 else {
905
906 if (win > (long)TCP_MAXWIN << tp->rcv_scale)
907 win = (long)TCP_MAXWIN << tp->rcv_scale;
908 th->th_win = htons((u_short) (win>>tp->rcv_scale));
909 }
910
911 /*
912 * Adjust the RXWIN0SENT flag - indicate that we have advertised
913 * a 0 window. This may cause the remote transmitter to stall. This
914 * flag tells soreceive() to disable delayed acknowledgements when
915 * draining the buffer. This can occur if the receiver is attempting
916 * to read more data then can be buffered prior to transmitting on
917 * the connection.
918 */
919 if (win == 0)
920 tp->t_flags |= TF_RXWIN0SENT;
921 else
922 tp->t_flags &= ~TF_RXWIN0SENT;
923
924 if (SEQ_GT(tp->snd_up, tp->snd_nxt)) {
925 th->th_urp = htons((u_short)(tp->snd_up - tp->snd_nxt));
926 th->th_flags |= TH_URG;
927 } else
928 /*
929 * If no urgent pointer to send, then we pull
930 * the urgent pointer to the left edge of the send window
931 * so that it doesn't drift into the send window on sequence
932 * number wraparound.
933 */
934 tp->snd_up = tp->snd_una; /* drag it along */
935
936 /*
937 * Put TCP length in extended header, and then
938 * checksum extended header and data.
939 */
940 m->m_pkthdr.len = hdrlen + len; /* in6_cksum() need this */
941 #if INET6
942 if (isipv6)
943 /*
944 * ip6_plen is not need to be filled now, and will be filled
945 * in ip6_output.
946 */
947 th->th_sum = in6_cksum(m, IPPROTO_TCP, sizeof(struct ip6_hdr),
948 sizeof(struct tcphdr) + optlen + len);
949 else
950 #endif /* INET6 */
951 {
952 m->m_pkthdr.csum_flags = CSUM_TCP;
953 m->m_pkthdr.csum_data = offsetof(struct tcphdr, th_sum);
954 if (len + optlen)
955 th->th_sum = in_addword(th->th_sum,
956 htons((u_short)(optlen + len)));
957
958 /* IP version must be set here for ipv4/ipv6 checking later */
959 KASSERT(ip->ip_v == IPVERSION,
960 ("%s: IP version incorrect: %d", __FUNCTION__, ip->ip_v));
961 }
962
963 /*
964 * In transmit state, time the transmission and arrange for
965 * the retransmit. In persist state, just set snd_max.
966 */
967 if (tp->t_force == 0 || tp->t_timer[TCPT_PERSIST] == 0) {
968 tcp_seq startseq = tp->snd_nxt;
969
970 /*
971 * Advance snd_nxt over sequence space of this segment.
972 */
973 if (flags & (TH_SYN|TH_FIN)) {
974 if (flags & TH_SYN)
975 tp->snd_nxt++;
976 if (flags & TH_FIN) {
977 tp->snd_nxt++;
978 tp->t_flags |= TF_SENTFIN;
979 }
980 }
981 tp->snd_nxt += len;
982 if (SEQ_GT(tp->snd_nxt, tp->snd_max)) {
983 tp->snd_max = tp->snd_nxt;
984 /*
985 * Time this transmission if not a retransmission and
986 * not currently timing anything.
987 */
988 if (tp->t_rtttime == 0) {
989 tp->t_rtttime = 1;
990 tp->t_rtseq = startseq;
991 tcpstat.tcps_segstimed++;
992 }
993 }
994
995 /*
996 * Set retransmit timer if not currently set,
997 * and not doing an ack or a keep-alive probe.
998 * Initial value for retransmit timer is smoothed
999 * round-trip time + 2 * round-trip time variance.
1000 * Initialize shift counter which is used for backoff
1001 * of retransmit time.
1002 */
1003 if (tp->t_timer[TCPT_REXMT] == 0 &&
1004 tp->snd_nxt != tp->snd_una) {
1005 tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
1006 if (tp->t_timer[TCPT_PERSIST]) {
1007 tp->t_timer[TCPT_PERSIST] = 0;
1008 tp->t_rxtshift = 0;
1009 }
1010 }
1011 } else
1012 if (SEQ_GT(tp->snd_nxt + len, tp->snd_max))
1013 tp->snd_max = tp->snd_nxt + len;
1014
1015 #if TCPDEBUG
1016 /*
1017 * Trace.
1018 */
1019 if (so->so_options & SO_DEBUG)
1020 tcp_trace(TA_OUTPUT, tp->t_state, tp, mtod(m, void *), th, 0);
1021 #endif
1022
1023 /*
1024 * Fill in IP length and desired time to live and
1025 * send to IP level. There should be a better way
1026 * to handle ttl and tos; we could keep them in
1027 * the template, but need a way to checksum without them.
1028 */
1029 /*
1030 * m->m_pkthdr.len should have been set before cksum calcuration,
1031 * because in6_cksum() need it.
1032 */
1033 #if INET6
1034 if (isipv6) {
1035 /*
1036 * we separately set hoplimit for every segment, since the
1037 * user might want to change the value via setsockopt.
1038 * Also, desired default hop limit might be changed via
1039 * Neighbor Discovery.
1040 */
1041 ip6->ip6_hlim = in6_selecthlim(tp->t_inpcb,
1042 tp->t_inpcb->in6p_route.ro_rt ?
1043 tp->t_inpcb->in6p_route.ro_rt->rt_ifp
1044 : NULL);
1045
1046 /* TODO: IPv6 IP6TOS_ECT bit on */
1047 #if IPSEC
1048 if (ipsec_bypass == 0 && ipsec_setsocket(m, so) != 0) {
1049 m_freem(m);
1050 error = ENOBUFS;
1051 goto out;
1052 }
1053 #endif /*IPSEC*/
1054 m->m_pkthdr.socket_id = socket_id;
1055 error = ip6_output(m,
1056 tp->t_inpcb->in6p_outputopts,
1057 &tp->t_inpcb->in6p_route,
1058 (so->so_options & SO_DONTROUTE), NULL, NULL, 0);
1059 } else
1060 #endif /* INET6 */
1061 {
1062 struct rtentry *rt;
1063 ip->ip_len = m->m_pkthdr.len;
1064 #if INET6
1065 if (isipv6)
1066 ip->ip_ttl = in6_selecthlim(tp->t_inpcb,
1067 tp->t_inpcb->in6p_route.ro_rt ?
1068 tp->t_inpcb->in6p_route.ro_rt->rt_ifp
1069 : NULL);
1070 else
1071 #endif /* INET6 */
1072 ip->ip_ttl = tp->t_inpcb->inp_ip_ttl; /* XXX */
1073 ip->ip_tos = tp->t_inpcb->inp_ip_tos; /* XXX */
1074
1075
1076 #if INET6
1077 if (isipv6) {
1078 KERNEL_DEBUG(DBG_LAYER_BEG,
1079 ((tp->t_inpcb->inp_fport << 16) | tp->t_inpcb->inp_lport),
1080 (((tp->t_inpcb->in6p_laddr.s6_addr16[0] & 0xffff) << 16) |
1081 (tp->t_inpcb->in6p_faddr.s6_addr16[0] & 0xffff)),
1082 0,0,0);
1083 }
1084 else
1085 #endif
1086 {
1087 KERNEL_DEBUG(DBG_LAYER_BEG,
1088 ((tp->t_inpcb->inp_fport << 16) | tp->t_inpcb->inp_lport),
1089 (((tp->t_inpcb->inp_laddr.s_addr & 0xffff) << 16) |
1090 (tp->t_inpcb->inp_faddr.s_addr & 0xffff)),
1091 0,0,0);
1092 }
1093
1094 /*
1095 * See if we should do MTU discovery. We do it only if the following
1096 * are true:
1097 * 1) we have a valid route to the destination
1098 * 2) the MTU is not locked (if it is, then discovery has been
1099 * disabled)
1100 */
1101 if (path_mtu_discovery
1102 && (rt = tp->t_inpcb->inp_route.ro_rt)
1103 && rt->rt_flags & RTF_UP
1104 && !(rt->rt_rmx.rmx_locks & RTV_MTU)) {
1105 ip->ip_off |= IP_DF;
1106 }
1107 #if IPSEC
1108 if (ipsec_bypass == 0)
1109 ipsec_setsocket(m, so);
1110 #endif /*IPSEC*/
1111
1112 /*
1113 * The socket is kept locked while sending out packets in ip_output, even if packet chaining is not active.
1114 */
1115
1116 m->m_pkthdr.socket_id = socket_id;
1117 if (packetlist) {
1118 m->m_nextpkt = NULL;
1119 lastpacket->m_nextpkt = m;
1120 lastpacket = m;
1121 packchain_listadd++;
1122 }
1123 else {
1124 m->m_nextpkt = NULL;
1125 packchain_newlist++;
1126 packetlist = lastpacket = m;
1127 packchain_listadd=0;
1128 }
1129
1130 if ((ipsec_bypass == 0) || fw_enable || sendalot == 0 || (tp->t_state != TCPS_ESTABLISHED) ||
1131 (tp->snd_cwnd <= (tp->snd_wnd / 4)) ||
1132 (tp->t_flags & (TH_PUSH | TF_ACKNOW)) || tp->t_force != 0 ||
1133 packchain_listadd >= tcp_packet_chaining) {
1134 lastpacket->m_nextpkt = 0;
1135 error = ip_output_list(packetlist, packchain_listadd, tp->t_inpcb->inp_options, &tp->t_inpcb->inp_route,
1136 (so->so_options & SO_DONTROUTE), 0);
1137 tp->t_lastchain = packchain_listadd;
1138 packchain_sent++;
1139 packetlist = NULL;
1140 if (error == 0)
1141 howmuchsent = 0;
1142 }
1143 else {
1144 error = 0;
1145 packchain_looped++;
1146 tcpstat.tcps_sndtotal++;
1147 if (win > 0 && SEQ_GT(tp->rcv_nxt+win, tp->rcv_adv))
1148 tp->rcv_adv = tp->rcv_nxt + win;
1149 tp->last_ack_sent = tp->rcv_nxt;
1150 tp->t_flags &= ~(TF_ACKNOW|TF_DELACK);
1151 goto again;
1152 }
1153 }
1154 if (error) {
1155
1156 /*
1157 * We know that the packet was lost, so back out the
1158 * sequence number advance, if any.
1159 */
1160 if (tp->t_force == 0 || !tp->t_timer[TCPT_PERSIST]) {
1161 /*
1162 * No need to check for TH_FIN here because
1163 * the TF_SENTFIN flag handles that case.
1164 */
1165 if ((flags & TH_SYN) == 0)
1166 tp->snd_nxt -= howmuchsent;
1167 }
1168 howmuchsent = 0;
1169 out:
1170 if (error == ENOBUFS) {
1171 if (!tp->t_timer[TCPT_REXMT] &&
1172 !tp->t_timer[TCPT_PERSIST])
1173 tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
1174 tcp_quench(tp->t_inpcb, 0);
1175 if (packetlist)
1176 m_freem_list(packetlist);
1177 tp->t_lastchain = 0;
1178 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT | DBG_FUNC_END, 0,0,0,0,0);
1179 return (0);
1180 }
1181 if (error == EMSGSIZE) {
1182 /*
1183 * ip_output() will have already fixed the route
1184 * for us. tcp_mtudisc() will, as its last action,
1185 * initiate retransmission, so it is important to
1186 * not do so here.
1187 */
1188 tcp_mtudisc(tp->t_inpcb, 0);
1189 if (packetlist)
1190 m_freem_list(packetlist);
1191 tp->t_lastchain = 0;
1192 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT | DBG_FUNC_END, 0,0,0,0,0);
1193 return 0;
1194 }
1195 if ((error == EHOSTUNREACH || error == ENETDOWN)
1196 && TCPS_HAVERCVDSYN(tp->t_state)) {
1197 tp->t_softerror = error;
1198 if (packetlist)
1199 m_freem_list(packetlist);
1200 tp->t_lastchain = 0;
1201 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT | DBG_FUNC_END, 0,0,0,0,0);
1202 return (0);
1203 }
1204 if (packetlist)
1205 m_freem_list(packetlist);
1206 tp->t_lastchain = 0;
1207 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT | DBG_FUNC_END, 0,0,0,0,0);
1208 return (error);
1209 }
1210 sentit:
1211 tcpstat.tcps_sndtotal++;
1212
1213 /*
1214 * Data sent (as far as we can tell).
1215 * If this advertises a larger window than any other segment,
1216 * then remember the size of the advertised window.
1217 * Any pending ACK has now been sent.
1218 */
1219 if (win > 0 && SEQ_GT(tp->rcv_nxt+win, tp->rcv_adv))
1220 tp->rcv_adv = tp->rcv_nxt + win;
1221 tp->last_ack_sent = tp->rcv_nxt;
1222 tp->t_flags &= ~(TF_ACKNOW|TF_DELACK);
1223
1224 KERNEL_DEBUG(DBG_FNC_TCP_OUTPUT | DBG_FUNC_END,0,0,0,0,0);
1225 if (sendalot && (!tcp_do_newreno || --maxburst))
1226 goto again;
1227 return (0);
1228 }
1229
1230 void
1231 tcp_setpersist(tp)
1232 register struct tcpcb *tp;
1233 {
1234 int t = ((tp->t_srtt >> 2) + tp->t_rttvar) >> 1;
1235
1236 if (tp->t_timer[TCPT_REXMT])
1237 panic("tcp_setpersist: retransmit pending");
1238 /*
1239 * Start/restart persistance timer.
1240 */
1241 TCPT_RANGESET(tp->t_timer[TCPT_PERSIST],
1242 t * tcp_backoff[tp->t_rxtshift],
1243 TCPTV_PERSMIN, TCPTV_PERSMAX);
1244 if (tp->t_rxtshift < TCP_MAXRXTSHIFT)
1245 tp->t_rxtshift++;
1246 }