OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [net/] [sctp/] [ulpevent.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/* SCTP kernel reference Implementation
2
 * Copyright (c) 1999-2000 Cisco, Inc.
3
 * Copyright (c) 1999-2001 Motorola, Inc.
4
 * Copyright (c) 2001 International Business Machines, Corp.
5
 * Copyright (c) 2001 Intel Corp.
6
 * Copyright (c) 2001 Nokia, Inc.
7
 * Copyright (c) 2001 La Monte H.P. Yarroll
8
 *
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)
15
 * any later version.
16
 *
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.
22
 *
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.
27
 *
28
 * Please send any bug reports or fixes you make to the
29
 * email address(es):
30
 *    lksctp developers <lksctp-developers@lists.sourceforge.net>
31
 *
32
 * Or submit a bug report through the following website:
33
 *    http://www.sf.net/projects/lksctp
34
 *
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>
40
 *
41
 * Any bugs reported given to us we will try to fix... any fixes shared will
42
 * be incorporated into the next SCTP release.
43
 */
44
 
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>
50
 
51
static inline void sctp_ulpevent_set_owner(struct sctp_ulpevent *event,
52
                                           const struct sctp_association *asoc);
53
static inline void sctp_ulpevent_release_owner(struct sctp_ulpevent *event);
54
static void sctp_ulpevent_receive_data(struct sctp_ulpevent *event,
55
                                       struct sctp_association *asoc);
56
static void sctp_ulpevent_release_data(struct sctp_ulpevent *event);
57
 
58
/* Create a new sctp_ulpevent.  */
59
struct sctp_ulpevent *sctp_ulpevent_new(int size, int msg_flags, int gfp)
60
{
61
        struct sctp_ulpevent *event;
62
        struct sk_buff *skb;
63
 
64
        skb = alloc_skb(size, gfp);
65
        if (!skb)
66
                goto fail;
67
 
68
        event = sctp_skb2event(skb);
69
        sctp_ulpevent_init(event, msg_flags);
70
 
71
        return event;
72
 
73
fail:
74
        return NULL;
75
}
76
 
77
/* Initialize an ULP event from an given skb.  */
78
void sctp_ulpevent_init(struct sctp_ulpevent *event, int msg_flags)
79
{
80
        memset(event, sizeof(struct sctp_ulpevent), 0x00);
81
        event->msg_flags = msg_flags;
82
}
83
 
84
/* Is this a MSG_NOTIFICATION?  */
85
int sctp_ulpevent_is_notification(const struct sctp_ulpevent *event)
86
{
87
        return MSG_NOTIFICATION == (event->msg_flags & MSG_NOTIFICATION);
88
}
89
 
90
/* Create and initialize an SCTP_ASSOC_CHANGE event.
91
 *
92
 * 5.3.1.1 SCTP_ASSOC_CHANGE
93
 *
94
 * Communication notifications inform the ULP that an SCTP association
95
 * has either begun or ended. The identifier for a new association is
96
 * provided by this notification.
97
 *
98
 * Note: There is no field checking here.  If a field is unused it will be
99
 * zero'd out.
100
 */
101
struct sctp_ulpevent  *sctp_ulpevent_make_assoc_change(
102
        const struct sctp_association *asoc,
103
        __u16 flags, __u16 state, __u16 error, __u16 outbound,
104
        __u16 inbound, int gfp)
105
{
106
        struct sctp_ulpevent *event;
107
        struct sctp_assoc_change *sac;
108
        struct sk_buff *skb;
109
 
110
        event = sctp_ulpevent_new(sizeof(struct sctp_assoc_change),
111
                                  MSG_NOTIFICATION, gfp);
112
        if (!event)
113
                goto fail;
114
        skb = sctp_event2skb(event);
115
        sac = (struct sctp_assoc_change *)
116
                skb_put(skb, sizeof(struct sctp_assoc_change));
117
 
118
        /* Socket Extensions for SCTP
119
         * 5.3.1.1 SCTP_ASSOC_CHANGE
120
         *
121
         * sac_type:
122
         * It should be SCTP_ASSOC_CHANGE.
123
         */
124
        sac->sac_type = SCTP_ASSOC_CHANGE;
125
 
126
        /* Socket Extensions for SCTP
127
         * 5.3.1.1 SCTP_ASSOC_CHANGE
128
         *
129
         * sac_state: 32 bits (signed integer)
130
         * This field holds one of a number of values that communicate the
131
         * event that happened to the association.
132
         */
133
        sac->sac_state = state;
134
 
135
        /* Socket Extensions for SCTP
136
         * 5.3.1.1 SCTP_ASSOC_CHANGE
137
         *
138
         * sac_flags: 16 bits (unsigned integer)
139
         * Currently unused.
140
         */
141
        sac->sac_flags = 0;
142
 
143
        /* Socket Extensions for SCTP
144
         * 5.3.1.1 SCTP_ASSOC_CHANGE
145
         *
146
         * sac_length: sizeof (__u32)
147
         * This field is the total length of the notification data, including
148
         * the notification header.
149
         */
150
        sac->sac_length = sizeof(struct sctp_assoc_change);
151
 
152
        /* Socket Extensions for SCTP
153
         * 5.3.1.1 SCTP_ASSOC_CHANGE
154
         *
155
         * sac_error:  32 bits (signed integer)
156
         *
157
         * If the state was reached due to a error condition (e.g.
158
         * COMMUNICATION_LOST) any relevant error information is available in
159
         * this field. This corresponds to the protocol error codes defined in
160
         * [SCTP].
161
         */
162
        sac->sac_error = error;
163
 
164
        /* Socket Extensions for SCTP
165
         * 5.3.1.1 SCTP_ASSOC_CHANGE
166
         *
167
         * sac_outbound_streams:  16 bits (unsigned integer)
168
         * sac_inbound_streams:  16 bits (unsigned integer)
169
         *
170
         * The maximum number of streams allowed in each direction are
171
         * available in sac_outbound_streams and sac_inbound streams.
172
         */
173
        sac->sac_outbound_streams = outbound;
174
        sac->sac_inbound_streams = inbound;
175
 
176
        /* Socket Extensions for SCTP
177
         * 5.3.1.1 SCTP_ASSOC_CHANGE
178
         *
179
         * sac_assoc_id: sizeof (sctp_assoc_t)
180
         *
181
         * The association id field, holds the identifier for the association.
182
         * All notifications for a given association have the same association
183
         * identifier.  For TCP style socket, this field is ignored.
184
         */
185
        sctp_ulpevent_set_owner(event, asoc);
186
        sac->sac_assoc_id = sctp_assoc2id(asoc);
187
 
188
        return event;
189
 
190
fail:
191
        return NULL;
192
}
193
 
194
/* Create and initialize an SCTP_PEER_ADDR_CHANGE event.
195
 *
196
 * Socket Extensions for SCTP - draft-01
197
 * 5.3.1.2 SCTP_PEER_ADDR_CHANGE
198
 *
199
 * When a destination address on a multi-homed peer encounters a change
200
 * an interface details event is sent.
201
 */
202
struct sctp_ulpevent *sctp_ulpevent_make_peer_addr_change(
203
        const struct sctp_association *asoc,
204
        const struct sockaddr_storage *aaddr,
205
        int flags, int state, int error, int gfp)
206
{
207
        struct sctp_ulpevent *event;
208
        struct sctp_paddr_change  *spc;
209
        struct sk_buff *skb;
210
 
211
        event = sctp_ulpevent_new(sizeof(struct sctp_paddr_change),
212
                                  MSG_NOTIFICATION, gfp);
213
        if (!event)
214
                goto fail;
215
 
216
        skb = sctp_event2skb(event);
217
        spc = (struct sctp_paddr_change *)
218
                skb_put(skb, sizeof(struct sctp_paddr_change));
219
 
220
        /* Sockets API Extensions for SCTP
221
         * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
222
         *
223
         * spc_type:
224
         *
225
         *    It should be SCTP_PEER_ADDR_CHANGE.
226
         */
227
        spc->spc_type = SCTP_PEER_ADDR_CHANGE;
228
 
229
        /* Sockets API Extensions for SCTP
230
         * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
231
         *
232
         * spc_length: sizeof (__u32)
233
         *
234
         * This field is the total length of the notification data, including
235
         * the notification header.
236
         */
237
        spc->spc_length = sizeof(struct sctp_paddr_change);
238
 
239
        /* Sockets API Extensions for SCTP
240
         * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
241
         *
242
         * spc_flags: 16 bits (unsigned integer)
243
         * Currently unused.
244
         */
245
        spc->spc_flags = 0;
246
 
247
        /* Sockets API Extensions for SCTP
248
         * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
249
         *
250
         * spc_state:  32 bits (signed integer)
251
         *
252
         * This field holds one of a number of values that communicate the
253
         * event that happened to the address.
254
         */
255
        spc->spc_state = state;
256
 
257
        /* Sockets API Extensions for SCTP
258
         * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
259
         *
260
         * spc_error:  32 bits (signed integer)
261
         *
262
         * If the state was reached due to any error condition (e.g.
263
         * ADDRESS_UNREACHABLE) any relevant error information is available in
264
         * this field.
265
         */
266
        spc->spc_error = error;
267
 
268
        /* Socket Extensions for SCTP
269
         * 5.3.1.1 SCTP_ASSOC_CHANGE
270
         *
271
         * spc_assoc_id: sizeof (sctp_assoc_t)
272
         *
273
         * The association id field, holds the identifier for the association.
274
         * All notifications for a given association have the same association
275
         * identifier.  For TCP style socket, this field is ignored.
276
         */
277
        sctp_ulpevent_set_owner(event, asoc);
278
        spc->spc_assoc_id = sctp_assoc2id(asoc);
279
 
280
        /* Sockets API Extensions for SCTP
281
         * Section 5.3.1.2 SCTP_PEER_ADDR_CHANGE
282
         *
283
         * spc_aaddr: sizeof (struct sockaddr_storage)
284
         *
285
         * The affected address field, holds the remote peer's address that is
286
         * encountering the change of state.
287
         */
288
        memcpy(&spc->spc_aaddr, aaddr, sizeof(struct sockaddr_storage));
289
 
290
        /* Map ipv4 address into v4-mapped-on-v6 address.  */
291
        sctp_get_pf_specific(asoc->base.sk->sk_family)->addr_v4map(
292
                                        sctp_sk(asoc->base.sk),
293
                                        (union sctp_addr *)&spc->spc_aaddr);
294
 
295
        return event;
296
 
297
fail:
298
        return NULL;
299
}
300
 
301
/* Create and initialize an SCTP_REMOTE_ERROR notification.
302
 *
303
 * Note: This assumes that the chunk->skb->data already points to the
304
 * operation error payload.
305
 *
306
 * Socket Extensions for SCTP - draft-01
307
 * 5.3.1.3 SCTP_REMOTE_ERROR
308
 *
309
 * A remote peer may send an Operational Error message to its peer.
310
 * This message indicates a variety of error conditions on an
311
 * association. The entire error TLV as it appears on the wire is
312
 * included in a SCTP_REMOTE_ERROR event.  Please refer to the SCTP
313
 * specification [SCTP] and any extensions for a list of possible
314
 * error formats.
315
 */
316
struct sctp_ulpevent *sctp_ulpevent_make_remote_error(
317
        const struct sctp_association *asoc, struct sctp_chunk *chunk,
318
        __u16 flags, int gfp)
319
{
320
        struct sctp_ulpevent *event;
321
        struct sctp_remote_error *sre;
322
        struct sk_buff *skb;
323
        sctp_errhdr_t *ch;
324
        __u16 cause;
325
        int elen;
326
 
327
        ch = (sctp_errhdr_t *)(chunk->skb->data);
328
        cause = ch->cause;
329
        elen = WORD_ROUND(ntohs(ch->length)) - sizeof(sctp_errhdr_t);
330
 
331
        /* Pull off the ERROR header.  */
332
        skb_pull(chunk->skb, sizeof(sctp_errhdr_t));
333
 
334
        /* Copy the skb to a new skb with room for us to prepend
335
         * notification with.
336
         */
337
        skb = skb_copy_expand(chunk->skb, sizeof(struct sctp_remote_error),
338
                              0, gfp);
339
 
340
        /* Pull off the rest of the cause TLV from the chunk.  */
341
        skb_pull(chunk->skb, elen);
342
        if (!skb)
343
                goto fail;
344
 
345
        /* Embed the event fields inside the cloned skb.  */
346
        event = sctp_skb2event(skb);
347
        sctp_ulpevent_init(event, MSG_NOTIFICATION);
348
 
349
        sre = (struct sctp_remote_error *)
350
                skb_push(skb, sizeof(struct sctp_remote_error));
351
 
352
        /* Trim the buffer to the right length.  */
353
        skb_trim(skb, sizeof(struct sctp_remote_error) + elen);
354
 
355
        /* Socket Extensions for SCTP
356
         * 5.3.1.3 SCTP_REMOTE_ERROR
357
         *
358
         * sre_type:
359
         *   It should be SCTP_REMOTE_ERROR.
360
         */
361
        sre->sre_type = SCTP_REMOTE_ERROR;
362
 
363
        /*
364
         * Socket Extensions for SCTP
365
         * 5.3.1.3 SCTP_REMOTE_ERROR
366
         *
367
         * sre_flags: 16 bits (unsigned integer)
368
         *   Currently unused.
369
         */
370
        sre->sre_flags = 0;
371
 
372
        /* Socket Extensions for SCTP
373
         * 5.3.1.3 SCTP_REMOTE_ERROR
374
         *
375
         * sre_length: sizeof (__u32)
376
         *
377
         * This field is the total length of the notification data,
378
         * including the notification header.
379
         */
380
        sre->sre_length = skb->len;
381
 
382
        /* Socket Extensions for SCTP
383
         * 5.3.1.3 SCTP_REMOTE_ERROR
384
         *
385
         * sre_error: 16 bits (unsigned integer)
386
         * This value represents one of the Operational Error causes defined in
387
         * the SCTP specification, in network byte order.
388
         */
389
        sre->sre_error = cause;
390
 
391
        /* Socket Extensions for SCTP
392
         * 5.3.1.3 SCTP_REMOTE_ERROR
393
         *
394
         * sre_assoc_id: sizeof (sctp_assoc_t)
395
         *
396
         * The association id field, holds the identifier for the association.
397
         * All notifications for a given association have the same association
398
         * identifier.  For TCP style socket, this field is ignored.
399
         */
400
        sctp_ulpevent_set_owner(event, asoc);
401
        sre->sre_assoc_id = sctp_assoc2id(asoc);
402
 
403
        return event;
404
 
405
fail:
406
        return NULL;
407
}
408
 
409
/* Create and initialize a SCTP_SEND_FAILED notification.
410
 *
411
 * Socket Extensions for SCTP - draft-01
412
 * 5.3.1.4 SCTP_SEND_FAILED
413
 */
414
struct sctp_ulpevent *sctp_ulpevent_make_send_failed(
415
        const struct sctp_association *asoc, struct sctp_chunk *chunk,
416
        __u16 flags, __u32 error, int gfp)
417
{
418
        struct sctp_ulpevent *event;
419
        struct sctp_send_failed *ssf;
420
        struct sk_buff *skb;
421
 
422
        /* Pull off any padding. */
423
        int len = ntohs(chunk->chunk_hdr->length);
424
 
425
        /* Make skb with more room so we can prepend notification.  */
426
        skb = skb_copy_expand(chunk->skb,
427
                              sizeof(struct sctp_send_failed), /* headroom */
428
                              0,                               /* tailroom */
429
                              gfp);
430
        if (!skb)
431
                goto fail;
432
 
433
        /* Pull off the common chunk header and DATA header.  */
434
        skb_pull(skb, sizeof(struct sctp_data_chunk));
435
        len -= sizeof(struct sctp_data_chunk);
436
 
437
        /* Embed the event fields inside the cloned skb.  */
438
        event = sctp_skb2event(skb);
439
        sctp_ulpevent_init(event, MSG_NOTIFICATION);
440
 
441
        ssf = (struct sctp_send_failed *)
442
                skb_push(skb, sizeof(struct sctp_send_failed));
443
 
444
        /* Socket Extensions for SCTP
445
         * 5.3.1.4 SCTP_SEND_FAILED
446
         *
447
         * ssf_type:
448
         * It should be SCTP_SEND_FAILED.
449
         */
450
        ssf->ssf_type = SCTP_SEND_FAILED;
451
 
452
        /* Socket Extensions for SCTP
453
         * 5.3.1.4 SCTP_SEND_FAILED
454
         *
455
         * ssf_flags: 16 bits (unsigned integer)
456
         * The flag value will take one of the following values
457
         *
458
         * SCTP_DATA_UNSENT - Indicates that the data was never put on
459
         *                    the wire.
460
         *
461
         * SCTP_DATA_SENT   - Indicates that the data was put on the wire.
462
         *                    Note that this does not necessarily mean that the
463
         *                    data was (or was not) successfully delivered.
464
         */
465
        ssf->ssf_flags = flags;
466
 
467
        /* Socket Extensions for SCTP
468
         * 5.3.1.4 SCTP_SEND_FAILED
469
         *
470
         * ssf_length: sizeof (__u32)
471
         * This field is the total length of the notification data, including
472
         * the notification header.
473
         */
474
        ssf->ssf_length = sizeof(struct sctp_send_failed) + len;
475
        skb_trim(skb, ssf->ssf_length);
476
 
477
        /* Socket Extensions for SCTP
478
         * 5.3.1.4 SCTP_SEND_FAILED
479
         *
480
         * ssf_error: 16 bits (unsigned integer)
481
         * This value represents the reason why the send failed, and if set,
482
         * will be a SCTP protocol error code as defined in [SCTP] section
483
         * 3.3.10.
484
         */
485
        ssf->ssf_error = error;
486
 
487
        /* Socket Extensions for SCTP
488
         * 5.3.1.4 SCTP_SEND_FAILED
489
         *
490
         * ssf_info: sizeof (struct sctp_sndrcvinfo)
491
         * The original send information associated with the undelivered
492
         * message.
493
         */
494
        memcpy(&ssf->ssf_info, &chunk->sinfo, sizeof(struct sctp_sndrcvinfo));
495
 
496
        /* Per TSVWG discussion with Randy. Allow the application to
497
         * ressemble a fragmented message.
498
         */
499
        ssf->ssf_info.sinfo_flags = chunk->chunk_hdr->flags;
500
 
501
        /* Socket Extensions for SCTP
502
         * 5.3.1.4 SCTP_SEND_FAILED
503
         *
504
         * ssf_assoc_id: sizeof (sctp_assoc_t)
505
         * The association id field, sf_assoc_id, holds the identifier for the
506
         * association.  All notifications for a given association have the
507
         * same association identifier.  For TCP style socket, this field is
508
         * ignored.
509
         */
510
        sctp_ulpevent_set_owner(event, asoc);
511
        ssf->ssf_assoc_id = sctp_assoc2id(asoc);
512
        return event;
513
 
514
fail:
515
        return NULL;
516
}
517
 
518
/* Create and initialize a SCTP_SHUTDOWN_EVENT notification.
519
 *
520
 * Socket Extensions for SCTP - draft-01
521
 * 5.3.1.5 SCTP_SHUTDOWN_EVENT
522
 */
523
struct sctp_ulpevent *sctp_ulpevent_make_shutdown_event(
524
        const struct sctp_association *asoc,
525
        __u16 flags, int gfp)
526
{
527
        struct sctp_ulpevent *event;
528
        struct sctp_shutdown_event *sse;
529
        struct sk_buff *skb;
530
 
531
        event = sctp_ulpevent_new(sizeof(struct sctp_assoc_change),
532
                                  MSG_NOTIFICATION, gfp);
533
        if (!event)
534
                goto fail;
535
 
536
        skb = sctp_event2skb(event);
537
        sse = (struct sctp_shutdown_event *)
538
                skb_put(skb, sizeof(struct sctp_shutdown_event));
539
 
540
        /* Socket Extensions for SCTP
541
         * 5.3.1.5 SCTP_SHUTDOWN_EVENT
542
         *
543
         * sse_type
544
         * It should be SCTP_SHUTDOWN_EVENT
545
         */
546
        sse->sse_type = SCTP_SHUTDOWN_EVENT;
547
 
548
        /* Socket Extensions for SCTP
549
         * 5.3.1.5 SCTP_SHUTDOWN_EVENT
550
         *
551
         * sse_flags: 16 bits (unsigned integer)
552
         * Currently unused.
553
         */
554
        sse->sse_flags = 0;
555
 
556
        /* Socket Extensions for SCTP
557
         * 5.3.1.5 SCTP_SHUTDOWN_EVENT
558
         *
559
         * sse_length: sizeof (__u32)
560
         * This field is the total length of the notification data, including
561
         * the notification header.
562
         */
563
        sse->sse_length = sizeof(struct sctp_shutdown_event);
564
 
565
        /* Socket Extensions for SCTP
566
         * 5.3.1.5 SCTP_SHUTDOWN_EVENT
567
         *
568
         * sse_assoc_id: sizeof (sctp_assoc_t)
569
         * The association id field, holds the identifier for the association.
570
         * All notifications for a given association have the same association
571
         * identifier.  For TCP style socket, this field is ignored.
572
         */
573
        sctp_ulpevent_set_owner(event, asoc);
574
        sse->sse_assoc_id = sctp_assoc2id(asoc);
575
 
576
        return event;
577
 
578
fail:
579
        return NULL;
580
}
581
 
582
/* A message has been received.  Package this message as a notification
583
 * to pass it to the upper layers.  Go ahead and calculate the sndrcvinfo
584
 * even if filtered out later.
585
 *
586
 * Socket Extensions for SCTP
587
 * 5.2.2 SCTP Header Information Structure (SCTP_SNDRCV)
588
 */
589
struct sctp_ulpevent *sctp_ulpevent_make_rcvmsg(struct sctp_association *asoc,
590
                                                struct sctp_chunk *chunk,
591
                                                int gfp)
592
{
593
        struct sctp_ulpevent *event;
594
        struct sctp_sndrcvinfo *info;
595
        struct sk_buff *skb;
596
        size_t padding, len;
597
 
598
        /* Clone the original skb, sharing the data.  */
599
        skb = skb_clone(chunk->skb, gfp);
600
        if (!skb)
601
                goto fail;
602
 
603
        /* First calculate the padding, so we don't inadvertently
604
         * pass up the wrong length to the user.
605
         *
606
         * RFC 2960 - Section 3.2  Chunk Field Descriptions
607
         *
608
         * The total length of a chunk(including Type, Length and Value fields)
609
         * MUST be a multiple of 4 bytes.  If the length of the chunk is not a
610
         * multiple of 4 bytes, the sender MUST pad the chunk with all zero
611
         * bytes and this padding is not included in the chunk length field.
612
         * The sender should never pad with more than 3 bytes.  The receiver
613
         * MUST ignore the padding bytes.
614
         */
615
        len = ntohs(chunk->chunk_hdr->length);
616
        padding = WORD_ROUND(len) - len;
617
 
618
        /* Fixup cloned skb with just this chunks data.  */
619
        skb_trim(skb, chunk->chunk_end - padding - skb->data);
620
 
621
        /* Embed the event fields inside the cloned skb.  */
622
        event = sctp_skb2event(skb);
623
 
624
        /* Initialize event with flags 0.  */
625
        sctp_ulpevent_init(event, 0);
626
 
627
        event->iif = sctp_chunk_iif(chunk);
628
 
629
        sctp_ulpevent_receive_data(event, asoc);
630
 
631
        info = (struct sctp_sndrcvinfo *) &event->sndrcvinfo;
632
 
633
        /* Sockets API Extensions for SCTP
634
         * Section 5.2.2 SCTP Header Information Structure (SCTP_SNDRCV)
635
         *
636
         * sinfo_stream: 16 bits (unsigned integer)
637
         *
638
         * For recvmsg() the SCTP stack places the message's stream number in
639
         * this value.
640
         */
641
        info->sinfo_stream = ntohs(chunk->subh.data_hdr->stream);
642
 
643
        /* Sockets API Extensions for SCTP
644
         * Section 5.2.2 SCTP Header Information Structure (SCTP_SNDRCV)
645
         *
646
         * sinfo_ssn: 16 bits (unsigned integer)
647
         *
648
         * For recvmsg() this value contains the stream sequence number that
649
         * the remote endpoint placed in the DATA chunk.  For fragmented
650
         * messages this is the same number for all deliveries of the message
651
         * (if more than one recvmsg() is needed to read the message).
652
         */
653
        info->sinfo_ssn = ntohs(chunk->subh.data_hdr->ssn);
654
 
655
        /* Sockets API Extensions for SCTP
656
         * Section 5.2.2 SCTP Header Information Structure (SCTP_SNDRCV)
657
         *
658
         * sinfo_ppid: 32 bits (unsigned integer)
659
         *
660
         * In recvmsg() this value is
661
         * the same information that was passed by the upper layer in the peer
662
         * application.  Please note that byte order issues are NOT accounted
663
         * for and this information is passed opaquely by the SCTP stack from
664
         * one end to the other.
665
         */
666
        info->sinfo_ppid = chunk->subh.data_hdr->ppid;
667
 
668
        /* Sockets API Extensions for SCTP
669
         * Section 5.2.2 SCTP Header Information Structure (SCTP_SNDRCV)
670
         *
671
         * sinfo_flags: 16 bits (unsigned integer)
672
         *
673
         * This field may contain any of the following flags and is composed of
674
         * a bitwise OR of these values.
675
         *
676
         * recvmsg() flags:
677
         *
678
         * MSG_UNORDERED - This flag is present when the message was sent
679
         *                 non-ordered.
680
         */
681
        if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) {
682
                info->sinfo_flags |= MSG_UNORDERED;
683
 
684
                /* sinfo_cumtsn: 32 bit (unsigned integer)
685
                 *
686
                 * This field will hold the current cumulative TSN as
687
                 * known by the underlying SCTP layer.  Note this field is
688
                 * ignored when sending and only valid for a receive
689
                 * operation when sinfo_flags are set to MSG_UNORDERED.
690
                 */
691
                info->sinfo_cumtsn = sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map);
692
        }
