~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to net/sctp/socket.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
658
658
                        goto err_bindx_rem;
659
659
                }
660
660
 
661
 
                if (sa_addr->v4.sin_port != htons(bp->port)) {
 
661
                if (sa_addr->v4.sin_port &&
 
662
                    sa_addr->v4.sin_port != htons(bp->port)) {
662
663
                        retval = -EINVAL;
663
664
                        goto err_bindx_rem;
664
665
                }
665
666
 
 
667
                if (!sa_addr->v4.sin_port)
 
668
                        sa_addr->v4.sin_port = htons(bp->port);
 
669
 
666
670
                /* FIXME - There is probably a need to check if sk->sk_saddr and
667
671
                 * sk->sk_rcv_addr are currently set to one of the addresses to
668
672
                 * be removed. This is something which needs to be looked into
1193
1197
 * an endpoint that is multi-homed.  Much like sctp_bindx() this call
1194
1198
 * allows a caller to specify multiple addresses at which a peer can be
1195
1199
 * reached.  The way the SCTP stack uses the list of addresses to set up
1196
 
 * the association is implementation dependant.  This function only
 
1200
 * the association is implementation dependent.  This function only
1197
1201
 * specifies that the stack will try to make use of all the addresses in
1198
1202
 * the list when needed.
1199
1203
 *
1380
1384
        struct sctp_endpoint *ep;
1381
1385
        struct sctp_association *asoc;
1382
1386
        struct list_head *pos, *temp;
 
1387
        unsigned int data_was_unread;
1383
1388
 
1384
1389
        SCTP_DEBUG_PRINTK("sctp_close(sk: 0x%p, timeout:%ld)\n", sk, timeout);
1385
1390
 
1389
1394
 
1390
1395
        ep = sctp_sk(sk)->ep;
1391
1396
 
 
1397
        /* Clean up any skbs sitting on the receive queue.  */
 
1398
        data_was_unread = sctp_queue_purge_ulpevents(&sk->sk_receive_queue);
 
1399
        data_was_unread += sctp_queue_purge_ulpevents(&sctp_sk(sk)->pd_lobby);
 
1400
 
1392
1401
        /* Walk all associations on an endpoint.  */
1393
1402
        list_for_each_safe(pos, temp, &ep->asocs) {
1394
1403
                asoc = list_entry(pos, struct sctp_association, asocs);
1406
1415
                        }
1407
1416
                }
1408
1417
 
1409
 
                if (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime) {
 
1418
                if (data_was_unread || !skb_queue_empty(&asoc->ulpq.lobby) ||
 
1419
                    !skb_queue_empty(&asoc->ulpq.reasm) ||
 
1420
                    (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime)) {
1410
1421
                        struct sctp_chunk *chunk;
1411
1422
 
1412
1423
                        chunk = sctp_make_abort_user(asoc, NULL, 0);
1416
1427
                        sctp_primitive_SHUTDOWN(asoc, NULL);
1417
1428
        }
1418
1429
 
1419
 
        /* Clean up any skbs sitting on the receive queue.  */
1420
 
        sctp_queue_purge_ulpevents(&sk->sk_receive_queue);
1421
 
        sctp_queue_purge_ulpevents(&sctp_sk(sk)->pd_lobby);
1422
 
 
1423
1430
        /* On a TCP-style socket, block for at most linger_time if set. */
1424
1431
        if (sctp_style(sk, TCP) && timeout)
1425
1432
                sctp_wait_for_close(sk, timeout);
1492
1499
        struct sctp_chunk *chunk;
1493
1500
        union sctp_addr to;
1494
1501
        struct sockaddr *msg_name = NULL;
1495
 
        struct sctp_sndrcvinfo default_sinfo = { 0 };
 
1502
        struct sctp_sndrcvinfo default_sinfo;
1496
1503
        struct sctp_sndrcvinfo *sinfo;
1497
1504
        struct sctp_initmsg *sinit;
1498
1505
        sctp_assoc_t associd = 0;
1756
1763
                /* If the user didn't specify SNDRCVINFO, make up one with
1757
1764
                 * some defaults.
1758
1765
                 */
 
1766
                memset(&default_sinfo, 0, sizeof(default_sinfo));
1759
1767
                default_sinfo.sinfo_stream = asoc->default_stream;
1760
1768
                default_sinfo.sinfo_flags = asoc->default_flags;
1761
1769
                default_sinfo.sinfo_ppid = asoc->default_ppid;
1786
1794
                goto out_free;
1787
1795
        }
