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