693
 
694
        /* Note:  For reassembly, we need to have the fragmentation bits.
695
         * For now, merge these into the msg_flags, since those bit
696
         * possitions are not used.
697
         */
698
        event->msg_flags |= chunk->chunk_hdr->flags;
699
 
700
        /* With 04 draft, tsn moves into sndrcvinfo. */
701
        info->sinfo_tsn = ntohl(chunk->subh.data_hdr->tsn);
702
 
703
        /* Context is not used on receive. */
704
        info->sinfo_context = 0;
705
 
706
        /* Sockets API Extensions for SCTP
707
         * Section 5.2.2 SCTP Header Information Structure (SCTP_SNDRCV)
708
         *
709
         * sinfo_assoc_id: sizeof (sctp_assoc_t)
710
         *
711
         * The association handle field, sinfo_assoc_id, holds the identifier
712
         * for the association announced in the COMMUNICATION_UP notification.
713
         * All notifications for a given association have the same identifier.
714
         * Ignored for TCP-style sockets.
715
         */
716
        info->sinfo_assoc_id = sctp_assoc2id(asoc);
717
 
718
        return event;
719
 
720
fail:
721
        return NULL;
722
}
723
 
724
/* Create a partial delivery related event.
725
 *
726
 * 5.3.1.7 SCTP_PARTIAL_DELIVERY_EVENT
727
 *
728
 *   When a reciever is engaged in a partial delivery of a
729
 *   message this notification will be used to inidicate
730
 *   various events.
731
 */
