Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 1 | /* SCTP kernel implementation |
| 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 | * |
| 7 | * This file is part of the SCTP kernel implementation |
| 8 | * |
| 9 | * These functions manipulate sctp tsn mapping array. |
| 10 | * |
| 11 | * This SCTP implementation is free software; |
| 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 | * |
| 17 | * This SCTP implementation is distributed in the hope that it |
| 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, see |
| 25 | * <http://www.gnu.org/licenses/>. |
| 26 | * |
| 27 | * Please send any bug reports or fixes you make to the |
| 28 | * email address(es): |
| 29 | * lksctp developers <linux-sctp@vger.kernel.org> |
| 30 | * |
| 31 | * Written or modified by: |
| 32 | * Xin Long <lucien.xin@gmail.com> |
| 33 | */ |
| 34 | |
| 35 | #include <net/sctp/sctp.h> |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 36 | #include <net/sctp/sm.h> |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 37 | |
Xin Long | 3dbcc10 | 2017-03-30 01:00:53 +0800 | [diff] [blame] | 38 | int sctp_stream_new(struct sctp_association *asoc, gfp_t gfp) |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 39 | { |
| 40 | struct sctp_stream *stream; |
| 41 | int i; |
| 42 | |
| 43 | stream = kzalloc(sizeof(*stream), gfp); |
| 44 | if (!stream) |
Xin Long | 3dbcc10 | 2017-03-30 01:00:53 +0800 | [diff] [blame] | 45 | return -ENOMEM; |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 46 | |
Xin Long | 3dbcc10 | 2017-03-30 01:00:53 +0800 | [diff] [blame] | 47 | stream->outcnt = asoc->c.sinit_num_ostreams; |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 48 | stream->out = kcalloc(stream->outcnt, sizeof(*stream->out), gfp); |
| 49 | if (!stream->out) { |
| 50 | kfree(stream); |
Xin Long | 3dbcc10 | 2017-03-30 01:00:53 +0800 | [diff] [blame] | 51 | return -ENOMEM; |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 52 | } |
| 53 | for (i = 0; i < stream->outcnt; i++) |
| 54 | stream->out[i].state = SCTP_STREAM_OPEN; |
| 55 | |
Xin Long | 3dbcc10 | 2017-03-30 01:00:53 +0800 | [diff] [blame] | 56 | asoc->stream = stream; |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | int sctp_stream_init(struct sctp_association *asoc, gfp_t gfp) |
| 62 | { |
| 63 | struct sctp_stream *stream = asoc->stream; |
| 64 | int i; |
| 65 | |
| 66 | /* Initial stream->out size may be very big, so free it and alloc |
| 67 | * a new one with new outcnt to save memory. |
| 68 | */ |
| 69 | kfree(stream->out); |
| 70 | stream->outcnt = asoc->c.sinit_num_ostreams; |
| 71 | stream->out = kcalloc(stream->outcnt, sizeof(*stream->out), gfp); |
| 72 | if (!stream->out) |
| 73 | goto nomem; |
| 74 | |
| 75 | for (i = 0; i < stream->outcnt; i++) |
| 76 | stream->out[i].state = SCTP_STREAM_OPEN; |
| 77 | |
| 78 | stream->incnt = asoc->c.sinit_max_instreams; |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 79 | stream->in = kcalloc(stream->incnt, sizeof(*stream->in), gfp); |
| 80 | if (!stream->in) { |
| 81 | kfree(stream->out); |
Xin Long | 3dbcc10 | 2017-03-30 01:00:53 +0800 | [diff] [blame] | 82 | goto nomem; |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 83 | } |
| 84 | |
Xin Long | 3dbcc10 | 2017-03-30 01:00:53 +0800 | [diff] [blame] | 85 | return 0; |
| 86 | |
| 87 | nomem: |
| 88 | asoc->stream = NULL; |
| 89 | kfree(stream); |
| 90 | |
| 91 | return -ENOMEM; |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | void sctp_stream_free(struct sctp_stream *stream) |
| 95 | { |
| 96 | if (unlikely(!stream)) |
| 97 | return; |
| 98 | |
| 99 | kfree(stream->out); |
| 100 | kfree(stream->in); |
| 101 | kfree(stream); |
| 102 | } |
| 103 | |
| 104 | void sctp_stream_clear(struct sctp_stream *stream) |
| 105 | { |
| 106 | int i; |
| 107 | |
| 108 | for (i = 0; i < stream->outcnt; i++) |
| 109 | stream->out[i].ssn = 0; |
| 110 | |
| 111 | for (i = 0; i < stream->incnt; i++) |
| 112 | stream->in[i].ssn = 0; |
| 113 | } |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 114 | |
| 115 | static int sctp_send_reconf(struct sctp_association *asoc, |
| 116 | struct sctp_chunk *chunk) |
| 117 | { |
| 118 | struct net *net = sock_net(asoc->base.sk); |
| 119 | int retval = 0; |
| 120 | |
| 121 | retval = sctp_primitive_RECONF(net, asoc, chunk); |
| 122 | if (retval) |
| 123 | sctp_chunk_free(chunk); |
| 124 | |
| 125 | return retval; |
| 126 | } |
| 127 | |
| 128 | int sctp_send_reset_streams(struct sctp_association *asoc, |
| 129 | struct sctp_reset_streams *params) |
| 130 | { |
| 131 | struct sctp_stream *stream = asoc->stream; |
| 132 | __u16 i, str_nums, *str_list; |
| 133 | struct sctp_chunk *chunk; |
| 134 | int retval = -EINVAL; |
| 135 | bool out, in; |
| 136 | |
| 137 | if (!asoc->peer.reconf_capable || |
| 138 | !(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ)) { |
| 139 | retval = -ENOPROTOOPT; |
| 140 | goto out; |
| 141 | } |
| 142 | |
| 143 | if (asoc->strreset_outstanding) { |
| 144 | retval = -EINPROGRESS; |
| 145 | goto out; |
| 146 | } |
| 147 | |
| 148 | out = params->srs_flags & SCTP_STREAM_RESET_OUTGOING; |
| 149 | in = params->srs_flags & SCTP_STREAM_RESET_INCOMING; |
| 150 | if (!out && !in) |
| 151 | goto out; |
| 152 | |
| 153 | str_nums = params->srs_number_streams; |
| 154 | str_list = params->srs_stream_list; |
| 155 | if (out && str_nums) |
| 156 | for (i = 0; i < str_nums; i++) |
| 157 | if (str_list[i] >= stream->outcnt) |
| 158 | goto out; |
| 159 | |
| 160 | if (in && str_nums) |
| 161 | for (i = 0; i < str_nums; i++) |
| 162 | if (str_list[i] >= stream->incnt) |
| 163 | goto out; |
| 164 | |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 165 | for (i = 0; i < str_nums; i++) |
| 166 | str_list[i] = htons(str_list[i]); |
| 167 | |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 168 | chunk = sctp_make_strreset_req(asoc, str_nums, str_list, out, in); |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 169 | |
| 170 | for (i = 0; i < str_nums; i++) |
| 171 | str_list[i] = ntohs(str_list[i]); |
| 172 | |
Xin Long | 119aecb | 2017-02-09 01:18:16 +0800 | [diff] [blame] | 173 | if (!chunk) { |
| 174 | retval = -ENOMEM; |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 175 | goto out; |
Xin Long | 119aecb | 2017-02-09 01:18:16 +0800 | [diff] [blame] | 176 | } |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 177 | |
| 178 | if (out) { |
| 179 | if (str_nums) |
| 180 | for (i = 0; i < str_nums; i++) |
| 181 | stream->out[str_list[i]].state = |
| 182 | SCTP_STREAM_CLOSED; |
| 183 | else |
| 184 | for (i = 0; i < stream->outcnt; i++) |
| 185 | stream->out[i].state = SCTP_STREAM_CLOSED; |
| 186 | } |
| 187 | |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 188 | asoc->strreset_chunk = chunk; |
| 189 | sctp_chunk_hold(asoc->strreset_chunk); |
| 190 | |
| 191 | retval = sctp_send_reconf(asoc, chunk); |
| 192 | if (retval) { |
| 193 | sctp_chunk_put(asoc->strreset_chunk); |
| 194 | asoc->strreset_chunk = NULL; |
Xin Long | 119aecb | 2017-02-09 01:18:16 +0800 | [diff] [blame] | 195 | if (!out) |
| 196 | goto out; |
| 197 | |
| 198 | if (str_nums) |
| 199 | for (i = 0; i < str_nums; i++) |
| 200 | stream->out[str_list[i]].state = |
| 201 | SCTP_STREAM_OPEN; |
| 202 | else |
| 203 | for (i = 0; i < stream->outcnt; i++) |
| 204 | stream->out[i].state = SCTP_STREAM_OPEN; |
| 205 | |
| 206 | goto out; |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 207 | } |
| 208 | |
Xin Long | 119aecb | 2017-02-09 01:18:16 +0800 | [diff] [blame] | 209 | asoc->strreset_outstanding = out + in; |
| 210 | |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 211 | out: |
| 212 | return retval; |
| 213 | } |
Xin Long | a92ce1a | 2017-02-09 01:18:18 +0800 | [diff] [blame] | 214 | |
| 215 | int sctp_send_reset_assoc(struct sctp_association *asoc) |
| 216 | { |
| 217 | struct sctp_chunk *chunk = NULL; |
| 218 | int retval; |
| 219 | __u16 i; |
| 220 | |
| 221 | if (!asoc->peer.reconf_capable || |
| 222 | !(asoc->strreset_enable & SCTP_ENABLE_RESET_ASSOC_REQ)) |
| 223 | return -ENOPROTOOPT; |
| 224 | |
| 225 | if (asoc->strreset_outstanding) |
| 226 | return -EINPROGRESS; |
| 227 | |
| 228 | chunk = sctp_make_strreset_tsnreq(asoc); |
| 229 | if (!chunk) |
| 230 | return -ENOMEM; |
| 231 | |
| 232 | /* Block further xmit of data until this request is completed */ |
| 233 | for (i = 0; i < asoc->stream->outcnt; i++) |
| 234 | asoc->stream->out[i].state = SCTP_STREAM_CLOSED; |
| 235 | |
| 236 | asoc->strreset_chunk = chunk; |
| 237 | sctp_chunk_hold(asoc->strreset_chunk); |
| 238 | |
| 239 | retval = sctp_send_reconf(asoc, chunk); |
| 240 | if (retval) { |
| 241 | sctp_chunk_put(asoc->strreset_chunk); |
| 242 | asoc->strreset_chunk = NULL; |
| 243 | |
| 244 | for (i = 0; i < asoc->stream->outcnt; i++) |
| 245 | asoc->stream->out[i].state = SCTP_STREAM_OPEN; |
| 246 | |
| 247 | return retval; |
| 248 | } |
| 249 | |
| 250 | asoc->strreset_outstanding = 1; |
| 251 | |
| 252 | return 0; |
| 253 | } |
Xin Long | 242bd2d | 2017-02-09 01:18:20 +0800 | [diff] [blame] | 254 | |
| 255 | int sctp_send_add_streams(struct sctp_association *asoc, |
| 256 | struct sctp_add_streams *params) |
| 257 | { |
| 258 | struct sctp_stream *stream = asoc->stream; |
| 259 | struct sctp_chunk *chunk = NULL; |
| 260 | int retval = -ENOMEM; |
| 261 | __u32 outcnt, incnt; |
| 262 | __u16 out, in; |
| 263 | |
| 264 | if (!asoc->peer.reconf_capable || |
| 265 | !(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ)) { |
| 266 | retval = -ENOPROTOOPT; |
| 267 | goto out; |
| 268 | } |
| 269 | |
| 270 | if (asoc->strreset_outstanding) { |
| 271 | retval = -EINPROGRESS; |
| 272 | goto out; |
| 273 | } |
| 274 | |
| 275 | out = params->sas_outstrms; |
| 276 | in = params->sas_instrms; |
| 277 | outcnt = stream->outcnt + out; |
| 278 | incnt = stream->incnt + in; |
| 279 | if (outcnt > SCTP_MAX_STREAM || incnt > SCTP_MAX_STREAM || |
| 280 | (!out && !in)) { |
| 281 | retval = -EINVAL; |
| 282 | goto out; |
| 283 | } |
| 284 | |
| 285 | if (out) { |
| 286 | struct sctp_stream_out *streamout; |
| 287 | |
| 288 | streamout = krealloc(stream->out, outcnt * sizeof(*streamout), |
| 289 | GFP_KERNEL); |
| 290 | if (!streamout) |
| 291 | goto out; |
| 292 | |
| 293 | memset(streamout + stream->outcnt, 0, out * sizeof(*streamout)); |
| 294 | stream->out = streamout; |
| 295 | } |
| 296 | |
Xin Long | 242bd2d | 2017-02-09 01:18:20 +0800 | [diff] [blame] | 297 | chunk = sctp_make_strreset_addstrm(asoc, out, in); |
| 298 | if (!chunk) |
| 299 | goto out; |
| 300 | |
| 301 | asoc->strreset_chunk = chunk; |
| 302 | sctp_chunk_hold(asoc->strreset_chunk); |
| 303 | |
| 304 | retval = sctp_send_reconf(asoc, chunk); |
| 305 | if (retval) { |
| 306 | sctp_chunk_put(asoc->strreset_chunk); |
| 307 | asoc->strreset_chunk = NULL; |
| 308 | goto out; |
| 309 | } |
| 310 | |
| 311 | stream->incnt = incnt; |
| 312 | stream->outcnt = outcnt; |
| 313 | |
| 314 | asoc->strreset_outstanding = !!out + !!in; |
| 315 | |
| 316 | out: |
| 317 | return retval; |
| 318 | } |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 319 | |
| 320 | static sctp_paramhdr_t *sctp_chunk_lookup_strreset_param( |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 321 | struct sctp_association *asoc, __u32 resp_seq, |
| 322 | __be16 type) |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 323 | { |
| 324 | struct sctp_chunk *chunk = asoc->strreset_chunk; |
| 325 | struct sctp_reconf_chunk *hdr; |
| 326 | union sctp_params param; |
| 327 | |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 328 | if (!chunk) |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 329 | return NULL; |
| 330 | |
| 331 | hdr = (struct sctp_reconf_chunk *)chunk->chunk_hdr; |
| 332 | sctp_walk_params(param, hdr, params) { |
| 333 | /* sctp_strreset_tsnreq is actually the basic structure |
| 334 | * of all stream reconf params, so it's safe to use it |
| 335 | * to access request_seq. |
| 336 | */ |
| 337 | struct sctp_strreset_tsnreq *req = param.v; |
| 338 | |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 339 | if ((!resp_seq || req->request_seq == resp_seq) && |
| 340 | (!type || type == req->param_hdr.type)) |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 341 | return param.v; |
| 342 | } |
| 343 | |
| 344 | return NULL; |
| 345 | } |
| 346 | |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 347 | static void sctp_update_strreset_result(struct sctp_association *asoc, |
| 348 | __u32 result) |
| 349 | { |
| 350 | asoc->strreset_result[1] = asoc->strreset_result[0]; |
| 351 | asoc->strreset_result[0] = result; |
| 352 | } |
| 353 | |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 354 | struct sctp_chunk *sctp_process_strreset_outreq( |
| 355 | struct sctp_association *asoc, |
| 356 | union sctp_params param, |
| 357 | struct sctp_ulpevent **evp) |
| 358 | { |
| 359 | struct sctp_strreset_outreq *outreq = param.v; |
| 360 | struct sctp_stream *stream = asoc->stream; |
| 361 | __u16 i, nums, flags = 0, *str_p = NULL; |
| 362 | __u32 result = SCTP_STRRESET_DENIED; |
| 363 | __u32 request_seq; |
| 364 | |
| 365 | request_seq = ntohl(outreq->request_seq); |
| 366 | |
| 367 | if (ntohl(outreq->send_reset_at_tsn) > |
| 368 | sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map)) { |
| 369 | result = SCTP_STRRESET_IN_PROGRESS; |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 370 | goto err; |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 371 | } |
| 372 | |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 373 | if (TSN_lt(asoc->strreset_inseq, request_seq) || |
| 374 | TSN_lt(request_seq, asoc->strreset_inseq - 2)) { |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 375 | result = SCTP_STRRESET_ERR_BAD_SEQNO; |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 376 | goto err; |
| 377 | } else if (TSN_lt(request_seq, asoc->strreset_inseq)) { |
| 378 | i = asoc->strreset_inseq - request_seq - 1; |
| 379 | result = asoc->strreset_result[i]; |
| 380 | goto err; |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 381 | } |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 382 | asoc->strreset_inseq++; |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 383 | |
| 384 | /* Check strreset_enable after inseq inc, as sender cannot tell |
| 385 | * the peer doesn't enable strreset after receiving response with |
| 386 | * result denied, as well as to keep consistent with bsd. |
| 387 | */ |
| 388 | if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ)) |
| 389 | goto out; |
| 390 | |
| 391 | if (asoc->strreset_chunk) { |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 392 | if (!sctp_chunk_lookup_strreset_param( |
| 393 | asoc, outreq->response_seq, |
| 394 | SCTP_PARAM_RESET_IN_REQUEST)) { |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 395 | /* same process with outstanding isn't 0 */ |
| 396 | result = SCTP_STRRESET_ERR_IN_PROGRESS; |
| 397 | goto out; |
| 398 | } |
| 399 | |
| 400 | asoc->strreset_outstanding--; |
| 401 | asoc->strreset_outseq++; |
| 402 | |
| 403 | if (!asoc->strreset_outstanding) { |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 404 | struct sctp_transport *t; |
| 405 | |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 406 | t = asoc->strreset_chunk->transport; |
| 407 | if (del_timer(&t->reconf_timer)) |
| 408 | sctp_transport_put(t); |
| 409 | |
| 410 | sctp_chunk_put(asoc->strreset_chunk); |
| 411 | asoc->strreset_chunk = NULL; |
| 412 | } |
| 413 | |
| 414 | flags = SCTP_STREAM_RESET_INCOMING_SSN; |
| 415 | } |
| 416 | |
| 417 | nums = (ntohs(param.p->length) - sizeof(*outreq)) / 2; |
| 418 | if (nums) { |
| 419 | str_p = outreq->list_of_streams; |
| 420 | for (i = 0; i < nums; i++) { |
| 421 | if (ntohs(str_p[i]) >= stream->incnt) { |
| 422 | result = SCTP_STRRESET_ERR_WRONG_SSN; |
| 423 | goto out; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | for (i = 0; i < nums; i++) |
| 428 | stream->in[ntohs(str_p[i])].ssn = 0; |
| 429 | } else { |
| 430 | for (i = 0; i < stream->incnt; i++) |
| 431 | stream->in[i].ssn = 0; |
| 432 | } |
| 433 | |
| 434 | result = SCTP_STRRESET_PERFORMED; |
| 435 | |
| 436 | *evp = sctp_ulpevent_make_stream_reset_event(asoc, |
| 437 | flags | SCTP_STREAM_RESET_OUTGOING_SSN, nums, str_p, |
| 438 | GFP_ATOMIC); |
| 439 | |
| 440 | out: |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 441 | sctp_update_strreset_result(asoc, result); |
| 442 | err: |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 443 | return sctp_make_strreset_resp(asoc, result, request_seq); |
| 444 | } |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 445 | |
| 446 | struct sctp_chunk *sctp_process_strreset_inreq( |
| 447 | struct sctp_association *asoc, |
| 448 | union sctp_params param, |
| 449 | struct sctp_ulpevent **evp) |
| 450 | { |
| 451 | struct sctp_strreset_inreq *inreq = param.v; |
| 452 | struct sctp_stream *stream = asoc->stream; |
| 453 | __u32 result = SCTP_STRRESET_DENIED; |
| 454 | struct sctp_chunk *chunk = NULL; |
| 455 | __u16 i, nums, *str_p; |
| 456 | __u32 request_seq; |
| 457 | |
| 458 | request_seq = ntohl(inreq->request_seq); |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 459 | if (TSN_lt(asoc->strreset_inseq, request_seq) || |
| 460 | TSN_lt(request_seq, asoc->strreset_inseq - 2)) { |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 461 | result = SCTP_STRRESET_ERR_BAD_SEQNO; |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 462 | goto err; |
| 463 | } else if (TSN_lt(request_seq, asoc->strreset_inseq)) { |
| 464 | i = asoc->strreset_inseq - request_seq - 1; |
| 465 | result = asoc->strreset_result[i]; |
| 466 | if (result == SCTP_STRRESET_PERFORMED) |
| 467 | return NULL; |
| 468 | goto err; |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 469 | } |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 470 | asoc->strreset_inseq++; |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 471 | |
| 472 | if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ)) |
| 473 | goto out; |
| 474 | |
| 475 | if (asoc->strreset_outstanding) { |
| 476 | result = SCTP_STRRESET_ERR_IN_PROGRESS; |
| 477 | goto out; |
| 478 | } |
| 479 | |
| 480 | nums = (ntohs(param.p->length) - sizeof(*inreq)) / 2; |
| 481 | str_p = inreq->list_of_streams; |
| 482 | for (i = 0; i < nums; i++) { |
| 483 | if (ntohs(str_p[i]) >= stream->outcnt) { |
| 484 | result = SCTP_STRRESET_ERR_WRONG_SSN; |
| 485 | goto out; |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | chunk = sctp_make_strreset_req(asoc, nums, str_p, 1, 0); |
| 490 | if (!chunk) |
| 491 | goto out; |
| 492 | |
| 493 | if (nums) |
| 494 | for (i = 0; i < nums; i++) |
| 495 | stream->out[ntohs(str_p[i])].state = |
| 496 | SCTP_STREAM_CLOSED; |
| 497 | else |
| 498 | for (i = 0; i < stream->outcnt; i++) |
| 499 | stream->out[i].state = SCTP_STREAM_CLOSED; |
| 500 | |
| 501 | asoc->strreset_chunk = chunk; |
| 502 | asoc->strreset_outstanding = 1; |
| 503 | sctp_chunk_hold(asoc->strreset_chunk); |
| 504 | |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 505 | result = SCTP_STRRESET_PERFORMED; |
| 506 | |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 507 | *evp = sctp_ulpevent_make_stream_reset_event(asoc, |
| 508 | SCTP_STREAM_RESET_INCOMING_SSN, nums, str_p, GFP_ATOMIC); |
| 509 | |
| 510 | out: |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 511 | sctp_update_strreset_result(asoc, result); |
| 512 | err: |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 513 | if (!chunk) |
| 514 | chunk = sctp_make_strreset_resp(asoc, result, request_seq); |
| 515 | |
| 516 | return chunk; |
| 517 | } |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 518 | |
| 519 | struct sctp_chunk *sctp_process_strreset_tsnreq( |
| 520 | struct sctp_association *asoc, |
| 521 | union sctp_params param, |
| 522 | struct sctp_ulpevent **evp) |
| 523 | { |
| 524 | __u32 init_tsn = 0, next_tsn = 0, max_tsn_seen; |
| 525 | struct sctp_strreset_tsnreq *tsnreq = param.v; |
| 526 | struct sctp_stream *stream = asoc->stream; |
| 527 | __u32 result = SCTP_STRRESET_DENIED; |
| 528 | __u32 request_seq; |
| 529 | __u16 i; |
| 530 | |
| 531 | request_seq = ntohl(tsnreq->request_seq); |
Xin Long | 6c80138 | 2017-04-15 22:00:29 +0800 | [diff] [blame^] | 532 | if (TSN_lt(asoc->strreset_inseq, request_seq) || |
| 533 | TSN_lt(request_seq, asoc->strreset_inseq - 2)) { |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 534 | result = SCTP_STRRESET_ERR_BAD_SEQNO; |
Xin Long | 6c80138 | 2017-04-15 22:00:29 +0800 | [diff] [blame^] | 535 | goto err; |
| 536 | } else if (TSN_lt(request_seq, asoc->strreset_inseq)) { |
| 537 | i = asoc->strreset_inseq - request_seq - 1; |
| 538 | result = asoc->strreset_result[i]; |
| 539 | if (result == SCTP_STRRESET_PERFORMED) { |
| 540 | next_tsn = asoc->next_tsn; |
| 541 | init_tsn = |
| 542 | sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + 1; |
| 543 | } |
| 544 | goto err; |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 545 | } |
Xin Long | 6c80138 | 2017-04-15 22:00:29 +0800 | [diff] [blame^] | 546 | asoc->strreset_inseq++; |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 547 | |
| 548 | if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_ASSOC_REQ)) |
| 549 | goto out; |
| 550 | |
| 551 | if (asoc->strreset_outstanding) { |
| 552 | result = SCTP_STRRESET_ERR_IN_PROGRESS; |
| 553 | goto out; |
| 554 | } |
| 555 | |
| 556 | /* G3: The same processing as though a SACK chunk with no gap report |
| 557 | * and a cumulative TSN ACK of the Sender's Next TSN minus 1 were |
| 558 | * received MUST be performed. |
| 559 | */ |
| 560 | max_tsn_seen = sctp_tsnmap_get_max_tsn_seen(&asoc->peer.tsn_map); |
| 561 | sctp_ulpq_reasm_flushtsn(&asoc->ulpq, max_tsn_seen); |
| 562 | sctp_ulpq_abort_pd(&asoc->ulpq, GFP_ATOMIC); |
| 563 | |
| 564 | /* G1: Compute an appropriate value for the Receiver's Next TSN -- the |
| 565 | * TSN that the peer should use to send the next DATA chunk. The |
| 566 | * value SHOULD be the smallest TSN not acknowledged by the |
| 567 | * receiver of the request plus 2^31. |
| 568 | */ |
| 569 | init_tsn = sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + (1 << 31); |
| 570 | sctp_tsnmap_init(&asoc->peer.tsn_map, SCTP_TSN_MAP_INITIAL, |
| 571 | init_tsn, GFP_ATOMIC); |
| 572 | |
| 573 | /* G4: The same processing as though a FWD-TSN chunk (as defined in |
| 574 | * [RFC3758]) with all streams affected and a new cumulative TSN |
| 575 | * ACK of the Receiver's Next TSN minus 1 were received MUST be |
| 576 | * performed. |
| 577 | */ |
| 578 | sctp_outq_free(&asoc->outqueue); |
| 579 | |
| 580 | /* G2: Compute an appropriate value for the local endpoint's next TSN, |
| 581 | * i.e., the next TSN assigned by the receiver of the SSN/TSN reset |
| 582 | * chunk. The value SHOULD be the highest TSN sent by the receiver |
| 583 | * of the request plus 1. |
| 584 | */ |
| 585 | next_tsn = asoc->next_tsn; |
| 586 | asoc->ctsn_ack_point = next_tsn - 1; |
| 587 | asoc->adv_peer_ack_point = asoc->ctsn_ack_point; |
| 588 | |
| 589 | /* G5: The next expected and outgoing SSNs MUST be reset to 0 for all |
| 590 | * incoming and outgoing streams. |
| 591 | */ |
| 592 | for (i = 0; i < stream->outcnt; i++) |
| 593 | stream->out[i].ssn = 0; |
| 594 | for (i = 0; i < stream->incnt; i++) |
| 595 | stream->in[i].ssn = 0; |
| 596 | |
| 597 | result = SCTP_STRRESET_PERFORMED; |
| 598 | |
| 599 | *evp = sctp_ulpevent_make_assoc_reset_event(asoc, 0, init_tsn, |
| 600 | next_tsn, GFP_ATOMIC); |
| 601 | |
| 602 | out: |
Xin Long | 6c80138 | 2017-04-15 22:00:29 +0800 | [diff] [blame^] | 603 | sctp_update_strreset_result(asoc, result); |
| 604 | err: |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 605 | return sctp_make_strreset_tsnresp(asoc, result, request_seq, |
| 606 | next_tsn, init_tsn); |
| 607 | } |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 608 | |
| 609 | struct sctp_chunk *sctp_process_strreset_addstrm_out( |
| 610 | struct sctp_association *asoc, |
| 611 | union sctp_params param, |
| 612 | struct sctp_ulpevent **evp) |
| 613 | { |
| 614 | struct sctp_strreset_addstrm *addstrm = param.v; |
| 615 | struct sctp_stream *stream = asoc->stream; |
| 616 | __u32 result = SCTP_STRRESET_DENIED; |
| 617 | struct sctp_stream_in *streamin; |
| 618 | __u32 request_seq, incnt; |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 619 | __u16 in, i; |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 620 | |
| 621 | request_seq = ntohl(addstrm->request_seq); |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 622 | if (TSN_lt(asoc->strreset_inseq, request_seq) || |
| 623 | TSN_lt(request_seq, asoc->strreset_inseq - 2)) { |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 624 | result = SCTP_STRRESET_ERR_BAD_SEQNO; |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 625 | goto err; |
| 626 | } else if (TSN_lt(request_seq, asoc->strreset_inseq)) { |
| 627 | i = asoc->strreset_inseq - request_seq - 1; |
| 628 | result = asoc->strreset_result[i]; |
| 629 | goto err; |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 630 | } |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 631 | asoc->strreset_inseq++; |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 632 | |
| 633 | if (!(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ)) |
| 634 | goto out; |
| 635 | |
| 636 | if (asoc->strreset_chunk) { |
| 637 | if (!sctp_chunk_lookup_strreset_param( |
| 638 | asoc, 0, SCTP_PARAM_RESET_ADD_IN_STREAMS)) { |
| 639 | /* same process with outstanding isn't 0 */ |
| 640 | result = SCTP_STRRESET_ERR_IN_PROGRESS; |
| 641 | goto out; |
| 642 | } |
| 643 | |
| 644 | asoc->strreset_outstanding--; |
| 645 | asoc->strreset_outseq++; |
| 646 | |
| 647 | if (!asoc->strreset_outstanding) { |
| 648 | struct sctp_transport *t; |
| 649 | |
| 650 | t = asoc->strreset_chunk->transport; |
| 651 | if (del_timer(&t->reconf_timer)) |
| 652 | sctp_transport_put(t); |
| 653 | |
| 654 | sctp_chunk_put(asoc->strreset_chunk); |
| 655 | asoc->strreset_chunk = NULL; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | in = ntohs(addstrm->number_of_streams); |
| 660 | incnt = stream->incnt + in; |
| 661 | if (!in || incnt > SCTP_MAX_STREAM) |
| 662 | goto out; |
| 663 | |
| 664 | streamin = krealloc(stream->in, incnt * sizeof(*streamin), |
| 665 | GFP_ATOMIC); |
| 666 | if (!streamin) |
| 667 | goto out; |
| 668 | |
| 669 | memset(streamin + stream->incnt, 0, in * sizeof(*streamin)); |
| 670 | stream->in = streamin; |
| 671 | stream->incnt = incnt; |
| 672 | |
| 673 | result = SCTP_STRRESET_PERFORMED; |
| 674 | |
| 675 | *evp = sctp_ulpevent_make_stream_change_event(asoc, |
| 676 | 0, ntohs(addstrm->number_of_streams), 0, GFP_ATOMIC); |
| 677 | |
| 678 | out: |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 679 | sctp_update_strreset_result(asoc, result); |
| 680 | err: |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 681 | return sctp_make_strreset_resp(asoc, result, request_seq); |
| 682 | } |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 683 | |
| 684 | struct sctp_chunk *sctp_process_strreset_addstrm_in( |
| 685 | struct sctp_association *asoc, |
| 686 | union sctp_params param, |
| 687 | struct sctp_ulpevent **evp) |
| 688 | { |
| 689 | struct sctp_strreset_addstrm *addstrm = param.v; |
| 690 | struct sctp_stream *stream = asoc->stream; |
| 691 | __u32 result = SCTP_STRRESET_DENIED; |
| 692 | struct sctp_stream_out *streamout; |
| 693 | struct sctp_chunk *chunk = NULL; |
| 694 | __u32 request_seq, outcnt; |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 695 | __u16 out, i; |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 696 | |
| 697 | request_seq = ntohl(addstrm->request_seq); |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 698 | if (TSN_lt(asoc->strreset_inseq, request_seq) || |
| 699 | TSN_lt(request_seq, asoc->strreset_inseq - 2)) { |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 700 | result = SCTP_STRRESET_ERR_BAD_SEQNO; |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 701 | goto err; |
| 702 | } else if (TSN_lt(request_seq, asoc->strreset_inseq)) { |
| 703 | i = asoc->strreset_inseq - request_seq - 1; |
| 704 | result = asoc->strreset_result[i]; |
| 705 | if (result == SCTP_STRRESET_PERFORMED) |
| 706 | return NULL; |
| 707 | goto err; |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 708 | } |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 709 | asoc->strreset_inseq++; |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 710 | |
| 711 | if (!(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ)) |
| 712 | goto out; |
| 713 | |
| 714 | if (asoc->strreset_outstanding) { |
| 715 | result = SCTP_STRRESET_ERR_IN_PROGRESS; |
| 716 | goto out; |
| 717 | } |
| 718 | |
| 719 | out = ntohs(addstrm->number_of_streams); |
| 720 | outcnt = stream->outcnt + out; |
| 721 | if (!out || outcnt > SCTP_MAX_STREAM) |
| 722 | goto out; |
| 723 | |
| 724 | streamout = krealloc(stream->out, outcnt * sizeof(*streamout), |
| 725 | GFP_ATOMIC); |
| 726 | if (!streamout) |
| 727 | goto out; |
| 728 | |
| 729 | memset(streamout + stream->outcnt, 0, out * sizeof(*streamout)); |
| 730 | stream->out = streamout; |
| 731 | |
| 732 | chunk = sctp_make_strreset_addstrm(asoc, out, 0); |
| 733 | if (!chunk) |
| 734 | goto out; |
| 735 | |
| 736 | asoc->strreset_chunk = chunk; |
| 737 | asoc->strreset_outstanding = 1; |
| 738 | sctp_chunk_hold(asoc->strreset_chunk); |
| 739 | |
| 740 | stream->outcnt = outcnt; |
| 741 | |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 742 | result = SCTP_STRRESET_PERFORMED; |
| 743 | |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 744 | *evp = sctp_ulpevent_make_stream_change_event(asoc, |
| 745 | 0, 0, ntohs(addstrm->number_of_streams), GFP_ATOMIC); |
| 746 | |
| 747 | out: |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 748 | sctp_update_strreset_result(asoc, result); |
| 749 | err: |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 750 | if (!chunk) |
| 751 | chunk = sctp_make_strreset_resp(asoc, result, request_seq); |
| 752 | |
| 753 | return chunk; |
| 754 | } |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 755 | |
| 756 | struct sctp_chunk *sctp_process_strreset_resp( |
| 757 | struct sctp_association *asoc, |
| 758 | union sctp_params param, |
| 759 | struct sctp_ulpevent **evp) |
| 760 | { |
| 761 | struct sctp_strreset_resp *resp = param.v; |
| 762 | struct sctp_stream *stream = asoc->stream; |
| 763 | struct sctp_transport *t; |
| 764 | __u16 i, nums, flags = 0; |
| 765 | sctp_paramhdr_t *req; |
| 766 | __u32 result; |
| 767 | |
| 768 | req = sctp_chunk_lookup_strreset_param(asoc, resp->response_seq, 0); |
| 769 | if (!req) |
| 770 | return NULL; |
| 771 | |
| 772 | result = ntohl(resp->result); |
| 773 | if (result != SCTP_STRRESET_PERFORMED) { |
| 774 | /* if in progress, do nothing but retransmit */ |
| 775 | if (result == SCTP_STRRESET_IN_PROGRESS) |
| 776 | return NULL; |
| 777 | else if (result == SCTP_STRRESET_DENIED) |
| 778 | flags = SCTP_STREAM_RESET_DENIED; |
| 779 | else |
| 780 | flags = SCTP_STREAM_RESET_FAILED; |
| 781 | } |
| 782 | |
| 783 | if (req->type == SCTP_PARAM_RESET_OUT_REQUEST) { |
| 784 | struct sctp_strreset_outreq *outreq; |
Xin Long | edb12f2 | 2017-04-15 21:56:57 +0800 | [diff] [blame] | 785 | __u16 *str_p; |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 786 | |
| 787 | outreq = (struct sctp_strreset_outreq *)req; |
Xin Long | edb12f2 | 2017-04-15 21:56:57 +0800 | [diff] [blame] | 788 | str_p = outreq->list_of_streams; |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 789 | nums = (ntohs(outreq->param_hdr.length) - sizeof(*outreq)) / 2; |
| 790 | |
| 791 | if (result == SCTP_STRRESET_PERFORMED) { |
| 792 | if (nums) { |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 793 | for (i = 0; i < nums; i++) |
| 794 | stream->out[ntohs(str_p[i])].ssn = 0; |
| 795 | } else { |
| 796 | for (i = 0; i < stream->outcnt; i++) |
| 797 | stream->out[i].ssn = 0; |
| 798 | } |
| 799 | |
| 800 | flags = SCTP_STREAM_RESET_OUTGOING_SSN; |
| 801 | } |
| 802 | |
| 803 | for (i = 0; i < stream->outcnt; i++) |
| 804 | stream->out[i].state = SCTP_STREAM_OPEN; |
| 805 | |
| 806 | *evp = sctp_ulpevent_make_stream_reset_event(asoc, flags, |
| 807 | nums, str_p, GFP_ATOMIC); |
| 808 | } else if (req->type == SCTP_PARAM_RESET_IN_REQUEST) { |
| 809 | struct sctp_strreset_inreq *inreq; |
Xin Long | edb12f2 | 2017-04-15 21:56:57 +0800 | [diff] [blame] | 810 | __u16 *str_p; |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 811 | |
| 812 | /* if the result is performed, it's impossible for inreq */ |
| 813 | if (result == SCTP_STRRESET_PERFORMED) |
| 814 | return NULL; |
| 815 | |
| 816 | inreq = (struct sctp_strreset_inreq *)req; |
Xin Long | edb12f2 | 2017-04-15 21:56:57 +0800 | [diff] [blame] | 817 | str_p = inreq->list_of_streams; |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 818 | nums = (ntohs(inreq->param_hdr.length) - sizeof(*inreq)) / 2; |
| 819 | |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 820 | *evp = sctp_ulpevent_make_stream_reset_event(asoc, flags, |
| 821 | nums, str_p, GFP_ATOMIC); |
| 822 | } else if (req->type == SCTP_PARAM_RESET_TSN_REQUEST) { |
| 823 | struct sctp_strreset_resptsn *resptsn; |
| 824 | __u32 stsn, rtsn; |
| 825 | |
| 826 | /* check for resptsn, as sctp_verify_reconf didn't do it*/ |
| 827 | if (ntohs(param.p->length) != sizeof(*resptsn)) |
| 828 | return NULL; |
| 829 | |
| 830 | resptsn = (struct sctp_strreset_resptsn *)resp; |
| 831 | stsn = ntohl(resptsn->senders_next_tsn); |
| 832 | rtsn = ntohl(resptsn->receivers_next_tsn); |
| 833 | |
| 834 | if (result == SCTP_STRRESET_PERFORMED) { |
| 835 | __u32 mtsn = sctp_tsnmap_get_max_tsn_seen( |
| 836 | &asoc->peer.tsn_map); |
| 837 | |
| 838 | sctp_ulpq_reasm_flushtsn(&asoc->ulpq, mtsn); |
| 839 | sctp_ulpq_abort_pd(&asoc->ulpq, GFP_ATOMIC); |
| 840 | |
| 841 | sctp_tsnmap_init(&asoc->peer.tsn_map, |
| 842 | SCTP_TSN_MAP_INITIAL, |
| 843 | stsn, GFP_ATOMIC); |
| 844 | |
| 845 | sctp_outq_free(&asoc->outqueue); |
| 846 | |
| 847 | asoc->next_tsn = rtsn; |
| 848 | asoc->ctsn_ack_point = asoc->next_tsn - 1; |
| 849 | asoc->adv_peer_ack_point = asoc->ctsn_ack_point; |
| 850 | |
| 851 | for (i = 0; i < stream->outcnt; i++) |
| 852 | stream->out[i].ssn = 0; |
| 853 | for (i = 0; i < stream->incnt; i++) |
| 854 | stream->in[i].ssn = 0; |
| 855 | } |
| 856 | |
| 857 | for (i = 0; i < stream->outcnt; i++) |
| 858 | stream->out[i].state = SCTP_STREAM_OPEN; |
| 859 | |
| 860 | *evp = sctp_ulpevent_make_assoc_reset_event(asoc, flags, |
| 861 | stsn, rtsn, GFP_ATOMIC); |
| 862 | } else if (req->type == SCTP_PARAM_RESET_ADD_OUT_STREAMS) { |
| 863 | struct sctp_strreset_addstrm *addstrm; |
| 864 | __u16 number; |
| 865 | |
| 866 | addstrm = (struct sctp_strreset_addstrm *)req; |
| 867 | nums = ntohs(addstrm->number_of_streams); |
| 868 | number = stream->outcnt - nums; |
| 869 | |
| 870 | if (result == SCTP_STRRESET_PERFORMED) |
| 871 | for (i = number; i < stream->outcnt; i++) |
| 872 | stream->out[i].state = SCTP_STREAM_OPEN; |
| 873 | else |
| 874 | stream->outcnt = number; |
| 875 | |
| 876 | *evp = sctp_ulpevent_make_stream_change_event(asoc, flags, |
| 877 | 0, nums, GFP_ATOMIC); |
| 878 | } else if (req->type == SCTP_PARAM_RESET_ADD_IN_STREAMS) { |
| 879 | struct sctp_strreset_addstrm *addstrm; |
| 880 | |
| 881 | /* if the result is performed, it's impossible for addstrm in |
| 882 | * request. |
| 883 | */ |
| 884 | if (result == SCTP_STRRESET_PERFORMED) |
| 885 | return NULL; |
| 886 | |
| 887 | addstrm = (struct sctp_strreset_addstrm *)req; |
| 888 | nums = ntohs(addstrm->number_of_streams); |
| 889 | |
| 890 | *evp = sctp_ulpevent_make_stream_change_event(asoc, flags, |
| 891 | nums, 0, GFP_ATOMIC); |
| 892 | } |
| 893 | |
| 894 | asoc->strreset_outstanding--; |
| 895 | asoc->strreset_outseq++; |
| 896 | |
| 897 | /* remove everything for this reconf request */ |
| 898 | if (!asoc->strreset_outstanding) { |
| 899 | t = asoc->strreset_chunk->transport; |
| 900 | if (del_timer(&t->reconf_timer)) |
| 901 | sctp_transport_put(t); |
| 902 | |
| 903 | sctp_chunk_put(asoc->strreset_chunk); |
| 904 | asoc->strreset_chunk = NULL; |
| 905 | } |
| 906 | |
| 907 | return NULL; |
| 908 | } |