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