732
struct sctp_ulpevent *sctp_ulpevent_make_pdapi(
733
        const struct sctp_association *asoc, __u32 indication, int gfp)
734
{
735
        struct sctp_ulpevent *event;
736
        struct sctp_pdapi_event *pd;
737
        struct sk_buff *skb;
738
 
739
        event = sctp_ulpevent_new(sizeof(struct sctp_assoc_change),
740
                                  MSG_NOTIFICATION, gfp);
741
        if (!event)
742
                goto fail;
743
 
744
        skb = sctp_event2skb(event);
745
        pd = (struct sctp_pdapi_event *)
746
                skb_put(skb, sizeof(struct sctp_pdapi_event));
747
 
748
        /* pdapi_type
749
         *   It should be SCTP_PARTIAL_DELIVERY_EVENT
750
         *
751
         * pdapi_flags: 16 bits (unsigned integer)
752
         *   Currently unused.
753
         */
754
        pd->pdapi_type = SCTP_PARTIAL_DELIVERY_EVENT;
755
        pd->pdapi_flags = 0;
756
 
757
        /* pdapi_length: 32 bits (unsigned integer)
758
         *
759
         * This field is the total length of the notification data, including
760
         * the notification header.  It will generally be sizeof (struct
761
         * sctp_pdapi_event).
762
         */
763
        pd->pdapi_length = sizeof(struct sctp_pdapi_event);
764
 
765
        /*  pdapi_indication: 32 bits (unsigned integer)
766
         *
767
         * This field holds the indication being sent to the application.
768
         */
769
        pd->pdapi_indication = indication;
770
 
771
        /*  pdapi_assoc_id: sizeof (sctp_assoc_t)
772
         *
773
         * The association id field, holds the identifier for the association.
774
         */
775
        sctp_ulpevent_set_owner(event, asoc);
776
        pd->pdapi_assoc_id = sctp_assoc2id(asoc);
777
 
778
        return event;
779
fail:
780
        return NULL;
781
}
782
 