1788
1796
 
1789
 
        if (sinfo) {
1790
 
                /* Check for invalid stream. */
1791
 
                if (sinfo->sinfo_stream >= asoc->c.sinit_num_ostreams) {
1792
 
                        err = -EINVAL;
1793
 
                        goto out_free;
1794
 
                }
 
1797
        /* Check for invalid stream. */
 
1798
        if (sinfo->sinfo_stream >= asoc->c.sinit_num_ostreams) {
 
1799
                err = -EINVAL;
 
1800
                goto out_free;
1795
1801
        }
1796
1802
 
1797
1803
        timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
2070
2076
static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
2071
2077
                                  unsigned int optlen)
2072
2078
{
 
2079
        struct sctp_association *asoc;
 
2080
        struct sctp_ulpevent *event;
 
2081
 
2073
2082
        if (optlen > sizeof(struct sctp_event_subscribe))
2074
2083
                return -EINVAL;
2075
2084
        if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
2076
2085
                return -EFAULT;
 
2086
 
 
2087
        /*
 
2088
         * At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
 
2089
         * if there is no data to be sent or retransmit, the stack will
 
2090
         * immediately send up this notification.
 
2091
         */
 
2092
        if (sctp_ulpevent_type_enabled(SCTP_SENDER_DRY_EVENT,
 
2093
                                       &sctp_sk(sk)->subscribe)) {
 
2094
                asoc = sctp_id2assoc(sk, 0);
 
2095
 
 
2096
                if (asoc && sctp_outq_is_empty(&asoc->outqueue)) {
 
2097
                        event = sctp_ulpevent_make_sender_dry_event(asoc,
 
2098
                                        GFP_ATOMIC);
 
2099
                        if (!event)
 
2100
                                return -ENOMEM;
 
2101
 
 
2102
                        sctp_ulpq_tail_event(&asoc->ulpq, event);
 
2103
                }
 
2104
        }
 
2105
 
2077
2106
        return 0;
2078
2107
}
2079
2108
 
2283
2312
                        trans->param_flags =
2284
2313
                                (trans->param_flags & ~SPP_PMTUD) | pmtud_change;
2285
2314
                        if (update) {
2286
 
                                sctp_transport_pmtu(trans);
 
2315
                                sctp_transport_pmtu(trans, sctp_opt2sk(sp));
2287
2316
                                sctp_assoc_sync_pmtu(asoc);
2288
2317
                        }
2289
2318
                } else if (asoc) {
2928
2957
                                             unsigned int optlen)
