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
);
54 static void sctp_ulpevent_release_frag_data(struct sctp_ulpevent
*event
);
57 /* Initialize an ULP event from an given skb. */
58 SCTP_STATIC
void sctp_ulpevent_init(struct sctp_ulpevent
*event
, int msg_flags
)
60 memset(event
, 0, sizeof(struct sctp_ulpevent
));
61 event
->msg_flags
= msg_flags
;
64 /* Create a new sctp_ulpevent. */
65 SCTP_STATIC
struct sctp_ulpevent
*sctp_ulpevent_new(int size
, int msg_flags
,
68 struct sctp_ulpevent
*event
;
71 skb
= alloc_skb(size
, gfp
);
75 event
= sctp_skb2event(skb
);
76 sctp_ulpevent_init(event
, msg_flags
);
84 /* Is this a MSG_NOTIFICATION? */
85 int sctp_ulpevent_is_notification(const struct sctp_ulpevent
*event
)
87 return MSG_NOTIFICATION
== (event
->msg_flags
& MSG_NOTIFICATION
);
90 /* Hold the association in case the msg_name needs read out of
93 static inline void sctp_ulpevent_set_owner(struct sctp_ulpevent
*event
,
94 const struct sctp_association
*asoc
)
98 /* Cast away the const, as we are just wanting to
99 * bump the reference count.
101 sctp_association_hold((struct sctp_association
*)asoc
);
102 skb
= sctp_event2skb(event
);
103 event
->asoc
= (struct sctp_association
*)asoc
;
104 atomic_add(skb
->truesize
, &event
->asoc
->rmem_alloc
);
105 skb_set_owner_r(skb
, asoc
->base
.sk
);
108 /* A simple destructor to give up the reference to the association. */
109 static inline void sctp_ulpevent_release_owner(struct sctp_ulpevent
*event
)
111 struct sctp_association
*asoc
= event
->asoc
;
112 struct sk_buff
*skb
= sctp_event2skb(event
);
114 atomic_sub(skb
->truesize
, &asoc
->rmem_alloc
);
115 sctp_association_put(asoc
);
118 /* Create and initialize an SCTP_ASSOC_CHANGE event.
120 * 5.3.1.1 SCTP_ASSOC_CHANGE
122 * Communication notifications inform the ULP that an SCTP association
123 * has either begun or ended. The identifier for a new association is
124 * provided by this notification.
126 * Note: There is no field checking here. If a field is unused it will be
129 struct sctp_ulpevent
*sctp_ulpevent_make_assoc_change(
130 const struct sctp_association
*asoc
,
131 __u16 flags
, __u16 state
, __u16 error
, __u16 outbound
,
132 __u16 inbound
, gfp_t gfp
)
134 struct sctp_ulpevent
*event
;
135 struct sctp_assoc_change
*sac
;
138 event
= sctp_ulpevent_new(sizeof(struct sctp_assoc_change
),
139 MSG_NOTIFICATION
, gfp
);
142 skb
= sctp_event2skb(event
);
143 sac
= (struct sctp_assoc_change
*)
144 skb_put(skb
, sizeof(struct sctp_assoc_change
));
146 /* Socket Extensions for SCTP
147 * 5.3.1.1 SCTP_ASSOC_CHANGE
150 * It should be SCTP_ASSOC_CHANGE.
152 sac
->sac_type
= SCTP_ASSOC_CHANGE
;
154 /* Socket Extensions for SCTP
155 * 5.3.1.1 SCTP_ASSOC_CHANGE
157 * sac_state: 32 bits (signed integer)
158 * This field holds one of a number of values that communicate the
159 * event that happened to the association.
161 sac
->sac_state
= state
;
163 /* Socket Extensions for SCTP
164 * 5.3.1.1 SCTP_ASSOC_CHANGE
166 * sac_flags: 16 bits (unsigned integer)
171 /* Socket Extensions for SCTP
172 * 5.3.1.1 SCTP_ASSOC_CHANGE
174 * sac_length: sizeof (__u32)
175 * This field is the total length of the notification data, including
176 * the notification header.
178 sac
->sac_length
= sizeof(struct sctp_assoc_change
);
180 /* Socket Extensions for SCTP
181 * 5.3.1.1 SCTP_ASSOC_CHANGE
183 * sac_error: 32 bits (signed integer)
185 * If the state was reached due to a error condition (e.g.
186 * COMMUNICATION_LOST) any relevant error information is available in
187 * this field. This corresponds to the protocol error codes defined in
190 sac
->sac_error
= error
;
192 /* Socket Extensions for SCTP
193 * 5.3.1.1 SCTP_ASSOC_CHANGE
195 * sac_outbound_streams: 16 bits (unsigned integer)
196 * sac_inbound_streams: 16 bits (unsigned integer)
198 * The maximum number of streams allowed in each direction are
199 * available in sac_outbound_streams and sac_inbound streams.
201 sac
->sac_outbound_streams
= outbound
;
202 sac
->sac_inbound_streams
= inbound
;
204 /* Socket Extensions for SCTP
205 * 5.3.1.1 SCTP_ASSOC_CHANGE
207 * sac_assoc_id: sizeof (sctp_assoc_t)
209 * The association id field, holds the identifier for the association.
210 * All notifications for a given association have the same association
211 * identifier. For TCP style socket, this field is ignored.
213 sctp_ulpevent_set_owner(event
, asoc
);
214 sac
->sac_assoc_id
= sctp_assoc2id(asoc
);
222 /* Create and initialize an SCTP_PEER_ADDR_CHANGE event.
224 * Socket Extensions for SCTP - draft-01
225 * 5.3.1.2 SCTP_PEER_ADDR_CHANGE
227 * When a destination address on a multi-homed peer encounters a change
228 * an interface details event is sent.
230 struct sctp_ulpevent
*sctp_ulpevent_make_peer_addr_change(
231 const struct sctp_association
*asoc
,
232 const struct sockaddr_storage
*aaddr
,
233 int flags
, int state
, int error
, gfp_t gfp
)
235 struct sctp_ulpevent
*event
;
236 struct sctp_paddr_change
*spc
;
239 event
= sctp_ulpevent_new(sizeof(struct sctp_paddr_change
),
240 MSG_NOTIFICATION
, gfp
);
244 skb
= sctp_event2skb(event
);
245 spc
= (struct sctp_paddr_change
*)
246 skb_put(skb
, sizeof(struct sctp_paddr_change
));
248 /* Sockets API Extensions for SCTP
249 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
253 * It should be SCTP_PEER_ADDR_CHANGE.
255 spc
->spc_type
= SCTP_PEER_ADDR_CHANGE
;
257 /* Sockets API Extensions for SCTP
258 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
260 * spc_length: sizeof (__u32)
262 * This field is the total length of the notification data, including
263 * the notification header.
265 spc
->spc_length
= sizeof(struct sctp_paddr_change
);
267 /* Sockets API Extensions for SCTP
268 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
270 * spc_flags: 16 bits (unsigned integer)
275 /* Sockets API Extensions for SCTP
276 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
278 * spc_state: 32 bits (signed integer)
280 * This field holds one of a number of values that communicate the
281 * event that happened to the address.
283 spc
->spc_state
= state
;
285 /* Sockets API Extensions for SCTP
286 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
288 * spc_error: 32 bits (signed integer)
290 * If the state was reached due to any error condition (e.g.
291 * ADDRESS_UNREACHABLE) any relevant error information is available in
294 spc
->spc_error
= error
;
296 /* Socket Extensions for SCTP
297 * 5.3.1.1 SCTP_ASSOC_CHANGE
299 * spc_assoc_id: sizeof (sctp_assoc_t)
301 * The association id field, holds the identifier for the association.
302 * All notifications for a given association have the same association
303 * identifier. For TCP style socket, this field is ignored.
305 sctp_ulpevent_set_owner(event
, asoc
);
306 spc
->spc_assoc_id
= sctp_assoc2id(asoc
);
308 /* Sockets API Extensions for SCTP
309 * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
311 * spc_aaddr: sizeof (struct sockaddr_storage)
313 * The affected address field, holds the remote peer's address that is
314 * encountering the change of state.
316 memcpy(&spc
->spc_aaddr
, aaddr
, sizeof(struct sockaddr_storage
));
318 /* Map ipv4 address into v4-mapped-on-v6 address. */
319 sctp_get_pf_specific(asoc
->base
.sk
->sk_family
)->addr_v4map(
320 sctp_sk(asoc
->base
.sk
),
321 (union sctp_addr
*)&spc
->spc_aaddr
);
329 /* Create and initialize an SCTP_REMOTE_ERROR notification.
331 * Note: This assumes that the chunk->skb->data already points to the
332 * operation error payload.
334 * Socket Extensions for SCTP - draft-01
335 * 5.3.1.3 SCTP_REMOTE_ERROR
337 * A remote peer may send an Operational Error message to its peer.
338 * This message indicates a variety of error conditions on an
339 * association. The entire error TLV as it appears on the wire is
340 * included in a SCTP_REMOTE_ERROR event. Please refer to the SCTP
341 * specification [SCTP] and any extensions for a list of possible
344 struct sctp_ulpevent
*sctp_ulpevent_make_remote_error(
345 const struct sctp_association
*asoc
, struct sctp_chunk
*chunk
,
346 __u16 flags
, gfp_t gfp
)
348 struct sctp_ulpevent
*event
;
349 struct sctp_remote_error
*sre
;
355 ch
= (sctp_errhdr_t
*)(chunk
->skb
->data
);
357 elen
= WORD_ROUND(ntohs(ch
->length
)) - sizeof(sctp_errhdr_t
);
359 /* Pull off the ERROR header. */
360 skb_pull(chunk
->skb
, sizeof(sctp_errhdr_t
));
362 /* Copy the skb to a new skb with room for us to prepend
365 skb
= skb_copy_expand(chunk
->skb
, sizeof(struct sctp_remote_error
),
368 /* Pull off the rest of the cause TLV from the chunk. */
369 skb_pull(chunk
->skb
, elen
);
373 /* Embed the event fields inside the cloned skb. */
374 event
= sctp_skb2event(skb
);
375 sctp_ulpevent_init(event
, MSG_NOTIFICATION
);
377 sre
= (struct sctp_remote_error
*)
378 skb_push(skb
, sizeof(struct sctp_remote_error
));
380 /* Trim the buffer to the right length. */
381 skb_trim(skb
, sizeof(struct sctp_remote_error
) + elen
);
383 /* Socket Extensions for SCTP
384 * 5.3.1.3 SCTP_REMOTE_ERROR
387 * It should be SCTP_REMOTE_ERROR.
389 sre
->sre_type
= SCTP_REMOTE_ERROR
;
392 * Socket Extensions for SCTP
393 * 5.3.1.3 SCTP_REMOTE_ERROR
395 * sre_flags: 16 bits (unsigned integer)
400 /* Socket Extensions for SCTP
401 * 5.3.1.3 SCTP_REMOTE_ERROR
403 * sre_length: sizeof (__u32)
405 * This field is the total length of the notification data,
406 * including the notification header.
408 sre
->sre_length
= skb
->len
;
410 /* Socket Extensions for SCTP
411 * 5.3.1.3 SCTP_REMOTE_ERROR
413 * sre_error: 16 bits (unsigned integer)
414 * This value represents one of the Operational Error causes defined in
415 * the SCTP specification, in network byte order.
417 sre
->sre_error
= cause
;
419 /* Socket Extensions for SCTP
420 * 5.3.1.3 SCTP_REMOTE_ERROR
422 * sre_assoc_id: sizeof (sctp_assoc_t)
424 * The association id field, holds the identifier for the association.
425 * All notifications for a given association have the same association
426 * identifier. For TCP style socket, this field is ignored.
428 sctp_ulpevent_set_owner(event
, asoc
);
429 sre
->sre_assoc_id
= sctp_assoc2id(asoc
);
437 /* Create and initialize a SCTP_SEND_FAILED notification.
439 * Socket Extensions for SCTP - draft-01
440 * 5.3.1.4 SCTP_SEND_FAILED
442 struct sctp_ulpevent
*sctp_ulpevent_make_send_failed(
443 const struct sctp_association
*asoc
, struct sctp_chunk
*chunk
,
444 __u16 flags
, __u32 error
, gfp_t gfp
)
446 struct sctp_ulpevent
*event
;
447 struct sctp_send_failed
*ssf
;
450 /* Pull off any padding. */
451 int len
= ntohs(chunk
->chunk_hdr
->length
);
453 /* Make skb with more room so we can prepend notification. */
454 skb
= skb_copy_expand(chunk
->skb
,
455 sizeof(struct sctp_send_failed
), /* headroom */
461 /* Pull off the common chunk header and DATA header. */
462 skb_pull(skb
, sizeof(struct sctp_data_chunk
));
463 len
-= sizeof(struct sctp_data_chunk
);
465 /* Embed the event fields inside the cloned skb. */
466 event
= sctp_skb2event(skb
);
467 sctp_ulpevent_init(event
, MSG_NOTIFICATION
);
469 ssf
= (struct sctp_send_failed
*)
470 skb_push(skb
, sizeof(struct sctp_send_failed
));
472 /* Socket Extensions for SCTP
473 * 5.3.1.4 SCTP_SEND_FAILED
476 * It should be SCTP_SEND_FAILED.
478 ssf
->ssf_type
= SCTP_SEND_FAILED
;
480 /* Socket Extensions for SCTP
481 * 5.3.1.4 SCTP_SEND_FAILED
483 * ssf_flags: 16 bits (unsigned integer)
484 * The flag value will take one of the following values
486 * SCTP_DATA_UNSENT - Indicates that the data was never put on
489 * SCTP_DATA_SENT - Indicates that the data was put on the wire.
490 * Note that this does not necessarily mean that the
491 * data was (or was not) successfully delivered.
493 ssf
->ssf_flags
= flags
;
495 /* Socket Extensions for SCTP
496 * 5.3.1.4 SCTP_SEND_FAILED
498 * ssf_length: sizeof (__u32)
499 * This field is the total length of the notification data, including
500 * the notification header.
502 ssf
->ssf_length
= sizeof(struct sctp_send_failed
) + len
;
503 skb_trim(skb
, ssf
->ssf_length
);
505 /* Socket Extensions for SCTP
506 * 5.3.1.4 SCTP_SEND_FAILED
508 * ssf_error: 16 bits (unsigned integer)
509 * This value represents the reason why the send failed, and if set,
510 * will be a SCTP protocol error code as defined in [SCTP] section
513 ssf
->ssf_error
= error
;
515 /* Socket Extensions for SCTP
516 * 5.3.1.4 SCTP_SEND_FAILED
518 * ssf_info: sizeof (struct sctp_sndrcvinfo)
519 * The original send information associated with the undelivered
522 memcpy(&ssf
->ssf_info
, &chunk
->sinfo
, sizeof(struct sctp_sndrcvinfo
));
524 /* Per TSVWG discussion with Randy. Allow the application to
525 * ressemble a fragmented message.
527 ssf
->ssf_info
.sinfo_flags
= chunk
->chunk_hdr
->flags
;
529 /* Socket Extensions for SCTP
530 * 5.3.1.4 SCTP_SEND_FAILED
532 * ssf_assoc_id: sizeof (sctp_assoc_t)
533 * The association id field, sf_assoc_id, holds the identifier for the
534 * association. All notifications for a given association have the
535 * same association identifier. For TCP style socket, this field is
538 sctp_ulpevent_set_owner(event
, asoc
);
539 ssf
->ssf_assoc_id
= sctp_assoc2id(asoc
);
546 /* Create and initialize a SCTP_SHUTDOWN_EVENT notification.
548 * Socket Extensions for SCTP - draft-01
549 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
551 struct sctp_ulpevent
*sctp_ulpevent_make_shutdown_event(
552 const struct sctp_association
*asoc
,
553 __u16 flags
, gfp_t gfp
)
555 struct sctp_ulpevent
*event
;
556 struct sctp_shutdown_event
*sse
;
559 event
= sctp_ulpevent_new(sizeof(struct sctp_shutdown_event
),
560 MSG_NOTIFICATION
, gfp
);
564 skb
= sctp_event2skb(event
);
565 sse
= (struct sctp_shutdown_event
*)
566 skb_put(skb
, sizeof(struct sctp_shutdown_event
));
568 /* Socket Extensions for SCTP
569 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
572 * It should be SCTP_SHUTDOWN_EVENT
574 sse
->sse_type
= SCTP_SHUTDOWN_EVENT
;
576 /* Socket Extensions for SCTP
577 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
579 * sse_flags: 16 bits (unsigned integer)
584 /* Socket Extensions for SCTP
585 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
587 * sse_length: sizeof (__u32)
588 * This field is the total length of the notification data, including
589 * the notification header.
591 sse
->sse_length
= sizeof(struct sctp_shutdown_event
);
593 /* Socket Extensions for SCTP
594 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
596 * sse_assoc_id: sizeof (sctp_assoc_t)
597 * The association id field, holds the identifier for the association.
598 * All notifications for a given association have the same association
599 * identifier. For TCP style socket, this field is ignored.
601 sctp_ulpevent_set_owner(event
, asoc
);
602 sse
->sse_assoc_id
= sctp_assoc2id(asoc
);
610 /* Create and initialize a SCTP_ADAPTION_INDICATION notification.
612 * Socket Extensions for SCTP
613 * 5.3.1.6 SCTP_ADAPTION_INDICATION
615 struct sctp_ulpevent
*sctp_ulpevent_make_adaption_indication(
616 const struct sctp_association
*asoc
, gfp_t gfp
)
618 struct sctp_ulpevent
*event
;
619 struct sctp_adaption_event
*sai
;
622 event
= sctp_ulpevent_new(sizeof(struct sctp_adaption_event
),
623 MSG_NOTIFICATION
, gfp
);
627 skb
= sctp_event2skb(event
);
628 sai
= (struct sctp_adaption_event
*)
629 skb_put(skb
, sizeof(struct sctp_adaption_event
));
631 sai
->sai_type
= SCTP_ADAPTION_INDICATION
;
633 sai
->sai_length
= sizeof(struct sctp_adaption_event
);
634 sai
->sai_adaption_ind
= asoc
->peer
.adaption_ind
;
635 sctp_ulpevent_set_owner(event
, asoc
);
636 sai
->sai_assoc_id
= sctp_assoc2id(asoc
);
644 /* A message has been received. Package this message as a notification
645 * to pass it to the upper layers. Go ahead and calculate the sndrcvinfo
646 * even if filtered out later.
648 * Socket Extensions for SCTP
649 * 5.2.2 SCTP Header Information Structure (SCTP_SNDRCV)
651 struct sctp_ulpevent
*sctp_ulpevent_make_rcvmsg(struct sctp_association
*asoc
,
652 struct sctp_chunk
*chunk
,
655 struct sctp_ulpevent
*event
= NULL
;
659 /* Clone the original skb, sharing the data. */
660 skb
= skb_clone(chunk
->skb
, gfp
);
664 /* First calculate the padding, so we don't inadvertently
665 * pass up the wrong length to the user.
667 * RFC 2960 - Section 3.2 Chunk Field Descriptions
669 * The total length of a chunk(including Type, Length and Value fields)
670 * MUST be a multiple of 4 bytes. If the length of the chunk is not a
671 * multiple of 4 bytes, the sender MUST pad the chunk with all zero
672 * bytes and this padding is not included in the chunk length field.
673 * The sender should never pad with more than 3 bytes. The receiver
674 * MUST ignore the padding bytes.
676 len
= ntohs(chunk
->chunk_hdr
->length
);
677 padding
= WORD_ROUND(len
) - len
;
679 /* Fixup cloned skb with just this chunks data. */
680 skb_trim(skb
, chunk
->chunk_end
- padding
- skb
->data
);
682 /* Embed the event fields inside the cloned skb. */
683 event
= sctp_skb2event(skb
);
685 /* Initialize event with flags 0. */
686 sctp_ulpevent_init(event
, 0);
688 sctp_ulpevent_receive_data(event
, asoc
);
690 event
->stream
= ntohs(chunk
->subh
.data_hdr
->stream
);
691 event
->ssn
= ntohs(chunk
->subh
.data_hdr
->ssn
);
692 event
->ppid
= chunk
->subh
.data_hdr
->ppid
;
693 if (chunk
->chunk_hdr
->flags
& SCTP_DATA_UNORDERED
) {
694 event
->flags
|= SCTP_UNORDERED
;
695 event
->cumtsn
= sctp_tsnmap_get_ctsn(&asoc
->peer
.tsn_map
);
697 event
->tsn
= ntohl(chunk
->subh
.data_hdr
->tsn
);
698 event
->msg_flags
|= chunk
->chunk_hdr
->flags
;
699 event
->iif
= sctp_chunk_iif(chunk
);
705 /* Create a partial delivery related event.
707 * 5.3.1.7 SCTP_PARTIAL_DELIVERY_EVENT
709 * When a receiver is engaged in a partial delivery of a
710 * message this notification will be used to indicate
713 struct sctp_ulpevent
*sctp_ulpevent_make_pdapi(
714 const struct sctp_association
*asoc
, __u32 indication
,
717 struct sctp_ulpevent
*event
;
718 struct sctp_pdapi_event
*pd
;
721 event
= sctp_ulpevent_new(sizeof(struct sctp_pdapi_event
),
722 MSG_NOTIFICATION
, gfp
);
726 skb
= sctp_event2skb(event
);
727 pd
= (struct sctp_pdapi_event
*)
728 skb_put(skb
, sizeof(struct sctp_pdapi_event
));
731 * It should be SCTP_PARTIAL_DELIVERY_EVENT
733 * pdapi_flags: 16 bits (unsigned integer)
736 pd
->pdapi_type
= SCTP_PARTIAL_DELIVERY_EVENT
;
739 /* pdapi_length: 32 bits (unsigned integer)
741 * This field is the total length of the notification data, including
742 * the notification header. It will generally be sizeof (struct
745 pd
->pdapi_length
= sizeof(struct sctp_pdapi_event
);
747 /* pdapi_indication: 32 bits (unsigned integer)
749 * This field holds the indication being sent to the application.
751 pd
->pdapi_indication
= indication
;
753 /* pdapi_assoc_id: sizeof (sctp_assoc_t)
755 * The association id field, holds the identifier for the association.
757 sctp_ulpevent_set_owner(event
, asoc
);
758 pd
->pdapi_assoc_id
= sctp_assoc2id(asoc
);
765 /* Return the notification type, assuming this is a notification
768 __u16
sctp_ulpevent_get_notification_type(const struct sctp_ulpevent
*event
)
770 union sctp_notification
*notification
;
773 skb
= sctp_event2skb((struct sctp_ulpevent
*)event
);
774 notification
= (union sctp_notification
*) skb
->data
;
775 return notification
->sn_header
.sn_type
;
778 /* Copy out the sndrcvinfo into a msghdr. */
779 void sctp_ulpevent_read_sndrcvinfo(const struct sctp_ulpevent
*event
,
780 struct msghdr
*msghdr
)
782 struct sctp_sndrcvinfo sinfo
;
784 if (sctp_ulpevent_is_notification(event
))
787 /* Sockets API Extensions for SCTP
788 * Section 5.2.2 SCTP Header Information Structure (SCTP_SNDRCV)
790 * sinfo_stream: 16 bits (unsigned integer)
792 * For recvmsg() the SCTP stack places the message's stream number in
795 sinfo
.sinfo_stream
= event
->stream
;
796 /* sinfo_ssn: 16 bits (unsigned integer)
798 * For recvmsg() this value contains the stream sequence number that
799 * the remote endpoint placed in the DATA chunk. For fragmented
800 * messages this is the same number for all deliveries of the message
801 * (if more than one recvmsg() is needed to read the message).
803 sinfo
.sinfo_ssn
= event
->ssn
;
804 /* sinfo_ppid: 32 bits (unsigned integer)
806 * In recvmsg() this value is
807 * the same information that was passed by the upper layer in the peer
808 * application. Please note that byte order issues are NOT accounted
809 * for and this information is passed opaquely by the SCTP stack from
810 * one end to the other.
812 sinfo
.sinfo_ppid
= event
->ppid
;
813 /* sinfo_flags: 16 bits (unsigned integer)
815 * This field may contain any of the following flags and is composed of
816 * a bitwise OR of these values.
820 * SCTP_UNORDERED - This flag is present when the message was sent
823 sinfo
.sinfo_flags
= event
->flags
;
824 /* sinfo_tsn: 32 bit (unsigned integer)
826 * For the receiving side, this field holds a TSN that was
827 * assigned to one of the SCTP Data Chunks.
829 sinfo
.sinfo_tsn
= event
->tsn
;
830 /* sinfo_cumtsn: 32 bit (unsigned integer)
832 * This field will hold the current cumulative TSN as
833 * known by the underlying SCTP layer. Note this field is
834 * ignored when sending and only valid for a receive
835 * operation when sinfo_flags are set to SCTP_UNORDERED.
837 sinfo
.sinfo_cumtsn
= event
->cumtsn
;
838 /* sinfo_assoc_id: sizeof (sctp_assoc_t)
840 * The association handle field, sinfo_assoc_id, holds the identifier
841 * for the association announced in the COMMUNICATION_UP notification.
842 * All notifications for a given association have the same identifier.
843 * Ignored for one-to-one style sockets.
845 sinfo
.sinfo_assoc_id
= sctp_assoc2id(event
->asoc
);
847 /* These fields are not used while receiving. */
848 sinfo
.sinfo_context
= 0;
849 sinfo
.sinfo_timetolive
= 0;
851 put_cmsg(msghdr
, IPPROTO_SCTP
, SCTP_SNDRCV
,
852 sizeof(struct sctp_sndrcvinfo
), (void *)&sinfo
);
855 /* Do accounting for bytes received and hold a reference to the association
858 static void sctp_ulpevent_receive_data(struct sctp_ulpevent
*event
,
859 struct sctp_association
*asoc
)
861 struct sk_buff
*skb
, *frag
;
863 skb
= sctp_event2skb(event
);
864 /* Set the owner and charge rwnd for bytes received. */
865 sctp_ulpevent_set_owner(event
, asoc
);
866 sctp_assoc_rwnd_decrease(asoc
, skb_headlen(skb
));
871 /* Note: Not clearing the entire event struct as this is just a
872 * fragment of the real event. However, we still need to do rwnd
874 * In general, the skb passed from IP can have only 1 level of
875 * fragments. But we allow multiple levels of fragments.
877 for (frag
= skb_shinfo(skb
)->frag_list
; frag
; frag
= frag
->next
) {
878 sctp_ulpevent_receive_data(sctp_skb2event(frag
), asoc
);
882 /* Do accounting for bytes just read by user and release the references to
885 static void sctp_ulpevent_release_data(struct sctp_ulpevent
*event
)
887 struct sk_buff
*skb
, *frag
;
890 /* Current stack structures assume that the rcv buffer is
891 * per socket. For UDP style sockets this is not true as
892 * multiple associations may be on a single UDP-style socket.
893 * Use the local private area of the skb to track the owning
897 skb
= sctp_event2skb(event
);
903 /* Don't forget the fragments. */
904 for (frag
= skb_shinfo(skb
)->frag_list
; frag
; frag
= frag
->next
) {
905 /* NOTE: skb_shinfos are recursive. Although IP returns
906 * skb's with only 1 level of fragments, SCTP reassembly can
907 * increase the levels.
909 sctp_ulpevent_release_frag_data(sctp_skb2event(frag
));
913 sctp_assoc_rwnd_increase(event
->asoc
, len
);
914 sctp_ulpevent_release_owner(event
);
917 static void sctp_ulpevent_release_frag_data(struct sctp_ulpevent
*event
)
919 struct sk_buff
*skb
, *frag
;
921 skb
= sctp_event2skb(event
);
926 /* Don't forget the fragments. */
927 for (frag
= skb_shinfo(skb
)->frag_list
; frag
; frag
= frag
->next
) {
928 /* NOTE: skb_shinfos are recursive. Although IP returns
929 * skb's with only 1 level of fragments, SCTP reassembly can
930 * increase the levels.
932 sctp_ulpevent_release_frag_data(sctp_skb2event(frag
));
936 sctp_ulpevent_release_owner(event
);
939 /* Free a ulpevent that has an owner. It includes releasing the reference
940 * to the owner, updating the rwnd in case of a DATA event and freeing the
943 void sctp_ulpevent_free(struct sctp_ulpevent
*event
)
945 if (sctp_ulpevent_is_notification(event
))
946 sctp_ulpevent_release_owner(event
);
948 sctp_ulpevent_release_data(event
);
950 kfree_skb(sctp_event2skb(event
));
953 /* Purge the skb lists holding ulpevents. */
954 void sctp_queue_purge_ulpevents(struct sk_buff_head
*list
)
957 while ((skb
= skb_dequeue(list
)) != NULL
)
958 sctp_ulpevent_free(sctp_skb2event(skb
));