783
/* Return the notification type, assuming this is a notification
784
 * event.
785
 */
786
__u16 sctp_ulpevent_get_notification_type(const struct sctp_ulpevent *event)
787
{
788
        union sctp_notification *notification;
789
        struct sk_buff *skb;
790
 
791
        skb = sctp_event2skb((struct sctp_ulpevent *)event);
792
        notification = (union sctp_notification *) skb->data;
793
        return notification->sn_header.sn_type;
794
}
795
 
796
/* Copy out the sndrcvinfo into a msghdr.  */
797
void sctp_ulpevent_read_sndrcvinfo(const struct sctp_ulpevent *event,
798
                                   struct msghdr *msghdr)
799
{
800
        if (!sctp_ulpevent_is_notification(event)) {
801
                put_cmsg(msghdr, IPPROTO_SCTP, SCTP_SNDRCV,
802
                         sizeof(struct sctp_sndrcvinfo),
803
                         (void *) &event->sndrcvinfo);
804
        }
805
}
806
 
807
/* Stub skb destructor.  */
808
static void sctp_stub_rfree(struct sk_buff *skb)
809
{
810
/* WARNING:  This function is just a warning not to use the
811
 * skb destructor.  If the skb is shared, we may get the destructor
812
 * callback on some processor that does not own the sock_lock.  This
813
 * was occuring with PACKET socket applications that were monitoring
814
 * our skbs.   We can't take the sock_lock, because we can't risk
815
 * recursing if we do really own the sock lock.  Instead, do all
816
 * of our rwnd manipulation while we own the sock_lock outright.
817
 */
818
}
819
 
