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 /* Initialize an ULP event from an given skb. */
69 SCTP_STATIC
void sctp_ulpevent_init(struct sctp_ulpevent
*event
, int msg_flags
)
71 memset(event
, 0, sizeof(struct sctp_ulpevent
));
72 event
->msg_flags
= msg_flags
;
75 /* Create a new sctp_ulpevent. */
76 SCTP_STATIC
struct sctp_ulpevent
*sctp_ulpevent_new(int size
, int msg_flags
,
79 struct sctp_ulpevent
*event
;
82 skb
= alloc_skb(size
, gfp
);
86 event
= sctp_skb2event(skb
);
87 sctp_ulpevent_init(event
, msg_flags
);
95 /* Is this a MSG_NOTIFICATION? */
96 int sctp_ulpevent_is_notification(const struct sctp_ulpevent
*event
)
98 return MSG_NOTIFICATION
== (event
->msg_flags
& MSG_NOTIFICATION
);
101 /* Hold the association in case the msg_name needs read out of
104 static inline void sctp_ulpevent_set_owner(struct sctp_ulpevent
*event
,
105 const struct sctp_association
*asoc
)
109 /* Cast away the const, as we are just wanting to
110 * bump the reference count.
112 sctp_association_hold((struct sctp_association
*)asoc
);
113 skb
= sctp_event2skb(event
);
114 skb
->sk
= asoc
->base
.sk
;
115 event
->asoc
= (struct sctp_association
*)asoc
;
116 skb
->destructor
= sctp_stub_rfree
;
119 /* A simple destructor to give up the reference to the association. */
120 static inline void sctp_ulpevent_release_owner(struct sctp_ulpevent
*event
)
122 sctp_association_put(event
->asoc
);
125 /* Create and initialize an SCTP_ASSOC_CHANGE event.
127 * 5.3.1.1 SCTP_ASSOC_CHANGE
129 * Communication notifications inform the ULP that an SCTP association
130 * has either begun or ended. The identifier for a new association is
131 * provided by this notification.
133 * Note: There is no field checking here. If a field is unused it will be
136 struct sctp_ulpevent
*sctp_ulpevent_make_assoc_change(
137 const struct sctp_association
*asoc
,
138 __u16 flags
, __u16 state
, __u16 error
, __u16 outbound
,
139 __u16 inbound
, int gfp
)
141 struct sctp_ulpevent
*event
;
142 struct sctp_assoc_change
*sac
;
145 event
= sctp_ulpevent_new(sizeof(struct sctp_assoc_change
),
146 MSG_NOTIFICATION
, gfp
);
149 skb
= sctp_event2skb(event
);
150 sac
= (struct sctp_assoc_change
*)
151 skb_put(skb
, sizeof(struct sctp_assoc_change
));
153 /* Socket Extensions for SCTP
154 * 5.3.1.1 SCTP_ASSOC_CHANGE
157 * It should be SCTP_ASSOC_CHANGE.
159 sac
->sac_type
= SCTP_ASSOC_CHANGE
;
161 /* Socket Extensions for SCTP
162 * 5.3.1.1 SCTP_ASSOC_CHANGE
164 * sac_state: 32 bits (signed integer)
165 * This field holds one of a number of values that communicate the
166 * event that happened to the association.
168 sac
->sac_state
= state
;
170 /* Socket Extensions for SCTP
171 * 5.3.1.1 SCTP_ASSOC_CHANGE
173 * sac_flags: 16 bits (unsigned integer)
178 /* Socket Extensions for SCTP
179 * 5.3.1.1 SCTP_ASSOC_CHANGE
181 * sac_length: sizeof (__u32)
182 * This field is the total length of the notification data, including
183 * the notification header.
185 sac
->sac_length
= sizeof(struct sctp_assoc_change
);
187 /* Socket Extensions for SCTP
188 * 5.3.1.1 SCTP_ASSOC_CHANGE
190 * sac_error: 32 bits (signed integer)
192 * If the state was reached due to a error condition (e.g.
193 * COMMUNICATION_LOST) any relevant error information is available in
194 * this field. This corresponds to the protocol error codes defined in
197 sac
->sac_error
= error
;
199 /* Socket Extensions for SCTP
200 * 5.3.1.1 SCTP_ASSOC_CHANGE
202 * sac_outbound_streams: 16 bits (unsigned integer)
203 * sac_inbound_streams: 16 bits (unsigned integer)
205 * The maximum number of streams allowed in each direction are
206 * available in sac_outbound_streams and sac_inbound streams.
208 sac
->sac_outbound_streams
= outbound
;
209 sac
->sac_inbound_streams
= inbound
;
211 /* Socket Extensions for SCTP
212 * 5.3.1.1 SCTP_ASSOC_CHANGE
214 * sac_assoc_id: sizeof (sctp_assoc_t)
216 * The association id field, holds the identifier for the association.
217 * All notifications for a given association have the same association
218 * identifier. For TCP style socket, this field is ignored.
220 sctp_ulpevent_set_owner(event
, asoc
);
221 sac
->sac_assoc_id
= sctp_assoc2id(asoc
);
229 /* Create and initialize an SCTP_PEER_ADDR_CHANGE event.
231 * Socket Extensions for SCTP - draft-01
232 * 5.3.1.2 SCTP_PEER_ADDR_CHANGE
234 * When a destination address on a multi-homed peer encounters a change
235 * an interface details event is sent.
237 struct sctp_ulpevent
*sctp_ulpevent_make_peer_addr_change(
238 const struct sctp_association
*asoc
,
239 const struct sockaddr_storage
*aaddr
,
240 int flags
, int state
, int error
, int gfp
)
242 struct sctp_ulpevent
*event
;
243 struct sctp_paddr_change
*spc
;
246 event
= sctp_ulpevent_new(sizeof(struct sctp_paddr_change
),
247 MSG_NOTIFICATION
, gfp
);
251 skb
= sctp_event2skb(event
);
252 spc
= (struct sctp_paddr_change
*)
253 skb_put(skb
, sizeof(struct sctp_paddr_change
));
255 /* Sockets API Extensions for SCTP
256 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
260 * It should be SCTP_PEER_ADDR_CHANGE.
262 spc
->spc_type
= SCTP_PEER_ADDR_CHANGE
;
264 /* Sockets API Extensions for SCTP
265 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
267 * spc_length: sizeof (__u32)
269 * This field is the total length of the notification data, including
270 * the notification header.
272 spc
->spc_length
= sizeof(struct sctp_paddr_change
);
274 /* Sockets API Extensions for SCTP
275 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
277 * spc_flags: 16 bits (unsigned integer)
282 /* Sockets API Extensions for SCTP
283 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
285 * spc_state: 32 bits (signed integer)
287 * This field holds one of a number of values that communicate the
288 * event that happened to the address.
290 spc
->spc_state
= state
;
292 /* Sockets API Extensions for SCTP
293 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
295 * spc_error: 32 bits (signed integer)
297 * If the state was reached due to any error condition (e.g.
298 * ADDRESS_UNREACHABLE) any relevant error information is available in
301 spc
->spc_error
= error
;
303 /* Socket Extensions for SCTP
304 * 5.3.1.1 SCTP_ASSOC_CHANGE
306 * spc_assoc_id: sizeof (sctp_assoc_t)
308 * The association id field, holds the identifier for the association.
309 * All notifications for a given association have the same association
310 * identifier. For TCP style socket, this field is ignored.
312 sctp_ulpevent_set_owner(event
, asoc
);
313 spc
->spc_assoc_id
= sctp_assoc2id(asoc
);
315 /* Sockets API Extensions for SCTP
316 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
318 * spc_aaddr: sizeof (struct sockaddr_storage)
320 * The affected address field, holds the remote peer's address that is
321 * encountering the change of state.
323 memcpy(&spc
->spc_aaddr
, aaddr
, sizeof(struct sockaddr_storage
));
325 /* Map ipv4 address into v4-mapped-on-v6 address. */
326 sctp_get_pf_specific(asoc
->base
.sk
->sk_family
)->addr_v4map(
327 sctp_sk(asoc
->base
.sk
),
328 (union sctp_addr
*)&spc
->spc_aaddr
);
336 /* Create and initialize an SCTP_REMOTE_ERROR notification.
338 * Note: This assumes that the chunk->skb->data already points to the
339 * operation error payload.
341 * Socket Extensions for SCTP - draft-01
342 * 5.3.1.3 SCTP_REMOTE_ERROR
344 * A remote peer may send an Operational Error message to its peer.
345 * This message indicates a variety of error conditions on an
346 * association. The entire error TLV as it appears on the wire is
347 * included in a SCTP_REMOTE_ERROR event. Please refer to the SCTP
348 * specification [SCTP] and any extensions for a list of possible
351 struct sctp_ulpevent
*sctp_ulpevent_make_remote_error(
352 const struct sctp_association
*asoc
, struct sctp_chunk
*chunk
,
353 __u16 flags
, int gfp
)
355 struct sctp_ulpevent
*event
;
356 struct sctp_remote_error
*sre
;
362 ch
= (sctp_errhdr_t
*)(chunk
->skb
->data
);
364 elen
= WORD_ROUND(ntohs(ch
->length
)) - sizeof(sctp_errhdr_t
);
366 /* Pull off the ERROR header. */
367 skb_pull(chunk
->skb
, sizeof(sctp_errhdr_t
));
369 /* Copy the skb to a new skb with room for us to prepend
372 skb
= skb_copy_expand(chunk
->skb
, sizeof(struct sctp_remote_error
),
375 /* Pull off the rest of the cause TLV from the chunk. */
376 skb_pull(chunk
->skb
, elen
);
380 /* Embed the event fields inside the cloned skb. */
381 event
= sctp_skb2event(skb
);
382 sctp_ulpevent_init(event
, MSG_NOTIFICATION
);
384 sre
= (struct sctp_remote_error
*)
385 skb_push(skb
, sizeof(struct sctp_remote_error
));
387 /* Trim the buffer to the right length. */
388 skb_trim(skb
, sizeof(struct sctp_remote_error
) + elen
);
390 /* Socket Extensions for SCTP
391 * 5.3.1.3 SCTP_REMOTE_ERROR
394 * It should be SCTP_REMOTE_ERROR.
396 sre
->sre_type
= SCTP_REMOTE_ERROR
;
399 * Socket Extensions for SCTP
400 * 5.3.1.3 SCTP_REMOTE_ERROR
402 * sre_flags: 16 bits (unsigned integer)
407 /* Socket Extensions for SCTP
408 * 5.3.1.3 SCTP_REMOTE_ERROR
410 * sre_length: sizeof (__u32)
412 * This field is the total length of the notification data,
413 * including the notification header.
415 sre
->sre_length
= skb
->len
;
417 /* Socket Extensions for SCTP
418 * 5.3.1.3 SCTP_REMOTE_ERROR
420 * sre_error: 16 bits (unsigned integer)
421 * This value represents one of the Operational Error causes defined in
422 * the SCTP specification, in network byte order.
424 sre
->sre_error
= cause
;
426 /* Socket Extensions for SCTP
427 * 5.3.1.3 SCTP_REMOTE_ERROR
429 * sre_assoc_id: sizeof (sctp_assoc_t)
431 * The association id field, holds the identifier for the association.
432 * All notifications for a given association have the same association
433 * identifier. For TCP style socket, this field is ignored.
435 sctp_ulpevent_set_owner(event
, asoc
);
436 sre
->sre_assoc_id
= sctp_assoc2id(asoc
);
444 /* Create and initialize a SCTP_SEND_FAILED notification.
446 * Socket Extensions for SCTP - draft-01
447 * 5.3.1.4 SCTP_SEND_FAILED
449 struct sctp_ulpevent
*sctp_ulpevent_make_send_failed(
450 const struct sctp_association
*asoc
, struct sctp_chunk
*chunk
,
451 __u16 flags
, __u32 error
, int gfp
)
453 struct sctp_ulpevent
*event
;
454 struct sctp_send_failed
*ssf
;
457 /* Pull off any padding. */
458 int len
= ntohs(chunk
->chunk_hdr
->length
);
460 /* Make skb with more room so we can prepend notification. */
461 skb
= skb_copy_expand(chunk
->skb
,
462 sizeof(struct sctp_send_failed
), /* headroom */
468 /* Pull off the common chunk header and DATA header. */
469 skb_pull(skb
, sizeof(struct sctp_data_chunk
));
470 len
-= sizeof(struct sctp_data_chunk
);
472 /* Embed the event fields inside the cloned skb. */
473 event
= sctp_skb2event(skb
);
474 sctp_ulpevent_init(event
, MSG_NOTIFICATION
);
476 ssf
= (struct sctp_send_failed
*)
477 skb_push(skb
, sizeof(struct sctp_send_failed
));
479 /* Socket Extensions for SCTP
480 * 5.3.1.4 SCTP_SEND_FAILED
483 * It should be SCTP_SEND_FAILED.
485 ssf
->ssf_type
= SCTP_SEND_FAILED
;
487 /* Socket Extensions for SCTP
488 * 5.3.1.4 SCTP_SEND_FAILED
490 * ssf_flags: 16 bits (unsigned integer)
491 * The flag value will take one of the following values
493 * SCTP_DATA_UNSENT - Indicates that the data was never put on
496 * SCTP_DATA_SENT - Indicates that the data was put on the wire.
497 * Note that this does not necessarily mean that the
498 * data was (or was not) successfully delivered.
500 ssf
->ssf_flags
= flags
;
502 /* Socket Extensions for SCTP
503 * 5.3.1.4 SCTP_SEND_FAILED
505 * ssf_length: sizeof (__u32)
506 * This field is the total length of the notification data, including
507 * the notification header.
509 ssf
->ssf_length
= sizeof(struct sctp_send_failed
) + len
;
510 skb_trim(skb
, ssf
->ssf_length
);
512 /* Socket Extensions for SCTP
513 * 5.3.1.4 SCTP_SEND_FAILED
515 * ssf_error: 16 bits (unsigned integer)
516 * This value represents the reason why the send failed, and if set,
517 * will be a SCTP protocol error code as defined in [SCTP] section
520 ssf
->ssf_error
= error
;
522 /* Socket Extensions for SCTP
523 * 5.3.1.4 SCTP_SEND_FAILED
525 * ssf_info: sizeof (struct sctp_sndrcvinfo)
526 * The original send information associated with the undelivered
529 memcpy(&ssf
->ssf_info
, &chunk
->sinfo
, sizeof(struct sctp_sndrcvinfo
));
531 /* Per TSVWG discussion with Randy. Allow the application to
532 * ressemble a fragmented message.
534 ssf
->ssf_info
.sinfo_flags
= chunk
->chunk_hdr
->flags
;
536 /* Socket Extensions for SCTP
537 * 5.3.1.4 SCTP_SEND_FAILED
539 * ssf_assoc_id: sizeof (sctp_assoc_t)
540 * The association id field, sf_assoc_id, holds the identifier for the
541 * association. All notifications for a given association have the
542 * same association identifier. For TCP style socket, this field is
545 sctp_ulpevent_set_owner(event
, asoc
);
546 ssf
->ssf_assoc_id
= sctp_assoc2id(asoc
);
553 /* Create and initialize a SCTP_SHUTDOWN_EVENT notification.
555 * Socket Extensions for SCTP - draft-01
556 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
558 struct sctp_ulpevent
*sctp_ulpevent_make_shutdown_event(
559 const struct sctp_association
*asoc
,
560 __u16 flags
, int gfp
)
562 struct sctp_ulpevent
*event
;
563 struct sctp_shutdown_event
*sse
;
566 event
= sctp_ulpevent_new(sizeof(struct sctp_shutdown_event
),
567 MSG_NOTIFICATION
, gfp
);
571 skb
= sctp_event2skb(event
);
572 sse
= (struct sctp_shutdown_event
*)
573 skb_put(skb
, sizeof(struct sctp_shutdown_event
));
575 /* Socket Extensions for SCTP
576 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
579 * It should be SCTP_SHUTDOWN_EVENT
581 sse
->sse_type
= SCTP_SHUTDOWN_EVENT
;
583 /* Socket Extensions for SCTP
584 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
586 * sse_flags: 16 bits (unsigned integer)
591 /* Socket Extensions for SCTP
592 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
594 * sse_length: sizeof (__u32)
595 * This field is the total length of the notification data, including
596 * the notification header.
598 sse
->sse_length
= sizeof(struct sctp_shutdown_event
);
600 /* Socket Extensions for SCTP
601 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
603 * sse_assoc_id: sizeof (sctp_assoc_t)
604 * The association id field, holds the identifier for the association.
605 * All notifications for a given association have the same association
606 * identifier. For TCP style socket, this field is ignored.
608 sctp_ulpevent_set_owner(event
, asoc
);
609 sse
->sse_assoc_id
= sctp_assoc2id(asoc
);
617 /* Create and initialize a SCTP_ADAPTION_INDICATION notification.
619 * Socket Extensions for SCTP
620 * 5.3.1.6 SCTP_ADAPTION_INDICATION
622 struct sctp_ulpevent
*sctp_ulpevent_make_adaption_indication(
623 const struct sctp_association
*asoc
, int gfp
)
625 struct sctp_ulpevent
*event
;
626 struct sctp_adaption_event
*sai
;
629 event
= sctp_ulpevent_new(sizeof(struct sctp_adaption_event
),
630 MSG_NOTIFICATION
, gfp
);
634 skb
= sctp_event2skb(event
);
635 sai
= (struct sctp_adaption_event
*)
636 skb_put(skb
, sizeof(struct sctp_adaption_event
));
638 sai
->sai_type
= SCTP_ADAPTION_INDICATION
;
640 sai
->sai_length
= sizeof(struct sctp_adaption_event
);
641 sai
->sai_adaption_ind
= asoc
->peer
.adaption_ind
;
642 sctp_ulpevent_set_owner(event
, asoc
);
643 sai
->sai_assoc_id
= sctp_assoc2id(asoc
);
651 /* A message has been received. Package this message as a notification
652 * to pass it to the upper layers. Go ahead and calculate the sndrcvinfo
653 * even if filtered out later.
655 * Socket Extensions for SCTP
656 * 5.2.2 SCTP Header Information Structure (SCTP_SNDRCV)
658 struct sctp_ulpevent
*sctp_ulpevent_make_rcvmsg(struct sctp_association
*asoc
,
659 struct sctp_chunk
*chunk
,
662 struct sctp_ulpevent
*event
= NULL
;
666 /* Clone the original skb, sharing the data. */
667 skb
= skb_clone(chunk
->skb
, gfp
);
671 /* First calculate the padding, so we don't inadvertently
672 * pass up the wrong length to the user.
674 * RFC 2960 - Section 3.2 Chunk Field Descriptions
676 * The total length of a chunk(including Type, Length and Value fields)
677 * MUST be a multiple of 4 bytes. If the length of the chunk is not a
678 * multiple of 4 bytes, the sender MUST pad the chunk with all zero
679 * bytes and this padding is not included in the chunk length field.
680 * The sender should never pad with more than 3 bytes. The receiver
681 * MUST ignore the padding bytes.
683 len
= ntohs(chunk
->chunk_hdr
->length
);
684 padding
= WORD_ROUND(len
) - len
;
686 /* Fixup cloned skb with just this chunks data. */
687 skb_trim(skb
, chunk
->chunk_end
- padding
- skb
->data
);
689 /* Embed the event fields inside the cloned skb. */
690 event
= sctp_skb2event(skb
);
692 /* Initialize event with flags 0. */
693 sctp_ulpevent_init(event
, 0);
695 sctp_ulpevent_receive_data(event
, asoc
);
697 event
->stream
= ntohs(chunk
->subh
.data_hdr
->stream
);
698 event
->ssn
= ntohs(chunk
->subh
.data_hdr
->ssn
);
699 event
->ppid
= chunk
->subh
.data_hdr
->ppid
;
700 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_UNORDERED
) {
701 event
->flags
|= MSG_UNORDERED
;
702 event
->cumtsn
= sctp_tsnmap_get_ctsn(&asoc
->peer
.tsn_map
);
704 event
->tsn
= ntohl(chunk
->subh
.data_hdr
->tsn
);
705 event
->msg_flags
|= chunk
->chunk_hdr
->flags
;
706 event
->iif
= sctp_chunk_iif(chunk
);
712 /* Create a partial delivery related event.
714 * 5.3.1.7 SCTP_PARTIAL_DELIVERY_EVENT
716 * When a receiver is engaged in a partial delivery of a
717 * message this notification will be used to indicate
720 struct sctp_ulpevent
*sctp_ulpevent_make_pdapi(
721 const struct sctp_association
*asoc
, __u32 indication
, int gfp
)
723 struct sctp_ulpevent
*event
;
724 struct sctp_pdapi_event
*pd
;
727 event
= sctp_ulpevent_new(sizeof(struct sctp_pdapi_event
),
728 MSG_NOTIFICATION
, gfp
);
732 skb
= sctp_event2skb(event
);
733 pd
= (struct sctp_pdapi_event
*)
734 skb_put(skb
, sizeof(struct sctp_pdapi_event
));
737 * It should be SCTP_PARTIAL_DELIVERY_EVENT
739 * pdapi_flags: 16 bits (unsigned integer)
742 pd
->pdapi_type
= SCTP_PARTIAL_DELIVERY_EVENT
;
745 /* pdapi_length: 32 bits (unsigned integer)
747 * This field is the total length of the notification data, including
748 * the notification header. It will generally be sizeof (struct
751 pd
->pdapi_length
= sizeof(struct sctp_pdapi_event
);
753 /* pdapi_indication: 32 bits (unsigned integer)
755 * This field holds the indication being sent to the application.
757 pd
->pdapi_indication
= indication
;
759 /* pdapi_assoc_id: sizeof (sctp_assoc_t)
761 * The association id field, holds the identifier for the association.
763 sctp_ulpevent_set_owner(event
, asoc
);
764 pd
->pdapi_assoc_id
= sctp_assoc2id(asoc
);
771 /* Return the notification type, assuming this is a notification
774 __u16
sctp_ulpevent_get_notification_type(const struct sctp_ulpevent
*event
)
776 union sctp_notification
*notification
;
779 skb
= sctp_event2skb((struct sctp_ulpevent
*)event
);
780 notification
= (union sctp_notification
*) skb
->data
;
781 return notification
->sn_header
.sn_type
;
784 /* Copy out the sndrcvinfo into a msghdr. */
785 void sctp_ulpevent_read_sndrcvinfo(const struct sctp_ulpevent
*event
,
786 struct msghdr
*msghdr
)
788 struct sctp_sndrcvinfo sinfo
;
790 if (sctp_ulpevent_is_notification(event
))
793 /* Sockets API Extensions for SCTP
794 * Section 5.2.2 SCTP Header Information Structure (SCTP_SNDRCV)
796 * sinfo_stream: 16 bits (unsigned integer)
798 * For recvmsg() the SCTP stack places the message's stream number in
801 sinfo
.sinfo_stream
= event
->stream
;
802 /* sinfo_ssn: 16 bits (unsigned integer)
804 * For recvmsg() this value contains the stream sequence number that
805 * the remote endpoint placed in the DATA chunk. For fragmented
806 * messages this is the same number for all deliveries of the message
807 * (if more than one recvmsg() is needed to read the message).
809 sinfo
.sinfo_ssn
= event
->ssn
;
810 /* sinfo_ppid: 32 bits (unsigned integer)
812 * In recvmsg() this value is
813 * the same information that was passed by the upper layer in the peer
814 * application. Please note that byte order issues are NOT accounted
815 * for and this information is passed opaquely by the SCTP stack from
816 * one end to the other.
818 sinfo
.sinfo_ppid
= event
->ppid
;
819 /* sinfo_flags: 16 bits (unsigned integer)
821 * This field may contain any of the following flags and is composed of
822 * a bitwise OR of these values.
826 * MSG_UNORDERED - This flag is present when the message was sent
829 sinfo
.sinfo_flags
= event
->flags
;
830 /* sinfo_tsn: 32 bit (unsigned integer)
832 * For the receiving side, this field holds a TSN that was
833 * assigned to one of the SCTP Data Chunks.
835 sinfo
.sinfo_tsn
= event
->tsn
;
836 /* sinfo_cumtsn: 32 bit (unsigned integer)
838 * This field will hold the current cumulative TSN as
839 * known by the underlying SCTP layer. Note this field is
840 * ignored when sending and only valid for a receive
841 * operation when sinfo_flags are set to MSG_UNORDERED.
843 sinfo
.sinfo_cumtsn
= event
->cumtsn
;
844 /* sinfo_assoc_id: sizeof (sctp_assoc_t)
846 * The association handle field, sinfo_assoc_id, holds the identifier
847 * for the association announced in the COMMUNICATION_UP notification.
848 * All notifications for a given association have the same identifier.
849 * Ignored for one-to-one style sockets.
851 sinfo
.sinfo_assoc_id
= sctp_assoc2id(event
->asoc
);
853 /* These fields are not used while receiving. */
854 sinfo
.sinfo_context
= 0;
855 sinfo
.sinfo_timetolive
= 0;
857 put_cmsg(msghdr
, IPPROTO_SCTP
, SCTP_SNDRCV
,
858 sizeof(struct sctp_sndrcvinfo
), (void *)&sinfo
);
861 /* Do accounting for bytes received and hold a reference to the association
864 static void sctp_ulpevent_receive_data(struct sctp_ulpevent
*event
,
865 struct sctp_association
*asoc
)
867 struct sk_buff
*skb
, *frag
;
869 skb
= sctp_event2skb(event
);
870 /* Set the owner and charge rwnd for bytes received. */
871 sctp_ulpevent_set_owner(event
, asoc
);
872 sctp_assoc_rwnd_decrease(asoc
, skb_headlen(skb
));
877 /* Note: Not clearing the entire event struct as this is just a
878 * fragment of the real event. However, we still need to do rwnd
880 * In general, the skb passed from IP can have only 1 level of
881 * fragments. But we allow multiple levels of fragments.
883 for (frag
= skb_shinfo(skb
)->frag_list
; frag
; frag
= frag
->next
) {
884 sctp_ulpevent_receive_data(sctp_skb2event(frag
), asoc
);
888 /* Do accounting for bytes just read by user and release the references to
891 static void sctp_ulpevent_release_data(struct sctp_ulpevent
*event
)
893 struct sk_buff
*skb
, *frag
;
895 /* Current stack structures assume that the rcv buffer is
896 * per socket. For UDP style sockets this is not true as
897 * multiple associations may be on a single UDP-style socket.
898 * Use the local private area of the skb to track the owning
902 skb
= sctp_event2skb(event
);
903 sctp_assoc_rwnd_increase(event
->asoc
, skb_headlen(skb
));
908 /* Don't forget the fragments. */
909 for (frag
= skb_shinfo(skb
)->frag_list
; frag
; frag
= frag
->next
) {
910 /* NOTE: skb_shinfos are recursive. Although IP returns
911 * skb's with only 1 level of fragments, SCTP reassembly can
912 * increase the levels.
914 sctp_ulpevent_release_data(sctp_skb2event(frag
));
918 sctp_ulpevent_release_owner(event
);
921 /* Free a ulpevent that has an owner. It includes releasing the reference
922 * to the owner, updating the rwnd in case of a DATA event and freeing the
924 * See comments in sctp_stub_rfree().
926 void sctp_ulpevent_free(struct sctp_ulpevent
*event
)
928 if (sctp_ulpevent_is_notification(event
))
929 sctp_ulpevent_release_owner(event
);
931 sctp_ulpevent_release_data(event
);
933 kfree_skb(sctp_event2skb(event
));
936 /* Purge the skb lists holding ulpevents. */
937 void sctp_queue_purge_ulpevents(struct sk_buff_head
*list
)
940 while ((skb
= skb_dequeue(list
)) != NULL
)
941 sctp_ulpevent_free(sctp_skb2event(skb
));