]> git.saurik.com Git - apple/xnu.git/blame - bsd/netinet/tcp_sack.c
xnu-1504.15.3.tar.gz
[apple/xnu.git] / bsd / netinet / tcp_sack.c
CommitLineData
8ad349bb 1/*
2d21ac55 2 * Copyright (c) 2004,2007 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
8ad349bb 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
8ad349bb
A
27 */
28/*
29 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
30 * The Regents of the University of California. All rights reserved.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
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.
47 *
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
58 * SUCH DAMAGE.
59 *
60 */
61
62#define _IP_VHL
63
64
65#include <sys/param.h>
66#include <sys/systm.h>
67#include <sys/kernel.h>
68#include <sys/sysctl.h>
69#include <sys/mbuf.h>
70#include <sys/domain.h>
71#include <sys/protosw.h>
72#include <sys/socket.h>
73#include <sys/socketvar.h>
74
2d21ac55
A
75#include <kern/zalloc.h>
76
8ad349bb
A
77#include <net/route.h>
78
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>
84#if INET6
85#include <netinet6/in6_pcb.h>
86#include <netinet/ip6.h>
87#include <netinet6/ip6_var.h>
88#endif
89#include <netinet/tcp.h>
90//#define TCPOUTFLAGS
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>
96#if TCPDEBUG
97#include <netinet/tcp_debug.h>
98#endif
99#include <sys/kdebug.h>
100
101#if IPSEC
102#include <netinet6/ipsec.h>
103#endif /*IPSEC*/
104
105int tcp_do_sack = 1;
106SYSCTL_INT(_net_inet_tcp, OID_AUTO, sack, CTLFLAG_RW, &tcp_do_sack, 0,
107 "Enable/Disable TCP SACK support");
108static int tcp_sack_maxholes = 128;
109SYSCTL_INT(_net_inet_tcp, OID_AUTO, sack_maxholes, CTLFLAG_RW,
110 &tcp_sack_maxholes, 0,
111 "Maximum number of TCP SACK holes allowed per connection");
112
113static int tcp_sack_globalmaxholes = 65536;
114SYSCTL_INT(_net_inet_tcp, OID_AUTO, sack_globalmaxholes, CTLFLAG_RW,
115 &tcp_sack_globalmaxholes, 0,
116 "Global maximum number of TCP SACK holes");
117
118static int tcp_sack_globalholes = 0;
119SYSCTL_INT(_net_inet_tcp, OID_AUTO, sack_globalholes, CTLFLAG_RD,
120 &tcp_sack_globalholes, 0,
121 "Global number of TCP SACK holes currently allocated");
122
123extern struct zone *sack_hole_zone;
124
125/*
126 * This function is called upon receipt of new valid data (while not in header
127 * prediction mode), and it updates the ordered list of sacks.
128 */
129void
130tcp_update_sack_list(struct tcpcb *tp, tcp_seq rcv_start, tcp_seq rcv_end)
131{
132 /*
133 * First reported block MUST be the most recent one. Subsequent
134 * blocks SHOULD be in the order in which they arrived at the
135 * receiver. These two conditions make the implementation fully
136 * compliant with RFC 2018.
137 */
138 struct sackblk head_blk, saved_blks[MAX_SACK_BLKS];
139 int num_head, num_saved, i;
140
141 /* SACK block for the received segment. */
142 head_blk.start = rcv_start;
143 head_blk.end = rcv_end;
144
145 /*
146 * Merge updated SACK blocks into head_blk, and
147 * save unchanged SACK blocks into saved_blks[].
148 * num_saved will have the number of the saved SACK blocks.
149 */
150 num_saved = 0;
151 for (i = 0; i < tp->rcv_numsacks; i++) {
152 tcp_seq start = tp->sackblks[i].start;
153 tcp_seq end = tp->sackblks[i].end;
154 if (SEQ_GEQ(start, end) || SEQ_LEQ(start, tp->rcv_nxt)) {
155 /*
156 * Discard this SACK block.
157 */
158 } else if (SEQ_LEQ(head_blk.start, end) &&
159 SEQ_GEQ(head_blk.end, start)) {
160 /*
161 * Merge this SACK block into head_blk.
162 * This SACK block itself will be discarded.
163 */
164 if (SEQ_GT(head_blk.start, start))
165 head_blk.start = start;
166 if (SEQ_LT(head_blk.end, end))
167 head_blk.end = end;
168 } else {
169 /*
170 * Save this SACK block.
171 */
172 saved_blks[num_saved].start = start;
173 saved_blks[num_saved].end = end;
174 num_saved++;
175 }
176 }
177
178 /*
179 * Update SACK list in tp->sackblks[].
180 */
181 num_head = 0;
182 if (SEQ_GT(head_blk.start, tp->rcv_nxt)) {
183 /*
184 * The received data segment is an out-of-order segment.
185 * Put head_blk at the top of SACK list.
186 */
187 tp->sackblks[0] = head_blk;
188 num_head = 1;
189 /*
190 * If the number of saved SACK blocks exceeds its limit,
191 * discard the last SACK block.
192 */
193 if (num_saved >= MAX_SACK_BLKS)
194 num_saved--;
195 }
196 if (num_saved > 0) {
197 /*
198 * Copy the saved SACK blocks back.
199 */
200 bcopy(saved_blks, &tp->sackblks[num_head],
201 sizeof(struct sackblk) * num_saved);
202 }
203
204 /* Save the number of SACK blocks. */
205 tp->rcv_numsacks = num_head + num_saved;
206}
207
208/*
209 * Delete all receiver-side SACK information.
210 */
211void
212tcp_clean_sackreport( struct tcpcb *tp)
213{
8ad349bb
A
214
215 tp->rcv_numsacks = 0;
8ad349bb
A
216 bzero(&tp->sackblks[0], sizeof (struct sackblk) * MAX_SACK_BLKS);
217}
218
219/*
220 * Allocate struct sackhole.
221 */
222static struct sackhole *
223tcp_sackhole_alloc(struct tcpcb *tp, tcp_seq start, tcp_seq end)
224{
225 struct sackhole *hole;
226
227 if (tp->snd_numholes >= tcp_sack_maxholes ||
228 tcp_sack_globalholes >= tcp_sack_globalmaxholes) {
229 tcpstat.tcps_sack_sboverflow++;
230 return NULL;
231 }
232
233 hole = (struct sackhole *)zalloc_noblock(sack_hole_zone);
234 if (hole == NULL)
235 return NULL;
236
237 hole->start = start;
238 hole->end = end;
239 hole->rxmit = start;
240
241 tp->snd_numholes++;
242 tcp_sack_globalholes++;
243
244 return hole;
245}
246
247/*
248 * Free struct sackhole.
249 */
250static void
251tcp_sackhole_free(struct tcpcb *tp, struct sackhole *hole)
252{
253 zfree(sack_hole_zone, hole);
254
255 tp->snd_numholes--;
256 tcp_sack_globalholes--;
257}
258
259/*
260 * Insert new SACK hole into scoreboard.
261 */
262static struct sackhole *
263tcp_sackhole_insert(struct tcpcb *tp, tcp_seq start, tcp_seq end,
264 struct sackhole *after)
265{
266 struct sackhole *hole;
267
268 /* Allocate a new SACK hole. */
269 hole = tcp_sackhole_alloc(tp, start, end);
270 if (hole == NULL)
271 return NULL;
272
273 /* Insert the new SACK hole into scoreboard */
274 if (after != NULL)
275 TAILQ_INSERT_AFTER(&tp->snd_holes, after, hole, scblink);
276 else
277 TAILQ_INSERT_TAIL(&tp->snd_holes, hole, scblink);
278
279 /* Update SACK hint. */
280 if (tp->sackhint.nexthole == NULL)
281 tp->sackhint.nexthole = hole;
282
283 return hole;
284}
285
286/*
287 * Remove SACK hole from scoreboard.
288 */
289static void
290tcp_sackhole_remove(struct tcpcb *tp, struct sackhole *hole)
291{
292 /* Update SACK hint. */
293 if (tp->sackhint.nexthole == hole)
294 tp->sackhint.nexthole = TAILQ_NEXT(hole, scblink);
295
296 /* Remove this SACK hole. */
297 TAILQ_REMOVE(&tp->snd_holes, hole, scblink);
298
299 /* Free this SACK hole. */
300 tcp_sackhole_free(tp, hole);
301}
302
303/*
304 * Process cumulative ACK and the TCP SACK option to update the scoreboard.
305 * tp->snd_holes is an ordered list of holes (oldest to newest, in terms of
306 * the sequence space).
307 */
308void
309tcp_sack_doack(struct tcpcb *tp, struct tcpopt *to, tcp_seq th_ack)
310{
311 struct sackhole *cur, *temp;
312 struct sackblk sack, sack_blocks[TCP_MAX_SACK + 1], *sblkp;
313 int i, j, num_sack_blks;
314
315 num_sack_blks = 0;
316 /*
317 * If SND.UNA will be advanced by SEG.ACK, and if SACK holes exist,
318 * treat [SND.UNA, SEG.ACK) as if it is a SACK block.
319 */
320 if (SEQ_LT(tp->snd_una, th_ack) && !TAILQ_EMPTY(&tp->snd_holes)) {
321 sack_blocks[num_sack_blks].start = tp->snd_una;
322 sack_blocks[num_sack_blks++].end = th_ack;
323 }
324 /*
325 * Append received valid SACK blocks to sack_blocks[].
b0d623f7 326 * Check that the SACK block range is valid.
8ad349bb 327 */
b0d623f7
A
328 for (i = 0; i < to->to_nsacks; i++) {
329 bcopy((to->to_sacks + i * TCPOLEN_SACK),
330 &sack, sizeof(sack));
331 sack.start = ntohl(sack.start);
332 sack.end = ntohl(sack.end);
333 if (SEQ_GT(sack.end, sack.start) &&
334 SEQ_GT(sack.start, tp->snd_una) &&
335 SEQ_GT(sack.start, th_ack) &&
336 SEQ_LT(sack.start, tp->snd_max) &&
337 SEQ_GT(sack.end, tp->snd_una) &&
338 SEQ_LEQ(sack.end, tp->snd_max))
339 sack_blocks[num_sack_blks++] = sack;
8ad349bb
A
340 }
341
342 /*
343 * Return if SND.UNA is not advanced and no valid SACK block
344 * is received.
345 */
346 if (num_sack_blks == 0)
347 return;
348
349 /*
350 * Sort the SACK blocks so we can update the scoreboard
351 * with just one pass. The overhead of sorting upto 4+1 elements
352 * is less than making upto 4+1 passes over the scoreboard.
353 */
354 for (i = 0; i < num_sack_blks; i++) {
355 for (j = i + 1; j < num_sack_blks; j++) {
356 if (SEQ_GT(sack_blocks[i].end, sack_blocks[j].end)) {
357 sack = sack_blocks[i];
358 sack_blocks[i] = sack_blocks[j];
359 sack_blocks[j] = sack;
360 }
361 }
362 }
363 if (TAILQ_EMPTY(&tp->snd_holes))
364 /*
365 * Empty scoreboard. Need to initialize snd_fack (it may be
366 * uninitialized or have a bogus value). Scoreboard holes
367 * (from the sack blocks received) are created later below (in
368 * the logic that adds holes to the tail of the scoreboard).
369 */
370 tp->snd_fack = SEQ_MAX(tp->snd_una, th_ack);
371 /*
372 * In the while-loop below, incoming SACK blocks (sack_blocks[])
373 * and SACK holes (snd_holes) are traversed from their tails with
374 * just one pass in order to reduce the number of compares especially
375 * when the bandwidth-delay product is large.
376 * Note: Typically, in the first RTT of SACK recovery, the highest
377 * three or four SACK blocks with the same ack number are received.
378 * In the second RTT, if retransmitted data segments are not lost,
379 * the highest three or four SACK blocks with ack number advancing
380 * are received.
381 */
382 sblkp = &sack_blocks[num_sack_blks - 1]; /* Last SACK block */
383 if (SEQ_LT(tp->snd_fack, sblkp->start)) {
384 /*
385 * The highest SACK block is beyond fack.
386 * Append new SACK hole at the tail.
387 * If the second or later highest SACK blocks are also
388 * beyond the current fack, they will be inserted by
389 * way of hole splitting in the while-loop below.
390 */
391 temp = tcp_sackhole_insert(tp, tp->snd_fack,sblkp->start,NULL);
392 if (temp != NULL) {
393 tp->snd_fack = sblkp->end;
394 /* Go to the previous sack block. */
395 sblkp--;
396 } else {
397 /*
398 * We failed to add a new hole based on the current
399 * sack block. Skip over all the sack blocks that
400 * fall completely to the right of snd_fack and proceed
401 * to trim the scoreboard based on the remaining sack
402 * blocks. This also trims the scoreboard for th_ack
403 * (which is sack_blocks[0]).
404 */
405 while (sblkp >= sack_blocks &&
406 SEQ_LT(tp->snd_fack, sblkp->start))
407 sblkp--;
408 if (sblkp >= sack_blocks &&
409 SEQ_LT(tp->snd_fack, sblkp->end))
410 tp->snd_fack = sblkp->end;
411 }
412 } else if (SEQ_LT(tp->snd_fack, sblkp->end))
413 /* fack is advanced. */
414 tp->snd_fack = sblkp->end;
415 /* We must have at least one SACK hole in scoreboard */
416 cur = TAILQ_LAST(&tp->snd_holes, sackhole_head); /* Last SACK hole */
417 /*
418 * Since the incoming sack blocks are sorted, we can process them
419 * making one sweep of the scoreboard.
420 */
421 while (sblkp >= sack_blocks && cur != NULL) {
422 if (SEQ_GEQ(sblkp->start, cur->end)) {
423 /*
424 * SACKs data beyond the current hole.
425 * Go to the previous sack block.
426 */
427 sblkp--;
428 continue;
429 }
430 if (SEQ_LEQ(sblkp->end, cur->start)) {
431 /*
432 * SACKs data before the current hole.
433 * Go to the previous hole.
434 */
435 cur = TAILQ_PREV(cur, sackhole_head, scblink);
436 continue;
437 }
438 tp->sackhint.sack_bytes_rexmit -= (cur->rxmit - cur->start);
439 if (SEQ_LEQ(sblkp->start, cur->start)) {
440 /* Data acks at least the beginning of hole */
441 if (SEQ_GEQ(sblkp->end, cur->end)) {
442 /* Acks entire hole, so delete hole */
443 temp = cur;
444 cur = TAILQ_PREV(cur, sackhole_head, scblink);
445 tcp_sackhole_remove(tp, temp);
446 /*
447 * The sack block may ack all or part of the next
448 * hole too, so continue onto the next hole.
449 */
450 continue;
451 } else {
452 /* Move start of hole forward */
453 cur->start = sblkp->end;
454 cur->rxmit = SEQ_MAX(cur->rxmit, cur->start);
455 }
456 } else {
457 /* Data acks at least the end of hole */
458 if (SEQ_GEQ(sblkp->end, cur->end)) {
459 /* Move end of hole backward */
460 cur->end = sblkp->start;
461 cur->rxmit = SEQ_MIN(cur->rxmit, cur->end);
462 } else {
463 /*
464 * ACKs some data in middle of a hole; need to
465 * split current hole
466 */
467 temp = tcp_sackhole_insert(tp, sblkp->end,
468 cur->end, cur);
469 if (temp != NULL) {
470 if (SEQ_GT(cur->rxmit, temp->rxmit)) {
471 temp->rxmit = cur->rxmit;
472 tp->sackhint.sack_bytes_rexmit
473 += (temp->rxmit
474 - temp->start);
475 }
476 cur->end = sblkp->start;
477 cur->rxmit = SEQ_MIN(cur->rxmit,
478 cur->end);
479 }
480 }
481 }
482 tp->sackhint.sack_bytes_rexmit += (cur->rxmit - cur->start);
483 /*
484 * Testing sblkp->start against cur->start tells us whether
485 * we're done with the sack block or the sack hole.
486 * Accordingly, we advance one or the other.
487 */
488 if (SEQ_LEQ(sblkp->start, cur->start))
489 cur = TAILQ_PREV(cur, sackhole_head, scblink);
490 else
491 sblkp--;
492 }
493}
494
495/*
496 * Free all SACK holes to clear the scoreboard.
497 */
498void
499tcp_free_sackholes(struct tcpcb *tp)
500{
501 struct sackhole *q;
502
503 while ((q = TAILQ_FIRST(&tp->snd_holes)) != NULL)
504 tcp_sackhole_remove(tp, q);
505 tp->sackhint.sack_bytes_rexmit = 0;
b0d623f7
A
506 tp->sackhint.nexthole = NULL;
507 tp->sack_newdata = 0;
8ad349bb
A
508
509}
510
511/*
512 * Partial ack handling within a sack recovery episode.
513 * Keeping this very simple for now. When a partial ack
514 * is received, force snd_cwnd to a value that will allow
515 * the sender to transmit no more than 2 segments.
516 * If necessary, a better scheme can be adopted at a
517 * later point, but for now, the goal is to prevent the
518 * sender from bursting a large amount of data in the midst
519 * of sack recovery.
520 */
521void
522tcp_sack_partialack(tp, th)
523 struct tcpcb *tp;
524 struct tcphdr *th;
525{
526 int num_segs = 1;
527
528 tp->t_timer[TCPT_REXMT] = 0;
529 tp->t_rtttime = 0;
530 /* send one or 2 segments based on how much new data was acked */
531 if (((th->th_ack - tp->snd_una) / tp->t_maxseg) > 2)
532 num_segs = 2;
533 tp->snd_cwnd = (tp->sackhint.sack_bytes_rexmit +
534 (tp->snd_nxt - tp->sack_newdata) +
535 num_segs * tp->t_maxseg);
536 if (tp->snd_cwnd > tp->snd_ssthresh)
537 tp->snd_cwnd = tp->snd_ssthresh;
538 tp->t_flags |= TF_ACKNOW;
539 (void) tcp_output(tp);
540}
541
542/*
543 * Debug version of tcp_sack_output() that walks the scoreboard. Used for
544 * now to sanity check the hint.
545 */
546static struct sackhole *
547tcp_sack_output_debug(struct tcpcb *tp, int *sack_bytes_rexmt)
548{
549 struct sackhole *p;
550
551 *sack_bytes_rexmt = 0;
552 TAILQ_FOREACH(p, &tp->snd_holes, scblink) {
553 if (SEQ_LT(p->rxmit, p->end)) {
554 if (SEQ_LT(p->rxmit, tp->snd_una)) {/* old SACK hole */
555 continue;
556 }
557 *sack_bytes_rexmt += (p->rxmit - p->start);
558 break;
559 }
560 *sack_bytes_rexmt += (p->rxmit - p->start);
561 }
562 return (p);
563}
564
565/*
566 * Returns the next hole to retransmit and the number of retransmitted bytes
567 * from the scoreboard. We store both the next hole and the number of
568 * retransmitted bytes as hints (and recompute these on the fly upon SACK/ACK
569 * reception). This avoids scoreboard traversals completely.
570 *
571 * The loop here will traverse *at most* one link. Here's the argument.
572 * For the loop to traverse more than 1 link before finding the next hole to
573 * retransmit, we would need to have at least 1 node following the current hint
574 * with (rxmit == end). But, for all holes following the current hint,
575 * (start == rxmit), since we have not yet retransmitted from them. Therefore,
576 * in order to traverse more 1 link in the loop below, we need to have at least
577 * one node following the current hint with (start == rxmit == end).
578 * But that can't happen, (start == end) means that all the data in that hole
579 * has been sacked, in which case, the hole would have been removed from the
580 * scoreboard.
581 */
582struct sackhole *
583tcp_sack_output(struct tcpcb *tp, int *sack_bytes_rexmt)
584{
585 struct sackhole *hole = NULL, *dbg_hole = NULL;
586 int dbg_bytes_rexmt;
587
588 dbg_hole = tcp_sack_output_debug(tp, &dbg_bytes_rexmt);
589 *sack_bytes_rexmt = tp->sackhint.sack_bytes_rexmit;
590 hole = tp->sackhint.nexthole;
591 if (hole == NULL || SEQ_LT(hole->rxmit, hole->end))
592 goto out;
593 while ((hole = TAILQ_NEXT(hole, scblink)) != NULL) {
594 if (SEQ_LT(hole->rxmit, hole->end)) {
595 tp->sackhint.nexthole = hole;
596 break;
597 }
598 }
599out:
600 if (dbg_hole != hole) {
601 printf("%s: Computed sack hole not the same as cached value\n", __func__);
602 hole = dbg_hole;
603 }
604 if (*sack_bytes_rexmt != dbg_bytes_rexmt) {
605 printf("%s: Computed sack_bytes_retransmitted (%d) not "
606 "the same as cached value (%d)\n",
607 __func__, dbg_bytes_rexmt, *sack_bytes_rexmt);
608 *sack_bytes_rexmt = dbg_bytes_rexmt;
609 }
610 return (hole);
611}
612
613/*
614 * After a timeout, the SACK list may be rebuilt. This SACK information
615 * should be used to avoid retransmitting SACKed data. This function
616 * traverses the SACK list to see if snd_nxt should be moved forward.
617 */
618void
619tcp_sack_adjust(struct tcpcb *tp)
620{
621 struct sackhole *p, *cur = TAILQ_FIRST(&tp->snd_holes);
622
623 if (cur == NULL)
624 return; /* No holes */
625 if (SEQ_GEQ(tp->snd_nxt, tp->snd_fack))
626 return; /* We're already beyond any SACKed blocks */
627 /*
628 * Two cases for which we want to advance snd_nxt:
629 * i) snd_nxt lies between end of one hole and beginning of another
630 * ii) snd_nxt lies between end of last hole and snd_fack
631 */
632 while ((p = TAILQ_NEXT(cur, scblink)) != NULL) {
633 if (SEQ_LT(tp->snd_nxt, cur->end))
634 return;
635 if (SEQ_GEQ(tp->snd_nxt, p->start))
636 cur = p;
637 else {
638 tp->snd_nxt = p->start;
639 return;
640 }
641 }
642 if (SEQ_LT(tp->snd_nxt, cur->end))
643 return;
644 tp->snd_nxt = tp->snd_fack;
645 return;
646}