socket.c (da86748bf60068e0d6ad56e5c919ca7e6782c4ba) socket.c (05364ca03cfd419caecb292fede20eb39667eaae)
1/* SCTP kernel implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001-2003 Intel Corp.
6 * Copyright (c) 2001-2002 Nokia, Inc.
7 * Copyright (c) 2001 La Monte H.P. Yarroll
8 *

--- 52 unchanged lines hidden (view full) ---

61#include <linux/ip.h>
62#include <linux/capability.h>
63#include <linux/fcntl.h>
64#include <linux/poll.h>
65#include <linux/init.h>
66#include <linux/slab.h>
67#include <linux/file.h>
68#include <linux/compat.h>
1/* SCTP kernel implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001-2003 Intel Corp.
6 * Copyright (c) 2001-2002 Nokia, Inc.
7 * Copyright (c) 2001 La Monte H.P. Yarroll
8 *

--- 52 unchanged lines hidden (view full) ---

61#include <linux/ip.h>
62#include <linux/capability.h>
63#include <linux/fcntl.h>
64#include <linux/poll.h>
65#include <linux/init.h>
66#include <linux/slab.h>
67#include <linux/file.h>
68#include <linux/compat.h>
69#include <linux/rhashtable.h>
69
70#include <net/ip.h>
71#include <net/icmp.h>
72#include <net/route.h>
73#include <net/ipv6.h>
74#include <net/inet_common.h>
75#include <net/busy_poll.h>
76

--- 1614 unchanged lines hidden (view full) ---

1691 union sctp_addr *daddr,
1692 struct sctp_transport **tp)
1693{
1694 struct sctp_endpoint *ep = sctp_sk(sk)->ep;
1695 struct net *net = sock_net(sk);
1696 struct sctp_association *asoc;
1697 enum sctp_scope scope;
1698 struct cmsghdr *cmsg;
70
71#include <net/ip.h>
72#include <net/icmp.h>
73#include <net/route.h>
74#include <net/ipv6.h>
75#include <net/inet_common.h>
76#include <net/busy_poll.h>
77

--- 1614 unchanged lines hidden (view full) ---

1692 union sctp_addr *daddr,
1693 struct sctp_transport **tp)
1694{
1695 struct sctp_endpoint *ep = sctp_sk(sk)->ep;
1696 struct net *net = sock_net(sk);
1697 struct sctp_association *asoc;
1698 enum sctp_scope scope;
1699 struct cmsghdr *cmsg;
1700 __be32 flowinfo = 0;
1699 struct sctp_af *af;
1700 int err;
1701
1702 *tp = NULL;
1703
1704 if (sflags & (SCTP_EOF | SCTP_ABORT))
1705 return -EINVAL;
1706

--- 68 unchanged lines hidden (view full) ---

1775 if (!*tp) {
1776 err = -ENOMEM;
1777 goto free;
1778 }
1779
1780 if (!cmsgs->addrs_msg)
1781 return 0;
1782
1701 struct sctp_af *af;
1702 int err;
1703
1704 *tp = NULL;
1705
1706 if (sflags & (SCTP_EOF | SCTP_ABORT))
1707 return -EINVAL;
1708

--- 68 unchanged lines hidden (view full) ---

1777 if (!*tp) {
1778 err = -ENOMEM;
1779 goto free;
1780 }
1781
1782 if (!cmsgs->addrs_msg)
1783 return 0;
1784
1785 if (daddr->sa.sa_family == AF_INET6)
1786 flowinfo = daddr->v6.sin6_flowinfo;
1787
1783 /* sendv addr list parse */
1784 for_each_cmsghdr(cmsg, cmsgs->addrs_msg) {
1785 struct sctp_transport *transport;
1786 struct sctp_association *old;
1787 union sctp_addr _daddr;
1788 int dlen;
1789
1790 if (cmsg->cmsg_level != IPPROTO_SCTP ||

--- 16 unchanged lines hidden (view full) ---

1807 memcpy(&daddr->v4.sin_addr, CMSG_DATA(cmsg), dlen);
1808 } else {
1809 if (dlen < sizeof(struct in6_addr)) {
1810 err = -EINVAL;
1811 goto free;
1812 }
1813
1814 dlen = sizeof(struct in6_addr);
1788 /* sendv addr list parse */
1789 for_each_cmsghdr(cmsg, cmsgs->addrs_msg) {
1790 struct sctp_transport *transport;
1791 struct sctp_association *old;
1792 union sctp_addr _daddr;
1793 int dlen;
1794
1795 if (cmsg->cmsg_level != IPPROTO_SCTP ||

--- 16 unchanged lines hidden (view full) ---

1812 memcpy(&daddr->v4.sin_addr, CMSG_DATA(cmsg), dlen);
1813 } else {
1814 if (dlen < sizeof(struct in6_addr)) {
1815 err = -EINVAL;
1816 goto free;
1817 }
1818
1819 dlen = sizeof(struct in6_addr);
1820 daddr->v6.sin6_flowinfo = flowinfo;
1815 daddr->v6.sin6_family = AF_INET6;
1816 daddr->v6.sin6_port = htons(asoc->peer.port);
1817 memcpy(&daddr->v6.sin6_addr, CMSG_DATA(cmsg), dlen);
1818 }
1819 err = sctp_verify_addr(sk, daddr, sizeof(*daddr));
1820 if (err)
1821 goto free;
1822

--- 77 unchanged lines hidden (view full) ---

1900 long timeo;
1901 int err;
1902
1903 if (sinfo->sinfo_stream >= asoc->stream.outcnt) {
1904 err = -EINVAL;
1905 goto err;
1906 }
1907
1821 daddr->v6.sin6_family = AF_INET6;
1822 daddr->v6.sin6_port = htons(asoc->peer.port);
1823 memcpy(&daddr->v6.sin6_addr, CMSG_DATA(cmsg), dlen);
1824 }
1825 err = sctp_verify_addr(sk, daddr, sizeof(*daddr));
1826 if (err)
1827 goto free;
1828

--- 77 unchanged lines hidden (view full) ---

1906 long timeo;
1907 int err;
1908
1909 if (sinfo->sinfo_stream >= asoc->stream.outcnt) {
1910 err = -EINVAL;
1911 goto err;
1912 }
1913
1908 if (unlikely(!asoc->stream.out[sinfo->sinfo_stream].ext)) {
1914 if (unlikely(!SCTP_SO(&asoc->stream, sinfo->sinfo_stream)->ext)) {
1909 err = sctp_stream_init_ext(&asoc->stream, sinfo->sinfo_stream);
1910 if (err)
1911 goto err;
1912 }
1913
1914 if (sp->disable_fragments && msg_len > asoc->frag_point) {
1915 err = -EMSGSIZE;
1916 goto err;

--- 470 unchanged lines hidden (view full) ---

2387 * struct sctp_paddrparams {
2388 * sctp_assoc_t spp_assoc_id;
2389 * struct sockaddr_storage spp_address;
2390 * uint32_t spp_hbinterval;
2391 * uint16_t spp_pathmaxrxt;
2392 * uint32_t spp_pathmtu;
2393 * uint32_t spp_sackdelay;
2394 * uint32_t spp_flags;
1915 err = sctp_stream_init_ext(&asoc->stream, sinfo->sinfo_stream);
1916 if (err)
1917 goto err;
1918 }
1919
1920 if (sp->disable_fragments && msg_len > asoc->frag_point) {
1921 err = -EMSGSIZE;
1922 goto err;

--- 470 unchanged lines hidden (view full) ---

2393 * struct sctp_paddrparams {
2394 * sctp_assoc_t spp_assoc_id;
2395 * struct sockaddr_storage spp_address;
2396 * uint32_t spp_hbinterval;
2397 * uint16_t spp_pathmaxrxt;
2398 * uint32_t spp_pathmtu;
2399 * uint32_t spp_sackdelay;
2400 * uint32_t spp_flags;
2401 * uint32_t spp_ipv6_flowlabel;
2402 * uint8_t spp_dscp;
2395 * };
2396 *
2397 * spp_assoc_id - (one-to-many style socket) This is filled in the
2398 * application, and identifies the association for
2399 * this query.
2400 * spp_address - This specifies which address is of interest.
2401 * spp_hbinterval - This contains the value of the heartbeat interval,
2402 * in milliseconds. If a value of zero

--- 63 unchanged lines hidden (view full) ---

2466 * enable delayed sack and take on the sack delay
2467 * value specified in spp_sackdelay.
2468 * SPP_SACKDELAY_DISABLE - Setting this flag turns
2469 * off delayed sack. If the spp_address field is blank then
2470 * delayed sack is disabled for the entire association. Note
2471 * also that this field is mutually exclusive to
2472 * SPP_SACKDELAY_ENABLE, setting both will have undefined
2473 * results.
2403 * };
2404 *
2405 * spp_assoc_id - (one-to-many style socket) This is filled in the
2406 * application, and identifies the association for
2407 * this query.
2408 * spp_address - This specifies which address is of interest.
2409 * spp_hbinterval - This contains the value of the heartbeat interval,
2410 * in milliseconds. If a value of zero

--- 63 unchanged lines hidden (view full) ---

2474 * enable delayed sack and take on the sack delay
2475 * value specified in spp_sackdelay.
2476 * SPP_SACKDELAY_DISABLE - Setting this flag turns
2477 * off delayed sack. If the spp_address field is blank then
2478 * delayed sack is disabled for the entire association. Note
2479 * also that this field is mutually exclusive to
2480 * SPP_SACKDELAY_ENABLE, setting both will have undefined
2481 * results.
2482 *
2483 * SPP_IPV6_FLOWLABEL: Setting this flag enables the
2484 * setting of the IPV6 flow label value. The value is
2485 * contained in the spp_ipv6_flowlabel field.
2486 * Upon retrieval, this flag will be set to indicate that
2487 * the spp_ipv6_flowlabel field has a valid value returned.
2488 * If a specific destination address is set (in the
2489 * spp_address field), then the value returned is that of
2490 * the address. If just an association is specified (and
2491 * no address), then the association's default flow label
2492 * is returned. If neither an association nor a destination
2493 * is specified, then the socket's default flow label is
2494 * returned. For non-IPv6 sockets, this flag will be left
2495 * cleared.
2496 *
2497 * SPP_DSCP: Setting this flag enables the setting of the
2498 * Differentiated Services Code Point (DSCP) value
2499 * associated with either the association or a specific
2500 * address. The value is obtained in the spp_dscp field.
2501 * Upon retrieval, this flag will be set to indicate that
2502 * the spp_dscp field has a valid value returned. If a
2503 * specific destination address is set when called (in the
2504 * spp_address field), then that specific destination
2505 * address's DSCP value is returned. If just an association
2506 * is specified, then the association's default DSCP is
2507 * returned. If neither an association nor a destination is
2508 * specified, then the socket's default DSCP is returned.
2509 *
2510 * spp_ipv6_flowlabel
2511 * - This field is used in conjunction with the
2512 * SPP_IPV6_FLOWLABEL flag and contains the IPv6 flow label.
2513 * The 20 least significant bits are used for the flow
2514 * label. This setting has precedence over any IPv6-layer
2515 * setting.
2516 *
2517 * spp_dscp - This field is used in conjunction with the SPP_DSCP flag
2518 * and contains the DSCP. The 6 most significant bits are
2519 * used for the DSCP. This setting has precedence over any
2520 * IPv4- or IPv6- layer setting.
2474 */
2475static int sctp_apply_peer_addr_params(struct sctp_paddrparams *params,
2476 struct sctp_transport *trans,
2477 struct sctp_association *asoc,
2478 struct sctp_sock *sp,
2479 int hb_change,
2480 int pmtud_change,
2481 int sackdelay_change)

--- 123 unchanged lines hidden (view full) ---

2605 trans->pathmaxrxt = params->spp_pathmaxrxt;
2606 } else if (asoc) {
2607 asoc->pathmaxrxt = params->spp_pathmaxrxt;
2608 } else {
2609 sp->pathmaxrxt = params->spp_pathmaxrxt;
2610 }
2611 }
2612
2521 */
2522static int sctp_apply_peer_addr_params(struct sctp_paddrparams *params,
2523 struct sctp_transport *trans,
2524 struct sctp_association *asoc,
2525 struct sctp_sock *sp,
2526 int hb_change,
2527 int pmtud_change,
2528 int sackdelay_change)

--- 123 unchanged lines hidden (view full) ---

2652 trans->pathmaxrxt = params->spp_pathmaxrxt;
2653 } else if (asoc) {
2654 asoc->pathmaxrxt = params->spp_pathmaxrxt;
2655 } else {
2656 sp->pathmaxrxt = params->spp_pathmaxrxt;
2657 }
2658 }
2659
2660 if (params->spp_flags & SPP_IPV6_FLOWLABEL) {
2661 if (trans && trans->ipaddr.sa.sa_family == AF_INET6) {
2662 trans->flowlabel = params->spp_ipv6_flowlabel &
2663 SCTP_FLOWLABEL_VAL_MASK;
2664 trans->flowlabel |= SCTP_FLOWLABEL_SET_MASK;
2665 } else if (asoc) {
2666 list_for_each_entry(trans,
2667 &asoc->peer.transport_addr_list,
2668 transports) {
2669 if (trans->ipaddr.sa.sa_family != AF_INET6)
2670 continue;
2671 trans->flowlabel = params->spp_ipv6_flowlabel &
2672 SCTP_FLOWLABEL_VAL_MASK;
2673 trans->flowlabel |= SCTP_FLOWLABEL_SET_MASK;
2674 }
2675 asoc->flowlabel = params->spp_ipv6_flowlabel &
2676 SCTP_FLOWLABEL_VAL_MASK;
2677 asoc->flowlabel |= SCTP_FLOWLABEL_SET_MASK;
2678 } else if (sctp_opt2sk(sp)->sk_family == AF_INET6) {
2679 sp->flowlabel = params->spp_ipv6_flowlabel &
2680 SCTP_FLOWLABEL_VAL_MASK;
2681 sp->flowlabel |= SCTP_FLOWLABEL_SET_MASK;
2682 }
2683 }
2684
2685 if (params->spp_flags & SPP_DSCP) {
2686 if (trans) {
2687 trans->dscp = params->spp_dscp & SCTP_DSCP_VAL_MASK;
2688 trans->dscp |= SCTP_DSCP_SET_MASK;
2689 } else if (asoc) {
2690 list_for_each_entry(trans,
2691 &asoc->peer.transport_addr_list,
2692 transports) {
2693 trans->dscp = params->spp_dscp &
2694 SCTP_DSCP_VAL_MASK;
2695 trans->dscp |= SCTP_DSCP_SET_MASK;
2696 }
2697 asoc->dscp = params->spp_dscp & SCTP_DSCP_VAL_MASK;
2698 asoc->dscp |= SCTP_DSCP_SET_MASK;
2699 } else {
2700 sp->dscp = params->spp_dscp & SCTP_DSCP_VAL_MASK;
2701 sp->dscp |= SCTP_DSCP_SET_MASK;
2702 }
2703 }
2704
2613 return 0;
2614}
2615
2616static int sctp_setsockopt_peer_addr_params(struct sock *sk,
2617 char __user *optval,
2618 unsigned int optlen)
2619{
2620 struct sctp_paddrparams params;
2621 struct sctp_transport *trans = NULL;
2622 struct sctp_association *asoc = NULL;
2623 struct sctp_sock *sp = sctp_sk(sk);
2624 int error;
2625 int hb_change, pmtud_change, sackdelay_change;
2626
2705 return 0;
2706}
2707
2708static int sctp_setsockopt_peer_addr_params(struct sock *sk,
2709 char __user *optval,
2710 unsigned int optlen)
2711{
2712 struct sctp_paddrparams params;
2713 struct sctp_transport *trans = NULL;
2714 struct sctp_association *asoc = NULL;
2715 struct sctp_sock *sp = sctp_sk(sk);
2716 int error;
2717 int hb_change, pmtud_change, sackdelay_change;
2718
2627 if (optlen != sizeof(struct sctp_paddrparams))
2719 if (optlen == sizeof(params)) {
2720 if (copy_from_user(&params, optval, optlen))
2721 return -EFAULT;
2722 } else if (optlen == ALIGN(offsetof(struct sctp_paddrparams,
2723 spp_ipv6_flowlabel), 4)) {
2724 if (copy_from_user(&params, optval, optlen))
2725 return -EFAULT;
2726 if (params.spp_flags & (SPP_DSCP | SPP_IPV6_FLOWLABEL))
2727 return -EINVAL;
2728 } else {
2628 return -EINVAL;
2729 return -EINVAL;
2730 }
2629
2731
2630 if (copy_from_user(&params, optval, optlen))
2631 return -EFAULT;
2632
2633 /* Validate flags and value parameters. */
2634 hb_change = params.spp_flags & SPP_HB;
2635 pmtud_change = params.spp_flags & SPP_PMTUD;
2636 sackdelay_change = params.spp_flags & SPP_SACKDELAY;
2637
2638 if (hb_change == SPP_HB ||
2639 pmtud_change == SPP_PMTUD ||
2640 sackdelay_change == SPP_SACKDELAY ||

--- 1523 unchanged lines hidden (view full) ---

4164 sp->strm_interleave = !!params.assoc_value;
4165
4166 retval = 0;
4167
4168out:
4169 return retval;
4170}
4171
2732 /* Validate flags and value parameters. */
2733 hb_change = params.spp_flags & SPP_HB;
2734 pmtud_change = params.spp_flags & SPP_PMTUD;
2735 sackdelay_change = params.spp_flags & SPP_SACKDELAY;
2736
2737 if (hb_change == SPP_HB ||
2738 pmtud_change == SPP_PMTUD ||
2739 sackdelay_change == SPP_SACKDELAY ||

--- 1523 unchanged lines hidden (view full) ---

4263 sp->strm_interleave = !!params.assoc_value;
4264
4265 retval = 0;
4266
4267out:
4268 return retval;
4269}
4270
4271static int sctp_setsockopt_reuse_port(struct sock *sk, char __user *optval,
4272 unsigned int optlen)
4273{
4274 int val;
4275
4276 if (!sctp_style(sk, TCP))
4277 return -EOPNOTSUPP;
4278
4279 if (sctp_sk(sk)->ep->base.bind_addr.port)
4280 return -EFAULT;
4281
4282 if (optlen < sizeof(int))
4283 return -EINVAL;
4284
4285 if (get_user(val, (int __user *)optval))
4286 return -EFAULT;
4287
4288 sctp_sk(sk)->reuse = !!val;
4289
4290 return 0;
4291}
4292
4172/* API 6.2 setsockopt(), getsockopt()
4173 *
4174 * Applications use setsockopt() and getsockopt() to set or retrieve
4175 * socket options. Socket options are used to change the default
4176 * behavior of sockets calls. They are described in Section 7.
4177 *
4178 * The syntax is:
4179 *

--- 178 unchanged lines hidden (view full) ---

4358 break;
4359 case SCTP_STREAM_SCHEDULER_VALUE:
4360 retval = sctp_setsockopt_scheduler_value(sk, optval, optlen);
4361 break;
4362 case SCTP_INTERLEAVING_SUPPORTED:
4363 retval = sctp_setsockopt_interleaving_supported(sk, optval,
4364 optlen);
4365 break;
4293/* API 6.2 setsockopt(), getsockopt()
4294 *
4295 * Applications use setsockopt() and getsockopt() to set or retrieve
4296 * socket options. Socket options are used to change the default
4297 * behavior of sockets calls. They are described in Section 7.
4298 *
4299 * The syntax is:
4300 *

--- 178 unchanged lines hidden (view full) ---

4479 break;
4480 case SCTP_STREAM_SCHEDULER_VALUE:
4481 retval = sctp_setsockopt_scheduler_value(sk, optval, optlen);
4482 break;
4483 case SCTP_INTERLEAVING_SUPPORTED:
4484 retval = sctp_setsockopt_interleaving_supported(sk, optval,
4485 optlen);
4486 break;
4487 case SCTP_REUSE_PORT:
4488 retval = sctp_setsockopt_reuse_port(sk, optval, optlen);
4489 break;
4366 default:
4367 retval = -ENOPROTOOPT;
4368 break;
4369 }
4370
4371 release_sock(sk);
4372
4373out_nounlock:

--- 1048 unchanged lines hidden (view full) ---

5422 * enable delayed sack and take on the sack delay
5423 * value specified in spp_sackdelay.
5424 * SPP_SACKDELAY_DISABLE - Setting this flag turns
5425 * off delayed sack. If the spp_address field is blank then
5426 * delayed sack is disabled for the entire association. Note
5427 * also that this field is mutually exclusive to
5428 * SPP_SACKDELAY_ENABLE, setting both will have undefined
5429 * results.
4490 default:
4491 retval = -ENOPROTOOPT;
4492 break;
4493 }
4494
4495 release_sock(sk);
4496
4497out_nounlock:

--- 1048 unchanged lines hidden (view full) ---

5546 * enable delayed sack and take on the sack delay
5547 * value specified in spp_sackdelay.
5548 * SPP_SACKDELAY_DISABLE - Setting this flag turns
5549 * off delayed sack. If the spp_address field is blank then
5550 * delayed sack is disabled for the entire association. Note
5551 * also that this field is mutually exclusive to
5552 * SPP_SACKDELAY_ENABLE, setting both will have undefined
5553 * results.
5554 *
5555 * SPP_IPV6_FLOWLABEL: Setting this flag enables the
5556 * setting of the IPV6 flow label value. The value is
5557 * contained in the spp_ipv6_flowlabel field.
5558 * Upon retrieval, this flag will be set to indicate that
5559 * the spp_ipv6_flowlabel field has a valid value returned.
5560 * If a specific destination address is set (in the
5561 * spp_address field), then the value returned is that of
5562 * the address. If just an association is specified (and
5563 * no address), then the association's default flow label
5564 * is returned. If neither an association nor a destination
5565 * is specified, then the socket's default flow label is
5566 * returned. For non-IPv6 sockets, this flag will be left
5567 * cleared.
5568 *
5569 * SPP_DSCP: Setting this flag enables the setting of the
5570 * Differentiated Services Code Point (DSCP) value
5571 * associated with either the association or a specific
5572 * address. The value is obtained in the spp_dscp field.
5573 * Upon retrieval, this flag will be set to indicate that
5574 * the spp_dscp field has a valid value returned. If a
5575 * specific destination address is set when called (in the
5576 * spp_address field), then that specific destination
5577 * address's DSCP value is returned. If just an association
5578 * is specified, then the association's default DSCP is
5579 * returned. If neither an association nor a destination is
5580 * specified, then the socket's default DSCP is returned.
5581 *
5582 * spp_ipv6_flowlabel
5583 * - This field is used in conjunction with the
5584 * SPP_IPV6_FLOWLABEL flag and contains the IPv6 flow label.
5585 * The 20 least significant bits are used for the flow
5586 * label. This setting has precedence over any IPv6-layer
5587 * setting.
5588 *
5589 * spp_dscp - This field is used in conjunction with the SPP_DSCP flag
5590 * and contains the DSCP. The 6 most significant bits are
5591 * used for the DSCP. This setting has precedence over any
5592 * IPv4- or IPv6- layer setting.
5430 */
5431static int sctp_getsockopt_peer_addr_params(struct sock *sk, int len,
5432 char __user *optval, int __user *optlen)
5433{
5434 struct sctp_paddrparams params;
5435 struct sctp_transport *trans = NULL;
5436 struct sctp_association *asoc = NULL;
5437 struct sctp_sock *sp = sctp_sk(sk);
5438
5593 */
5594static int sctp_getsockopt_peer_addr_params(struct sock *sk, int len,
5595 char __user *optval, int __user *optlen)
5596{
5597 struct sctp_paddrparams params;
5598 struct sctp_transport *trans = NULL;
5599 struct sctp_association *asoc = NULL;
5600 struct sctp_sock *sp = sctp_sk(sk);
5601
5439 if (len < sizeof(struct sctp_paddrparams))
5602 if (len >= sizeof(params))
5603 len = sizeof(params);
5604 else if (len >= ALIGN(offsetof(struct sctp_paddrparams,
5605 spp_ipv6_flowlabel), 4))
5606 len = ALIGN(offsetof(struct sctp_paddrparams,
5607 spp_ipv6_flowlabel), 4);
5608 else
5440 return -EINVAL;
5609 return -EINVAL;
5441 len = sizeof(struct sctp_paddrparams);
5610
5442 if (copy_from_user(&params, optval, len))
5443 return -EFAULT;
5444
5445 /* If an address other than INADDR_ANY is specified, and
5446 * no transport is found, then the request is invalid.
5447 */
5448 if (!sctp_is_any(sk, (union sctp_addr *)&params.spp_address)) {
5449 trans = sctp_addr_id2transport(sk, &params.spp_address,

--- 18 unchanged lines hidden (view full) ---

5468 /* Fetch transport values. */
5469 params.spp_hbinterval = jiffies_to_msecs(trans->hbinterval);
5470 params.spp_pathmtu = trans->pathmtu;
5471 params.spp_pathmaxrxt = trans->pathmaxrxt;
5472 params.spp_sackdelay = jiffies_to_msecs(trans->sackdelay);
5473
5474 /*draft-11 doesn't say what to return in spp_flags*/
5475 params.spp_flags = trans->param_flags;
5611 if (copy_from_user(&params, optval, len))
5612 return -EFAULT;
5613
5614 /* If an address other than INADDR_ANY is specified, and
5615 * no transport is found, then the request is invalid.
5616 */
5617 if (!sctp_is_any(sk, (union sctp_addr *)&params.spp_address)) {
5618 trans = sctp_addr_id2transport(sk, &params.spp_address,

--- 18 unchanged lines hidden (view full) ---

5637 /* Fetch transport values. */
5638 params.spp_hbinterval = jiffies_to_msecs(trans->hbinterval);
5639 params.spp_pathmtu = trans->pathmtu;
5640 params.spp_pathmaxrxt = trans->pathmaxrxt;
5641 params.spp_sackdelay = jiffies_to_msecs(trans->sackdelay);
5642
5643 /*draft-11 doesn't say what to return in spp_flags*/
5644 params.spp_flags = trans->param_flags;
5645 if (trans->flowlabel & SCTP_FLOWLABEL_SET_MASK) {
5646 params.spp_ipv6_flowlabel = trans->flowlabel &
5647 SCTP_FLOWLABEL_VAL_MASK;
5648 params.spp_flags |= SPP_IPV6_FLOWLABEL;
5649 }
5650 if (trans->dscp & SCTP_DSCP_SET_MASK) {
5651 params.spp_dscp = trans->dscp & SCTP_DSCP_VAL_MASK;
5652 params.spp_flags |= SPP_DSCP;
5653 }
5476 } else if (asoc) {
5477 /* Fetch association values. */
5478 params.spp_hbinterval = jiffies_to_msecs(asoc->hbinterval);
5479 params.spp_pathmtu = asoc->pathmtu;
5480 params.spp_pathmaxrxt = asoc->pathmaxrxt;
5481 params.spp_sackdelay = jiffies_to_msecs(asoc->sackdelay);
5482
5483 /*draft-11 doesn't say what to return in spp_flags*/
5484 params.spp_flags = asoc->param_flags;
5654 } else if (asoc) {
5655 /* Fetch association values. */
5656 params.spp_hbinterval = jiffies_to_msecs(asoc->hbinterval);
5657 params.spp_pathmtu = asoc->pathmtu;
5658 params.spp_pathmaxrxt = asoc->pathmaxrxt;
5659 params.spp_sackdelay = jiffies_to_msecs(asoc->sackdelay);
5660
5661 /*draft-11 doesn't say what to return in spp_flags*/
5662 params.spp_flags = asoc->param_flags;
5663 if (asoc->flowlabel & SCTP_FLOWLABEL_SET_MASK) {
5664 params.spp_ipv6_flowlabel = asoc->flowlabel &
5665 SCTP_FLOWLABEL_VAL_MASK;
5666 params.spp_flags |= SPP_IPV6_FLOWLABEL;
5667 }
5668 if (asoc->dscp & SCTP_DSCP_SET_MASK) {
5669 params.spp_dscp = asoc->dscp & SCTP_DSCP_VAL_MASK;
5670 params.spp_flags |= SPP_DSCP;
5671 }
5485 } else {
5486 /* Fetch socket values. */
5487 params.spp_hbinterval = sp->hbinterval;
5488 params.spp_pathmtu = sp->pathmtu;
5489 params.spp_sackdelay = sp->sackdelay;
5490 params.spp_pathmaxrxt = sp->pathmaxrxt;
5491
5492 /*draft-11 doesn't say what to return in spp_flags*/
5493 params.spp_flags = sp->param_flags;
5672 } else {
5673 /* Fetch socket values. */
5674 params.spp_hbinterval = sp->hbinterval;
5675 params.spp_pathmtu = sp->pathmtu;
5676 params.spp_sackdelay = sp->sackdelay;
5677 params.spp_pathmaxrxt = sp->pathmaxrxt;
5678
5679 /*draft-11 doesn't say what to return in spp_flags*/
5680 params.spp_flags = sp->param_flags;
5681 if (sp->flowlabel & SCTP_FLOWLABEL_SET_MASK) {
5682 params.spp_ipv6_flowlabel = sp->flowlabel &
5683 SCTP_FLOWLABEL_VAL_MASK;
5684 params.spp_flags |= SPP_IPV6_FLOWLABEL;
5685 }
5686 if (sp->dscp & SCTP_DSCP_SET_MASK) {
5687 params.spp_dscp = sp->dscp & SCTP_DSCP_VAL_MASK;
5688 params.spp_flags |= SPP_DSCP;
5689 }
5494 }
5495
5496 if (copy_to_user(optval, &params, len))
5497 return -EFAULT;
5498
5499 if (put_user(len, optlen))
5500 return -EFAULT;
5501

--- 1451 unchanged lines hidden (view full) ---

6953 policy = params.sprstat_policy;
6954 if (policy & ~SCTP_PR_SCTP_MASK)
6955 goto out;
6956
6957 asoc = sctp_id2assoc(sk, params.sprstat_assoc_id);
6958 if (!asoc || params.sprstat_sid >= asoc->stream.outcnt)
6959 goto out;
6960
5690 }
5691
5692 if (copy_to_user(optval, &params, len))
5693 return -EFAULT;
5694
5695 if (put_user(len, optlen))
5696 return -EFAULT;
5697

--- 1451 unchanged lines hidden (view full) ---

7149 policy = params.sprstat_policy;
7150 if (policy & ~SCTP_PR_SCTP_MASK)
7151 goto out;
7152
7153 asoc = sctp_id2assoc(sk, params.sprstat_assoc_id);
7154 if (!asoc || params.sprstat_sid >= asoc->stream.outcnt)
7155 goto out;
7156
6961 streamoute = asoc->stream.out[params.sprstat_sid].ext;
7157 streamoute = SCTP_SO(&asoc->stream, params.sprstat_sid)->ext;
6962 if (!streamoute) {
6963 /* Not allocated yet, means all stats are 0 */
6964 params.sprstat_abandoned_unsent = 0;
6965 params.sprstat_abandoned_sent = 0;
6966 retval = 0;
6967 goto out;
6968 }
6969

--- 221 unchanged lines hidden (view full) ---

7191 goto out;
7192
7193 retval = 0;
7194
7195out:
7196 return retval;
7197}
7198
7158 if (!streamoute) {
7159 /* Not allocated yet, means all stats are 0 */
7160 params.sprstat_abandoned_unsent = 0;
7161 params.sprstat_abandoned_sent = 0;
7162 retval = 0;
7163 goto out;
7164 }
7165

--- 221 unchanged lines hidden (view full) ---

7387 goto out;
7388
7389 retval = 0;
7390
7391out:
7392 return retval;
7393}
7394
7395static int sctp_getsockopt_reuse_port(struct sock *sk, int len,
7396 char __user *optval,
7397 int __user *optlen)
7398{
7399 int val;
7400
7401 if (len < sizeof(int))
7402 return -EINVAL;
7403
7404 len = sizeof(int);
7405 val = sctp_sk(sk)->reuse;
7406 if (put_user(len, optlen))
7407 return -EFAULT;
7408
7409 if (copy_to_user(optval, &val, len))
7410 return -EFAULT;
7411
7412 return 0;
7413}
7414
7199static int sctp_getsockopt(struct sock *sk, int level, int optname,
7200 char __user *optval, int __user *optlen)
7201{
7202 int retval = 0;
7203 int len;
7204
7205 pr_debug("%s: sk:%p, optname:%d\n", __func__, sk, optname);
7206

--- 179 unchanged lines hidden (view full) ---

7386 case SCTP_STREAM_SCHEDULER_VALUE:
7387 retval = sctp_getsockopt_scheduler_value(sk, len, optval,
7388 optlen);
7389 break;
7390 case SCTP_INTERLEAVING_SUPPORTED:
7391 retval = sctp_getsockopt_interleaving_supported(sk, len, optval,
7392 optlen);
7393 break;
7415static int sctp_getsockopt(struct sock *sk, int level, int optname,
7416 char __user *optval, int __user *optlen)
7417{
7418 int retval = 0;
7419 int len;
7420
7421 pr_debug("%s: sk:%p, optname:%d\n", __func__, sk, optname);
7422

--- 179 unchanged lines hidden (view full) ---

7602 case SCTP_STREAM_SCHEDULER_VALUE:
7603 retval = sctp_getsockopt_scheduler_value(sk, len, optval,
7604 optlen);
7605 break;
7606 case SCTP_INTERLEAVING_SUPPORTED:
7607 retval = sctp_getsockopt_interleaving_supported(sk, len, optval,
7608 optlen);
7609 break;
7610 case SCTP_REUSE_PORT:
7611 retval = sctp_getsockopt_reuse_port(sk, len, optval, optlen);
7612 break;
7394 default:
7395 retval = -ENOPROTOOPT;
7396 break;
7397 }
7398
7399 release_sock(sk);
7400 return retval;
7401}

--- 21 unchanged lines hidden (view full) ---

7423 * link to the socket (struct sock) that uses it, the port number and
7424 * a fastreuse flag (FIXME: NPI ipg).
7425 */
7426static struct sctp_bind_bucket *sctp_bucket_create(
7427 struct sctp_bind_hashbucket *head, struct net *, unsigned short snum);
7428
7429static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
7430{
7613 default:
7614 retval = -ENOPROTOOPT;
7615 break;
7616 }
7617
7618 release_sock(sk);
7619 return retval;
7620}

--- 21 unchanged lines hidden (view full) ---

7642 * link to the socket (struct sock) that uses it, the port number and
7643 * a fastreuse flag (FIXME: NPI ipg).
7644 */
7645static struct sctp_bind_bucket *sctp_bucket_create(
7646 struct sctp_bind_hashbucket *head, struct net *, unsigned short snum);
7647
7648static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
7649{
7650 bool reuse = (sk->sk_reuse || sctp_sk(sk)->reuse);
7431 struct sctp_bind_hashbucket *head; /* hash list */
7432 struct sctp_bind_bucket *pp;
7433 unsigned short snum;
7434 int ret;
7435
7436 snum = ntohs(addr->v4.sin_port);
7437
7438 pr_debug("%s: begins, snum:%d\n", __func__, snum);

--- 56 unchanged lines hidden (view full) ---

7495 goto pp_not_found;
7496pp_found:
7497 if (!hlist_empty(&pp->owner)) {
7498 /* We had a port hash table hit - there is an
7499 * available port (pp != NULL) and it is being
7500 * used by other socket (pp->owner not empty); that other
7501 * socket is going to be sk2.
7502 */
7651 struct sctp_bind_hashbucket *head; /* hash list */
7652 struct sctp_bind_bucket *pp;
7653 unsigned short snum;
7654 int ret;
7655
7656 snum = ntohs(addr->v4.sin_port);
7657
7658 pr_debug("%s: begins, snum:%d\n", __func__, snum);

--- 56 unchanged lines hidden (view full) ---

7715 goto pp_not_found;
7716pp_found:
7717 if (!hlist_empty(&pp->owner)) {
7718 /* We had a port hash table hit - there is an
7719 * available port (pp != NULL) and it is being
7720 * used by other socket (pp->owner not empty); that other
7721 * socket is going to be sk2.
7722 */
7503 int reuse = sk->sk_reuse;
7504 struct sock *sk2;
7505
7506 pr_debug("%s: found a possible match\n", __func__);
7507
7723 struct sock *sk2;
7724
7725 pr_debug("%s: found a possible match\n", __func__);
7726
7508 if (pp->fastreuse && sk->sk_reuse &&
7509 sk->sk_state != SCTP_SS_LISTENING)
7727 if (pp->fastreuse && reuse && sk->sk_state != SCTP_SS_LISTENING)
7510 goto success;
7511
7512 /* Run through the list of sockets bound to the port
7513 * (pp->port) [via the pointers bind_next and
7514 * bind_pprev in the struct sock *sk2 (pp->sk)]. On each one,
7515 * we get the endpoint they describe and run through
7516 * the endpoint's list of IP (v4 or v6) addresses,
7517 * comparing each of the addresses with the address of
7518 * the socket sk. If we find a match, then that means
7519 * that this port/socket (sk) combination are already
7520 * in an endpoint.
7521 */
7522 sk_for_each_bound(sk2, &pp->owner) {
7523 struct sctp_endpoint *ep2;
7524 ep2 = sctp_sk(sk2)->ep;
7525
7526 if (sk == sk2 ||
7728 goto success;
7729
7730 /* Run through the list of sockets bound to the port
7731 * (pp->port) [via the pointers bind_next and
7732 * bind_pprev in the struct sock *sk2 (pp->sk)]. On each one,
7733 * we get the endpoint they describe and run through
7734 * the endpoint's list of IP (v4 or v6) addresses,
7735 * comparing each of the addresses with the address of
7736 * the socket sk. If we find a match, then that means
7737 * that this port/socket (sk) combination are already
7738 * in an endpoint.
7739 */
7740 sk_for_each_bound(sk2, &pp->owner) {
7741 struct sctp_endpoint *ep2;
7742 ep2 = sctp_sk(sk2)->ep;
7743
7744 if (sk == sk2 ||
7527 (reuse && sk2->sk_reuse &&
7745 (reuse && (sk2->sk_reuse || sctp_sk(sk2)->reuse) &&
7528 sk2->sk_state != SCTP_SS_LISTENING))
7529 continue;
7530
7531 if (sctp_bind_addr_conflict(&ep2->base.bind_addr, addr,
7532 sctp_sk(sk2), sctp_sk(sk))) {
7533 ret = (long)sk2;
7534 goto fail_unlock;
7535 }

--- 7 unchanged lines hidden (view full) ---

7543 if (!pp && !(pp = sctp_bucket_create(head, sock_net(sk), snum)))
7544 goto fail_unlock;
7545
7546 /* In either case (hit or miss), make sure fastreuse is 1 only
7547 * if sk->sk_reuse is too (that is, if the caller requested
7548 * SO_REUSEADDR on this socket -sk-).
7549 */
7550 if (hlist_empty(&pp->owner)) {
7746 sk2->sk_state != SCTP_SS_LISTENING))
7747 continue;
7748
7749 if (sctp_bind_addr_conflict(&ep2->base.bind_addr, addr,
7750 sctp_sk(sk2), sctp_sk(sk))) {
7751 ret = (long)sk2;
7752 goto fail_unlock;
7753 }

--- 7 unchanged lines hidden (view full) ---

7761 if (!pp && !(pp = sctp_bucket_create(head, sock_net(sk), snum)))
7762 goto fail_unlock;
7763
7764 /* In either case (hit or miss), make sure fastreuse is 1 only
7765 * if sk->sk_reuse is too (that is, if the caller requested
7766 * SO_REUSEADDR on this socket -sk-).
7767 */
7768 if (hlist_empty(&pp->owner)) {
7551 if (sk->sk_reuse && sk->sk_state != SCTP_SS_LISTENING)
7769 if (reuse && sk->sk_state != SCTP_SS_LISTENING)
7552 pp->fastreuse = 1;
7553 else
7554 pp->fastreuse = 0;
7555 } else if (pp->fastreuse &&
7770 pp->fastreuse = 1;
7771 else
7772 pp->fastreuse = 0;
7773 } else if (pp->fastreuse &&
7556 (!sk->sk_reuse || sk->sk_state == SCTP_SS_LISTENING))
7774 (!reuse || sk->sk_state == SCTP_SS_LISTENING))
7557 pp->fastreuse = 0;
7558
7559 /* We are set, so fill up all the data in the hash table
7560 * entry, tie the socket list information with the rest of the
7561 * sockets FIXME: Blurry, NPI (ipg).
7562 */
7563success:
7564 if (!sctp_sk(sk)->bind_hash) {

--- 114 unchanged lines hidden (view full) ---

7679 /* If backlog is zero, disable listening. */
7680 if (!backlog) {
7681 if (sctp_sstate(sk, CLOSED))
7682 goto out;
7683
7684 err = 0;
7685 sctp_unhash_endpoint(ep);
7686 sk->sk_state = SCTP_SS_CLOSED;
7775 pp->fastreuse = 0;
7776
7777 /* We are set, so fill up all the data in the hash table
7778 * entry, tie the socket list information with the rest of the
7779 * sockets FIXME: Blurry, NPI (ipg).
7780 */
7781success:
7782 if (!sctp_sk(sk)->bind_hash) {

--- 114 unchanged lines hidden (view full) ---

7897 /* If backlog is zero, disable listening. */
7898 if (!backlog) {
7899 if (sctp_sstate(sk, CLOSED))
7900 goto out;
7901
7902 err = 0;
7903 sctp_unhash_endpoint(ep);
7904 sk->sk_state = SCTP_SS_CLOSED;
7687 if (sk->sk_reuse)
7905 if (sk->sk_reuse || sctp_sk(sk)->reuse)
7688 sctp_sk(sk)->bind_hash->fastreuse = 1;
7689 goto out;
7690 }
7691
7692 /* If we are already listening, just update the backlog */
7693 if (sctp_sstate(sk, LISTENING))
7694 sk->sk_max_ack_backlog = backlog;
7695 else {

--- 850 unchanged lines hidden (view full) ---

8546
8547 newsk->sk_type = sk->sk_type;
8548 newsk->sk_bound_dev_if = sk->sk_bound_dev_if;
8549 newsk->sk_flags = sk->sk_flags;
8550 newsk->sk_tsflags = sk->sk_tsflags;
8551 newsk->sk_no_check_tx = sk->sk_no_check_tx;
8552 newsk->sk_no_check_rx = sk->sk_no_check_rx;
8553 newsk->sk_reuse = sk->sk_reuse;
7906 sctp_sk(sk)->bind_hash->fastreuse = 1;
7907 goto out;
7908 }
7909
7910 /* If we are already listening, just update the backlog */
7911 if (sctp_sstate(sk, LISTENING))
7912 sk->sk_max_ack_backlog = backlog;
7913 else {

--- 850 unchanged lines hidden (view full) ---

8764
8765 newsk->sk_type = sk->sk_type;
8766 newsk->sk_bound_dev_if = sk->sk_bound_dev_if;
8767 newsk->sk_flags = sk->sk_flags;
8768 newsk->sk_tsflags = sk->sk_tsflags;
8769 newsk->sk_no_check_tx = sk->sk_no_check_tx;
8770 newsk->sk_no_check_rx = sk->sk_no_check_rx;
8771 newsk->sk_reuse = sk->sk_reuse;
8772 sctp_sk(newsk)->reuse = sp->reuse;
8554
8555 newsk->sk_shutdown = sk->sk_shutdown;
8556 newsk->sk_destruct = sctp_destruct_sock;
8557 newsk->sk_family = sk->sk_family;
8558 newsk->sk_protocol = IPPROTO_SCTP;
8559 newsk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
8560 newsk->sk_sndbuf = sk->sk_sndbuf;
8561 newsk->sk_rcvbuf = sk->sk_rcvbuf;

--- 252 unchanged lines hidden ---
8773
8774 newsk->sk_shutdown = sk->sk_shutdown;
8775 newsk->sk_destruct = sctp_destruct_sock;
8776 newsk->sk_family = sk->sk_family;
8777 newsk->sk_protocol = IPPROTO_SCTP;
8778 newsk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
8779 newsk->sk_sndbuf = sk->sk_sndbuf;
8780 newsk->sk_rcvbuf = sk->sk_rcvbuf;

--- 252 unchanged lines hidden ---