Home | History | Annotate | Line # | Download | only in netinet
tcp_sack.c revision 1.6
      1 /* $NetBSD: tcp_sack.c,v 1.6 2005/03/07 09:40:35 yamt Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2005 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Kentaro A. Kurahone.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1994, 1995
     41  *	The Regents of the University of California.  All rights reserved.
     42  *
     43  * Redistribution and use in source and binary forms, with or without
     44  * modification, are permitted provided that the following conditions
     45  * are met:
     46  * 1. Redistributions of source code must retain the above copyright
     47  *    notice, this list of conditions and the following disclaimer.
     48  * 2. Redistributions in binary form must reproduce the above copyright
     49  *    notice, this list of conditions and the following disclaimer in the
     50  *    documentation and/or other materials provided with the distribution.
     51  * 4. Neither the name of the University 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.
     54  *
     55  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     56  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     57  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     58  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     59  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     60  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     61  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     62  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     63  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     64  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     65  * SUCH DAMAGE.
     66  *
     67  *	@(#)tcp_sack.c	8.12 (Berkeley) 5/24/95
     68  * $FreeBSD: src/sys/netinet/tcp_sack.c,v 1.3.2.2 2004/12/25 23:02:57 rwatson Exp $
     69  */
     70 
     71 /*
     72  *	@@(#)COPYRIGHT	1.1 (NRL) 17 January 1995
     73  *
     74  * NRL grants permission for redistribution and use in source and binary
     75  * forms, with or without modification, of the software and documentation
     76  * created at NRL provided that the following conditions are met:
     77  *
     78  * 1. Redistributions of source code must retain the above copyright
     79  *    notice, this list of conditions and the following disclaimer.
     80  * 2. Redistributions in binary form must reproduce the above copyright
     81  *    notice, this list of conditions and the following disclaimer in the
     82  *    documentation and/or other materials provided with the distribution.
     83  * 3. All advertising materials mentioning features or use of this software
     84  *    must display the following acknowledgements:
     85  *	This product includes software developed by the University of
     86  *	California, Berkeley and its contributors.
     87  *	This product includes software developed at the Information
     88  *	Technology Division, US Naval Research Laboratory.
     89  * 4. Neither the name of the NRL nor the names of its contributors
     90  *    may be used to endorse or promote products derived from this software
     91  *    without specific prior written permission.
     92  *
     93  * THE SOFTWARE PROVIDED BY NRL IS PROVIDED BY NRL AND CONTRIBUTORS ``AS
     94  * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     95  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
     96  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL NRL OR
     97  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     98  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     99  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    100  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    101  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    102  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    103  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    104  *
    105  * The views and conclusions contained in the software and documentation
    106  * are those of the authors and should not be interpreted as representing
    107  * official policies, either expressed or implied, of the US Naval
    108  * Research Laboratory (NRL).
    109  */
    110 
    111 #include <sys/cdefs.h>
    112 __KERNEL_RCSID(0, "$NetBSD: tcp_sack.c,v 1.6 2005/03/07 09:40:35 yamt Exp $");
    113 
    114 #include "opt_inet.h"
    115 #include "opt_ipsec.h"
    116 #include "opt_inet_csum.h"
    117 #include "opt_tcp_debug.h"
    118 
    119 #include <sys/param.h>
    120 #include <sys/systm.h>
    121 #include <sys/malloc.h>
    122 #include <sys/mbuf.h>
    123 #include <sys/protosw.h>
    124 #include <sys/socket.h>
    125 #include <sys/socketvar.h>
    126 #include <sys/errno.h>
    127 #include <sys/syslog.h>
    128 #include <sys/pool.h>
    129 #include <sys/domain.h>
    130 #include <sys/kernel.h>
    131 
    132 #include <net/if.h>
    133 #include <net/route.h>
    134 #include <net/if_types.h>
    135 
    136 #include <netinet/in.h>
    137 #include <netinet/in_systm.h>
    138 #include <netinet/ip.h>
    139 #include <netinet/in_pcb.h>
    140 #include <netinet/in_var.h>
    141 #include <netinet/ip_var.h>
    142 
    143 #ifdef INET6
    144 #ifndef INET
    145 #include <netinet/in.h>
    146 #endif
    147 #include <netinet/ip6.h>
    148 #include <netinet6/ip6_var.h>
    149 #include <netinet6/in6_pcb.h>
    150 #include <netinet6/ip6_var.h>
    151 #include <netinet6/in6_var.h>
    152 #include <netinet/icmp6.h>
    153 #include <netinet6/nd6.h>
    154 #endif
    155 
    156 #ifndef INET6
    157 /* always need ip6.h for IP6_EXTHDR_GET */
    158 #include <netinet/ip6.h>
    159 #endif
    160 
    161 #include <netinet/tcp.h>
    162 #include <netinet/tcp_fsm.h>
    163 #include <netinet/tcp_seq.h>
    164 #include <netinet/tcp_timer.h>
    165 #include <netinet/tcp_var.h>
    166 #include <netinet/tcpip.h>
    167 #include <netinet/tcp_debug.h>
    168 
    169 #include <machine/stdarg.h>
    170 
    171 #define SEQ_MIN(a, b)	((SEQ_LT(a, b)) ? (a) : (b))
    172 #define SEQ_MAX(a, b)	((SEQ_GT(a, b)) ? (a) : (b))
    173 
    174 /* SACK block pool. */
    175 POOL_INIT(sackhole_pool, sizeof(struct sackhole), 0, 0, 0, "sackholepl", NULL);
    176 
    177 void
    178 tcp_update_sack_list(struct tcpcb *tp)
    179 {
    180 	int i = 0;
    181 	struct ipqent *tiqe = NULL;
    182 
    183 	if (!TCP_SACK_ENABLED(tp) || (tp->t_flags & TF_SIGNATURE)) {
    184 		/* Can't SACK this connection. */
    185 		return;
    186 	}
    187 
    188 	/*
    189 	 * If possible, tack on the D-SACK block. (RFC2883)
    190 	 */
    191 	if (tp->rcv_sack_flags & TCPSACK_HAVED) {
    192 		tp->rcv_sack_block[0].left = tp->rcv_dsack_block.left;
    193 		tp->rcv_sack_block[0].right = tp->rcv_dsack_block.right;
    194 		tp->rcv_sack_flags &= ~TCPSACK_HAVED;
    195 		i++;
    196 	}
    197 
    198 	/*
    199 	 * Build up a list of holes in the TCP space.  Note that
    200 	 * the first SACK block is always the most recent segment
    201 	 * received.
    202 	 */
    203 	TAILQ_FOREACH(tiqe, &tp->timeq, ipqe_timeq) {
    204 		tp->rcv_sack_block[i].left = tiqe->ipqe_seq;
    205 		tp->rcv_sack_block[i].right = tiqe->ipqe_seq + tiqe->ipqe_len;
    206 		i++;
    207 		if (i >= TCP_SACK_MAX) {
    208 			break;
    209 		}
    210 	}
    211 
    212 	/* If we can SACK, do so. */
    213 	tp->rcv_sack_num = i;
    214 }
    215 
    216 void
    217 tcp_new_dsack(struct tcpcb *tp, tcp_seq seq, u_int32_t len)
    218 {
    219 	if (TCP_SACK_ENABLED(tp)) {
    220 		tp->rcv_dsack_block.left = seq;
    221 		tp->rcv_dsack_block.right = seq + len;
    222 		tp->rcv_sack_flags |= TCPSACK_HAVED;
    223 	}
    224 }
    225 
    226 void
    227 tcp_sack_option(struct tcpcb *tp, struct tcphdr *th, u_char *cp, int optlen)
    228 {
    229 	struct sackblk
    230 	    t_sack_block[(MAX_TCPOPTLEN - 2) / (sizeof(u_int32_t) * 2)];
    231 	struct sackblk *sack = NULL;
    232 	struct sackhole *cur = NULL;
    233 	struct sackhole *tmp = NULL;
    234 	u_int32_t *lp = (u_int32_t *) (cp + 2);
    235 	int i, j, num_sack_blks;
    236 	tcp_seq left, right, acked;
    237 
    238 	/*
    239 	 * If we aren't processing SACK responses, or the peer
    240 	 * sends us a sack option with invalid length, don't
    241 	 * update the scoreboard.
    242 	 */
    243 	if (!TCP_SACK_ENABLED(tp) || (optlen % 8 != 2 || optlen < 10)) {
    244 		return;
    245 	}
    246 
    247 	/*
    248 	 * Extract SACK blocks.
    249 	 *
    250 	 * Note that t_sack_block is sorted so that we only need to do
    251 	 * one pass over the sequence number space. (SACK "fast-path")
    252 	 */
    253 	num_sack_blks = optlen / 8;
    254 	acked = (SEQ_GT(th->th_ack, tp->snd_una)) ? th->th_ack : tp->snd_una;
    255 	for (i = 0; i < num_sack_blks; i++, lp += 2) {
    256 		memcpy(&left, lp, sizeof(*lp));
    257 		memcpy(&right, lp + 1, sizeof(*lp));
    258 		left = ntohl(left);
    259 		right = ntohl(right);
    260 
    261 		if (SEQ_LEQ(right, acked) || SEQ_GEQ(left, tp->snd_max) ||
    262 		    SEQ_GEQ(left, right)) {
    263 			/* SACK entry that's old, or invalid. */
    264 			i--;
    265 			num_sack_blks--;
    266 			continue;
    267 		}
    268 
    269 		/* Insertion sort. */
    270 		for (j = i; (j > 0) && SEQ_LT(left, t_sack_block[j - 1].left);
    271 		    j--) {
    272 			t_sack_block[j].left = t_sack_block[j - 1].left;
    273 			t_sack_block[j].right = t_sack_block[j - 1].right;
    274 		}
    275 		t_sack_block[j].left = left;
    276 		t_sack_block[j].right = right;
    277 	}
    278 
    279 	/* Update the scoreboard. */
    280 	cur = TAILQ_FIRST(&tp->snd_holes);
    281 	for (i = 0; i < num_sack_blks; i++) {
    282 		sack = &t_sack_block[i];
    283 		/*
    284 		 * FACK TCP.  Update snd_fack so we can enter Fast
    285 		 * Recovery early.
    286 		 */
    287 		if (SEQ_GEQ(sack->right, tp->snd_fack))
    288 			tp->snd_fack = sack->right;
    289 
    290 		if (TAILQ_EMPTY(&tp->snd_holes)) {
    291 			/* First hole. */
    292 			cur = (struct sackhole *)
    293 			    pool_get(&sackhole_pool, PR_NOWAIT);
    294 			if (cur == NULL) {
    295 				/* ENOBUFS, bail out*/
    296 				return;
    297 			}
    298 			cur->start = th->th_ack;
    299 			cur->end = sack->left;
    300 			cur->rxmit = cur->start;
    301 			tp->rcv_lastsack = sack->right;
    302 			TAILQ_INSERT_HEAD(&tp->snd_holes, cur, sackhole_q);
    303 			continue; /* With next sack block */
    304 		}
    305 
    306 		/* Go through the list of holes. */
    307 		while (cur) {
    308 			if (SEQ_LEQ(sack->right, cur->start))
    309 				/* SACKs data before the current hole */
    310 				break; /* No use going through more holes */
    311 
    312 			if (SEQ_GEQ(sack->left, cur->end)) {
    313 				/* SACKs data beyond the current hole */
    314 				cur = TAILQ_NEXT(cur, sackhole_q);
    315 				continue;
    316 			}
    317 
    318 			if (SEQ_LEQ(sack->left, cur->start)) {
    319 				/* Data acks at least the beginning of hole */
    320 				if (SEQ_GEQ(sack->right, cur->end)) {
    321 					/* Acks entire hole, so delete hole */
    322 					tmp = cur;
    323 					cur = TAILQ_NEXT(cur, sackhole_q);
    324 					TAILQ_REMOVE(&tp->snd_holes, tmp,
    325 					    sackhole_q);
    326 					pool_put(&sackhole_pool, tmp);
    327 					break;
    328 				}
    329 
    330 				/* Otherwise, move start of hole forward */
    331 				cur->start = sack->right;
    332 				cur->rxmit = SEQ_MAX(cur->rxmit, cur->start);
    333 				cur = TAILQ_NEXT(cur, sackhole_q);
    334 				break;
    335 			}
    336 
    337 			if (SEQ_GEQ(sack->right, cur->end)) {
    338 				/* Move end of hole backward. */
    339 				cur->end = sack->left;
    340 				cur->rxmit = SEQ_MIN(cur->rxmit, cur->end);
    341 				cur = TAILQ_NEXT(cur, sackhole_q);
    342 				break;
    343 			}
    344 
    345 			if (SEQ_LT(cur->start, sack->left) &&
    346 			    SEQ_GT(cur->end, sack->right)) {
    347 				/*
    348 				 * ACKs some data in middle of a hole; need to
    349 				 * split current hole
    350 				 */
    351 				tmp = (struct sackhole *)
    352 				    pool_get(&sackhole_pool, PR_NOWAIT);
    353 				if (tmp == NULL) {
    354 					/* ENOBUFS, bail out. */
    355 					return;
    356 				}
    357 				tmp->start = sack->right;
    358 				tmp->end = cur->end;
    359 				tmp->rxmit = SEQ_MAX(cur->rxmit, tmp->start);
    360 				cur->end = sack->left;
    361 				cur->rxmit = SEQ_MIN(cur->rxmit, cur->end);
    362 				TAILQ_INSERT_AFTER(&tp->snd_holes, cur, tmp,
    363 						sackhole_q);
    364 				cur = TAILQ_NEXT(tmp, sackhole_q);
    365 				break;
    366 			}
    367 		}
    368 
    369 		/* At this point, we have reached the tail of the list. */
    370 		if (SEQ_LT(tp->rcv_lastsack, sack->left)) {
    371 			/*
    372 			 * Need to append new hole at end.
    373 			 */
    374 			tmp = (struct sackhole *)
    375 			    pool_get(&sackhole_pool, PR_NOWAIT);
    376 			if (tmp == NULL)
    377 				continue; /* ENOBUFS */
    378 			tmp->start = tp->rcv_lastsack;
    379 			tmp->end = sack->left;
    380 			tmp->rxmit = tmp->start;
    381 			tp->rcv_lastsack = sack->right;
    382 			TAILQ_INSERT_TAIL(&tp->snd_holes, tmp, sackhole_q);
    383 			cur = tmp;
    384 		}
    385 	}
    386 }
    387 
    388 void
    389 tcp_del_sackholes(struct tcpcb *tp, struct tcphdr *th)
    390 {
    391 	/* Max because this could be an older ack that just arrived. */
    392 	tcp_seq lastack = SEQ_GT(th->th_ack, tp->snd_una) ?
    393 		th->th_ack : tp->snd_una;
    394 	struct sackhole *cur = TAILQ_FIRST(&tp->snd_holes);
    395 	struct sackhole *tmp;
    396 
    397 	while (cur) {
    398 		if (SEQ_LEQ(cur->end, lastack)) {
    399 			tmp = cur;
    400 			cur = TAILQ_NEXT(cur, sackhole_q);
    401 			TAILQ_REMOVE(&tp->snd_holes, tmp, sackhole_q);
    402 			pool_put(&sackhole_pool, tmp);
    403 		} else if (SEQ_LT(cur->start, lastack)) {
    404 			cur->start = lastack;
    405 			if (SEQ_LT(cur->rxmit, cur->start))
    406 				cur->rxmit = cur->start;
    407 			break;
    408 		} else
    409 			break;
    410 
    411 	}
    412 }
    413 
    414 void
    415 tcp_free_sackholes(struct tcpcb *tp)
    416 {
    417 	struct sackhole *sack;
    418 
    419 	/* Free up the SACK hole list. */
    420 	while (!TAILQ_EMPTY(&tp->snd_holes)) {
    421 		sack = TAILQ_FIRST(&tp->snd_holes);
    422 		TAILQ_REMOVE(&tp->snd_holes, sack, sackhole_q);
    423 		pool_put(&sackhole_pool, sack);
    424 	}
    425 }
    426 
    427 /*
    428  * Implements the SACK response to a new ack, checking for partial acks
    429  * in fast recovery.
    430  */
    431 void
    432 tcp_sack_newack(struct tcpcb *tp, struct tcphdr *th)
    433 {
    434 	if (tp->t_partialacks < 0) {
    435 		/*
    436 		 * Not in fast recovery.  Reset the duplicate ack
    437 		 * counter.
    438 		 */
    439 		tp->t_dupacks = 0;
    440 	} else if (SEQ_LT(th->th_ack, tp->snd_recover)) {
    441 		/*
    442 		 * Partial ack handling within a sack recovery episode.
    443 		 * Keeping this very simple for now. When a partial ack
    444 		 * is received, force snd_cwnd to a value that will allow
    445 		 * the sender to transmit no more than 2 segments.
    446 		 * If necessary, a fancier scheme can be adopted at a
    447 		 * later point, but for now, the goal is to prevent the
    448 		 * sender from bursting a large amount of data in the midst
    449 		 * of sack recovery.
    450 		 */
    451 		int num_segs = 1;
    452 		int sack_bytes_rxmt = 0;
    453 
    454 		tp->t_partialacks++;
    455 		TCP_TIMER_DISARM(tp, TCPT_REXMT);
    456 		tp->t_rtttime = 0;
    457 
    458 	 	/*
    459 		 * send one or 2 segments based on how much new data was acked
    460 		 */
    461  		if (((th->th_ack - tp->snd_una) / tp->t_segsz) > 2)
    462  			num_segs = 2;
    463 	 	(void)tcp_sack_output(tp, &sack_bytes_rxmt);
    464  		tp->snd_cwnd = sack_bytes_rxmt +
    465 		    (tp->snd_nxt - tp->sack_newdata) + num_segs * tp->t_segsz;
    466   		tp->t_flags |= TF_ACKNOW;
    467 	  	(void) tcp_output(tp);
    468 	} else {
    469 		/*
    470 		 * Complete ack, inflate the congestion window to
    471                  * ssthresh and exit fast recovery.
    472 		 *
    473 		 * Window inflation should have left us with approx.
    474 		 * snd_ssthresh outstanding data.  But in case we
    475 		 * would be inclined to send a burst, better to do
    476 		 * it via the slow start mechanism.
    477 		 */
    478 		if (SEQ_SUB(tp->snd_max, th->th_ack) < tp->snd_ssthresh)
    479 			tp->snd_cwnd = SEQ_SUB(tp->snd_max, th->th_ack)
    480 			    + tp->t_segsz;
    481 		else
    482 			tp->snd_cwnd = tp->snd_ssthresh;
    483 		tp->t_partialacks = -1;
    484 		tp->t_dupacks = 0;
    485 		if (SEQ_GT(th->th_ack, tp->snd_fack))
    486 			tp->snd_fack = th->th_ack;
    487 	}
    488 }
    489 
    490 /*
    491  * Returns pointer to a sackhole if there are any pending retransmissions;
    492  * NULL otherwise.
    493  */
    494 struct sackhole *
    495 tcp_sack_output(struct tcpcb *tp, int *sack_bytes_rexmt)
    496 {
    497 	struct sackhole *cur = NULL;
    498 
    499 	if(!TCP_SACK_ENABLED(tp))
    500 		return (NULL);
    501 
    502 	*sack_bytes_rexmt = 0;
    503 	TAILQ_FOREACH(cur, &tp->snd_holes, sackhole_q) {
    504 		if (SEQ_LT(cur->rxmit, cur->end)) {
    505 			if (SEQ_LT(cur->rxmit, tp->snd_una)) {
    506 				/* old SACK hole */
    507 				continue;
    508 			}
    509 			*sack_bytes_rexmt += (cur->rxmit - cur->start);
    510 			break;
    511 		}
    512 		*sack_bytes_rexmt += (cur->rxmit - cur->start);
    513 	}
    514 
    515 	return (cur);
    516 }
    517 
    518 /*
    519  * After a timeout, the SACK list may be rebuilt.  This SACK information
    520  * should be used to avoid retransmitting SACKed data.  This function
    521  * traverses the SACK list to see if snd_nxt should be moved forward.
    522  */
    523 void
    524 tcp_sack_adjust(struct tcpcb *tp)
    525 {
    526 	struct sackhole *cur = TAILQ_FIRST(&tp->snd_holes);
    527 	struct sackhole *n = NULL;
    528 
    529 	if (TAILQ_EMPTY(&tp->snd_holes))
    530 		return; /* No holes */
    531 	if (SEQ_GEQ(tp->snd_nxt, tp->rcv_lastsack))
    532 		return; /* We're already beyond any SACKed blocks */
    533 
    534 	/*
    535 	 * Two cases for which we want to advance snd_nxt:
    536 	 * i) snd_nxt lies between end of one hole and beginning of another
    537 	 * ii) snd_nxt lies between end of last hole and rcv_lastsack
    538 	 */
    539 	while ((n = TAILQ_NEXT(cur, sackhole_q)) != NULL) {
    540 		if (SEQ_LT(tp->snd_nxt, cur->end))
    541 			return;
    542 		if (SEQ_GEQ(tp->snd_nxt, n->start))
    543 			cur = n;
    544 		else {
    545 			tp->snd_nxt = n->start;
    546 			return;
    547 		}
    548 	}
    549 	if (SEQ_LT(tp->snd_nxt, cur->end))
    550 		return;
    551 	tp->snd_nxt = tp->rcv_lastsack;
    552 
    553 	return;
    554 }
    555