/* Test the tracking state of this TSN. *Returns: *0iftheTSNhasnotyetbeenseen *>0iftheTSNhasbeenseen(duplicate) *<0iftheTSNisinvalid(toolargetotrack)
*/ int sctp_tsnmap_check(conststruct sctp_tsnmap *map, __u32 tsn)
{
u32 gap;
/* Check to see if this is an old TSN */ if (TSN_lte(tsn, map->cumulative_tsn_ack_point)) return1;
/* Verify that we can hold this TSN and that it will not *overflowourmap
*/ if (!TSN_lt(tsn, map->base_tsn + SCTP_TSN_MAP_SIZE)) return -1;
/* Calculate the index into the mapping arrays. */
gap = tsn - map->base_tsn;
/* Check to see if TSN has already been recorded. */ if (gap < map->len && test_bit(gap, map->tsn_map)) return1; else return0;
}
/* Mark this TSN as seen. */ int sctp_tsnmap_mark(struct sctp_tsnmap *map, __u32 tsn, struct sctp_transport *trans)
{
u16 gap;
if (TSN_lt(tsn, map->base_tsn)) return0;
gap = tsn - map->base_tsn;
if (gap >= map->len && !sctp_tsnmap_grow(map, gap + 1)) return -ENOMEM;
if (!sctp_tsnmap_has_gap(map) && gap == 0) { /* In this case the map has no gaps and the tsn we are *recordingisthenextexpectedtsn.Wedon'ttouch *themapbutsimplybumpthevalues.
*/
map->max_tsn_seen++;
map->cumulative_tsn_ack_point++; if (trans)
trans->sack_generation =
trans->asoc->peer.sack_generation;
map->base_tsn++;
} else { /* Either we already have a gap, or about to record a gap, so *haveworktodo. * *Bumpthemax.
*/ if (TSN_lt(map->max_tsn_seen, tsn))
map->max_tsn_seen = tsn;
/* Mark the TSN as received. */
set_bit(gap, map->tsn_map);
/* Go fixup any internal TSN mapping variables including *cumulative_tsn_ack_point.
*/
sctp_tsnmap_update(map);
}
return0;
}
/* Initialize a Gap Ack Block iterator from memory being provided. */ staticvoid sctp_tsnmap_iter_init(conststruct sctp_tsnmap *map, struct sctp_tsnmap_iter *iter)
{ /* Only start looking one past the Cumulative TSN Ack Point. */
iter->start = map->cumulative_tsn_ack_point + 1;
}
/* Get the next Gap Ack Blocks. Returns 0 if there was not another block *toget.
*/ staticint sctp_tsnmap_next_gap_ack(conststruct sctp_tsnmap *map, struct sctp_tsnmap_iter *iter,
__u16 *start, __u16 *end)
{ int ended = 0;
__u16 start_ = 0, end_ = 0, offset;
/* If there are no more gap acks possible, get out fast. */ if (TSN_lte(map->max_tsn_seen, iter->start)) return0;
/* The Gap Ack Block happens to end at the end of the map. */ if (start_ && !end_)
end_ = map->len - 1;
/* If we found a Gap Ack Block, return the start and end and *bumptheiteratorforward.
*/ if (end_) { /* Fix up the start and end based on the *CumulativeTSNAckwhichisalways1behindbase.
*/
*start = start_ + 1;
*end = end_ + 1;
/* Mark this and any lower TSN as seen. */ void sctp_tsnmap_skip(struct sctp_tsnmap *map, __u32 tsn)
{
u32 gap;
if (TSN_lt(tsn, map->base_tsn)) return; if (!TSN_lt(tsn, map->base_tsn + SCTP_TSN_MAP_SIZE)) return;
/* Bump the max. */ if (TSN_lt(map->max_tsn_seen, tsn))
map->max_tsn_seen = tsn;
gap = tsn - map->base_tsn + 1;
map->base_tsn += gap;
map->cumulative_tsn_ack_point += gap; if (gap >= map->len) { /* If our gap is larger then the map size, just *zerooutthemap.
*/
bitmap_zero(map->tsn_map, map->len);
} else { /* If the gap is smaller than the map size, *shiftthemapby'gap'bitsandupdatefurther.
*/
bitmap_shift_right(map->tsn_map, map->tsn_map, gap, map->len);
sctp_tsnmap_update(map);
}
}
/* This private helper function updates the tsnmap buffers and *theCumulativeTSNAckPoint.
*/ staticvoid sctp_tsnmap_update(struct sctp_tsnmap *map)
{
u16 len; unsignedlong zero_bit;
len = map->max_tsn_seen - map->cumulative_tsn_ack_point;
zero_bit = find_first_zero_bit(map->tsn_map, len); if (!zero_bit) return; /* The first 0-bit is bit 0. nothing to do */
/* How many data chunks are we missing from our peer?
*/
__u16 sctp_tsnmap_pending(struct sctp_tsnmap *map)
{
__u32 cum_tsn = map->cumulative_tsn_ack_point;
__u32 max_tsn = map->max_tsn_seen;
__u32 base_tsn = map->base_tsn;
__u16 pending_data;
u32 gap;
pending_data = max_tsn - cum_tsn;
gap = max_tsn - base_tsn;
if (gap == 0 || gap >= map->len) goto out;
pending_data -= bitmap_weight(map->tsn_map, gap + 1);
out: return pending_data;
}
/* This is a private helper for finding Gap Ack Blocks. It searches a *singlearrayforthestartandendofaGapAckBlock. * *Theflags"started"and"ended"tellisifwefoundthebeginning *or(respectively)theendofaGapAckBlock.
*/ staticvoid sctp_tsnmap_find_gap_ack(unsignedlong *map, __u16 off,
__u16 len, __u16 *start, __u16 *end)
{ int i = off;
/* Look through the entire array, but break out *earlyifwehavefoundtheendoftheGapAckBlock.
*/
/* Also, stop looking past the maximum TSN seen. */
/* Look for the start. */
i = find_next_bit(map, len, off); if (i < len)
*start = i;
/* Look for the end. */ if (*start) { /* We have found the start, let's find the *end.Ifwefindtheend,breakout.
*/
i = find_next_zero_bit(map, len, i); if (i < len)
*end = i - 1;
}
}
/* Renege that we have seen a TSN. */ void sctp_tsnmap_renege(struct sctp_tsnmap *map, __u32 tsn)
{
u32 gap;
if (TSN_lt(tsn, map->base_tsn)) return; /* Assert: TSN is in range. */ if (!TSN_lt(tsn, map->base_tsn + map->len)) return;
gap = tsn - map->base_tsn;
/* Pretend we never saw the TSN. */
clear_bit(gap, map->tsn_map);
}
/* How many gap ack blocks do we have recorded? */
__u16 sctp_tsnmap_num_gabs(struct sctp_tsnmap *map, struct sctp_gap_ack_block *gabs)
{ struct sctp_tsnmap_iter iter; int ngaps = 0;
/* Refresh the gap ack information. */ if (sctp_tsnmap_has_gap(map)) {
__u16 start = 0, end = 0;
sctp_tsnmap_iter_init(map, &iter); while (sctp_tsnmap_next_gap_ack(map, &iter,
&start,
&end)) {
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.