1 /* SCTP kernel reference Implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001 Intel Corp.
6 * Copyright (c) 2001 Nokia, Inc.
7 * Copyright (c) 2001 La Monte H.P. Yarroll
9 * These functions manipulate an sctp event. The struct ulpevent is used
10 * to carry notifications and data to the ULP (sockets).
11 * The SCTP reference implementation is free software;
12 * you can redistribute it and/or modify it under the terms of
13 * the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
17 * The SCTP reference implementation is distributed in the hope that it
18 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
19 * ************************
20 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 * See the GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with GNU CC; see the file COPYING. If not, write to
25 * the Free Software Foundation, 59 Temple Place - Suite 330,
26 * Boston, MA 02111-1307, USA.
28 * Please send any bug reports or fixes you make to the
30 * lksctp developers <lksctp-developers@lists.sourceforge.net>
32 * Or submit a bug report through the following website:
33 * http://www.sf.net/projects/lksctp
35 * Written or modified by:
36 * Jon Grimm <jgrimm@us.ibm.com>
37 * La Monte H.P. Yarroll <piggy@acm.org>
38 * Ardelle Fan <ardelle.fan@intel.com>
39 * Sridhar Samudrala <sri@us.ibm.com>
41 * Any bugs reported given to us we will try to fix... any fixes shared will
42 * be incorporated into the next SCTP release.
45 #include <linux/types.h>
46 #include <linux/skbuff.h>
47 #include <net/sctp/structs.h>
48 #include <net/sctp/sctp.h>
49 #include <net/sctp/sm.h>
51 static void sctp_ulpevent_receive_data(struct sctp_ulpevent *event,
52 struct sctp_association *asoc);
53 static void sctp_ulpevent_release_data(struct sctp_ulpevent *event);
55 /* Stub skb destructor. */
56 static void sctp_stub_rfree(struct sk_buff *skb)
58 /* WARNING: This function is just a warning not to use the
59 * skb destructor. If the skb is shared, we may get the destructor
60 * callback on some processor that does not own the sock_lock. This
61 * was occuring with PACKET socket applications that were monitoring
62 * our skbs. We can't take the sock_lock, because we can't risk
63 * recursing if we do really own the sock lock. Instead, do all
64 * of our rwnd manipulation while we own the sock_lock outright.
68 /* Create a new sctp_ulpevent. */
69 struct sctp_ulpevent *sctp_ulpevent_new(int size, int msg_flags, int gfp)
71 struct sctp_ulpevent *event;
74 skb = alloc_skb(size, gfp);
78 event = sctp_skb2event(skb);
79 sctp_ulpevent_init(event, msg_flags);
87 /* Initialize an ULP event from an given skb. */
88 void sctp_ulpevent_init(struct sctp_ulpevent *event, int msg_flags)
90 memset(event, 0, sizeof(struct sctp_ulpevent));
91 event->msg_flags = msg_flags;
94 /* Is this a MSG_NOTIFICATION? */
95 int sctp_ulpevent_is_notification(const struct sctp_ulpevent *event)
97 return MSG_NOTIFICATION == (event->msg_flags & MSG_NOTIFICATION);
100 /* Hold the association in case the msg_name needs read out of
103 static inline void sctp_ulpevent_set_owner(struct sctp_ulpevent *event,
104 const struct sctp_association *asoc)
108 /* Cast away the const, as we are just wanting to
109 * bump the reference count.
111 sctp_association_hold((struct sctp_association *)asoc);
112 skb = sctp_event2skb(event);
113 skb->sk = asoc->base.sk;
114 event->asoc = (struct sctp_association *)asoc;
115 skb->destructor = sctp_stub_rfree;
118 /* A simple destructor to give up the reference to the association. */
119 static inline void sctp_ulpevent_release_owner(struct sctp_ulpevent *event)
121 sctp_association_put(event->asoc);
124 /* Create and initialize an SCTP_ASSOC_CHANGE event.
126 * 5.3.1.1 SCTP_ASSOC_CHANGE
128 * Communication notifications inform the ULP that an SCTP association
129 * has either begun or ended. The identifier for a new association is
130 * provided by this notification.
132 * Note: There is no field checking here. If a field is unused it will be
135 struct sctp_ulpevent *sctp_ulpevent_make_assoc_change(
136 const struct sctp_association *asoc,
137 __u16 flags, __u16 state, __u16 error, __u16 outbound,
138 __u16 inbound, int gfp)
140 struct sctp_ulpevent *event;
141 struct sctp_assoc_change *sac;
144 event = sctp_ulpevent_new(sizeof(struct sctp_assoc_change),
145 MSG_NOTIFICATION, gfp);
148 skb = sctp_event2skb(event);
149 sac = (struct sctp_assoc_change *)
150 skb_put(skb, sizeof(struct sctp_assoc_change));
152 /* Socket Extensions for SCTP
153 * 5.3.1.1 SCTP_ASSOC_CHANGE
156 * It should be SCTP_ASSOC_CHANGE.
158 sac->sac_type = SCTP_ASSOC_CHANGE;
160 /* Socket Extensions for SCTP
161 * 5.3.1.1 SCTP_ASSOC_CHANGE
163 * sac_state: 32 bits (signed integer)
164 * This field holds one of a number of values that communicate the
165 * event that happened to the association.
167 sac->sac_state = state;
169 /* Socket Extensions for SCTP
170 * 5.3.1.1 SCTP_ASSOC_CHANGE
172 * sac_flags: 16 bits (unsigned integer)
177 /* Socket Extensions for SCTP
178 * 5.3.1.1 SCTP_ASSOC_CHANGE
180 * sac_length: sizeof (__u32)
181 * This field is the total length of the notification data, including
182 * the notification header.
184 sac->sac_length = sizeof(struct sctp_assoc_change);
186 /* Socket Extensions for SCTP
187 * 5.3.1.1 SCTP_ASSOC_CHANGE
189 * sac_error: 32 bits (signed integer)
191 * If the state was reached due to a error condition (e.g.
192 * COMMUNICATION_LOST) any relevant error information is available in
193 * this field. This corresponds to the protocol error codes defined in
196 sac->sac_error = error;
198 /* Socket Extensions for SCTP
199 * 5.3.1.1 SCTP_ASSOC_CHANGE
201 * sac_outbound_streams: 16 bits (unsigned integer)
202 * sac_inbound_streams: 16 bits (unsigned integer)
204 * The maximum number of streams allowed in each direction are
205 * available in sac_outbound_streams and sac_inbound streams.
207 sac->sac_outbound_streams = outbound;
208 sac->sac_inbound_streams = inbound;
210 /* Socket Extensions for SCTP
211 * 5.3.1.1 SCTP_ASSOC_CHANGE
213 * sac_assoc_id: sizeof (sctp_assoc_t)
215 * The association id field, holds the identifier for the association.
216 * All notifications for a given association have the same association
217 * identifier. For TCP style socket, this field is ignored.
219 sctp_ulpevent_set_owner(event, asoc);
220 sac->sac_assoc_id = sctp_assoc2id(asoc);
228 /* Create and initialize an SCTP_PEER_ADDR_CHANGE event.
230 * Socket Extensions for SCTP - draft-01
231 * 5.3.1.2 SCTP_PEER_ADDR_CHANGE
233 * When a destination address on a multi-homed peer encounters a change
234 * an interface details event is sent.
236 struct sctp_ulpevent *sctp_ulpevent_make_peer_addr_change(
237 const struct sctp_association *asoc,
238 const struct sockaddr_storage *aaddr,
239 int flags, int state, int error, int gfp)
241 struct sctp_ulpevent *event;
242 struct sctp_paddr_change *spc;
245 event = sctp_ulpevent_new(sizeof(struct sctp_paddr_change),
246 MSG_NOTIFICATION, gfp);
250 skb = sctp_event2skb(event);
251 spc = (struct sctp_paddr_change *)
252 skb_put(skb, sizeof(struct sctp_paddr_change));
254 /* Sockets API Extensions for SCTP
255 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
259 * It should be SCTP_PEER_ADDR_CHANGE.
261 spc->spc_type = SCTP_PEER_ADDR_CHANGE;
263 /* Sockets API Extensions for SCTP
264 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
266 * spc_length: sizeof (__u32)
268 * This field is the total length of the notification data, including
269 * the notification header.
271 spc->spc_length = sizeof(struct sctp_paddr_change);
273 /* Sockets API Extensions for SCTP
274 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
276 * spc_flags: 16 bits (unsigned integer)
281 /* Sockets API Extensions for SCTP
282 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
284 * spc_state: 32 bits (signed integer)
286 * This field holds one of a number of values that communicate the
287 * event that happened to the address.
289 spc->spc_state = state;
291 /* Sockets API Extensions for SCTP
292 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
294 * spc_error: 32 bits (signed integer)
296 * If the state was reached due to any error condition (e.g.
297 * ADDRESS_UNREACHABLE) any relevant error information is available in
300 spc->spc_error = error;
302 /* Socket Extensions for SCTP
303 * 5.3.1.1 SCTP_ASSOC_CHANGE
305 * spc_assoc_id: sizeof (sctp_assoc_t)
307 * The association id field, holds the identifier for the association.
308 * All notifications for a given association have the same association
309 * identifier. For TCP style socket, this field is ignored.
311 sctp_ulpevent_set_owner(event, asoc);
312 spc->spc_assoc_id = sctp_assoc2id(asoc);
314 /* Sockets API Extensions for SCTP
315 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
317 * spc_aaddr: sizeof (struct sockaddr_storage)
319 * The affected address field, holds the remote peer's address that is
320 * encountering the change of state.
322 memcpy(&spc->spc_aaddr, aaddr, sizeof(struct sockaddr_storage));
324 /* Map ipv4 address into v4-mapped-on-v6 address. */
325 sctp_get_pf_specific(asoc->base.sk->sk_family)->addr_v4map(
326 sctp_sk(asoc->base.sk),
327 (union sctp_addr *)&spc->spc_aaddr);
335 /* Create and initialize an SCTP_REMOTE_ERROR notification.
337 * Note: This assumes that the chunk->skb->data already points to the
338 * operation error payload.
340 * Socket Extensions for SCTP - draft-01
341 * 5.3.1.3 SCTP_REMOTE_ERROR
343 * A remote peer may send an Operational Error message to its peer.
344 * This message indicates a variety of error conditions on an
345 * association. The entire error TLV as it appears on the wire is
346 * included in a SCTP_REMOTE_ERROR event. Please refer to the SCTP
347 * specification [SCTP] and any extensions for a list of possible
350 struct sctp_ulpevent *sctp_ulpevent_make_remote_error(
351 const struct sctp_association *asoc, struct sctp_chunk *chunk,
352 __u16 flags, int gfp)
354 struct sctp_ulpevent *event;
355 struct sctp_remote_error *sre;
361 ch = (sctp_errhdr_t *)(chunk->skb->data);
363 elen = WORD_ROUND(ntohs(ch->length)) - sizeof(sctp_errhdr_t);
365 /* Pull off the ERROR header. */
366 skb_pull(chunk->skb, sizeof(sctp_errhdr_t));
368 /* Copy the skb to a new skb with room for us to prepend
371 skb = skb_copy_expand(chunk->skb, sizeof(struct sctp_remote_error),
374 /* Pull off the rest of the cause TLV from the chunk. */
375 skb_pull(chunk->skb, elen);
379 /* Embed the event fields inside the cloned skb. */
380 event = sctp_skb2event(skb);
381 sctp_ulpevent_init(event, MSG_NOTIFICATION);
383 sre = (struct sctp_remote_error *)
384 skb_push(skb, sizeof(struct sctp_remote_error));
386 /* Trim the buffer to the right length. */
387 skb_trim(skb, sizeof(struct sctp_remote_error) + elen);
389 /* Socket Extensions for SCTP
390 * 5.3.1.3 SCTP_REMOTE_ERROR
393 * It should be SCTP_REMOTE_ERROR.
395 sre->sre_type = SCTP_REMOTE_ERROR;
398 * Socket Extensions for SCTP
399 * 5.3.1.3 SCTP_REMOTE_ERROR
401 * sre_flags: 16 bits (unsigned integer)
406 /* Socket Extensions for SCTP
407 * 5.3.1.3 SCTP_REMOTE_ERROR
409 * sre_length: sizeof (__u32)
411 * This field is the total length of the notification data,
412 * including the notification header.
414 sre->sre_length = skb->len;
416 /* Socket Extensions for SCTP
417 * 5.3.1.3 SCTP_REMOTE_ERROR
419 * sre_error: 16 bits (unsigned integer)
420 * This value represents one of the Operational Error causes defined in
421 * the SCTP specification, in network byte order.
423 sre->sre_error = cause;
425 /* Socket Extensions for SCTP
426 * 5.3.1.3 SCTP_REMOTE_ERROR
428 * sre_assoc_id: sizeof (sctp_assoc_t)
430 * The association id field, holds the identifier for the association.
431 * All notifications for a given association have the same association
432 * identifier. For TCP style socket, this field is ignored.
434 sctp_ulpevent_set_owner(event, asoc);
435 sre->sre_assoc_id = sctp_assoc2id(asoc);
443 /* Create and initialize a SCTP_SEND_FAILED notification.
445 * Socket Extensions for SCTP - draft-01
446 * 5.3.1.4 SCTP_SEND_FAILED
448 struct sctp_ulpevent *sctp_ulpevent_make_send_failed(
449 const struct sctp_association *asoc, struct sctp_chunk *chunk,
450 __u16 flags, __u32 error, int gfp)
452 struct sctp_ulpevent *event;
453 struct sctp_send_failed *ssf;
456 /* Pull off any padding. */
457 int len = ntohs(chunk->chunk_hdr->length);
459 /* Make skb with more room so we can prepend notification. */
460 skb = skb_copy_expand(chunk->skb,
461 sizeof(struct sctp_send_failed), /* headroom */
467 /* Pull off the common chunk header and DATA header. */
468 skb_pull(skb, sizeof(struct sctp_data_chunk));
469 len -= sizeof(struct sctp_data_chunk);
471 /* Embed the event fields inside the cloned skb. */
472 event = sctp_skb2event(skb);
473 sctp_ulpevent_init(event, MSG_NOTIFICATION);
475 ssf = (struct sctp_send_failed *)
476 skb_push(skb, sizeof(struct sctp_send_failed));
478 /* Socket Extensions for SCTP
479 * 5.3.1.4 SCTP_SEND_FAILED
482 * It should be SCTP_SEND_FAILED.
484 ssf->ssf_type = SCTP_SEND_FAILED;
486 /* Socket Extensions for SCTP
487 * 5.3.1.4 SCTP_SEND_FAILED
489 * ssf_flags: 16 bits (unsigned integer)
490 * The flag value will take one of the following values
492 * SCTP_DATA_UNSENT - Indicates that the data was never put on
495 * SCTP_DATA_SENT - Indicates that the data was put on the wire.
496 * Note that this does not necessarily mean that the
497 * data was (or was not) successfully delivered.
499 ssf->ssf_flags = flags;
501 /* Socket Extensions for SCTP
502 * 5.3.1.4 SCTP_SEND_FAILED
504 * ssf_length: sizeof (__u32)
505 * This field is the total length of the notification data, including
506 * the notification header.
508 ssf->ssf_length = sizeof(struct sctp_send_failed) + len;
509 skb_trim(skb, ssf->ssf_length);
511 /* Socket Extensions for SCTP
512 * 5.3.1.4 SCTP_SEND_FAILED
514 * ssf_error: 16 bits (unsigned integer)
515 * This value represents the reason why the send failed, and if set,
516 * will be a SCTP protocol error code as defined in [SCTP] section
519 ssf->ssf_error = error;
521 /* Socket Extensions for SCTP
522 * 5.3.1.4 SCTP_SEND_FAILED
524 * ssf_info: sizeof (struct sctp_sndrcvinfo)
525 * The original send information associated with the undelivered
528 memcpy(&ssf->ssf_info, &chunk->sinfo, sizeof(struct sctp_sndrcvinfo));
530 /* Per TSVWG discussion with Randy. Allow the application to
531 * ressemble a fragmented message.
533 ssf->ssf_info.sinfo_flags = chunk->chunk_hdr->flags;
535 /* Socket Extensions for SCTP
536 * 5.3.1.4 SCTP_SEND_FAILED
538 * ssf_assoc_id: sizeof (sctp_assoc_t)
539 * The association id field, sf_assoc_id, holds the identifier for the
540 * association. All notifications for a given association have the
541 * same association identifier. For TCP style socket, this field is
544 sctp_ulpevent_set_owner(event, asoc);
545 ssf->ssf_assoc_id = sctp_assoc2id(asoc);
552 /* Create and initialize a SCTP_SHUTDOWN_EVENT notification.
554 * Socket Extensions for SCTP - draft-01
555 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
557 struct sctp_ulpevent *sctp_ulpevent_make_shutdown_event(
558 const struct sctp_association *asoc,
559 __u16 flags, int gfp)
561 struct sctp_ulpevent *event;
562 struct sctp_shutdown_event *sse;
565 event = sctp_ulpevent_new(sizeof(struct sctp_assoc_change),
566 MSG_NOTIFICATION, gfp);
570 skb = sctp_event2skb(event);
571 sse = (struct sctp_shutdown_event *)
572 skb_put(skb, sizeof(struct sctp_shutdown_event));
574 /* Socket Extensions for SCTP
575 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
578 * It should be SCTP_SHUTDOWN_EVENT
580 sse->sse_type = SCTP_SHUTDOWN_EVENT;
582 /* Socket Extensions for SCTP
583 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
585 * sse_flags: 16 bits (unsigned integer)
590 /* Socket Extensions for SCTP
591 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
593 * sse_length: sizeof (__u32)
594 * This field is the total length of the notification data, including
595 * the notification header.
597 sse->sse_length = sizeof(struct sctp_shutdown_event);
599 /* Socket Extensions for SCTP
600 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
602 * sse_assoc_id: sizeof (sctp_assoc_t)
603 * The association id field, holds the identifier for the association.
604 * All notifications for a given association have the same association
605 * identifier. For TCP style socket, this field is ignored.
607 sctp_ulpevent_set_owner(event, asoc);
608 sse->sse_assoc_id = sctp_assoc2id(asoc);
616 /* A message has been received. Package this message as a notification
617 * to pass it to the upper layers. Go ahead and calculate the sndrcvinfo
618 * even if filtered out later.
620 * Socket Extensions for SCTP
621 * 5.2.2 SCTP Header Information Structure (SCTP_SNDRCV)
623 struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
624 struct sctp_chunk *chunk,
627 struct sctp_ulpevent *event = NULL;
631 /* Clone the original skb, sharing the data. */
632 skb = skb_clone(chunk->skb, gfp);
636 /* First calculate the padding, so we don't inadvertently
637 * pass up the wrong length to the user.
639 * RFC 2960 - Section 3.2 Chunk Field Descriptions
641 * The total length of a chunk(including Type, Length and Value fields)
642 * MUST be a multiple of 4 bytes. If the length of the chunk is not a
643 * multiple of 4 bytes, the sender MUST pad the chunk with all zero
644 * bytes and this padding is not included in the chunk length field.
645 * The sender should never pad with more than 3 bytes. The receiver
646 * MUST ignore the padding bytes.
648 len = ntohs(chunk->chunk_hdr->length);
649 padding = WORD_ROUND(len) - len;
651 /* Fixup cloned skb with just this chunks data. */
652 skb_trim(skb, chunk->chunk_end - padding - skb->data);
654 /* Embed the event fields inside the cloned skb. */
655 event = sctp_skb2event(skb);
657 /* Initialize event with flags 0. */
658 sctp_ulpevent_init(event, 0);
660 sctp_ulpevent_receive_data(event, asoc);
662 event->stream = ntohs(chunk->subh.data_hdr->stream);
663 event->ssn = ntohs(chunk->subh.data_hdr->ssn);
664 event->ppid = chunk->subh.data_hdr->ppid;
665 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) {
666 event->flags |= MSG_UNORDERED;
667 event->cumtsn = sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map);
669 event->tsn = ntohl(chunk->subh.data_hdr->tsn);
670 event->msg_flags |= chunk->chunk_hdr->flags;
671 event->iif = sctp_chunk_iif(chunk);
677 /* Create a partial delivery related event.
679 * 5.3.1.7 SCTP_PARTIAL_DELIVERY_EVENT
681 * When a reciever is engaged in a partial delivery of a
682 * message this notification will be used to inidicate
685 struct sctp_ulpevent *sctp_ulpevent_make_pdapi(
686 const struct sctp_association *asoc, __u32 indication, int gfp)
688 struct sctp_ulpevent *event;
689 struct sctp_pdapi_event *pd;
692 event = sctp_ulpevent_new(sizeof(struct sctp_assoc_change),
693 MSG_NOTIFICATION, gfp);
697 skb = sctp_event2skb(event);
698 pd = (struct sctp_pdapi_event *)
699 skb_put(skb, sizeof(struct sctp_pdapi_event));
702 * It should be SCTP_PARTIAL_DELIVERY_EVENT
704 * pdapi_flags: 16 bits (unsigned integer)
707 pd->pdapi_type = SCTP_PARTIAL_DELIVERY_EVENT;
710 /* pdapi_length: 32 bits (unsigned integer)
712 * This field is the total length of the notification data, including
713 * the notification header. It will generally be sizeof (struct
716 pd->pdapi_length = sizeof(struct sctp_pdapi_event);
718 /* pdapi_indication: 32 bits (unsigned integer)
720 * This field holds the indication being sent to the application.
722 pd->pdapi_indication = indication;
724 /* pdapi_assoc_id: sizeof (sctp_assoc_t)
726 * The association id field, holds the identifier for the association.
728 sctp_ulpevent_set_owner(event, asoc);
729 pd->pdapi_assoc_id = sctp_assoc2id(asoc);
736 /* Return the notification type, assuming this is a notification
739 __u16 sctp_ulpevent_get_notification_type(const struct sctp_ulpevent *event)
741 union sctp_notification *notification;
744 skb = sctp_event2skb((struct sctp_ulpevent *)event);
745 notification = (union sctp_notification *) skb->data;
746 return notification->sn_header.sn_type;
749 /* Copy out the sndrcvinfo into a msghdr. */
750 void sctp_ulpevent_read_sndrcvinfo(const struct sctp_ulpevent *event,
751 struct msghdr *msghdr)
753 struct sctp_sndrcvinfo sinfo;
755 if (sctp_ulpevent_is_notification(event))
758 /* Sockets API Extensions for SCTP
759 * Section 5.2.2 SCTP Header Information Structure (SCTP_SNDRCV)
761 * sinfo_stream: 16 bits (unsigned integer)
763 * For recvmsg() the SCTP stack places the message's stream number in
766 sinfo.sinfo_stream = event->stream;
767 /* sinfo_ssn: 16 bits (unsigned integer)
769 * For recvmsg() this value contains the stream sequence number that
770 * the remote endpoint placed in the DATA chunk. For fragmented
771 * messages this is the same number for all deliveries of the message
772 * (if more than one recvmsg() is needed to read the message).
774 sinfo.sinfo_ssn = event->ssn;
775 /* sinfo_ppid: 32 bits (unsigned integer)
777 * In recvmsg() this value is
778 * the same information that was passed by the upper layer in the peer
779 * application. Please note that byte order issues are NOT accounted
780 * for and this information is passed opaquely by the SCTP stack from
781 * one end to the other.
783 sinfo.sinfo_ppid = event->ppid;
784 /* sinfo_flags: 16 bits (unsigned integer)
786 * This field may contain any of the following flags and is composed of
787 * a bitwise OR of these values.
791 * MSG_UNORDERED - This flag is present when the message was sent
794 sinfo.sinfo_flags = event->flags;
795 /* sinfo_tsn: 32 bit (unsigned integer)
797 * For the receiving side, this field holds a TSN that was
798 * assigned to one of the SCTP Data Chunks.
800 sinfo.sinfo_tsn = event->tsn;
801 /* sinfo_cumtsn: 32 bit (unsigned integer)
803 * This field will hold the current cumulative TSN as
804 * known by the underlying SCTP layer. Note this field is
805 * ignored when sending and only valid for a receive
806 * operation when sinfo_flags are set to MSG_UNORDERED.
808 sinfo.sinfo_cumtsn = event->cumtsn;
809 /* sinfo_assoc_id: sizeof (sctp_assoc_t)
811 * The association handle field, sinfo_assoc_id, holds the identifier
812 * for the association announced in the COMMUNICATION_UP notification.
813 * All notifications for a given association have the same identifier.
814 * Ignored for one-to-one style sockets.
816 sinfo.sinfo_assoc_id = sctp_assoc2id(event->asoc);
818 /* These fields are not used while receiving. */
819 sinfo.sinfo_context = 0;
820 sinfo.sinfo_timetolive = 0;
822 put_cmsg(msghdr, IPPROTO_SCTP, SCTP_SNDRCV,
823 sizeof(struct sctp_sndrcvinfo), (void *)&sinfo);
826 /* Do accounting for bytes received and hold a reference to the association
829 static void sctp_ulpevent_receive_data(struct sctp_ulpevent *event,
830 struct sctp_association *asoc)
832 struct sk_buff *skb, *frag;
834 skb = sctp_event2skb(event);
835 /* Set the owner and charge rwnd for bytes received. */
836 sctp_ulpevent_set_owner(event, asoc);
837 sctp_assoc_rwnd_decrease(asoc, skb_headlen(skb));
842 /* Note: Not clearing the entire event struct as this is just a
843 * fragment of the real event. However, we still need to do rwnd
845 * In general, the skb passed from IP can have only 1 level of
846 * fragments. But we allow multiple levels of fragments.
848 for (frag = skb_shinfo(skb)->frag_list; frag; frag = frag->next) {
849 sctp_ulpevent_receive_data(sctp_skb2event(frag), asoc);
853 /* Do accounting for bytes just read by user and release the references to
856 static void sctp_ulpevent_release_data(struct sctp_ulpevent *event)
858 struct sk_buff *skb, *frag;
860 /* Current stack structures assume that the rcv buffer is
861 * per socket. For UDP style sockets this is not true as
862 * multiple associations may be on a single UDP-style socket.
863 * Use the local private area of the skb to track the owning
867 skb = sctp_event2skb(event);
868 sctp_assoc_rwnd_increase(event->asoc, skb_headlen(skb));
873 /* Don't forget the fragments. */
874 for (frag = skb_shinfo(skb)->frag_list; frag; frag = frag->next) {
875 /* NOTE: skb_shinfos are recursive. Although IP returns
876 * skb's with only 1 level of fragments, SCTP reassembly can
877 * increase the levels.
879 sctp_ulpevent_release_data(sctp_skb2event(frag));
883 sctp_ulpevent_release_owner(event);
886 /* Free a ulpevent that has an owner. It includes releasing the reference
887 * to the owner, updating the rwnd in case of a DATA event and freeing the
889 * See comments in sctp_stub_rfree().
891 void sctp_ulpevent_free(struct sctp_ulpevent *event)
893 if (sctp_ulpevent_is_notification(event))
894 sctp_ulpevent_release_owner(event);
896 sctp_ulpevent_release_data(event);
898 kfree_skb(sctp_event2skb(event));
901 /* Purge the skb lists holding ulpevents. */
902 void sctp_queue_purge_ulpevents(struct sk_buff_head *list)
905 while ((skb = skb_dequeue(list)) != NULL)
906 sctp_ulpevent_free(sctp_skb2event(skb));