diff options
Diffstat (limited to 'net/sctp/socket.c')
-rw-r--r-- | net/sctp/socket.c | 286 |
1 files changed, 161 insertions, 125 deletions
diff --git a/net/sctp/socket.c b/net/sctp/socket.c index 42b709c95cf3..981aaf8b6ace 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c | |||
@@ -28,9 +28,8 @@ | |||
28 | * See the GNU General Public License for more details. | 28 | * See the GNU General Public License for more details. |
29 | * | 29 | * |
30 | * You should have received a copy of the GNU General Public License | 30 | * You should have received a copy of the GNU General Public License |
31 | * along with GNU CC; see the file COPYING. If not, write to | 31 | * along with GNU CC; see the file COPYING. If not, see |
32 | * the Free Software Foundation, 59 Temple Place - Suite 330, | 32 | * <http://www.gnu.org/licenses/>. |
33 | * Boston, MA 02111-1307, USA. | ||
34 | * | 33 | * |
35 | * Please send any bug reports or fixes you make to the | 34 | * Please send any bug reports or fixes you make to the |
36 | * email address(es): | 35 | * email address(es): |
@@ -65,6 +64,7 @@ | |||
65 | #include <linux/crypto.h> | 64 | #include <linux/crypto.h> |
66 | #include <linux/slab.h> | 65 | #include <linux/slab.h> |
67 | #include <linux/file.h> | 66 | #include <linux/file.h> |
67 | #include <linux/compat.h> | ||
68 | 68 | ||
69 | #include <net/ip.h> | 69 | #include <net/ip.h> |
70 | #include <net/icmp.h> | 70 | #include <net/icmp.h> |
@@ -83,7 +83,7 @@ static int sctp_writeable(struct sock *sk); | |||
83 | static void sctp_wfree(struct sk_buff *skb); | 83 | static void sctp_wfree(struct sk_buff *skb); |
84 | static int sctp_wait_for_sndbuf(struct sctp_association *, long *timeo_p, | 84 | static int sctp_wait_for_sndbuf(struct sctp_association *, long *timeo_p, |
85 | size_t msg_len); | 85 | size_t msg_len); |
86 | static int sctp_wait_for_packet(struct sock * sk, int *err, long *timeo_p); | 86 | static int sctp_wait_for_packet(struct sock *sk, int *err, long *timeo_p); |
87 | static int sctp_wait_for_connect(struct sctp_association *, long *timeo_p); | 87 | static int sctp_wait_for_connect(struct sctp_association *, long *timeo_p); |
88 | static int sctp_wait_for_accept(struct sock *sk, long timeo); | 88 | static int sctp_wait_for_accept(struct sock *sk, long timeo); |
89 | static void sctp_wait_for_close(struct sock *sk, long timeo); | 89 | static void sctp_wait_for_close(struct sock *sk, long timeo); |
@@ -273,7 +273,7 @@ static int sctp_bind(struct sock *sk, struct sockaddr *addr, int addr_len) | |||
273 | { | 273 | { |
274 | int retval = 0; | 274 | int retval = 0; |
275 | 275 | ||
276 | sctp_lock_sock(sk); | 276 | lock_sock(sk); |
277 | 277 | ||
278 | pr_debug("%s: sk:%p, addr:%p, addr_len:%d\n", __func__, sk, | 278 | pr_debug("%s: sk:%p, addr:%p, addr_len:%d\n", __func__, sk, |
279 | addr, addr_len); | 279 | addr, addr_len); |
@@ -285,7 +285,7 @@ static int sctp_bind(struct sock *sk, struct sockaddr *addr, int addr_len) | |||
285 | else | 285 | else |
286 | retval = -EINVAL; | 286 | retval = -EINVAL; |
287 | 287 | ||
288 | sctp_release_sock(sk); | 288 | release_sock(sk); |
289 | 289 | ||
290 | return retval; | 290 | return retval; |
291 | } | 291 | } |
@@ -953,7 +953,7 @@ int sctp_asconf_mgmt(struct sctp_sock *sp, struct sctp_sockaddr_entry *addrw) | |||
953 | * | 953 | * |
954 | * Returns 0 if ok, <0 errno code on error. | 954 | * Returns 0 if ok, <0 errno code on error. |
955 | */ | 955 | */ |
956 | static int sctp_setsockopt_bindx(struct sock* sk, | 956 | static int sctp_setsockopt_bindx(struct sock *sk, |
957 | struct sockaddr __user *addrs, | 957 | struct sockaddr __user *addrs, |
958 | int addrs_size, int op) | 958 | int addrs_size, int op) |
959 | { | 959 | { |
@@ -1040,7 +1040,7 @@ out: | |||
1040 | * Common routine for handling connect() and sctp_connectx(). | 1040 | * Common routine for handling connect() and sctp_connectx(). |
1041 | * Connect will come in with just a single address. | 1041 | * Connect will come in with just a single address. |
1042 | */ | 1042 | */ |
1043 | static int __sctp_connect(struct sock* sk, | 1043 | static int __sctp_connect(struct sock *sk, |
1044 | struct sockaddr *kaddrs, | 1044 | struct sockaddr *kaddrs, |
1045 | int addrs_size, | 1045 | int addrs_size, |
1046 | sctp_assoc_t *assoc_id) | 1046 | sctp_assoc_t *assoc_id) |
@@ -1300,7 +1300,7 @@ out_free: | |||
1300 | * | 1300 | * |
1301 | * Returns >=0 if ok, <0 errno code on error. | 1301 | * Returns >=0 if ok, <0 errno code on error. |
1302 | */ | 1302 | */ |
1303 | static int __sctp_setsockopt_connectx(struct sock* sk, | 1303 | static int __sctp_setsockopt_connectx(struct sock *sk, |
1304 | struct sockaddr __user *addrs, | 1304 | struct sockaddr __user *addrs, |
1305 | int addrs_size, | 1305 | int addrs_size, |
1306 | sctp_assoc_t *assoc_id) | 1306 | sctp_assoc_t *assoc_id) |
@@ -1338,7 +1338,7 @@ static int __sctp_setsockopt_connectx(struct sock* sk, | |||
1338 | * This is an older interface. It's kept for backward compatibility | 1338 | * This is an older interface. It's kept for backward compatibility |
1339 | * to the option that doesn't provide association id. | 1339 | * to the option that doesn't provide association id. |
1340 | */ | 1340 | */ |
1341 | static int sctp_setsockopt_connectx_old(struct sock* sk, | 1341 | static int sctp_setsockopt_connectx_old(struct sock *sk, |
1342 | struct sockaddr __user *addrs, | 1342 | struct sockaddr __user *addrs, |
1343 | int addrs_size) | 1343 | int addrs_size) |
1344 | { | 1344 | { |
@@ -1351,7 +1351,7 @@ static int sctp_setsockopt_connectx_old(struct sock* sk, | |||
1351 | * indication to the call. Error is always negative and association id is | 1351 | * indication to the call. Error is always negative and association id is |
1352 | * always positive. | 1352 | * always positive. |
1353 | */ | 1353 | */ |
1354 | static int sctp_setsockopt_connectx(struct sock* sk, | 1354 | static int sctp_setsockopt_connectx(struct sock *sk, |
1355 | struct sockaddr __user *addrs, | 1355 | struct sockaddr __user *addrs, |
1356 | int addrs_size) | 1356 | int addrs_size) |
1357 | { | 1357 | { |
@@ -1369,12 +1369,20 @@ static int sctp_setsockopt_connectx(struct sock* sk, | |||
1369 | /* | 1369 | /* |
1370 | * New (hopefully final) interface for the API. | 1370 | * New (hopefully final) interface for the API. |
1371 | * We use the sctp_getaddrs_old structure so that use-space library | 1371 | * We use the sctp_getaddrs_old structure so that use-space library |
1372 | * can avoid any unnecessary allocations. The only defferent part | 1372 | * can avoid any unnecessary allocations. The only different part |
1373 | * is that we store the actual length of the address buffer into the | 1373 | * is that we store the actual length of the address buffer into the |
1374 | * addrs_num structure member. That way we can re-use the existing | 1374 | * addrs_num structure member. That way we can re-use the existing |
1375 | * code. | 1375 | * code. |
1376 | */ | 1376 | */ |
1377 | static int sctp_getsockopt_connectx3(struct sock* sk, int len, | 1377 | #ifdef CONFIG_COMPAT |
1378 | struct compat_sctp_getaddrs_old { | ||
1379 | sctp_assoc_t assoc_id; | ||
1380 | s32 addr_num; | ||
1381 | compat_uptr_t addrs; /* struct sockaddr * */ | ||
1382 | }; | ||
1383 | #endif | ||
1384 | |||
1385 | static int sctp_getsockopt_connectx3(struct sock *sk, int len, | ||
1378 | char __user *optval, | 1386 | char __user *optval, |
1379 | int __user *optlen) | 1387 | int __user *optlen) |
1380 | { | 1388 | { |
@@ -1382,16 +1390,30 @@ static int sctp_getsockopt_connectx3(struct sock* sk, int len, | |||
1382 | sctp_assoc_t assoc_id = 0; | 1390 | sctp_assoc_t assoc_id = 0; |
1383 | int err = 0; | 1391 | int err = 0; |
1384 | 1392 | ||
1385 | if (len < sizeof(param)) | 1393 | #ifdef CONFIG_COMPAT |
1386 | return -EINVAL; | 1394 | if (is_compat_task()) { |
1395 | struct compat_sctp_getaddrs_old param32; | ||
1387 | 1396 | ||
1388 | if (copy_from_user(¶m, optval, sizeof(param))) | 1397 | if (len < sizeof(param32)) |
1389 | return -EFAULT; | 1398 | return -EINVAL; |
1399 | if (copy_from_user(¶m32, optval, sizeof(param32))) | ||
1400 | return -EFAULT; | ||
1390 | 1401 | ||
1391 | err = __sctp_setsockopt_connectx(sk, | 1402 | param.assoc_id = param32.assoc_id; |
1392 | (struct sockaddr __user *)param.addrs, | 1403 | param.addr_num = param32.addr_num; |
1393 | param.addr_num, &assoc_id); | 1404 | param.addrs = compat_ptr(param32.addrs); |
1405 | } else | ||
1406 | #endif | ||
1407 | { | ||
1408 | if (len < sizeof(param)) | ||
1409 | return -EINVAL; | ||
1410 | if (copy_from_user(¶m, optval, sizeof(param))) | ||
1411 | return -EFAULT; | ||
1412 | } | ||
1394 | 1413 | ||
1414 | err = __sctp_setsockopt_connectx(sk, (struct sockaddr __user *) | ||
1415 | param.addrs, param.addr_num, | ||
1416 | &assoc_id); | ||
1395 | if (err == 0 || err == -EINPROGRESS) { | 1417 | if (err == 0 || err == -EINPROGRESS) { |
1396 | if (copy_to_user(optval, &assoc_id, sizeof(assoc_id))) | 1418 | if (copy_to_user(optval, &assoc_id, sizeof(assoc_id))) |
1397 | return -EFAULT; | 1419 | return -EFAULT; |
@@ -1462,7 +1484,7 @@ static void sctp_close(struct sock *sk, long timeout) | |||
1462 | 1484 | ||
1463 | pr_debug("%s: sk:%p, timeout:%ld\n", __func__, sk, timeout); | 1485 | pr_debug("%s: sk:%p, timeout:%ld\n", __func__, sk, timeout); |
1464 | 1486 | ||
1465 | sctp_lock_sock(sk); | 1487 | lock_sock(sk); |
1466 | sk->sk_shutdown = SHUTDOWN_MASK; | 1488 | sk->sk_shutdown = SHUTDOWN_MASK; |
1467 | sk->sk_state = SCTP_SS_CLOSING; | 1489 | sk->sk_state = SCTP_SS_CLOSING; |
1468 | 1490 | ||
@@ -1506,13 +1528,13 @@ static void sctp_close(struct sock *sk, long timeout) | |||
1506 | sctp_wait_for_close(sk, timeout); | 1528 | sctp_wait_for_close(sk, timeout); |
1507 | 1529 | ||
1508 | /* This will run the backlog queue. */ | 1530 | /* This will run the backlog queue. */ |
1509 | sctp_release_sock(sk); | 1531 | release_sock(sk); |
1510 | 1532 | ||
1511 | /* Supposedly, no process has access to the socket, but | 1533 | /* Supposedly, no process has access to the socket, but |
1512 | * the net layers still may. | 1534 | * the net layers still may. |
1513 | */ | 1535 | */ |
1514 | sctp_local_bh_disable(); | 1536 | local_bh_disable(); |
1515 | sctp_bh_lock_sock(sk); | 1537 | bh_lock_sock(sk); |
1516 | 1538 | ||
1517 | /* Hold the sock, since sk_common_release() will put sock_put() | 1539 | /* Hold the sock, since sk_common_release() will put sock_put() |
1518 | * and we have just a little more cleanup. | 1540 | * and we have just a little more cleanup. |
@@ -1520,8 +1542,8 @@ static void sctp_close(struct sock *sk, long timeout) | |||
1520 | sock_hold(sk); | 1542 | sock_hold(sk); |
1521 | sk_common_release(sk); | 1543 | sk_common_release(sk); |
1522 | 1544 | ||
1523 | sctp_bh_unlock_sock(sk); | 1545 | bh_unlock_sock(sk); |
1524 | sctp_local_bh_enable(); | 1546 | local_bh_enable(); |
1525 | 1547 | ||
1526 | sock_put(sk); | 1548 | sock_put(sk); |
1527 | 1549 | ||
@@ -1569,7 +1591,7 @@ static int sctp_sendmsg(struct kiocb *iocb, struct sock *sk, | |||
1569 | struct net *net = sock_net(sk); | 1591 | struct net *net = sock_net(sk); |
1570 | struct sctp_sock *sp; | 1592 | struct sctp_sock *sp; |
1571 | struct sctp_endpoint *ep; | 1593 | struct sctp_endpoint *ep; |
1572 | struct sctp_association *new_asoc=NULL, *asoc=NULL; | 1594 | struct sctp_association *new_asoc = NULL, *asoc = NULL; |
1573 | struct sctp_transport *transport, *chunk_tp; | 1595 | struct sctp_transport *transport, *chunk_tp; |
1574 | struct sctp_chunk *chunk; | 1596 | struct sctp_chunk *chunk; |
1575 | union sctp_addr to; | 1597 | union sctp_addr to; |
@@ -1666,7 +1688,7 @@ static int sctp_sendmsg(struct kiocb *iocb, struct sock *sk, | |||
1666 | 1688 | ||
1667 | pr_debug("%s: about to look up association\n", __func__); | 1689 | pr_debug("%s: about to look up association\n", __func__); |
1668 | 1690 | ||
1669 | sctp_lock_sock(sk); | 1691 | lock_sock(sk); |
1670 | 1692 | ||
1671 | /* If a msg_name has been specified, assume this is to be used. */ | 1693 | /* If a msg_name has been specified, assume this is to be used. */ |
1672 | if (msg_name) { | 1694 | if (msg_name) { |
@@ -1744,7 +1766,7 @@ static int sctp_sendmsg(struct kiocb *iocb, struct sock *sk, | |||
1744 | * either the default or the user specified stream counts. | 1766 | * either the default or the user specified stream counts. |
1745 | */ | 1767 | */ |
1746 | if (sinfo) { | 1768 | if (sinfo) { |
1747 | if (!sinit || (sinit && !sinit->sinit_num_ostreams)) { | 1769 | if (!sinit || !sinit->sinit_num_ostreams) { |
1748 | /* Check against the defaults. */ | 1770 | /* Check against the defaults. */ |
1749 | if (sinfo->sinfo_stream >= | 1771 | if (sinfo->sinfo_stream >= |
1750 | sp->initmsg.sinit_num_ostreams) { | 1772 | sp->initmsg.sinit_num_ostreams) { |
@@ -1950,7 +1972,7 @@ out_free: | |||
1950 | sctp_association_free(asoc); | 1972 | sctp_association_free(asoc); |
1951 | } | 1973 | } |
1952 | out_unlock: | 1974 | out_unlock: |
1953 | sctp_release_sock(sk); | 1975 | release_sock(sk); |
1954 | 1976 | ||
1955 | out_nounlock: | 1977 | out_nounlock: |
1956 | return sctp_error(sk, msg_flags, err); | 1978 | return sctp_error(sk, msg_flags, err); |
@@ -2036,7 +2058,7 @@ static int sctp_recvmsg(struct kiocb *iocb, struct sock *sk, | |||
2036 | "addr_len:%p)\n", __func__, sk, msg, len, noblock, flags, | 2058 | "addr_len:%p)\n", __func__, sk, msg, len, noblock, flags, |
2037 | addr_len); | 2059 | addr_len); |
2038 | 2060 | ||
2039 | sctp_lock_sock(sk); | 2061 | lock_sock(sk); |
2040 | 2062 | ||
2041 | if (sctp_style(sk, TCP) && !sctp_sstate(sk, ESTABLISHED)) { | 2063 | if (sctp_style(sk, TCP) && !sctp_sstate(sk, ESTABLISHED)) { |
2042 | err = -ENOTCONN; | 2064 | err = -ENOTCONN; |
@@ -2093,12 +2115,6 @@ static int sctp_recvmsg(struct kiocb *iocb, struct sock *sk, | |||
2093 | sctp_skb_pull(skb, copied); | 2115 | sctp_skb_pull(skb, copied); |
2094 | skb_queue_head(&sk->sk_receive_queue, skb); | 2116 | skb_queue_head(&sk->sk_receive_queue, skb); |
2095 | 2117 | ||
2096 | /* When only partial message is copied to the user, increase | ||
2097 | * rwnd by that amount. If all the data in the skb is read, | ||
2098 | * rwnd is updated when the event is freed. | ||
2099 | */ | ||
2100 | if (!sctp_ulpevent_is_notification(event)) | ||
2101 | sctp_assoc_rwnd_increase(event->asoc, copied); | ||
2102 | goto out; | 2118 | goto out; |
2103 | } else if ((event->msg_flags & MSG_NOTIFICATION) || | 2119 | } else if ((event->msg_flags & MSG_NOTIFICATION) || |
2104 | (event->msg_flags & MSG_EOR)) | 2120 | (event->msg_flags & MSG_EOR)) |
@@ -2120,7 +2136,7 @@ out_free: | |||
2120 | sctp_ulpevent_free(event); | 2136 | sctp_ulpevent_free(event); |
2121 | } | 2137 | } |
2122 | out: | 2138 | out: |
2123 | sctp_release_sock(sk); | 2139 | release_sock(sk); |
2124 | return err; | 2140 | return err; |
2125 | } | 2141 | } |
2126 | 2142 | ||
@@ -2463,7 +2479,7 @@ static int sctp_setsockopt_peer_addr_params(struct sock *sk, | |||
2463 | int hb_change, pmtud_change, sackdelay_change; | 2479 | int hb_change, pmtud_change, sackdelay_change; |
2464 | 2480 | ||
2465 | if (optlen != sizeof(struct sctp_paddrparams)) | 2481 | if (optlen != sizeof(struct sctp_paddrparams)) |
2466 | return - EINVAL; | 2482 | return -EINVAL; |
2467 | 2483 | ||
2468 | if (copy_from_user(¶ms, optval, optlen)) | 2484 | if (copy_from_user(¶ms, optval, optlen)) |
2469 | return -EFAULT; | 2485 | return -EFAULT; |
@@ -2484,7 +2500,7 @@ static int sctp_setsockopt_peer_addr_params(struct sock *sk, | |||
2484 | /* If an address other than INADDR_ANY is specified, and | 2500 | /* If an address other than INADDR_ANY is specified, and |
2485 | * no transport is found, then the request is invalid. | 2501 | * no transport is found, then the request is invalid. |
2486 | */ | 2502 | */ |
2487 | if (!sctp_is_any(sk, ( union sctp_addr *)¶ms.spp_address)) { | 2503 | if (!sctp_is_any(sk, (union sctp_addr *)¶ms.spp_address)) { |
2488 | trans = sctp_addr_id2transport(sk, ¶ms.spp_address, | 2504 | trans = sctp_addr_id2transport(sk, ¶ms.spp_address, |
2489 | params.spp_assoc_id); | 2505 | params.spp_assoc_id); |
2490 | if (!trans) | 2506 | if (!trans) |
@@ -2528,6 +2544,16 @@ static int sctp_setsockopt_peer_addr_params(struct sock *sk, | |||
2528 | return 0; | 2544 | return 0; |
2529 | } | 2545 | } |
2530 | 2546 | ||
2547 | static inline __u32 sctp_spp_sackdelay_enable(__u32 param_flags) | ||
2548 | { | ||
2549 | return (param_flags & ~SPP_SACKDELAY) | SPP_SACKDELAY_ENABLE; | ||
2550 | } | ||
2551 | |||
2552 | static inline __u32 sctp_spp_sackdelay_disable(__u32 param_flags) | ||
2553 | { | ||
2554 | return (param_flags & ~SPP_SACKDELAY) | SPP_SACKDELAY_DISABLE; | ||
2555 | } | ||
2556 | |||
2531 | /* | 2557 | /* |
2532 | * 7.1.23. Get or set delayed ack timer (SCTP_DELAYED_SACK) | 2558 | * 7.1.23. Get or set delayed ack timer (SCTP_DELAYED_SACK) |
2533 | * | 2559 | * |
@@ -2579,8 +2605,11 @@ static int sctp_setsockopt_delayed_ack(struct sock *sk, | |||
2579 | if (params.sack_delay == 0 && params.sack_freq == 0) | 2605 | if (params.sack_delay == 0 && params.sack_freq == 0) |
2580 | return 0; | 2606 | return 0; |
2581 | } else if (optlen == sizeof(struct sctp_assoc_value)) { | 2607 | } else if (optlen == sizeof(struct sctp_assoc_value)) { |
2582 | pr_warn("Use of struct sctp_assoc_value in delayed_ack socket option deprecated\n"); | 2608 | pr_warn_ratelimited(DEPRECATED |
2583 | pr_warn("Use struct sctp_sack_info instead\n"); | 2609 | "%s (pid %d) " |
2610 | "Use of struct sctp_assoc_value in delayed_ack socket option.\n" | ||
2611 | "Use struct sctp_sack_info instead\n", | ||
2612 | current->comm, task_pid_nr(current)); | ||
2584 | if (copy_from_user(¶ms, optval, optlen)) | 2613 | if (copy_from_user(¶ms, optval, optlen)) |
2585 | return -EFAULT; | 2614 | return -EFAULT; |
2586 | 2615 | ||
@@ -2589,7 +2618,7 @@ static int sctp_setsockopt_delayed_ack(struct sock *sk, | |||
2589 | else | 2618 | else |
2590 | params.sack_freq = 0; | 2619 | params.sack_freq = 0; |
2591 | } else | 2620 | } else |
2592 | return - EINVAL; | 2621 | return -EINVAL; |
2593 | 2622 | ||
2594 | /* Validate value parameter. */ | 2623 | /* Validate value parameter. */ |
2595 | if (params.sack_delay > 500) | 2624 | if (params.sack_delay > 500) |
@@ -2608,37 +2637,31 @@ static int sctp_setsockopt_delayed_ack(struct sock *sk, | |||
2608 | asoc->sackdelay = | 2637 | asoc->sackdelay = |
2609 | msecs_to_jiffies(params.sack_delay); | 2638 | msecs_to_jiffies(params.sack_delay); |
2610 | asoc->param_flags = | 2639 | asoc->param_flags = |
2611 | (asoc->param_flags & ~SPP_SACKDELAY) | | 2640 | sctp_spp_sackdelay_enable(asoc->param_flags); |
2612 | SPP_SACKDELAY_ENABLE; | ||
2613 | } else { | 2641 | } else { |
2614 | sp->sackdelay = params.sack_delay; | 2642 | sp->sackdelay = params.sack_delay; |
2615 | sp->param_flags = | 2643 | sp->param_flags = |
2616 | (sp->param_flags & ~SPP_SACKDELAY) | | 2644 | sctp_spp_sackdelay_enable(sp->param_flags); |
2617 | SPP_SACKDELAY_ENABLE; | ||
2618 | } | 2645 | } |
2619 | } | 2646 | } |
2620 | 2647 | ||
2621 | if (params.sack_freq == 1) { | 2648 | if (params.sack_freq == 1) { |
2622 | if (asoc) { | 2649 | if (asoc) { |
2623 | asoc->param_flags = | 2650 | asoc->param_flags = |
2624 | (asoc->param_flags & ~SPP_SACKDELAY) | | 2651 | sctp_spp_sackdelay_disable(asoc->param_flags); |
2625 | SPP_SACKDELAY_DISABLE; | ||
2626 | } else { | 2652 | } else { |
2627 | sp->param_flags = | 2653 | sp->param_flags = |
2628 | (sp->param_flags & ~SPP_SACKDELAY) | | 2654 | sctp_spp_sackdelay_disable(sp->param_flags); |
2629 | SPP_SACKDELAY_DISABLE; | ||
2630 | } | 2655 | } |
2631 | } else if (params.sack_freq > 1) { | 2656 | } else if (params.sack_freq > 1) { |
2632 | if (asoc) { | 2657 | if (asoc) { |
2633 | asoc->sackfreq = params.sack_freq; | 2658 | asoc->sackfreq = params.sack_freq; |
2634 | asoc->param_flags = | 2659 | asoc->param_flags = |
2635 | (asoc->param_flags & ~SPP_SACKDELAY) | | 2660 | sctp_spp_sackdelay_enable(asoc->param_flags); |
2636 | SPP_SACKDELAY_ENABLE; | ||
2637 | } else { | 2661 | } else { |
2638 | sp->sackfreq = params.sack_freq; | 2662 | sp->sackfreq = params.sack_freq; |
2639 | sp->param_flags = | 2663 | sp->param_flags = |
2640 | (sp->param_flags & ~SPP_SACKDELAY) | | 2664 | sctp_spp_sackdelay_enable(sp->param_flags); |
2641 | SPP_SACKDELAY_ENABLE; | ||
2642 | } | 2665 | } |
2643 | } | 2666 | } |
2644 | 2667 | ||
@@ -2650,18 +2673,15 @@ static int sctp_setsockopt_delayed_ack(struct sock *sk, | |||
2650 | trans->sackdelay = | 2673 | trans->sackdelay = |
2651 | msecs_to_jiffies(params.sack_delay); | 2674 | msecs_to_jiffies(params.sack_delay); |
2652 | trans->param_flags = | 2675 | trans->param_flags = |
2653 | (trans->param_flags & ~SPP_SACKDELAY) | | 2676 | sctp_spp_sackdelay_enable(trans->param_flags); |
2654 | SPP_SACKDELAY_ENABLE; | ||
2655 | } | 2677 | } |
2656 | if (params.sack_freq == 1) { | 2678 | if (params.sack_freq == 1) { |
2657 | trans->param_flags = | 2679 | trans->param_flags = |
2658 | (trans->param_flags & ~SPP_SACKDELAY) | | 2680 | sctp_spp_sackdelay_disable(trans->param_flags); |
2659 | SPP_SACKDELAY_DISABLE; | ||
2660 | } else if (params.sack_freq > 1) { | 2681 | } else if (params.sack_freq > 1) { |
2661 | trans->sackfreq = params.sack_freq; | 2682 | trans->sackfreq = params.sack_freq; |
2662 | trans->param_flags = | 2683 | trans->param_flags = |
2663 | (trans->param_flags & ~SPP_SACKDELAY) | | 2684 | sctp_spp_sackdelay_enable(trans->param_flags); |
2664 | SPP_SACKDELAY_ENABLE; | ||
2665 | } | 2685 | } |
2666 | } | 2686 | } |
2667 | } | 2687 | } |
@@ -2995,8 +3015,11 @@ static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned | |||
2995 | int val; | 3015 | int val; |
2996 | 3016 | ||
2997 | if (optlen == sizeof(int)) { | 3017 | if (optlen == sizeof(int)) { |
2998 | pr_warn("Use of int in maxseg socket option deprecated\n"); | 3018 | pr_warn_ratelimited(DEPRECATED |
2999 | pr_warn("Use struct sctp_assoc_value instead\n"); | 3019 | "%s (pid %d) " |
3020 | "Use of int in maxseg socket option.\n" | ||
3021 | "Use struct sctp_assoc_value instead\n", | ||
3022 | current->comm, task_pid_nr(current)); | ||
3000 | if (copy_from_user(&val, optval, optlen)) | 3023 | if (copy_from_user(&val, optval, optlen)) |
3001 | return -EFAULT; | 3024 | return -EFAULT; |
3002 | params.assoc_id = 0; | 3025 | params.assoc_id = 0; |
@@ -3253,8 +3276,11 @@ static int sctp_setsockopt_maxburst(struct sock *sk, | |||
3253 | int assoc_id = 0; | 3276 | int assoc_id = 0; |
3254 | 3277 | ||
3255 | if (optlen == sizeof(int)) { | 3278 | if (optlen == sizeof(int)) { |
3256 | pr_warn("Use of int in max_burst socket option deprecated\n"); | 3279 | pr_warn_ratelimited(DEPRECATED |
3257 | pr_warn("Use struct sctp_assoc_value instead\n"); | 3280 | "%s (pid %d) " |
3281 | "Use of int in max_burst socket option deprecated.\n" | ||
3282 | "Use struct sctp_assoc_value instead\n", | ||
3283 | current->comm, task_pid_nr(current)); | ||
3258 | if (copy_from_user(&val, optval, optlen)) | 3284 | if (copy_from_user(&val, optval, optlen)) |
3259 | return -EFAULT; | 3285 | return -EFAULT; |
3260 | } else if (optlen == sizeof(struct sctp_assoc_value)) { | 3286 | } else if (optlen == sizeof(struct sctp_assoc_value)) { |
@@ -3333,7 +3359,7 @@ static int sctp_setsockopt_hmac_ident(struct sock *sk, | |||
3333 | if (optlen < sizeof(struct sctp_hmacalgo)) | 3359 | if (optlen < sizeof(struct sctp_hmacalgo)) |
3334 | return -EINVAL; | 3360 | return -EINVAL; |
3335 | 3361 | ||
3336 | hmacs= memdup_user(optval, optlen); | 3362 | hmacs = memdup_user(optval, optlen); |
3337 | if (IS_ERR(hmacs)) | 3363 | if (IS_ERR(hmacs)) |
3338 | return PTR_ERR(hmacs); | 3364 | return PTR_ERR(hmacs); |
3339 | 3365 | ||
@@ -3371,7 +3397,7 @@ static int sctp_setsockopt_auth_key(struct sock *sk, | |||
3371 | if (optlen <= sizeof(struct sctp_authkey)) | 3397 | if (optlen <= sizeof(struct sctp_authkey)) |
3372 | return -EINVAL; | 3398 | return -EINVAL; |
3373 | 3399 | ||
3374 | authkey= memdup_user(optval, optlen); | 3400 | authkey = memdup_user(optval, optlen); |
3375 | if (IS_ERR(authkey)) | 3401 | if (IS_ERR(authkey)) |
3376 | return PTR_ERR(authkey); | 3402 | return PTR_ERR(authkey); |
3377 | 3403 | ||
@@ -3581,7 +3607,7 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname, | |||
3581 | goto out_nounlock; | 3607 | goto out_nounlock; |
3582 | } | 3608 | } |
3583 | 3609 | ||
3584 | sctp_lock_sock(sk); | 3610 | lock_sock(sk); |
3585 | 3611 | ||
3586 | switch (optname) { | 3612 | switch (optname) { |
3587 | case SCTP_SOCKOPT_BINDX_ADD: | 3613 | case SCTP_SOCKOPT_BINDX_ADD: |
@@ -3699,7 +3725,7 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname, | |||
3699 | break; | 3725 | break; |
3700 | } | 3726 | } |
3701 | 3727 | ||
3702 | sctp_release_sock(sk); | 3728 | release_sock(sk); |
3703 | 3729 | ||
3704 | out_nounlock: | 3730 | out_nounlock: |
3705 | return retval; | 3731 | return retval; |
@@ -3727,7 +3753,7 @@ static int sctp_connect(struct sock *sk, struct sockaddr *addr, | |||
3727 | int err = 0; | 3753 | int err = 0; |
3728 | struct sctp_af *af; | 3754 | struct sctp_af *af; |
3729 | 3755 | ||
3730 | sctp_lock_sock(sk); | 3756 | lock_sock(sk); |
3731 | 3757 | ||
3732 | pr_debug("%s: sk:%p, sockaddr:%p, addr_len:%d\n", __func__, sk, | 3758 | pr_debug("%s: sk:%p, sockaddr:%p, addr_len:%d\n", __func__, sk, |
3733 | addr, addr_len); | 3759 | addr, addr_len); |
@@ -3743,7 +3769,7 @@ static int sctp_connect(struct sock *sk, struct sockaddr *addr, | |||
3743 | err = __sctp_connect(sk, addr, af->sockaddr_len, NULL); | 3769 | err = __sctp_connect(sk, addr, af->sockaddr_len, NULL); |
3744 | } | 3770 | } |
3745 | 3771 | ||
3746 | sctp_release_sock(sk); | 3772 | release_sock(sk); |
3747 | return err; | 3773 | return err; |
3748 | } | 3774 | } |
3749 | 3775 | ||
@@ -3769,7 +3795,7 @@ static struct sock *sctp_accept(struct sock *sk, int flags, int *err) | |||
3769 | long timeo; | 3795 | long timeo; |
3770 | int error = 0; | 3796 | int error = 0; |
3771 | 3797 | ||
3772 | sctp_lock_sock(sk); | 3798 | lock_sock(sk); |
3773 | 3799 | ||
3774 | sp = sctp_sk(sk); | 3800 | sp = sctp_sk(sk); |
3775 | ep = sp->ep; | 3801 | ep = sp->ep; |
@@ -3807,7 +3833,7 @@ static struct sock *sctp_accept(struct sock *sk, int flags, int *err) | |||
3807 | sctp_sock_migrate(sk, newsk, asoc, SCTP_SOCKET_TCP); | 3833 | sctp_sock_migrate(sk, newsk, asoc, SCTP_SOCKET_TCP); |
3808 | 3834 | ||
3809 | out: | 3835 | out: |
3810 | sctp_release_sock(sk); | 3836 | release_sock(sk); |
3811 | *err = error; | 3837 | *err = error; |
3812 | return newsk; | 3838 | return newsk; |
3813 | } | 3839 | } |
@@ -3817,7 +3843,7 @@ static int sctp_ioctl(struct sock *sk, int cmd, unsigned long arg) | |||
3817 | { | 3843 | { |
3818 | int rc = -ENOTCONN; | 3844 | int rc = -ENOTCONN; |
3819 | 3845 | ||
3820 | sctp_lock_sock(sk); | 3846 | lock_sock(sk); |
3821 | 3847 | ||
3822 | /* | 3848 | /* |
3823 | * SEQPACKET-style sockets in LISTENING state are valid, for | 3849 | * SEQPACKET-style sockets in LISTENING state are valid, for |
@@ -3847,7 +3873,7 @@ static int sctp_ioctl(struct sock *sk, int cmd, unsigned long arg) | |||
3847 | break; | 3873 | break; |
3848 | } | 3874 | } |
3849 | out: | 3875 | out: |
3850 | sctp_release_sock(sk); | 3876 | release_sock(sk); |
3851 | return rc; | 3877 | return rc; |
3852 | } | 3878 | } |
3853 | 3879 | ||
@@ -3925,7 +3951,7 @@ static int sctp_init_sock(struct sock *sk) | |||
3925 | */ | 3951 | */ |
3926 | sp->hbinterval = net->sctp.hb_interval; | 3952 | sp->hbinterval = net->sctp.hb_interval; |
3927 | sp->pathmaxrxt = net->sctp.max_retrans_path; | 3953 | sp->pathmaxrxt = net->sctp.max_retrans_path; |
3928 | sp->pathmtu = 0; // allow default discovery | 3954 | sp->pathmtu = 0; /* allow default discovery */ |
3929 | sp->sackdelay = net->sctp.sack_timeout; | 3955 | sp->sackdelay = net->sctp.sack_timeout; |
3930 | sp->sackfreq = 2; | 3956 | sp->sackfreq = 2; |
3931 | sp->param_flags = SPP_HB_ENABLE | | 3957 | sp->param_flags = SPP_HB_ENABLE | |
@@ -4468,7 +4494,7 @@ static int sctp_getsockopt_peer_addr_params(struct sock *sk, int len, | |||
4468 | /* If an address other than INADDR_ANY is specified, and | 4494 | /* If an address other than INADDR_ANY is specified, and |
4469 | * no transport is found, then the request is invalid. | 4495 | * no transport is found, then the request is invalid. |
4470 | */ | 4496 | */ |
4471 | if (!sctp_is_any(sk, ( union sctp_addr *)¶ms.spp_address)) { | 4497 | if (!sctp_is_any(sk, (union sctp_addr *)¶ms.spp_address)) { |
4472 | trans = sctp_addr_id2transport(sk, ¶ms.spp_address, | 4498 | trans = sctp_addr_id2transport(sk, ¶ms.spp_address, |
4473 | params.spp_assoc_id); | 4499 | params.spp_assoc_id); |
4474 | if (!trans) { | 4500 | if (!trans) { |
@@ -4574,12 +4600,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len, | |||
4574 | if (copy_from_user(¶ms, optval, len)) | 4600 | if (copy_from_user(¶ms, optval, len)) |
4575 | return -EFAULT; | 4601 | return -EFAULT; |
4576 | } else if (len == sizeof(struct sctp_assoc_value)) { | 4602 | } else if (len == sizeof(struct sctp_assoc_value)) { |
4577 | pr_warn("Use of struct sctp_assoc_value in delayed_ack socket option deprecated\n"); | 4603 | pr_warn_ratelimited(DEPRECATED |
4578 | pr_warn("Use struct sctp_sack_info instead\n"); | 4604 | "%s (pid %d) " |
4605 | "Use of struct sctp_assoc_value in delayed_ack socket option.\n" | ||
4606 | "Use struct sctp_sack_info instead\n", | ||
4607 | current->comm, task_pid_nr(current)); | ||
4579 | if (copy_from_user(¶ms, optval, len)) | 4608 | if (copy_from_user(¶ms, optval, len)) |
4580 | return -EFAULT; | 4609 | return -EFAULT; |
4581 | } else | 4610 | } else |
4582 | return - EINVAL; | 4611 | return -EINVAL; |
4583 | 4612 | ||
4584 | /* Get association, if sack_assoc_id != 0 and the socket is a one | 4613 | /* Get association, if sack_assoc_id != 0 and the socket is a one |
4585 | * to many style socket, and an association was not found, then | 4614 | * to many style socket, and an association was not found, then |
@@ -4669,8 +4698,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len, | |||
4669 | if (!asoc) | 4698 | if (!asoc) |
4670 | return -EINVAL; | 4699 | return -EINVAL; |
4671 | 4700 | ||
4672 | to = optval + offsetof(struct sctp_getaddrs,addrs); | 4701 | to = optval + offsetof(struct sctp_getaddrs, addrs); |
4673 | space_left = len - offsetof(struct sctp_getaddrs,addrs); | 4702 | space_left = len - offsetof(struct sctp_getaddrs, addrs); |
4674 | 4703 | ||
4675 | list_for_each_entry(from, &asoc->peer.transport_addr_list, | 4704 | list_for_each_entry(from, &asoc->peer.transport_addr_list, |
4676 | transports) { | 4705 | transports) { |
@@ -4730,7 +4759,7 @@ static int sctp_copy_laddrs(struct sock *sk, __u16 port, void *to, | |||
4730 | memcpy(to, &temp, addrlen); | 4759 | memcpy(to, &temp, addrlen); |
4731 | 4760 | ||
4732 | to += addrlen; | 4761 | to += addrlen; |
4733 | cnt ++; | 4762 | cnt++; |
4734 | space_left -= addrlen; | 4763 | space_left -= addrlen; |
4735 | *bytes_copied += addrlen; | 4764 | *bytes_copied += addrlen; |
4736 | } | 4765 | } |
@@ -4779,8 +4808,8 @@ static int sctp_getsockopt_local_addrs(struct sock *sk, int len, | |||
4779 | bp = &asoc->base.bind_addr; | 4808 | bp = &asoc->base.bind_addr; |
4780 | } | 4809 | } |
4781 | 4810 | ||
4782 | to = optval + offsetof(struct sctp_getaddrs,addrs); | 4811 | to = optval + offsetof(struct sctp_getaddrs, addrs); |
4783 | space_left = len - offsetof(struct sctp_getaddrs,addrs); | 4812 | space_left = len - offsetof(struct sctp_getaddrs, addrs); |
4784 | 4813 | ||
4785 | addrs = kmalloc(space_left, GFP_KERNEL); | 4814 | addrs = kmalloc(space_left, GFP_KERNEL); |
4786 | if (!addrs) | 4815 | if (!addrs) |
@@ -4819,7 +4848,7 @@ static int sctp_getsockopt_local_addrs(struct sock *sk, int len, | |||
4819 | memcpy(buf, &temp, addrlen); | 4848 | memcpy(buf, &temp, addrlen); |
4820 | buf += addrlen; | 4849 | buf += addrlen; |
4821 | bytes_copied += addrlen; | 4850 | bytes_copied += addrlen; |
4822 | cnt ++; | 4851 | cnt++; |
4823 | space_left -= addrlen; | 4852 | space_left -= addrlen; |
4824 | } | 4853 | } |
4825 | 4854 | ||
@@ -5091,7 +5120,7 @@ static int sctp_getsockopt_associnfo(struct sock *sk, int len, | |||
5091 | assocparams.sasoc_cookie_life = ktime_to_ms(asoc->cookie_life); | 5120 | assocparams.sasoc_cookie_life = ktime_to_ms(asoc->cookie_life); |
5092 | 5121 | ||
5093 | list_for_each(pos, &asoc->peer.transport_addr_list) { | 5122 | list_for_each(pos, &asoc->peer.transport_addr_list) { |
5094 | cnt ++; | 5123 | cnt++; |
5095 | } | 5124 | } |
5096 | 5125 | ||
5097 | assocparams.sasoc_number_peer_destinations = cnt; | 5126 | assocparams.sasoc_number_peer_destinations = cnt; |
@@ -5219,8 +5248,11 @@ static int sctp_getsockopt_maxseg(struct sock *sk, int len, | |||
5219 | struct sctp_association *asoc; | 5248 | struct sctp_association *asoc; |
5220 | 5249 | ||
5221 | if (len == sizeof(int)) { | 5250 | if (len == sizeof(int)) { |
5222 | pr_warn("Use of int in maxseg socket option deprecated\n"); | 5251 | pr_warn_ratelimited(DEPRECATED |
5223 | pr_warn("Use struct sctp_assoc_value instead\n"); | 5252 | "%s (pid %d) " |
5253 | "Use of int in maxseg socket option.\n" | ||
5254 | "Use struct sctp_assoc_value instead\n", | ||
5255 | current->comm, task_pid_nr(current)); | ||
5224 | params.assoc_id = 0; | 5256 | params.assoc_id = 0; |
5225 | } else if (len >= sizeof(struct sctp_assoc_value)) { | 5257 | } else if (len >= sizeof(struct sctp_assoc_value)) { |
5226 | len = sizeof(struct sctp_assoc_value); | 5258 | len = sizeof(struct sctp_assoc_value); |
@@ -5311,8 +5343,11 @@ static int sctp_getsockopt_maxburst(struct sock *sk, int len, | |||
5311 | struct sctp_association *asoc; | 5343 | struct sctp_association *asoc; |
5312 | 5344 | ||
5313 | if (len == sizeof(int)) { | 5345 | if (len == sizeof(int)) { |
5314 | pr_warn("Use of int in max_burst socket option deprecated\n"); | 5346 | pr_warn_ratelimited(DEPRECATED |
5315 | pr_warn("Use struct sctp_assoc_value instead\n"); | 5347 | "%s (pid %d) " |
5348 | "Use of int in max_burst socket option.\n" | ||
5349 | "Use struct sctp_assoc_value instead\n", | ||
5350 | current->comm, task_pid_nr(current)); | ||
5316 | params.assoc_id = 0; | 5351 | params.assoc_id = 0; |
5317 | } else if (len >= sizeof(struct sctp_assoc_value)) { | 5352 | } else if (len >= sizeof(struct sctp_assoc_value)) { |
5318 | len = sizeof(struct sctp_assoc_value); | 5353 | len = sizeof(struct sctp_assoc_value); |
@@ -5444,7 +5479,8 @@ static int sctp_getsockopt_peer_auth_chunks(struct sock *sk, int len, | |||
5444 | return -EFAULT; | 5479 | return -EFAULT; |
5445 | num: | 5480 | num: |
5446 | len = sizeof(struct sctp_authchunks) + num_chunks; | 5481 | len = sizeof(struct sctp_authchunks) + num_chunks; |
5447 | if (put_user(len, optlen)) return -EFAULT; | 5482 | if (put_user(len, optlen)) |
5483 | return -EFAULT; | ||
5448 | if (put_user(num_chunks, &p->gauth_number_of_chunks)) | 5484 | if (put_user(num_chunks, &p->gauth_number_of_chunks)) |
5449 | return -EFAULT; | 5485 | return -EFAULT; |
5450 | return 0; | 5486 | return 0; |
@@ -5476,7 +5512,7 @@ static int sctp_getsockopt_local_auth_chunks(struct sock *sk, int len, | |||
5476 | return -EINVAL; | 5512 | return -EINVAL; |
5477 | 5513 | ||
5478 | if (asoc) | 5514 | if (asoc) |
5479 | ch = (struct sctp_chunks_param*)asoc->c.auth_chunks; | 5515 | ch = (struct sctp_chunks_param *)asoc->c.auth_chunks; |
5480 | else | 5516 | else |
5481 | ch = sctp_sk(sk)->ep->auth_chunk_list; | 5517 | ch = sctp_sk(sk)->ep->auth_chunk_list; |
5482 | 5518 | ||
@@ -5735,7 +5771,7 @@ static int sctp_getsockopt(struct sock *sk, int level, int optname, | |||
5735 | if (get_user(len, optlen)) | 5771 | if (get_user(len, optlen)) |
5736 | return -EFAULT; | 5772 | return -EFAULT; |
5737 | 5773 | ||
5738 | sctp_lock_sock(sk); | 5774 | lock_sock(sk); |
5739 | 5775 | ||
5740 | switch (optname) { | 5776 | switch (optname) { |
5741 | case SCTP_STATUS: | 5777 | case SCTP_STATUS: |
@@ -5859,7 +5895,7 @@ static int sctp_getsockopt(struct sock *sk, int level, int optname, | |||
5859 | break; | 5895 | break; |
5860 | } | 5896 | } |
5861 | 5897 | ||
5862 | sctp_release_sock(sk); | 5898 | release_sock(sk); |
5863 | return retval; | 5899 | return retval; |
5864 | } | 5900 | } |
5865 | 5901 | ||
@@ -5899,7 +5935,7 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr) | |||
5899 | 5935 | ||
5900 | pr_debug("%s: begins, snum:%d\n", __func__, snum); | 5936 | pr_debug("%s: begins, snum:%d\n", __func__, snum); |
5901 | 5937 | ||
5902 | sctp_local_bh_disable(); | 5938 | local_bh_disable(); |
5903 | 5939 | ||
5904 | if (snum == 0) { | 5940 | if (snum == 0) { |
5905 | /* Search for an available port. */ | 5941 | /* Search for an available port. */ |
@@ -5908,7 +5944,7 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr) | |||
5908 | 5944 | ||
5909 | inet_get_local_port_range(sock_net(sk), &low, &high); | 5945 | inet_get_local_port_range(sock_net(sk), &low, &high); |
5910 | remaining = (high - low) + 1; | 5946 | remaining = (high - low) + 1; |
5911 | rover = net_random() % remaining + low; | 5947 | rover = prandom_u32() % remaining + low; |
5912 | 5948 | ||
5913 | do { | 5949 | do { |
5914 | rover++; | 5950 | rover++; |
@@ -5918,14 +5954,14 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr) | |||
5918 | continue; | 5954 | continue; |
5919 | index = sctp_phashfn(sock_net(sk), rover); | 5955 | index = sctp_phashfn(sock_net(sk), rover); |
5920 | head = &sctp_port_hashtable[index]; | 5956 | head = &sctp_port_hashtable[index]; |
5921 | sctp_spin_lock(&head->lock); | 5957 | spin_lock(&head->lock); |
5922 | sctp_for_each_hentry(pp, &head->chain) | 5958 | sctp_for_each_hentry(pp, &head->chain) |
5923 | if ((pp->port == rover) && | 5959 | if ((pp->port == rover) && |
5924 | net_eq(sock_net(sk), pp->net)) | 5960 | net_eq(sock_net(sk), pp->net)) |
5925 | goto next; | 5961 | goto next; |
5926 | break; | 5962 | break; |
5927 | next: | 5963 | next: |
5928 | sctp_spin_unlock(&head->lock); | 5964 | spin_unlock(&head->lock); |
5929 | } while (--remaining > 0); | 5965 | } while (--remaining > 0); |
5930 | 5966 | ||
5931 | /* Exhausted local port range during search? */ | 5967 | /* Exhausted local port range during search? */ |
@@ -5946,7 +5982,7 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr) | |||
5946 | * port iterator, pp being NULL. | 5982 | * port iterator, pp being NULL. |
5947 | */ | 5983 | */ |
5948 | head = &sctp_port_hashtable[sctp_phashfn(sock_net(sk), snum)]; | 5984 | head = &sctp_port_hashtable[sctp_phashfn(sock_net(sk), snum)]; |
5949 | sctp_spin_lock(&head->lock); | 5985 | spin_lock(&head->lock); |
5950 | sctp_for_each_hentry(pp, &head->chain) { | 5986 | sctp_for_each_hentry(pp, &head->chain) { |
5951 | if ((pp->port == snum) && net_eq(pp->net, sock_net(sk))) | 5987 | if ((pp->port == snum) && net_eq(pp->net, sock_net(sk))) |
5952 | goto pp_found; | 5988 | goto pp_found; |
@@ -6030,10 +6066,10 @@ success: | |||
6030 | ret = 0; | 6066 | ret = 0; |
6031 | 6067 | ||
6032 | fail_unlock: | 6068 | fail_unlock: |
6033 | sctp_spin_unlock(&head->lock); | 6069 | spin_unlock(&head->lock); |
6034 | 6070 | ||
6035 | fail: | 6071 | fail: |
6036 | sctp_local_bh_enable(); | 6072 | local_bh_enable(); |
6037 | return ret; | 6073 | return ret; |
6038 | } | 6074 | } |
6039 | 6075 | ||
@@ -6125,7 +6161,7 @@ int sctp_inet_listen(struct socket *sock, int backlog) | |||
6125 | if (unlikely(backlog < 0)) | 6161 | if (unlikely(backlog < 0)) |
6126 | return err; | 6162 | return err; |
6127 | 6163 | ||
6128 | sctp_lock_sock(sk); | 6164 | lock_sock(sk); |
6129 | 6165 | ||
6130 | /* Peeled-off sockets are not allowed to listen(). */ | 6166 | /* Peeled-off sockets are not allowed to listen(). */ |
6131 | if (sctp_style(sk, UDP_HIGH_BANDWIDTH)) | 6167 | if (sctp_style(sk, UDP_HIGH_BANDWIDTH)) |
@@ -6158,7 +6194,7 @@ int sctp_inet_listen(struct socket *sock, int backlog) | |||
6158 | 6194 | ||
6159 | err = 0; | 6195 | err = 0; |
6160 | out: | 6196 | out: |
6161 | sctp_release_sock(sk); | 6197 | release_sock(sk); |
6162 | return err; | 6198 | return err; |
6163 | } | 6199 | } |
6164 | 6200 | ||
@@ -6267,20 +6303,20 @@ static inline void __sctp_put_port(struct sock *sk) | |||
6267 | inet_sk(sk)->inet_num)]; | 6303 | inet_sk(sk)->inet_num)]; |
6268 | struct sctp_bind_bucket *pp; | 6304 | struct sctp_bind_bucket *pp; |
6269 | 6305 | ||
6270 | sctp_spin_lock(&head->lock); | 6306 | spin_lock(&head->lock); |
6271 | pp = sctp_sk(sk)->bind_hash; | 6307 | pp = sctp_sk(sk)->bind_hash; |
6272 | __sk_del_bind_node(sk); | 6308 | __sk_del_bind_node(sk); |
6273 | sctp_sk(sk)->bind_hash = NULL; | 6309 | sctp_sk(sk)->bind_hash = NULL; |
6274 | inet_sk(sk)->inet_num = 0; | 6310 | inet_sk(sk)->inet_num = 0; |
6275 | sctp_bucket_destroy(pp); | 6311 | sctp_bucket_destroy(pp); |
6276 | sctp_spin_unlock(&head->lock); | 6312 | spin_unlock(&head->lock); |
6277 | } | 6313 | } |
6278 | 6314 | ||
6279 | void sctp_put_port(struct sock *sk) | 6315 | void sctp_put_port(struct sock *sk) |
6280 | { | 6316 | { |
6281 | sctp_local_bh_disable(); | 6317 | local_bh_disable(); |
6282 | __sctp_put_port(sk); | 6318 | __sctp_put_port(sk); |
6283 | sctp_local_bh_enable(); | 6319 | local_bh_enable(); |
6284 | } | 6320 | } |
6285 | 6321 | ||
6286 | /* | 6322 | /* |
@@ -6418,7 +6454,7 @@ static int sctp_msghdr_parse(const struct msghdr *msg, sctp_cmsgs_t *cmsgs) | |||
6418 | * Note: This function is the same function as in core/datagram.c | 6454 | * Note: This function is the same function as in core/datagram.c |
6419 | * with a few modifications to make lksctp work. | 6455 | * with a few modifications to make lksctp work. |
6420 | */ | 6456 | */ |
6421 | static int sctp_wait_for_packet(struct sock * sk, int *err, long *timeo_p) | 6457 | static int sctp_wait_for_packet(struct sock *sk, int *err, long *timeo_p) |
6422 | { | 6458 | { |
6423 | int error; | 6459 | int error; |
6424 | DEFINE_WAIT(wait); | 6460 | DEFINE_WAIT(wait); |
@@ -6455,9 +6491,9 @@ static int sctp_wait_for_packet(struct sock * sk, int *err, long *timeo_p) | |||
6455 | * does not fit in the user's buffer, but this seems to be the | 6491 | * does not fit in the user's buffer, but this seems to be the |
6456 | * only way to honor MSG_DONTWAIT realistically. | 6492 | * only way to honor MSG_DONTWAIT realistically. |
6457 | */ | 6493 | */ |
6458 | sctp_release_sock(sk); | 6494 | release_sock(sk); |
6459 | *timeo_p = schedule_timeout(*timeo_p); | 6495 | *timeo_p = schedule_timeout(*timeo_p); |
6460 | sctp_lock_sock(sk); | 6496 | lock_sock(sk); |
6461 | 6497 | ||
6462 | ready: | 6498 | ready: |
6463 | finish_wait(sk_sleep(sk), &wait); | 6499 | finish_wait(sk_sleep(sk), &wait); |
@@ -6640,10 +6676,10 @@ static int sctp_wait_for_sndbuf(struct sctp_association *asoc, long *timeo_p, | |||
6640 | /* Let another process have a go. Since we are going | 6676 | /* Let another process have a go. Since we are going |
6641 | * to sleep anyway. | 6677 | * to sleep anyway. |
6642 | */ | 6678 | */ |
6643 | sctp_release_sock(sk); | 6679 | release_sock(sk); |
6644 | current_timeo = schedule_timeout(current_timeo); | 6680 | current_timeo = schedule_timeout(current_timeo); |
6645 | BUG_ON(sk != asoc->base.sk); | 6681 | BUG_ON(sk != asoc->base.sk); |
6646 | sctp_lock_sock(sk); | 6682 | lock_sock(sk); |
6647 | 6683 | ||
6648 | *timeo_p = current_timeo; | 6684 | *timeo_p = current_timeo; |
6649 | } | 6685 | } |
@@ -6748,9 +6784,9 @@ static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p) | |||
6748 | /* Let another process have a go. Since we are going | 6784 | /* Let another process have a go. Since we are going |
6749 | * to sleep anyway. | 6785 | * to sleep anyway. |
6750 | */ | 6786 | */ |
6751 | sctp_release_sock(sk); | 6787 | release_sock(sk); |
6752 | current_timeo = schedule_timeout(current_timeo); | 6788 | current_timeo = schedule_timeout(current_timeo); |
6753 | sctp_lock_sock(sk); | 6789 | lock_sock(sk); |
6754 | 6790 | ||
6755 | *timeo_p = current_timeo; | 6791 | *timeo_p = current_timeo; |
6756 | } | 6792 | } |
@@ -6793,9 +6829,9 @@ static int sctp_wait_for_accept(struct sock *sk, long timeo) | |||
6793 | TASK_INTERRUPTIBLE); | 6829 | TASK_INTERRUPTIBLE); |
6794 | 6830 | ||
6795 | if (list_empty(&ep->asocs)) { | 6831 | if (list_empty(&ep->asocs)) { |
6796 | sctp_release_sock(sk); | 6832 | release_sock(sk); |
6797 | timeo = schedule_timeout(timeo); | 6833 | timeo = schedule_timeout(timeo); |
6798 | sctp_lock_sock(sk); | 6834 | lock_sock(sk); |
6799 | } | 6835 | } |
6800 | 6836 | ||
6801 | err = -EINVAL; | 6837 | err = -EINVAL; |
@@ -6828,9 +6864,9 @@ static void sctp_wait_for_close(struct sock *sk, long timeout) | |||
6828 | prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); | 6864 | prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); |
6829 | if (list_empty(&sctp_sk(sk)->ep->asocs)) | 6865 | if (list_empty(&sctp_sk(sk)->ep->asocs)) |
6830 | break; | 6866 | break; |
6831 | sctp_release_sock(sk); | 6867 | release_sock(sk); |
6832 | timeout = schedule_timeout(timeout); | 6868 | timeout = schedule_timeout(timeout); |
6833 | sctp_lock_sock(sk); | 6869 | lock_sock(sk); |
6834 | } while (!signal_pending(current) && timeout); | 6870 | } while (!signal_pending(current) && timeout); |
6835 | 6871 | ||
6836 | finish_wait(sk_sleep(sk), &wait); | 6872 | finish_wait(sk_sleep(sk), &wait); |
@@ -6931,14 +6967,14 @@ static void sctp_sock_migrate(struct sock *oldsk, struct sock *newsk, | |||
6931 | /* Hook this new socket in to the bind_hash list. */ | 6967 | /* Hook this new socket in to the bind_hash list. */ |
6932 | head = &sctp_port_hashtable[sctp_phashfn(sock_net(oldsk), | 6968 | head = &sctp_port_hashtable[sctp_phashfn(sock_net(oldsk), |
6933 | inet_sk(oldsk)->inet_num)]; | 6969 | inet_sk(oldsk)->inet_num)]; |
6934 | sctp_local_bh_disable(); | 6970 | local_bh_disable(); |
6935 | sctp_spin_lock(&head->lock); | 6971 | spin_lock(&head->lock); |
6936 | pp = sctp_sk(oldsk)->bind_hash; | 6972 | pp = sctp_sk(oldsk)->bind_hash; |
6937 | sk_add_bind_node(newsk, &pp->owner); | 6973 | sk_add_bind_node(newsk, &pp->owner); |
6938 | sctp_sk(newsk)->bind_hash = pp; | 6974 | sctp_sk(newsk)->bind_hash = pp; |
6939 | inet_sk(newsk)->inet_num = inet_sk(oldsk)->inet_num; | 6975 | inet_sk(newsk)->inet_num = inet_sk(oldsk)->inet_num; |
6940 | sctp_spin_unlock(&head->lock); | 6976 | spin_unlock(&head->lock); |
6941 | sctp_local_bh_enable(); | 6977 | local_bh_enable(); |
6942 | 6978 | ||
6943 | /* Copy the bind_addr list from the original endpoint to the new | 6979 | /* Copy the bind_addr list from the original endpoint to the new |
6944 | * endpoint so that we can handle restarts properly | 6980 | * endpoint so that we can handle restarts properly |
@@ -7027,7 +7063,7 @@ static void sctp_sock_migrate(struct sock *oldsk, struct sock *newsk, | |||
7027 | newsk->sk_shutdown |= RCV_SHUTDOWN; | 7063 | newsk->sk_shutdown |= RCV_SHUTDOWN; |
7028 | 7064 | ||
7029 | newsk->sk_state = SCTP_SS_ESTABLISHED; | 7065 | newsk->sk_state = SCTP_SS_ESTABLISHED; |
7030 | sctp_release_sock(newsk); | 7066 | release_sock(newsk); |
7031 | } | 7067 | } |
7032 | 7068 | ||
7033 | 7069 | ||