xref: /OK3568_Linux_fs/kernel/net/sctp/chunk.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /* SCTP kernel implementation
3*4882a593Smuzhiyun  * (C) Copyright IBM Corp. 2003, 2004
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * This file is part of the SCTP kernel implementation
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * This file contains the code relating the chunk abstraction.
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * Please send any bug reports or fixes you make to the
10*4882a593Smuzhiyun  * email address(es):
11*4882a593Smuzhiyun  *    lksctp developers <linux-sctp@vger.kernel.org>
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  * Written or modified by:
14*4882a593Smuzhiyun  *    Jon Grimm             <jgrimm@us.ibm.com>
15*4882a593Smuzhiyun  *    Sridhar Samudrala     <sri@us.ibm.com>
16*4882a593Smuzhiyun  */
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #include <linux/types.h>
21*4882a593Smuzhiyun #include <linux/kernel.h>
22*4882a593Smuzhiyun #include <linux/net.h>
23*4882a593Smuzhiyun #include <linux/inet.h>
24*4882a593Smuzhiyun #include <linux/skbuff.h>
25*4882a593Smuzhiyun #include <linux/slab.h>
26*4882a593Smuzhiyun #include <net/sock.h>
27*4882a593Smuzhiyun #include <net/sctp/sctp.h>
28*4882a593Smuzhiyun #include <net/sctp/sm.h>
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun /* This file is mostly in anticipation of future work, but initially
31*4882a593Smuzhiyun  * populate with fragment tracking for an outbound message.
32*4882a593Smuzhiyun  */
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun /* Initialize datamsg from memory. */
sctp_datamsg_init(struct sctp_datamsg * msg)35*4882a593Smuzhiyun static void sctp_datamsg_init(struct sctp_datamsg *msg)
36*4882a593Smuzhiyun {
37*4882a593Smuzhiyun 	refcount_set(&msg->refcnt, 1);
38*4882a593Smuzhiyun 	msg->send_failed = 0;
39*4882a593Smuzhiyun 	msg->send_error = 0;
40*4882a593Smuzhiyun 	msg->can_delay = 1;
41*4882a593Smuzhiyun 	msg->abandoned = 0;
42*4882a593Smuzhiyun 	msg->expires_at = 0;
43*4882a593Smuzhiyun 	INIT_LIST_HEAD(&msg->chunks);
44*4882a593Smuzhiyun }
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun /* Allocate and initialize datamsg. */
sctp_datamsg_new(gfp_t gfp)47*4882a593Smuzhiyun static struct sctp_datamsg *sctp_datamsg_new(gfp_t gfp)
48*4882a593Smuzhiyun {
49*4882a593Smuzhiyun 	struct sctp_datamsg *msg;
50*4882a593Smuzhiyun 	msg = kmalloc(sizeof(struct sctp_datamsg), gfp);
51*4882a593Smuzhiyun 	if (msg) {
52*4882a593Smuzhiyun 		sctp_datamsg_init(msg);
53*4882a593Smuzhiyun 		SCTP_DBG_OBJCNT_INC(datamsg);
54*4882a593Smuzhiyun 	}
55*4882a593Smuzhiyun 	return msg;
56*4882a593Smuzhiyun }
57*4882a593Smuzhiyun 
sctp_datamsg_free(struct sctp_datamsg * msg)58*4882a593Smuzhiyun void sctp_datamsg_free(struct sctp_datamsg *msg)
59*4882a593Smuzhiyun {
60*4882a593Smuzhiyun 	struct sctp_chunk *chunk;
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun 	/* This doesn't have to be a _safe vairant because
63*4882a593Smuzhiyun 	 * sctp_chunk_free() only drops the refs.
64*4882a593Smuzhiyun 	 */
65*4882a593Smuzhiyun 	list_for_each_entry(chunk, &msg->chunks, frag_list)
66*4882a593Smuzhiyun 		sctp_chunk_free(chunk);
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun 	sctp_datamsg_put(msg);
69*4882a593Smuzhiyun }
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun /* Final destructruction of datamsg memory. */
sctp_datamsg_destroy(struct sctp_datamsg * msg)72*4882a593Smuzhiyun static void sctp_datamsg_destroy(struct sctp_datamsg *msg)
73*4882a593Smuzhiyun {
74*4882a593Smuzhiyun 	struct sctp_association *asoc = NULL;
75*4882a593Smuzhiyun 	struct list_head *pos, *temp;
76*4882a593Smuzhiyun 	struct sctp_chunk *chunk;
77*4882a593Smuzhiyun 	struct sctp_ulpevent *ev;
78*4882a593Smuzhiyun 	int error, sent;
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun 	/* Release all references. */
81*4882a593Smuzhiyun 	list_for_each_safe(pos, temp, &msg->chunks) {
82*4882a593Smuzhiyun 		list_del_init(pos);
83*4882a593Smuzhiyun 		chunk = list_entry(pos, struct sctp_chunk, frag_list);
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun 		if (!msg->send_failed) {
86*4882a593Smuzhiyun 			sctp_chunk_put(chunk);
87*4882a593Smuzhiyun 			continue;
88*4882a593Smuzhiyun 		}
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun 		asoc = chunk->asoc;
91*4882a593Smuzhiyun 		error = msg->send_error ?: asoc->outqueue.error;
92*4882a593Smuzhiyun 		sent = chunk->has_tsn ? SCTP_DATA_SENT : SCTP_DATA_UNSENT;
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun 		if (sctp_ulpevent_type_enabled(asoc->subscribe,
95*4882a593Smuzhiyun 					       SCTP_SEND_FAILED)) {
96*4882a593Smuzhiyun 			ev = sctp_ulpevent_make_send_failed(asoc, chunk, sent,
97*4882a593Smuzhiyun 							    error, GFP_ATOMIC);
98*4882a593Smuzhiyun 			if (ev)
99*4882a593Smuzhiyun 				asoc->stream.si->enqueue_event(&asoc->ulpq, ev);
100*4882a593Smuzhiyun 		}
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun 		if (sctp_ulpevent_type_enabled(asoc->subscribe,
103*4882a593Smuzhiyun 					       SCTP_SEND_FAILED_EVENT)) {
104*4882a593Smuzhiyun 			ev = sctp_ulpevent_make_send_failed_event(asoc, chunk,
105*4882a593Smuzhiyun 								  sent, error,
106*4882a593Smuzhiyun 								  GFP_ATOMIC);
107*4882a593Smuzhiyun 			if (ev)
108*4882a593Smuzhiyun 				asoc->stream.si->enqueue_event(&asoc->ulpq, ev);
109*4882a593Smuzhiyun 		}
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun 		sctp_chunk_put(chunk);
112*4882a593Smuzhiyun 	}
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun 	SCTP_DBG_OBJCNT_DEC(datamsg);
115*4882a593Smuzhiyun 	kfree(msg);
116*4882a593Smuzhiyun }
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun /* Hold a reference. */
sctp_datamsg_hold(struct sctp_datamsg * msg)119*4882a593Smuzhiyun static void sctp_datamsg_hold(struct sctp_datamsg *msg)
120*4882a593Smuzhiyun {
121*4882a593Smuzhiyun 	refcount_inc(&msg->refcnt);
122*4882a593Smuzhiyun }
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun /* Release a reference. */
sctp_datamsg_put(struct sctp_datamsg * msg)125*4882a593Smuzhiyun void sctp_datamsg_put(struct sctp_datamsg *msg)
126*4882a593Smuzhiyun {
127*4882a593Smuzhiyun 	if (refcount_dec_and_test(&msg->refcnt))
128*4882a593Smuzhiyun 		sctp_datamsg_destroy(msg);
129*4882a593Smuzhiyun }
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun /* Assign a chunk to this datamsg. */
sctp_datamsg_assign(struct sctp_datamsg * msg,struct sctp_chunk * chunk)132*4882a593Smuzhiyun static void sctp_datamsg_assign(struct sctp_datamsg *msg, struct sctp_chunk *chunk)
133*4882a593Smuzhiyun {
134*4882a593Smuzhiyun 	sctp_datamsg_hold(msg);
135*4882a593Smuzhiyun 	chunk->msg = msg;
136*4882a593Smuzhiyun }
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun /* A data chunk can have a maximum payload of (2^16 - 20).  Break
140*4882a593Smuzhiyun  * down any such message into smaller chunks.  Opportunistically, fragment
141*4882a593Smuzhiyun  * the chunks down to the current MTU constraints.  We may get refragmented
142*4882a593Smuzhiyun  * later if the PMTU changes, but it is _much better_ to fragment immediately
143*4882a593Smuzhiyun  * with a reasonable guess than always doing our fragmentation on the
144*4882a593Smuzhiyun  * soft-interrupt.
145*4882a593Smuzhiyun  */
sctp_datamsg_from_user(struct sctp_association * asoc,struct sctp_sndrcvinfo * sinfo,struct iov_iter * from)146*4882a593Smuzhiyun struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
147*4882a593Smuzhiyun 					    struct sctp_sndrcvinfo *sinfo,
148*4882a593Smuzhiyun 					    struct iov_iter *from)
149*4882a593Smuzhiyun {
150*4882a593Smuzhiyun 	size_t len, first_len, max_data, remaining;
151*4882a593Smuzhiyun 	size_t msg_len = iov_iter_count(from);
152*4882a593Smuzhiyun 	struct sctp_shared_key *shkey = NULL;
153*4882a593Smuzhiyun 	struct list_head *pos, *temp;
154*4882a593Smuzhiyun 	struct sctp_chunk *chunk;
155*4882a593Smuzhiyun 	struct sctp_datamsg *msg;
156*4882a593Smuzhiyun 	int err;
157*4882a593Smuzhiyun 
158*4882a593Smuzhiyun 	msg = sctp_datamsg_new(GFP_KERNEL);
159*4882a593Smuzhiyun 	if (!msg)
160*4882a593Smuzhiyun 		return ERR_PTR(-ENOMEM);
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun 	/* Note: Calculate this outside of the loop, so that all fragments
163*4882a593Smuzhiyun 	 * have the same expiration.
164*4882a593Smuzhiyun 	 */
165*4882a593Smuzhiyun 	if (asoc->peer.prsctp_capable && sinfo->sinfo_timetolive &&
166*4882a593Smuzhiyun 	    (SCTP_PR_TTL_ENABLED(sinfo->sinfo_flags) ||
167*4882a593Smuzhiyun 	     !SCTP_PR_POLICY(sinfo->sinfo_flags)))
168*4882a593Smuzhiyun 		msg->expires_at = jiffies +
169*4882a593Smuzhiyun 				  msecs_to_jiffies(sinfo->sinfo_timetolive);
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun 	/* This is the biggest possible DATA chunk that can fit into
172*4882a593Smuzhiyun 	 * the packet
173*4882a593Smuzhiyun 	 */
174*4882a593Smuzhiyun 	max_data = asoc->frag_point;
175*4882a593Smuzhiyun 	if (unlikely(!max_data)) {
176*4882a593Smuzhiyun 		max_data = sctp_min_frag_point(sctp_sk(asoc->base.sk),
177*4882a593Smuzhiyun 					       sctp_datachk_len(&asoc->stream));
178*4882a593Smuzhiyun 		pr_warn_ratelimited("%s: asoc:%p frag_point is zero, forcing max_data to default minimum (%zu)",
179*4882a593Smuzhiyun 				    __func__, asoc, max_data);
180*4882a593Smuzhiyun 	}
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun 	/* If the peer requested that we authenticate DATA chunks
183*4882a593Smuzhiyun 	 * we need to account for bundling of the AUTH chunks along with
184*4882a593Smuzhiyun 	 * DATA.
185*4882a593Smuzhiyun 	 */
186*4882a593Smuzhiyun 	if (sctp_auth_send_cid(SCTP_CID_DATA, asoc)) {
187*4882a593Smuzhiyun 		struct sctp_hmac *hmac_desc = sctp_auth_asoc_get_hmac(asoc);
188*4882a593Smuzhiyun 
189*4882a593Smuzhiyun 		if (hmac_desc)
190*4882a593Smuzhiyun 			max_data -= SCTP_PAD4(sizeof(struct sctp_auth_chunk) +
191*4882a593Smuzhiyun 					      hmac_desc->hmac_len);
192*4882a593Smuzhiyun 
193*4882a593Smuzhiyun 		if (sinfo->sinfo_tsn &&
194*4882a593Smuzhiyun 		    sinfo->sinfo_ssn != asoc->active_key_id) {
195*4882a593Smuzhiyun 			shkey = sctp_auth_get_shkey(asoc, sinfo->sinfo_ssn);
196*4882a593Smuzhiyun 			if (!shkey) {
197*4882a593Smuzhiyun 				err = -EINVAL;
198*4882a593Smuzhiyun 				goto errout;
199*4882a593Smuzhiyun 			}
200*4882a593Smuzhiyun 		} else {
201*4882a593Smuzhiyun 			shkey = asoc->shkey;
202*4882a593Smuzhiyun 		}
203*4882a593Smuzhiyun 	}
204*4882a593Smuzhiyun 
205*4882a593Smuzhiyun 	/* Set first_len and then account for possible bundles on first frag */
206*4882a593Smuzhiyun 	first_len = max_data;
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun 	/* Check to see if we have a pending SACK and try to let it be bundled
209*4882a593Smuzhiyun 	 * with this message.  Do this if we don't have any data queued already.
210*4882a593Smuzhiyun 	 * To check that, look at out_qlen and retransmit list.
211*4882a593Smuzhiyun 	 * NOTE: we will not reduce to account for SACK, if the message would
212*4882a593Smuzhiyun 	 * not have been fragmented.
213*4882a593Smuzhiyun 	 */
214*4882a593Smuzhiyun 	if (timer_pending(&asoc->timers[SCTP_EVENT_TIMEOUT_SACK]) &&
215*4882a593Smuzhiyun 	    asoc->outqueue.out_qlen == 0 &&
216*4882a593Smuzhiyun 	    list_empty(&asoc->outqueue.retransmit) &&
217*4882a593Smuzhiyun 	    msg_len > max_data)
218*4882a593Smuzhiyun 		first_len -= SCTP_PAD4(sizeof(struct sctp_sack_chunk));
219*4882a593Smuzhiyun 
220*4882a593Smuzhiyun 	/* Encourage Cookie-ECHO bundling. */
221*4882a593Smuzhiyun 	if (asoc->state < SCTP_STATE_COOKIE_ECHOED)
222*4882a593Smuzhiyun 		first_len -= SCTP_ARBITRARY_COOKIE_ECHO_LEN;
223*4882a593Smuzhiyun 
224*4882a593Smuzhiyun 	/* Account for a different sized first fragment */
225*4882a593Smuzhiyun 	if (msg_len >= first_len) {
226*4882a593Smuzhiyun 		msg->can_delay = 0;
227*4882a593Smuzhiyun 		if (msg_len > first_len)
228*4882a593Smuzhiyun 			SCTP_INC_STATS(asoc->base.net,
229*4882a593Smuzhiyun 				       SCTP_MIB_FRAGUSRMSGS);
230*4882a593Smuzhiyun 	} else {
231*4882a593Smuzhiyun 		/* Which may be the only one... */
232*4882a593Smuzhiyun 		first_len = msg_len;
233*4882a593Smuzhiyun 	}
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun 	/* Create chunks for all DATA chunks. */
236*4882a593Smuzhiyun 	for (remaining = msg_len; remaining; remaining -= len) {
237*4882a593Smuzhiyun 		u8 frag = SCTP_DATA_MIDDLE_FRAG;
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun 		if (remaining == msg_len) {
240*4882a593Smuzhiyun 			/* First frag, which may also be the last */
241*4882a593Smuzhiyun 			frag |= SCTP_DATA_FIRST_FRAG;
242*4882a593Smuzhiyun 			len = first_len;
243*4882a593Smuzhiyun 		} else {
244*4882a593Smuzhiyun 			/* Middle frags */
245*4882a593Smuzhiyun 			len = max_data;
246*4882a593Smuzhiyun 		}
247*4882a593Smuzhiyun 
248*4882a593Smuzhiyun 		if (len >= remaining) {
249*4882a593Smuzhiyun 			/* Last frag, which may also be the first */
250*4882a593Smuzhiyun 			len = remaining;
251*4882a593Smuzhiyun 			frag |= SCTP_DATA_LAST_FRAG;
252*4882a593Smuzhiyun 
253*4882a593Smuzhiyun 			/* The application requests to set the I-bit of the
254*4882a593Smuzhiyun 			 * last DATA chunk of a user message when providing
255*4882a593Smuzhiyun 			 * the user message to the SCTP implementation.
256*4882a593Smuzhiyun 			 */
257*4882a593Smuzhiyun 			if ((sinfo->sinfo_flags & SCTP_EOF) ||
258*4882a593Smuzhiyun 			    (sinfo->sinfo_flags & SCTP_SACK_IMMEDIATELY))
259*4882a593Smuzhiyun 				frag |= SCTP_DATA_SACK_IMM;
260*4882a593Smuzhiyun 		}
261*4882a593Smuzhiyun 
262*4882a593Smuzhiyun 		chunk = asoc->stream.si->make_datafrag(asoc, sinfo, len, frag,
263*4882a593Smuzhiyun 						       GFP_KERNEL);
264*4882a593Smuzhiyun 		if (!chunk) {
265*4882a593Smuzhiyun 			err = -ENOMEM;
266*4882a593Smuzhiyun 			goto errout;
267*4882a593Smuzhiyun 		}
268*4882a593Smuzhiyun 
269*4882a593Smuzhiyun 		err = sctp_user_addto_chunk(chunk, len, from);
270*4882a593Smuzhiyun 		if (err < 0)
271*4882a593Smuzhiyun 			goto errout_chunk_free;
272*4882a593Smuzhiyun 
273*4882a593Smuzhiyun 		chunk->shkey = shkey;
274*4882a593Smuzhiyun 
275*4882a593Smuzhiyun 		/* Put the chunk->skb back into the form expected by send.  */
276*4882a593Smuzhiyun 		__skb_pull(chunk->skb, (__u8 *)chunk->chunk_hdr -
277*4882a593Smuzhiyun 				       chunk->skb->data);
278*4882a593Smuzhiyun 
279*4882a593Smuzhiyun 		sctp_datamsg_assign(msg, chunk);
280*4882a593Smuzhiyun 		list_add_tail(&chunk->frag_list, &msg->chunks);
281*4882a593Smuzhiyun 	}
282*4882a593Smuzhiyun 
283*4882a593Smuzhiyun 	return msg;
284*4882a593Smuzhiyun 
285*4882a593Smuzhiyun errout_chunk_free:
286*4882a593Smuzhiyun 	sctp_chunk_free(chunk);
287*4882a593Smuzhiyun 
288*4882a593Smuzhiyun errout:
289*4882a593Smuzhiyun 	list_for_each_safe(pos, temp, &msg->chunks) {
290*4882a593Smuzhiyun 		list_del_init(pos);
291*4882a593Smuzhiyun 		chunk = list_entry(pos, struct sctp_chunk, frag_list);
292*4882a593Smuzhiyun 		sctp_chunk_free(chunk);
293*4882a593Smuzhiyun 	}
294*4882a593Smuzhiyun 	sctp_datamsg_put(msg);
295*4882a593Smuzhiyun 
296*4882a593Smuzhiyun 	return ERR_PTR(err);
297*4882a593Smuzhiyun }
298*4882a593Smuzhiyun 
299*4882a593Smuzhiyun /* Check whether this message has expired. */
sctp_chunk_abandoned(struct sctp_chunk * chunk)300*4882a593Smuzhiyun int sctp_chunk_abandoned(struct sctp_chunk *chunk)
301*4882a593Smuzhiyun {
302*4882a593Smuzhiyun 	if (!chunk->asoc->peer.prsctp_capable)
303*4882a593Smuzhiyun 		return 0;
304*4882a593Smuzhiyun 
305*4882a593Smuzhiyun 	if (chunk->msg->abandoned)
306*4882a593Smuzhiyun 		return 1;
307*4882a593Smuzhiyun 
308*4882a593Smuzhiyun 	if (!chunk->has_tsn &&
309*4882a593Smuzhiyun 	    !(chunk->chunk_hdr->flags & SCTP_DATA_FIRST_FRAG))
310*4882a593Smuzhiyun 		return 0;
311*4882a593Smuzhiyun 
312*4882a593Smuzhiyun 	if (SCTP_PR_TTL_ENABLED(chunk->sinfo.sinfo_flags) &&
313*4882a593Smuzhiyun 	    time_after(jiffies, chunk->msg->expires_at)) {
314*4882a593Smuzhiyun 		struct sctp_stream_out *streamout =
315*4882a593Smuzhiyun 			SCTP_SO(&chunk->asoc->stream,
316*4882a593Smuzhiyun 				chunk->sinfo.sinfo_stream);
317*4882a593Smuzhiyun 
318*4882a593Smuzhiyun 		if (chunk->sent_count) {
319*4882a593Smuzhiyun 			chunk->asoc->abandoned_sent[SCTP_PR_INDEX(TTL)]++;
320*4882a593Smuzhiyun 			streamout->ext->abandoned_sent[SCTP_PR_INDEX(TTL)]++;
321*4882a593Smuzhiyun 		} else {
322*4882a593Smuzhiyun 			chunk->asoc->abandoned_unsent[SCTP_PR_INDEX(TTL)]++;
323*4882a593Smuzhiyun 			streamout->ext->abandoned_unsent[SCTP_PR_INDEX(TTL)]++;
324*4882a593Smuzhiyun 		}
325*4882a593Smuzhiyun 		chunk->msg->abandoned = 1;
326*4882a593Smuzhiyun 		return 1;
327*4882a593Smuzhiyun 	} else if (SCTP_PR_RTX_ENABLED(chunk->sinfo.sinfo_flags) &&
328*4882a593Smuzhiyun 		   chunk->sent_count > chunk->sinfo.sinfo_timetolive) {
329*4882a593Smuzhiyun 		struct sctp_stream_out *streamout =
330*4882a593Smuzhiyun 			SCTP_SO(&chunk->asoc->stream,
331*4882a593Smuzhiyun 				chunk->sinfo.sinfo_stream);
332*4882a593Smuzhiyun 
333*4882a593Smuzhiyun 		chunk->asoc->abandoned_sent[SCTP_PR_INDEX(RTX)]++;
334*4882a593Smuzhiyun 		streamout->ext->abandoned_sent[SCTP_PR_INDEX(RTX)]++;
335*4882a593Smuzhiyun 		chunk->msg->abandoned = 1;
336*4882a593Smuzhiyun 		return 1;
337*4882a593Smuzhiyun 	} else if (!SCTP_PR_POLICY(chunk->sinfo.sinfo_flags) &&
338*4882a593Smuzhiyun 		   chunk->msg->expires_at &&
339*4882a593Smuzhiyun 		   time_after(jiffies, chunk->msg->expires_at)) {
340*4882a593Smuzhiyun 		chunk->msg->abandoned = 1;
341*4882a593Smuzhiyun 		return 1;
342*4882a593Smuzhiyun 	}
343*4882a593Smuzhiyun 	/* PRIO policy is processed by sendmsg, not here */
344*4882a593Smuzhiyun 
345*4882a593Smuzhiyun 	return 0;
346*4882a593Smuzhiyun }
347*4882a593Smuzhiyun 
348*4882a593Smuzhiyun /* This chunk (and consequently entire message) has failed in its sending. */
sctp_chunk_fail(struct sctp_chunk * chunk,int error)349*4882a593Smuzhiyun void sctp_chunk_fail(struct sctp_chunk *chunk, int error)
350*4882a593Smuzhiyun {
351*4882a593Smuzhiyun 	chunk->msg->send_failed = 1;
352*4882a593Smuzhiyun 	chunk->msg->send_error = error;
353*4882a593Smuzhiyun }
354