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