2 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1994, 1995
3 * The Regents of the University of California.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 4. Neither the name of the University nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * @(#)tcp_sack.c 8.12 (Berkeley) 5/24/95
34 * @@(#)COPYRIGHT 1.1 (NRL) 17 January 1995
36 * NRL grants permission for redistribution and use in source and binary
37 * forms, with or without modification, of the software and documentation
38 * created at NRL provided that the following conditions are met:
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. All advertising materials mentioning features or use of this software
46 * must display the following acknowledgements:
47 * This product includes software developed by the University of
48 * California, Berkeley and its contributors.
49 * This product includes software developed at the Information
50 * Technology Division, US Naval Research Laboratory.
51 * 4. Neither the name of the NRL nor the names of its contributors
52 * may be used to endorse or promote products derived from this software
53 * without specific prior written permission.
55 * THE SOFTWARE PROVIDED BY NRL IS PROVIDED BY NRL AND CONTRIBUTORS ``AS
56 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
57 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
58 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NRL OR
59 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
60 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
61 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
62 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
63 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
64 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
65 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 * The views and conclusions contained in the software and documentation
68 * are those of the authors and should not be interpreted as representing
69 * official policies, either expressed or implied, of the US Naval
70 * Research Laboratory (NRL).
73 #include <sys/cdefs.h>
74 __FBSDID("$FreeBSD$");
77 #include "opt_inet6.h"
78 #include "opt_tcpdebug.h"
80 #include <sys/param.h>
81 #include <sys/systm.h>
82 #include <sys/kernel.h>
83 #include <sys/sysctl.h>
84 #include <sys/malloc.h>
86 #include <sys/proc.h> /* for proc0 declaration */
87 #include <sys/protosw.h>
88 #include <sys/socket.h>
89 #include <sys/socketvar.h>
90 #include <sys/syslog.h>
91 #include <sys/systm.h>
93 #include <machine/cpu.h> /* before tcp_seq.h, for tcp_random18() */
98 #include <net/route.h>
101 #include <netinet/in.h>
102 #include <netinet/in_systm.h>
103 #include <netinet/ip.h>
104 #include <netinet/in_var.h>
105 #include <netinet/in_pcb.h>
106 #include <netinet/ip_var.h>
107 #include <netinet/ip6.h>
108 #include <netinet/icmp6.h>
109 #include <netinet6/nd6.h>
110 #include <netinet6/ip6_var.h>
111 #include <netinet6/in6_pcb.h>
112 #include <netinet/tcp.h>
113 #include <netinet/tcp_fsm.h>
114 #include <netinet/tcp_seq.h>
115 #include <netinet/tcp_timer.h>
116 #include <netinet/tcp_var.h>
117 #include <netinet6/tcp6_var.h>
118 #include <netinet/tcpip.h>
120 #include <netinet/tcp_debug.h>
121 #endif /* TCPDEBUG */
123 #include <machine/in_cksum.h>
125 VNET_DECLARE(struct uma_zone *, sack_hole_zone);
126 #define V_sack_hole_zone VNET(sack_hole_zone)
128 SYSCTL_NODE(_net_inet_tcp, OID_AUTO, sack, CTLFLAG_RW, 0, "TCP SACK");
129 VNET_DEFINE(int, tcp_do_sack) = 1;
130 #define V_tcp_do_sack VNET(tcp_do_sack)
131 SYSCTL_VNET_INT(_net_inet_tcp_sack, OID_AUTO, enable, CTLFLAG_RW,
132 &VNET_NAME(tcp_do_sack), 0, "Enable/Disable TCP SACK support");
134 VNET_DEFINE(int, tcp_sack_maxholes) = 128;
135 #define V_tcp_sack_maxholes VNET(tcp_sack_maxholes)
136 SYSCTL_VNET_INT(_net_inet_tcp_sack, OID_AUTO, maxholes, CTLFLAG_RW,
137 &VNET_NAME(tcp_sack_maxholes), 0,
138 "Maximum number of TCP SACK holes allowed per connection");
140 VNET_DEFINE(int, tcp_sack_globalmaxholes) = 65536;
141 #define V_tcp_sack_globalmaxholes VNET(tcp_sack_globalmaxholes)
142 SYSCTL_VNET_INT(_net_inet_tcp_sack, OID_AUTO, globalmaxholes, CTLFLAG_RW,
143 &VNET_NAME(tcp_sack_globalmaxholes), 0,
144 "Global maximum number of TCP SACK holes");
146 VNET_DEFINE(int, tcp_sack_globalholes) = 0;
147 #define V_tcp_sack_globalholes VNET(tcp_sack_globalholes)
148 SYSCTL_VNET_INT(_net_inet_tcp_sack, OID_AUTO, globalholes, CTLFLAG_RD,
149 &VNET_NAME(tcp_sack_globalholes), 0,
150 "Global number of TCP SACK holes currently allocated");
153 * This function is called upon receipt of new valid data (while not in
154 * header prediction mode), and it updates the ordered list of sacks.
157 tcp_update_sack_list(struct tcpcb *tp, tcp_seq rcv_start, tcp_seq rcv_end)
160 * First reported block MUST be the most recent one. Subsequent
161 * blocks SHOULD be in the order in which they arrived at the
162 * receiver. These two conditions make the implementation fully
163 * compliant with RFC 2018.
165 struct sackblk head_blk, saved_blks[MAX_SACK_BLKS];
166 int num_head, num_saved, i;
168 INP_WLOCK_ASSERT(tp->t_inpcb);
170 /* Check arguments. */
171 KASSERT(SEQ_LT(rcv_start, rcv_end), ("rcv_start < rcv_end"));
173 /* SACK block for the received segment. */
174 head_blk.start = rcv_start;
175 head_blk.end = rcv_end;
178 * Merge updated SACK blocks into head_blk, and save unchanged SACK
179 * blocks into saved_blks[]. num_saved will have the number of the
183 for (i = 0; i < tp->rcv_numsacks; i++) {
184 tcp_seq start = tp->sackblks[i].start;
185 tcp_seq end = tp->sackblks[i].end;
186 if (SEQ_GEQ(start, end) || SEQ_LEQ(start, tp->rcv_nxt)) {
188 * Discard this SACK block.
190 } else if (SEQ_LEQ(head_blk.start, end) &&
191 SEQ_GEQ(head_blk.end, start)) {
193 * Merge this SACK block into head_blk. This SACK
194 * block itself will be discarded.
196 if (SEQ_GT(head_blk.start, start))
197 head_blk.start = start;
198 if (SEQ_LT(head_blk.end, end))
202 * Save this SACK block.
204 saved_blks[num_saved].start = start;
205 saved_blks[num_saved].end = end;
211 * Update SACK list in tp->sackblks[].
214 if (SEQ_GT(head_blk.start, tp->rcv_nxt)) {
216 * The received data segment is an out-of-order segment. Put
217 * head_blk at the top of SACK list.
219 tp->sackblks[0] = head_blk;
222 * If the number of saved SACK blocks exceeds its limit,
223 * discard the last SACK block.
225 if (num_saved >= MAX_SACK_BLKS)
230 * Copy the saved SACK blocks back.
232 bcopy(saved_blks, &tp->sackblks[num_head],
233 sizeof(struct sackblk) * num_saved);
236 /* Save the number of SACK blocks. */
237 tp->rcv_numsacks = num_head + num_saved;
241 * Delete all receiver-side SACK information.
244 tcp_clean_sackreport(struct tcpcb *tp)
248 INP_WLOCK_ASSERT(tp->t_inpcb);
249 tp->rcv_numsacks = 0;
250 for (i = 0; i < MAX_SACK_BLKS; i++)
251 tp->sackblks[i].start = tp->sackblks[i].end=0;
255 * Allocate struct sackhole.
257 static struct sackhole *
258 tcp_sackhole_alloc(struct tcpcb *tp, tcp_seq start, tcp_seq end)
260 struct sackhole *hole;
262 if (tp->snd_numholes >= V_tcp_sack_maxholes ||
263 V_tcp_sack_globalholes >= V_tcp_sack_globalmaxholes) {
264 TCPSTAT_INC(tcps_sack_sboverflow);
268 hole = (struct sackhole *)uma_zalloc(V_sack_hole_zone, M_NOWAIT);
277 atomic_add_int(&V_tcp_sack_globalholes, 1);
283 * Free struct sackhole.
286 tcp_sackhole_free(struct tcpcb *tp, struct sackhole *hole)
289 uma_zfree(V_sack_hole_zone, hole);
292 atomic_subtract_int(&V_tcp_sack_globalholes, 1);
294 KASSERT(tp->snd_numholes >= 0, ("tp->snd_numholes >= 0"));
295 KASSERT(V_tcp_sack_globalholes >= 0, ("tcp_sack_globalholes >= 0"));
299 * Insert new SACK hole into scoreboard.
301 static struct sackhole *
302 tcp_sackhole_insert(struct tcpcb *tp, tcp_seq start, tcp_seq end,
303 struct sackhole *after)
305 struct sackhole *hole;
307 /* Allocate a new SACK hole. */
308 hole = tcp_sackhole_alloc(tp, start, end);
312 /* Insert the new SACK hole into scoreboard. */
314 TAILQ_INSERT_AFTER(&tp->snd_holes, after, hole, scblink);
316 TAILQ_INSERT_TAIL(&tp->snd_holes, hole, scblink);
318 /* Update SACK hint. */
319 if (tp->sackhint.nexthole == NULL)
320 tp->sackhint.nexthole = hole;
326 * Remove SACK hole from scoreboard.
329 tcp_sackhole_remove(struct tcpcb *tp, struct sackhole *hole)
332 /* Update SACK hint. */
333 if (tp->sackhint.nexthole == hole)
334 tp->sackhint.nexthole = TAILQ_NEXT(hole, scblink);
336 /* Remove this SACK hole. */
337 TAILQ_REMOVE(&tp->snd_holes, hole, scblink);
339 /* Free this SACK hole. */
340 tcp_sackhole_free(tp, hole);
344 * Process cumulative ACK and the TCP SACK option to update the scoreboard.
345 * tp->snd_holes is an ordered list of holes (oldest to newest, in terms of
346 * the sequence space).
347 * Returns 1 if incoming ACK has previously unknown SACK information,
348 * 0 otherwise. Note: We treat (snd_una, th_ack) as a sack block so any changes
349 * to that (i.e. left edge moving) would also be considered a change in SACK
350 * information which is slightly different than rfc6675.
353 tcp_sack_doack(struct tcpcb *tp, struct tcpopt *to, tcp_seq th_ack)
355 struct sackhole *cur, *temp;
356 struct sackblk sack, sack_blocks[TCP_MAX_SACK + 1], *sblkp;
357 int i, j, num_sack_blks, sack_changed;
359 INP_WLOCK_ASSERT(tp->t_inpcb);
364 * If SND.UNA will be advanced by SEG.ACK, and if SACK holes exist,
365 * treat [SND.UNA, SEG.ACK) as if it is a SACK block.
367 if (SEQ_LT(tp->snd_una, th_ack) && !TAILQ_EMPTY(&tp->snd_holes)) {
368 sack_blocks[num_sack_blks].start = tp->snd_una;
369 sack_blocks[num_sack_blks++].end = th_ack;
372 * Append received valid SACK blocks to sack_blocks[], but only if we
373 * received new blocks from the other side.
375 if (to->to_flags & TOF_SACK) {
376 tp->sackhint.sacked_bytes = 0; /* reset */
377 for (i = 0; i < to->to_nsacks; i++) {
378 bcopy((to->to_sacks + i * TCPOLEN_SACK),
379 &sack, sizeof(sack));
380 sack.start = ntohl(sack.start);
381 sack.end = ntohl(sack.end);
382 if (SEQ_GT(sack.end, sack.start) &&
383 SEQ_GT(sack.start, tp->snd_una) &&
384 SEQ_GT(sack.start, th_ack) &&
385 SEQ_LT(sack.start, tp->snd_max) &&
386 SEQ_GT(sack.end, tp->snd_una) &&
387 SEQ_LEQ(sack.end, tp->snd_max)) {
388 sack_blocks[num_sack_blks++] = sack;
389 tp->sackhint.sacked_bytes +=
390 (sack.end-sack.start);
395 * Return if SND.UNA is not advanced and no valid SACK block is
398 if (num_sack_blks == 0)
399 return (sack_changed);
402 * Sort the SACK blocks so we can update the scoreboard with just one
403 * pass. The overhead of sorting upto 4+1 elements is less than
404 * making upto 4+1 passes over the scoreboard.
406 for (i = 0; i < num_sack_blks; i++) {
407 for (j = i + 1; j < num_sack_blks; j++) {
408 if (SEQ_GT(sack_blocks[i].end, sack_blocks[j].end)) {
409 sack = sack_blocks[i];
410 sack_blocks[i] = sack_blocks[j];
411 sack_blocks[j] = sack;
415 if (TAILQ_EMPTY(&tp->snd_holes))
417 * Empty scoreboard. Need to initialize snd_fack (it may be
418 * uninitialized or have a bogus value). Scoreboard holes
419 * (from the sack blocks received) are created later below
420 * (in the logic that adds holes to the tail of the
423 tp->snd_fack = SEQ_MAX(tp->snd_una, th_ack);
425 * In the while-loop below, incoming SACK blocks (sack_blocks[]) and
426 * SACK holes (snd_holes) are traversed from their tails with just
427 * one pass in order to reduce the number of compares especially when
428 * the bandwidth-delay product is large.
430 * Note: Typically, in the first RTT of SACK recovery, the highest
431 * three or four SACK blocks with the same ack number are received.
432 * In the second RTT, if retransmitted data segments are not lost,
433 * the highest three or four SACK blocks with ack number advancing
436 sblkp = &sack_blocks[num_sack_blks - 1]; /* Last SACK block */
437 tp->sackhint.last_sack_ack = sblkp->end;
438 if (SEQ_LT(tp->snd_fack, sblkp->start)) {
440 * The highest SACK block is beyond fack. Append new SACK
441 * hole at the tail. If the second or later highest SACK
442 * blocks are also beyond the current fack, they will be
443 * inserted by way of hole splitting in the while-loop below.
445 temp = tcp_sackhole_insert(tp, tp->snd_fack,sblkp->start,NULL);
447 tp->snd_fack = sblkp->end;
448 /* Go to the previous sack block. */
453 * We failed to add a new hole based on the current
454 * sack block. Skip over all the sack blocks that
455 * fall completely to the right of snd_fack and
456 * proceed to trim the scoreboard based on the
457 * remaining sack blocks. This also trims the
458 * scoreboard for th_ack (which is sack_blocks[0]).
460 while (sblkp >= sack_blocks &&
461 SEQ_LT(tp->snd_fack, sblkp->start))
463 if (sblkp >= sack_blocks &&
464 SEQ_LT(tp->snd_fack, sblkp->end))
465 tp->snd_fack = sblkp->end;
467 } else if (SEQ_LT(tp->snd_fack, sblkp->end)) {
468 /* fack is advanced. */
469 tp->snd_fack = sblkp->end;
472 /* We must have at least one SACK hole in scoreboard. */
473 KASSERT(!TAILQ_EMPTY(&tp->snd_holes),
474 ("SACK scoreboard must not be empty"));
475 cur = TAILQ_LAST(&tp->snd_holes, sackhole_head); /* Last SACK hole. */
477 * Since the incoming sack blocks are sorted, we can process them
478 * making one sweep of the scoreboard.
480 while (sblkp >= sack_blocks && cur != NULL) {
481 if (SEQ_GEQ(sblkp->start, cur->end)) {
483 * SACKs data beyond the current hole. Go to the
484 * previous sack block.
489 if (SEQ_LEQ(sblkp->end, cur->start)) {
491 * SACKs data before the current hole. Go to the
494 cur = TAILQ_PREV(cur, sackhole_head, scblink);
497 tp->sackhint.sack_bytes_rexmit -= (cur->rxmit - cur->start);
498 KASSERT(tp->sackhint.sack_bytes_rexmit >= 0,
499 ("sackhint bytes rtx >= 0"));
501 if (SEQ_LEQ(sblkp->start, cur->start)) {
502 /* Data acks at least the beginning of hole. */
503 if (SEQ_GEQ(sblkp->end, cur->end)) {
504 /* Acks entire hole, so delete hole. */
506 cur = TAILQ_PREV(cur, sackhole_head, scblink);
507 tcp_sackhole_remove(tp, temp);
509 * The sack block may ack all or part of the
510 * next hole too, so continue onto the next
515 /* Move start of hole forward. */
516 cur->start = sblkp->end;
517 cur->rxmit = SEQ_MAX(cur->rxmit, cur->start);
520 /* Data acks at least the end of hole. */
521 if (SEQ_GEQ(sblkp->end, cur->end)) {
522 /* Move end of hole backward. */
523 cur->end = sblkp->start;
524 cur->rxmit = SEQ_MIN(cur->rxmit, cur->end);
527 * ACKs some data in middle of a hole; need
528 * to split current hole
530 temp = tcp_sackhole_insert(tp, sblkp->end,
533 if (SEQ_GT(cur->rxmit, temp->rxmit)) {
534 temp->rxmit = cur->rxmit;
535 tp->sackhint.sack_bytes_rexmit
539 cur->end = sblkp->start;
540 cur->rxmit = SEQ_MIN(cur->rxmit,
545 tp->sackhint.sack_bytes_rexmit += (cur->rxmit - cur->start);
547 * Testing sblkp->start against cur->start tells us whether
548 * we're done with the sack block or the sack hole.
549 * Accordingly, we advance one or the other.
551 if (SEQ_LEQ(sblkp->start, cur->start))
552 cur = TAILQ_PREV(cur, sackhole_head, scblink);
556 return (sack_changed);
560 * Free all SACK holes to clear the scoreboard.
563 tcp_free_sackholes(struct tcpcb *tp)
567 INP_WLOCK_ASSERT(tp->t_inpcb);
568 while ((q = TAILQ_FIRST(&tp->snd_holes)) != NULL)
569 tcp_sackhole_remove(tp, q);
570 tp->sackhint.sack_bytes_rexmit = 0;
572 KASSERT(tp->snd_numholes == 0, ("tp->snd_numholes == 0"));
573 KASSERT(tp->sackhint.nexthole == NULL,
574 ("tp->sackhint.nexthole == NULL"));
578 * Partial ack handling within a sack recovery episode. Keeping this very
579 * simple for now. When a partial ack is received, force snd_cwnd to a value
580 * that will allow the sender to transmit no more than 2 segments. If
581 * necessary, a better scheme can be adopted at a later point, but for now,
582 * the goal is to prevent the sender from bursting a large amount of data in
583 * the midst of sack recovery.
586 tcp_sack_partialack(struct tcpcb *tp, struct tcphdr *th)
590 INP_WLOCK_ASSERT(tp->t_inpcb);
591 tcp_timer_activate(tp, TT_REXMT, 0);
593 /* Send one or 2 segments based on how much new data was acked. */
594 if ((BYTES_THIS_ACK(tp, th) / tp->t_maxseg) >= 2)
596 tp->snd_cwnd = (tp->sackhint.sack_bytes_rexmit +
597 (tp->snd_nxt - tp->sack_newdata) + num_segs * tp->t_maxseg);
598 if (tp->snd_cwnd > tp->snd_ssthresh)
599 tp->snd_cwnd = tp->snd_ssthresh;
600 tp->t_flags |= TF_ACKNOW;
601 (void) tcp_output(tp);
606 * Debug version of tcp_sack_output() that walks the scoreboard. Used for
607 * now to sanity check the hint.
609 static struct sackhole *
610 tcp_sack_output_debug(struct tcpcb *tp, int *sack_bytes_rexmt)
614 INP_WLOCK_ASSERT(tp->t_inpcb);
615 *sack_bytes_rexmt = 0;
616 TAILQ_FOREACH(p, &tp->snd_holes, scblink) {
617 if (SEQ_LT(p->rxmit, p->end)) {
618 if (SEQ_LT(p->rxmit, tp->snd_una)) {/* old SACK hole */
621 *sack_bytes_rexmt += (p->rxmit - p->start);
624 *sack_bytes_rexmt += (p->rxmit - p->start);
631 * Returns the next hole to retransmit and the number of retransmitted bytes
632 * from the scoreboard. We store both the next hole and the number of
633 * retransmitted bytes as hints (and recompute these on the fly upon SACK/ACK
634 * reception). This avoids scoreboard traversals completely.
636 * The loop here will traverse *at most* one link. Here's the argument. For
637 * the loop to traverse more than 1 link before finding the next hole to
638 * retransmit, we would need to have at least 1 node following the current
639 * hint with (rxmit == end). But, for all holes following the current hint,
640 * (start == rxmit), since we have not yet retransmitted from them.
641 * Therefore, in order to traverse more 1 link in the loop below, we need to
642 * have at least one node following the current hint with (start == rxmit ==
643 * end). But that can't happen, (start == end) means that all the data in
644 * that hole has been sacked, in which case, the hole would have been removed
645 * from the scoreboard.
648 tcp_sack_output(struct tcpcb *tp, int *sack_bytes_rexmt)
650 struct sackhole *hole = NULL;
652 INP_WLOCK_ASSERT(tp->t_inpcb);
653 *sack_bytes_rexmt = tp->sackhint.sack_bytes_rexmit;
654 hole = tp->sackhint.nexthole;
655 if (hole == NULL || SEQ_LT(hole->rxmit, hole->end))
657 while ((hole = TAILQ_NEXT(hole, scblink)) != NULL) {
658 if (SEQ_LT(hole->rxmit, hole->end)) {
659 tp->sackhint.nexthole = hole;
668 * After a timeout, the SACK list may be rebuilt. This SACK information
669 * should be used to avoid retransmitting SACKed data. This function
670 * traverses the SACK list to see if snd_nxt should be moved forward.
673 tcp_sack_adjust(struct tcpcb *tp)
675 struct sackhole *p, *cur = TAILQ_FIRST(&tp->snd_holes);
677 INP_WLOCK_ASSERT(tp->t_inpcb);
679 return; /* No holes */
680 if (SEQ_GEQ(tp->snd_nxt, tp->snd_fack))
681 return; /* We're already beyond any SACKed blocks */
683 * Two cases for which we want to advance snd_nxt:
684 * i) snd_nxt lies between end of one hole and beginning of another
685 * ii) snd_nxt lies between end of last hole and snd_fack
687 while ((p = TAILQ_NEXT(cur, scblink)) != NULL) {
688 if (SEQ_LT(tp->snd_nxt, cur->end))
690 if (SEQ_GEQ(tp->snd_nxt, p->start))
693 tp->snd_nxt = p->start;
697 if (SEQ_LT(tp->snd_nxt, cur->end))
699 tp->snd_nxt = tp->snd_fack;