2 * Copyright (c) 2003, 2004 Jeffrey M. Hsu. All rights reserved.
3 * Copyright (c) 2003, 2004 The DragonFly Project. All rights reserved.
5 * This code is derived from software contributed to The DragonFly Project
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of The DragonFly Project nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific, prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * $DragonFly: src/sys/netinet/tcp_sack.c,v 1.8 2008/08/15 21:37:16 nth Exp $
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/malloc.h>
40 #include <sys/queue.h>
41 #include <sys/thread.h>
42 #include <sys/types.h>
43 #include <sys/socket.h>
44 #include <sys/socketvar.h>
48 #include <netinet/in.h>
49 #include <netinet/in_systm.h>
50 #include <netinet/ip.h>
51 #include <netinet/in_var.h>
52 #include <netinet/in_pcb.h>
53 #include <netinet/ip_var.h>
54 #include <netinet/tcp.h>
55 #include <netinet/tcp_seq.h>
56 #include <netinet/tcp_var.h>
61 TAILQ_ENTRY(sackblock
) sblk_list
;
64 #define MAXSAVEDBLOCKS 8 /* per connection limit */
66 static void insert_block(struct scoreboard
*scb
, struct sackblock
*newblock
);
67 static void update_lostseq(struct scoreboard
*scb
, tcp_seq snd_una
,
70 static MALLOC_DEFINE(M_SACKBLOCK
, "sblk", "sackblock struct");
73 * Per-tcpcb initialization.
76 tcp_sack_tcpcb_init(struct tcpcb
*tp
)
78 struct scoreboard
*scb
= &tp
->scb
;
81 TAILQ_INIT(&scb
->sackblocks
);
82 scb
->lastfound
= NULL
;
86 * Find the SACK block containing or immediately preceding "seq".
87 * The boolean result indicates whether the sequence is actually
88 * contained in the SACK block.
91 sack_block_lookup(struct scoreboard
*scb
, tcp_seq seq
, struct sackblock
**sb
)
93 struct sackblock
*hint
= scb
->lastfound
;
94 struct sackblock
*cur
, *last
, *prev
;
96 if (TAILQ_EMPTY(&scb
->sackblocks
)) {
102 /* No hint. Search from start to end. */
103 cur
= TAILQ_FIRST(&scb
->sackblocks
);
105 prev
= TAILQ_LAST(&scb
->sackblocks
, sackblock_list
);
107 if (SEQ_GEQ(seq
, hint
->sblk_start
)) {
108 /* Search from hint to end of list. */
111 prev
= TAILQ_LAST(&scb
->sackblocks
, sackblock_list
);
113 /* Search from front of list to hint. */
114 cur
= TAILQ_FIRST(&scb
->sackblocks
);
116 prev
= TAILQ_PREV(hint
, sackblock_list
, sblk_list
);
121 if (SEQ_GT(cur
->sblk_end
, seq
)) {
122 if (SEQ_GEQ(seq
, cur
->sblk_start
)) {
123 *sb
= scb
->lastfound
= cur
;
126 *sb
= scb
->lastfound
=
127 TAILQ_PREV(cur
, sackblock_list
, sblk_list
);
131 cur
= TAILQ_NEXT(cur
, sblk_list
);
132 } while (cur
!= last
);
134 *sb
= scb
->lastfound
= prev
;
139 * Allocate a SACK block.
141 static __inline
struct sackblock
*
142 alloc_sackblock(void)
144 return (kmalloc(sizeof(struct sackblock
), M_SACKBLOCK
, M_NOWAIT
));
151 free_sackblock(struct sackblock
*s
)
153 kfree(s
, M_SACKBLOCK
);
157 * Free up SACK blocks for data that's been acked.
160 tcp_sack_ack_blocks(struct scoreboard
*scb
, tcp_seq th_ack
)
162 struct sackblock
*sb
, *nb
;
164 sb
= TAILQ_FIRST(&scb
->sackblocks
);
165 while (sb
&& SEQ_LEQ(sb
->sblk_end
, th_ack
)) {
166 nb
= TAILQ_NEXT(sb
, sblk_list
);
167 if (scb
->lastfound
== sb
)
168 scb
->lastfound
= NULL
;
169 TAILQ_REMOVE(&scb
->sackblocks
, sb
, sblk_list
);
172 KASSERT(scb
->nblocks
>= 0,
173 ("SACK block count underflow: %d < 0", scb
->nblocks
));
176 if (sb
&& SEQ_GT(th_ack
, sb
->sblk_start
))
177 sb
->sblk_start
= th_ack
; /* other side reneged? XXX */
181 * Delete and free SACK blocks saved in scoreboard.
184 tcp_sack_cleanup(struct scoreboard
*scb
)
186 struct sackblock
*sb
, *nb
;
188 TAILQ_FOREACH_MUTABLE(sb
, &scb
->sackblocks
, sblk_list
, nb
) {
192 KASSERT(scb
->nblocks
== 0,
193 ("SACK block %d count not zero", scb
->nblocks
));
194 TAILQ_INIT(&scb
->sackblocks
);
195 scb
->lastfound
= NULL
;
199 * Returns 0 if not D-SACK block,
201 * 2 if duplicate of out-of-order D-SACK block.
204 tcp_sack_ndsack_blocks(struct raw_sackblock
*blocks
, const int numblocks
,
210 if (SEQ_LT(blocks
[0].rblk_start
, snd_una
))
213 /* block 0 inside block 1 */
215 SEQ_GEQ(blocks
[0].rblk_start
, blocks
[1].rblk_start
) &&
216 SEQ_LEQ(blocks
[0].rblk_end
, blocks
[1].rblk_end
))
223 * Update scoreboard on new incoming ACK.
226 tcp_sack_add_blocks(struct tcpcb
*tp
, struct tcpopt
*to
)
228 const int numblocks
= to
->to_nsackblocks
;
229 struct raw_sackblock
*blocks
= to
->to_sackblocks
;
230 struct scoreboard
*scb
= &tp
->scb
;
231 struct sackblock
*sb
;
235 if (tcp_sack_ndsack_blocks(blocks
, numblocks
, tp
->snd_una
) > 0)
240 for (i
= startblock
; i
< numblocks
; i
++) {
241 struct raw_sackblock
*newsackblock
= &blocks
[i
];
243 /* don't accept bad SACK blocks */
244 if (SEQ_GT(newsackblock
->rblk_end
, tp
->snd_max
))
245 break; /* skip all other blocks */
247 sb
= alloc_sackblock();
248 if (sb
== NULL
) /* do some sort of cleanup? XXX */
249 break; /* just skip rest of blocks */
250 sb
->sblk_start
= newsackblock
->rblk_start
;
251 sb
->sblk_end
= newsackblock
->rblk_end
;
252 if (TAILQ_EMPTY(&scb
->sackblocks
)) {
253 KASSERT(scb
->nblocks
== 0, ("emply scb w/ blocks"));
255 TAILQ_INSERT_HEAD(&scb
->sackblocks
, sb
, sblk_list
);
257 insert_block(scb
, sb
);
263 tcp_sack_update_scoreboard(struct tcpcb
*tp
, struct tcpopt
*to
)
265 struct scoreboard
*scb
= &tp
->scb
;
267 tcp_sack_ack_blocks(scb
, tp
->snd_una
);
268 tcp_sack_add_blocks(tp
, to
);
269 update_lostseq(scb
, tp
->snd_una
, tp
->t_maxseg
);
270 if (SEQ_LT(tp
->rexmt_high
, tp
->snd_una
))
271 tp
->rexmt_high
= tp
->snd_una
;
275 * Insert SACK block into sender's scoreboard.
278 insert_block(struct scoreboard
*scb
, struct sackblock
*newblock
)
280 struct sackblock
*sb
, *workingblock
;
281 boolean_t overlap_front
;
283 KASSERT(scb
->nblocks
> 0, ("insert_block() called w/ no blocks"));
285 if (scb
->nblocks
== MAXSAVEDBLOCKS
) {
287 * Should try to kick out older blocks XXX JH
288 * May be able to coalesce with existing block.
289 * Or, go other way and free all blocks if we hit this limit.
291 free_sackblock(newblock
);
294 KASSERT(scb
->nblocks
< MAXSAVEDBLOCKS
,
295 ("too many SACK blocks %d", scb
->nblocks
));
297 overlap_front
= sack_block_lookup(scb
, newblock
->sblk_start
, &sb
);
300 workingblock
= newblock
;
301 TAILQ_INSERT_HEAD(&scb
->sackblocks
, newblock
, sblk_list
);
304 if (overlap_front
|| sb
->sblk_end
== newblock
->sblk_start
) {
305 /* extend old block and discard new one */
307 if (SEQ_GT(newblock
->sblk_end
, sb
->sblk_end
))
308 sb
->sblk_end
= newblock
->sblk_end
;
309 free_sackblock(newblock
);
311 workingblock
= newblock
;
312 TAILQ_INSERT_AFTER(&scb
->sackblocks
, sb
, newblock
,
318 /* Consolidate right-hand side. */
319 sb
= TAILQ_NEXT(workingblock
, sblk_list
);
321 SEQ_GEQ(workingblock
->sblk_end
, sb
->sblk_end
)) {
322 struct sackblock
*nextblock
;
324 nextblock
= TAILQ_NEXT(sb
, sblk_list
);
325 if (scb
->lastfound
== sb
)
326 scb
->lastfound
= NULL
;
327 /* Remove completely overlapped block */
328 TAILQ_REMOVE(&scb
->sackblocks
, sb
, sblk_list
);
331 KASSERT(scb
->nblocks
> 0,
332 ("removed overlapped block: %d blocks left", scb
->nblocks
));
336 SEQ_GEQ(workingblock
->sblk_end
, sb
->sblk_start
)) {
337 /* Extend new block to cover partially overlapped old block. */
338 workingblock
->sblk_end
= sb
->sblk_end
;
339 if (scb
->lastfound
== sb
)
340 scb
->lastfound
= NULL
;
341 TAILQ_REMOVE(&scb
->sackblocks
, sb
, sblk_list
);
344 KASSERT(scb
->nblocks
> 0,
345 ("removed partial right: %d blocks left", scb
->nblocks
));
349 #ifdef DEBUG_SACK_BLOCKS
351 tcp_sack_dump_blocks(struct scoreboard
*scb
)
353 struct sackblock
*sb
;
355 kprintf("%d blocks:", scb
->nblocks
);
356 TAILQ_FOREACH(sb
, &scb
->sackblocks
, sblk_list
)
357 kprintf(" [%u, %u)", sb
->sblk_start
, sb
->sblk_end
);
362 tcp_sack_dump_blocks(struct scoreboard
*scb
)
368 * Optimization to quickly determine which packets are lost.
371 update_lostseq(struct scoreboard
*scb
, tcp_seq snd_una
, u_int maxseg
)
373 struct sackblock
*sb
;
375 int bytes_sacked
= 0;
377 sb
= TAILQ_LAST(&scb
->sackblocks
, sackblock_list
);
380 bytes_sacked
+= sb
->sblk_end
- sb
->sblk_start
;
381 if (nsackblocks
== tcprexmtthresh
||
382 bytes_sacked
>= tcprexmtthresh
* maxseg
) {
383 scb
->lostseq
= sb
->sblk_start
;
386 sb
= TAILQ_PREV(sb
, sackblock_list
, sblk_list
);
388 scb
->lostseq
= snd_una
;
392 * Return whether the given sequence number is considered lost.
395 scb_islost(struct scoreboard
*scb
, tcp_seq seqnum
)
397 return SEQ_LT(seqnum
, scb
->lostseq
);
401 * True if at least "amount" has been SACKed. Used by Early Retransmit.
404 tcp_sack_has_sacked(struct scoreboard
*scb
, u_int amount
)
406 struct sackblock
*sb
;
407 int bytes_sacked
= 0;
409 TAILQ_FOREACH(sb
, &scb
->sackblocks
, sblk_list
) {
410 bytes_sacked
+= sb
->sblk_end
- sb
->sblk_start
;
411 if (bytes_sacked
>= amount
)
418 * Number of bytes SACKed below seq.
421 tcp_sack_bytes_below(struct scoreboard
*scb
, tcp_seq seq
)
423 struct sackblock
*sb
;
424 int bytes_sacked
= 0;
426 sb
= TAILQ_FIRST(&scb
->sackblocks
);
427 while (sb
&& SEQ_GT(seq
, sb
->sblk_start
)) {
428 bytes_sacked
+= seq_min(seq
, sb
->sblk_end
) - sb
->sblk_start
;
429 sb
= TAILQ_NEXT(sb
, sblk_list
);
435 * Return estimate of the number of bytes outstanding in the network.
438 tcp_sack_compute_pipe(struct tcpcb
*tp
)
440 struct scoreboard
*scb
= &tp
->scb
;
441 struct sackblock
*sb
;
442 int nlost
, nretransmitted
;
445 nlost
= tp
->snd_max
- scb
->lostseq
;
446 nretransmitted
= tp
->rexmt_high
- tp
->snd_una
;
448 TAILQ_FOREACH(sb
, &scb
->sackblocks
, sblk_list
) {
449 if (SEQ_LT(sb
->sblk_start
, tp
->rexmt_high
)) {
450 end
= seq_min(sb
->sblk_end
, tp
->rexmt_high
);
451 nretransmitted
-= end
- sb
->sblk_start
;
453 if (SEQ_GEQ(sb
->sblk_start
, scb
->lostseq
))
454 nlost
-= sb
->sblk_end
- sb
->sblk_start
;
457 return (nlost
+ nretransmitted
);
461 * Return the sequence number and length of the next segment to transmit
462 * when in Fast Recovery.
465 tcp_sack_nextseg(struct tcpcb
*tp
, tcp_seq
*nextrexmt
, uint32_t *plen
,
468 struct scoreboard
*scb
= &tp
->scb
;
469 struct socket
*so
= tp
->t_inpcb
->inp_socket
;
470 struct sackblock
*sb
;
471 const struct sackblock
*lastblock
=
472 TAILQ_LAST(&scb
->sackblocks
, sackblock_list
);
476 /* skip SACKed data */
477 tcp_sack_skip_sacked(scb
, &tp
->rexmt_high
);
479 /* Look for lost data. */
480 torexmt
= tp
->rexmt_high
;
482 if (lastblock
!= NULL
) {
483 if (SEQ_LT(torexmt
, lastblock
->sblk_end
) &&
484 scb_islost(scb
, torexmt
)) {
486 *nextrexmt
= torexmt
;
487 /* If the left-hand edge has been SACKed, pull it in. */
488 if (sack_block_lookup(scb
, torexmt
+ tp
->t_maxseg
, &sb
))
489 *plen
= sb
->sblk_start
- torexmt
;
491 *plen
= tp
->t_maxseg
;
496 /* See if unsent data available within send window. */
497 off
= tp
->snd_max
- tp
->snd_una
;
498 len
= (long) ulmin(so
->so_snd
.ssb_cc
, tp
->snd_wnd
) - off
;
500 *nextrexmt
= tp
->snd_max
; /* Send new data. */
501 *plen
= tp
->t_maxseg
;
505 /* We're less certain this data has been lost. */
506 if (lastblock
== NULL
|| SEQ_LT(torexmt
, lastblock
->sblk_end
))
513 * Return the next sequence number higher than "*prexmt" that has
517 tcp_sack_skip_sacked(struct scoreboard
*scb
, tcp_seq
*prexmt
)
519 struct sackblock
*sb
;
521 /* skip SACKed data */
522 if (sack_block_lookup(scb
, *prexmt
, &sb
))
523 *prexmt
= sb
->sblk_end
;
528 tcp_sack_save_scoreboard(struct scoreboard
*scb
)
530 struct scoreboard
*scb
= &tp
->scb
;
532 scb
->sackblocks_prev
= scb
->sackblocks
;
533 TAILQ_INIT(&scb
->sackblocks
);
537 tcp_sack_revert_scoreboard(struct scoreboard
*scb
, tcp_seq snd_una
,
540 struct sackblock
*sb
;
542 scb
->sackblocks
= scb
->sackblocks_prev
;
544 TAILQ_FOREACH(sb
, &scb
->sackblocks
, sblk_list
)
546 tcp_sack_ack_blocks(scb
, snd_una
);
547 scb
->lastfound
= NULL
;
551 #ifdef DEBUG_SACK_HISTORY
553 tcp_sack_dump_history(char *msg
, struct tcpcb
*tp
)
558 /* only need a couple of these to debug most problems */
562 kprintf("%s:\tnsackhistory %d: ", msg
, tp
->nsackhistory
);
563 for (i
= 0; i
< tp
->nsackhistory
; ++i
)
564 kprintf("[%u, %u) ", tp
->sackhistory
[i
].rblk_start
,
565 tp
->sackhistory
[i
].rblk_end
);
570 tcp_sack_dump_history(char *msg
, struct tcpcb
*tp
)
576 * Remove old SACK blocks from the SACK history that have already been ACKed.
579 tcp_sack_ack_history(struct tcpcb
*tp
)
581 int i
, nblocks
, openslot
;
583 tcp_sack_dump_history("before tcp_sack_ack_history", tp
);
584 nblocks
= tp
->nsackhistory
;
585 for (i
= openslot
= 0; i
< nblocks
; ++i
) {
586 if (SEQ_LEQ(tp
->sackhistory
[i
].rblk_end
, tp
->rcv_nxt
)) {
590 if (SEQ_LT(tp
->sackhistory
[i
].rblk_start
, tp
->rcv_nxt
))
591 tp
->sackhistory
[i
].rblk_start
= tp
->rcv_nxt
;
595 tp
->sackhistory
[openslot
++] = tp
->sackhistory
[i
];
597 tcp_sack_dump_history("after tcp_sack_ack_history", tp
);
598 KASSERT(openslot
== tp
->nsackhistory
,
599 ("tcp_sack_ack_history miscounted: %d != %d",
600 openslot
, tp
->nsackhistory
));
604 * Add or merge newblock into reported history.
605 * Also remove or update SACK blocks that will be acked.
608 tcp_sack_update_reported_history(struct tcpcb
*tp
, tcp_seq start
, tcp_seq end
)
610 struct raw_sackblock copy
[MAX_SACK_REPORT_BLOCKS
];
613 tcp_sack_dump_history("before tcp_sack_update_reported_history", tp
);
617 * 1) newblock == oldblock
618 * 2) oldblock contains newblock
619 * 3) newblock contains oldblock
620 * 4) tail of oldblock overlaps or abuts start of newblock
621 * 5) tail of newblock overlaps or abuts head of oldblock
623 for (i
= cindex
= 0; i
< tp
->nsackhistory
; ++i
) {
624 struct raw_sackblock
*oldblock
= &tp
->sackhistory
[i
];
625 tcp_seq old_start
= oldblock
->rblk_start
;
626 tcp_seq old_end
= oldblock
->rblk_end
;
628 if (SEQ_LT(end
, old_start
) || SEQ_GT(start
, old_end
)) {
629 /* Case 0: no overlap. Copy old block. */
630 copy
[cindex
++] = *oldblock
;
634 if (SEQ_GEQ(start
, old_start
) && SEQ_LEQ(end
, old_end
)) {
635 /* Cases 1 & 2. Move block to front of history. */
640 /* no need to check rest of blocks */
641 for (j
= i
+ 1; j
< tp
->nsackhistory
; ++j
)
642 copy
[cindex
++] = tp
->sackhistory
[j
];
646 if (SEQ_GEQ(old_end
, start
) && SEQ_LT(old_start
, start
)) {
647 /* Case 4: extend start of new block. */
649 } else if (SEQ_GEQ(end
, old_start
) && SEQ_GT(old_end
, end
)) {
650 /* Case 5: extend end of new block */
653 /* Case 3. Delete old block by not copying it. */
654 KASSERT(SEQ_LEQ(start
, old_start
) &&
655 SEQ_GEQ(end
, old_end
),
656 ("bad logic: old [%u, %u), new [%u, %u)",
657 old_start
, old_end
, start
, end
));
661 /* insert new block */
662 tp
->sackhistory
[0].rblk_start
= start
;
663 tp
->sackhistory
[0].rblk_end
= end
;
664 cindex
= min(cindex
, MAX_SACK_REPORT_BLOCKS
- 1);
665 for (i
= 0; i
< cindex
; ++i
)
666 tp
->sackhistory
[i
+ 1] = copy
[i
];
667 tp
->nsackhistory
= cindex
+ 1;
668 tcp_sack_dump_history("after tcp_sack_update_reported_history", tp
);
672 * Fill in SACK report to return to data sender.
675 tcp_sack_fill_report(struct tcpcb
*tp
, u_char
*opt
, u_int
*plen
)
677 u_int optlen
= *plen
;
678 uint32_t *lp
= (uint32_t *)(opt
+ optlen
);
680 tcp_seq hstart
= tp
->rcv_nxt
, hend
;
683 KASSERT(TCP_MAXOLEN
- optlen
>=
684 TCPOLEN_SACK_ALIGNED
+ TCPOLEN_SACK_BLOCK
,
685 ("no room for SACK header and one block: optlen %d", optlen
));
688 optlen
+= TCPOLEN_SACK_ALIGNED
;
690 tcp_sack_ack_history(tp
);
691 if (tp
->reportblk
.rblk_start
!= tp
->reportblk
.rblk_end
) {
692 *lp
++ = htonl(tp
->reportblk
.rblk_start
);
693 *lp
++ = htonl(tp
->reportblk
.rblk_end
);
694 optlen
+= TCPOLEN_SACK_BLOCK
;
695 hstart
= tp
->reportblk
.rblk_start
;
696 hend
= tp
->reportblk
.rblk_end
;
697 if (tp
->t_flags
& TF_ENCLOSESEG
) {
698 KASSERT(TCP_MAXOLEN
- optlen
>= TCPOLEN_SACK_BLOCK
,
699 ("no room for enclosing SACK block: oplen %d",
701 *lp
++ = htonl(tp
->encloseblk
.rblk_start
);
702 *lp
++ = htonl(tp
->encloseblk
.rblk_end
);
703 optlen
+= TCPOLEN_SACK_BLOCK
;
704 hstart
= tp
->encloseblk
.rblk_start
;
705 hend
= tp
->encloseblk
.rblk_end
;
707 if (SEQ_GT(hstart
, tp
->rcv_nxt
))
708 tcp_sack_update_reported_history(tp
, hstart
, hend
);
710 if (tcp_do_smartsack
&& (tp
->t_flags
& TF_SACKLEFT
)) {
711 /* Fill in from left! Walk re-assembly queue. */
714 q
= LIST_FIRST(&tp
->t_segq
);
716 TCP_MAXOLEN
- optlen
>= TCPOLEN_SACK_BLOCK
) {
717 *lp
++ = htonl(q
->tqe_th
->th_seq
);
718 *lp
++ = htonl(q
->tqe_th
->th_seq
+ q
->tqe_len
);
719 optlen
+= TCPOLEN_SACK_BLOCK
;
720 q
= LIST_NEXT(q
, tqe_q
);
725 /* Fill in SACK blocks from right side. */
726 while (n
< tp
->nsackhistory
&&
727 TCP_MAXOLEN
- optlen
>= TCPOLEN_SACK_BLOCK
) {
728 if (tp
->sackhistory
[n
].rblk_start
!= hstart
) {
729 *lp
++ = htonl(tp
->sackhistory
[n
].rblk_start
);
730 *lp
++ = htonl(tp
->sackhistory
[n
].rblk_end
);
731 optlen
+= TCPOLEN_SACK_BLOCK
;
736 tp
->reportblk
.rblk_start
= tp
->reportblk
.rblk_end
;
737 tp
->t_flags
&= ~(TF_DUPSEG
| TF_ENCLOSESEG
| TF_SACKLEFT
);
738 nblocks
= (lp
- olp
- 1) / 2;
739 *olp
= htonl(TCPOPT_SACK_ALIGNED
|
740 (TCPOLEN_SACK
+ nblocks
* TCPOLEN_SACK_BLOCK
));