hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/net/sctp/chunk.c
....@@ -1,25 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* SCTP kernel implementation
23 * (C) Copyright IBM Corp. 2003, 2004
34 *
45 * This file is part of the SCTP kernel implementation
56 *
67 * This file contains the code relating the chunk abstraction.
7
- *
8
- * This SCTP implementation is free software;
9
- * you can redistribute it and/or modify it under the terms of
10
- * the GNU General Public License as published by
11
- * the Free Software Foundation; either version 2, or (at your option)
12
- * any later version.
13
- *
14
- * This SCTP implementation is distributed in the hope that it
15
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16
- * ************************
17
- * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
- * See the GNU General Public License for more details.
19
- *
20
- * You should have received a copy of the GNU General Public License
21
- * along with GNU CC; see the file COPYING. If not, see
22
- * <http://www.gnu.org/licenses/>.
238 *
249 * Please send any bug reports or fixes you make to the
2510 * email address(es):
....@@ -86,43 +71,39 @@
8671 /* Final destructruction of datamsg memory. */
8772 static void sctp_datamsg_destroy(struct sctp_datamsg *msg)
8873 {
74
+ struct sctp_association *asoc = NULL;
8975 struct list_head *pos, *temp;
9076 struct sctp_chunk *chunk;
91
- struct sctp_sock *sp;
9277 struct sctp_ulpevent *ev;
93
- struct sctp_association *asoc = NULL;
94
- int error = 0, notify;
95
-
96
- /* If we failed, we may need to notify. */
97
- notify = msg->send_failed ? -1 : 0;
78
+ int error, sent;
9879
9980 /* Release all references. */
10081 list_for_each_safe(pos, temp, &msg->chunks) {
10182 list_del_init(pos);
10283 chunk = list_entry(pos, struct sctp_chunk, frag_list);
103
- /* Check whether we _really_ need to notify. */
104
- if (notify < 0) {
105
- asoc = chunk->asoc;
106
- if (msg->send_error)
107
- error = msg->send_error;
108
- else
109
- error = asoc->outqueue.error;
11084
111
- sp = sctp_sk(asoc->base.sk);
112
- notify = sctp_ulpevent_type_enabled(SCTP_SEND_FAILED,
113
- &sp->subscribe);
85
+ if (!msg->send_failed) {
86
+ sctp_chunk_put(chunk);
87
+ continue;
11488 }
11589
116
- /* Generate a SEND FAILED event only if enabled. */
117
- if (notify > 0) {
118
- int sent;
119
- if (chunk->has_tsn)
120
- sent = SCTP_DATA_SENT;
121
- else
122
- sent = SCTP_DATA_UNSENT;
90
+ asoc = chunk->asoc;
91
+ error = msg->send_error ?: asoc->outqueue.error;
92
+ sent = chunk->has_tsn ? SCTP_DATA_SENT : SCTP_DATA_UNSENT;
12393
94
+ if (sctp_ulpevent_type_enabled(asoc->subscribe,
95
+ SCTP_SEND_FAILED)) {
12496 ev = sctp_ulpevent_make_send_failed(asoc, chunk, sent,
12597 error, GFP_ATOMIC);
98
+ if (ev)
99
+ asoc->stream.si->enqueue_event(&asoc->ulpq, ev);
100
+ }
101
+
102
+ if (sctp_ulpevent_type_enabled(asoc->subscribe,
103
+ SCTP_SEND_FAILED_EVENT)) {
104
+ ev = sctp_ulpevent_make_send_failed_event(asoc, chunk,
105
+ sent, error,
106
+ GFP_ATOMIC);
126107 if (ev)
127108 asoc->stream.si->enqueue_event(&asoc->ulpq, ev);
128109 }
....@@ -194,11 +175,11 @@
194175 if (unlikely(!max_data)) {
195176 max_data = sctp_min_frag_point(sctp_sk(asoc->base.sk),
196177 sctp_datachk_len(&asoc->stream));
197
- pr_warn_ratelimited("%s: asoc:%p frag_point is zero, forcing max_data to default minimum (%Zu)",
178
+ pr_warn_ratelimited("%s: asoc:%p frag_point is zero, forcing max_data to default minimum (%zu)",
198179 __func__, asoc, max_data);
199180 }
200181
201
- /* If the the peer requested that we authenticate DATA chunks
182
+ /* If the peer requested that we authenticate DATA chunks
202183 * we need to account for bundling of the AUTH chunks along with
203184 * DATA.
204185 */
....@@ -244,7 +225,7 @@
244225 if (msg_len >= first_len) {
245226 msg->can_delay = 0;
246227 if (msg_len > first_len)
247
- SCTP_INC_STATS(sock_net(asoc->base.sk),
228
+ SCTP_INC_STATS(asoc->base.net,
248229 SCTP_MIB_FRAGUSRMSGS);
249230 } else {
250231 /* Which may be the only one... */