658
658
goto err_bindx_rem;
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;
667
if (!sa_addr->v4.sin_port)
668
sa_addr->v4.sin_port = htons(bp->port);
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.
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;
1384
1389
SCTP_DEBUG_PRINTK("sctp_close(sk: 0x%p, timeout:%ld)\n", sk, timeout);
1390
1395
ep = sctp_sk(sk)->ep;
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);
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);
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;
1412
1423
chunk = sctp_make_abort_user(asoc, NULL, 0);
1416
1427
sctp_primitive_SHUTDOWN(asoc, NULL);
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);
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.
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;
1790
/* Check for invalid stream. */
1791
if (sinfo->sinfo_stream >= asoc->c.sinit_num_ostreams) {
1797
/* Check for invalid stream. */
1798
if (sinfo->sinfo_stream >= asoc->c.sinit_num_ostreams) {
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)
2079
struct sctp_association *asoc;
2080
struct sctp_ulpevent *event;
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;
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.
2092
if (sctp_ulpevent_type_enabled(SCTP_SENDER_DRY_EVENT,
2093
&sctp_sk(sk)->subscribe)) {
2094
asoc = sctp_id2assoc(sk, 0);
2096
if (asoc && sctp_outq_is_empty(&asoc->outqueue)) {
2097
event = sctp_ulpevent_make_sender_dry_event(asoc,
2102
sctp_ulpq_tail_event(&asoc->ulpq, event);
2283
2312
trans->param_flags =
2284
2313
(trans->param_flags & ~SPP_PMTUD) | pmtud_change;
2286
sctp_transport_pmtu(trans);
2315
sctp_transport_pmtu(trans, sctp_opt2sk(sp));
2287
2316
sctp_assoc_sync_pmtu(asoc);
2289
2318
} else if (asoc) {
3217
3244
if (optlen < sizeof(struct sctp_hmacalgo))
3218
3245
return -EINVAL;
3220
hmacs = kmalloc(optlen, GFP_KERNEL);
3224
if (copy_from_user(hmacs, optval, optlen)) {
3247
hmacs= memdup_user(optval, optlen);
3249
return PTR_ERR(hmacs);
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;
3262
authkey = kmalloc(optlen, GFP_KERNEL);
3266
if (copy_from_user(authkey, optval, optlen)) {
3284
authkey= memdup_user(optval, optlen);
3285
if (IS_ERR(authkey))
3286
return PTR_ERR(authkey);
3271
3288
if (authkey->sca_keylength > optlen - sizeof(struct sctp_authkey)) {
5306
* 8.2.6. Get the Current Identifiers of Associations
5307
* (SCTP_GET_ASSOC_ID_LIST)
5309
* This option gets the current list of SCTP association identifiers of
5310
* the SCTP associations handled by a one-to-many style socket.
5312
static int sctp_getsockopt_assoc_ids(struct sock *sk, int len,
5313
char __user *optval, int __user *optlen)
5315
struct sctp_sock *sp = sctp_sk(sk);
5316
struct sctp_association *asoc;
5317
struct sctp_assoc_ids *ids;
5320
if (sctp_style(sk, TCP))
5323
if (len < sizeof(struct sctp_assoc_ids))
5326
list_for_each_entry(asoc, &(sp->ep->asocs), asocs) {
5330
if (len < sizeof(struct sctp_assoc_ids) + sizeof(sctp_assoc_t) * num)
5333
len = sizeof(struct sctp_assoc_ids) + sizeof(sctp_assoc_t) * num;
5335
ids = kmalloc(len, GFP_KERNEL);
5339
ids->gaids_number_of_ids = num;
5341
list_for_each_entry(asoc, &(sp->ep->asocs), asocs) {
5342
ids->gaids_assoc_id[num++] = asoc->assoc_id;
5345
if (put_user(len, optlen) || copy_to_user(optval, ids, len)) {
5288
5354
SCTP_STATIC int sctp_getsockopt(struct sock *sk, int level, int optname,
5289
5355
char __user *optval, int __user *optlen)
5417
5483
case SCTP_GET_ASSOC_NUMBER:
5418
5484
retval = sctp_getsockopt_assoc_number(sk, len, optval, optlen);
5486
case SCTP_GET_ASSOC_ID_LIST:
5487
retval = sctp_getsockopt_assoc_ids(sk, len, optval, optlen);
5421
5490
retval = -ENOPROTOOPT;
6102
6171
wake_up_interruptible(&asoc->wait);
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);
6176
if (wq && waitqueue_active(wq))
6177
wake_up_interruptible(wq);
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.
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);