2929
2958
{
2930
2959
        struct sctp_sock        *sp;
2931
 
        struct sctp_endpoint    *ep;
2932
2960
        struct sctp_association *asoc = NULL;
2933
2961
        struct sctp_setpeerprim prim;
2934
2962
        struct sctp_chunk       *chunk;
2936
2964
        int                     err;
2937
2965
 
2938
2966
        sp = sctp_sk(sk);
2939
 
        ep = sp->ep;
2940
2967
 
2941
2968
        if (!sctp_addip_enable)
2942
2969
                return -EPERM;
3217
3244
        if (optlen < sizeof(struct sctp_hmacalgo))
3218
3245
                return -EINVAL;
3219
3246
 
3220
 
        hmacs = kmalloc(optlen, GFP_KERNEL);
3221
 
        if (!hmacs)
3222
 
                return -ENOMEM;
3223
 
 
3224
 
        if (copy_from_user(hmacs, optval, optlen)) {
3225
 
                err = -EFAULT;
3226
 
                goto out;
3227
 
        }
 
3247
        hmacs= memdup_user(optval, optlen);
 
3248
        if (IS_ERR(hmacs))
 
3249
                return PTR_ERR(hmacs);
3228
3250
 
3229
3251
        idents = hmacs->shmac_num_idents;
3230
3252
        if (idents == 0 || idents > SCTP_AUTH_NUM_HMACS ||
3259
3281
        if (optlen <= sizeof(struct sctp_authkey))
3260
3282
                return -EINVAL;
3261
3283
 
3262
 
        authkey = kmalloc(optlen, GFP_KERNEL);
3263
 
        if (!authkey)
3264
 
                return -ENOMEM;
3265
 
 
3266
 
        if (copy_from_user(authkey, optval, optlen)) {
3267
 
                ret = -EFAULT;
3268
 
                goto out;
3269
 
        }
 
3284
        authkey= memdup_user(optval, optlen);
 
3285
        if (IS_ERR(authkey))
 
3286
                return PTR_ERR(authkey);
3270
3287
 
3271
3288
        if (authkey->sca_keylength > optlen - sizeof(struct sctp_authkey)) {
3272
3289
                ret = -EINVAL;
5285
5302
        return 0;
5286
5303
}
5287
5304
 
 
5305
/*
 
5306
 * 8.2.6. Get the Current Identifiers of Associations
 
5307
 *        (SCTP_GET_ASSOC_ID_LIST)
 
5308
 *
 
5309
 * This option gets the current list of SCTP association identifiers of
 
5310
 * the SCTP associations handled by a one-to-many style socket.
 
5311
 */
 
5312
static int sctp_getsockopt_assoc_ids(struct sock *sk, int len,
 
5313
                                    char __user *optval, int __user *optlen)
 
5314
{
 
5315
        struct sctp_sock *sp = sctp_sk(sk);
 
5316
        struct sctp_association *asoc;
 
5317
        struct sctp_assoc_ids *ids;
 
5318
        u32 num = 0;
 
5319
 
 
5320
        if (sctp_style(sk, TCP))
 
5321
                return -EOPNOTSUPP;
 
5322
 
 
5323
        if (len < sizeof(struct sctp_assoc_ids))
 
5324
                return -EINVAL;
 
5325
 
 
5326
        list_for_each_entry(asoc, &(sp->ep->asocs), asocs) {
 
5327
                num++;
 
5328
        }
 
5329
 
 
5330
        if (len < sizeof(struct sctp_assoc_ids) + sizeof(sctp_assoc_t) * num)
 
5331
                return -EINVAL;
 
5332
 
 
5333
        len = sizeof(struct sctp_assoc_ids) + sizeof(sctp_assoc_t) * num;
 
5334
 
 
5335
        ids = kmalloc(len, GFP_KERNEL);
 
5336
        if (unlikely(!ids))
 
5337
                return -ENOMEM;
 
5338
 
 
5339
        ids->gaids_number_of_ids = num;
 
5340
        num = 0;
 
5341
        list_for_each_entry(asoc, &(sp->ep->asocs), asocs) {
 
5342
                ids->gaids_assoc_id[num++] = asoc->assoc_id;
 
5343
        }
 
5344
 
 
5345
        if (put_user(len, optlen) || copy_to_user(optval, ids, len)) {
 
5346
                kfree(ids);
 
5347
                return -EFAULT;
 
5348
        }
 
5349
 
 
5350
        kfree(ids);
 
5351
        return 0;
 
5352
}
 
5353
 
5288
5354
SCTP_STATIC int sctp_getsockopt(struct sock *sk, int level, int optname,
5289
5355
                                char __user *optval, int __user *optlen)
5290
5356
{
5417
5483
        case SCTP_GET_ASSOC_NUMBER:
5418
5484
                retval = sctp_getsockopt_assoc_number(sk, len, optval, optlen);
5419
5485
                break;
 
5486
        case SCTP_GET_ASSOC_ID_LIST:
 
5487
                retval = sctp_getsockopt_assoc_ids(sk, len, optval, optlen);
 
5488
                break;
5420
5489
        default:
5421
5490
                retval = -ENOPROTOOPT;
5422
5491
                break;
6102
6171
                        wake_up_interruptible(&asoc->wait);
6103
6172
 
6104
6173
                if (sctp_writeable(sk)) {
6105
 
                        if (sk_sleep(sk) && waitqueue_active(sk_sleep(sk)))
6106
 
                                wake_up_interruptible(sk_sleep(sk));
 
6174
                        wait_queue_head_t *wq = sk_sleep(sk);
 
6175
 
 
6176
                        if (wq && waitqueue_active(wq))
 
6177
                                wake_up_interruptible(wq);
6107
6178
 
6108
6179
                        /* Note that we try to include the Async I/O support
6109
6180
                         * here by modeling from the current TCP/UDP code.
6110
6181
                         * We have not tested with it yet.
6111
6182
                         */
6112
 
                        if (sock->wq->fasync_list &&
6113
 
                            !(sk->sk_shutdown & SEND_SHUTDOWN))
 
6183
                        if (!(sk->sk_shutdown & SEND_SHUTDOWN))
6114
6184
                                sock_wake_async(sock,
6115
6185
                                                SOCK_WAKE_SPACE, POLL_OUT);
6116
6186
                }