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