Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 1 | /* SCTP kernel implementation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * (C) Copyright IBM Corp. 2001, 2004 |
| 3 | * Copyright (c) 1999-2000 Cisco, Inc. |
| 4 | * Copyright (c) 1999-2001 Motorola, Inc. |
| 5 | * Copyright (c) 2001 Intel Corp. |
| 6 | * |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 7 | * This file is part of the SCTP kernel implementation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * These functions manipulate sctp tsn mapping array. |
| 10 | * |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 11 | * This SCTP implementation is free software; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * you can redistribute it and/or modify it under the terms of |
| 13 | * the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2, or (at your option) |
| 15 | * any later version. |
| 16 | * |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 17 | * This SCTP implementation is distributed in the hope that it |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied |
| 19 | * ************************ |
| 20 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 21 | * See the GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with GNU CC; see the file COPYING. If not, write to |
| 25 | * the Free Software Foundation, 59 Temple Place - Suite 330, |
| 26 | * Boston, MA 02111-1307, USA. |
| 27 | * |
| 28 | * Please send any bug reports or fixes you make to the |
| 29 | * email address(es): |
| 30 | * lksctp developers <lksctp-developers@lists.sourceforge.net> |
| 31 | * |
| 32 | * Or submit a bug report through the following website: |
| 33 | * http://www.sf.net/projects/lksctp |
| 34 | * |
| 35 | * Written or modified by: |
| 36 | * La Monte H.P. Yarroll <piggy@acm.org> |
| 37 | * Jon Grimm <jgrimm@us.ibm.com> |
| 38 | * Karl Knutson <karl@athena.chicago.il.us> |
| 39 | * Sridhar Samudrala <sri@us.ibm.com> |
| 40 | * |
| 41 | * Any bugs reported given to us we will try to fix... any fixes shared will |
| 42 | * be incorporated into the next SCTP release. |
| 43 | */ |
| 44 | |
| 45 | #include <linux/types.h> |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 46 | #include <linux/bitmap.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <net/sctp/sctp.h> |
| 48 | #include <net/sctp/sm.h> |
| 49 | |
| 50 | static void sctp_tsnmap_update(struct sctp_tsnmap *map); |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 51 | static void sctp_tsnmap_find_gap_ack(unsigned long *map, __u16 off, |
| 52 | __u16 len, __u16 *start, __u16 *end); |
| 53 | static int sctp_tsnmap_grow(struct sctp_tsnmap *map, u16 gap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | /* Initialize a block of memory as a tsnmap. */ |
| 56 | struct sctp_tsnmap *sctp_tsnmap_init(struct sctp_tsnmap *map, __u16 len, |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 57 | __u32 initial_tsn, gfp_t gfp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 59 | if (!map->tsn_map) { |
| 60 | map->tsn_map = kzalloc(len>>3, gfp); |
| 61 | if (map->tsn_map == NULL) |
| 62 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 64 | map->len = len; |
| 65 | } else { |
| 66 | bitmap_zero(map->tsn_map, map->len); |
| 67 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | /* Keep track of TSNs represented by tsn_map. */ |
| 70 | map->base_tsn = initial_tsn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | map->cumulative_tsn_ack_point = initial_tsn - 1; |
| 72 | map->max_tsn_seen = map->cumulative_tsn_ack_point; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | map->num_dup_tsns = 0; |
| 74 | |
| 75 | return map; |
| 76 | } |
| 77 | |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 78 | void sctp_tsnmap_free(struct sctp_tsnmap *map) |
| 79 | { |
| 80 | map->len = 0; |
| 81 | kfree(map->tsn_map); |
| 82 | } |
| 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | /* Test the tracking state of this TSN. |
| 85 | * Returns: |
| 86 | * 0 if the TSN has not yet been seen |
| 87 | * >0 if the TSN has been seen (duplicate) |
| 88 | * <0 if the TSN is invalid (too large to track) |
| 89 | */ |
| 90 | int sctp_tsnmap_check(const struct sctp_tsnmap *map, __u32 tsn) |
| 91 | { |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 92 | u32 gap; |
| 93 | |
| 94 | /* Check to see if this is an old TSN */ |
| 95 | if (TSN_lte(tsn, map->cumulative_tsn_ack_point)) |
| 96 | return 1; |
| 97 | |
| 98 | /* Verify that we can hold this TSN and that it will not |
| 99 | * overlfow our map |
| 100 | */ |
| 101 | if (!TSN_lt(tsn, map->base_tsn + SCTP_TSN_MAP_SIZE)) |
| 102 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | /* Calculate the index into the mapping arrays. */ |
| 105 | gap = tsn - map->base_tsn; |
| 106 | |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 107 | /* Check to see if TSN has already been recorded. */ |
| 108 | if (gap < map->len && test_bit(gap, map->tsn_map)) |
| 109 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | else |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 111 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | |
| 115 | /* Mark this TSN as seen. */ |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 116 | int sctp_tsnmap_mark(struct sctp_tsnmap *map, __u32 tsn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | { |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 118 | u16 gap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | if (TSN_lt(tsn, map->base_tsn)) |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 121 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | gap = tsn - map->base_tsn; |
| 124 | |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 125 | if (gap >= map->len && !sctp_tsnmap_grow(map, gap)) |
| 126 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 128 | if (!sctp_tsnmap_has_gap(map) && gap == 0) { |
| 129 | /* In this case the map has no gaps and the tsn we are |
| 130 | * recording is the next expected tsn. We don't touch |
| 131 | * the map but simply bump the values. |
| 132 | */ |
| 133 | map->max_tsn_seen++; |
| 134 | map->cumulative_tsn_ack_point++; |
| 135 | map->base_tsn++; |
| 136 | } else { |
| 137 | /* Either we already have a gap, or about to record a gap, so |
| 138 | * have work to do. |
| 139 | * |
| 140 | * Bump the max. |
| 141 | */ |
| 142 | if (TSN_lt(map->max_tsn_seen, tsn)) |
| 143 | map->max_tsn_seen = tsn; |
| 144 | |
| 145 | /* Mark the TSN as received. */ |
| 146 | set_bit(gap, map->tsn_map); |
| 147 | |
| 148 | /* Go fixup any internal TSN mapping variables including |
| 149 | * cumulative_tsn_ack_point. |
| 150 | */ |
| 151 | sctp_tsnmap_update(map); |
| 152 | } |
| 153 | |
| 154 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | |
| 158 | /* Initialize a Gap Ack Block iterator from memory being provided. */ |
| 159 | SCTP_STATIC void sctp_tsnmap_iter_init(const struct sctp_tsnmap *map, |
| 160 | struct sctp_tsnmap_iter *iter) |
| 161 | { |
| 162 | /* Only start looking one past the Cumulative TSN Ack Point. */ |
| 163 | iter->start = map->cumulative_tsn_ack_point + 1; |
| 164 | } |
| 165 | |
| 166 | /* Get the next Gap Ack Blocks. Returns 0 if there was not another block |
| 167 | * to get. |
| 168 | */ |
| 169 | SCTP_STATIC int sctp_tsnmap_next_gap_ack(const struct sctp_tsnmap *map, |
| 170 | struct sctp_tsnmap_iter *iter, |
| 171 | __u16 *start, __u16 *end) |
| 172 | { |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 173 | int ended = 0; |
| 174 | __u16 start_ = 0, end_ = 0, offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
| 176 | /* If there are no more gap acks possible, get out fast. */ |
| 177 | if (TSN_lte(map->max_tsn_seen, iter->start)) |
| 178 | return 0; |
| 179 | |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 180 | offset = iter->start - map->base_tsn; |
| 181 | sctp_tsnmap_find_gap_ack(map->tsn_map, offset, map->len, |
| 182 | &start_, &end_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 184 | /* The Gap Ack Block happens to end at the end of the map. */ |
| 185 | if (start_ && !end_) |
| 186 | end_ = map->len - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 188 | /* If we found a Gap Ack Block, return the start and end and |
| 189 | * bump the iterator forward. |
| 190 | */ |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 191 | if (end_) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | /* Fix up the start and end based on the |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 193 | * Cumulative TSN Ack which is always 1 behind base. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | */ |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 195 | *start = start_ + 1; |
| 196 | *end = end_ + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | /* Move the iterator forward. */ |
| 199 | iter->start = map->cumulative_tsn_ack_point + *end + 1; |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 200 | ended = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | return ended; |
| 204 | } |
| 205 | |
| 206 | /* Mark this and any lower TSN as seen. */ |
| 207 | void sctp_tsnmap_skip(struct sctp_tsnmap *map, __u32 tsn) |
| 208 | { |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 209 | u32 gap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | if (TSN_lt(tsn, map->base_tsn)) |
| 212 | return; |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 213 | if (!TSN_lt(tsn, map->base_tsn + SCTP_TSN_MAP_SIZE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | return; |
| 215 | |
| 216 | /* Bump the max. */ |
| 217 | if (TSN_lt(map->max_tsn_seen, tsn)) |
| 218 | map->max_tsn_seen = tsn; |
| 219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | gap = tsn - map->base_tsn + 1; |
| 221 | |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 222 | map->base_tsn += gap; |
| 223 | map->cumulative_tsn_ack_point += gap; |
| 224 | if (gap >= map->len) { |
| 225 | /* If our gap is larger then the map size, just |
| 226 | * zero out the map. |
| 227 | */ |
| 228 | bitmap_zero(map->tsn_map, map->len); |
| 229 | } else { |
| 230 | /* If the gap is smaller then the map size, |
| 231 | * shift the map by 'gap' bits and update further. |
| 232 | */ |
| 233 | bitmap_shift_right(map->tsn_map, map->tsn_map, gap, map->len); |
| 234 | sctp_tsnmap_update(map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | /******************************************************************** |
| 239 | * 2nd Level Abstractions |
| 240 | ********************************************************************/ |
| 241 | |
| 242 | /* This private helper function updates the tsnmap buffers and |
| 243 | * the Cumulative TSN Ack Point. |
| 244 | */ |
| 245 | static void sctp_tsnmap_update(struct sctp_tsnmap *map) |
| 246 | { |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 247 | u16 len; |
| 248 | unsigned long zero_bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 251 | len = map->max_tsn_seen - map->cumulative_tsn_ack_point; |
| 252 | zero_bit = find_first_zero_bit(map->tsn_map, len); |
| 253 | if (!zero_bit) |
| 254 | return; /* The first 0-bit is bit 0. nothing to do */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 256 | map->base_tsn += zero_bit; |
| 257 | map->cumulative_tsn_ack_point += zero_bit; |
| 258 | |
| 259 | bitmap_shift_right(map->tsn_map, map->tsn_map, zero_bit, map->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | /* How many data chunks are we missing from our peer? |
| 263 | */ |
| 264 | __u16 sctp_tsnmap_pending(struct sctp_tsnmap *map) |
| 265 | { |
| 266 | __u32 cum_tsn = map->cumulative_tsn_ack_point; |
| 267 | __u32 max_tsn = map->max_tsn_seen; |
| 268 | __u32 base_tsn = map->base_tsn; |
| 269 | __u16 pending_data; |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 270 | u32 gap, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
| 272 | pending_data = max_tsn - cum_tsn; |
| 273 | gap = max_tsn - base_tsn; |
| 274 | |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 275 | if (gap == 0 || gap >= map->len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | goto out; |
| 277 | |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 278 | for (i = 0; i < gap+1; i++) { |
| 279 | if (test_bit(i, map->tsn_map)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | pending_data--; |
| 281 | } |
| 282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | out: |
| 284 | return pending_data; |
| 285 | } |
| 286 | |
| 287 | /* This is a private helper for finding Gap Ack Blocks. It searches a |
| 288 | * single array for the start and end of a Gap Ack Block. |
| 289 | * |
| 290 | * The flags "started" and "ended" tell is if we found the beginning |
| 291 | * or (respectively) the end of a Gap Ack Block. |
| 292 | */ |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 293 | static void sctp_tsnmap_find_gap_ack(unsigned long *map, __u16 off, |
| 294 | __u16 len, __u16 *start, __u16 *end) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | { |
| 296 | int i = off; |
| 297 | |
| 298 | /* Look through the entire array, but break out |
| 299 | * early if we have found the end of the Gap Ack Block. |
| 300 | */ |
| 301 | |
| 302 | /* Also, stop looking past the maximum TSN seen. */ |
| 303 | |
| 304 | /* Look for the start. */ |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 305 | i = find_next_bit(map, len, off); |
| 306 | if (i < len) |
| 307 | *start = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | /* Look for the end. */ |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 310 | if (*start) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | /* We have found the start, let's find the |
| 312 | * end. If we find the end, break out. |
| 313 | */ |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 314 | i = find_next_zero_bit(map, len, i); |
| 315 | if (i < len) |
| 316 | *end = i - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
| 320 | /* Renege that we have seen a TSN. */ |
| 321 | void sctp_tsnmap_renege(struct sctp_tsnmap *map, __u32 tsn) |
| 322 | { |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 323 | u32 gap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
| 325 | if (TSN_lt(tsn, map->base_tsn)) |
| 326 | return; |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 327 | /* Assert: TSN is in range. */ |
| 328 | if (!TSN_lt(tsn, map->base_tsn + map->len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | return; |
| 330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | gap = tsn - map->base_tsn; |
| 332 | |
| 333 | /* Pretend we never saw the TSN. */ |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 334 | clear_bit(gap, map->tsn_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | /* How many gap ack blocks do we have recorded? */ |
| 338 | __u16 sctp_tsnmap_num_gabs(struct sctp_tsnmap *map) |
| 339 | { |
| 340 | struct sctp_tsnmap_iter iter; |
| 341 | int gabs = 0; |
| 342 | |
| 343 | /* Refresh the gap ack information. */ |
| 344 | if (sctp_tsnmap_has_gap(map)) { |
Al Viro | 9f81bcd | 2006-11-20 17:26:34 -0800 | [diff] [blame] | 345 | __u16 start, end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | sctp_tsnmap_iter_init(map, &iter); |
| 347 | while (sctp_tsnmap_next_gap_ack(map, &iter, |
Al Viro | 9f81bcd | 2006-11-20 17:26:34 -0800 | [diff] [blame] | 348 | &start, |
| 349 | &end)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
Al Viro | 9f81bcd | 2006-11-20 17:26:34 -0800 | [diff] [blame] | 351 | map->gabs[gabs].start = htons(start); |
| 352 | map->gabs[gabs].end = htons(end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | gabs++; |
| 354 | if (gabs >= SCTP_MAX_GABS) |
| 355 | break; |
| 356 | } |
| 357 | } |
| 358 | return gabs; |
| 359 | } |
Vlad Yasevich | 8e1ee18 | 2008-10-08 14:18:39 -0700 | [diff] [blame^] | 360 | |
| 361 | static int sctp_tsnmap_grow(struct sctp_tsnmap *map, u16 gap) |
| 362 | { |
| 363 | unsigned long *new; |
| 364 | unsigned long inc; |
| 365 | u16 len; |
| 366 | |
| 367 | if (gap >= SCTP_TSN_MAP_SIZE) |
| 368 | return 0; |
| 369 | |
| 370 | inc = ALIGN((gap - map->len),BITS_PER_LONG) + SCTP_TSN_MAP_INCREMENT; |
| 371 | len = min_t(u16, map->len + inc, SCTP_TSN_MAP_SIZE); |
| 372 | |
| 373 | new = kzalloc(len>>3, GFP_ATOMIC); |
| 374 | if (!new) |
| 375 | return 0; |
| 376 | |
| 377 | bitmap_copy(new, map->tsn_map, map->max_tsn_seen - map->base_tsn); |
| 378 | kfree(map->tsn_map); |
| 379 | map->tsn_map = new; |
| 380 | map->len = len; |
| 381 | |
| 382 | return 1; |
| 383 | } |