patch-2.4.26 linux-2.4.26/net/sctp/ulpevent.c
Next file: linux-2.4.26/net/sctp/ulpqueue.c
Previous file: linux-2.4.26/net/sctp/tsnmap.c
Back to the patch index
Back to the overall index
- Lines: 492
- Date:
2004-04-14 06:05:41.000000000 -0700
- Orig file:
linux-2.4.25/net/sctp/ulpevent.c
- Orig date:
2003-11-28 10:26:21.000000000 -0800
diff -urN linux-2.4.25/net/sctp/ulpevent.c linux-2.4.26/net/sctp/ulpevent.c
@@ -35,6 +35,8 @@
* Written or modified by:
* Jon Grimm <jgrimm@us.ibm.com>
* La Monte H.P. Yarroll <piggy@acm.org>
+ * Ardelle Fan <ardelle.fan@intel.com>
+ * Sridhar Samudrala <sri@us.ibm.com>
*
* Any bugs reported given to us we will try to fix... any fixes shared will
* be incorporated into the next SCTP release.
@@ -46,10 +48,12 @@
#include <net/sctp/sctp.h>
#include <net/sctp/sm.h>
-static void sctp_ulpevent_set_owner_r(struct sk_buff *skb,
- struct sctp_association *asoc);
-static void sctp_ulpevent_set_owner(struct sk_buff *skb,
- const struct sctp_association *asoc);
+static inline void sctp_ulpevent_set_owner(struct sctp_ulpevent *event,
+ const struct sctp_association *asoc);
+static inline void sctp_ulpevent_release_owner(struct sctp_ulpevent *event);
+static void sctp_ulpevent_receive_data(struct sctp_ulpevent *event,
+ struct sctp_association *asoc);
+static void sctp_ulpevent_release_data(struct sctp_ulpevent *event);
/* Create a new sctp_ulpevent. */
struct sctp_ulpevent *sctp_ulpevent_new(int size, int msg_flags, int gfp)
@@ -62,30 +66,19 @@
goto fail;
event = sctp_skb2event(skb);
- event = sctp_ulpevent_init(event, msg_flags);
- if (!event)
- goto fail_init;
+ sctp_ulpevent_init(event, msg_flags);
+
return event;
-fail_init:
- kfree_skb(skb);
fail:
return NULL;
}
/* Initialize an ULP event from an given skb. */
-struct sctp_ulpevent *sctp_ulpevent_init(struct sctp_ulpevent *event,
- int msg_flags)
+void sctp_ulpevent_init(struct sctp_ulpevent *event, int msg_flags)
{
memset(event, sizeof(struct sctp_ulpevent), 0x00);
event->msg_flags = msg_flags;
- return event;
-}
-
-/* Dispose of an event. */
-void sctp_ulpevent_free(struct sctp_ulpevent *event)
-{
- kfree_skb(sctp_event2skb(event));
}
/* Is this a MSG_NOTIFICATION? */
@@ -189,7 +182,7 @@
* All notifications for a given association have the same association
* identifier. For TCP style socket, this field is ignored.
*/
- sctp_ulpevent_set_owner(skb, asoc);
+ sctp_ulpevent_set_owner(event, asoc);
sac->sac_assoc_id = sctp_assoc2id(asoc);
return event;
@@ -281,7 +274,7 @@
* All notifications for a given association have the same association
* identifier. For TCP style socket, this field is ignored.
*/
- sctp_ulpevent_set_owner(skb, asoc);
+ sctp_ulpevent_set_owner(event, asoc);
spc->spc_assoc_id = sctp_assoc2id(asoc);
/* Sockets API Extensions for SCTP
@@ -294,6 +287,11 @@
*/
memcpy(&spc->spc_aaddr, aaddr, sizeof(struct sockaddr_storage));
+ /* Map ipv4 address into v4-mapped-on-v6 address. */
+ sctp_get_pf_specific(asoc->base.sk->sk_family)->addr_v4map(
+ sctp_sk(asoc->base.sk),
+ (union sctp_addr *)&spc->spc_aaddr);
+
return event;
fail:
@@ -316,7 +314,7 @@
* error formats.
*/
struct sctp_ulpevent *sctp_ulpevent_make_remote_error(
- const struct sctp_association *asoc, sctp_chunk_t *chunk,
+ const struct sctp_association *asoc, struct sctp_chunk *chunk,
__u16 flags, int gfp)
{
struct sctp_ulpevent *event;
@@ -328,7 +326,7 @@
ch = (sctp_errhdr_t *)(chunk->skb->data);
cause = ch->cause;
- elen = ntohs(ch->length) - sizeof(sctp_errhdr_t);
+ elen = WORD_ROUND(ntohs(ch->length)) - sizeof(sctp_errhdr_t);
/* Pull off the ERROR header. */
skb_pull(chunk->skb, sizeof(sctp_errhdr_t));
@@ -336,10 +334,8 @@
/* Copy the skb to a new skb with room for us to prepend
* notification with.
*/
- skb = skb_copy_expand(chunk->skb,
- sizeof(struct sctp_remote_error), /* headroom */
- 0, /* tailroom */
- gfp);
+ skb = skb_copy_expand(chunk->skb, sizeof(struct sctp_remote_error),
+ 0, gfp);
/* Pull off the rest of the cause TLV from the chunk. */
skb_pull(chunk->skb, elen);
@@ -348,10 +344,7 @@
/* Embed the event fields inside the cloned skb. */
event = sctp_skb2event(skb);
- event = sctp_ulpevent_init(event, MSG_NOTIFICATION);
-
- if (!event)
- goto fail;
+ sctp_ulpevent_init(event, MSG_NOTIFICATION);
sre = (struct sctp_remote_error *)
skb_push(skb, sizeof(struct sctp_remote_error));
@@ -404,8 +397,7 @@
* All notifications for a given association have the same association
* identifier. For TCP style socket, this field is ignored.
*/
- skb = sctp_event2skb(event);
- sctp_ulpevent_set_owner(skb, asoc);
+ sctp_ulpevent_set_owner(event, asoc);
sre->sre_assoc_id = sctp_assoc2id(asoc);
return event;
@@ -420,13 +412,16 @@
* 5.3.1.4 SCTP_SEND_FAILED
*/
struct sctp_ulpevent *sctp_ulpevent_make_send_failed(
- const struct sctp_association *asoc, sctp_chunk_t *chunk,
+ const struct sctp_association *asoc, struct sctp_chunk *chunk,
__u16 flags, __u32 error, int gfp)
{
struct sctp_ulpevent *event;
struct sctp_send_failed *ssf;
struct sk_buff *skb;
+ /* Pull off any padding. */
+ int len = ntohs(chunk->chunk_hdr->length);
+
/* Make skb with more room so we can prepend notification. */
skb = skb_copy_expand(chunk->skb,
sizeof(struct sctp_send_failed), /* headroom */
@@ -436,13 +431,12 @@
goto fail;
/* Pull off the common chunk header and DATA header. */
- skb_pull(skb, sizeof(sctp_data_chunk_t));
+ skb_pull(skb, sizeof(struct sctp_data_chunk));
+ len -= sizeof(struct sctp_data_chunk);
/* Embed the event fields inside the cloned skb. */
event = sctp_skb2event(skb);
- event = sctp_ulpevent_init(event, MSG_NOTIFICATION);
- if (!event)
- goto fail;
+ sctp_ulpevent_init(event, MSG_NOTIFICATION);
ssf = (struct sctp_send_failed *)
skb_push(skb, sizeof(struct sctp_send_failed));
@@ -477,7 +471,8 @@
* This field is the total length of the notification data, including
* the notification header.
*/
- ssf->ssf_length = skb->len;
+ ssf->ssf_length = sizeof(struct sctp_send_failed) + len;
+ skb_trim(skb, ssf->ssf_length);
/* Socket Extensions for SCTP
* 5.3.1.4 SCTP_SEND_FAILED
@@ -498,6 +493,11 @@
*/
memcpy(&ssf->ssf_info, &chunk->sinfo, sizeof(struct sctp_sndrcvinfo));
+ /* Per TSVWG discussion with Randy. Allow the application to
+ * ressemble a fragmented message.
+ */
+ ssf->ssf_info.sinfo_flags = chunk->chunk_hdr->flags;
+
/* Socket Extensions for SCTP
* 5.3.1.4 SCTP_SEND_FAILED
*
@@ -507,8 +507,7 @@
* same association identifier. For TCP style socket, this field is
* ignored.
*/
- skb = sctp_event2skb(event);
- sctp_ulpevent_set_owner(skb, asoc);
+ sctp_ulpevent_set_owner(event, asoc);
ssf->ssf_assoc_id = sctp_assoc2id(asoc);
return event;
@@ -571,7 +570,7 @@
* All notifications for a given association have the same association
* identifier. For TCP style socket, this field is ignored.
*/
- sctp_ulpevent_set_owner(skb, asoc);
+ sctp_ulpevent_set_owner(event, asoc);
sse->sse_assoc_id = sctp_assoc2id(asoc);
return event;
@@ -588,11 +587,12 @@
* 5.2.2 SCTP Header Information Structure (SCTP_SNDRCV)
*/
struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
- sctp_chunk_t *chunk, int gfp)
+ struct sctp_chunk *chunk,
+ int gfp)
{
struct sctp_ulpevent *event;
struct sctp_sndrcvinfo *info;
- struct sk_buff *skb, *list;
+ struct sk_buff *skb;
size_t padding, len;
/* Clone the original skb, sharing the data. */
@@ -618,24 +618,15 @@
/* Fixup cloned skb with just this chunks data. */
skb_trim(skb, chunk->chunk_end - padding - skb->data);
- /* Set up a destructor to do rwnd accounting. */
- sctp_ulpevent_set_owner_r(skb, asoc);
-
/* Embed the event fields inside the cloned skb. */
event = sctp_skb2event(skb);
/* Initialize event with flags 0. */
- event = sctp_ulpevent_init(event, 0);
- if (!event)
- goto fail_init;
+ sctp_ulpevent_init(event, 0);
event->iif = sctp_chunk_iif(chunk);
- /* Note: Not clearing the entire event struct as
- * this is just a fragment of the real event. However,
- * we still need to do rwnd accounting.
- */
- for (list = skb_shinfo(skb)->frag_list; list; list = list->next)
- sctp_ulpevent_set_owner_r(list, asoc);
+
+ sctp_ulpevent_receive_data(event, asoc);
info = (struct sctp_sndrcvinfo *) &event->sndrcvinfo;
@@ -672,7 +663,7 @@
* for and this information is passed opaquely by the SCTP stack from
* one end to the other.
*/
- info->sinfo_ppid = ntohl(chunk->subh.data_hdr->ppid);
+ info->sinfo_ppid = chunk->subh.data_hdr->ppid;
/* Sockets API Extensions for SCTP
* Section 5.2.2 SCTP Header Information Structure (SCTP_SNDRCV)
@@ -726,9 +717,6 @@
return event;
-fail_init:
- kfree_skb(skb);
-
fail:
return NULL;
}
@@ -745,7 +733,7 @@
const struct sctp_association *asoc, __u32 indication, int gfp)
{
struct sctp_ulpevent *event;
- struct sctp_rcv_pdapi_event *pd;
+ struct sctp_pdapi_event *pd;
struct sk_buff *skb;
event = sctp_ulpevent_new(sizeof(struct sctp_assoc_change),
@@ -754,8 +742,8 @@
goto fail;
skb = sctp_event2skb(event);
- pd = (struct sctp_rcv_pdapi_event *)
- skb_put(skb, sizeof(struct sctp_rcv_pdapi_event));
+ pd = (struct sctp_pdapi_event *)
+ skb_put(skb, sizeof(struct sctp_pdapi_event));
/* pdapi_type
* It should be SCTP_PARTIAL_DELIVERY_EVENT
@@ -770,9 +758,9 @@
*
* This field is the total length of the notification data, including
* the notification header. It will generally be sizeof (struct
- * sctp_rcv_pdapi_event).
+ * sctp_pdapi_event).
*/
- pd->pdapi_length = sizeof(struct sctp_rcv_pdapi_event);
+ pd->pdapi_length = sizeof(struct sctp_pdapi_event);
/* pdapi_indication: 32 bits (unsigned integer)
*
@@ -784,6 +772,7 @@
*
* The association id field, holds the identifier for the association.
*/
+ sctp_ulpevent_set_owner(event, asoc);
pd->pdapi_assoc_id = sctp_assoc2id(asoc);
return event;
@@ -801,7 +790,7 @@
skb = sctp_event2skb((struct sctp_ulpevent *)event);
notification = (union sctp_notification *) skb->data;
- return notification->h.sn_type;
+ return notification->sn_header.sn_type;
}
/* Copy out the sndrcvinfo into a msghdr. */
@@ -815,69 +804,115 @@
}
}
-/* Do accounting for bytes just read by user. */
-static void sctp_rcvmsg_rfree(struct sk_buff *skb)
+/* Stub skb destructor. */
+static void sctp_stub_rfree(struct sk_buff *skb)
{
- struct sctp_association *asoc;
- struct sctp_ulpevent *event;
-
- /* Current stack structures assume that the rcv buffer is
- * per socket. For UDP style sockets this is not true as
- * multiple associations may be on a single UDP-style socket.
- * Use the local private area of the skb to track the owning
- * association.
- */
- event = sctp_skb2event(skb);
- asoc = event->event_asoc;
- sctp_assoc_rwnd_increase(asoc, skb_headlen(skb));
- sctp_association_put(asoc);
+/* WARNING: This function is just a warning not to use the
+ * skb destructor. If the skb is shared, we may get the destructor
+ * callback on some processor that does not own the sock_lock. This
+ * was occuring with PACKET socket applications that were monitoring
+ * our skbs. We can't take the sock_lock, because we can't risk
+ * recursing if we do really own the sock lock. Instead, do all
+ * of our rwnd manipulation while we own the sock_lock outright.
+ */
}
-/* Charge receive window for bytes received. */
-static void sctp_ulpevent_set_owner_r(struct sk_buff *skb,
- struct sctp_association *asoc)
+/* Hold the association in case the msg_name needs read out of
+ * the association.
+ */
+static inline void sctp_ulpevent_set_owner(struct sctp_ulpevent *event,
+ const struct sctp_association *asoc)
{
- struct sctp_ulpevent *event;
+ struct sk_buff *skb;
- /* The current stack structures assume that the rcv buffer is
- * per socket. For UDP-style sockets this is not true as
- * multiple associations may be on a single UDP-style socket.
- * We use the local private area of the skb to track the owning
- * association.
+ /* Cast away the const, as we are just wanting to
+ * bump the reference count.
*/
- sctp_association_hold(asoc);
+ sctp_association_hold((struct sctp_association *)asoc);
+ skb = sctp_event2skb(event);
skb->sk = asoc->base.sk;
- event = sctp_skb2event(skb);
- event->event_asoc = asoc;
+ event->sndrcvinfo.sinfo_assoc_id = sctp_assoc2id(asoc);
+ skb->destructor = sctp_stub_rfree;
+}
+
+/* A simple destructor to give up the reference to the association. */
+static inline void sctp_ulpevent_release_owner(struct sctp_ulpevent *event)
+{
+ sctp_association_put(event->sndrcvinfo.sinfo_assoc_id);
+}
- skb->destructor = sctp_rcvmsg_rfree;
+/* Do accounting for bytes received and hold a reference to the association
+ * for each skb.
+ */
+static void sctp_ulpevent_receive_data(struct sctp_ulpevent *event,
+ struct sctp_association *asoc)
+{
+ struct sk_buff *skb, *frag;
+ skb = sctp_event2skb(event);
+ /* Set the owner and charge rwnd for bytes received. */
+ sctp_ulpevent_set_owner(event, asoc);
sctp_assoc_rwnd_decrease(asoc, skb_headlen(skb));
+
+ /* Note: Not clearing the entire event struct as this is just a
+ * fragment of the real event. However, we still need to do rwnd
+ * accounting.
+ * In general, the skb passed from IP can have only 1 level of
+ * fragments. But we allow multiple levels of fragments.
+ */
+ for (frag = skb_shinfo(skb)->frag_list; frag; frag = frag->next) {
+ sctp_ulpevent_receive_data(sctp_skb2event(frag), asoc);
+ }
}
-/* A simple destructor to give up the reference to the association. */
-static void sctp_ulpevent_rfree(struct sk_buff *skb)
+/* Do accounting for bytes just read by user and release the references to
+ * the association.
+ */
+static void sctp_ulpevent_release_data(struct sctp_ulpevent *event)
{
- struct sctp_ulpevent *event;
+ struct sk_buff *skb, *frag;
- event = sctp_skb2event(skb);
- sctp_association_put(event->event_asoc);
+ /* Current stack structures assume that the rcv buffer is
+ * per socket. For UDP style sockets this is not true as
+ * multiple associations may be on a single UDP-style socket.
+ * Use the local private area of the skb to track the owning
+ * association.
+ */
+
+ skb = sctp_event2skb(event);
+ sctp_assoc_rwnd_increase(event->sndrcvinfo.sinfo_assoc_id,
+ skb_headlen(skb));
+
+ /* Don't forget the fragments. */
+ for (frag = skb_shinfo(skb)->frag_list; frag; frag = frag->next) {
+ /* NOTE: skb_shinfos are recursive. Although IP returns
+ * skb's with only 1 level of fragments, SCTP reassembly can
+ * increase the levels.
+ */
+ sctp_ulpevent_release_data(sctp_skb2event(frag));
+ }
+ sctp_ulpevent_release_owner(event);
}
-/* Hold the association in case the msg_name needs read out of
- * the association.
+/* Free a ulpevent that has an owner. It includes releasing the reference
+ * to the owner, updating the rwnd in case of a DATA event and freeing the
+ * skb.
+ * See comments in sctp_stub_rfree().
*/
-static void sctp_ulpevent_set_owner(struct sk_buff *skb,
- const struct sctp_association *asoc)
+void sctp_ulpevent_free(struct sctp_ulpevent *event)
{
- struct sctp_ulpevent *event;
+ if (sctp_ulpevent_is_notification(event))
+ sctp_ulpevent_release_owner(event);
+ else
+ sctp_ulpevent_release_data(event);
- /* Cast away the const, as we are just wanting to
- * bump the reference count.
- */
- sctp_association_hold((struct sctp_association *)asoc);
- skb->sk = asoc->base.sk;
- event = sctp_skb2event(skb);
- event->event_asoc = (struct sctp_association *)asoc;
- skb->destructor = sctp_ulpevent_rfree;
+ kfree_skb(sctp_event2skb(event));
+}
+
+/* Purge the skb lists holding ulpevents. */
+void sctp_queue_purge_ulpevents(struct sk_buff_head *list)
+{
+ struct sk_buff *skb;
+ while ((skb = skb_dequeue(list)) != NULL)
+ sctp_ulpevent_free(sctp_skb2event(skb));
}
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)