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 /* Initialize an ULP event from an given skb. */
56 SCTP_STATIC void sctp_ulpevent_init(struct sctp_ulpevent *event, int msg_flags)
58 memset(event, 0, sizeof(struct sctp_ulpevent));
59 event->msg_flags = msg_flags;
62 /* Create a new sctp_ulpevent. */
63 SCTP_STATIC struct sctp_ulpevent *sctp_ulpevent_new(int size, int msg_flags,
66 struct sctp_ulpevent *event;
69 skb = alloc_skb(size, gfp);
73 event = sctp_skb2event(skb);
74 sctp_ulpevent_init(event, msg_flags);
82 /* Is this a MSG_NOTIFICATION? */
83 int sctp_ulpevent_is_notification(const struct sctp_ulpevent *event)
85 return MSG_NOTIFICATION == (event->msg_flags & MSG_NOTIFICATION);
88 /* Hold the association in case the msg_name needs read out of
91 static inline void sctp_ulpevent_set_owner(struct sctp_ulpevent *event,
92 const struct sctp_association *asoc)
96 /* Cast away the const, as we are just wanting to
97 * bump the reference count.
99 sctp_association_hold((struct sctp_association *)asoc);
100 skb = sctp_event2skb(event);
101 event->asoc = (struct sctp_association *)asoc;
102 atomic_add(skb->truesize, &event->asoc->rmem_alloc);
103 skb_set_owner_r(skb, asoc->base.sk);
106 /* A simple destructor to give up the reference to the association. */
107 static inline void sctp_ulpevent_release_owner(struct sctp_ulpevent *event)
109 struct sctp_association *asoc = event->asoc;
110 struct sk_buff *skb = sctp_event2skb(event);
112 atomic_sub(skb->truesize, &asoc->rmem_alloc);
113 sctp_association_put(asoc);
116 /* Create and initialize an SCTP_ASSOC_CHANGE event.
118 * 5.3.1.1 SCTP_ASSOC_CHANGE
120 * Communication notifications inform the ULP that an SCTP association
121 * has either begun or ended. The identifier for a new association is
122 * provided by this notification.
124 * Note: There is no field checking here. If a field is unused it will be
127 struct sctp_ulpevent *sctp_ulpevent_make_assoc_change(
128 const struct sctp_association *asoc,
129 __u16 flags, __u16 state, __u16 error, __u16 outbound,
130 __u16 inbound, gfp_t gfp)
132 struct sctp_ulpevent *event;
133 struct sctp_assoc_change *sac;
136 event = sctp_ulpevent_new(sizeof(struct sctp_assoc_change),
137 MSG_NOTIFICATION, gfp);
140 skb = sctp_event2skb(event);
141 sac = (struct sctp_assoc_change *)
142 skb_put(skb, sizeof(struct sctp_assoc_change));
144 /* Socket Extensions for SCTP
145 * 5.3.1.1 SCTP_ASSOC_CHANGE
148 * It should be SCTP_ASSOC_CHANGE.
150 sac->sac_type = SCTP_ASSOC_CHANGE;
152 /* Socket Extensions for SCTP
153 * 5.3.1.1 SCTP_ASSOC_CHANGE
155 * sac_state: 32 bits (signed integer)
156 * This field holds one of a number of values that communicate the
157 * event that happened to the association.
159 sac->sac_state = state;
161 /* Socket Extensions for SCTP
162 * 5.3.1.1 SCTP_ASSOC_CHANGE
164 * sac_flags: 16 bits (unsigned integer)
169 /* Socket Extensions for SCTP
170 * 5.3.1.1 SCTP_ASSOC_CHANGE
172 * sac_length: sizeof (__u32)
173 * This field is the total length of the notification data, including
174 * the notification header.
176 sac->sac_length = sizeof(struct sctp_assoc_change);
178 /* Socket Extensions for SCTP
179 * 5.3.1.1 SCTP_ASSOC_CHANGE
181 * sac_error: 32 bits (signed integer)
183 * If the state was reached due to a error condition (e.g.
184 * COMMUNICATION_LOST) any relevant error information is available in
185 * this field. This corresponds to the protocol error codes defined in
188 sac->sac_error = error;
190 /* Socket Extensions for SCTP
191 * 5.3.1.1 SCTP_ASSOC_CHANGE
193 * sac_outbound_streams: 16 bits (unsigned integer)
194 * sac_inbound_streams: 16 bits (unsigned integer)
196 * The maximum number of streams allowed in each direction are
197 * available in sac_outbound_streams and sac_inbound streams.
199 sac->sac_outbound_streams = outbound;
200 sac->sac_inbound_streams = inbound;
202 /* Socket Extensions for SCTP
203 * 5.3.1.1 SCTP_ASSOC_CHANGE
205 * sac_assoc_id: sizeof (sctp_assoc_t)
207 * The association id field, holds the identifier for the association.
208 * All notifications for a given association have the same association
209 * identifier. For TCP style socket, this field is ignored.
211 sctp_ulpevent_set_owner(event, asoc);
212 sac->sac_assoc_id = sctp_assoc2id(asoc);
220 /* Create and initialize an SCTP_PEER_ADDR_CHANGE event.
222 * Socket Extensions for SCTP - draft-01
223 * 5.3.1.2 SCTP_PEER_ADDR_CHANGE
225 * When a destination address on a multi-homed peer encounters a change
226 * an interface details event is sent.
228 struct sctp_ulpevent *sctp_ulpevent_make_peer_addr_change(
229 const struct sctp_association *asoc,
230 const struct sockaddr_storage *aaddr,
231 int flags, int state, int error, gfp_t gfp)
233 struct sctp_ulpevent *event;
234 struct sctp_paddr_change *spc;
237 event = sctp_ulpevent_new(sizeof(struct sctp_paddr_change),
238 MSG_NOTIFICATION, gfp);
242 skb = sctp_event2skb(event);
243 spc = (struct sctp_paddr_change *)
244 skb_put(skb, sizeof(struct sctp_paddr_change));
246 /* Sockets API Extensions for SCTP
247 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
251 * It should be SCTP_PEER_ADDR_CHANGE.
253 spc->spc_type = SCTP_PEER_ADDR_CHANGE;
255 /* Sockets API Extensions for SCTP
256 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
258 * spc_length: sizeof (__u32)
260 * This field is the total length of the notification data, including
261 * the notification header.
263 spc->spc_length = sizeof(struct sctp_paddr_change);
265 /* Sockets API Extensions for SCTP
266 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
268 * spc_flags: 16 bits (unsigned integer)
273 /* Sockets API Extensions for SCTP
274 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
276 * spc_state: 32 bits (signed integer)
278 * This field holds one of a number of values that communicate the
279 * event that happened to the address.
281 spc->spc_state = state;
283 /* Sockets API Extensions for SCTP
284 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
286 * spc_error: 32 bits (signed integer)
288 * If the state was reached due to any error condition (e.g.
289 * ADDRESS_UNREACHABLE) any relevant error information is available in
292 spc->spc_error = error;
294 /* Socket Extensions for SCTP
295 * 5.3.1.1 SCTP_ASSOC_CHANGE
297 * spc_assoc_id: sizeof (sctp_assoc_t)
299 * The association id field, holds the identifier for the association.
300 * All notifications for a given association have the same association
301 * identifier. For TCP style socket, this field is ignored.
303 sctp_ulpevent_set_owner(event, asoc);
304 spc->spc_assoc_id = sctp_assoc2id(asoc);
306 /* Sockets API Extensions for SCTP
307 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
309 * spc_aaddr: sizeof (struct sockaddr_storage)
311 * The affected address field, holds the remote peer's address that is
312 * encountering the change of state.
314 memcpy(&spc->spc_aaddr, aaddr, sizeof(struct sockaddr_storage));
316 /* Map ipv4 address into v4-mapped-on-v6 address. */
317 sctp_get_pf_specific(asoc->base.sk->sk_family)->addr_v4map(
318 sctp_sk(asoc->base.sk),
319 (union sctp_addr *)&spc->spc_aaddr);
327 /* Create and initialize an SCTP_REMOTE_ERROR notification.
329 * Note: This assumes that the chunk->skb->data already points to the
330 * operation error payload.
332 * Socket Extensions for SCTP - draft-01
333 * 5.3.1.3 SCTP_REMOTE_ERROR
335 * A remote peer may send an Operational Error message to its peer.
336 * This message indicates a variety of error conditions on an
337 * association. The entire error TLV as it appears on the wire is
338 * included in a SCTP_REMOTE_ERROR event. Please refer to the SCTP
339 * specification [SCTP] and any extensions for a list of possible
342 struct sctp_ulpevent *sctp_ulpevent_make_remote_error(
343 const struct sctp_association *asoc, struct sctp_chunk *chunk,
344 __u16 flags, gfp_t gfp)
346 struct sctp_ulpevent *event;
347 struct sctp_remote_error *sre;
353 ch = (sctp_errhdr_t *)(chunk->skb->data);
355 elen = WORD_ROUND(ntohs(ch->length)) - sizeof(sctp_errhdr_t);
357 /* Pull off the ERROR header. */
358 skb_pull(chunk->skb, sizeof(sctp_errhdr_t));
360 /* Copy the skb to a new skb with room for us to prepend
363 skb = skb_copy_expand(chunk->skb, sizeof(struct sctp_remote_error),
366 /* Pull off the rest of the cause TLV from the chunk. */
367 skb_pull(chunk->skb, elen);
371 /* Embed the event fields inside the cloned skb. */
372 event = sctp_skb2event(skb);
373 sctp_ulpevent_init(event, MSG_NOTIFICATION);
375 sre = (struct sctp_remote_error *)
376 skb_push(skb, sizeof(struct sctp_remote_error));
378 /* Trim the buffer to the right length. */
379 skb_trim(skb, sizeof(struct sctp_remote_error) + elen);
381 /* Socket Extensions for SCTP
382 * 5.3.1.3 SCTP_REMOTE_ERROR
385 * It should be SCTP_REMOTE_ERROR.
387 sre->sre_type = SCTP_REMOTE_ERROR;
390 * Socket Extensions for SCTP
391 * 5.3.1.3 SCTP_REMOTE_ERROR
393 * sre_flags: 16 bits (unsigned integer)
398 /* Socket Extensions for SCTP
399 * 5.3.1.3 SCTP_REMOTE_ERROR
401 * sre_length: sizeof (__u32)
403 * This field is the total length of the notification data,
404 * including the notification header.
406 sre->sre_length = skb->len;
408 /* Socket Extensions for SCTP
409 * 5.3.1.3 SCTP_REMOTE_ERROR
411 * sre_error: 16 bits (unsigned integer)
412 * This value represents one of the Operational Error causes defined in
413 * the SCTP specification, in network byte order.
415 sre->sre_error = cause;
417 /* Socket Extensions for SCTP
418 * 5.3.1.3 SCTP_REMOTE_ERROR
420 * sre_assoc_id: sizeof (sctp_assoc_t)
422 * The association id field, holds the identifier for the association.
423 * All notifications for a given association have the same association
424 * identifier. For TCP style socket, this field is ignored.
426 sctp_ulpevent_set_owner(event, asoc);
427 sre->sre_assoc_id = sctp_assoc2id(asoc);
435 /* Create and initialize a SCTP_SEND_FAILED notification.
437 * Socket Extensions for SCTP - draft-01
438 * 5.3.1.4 SCTP_SEND_FAILED
440 struct sctp_ulpevent *sctp_ulpevent_make_send_failed(
441 const struct sctp_association *asoc, struct sctp_chunk *chunk,
442 __u16 flags, __u32 error, gfp_t gfp)
444 struct sctp_ulpevent *event;
445 struct sctp_send_failed *ssf;
448 /* Pull off any padding. */
449 int len = ntohs(chunk->chunk_hdr->length);
451 /* Make skb with more room so we can prepend notification. */
452 skb = skb_copy_expand(chunk->skb,
453 sizeof(struct sctp_send_failed), /* headroom */
459 /* Pull off the common chunk header and DATA header. */
460 skb_pull(skb, sizeof(struct sctp_data_chunk));
461 len -= sizeof(struct sctp_data_chunk);
463 /* Embed the event fields inside the cloned skb. */
464 event = sctp_skb2event(skb);
465 sctp_ulpevent_init(event, MSG_NOTIFICATION);
467 ssf = (struct sctp_send_failed *)
468 skb_push(skb, sizeof(struct sctp_send_failed));
470 /* Socket Extensions for SCTP
471 * 5.3.1.4 SCTP_SEND_FAILED
474 * It should be SCTP_SEND_FAILED.
476 ssf->ssf_type = SCTP_SEND_FAILED;
478 /* Socket Extensions for SCTP
479 * 5.3.1.4 SCTP_SEND_FAILED
481 * ssf_flags: 16 bits (unsigned integer)
482 * The flag value will take one of the following values
484 * SCTP_DATA_UNSENT - Indicates that the data was never put on
487 * SCTP_DATA_SENT - Indicates that the data was put on the wire.
488 * Note that this does not necessarily mean that the
489 * data was (or was not) successfully delivered.
491 ssf->ssf_flags = flags;
493 /* Socket Extensions for SCTP
494 * 5.3.1.4 SCTP_SEND_FAILED
496 * ssf_length: sizeof (__u32)
497 * This field is the total length of the notification data, including
498 * the notification header.
500 ssf->ssf_length = sizeof(struct sctp_send_failed) + len;
501 skb_trim(skb, ssf->ssf_length);
503 /* Socket Extensions for SCTP
504 * 5.3.1.4 SCTP_SEND_FAILED
506 * ssf_error: 16 bits (unsigned integer)
507 * This value represents the reason why the send failed, and if set,
508 * will be a SCTP protocol error code as defined in [SCTP] section
511 ssf->ssf_error = error;
513 /* Socket Extensions for SCTP
514 * 5.3.1.4 SCTP_SEND_FAILED
516 * ssf_info: sizeof (struct sctp_sndrcvinfo)
517 * The original send information associated with the undelivered
520 memcpy(&ssf->ssf_info, &chunk->sinfo, sizeof(struct sctp_sndrcvinfo));
522 /* Per TSVWG discussion with Randy. Allow the application to
523 * ressemble a fragmented message.
525 ssf->ssf_info.sinfo_flags = chunk->chunk_hdr->flags;
527 /* Socket Extensions for SCTP
528 * 5.3.1.4 SCTP_SEND_FAILED
530 * ssf_assoc_id: sizeof (sctp_assoc_t)
531 * The association id field, sf_assoc_id, holds the identifier for the
532 * association. All notifications for a given association have the
533 * same association identifier. For TCP style socket, this field is
536 sctp_ulpevent_set_owner(event, asoc);
537 ssf->ssf_assoc_id = sctp_assoc2id(asoc);
544 /* Create and initialize a SCTP_SHUTDOWN_EVENT notification.
546 * Socket Extensions for SCTP - draft-01
547 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
549 struct sctp_ulpevent *sctp_ulpevent_make_shutdown_event(
550 const struct sctp_association *asoc,
551 __u16 flags, gfp_t gfp)
553 struct sctp_ulpevent *event;
554 struct sctp_shutdown_event *sse;
557 event = sctp_ulpevent_new(sizeof(struct sctp_shutdown_event),
558 MSG_NOTIFICATION, gfp);
562 skb = sctp_event2skb(event);
563 sse = (struct sctp_shutdown_event *)
564 skb_put(skb, sizeof(struct sctp_shutdown_event));
566 /* Socket Extensions for SCTP
567 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
570 * It should be SCTP_SHUTDOWN_EVENT
572 sse->sse_type = SCTP_SHUTDOWN_EVENT;
574 /* Socket Extensions for SCTP
575 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
577 * sse_flags: 16 bits (unsigned integer)
582 /* Socket Extensions for SCTP
583 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
585 * sse_length: sizeof (__u32)
586 * This field is the total length of the notification data, including
587 * the notification header.
589 sse->sse_length = sizeof(struct sctp_shutdown_event);
591 /* Socket Extensions for SCTP
592 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
594 * sse_assoc_id: sizeof (sctp_assoc_t)
595 * The association id field, holds the identifier for the association.
596 * All notifications for a given association have the same association
597 * identifier. For TCP style socket, this field is ignored.
599 sctp_ulpevent_set_owner(event, asoc);
600 sse->sse_assoc_id = sctp_assoc2id(asoc);
608 /* Create and initialize a SCTP_ADAPTION_INDICATION notification.
610 * Socket Extensions for SCTP
611 * 5.3.1.6 SCTP_ADAPTION_INDICATION
613 struct sctp_ulpevent *sctp_ulpevent_make_adaption_indication(
614 const struct sctp_association *asoc, gfp_t gfp)
616 struct sctp_ulpevent *event;
617 struct sctp_adaption_event *sai;
620 event = sctp_ulpevent_new(sizeof(struct sctp_adaption_event),
621 MSG_NOTIFICATION, gfp);
625 skb = sctp_event2skb(event);
626 sai = (struct sctp_adaption_event *)
627 skb_put(skb, sizeof(struct sctp_adaption_event));
629 sai->sai_type = SCTP_ADAPTION_INDICATION;
631 sai->sai_length = sizeof(struct sctp_adaption_event);
632 sai->sai_adaption_ind = asoc->peer.adaption_ind;
633 sctp_ulpevent_set_owner(event, asoc);
634 sai->sai_assoc_id = sctp_assoc2id(asoc);
642 /* A message has been received. Package this message as a notification
643 * to pass it to the upper layers. Go ahead and calculate the sndrcvinfo
644 * even if filtered out later.
646 * Socket Extensions for SCTP
647 * 5.2.2 SCTP Header Information Structure (SCTP_SNDRCV)
649 struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
650 struct sctp_chunk *chunk,
653 struct sctp_ulpevent *event = NULL;
657 /* Clone the original skb, sharing the data. */
658 skb = skb_clone(chunk->skb, gfp);
662 /* First calculate the padding, so we don't inadvertently
663 * pass up the wrong length to the user.
665 * RFC 2960 - Section 3.2 Chunk Field Descriptions
667 * The total length of a chunk(including Type, Length and Value fields)
668 * MUST be a multiple of 4 bytes. If the length of the chunk is not a
669 * multiple of 4 bytes, the sender MUST pad the chunk with all zero
670 * bytes and this padding is not included in the chunk length field.
671 * The sender should never pad with more than 3 bytes. The receiver
672 * MUST ignore the padding bytes.
674 len = ntohs(chunk->chunk_hdr->length);
675 padding = WORD_ROUND(len) - len;
677 /* Fixup cloned skb with just this chunks data. */
678 skb_trim(skb, chunk->chunk_end - padding - skb->data);
680 /* Embed the event fields inside the cloned skb. */
681 event = sctp_skb2event(skb);
683 /* Initialize event with flags 0. */
684 sctp_ulpevent_init(event, 0);
686 sctp_ulpevent_receive_data(event, asoc);
688 event->stream = ntohs(chunk->subh.data_hdr->stream);
689 event->ssn = ntohs(chunk->subh.data_hdr->ssn);
690 event->ppid = chunk->subh.data_hdr->ppid;
691 if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) {
692 event->flags |= SCTP_UNORDERED;
693 event->cumtsn = sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map);
695 event->tsn = ntohl(chunk->subh.data_hdr->tsn);
696 event->msg_flags |= chunk->chunk_hdr->flags;
697 event->iif = sctp_chunk_iif(chunk);
703 /* Create a partial delivery related event.
705 * 5.3.1.7 SCTP_PARTIAL_DELIVERY_EVENT
707 * When a receiver is engaged in a partial delivery of a
708 * message this notification will be used to indicate
711 struct sctp_ulpevent *sctp_ulpevent_make_pdapi(
712 const struct sctp_association *asoc, __u32 indication,
715 struct sctp_ulpevent *event;
716 struct sctp_pdapi_event *pd;
719 event = sctp_ulpevent_new(sizeof(struct sctp_pdapi_event),
720 MSG_NOTIFICATION, gfp);
724 skb = sctp_event2skb(event);
725 pd = (struct sctp_pdapi_event *)
726 skb_put(skb, sizeof(struct sctp_pdapi_event));
729 * It should be SCTP_PARTIAL_DELIVERY_EVENT
731 * pdapi_flags: 16 bits (unsigned integer)
734 pd->pdapi_type = SCTP_PARTIAL_DELIVERY_EVENT;
737 /* pdapi_length: 32 bits (unsigned integer)
739 * This field is the total length of the notification data, including
740 * the notification header. It will generally be sizeof (struct
743 pd->pdapi_length = sizeof(struct sctp_pdapi_event);
745 /* pdapi_indication: 32 bits (unsigned integer)
747 * This field holds the indication being sent to the application.
749 pd->pdapi_indication = indication;
751 /* pdapi_assoc_id: sizeof (sctp_assoc_t)
753 * The association id field, holds the identifier for the association.
755 sctp_ulpevent_set_owner(event, asoc);
756 pd->pdapi_assoc_id = sctp_assoc2id(asoc);
763 /* Return the notification type, assuming this is a notification
766 __u16 sctp_ulpevent_get_notification_type(const struct sctp_ulpevent *event)
768 union sctp_notification *notification;
771 skb = sctp_event2skb((struct sctp_ulpevent *)event);
772 notification = (union sctp_notification *) skb->data;
773 return notification->sn_header.sn_type;
776 /* Copy out the sndrcvinfo into a msghdr. */
777 void sctp_ulpevent_read_sndrcvinfo(const struct sctp_ulpevent *event,
778 struct msghdr *msghdr)
780 struct sctp_sndrcvinfo sinfo;
782 if (sctp_ulpevent_is_notification(event))
785 /* Sockets API Extensions for SCTP
786 * Section 5.2.2 SCTP Header Information Structure (SCTP_SNDRCV)
788 * sinfo_stream: 16 bits (unsigned integer)
790 * For recvmsg() the SCTP stack places the message's stream number in
793 sinfo.sinfo_stream = event->stream;
794 /* sinfo_ssn: 16 bits (unsigned integer)
796 * For recvmsg() this value contains the stream sequence number that
797 * the remote endpoint placed in the DATA chunk. For fragmented
798 * messages this is the same number for all deliveries of the message
799 * (if more than one recvmsg() is needed to read the message).
801 sinfo.sinfo_ssn = event->ssn;
802 /* sinfo_ppid: 32 bits (unsigned integer)
804 * In recvmsg() this value is
805 * the same information that was passed by the upper layer in the peer
806 * application. Please note that byte order issues are NOT accounted
807 * for and this information is passed opaquely by the SCTP stack from
808 * one end to the other.
810 sinfo.sinfo_ppid = event->ppid;
811 /* sinfo_flags: 16 bits (unsigned integer)
813 * This field may contain any of the following flags and is composed of
814 * a bitwise OR of these values.
818 * SCTP_UNORDERED - This flag is present when the message was sent
821 sinfo.sinfo_flags = event->flags;
822 /* sinfo_tsn: 32 bit (unsigned integer)
824 * For the receiving side, this field holds a TSN that was
825 * assigned to one of the SCTP Data Chunks.
827 sinfo.sinfo_tsn = event->tsn;
828 /* sinfo_cumtsn: 32 bit (unsigned integer)
830 * This field will hold the current cumulative TSN as
831 * known by the underlying SCTP layer. Note this field is
832 * ignored when sending and only valid for a receive
833 * operation when sinfo_flags are set to SCTP_UNORDERED.
835 sinfo.sinfo_cumtsn = event->cumtsn;
836 /* sinfo_assoc_id: sizeof (sctp_assoc_t)
838 * The association handle field, sinfo_assoc_id, holds the identifier
839 * for the association announced in the COMMUNICATION_UP notification.
840 * All notifications for a given association have the same identifier.
841 * Ignored for one-to-one style sockets.
843 sinfo.sinfo_assoc_id = sctp_assoc2id(event->asoc);
845 /* These fields are not used while receiving. */
846 sinfo.sinfo_context = 0;
847 sinfo.sinfo_timetolive = 0;
849 put_cmsg(msghdr, IPPROTO_SCTP, SCTP_SNDRCV,
850 sizeof(struct sctp_sndrcvinfo), (void *)&sinfo);
853 /* Do accounting for bytes received and hold a reference to the association
856 static void sctp_ulpevent_receive_data(struct sctp_ulpevent *event,
857 struct sctp_association *asoc)
859 struct sk_buff *skb, *frag;
861 skb = sctp_event2skb(event);
862 /* Set the owner and charge rwnd for bytes received. */
863 sctp_ulpevent_set_owner(event, asoc);
864 sctp_assoc_rwnd_decrease(asoc, skb_headlen(skb));
869 /* Note: Not clearing the entire event struct as this is just a
870 * fragment of the real event. However, we still need to do rwnd
872 * In general, the skb passed from IP can have only 1 level of
873 * fragments. But we allow multiple levels of fragments.
875 for (frag = skb_shinfo(skb)->frag_list; frag; frag = frag->next) {
876 sctp_ulpevent_receive_data(sctp_skb2event(frag), asoc);
880 /* Do accounting for bytes just read by user and release the references to
883 static void sctp_ulpevent_release_data(struct sctp_ulpevent *event)
885 struct sk_buff *skb, *frag;
887 /* Current stack structures assume that the rcv buffer is
888 * per socket. For UDP style sockets this is not true as
889 * multiple associations may be on a single UDP-style socket.
890 * Use the local private area of the skb to track the owning
894 skb = sctp_event2skb(event);
895 sctp_assoc_rwnd_increase(event->asoc, skb_headlen(skb));
900 /* Don't forget the fragments. */
901 for (frag = skb_shinfo(skb)->frag_list; frag; frag = frag->next) {
902 /* NOTE: skb_shinfos are recursive. Although IP returns
903 * skb's with only 1 level of fragments, SCTP reassembly can
904 * increase the levels.
906 sctp_ulpevent_release_data(sctp_skb2event(frag));
910 sctp_ulpevent_release_owner(event);
913 /* Free a ulpevent that has an owner. It includes releasing the reference
914 * to the owner, updating the rwnd in case of a DATA event and freeing the
917 void sctp_ulpevent_free(struct sctp_ulpevent *event)
919 if (sctp_ulpevent_is_notification(event))
920 sctp_ulpevent_release_owner(event);
922 sctp_ulpevent_release_data(event);
924 kfree_skb(sctp_event2skb(event));
927 /* Purge the skb lists holding ulpevents. */
928 void sctp_queue_purge_ulpevents(struct sk_buff_head *list)
931 while ((skb = skb_dequeue(list)) != NULL)
932 sctp_ulpevent_free(sctp_skb2event(skb));