820
/* Hold the association in case the msg_name needs read out of
821
 * the association.
822
 */
823
static inline void sctp_ulpevent_set_owner(struct sctp_ulpevent *event,
824
                                           const struct sctp_association *asoc)
825
{
826
        struct sk_buff *skb;
827
 
828
        /* Cast away the const, as we are just wanting to
829
         * bump the reference count.
830
         */
831
        sctp_association_hold((struct sctp_association *)asoc);
832
        skb = sctp_event2skb(event);
833
        skb->sk = asoc->base.sk;
834
        event->sndrcvinfo.sinfo_assoc_id = sctp_assoc2id(asoc);
835
        skb->destructor = sctp_stub_rfree;
836
}
837
 
838
/* A simple destructor to give up the reference to the association. */
839
static inline void sctp_ulpevent_release_owner(struct sctp_ulpevent *event)
840
{
841
        sctp_association_put(event->sndrcvinfo.sinfo_assoc_id);
842
}
843
 
844
/* Do accounting for bytes received and hold a reference to the association
845
 * for each skb.
846
 */
847
static void sctp_ulpevent_receive_data(struct sctp_ulpevent *event,
848
                                       struct sctp_association *asoc)
849
{
850
        struct sk_buff *skb, *frag;
851
 
852
        skb = sctp_event2skb(event);
853
        /* Set the owner and charge rwnd for bytes received.  */
854
        sctp_ulpevent_set_owner(event, asoc);
855
        sctp_assoc_rwnd_decrease(asoc, skb_headlen(skb));
856
 
857
        /* Note:  Not clearing the entire event struct as this is just a
858
         * fragment of the real event.  However, we still need to do rwnd
859
         * accounting.
860
         * In general, the skb passed from IP can have only 1 level of
861
         * fragments. But we allow multiple levels of fragments.
862
         */
863
        for (frag = skb_shinfo(skb)->frag_list; frag; frag = frag->next) {
864
                sctp_ulpevent_receive_data(sctp_skb2event(frag), asoc);
865
        }
866
}
867
 
