Lines Matching +full:bp +full:- +full:disabled +full:- +full:ports
1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (c) 1999-2000 Cisco, Inc.
5 * Copyright (c) 1999-2001 Motorola, Inc.
6 * Copyright (c) 2001-2003 Intel Corp.
7 * Copyright (c) 2001-2002 Nokia, Inc.
16 * functions--this file is the functions which populate the struct proto
21 * lksctp developers <linux-sctp@vger.kernel.org>
31 * Inaky Perez-Gonzalez <inaky.gonzalez@intel.com>
109 struct sock *sk = asoc->base.sk; in sctp_wspace()
111 return asoc->ep->sndbuf_policy ? sk->sk_sndbuf - asoc->sndbuf_used in sctp_wspace()
119 * Since it is always 1-1 between chunk and skb, and also a new skb is always
126 struct sctp_association *asoc = chunk->asoc; in sctp_set_owner_w()
127 struct sock *sk = asoc->base.sk; in sctp_set_owner_w()
132 if (chunk->shkey) in sctp_set_owner_w()
133 sctp_auth_shkey_hold(chunk->shkey); in sctp_set_owner_w()
135 skb_set_owner_w(chunk->skb, sk); in sctp_set_owner_w()
137 chunk->skb->destructor = sctp_wfree; in sctp_set_owner_w()
139 skb_shinfo(chunk->skb)->destructor_arg = chunk; in sctp_set_owner_w()
141 refcount_add(sizeof(struct sctp_chunk), &sk->sk_wmem_alloc); in sctp_set_owner_w()
142 asoc->sndbuf_used += chunk->skb->truesize + sizeof(struct sctp_chunk); in sctp_set_owner_w()
143 sk_wmem_queued_add(sk, chunk->skb->truesize + sizeof(struct sctp_chunk)); in sctp_set_owner_w()
144 sk_mem_charge(sk, chunk->skb->truesize); in sctp_set_owner_w()
149 skb_orphan(chunk->skb); in sctp_clear_owner_w()
154 msg = chunk->msg; \
157 list_for_each_entry(c, &msg->chunks, frag_list) { \
158 if ((clear && asoc->base.sk == c->skb->sk) || \
159 (!clear && asoc->base.sk != c->skb->sk)) \
171 struct sctp_outq *q = &asoc->outqueue; in sctp_for_each_tx_datachunk()
175 list_for_each_entry(t, &asoc->peer.transport_addr_list, transports) in sctp_for_each_tx_datachunk()
176 list_for_each_entry(chunk, &t->transmitted, transmitted_list) in sctp_for_each_tx_datachunk()
179 list_for_each_entry(chunk, &q->retransmit, transmitted_list) in sctp_for_each_tx_datachunk()
182 list_for_each_entry(chunk, &q->sacked, transmitted_list) in sctp_for_each_tx_datachunk()
185 list_for_each_entry(chunk, &q->abandoned, transmitted_list) in sctp_for_each_tx_datachunk()
188 list_for_each_entry(chunk, &q->out_chunk_list, list) in sctp_for_each_tx_datachunk()
198 sctp_skb_for_each(skb, &asoc->ulpq.lobby, tmp) in sctp_for_each_rx_skb()
201 sctp_skb_for_each(skb, &asoc->ulpq.reasm, tmp) in sctp_for_each_rx_skb()
204 sctp_skb_for_each(skb, &asoc->ulpq.reasm_uo, tmp) in sctp_for_each_rx_skb()
217 return -EINVAL; in sctp_verify_addr()
220 if (!af->addr_valid(addr, sctp_sk(sk), NULL)) in sctp_verify_addr()
221 return -EINVAL; in sctp_verify_addr()
223 if (!sctp_sk(sk)->pf->send_verify(sctp_sk(sk), (addr))) in sctp_verify_addr()
224 return -EINVAL; in sctp_verify_addr()
229 /* Look up the association by its id. If this is not a UDP-style
236 /* If this is not a UDP-style socket, assoc id should be ignored. */ in sctp_id2assoc()
239 * could be a TCP-style listening socket or a socket which in sctp_id2assoc()
246 if (!list_empty(&sctp_sk(sk)->ep->asocs)) in sctp_id2assoc()
247 asoc = list_entry(sctp_sk(sk)->ep->asocs.next, in sctp_id2assoc()
252 /* Otherwise this is a UDP-style socket. */ in sctp_id2assoc()
258 if (asoc && (asoc->base.sk != sk || asoc->base.dead)) in sctp_id2assoc()
274 struct sctp_af *af = sctp_get_af_specific(addr->ss_family); in sctp_addr_id2transport()
278 if (!af || sctp_verify_addr(sk, laddr, af->sockaddr_len)) in sctp_addr_id2transport()
281 addr_asoc = sctp_endpoint_lookup_assoc(sctp_sk(sk)->ep, in sctp_addr_id2transport()
292 sctp_get_pf_specific(sk->sk_family)->addr_to_user(sctp_sk(sk), in sctp_addr_id2transport()
298 /* API 3.1.2 bind() - UDP Style Syntax
303 * sd - the socket descriptor returned by socket().
304 * addr - the address structure (struct sockaddr_in or struct
306 * addr_len - the size of the address structure.
318 if (!sctp_sk(sk)->ep->base.bind_addr.port) in sctp_bind()
322 retval = -EINVAL; in sctp_bind()
341 if (!opt->pf->af_supported(addr->sa.sa_family, opt)) in sctp_sockaddr_af()
344 if (addr->sa.sa_family == AF_INET6) { in sctp_sockaddr_af()
348 if (ipv6_addr_v4mapped(&addr->v6.sin6_addr) && in sctp_sockaddr_af()
349 !opt->pf->af_supported(AF_INET, opt)) in sctp_sockaddr_af()
354 af = sctp_get_af_specific(addr->sa.sa_family); in sctp_sockaddr_af()
356 if (len < af->sockaddr_len) in sctp_sockaddr_af()
364 struct net *net = sock_net(&sp->inet.sk); in sctp_auto_asconf_init()
366 if (net->sctp.default_auto_asconf) { in sctp_auto_asconf_init()
367 spin_lock_bh(&net->sctp.addr_wq_lock); in sctp_auto_asconf_init()
368 list_add_tail(&sp->auto_asconf_list, &net->sctp.auto_asconf_splist); in sctp_auto_asconf_init()
369 spin_unlock_bh(&net->sctp.addr_wq_lock); in sctp_auto_asconf_init()
370 sp->do_auto_asconf = 1; in sctp_auto_asconf_init()
379 struct sctp_endpoint *ep = sp->ep; in sctp_do_bind()
380 struct sctp_bind_addr *bp = &ep->base.bind_addr; in sctp_do_bind() local
390 return -EINVAL; in sctp_do_bind()
393 snum = ntohs(addr->v4.sin_port); in sctp_do_bind()
396 __func__, sk, &addr->sa, bp->port, snum, len); in sctp_do_bind()
399 if (!sp->pf->bind_verify(sp, addr)) in sctp_do_bind()
400 return -EADDRNOTAVAIL; in sctp_do_bind()
403 * It's OK to allow 0 ports if we are already bound. in sctp_do_bind()
406 if (bp->port) { in sctp_do_bind()
408 snum = bp->port; in sctp_do_bind()
409 else if (snum != bp->port) { in sctp_do_bind()
411 "%d\n", __func__, snum, bp->port); in sctp_do_bind()
412 return -EINVAL; in sctp_do_bind()
417 !ns_capable(net->user_ns, CAP_NET_BIND_SERVICE)) in sctp_do_bind()
418 return -EACCES; in sctp_do_bind()
423 if (sctp_bind_addr_match(bp, addr, sp)) in sctp_do_bind()
424 return -EINVAL; in sctp_do_bind()
430 addr->v4.sin_port = htons(snum); in sctp_do_bind()
432 return -EADDRINUSE; in sctp_do_bind()
435 if (!bp->port) { in sctp_do_bind()
436 bp->port = inet_sk(sk)->inet_num; in sctp_do_bind()
441 * Use GFP_ATOMIC since BHs will be disabled. in sctp_do_bind()
443 ret = sctp_add_bind_addr(bp, addr, af->sockaddr_len, in sctp_do_bind()
451 inet_sk(sk)->inet_sport = htons(inet_sk(sk)->inet_num); in sctp_do_bind()
452 sp->pf->to_sk_saddr(addr, sk); in sctp_do_bind()
462 * ASCONF-ACK Chunk returns from the previous ASCONF Chunk before sending a
464 * time two ASCONF may be in-transit on any given association (one sent
475 if (asoc->addip_last_asconf) { in sctp_send_asconf()
476 list_add_tail(&chunk->list, &asoc->addip_chunk_list); in sctp_send_asconf()
482 retval = sctp_primitive_ASCONF(asoc->base.net, asoc, chunk); in sctp_send_asconf()
486 asoc->addip_last_asconf = chunk; in sctp_send_asconf()
521 af = sctp_get_af_specific(sa_addr->sa_family); in sctp_bindx_add()
523 retval = -EINVAL; in sctp_bindx_add()
528 af->sockaddr_len); in sctp_bindx_add()
530 addr_buf += af->sockaddr_len; in sctp_bindx_add()
561 struct sctp_bind_addr *bp; in sctp_send_asconf_add_ip() local
573 ep = sp->ep; in sctp_send_asconf_add_ip()
575 if (!ep->asconf_enable) in sctp_send_asconf_add_ip()
581 list_for_each_entry(asoc, &ep->asocs, asocs) { in sctp_send_asconf_add_ip()
582 if (!asoc->peer.asconf_capable) in sctp_send_asconf_add_ip()
585 if (asoc->peer.addip_disabled_mask & SCTP_PARAM_ADD_IP) in sctp_send_asconf_add_ip()
599 af = sctp_get_af_specific(addr->v4.sin_family); in sctp_send_asconf_add_ip()
601 retval = -EINVAL; in sctp_send_asconf_add_ip()
608 addr_buf += af->sockaddr_len; in sctp_send_asconf_add_ip()
616 bp = &asoc->base.bind_addr; in sctp_send_asconf_add_ip()
617 p = bp->address_list.next; in sctp_send_asconf_add_ip()
619 chunk = sctp_make_asconf_update_ip(asoc, &laddr->a, addrs, in sctp_send_asconf_add_ip()
622 retval = -ENOMEM; in sctp_send_asconf_add_ip()
632 af = sctp_get_af_specific(addr->v4.sin_family); in sctp_send_asconf_add_ip()
633 memcpy(&saveaddr, addr, af->sockaddr_len); in sctp_send_asconf_add_ip()
634 retval = sctp_add_bind_addr(bp, &saveaddr, in sctp_send_asconf_add_ip()
637 addr_buf += af->sockaddr_len; in sctp_send_asconf_add_ip()
639 if (asoc->src_out_of_asoc_ok) { in sctp_send_asconf_add_ip()
643 &asoc->peer.transport_addr_list, transports) { in sctp_send_asconf_add_ip()
644 trans->cwnd = min(4*asoc->pathmtu, max_t(__u32, in sctp_send_asconf_add_ip()
645 2*asoc->pathmtu, 4380)); in sctp_send_asconf_add_ip()
646 trans->ssthresh = asoc->peer.i.a_rwnd; in sctp_send_asconf_add_ip()
647 trans->rto = asoc->rto_initial; in sctp_send_asconf_add_ip()
649 trans->rtt = trans->srtt = trans->rttvar = 0; in sctp_send_asconf_add_ip()
652 sctp_sk(asoc->base.sk)); in sctp_send_asconf_add_ip()
673 * available, the operation will return -EBUSY.
680 struct sctp_endpoint *ep = sp->ep; in sctp_bindx_rem()
682 struct sctp_bind_addr *bp = &ep->base.bind_addr; in sctp_bindx_rem() local
697 if (list_empty(&bp->address_list) || in sctp_bindx_rem()
698 (sctp_list_single_entry(&bp->address_list))) { in sctp_bindx_rem()
699 retval = -EBUSY; in sctp_bindx_rem()
704 af = sctp_get_af_specific(sa_addr->sa.sa_family); in sctp_bindx_rem()
706 retval = -EINVAL; in sctp_bindx_rem()
710 if (!af->addr_valid(sa_addr, sp, NULL)) { in sctp_bindx_rem()
711 retval = -EADDRNOTAVAIL; in sctp_bindx_rem()
715 if (sa_addr->v4.sin_port && in sctp_bindx_rem()
716 sa_addr->v4.sin_port != htons(bp->port)) { in sctp_bindx_rem()
717 retval = -EINVAL; in sctp_bindx_rem()
721 if (!sa_addr->v4.sin_port) in sctp_bindx_rem()
722 sa_addr->v4.sin_port = htons(bp->port); in sctp_bindx_rem()
724 /* FIXME - There is probably a need to check if sk->sk_saddr and in sctp_bindx_rem()
725 * sk->sk_rcv_addr are currently set to one of the addresses to in sctp_bindx_rem()
727 * when we are fixing the outstanding issues with multi-homing in sctp_bindx_rem()
729 * sctp_do_bind(). -daisy in sctp_bindx_rem()
731 retval = sctp_del_bind_addr(bp, sa_addr); in sctp_bindx_rem()
733 addr_buf += af->sockaddr_len; in sctp_bindx_rem()
764 struct sctp_bind_addr *bp; in sctp_send_asconf_del_ip() local
776 ep = sp->ep; in sctp_send_asconf_del_ip()
778 if (!ep->asconf_enable) in sctp_send_asconf_del_ip()
784 list_for_each_entry(asoc, &ep->asocs, asocs) { in sctp_send_asconf_del_ip()
786 if (!asoc->peer.asconf_capable) in sctp_send_asconf_del_ip()
789 if (asoc->peer.addip_disabled_mask & SCTP_PARAM_DEL_IP) in sctp_send_asconf_del_ip()
803 af = sctp_get_af_specific(laddr->v4.sin_family); in sctp_send_asconf_del_ip()
805 retval = -EINVAL; in sctp_send_asconf_del_ip()
812 addr_buf += af->sockaddr_len; in sctp_send_asconf_del_ip()
822 bp = &asoc->base.bind_addr; in sctp_send_asconf_del_ip()
823 laddr = sctp_find_unmatch_addr(bp, (union sctp_addr *)addrs, in sctp_send_asconf_del_ip()
826 if (asoc->asconf_addr_del_pending) in sctp_send_asconf_del_ip()
828 asoc->asconf_addr_del_pending = in sctp_send_asconf_del_ip()
830 if (asoc->asconf_addr_del_pending == NULL) { in sctp_send_asconf_del_ip()
831 retval = -ENOMEM; in sctp_send_asconf_del_ip()
834 asoc->asconf_addr_del_pending->sa.sa_family = in sctp_send_asconf_del_ip()
835 addrs->sa_family; in sctp_send_asconf_del_ip()
836 asoc->asconf_addr_del_pending->v4.sin_port = in sctp_send_asconf_del_ip()
837 htons(bp->port); in sctp_send_asconf_del_ip()
838 if (addrs->sa_family == AF_INET) { in sctp_send_asconf_del_ip()
842 asoc->asconf_addr_del_pending->v4.sin_addr.s_addr = sin->sin_addr.s_addr; in sctp_send_asconf_del_ip()
843 } else if (addrs->sa_family == AF_INET6) { in sctp_send_asconf_del_ip()
847 asoc->asconf_addr_del_pending->v6.sin6_addr = sin6->sin6_addr; in sctp_send_asconf_del_ip()
851 __func__, asoc, &asoc->asconf_addr_del_pending->sa, in sctp_send_asconf_del_ip()
852 asoc->asconf_addr_del_pending); in sctp_send_asconf_del_ip()
854 asoc->src_out_of_asoc_ok = 1; in sctp_send_asconf_del_ip()
860 return -EINVAL; in sctp_send_asconf_del_ip()
869 retval = -ENOMEM; in sctp_send_asconf_del_ip()
880 af = sctp_get_af_specific(laddr->v4.sin_family); in sctp_send_asconf_del_ip()
881 list_for_each_entry(saddr, &bp->address_list, list) { in sctp_send_asconf_del_ip()
882 if (sctp_cmp_addr_exact(&saddr->a, laddr)) in sctp_send_asconf_del_ip()
883 saddr->state = SCTP_ADDR_DEL; in sctp_send_asconf_del_ip()
885 addr_buf += af->sockaddr_len; in sctp_send_asconf_del_ip()
892 list_for_each_entry(transport, &asoc->peer.transport_addr_list, in sctp_send_asconf_del_ip()
895 sctp_sk(asoc->base.sk)); in sctp_send_asconf_del_ip()
915 addr = &addrw->a; in sctp_asconf_mgmt()
916 addr->v4.sin_port = htons(sp->ep->base.bind_addr.port); in sctp_asconf_mgmt()
917 af = sctp_get_af_specific(addr->sa.sa_family); in sctp_asconf_mgmt()
919 return -EINVAL; in sctp_asconf_mgmt()
920 if (sctp_verify_addr(sk, addr, af->sockaddr_len)) in sctp_asconf_mgmt()
921 return -EINVAL; in sctp_asconf_mgmt()
923 if (addrw->state == SCTP_ADDR_NEW) in sctp_asconf_mgmt()
950 * -1, and sets errno to the appropriate error code.
1012 return -EINVAL; in sctp_setsockopt_bindx()
1017 return -EINVAL; in sctp_setsockopt_bindx()
1020 af = sctp_get_af_specific(sa_addr->sa_family); in sctp_setsockopt_bindx()
1025 if (!af || (walk_size + af->sockaddr_len) > addrs_size) in sctp_setsockopt_bindx()
1026 return -EINVAL; in sctp_setsockopt_bindx()
1028 addr_buf += af->sockaddr_len; in sctp_setsockopt_bindx()
1029 walk_size += af->sockaddr_len; in sctp_setsockopt_bindx()
1051 return -EINVAL; in sctp_setsockopt_bindx()
1072 struct sock *sk = ep->base.sk; in sctp_connect_new_asoc()
1078 return -EADDRNOTAVAIL; in sctp_connect_new_asoc()
1080 if (!ep->base.bind_addr.port) { in sctp_connect_new_asoc()
1082 return -EAGAIN; in sctp_connect_new_asoc()
1084 if (inet_port_requires_bind_service(net, ep->base.bind_addr.port) && in sctp_connect_new_asoc()
1085 !ns_capable(net->user_ns, CAP_NET_BIND_SERVICE)) in sctp_connect_new_asoc()
1086 return -EACCES; in sctp_connect_new_asoc()
1092 return -ENOMEM; in sctp_connect_new_asoc()
1100 err = -ENOMEM; in sctp_connect_new_asoc()
1107 if (init->sinit_num_ostreams) { in sctp_connect_new_asoc()
1108 __u16 outcnt = init->sinit_num_ostreams; in sctp_connect_new_asoc()
1110 asoc->c.sinit_num_ostreams = outcnt; in sctp_connect_new_asoc()
1111 /* outcnt has been changed, need to re-init stream */ in sctp_connect_new_asoc()
1112 err = sctp_stream_init(&asoc->stream, outcnt, 0, GFP_KERNEL); in sctp_connect_new_asoc()
1117 if (init->sinit_max_instreams) in sctp_connect_new_asoc()
1118 asoc->c.sinit_max_instreams = init->sinit_max_instreams; in sctp_connect_new_asoc()
1120 if (init->sinit_max_attempts) in sctp_connect_new_asoc()
1121 asoc->max_init_attempts = init->sinit_max_attempts; in sctp_connect_new_asoc()
1123 if (init->sinit_max_init_timeo) in sctp_connect_new_asoc()
1124 asoc->max_init_timeo = in sctp_connect_new_asoc()
1125 msecs_to_jiffies(init->sinit_max_init_timeo); in sctp_connect_new_asoc()
1136 struct sctp_endpoint *ep = asoc->ep; in sctp_connect_add_peer()
1141 err = sctp_verify_addr(ep->base.sk, daddr, addr_len); in sctp_connect_add_peer()
1147 return old->state >= SCTP_STATE_ESTABLISHED ? -EISCONN in sctp_connect_add_peer()
1148 : -EALREADY; in sctp_connect_add_peer()
1151 return -EADDRNOTAVAIL; in sctp_connect_add_peer()
1155 return -ENOMEM; in sctp_connect_add_peer()
1169 struct sctp_endpoint *ep = sp->ep; in __sctp_connect()
1180 return -EISCONN; in __sctp_connect()
1183 af = sctp_get_af_specific(daddr->sa.sa_family); in __sctp_connect()
1184 if (!af || af->sockaddr_len > addrs_size) in __sctp_connect()
1185 return -EINVAL; in __sctp_connect()
1187 err = sctp_verify_addr(sk, daddr, af->sockaddr_len); in __sctp_connect()
1193 return asoc->state >= SCTP_STATE_ESTABLISHED ? -EISCONN in __sctp_connect()
1194 : -EALREADY; in __sctp_connect()
1199 asoc = transport->asoc; in __sctp_connect()
1201 addr_buf += af->sockaddr_len; in __sctp_connect()
1202 walk_size = af->sockaddr_len; in __sctp_connect()
1204 err = -EINVAL; in __sctp_connect()
1209 af = sctp_get_af_specific(daddr->sa.sa_family); in __sctp_connect()
1210 if (!af || af->sockaddr_len + walk_size > addrs_size) in __sctp_connect()
1213 if (asoc->peer.port != ntohs(daddr->v4.sin_port)) in __sctp_connect()
1216 err = sctp_connect_add_peer(asoc, daddr, af->sockaddr_len); in __sctp_connect()
1220 addr_buf += af->sockaddr_len; in __sctp_connect()
1221 walk_size += af->sockaddr_len; in __sctp_connect()
1238 inet_sk(sk)->inet_dport = htons(asoc->peer.port); in __sctp_connect()
1239 sp->pf->to_sk_daddr(daddr, sk); in __sctp_connect()
1240 sk->sk_err = 0; in __sctp_connect()
1243 *assoc_id = asoc->assoc_id; in __sctp_connect()
1277 * returns -1, and sets errno to the appropriate error code. The assoc_id
1284 * an endpoint that is multi-homed. Much like sctp_bindx() this call
1320 return -EINVAL; in __sctp_setsockopt_connectx()
1329 /* in-kernel sockets don't generally have a file allocated to them in __sctp_setsockopt_connectx()
1332 if (sk->sk_socket->file) in __sctp_setsockopt_connectx()
1333 flags = sk->sk_socket->file->f_flags; in __sctp_setsockopt_connectx()
1372 * We use the sctp_getaddrs_old structure so that use-space library
1375 * addrs_num structure member. That way we can re-use the existing
1400 return -EINVAL; in sctp_getsockopt_connectx3()
1402 return -EFAULT; in sctp_getsockopt_connectx3()
1411 return -EINVAL; in sctp_getsockopt_connectx3()
1413 return -EFAULT; in sctp_getsockopt_connectx3()
1422 if (err == 0 || err == -EINPROGRESS) { in sctp_getsockopt_connectx3()
1424 return -EFAULT; in sctp_getsockopt_connectx3()
1426 return -EFAULT; in sctp_getsockopt_connectx3()
1432 /* API 3.1.4 close() - UDP Style Syntax
1435 * by a UDP-style socket.
1441 * sd - the socket descriptor of the associations to be closed.
1444 * UDP-style socket, an application should use the sendmsg() call,
1448 * If sd in the close() call is a branched-off socket representing only
1451 * 4.1.6 close() - TCP Style Syntax
1459 * sd - the socket descriptor of the association to be closed.
1466 * An application using the TCP-style socket can use this option to
1493 sk->sk_shutdown = SHUTDOWN_MASK; in sctp_close()
1496 ep = sctp_sk(sk)->ep; in sctp_close()
1499 data_was_unread = sctp_queue_purge_ulpevents(&sk->sk_receive_queue); in sctp_close()
1500 data_was_unread += sctp_queue_purge_ulpevents(&sctp_sk(sk)->pd_lobby); in sctp_close()
1503 list_for_each_safe(pos, temp, &ep->asocs) { in sctp_close()
1508 * it belongs to a TCP-style listening socket that is in sctp_close()
1518 if (data_was_unread || !skb_queue_empty(&asoc->ulpq.lobby) || in sctp_close()
1519 !skb_queue_empty(&asoc->ulpq.reasm) || in sctp_close()
1520 !skb_queue_empty(&asoc->ulpq.reasm_uo) || in sctp_close()
1521 (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime)) { in sctp_close()
1530 /* On a TCP-style socket, block for at most linger_time if set. */ in sctp_close()
1542 spin_lock_bh(&net->sctp.addr_wq_lock); in sctp_close()
1552 spin_unlock_bh(&net->sctp.addr_wq_lock); in sctp_close()
1562 if (err == -EPIPE) in sctp_error()
1563 err = sock_error(sk) ? : -EPIPE; in sctp_error()
1564 if (err == -EPIPE && !(flags & MSG_NOSIGNAL)) in sctp_error()
1569 /* API 3.1.3 sendmsg() - UDP Style Syntax
1577 * socket - the socket descriptor of the endpoint.
1578 * message - pointer to the msghdr structure which contains a single
1584 * flags - flags sent or received with the user message, see Section
1603 return -EPIPE; in sctp_sendmsg_parse()
1605 if (msg_len > sk->sk_sndbuf) in sctp_sendmsg_parse()
1606 return -EMSGSIZE; in sctp_sendmsg_parse()
1616 if (cmsgs->srinfo) { in sctp_sendmsg_parse()
1617 srinfo->sinfo_stream = cmsgs->srinfo->sinfo_stream; in sctp_sendmsg_parse()
1618 srinfo->sinfo_flags = cmsgs->srinfo->sinfo_flags; in sctp_sendmsg_parse()
1619 srinfo->sinfo_ppid = cmsgs->srinfo->sinfo_ppid; in sctp_sendmsg_parse()
1620 srinfo->sinfo_context = cmsgs->srinfo->sinfo_context; in sctp_sendmsg_parse()
1621 srinfo->sinfo_assoc_id = cmsgs->srinfo->sinfo_assoc_id; in sctp_sendmsg_parse()
1622 srinfo->sinfo_timetolive = cmsgs->srinfo->sinfo_timetolive; in sctp_sendmsg_parse()
1625 if (cmsgs->sinfo) { in sctp_sendmsg_parse()
1626 srinfo->sinfo_stream = cmsgs->sinfo->snd_sid; in sctp_sendmsg_parse()
1627 srinfo->sinfo_flags = cmsgs->sinfo->snd_flags; in sctp_sendmsg_parse()
1628 srinfo->sinfo_ppid = cmsgs->sinfo->snd_ppid; in sctp_sendmsg_parse()
1629 srinfo->sinfo_context = cmsgs->sinfo->snd_context; in sctp_sendmsg_parse()
1630 srinfo->sinfo_assoc_id = cmsgs->sinfo->snd_assoc_id; in sctp_sendmsg_parse()
1633 if (cmsgs->prinfo) { in sctp_sendmsg_parse()
1634 srinfo->sinfo_timetolive = cmsgs->prinfo->pr_value; in sctp_sendmsg_parse()
1635 SCTP_PR_SET_POLICY(srinfo->sinfo_flags, in sctp_sendmsg_parse()
1636 cmsgs->prinfo->pr_policy); in sctp_sendmsg_parse()
1639 sflags = srinfo->sinfo_flags; in sctp_sendmsg_parse()
1644 return -EINVAL; in sctp_sendmsg_parse()
1648 return -EINVAL; in sctp_sendmsg_parse()
1650 if ((sflags & SCTP_ADDR_OVER) && !msg->msg_name) in sctp_sendmsg_parse()
1651 return -EINVAL; in sctp_sendmsg_parse()
1661 struct sctp_endpoint *ep = sctp_sk(sk)->ep; in sctp_sendmsg_new_asoc()
1671 return -EINVAL; in sctp_sendmsg_new_asoc()
1675 return -EADDRNOTAVAIL; in sctp_sendmsg_new_asoc()
1677 /* Label connection socket for first association 1-to-many in sctp_sendmsg_new_asoc()
1678 * style for client sequence socket()->sendmsg(). This in sctp_sendmsg_new_asoc()
1683 af = sctp_get_af_specific(daddr->sa.sa_family); in sctp_sendmsg_new_asoc()
1685 return -EINVAL; in sctp_sendmsg_new_asoc()
1688 af->sockaddr_len); in sctp_sendmsg_new_asoc()
1692 err = sctp_connect_new_asoc(ep, daddr, cmsgs->init, tp); in sctp_sendmsg_new_asoc()
1695 asoc = (*tp)->asoc; in sctp_sendmsg_new_asoc()
1697 if (!cmsgs->addrs_msg) in sctp_sendmsg_new_asoc()
1700 if (daddr->sa.sa_family == AF_INET6) in sctp_sendmsg_new_asoc()
1701 flowinfo = daddr->v6.sin6_flowinfo; in sctp_sendmsg_new_asoc()
1704 for_each_cmsghdr(cmsg, cmsgs->addrs_msg) { in sctp_sendmsg_new_asoc()
1708 if (cmsg->cmsg_level != IPPROTO_SCTP || in sctp_sendmsg_new_asoc()
1709 (cmsg->cmsg_type != SCTP_DSTADDRV4 && in sctp_sendmsg_new_asoc()
1710 cmsg->cmsg_type != SCTP_DSTADDRV6)) in sctp_sendmsg_new_asoc()
1715 dlen = cmsg->cmsg_len - sizeof(struct cmsghdr); in sctp_sendmsg_new_asoc()
1716 if (cmsg->cmsg_type == SCTP_DSTADDRV4) { in sctp_sendmsg_new_asoc()
1718 err = -EINVAL; in sctp_sendmsg_new_asoc()
1723 daddr->v4.sin_family = AF_INET; in sctp_sendmsg_new_asoc()
1724 daddr->v4.sin_port = htons(asoc->peer.port); in sctp_sendmsg_new_asoc()
1725 memcpy(&daddr->v4.sin_addr, CMSG_DATA(cmsg), dlen); in sctp_sendmsg_new_asoc()
1728 err = -EINVAL; in sctp_sendmsg_new_asoc()
1733 daddr->v6.sin6_flowinfo = flowinfo; in sctp_sendmsg_new_asoc()
1734 daddr->v6.sin6_family = AF_INET6; in sctp_sendmsg_new_asoc()
1735 daddr->v6.sin6_port = htons(asoc->peer.port); in sctp_sendmsg_new_asoc()
1736 memcpy(&daddr->v6.sin6_addr, CMSG_DATA(cmsg), dlen); in sctp_sendmsg_new_asoc()
1755 struct sock *sk = asoc->base.sk; in sctp_sendmsg_check_sflags()
1759 return -EPIPE; in sctp_sendmsg_check_sflags()
1777 return -ENOMEM; in sctp_sendmsg_check_sflags()
1781 iov_iter_revert(&msg->msg_iter, msg_len); in sctp_sendmsg_check_sflags()
1794 struct sock *sk = asoc->base.sk; in sctp_sendmsg_to_asoc()
1803 if (sinfo->sinfo_stream >= asoc->stream.outcnt) { in sctp_sendmsg_to_asoc()
1804 err = -EINVAL; in sctp_sendmsg_to_asoc()
1808 if (unlikely(!SCTP_SO(&asoc->stream, sinfo->sinfo_stream)->ext)) { in sctp_sendmsg_to_asoc()
1809 err = sctp_stream_init_ext(&asoc->stream, sinfo->sinfo_stream); in sctp_sendmsg_to_asoc()
1814 if (sp->disable_fragments && msg_len > asoc->frag_point) { in sctp_sendmsg_to_asoc()
1815 err = -EMSGSIZE; in sctp_sendmsg_to_asoc()
1819 if (asoc->pmtu_pending) { in sctp_sendmsg_to_asoc()
1820 if (sp->param_flags & SPP_PMTUD_ENABLE) in sctp_sendmsg_to_asoc()
1822 asoc->pmtu_pending = 0; in sctp_sendmsg_to_asoc()
1826 sctp_prsctp_prune(asoc, sinfo, msg_len - sctp_wspace(asoc)); in sctp_sendmsg_to_asoc()
1829 timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT); in sctp_sendmsg_to_asoc()
1833 if (unlikely(sinfo->sinfo_stream >= asoc->stream.outcnt)) { in sctp_sendmsg_to_asoc()
1834 err = -EINVAL; in sctp_sendmsg_to_asoc()
1844 if (asoc->ep->intl_enable) { in sctp_sendmsg_to_asoc()
1848 err = -ESRCH; in sctp_sendmsg_to_asoc()
1858 datamsg = sctp_datamsg_from_user(asoc, sinfo, &msg->msg_iter); in sctp_sendmsg_to_asoc()
1864 asoc->force_delay = !!(msg->msg_flags & MSG_MORE); in sctp_sendmsg_to_asoc()
1866 list_for_each_entry(chunk, &datamsg->chunks, frag_list) { in sctp_sendmsg_to_asoc()
1869 chunk->transport = transport; in sctp_sendmsg_to_asoc()
1883 timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT); in sctp_sendmsg_to_asoc()
1900 if (!sctp_style(sk, UDP_HIGH_BANDWIDTH) && msg->msg_name) { in sctp_sendmsg_get_daddr()
1901 int len = msg->msg_namelen; in sctp_sendmsg_get_daddr()
1906 daddr = (union sctp_addr *)msg->msg_name; in sctp_sendmsg_get_daddr()
1920 if (!cmsgs->srinfo && !cmsgs->sinfo) { in sctp_sendmsg_update_sinfo()
1921 sinfo->sinfo_stream = asoc->default_stream; in sctp_sendmsg_update_sinfo()
1922 sinfo->sinfo_ppid = asoc->default_ppid; in sctp_sendmsg_update_sinfo()
1923 sinfo->sinfo_context = asoc->default_context; in sctp_sendmsg_update_sinfo()
1924 sinfo->sinfo_assoc_id = sctp_assoc2id(asoc); in sctp_sendmsg_update_sinfo()
1926 if (!cmsgs->prinfo) in sctp_sendmsg_update_sinfo()
1927 sinfo->sinfo_flags = asoc->default_flags; in sctp_sendmsg_update_sinfo()
1930 if (!cmsgs->srinfo && !cmsgs->prinfo) in sctp_sendmsg_update_sinfo()
1931 sinfo->sinfo_timetolive = asoc->default_timetolive; in sctp_sendmsg_update_sinfo()
1933 if (cmsgs->authinfo) { in sctp_sendmsg_update_sinfo()
1937 sinfo->sinfo_tsn = 1; in sctp_sendmsg_update_sinfo()
1938 sinfo->sinfo_ssn = cmsgs->authinfo->auth_keynumber; in sctp_sendmsg_update_sinfo()
1944 struct sctp_endpoint *ep = sctp_sk(sk)->ep; in sctp_sendmsg()
1960 sflags = sinfo->sinfo_flags; in sctp_sendmsg()
1973 list_for_each_entry_safe(asoc, tmp, &ep->asocs, asocs) { in sctp_sendmsg()
1988 iov_iter_revert(&msg->msg_iter, err); in sctp_sendmsg()
2008 asoc = transport->asoc; in sctp_sendmsg()
2015 asoc = sctp_id2assoc(sk, sinfo->sinfo_assoc_id); in sctp_sendmsg()
2017 err = -EPIPE; in sctp_sendmsg()
2031 if (err < 0 && err != -ESRCH && new) in sctp_sendmsg()
2037 return sctp_error(sk, msg->msg_flags, err); in sctp_sendmsg()
2057 len -= skb_len; in sctp_skb_pull()
2062 skb->len -= (len-rlen); in sctp_skb_pull()
2063 skb->data_len -= (len-rlen); in sctp_skb_pull()
2074 /* API 3.1.3 recvmsg() - UDP Style Syntax
2079 * socket - the socket descriptor of the endpoint.
2080 * message - pointer to the msghdr structure which contains a single
2086 * flags - flags sent or received with the user message, see Section
2106 err = -ENOTCONN; in sctp_recvmsg()
2117 skb_len = skb->len; in sctp_recvmsg()
2130 if (event->chunk && event->chunk->head_skb) in sctp_recvmsg()
2131 head_skb = event->chunk->head_skb; in sctp_recvmsg()
2136 msg->msg_flags |= MSG_NOTIFICATION; in sctp_recvmsg()
2137 sp->pf->event_msgname(event, msg->msg_name, addr_len); in sctp_recvmsg()
2139 sp->pf->skb_msgname(head_skb, msg->msg_name, addr_len); in sctp_recvmsg()
2143 if (sp->recvnxtinfo) in sctp_recvmsg()
2146 if (sp->recvrcvinfo) in sctp_recvmsg()
2149 if (sctp_ulpevent_type_enabled(sp->subscribe, SCTP_DATA_IO_EVENT)) in sctp_recvmsg()
2159 msg->msg_flags &= ~MSG_EOR; in sctp_recvmsg()
2163 skb_queue_head(&sk->sk_receive_queue, skb); in sctp_recvmsg()
2170 sctp_assoc_rwnd_increase(event->asoc, copied); in sctp_recvmsg()
2172 } else if ((event->msg_flags & MSG_NOTIFICATION) || in sctp_recvmsg()
2173 (event->msg_flags & MSG_EOR)) in sctp_recvmsg()
2174 msg->msg_flags |= MSG_EOR; in sctp_recvmsg()
2176 msg->msg_flags &= ~MSG_EOR; in sctp_recvmsg()
2207 return -EINVAL; in sctp_setsockopt_disable_fragments()
2208 sctp_sk(sk)->disable_fragments = (*val == 0) ? 0 : 1; in sctp_setsockopt_disable_fragments()
2220 return -EINVAL; in sctp_setsockopt_events()
2223 sctp_ulpevent_type_set(&sp->subscribe, SCTP_SN_TYPE_BASE + i, in sctp_setsockopt_events()
2226 list_for_each_entry(asoc, &sp->ep->asocs, asocs) in sctp_setsockopt_events()
2227 asoc->subscribe = sctp_sk(sk)->subscribe; in sctp_setsockopt_events()
2233 if (sctp_ulpevent_type_enabled(sp->subscribe, SCTP_SENDER_DRY_EVENT)) { in sctp_setsockopt_events()
2237 if (asoc && sctp_outq_is_empty(&asoc->outqueue)) { in sctp_setsockopt_events()
2241 return -ENOMEM; in sctp_setsockopt_events()
2243 asoc->stream.si->enqueue_event(&asoc->ulpq, event); in sctp_setsockopt_events()
2252 * This socket option is applicable to the UDP-style socket only. When
2267 /* Applicable to UDP-style socket only */ in sctp_setsockopt_autoclose()
2269 return -EOPNOTSUPP; in sctp_setsockopt_autoclose()
2271 return -EINVAL; in sctp_setsockopt_autoclose()
2273 sp->autoclose = *optval; in sctp_setsockopt_autoclose()
2274 if (sp->autoclose > net->sctp.max_autoclose) in sctp_setsockopt_autoclose()
2275 sp->autoclose = net->sctp.max_autoclose; in sctp_setsockopt_autoclose()
2301 * spp_assoc_id - (one-to-many style socket) This is filled in the
2304 * spp_address - This specifies which address is of interest.
2305 * spp_hbinterval - This contains the value of the heartbeat interval,
2309 * spp_pathmaxrxt - This contains the maximum number of
2314 * spp_pathmtu - When Path MTU discovery is disabled the value
2320 * spp_sackdelay - When delayed sack is enabled, this value specifies
2328 * spp_flags - These flags are used to control various features
2332 * SPP_HB_ENABLE - Enable heartbeats on the
2337 * SPP_HB_DISABLE - Disable heartbeats on the
2340 * will have their heartbeats disabled. Note also
2346 * SPP_HB_DEMAND - Request a user initiated heartbeat
2349 * SPP_HB_TIME_IS_ZERO - Specify's that the time for
2353 * SPP_PMTUD_ENABLE - This field will enable PMTU
2358 * SPP_PMTUD_DISABLE - This field will disable PMTU
2366 * SPP_SACKDELAY_ENABLE - Setting this flag turns
2372 * SPP_SACKDELAY_DISABLE - Setting this flag turns
2374 * delayed sack is disabled for the entire association. Note
2390 * returned. For non-IPv6 sockets, this flag will be left
2407 * - This field is used in conjunction with the
2410 * label. This setting has precedence over any IPv6-layer
2413 * spp_dscp - This field is used in conjunction with the SPP_DSCP flag
2416 * IPv4- or IPv6- layer setting.
2428 if (params->spp_flags & SPP_HB_DEMAND && trans) { in sctp_apply_peer_addr_params()
2429 error = sctp_primitive_REQUESTHEARTBEAT(trans->asoc->base.net, in sctp_apply_peer_addr_params()
2430 trans->asoc, trans); in sctp_apply_peer_addr_params()
2439 if (params->spp_flags & SPP_HB_ENABLE) { in sctp_apply_peer_addr_params()
2441 /* Re-zero the interval if the SPP_HB_TIME_IS_ZERO is in sctp_apply_peer_addr_params()
2445 if (params->spp_flags & SPP_HB_TIME_IS_ZERO) in sctp_apply_peer_addr_params()
2446 params->spp_hbinterval = 0; in sctp_apply_peer_addr_params()
2448 if (params->spp_hbinterval || in sctp_apply_peer_addr_params()
2449 (params->spp_flags & SPP_HB_TIME_IS_ZERO)) { in sctp_apply_peer_addr_params()
2451 trans->hbinterval = in sctp_apply_peer_addr_params()
2452 msecs_to_jiffies(params->spp_hbinterval); in sctp_apply_peer_addr_params()
2455 asoc->hbinterval = in sctp_apply_peer_addr_params()
2456 msecs_to_jiffies(params->spp_hbinterval); in sctp_apply_peer_addr_params()
2458 sp->hbinterval = params->spp_hbinterval; in sctp_apply_peer_addr_params()
2465 trans->param_flags = in sctp_apply_peer_addr_params()
2466 (trans->param_flags & ~SPP_HB) | hb_change; in sctp_apply_peer_addr_params()
2468 asoc->param_flags = in sctp_apply_peer_addr_params()
2469 (asoc->param_flags & ~SPP_HB) | hb_change; in sctp_apply_peer_addr_params()
2471 sp->param_flags = in sctp_apply_peer_addr_params()
2472 (sp->param_flags & ~SPP_HB) | hb_change; in sctp_apply_peer_addr_params()
2476 /* When Path MTU discovery is disabled the value specified here will in sctp_apply_peer_addr_params()
2481 if ((params->spp_flags & SPP_PMTUD_DISABLE) && params->spp_pathmtu) { in sctp_apply_peer_addr_params()
2483 trans->pathmtu = params->spp_pathmtu; in sctp_apply_peer_addr_params()
2486 sctp_assoc_set_pmtu(asoc, params->spp_pathmtu); in sctp_apply_peer_addr_params()
2488 sp->pathmtu = params->spp_pathmtu; in sctp_apply_peer_addr_params()
2494 int update = (trans->param_flags & SPP_PMTUD_DISABLE) && in sctp_apply_peer_addr_params()
2495 (params->spp_flags & SPP_PMTUD_ENABLE); in sctp_apply_peer_addr_params()
2496 trans->param_flags = in sctp_apply_peer_addr_params()
2497 (trans->param_flags & ~SPP_PMTUD) | pmtud_change; in sctp_apply_peer_addr_params()
2504 asoc->param_flags = in sctp_apply_peer_addr_params()
2505 (asoc->param_flags & ~SPP_PMTUD) | pmtud_change; in sctp_apply_peer_addr_params()
2507 sp->param_flags = in sctp_apply_peer_addr_params()
2508 (sp->param_flags & ~SPP_PMTUD) | pmtud_change; in sctp_apply_peer_addr_params()
2516 if ((params->spp_flags & SPP_SACKDELAY_ENABLE) && params->spp_sackdelay) { in sctp_apply_peer_addr_params()
2518 trans->sackdelay = in sctp_apply_peer_addr_params()
2519 msecs_to_jiffies(params->spp_sackdelay); in sctp_apply_peer_addr_params()
2521 asoc->sackdelay = in sctp_apply_peer_addr_params()
2522 msecs_to_jiffies(params->spp_sackdelay); in sctp_apply_peer_addr_params()
2524 sp->sackdelay = params->spp_sackdelay; in sctp_apply_peer_addr_params()
2530 trans->param_flags = in sctp_apply_peer_addr_params()
2531 (trans->param_flags & ~SPP_SACKDELAY) | in sctp_apply_peer_addr_params()
2534 asoc->param_flags = in sctp_apply_peer_addr_params()
2535 (asoc->param_flags & ~SPP_SACKDELAY) | in sctp_apply_peer_addr_params()
2538 sp->param_flags = in sctp_apply_peer_addr_params()
2539 (sp->param_flags & ~SPP_SACKDELAY) | in sctp_apply_peer_addr_params()
2547 if (params->spp_pathmaxrxt) { in sctp_apply_peer_addr_params()
2549 trans->pathmaxrxt = params->spp_pathmaxrxt; in sctp_apply_peer_addr_params()
2551 asoc->pathmaxrxt = params->spp_pathmaxrxt; in sctp_apply_peer_addr_params()
2553 sp->pathmaxrxt = params->spp_pathmaxrxt; in sctp_apply_peer_addr_params()
2557 if (params->spp_flags & SPP_IPV6_FLOWLABEL) { in sctp_apply_peer_addr_params()
2559 if (trans->ipaddr.sa.sa_family == AF_INET6) { in sctp_apply_peer_addr_params()
2560 trans->flowlabel = params->spp_ipv6_flowlabel & in sctp_apply_peer_addr_params()
2562 trans->flowlabel |= SCTP_FLOWLABEL_SET_MASK; in sctp_apply_peer_addr_params()
2567 list_for_each_entry(t, &asoc->peer.transport_addr_list, in sctp_apply_peer_addr_params()
2569 if (t->ipaddr.sa.sa_family != AF_INET6) in sctp_apply_peer_addr_params()
2571 t->flowlabel = params->spp_ipv6_flowlabel & in sctp_apply_peer_addr_params()
2573 t->flowlabel |= SCTP_FLOWLABEL_SET_MASK; in sctp_apply_peer_addr_params()
2575 asoc->flowlabel = params->spp_ipv6_flowlabel & in sctp_apply_peer_addr_params()
2577 asoc->flowlabel |= SCTP_FLOWLABEL_SET_MASK; in sctp_apply_peer_addr_params()
2578 } else if (sctp_opt2sk(sp)->sk_family == AF_INET6) { in sctp_apply_peer_addr_params()
2579 sp->flowlabel = params->spp_ipv6_flowlabel & in sctp_apply_peer_addr_params()
2581 sp->flowlabel |= SCTP_FLOWLABEL_SET_MASK; in sctp_apply_peer_addr_params()
2585 if (params->spp_flags & SPP_DSCP) { in sctp_apply_peer_addr_params()
2587 trans->dscp = params->spp_dscp & SCTP_DSCP_VAL_MASK; in sctp_apply_peer_addr_params()
2588 trans->dscp |= SCTP_DSCP_SET_MASK; in sctp_apply_peer_addr_params()
2592 list_for_each_entry(t, &asoc->peer.transport_addr_list, in sctp_apply_peer_addr_params()
2594 t->dscp = params->spp_dscp & in sctp_apply_peer_addr_params()
2596 t->dscp |= SCTP_DSCP_SET_MASK; in sctp_apply_peer_addr_params()
2598 asoc->dscp = params->spp_dscp & SCTP_DSCP_VAL_MASK; in sctp_apply_peer_addr_params()
2599 asoc->dscp |= SCTP_DSCP_SET_MASK; in sctp_apply_peer_addr_params()
2601 sp->dscp = params->spp_dscp & SCTP_DSCP_VAL_MASK; in sctp_apply_peer_addr_params()
2602 sp->dscp |= SCTP_DSCP_SET_MASK; in sctp_apply_peer_addr_params()
2621 if (params->spp_flags & (SPP_DSCP | SPP_IPV6_FLOWLABEL)) in sctp_setsockopt_peer_addr_params()
2622 return -EINVAL; in sctp_setsockopt_peer_addr_params()
2624 return -EINVAL; in sctp_setsockopt_peer_addr_params()
2628 hb_change = params->spp_flags & SPP_HB; in sctp_setsockopt_peer_addr_params()
2629 pmtud_change = params->spp_flags & SPP_PMTUD; in sctp_setsockopt_peer_addr_params()
2630 sackdelay_change = params->spp_flags & SPP_SACKDELAY; in sctp_setsockopt_peer_addr_params()
2635 params->spp_sackdelay > 500 || in sctp_setsockopt_peer_addr_params()
2636 (params->spp_pathmtu && in sctp_setsockopt_peer_addr_params()
2637 params->spp_pathmtu < SCTP_DEFAULT_MINSEGMENT)) in sctp_setsockopt_peer_addr_params()
2638 return -EINVAL; in sctp_setsockopt_peer_addr_params()
2643 if (!sctp_is_any(sk, (union sctp_addr *)¶ms->spp_address)) { in sctp_setsockopt_peer_addr_params()
2644 trans = sctp_addr_id2transport(sk, ¶ms->spp_address, in sctp_setsockopt_peer_addr_params()
2645 params->spp_assoc_id); in sctp_setsockopt_peer_addr_params()
2647 return -EINVAL; in sctp_setsockopt_peer_addr_params()
2654 asoc = sctp_id2assoc(sk, params->spp_assoc_id); in sctp_setsockopt_peer_addr_params()
2655 if (!asoc && params->spp_assoc_id != SCTP_FUTURE_ASSOC && in sctp_setsockopt_peer_addr_params()
2657 return -EINVAL; in sctp_setsockopt_peer_addr_params()
2662 if (params->spp_flags & SPP_HB_DEMAND && !trans && !asoc) in sctp_setsockopt_peer_addr_params()
2663 return -EINVAL; in sctp_setsockopt_peer_addr_params()
2677 list_for_each_entry(trans, &asoc->peer.transport_addr_list, in sctp_setsockopt_peer_addr_params()
2703 if (params->sack_delay) { in sctp_apply_asoc_delayed_ack()
2704 asoc->sackdelay = msecs_to_jiffies(params->sack_delay); in sctp_apply_asoc_delayed_ack()
2705 asoc->param_flags = in sctp_apply_asoc_delayed_ack()
2706 sctp_spp_sackdelay_enable(asoc->param_flags); in sctp_apply_asoc_delayed_ack()
2708 if (params->sack_freq == 1) { in sctp_apply_asoc_delayed_ack()
2709 asoc->param_flags = in sctp_apply_asoc_delayed_ack()
2710 sctp_spp_sackdelay_disable(asoc->param_flags); in sctp_apply_asoc_delayed_ack()
2711 } else if (params->sack_freq > 1) { in sctp_apply_asoc_delayed_ack()
2712 asoc->sackfreq = params->sack_freq; in sctp_apply_asoc_delayed_ack()
2713 asoc->param_flags = in sctp_apply_asoc_delayed_ack()
2714 sctp_spp_sackdelay_enable(asoc->param_flags); in sctp_apply_asoc_delayed_ack()
2717 list_for_each_entry(trans, &asoc->peer.transport_addr_list, in sctp_apply_asoc_delayed_ack()
2719 if (params->sack_delay) { in sctp_apply_asoc_delayed_ack()
2720 trans->sackdelay = msecs_to_jiffies(params->sack_delay); in sctp_apply_asoc_delayed_ack()
2721 trans->param_flags = in sctp_apply_asoc_delayed_ack()
2722 sctp_spp_sackdelay_enable(trans->param_flags); in sctp_apply_asoc_delayed_ack()
2724 if (params->sack_freq == 1) { in sctp_apply_asoc_delayed_ack()
2725 trans->param_flags = in sctp_apply_asoc_delayed_ack()
2726 sctp_spp_sackdelay_disable(trans->param_flags); in sctp_apply_asoc_delayed_ack()
2727 } else if (params->sack_freq > 1) { in sctp_apply_asoc_delayed_ack()
2728 trans->sackfreq = params->sack_freq; in sctp_apply_asoc_delayed_ack()
2729 trans->param_flags = in sctp_apply_asoc_delayed_ack()
2730 sctp_spp_sackdelay_enable(trans->param_flags); in sctp_apply_asoc_delayed_ack()
2743 * values. If the assoc_id field is non-zero, then the set or get
2755 * sack_assoc_id - This parameter, indicates which association the user
2760 * sack_delay - This parameter contains the number of milliseconds that
2765 * sack_freq - This parameter contains the number of packets that must
2777 if (params->sack_delay > 500) in __sctp_setsockopt_delayed_ack()
2778 return -EINVAL; in __sctp_setsockopt_delayed_ack()
2784 asoc = sctp_id2assoc(sk, params->sack_assoc_id); in __sctp_setsockopt_delayed_ack()
2785 if (!asoc && params->sack_assoc_id > SCTP_ALL_ASSOC && in __sctp_setsockopt_delayed_ack()
2787 return -EINVAL; in __sctp_setsockopt_delayed_ack()
2796 params->sack_assoc_id = SCTP_FUTURE_ASSOC; in __sctp_setsockopt_delayed_ack()
2798 if (params->sack_assoc_id == SCTP_FUTURE_ASSOC || in __sctp_setsockopt_delayed_ack()
2799 params->sack_assoc_id == SCTP_ALL_ASSOC) { in __sctp_setsockopt_delayed_ack()
2800 if (params->sack_delay) { in __sctp_setsockopt_delayed_ack()
2801 sp->sackdelay = params->sack_delay; in __sctp_setsockopt_delayed_ack()
2802 sp->param_flags = in __sctp_setsockopt_delayed_ack()
2803 sctp_spp_sackdelay_enable(sp->param_flags); in __sctp_setsockopt_delayed_ack()
2805 if (params->sack_freq == 1) { in __sctp_setsockopt_delayed_ack()
2806 sp->param_flags = in __sctp_setsockopt_delayed_ack()
2807 sctp_spp_sackdelay_disable(sp->param_flags); in __sctp_setsockopt_delayed_ack()
2808 } else if (params->sack_freq > 1) { in __sctp_setsockopt_delayed_ack()
2809 sp->sackfreq = params->sack_freq; in __sctp_setsockopt_delayed_ack()
2810 sp->param_flags = in __sctp_setsockopt_delayed_ack()
2811 sctp_spp_sackdelay_enable(sp->param_flags); in __sctp_setsockopt_delayed_ack()
2815 if (params->sack_assoc_id == SCTP_CURRENT_ASSOC || in __sctp_setsockopt_delayed_ack()
2816 params->sack_assoc_id == SCTP_ALL_ASSOC) in __sctp_setsockopt_delayed_ack()
2817 list_for_each_entry(asoc, &sp->ep->asocs, asocs) in __sctp_setsockopt_delayed_ack()
2835 current->comm, task_pid_nr(current)); in sctp_setsockopt_delayed_ack()
2837 p.sack_assoc_id = v->assoc_id; in sctp_setsockopt_delayed_ack()
2838 p.sack_delay = v->assoc_value; in sctp_setsockopt_delayed_ack()
2839 p.sack_freq = v->assoc_value ? 0 : 1; in sctp_setsockopt_delayed_ack()
2844 return -EINVAL; in sctp_setsockopt_delayed_ack()
2845 if (params->sack_delay == 0 && params->sack_freq == 0) in sctp_setsockopt_delayed_ack()
2857 * socket (for UDP-style sockets only future associations are effected
2858 * by the change). With TCP-style sockets, this option is inherited by
2867 return -EINVAL; in sctp_setsockopt_initmsg()
2869 if (sinit->sinit_num_ostreams) in sctp_setsockopt_initmsg()
2870 sp->initmsg.sinit_num_ostreams = sinit->sinit_num_ostreams; in sctp_setsockopt_initmsg()
2871 if (sinit->sinit_max_instreams) in sctp_setsockopt_initmsg()
2872 sp->initmsg.sinit_max_instreams = sinit->sinit_max_instreams; in sctp_setsockopt_initmsg()
2873 if (sinit->sinit_max_attempts) in sctp_setsockopt_initmsg()
2874 sp->initmsg.sinit_max_attempts = sinit->sinit_max_attempts; in sctp_setsockopt_initmsg()
2875 if (sinit->sinit_max_init_timeo) in sctp_setsockopt_initmsg()
2876 sp->initmsg.sinit_max_init_timeo = sinit->sinit_max_init_timeo; in sctp_setsockopt_initmsg()
2903 return -EINVAL; in sctp_setsockopt_default_send_param()
2904 if (info->sinfo_flags & in sctp_setsockopt_default_send_param()
2907 return -EINVAL; in sctp_setsockopt_default_send_param()
2909 asoc = sctp_id2assoc(sk, info->sinfo_assoc_id); in sctp_setsockopt_default_send_param()
2910 if (!asoc && info->sinfo_assoc_id > SCTP_ALL_ASSOC && in sctp_setsockopt_default_send_param()
2912 return -EINVAL; in sctp_setsockopt_default_send_param()
2915 asoc->default_stream = info->sinfo_stream; in sctp_setsockopt_default_send_param()
2916 asoc->default_flags = info->sinfo_flags; in sctp_setsockopt_default_send_param()
2917 asoc->default_ppid = info->sinfo_ppid; in sctp_setsockopt_default_send_param()
2918 asoc->default_context = info->sinfo_context; in sctp_setsockopt_default_send_param()
2919 asoc->default_timetolive = info->sinfo_timetolive; in sctp_setsockopt_default_send_param()
2925 info->sinfo_assoc_id = SCTP_FUTURE_ASSOC; in sctp_setsockopt_default_send_param()
2927 if (info->sinfo_assoc_id == SCTP_FUTURE_ASSOC || in sctp_setsockopt_default_send_param()
2928 info->sinfo_assoc_id == SCTP_ALL_ASSOC) { in sctp_setsockopt_default_send_param()
2929 sp->default_stream = info->sinfo_stream; in sctp_setsockopt_default_send_param()
2930 sp->default_flags = info->sinfo_flags; in sctp_setsockopt_default_send_param()
2931 sp->default_ppid = info->sinfo_ppid; in sctp_setsockopt_default_send_param()
2932 sp->default_context = info->sinfo_context; in sctp_setsockopt_default_send_param()
2933 sp->default_timetolive = info->sinfo_timetolive; in sctp_setsockopt_default_send_param()
2936 if (info->sinfo_assoc_id == SCTP_CURRENT_ASSOC || in sctp_setsockopt_default_send_param()
2937 info->sinfo_assoc_id == SCTP_ALL_ASSOC) { in sctp_setsockopt_default_send_param()
2938 list_for_each_entry(asoc, &sp->ep->asocs, asocs) { in sctp_setsockopt_default_send_param()
2939 asoc->default_stream = info->sinfo_stream; in sctp_setsockopt_default_send_param()
2940 asoc->default_flags = info->sinfo_flags; in sctp_setsockopt_default_send_param()
2941 asoc->default_ppid = info->sinfo_ppid; in sctp_setsockopt_default_send_param()
2942 asoc->default_context = info->sinfo_context; in sctp_setsockopt_default_send_param()
2943 asoc->default_timetolive = info->sinfo_timetolive; in sctp_setsockopt_default_send_param()
2961 return -EINVAL; in sctp_setsockopt_default_sndinfo()
2962 if (info->snd_flags & in sctp_setsockopt_default_sndinfo()
2965 return -EINVAL; in sctp_setsockopt_default_sndinfo()
2967 asoc = sctp_id2assoc(sk, info->snd_assoc_id); in sctp_setsockopt_default_sndinfo()
2968 if (!asoc && info->snd_assoc_id > SCTP_ALL_ASSOC && in sctp_setsockopt_default_sndinfo()
2970 return -EINVAL; in sctp_setsockopt_default_sndinfo()
2973 asoc->default_stream = info->snd_sid; in sctp_setsockopt_default_sndinfo()
2974 asoc->default_flags = info->snd_flags; in sctp_setsockopt_default_sndinfo()
2975 asoc->default_ppid = info->snd_ppid; in sctp_setsockopt_default_sndinfo()
2976 asoc->default_context = info->snd_context; in sctp_setsockopt_default_sndinfo()
2982 info->snd_assoc_id = SCTP_FUTURE_ASSOC; in sctp_setsockopt_default_sndinfo()
2984 if (info->snd_assoc_id == SCTP_FUTURE_ASSOC || in sctp_setsockopt_default_sndinfo()
2985 info->snd_assoc_id == SCTP_ALL_ASSOC) { in sctp_setsockopt_default_sndinfo()
2986 sp->default_stream = info->snd_sid; in sctp_setsockopt_default_sndinfo()
2987 sp->default_flags = info->snd_flags; in sctp_setsockopt_default_sndinfo()
2988 sp->default_ppid = info->snd_ppid; in sctp_setsockopt_default_sndinfo()
2989 sp->default_context = info->snd_context; in sctp_setsockopt_default_sndinfo()
2992 if (info->snd_assoc_id == SCTP_CURRENT_ASSOC || in sctp_setsockopt_default_sndinfo()
2993 info->snd_assoc_id == SCTP_ALL_ASSOC) { in sctp_setsockopt_default_sndinfo()
2994 list_for_each_entry(asoc, &sp->ep->asocs, asocs) { in sctp_setsockopt_default_sndinfo()
2995 asoc->default_stream = info->snd_sid; in sctp_setsockopt_default_sndinfo()
2996 asoc->default_flags = info->snd_flags; in sctp_setsockopt_default_sndinfo()
2997 asoc->default_ppid = info->snd_ppid; in sctp_setsockopt_default_sndinfo()
2998 asoc->default_context = info->snd_context; in sctp_setsockopt_default_sndinfo()
3019 return -EINVAL; in sctp_setsockopt_primary_addr()
3022 af = sctp_get_af_specific(prim->ssp_addr.ss_family); in sctp_setsockopt_primary_addr()
3024 return -EINVAL; in sctp_setsockopt_primary_addr()
3027 (struct sockaddr *)&prim->ssp_addr, in sctp_setsockopt_primary_addr()
3028 af->sockaddr_len); in sctp_setsockopt_primary_addr()
3032 trans = sctp_addr_id2transport(sk, &prim->ssp_addr, prim->ssp_assoc_id); in sctp_setsockopt_primary_addr()
3034 return -EINVAL; in sctp_setsockopt_primary_addr()
3036 sctp_assoc_set_primary(trans->asoc, trans); in sctp_setsockopt_primary_addr()
3044 * Turn on/off any Nagle-like algorithm. This means that packets are
3053 return -EINVAL; in sctp_setsockopt_nodelay()
3054 sctp_sk(sk)->nodelay = (*val == 0) ? 0 : 1; in sctp_setsockopt_nodelay()
3079 return -EINVAL; in sctp_setsockopt_rtoinfo()
3081 asoc = sctp_id2assoc(sk, rtoinfo->srto_assoc_id); in sctp_setsockopt_rtoinfo()
3084 if (!asoc && rtoinfo->srto_assoc_id != SCTP_FUTURE_ASSOC && in sctp_setsockopt_rtoinfo()
3086 return -EINVAL; in sctp_setsockopt_rtoinfo()
3088 rto_max = rtoinfo->srto_max; in sctp_setsockopt_rtoinfo()
3089 rto_min = rtoinfo->srto_min; in sctp_setsockopt_rtoinfo()
3094 rto_max = asoc ? asoc->rto_max : sp->rtoinfo.srto_max; in sctp_setsockopt_rtoinfo()
3099 rto_min = asoc ? asoc->rto_min : sp->rtoinfo.srto_min; in sctp_setsockopt_rtoinfo()
3102 return -EINVAL; in sctp_setsockopt_rtoinfo()
3105 if (rtoinfo->srto_initial != 0) in sctp_setsockopt_rtoinfo()
3106 asoc->rto_initial = in sctp_setsockopt_rtoinfo()
3107 msecs_to_jiffies(rtoinfo->srto_initial); in sctp_setsockopt_rtoinfo()
3108 asoc->rto_max = rto_max; in sctp_setsockopt_rtoinfo()
3109 asoc->rto_min = rto_min; in sctp_setsockopt_rtoinfo()
3111 /* If there is no association or the association-id = 0 in sctp_setsockopt_rtoinfo()
3114 if (rtoinfo->srto_initial != 0) in sctp_setsockopt_rtoinfo()
3115 sp->rtoinfo.srto_initial = rtoinfo->srto_initial; in sctp_setsockopt_rtoinfo()
3116 sp->rtoinfo.srto_max = rto_max; in sctp_setsockopt_rtoinfo()
3117 sp->rtoinfo.srto_min = rto_min; in sctp_setsockopt_rtoinfo()
3142 return -EINVAL; in sctp_setsockopt_associnfo()
3144 asoc = sctp_id2assoc(sk, assocparams->sasoc_assoc_id); in sctp_setsockopt_associnfo()
3146 if (!asoc && assocparams->sasoc_assoc_id != SCTP_FUTURE_ASSOC && in sctp_setsockopt_associnfo()
3148 return -EINVAL; in sctp_setsockopt_associnfo()
3152 if (assocparams->sasoc_asocmaxrxt != 0) { in sctp_setsockopt_associnfo()
3157 list_for_each_entry(peer_addr, &asoc->peer.transport_addr_list, in sctp_setsockopt_associnfo()
3159 path_sum += peer_addr->pathmaxrxt; in sctp_setsockopt_associnfo()
3169 assocparams->sasoc_asocmaxrxt > path_sum) in sctp_setsockopt_associnfo()
3170 return -EINVAL; in sctp_setsockopt_associnfo()
3172 asoc->max_retrans = assocparams->sasoc_asocmaxrxt; in sctp_setsockopt_associnfo()
3175 if (assocparams->sasoc_cookie_life != 0) in sctp_setsockopt_associnfo()
3176 asoc->cookie_life = in sctp_setsockopt_associnfo()
3177 ms_to_ktime(assocparams->sasoc_cookie_life); in sctp_setsockopt_associnfo()
3182 if (assocparams->sasoc_asocmaxrxt != 0) in sctp_setsockopt_associnfo()
3183 sp->assocparams.sasoc_asocmaxrxt = in sctp_setsockopt_associnfo()
3184 assocparams->sasoc_asocmaxrxt; in sctp_setsockopt_associnfo()
3185 if (assocparams->sasoc_cookie_life != 0) in sctp_setsockopt_associnfo()
3186 sp->assocparams.sasoc_cookie_life = in sctp_setsockopt_associnfo()
3187 assocparams->sasoc_cookie_life; in sctp_setsockopt_associnfo()
3208 return -EINVAL; in sctp_setsockopt_mappedv4()
3210 sp->v4mapped = 1; in sctp_setsockopt_mappedv4()
3212 sp->v4mapped = 0; in sctp_setsockopt_mappedv4()
3237 * assoc_id: This parameter is ignored for one-to-one style sockets.
3238 * For one-to-many style sockets this parameter indicates which
3258 current->comm, task_pid_nr(current)); in sctp_setsockopt_maxseg()
3262 assoc_id = params->assoc_id; in sctp_setsockopt_maxseg()
3263 val = params->assoc_value; in sctp_setsockopt_maxseg()
3265 return -EINVAL; in sctp_setsockopt_maxseg()
3271 return -EINVAL; in sctp_setsockopt_maxseg()
3275 __u16 datasize = asoc ? sctp_datachk_len(&asoc->stream) : in sctp_setsockopt_maxseg()
3279 max_len = SCTP_MAX_CHUNK_LEN - datasize; in sctp_setsockopt_maxseg()
3282 return -EINVAL; in sctp_setsockopt_maxseg()
3286 asoc->user_frag = val; in sctp_setsockopt_maxseg()
3289 sp->user_frag = val; in sctp_setsockopt_maxseg()
3316 if (!sp->ep->asconf_enable) in sctp_setsockopt_peer_primary_addr()
3317 return -EPERM; in sctp_setsockopt_peer_primary_addr()
3320 return -EINVAL; in sctp_setsockopt_peer_primary_addr()
3322 asoc = sctp_id2assoc(sk, prim->sspp_assoc_id); in sctp_setsockopt_peer_primary_addr()
3324 return -EINVAL; in sctp_setsockopt_peer_primary_addr()
3326 if (!asoc->peer.asconf_capable) in sctp_setsockopt_peer_primary_addr()
3327 return -EPERM; in sctp_setsockopt_peer_primary_addr()
3329 if (asoc->peer.addip_disabled_mask & SCTP_PARAM_SET_PRIMARY) in sctp_setsockopt_peer_primary_addr()
3330 return -EPERM; in sctp_setsockopt_peer_primary_addr()
3333 return -ENOTCONN; in sctp_setsockopt_peer_primary_addr()
3335 af = sctp_get_af_specific(prim->sspp_addr.ss_family); in sctp_setsockopt_peer_primary_addr()
3337 return -EINVAL; in sctp_setsockopt_peer_primary_addr()
3339 if (!af->addr_valid((union sctp_addr *)&prim->sspp_addr, sp, NULL)) in sctp_setsockopt_peer_primary_addr()
3340 return -EADDRNOTAVAIL; in sctp_setsockopt_peer_primary_addr()
3342 if (!sctp_assoc_lookup_laddr(asoc, (union sctp_addr *)&prim->sspp_addr)) in sctp_setsockopt_peer_primary_addr()
3343 return -EADDRNOTAVAIL; in sctp_setsockopt_peer_primary_addr()
3347 (struct sockaddr *)&prim->sspp_addr, in sctp_setsockopt_peer_primary_addr()
3348 af->sockaddr_len); in sctp_setsockopt_peer_primary_addr()
3354 (union sctp_addr *)&prim->sspp_addr); in sctp_setsockopt_peer_primary_addr()
3356 return -ENOMEM; in sctp_setsockopt_peer_primary_addr()
3370 return -EINVAL; in sctp_setsockopt_adaptation_layer()
3372 sctp_sk(sk)->adaptation_ind = adapt->ssb_adaptation_ind; in sctp_setsockopt_adaptation_layer()
3385 * one-2-many model for an application to keep some reference to an
3399 return -EINVAL; in sctp_setsockopt_context()
3401 asoc = sctp_id2assoc(sk, params->assoc_id); in sctp_setsockopt_context()
3402 if (!asoc && params->assoc_id > SCTP_ALL_ASSOC && in sctp_setsockopt_context()
3404 return -EINVAL; in sctp_setsockopt_context()
3407 asoc->default_rcv_context = params->assoc_value; in sctp_setsockopt_context()
3413 params->assoc_id = SCTP_FUTURE_ASSOC; in sctp_setsockopt_context()
3415 if (params->assoc_id == SCTP_FUTURE_ASSOC || in sctp_setsockopt_context()
3416 params->assoc_id == SCTP_ALL_ASSOC) in sctp_setsockopt_context()
3417 sp->default_rcv_context = params->assoc_value; in sctp_setsockopt_context()
3419 if (params->assoc_id == SCTP_CURRENT_ASSOC || in sctp_setsockopt_context()
3420 params->assoc_id == SCTP_ALL_ASSOC) in sctp_setsockopt_context()
3421 list_for_each_entry(asoc, &sp->ep->asocs, asocs) in sctp_setsockopt_context()
3422 asoc->default_rcv_context = params->assoc_value; in sctp_setsockopt_context()
3442 * This option takes a boolean value. A non-zero value indicates that
3455 return -EINVAL; in sctp_setsockopt_fragment_interleave()
3457 sctp_sk(sk)->frag_interleave = !!*val; in sctp_setsockopt_fragment_interleave()
3459 if (!sctp_sk(sk)->frag_interleave) in sctp_setsockopt_fragment_interleave()
3460 sctp_sk(sk)->ep->intl_enable = 0; in sctp_setsockopt_fragment_interleave()
3486 return -EINVAL; in sctp_setsockopt_partial_delivery_point()
3491 if (*val > (sk->sk_rcvbuf >> 1)) in sctp_setsockopt_partial_delivery_point()
3492 return -EINVAL; in sctp_setsockopt_partial_delivery_point()
3494 sctp_sk(sk)->pd_point = *val; in sctp_setsockopt_partial_delivery_point()
3524 current->comm, task_pid_nr(current)); in sctp_setsockopt_maxburst()
3528 assoc_id = params->assoc_id; in sctp_setsockopt_maxburst()
3529 assoc_value = params->assoc_value; in sctp_setsockopt_maxburst()
3531 return -EINVAL; in sctp_setsockopt_maxburst()
3535 return -EINVAL; in sctp_setsockopt_maxburst()
3538 asoc->max_burst = assoc_value; in sctp_setsockopt_maxburst()
3547 sp->max_burst = assoc_value; in sctp_setsockopt_maxburst()
3550 list_for_each_entry(asoc, &sp->ep->asocs, asocs) in sctp_setsockopt_maxburst()
3551 asoc->max_burst = assoc_value; in sctp_setsockopt_maxburst()
3567 struct sctp_endpoint *ep = sctp_sk(sk)->ep; in sctp_setsockopt_auth_chunk()
3569 if (!ep->auth_enable) in sctp_setsockopt_auth_chunk()
3570 return -EACCES; in sctp_setsockopt_auth_chunk()
3573 return -EINVAL; in sctp_setsockopt_auth_chunk()
3575 switch (val->sauth_chunk) { in sctp_setsockopt_auth_chunk()
3580 return -EINVAL; in sctp_setsockopt_auth_chunk()
3584 return sctp_auth_ep_add_chunkid(ep, val->sauth_chunk); in sctp_setsockopt_auth_chunk()
3597 struct sctp_endpoint *ep = sctp_sk(sk)->ep; in sctp_setsockopt_hmac_ident()
3600 if (!ep->auth_enable) in sctp_setsockopt_hmac_ident()
3601 return -EACCES; in sctp_setsockopt_hmac_ident()
3604 return -EINVAL; in sctp_setsockopt_hmac_ident()
3608 idents = hmacs->shmac_num_idents; in sctp_setsockopt_hmac_ident()
3610 (idents * sizeof(u16)) > (optlen - sizeof(struct sctp_hmacalgo))) in sctp_setsockopt_hmac_ident()
3611 return -EINVAL; in sctp_setsockopt_hmac_ident()
3626 struct sctp_endpoint *ep = sctp_sk(sk)->ep; in sctp_setsockopt_auth_key()
3628 int ret = -EINVAL; in sctp_setsockopt_auth_key()
3631 return -EINVAL; in sctp_setsockopt_auth_key()
3632 /* authkey->sca_keylength is u16, so optlen can't be bigger than in sctp_setsockopt_auth_key()
3637 if (authkey->sca_keylength > optlen - sizeof(*authkey)) in sctp_setsockopt_auth_key()
3640 asoc = sctp_id2assoc(sk, authkey->sca_assoc_id); in sctp_setsockopt_auth_key()
3641 if (!asoc && authkey->sca_assoc_id > SCTP_ALL_ASSOC && in sctp_setsockopt_auth_key()
3651 authkey->sca_assoc_id = SCTP_FUTURE_ASSOC; in sctp_setsockopt_auth_key()
3653 if (authkey->sca_assoc_id == SCTP_FUTURE_ASSOC || in sctp_setsockopt_auth_key()
3654 authkey->sca_assoc_id == SCTP_ALL_ASSOC) { in sctp_setsockopt_auth_key()
3662 if (authkey->sca_assoc_id == SCTP_CURRENT_ASSOC || in sctp_setsockopt_auth_key()
3663 authkey->sca_assoc_id == SCTP_ALL_ASSOC) { in sctp_setsockopt_auth_key()
3664 list_for_each_entry(asoc, &ep->asocs, asocs) { in sctp_setsockopt_auth_key()
3687 struct sctp_endpoint *ep = sctp_sk(sk)->ep; in sctp_setsockopt_active_key()
3692 return -EINVAL; in sctp_setsockopt_active_key()
3694 asoc = sctp_id2assoc(sk, val->scact_assoc_id); in sctp_setsockopt_active_key()
3695 if (!asoc && val->scact_assoc_id > SCTP_ALL_ASSOC && in sctp_setsockopt_active_key()
3697 return -EINVAL; in sctp_setsockopt_active_key()
3700 return sctp_auth_set_active_key(ep, asoc, val->scact_keynumber); in sctp_setsockopt_active_key()
3703 val->scact_assoc_id = SCTP_FUTURE_ASSOC; in sctp_setsockopt_active_key()
3705 if (val->scact_assoc_id == SCTP_FUTURE_ASSOC || in sctp_setsockopt_active_key()
3706 val->scact_assoc_id == SCTP_ALL_ASSOC) { in sctp_setsockopt_active_key()
3707 ret = sctp_auth_set_active_key(ep, asoc, val->scact_keynumber); in sctp_setsockopt_active_key()
3712 if (val->scact_assoc_id == SCTP_CURRENT_ASSOC || in sctp_setsockopt_active_key()
3713 val->scact_assoc_id == SCTP_ALL_ASSOC) { in sctp_setsockopt_active_key()
3714 list_for_each_entry(asoc, &ep->asocs, asocs) { in sctp_setsockopt_active_key()
3716 val->scact_keynumber); in sctp_setsockopt_active_key()
3735 struct sctp_endpoint *ep = sctp_sk(sk)->ep; in sctp_setsockopt_del_key()
3740 return -EINVAL; in sctp_setsockopt_del_key()
3742 asoc = sctp_id2assoc(sk, val->scact_assoc_id); in sctp_setsockopt_del_key()
3743 if (!asoc && val->scact_assoc_id > SCTP_ALL_ASSOC && in sctp_setsockopt_del_key()
3745 return -EINVAL; in sctp_setsockopt_del_key()
3748 return sctp_auth_del_key_id(ep, asoc, val->scact_keynumber); in sctp_setsockopt_del_key()
3751 val->scact_assoc_id = SCTP_FUTURE_ASSOC; in sctp_setsockopt_del_key()
3753 if (val->scact_assoc_id == SCTP_FUTURE_ASSOC || in sctp_setsockopt_del_key()
3754 val->scact_assoc_id == SCTP_ALL_ASSOC) { in sctp_setsockopt_del_key()
3755 ret = sctp_auth_del_key_id(ep, asoc, val->scact_keynumber); in sctp_setsockopt_del_key()
3760 if (val->scact_assoc_id == SCTP_CURRENT_ASSOC || in sctp_setsockopt_del_key()
3761 val->scact_assoc_id == SCTP_ALL_ASSOC) { in sctp_setsockopt_del_key()
3762 list_for_each_entry(asoc, &ep->asocs, asocs) { in sctp_setsockopt_del_key()
3764 val->scact_keynumber); in sctp_setsockopt_del_key()
3783 struct sctp_endpoint *ep = sctp_sk(sk)->ep; in sctp_setsockopt_deactivate_key()
3788 return -EINVAL; in sctp_setsockopt_deactivate_key()
3790 asoc = sctp_id2assoc(sk, val->scact_assoc_id); in sctp_setsockopt_deactivate_key()
3791 if (!asoc && val->scact_assoc_id > SCTP_ALL_ASSOC && in sctp_setsockopt_deactivate_key()
3793 return -EINVAL; in sctp_setsockopt_deactivate_key()
3796 return sctp_auth_deact_key_id(ep, asoc, val->scact_keynumber); in sctp_setsockopt_deactivate_key()
3799 val->scact_assoc_id = SCTP_FUTURE_ASSOC; in sctp_setsockopt_deactivate_key()
3801 if (val->scact_assoc_id == SCTP_FUTURE_ASSOC || in sctp_setsockopt_deactivate_key()
3802 val->scact_assoc_id == SCTP_ALL_ASSOC) { in sctp_setsockopt_deactivate_key()
3803 ret = sctp_auth_deact_key_id(ep, asoc, val->scact_keynumber); in sctp_setsockopt_deactivate_key()
3808 if (val->scact_assoc_id == SCTP_CURRENT_ASSOC || in sctp_setsockopt_deactivate_key()
3809 val->scact_assoc_id == SCTP_ALL_ASSOC) { in sctp_setsockopt_deactivate_key()
3810 list_for_each_entry(asoc, &ep->asocs, asocs) { in sctp_setsockopt_deactivate_key()
3812 val->scact_keynumber); in sctp_setsockopt_deactivate_key()
3831 * This option expects an integer boolean flag, where a non-zero value turns on
3842 return -EINVAL; in sctp_setsockopt_auto_asconf()
3844 return -EINVAL; in sctp_setsockopt_auto_asconf()
3845 if ((*val && sp->do_auto_asconf) || (!*val && !sp->do_auto_asconf)) in sctp_setsockopt_auto_asconf()
3848 spin_lock_bh(&sock_net(sk)->sctp.addr_wq_lock); in sctp_setsockopt_auto_asconf()
3849 if (*val == 0 && sp->do_auto_asconf) { in sctp_setsockopt_auto_asconf()
3850 list_del(&sp->auto_asconf_list); in sctp_setsockopt_auto_asconf()
3851 sp->do_auto_asconf = 0; in sctp_setsockopt_auto_asconf()
3852 } else if (*val && !sp->do_auto_asconf) { in sctp_setsockopt_auto_asconf()
3853 list_add_tail(&sp->auto_asconf_list, in sctp_setsockopt_auto_asconf()
3854 &sock_net(sk)->sctp.auto_asconf_splist); in sctp_setsockopt_auto_asconf()
3855 sp->do_auto_asconf = 1; in sctp_setsockopt_auto_asconf()
3857 spin_unlock_bh(&sock_net(sk)->sctp.addr_wq_lock); in sctp_setsockopt_auto_asconf()
3866 * http://www.ietf.org/id/draft-nishida-tsvwg-sctp-failover-05.txt
3878 return -EINVAL; in sctp_setsockopt_paddr_thresholds()
3880 if (v2 && val->spt_pathpfthld > val->spt_pathcpthld) in sctp_setsockopt_paddr_thresholds()
3881 return -EINVAL; in sctp_setsockopt_paddr_thresholds()
3883 if (!sctp_is_any(sk, (const union sctp_addr *)&val->spt_address)) { in sctp_setsockopt_paddr_thresholds()
3884 trans = sctp_addr_id2transport(sk, &val->spt_address, in sctp_setsockopt_paddr_thresholds()
3885 val->spt_assoc_id); in sctp_setsockopt_paddr_thresholds()
3887 return -ENOENT; in sctp_setsockopt_paddr_thresholds()
3889 if (val->spt_pathmaxrxt) in sctp_setsockopt_paddr_thresholds()
3890 trans->pathmaxrxt = val->spt_pathmaxrxt; in sctp_setsockopt_paddr_thresholds()
3892 trans->ps_retrans = val->spt_pathcpthld; in sctp_setsockopt_paddr_thresholds()
3893 trans->pf_retrans = val->spt_pathpfthld; in sctp_setsockopt_paddr_thresholds()
3898 asoc = sctp_id2assoc(sk, val->spt_assoc_id); in sctp_setsockopt_paddr_thresholds()
3899 if (!asoc && val->spt_assoc_id != SCTP_FUTURE_ASSOC && in sctp_setsockopt_paddr_thresholds()
3901 return -EINVAL; in sctp_setsockopt_paddr_thresholds()
3904 list_for_each_entry(trans, &asoc->peer.transport_addr_list, in sctp_setsockopt_paddr_thresholds()
3906 if (val->spt_pathmaxrxt) in sctp_setsockopt_paddr_thresholds()
3907 trans->pathmaxrxt = val->spt_pathmaxrxt; in sctp_setsockopt_paddr_thresholds()
3909 trans->ps_retrans = val->spt_pathcpthld; in sctp_setsockopt_paddr_thresholds()
3910 trans->pf_retrans = val->spt_pathpfthld; in sctp_setsockopt_paddr_thresholds()
3913 if (val->spt_pathmaxrxt) in sctp_setsockopt_paddr_thresholds()
3914 asoc->pathmaxrxt = val->spt_pathmaxrxt; in sctp_setsockopt_paddr_thresholds()
3916 asoc->ps_retrans = val->spt_pathcpthld; in sctp_setsockopt_paddr_thresholds()
3917 asoc->pf_retrans = val->spt_pathpfthld; in sctp_setsockopt_paddr_thresholds()
3921 if (val->spt_pathmaxrxt) in sctp_setsockopt_paddr_thresholds()
3922 sp->pathmaxrxt = val->spt_pathmaxrxt; in sctp_setsockopt_paddr_thresholds()
3924 sp->ps_retrans = val->spt_pathcpthld; in sctp_setsockopt_paddr_thresholds()
3925 sp->pf_retrans = val->spt_pathpfthld; in sctp_setsockopt_paddr_thresholds()
3935 return -EINVAL; in sctp_setsockopt_recvrcvinfo()
3937 sctp_sk(sk)->recvrcvinfo = (*val == 0) ? 0 : 1; in sctp_setsockopt_recvrcvinfo()
3946 return -EINVAL; in sctp_setsockopt_recvnxtinfo()
3948 sctp_sk(sk)->recvnxtinfo = (*val == 0) ? 0 : 1; in sctp_setsockopt_recvnxtinfo()
3960 return -EINVAL; in sctp_setsockopt_pr_supported()
3962 asoc = sctp_id2assoc(sk, params->assoc_id); in sctp_setsockopt_pr_supported()
3963 if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC && in sctp_setsockopt_pr_supported()
3965 return -EINVAL; in sctp_setsockopt_pr_supported()
3967 sctp_sk(sk)->ep->prsctp_enable = !!params->assoc_value; in sctp_setsockopt_pr_supported()
3978 int retval = -EINVAL; in sctp_setsockopt_default_prinfo()
3983 if (info->pr_policy & ~SCTP_PR_SCTP_MASK) in sctp_setsockopt_default_prinfo()
3986 if (info->pr_policy == SCTP_PR_SCTP_NONE) in sctp_setsockopt_default_prinfo()
3987 info->pr_value = 0; in sctp_setsockopt_default_prinfo()
3989 asoc = sctp_id2assoc(sk, info->pr_assoc_id); in sctp_setsockopt_default_prinfo()
3990 if (!asoc && info->pr_assoc_id > SCTP_ALL_ASSOC && in sctp_setsockopt_default_prinfo()
3997 SCTP_PR_SET_POLICY(asoc->default_flags, info->pr_policy); in sctp_setsockopt_default_prinfo()
3998 asoc->default_timetolive = info->pr_value; in sctp_setsockopt_default_prinfo()
4003 info->pr_assoc_id = SCTP_FUTURE_ASSOC; in sctp_setsockopt_default_prinfo()
4005 if (info->pr_assoc_id == SCTP_FUTURE_ASSOC || in sctp_setsockopt_default_prinfo()
4006 info->pr_assoc_id == SCTP_ALL_ASSOC) { in sctp_setsockopt_default_prinfo()
4007 SCTP_PR_SET_POLICY(sp->default_flags, info->pr_policy); in sctp_setsockopt_default_prinfo()
4008 sp->default_timetolive = info->pr_value; in sctp_setsockopt_default_prinfo()
4011 if (info->pr_assoc_id == SCTP_CURRENT_ASSOC || in sctp_setsockopt_default_prinfo()
4012 info->pr_assoc_id == SCTP_ALL_ASSOC) { in sctp_setsockopt_default_prinfo()
4013 list_for_each_entry(asoc, &sp->ep->asocs, asocs) { in sctp_setsockopt_default_prinfo()
4014 SCTP_PR_SET_POLICY(asoc->default_flags, in sctp_setsockopt_default_prinfo()
4015 info->pr_policy); in sctp_setsockopt_default_prinfo()
4016 asoc->default_timetolive = info->pr_value; in sctp_setsockopt_default_prinfo()
4029 int retval = -EINVAL; in sctp_setsockopt_reconfig_supported()
4034 asoc = sctp_id2assoc(sk, params->assoc_id); in sctp_setsockopt_reconfig_supported()
4035 if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC && in sctp_setsockopt_reconfig_supported()
4039 sctp_sk(sk)->ep->reconf_enable = !!params->assoc_value; in sctp_setsockopt_reconfig_supported()
4051 struct sctp_endpoint *ep = sctp_sk(sk)->ep; in sctp_setsockopt_enable_strreset()
4053 int retval = -EINVAL; in sctp_setsockopt_enable_strreset()
4058 if (params->assoc_value & (~SCTP_ENABLE_STRRESET_MASK)) in sctp_setsockopt_enable_strreset()
4061 asoc = sctp_id2assoc(sk, params->assoc_id); in sctp_setsockopt_enable_strreset()
4062 if (!asoc && params->assoc_id > SCTP_ALL_ASSOC && in sctp_setsockopt_enable_strreset()
4069 asoc->strreset_enable = params->assoc_value; in sctp_setsockopt_enable_strreset()
4074 params->assoc_id = SCTP_FUTURE_ASSOC; in sctp_setsockopt_enable_strreset()
4076 if (params->assoc_id == SCTP_FUTURE_ASSOC || in sctp_setsockopt_enable_strreset()
4077 params->assoc_id == SCTP_ALL_ASSOC) in sctp_setsockopt_enable_strreset()
4078 ep->strreset_enable = params->assoc_value; in sctp_setsockopt_enable_strreset()
4080 if (params->assoc_id == SCTP_CURRENT_ASSOC || in sctp_setsockopt_enable_strreset()
4081 params->assoc_id == SCTP_ALL_ASSOC) in sctp_setsockopt_enable_strreset()
4082 list_for_each_entry(asoc, &ep->asocs, asocs) in sctp_setsockopt_enable_strreset()
4083 asoc->strreset_enable = params->assoc_value; in sctp_setsockopt_enable_strreset()
4096 return -EINVAL; in sctp_setsockopt_reset_streams()
4101 if (params->srs_number_streams * sizeof(__u16) > in sctp_setsockopt_reset_streams()
4102 optlen - sizeof(*params)) in sctp_setsockopt_reset_streams()
4103 return -EINVAL; in sctp_setsockopt_reset_streams()
4105 asoc = sctp_id2assoc(sk, params->srs_assoc_id); in sctp_setsockopt_reset_streams()
4107 return -EINVAL; in sctp_setsockopt_reset_streams()
4118 return -EINVAL; in sctp_setsockopt_reset_assoc()
4122 return -EINVAL; in sctp_setsockopt_reset_assoc()
4134 return -EINVAL; in sctp_setsockopt_add_streams()
4136 asoc = sctp_id2assoc(sk, params->sas_assoc_id); in sctp_setsockopt_add_streams()
4138 return -EINVAL; in sctp_setsockopt_add_streams()
4152 return -EINVAL; in sctp_setsockopt_scheduler()
4154 if (params->assoc_value > SCTP_SS_MAX) in sctp_setsockopt_scheduler()
4155 return -EINVAL; in sctp_setsockopt_scheduler()
4157 asoc = sctp_id2assoc(sk, params->assoc_id); in sctp_setsockopt_scheduler()
4158 if (!asoc && params->assoc_id > SCTP_ALL_ASSOC && in sctp_setsockopt_scheduler()
4160 return -EINVAL; in sctp_setsockopt_scheduler()
4163 return sctp_sched_set_sched(asoc, params->assoc_value); in sctp_setsockopt_scheduler()
4166 params->assoc_id = SCTP_FUTURE_ASSOC; in sctp_setsockopt_scheduler()
4168 if (params->assoc_id == SCTP_FUTURE_ASSOC || in sctp_setsockopt_scheduler()
4169 params->assoc_id == SCTP_ALL_ASSOC) in sctp_setsockopt_scheduler()
4170 sp->default_ss = params->assoc_value; in sctp_setsockopt_scheduler()
4172 if (params->assoc_id == SCTP_CURRENT_ASSOC || in sctp_setsockopt_scheduler()
4173 params->assoc_id == SCTP_ALL_ASSOC) { in sctp_setsockopt_scheduler()
4174 list_for_each_entry(asoc, &sp->ep->asocs, asocs) { in sctp_setsockopt_scheduler()
4176 params->assoc_value); in sctp_setsockopt_scheduler()
4191 int retval = -EINVAL; in sctp_setsockopt_scheduler_value()
4196 asoc = sctp_id2assoc(sk, params->assoc_id); in sctp_setsockopt_scheduler_value()
4197 if (!asoc && params->assoc_id != SCTP_CURRENT_ASSOC && in sctp_setsockopt_scheduler_value()
4202 retval = sctp_sched_set_value(asoc, params->stream_id, in sctp_setsockopt_scheduler_value()
4203 params->stream_value, GFP_KERNEL); in sctp_setsockopt_scheduler_value()
4209 list_for_each_entry(asoc, &sctp_sk(sk)->ep->asocs, asocs) { in sctp_setsockopt_scheduler_value()
4210 int ret = sctp_sched_set_value(asoc, params->stream_id, in sctp_setsockopt_scheduler_value()
4211 params->stream_value, in sctp_setsockopt_scheduler_value()
4229 return -EINVAL; in sctp_setsockopt_interleaving_supported()
4231 asoc = sctp_id2assoc(sk, p->assoc_id); in sctp_setsockopt_interleaving_supported()
4232 if (!asoc && p->assoc_id != SCTP_FUTURE_ASSOC && sctp_style(sk, UDP)) in sctp_setsockopt_interleaving_supported()
4233 return -EINVAL; in sctp_setsockopt_interleaving_supported()
4235 if (!sock_net(sk)->sctp.intl_enable || !sp->frag_interleave) { in sctp_setsockopt_interleaving_supported()
4236 return -EPERM; in sctp_setsockopt_interleaving_supported()
4239 sp->ep->intl_enable = !!p->assoc_value; in sctp_setsockopt_interleaving_supported()
4247 return -EOPNOTSUPP; in sctp_setsockopt_reuse_port()
4249 if (sctp_sk(sk)->ep->base.bind_addr.port) in sctp_setsockopt_reuse_port()
4250 return -EFAULT; in sctp_setsockopt_reuse_port()
4253 return -EINVAL; in sctp_setsockopt_reuse_port()
4255 sctp_sk(sk)->reuse = !!*val; in sctp_setsockopt_reuse_port()
4265 sctp_ulpevent_type_set(&asoc->subscribe, param->se_type, param->se_on); in sctp_assoc_ulpevent_type_set()
4267 if (param->se_type == SCTP_SENDER_DRY_EVENT && param->se_on) { in sctp_assoc_ulpevent_type_set()
4268 if (sctp_outq_is_empty(&asoc->outqueue)) { in sctp_assoc_ulpevent_type_set()
4272 return -ENOMEM; in sctp_assoc_ulpevent_type_set()
4274 asoc->stream.si->enqueue_event(&asoc->ulpq, event); in sctp_assoc_ulpevent_type_set()
4289 return -EINVAL; in sctp_setsockopt_event()
4291 if (param->se_type < SCTP_SN_TYPE_BASE || in sctp_setsockopt_event()
4292 param->se_type > SCTP_SN_TYPE_MAX) in sctp_setsockopt_event()
4293 return -EINVAL; in sctp_setsockopt_event()
4295 asoc = sctp_id2assoc(sk, param->se_assoc_id); in sctp_setsockopt_event()
4296 if (!asoc && param->se_assoc_id > SCTP_ALL_ASSOC && in sctp_setsockopt_event()
4298 return -EINVAL; in sctp_setsockopt_event()
4304 param->se_assoc_id = SCTP_FUTURE_ASSOC; in sctp_setsockopt_event()
4306 if (param->se_assoc_id == SCTP_FUTURE_ASSOC || in sctp_setsockopt_event()
4307 param->se_assoc_id == SCTP_ALL_ASSOC) in sctp_setsockopt_event()
4308 sctp_ulpevent_type_set(&sp->subscribe, in sctp_setsockopt_event()
4309 param->se_type, param->se_on); in sctp_setsockopt_event()
4311 if (param->se_assoc_id == SCTP_CURRENT_ASSOC || in sctp_setsockopt_event()
4312 param->se_assoc_id == SCTP_ALL_ASSOC) { in sctp_setsockopt_event()
4313 list_for_each_entry(asoc, &sp->ep->asocs, asocs) { in sctp_setsockopt_event()
4330 int retval = -EINVAL; in sctp_setsockopt_asconf_supported()
4335 asoc = sctp_id2assoc(sk, params->assoc_id); in sctp_setsockopt_asconf_supported()
4336 if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC && in sctp_setsockopt_asconf_supported()
4340 ep = sctp_sk(sk)->ep; in sctp_setsockopt_asconf_supported()
4341 ep->asconf_enable = !!params->assoc_value; in sctp_setsockopt_asconf_supported()
4343 if (ep->asconf_enable && ep->auth_enable) { in sctp_setsockopt_asconf_supported()
4360 int retval = -EINVAL; in sctp_setsockopt_auth_supported()
4365 asoc = sctp_id2assoc(sk, params->assoc_id); in sctp_setsockopt_auth_supported()
4366 if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC && in sctp_setsockopt_auth_supported()
4370 ep = sctp_sk(sk)->ep; in sctp_setsockopt_auth_supported()
4371 if (params->assoc_value) { in sctp_setsockopt_auth_supported()
4375 if (ep->asconf_enable) { in sctp_setsockopt_auth_supported()
4381 ep->auth_enable = !!params->assoc_value; in sctp_setsockopt_auth_supported()
4393 int retval = -EINVAL; in sctp_setsockopt_ecn_supported()
4398 asoc = sctp_id2assoc(sk, params->assoc_id); in sctp_setsockopt_ecn_supported()
4399 if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC && in sctp_setsockopt_ecn_supported()
4403 sctp_sk(sk)->ep->ecn_enable = !!params->assoc_value; in sctp_setsockopt_ecn_supported()
4415 int retval = -EINVAL; in sctp_setsockopt_pf_expose()
4420 if (params->assoc_value > SCTP_PF_EXPOSE_MAX) in sctp_setsockopt_pf_expose()
4423 asoc = sctp_id2assoc(sk, params->assoc_id); in sctp_setsockopt_pf_expose()
4424 if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC && in sctp_setsockopt_pf_expose()
4429 asoc->pf_expose = params->assoc_value; in sctp_setsockopt_pf_expose()
4431 sctp_sk(sk)->pf_expose = params->assoc_value; in sctp_setsockopt_pf_expose()
4447 return -EINVAL; in sctp_setsockopt_encap_port()
4452 encap_port = (__force __be16)encap->sue_port; in sctp_setsockopt_encap_port()
4453 if (!sctp_is_any(sk, (union sctp_addr *)&encap->sue_address)) { in sctp_setsockopt_encap_port()
4454 t = sctp_addr_id2transport(sk, &encap->sue_address, in sctp_setsockopt_encap_port()
4455 encap->sue_assoc_id); in sctp_setsockopt_encap_port()
4457 return -EINVAL; in sctp_setsockopt_encap_port()
4459 t->encap_port = encap_port; in sctp_setsockopt_encap_port()
4467 asoc = sctp_id2assoc(sk, encap->sue_assoc_id); in sctp_setsockopt_encap_port()
4468 if (!asoc && encap->sue_assoc_id != SCTP_FUTURE_ASSOC && in sctp_setsockopt_encap_port()
4470 return -EINVAL; in sctp_setsockopt_encap_port()
4476 list_for_each_entry(t, &asoc->peer.transport_addr_list, in sctp_setsockopt_encap_port()
4478 t->encap_port = encap_port; in sctp_setsockopt_encap_port()
4480 asoc->encap_port = encap_port; in sctp_setsockopt_encap_port()
4484 sctp_sk(sk)->encap_port = encap_port; in sctp_setsockopt_encap_port()
4497 return -EINVAL; in sctp_setsockopt_probe_interval()
4499 probe_interval = params->spi_interval; in sctp_setsockopt_probe_interval()
4501 return -EINVAL; in sctp_setsockopt_probe_interval()
4506 if (!sctp_is_any(sk, (union sctp_addr *)¶ms->spi_address)) { in sctp_setsockopt_probe_interval()
4507 t = sctp_addr_id2transport(sk, ¶ms->spi_address, in sctp_setsockopt_probe_interval()
4508 params->spi_assoc_id); in sctp_setsockopt_probe_interval()
4510 return -EINVAL; in sctp_setsockopt_probe_interval()
4512 t->probe_interval = msecs_to_jiffies(probe_interval); in sctp_setsockopt_probe_interval()
4521 asoc = sctp_id2assoc(sk, params->spi_assoc_id); in sctp_setsockopt_probe_interval()
4522 if (!asoc && params->spi_assoc_id != SCTP_FUTURE_ASSOC && in sctp_setsockopt_probe_interval()
4524 return -EINVAL; in sctp_setsockopt_probe_interval()
4530 list_for_each_entry(t, &asoc->peer.transport_addr_list, transports) { in sctp_setsockopt_probe_interval()
4531 t->probe_interval = msecs_to_jiffies(probe_interval); in sctp_setsockopt_probe_interval()
4535 asoc->probe_interval = msecs_to_jiffies(probe_interval); in sctp_setsockopt_probe_interval()
4539 sctp_sk(sk)->probe_interval = probe_interval; in sctp_setsockopt_probe_interval()
4556 * sd - the socket descript.
4557 * level - set to IPPROTO_SCTP for all SCTP options.
4558 * optname - the option name.
4559 * optval - the buffer to store the value of the option.
4560 * optlen - the size of the buffer.
4574 * are at all well-founded. in sctp_setsockopt()
4577 struct sctp_af *af = sctp_sk(sk)->pf->af; in sctp_setsockopt()
4579 return af->setsockopt(sk, level, optname, optval, optlen); in sctp_setsockopt()
4773 retval = -ENOPROTOOPT; in sctp_setsockopt()
4782 /* API 3.1.6 connect() - UDP Style Syntax
4802 int err = -EINVAL; in sctp_connect()
4809 af = sctp_get_af_specific(addr->sa_family); in sctp_connect()
4810 if (af && addr_len >= af->sockaddr_len) in sctp_connect()
4811 err = __sctp_connect(sk, addr, af->sockaddr_len, flags, NULL); in sctp_connect()
4820 if (addr_len < sizeof(uaddr->sa_family)) in sctp_inet_connect()
4821 return -EINVAL; in sctp_inet_connect()
4823 if (uaddr->sa_family == AF_UNSPEC) in sctp_inet_connect()
4824 return -EOPNOTSUPP; in sctp_inet_connect()
4826 return sctp_connect(sock->sk, uaddr, addr_len, flags); in sctp_inet_connect()
4832 return -EOPNOTSUPP; /* STUB */ in sctp_disconnect()
4835 /* 4.1.4 accept() - TCP Style Syntax
4854 ep = sp->ep; in sctp_accept()
4857 error = -EOPNOTSUPP; in sctp_accept()
4862 error = -EINVAL; in sctp_accept()
4875 asoc = list_entry(ep->asocs.next, struct sctp_association, asocs); in sctp_accept()
4877 newsk = sp->pf->create_accept_sk(sk, asoc, kern); in sctp_accept()
4879 error = -ENOMEM; in sctp_accept()
4901 int rc = -ENOTCONN; in sctp_ioctl()
4906 * SEQPACKET-style sockets in LISTENING state are valid, for in sctp_ioctl()
4907 * SCTP, so only discard TCP-style sockets in LISTENING state. in sctp_ioctl()
4917 skb = skb_peek(&sk->sk_receive_queue); in sctp_ioctl()
4923 *karg = skb->len; in sctp_ioctl()
4929 rc = -ENOIOCTLCMD; in sctp_ioctl()
4938 * initialized the SCTP-specific portion of the sock.
4939 * The sock structure should already be zero-filled memory.
4951 switch (sk->sk_type) { in sctp_init_sock()
4953 sp->type = SCTP_SOCKET_UDP; in sctp_init_sock()
4956 sp->type = SCTP_SOCKET_TCP; in sctp_init_sock()
4959 return -ESOCKTNOSUPPORT; in sctp_init_sock()
4962 sk->sk_gso_type = SKB_GSO_SCTP; in sctp_init_sock()
4967 sp->default_stream = 0; in sctp_init_sock()
4968 sp->default_ppid = 0; in sctp_init_sock()
4969 sp->default_flags = 0; in sctp_init_sock()
4970 sp->default_context = 0; in sctp_init_sock()
4971 sp->default_timetolive = 0; in sctp_init_sock()
4973 sp->default_rcv_context = 0; in sctp_init_sock()
4974 sp->max_burst = net->sctp.max_burst; in sctp_init_sock()
4976 sp->sctp_hmac_alg = net->sctp.sctp_hmac_alg; in sctp_init_sock()
4982 sp->initmsg.sinit_num_ostreams = sctp_max_outstreams; in sctp_init_sock()
4983 sp->initmsg.sinit_max_instreams = sctp_max_instreams; in sctp_init_sock()
4984 sp->initmsg.sinit_max_attempts = net->sctp.max_retrans_init; in sctp_init_sock()
4985 sp->initmsg.sinit_max_init_timeo = net->sctp.rto_max; in sctp_init_sock()
4990 sp->rtoinfo.srto_initial = net->sctp.rto_initial; in sctp_init_sock()
4991 sp->rtoinfo.srto_max = net->sctp.rto_max; in sctp_init_sock()
4992 sp->rtoinfo.srto_min = net->sctp.rto_min; in sctp_init_sock()
4997 sp->assocparams.sasoc_asocmaxrxt = net->sctp.max_retrans_association; in sctp_init_sock()
4998 sp->assocparams.sasoc_number_peer_destinations = 0; in sctp_init_sock()
4999 sp->assocparams.sasoc_peer_rwnd = 0; in sctp_init_sock()
5000 sp->assocparams.sasoc_local_rwnd = 0; in sctp_init_sock()
5001 sp->assocparams.sasoc_cookie_life = net->sctp.valid_cookie_life; in sctp_init_sock()
5006 sp->subscribe = 0; in sctp_init_sock()
5011 sp->hbinterval = net->sctp.hb_interval; in sctp_init_sock()
5012 sp->udp_port = htons(net->sctp.udp_port); in sctp_init_sock()
5013 sp->encap_port = htons(net->sctp.encap_port); in sctp_init_sock()
5014 sp->pathmaxrxt = net->sctp.max_retrans_path; in sctp_init_sock()
5015 sp->pf_retrans = net->sctp.pf_retrans; in sctp_init_sock()
5016 sp->ps_retrans = net->sctp.ps_retrans; in sctp_init_sock()
5017 sp->pf_expose = net->sctp.pf_expose; in sctp_init_sock()
5018 sp->pathmtu = 0; /* allow default discovery */ in sctp_init_sock()
5019 sp->sackdelay = net->sctp.sack_timeout; in sctp_init_sock()
5020 sp->sackfreq = 2; in sctp_init_sock()
5021 sp->param_flags = SPP_HB_ENABLE | in sctp_init_sock()
5024 sp->default_ss = SCTP_SS_DEFAULT; in sctp_init_sock()
5029 sp->disable_fragments = 0; in sctp_init_sock()
5032 sp->nodelay = 0; in sctp_init_sock()
5034 sp->recvrcvinfo = 0; in sctp_init_sock()
5035 sp->recvnxtinfo = 0; in sctp_init_sock()
5038 sp->v4mapped = 1; in sctp_init_sock()
5040 /* Auto-close idle associations after the configured in sctp_init_sock()
5043 * for UDP-style sockets only. in sctp_init_sock()
5045 sp->autoclose = 0; in sctp_init_sock()
5048 sp->user_frag = 0; in sctp_init_sock()
5050 sp->adaptation_ind = 0; in sctp_init_sock()
5052 sp->pf = sctp_get_pf_specific(sk->sk_family); in sctp_init_sock()
5055 atomic_set(&sp->pd_mode, 0); in sctp_init_sock()
5056 skb_queue_head_init(&sp->pd_lobby); in sctp_init_sock()
5057 sp->frag_interleave = 0; in sctp_init_sock()
5058 sp->probe_interval = net->sctp.probe_interval; in sctp_init_sock()
5062 * be useful for storing pre-connect address information. in sctp_init_sock()
5064 sp->ep = sctp_endpoint_new(sk, GFP_KERNEL); in sctp_init_sock()
5065 if (!sp->ep) in sctp_init_sock()
5066 return -ENOMEM; in sctp_init_sock()
5068 sp->hmac = NULL; in sctp_init_sock()
5070 sk->sk_destruct = sctp_destruct_sock; in sctp_init_sock()
5075 sock_prot_inuse_add(net, sk->sk_prot, 1); in sctp_init_sock()
5081 * sock_net(sk)->sctp.addr_wq_lock held if sp->do_auto_asconf is true
5094 if (sp->ep == NULL) in sctp_destroy_sock()
5097 if (sp->do_auto_asconf) { in sctp_destroy_sock()
5098 sp->do_auto_asconf = 0; in sctp_destroy_sock()
5099 list_del(&sp->auto_asconf_list); in sctp_destroy_sock()
5101 sctp_endpoint_free(sp->ep); in sctp_destroy_sock()
5103 sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); in sctp_destroy_sock()
5112 crypto_free_shash(sp->hmac); in sctp_destruct_common()
5121 /* API 4.1.7 shutdown() - TCP Style Syntax
5124 * sd - the socket descriptor of the association to be closed.
5125 * how - Specifies the type of shutdown. The values are
5145 ep = sctp_sk(sk)->ep; in sctp_shutdown()
5146 if (how & SEND_SHUTDOWN && !list_empty(&ep->asocs)) { in sctp_shutdown()
5150 asoc = list_entry(ep->asocs.next, in sctp_shutdown()
5167 info->sctpi_s_autoclose = sp->autoclose; in sctp_get_sctp_info()
5168 info->sctpi_s_adaptation_ind = sp->adaptation_ind; in sctp_get_sctp_info()
5169 info->sctpi_s_pd_point = sp->pd_point; in sctp_get_sctp_info()
5170 info->sctpi_s_nodelay = sp->nodelay; in sctp_get_sctp_info()
5171 info->sctpi_s_disable_fragments = sp->disable_fragments; in sctp_get_sctp_info()
5172 info->sctpi_s_v4mapped = sp->v4mapped; in sctp_get_sctp_info()
5173 info->sctpi_s_frag_interleave = sp->frag_interleave; in sctp_get_sctp_info()
5174 info->sctpi_s_type = sp->type; in sctp_get_sctp_info()
5179 info->sctpi_tag = asoc->c.my_vtag; in sctp_get_sctp_info()
5180 info->sctpi_state = asoc->state; in sctp_get_sctp_info()
5181 info->sctpi_rwnd = asoc->a_rwnd; in sctp_get_sctp_info()
5182 info->sctpi_unackdata = asoc->unack_data; in sctp_get_sctp_info()
5183 info->sctpi_penddata = sctp_tsnmap_pending(&asoc->peer.tsn_map); in sctp_get_sctp_info()
5184 info->sctpi_instrms = asoc->stream.incnt; in sctp_get_sctp_info()
5185 info->sctpi_outstrms = asoc->stream.outcnt; in sctp_get_sctp_info()
5186 list_for_each(pos, &asoc->base.inqueue.in_chunk_list) in sctp_get_sctp_info()
5187 info->sctpi_inqueue++; in sctp_get_sctp_info()
5188 list_for_each(pos, &asoc->outqueue.out_chunk_list) in sctp_get_sctp_info()
5189 info->sctpi_outqueue++; in sctp_get_sctp_info()
5190 info->sctpi_overall_error = asoc->overall_error_count; in sctp_get_sctp_info()
5191 info->sctpi_max_burst = asoc->max_burst; in sctp_get_sctp_info()
5192 info->sctpi_maxseg = asoc->frag_point; in sctp_get_sctp_info()
5193 info->sctpi_peer_rwnd = asoc->peer.rwnd; in sctp_get_sctp_info()
5194 info->sctpi_peer_tag = asoc->c.peer_vtag; in sctp_get_sctp_info()
5196 mask = asoc->peer.intl_capable << 1; in sctp_get_sctp_info()
5197 mask = (mask | asoc->peer.ecn_capable) << 1; in sctp_get_sctp_info()
5198 mask = (mask | asoc->peer.ipv4_address) << 1; in sctp_get_sctp_info()
5199 mask = (mask | asoc->peer.ipv6_address) << 1; in sctp_get_sctp_info()
5200 mask = (mask | asoc->peer.reconf_capable) << 1; in sctp_get_sctp_info()
5201 mask = (mask | asoc->peer.asconf_capable) << 1; in sctp_get_sctp_info()
5202 mask = (mask | asoc->peer.prsctp_capable) << 1; in sctp_get_sctp_info()
5203 mask = (mask | asoc->peer.auth_capable); in sctp_get_sctp_info()
5204 info->sctpi_peer_capable = mask; in sctp_get_sctp_info()
5205 mask = asoc->peer.sack_needed << 1; in sctp_get_sctp_info()
5206 mask = (mask | asoc->peer.sack_generation) << 1; in sctp_get_sctp_info()
5207 mask = (mask | asoc->peer.zero_window_announced); in sctp_get_sctp_info()
5208 info->sctpi_peer_sack = mask; in sctp_get_sctp_info()
5210 info->sctpi_isacks = asoc->stats.isacks; in sctp_get_sctp_info()
5211 info->sctpi_osacks = asoc->stats.osacks; in sctp_get_sctp_info()
5212 info->sctpi_opackets = asoc->stats.opackets; in sctp_get_sctp_info()
5213 info->sctpi_ipackets = asoc->stats.ipackets; in sctp_get_sctp_info()
5214 info->sctpi_rtxchunks = asoc->stats.rtxchunks; in sctp_get_sctp_info()
5215 info->sctpi_outofseqtsns = asoc->stats.outofseqtsns; in sctp_get_sctp_info()
5216 info->sctpi_idupchunks = asoc->stats.idupchunks; in sctp_get_sctp_info()
5217 info->sctpi_gapcnt = asoc->stats.gapcnt; in sctp_get_sctp_info()
5218 info->sctpi_ouodchunks = asoc->stats.ouodchunks; in sctp_get_sctp_info()
5219 info->sctpi_iuodchunks = asoc->stats.iuodchunks; in sctp_get_sctp_info()
5220 info->sctpi_oodchunks = asoc->stats.oodchunks; in sctp_get_sctp_info()
5221 info->sctpi_iodchunks = asoc->stats.iodchunks; in sctp_get_sctp_info()
5222 info->sctpi_octrlchunks = asoc->stats.octrlchunks; in sctp_get_sctp_info()
5223 info->sctpi_ictrlchunks = asoc->stats.ictrlchunks; in sctp_get_sctp_info()
5225 prim = asoc->peer.primary_path; in sctp_get_sctp_info()
5226 memcpy(&info->sctpi_p_address, &prim->ipaddr, sizeof(prim->ipaddr)); in sctp_get_sctp_info()
5227 info->sctpi_p_state = prim->state; in sctp_get_sctp_info()
5228 info->sctpi_p_cwnd = prim->cwnd; in sctp_get_sctp_info()
5229 info->sctpi_p_srtt = prim->srtt; in sctp_get_sctp_info()
5230 info->sctpi_p_rto = jiffies_to_msecs(prim->rto); in sctp_get_sctp_info()
5231 info->sctpi_p_hbinterval = prim->hbinterval; in sctp_get_sctp_info()
5232 info->sctpi_p_pathmaxrxt = prim->pathmaxrxt; in sctp_get_sctp_info()
5233 info->sctpi_p_sackdelay = jiffies_to_msecs(prim->sackdelay); in sctp_get_sctp_info()
5234 info->sctpi_p_ssthresh = prim->ssthresh; in sctp_get_sctp_info()
5235 info->sctpi_p_partial_bytes_acked = prim->partial_bytes_acked; in sctp_get_sctp_info()
5236 info->sctpi_p_flight_size = prim->flight_size; in sctp_get_sctp_info()
5237 info->sctpi_p_error = prim->error_count; in sctp_get_sctp_info()
5265 if (PTR_ERR(t) == -EAGAIN) in sctp_transport_get_next()
5273 if (net_eq(t->asoc->base.net, net) && in sctp_transport_get_next()
5274 t->asoc->peer.primary_path == t) in sctp_transport_get_next()
5293 if (!--pos) in sctp_transport_get_idx()
5310 read_lock_bh(&head->lock); in sctp_for_each_endpoint()
5311 sctp_for_each_hentry(ep, &head->chain) { in sctp_for_each_endpoint()
5316 read_unlock_bh(&head->lock); in sctp_for_each_endpoint()
5329 int err = -ENOENT; in sctp_transport_lookup_process()
5337 ep = transport->asoc->ep; in sctp_transport_lookup_process()
5366 ep = tsp->asoc->ep; in sctp_transport_traverse_process()
5398 * receipt. This information is read-only.
5411 retval = -EINVAL; in sctp_getsockopt_sctp_status()
5417 retval = -EFAULT; in sctp_getsockopt_sctp_status()
5424 retval = -EINVAL; in sctp_getsockopt_sctp_status()
5428 transport = asoc->peer.primary_path; in sctp_getsockopt_sctp_status()
5432 status.sstat_rwnd = asoc->peer.rwnd; in sctp_getsockopt_sctp_status()
5433 status.sstat_unackdata = asoc->unack_data; in sctp_getsockopt_sctp_status()
5435 status.sstat_penddata = sctp_tsnmap_pending(&asoc->peer.tsn_map); in sctp_getsockopt_sctp_status()
5436 status.sstat_instrms = asoc->stream.incnt; in sctp_getsockopt_sctp_status()
5437 status.sstat_outstrms = asoc->stream.outcnt; in sctp_getsockopt_sctp_status()
5438 status.sstat_fragmentation_point = asoc->frag_point; in sctp_getsockopt_sctp_status()
5439 status.sstat_primary.spinfo_assoc_id = sctp_assoc2id(transport->asoc); in sctp_getsockopt_sctp_status()
5440 memcpy(&status.sstat_primary.spinfo_address, &transport->ipaddr, in sctp_getsockopt_sctp_status()
5441 transport->af_specific->sockaddr_len); in sctp_getsockopt_sctp_status()
5442 /* Map ipv4 address into v4-mapped-on-v6 address. */ in sctp_getsockopt_sctp_status()
5443 sctp_get_pf_specific(sk->sk_family)->addr_to_user(sctp_sk(sk), in sctp_getsockopt_sctp_status()
5445 status.sstat_primary.spinfo_state = transport->state; in sctp_getsockopt_sctp_status()
5446 status.sstat_primary.spinfo_cwnd = transport->cwnd; in sctp_getsockopt_sctp_status()
5447 status.sstat_primary.spinfo_srtt = transport->srtt; in sctp_getsockopt_sctp_status()
5448 status.sstat_primary.spinfo_rto = jiffies_to_msecs(transport->rto); in sctp_getsockopt_sctp_status()
5449 status.sstat_primary.spinfo_mtu = transport->pathmtu; in sctp_getsockopt_sctp_status()
5455 retval = -EFAULT; in sctp_getsockopt_sctp_status()
5464 retval = -EFAULT; in sctp_getsockopt_sctp_status()
5478 * read-only.
5489 retval = -EINVAL; in sctp_getsockopt_peer_addr_info()
5495 retval = -EFAULT; in sctp_getsockopt_peer_addr_info()
5502 retval = -EINVAL; in sctp_getsockopt_peer_addr_info()
5506 if (transport->state == SCTP_PF && in sctp_getsockopt_peer_addr_info()
5507 transport->asoc->pf_expose == SCTP_PF_EXPOSE_DISABLE) { in sctp_getsockopt_peer_addr_info()
5508 retval = -EACCES; in sctp_getsockopt_peer_addr_info()
5512 pinfo.spinfo_assoc_id = sctp_assoc2id(transport->asoc); in sctp_getsockopt_peer_addr_info()
5513 pinfo.spinfo_state = transport->state; in sctp_getsockopt_peer_addr_info()
5514 pinfo.spinfo_cwnd = transport->cwnd; in sctp_getsockopt_peer_addr_info()
5515 pinfo.spinfo_srtt = transport->srtt; in sctp_getsockopt_peer_addr_info()
5516 pinfo.spinfo_rto = jiffies_to_msecs(transport->rto); in sctp_getsockopt_peer_addr_info()
5517 pinfo.spinfo_mtu = transport->pathmtu; in sctp_getsockopt_peer_addr_info()
5523 retval = -EFAULT; in sctp_getsockopt_peer_addr_info()
5528 retval = -EFAULT; in sctp_getsockopt_peer_addr_info()
5549 return -EINVAL; in sctp_getsockopt_disable_fragments()
5552 val = (sctp_sk(sk)->disable_fragments == 1); in sctp_getsockopt_disable_fragments()
5554 return -EFAULT; in sctp_getsockopt_disable_fragments()
5556 return -EFAULT; in sctp_getsockopt_disable_fragments()
5573 return -EINVAL; in sctp_getsockopt_events()
5577 return -EFAULT; in sctp_getsockopt_events()
5580 sn_type[i] = sctp_ulpevent_type_enabled(sctp_sk(sk)->subscribe, in sctp_getsockopt_events()
5584 return -EFAULT; in sctp_getsockopt_events()
5591 * This socket option is applicable to the UDP-style socket only. When
5602 /* Applicable to UDP-style socket only */ in sctp_getsockopt_autoclose()
5604 return -EOPNOTSUPP; in sctp_getsockopt_autoclose()
5606 return -EINVAL; in sctp_getsockopt_autoclose()
5609 return -EFAULT; in sctp_getsockopt_autoclose()
5610 if (put_user(sctp_sk(sk)->autoclose, (int __user *)optval)) in sctp_getsockopt_autoclose()
5611 return -EFAULT; in sctp_getsockopt_autoclose()
5624 if (!net_eq(current->nsproxy->net_ns, sock_net(sk))) in sctp_do_peeloff()
5625 return -EINVAL; in sctp_do_peeloff()
5628 return -EINVAL; in sctp_do_peeloff()
5630 /* An association cannot be branched off from an already peeled-off in sctp_do_peeloff()
5634 return -EINVAL; in sctp_do_peeloff()
5637 err = sock_create(sk->sk_family, SOCK_SEQPACKET, IPPROTO_SCTP, &sock); in sctp_do_peeloff()
5641 sctp_copy_sock(sock->sk, sk, asoc); in sctp_do_peeloff()
5643 /* Make peeled-off sockets more like 1-1 accepted sockets. in sctp_do_peeloff()
5647 sp->pf->to_sk_daddr(&asoc->peer.primary_addr, sock->sk); in sctp_do_peeloff()
5648 sp->pf->copy_ip_options(sk, sock->sk); in sctp_do_peeloff()
5653 err = sctp_sock_migrate(sk, sock->sk, asoc, in sctp_do_peeloff()
5672 retval = sctp_do_peeloff(sk, peeloff->associd, &newsock); in sctp_getsockopt_peeloff_common()
5691 pr_debug("%s: sk:%p, newsk:%p, sd:%d\n", __func__, sk, newsock->sk, in sctp_getsockopt_peeloff_common()
5694 peeloff->sd = retval; in sctp_getsockopt_peeloff_common()
5697 (*newfile)->f_flags |= O_NONBLOCK; in sctp_getsockopt_peeloff_common()
5709 return -EINVAL; in sctp_getsockopt_peeloff()
5712 return -EFAULT; in sctp_getsockopt_peeloff()
5722 return -EFAULT; in sctp_getsockopt_peeloff()
5728 return -EFAULT; in sctp_getsockopt_peeloff()
5743 return -EINVAL; in sctp_getsockopt_peeloff_flags()
5746 return -EFAULT; in sctp_getsockopt_peeloff_flags()
5757 return -EFAULT; in sctp_getsockopt_peeloff_flags()
5763 return -EFAULT; in sctp_getsockopt_peeloff_flags()
5789 * spp_assoc_id - (one-to-many style socket) This is filled in the
5792 * spp_address - This specifies which address is of interest.
5793 * spp_hbinterval - This contains the value of the heartbeat interval,
5797 * spp_pathmaxrxt - This contains the maximum number of
5802 * spp_pathmtu - When Path MTU discovery is disabled the value
5808 * spp_sackdelay - When delayed sack is enabled, this value specifies
5816 * spp_flags - These flags are used to control various features
5820 * SPP_HB_ENABLE - Enable heartbeats on the
5825 * SPP_HB_DISABLE - Disable heartbeats on the
5828 * will have their heartbeats disabled. Note also
5834 * SPP_HB_DEMAND - Request a user initiated heartbeat
5837 * SPP_PMTUD_ENABLE - This field will enable PMTU
5842 * SPP_PMTUD_DISABLE - This field will disable PMTU
5850 * SPP_SACKDELAY_ENABLE - Setting this flag turns
5856 * SPP_SACKDELAY_DISABLE - Setting this flag turns
5858 * delayed sack is disabled for the entire association. Note
5874 * returned. For non-IPv6 sockets, this flag will be left
5891 * - This field is used in conjunction with the
5894 * label. This setting has precedence over any IPv6-layer
5897 * spp_dscp - This field is used in conjunction with the SPP_DSCP flag
5900 * IPv4- or IPv6- layer setting.
5917 return -EINVAL; in sctp_getsockopt_peer_addr_params()
5920 return -EFAULT; in sctp_getsockopt_peer_addr_params()
5930 return -EINVAL; in sctp_getsockopt_peer_addr_params()
5942 return -EINVAL; in sctp_getsockopt_peer_addr_params()
5947 params.spp_hbinterval = jiffies_to_msecs(trans->hbinterval); in sctp_getsockopt_peer_addr_params()
5948 params.spp_pathmtu = trans->pathmtu; in sctp_getsockopt_peer_addr_params()
5949 params.spp_pathmaxrxt = trans->pathmaxrxt; in sctp_getsockopt_peer_addr_params()
5950 params.spp_sackdelay = jiffies_to_msecs(trans->sackdelay); in sctp_getsockopt_peer_addr_params()
5952 /*draft-11 doesn't say what to return in spp_flags*/ in sctp_getsockopt_peer_addr_params()
5953 params.spp_flags = trans->param_flags; in sctp_getsockopt_peer_addr_params()
5954 if (trans->flowlabel & SCTP_FLOWLABEL_SET_MASK) { in sctp_getsockopt_peer_addr_params()
5955 params.spp_ipv6_flowlabel = trans->flowlabel & in sctp_getsockopt_peer_addr_params()
5959 if (trans->dscp & SCTP_DSCP_SET_MASK) { in sctp_getsockopt_peer_addr_params()
5960 params.spp_dscp = trans->dscp & SCTP_DSCP_VAL_MASK; in sctp_getsockopt_peer_addr_params()
5965 params.spp_hbinterval = jiffies_to_msecs(asoc->hbinterval); in sctp_getsockopt_peer_addr_params()
5966 params.spp_pathmtu = asoc->pathmtu; in sctp_getsockopt_peer_addr_params()
5967 params.spp_pathmaxrxt = asoc->pathmaxrxt; in sctp_getsockopt_peer_addr_params()
5968 params.spp_sackdelay = jiffies_to_msecs(asoc->sackdelay); in sctp_getsockopt_peer_addr_params()
5970 /*draft-11 doesn't say what to return in spp_flags*/ in sctp_getsockopt_peer_addr_params()
5971 params.spp_flags = asoc->param_flags; in sctp_getsockopt_peer_addr_params()
5972 if (asoc->flowlabel & SCTP_FLOWLABEL_SET_MASK) { in sctp_getsockopt_peer_addr_params()
5973 params.spp_ipv6_flowlabel = asoc->flowlabel & in sctp_getsockopt_peer_addr_params()
5977 if (asoc->dscp & SCTP_DSCP_SET_MASK) { in sctp_getsockopt_peer_addr_params()
5978 params.spp_dscp = asoc->dscp & SCTP_DSCP_VAL_MASK; in sctp_getsockopt_peer_addr_params()
5983 params.spp_hbinterval = sp->hbinterval; in sctp_getsockopt_peer_addr_params()
5984 params.spp_pathmtu = sp->pathmtu; in sctp_getsockopt_peer_addr_params()
5985 params.spp_sackdelay = sp->sackdelay; in sctp_getsockopt_peer_addr_params()
5986 params.spp_pathmaxrxt = sp->pathmaxrxt; in sctp_getsockopt_peer_addr_params()
5988 /*draft-11 doesn't say what to return in spp_flags*/ in sctp_getsockopt_peer_addr_params()
5989 params.spp_flags = sp->param_flags; in sctp_getsockopt_peer_addr_params()
5990 if (sp->flowlabel & SCTP_FLOWLABEL_SET_MASK) { in sctp_getsockopt_peer_addr_params()
5991 params.spp_ipv6_flowlabel = sp->flowlabel & in sctp_getsockopt_peer_addr_params()
5995 if (sp->dscp & SCTP_DSCP_SET_MASK) { in sctp_getsockopt_peer_addr_params()
5996 params.spp_dscp = sp->dscp & SCTP_DSCP_VAL_MASK; in sctp_getsockopt_peer_addr_params()
6002 return -EFAULT; in sctp_getsockopt_peer_addr_params()
6005 return -EFAULT; in sctp_getsockopt_peer_addr_params()
6018 * values. If the assoc_id field is non-zero, then the set or get
6030 * sack_assoc_id - This parameter, indicates which association the user
6035 * sack_delay - This parameter contains the number of milliseconds that
6040 * sack_freq - This parameter contains the number of packets that must
6057 return -EFAULT; in sctp_getsockopt_delayed_ack()
6063 current->comm, task_pid_nr(current)); in sctp_getsockopt_delayed_ack()
6065 return -EFAULT; in sctp_getsockopt_delayed_ack()
6067 return -EINVAL; in sctp_getsockopt_delayed_ack()
6076 return -EINVAL; in sctp_getsockopt_delayed_ack()
6080 if (asoc->param_flags & SPP_SACKDELAY_ENABLE) { in sctp_getsockopt_delayed_ack()
6081 params.sack_delay = jiffies_to_msecs(asoc->sackdelay); in sctp_getsockopt_delayed_ack()
6082 params.sack_freq = asoc->sackfreq; in sctp_getsockopt_delayed_ack()
6090 if (sp->param_flags & SPP_SACKDELAY_ENABLE) { in sctp_getsockopt_delayed_ack()
6091 params.sack_delay = sp->sackdelay; in sctp_getsockopt_delayed_ack()
6092 params.sack_freq = sp->sackfreq; in sctp_getsockopt_delayed_ack()
6100 return -EFAULT; in sctp_getsockopt_delayed_ack()
6103 return -EFAULT; in sctp_getsockopt_delayed_ack()
6115 * socket (for UDP-style sockets only future associations are effected
6116 * by the change). With TCP-style sockets, this option is inherited by
6122 return -EINVAL; in sctp_getsockopt_initmsg()
6125 return -EFAULT; in sctp_getsockopt_initmsg()
6126 if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len)) in sctp_getsockopt_initmsg()
6127 return -EFAULT; in sctp_getsockopt_initmsg()
6147 return -EINVAL; in sctp_getsockopt_peer_addrs()
6150 return -EFAULT; in sctp_getsockopt_peer_addrs()
6152 /* For UDP-style sockets, id specifies the association to query. */ in sctp_getsockopt_peer_addrs()
6155 return -EINVAL; in sctp_getsockopt_peer_addrs()
6158 space_left = len - offsetof(struct sctp_getaddrs, addrs); in sctp_getsockopt_peer_addrs()
6160 list_for_each_entry(from, &asoc->peer.transport_addr_list, in sctp_getsockopt_peer_addrs()
6162 memcpy(&temp, &from->ipaddr, sizeof(temp)); in sctp_getsockopt_peer_addrs()
6163 addrlen = sctp_get_pf_specific(sk->sk_family) in sctp_getsockopt_peer_addrs()
6164 ->addr_to_user(sp, &temp); in sctp_getsockopt_peer_addrs()
6166 return -ENOMEM; in sctp_getsockopt_peer_addrs()
6168 return -EFAULT; in sctp_getsockopt_peer_addrs()
6171 space_left -= addrlen; in sctp_getsockopt_peer_addrs()
6174 if (put_user(cnt, &((struct sctp_getaddrs __user *)optval)->addr_num)) in sctp_getsockopt_peer_addrs()
6175 return -EFAULT; in sctp_getsockopt_peer_addrs()
6176 bytes_copied = ((char __user *)to) - optval; in sctp_getsockopt_peer_addrs()
6178 return -EFAULT; in sctp_getsockopt_peer_addrs()
6193 list_for_each_entry_rcu(addr, &net->sctp.local_addr_list, list) { in sctp_copy_laddrs()
6194 if (!addr->valid) in sctp_copy_laddrs()
6197 if ((PF_INET == sk->sk_family) && in sctp_copy_laddrs()
6198 (AF_INET6 == addr->a.sa.sa_family)) in sctp_copy_laddrs()
6200 if ((PF_INET6 == sk->sk_family) && in sctp_copy_laddrs()
6202 (AF_INET == addr->a.sa.sa_family)) in sctp_copy_laddrs()
6204 memcpy(&temp, &addr->a, sizeof(temp)); in sctp_copy_laddrs()
6208 addrlen = sctp_get_pf_specific(sk->sk_family) in sctp_copy_laddrs()
6209 ->addr_to_user(sctp_sk(sk), &temp); in sctp_copy_laddrs()
6212 cnt = -ENOMEM; in sctp_copy_laddrs()
6219 space_left -= addrlen; in sctp_copy_laddrs()
6231 struct sctp_bind_addr *bp; in sctp_getsockopt_local_addrs() local
6247 return -EINVAL; in sctp_getsockopt_local_addrs()
6250 return -EFAULT; in sctp_getsockopt_local_addrs()
6253 * For UDP-style sockets, id specifies the association to query. in sctp_getsockopt_local_addrs()
6259 bp = &sctp_sk(sk)->ep->base.bind_addr; in sctp_getsockopt_local_addrs()
6263 return -EINVAL; in sctp_getsockopt_local_addrs()
6264 bp = &asoc->base.bind_addr; in sctp_getsockopt_local_addrs()
6268 space_left = len - offsetof(struct sctp_getaddrs, addrs); in sctp_getsockopt_local_addrs()
6272 return -ENOMEM; in sctp_getsockopt_local_addrs()
6277 if (sctp_list_single_entry(&bp->address_list)) { in sctp_getsockopt_local_addrs()
6278 addr = list_entry(bp->address_list.next, in sctp_getsockopt_local_addrs()
6280 if (sctp_is_any(sk, &addr->a)) { in sctp_getsockopt_local_addrs()
6281 cnt = sctp_copy_laddrs(sk, bp->port, addrs, in sctp_getsockopt_local_addrs()
6296 list_for_each_entry(addr, &bp->address_list, list) { in sctp_getsockopt_local_addrs()
6297 memcpy(&temp, &addr->a, sizeof(temp)); in sctp_getsockopt_local_addrs()
6298 addrlen = sctp_get_pf_specific(sk->sk_family) in sctp_getsockopt_local_addrs()
6299 ->addr_to_user(sp, &temp); in sctp_getsockopt_local_addrs()
6301 err = -ENOMEM; /*fixme: right error?*/ in sctp_getsockopt_local_addrs()
6308 space_left -= addrlen; in sctp_getsockopt_local_addrs()
6313 err = -EFAULT; in sctp_getsockopt_local_addrs()
6316 if (put_user(cnt, &((struct sctp_getaddrs __user *)optval)->addr_num)) { in sctp_getsockopt_local_addrs()
6317 err = -EFAULT; in sctp_getsockopt_local_addrs()
6324 err = -EFAULT; in sctp_getsockopt_local_addrs()
6344 return -EINVAL; in sctp_getsockopt_primary_addr()
6349 return -EFAULT; in sctp_getsockopt_primary_addr()
6353 return -EINVAL; in sctp_getsockopt_primary_addr()
6355 if (!asoc->peer.primary_path) in sctp_getsockopt_primary_addr()
6356 return -ENOTCONN; in sctp_getsockopt_primary_addr()
6358 memcpy(&prim.ssp_addr, &asoc->peer.primary_path->ipaddr, in sctp_getsockopt_primary_addr()
6359 asoc->peer.primary_path->af_specific->sockaddr_len); in sctp_getsockopt_primary_addr()
6361 sctp_get_pf_specific(sk->sk_family)->addr_to_user(sp, in sctp_getsockopt_primary_addr()
6365 return -EFAULT; in sctp_getsockopt_primary_addr()
6367 return -EFAULT; in sctp_getsockopt_primary_addr()
6376 * Indication parameter for all future INIT and INIT-ACK exchanges.
6384 return -EINVAL; in sctp_getsockopt_adaptation_layer()
6388 adaptation.ssb_adaptation_ind = sctp_sk(sk)->adaptation_ind; in sctp_getsockopt_adaptation_layer()
6391 return -EFAULT; in sctp_getsockopt_adaptation_layer()
6393 return -EFAULT; in sctp_getsockopt_adaptation_layer()
6426 return -EINVAL; in sctp_getsockopt_default_send_param()
6431 return -EFAULT; in sctp_getsockopt_default_send_param()
6436 return -EINVAL; in sctp_getsockopt_default_send_param()
6439 info.sinfo_stream = asoc->default_stream; in sctp_getsockopt_default_send_param()
6440 info.sinfo_flags = asoc->default_flags; in sctp_getsockopt_default_send_param()
6441 info.sinfo_ppid = asoc->default_ppid; in sctp_getsockopt_default_send_param()
6442 info.sinfo_context = asoc->default_context; in sctp_getsockopt_default_send_param()
6443 info.sinfo_timetolive = asoc->default_timetolive; in sctp_getsockopt_default_send_param()
6445 info.sinfo_stream = sp->default_stream; in sctp_getsockopt_default_send_param()
6446 info.sinfo_flags = sp->default_flags; in sctp_getsockopt_default_send_param()
6447 info.sinfo_ppid = sp->default_ppid; in sctp_getsockopt_default_send_param()
6448 info.sinfo_context = sp->default_context; in sctp_getsockopt_default_send_param()
6449 info.sinfo_timetolive = sp->default_timetolive; in sctp_getsockopt_default_send_param()
6453 return -EFAULT; in sctp_getsockopt_default_send_param()
6455 return -EFAULT; in sctp_getsockopt_default_send_param()
6472 return -EINVAL; in sctp_getsockopt_default_sndinfo()
6477 return -EFAULT; in sctp_getsockopt_default_sndinfo()
6482 return -EINVAL; in sctp_getsockopt_default_sndinfo()
6485 info.snd_sid = asoc->default_stream; in sctp_getsockopt_default_sndinfo()
6486 info.snd_flags = asoc->default_flags; in sctp_getsockopt_default_sndinfo()
6487 info.snd_ppid = asoc->default_ppid; in sctp_getsockopt_default_sndinfo()
6488 info.snd_context = asoc->default_context; in sctp_getsockopt_default_sndinfo()
6490 info.snd_sid = sp->default_stream; in sctp_getsockopt_default_sndinfo()
6491 info.snd_flags = sp->default_flags; in sctp_getsockopt_default_sndinfo()
6492 info.snd_ppid = sp->default_ppid; in sctp_getsockopt_default_sndinfo()
6493 info.snd_context = sp->default_context; in sctp_getsockopt_default_sndinfo()
6497 return -EFAULT; in sctp_getsockopt_default_sndinfo()
6499 return -EFAULT; in sctp_getsockopt_default_sndinfo()
6508 * Turn on/off any Nagle-like algorithm. This means that packets are
6520 return -EINVAL; in sctp_getsockopt_nodelay()
6523 val = (sctp_sk(sk)->nodelay == 1); in sctp_getsockopt_nodelay()
6525 return -EFAULT; in sctp_getsockopt_nodelay()
6527 return -EFAULT; in sctp_getsockopt_nodelay()
6550 return -EINVAL; in sctp_getsockopt_rtoinfo()
6555 return -EFAULT; in sctp_getsockopt_rtoinfo()
6561 return -EINVAL; in sctp_getsockopt_rtoinfo()
6565 rtoinfo.srto_initial = jiffies_to_msecs(asoc->rto_initial); in sctp_getsockopt_rtoinfo()
6566 rtoinfo.srto_max = jiffies_to_msecs(asoc->rto_max); in sctp_getsockopt_rtoinfo()
6567 rtoinfo.srto_min = jiffies_to_msecs(asoc->rto_min); in sctp_getsockopt_rtoinfo()
6572 rtoinfo.srto_initial = sp->rtoinfo.srto_initial; in sctp_getsockopt_rtoinfo()
6573 rtoinfo.srto_max = sp->rtoinfo.srto_max; in sctp_getsockopt_rtoinfo()
6574 rtoinfo.srto_min = sp->rtoinfo.srto_min; in sctp_getsockopt_rtoinfo()
6578 return -EFAULT; in sctp_getsockopt_rtoinfo()
6581 return -EFAULT; in sctp_getsockopt_rtoinfo()
6608 return -EINVAL; in sctp_getsockopt_associnfo()
6613 return -EFAULT; in sctp_getsockopt_associnfo()
6619 return -EINVAL; in sctp_getsockopt_associnfo()
6623 assocparams.sasoc_asocmaxrxt = asoc->max_retrans; in sctp_getsockopt_associnfo()
6624 assocparams.sasoc_peer_rwnd = asoc->peer.rwnd; in sctp_getsockopt_associnfo()
6625 assocparams.sasoc_local_rwnd = asoc->a_rwnd; in sctp_getsockopt_associnfo()
6626 assocparams.sasoc_cookie_life = ktime_to_ms(asoc->cookie_life); in sctp_getsockopt_associnfo()
6628 list_for_each(pos, &asoc->peer.transport_addr_list) { in sctp_getsockopt_associnfo()
6637 assocparams.sasoc_asocmaxrxt = sp->assocparams.sasoc_asocmaxrxt; in sctp_getsockopt_associnfo()
6638 assocparams.sasoc_peer_rwnd = sp->assocparams.sasoc_peer_rwnd; in sctp_getsockopt_associnfo()
6639 assocparams.sasoc_local_rwnd = sp->assocparams.sasoc_local_rwnd; in sctp_getsockopt_associnfo()
6641 sp->assocparams.sasoc_cookie_life; in sctp_getsockopt_associnfo()
6643 sp->assocparams. in sctp_getsockopt_associnfo()
6648 return -EFAULT; in sctp_getsockopt_associnfo()
6651 return -EFAULT; in sctp_getsockopt_associnfo()
6673 return -EINVAL; in sctp_getsockopt_mappedv4()
6676 val = sp->v4mapped; in sctp_getsockopt_mappedv4()
6678 return -EFAULT; in sctp_getsockopt_mappedv4()
6680 return -EFAULT; in sctp_getsockopt_mappedv4()
6696 return -EINVAL; in sctp_getsockopt_context()
6701 return -EFAULT; in sctp_getsockopt_context()
6706 return -EINVAL; in sctp_getsockopt_context()
6708 params.assoc_value = asoc ? asoc->default_rcv_context in sctp_getsockopt_context()
6709 : sctp_sk(sk)->default_rcv_context; in sctp_getsockopt_context()
6712 return -EFAULT; in sctp_getsockopt_context()
6714 return -EFAULT; in sctp_getsockopt_context()
6739 * assoc_id: This parameter is ignored for one-to-one style sockets.
6740 * For one-to-many style sockets this parameter indicates which
6757 current->comm, task_pid_nr(current)); in sctp_getsockopt_maxseg()
6762 return -EFAULT; in sctp_getsockopt_maxseg()
6764 return -EINVAL; in sctp_getsockopt_maxseg()
6769 return -EINVAL; in sctp_getsockopt_maxseg()
6772 params.assoc_value = asoc->frag_point; in sctp_getsockopt_maxseg()
6774 params.assoc_value = sctp_sk(sk)->user_frag; in sctp_getsockopt_maxseg()
6777 return -EFAULT; in sctp_getsockopt_maxseg()
6780 return -EFAULT; in sctp_getsockopt_maxseg()
6783 return -EFAULT; in sctp_getsockopt_maxseg()
6799 return -EINVAL; in sctp_getsockopt_fragment_interleave()
6803 val = sctp_sk(sk)->frag_interleave; in sctp_getsockopt_fragment_interleave()
6805 return -EFAULT; in sctp_getsockopt_fragment_interleave()
6807 return -EFAULT; in sctp_getsockopt_fragment_interleave()
6823 return -EINVAL; in sctp_getsockopt_partial_delivery_point()
6827 val = sctp_sk(sk)->pd_point; in sctp_getsockopt_partial_delivery_point()
6829 return -EFAULT; in sctp_getsockopt_partial_delivery_point()
6831 return -EFAULT; in sctp_getsockopt_partial_delivery_point()
6852 current->comm, task_pid_nr(current)); in sctp_getsockopt_maxburst()
6857 return -EFAULT; in sctp_getsockopt_maxburst()
6859 return -EINVAL; in sctp_getsockopt_maxburst()
6864 return -EINVAL; in sctp_getsockopt_maxburst()
6866 params.assoc_value = asoc ? asoc->max_burst : sctp_sk(sk)->max_burst; in sctp_getsockopt_maxburst()
6870 return -EFAULT; in sctp_getsockopt_maxburst()
6873 return -EFAULT; in sctp_getsockopt_maxburst()
6883 struct sctp_endpoint *ep = sctp_sk(sk)->ep; in sctp_getsockopt_hmac_ident()
6890 if (!ep->auth_enable) in sctp_getsockopt_hmac_ident()
6891 return -EACCES; in sctp_getsockopt_hmac_ident()
6893 hmacs = ep->auth_hmacs_list; in sctp_getsockopt_hmac_ident()
6894 data_len = ntohs(hmacs->param_hdr.length) - in sctp_getsockopt_hmac_ident()
6898 return -EINVAL; in sctp_getsockopt_hmac_ident()
6904 return -EFAULT; in sctp_getsockopt_hmac_ident()
6905 if (put_user(num_idents, &p->shmac_num_idents)) in sctp_getsockopt_hmac_ident()
6906 return -EFAULT; in sctp_getsockopt_hmac_ident()
6908 __u16 hmacid = ntohs(hmacs->hmac_ids[i]); in sctp_getsockopt_hmac_ident()
6910 if (copy_to_user(&p->shmac_idents[i], &hmacid, sizeof(__u16))) in sctp_getsockopt_hmac_ident()
6911 return -EFAULT; in sctp_getsockopt_hmac_ident()
6919 struct sctp_endpoint *ep = sctp_sk(sk)->ep; in sctp_getsockopt_active_key()
6924 return -EINVAL; in sctp_getsockopt_active_key()
6928 return -EFAULT; in sctp_getsockopt_active_key()
6932 return -EINVAL; in sctp_getsockopt_active_key()
6935 if (!asoc->peer.auth_capable) in sctp_getsockopt_active_key()
6936 return -EACCES; in sctp_getsockopt_active_key()
6937 val.scact_keynumber = asoc->active_key_id; in sctp_getsockopt_active_key()
6939 if (!ep->auth_enable) in sctp_getsockopt_active_key()
6940 return -EACCES; in sctp_getsockopt_active_key()
6941 val.scact_keynumber = ep->active_key_id; in sctp_getsockopt_active_key()
6945 return -EFAULT; in sctp_getsockopt_active_key()
6947 return -EFAULT; in sctp_getsockopt_active_key()
6963 return -EINVAL; in sctp_getsockopt_peer_auth_chunks()
6966 return -EFAULT; in sctp_getsockopt_peer_auth_chunks()
6968 to = p->gauth_chunks; in sctp_getsockopt_peer_auth_chunks()
6971 return -EINVAL; in sctp_getsockopt_peer_auth_chunks()
6973 if (!asoc->peer.auth_capable) in sctp_getsockopt_peer_auth_chunks()
6974 return -EACCES; in sctp_getsockopt_peer_auth_chunks()
6976 ch = asoc->peer.peer_chunks; in sctp_getsockopt_peer_auth_chunks()
6981 num_chunks = ntohs(ch->param_hdr.length) - sizeof(struct sctp_paramhdr); in sctp_getsockopt_peer_auth_chunks()
6983 return -EINVAL; in sctp_getsockopt_peer_auth_chunks()
6985 if (copy_to_user(to, ch->chunks, num_chunks)) in sctp_getsockopt_peer_auth_chunks()
6986 return -EFAULT; in sctp_getsockopt_peer_auth_chunks()
6990 return -EFAULT; in sctp_getsockopt_peer_auth_chunks()
6991 if (put_user(num_chunks, &p->gauth_number_of_chunks)) in sctp_getsockopt_peer_auth_chunks()
6992 return -EFAULT; in sctp_getsockopt_peer_auth_chunks()
6999 struct sctp_endpoint *ep = sctp_sk(sk)->ep; in sctp_getsockopt_local_auth_chunks()
7008 return -EINVAL; in sctp_getsockopt_local_auth_chunks()
7011 return -EFAULT; in sctp_getsockopt_local_auth_chunks()
7013 to = p->gauth_chunks; in sctp_getsockopt_local_auth_chunks()
7017 return -EINVAL; in sctp_getsockopt_local_auth_chunks()
7020 if (!asoc->peer.auth_capable) in sctp_getsockopt_local_auth_chunks()
7021 return -EACCES; in sctp_getsockopt_local_auth_chunks()
7022 ch = (struct sctp_chunks_param *)asoc->c.auth_chunks; in sctp_getsockopt_local_auth_chunks()
7024 if (!ep->auth_enable) in sctp_getsockopt_local_auth_chunks()
7025 return -EACCES; in sctp_getsockopt_local_auth_chunks()
7026 ch = ep->auth_chunk_list; in sctp_getsockopt_local_auth_chunks()
7031 num_chunks = ntohs(ch->param_hdr.length) - sizeof(struct sctp_paramhdr); in sctp_getsockopt_local_auth_chunks()
7033 return -EINVAL; in sctp_getsockopt_local_auth_chunks()
7035 if (copy_to_user(to, ch->chunks, num_chunks)) in sctp_getsockopt_local_auth_chunks()
7036 return -EFAULT; in sctp_getsockopt_local_auth_chunks()
7040 return -EFAULT; in sctp_getsockopt_local_auth_chunks()
7041 if (put_user(num_chunks, &p->gauth_number_of_chunks)) in sctp_getsockopt_local_auth_chunks()
7042 return -EFAULT; in sctp_getsockopt_local_auth_chunks()
7050 * to a one-to-many style socket. The option value is an uint32_t.
7060 return -EOPNOTSUPP; in sctp_getsockopt_assoc_number()
7063 return -EINVAL; in sctp_getsockopt_assoc_number()
7067 list_for_each_entry(asoc, &(sp->ep->asocs), asocs) { in sctp_getsockopt_assoc_number()
7072 return -EFAULT; in sctp_getsockopt_assoc_number()
7074 return -EFAULT; in sctp_getsockopt_assoc_number()
7089 return -EINVAL; in sctp_getsockopt_auto_asconf()
7092 if (sctp_sk(sk)->do_auto_asconf && sctp_is_ep_boundall(sk)) in sctp_getsockopt_auto_asconf()
7095 return -EFAULT; in sctp_getsockopt_auto_asconf()
7097 return -EFAULT; in sctp_getsockopt_auto_asconf()
7106 * the SCTP associations handled by a one-to-many style socket.
7117 return -EOPNOTSUPP; in sctp_getsockopt_assoc_ids()
7120 return -EINVAL; in sctp_getsockopt_assoc_ids()
7122 list_for_each_entry(asoc, &(sp->ep->asocs), asocs) { in sctp_getsockopt_assoc_ids()
7127 return -EINVAL; in sctp_getsockopt_assoc_ids()
7133 return -ENOMEM; in sctp_getsockopt_assoc_ids()
7135 ids->gaids_number_of_ids = num; in sctp_getsockopt_assoc_ids()
7137 list_for_each_entry(asoc, &(sp->ep->asocs), asocs) { in sctp_getsockopt_assoc_ids()
7138 ids->gaids_assoc_id[num++] = asoc->assoc_id; in sctp_getsockopt_assoc_ids()
7143 return -EFAULT; in sctp_getsockopt_assoc_ids()
7155 * http://www.ietf.org/id/draft-nishida-tsvwg-sctp-failover-05.txt
7168 return -EINVAL; in sctp_getsockopt_paddr_thresholds()
7171 return -EFAULT; in sctp_getsockopt_paddr_thresholds()
7177 return -ENOENT; in sctp_getsockopt_paddr_thresholds()
7179 val.spt_pathmaxrxt = trans->pathmaxrxt; in sctp_getsockopt_paddr_thresholds()
7180 val.spt_pathpfthld = trans->pf_retrans; in sctp_getsockopt_paddr_thresholds()
7181 val.spt_pathcpthld = trans->ps_retrans; in sctp_getsockopt_paddr_thresholds()
7189 return -EINVAL; in sctp_getsockopt_paddr_thresholds()
7192 val.spt_pathpfthld = asoc->pf_retrans; in sctp_getsockopt_paddr_thresholds()
7193 val.spt_pathmaxrxt = asoc->pathmaxrxt; in sctp_getsockopt_paddr_thresholds()
7194 val.spt_pathcpthld = asoc->ps_retrans; in sctp_getsockopt_paddr_thresholds()
7198 val.spt_pathpfthld = sp->pf_retrans; in sctp_getsockopt_paddr_thresholds()
7199 val.spt_pathmaxrxt = sp->pathmaxrxt; in sctp_getsockopt_paddr_thresholds()
7200 val.spt_pathcpthld = sp->ps_retrans; in sctp_getsockopt_paddr_thresholds()
7205 return -EFAULT; in sctp_getsockopt_paddr_thresholds()
7225 return -EINVAL; in sctp_getsockopt_assoc_stats()
7231 return -EFAULT; in sctp_getsockopt_assoc_stats()
7235 return -EINVAL; in sctp_getsockopt_assoc_stats()
7237 sas.sas_rtxchunks = asoc->stats.rtxchunks; in sctp_getsockopt_assoc_stats()
7238 sas.sas_gapcnt = asoc->stats.gapcnt; in sctp_getsockopt_assoc_stats()
7239 sas.sas_outofseqtsns = asoc->stats.outofseqtsns; in sctp_getsockopt_assoc_stats()
7240 sas.sas_osacks = asoc->stats.osacks; in sctp_getsockopt_assoc_stats()
7241 sas.sas_isacks = asoc->stats.isacks; in sctp_getsockopt_assoc_stats()
7242 sas.sas_octrlchunks = asoc->stats.octrlchunks; in sctp_getsockopt_assoc_stats()
7243 sas.sas_ictrlchunks = asoc->stats.ictrlchunks; in sctp_getsockopt_assoc_stats()
7244 sas.sas_oodchunks = asoc->stats.oodchunks; in sctp_getsockopt_assoc_stats()
7245 sas.sas_iodchunks = asoc->stats.iodchunks; in sctp_getsockopt_assoc_stats()
7246 sas.sas_ouodchunks = asoc->stats.ouodchunks; in sctp_getsockopt_assoc_stats()
7247 sas.sas_iuodchunks = asoc->stats.iuodchunks; in sctp_getsockopt_assoc_stats()
7248 sas.sas_idupchunks = asoc->stats.idupchunks; in sctp_getsockopt_assoc_stats()
7249 sas.sas_opackets = asoc->stats.opackets; in sctp_getsockopt_assoc_stats()
7250 sas.sas_ipackets = asoc->stats.ipackets; in sctp_getsockopt_assoc_stats()
7256 sas.sas_maxrto = asoc->stats.max_obs_rto; in sctp_getsockopt_assoc_stats()
7257 memcpy(&sas.sas_obs_rto_ipaddr, &asoc->stats.obs_rto_ipaddr, in sctp_getsockopt_assoc_stats()
7261 asoc->stats.max_obs_rto = asoc->rto_min; in sctp_getsockopt_assoc_stats()
7264 return -EFAULT; in sctp_getsockopt_assoc_stats()
7269 return -EFAULT; in sctp_getsockopt_assoc_stats()
7281 return -EINVAL; in sctp_getsockopt_recvrcvinfo()
7284 if (sctp_sk(sk)->recvrcvinfo) in sctp_getsockopt_recvrcvinfo()
7287 return -EFAULT; in sctp_getsockopt_recvrcvinfo()
7289 return -EFAULT; in sctp_getsockopt_recvrcvinfo()
7301 return -EINVAL; in sctp_getsockopt_recvnxtinfo()
7304 if (sctp_sk(sk)->recvnxtinfo) in sctp_getsockopt_recvnxtinfo()
7307 return -EFAULT; in sctp_getsockopt_recvnxtinfo()
7309 return -EFAULT; in sctp_getsockopt_recvnxtinfo()
7320 int retval = -EFAULT; in sctp_getsockopt_pr_supported()
7323 retval = -EINVAL; in sctp_getsockopt_pr_supported()
7334 retval = -EINVAL; in sctp_getsockopt_pr_supported()
7338 params.assoc_value = asoc ? asoc->peer.prsctp_capable in sctp_getsockopt_pr_supported()
7339 : sctp_sk(sk)->ep->prsctp_enable; in sctp_getsockopt_pr_supported()
7359 int retval = -EFAULT; in sctp_getsockopt_default_prinfo()
7362 retval = -EINVAL; in sctp_getsockopt_default_prinfo()
7373 retval = -EINVAL; in sctp_getsockopt_default_prinfo()
7378 info.pr_policy = SCTP_PR_POLICY(asoc->default_flags); in sctp_getsockopt_default_prinfo()
7379 info.pr_value = asoc->default_timetolive; in sctp_getsockopt_default_prinfo()
7383 info.pr_policy = SCTP_PR_POLICY(sp->default_flags); in sctp_getsockopt_default_prinfo()
7384 info.pr_value = sp->default_timetolive; in sctp_getsockopt_default_prinfo()
7406 int retval = -EINVAL; in sctp_getsockopt_pr_assocstatus()
7413 retval = -EFAULT; in sctp_getsockopt_pr_assocstatus()
7431 asoc->abandoned_unsent[policy]; in sctp_getsockopt_pr_assocstatus()
7433 asoc->abandoned_sent[policy]; in sctp_getsockopt_pr_assocstatus()
7437 asoc->abandoned_unsent[__SCTP_PR_INDEX(policy)]; in sctp_getsockopt_pr_assocstatus()
7439 asoc->abandoned_sent[__SCTP_PR_INDEX(policy)]; in sctp_getsockopt_pr_assocstatus()
7443 retval = -EFAULT; in sctp_getsockopt_pr_assocstatus()
7448 retval = -EFAULT; in sctp_getsockopt_pr_assocstatus()
7465 int retval = -EINVAL; in sctp_getsockopt_pr_streamstatus()
7473 retval = -EFAULT; in sctp_getsockopt_pr_streamstatus()
7483 if (!asoc || params.sprstat_sid >= asoc->stream.outcnt) in sctp_getsockopt_pr_streamstatus()
7486 streamoute = SCTP_SO(&asoc->stream, params.sprstat_sid)->ext; in sctp_getsockopt_pr_streamstatus()
7500 streamoute->abandoned_unsent[policy]; in sctp_getsockopt_pr_streamstatus()
7502 streamoute->abandoned_sent[policy]; in sctp_getsockopt_pr_streamstatus()
7506 streamoute->abandoned_unsent[__SCTP_PR_INDEX(policy)]; in sctp_getsockopt_pr_streamstatus()
7508 streamoute->abandoned_sent[__SCTP_PR_INDEX(policy)]; in sctp_getsockopt_pr_streamstatus()
7512 retval = -EFAULT; in sctp_getsockopt_pr_streamstatus()
7528 int retval = -EFAULT; in sctp_getsockopt_reconfig_supported()
7531 retval = -EINVAL; in sctp_getsockopt_reconfig_supported()
7542 retval = -EINVAL; in sctp_getsockopt_reconfig_supported()
7546 params.assoc_value = asoc ? asoc->peer.reconf_capable in sctp_getsockopt_reconfig_supported()
7547 : sctp_sk(sk)->ep->reconf_enable; in sctp_getsockopt_reconfig_supported()
7567 int retval = -EFAULT; in sctp_getsockopt_enable_strreset()
7570 retval = -EINVAL; in sctp_getsockopt_enable_strreset()
7581 retval = -EINVAL; in sctp_getsockopt_enable_strreset()
7585 params.assoc_value = asoc ? asoc->strreset_enable in sctp_getsockopt_enable_strreset()
7586 : sctp_sk(sk)->ep->strreset_enable; in sctp_getsockopt_enable_strreset()
7606 int retval = -EFAULT; in sctp_getsockopt_scheduler()
7609 retval = -EINVAL; in sctp_getsockopt_scheduler()
7620 retval = -EINVAL; in sctp_getsockopt_scheduler()
7625 : sctp_sk(sk)->default_ss; in sctp_getsockopt_scheduler()
7645 int retval = -EFAULT; in sctp_getsockopt_scheduler_value()
7648 retval = -EINVAL; in sctp_getsockopt_scheduler_value()
7658 retval = -EINVAL; in sctp_getsockopt_scheduler_value()
7668 retval = -EFAULT; in sctp_getsockopt_scheduler_value()
7673 retval = -EFAULT; in sctp_getsockopt_scheduler_value()
7687 int retval = -EFAULT; in sctp_getsockopt_interleaving_supported()
7690 retval = -EINVAL; in sctp_getsockopt_interleaving_supported()
7701 retval = -EINVAL; in sctp_getsockopt_interleaving_supported()
7705 params.assoc_value = asoc ? asoc->peer.intl_capable in sctp_getsockopt_interleaving_supported()
7706 : sctp_sk(sk)->ep->intl_enable; in sctp_getsockopt_interleaving_supported()
7727 return -EINVAL; in sctp_getsockopt_reuse_port()
7730 val = sctp_sk(sk)->reuse; in sctp_getsockopt_reuse_port()
7732 return -EFAULT; in sctp_getsockopt_reuse_port()
7735 return -EFAULT; in sctp_getsockopt_reuse_port()
7748 return -EINVAL; in sctp_getsockopt_event()
7752 return -EFAULT; in sctp_getsockopt_event()
7756 return -EINVAL; in sctp_getsockopt_event()
7761 return -EINVAL; in sctp_getsockopt_event()
7763 subscribe = asoc ? asoc->subscribe : sctp_sk(sk)->subscribe; in sctp_getsockopt_event()
7767 return -EFAULT; in sctp_getsockopt_event()
7770 return -EFAULT; in sctp_getsockopt_event()
7781 int retval = -EFAULT; in sctp_getsockopt_asconf_supported()
7784 retval = -EINVAL; in sctp_getsockopt_asconf_supported()
7795 retval = -EINVAL; in sctp_getsockopt_asconf_supported()
7799 params.assoc_value = asoc ? asoc->peer.asconf_capable in sctp_getsockopt_asconf_supported()
7800 : sctp_sk(sk)->ep->asconf_enable; in sctp_getsockopt_asconf_supported()
7820 int retval = -EFAULT; in sctp_getsockopt_auth_supported()
7823 retval = -EINVAL; in sctp_getsockopt_auth_supported()
7834 retval = -EINVAL; in sctp_getsockopt_auth_supported()
7838 params.assoc_value = asoc ? asoc->peer.auth_capable in sctp_getsockopt_auth_supported()
7839 : sctp_sk(sk)->ep->auth_enable; in sctp_getsockopt_auth_supported()
7859 int retval = -EFAULT; in sctp_getsockopt_ecn_supported()
7862 retval = -EINVAL; in sctp_getsockopt_ecn_supported()
7873 retval = -EINVAL; in sctp_getsockopt_ecn_supported()
7877 params.assoc_value = asoc ? asoc->peer.ecn_capable in sctp_getsockopt_ecn_supported()
7878 : sctp_sk(sk)->ep->ecn_enable; in sctp_getsockopt_ecn_supported()
7898 int retval = -EFAULT; in sctp_getsockopt_pf_expose()
7901 retval = -EINVAL; in sctp_getsockopt_pf_expose()
7912 retval = -EINVAL; in sctp_getsockopt_pf_expose()
7916 params.assoc_value = asoc ? asoc->pf_expose in sctp_getsockopt_pf_expose()
7917 : sctp_sk(sk)->pf_expose; in sctp_getsockopt_pf_expose()
7940 return -EINVAL; in sctp_getsockopt_encap_port()
7944 return -EFAULT; in sctp_getsockopt_encap_port()
7954 return -EINVAL; in sctp_getsockopt_encap_port()
7957 encap_port = t->encap_port; in sctp_getsockopt_encap_port()
7969 return -EINVAL; in sctp_getsockopt_encap_port()
7973 encap_port = asoc->encap_port; in sctp_getsockopt_encap_port()
7977 encap_port = sctp_sk(sk)->encap_port; in sctp_getsockopt_encap_port()
7982 return -EFAULT; in sctp_getsockopt_encap_port()
7985 return -EFAULT; in sctp_getsockopt_encap_port()
8000 return -EINVAL; in sctp_getsockopt_probe_interval()
8004 return -EFAULT; in sctp_getsockopt_probe_interval()
8014 return -EINVAL; in sctp_getsockopt_probe_interval()
8017 probe_interval = jiffies_to_msecs(t->probe_interval); in sctp_getsockopt_probe_interval()
8029 return -EINVAL; in sctp_getsockopt_probe_interval()
8033 probe_interval = jiffies_to_msecs(asoc->probe_interval); in sctp_getsockopt_probe_interval()
8037 probe_interval = sctp_sk(sk)->probe_interval; in sctp_getsockopt_probe_interval()
8042 return -EFAULT; in sctp_getsockopt_probe_interval()
8045 return -EFAULT; in sctp_getsockopt_probe_interval()
8062 * are at all well-founded. in sctp_getsockopt()
8065 struct sctp_af *af = sctp_sk(sk)->pf->af; in sctp_getsockopt()
8067 retval = af->getsockopt(sk, level, optname, optval, optlen); in sctp_getsockopt()
8072 return -EFAULT; in sctp_getsockopt()
8075 return -EINVAL; in sctp_getsockopt()
8173 retval = -EOPNOTSUPP; in sctp_getsockopt()
8277 retval = -ENOPROTOOPT; in sctp_getsockopt()
8318 * would expect from a hash function, all the ports in a given list have
8320 * expecting that, right?); so each list has a set of ports, with a
8330 bool reuse = (sk->sk_reuse || sp->reuse); in sctp_get_port_local()
8338 snum = ntohs(addr->v4.sin_port); in sctp_get_port_local()
8348 remaining = (high - low) + 1; in sctp_get_port_local()
8359 spin_lock_bh(&head->lock); in sctp_get_port_local()
8360 sctp_for_each_hentry(pp, &head->chain) in sctp_get_port_local()
8361 if ((pp->port == rover) && in sctp_get_port_local()
8362 net_eq(net, pp->net)) in sctp_get_port_local()
8366 spin_unlock_bh(&head->lock); in sctp_get_port_local()
8368 } while (--remaining > 0); in sctp_get_port_local()
8376 * hash table list entry) is non-NULL and we hold it's in sctp_get_port_local()
8384 * to the port number (snum) - we detect that with the in sctp_get_port_local()
8388 spin_lock_bh(&head->lock); in sctp_get_port_local()
8389 sctp_for_each_hentry(pp, &head->chain) { in sctp_get_port_local()
8390 if ((pp->port == snum) && net_eq(pp->net, net)) in sctp_get_port_local()
8397 if (!hlist_empty(&pp->owner)) { in sctp_get_port_local()
8398 /* We had a port hash table hit - there is an in sctp_get_port_local()
8400 * used by other socket (pp->owner not empty); that other in sctp_get_port_local()
8407 if ((pp->fastreuse && reuse && in sctp_get_port_local()
8408 sk->sk_state != SCTP_SS_LISTENING) || in sctp_get_port_local()
8409 (pp->fastreuseport && sk->sk_reuseport && in sctp_get_port_local()
8410 uid_eq(pp->fastuid, uid))) in sctp_get_port_local()
8414 * (pp->port) [via the pointers bind_next and in sctp_get_port_local()
8415 * bind_pprev in the struct sock *sk2 (pp->sk)]. On each one, in sctp_get_port_local()
8423 sk_for_each_bound(sk2, &pp->owner) { in sctp_get_port_local()
8424 int bound_dev_if2 = READ_ONCE(sk2->sk_bound_dev_if); in sctp_get_port_local()
8426 struct sctp_endpoint *ep2 = sp2->ep; in sctp_get_port_local()
8429 (reuse && (sk2->sk_reuse || sp2->reuse) && in sctp_get_port_local()
8430 sk2->sk_state != SCTP_SS_LISTENING) || in sctp_get_port_local()
8431 (sk->sk_reuseport && sk2->sk_reuseport && in sctp_get_port_local()
8435 if ((!sk->sk_bound_dev_if || !bound_dev_if2 || in sctp_get_port_local()
8436 sk->sk_bound_dev_if == bound_dev_if2) && in sctp_get_port_local()
8437 sctp_bind_addr_conflict(&ep2->base.bind_addr, in sctp_get_port_local()
8453 * if sk->sk_reuse is too (that is, if the caller requested in sctp_get_port_local()
8454 * SO_REUSEADDR on this socket -sk-). in sctp_get_port_local()
8456 if (hlist_empty(&pp->owner)) { in sctp_get_port_local()
8457 if (reuse && sk->sk_state != SCTP_SS_LISTENING) in sctp_get_port_local()
8458 pp->fastreuse = 1; in sctp_get_port_local()
8460 pp->fastreuse = 0; in sctp_get_port_local()
8462 if (sk->sk_reuseport) { in sctp_get_port_local()
8463 pp->fastreuseport = 1; in sctp_get_port_local()
8464 pp->fastuid = uid; in sctp_get_port_local()
8466 pp->fastreuseport = 0; in sctp_get_port_local()
8469 if (pp->fastreuse && in sctp_get_port_local()
8470 (!reuse || sk->sk_state == SCTP_SS_LISTENING)) in sctp_get_port_local()
8471 pp->fastreuse = 0; in sctp_get_port_local()
8473 if (pp->fastreuseport && in sctp_get_port_local()
8474 (!sk->sk_reuseport || !uid_eq(pp->fastuid, uid))) in sctp_get_port_local()
8475 pp->fastreuseport = 0; in sctp_get_port_local()
8483 if (!sp->bind_hash) { in sctp_get_port_local()
8484 inet_sk(sk)->inet_num = snum; in sctp_get_port_local()
8485 sk_add_bind_node(sk, &pp->owner); in sctp_get_port_local()
8486 sp->bind_hash = pp; in sctp_get_port_local()
8491 spin_unlock_bh(&head->lock); in sctp_get_port_local()
8501 struct sctp_af *af = sctp_sk(sk)->pf->af; in sctp_get_port()
8504 af->from_sk(&addr, sk); in sctp_get_port()
8507 /* Note: sk->sk_num gets filled in if ephemeral port request. */ in sctp_get_port()
8517 struct sctp_endpoint *ep = sp->ep; in sctp_listen_start()
8522 if (!sp->hmac && sp->sctp_hmac_alg) { in sctp_listen_start()
8523 sprintf(alg, "hmac(%s)", sp->sctp_hmac_alg); in sctp_listen_start()
8527 sp->sctp_hmac_alg, PTR_ERR(tfm)); in sctp_listen_start()
8528 return -ENOSYS; in sctp_listen_start()
8530 sctp_sk(sk)->hmac = tfm; in sctp_listen_start()
8545 if (!ep->base.bind_addr.port) { in sctp_listen_start()
8547 return -EAGAIN; in sctp_listen_start()
8549 if (sctp_get_port(sk, inet_sk(sk)->inet_num)) { in sctp_listen_start()
8551 return -EADDRINUSE; in sctp_listen_start()
8555 WRITE_ONCE(sk->sk_max_ack_backlog, backlog); in sctp_listen_start()
8575 struct sock *sk = sock->sk; in sctp_inet_listen()
8576 struct sctp_endpoint *ep = sctp_sk(sk)->ep; in sctp_inet_listen()
8577 int err = -EINVAL; in sctp_inet_listen()
8584 /* Peeled-off sockets are not allowed to listen(). */ in sctp_inet_listen()
8588 if (sock->state != SS_UNCONNECTED) in sctp_inet_listen()
8601 sk->sk_state = SCTP_SS_CLOSED; in sctp_inet_listen()
8602 if (sk->sk_reuse || sctp_sk(sk)->reuse) in sctp_inet_listen()
8603 sctp_sk(sk)->bind_hash->fastreuse = 1; in sctp_inet_listen()
8609 WRITE_ONCE(sk->sk_max_ack_backlog, backlog); in sctp_inet_listen()
8637 struct sock *sk = sock->sk; in sctp_poll()
8645 /* A TCP-style listening socket becomes readable when the accept queue in sctp_poll()
8649 return (!list_empty(&sp->ep->asocs)) ? in sctp_poll()
8655 if (sk->sk_err || !skb_queue_empty_lockless(&sk->sk_error_queue)) in sctp_poll()
8658 if (sk->sk_shutdown & RCV_SHUTDOWN) in sctp_poll()
8660 if (sk->sk_shutdown == SHUTDOWN_MASK) in sctp_poll()
8663 /* Is it readable? Reconsider this code with TCP-style support. */ in sctp_poll()
8664 if (!skb_queue_empty_lockless(&sk->sk_receive_queue)) in sctp_poll()
8702 pp->port = snum; in sctp_bucket_create()
8703 pp->fastreuse = 0; in sctp_bucket_create()
8704 INIT_HLIST_HEAD(&pp->owner); in sctp_bucket_create()
8705 pp->net = net; in sctp_bucket_create()
8706 hlist_add_head(&pp->node, &head->chain); in sctp_bucket_create()
8711 /* Caller must hold hashbucket lock for this tb with local BH disabled */
8714 if (pp && hlist_empty(&pp->owner)) { in sctp_bucket_destroy()
8715 __hlist_del(&pp->node); in sctp_bucket_destroy()
8726 inet_sk(sk)->inet_num)]; in __sctp_put_port()
8729 spin_lock(&head->lock); in __sctp_put_port()
8730 pp = sctp_sk(sk)->bind_hash; in __sctp_put_port()
8732 sctp_sk(sk)->bind_hash = NULL; in __sctp_put_port()
8733 inet_sk(sk)->inet_num = 0; in __sctp_put_port()
8735 spin_unlock(&head->lock); in __sctp_put_port()
8758 af = sctp_sk(sk)->pf->af; in sctp_autobind()
8760 port = htons(inet_sk(sk)->inet_num); in sctp_autobind()
8761 af->inaddr_any(&autoaddr, port); in sctp_autobind()
8763 return sctp_do_bind(sk, &autoaddr, af->sockaddr_len); in sctp_autobind()
8775 * Historically Berkeley-derived implementations have passed only one object
8780 * |<--------------------------- msg_controllen -------------------------->|
8783 * |<----- ancillary data object ----->|<----- ancillary data object ----->|
8785 * |<---------- CMSG_SPACE() --------->|<---------- CMSG_SPACE() --------->|
8788 * |<---------- cmsg_len ---------->| |<--------- cmsg_len ----------->| |
8790 * |<--------- CMSG_LEN() --------->| |<-------- CMSG_LEN() ---------->| |
8793 * +-----+-----+-----+--+-----------+--+-----+-----+-----+--+-----------+--+
8798 * +-----+-----+-----+--+-----------+--+-----+-----+-----+--+-----------+--+
8812 return -EINVAL; in sctp_msghdr_parse()
8815 if (cmsg->cmsg_level != IPPROTO_SCTP) in sctp_msghdr_parse()
8819 switch (cmsg->cmsg_type) { in sctp_msghdr_parse()
8831 * ------------ ------------ ---------------------- in sctp_msghdr_parse()
8834 if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct sctp_initmsg))) in sctp_msghdr_parse()
8835 return -EINVAL; in sctp_msghdr_parse()
8837 cmsgs->init = CMSG_DATA(cmsg); in sctp_msghdr_parse()
8849 * ------------ ------------ ---------------------- in sctp_msghdr_parse()
8852 if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct sctp_sndrcvinfo))) in sctp_msghdr_parse()
8853 return -EINVAL; in sctp_msghdr_parse()
8855 cmsgs->srinfo = CMSG_DATA(cmsg); in sctp_msghdr_parse()
8857 if (cmsgs->srinfo->sinfo_flags & in sctp_msghdr_parse()
8861 return -EINVAL; in sctp_msghdr_parse()
8873 * ------------ ------------ --------------------- in sctp_msghdr_parse()
8876 if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct sctp_sndinfo))) in sctp_msghdr_parse()
8877 return -EINVAL; in sctp_msghdr_parse()
8879 cmsgs->sinfo = CMSG_DATA(cmsg); in sctp_msghdr_parse()
8881 if (cmsgs->sinfo->snd_flags & in sctp_msghdr_parse()
8885 return -EINVAL; in sctp_msghdr_parse()
8889 * 5.3.7 SCTP PR-SCTP Information Structure (SCTP_PRINFO) in sctp_msghdr_parse()
8894 * ------------ ------------ --------------------- in sctp_msghdr_parse()
8897 if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct sctp_prinfo))) in sctp_msghdr_parse()
8898 return -EINVAL; in sctp_msghdr_parse()
8900 cmsgs->prinfo = CMSG_DATA(cmsg); in sctp_msghdr_parse()
8901 if (cmsgs->prinfo->pr_policy & ~SCTP_PR_SCTP_MASK) in sctp_msghdr_parse()
8902 return -EINVAL; in sctp_msghdr_parse()
8904 if (cmsgs->prinfo->pr_policy == SCTP_PR_SCTP_NONE) in sctp_msghdr_parse()
8905 cmsgs->prinfo->pr_value = 0; in sctp_msghdr_parse()
8914 * ------------ ------------ --------------------- in sctp_msghdr_parse()
8917 if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct sctp_authinfo))) in sctp_msghdr_parse()
8918 return -EINVAL; in sctp_msghdr_parse()
8920 cmsgs->authinfo = CMSG_DATA(cmsg); in sctp_msghdr_parse()
8930 * ------------ ------------ --------------------- in sctp_msghdr_parse()
8932 * ------------ ------------ --------------------- in sctp_msghdr_parse()
8935 cmsgs->addrs_msg = my_msg; in sctp_msghdr_parse()
8938 return -EINVAL; in sctp_msghdr_parse()
8962 if (!skb_queue_empty(&sk->sk_receive_queue)) in sctp_wait_for_packet()
8966 if (sk->sk_shutdown & RCV_SHUTDOWN) in sctp_wait_for_packet()
8972 error = -ENOTCONN; in sctp_wait_for_packet()
8975 if (list_empty(&sctp_sk(sk)->ep->asocs) && !sctp_sstate(sk, LISTENING)) in sctp_wait_for_packet()
9028 skb = skb_peek(&sk->sk_receive_queue); in sctp_skb_recv_datagram()
9030 refcount_inc(&skb->users); in sctp_skb_recv_datagram()
9032 skb = __skb_dequeue(&sk->sk_receive_queue); in sctp_skb_recv_datagram()
9038 /* Caller is allowed not to check sk->sk_err before calling. */ in sctp_skb_recv_datagram()
9043 if (sk->sk_shutdown & RCV_SHUTDOWN) in sctp_skb_recv_datagram()
9049 if (!skb_queue_empty_lockless(&sk->sk_receive_queue)) in sctp_skb_recv_datagram()
9054 error = -EAGAIN; in sctp_skb_recv_datagram()
9069 struct sock *sk = asoc->base.sk; in __sctp_write_space()
9074 if (waitqueue_active(&asoc->wait)) in __sctp_write_space()
9075 wake_up_interruptible(&asoc->wait); in __sctp_write_space()
9081 wq = rcu_dereference(sk->sk_wq); in __sctp_write_space()
9083 if (waitqueue_active(&wq->wait)) in __sctp_write_space()
9084 wake_up_interruptible(&wq->wait); in __sctp_write_space()
9090 if (!(sk->sk_shutdown & SEND_SHUTDOWN)) in __sctp_write_space()
9105 if (asoc->ep->sndbuf_policy) in sctp_wake_up_waiters()
9111 if (asoc->base.dead) in sctp_wake_up_waiters()
9127 if (&tmp->asocs == &((sctp_sk(sk))->ep->asocs)) in sctp_wake_up_waiters()
9143 struct sctp_chunk *chunk = skb_shinfo(skb)->destructor_arg; in sctp_wfree()
9144 struct sctp_association *asoc = chunk->asoc; in sctp_wfree()
9145 struct sock *sk = asoc->base.sk; in sctp_wfree()
9147 sk_mem_uncharge(sk, skb->truesize); in sctp_wfree()
9148 sk_wmem_queued_add(sk, -(skb->truesize + sizeof(struct sctp_chunk))); in sctp_wfree()
9149 asoc->sndbuf_used -= skb->truesize + sizeof(struct sctp_chunk); in sctp_wfree()
9151 &sk->sk_wmem_alloc)); in sctp_wfree()
9153 if (chunk->shkey) { in sctp_wfree()
9154 struct sctp_shared_key *shkey = chunk->shkey; in sctp_wfree()
9160 if (shkey->deactivated && !list_empty(&shkey->key_list) && in sctp_wfree()
9161 refcount_read(&shkey->refcnt) == 2) { in sctp_wfree()
9164 ev = sctp_ulpevent_make_authkey(asoc, shkey->key_id, in sctp_wfree()
9168 asoc->stream.si->enqueue_event(&asoc->ulpq, ev); in sctp_wfree()
9170 sctp_auth_shkey_release(chunk->shkey); in sctp_wfree()
9186 struct sock *sk = skb->sk; in sctp_sock_rfree()
9189 atomic_sub(event->rmem_len, &sk->sk_rmem_alloc); in sctp_sock_rfree()
9194 sk_mem_uncharge(sk, event->rmem_len); in sctp_sock_rfree()
9202 struct sock *sk = asoc->base.sk; in sctp_wait_for_sndbuf()
9215 prepare_to_wait_exclusive(&asoc->wait, &wait, in sctp_wait_for_sndbuf()
9217 if (asoc->base.dead) in sctp_wait_for_sndbuf()
9221 if (sk->sk_err || asoc->state >= SCTP_STATE_SHUTDOWN_PENDING) in sctp_wait_for_sndbuf()
9235 if (sk != asoc->base.sk) in sctp_wait_for_sndbuf()
9242 finish_wait(&asoc->wait, &wait); in sctp_wait_for_sndbuf()
9250 err = -ESRCH; in sctp_wait_for_sndbuf()
9254 err = -EPIPE; in sctp_wait_for_sndbuf()
9262 err = -EAGAIN; in sctp_wait_for_sndbuf()
9273 wq = rcu_dereference(sk->sk_wq); in sctp_data_ready()
9275 wake_up_interruptible_sync_poll(&wq->wait, EPOLLIN | in sctp_data_ready()
9287 list_for_each_entry(asoc, &((sctp_sk(sk))->ep->asocs), asocs) { in sctp_write_space()
9295 * associations on the same socket. For a UDP-style socket with
9299 * would cause an unwanted block under certain circumstances. For the 1-1
9300 * UDP-style sockets or TCP-style sockets, this code should work.
9301 * - Daisy
9305 return READ_ONCE(sk->sk_sndbuf) > READ_ONCE(sk->sk_wmem_queued); in sctp_writeable()
9313 struct sock *sk = asoc->base.sk; in sctp_wait_for_connect()
9324 prepare_to_wait_exclusive(&asoc->wait, &wait, in sctp_wait_for_connect()
9328 if (sk->sk_shutdown & RCV_SHUTDOWN) in sctp_wait_for_connect()
9330 if (sk->sk_err || asoc->state >= SCTP_STATE_SHUTDOWN_PENDING || in sctp_wait_for_connect()
9331 asoc->base.dead) in sctp_wait_for_connect()
9350 finish_wait(&asoc->wait, &wait); in sctp_wait_for_connect()
9358 if (asoc->init_err_counter + 1 > asoc->max_init_attempts) in sctp_wait_for_connect()
9359 err = -ETIMEDOUT; in sctp_wait_for_connect()
9361 err = -ECONNREFUSED; in sctp_wait_for_connect()
9369 err = -EINPROGRESS; in sctp_wait_for_connect()
9379 ep = sctp_sk(sk)->ep; in sctp_wait_for_accept()
9386 if (list_empty(&ep->asocs)) { in sctp_wait_for_accept()
9392 err = -EINVAL; in sctp_wait_for_accept()
9397 if (!list_empty(&ep->asocs)) in sctp_wait_for_accept()
9404 err = -EAGAIN; in sctp_wait_for_accept()
9420 if (list_empty(&sctp_sk(sk)->ep->asocs)) in sctp_wait_for_close()
9434 if (!skb->data_len) in sctp_skb_set_owner_r_frag()
9452 newsk->sk_type = sk->sk_type; in sctp_copy_sock()
9453 newsk->sk_bound_dev_if = sk->sk_bound_dev_if; in sctp_copy_sock()
9454 newsk->sk_flags = sk->sk_flags; in sctp_copy_sock()
9455 newsk->sk_tsflags = sk->sk_tsflags; in sctp_copy_sock()
9456 newsk->sk_no_check_tx = sk->sk_no_check_tx; in sctp_copy_sock()
9457 newsk->sk_no_check_rx = sk->sk_no_check_rx; in sctp_copy_sock()
9458 newsk->sk_reuse = sk->sk_reuse; in sctp_copy_sock()
9459 sctp_sk(newsk)->reuse = sp->reuse; in sctp_copy_sock()
9461 newsk->sk_shutdown = sk->sk_shutdown; in sctp_copy_sock()
9462 newsk->sk_destruct = sk->sk_destruct; in sctp_copy_sock()
9463 newsk->sk_family = sk->sk_family; in sctp_copy_sock()
9464 newsk->sk_protocol = IPPROTO_SCTP; in sctp_copy_sock()
9465 newsk->sk_backlog_rcv = sk->sk_prot->backlog_rcv; in sctp_copy_sock()
9466 newsk->sk_sndbuf = sk->sk_sndbuf; in sctp_copy_sock()
9467 newsk->sk_rcvbuf = sk->sk_rcvbuf; in sctp_copy_sock()
9468 newsk->sk_lingertime = sk->sk_lingertime; in sctp_copy_sock()
9469 newsk->sk_rcvtimeo = sk->sk_rcvtimeo; in sctp_copy_sock()
9470 newsk->sk_sndtimeo = sk->sk_sndtimeo; in sctp_copy_sock()
9471 newsk->sk_rxhash = sk->sk_rxhash; in sctp_copy_sock()
9478 newinet->inet_sport = inet->inet_sport; in sctp_copy_sock()
9479 newinet->inet_saddr = inet->inet_saddr; in sctp_copy_sock()
9480 newinet->inet_rcv_saddr = inet->inet_rcv_saddr; in sctp_copy_sock()
9481 newinet->inet_dport = htons(asoc->peer.port); in sctp_copy_sock()
9482 newinet->pmtudisc = inet->pmtudisc; in sctp_copy_sock()
9483 atomic_set(&newinet->inet_id, get_random_u16()); in sctp_copy_sock()
9485 newinet->uc_ttl = inet->uc_ttl; in sctp_copy_sock()
9487 newinet->mc_ttl = 1; in sctp_copy_sock()
9488 newinet->mc_index = 0; in sctp_copy_sock()
9489 newinet->mc_list = NULL; in sctp_copy_sock()
9491 if (newsk->sk_flags & SK_FLAGS_TIMESTAMP) in sctp_copy_sock()
9505 ancestor_size += sk_from->sk_prot->obj_size; in sctp_copy_descendant()
9506 ancestor_size -= offsetof(struct sctp_sock, pd_lobby); in sctp_copy_descendant()
9520 struct sctp_endpoint *newep = newsp->ep; in sctp_sock_migrate()
9529 newsk->sk_sndbuf = oldsk->sk_sndbuf; in sctp_sock_migrate()
9530 newsk->sk_rcvbuf = oldsk->sk_rcvbuf; in sctp_sock_migrate()
9537 newsp->ep = newep; in sctp_sock_migrate()
9538 newsp->hmac = NULL; in sctp_sock_migrate()
9542 inet_sk(oldsk)->inet_num)]; in sctp_sock_migrate()
9543 spin_lock_bh(&head->lock); in sctp_sock_migrate()
9544 pp = sctp_sk(oldsk)->bind_hash; in sctp_sock_migrate()
9545 sk_add_bind_node(newsk, &pp->owner); in sctp_sock_migrate()
9546 sctp_sk(newsk)->bind_hash = pp; in sctp_sock_migrate()
9547 inet_sk(newsk)->inet_num = inet_sk(oldsk)->inet_num; in sctp_sock_migrate()
9548 spin_unlock_bh(&head->lock); in sctp_sock_migrate()
9553 err = sctp_bind_addr_dup(&newsp->ep->base.bind_addr, in sctp_sock_migrate()
9554 &oldsp->ep->base.bind_addr, GFP_KERNEL); in sctp_sock_migrate()
9559 * that net->sctp.auth_enable has been changed to 0 by users and in sctp_sock_migrate()
9562 if (oldsp->ep->auth_hmacs) { in sctp_sock_migrate()
9563 err = sctp_auth_init_hmacs(newsp->ep, GFP_KERNEL); in sctp_sock_migrate()
9573 sctp_skb_for_each(skb, &oldsk->sk_receive_queue, tmp) { in sctp_sock_migrate()
9575 if (event->asoc == assoc) { in sctp_sock_migrate()
9576 __skb_unlink(skb, &oldsk->sk_receive_queue); in sctp_sock_migrate()
9577 __skb_queue_tail(&newsk->sk_receive_queue, skb); in sctp_sock_migrate()
9586 * 3) Peeling off non-partial delivery; move pd_lobby to receive_queue. in sctp_sock_migrate()
9588 atomic_set(&sctp_sk(newsk)->pd_mode, assoc->ulpq.pd_mode); in sctp_sock_migrate()
9590 if (atomic_read(&sctp_sk(oldsk)->pd_mode)) { in sctp_sock_migrate()
9594 if (assoc->ulpq.pd_mode) { in sctp_sock_migrate()
9595 queue = &newsp->pd_lobby; in sctp_sock_migrate()
9597 queue = &newsk->sk_receive_queue; in sctp_sock_migrate()
9602 sctp_skb_for_each(skb, &oldsp->pd_lobby, tmp) { in sctp_sock_migrate()
9604 if (event->asoc == assoc) { in sctp_sock_migrate()
9605 __skb_unlink(skb, &oldsp->pd_lobby); in sctp_sock_migrate()
9614 if (assoc->ulpq.pd_mode) in sctp_sock_migrate()
9622 * original UDP-style socket or created with the accept() call on a in sctp_sock_migrate()
9623 * TCP-style socket.. in sctp_sock_migrate()
9625 newsp->type = type; in sctp_sock_migrate()
9627 /* Mark the new socket "in-use" by the user so that any packets in sctp_sock_migrate()
9630 * backlog processing on the old socket and new-packet processing in sctp_sock_migrate()
9646 newsk->sk_shutdown |= RCV_SHUTDOWN; in sctp_sock_migrate()
9681 .usersize = offsetof(struct sctp_sock, initmsg) -
9709 sk->sk_destruct = sctp_v6_destruct_sock; in sctp_v6_init_sock()
9738 .usersize = offsetof(struct sctp6_sock, sctp.initmsg) -