Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /* SCTP kernel implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * (C) Copyright IBM Corp. 2001, 2004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Copyright (c) 1999-2000 Cisco, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (c) 1999-2001 Motorola, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright (c) 2001 Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * Copyright (c) 2001 Nokia, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * Copyright (c) 2001 La Monte H.P. Yarroll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  * These functions manipulate an sctp event.   The struct ulpevent is used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  * to carry notifications and data to the ULP (sockets).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  * Please send any bug reports or fixes you make to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  * email address(es):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  *    lksctp developers <linux-sctp@vger.kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  * Written or modified by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  *    Jon Grimm             <jgrimm@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  *    La Monte H.P. Yarroll <piggy@acm.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  *    Ardelle Fan	    <ardelle.fan@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  *    Sridhar Samudrala     <sri@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <net/sctp/structs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <net/sctp/sctp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <net/sctp/sm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) static void sctp_ulpevent_receive_data(struct sctp_ulpevent *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) 				       struct sctp_association *asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) static void sctp_ulpevent_release_data(struct sctp_ulpevent *event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) static void sctp_ulpevent_release_frag_data(struct sctp_ulpevent *event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) /* Initialize an ULP event from an given skb.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) static void sctp_ulpevent_init(struct sctp_ulpevent *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 			       __u16 msg_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 			       unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 	memset(event, 0, sizeof(struct sctp_ulpevent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 	event->msg_flags = msg_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 	event->rmem_len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) /* Create a new sctp_ulpevent.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) static struct sctp_ulpevent *sctp_ulpevent_new(int size, __u16 msg_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 					       gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 	struct sctp_ulpevent *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 	skb = alloc_skb(size, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 	event = sctp_skb2event(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 	sctp_ulpevent_init(event, msg_flags, skb->truesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 	return event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) /* Is this a MSG_NOTIFICATION?  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) int sctp_ulpevent_is_notification(const struct sctp_ulpevent *event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	return MSG_NOTIFICATION == (event->msg_flags & MSG_NOTIFICATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) /* Hold the association in case the msg_name needs read out of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74)  * the association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) static inline void sctp_ulpevent_set_owner(struct sctp_ulpevent *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 					   const struct sctp_association *asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	struct sctp_chunk *chunk = event->chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	/* Cast away the const, as we are just wanting to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	 * bump the reference count.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	sctp_association_hold((struct sctp_association *)asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	skb = sctp_event2skb(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	event->asoc = (struct sctp_association *)asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 	atomic_add(event->rmem_len, &event->asoc->rmem_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	sctp_skb_set_owner_r(skb, asoc->base.sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	if (chunk && chunk->head_skb && !chunk->head_skb->sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 		chunk->head_skb->sk = asoc->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) /* A simple destructor to give up the reference to the association. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) static inline void sctp_ulpevent_release_owner(struct sctp_ulpevent *event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	struct sctp_association *asoc = event->asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	atomic_sub(event->rmem_len, &asoc->rmem_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 	sctp_association_put(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) /* Create and initialize an SCTP_ASSOC_CHANGE event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105)  * 5.3.1.1 SCTP_ASSOC_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107)  * Communication notifications inform the ULP that an SCTP association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108)  * has either begun or ended. The identifier for a new association is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109)  * provided by this notification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111)  * Note: There is no field checking here.  If a field is unused it will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112)  * zero'd out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) struct sctp_ulpevent  *sctp_ulpevent_make_assoc_change(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	__u16 flags, __u16 state, __u16 error, __u16 outbound,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	__u16 inbound, struct sctp_chunk *chunk, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	struct sctp_ulpevent *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	struct sctp_assoc_change *sac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	/* If the lower layer passed in the chunk, it will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	 * an ABORT, so we need to include it in the sac_info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	if (chunk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 		/* Copy the chunk data to a new skb and reserve enough
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 		 * head room to use as notification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 		skb = skb_copy_expand(chunk->skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 				      sizeof(struct sctp_assoc_change), 0, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 		if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 		/* Embed the event fields inside the cloned skb.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 		event = sctp_skb2event(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 		sctp_ulpevent_init(event, MSG_NOTIFICATION, skb->truesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 		/* Include the notification structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 		sac = skb_push(skb, sizeof(struct sctp_assoc_change));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 		/* Trim the buffer to the right length.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 		skb_trim(skb, sizeof(struct sctp_assoc_change) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 			 ntohs(chunk->chunk_hdr->length) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 			 sizeof(struct sctp_chunkhdr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 		event = sctp_ulpevent_new(sizeof(struct sctp_assoc_change),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 				  MSG_NOTIFICATION, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 		if (!event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 		skb = sctp_event2skb(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 		sac = skb_put(skb, sizeof(struct sctp_assoc_change));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	/* Socket Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	 * 5.3.1.1 SCTP_ASSOC_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	 * sac_type:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	 * It should be SCTP_ASSOC_CHANGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	sac->sac_type = SCTP_ASSOC_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	/* Socket Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	 * 5.3.1.1 SCTP_ASSOC_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	 * sac_state: 32 bits (signed integer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	 * This field holds one of a number of values that communicate the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	 * event that happened to the association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	sac->sac_state = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	/* Socket Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	 * 5.3.1.1 SCTP_ASSOC_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	 * sac_flags: 16 bits (unsigned integer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	 * Currently unused.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	sac->sac_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	/* Socket Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	 * 5.3.1.1 SCTP_ASSOC_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	 * sac_length: sizeof (__u32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	 * This field is the total length of the notification data, including
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	 * the notification header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	sac->sac_length = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	/* Socket Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	 * 5.3.1.1 SCTP_ASSOC_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	 * sac_error:  32 bits (signed integer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	 * If the state was reached due to a error condition (e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	 * COMMUNICATION_LOST) any relevant error information is available in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	 * this field. This corresponds to the protocol error codes defined in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	 * [SCTP].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	sac->sac_error = error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	/* Socket Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	 * 5.3.1.1 SCTP_ASSOC_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	 * sac_outbound_streams:  16 bits (unsigned integer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	 * sac_inbound_streams:  16 bits (unsigned integer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	 * The maximum number of streams allowed in each direction are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	 * available in sac_outbound_streams and sac_inbound streams.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	sac->sac_outbound_streams = outbound;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	sac->sac_inbound_streams = inbound;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	/* Socket Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	 * 5.3.1.1 SCTP_ASSOC_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	 * sac_assoc_id: sizeof (sctp_assoc_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	 * The association id field, holds the identifier for the association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	 * All notifications for a given association have the same association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	 * identifier.  For TCP style socket, this field is ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	sctp_ulpevent_set_owner(event, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	sac->sac_assoc_id = sctp_assoc2id(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	return event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) /* Create and initialize an SCTP_PEER_ADDR_CHANGE event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235)  * Socket Extensions for SCTP - draft-01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236)  * 5.3.1.2 SCTP_PEER_ADDR_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238)  * When a destination address on a multi-homed peer encounters a change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239)  * an interface details event is sent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) static struct sctp_ulpevent *sctp_ulpevent_make_peer_addr_change(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	const struct sockaddr_storage *aaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	int flags, int state, int error, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	struct sctp_ulpevent *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	struct sctp_paddr_change  *spc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	event = sctp_ulpevent_new(sizeof(struct sctp_paddr_change),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 				  MSG_NOTIFICATION, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	if (!event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	skb = sctp_event2skb(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	spc = skb_put(skb, sizeof(struct sctp_paddr_change));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	/* Sockets API Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	 * spc_type:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	 *    It should be SCTP_PEER_ADDR_CHANGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	spc->spc_type = SCTP_PEER_ADDR_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	/* Sockets API Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	 * spc_length: sizeof (__u32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	 * This field is the total length of the notification data, including
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	 * the notification header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	spc->spc_length = sizeof(struct sctp_paddr_change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	/* Sockets API Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	 * spc_flags: 16 bits (unsigned integer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	 * Currently unused.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	spc->spc_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	/* Sockets API Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	 * spc_state:  32 bits (signed integer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	 * This field holds one of a number of values that communicate the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	 * event that happened to the address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	spc->spc_state = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	/* Sockets API Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	 * spc_error:  32 bits (signed integer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	 * If the state was reached due to any error condition (e.g.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	 * ADDRESS_UNREACHABLE) any relevant error information is available in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	 * this field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	spc->spc_error = error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	/* Socket Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	 * 5.3.1.1 SCTP_ASSOC_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	 * spc_assoc_id: sizeof (sctp_assoc_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	 * The association id field, holds the identifier for the association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	 * All notifications for a given association have the same association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	 * identifier.  For TCP style socket, this field is ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	sctp_ulpevent_set_owner(event, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	spc->spc_assoc_id = sctp_assoc2id(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	/* Sockets API Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	 * spc_aaddr: sizeof (struct sockaddr_storage)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	 * The affected address field, holds the remote peer's address that is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	 * encountering the change of state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	memcpy(&spc->spc_aaddr, aaddr, sizeof(struct sockaddr_storage));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	/* Map ipv4 address into v4-mapped-on-v6 address.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	sctp_get_pf_specific(asoc->base.sk->sk_family)->addr_to_user(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 					sctp_sk(asoc->base.sk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 					(union sctp_addr *)&spc->spc_aaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	return event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) void sctp_ulpevent_notify_peer_addr_change(struct sctp_transport *transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 					   int state, int error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	struct sctp_association *asoc = transport->asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	struct sockaddr_storage addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	struct sctp_ulpevent *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	if (asoc->state < SCTP_STATE_ESTABLISHED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	memset(&addr, 0, sizeof(struct sockaddr_storage));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	memcpy(&addr, &transport->ipaddr, transport->af_specific->sockaddr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	event = sctp_ulpevent_make_peer_addr_change(asoc, &addr, 0, state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 						    error, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	if (event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 		asoc->stream.si->enqueue_event(&asoc->ulpq, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) /* Create and initialize an SCTP_REMOTE_ERROR notification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360)  * Note: This assumes that the chunk->skb->data already points to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361)  * operation error payload.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363)  * Socket Extensions for SCTP - draft-01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364)  * 5.3.1.3 SCTP_REMOTE_ERROR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366)  * A remote peer may send an Operational Error message to its peer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367)  * This message indicates a variety of error conditions on an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368)  * association. The entire error TLV as it appears on the wire is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369)  * included in a SCTP_REMOTE_ERROR event.  Please refer to the SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370)  * specification [SCTP] and any extensions for a list of possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371)  * error formats.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) struct sctp_ulpevent *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) sctp_ulpevent_make_remote_error(const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 				struct sctp_chunk *chunk, __u16 flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 				gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	struct sctp_remote_error *sre;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	struct sctp_ulpevent *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	struct sctp_errhdr *ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	__be16 cause;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	int elen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	ch = (struct sctp_errhdr *)(chunk->skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	cause = ch->cause;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	elen = SCTP_PAD4(ntohs(ch->length)) - sizeof(*ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	/* Pull off the ERROR header.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	skb_pull(chunk->skb, sizeof(*ch));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	/* Copy the skb to a new skb with room for us to prepend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	 * notification with.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	skb = skb_copy_expand(chunk->skb, sizeof(*sre), 0, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	/* Pull off the rest of the cause TLV from the chunk.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	skb_pull(chunk->skb, elen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	/* Embed the event fields inside the cloned skb.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	event = sctp_skb2event(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	sctp_ulpevent_init(event, MSG_NOTIFICATION, skb->truesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	sre = skb_push(skb, sizeof(*sre));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	/* Trim the buffer to the right length.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	skb_trim(skb, sizeof(*sre) + elen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	/* RFC6458, Section 6.1.3. SCTP_REMOTE_ERROR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	memset(sre, 0, sizeof(*sre));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	sre->sre_type = SCTP_REMOTE_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	sre->sre_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	sre->sre_length = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	sre->sre_error = cause;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	sctp_ulpevent_set_owner(event, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	sre->sre_assoc_id = sctp_assoc2id(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	return event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) /* Create and initialize a SCTP_SEND_FAILED notification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427)  * Socket Extensions for SCTP - draft-01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428)  * 5.3.1.4 SCTP_SEND_FAILED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) struct sctp_ulpevent *sctp_ulpevent_make_send_failed(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	const struct sctp_association *asoc, struct sctp_chunk *chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	__u16 flags, __u32 error, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	struct sctp_ulpevent *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	struct sctp_send_failed *ssf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	/* Pull off any padding. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	int len = ntohs(chunk->chunk_hdr->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	/* Make skb with more room so we can prepend notification.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	skb = skb_copy_expand(chunk->skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 			      sizeof(struct sctp_send_failed), /* headroom */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 			      0,                               /* tailroom */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 			      gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	/* Pull off the common chunk header and DATA header.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	skb_pull(skb, sctp_datachk_len(&asoc->stream));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	len -= sctp_datachk_len(&asoc->stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	/* Embed the event fields inside the cloned skb.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	event = sctp_skb2event(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	sctp_ulpevent_init(event, MSG_NOTIFICATION, skb->truesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	ssf = skb_push(skb, sizeof(struct sctp_send_failed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	/* Socket Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	 * 5.3.1.4 SCTP_SEND_FAILED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	 * ssf_type:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	 * It should be SCTP_SEND_FAILED.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	ssf->ssf_type = SCTP_SEND_FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	/* Socket Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	 * 5.3.1.4 SCTP_SEND_FAILED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	 * ssf_flags: 16 bits (unsigned integer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	 * The flag value will take one of the following values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	 * SCTP_DATA_UNSENT - Indicates that the data was never put on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	 *                    the wire.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	 * SCTP_DATA_SENT   - Indicates that the data was put on the wire.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	 *                    Note that this does not necessarily mean that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	 *                    data was (or was not) successfully delivered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	ssf->ssf_flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	/* Socket Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	 * 5.3.1.4 SCTP_SEND_FAILED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	 * ssf_length: sizeof (__u32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	 * This field is the total length of the notification data, including
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	 * the notification header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	ssf->ssf_length = sizeof(struct sctp_send_failed) + len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	skb_trim(skb, ssf->ssf_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	/* Socket Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	 * 5.3.1.4 SCTP_SEND_FAILED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	 * ssf_error: 16 bits (unsigned integer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	 * This value represents the reason why the send failed, and if set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	 * will be a SCTP protocol error code as defined in [SCTP] section
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	 * 3.3.10.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	ssf->ssf_error = error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	/* Socket Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	 * 5.3.1.4 SCTP_SEND_FAILED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	 * ssf_info: sizeof (struct sctp_sndrcvinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	 * The original send information associated with the undelivered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	 * message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	memcpy(&ssf->ssf_info, &chunk->sinfo, sizeof(struct sctp_sndrcvinfo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	/* Per TSVWG discussion with Randy. Allow the application to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	 * reassemble a fragmented message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	ssf->ssf_info.sinfo_flags = chunk->chunk_hdr->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	/* Socket Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	 * 5.3.1.4 SCTP_SEND_FAILED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	 * ssf_assoc_id: sizeof (sctp_assoc_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	 * The association id field, sf_assoc_id, holds the identifier for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	 * association.  All notifications for a given association have the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	 * same association identifier.  For TCP style socket, this field is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	 * ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	sctp_ulpevent_set_owner(event, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	ssf->ssf_assoc_id = sctp_assoc2id(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	return event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) struct sctp_ulpevent *sctp_ulpevent_make_send_failed_event(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	const struct sctp_association *asoc, struct sctp_chunk *chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	__u16 flags, __u32 error, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	struct sctp_send_failed_event *ssf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	struct sctp_ulpevent *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	skb = skb_copy_expand(chunk->skb, sizeof(*ssf), 0, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	len = ntohs(chunk->chunk_hdr->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	len -= sctp_datachk_len(&asoc->stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	skb_pull(skb, sctp_datachk_len(&asoc->stream));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	event = sctp_skb2event(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	sctp_ulpevent_init(event, MSG_NOTIFICATION, skb->truesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	ssf = skb_push(skb, sizeof(*ssf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	ssf->ssf_type = SCTP_SEND_FAILED_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	ssf->ssf_flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	ssf->ssf_length = sizeof(*ssf) + len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	skb_trim(skb, ssf->ssf_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	ssf->ssf_error = error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	ssf->ssfe_info.snd_sid = chunk->sinfo.sinfo_stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	ssf->ssfe_info.snd_ppid = chunk->sinfo.sinfo_ppid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	ssf->ssfe_info.snd_context = chunk->sinfo.sinfo_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	ssf->ssfe_info.snd_assoc_id = chunk->sinfo.sinfo_assoc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	ssf->ssfe_info.snd_flags = chunk->chunk_hdr->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	sctp_ulpevent_set_owner(event, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	ssf->ssf_assoc_id = sctp_assoc2id(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	return event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) /* Create and initialize a SCTP_SHUTDOWN_EVENT notification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574)  * Socket Extensions for SCTP - draft-01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575)  * 5.3.1.5 SCTP_SHUTDOWN_EVENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) struct sctp_ulpevent *sctp_ulpevent_make_shutdown_event(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	__u16 flags, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	struct sctp_ulpevent *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	struct sctp_shutdown_event *sse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	event = sctp_ulpevent_new(sizeof(struct sctp_shutdown_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 				  MSG_NOTIFICATION, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	if (!event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	skb = sctp_event2skb(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	sse = skb_put(skb, sizeof(struct sctp_shutdown_event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	/* Socket Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	 * sse_type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	 * It should be SCTP_SHUTDOWN_EVENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	sse->sse_type = SCTP_SHUTDOWN_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	/* Socket Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	 * sse_flags: 16 bits (unsigned integer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	 * Currently unused.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	sse->sse_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	/* Socket Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	 * sse_length: sizeof (__u32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	 * This field is the total length of the notification data, including
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	 * the notification header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	sse->sse_length = sizeof(struct sctp_shutdown_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	/* Socket Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	 * sse_assoc_id: sizeof (sctp_assoc_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	 * The association id field, holds the identifier for the association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	 * All notifications for a given association have the same association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	 * identifier.  For TCP style socket, this field is ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	sctp_ulpevent_set_owner(event, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	sse->sse_assoc_id = sctp_assoc2id(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	return event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) /* Create and initialize a SCTP_ADAPTATION_INDICATION notification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637)  * Socket Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638)  * 5.3.1.6 SCTP_ADAPTATION_INDICATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) struct sctp_ulpevent *sctp_ulpevent_make_adaptation_indication(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	const struct sctp_association *asoc, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	struct sctp_ulpevent *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	struct sctp_adaptation_event *sai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	event = sctp_ulpevent_new(sizeof(struct sctp_adaptation_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 				  MSG_NOTIFICATION, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	if (!event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	skb = sctp_event2skb(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	sai = skb_put(skb, sizeof(struct sctp_adaptation_event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	sai->sai_type = SCTP_ADAPTATION_INDICATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	sai->sai_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	sai->sai_length = sizeof(struct sctp_adaptation_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	sai->sai_adaptation_ind = asoc->peer.adaptation_ind;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	sctp_ulpevent_set_owner(event, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	sai->sai_assoc_id = sctp_assoc2id(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	return event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) /* A message has been received.  Package this message as a notification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669)  * to pass it to the upper layers.  Go ahead and calculate the sndrcvinfo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670)  * even if filtered out later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672)  * Socket Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673)  * 5.2.2 SCTP Header Information Structure (SCTP_SNDRCV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 						struct sctp_chunk *chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 						gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	struct sctp_ulpevent *event = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	struct sk_buff *skb = chunk->skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	struct sock *sk = asoc->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	size_t padding, datalen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	int rx_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	 * check to see if we need to make space for this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	 * new skb, expand the rcvbuffer if needed, or drop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	 * the frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	if (asoc->ep->rcvbuf_policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		rx_count = atomic_read(&asoc->rmem_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 		rx_count = atomic_read(&sk->sk_rmem_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	datalen = ntohs(chunk->chunk_hdr->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	if (rx_count >= sk->sk_rcvbuf || !sk_rmem_schedule(sk, skb, datalen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	/* Clone the original skb, sharing the data.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	skb = skb_clone(chunk->skb, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	/* Now that all memory allocations for this chunk succeeded, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	 * can mark it as received so the tsn_map is updated correctly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	if (sctp_tsnmap_mark(&asoc->peer.tsn_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 			     ntohl(chunk->subh.data_hdr->tsn),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 			     chunk->transport))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 		goto fail_mark;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	/* First calculate the padding, so we don't inadvertently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	 * pass up the wrong length to the user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	 * RFC 2960 - Section 3.2  Chunk Field Descriptions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	 * The total length of a chunk(including Type, Length and Value fields)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	 * MUST be a multiple of 4 bytes.  If the length of the chunk is not a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	 * multiple of 4 bytes, the sender MUST pad the chunk with all zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	 * bytes and this padding is not included in the chunk length field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	 * The sender should never pad with more than 3 bytes.  The receiver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	 * MUST ignore the padding bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	padding = SCTP_PAD4(datalen) - datalen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	/* Fixup cloned skb with just this chunks data.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	skb_trim(skb, chunk->chunk_end - padding - skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	/* Embed the event fields inside the cloned skb.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	event = sctp_skb2event(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	/* Initialize event with flags 0  and correct length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	 * Since this is a clone of the original skb, only account for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	 * the data of this chunk as other chunks will be accounted separately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	sctp_ulpevent_init(event, 0, skb->len + sizeof(struct sk_buff));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	/* And hold the chunk as we need it for getting the IP headers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	 * later in recvmsg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	sctp_chunk_hold(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	event->chunk = chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	sctp_ulpevent_receive_data(event, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	event->stream = ntohs(chunk->subh.data_hdr->stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		event->flags |= SCTP_UNORDERED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		event->cumtsn = sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	event->tsn = ntohl(chunk->subh.data_hdr->tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	event->msg_flags |= chunk->chunk_hdr->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	return event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) fail_mark:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) /* Create a partial delivery related event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765)  * 5.3.1.7 SCTP_PARTIAL_DELIVERY_EVENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767)  *   When a receiver is engaged in a partial delivery of a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768)  *   message this notification will be used to indicate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769)  *   various events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) struct sctp_ulpevent *sctp_ulpevent_make_pdapi(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 					const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 					__u32 indication, __u32 sid, __u32 seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 					__u32 flags, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	struct sctp_ulpevent *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	struct sctp_pdapi_event *pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	event = sctp_ulpevent_new(sizeof(struct sctp_pdapi_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 				  MSG_NOTIFICATION, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	if (!event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	skb = sctp_event2skb(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	pd = skb_put(skb, sizeof(struct sctp_pdapi_event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	/* pdapi_type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	 *   It should be SCTP_PARTIAL_DELIVERY_EVENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	 * pdapi_flags: 16 bits (unsigned integer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	 *   Currently unused.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	pd->pdapi_type = SCTP_PARTIAL_DELIVERY_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	pd->pdapi_flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	pd->pdapi_stream = sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	pd->pdapi_seq = seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	/* pdapi_length: 32 bits (unsigned integer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	 * This field is the total length of the notification data, including
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	 * the notification header.  It will generally be sizeof (struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	 * sctp_pdapi_event).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	pd->pdapi_length = sizeof(struct sctp_pdapi_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	/*  pdapi_indication: 32 bits (unsigned integer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	 * This field holds the indication being sent to the application.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	pd->pdapi_indication = indication;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	/*  pdapi_assoc_id: sizeof (sctp_assoc_t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	 * The association id field, holds the identifier for the association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	sctp_ulpevent_set_owner(event, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	pd->pdapi_assoc_id = sctp_assoc2id(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	return event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) struct sctp_ulpevent *sctp_ulpevent_make_authkey(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	const struct sctp_association *asoc, __u16 key_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	__u32 indication, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	struct sctp_ulpevent *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	struct sctp_authkey_event *ak;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	event = sctp_ulpevent_new(sizeof(struct sctp_authkey_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 				  MSG_NOTIFICATION, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 	if (!event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	skb = sctp_event2skb(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	ak = skb_put(skb, sizeof(struct sctp_authkey_event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	ak->auth_type = SCTP_AUTHENTICATION_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	ak->auth_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	ak->auth_length = sizeof(struct sctp_authkey_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	ak->auth_keynumber = key_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	ak->auth_altkeynumber = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	ak->auth_indication = indication;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	 * The association id field, holds the identifier for the association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	sctp_ulpevent_set_owner(event, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	ak->auth_assoc_id = sctp_assoc2id(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	return event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861)  * Socket Extensions for SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862)  * 6.3.10. SCTP_SENDER_DRY_EVENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) struct sctp_ulpevent *sctp_ulpevent_make_sender_dry_event(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	const struct sctp_association *asoc, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	struct sctp_ulpevent *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	struct sctp_sender_dry_event *sdry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	event = sctp_ulpevent_new(sizeof(struct sctp_sender_dry_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 				  MSG_NOTIFICATION, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	if (!event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	skb = sctp_event2skb(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	sdry = skb_put(skb, sizeof(struct sctp_sender_dry_event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	sdry->sender_dry_type = SCTP_SENDER_DRY_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	sdry->sender_dry_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	sdry->sender_dry_length = sizeof(struct sctp_sender_dry_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	sctp_ulpevent_set_owner(event, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	sdry->sender_dry_assoc_id = sctp_assoc2id(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	return event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) struct sctp_ulpevent *sctp_ulpevent_make_stream_reset_event(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	const struct sctp_association *asoc, __u16 flags, __u16 stream_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	__be16 *stream_list, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	struct sctp_stream_reset_event *sreset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	struct sctp_ulpevent *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	int length, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	length = sizeof(struct sctp_stream_reset_event) + 2 * stream_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	event = sctp_ulpevent_new(length, MSG_NOTIFICATION, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	if (!event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	skb = sctp_event2skb(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	sreset = skb_put(skb, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	sreset->strreset_type = SCTP_STREAM_RESET_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	sreset->strreset_flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	sreset->strreset_length = length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	sctp_ulpevent_set_owner(event, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	sreset->strreset_assoc_id = sctp_assoc2id(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	for (i = 0; i < stream_num; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 		sreset->strreset_stream_list[i] = ntohs(stream_list[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	return event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) struct sctp_ulpevent *sctp_ulpevent_make_assoc_reset_event(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	const struct sctp_association *asoc, __u16 flags, __u32 local_tsn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	__u32 remote_tsn, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	struct sctp_assoc_reset_event *areset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	struct sctp_ulpevent *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	event = sctp_ulpevent_new(sizeof(struct sctp_assoc_reset_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 				  MSG_NOTIFICATION, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	if (!event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	skb = sctp_event2skb(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	areset = skb_put(skb, sizeof(struct sctp_assoc_reset_event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	areset->assocreset_type = SCTP_ASSOC_RESET_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	areset->assocreset_flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	areset->assocreset_length = sizeof(struct sctp_assoc_reset_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	sctp_ulpevent_set_owner(event, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	areset->assocreset_assoc_id = sctp_assoc2id(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	areset->assocreset_local_tsn = local_tsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	areset->assocreset_remote_tsn = remote_tsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	return event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) struct sctp_ulpevent *sctp_ulpevent_make_stream_change_event(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	const struct sctp_association *asoc, __u16 flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	__u32 strchange_instrms, __u32 strchange_outstrms, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	struct sctp_stream_change_event *schange;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	struct sctp_ulpevent *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	event = sctp_ulpevent_new(sizeof(struct sctp_stream_change_event),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 				  MSG_NOTIFICATION, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	if (!event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	skb = sctp_event2skb(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	schange = skb_put(skb, sizeof(struct sctp_stream_change_event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	schange->strchange_type = SCTP_STREAM_CHANGE_EVENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	schange->strchange_flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	schange->strchange_length = sizeof(struct sctp_stream_change_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	sctp_ulpevent_set_owner(event, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	schange->strchange_assoc_id = sctp_assoc2id(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	schange->strchange_instrms = strchange_instrms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	schange->strchange_outstrms = strchange_outstrms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	return event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) /* Return the notification type, assuming this is a notification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972)  * event.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) __u16 sctp_ulpevent_get_notification_type(const struct sctp_ulpevent *event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	union sctp_notification *notification;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	skb = sctp_event2skb(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	notification = (union sctp_notification *) skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 	return notification->sn_header.sn_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) /* RFC6458, Section 5.3.2. SCTP Header Information Structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985)  * (SCTP_SNDRCV, DEPRECATED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) void sctp_ulpevent_read_sndrcvinfo(const struct sctp_ulpevent *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 				   struct msghdr *msghdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	struct sctp_sndrcvinfo sinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	if (sctp_ulpevent_is_notification(event))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	memset(&sinfo, 0, sizeof(sinfo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	sinfo.sinfo_stream = event->stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	sinfo.sinfo_ssn = event->ssn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	sinfo.sinfo_ppid = event->ppid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	sinfo.sinfo_flags = event->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	sinfo.sinfo_tsn = event->tsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	sinfo.sinfo_cumtsn = event->cumtsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	sinfo.sinfo_assoc_id = sctp_assoc2id(event->asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	/* Context value that is set via SCTP_CONTEXT socket option. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	sinfo.sinfo_context = event->asoc->default_rcv_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	/* These fields are not used while receiving. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	sinfo.sinfo_timetolive = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	put_cmsg(msghdr, IPPROTO_SCTP, SCTP_SNDRCV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 		 sizeof(sinfo), &sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) /* RFC6458, Section 5.3.5 SCTP Receive Information Structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013)  * (SCTP_SNDRCV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) void sctp_ulpevent_read_rcvinfo(const struct sctp_ulpevent *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 				struct msghdr *msghdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	struct sctp_rcvinfo rinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	if (sctp_ulpevent_is_notification(event))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	memset(&rinfo, 0, sizeof(struct sctp_rcvinfo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	rinfo.rcv_sid = event->stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	rinfo.rcv_ssn = event->ssn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	rinfo.rcv_ppid = event->ppid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	rinfo.rcv_flags = event->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	rinfo.rcv_tsn = event->tsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	rinfo.rcv_cumtsn = event->cumtsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	rinfo.rcv_assoc_id = sctp_assoc2id(event->asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	rinfo.rcv_context = event->asoc->default_rcv_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	put_cmsg(msghdr, IPPROTO_SCTP, SCTP_RCVINFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 		 sizeof(rinfo), &rinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) /* RFC6458, Section 5.3.6. SCTP Next Receive Information Structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)  * (SCTP_NXTINFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) static void __sctp_ulpevent_read_nxtinfo(const struct sctp_ulpevent *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 					 struct msghdr *msghdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 					 const struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	struct sctp_nxtinfo nxtinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	memset(&nxtinfo, 0, sizeof(nxtinfo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	nxtinfo.nxt_sid = event->stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	nxtinfo.nxt_ppid = event->ppid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	nxtinfo.nxt_flags = event->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	if (sctp_ulpevent_is_notification(event))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 		nxtinfo.nxt_flags |= SCTP_NOTIFICATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	nxtinfo.nxt_length = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	nxtinfo.nxt_assoc_id = sctp_assoc2id(event->asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	put_cmsg(msghdr, IPPROTO_SCTP, SCTP_NXTINFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 		 sizeof(nxtinfo), &nxtinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) void sctp_ulpevent_read_nxtinfo(const struct sctp_ulpevent *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 				struct msghdr *msghdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 				struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	skb = sctp_skb_recv_datagram(sk, MSG_PEEK, 1, &err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	if (skb != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 		__sctp_ulpevent_read_nxtinfo(sctp_skb2event(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 					     msghdr, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 		/* Just release refcount here. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) /* Do accounting for bytes received and hold a reference to the association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076)  * for each skb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) static void sctp_ulpevent_receive_data(struct sctp_ulpevent *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 				       struct sctp_association *asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	struct sk_buff *skb, *frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	skb = sctp_event2skb(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	/* Set the owner and charge rwnd for bytes received.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	sctp_ulpevent_set_owner(event, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	sctp_assoc_rwnd_decrease(asoc, skb_headlen(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	if (!skb->data_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	/* Note:  Not clearing the entire event struct as this is just a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	 * fragment of the real event.  However, we still need to do rwnd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	 * accounting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	 * In general, the skb passed from IP can have only 1 level of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	 * fragments. But we allow multiple levels of fragments.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	skb_walk_frags(skb, frag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 		sctp_ulpevent_receive_data(sctp_skb2event(frag), asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) /* Do accounting for bytes just read by user and release the references to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)  * the association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) static void sctp_ulpevent_release_data(struct sctp_ulpevent *event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	struct sk_buff *skb, *frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	unsigned int	len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	/* Current stack structures assume that the rcv buffer is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	 * per socket.   For UDP style sockets this is not true as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	 * multiple associations may be on a single UDP-style socket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	 * Use the local private area of the skb to track the owning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	 * association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	skb = sctp_event2skb(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	len = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	if (!skb->data_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	/* Don't forget the fragments. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	skb_walk_frags(skb, frag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 		/* NOTE:  skb_shinfos are recursive. Although IP returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 		 * skb's with only 1 level of fragments, SCTP reassembly can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 		 * increase the levels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 		sctp_ulpevent_release_frag_data(sctp_skb2event(frag));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	sctp_assoc_rwnd_increase(event->asoc, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	sctp_chunk_put(event->chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	sctp_ulpevent_release_owner(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) static void sctp_ulpevent_release_frag_data(struct sctp_ulpevent *event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	struct sk_buff *skb, *frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	skb = sctp_event2skb(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	if (!skb->data_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	/* Don't forget the fragments. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	skb_walk_frags(skb, frag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 		/* NOTE:  skb_shinfos are recursive. Although IP returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 		 * skb's with only 1 level of fragments, SCTP reassembly can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 		 * increase the levels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 		sctp_ulpevent_release_frag_data(sctp_skb2event(frag));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	sctp_chunk_put(event->chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	sctp_ulpevent_release_owner(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) /* Free a ulpevent that has an owner.  It includes releasing the reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161)  * to the owner, updating the rwnd in case of a DATA event and freeing the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)  * skb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) void sctp_ulpevent_free(struct sctp_ulpevent *event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	if (sctp_ulpevent_is_notification(event))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 		sctp_ulpevent_release_owner(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 		sctp_ulpevent_release_data(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	kfree_skb(sctp_event2skb(event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) /* Purge the skb lists holding ulpevents. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) unsigned int sctp_queue_purge_ulpevents(struct sk_buff_head *list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	unsigned int data_unread = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	while ((skb = skb_dequeue(list)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 		struct sctp_ulpevent *event = sctp_skb2event(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 		if (!sctp_ulpevent_is_notification(event))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 			data_unread += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 		sctp_ulpevent_free(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	return data_unread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) }