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 | * |
Xin Long | fae8b6f | 2018-02-13 19:29:13 +0800 | [diff] [blame] | 9 | * This file contains sctp stream maniuplation primitives and helpers. |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 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 | |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 35 | #include <linux/list.h> |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 36 | #include <net/sctp/sctp.h> |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 37 | #include <net/sctp/sm.h> |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 38 | #include <net/sctp/stream_sched.h> |
| 39 | |
Konstantin Khorenko | 0d493b4 | 2018-08-10 20:11:43 +0300 | [diff] [blame] | 40 | static struct flex_array *fa_alloc(size_t elem_size, size_t elem_count, |
| 41 | gfp_t gfp) |
| 42 | { |
| 43 | struct flex_array *result; |
| 44 | int err; |
| 45 | |
| 46 | result = flex_array_alloc(elem_size, elem_count, gfp); |
| 47 | if (result) { |
| 48 | err = flex_array_prealloc(result, 0, elem_count, gfp); |
| 49 | if (err) { |
| 50 | flex_array_free(result); |
| 51 | result = NULL; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | return result; |
| 56 | } |
| 57 | |
| 58 | static void fa_free(struct flex_array *fa) |
| 59 | { |
| 60 | if (fa) |
| 61 | flex_array_free(fa); |
| 62 | } |
| 63 | |
| 64 | static void fa_copy(struct flex_array *fa, struct flex_array *from, |
| 65 | size_t index, size_t count) |
| 66 | { |
| 67 | void *elem; |
| 68 | |
| 69 | while (count--) { |
| 70 | elem = flex_array_get(from, index); |
| 71 | flex_array_put(fa, index, elem, 0); |
| 72 | index++; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | static void fa_zero(struct flex_array *fa, size_t index, size_t count) |
| 77 | { |
| 78 | void *elem; |
| 79 | |
| 80 | while (count--) { |
| 81 | elem = flex_array_get(fa, index); |
| 82 | memset(elem, 0, fa->element_size); |
| 83 | index++; |
| 84 | } |
| 85 | } |
| 86 | |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 87 | /* Migrates chunks from stream queues to new stream queues if needed, |
| 88 | * but not across associations. Also, removes those chunks to streams |
| 89 | * higher than the new max. |
| 90 | */ |
| 91 | static void sctp_stream_outq_migrate(struct sctp_stream *stream, |
| 92 | struct sctp_stream *new, __u16 outcnt) |
| 93 | { |
| 94 | struct sctp_association *asoc; |
| 95 | struct sctp_chunk *ch, *temp; |
| 96 | struct sctp_outq *outq; |
| 97 | int i; |
| 98 | |
| 99 | asoc = container_of(stream, struct sctp_association, stream); |
| 100 | outq = &asoc->outqueue; |
| 101 | |
| 102 | list_for_each_entry_safe(ch, temp, &outq->out_chunk_list, list) { |
| 103 | __u16 sid = sctp_chunk_stream_no(ch); |
| 104 | |
| 105 | if (sid < outcnt) |
| 106 | continue; |
| 107 | |
| 108 | sctp_sched_dequeue_common(outq, ch); |
| 109 | /* No need to call dequeue_done here because |
| 110 | * the chunks are not scheduled by now. |
| 111 | */ |
| 112 | |
| 113 | /* Mark as failed send. */ |
Xin Long | 08f4607 | 2017-11-26 20:16:06 +0800 | [diff] [blame] | 114 | sctp_chunk_fail(ch, (__force __u32)SCTP_ERROR_INV_STRM); |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 115 | if (asoc->peer.prsctp_capable && |
| 116 | SCTP_PR_PRIO_ENABLED(ch->sinfo.sinfo_flags)) |
| 117 | asoc->sent_cnt_removable--; |
| 118 | |
| 119 | sctp_chunk_free(ch); |
| 120 | } |
| 121 | |
| 122 | if (new) { |
| 123 | /* Here we actually move the old ext stuff into the new |
| 124 | * buffer, because we want to keep it. Then |
| 125 | * sctp_stream_update will swap ->out pointers. |
| 126 | */ |
| 127 | for (i = 0; i < outcnt; i++) { |
Konstantin Khorenko | 0d493b4 | 2018-08-10 20:11:43 +0300 | [diff] [blame] | 128 | kfree(SCTP_SO(new, i)->ext); |
| 129 | SCTP_SO(new, i)->ext = SCTP_SO(stream, i)->ext; |
| 130 | SCTP_SO(stream, i)->ext = NULL; |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | |
| 134 | for (i = outcnt; i < stream->outcnt; i++) |
Konstantin Khorenko | 0d493b4 | 2018-08-10 20:11:43 +0300 | [diff] [blame] | 135 | kfree(SCTP_SO(stream, i)->ext); |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 136 | } |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 137 | |
Marcelo Ricardo Leitner | e090abd | 2017-10-03 19:20:09 -0300 | [diff] [blame] | 138 | static int sctp_stream_alloc_out(struct sctp_stream *stream, __u16 outcnt, |
| 139 | gfp_t gfp) |
| 140 | { |
Konstantin Khorenko | 0d493b4 | 2018-08-10 20:11:43 +0300 | [diff] [blame] | 141 | struct flex_array *out; |
| 142 | size_t elem_size = sizeof(struct sctp_stream_out); |
Marcelo Ricardo Leitner | e090abd | 2017-10-03 19:20:09 -0300 | [diff] [blame] | 143 | |
Konstantin Khorenko | 0d493b4 | 2018-08-10 20:11:43 +0300 | [diff] [blame] | 144 | out = fa_alloc(elem_size, outcnt, gfp); |
Marcelo Ricardo Leitner | e090abd | 2017-10-03 19:20:09 -0300 | [diff] [blame] | 145 | if (!out) |
| 146 | return -ENOMEM; |
| 147 | |
| 148 | if (stream->out) { |
Konstantin Khorenko | 0d493b4 | 2018-08-10 20:11:43 +0300 | [diff] [blame] | 149 | fa_copy(out, stream->out, 0, min(outcnt, stream->outcnt)); |
| 150 | fa_free(stream->out); |
Marcelo Ricardo Leitner | e090abd | 2017-10-03 19:20:09 -0300 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | if (outcnt > stream->outcnt) |
Konstantin Khorenko | 0d493b4 | 2018-08-10 20:11:43 +0300 | [diff] [blame] | 154 | fa_zero(out, stream->outcnt, (outcnt - stream->outcnt)); |
Marcelo Ricardo Leitner | e090abd | 2017-10-03 19:20:09 -0300 | [diff] [blame] | 155 | |
| 156 | stream->out = out; |
| 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
Marcelo Ricardo Leitner | 1fdb8d8 | 2017-10-03 19:20:10 -0300 | [diff] [blame] | 161 | static int sctp_stream_alloc_in(struct sctp_stream *stream, __u16 incnt, |
| 162 | gfp_t gfp) |
| 163 | { |
Konstantin Khorenko | 0d493b4 | 2018-08-10 20:11:43 +0300 | [diff] [blame] | 164 | struct flex_array *in; |
| 165 | size_t elem_size = sizeof(struct sctp_stream_in); |
Marcelo Ricardo Leitner | 1fdb8d8 | 2017-10-03 19:20:10 -0300 | [diff] [blame] | 166 | |
Konstantin Khorenko | 0d493b4 | 2018-08-10 20:11:43 +0300 | [diff] [blame] | 167 | in = fa_alloc(elem_size, incnt, gfp); |
Marcelo Ricardo Leitner | 1fdb8d8 | 2017-10-03 19:20:10 -0300 | [diff] [blame] | 168 | if (!in) |
| 169 | return -ENOMEM; |
| 170 | |
| 171 | if (stream->in) { |
Konstantin Khorenko | 0d493b4 | 2018-08-10 20:11:43 +0300 | [diff] [blame] | 172 | fa_copy(in, stream->in, 0, min(incnt, stream->incnt)); |
| 173 | fa_free(stream->in); |
Marcelo Ricardo Leitner | 1fdb8d8 | 2017-10-03 19:20:10 -0300 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | if (incnt > stream->incnt) |
Konstantin Khorenko | 0d493b4 | 2018-08-10 20:11:43 +0300 | [diff] [blame] | 177 | fa_zero(in, stream->incnt, (incnt - stream->incnt)); |
Marcelo Ricardo Leitner | 1fdb8d8 | 2017-10-03 19:20:10 -0300 | [diff] [blame] | 178 | |
| 179 | stream->in = in; |
| 180 | |
| 181 | return 0; |
| 182 | } |
| 183 | |
Xin Long | ff35641 | 2017-05-31 16:36:32 +0800 | [diff] [blame] | 184 | int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt, |
| 185 | gfp_t gfp) |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 186 | { |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 187 | struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream); |
| 188 | int i, ret = 0; |
Xin Long | 3dbcc10 | 2017-03-30 01:00:53 +0800 | [diff] [blame] | 189 | |
Marcelo Ricardo Leitner | 1ae2eaa | 2017-10-03 19:20:08 -0300 | [diff] [blame] | 190 | gfp |= __GFP_NOWARN; |
| 191 | |
Xin Long | 3dbcc10 | 2017-03-30 01:00:53 +0800 | [diff] [blame] | 192 | /* Initial stream->out size may be very big, so free it and alloc |
Marcelo Ricardo Leitner | 1ae2eaa | 2017-10-03 19:20:08 -0300 | [diff] [blame] | 193 | * a new one with new outcnt to save memory if needed. |
Xin Long | 3dbcc10 | 2017-03-30 01:00:53 +0800 | [diff] [blame] | 194 | */ |
Marcelo Ricardo Leitner | 1ae2eaa | 2017-10-03 19:20:08 -0300 | [diff] [blame] | 195 | if (outcnt == stream->outcnt) |
| 196 | goto in; |
| 197 | |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 198 | /* Filter out chunks queued on streams that won't exist anymore */ |
| 199 | sched->unsched_all(stream); |
| 200 | sctp_stream_outq_migrate(stream, NULL, outcnt); |
| 201 | sched->sched_all(stream); |
| 202 | |
Marcelo Ricardo Leitner | 79d0895 | 2018-01-02 19:44:37 -0200 | [diff] [blame] | 203 | ret = sctp_stream_alloc_out(stream, outcnt, gfp); |
| 204 | if (ret) |
| 205 | goto out; |
Xin Long | 3dbcc10 | 2017-03-30 01:00:53 +0800 | [diff] [blame] | 206 | |
Xin Long | ff35641 | 2017-05-31 16:36:32 +0800 | [diff] [blame] | 207 | stream->outcnt = outcnt; |
Xin Long | 3dbcc10 | 2017-03-30 01:00:53 +0800 | [diff] [blame] | 208 | for (i = 0; i < stream->outcnt; i++) |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 209 | SCTP_SO(stream, i)->state = SCTP_STREAM_OPEN; |
Xin Long | 3dbcc10 | 2017-03-30 01:00:53 +0800 | [diff] [blame] | 210 | |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 211 | sched->init(stream); |
| 212 | |
Marcelo Ricardo Leitner | 1ae2eaa | 2017-10-03 19:20:08 -0300 | [diff] [blame] | 213 | in: |
Xin Long | 0c3f6f6 | 2017-12-08 21:04:01 +0800 | [diff] [blame] | 214 | sctp_stream_interleave_init(stream); |
Xin Long | ff35641 | 2017-05-31 16:36:32 +0800 | [diff] [blame] | 215 | if (!incnt) |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 216 | goto out; |
Xin Long | ff35641 | 2017-05-31 16:36:32 +0800 | [diff] [blame] | 217 | |
Marcelo Ricardo Leitner | 79d0895 | 2018-01-02 19:44:37 -0200 | [diff] [blame] | 218 | ret = sctp_stream_alloc_in(stream, incnt, gfp); |
| 219 | if (ret) { |
| 220 | sched->free(stream); |
Konstantin Khorenko | 0d493b4 | 2018-08-10 20:11:43 +0300 | [diff] [blame] | 221 | fa_free(stream->out); |
Marcelo Ricardo Leitner | 79d0895 | 2018-01-02 19:44:37 -0200 | [diff] [blame] | 222 | stream->out = NULL; |
| 223 | stream->outcnt = 0; |
| 224 | goto out; |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 225 | } |
| 226 | |
Xin Long | ff35641 | 2017-05-31 16:36:32 +0800 | [diff] [blame] | 227 | stream->incnt = incnt; |
| 228 | |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 229 | out: |
| 230 | return ret; |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 231 | } |
| 232 | |
Marcelo Ricardo Leitner | f952be7 | 2017-10-03 19:20:11 -0300 | [diff] [blame] | 233 | int sctp_stream_init_ext(struct sctp_stream *stream, __u16 sid) |
| 234 | { |
| 235 | struct sctp_stream_out_ext *soute; |
| 236 | |
| 237 | soute = kzalloc(sizeof(*soute), GFP_KERNEL); |
| 238 | if (!soute) |
| 239 | return -ENOMEM; |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 240 | SCTP_SO(stream, sid)->ext = soute; |
Marcelo Ricardo Leitner | f952be7 | 2017-10-03 19:20:11 -0300 | [diff] [blame] | 241 | |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 242 | return sctp_sched_init_sid(stream, sid, GFP_KERNEL); |
Marcelo Ricardo Leitner | f952be7 | 2017-10-03 19:20:11 -0300 | [diff] [blame] | 243 | } |
| 244 | |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 245 | void sctp_stream_free(struct sctp_stream *stream) |
| 246 | { |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 247 | struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream); |
Marcelo Ricardo Leitner | f952be7 | 2017-10-03 19:20:11 -0300 | [diff] [blame] | 248 | int i; |
| 249 | |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 250 | sched->free(stream); |
Marcelo Ricardo Leitner | f952be7 | 2017-10-03 19:20:11 -0300 | [diff] [blame] | 251 | for (i = 0; i < stream->outcnt; i++) |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 252 | kfree(SCTP_SO(stream, i)->ext); |
Konstantin Khorenko | 0d493b4 | 2018-08-10 20:11:43 +0300 | [diff] [blame] | 253 | fa_free(stream->out); |
| 254 | fa_free(stream->in); |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | void sctp_stream_clear(struct sctp_stream *stream) |
| 258 | { |
| 259 | int i; |
| 260 | |
Xin Long | 107e242 | 2017-12-15 00:41:31 +0800 | [diff] [blame] | 261 | for (i = 0; i < stream->outcnt; i++) { |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 262 | SCTP_SO(stream, i)->mid = 0; |
| 263 | SCTP_SO(stream, i)->mid_uo = 0; |
Xin Long | 107e242 | 2017-12-15 00:41:31 +0800 | [diff] [blame] | 264 | } |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 265 | |
| 266 | for (i = 0; i < stream->incnt; i++) |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 267 | SCTP_SI(stream, i)->mid = 0; |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 268 | } |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 269 | |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 270 | void sctp_stream_update(struct sctp_stream *stream, struct sctp_stream *new) |
| 271 | { |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 272 | struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream); |
| 273 | |
| 274 | sched->unsched_all(stream); |
| 275 | sctp_stream_outq_migrate(stream, new, new->outcnt); |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 276 | sctp_stream_free(stream); |
| 277 | |
| 278 | stream->out = new->out; |
| 279 | stream->in = new->in; |
| 280 | stream->outcnt = new->outcnt; |
| 281 | stream->incnt = new->incnt; |
| 282 | |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 283 | sched->sched_all(stream); |
| 284 | |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 285 | new->out = NULL; |
| 286 | new->in = NULL; |
Xin Long | 6a9a27d | 2018-04-26 15:21:44 +0800 | [diff] [blame] | 287 | new->outcnt = 0; |
| 288 | new->incnt = 0; |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 289 | } |
| 290 | |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 291 | static int sctp_send_reconf(struct sctp_association *asoc, |
| 292 | struct sctp_chunk *chunk) |
| 293 | { |
| 294 | struct net *net = sock_net(asoc->base.sk); |
| 295 | int retval = 0; |
| 296 | |
| 297 | retval = sctp_primitive_RECONF(net, asoc, chunk); |
| 298 | if (retval) |
| 299 | sctp_chunk_free(chunk); |
| 300 | |
| 301 | return retval; |
| 302 | } |
| 303 | |
Xin Long | d570a59 | 2017-11-25 21:05:33 +0800 | [diff] [blame] | 304 | static bool sctp_stream_outq_is_empty(struct sctp_stream *stream, |
| 305 | __u16 str_nums, __be16 *str_list) |
| 306 | { |
| 307 | struct sctp_association *asoc; |
| 308 | __u16 i; |
| 309 | |
| 310 | asoc = container_of(stream, struct sctp_association, stream); |
| 311 | if (!asoc->outqueue.out_qlen) |
| 312 | return true; |
| 313 | |
| 314 | if (!str_nums) |
| 315 | return false; |
| 316 | |
| 317 | for (i = 0; i < str_nums; i++) { |
| 318 | __u16 sid = ntohs(str_list[i]); |
| 319 | |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 320 | if (SCTP_SO(stream, sid)->ext && |
| 321 | !list_empty(&SCTP_SO(stream, sid)->ext->outq)) |
Xin Long | d570a59 | 2017-11-25 21:05:33 +0800 | [diff] [blame] | 322 | return false; |
| 323 | } |
| 324 | |
| 325 | return true; |
| 326 | } |
| 327 | |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 328 | int sctp_send_reset_streams(struct sctp_association *asoc, |
| 329 | struct sctp_reset_streams *params) |
| 330 | { |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 331 | struct sctp_stream *stream = &asoc->stream; |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 332 | __u16 i, str_nums, *str_list; |
| 333 | struct sctp_chunk *chunk; |
| 334 | int retval = -EINVAL; |
Xin Long | 1da4fc9 | 2017-10-28 19:43:54 +0800 | [diff] [blame] | 335 | __be16 *nstr_list; |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 336 | bool out, in; |
| 337 | |
| 338 | if (!asoc->peer.reconf_capable || |
| 339 | !(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ)) { |
| 340 | retval = -ENOPROTOOPT; |
| 341 | goto out; |
| 342 | } |
| 343 | |
| 344 | if (asoc->strreset_outstanding) { |
| 345 | retval = -EINPROGRESS; |
| 346 | goto out; |
| 347 | } |
| 348 | |
| 349 | out = params->srs_flags & SCTP_STREAM_RESET_OUTGOING; |
| 350 | in = params->srs_flags & SCTP_STREAM_RESET_INCOMING; |
| 351 | if (!out && !in) |
| 352 | goto out; |
| 353 | |
| 354 | str_nums = params->srs_number_streams; |
| 355 | str_list = params->srs_stream_list; |
Xin Long | 423852f | 2017-11-15 17:00:11 +0800 | [diff] [blame] | 356 | if (str_nums) { |
| 357 | int param_len = 0; |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 358 | |
Xin Long | 423852f | 2017-11-15 17:00:11 +0800 | [diff] [blame] | 359 | if (out) { |
| 360 | for (i = 0; i < str_nums; i++) |
| 361 | if (str_list[i] >= stream->outcnt) |
| 362 | goto out; |
| 363 | |
| 364 | param_len = str_nums * sizeof(__u16) + |
| 365 | sizeof(struct sctp_strreset_outreq); |
| 366 | } |
| 367 | |
| 368 | if (in) { |
| 369 | for (i = 0; i < str_nums; i++) |
| 370 | if (str_list[i] >= stream->incnt) |
| 371 | goto out; |
| 372 | |
| 373 | param_len += str_nums * sizeof(__u16) + |
| 374 | sizeof(struct sctp_strreset_inreq); |
| 375 | } |
| 376 | |
| 377 | if (param_len > SCTP_MAX_CHUNK_LEN - |
| 378 | sizeof(struct sctp_reconf_chunk)) |
| 379 | goto out; |
| 380 | } |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 381 | |
Xin Long | 1da4fc9 | 2017-10-28 19:43:54 +0800 | [diff] [blame] | 382 | nstr_list = kcalloc(str_nums, sizeof(__be16), GFP_KERNEL); |
| 383 | if (!nstr_list) { |
| 384 | retval = -ENOMEM; |
| 385 | goto out; |
| 386 | } |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 387 | |
| 388 | for (i = 0; i < str_nums; i++) |
Xin Long | 1da4fc9 | 2017-10-28 19:43:54 +0800 | [diff] [blame] | 389 | nstr_list[i] = htons(str_list[i]); |
| 390 | |
Xin Long | d570a59 | 2017-11-25 21:05:33 +0800 | [diff] [blame] | 391 | if (out && !sctp_stream_outq_is_empty(stream, str_nums, nstr_list)) { |
| 392 | retval = -EAGAIN; |
| 393 | goto out; |
| 394 | } |
| 395 | |
Xin Long | 1da4fc9 | 2017-10-28 19:43:54 +0800 | [diff] [blame] | 396 | chunk = sctp_make_strreset_req(asoc, str_nums, nstr_list, out, in); |
| 397 | |
| 398 | kfree(nstr_list); |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 399 | |
Xin Long | 119aecb | 2017-02-09 01:18:16 +0800 | [diff] [blame] | 400 | if (!chunk) { |
| 401 | retval = -ENOMEM; |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 402 | goto out; |
Xin Long | 119aecb | 2017-02-09 01:18:16 +0800 | [diff] [blame] | 403 | } |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 404 | |
| 405 | if (out) { |
| 406 | if (str_nums) |
| 407 | for (i = 0; i < str_nums; i++) |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 408 | SCTP_SO(stream, str_list[i])->state = |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 409 | SCTP_STREAM_CLOSED; |
| 410 | else |
| 411 | for (i = 0; i < stream->outcnt; i++) |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 412 | SCTP_SO(stream, i)->state = SCTP_STREAM_CLOSED; |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 413 | } |
| 414 | |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 415 | asoc->strreset_chunk = chunk; |
| 416 | sctp_chunk_hold(asoc->strreset_chunk); |
| 417 | |
| 418 | retval = sctp_send_reconf(asoc, chunk); |
| 419 | if (retval) { |
| 420 | sctp_chunk_put(asoc->strreset_chunk); |
| 421 | asoc->strreset_chunk = NULL; |
Xin Long | 119aecb | 2017-02-09 01:18:16 +0800 | [diff] [blame] | 422 | if (!out) |
| 423 | goto out; |
| 424 | |
| 425 | if (str_nums) |
| 426 | for (i = 0; i < str_nums; i++) |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 427 | SCTP_SO(stream, str_list[i])->state = |
Xin Long | 119aecb | 2017-02-09 01:18:16 +0800 | [diff] [blame] | 428 | SCTP_STREAM_OPEN; |
| 429 | else |
| 430 | for (i = 0; i < stream->outcnt; i++) |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 431 | SCTP_SO(stream, i)->state = SCTP_STREAM_OPEN; |
Xin Long | 119aecb | 2017-02-09 01:18:16 +0800 | [diff] [blame] | 432 | |
| 433 | goto out; |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 434 | } |
| 435 | |
Xin Long | 119aecb | 2017-02-09 01:18:16 +0800 | [diff] [blame] | 436 | asoc->strreset_outstanding = out + in; |
| 437 | |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 438 | out: |
| 439 | return retval; |
| 440 | } |
Xin Long | a92ce1a | 2017-02-09 01:18:18 +0800 | [diff] [blame] | 441 | |
| 442 | int sctp_send_reset_assoc(struct sctp_association *asoc) |
| 443 | { |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 444 | struct sctp_stream *stream = &asoc->stream; |
Xin Long | a92ce1a | 2017-02-09 01:18:18 +0800 | [diff] [blame] | 445 | struct sctp_chunk *chunk = NULL; |
| 446 | int retval; |
| 447 | __u16 i; |
| 448 | |
| 449 | if (!asoc->peer.reconf_capable || |
| 450 | !(asoc->strreset_enable & SCTP_ENABLE_RESET_ASSOC_REQ)) |
| 451 | return -ENOPROTOOPT; |
| 452 | |
| 453 | if (asoc->strreset_outstanding) |
| 454 | return -EINPROGRESS; |
| 455 | |
Xin Long | 5c6144a | 2017-11-25 21:05:34 +0800 | [diff] [blame] | 456 | if (!sctp_outq_is_empty(&asoc->outqueue)) |
| 457 | return -EAGAIN; |
| 458 | |
Xin Long | a92ce1a | 2017-02-09 01:18:18 +0800 | [diff] [blame] | 459 | chunk = sctp_make_strreset_tsnreq(asoc); |
| 460 | if (!chunk) |
| 461 | return -ENOMEM; |
| 462 | |
| 463 | /* Block further xmit of data until this request is completed */ |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 464 | for (i = 0; i < stream->outcnt; i++) |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 465 | SCTP_SO(stream, i)->state = SCTP_STREAM_CLOSED; |
Xin Long | a92ce1a | 2017-02-09 01:18:18 +0800 | [diff] [blame] | 466 | |
| 467 | asoc->strreset_chunk = chunk; |
| 468 | sctp_chunk_hold(asoc->strreset_chunk); |
| 469 | |
| 470 | retval = sctp_send_reconf(asoc, chunk); |
| 471 | if (retval) { |
| 472 | sctp_chunk_put(asoc->strreset_chunk); |
| 473 | asoc->strreset_chunk = NULL; |
| 474 | |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 475 | for (i = 0; i < stream->outcnt; i++) |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 476 | SCTP_SO(stream, i)->state = SCTP_STREAM_OPEN; |
Xin Long | a92ce1a | 2017-02-09 01:18:18 +0800 | [diff] [blame] | 477 | |
| 478 | return retval; |
| 479 | } |
| 480 | |
| 481 | asoc->strreset_outstanding = 1; |
| 482 | |
| 483 | return 0; |
| 484 | } |
Xin Long | 242bd2d | 2017-02-09 01:18:20 +0800 | [diff] [blame] | 485 | |
| 486 | int sctp_send_add_streams(struct sctp_association *asoc, |
| 487 | struct sctp_add_streams *params) |
| 488 | { |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 489 | struct sctp_stream *stream = &asoc->stream; |
Xin Long | 242bd2d | 2017-02-09 01:18:20 +0800 | [diff] [blame] | 490 | struct sctp_chunk *chunk = NULL; |
Wei Yongjun | dc82673 | 2017-10-31 13:28:16 +0000 | [diff] [blame] | 491 | int retval; |
Xin Long | 242bd2d | 2017-02-09 01:18:20 +0800 | [diff] [blame] | 492 | __u32 outcnt, incnt; |
| 493 | __u16 out, in; |
| 494 | |
| 495 | if (!asoc->peer.reconf_capable || |
| 496 | !(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ)) { |
| 497 | retval = -ENOPROTOOPT; |
| 498 | goto out; |
| 499 | } |
| 500 | |
| 501 | if (asoc->strreset_outstanding) { |
| 502 | retval = -EINPROGRESS; |
| 503 | goto out; |
| 504 | } |
| 505 | |
| 506 | out = params->sas_outstrms; |
| 507 | in = params->sas_instrms; |
| 508 | outcnt = stream->outcnt + out; |
| 509 | incnt = stream->incnt + in; |
| 510 | if (outcnt > SCTP_MAX_STREAM || incnt > SCTP_MAX_STREAM || |
| 511 | (!out && !in)) { |
| 512 | retval = -EINVAL; |
| 513 | goto out; |
| 514 | } |
| 515 | |
| 516 | if (out) { |
Marcelo Ricardo Leitner | e090abd | 2017-10-03 19:20:09 -0300 | [diff] [blame] | 517 | retval = sctp_stream_alloc_out(stream, outcnt, GFP_KERNEL); |
| 518 | if (retval) |
Xin Long | 242bd2d | 2017-02-09 01:18:20 +0800 | [diff] [blame] | 519 | goto out; |
Xin Long | 242bd2d | 2017-02-09 01:18:20 +0800 | [diff] [blame] | 520 | } |
| 521 | |
Xin Long | 242bd2d | 2017-02-09 01:18:20 +0800 | [diff] [blame] | 522 | chunk = sctp_make_strreset_addstrm(asoc, out, in); |
Wei Yongjun | dc82673 | 2017-10-31 13:28:16 +0000 | [diff] [blame] | 523 | if (!chunk) { |
| 524 | retval = -ENOMEM; |
Xin Long | 242bd2d | 2017-02-09 01:18:20 +0800 | [diff] [blame] | 525 | goto out; |
Wei Yongjun | dc82673 | 2017-10-31 13:28:16 +0000 | [diff] [blame] | 526 | } |
Xin Long | 242bd2d | 2017-02-09 01:18:20 +0800 | [diff] [blame] | 527 | |
| 528 | asoc->strreset_chunk = chunk; |
| 529 | sctp_chunk_hold(asoc->strreset_chunk); |
| 530 | |
| 531 | retval = sctp_send_reconf(asoc, chunk); |
| 532 | if (retval) { |
| 533 | sctp_chunk_put(asoc->strreset_chunk); |
| 534 | asoc->strreset_chunk = NULL; |
| 535 | goto out; |
| 536 | } |
| 537 | |
Xin Long | 242bd2d | 2017-02-09 01:18:20 +0800 | [diff] [blame] | 538 | stream->outcnt = outcnt; |
| 539 | |
| 540 | asoc->strreset_outstanding = !!out + !!in; |
| 541 | |
| 542 | out: |
| 543 | return retval; |
| 544 | } |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 545 | |
Xin Long | 3c91870 | 2017-06-30 11:52:16 +0800 | [diff] [blame] | 546 | static struct sctp_paramhdr *sctp_chunk_lookup_strreset_param( |
Xin Long | 1da4fc9 | 2017-10-28 19:43:54 +0800 | [diff] [blame] | 547 | struct sctp_association *asoc, __be32 resp_seq, |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 548 | __be16 type) |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 549 | { |
| 550 | struct sctp_chunk *chunk = asoc->strreset_chunk; |
| 551 | struct sctp_reconf_chunk *hdr; |
| 552 | union sctp_params param; |
| 553 | |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 554 | if (!chunk) |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 555 | return NULL; |
| 556 | |
| 557 | hdr = (struct sctp_reconf_chunk *)chunk->chunk_hdr; |
| 558 | sctp_walk_params(param, hdr, params) { |
| 559 | /* sctp_strreset_tsnreq is actually the basic structure |
| 560 | * of all stream reconf params, so it's safe to use it |
| 561 | * to access request_seq. |
| 562 | */ |
| 563 | struct sctp_strreset_tsnreq *req = param.v; |
| 564 | |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 565 | if ((!resp_seq || req->request_seq == resp_seq) && |
| 566 | (!type || type == req->param_hdr.type)) |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 567 | return param.v; |
| 568 | } |
| 569 | |
| 570 | return NULL; |
| 571 | } |
| 572 | |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 573 | static void sctp_update_strreset_result(struct sctp_association *asoc, |
| 574 | __u32 result) |
| 575 | { |
| 576 | asoc->strreset_result[1] = asoc->strreset_result[0]; |
| 577 | asoc->strreset_result[0] = result; |
| 578 | } |
| 579 | |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 580 | struct sctp_chunk *sctp_process_strreset_outreq( |
| 581 | struct sctp_association *asoc, |
| 582 | union sctp_params param, |
| 583 | struct sctp_ulpevent **evp) |
| 584 | { |
| 585 | struct sctp_strreset_outreq *outreq = param.v; |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 586 | struct sctp_stream *stream = &asoc->stream; |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 587 | __u32 result = SCTP_STRRESET_DENIED; |
Xin Long | 1da4fc9 | 2017-10-28 19:43:54 +0800 | [diff] [blame] | 588 | __be16 *str_p = NULL; |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 589 | __u32 request_seq; |
Xin Long | 2e6dc4d | 2019-01-22 02:39:34 +0800 | [diff] [blame] | 590 | __u16 i, nums; |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 591 | |
| 592 | request_seq = ntohl(outreq->request_seq); |
| 593 | |
| 594 | if (ntohl(outreq->send_reset_at_tsn) > |
| 595 | sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map)) { |
| 596 | result = SCTP_STRRESET_IN_PROGRESS; |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 597 | goto err; |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 598 | } |
| 599 | |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 600 | if (TSN_lt(asoc->strreset_inseq, request_seq) || |
| 601 | TSN_lt(request_seq, asoc->strreset_inseq - 2)) { |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 602 | result = SCTP_STRRESET_ERR_BAD_SEQNO; |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 603 | goto err; |
| 604 | } else if (TSN_lt(request_seq, asoc->strreset_inseq)) { |
| 605 | i = asoc->strreset_inseq - request_seq - 1; |
| 606 | result = asoc->strreset_result[i]; |
| 607 | goto err; |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 608 | } |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 609 | asoc->strreset_inseq++; |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 610 | |
| 611 | /* Check strreset_enable after inseq inc, as sender cannot tell |
| 612 | * the peer doesn't enable strreset after receiving response with |
| 613 | * result denied, as well as to keep consistent with bsd. |
| 614 | */ |
| 615 | if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ)) |
| 616 | goto out; |
| 617 | |
Xin Long | 2e6dc4d | 2019-01-22 02:39:34 +0800 | [diff] [blame] | 618 | nums = (ntohs(param.p->length) - sizeof(*outreq)) / sizeof(__u16); |
| 619 | str_p = outreq->list_of_streams; |
| 620 | for (i = 0; i < nums; i++) { |
| 621 | if (ntohs(str_p[i]) >= stream->incnt) { |
| 622 | result = SCTP_STRRESET_ERR_WRONG_SSN; |
| 623 | goto out; |
| 624 | } |
| 625 | } |
| 626 | |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 627 | if (asoc->strreset_chunk) { |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 628 | if (!sctp_chunk_lookup_strreset_param( |
| 629 | asoc, outreq->response_seq, |
| 630 | SCTP_PARAM_RESET_IN_REQUEST)) { |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 631 | /* same process with outstanding isn't 0 */ |
| 632 | result = SCTP_STRRESET_ERR_IN_PROGRESS; |
| 633 | goto out; |
| 634 | } |
| 635 | |
| 636 | asoc->strreset_outstanding--; |
| 637 | asoc->strreset_outseq++; |
| 638 | |
| 639 | if (!asoc->strreset_outstanding) { |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 640 | struct sctp_transport *t; |
| 641 | |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 642 | t = asoc->strreset_chunk->transport; |
| 643 | if (del_timer(&t->reconf_timer)) |
| 644 | sctp_transport_put(t); |
| 645 | |
| 646 | sctp_chunk_put(asoc->strreset_chunk); |
| 647 | asoc->strreset_chunk = NULL; |
| 648 | } |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 649 | } |
| 650 | |
Xin Long | 2e6dc4d | 2019-01-22 02:39:34 +0800 | [diff] [blame] | 651 | if (nums) |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 652 | for (i = 0; i < nums; i++) |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 653 | SCTP_SI(stream, ntohs(str_p[i]))->mid = 0; |
Xin Long | 2e6dc4d | 2019-01-22 02:39:34 +0800 | [diff] [blame] | 654 | else |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 655 | for (i = 0; i < stream->incnt; i++) |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 656 | SCTP_SI(stream, i)->mid = 0; |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 657 | |
| 658 | result = SCTP_STRRESET_PERFORMED; |
| 659 | |
| 660 | *evp = sctp_ulpevent_make_stream_reset_event(asoc, |
Xin Long | 2e6dc4d | 2019-01-22 02:39:34 +0800 | [diff] [blame] | 661 | SCTP_STREAM_RESET_INCOMING_SSN, nums, str_p, GFP_ATOMIC); |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 662 | |
| 663 | out: |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 664 | sctp_update_strreset_result(asoc, result); |
| 665 | err: |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 666 | return sctp_make_strreset_resp(asoc, result, request_seq); |
| 667 | } |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 668 | |
| 669 | struct sctp_chunk *sctp_process_strreset_inreq( |
| 670 | struct sctp_association *asoc, |
| 671 | union sctp_params param, |
| 672 | struct sctp_ulpevent **evp) |
| 673 | { |
| 674 | struct sctp_strreset_inreq *inreq = param.v; |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 675 | struct sctp_stream *stream = &asoc->stream; |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 676 | __u32 result = SCTP_STRRESET_DENIED; |
| 677 | struct sctp_chunk *chunk = NULL; |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 678 | __u32 request_seq; |
Xin Long | 1da4fc9 | 2017-10-28 19:43:54 +0800 | [diff] [blame] | 679 | __u16 i, nums; |
| 680 | __be16 *str_p; |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 681 | |
| 682 | request_seq = ntohl(inreq->request_seq); |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 683 | if (TSN_lt(asoc->strreset_inseq, request_seq) || |
| 684 | TSN_lt(request_seq, asoc->strreset_inseq - 2)) { |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 685 | result = SCTP_STRRESET_ERR_BAD_SEQNO; |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 686 | goto err; |
| 687 | } else if (TSN_lt(request_seq, asoc->strreset_inseq)) { |
| 688 | i = asoc->strreset_inseq - request_seq - 1; |
| 689 | result = asoc->strreset_result[i]; |
| 690 | if (result == SCTP_STRRESET_PERFORMED) |
| 691 | return NULL; |
| 692 | goto err; |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 693 | } |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 694 | asoc->strreset_inseq++; |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 695 | |
| 696 | if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ)) |
| 697 | goto out; |
| 698 | |
| 699 | if (asoc->strreset_outstanding) { |
| 700 | result = SCTP_STRRESET_ERR_IN_PROGRESS; |
| 701 | goto out; |
| 702 | } |
| 703 | |
Xin Long | 3aa623d | 2017-11-25 21:05:32 +0800 | [diff] [blame] | 704 | nums = (ntohs(param.p->length) - sizeof(*inreq)) / sizeof(__u16); |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 705 | str_p = inreq->list_of_streams; |
| 706 | for (i = 0; i < nums; i++) { |
| 707 | if (ntohs(str_p[i]) >= stream->outcnt) { |
| 708 | result = SCTP_STRRESET_ERR_WRONG_SSN; |
| 709 | goto out; |
| 710 | } |
| 711 | } |
| 712 | |
Xin Long | d570a59 | 2017-11-25 21:05:33 +0800 | [diff] [blame] | 713 | if (!sctp_stream_outq_is_empty(stream, nums, str_p)) { |
| 714 | result = SCTP_STRRESET_IN_PROGRESS; |
| 715 | asoc->strreset_inseq--; |
| 716 | goto err; |
| 717 | } |
| 718 | |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 719 | chunk = sctp_make_strreset_req(asoc, nums, str_p, 1, 0); |
| 720 | if (!chunk) |
| 721 | goto out; |
| 722 | |
| 723 | if (nums) |
| 724 | for (i = 0; i < nums; i++) |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 725 | SCTP_SO(stream, ntohs(str_p[i]))->state = |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 726 | SCTP_STREAM_CLOSED; |
| 727 | else |
| 728 | for (i = 0; i < stream->outcnt; i++) |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 729 | SCTP_SO(stream, i)->state = SCTP_STREAM_CLOSED; |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 730 | |
| 731 | asoc->strreset_chunk = chunk; |
| 732 | asoc->strreset_outstanding = 1; |
| 733 | sctp_chunk_hold(asoc->strreset_chunk); |
| 734 | |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 735 | result = SCTP_STRRESET_PERFORMED; |
| 736 | |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 737 | out: |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 738 | sctp_update_strreset_result(asoc, result); |
| 739 | err: |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 740 | if (!chunk) |
| 741 | chunk = sctp_make_strreset_resp(asoc, result, request_seq); |
| 742 | |
| 743 | return chunk; |
| 744 | } |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 745 | |
| 746 | struct sctp_chunk *sctp_process_strreset_tsnreq( |
| 747 | struct sctp_association *asoc, |
| 748 | union sctp_params param, |
| 749 | struct sctp_ulpevent **evp) |
| 750 | { |
| 751 | __u32 init_tsn = 0, next_tsn = 0, max_tsn_seen; |
| 752 | struct sctp_strreset_tsnreq *tsnreq = param.v; |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 753 | struct sctp_stream *stream = &asoc->stream; |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 754 | __u32 result = SCTP_STRRESET_DENIED; |
| 755 | __u32 request_seq; |
| 756 | __u16 i; |
| 757 | |
| 758 | request_seq = ntohl(tsnreq->request_seq); |
Xin Long | 6c80138 | 2017-04-15 22:00:29 +0800 | [diff] [blame] | 759 | if (TSN_lt(asoc->strreset_inseq, request_seq) || |
| 760 | TSN_lt(request_seq, asoc->strreset_inseq - 2)) { |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 761 | result = SCTP_STRRESET_ERR_BAD_SEQNO; |
Xin Long | 6c80138 | 2017-04-15 22:00:29 +0800 | [diff] [blame] | 762 | goto err; |
| 763 | } else if (TSN_lt(request_seq, asoc->strreset_inseq)) { |
| 764 | i = asoc->strreset_inseq - request_seq - 1; |
| 765 | result = asoc->strreset_result[i]; |
| 766 | if (result == SCTP_STRRESET_PERFORMED) { |
Xin Long | 52a3958 | 2017-11-25 21:05:36 +0800 | [diff] [blame] | 767 | next_tsn = asoc->ctsn_ack_point + 1; |
Xin Long | 6c80138 | 2017-04-15 22:00:29 +0800 | [diff] [blame] | 768 | init_tsn = |
| 769 | sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + 1; |
| 770 | } |
| 771 | goto err; |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 772 | } |
Xin Long | 5c6144a | 2017-11-25 21:05:34 +0800 | [diff] [blame] | 773 | |
| 774 | if (!sctp_outq_is_empty(&asoc->outqueue)) { |
| 775 | result = SCTP_STRRESET_IN_PROGRESS; |
| 776 | goto err; |
| 777 | } |
| 778 | |
Xin Long | 6c80138 | 2017-04-15 22:00:29 +0800 | [diff] [blame] | 779 | asoc->strreset_inseq++; |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 780 | |
| 781 | if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_ASSOC_REQ)) |
| 782 | goto out; |
| 783 | |
| 784 | if (asoc->strreset_outstanding) { |
| 785 | result = SCTP_STRRESET_ERR_IN_PROGRESS; |
| 786 | goto out; |
| 787 | } |
| 788 | |
Xin Long | 159f2a7 | 2017-11-25 21:05:35 +0800 | [diff] [blame] | 789 | /* G4: The same processing as though a FWD-TSN chunk (as defined in |
| 790 | * [RFC3758]) with all streams affected and a new cumulative TSN |
| 791 | * ACK of the Receiver's Next TSN minus 1 were received MUST be |
| 792 | * performed. |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 793 | */ |
| 794 | max_tsn_seen = sctp_tsnmap_get_max_tsn_seen(&asoc->peer.tsn_map); |
Xin Long | 47b20a8 | 2017-12-15 00:41:28 +0800 | [diff] [blame] | 795 | asoc->stream.si->report_ftsn(&asoc->ulpq, max_tsn_seen); |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 796 | |
| 797 | /* G1: Compute an appropriate value for the Receiver's Next TSN -- the |
| 798 | * TSN that the peer should use to send the next DATA chunk. The |
| 799 | * value SHOULD be the smallest TSN not acknowledged by the |
| 800 | * receiver of the request plus 2^31. |
| 801 | */ |
| 802 | init_tsn = sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + (1 << 31); |
| 803 | sctp_tsnmap_init(&asoc->peer.tsn_map, SCTP_TSN_MAP_INITIAL, |
| 804 | init_tsn, GFP_ATOMIC); |
| 805 | |
Xin Long | 159f2a7 | 2017-11-25 21:05:35 +0800 | [diff] [blame] | 806 | /* G3: The same processing as though a SACK chunk with no gap report |
| 807 | * and a cumulative TSN ACK of the Sender's Next TSN minus 1 were |
| 808 | * received MUST be performed. |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 809 | */ |
| 810 | sctp_outq_free(&asoc->outqueue); |
| 811 | |
| 812 | /* G2: Compute an appropriate value for the local endpoint's next TSN, |
| 813 | * i.e., the next TSN assigned by the receiver of the SSN/TSN reset |
| 814 | * chunk. The value SHOULD be the highest TSN sent by the receiver |
| 815 | * of the request plus 1. |
| 816 | */ |
| 817 | next_tsn = asoc->next_tsn; |
| 818 | asoc->ctsn_ack_point = next_tsn - 1; |
| 819 | asoc->adv_peer_ack_point = asoc->ctsn_ack_point; |
| 820 | |
| 821 | /* G5: The next expected and outgoing SSNs MUST be reset to 0 for all |
| 822 | * incoming and outgoing streams. |
| 823 | */ |
Xin Long | 107e242 | 2017-12-15 00:41:31 +0800 | [diff] [blame] | 824 | for (i = 0; i < stream->outcnt; i++) { |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 825 | SCTP_SO(stream, i)->mid = 0; |
| 826 | SCTP_SO(stream, i)->mid_uo = 0; |
Xin Long | 107e242 | 2017-12-15 00:41:31 +0800 | [diff] [blame] | 827 | } |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 828 | for (i = 0; i < stream->incnt; i++) |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 829 | SCTP_SI(stream, i)->mid = 0; |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 830 | |
| 831 | result = SCTP_STRRESET_PERFORMED; |
| 832 | |
| 833 | *evp = sctp_ulpevent_make_assoc_reset_event(asoc, 0, init_tsn, |
| 834 | next_tsn, GFP_ATOMIC); |
| 835 | |
| 836 | out: |
Xin Long | 6c80138 | 2017-04-15 22:00:29 +0800 | [diff] [blame] | 837 | sctp_update_strreset_result(asoc, result); |
| 838 | err: |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 839 | return sctp_make_strreset_tsnresp(asoc, result, request_seq, |
| 840 | next_tsn, init_tsn); |
| 841 | } |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 842 | |
| 843 | struct sctp_chunk *sctp_process_strreset_addstrm_out( |
| 844 | struct sctp_association *asoc, |
| 845 | union sctp_params param, |
| 846 | struct sctp_ulpevent **evp) |
| 847 | { |
| 848 | struct sctp_strreset_addstrm *addstrm = param.v; |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 849 | struct sctp_stream *stream = &asoc->stream; |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 850 | __u32 result = SCTP_STRRESET_DENIED; |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 851 | __u32 request_seq, incnt; |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 852 | __u16 in, i; |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 853 | |
| 854 | request_seq = ntohl(addstrm->request_seq); |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 855 | if (TSN_lt(asoc->strreset_inseq, request_seq) || |
| 856 | TSN_lt(request_seq, asoc->strreset_inseq - 2)) { |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 857 | result = SCTP_STRRESET_ERR_BAD_SEQNO; |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 858 | goto err; |
| 859 | } else if (TSN_lt(request_seq, asoc->strreset_inseq)) { |
| 860 | i = asoc->strreset_inseq - request_seq - 1; |
| 861 | result = asoc->strreset_result[i]; |
| 862 | goto err; |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 863 | } |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 864 | asoc->strreset_inseq++; |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 865 | |
| 866 | if (!(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ)) |
| 867 | goto out; |
| 868 | |
Xin Long | 8220c87 | 2019-01-22 02:40:12 +0800 | [diff] [blame] | 869 | in = ntohs(addstrm->number_of_streams); |
| 870 | incnt = stream->incnt + in; |
| 871 | if (!in || incnt > SCTP_MAX_STREAM) |
| 872 | goto out; |
| 873 | |
| 874 | if (sctp_stream_alloc_in(stream, incnt, GFP_ATOMIC)) |
| 875 | goto out; |
| 876 | |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 877 | if (asoc->strreset_chunk) { |
| 878 | if (!sctp_chunk_lookup_strreset_param( |
| 879 | asoc, 0, SCTP_PARAM_RESET_ADD_IN_STREAMS)) { |
| 880 | /* same process with outstanding isn't 0 */ |
| 881 | result = SCTP_STRRESET_ERR_IN_PROGRESS; |
| 882 | goto out; |
| 883 | } |
| 884 | |
| 885 | asoc->strreset_outstanding--; |
| 886 | asoc->strreset_outseq++; |
| 887 | |
| 888 | if (!asoc->strreset_outstanding) { |
| 889 | struct sctp_transport *t; |
| 890 | |
| 891 | t = asoc->strreset_chunk->transport; |
| 892 | if (del_timer(&t->reconf_timer)) |
| 893 | sctp_transport_put(t); |
| 894 | |
| 895 | sctp_chunk_put(asoc->strreset_chunk); |
| 896 | asoc->strreset_chunk = NULL; |
| 897 | } |
| 898 | } |
| 899 | |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 900 | stream->incnt = incnt; |
| 901 | |
| 902 | result = SCTP_STRRESET_PERFORMED; |
| 903 | |
| 904 | *evp = sctp_ulpevent_make_stream_change_event(asoc, |
| 905 | 0, ntohs(addstrm->number_of_streams), 0, GFP_ATOMIC); |
| 906 | |
| 907 | out: |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 908 | sctp_update_strreset_result(asoc, result); |
| 909 | err: |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 910 | return sctp_make_strreset_resp(asoc, result, request_seq); |
| 911 | } |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 912 | |
| 913 | struct sctp_chunk *sctp_process_strreset_addstrm_in( |
| 914 | struct sctp_association *asoc, |
| 915 | union sctp_params param, |
| 916 | struct sctp_ulpevent **evp) |
| 917 | { |
| 918 | struct sctp_strreset_addstrm *addstrm = param.v; |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 919 | struct sctp_stream *stream = &asoc->stream; |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 920 | __u32 result = SCTP_STRRESET_DENIED; |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 921 | struct sctp_chunk *chunk = NULL; |
| 922 | __u32 request_seq, outcnt; |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 923 | __u16 out, i; |
Marcelo Ricardo Leitner | e090abd | 2017-10-03 19:20:09 -0300 | [diff] [blame] | 924 | int ret; |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 925 | |
| 926 | request_seq = ntohl(addstrm->request_seq); |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 927 | if (TSN_lt(asoc->strreset_inseq, request_seq) || |
| 928 | TSN_lt(request_seq, asoc->strreset_inseq - 2)) { |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 929 | result = SCTP_STRRESET_ERR_BAD_SEQNO; |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 930 | goto err; |
| 931 | } else if (TSN_lt(request_seq, asoc->strreset_inseq)) { |
| 932 | i = asoc->strreset_inseq - request_seq - 1; |
| 933 | result = asoc->strreset_result[i]; |
| 934 | if (result == SCTP_STRRESET_PERFORMED) |
| 935 | return NULL; |
| 936 | goto err; |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 937 | } |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 938 | asoc->strreset_inseq++; |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 939 | |
| 940 | if (!(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ)) |
| 941 | goto out; |
| 942 | |
| 943 | if (asoc->strreset_outstanding) { |
| 944 | result = SCTP_STRRESET_ERR_IN_PROGRESS; |
| 945 | goto out; |
| 946 | } |
| 947 | |
| 948 | out = ntohs(addstrm->number_of_streams); |
| 949 | outcnt = stream->outcnt + out; |
| 950 | if (!out || outcnt > SCTP_MAX_STREAM) |
| 951 | goto out; |
| 952 | |
Marcelo Ricardo Leitner | e090abd | 2017-10-03 19:20:09 -0300 | [diff] [blame] | 953 | ret = sctp_stream_alloc_out(stream, outcnt, GFP_ATOMIC); |
| 954 | if (ret) |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 955 | goto out; |
| 956 | |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 957 | chunk = sctp_make_strreset_addstrm(asoc, out, 0); |
| 958 | if (!chunk) |
| 959 | goto out; |
| 960 | |
| 961 | asoc->strreset_chunk = chunk; |
| 962 | asoc->strreset_outstanding = 1; |
| 963 | sctp_chunk_hold(asoc->strreset_chunk); |
| 964 | |
| 965 | stream->outcnt = outcnt; |
| 966 | |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 967 | result = SCTP_STRRESET_PERFORMED; |
| 968 | |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 969 | out: |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 970 | sctp_update_strreset_result(asoc, result); |
| 971 | err: |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 972 | if (!chunk) |
| 973 | chunk = sctp_make_strreset_resp(asoc, result, request_seq); |
| 974 | |
| 975 | return chunk; |
| 976 | } |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 977 | |
| 978 | struct sctp_chunk *sctp_process_strreset_resp( |
| 979 | struct sctp_association *asoc, |
| 980 | union sctp_params param, |
| 981 | struct sctp_ulpevent **evp) |
| 982 | { |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 983 | struct sctp_stream *stream = &asoc->stream; |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 984 | struct sctp_strreset_resp *resp = param.v; |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 985 | struct sctp_transport *t; |
| 986 | __u16 i, nums, flags = 0; |
Xin Long | 3c91870 | 2017-06-30 11:52:16 +0800 | [diff] [blame] | 987 | struct sctp_paramhdr *req; |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 988 | __u32 result; |
| 989 | |
| 990 | req = sctp_chunk_lookup_strreset_param(asoc, resp->response_seq, 0); |
| 991 | if (!req) |
| 992 | return NULL; |
| 993 | |
| 994 | result = ntohl(resp->result); |
| 995 | if (result != SCTP_STRRESET_PERFORMED) { |
| 996 | /* if in progress, do nothing but retransmit */ |
| 997 | if (result == SCTP_STRRESET_IN_PROGRESS) |
| 998 | return NULL; |
| 999 | else if (result == SCTP_STRRESET_DENIED) |
| 1000 | flags = SCTP_STREAM_RESET_DENIED; |
| 1001 | else |
| 1002 | flags = SCTP_STREAM_RESET_FAILED; |
| 1003 | } |
| 1004 | |
| 1005 | if (req->type == SCTP_PARAM_RESET_OUT_REQUEST) { |
| 1006 | struct sctp_strreset_outreq *outreq; |
Xin Long | 1da4fc9 | 2017-10-28 19:43:54 +0800 | [diff] [blame] | 1007 | __be16 *str_p; |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1008 | |
| 1009 | outreq = (struct sctp_strreset_outreq *)req; |
Xin Long | edb12f2 | 2017-04-15 21:56:57 +0800 | [diff] [blame] | 1010 | str_p = outreq->list_of_streams; |
Xin Long | 3aa623d | 2017-11-25 21:05:32 +0800 | [diff] [blame] | 1011 | nums = (ntohs(outreq->param_hdr.length) - sizeof(*outreq)) / |
| 1012 | sizeof(__u16); |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1013 | |
| 1014 | if (result == SCTP_STRRESET_PERFORMED) { |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 1015 | struct sctp_stream_out *sout; |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1016 | if (nums) { |
Xin Long | 107e242 | 2017-12-15 00:41:31 +0800 | [diff] [blame] | 1017 | for (i = 0; i < nums; i++) { |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 1018 | sout = SCTP_SO(stream, ntohs(str_p[i])); |
| 1019 | sout->mid = 0; |
| 1020 | sout->mid_uo = 0; |
Xin Long | 107e242 | 2017-12-15 00:41:31 +0800 | [diff] [blame] | 1021 | } |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1022 | } else { |
Xin Long | 107e242 | 2017-12-15 00:41:31 +0800 | [diff] [blame] | 1023 | for (i = 0; i < stream->outcnt; i++) { |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 1024 | sout = SCTP_SO(stream, i); |
| 1025 | sout->mid = 0; |
| 1026 | sout->mid_uo = 0; |
Xin Long | 107e242 | 2017-12-15 00:41:31 +0800 | [diff] [blame] | 1027 | } |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1028 | } |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1029 | } |
| 1030 | |
Xin Long | 2e6dc4d | 2019-01-22 02:39:34 +0800 | [diff] [blame] | 1031 | flags |= SCTP_STREAM_RESET_OUTGOING_SSN; |
| 1032 | |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1033 | for (i = 0; i < stream->outcnt; i++) |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 1034 | SCTP_SO(stream, i)->state = SCTP_STREAM_OPEN; |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1035 | |
| 1036 | *evp = sctp_ulpevent_make_stream_reset_event(asoc, flags, |
| 1037 | nums, str_p, GFP_ATOMIC); |
| 1038 | } else if (req->type == SCTP_PARAM_RESET_IN_REQUEST) { |
| 1039 | struct sctp_strreset_inreq *inreq; |
Xin Long | 1da4fc9 | 2017-10-28 19:43:54 +0800 | [diff] [blame] | 1040 | __be16 *str_p; |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1041 | |
| 1042 | /* if the result is performed, it's impossible for inreq */ |
| 1043 | if (result == SCTP_STRRESET_PERFORMED) |
| 1044 | return NULL; |
| 1045 | |
| 1046 | inreq = (struct sctp_strreset_inreq *)req; |
Xin Long | edb12f2 | 2017-04-15 21:56:57 +0800 | [diff] [blame] | 1047 | str_p = inreq->list_of_streams; |
Xin Long | 3aa623d | 2017-11-25 21:05:32 +0800 | [diff] [blame] | 1048 | nums = (ntohs(inreq->param_hdr.length) - sizeof(*inreq)) / |
| 1049 | sizeof(__u16); |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1050 | |
Xin Long | 2e6dc4d | 2019-01-22 02:39:34 +0800 | [diff] [blame] | 1051 | flags |= SCTP_STREAM_RESET_INCOMING_SSN; |
| 1052 | |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1053 | *evp = sctp_ulpevent_make_stream_reset_event(asoc, flags, |
| 1054 | nums, str_p, GFP_ATOMIC); |
| 1055 | } else if (req->type == SCTP_PARAM_RESET_TSN_REQUEST) { |
| 1056 | struct sctp_strreset_resptsn *resptsn; |
| 1057 | __u32 stsn, rtsn; |
| 1058 | |
| 1059 | /* check for resptsn, as sctp_verify_reconf didn't do it*/ |
| 1060 | if (ntohs(param.p->length) != sizeof(*resptsn)) |
| 1061 | return NULL; |
| 1062 | |
| 1063 | resptsn = (struct sctp_strreset_resptsn *)resp; |
| 1064 | stsn = ntohl(resptsn->senders_next_tsn); |
| 1065 | rtsn = ntohl(resptsn->receivers_next_tsn); |
| 1066 | |
| 1067 | if (result == SCTP_STRRESET_PERFORMED) { |
| 1068 | __u32 mtsn = sctp_tsnmap_get_max_tsn_seen( |
| 1069 | &asoc->peer.tsn_map); |
Xin Long | 159f2a7 | 2017-11-25 21:05:35 +0800 | [diff] [blame] | 1070 | LIST_HEAD(temp); |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1071 | |
Xin Long | 47b20a8 | 2017-12-15 00:41:28 +0800 | [diff] [blame] | 1072 | asoc->stream.si->report_ftsn(&asoc->ulpq, mtsn); |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1073 | |
| 1074 | sctp_tsnmap_init(&asoc->peer.tsn_map, |
| 1075 | SCTP_TSN_MAP_INITIAL, |
| 1076 | stsn, GFP_ATOMIC); |
| 1077 | |
Xin Long | 159f2a7 | 2017-11-25 21:05:35 +0800 | [diff] [blame] | 1078 | /* Clean up sacked and abandoned queues only. As the |
| 1079 | * out_chunk_list may not be empty, splice it to temp, |
| 1080 | * then get it back after sctp_outq_free is done. |
| 1081 | */ |
| 1082 | list_splice_init(&asoc->outqueue.out_chunk_list, &temp); |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1083 | sctp_outq_free(&asoc->outqueue); |
Xin Long | 159f2a7 | 2017-11-25 21:05:35 +0800 | [diff] [blame] | 1084 | list_splice_init(&temp, &asoc->outqueue.out_chunk_list); |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1085 | |
| 1086 | asoc->next_tsn = rtsn; |
| 1087 | asoc->ctsn_ack_point = asoc->next_tsn - 1; |
| 1088 | asoc->adv_peer_ack_point = asoc->ctsn_ack_point; |
| 1089 | |
Xin Long | 107e242 | 2017-12-15 00:41:31 +0800 | [diff] [blame] | 1090 | for (i = 0; i < stream->outcnt; i++) { |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 1091 | SCTP_SO(stream, i)->mid = 0; |
| 1092 | SCTP_SO(stream, i)->mid_uo = 0; |
Xin Long | 107e242 | 2017-12-15 00:41:31 +0800 | [diff] [blame] | 1093 | } |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1094 | for (i = 0; i < stream->incnt; i++) |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 1095 | SCTP_SI(stream, i)->mid = 0; |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | for (i = 0; i < stream->outcnt; i++) |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 1099 | SCTP_SO(stream, i)->state = SCTP_STREAM_OPEN; |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1100 | |
| 1101 | *evp = sctp_ulpevent_make_assoc_reset_event(asoc, flags, |
| 1102 | stsn, rtsn, GFP_ATOMIC); |
| 1103 | } else if (req->type == SCTP_PARAM_RESET_ADD_OUT_STREAMS) { |
| 1104 | struct sctp_strreset_addstrm *addstrm; |
| 1105 | __u16 number; |
| 1106 | |
| 1107 | addstrm = (struct sctp_strreset_addstrm *)req; |
| 1108 | nums = ntohs(addstrm->number_of_streams); |
| 1109 | number = stream->outcnt - nums; |
| 1110 | |
| 1111 | if (result == SCTP_STRRESET_PERFORMED) |
| 1112 | for (i = number; i < stream->outcnt; i++) |
Konstantin Khorenko | 05364ca | 2018-08-10 20:11:42 +0300 | [diff] [blame] | 1113 | SCTP_SO(stream, i)->state = SCTP_STREAM_OPEN; |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1114 | else |
| 1115 | stream->outcnt = number; |
| 1116 | |
| 1117 | *evp = sctp_ulpevent_make_stream_change_event(asoc, flags, |
| 1118 | 0, nums, GFP_ATOMIC); |
| 1119 | } else if (req->type == SCTP_PARAM_RESET_ADD_IN_STREAMS) { |
| 1120 | struct sctp_strreset_addstrm *addstrm; |
| 1121 | |
| 1122 | /* if the result is performed, it's impossible for addstrm in |
| 1123 | * request. |
| 1124 | */ |
| 1125 | if (result == SCTP_STRRESET_PERFORMED) |
| 1126 | return NULL; |
| 1127 | |
| 1128 | addstrm = (struct sctp_strreset_addstrm *)req; |
| 1129 | nums = ntohs(addstrm->number_of_streams); |
| 1130 | |
| 1131 | *evp = sctp_ulpevent_make_stream_change_event(asoc, flags, |
| 1132 | nums, 0, GFP_ATOMIC); |
| 1133 | } |
| 1134 | |
| 1135 | asoc->strreset_outstanding--; |
| 1136 | asoc->strreset_outseq++; |
| 1137 | |
| 1138 | /* remove everything for this reconf request */ |
| 1139 | if (!asoc->strreset_outstanding) { |
| 1140 | t = asoc->strreset_chunk->transport; |
| 1141 | if (del_timer(&t->reconf_timer)) |
| 1142 | sctp_transport_put(t); |
| 1143 | |
| 1144 | sctp_chunk_put(asoc->strreset_chunk); |
| 1145 | asoc->strreset_chunk = NULL; |
| 1146 | } |
| 1147 | |
| 1148 | return NULL; |
| 1149 | } |