868
/* Do accounting for bytes just read by user and release the references to
869
 * the association.
870
 */
871
static void sctp_ulpevent_release_data(struct sctp_ulpevent *event)
872
{
873
        struct sk_buff *skb, *frag;
874
 
875
        /* Current stack structures assume that the rcv buffer is
876
         * per socket.   For UDP style sockets this is not true as
877
         * multiple associations may be on a single UDP-style socket.
878
         * Use the local private area of the skb to track the owning
879
         * association.
880
         */
881
 
882
        skb = sctp_event2skb(event);
883
        sctp_assoc_rwnd_increase(event->sndrcvinfo.sinfo_assoc_id,
884
                                 skb_headlen(skb));
885
 
886
        /* Don't forget the fragments. */
887
        for (frag = skb_shinfo(skb)->frag_list; frag; frag = frag->next) {
888
                /* NOTE:  skb_shinfos are recursive. Although IP returns
889
                 * skb's with only 1 level of fragments, SCTP reassembly can
890
                 * increase the levels.
891
                 */
892
                sctp_ulpevent_release_data(sctp_skb2event(frag));
893
        }
894
        sctp_ulpevent_release_owner(event);
895
}
896
 
897
/* Free a ulpevent that has an owner.  It includes releasing the reference
898
 * to the owner, updating the rwnd in case of a DATA event and freeing the
899
 * skb.
900
 * See comments in sctp_stub_rfree().
901
 */
902
void sctp_ulpevent_free(struct sctp_ulpevent *event)
903
{
904
        if (sctp_ulpevent_is_notification(event))
905
                sctp_ulpevent_release_owner(event);
906
        else
907
                sctp_ulpevent_release_data(event);
908
 
909
        kfree_skb(sctp_event2skb(event));
910
}
911
 
912
/* Purge the skb lists holding ulpevents. */
913
void sctp_queue_purge_ulpevents(struct sk_buff_head *list)
914
{
915
        struct sk_buff *skb;
916
        while ((skb = skb_dequeue(list)) != NULL)
917
                sctp_ulpevent_free(sctp_skb2event(skb));
918
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.