1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* SCTP kernel implementation
3 * (C) Copyright IBM Corp. 2001, 2004
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.
8 * Copyright (c) 2001 La Monte H.P. Yarroll
10 * This file is part of the SCTP kernel implementation
12 * These functions interface with the sockets layer to implement the
13 * SCTP Extensions for the Sockets API.
15 * Note that the descriptions from the specification are USER level
16 * functions--this file is the functions which populate the struct proto
17 * for SCTP which is the BOTTOM of the sockets interface.
19 * Please send any bug reports or fixes you make to the
21 * lksctp developers <linux-sctp@vger.kernel.org>
23 * Written or modified by:
24 * La Monte H.P. Yarroll <piggy@acm.org>
25 * Narasimha Budihal <narsi@refcode.org>
26 * Karl Knutson <karl@athena.chicago.il.us>
27 * Jon Grimm <jgrimm@us.ibm.com>
28 * Xingang Guo <xingang.guo@intel.com>
29 * Daisy Chang <daisyc@us.ibm.com>
30 * Sridhar Samudrala <samudrala@us.ibm.com>
31 * Inaky Perez-Gonzalez <inaky.gonzalez@intel.com>
32 * Ardelle Fan <ardelle.fan@intel.com>
33 * Ryan Layer <rmlayer@us.ibm.com>
34 * Anup Pemmaiah <pemmaiah@cc.usu.edu>
35 * Kevin Gao <kevin.gao@intel.com>
38 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
40 #include <crypto/hash.h>
41 #include <linux/types.h>
42 #include <linux/kernel.h>
43 #include <linux/wait.h>
44 #include <linux/time.h>
45 #include <linux/sched/signal.h>
47 #include <linux/capability.h>
48 #include <linux/fcntl.h>
49 #include <linux/poll.h>
50 #include <linux/init.h>
51 #include <linux/slab.h>
52 #include <linux/file.h>
53 #include <linux/compat.h>
54 #include <linux/rhashtable.h>
58 #include <net/route.h>
60 #include <net/inet_common.h>
61 #include <net/busy_poll.h>
62 #include <trace/events/sock.h>
64 #include <linux/socket.h> /* for sa_family_t */
65 #include <linux/export.h>
67 #include <net/sctp/sctp.h>
68 #include <net/sctp/sm.h>
69 #include <net/sctp/stream_sched.h>
72 /* Forward declarations for internal helper functions. */
73 static bool sctp_writeable(const struct sock
*sk
);
74 static void sctp_wfree(struct sk_buff
*skb
);
75 static int sctp_wait_for_sndbuf(struct sctp_association
*asoc
,
76 struct sctp_transport
*transport
,
77 long *timeo_p
, size_t msg_len
);
78 static int sctp_wait_for_packet(struct sock
*sk
, int *err
, long *timeo_p
);
79 static int sctp_wait_for_connect(struct sctp_association
*, long *timeo_p
);
80 static int sctp_wait_for_accept(struct sock
*sk
, long timeo
);
81 static void sctp_wait_for_close(struct sock
*sk
, long timeo
);
82 static void sctp_destruct_sock(struct sock
*sk
);
83 static struct sctp_af
*sctp_sockaddr_af(struct sctp_sock
*opt
,
84 union sctp_addr
*addr
, int len
);
85 static int sctp_bindx_add(struct sock
*, struct sockaddr
*, int);
86 static int sctp_bindx_rem(struct sock
*, struct sockaddr
*, int);
87 static int sctp_send_asconf_add_ip(struct sock
*, struct sockaddr
*, int);
88 static int sctp_send_asconf_del_ip(struct sock
*, struct sockaddr
*, int);
89 static int sctp_send_asconf(struct sctp_association
*asoc
,
90 struct sctp_chunk
*chunk
);
91 static int sctp_do_bind(struct sock
*, union sctp_addr
*, int);
92 static int sctp_autobind(struct sock
*sk
);
93 static int sctp_sock_migrate(struct sock
*oldsk
, struct sock
*newsk
,
94 struct sctp_association
*assoc
,
95 enum sctp_socket_type type
);
97 static unsigned long sctp_memory_pressure
;
98 static atomic_long_t sctp_memory_allocated
;
99 static DEFINE_PER_CPU(int, sctp_memory_per_cpu_fw_alloc
);
100 struct percpu_counter sctp_sockets_allocated
;
102 static void sctp_enter_memory_pressure(struct sock
*sk
)
104 WRITE_ONCE(sctp_memory_pressure
, 1);
108 /* Get the sndbuf space available at the time on the association. */
109 static inline int sctp_wspace(struct sctp_association
*asoc
)
111 struct sock
*sk
= asoc
->base
.sk
;
113 return asoc
->ep
->sndbuf_policy
? sk
->sk_sndbuf
- asoc
->sndbuf_used
114 : sk_stream_wspace(sk
);
117 /* Increment the used sndbuf space count of the corresponding association by
118 * the size of the outgoing data chunk.
119 * Also, set the skb destructor for sndbuf accounting later.
121 * Since it is always 1-1 between chunk and skb, and also a new skb is always
122 * allocated for chunk bundling in sctp_packet_transmit(), we can use the
123 * destructor in the data chunk skb for the purpose of the sndbuf space
126 static inline void sctp_set_owner_w(struct sctp_chunk
*chunk
)
128 struct sctp_association
*asoc
= chunk
->asoc
;
129 struct sock
*sk
= asoc
->base
.sk
;
131 /* The sndbuf space is tracked per association. */
132 sctp_association_hold(asoc
);
135 sctp_auth_shkey_hold(chunk
->shkey
);
137 skb_set_owner_w(chunk
->skb
, sk
);
139 chunk
->skb
->destructor
= sctp_wfree
;
140 /* Save the chunk pointer in skb for sctp_wfree to use later. */
141 skb_shinfo(chunk
->skb
)->destructor_arg
= chunk
;
143 refcount_add(sizeof(struct sctp_chunk
), &sk
->sk_wmem_alloc
);
144 asoc
->sndbuf_used
+= chunk
->skb
->truesize
+ sizeof(struct sctp_chunk
);
145 sk_wmem_queued_add(sk
, chunk
->skb
->truesize
+ sizeof(struct sctp_chunk
));
146 sk_mem_charge(sk
, chunk
->skb
->truesize
);
149 static void sctp_clear_owner_w(struct sctp_chunk
*chunk
)
151 skb_orphan(chunk
->skb
);
154 #define traverse_and_process() \
157 if (msg == prev_msg) \
159 list_for_each_entry(c, &msg->chunks, frag_list) { \
160 if ((clear && asoc->base.sk == c->skb->sk) || \
161 (!clear && asoc->base.sk != c->skb->sk)) \
167 static void sctp_for_each_tx_datachunk(struct sctp_association
*asoc
,
169 void (*cb
)(struct sctp_chunk
*))
172 struct sctp_datamsg
*msg
, *prev_msg
= NULL
;
173 struct sctp_outq
*q
= &asoc
->outqueue
;
174 struct sctp_chunk
*chunk
, *c
;
175 struct sctp_transport
*t
;
177 list_for_each_entry(t
, &asoc
->peer
.transport_addr_list
, transports
)
178 list_for_each_entry(chunk
, &t
->transmitted
, transmitted_list
)
179 traverse_and_process();
181 list_for_each_entry(chunk
, &q
->retransmit
, transmitted_list
)
182 traverse_and_process();
184 list_for_each_entry(chunk
, &q
->sacked
, transmitted_list
)
185 traverse_and_process();
187 list_for_each_entry(chunk
, &q
->abandoned
, transmitted_list
)
188 traverse_and_process();
190 list_for_each_entry(chunk
, &q
->out_chunk_list
, list
)
191 traverse_and_process();
194 static void sctp_for_each_rx_skb(struct sctp_association
*asoc
, struct sock
*sk
,
195 void (*cb
)(struct sk_buff
*, struct sock
*))
198 struct sk_buff
*skb
, *tmp
;
200 sctp_skb_for_each(skb
, &asoc
->ulpq
.lobby
, tmp
)
203 sctp_skb_for_each(skb
, &asoc
->ulpq
.reasm
, tmp
)
206 sctp_skb_for_each(skb
, &asoc
->ulpq
.reasm_uo
, tmp
)
210 /* Verify that this is a valid address. */
211 static inline int sctp_verify_addr(struct sock
*sk
, union sctp_addr
*addr
,
216 /* Verify basic sockaddr. */
217 af
= sctp_sockaddr_af(sctp_sk(sk
), addr
, len
);
221 /* Is this a valid SCTP address? */
222 if (!af
->addr_valid(addr
, sctp_sk(sk
), NULL
))
225 if (!sctp_sk(sk
)->pf
->send_verify(sctp_sk(sk
), (addr
)))
231 /* Look up the association by its id. If this is not a UDP-style
232 * socket, the ID field is always ignored.
234 struct sctp_association
*sctp_id2assoc(struct sock
*sk
, sctp_assoc_t id
)
236 struct sctp_association
*asoc
= NULL
;
238 /* If this is not a UDP-style socket, assoc id should be ignored. */
239 if (!sctp_style(sk
, UDP
)) {
240 /* Return NULL if the socket state is not ESTABLISHED. It
241 * could be a TCP-style listening socket or a socket which
242 * hasn't yet called connect() to establish an association.
244 if (!sctp_sstate(sk
, ESTABLISHED
) && !sctp_sstate(sk
, CLOSING
))
247 /* Get the first and the only association from the list. */
248 if (!list_empty(&sctp_sk(sk
)->ep
->asocs
))
249 asoc
= list_entry(sctp_sk(sk
)->ep
->asocs
.next
,
250 struct sctp_association
, asocs
);
254 /* Otherwise this is a UDP-style socket. */
255 if (id
<= SCTP_ALL_ASSOC
)
258 spin_lock_bh(&sctp_assocs_id_lock
);
259 asoc
= (struct sctp_association
*)idr_find(&sctp_assocs_id
, (int)id
);
260 if (asoc
&& (asoc
->base
.sk
!= sk
|| asoc
->base
.dead
))
262 spin_unlock_bh(&sctp_assocs_id_lock
);
267 /* Look up the transport from an address and an assoc id. If both address and
268 * id are specified, the associations matching the address and the id should be
271 static struct sctp_transport
*sctp_addr_id2transport(struct sock
*sk
,
272 struct sockaddr_storage
*addr
,
275 struct sctp_association
*addr_asoc
= NULL
, *id_asoc
= NULL
;
276 struct sctp_af
*af
= sctp_get_af_specific(addr
->ss_family
);
277 union sctp_addr
*laddr
= (union sctp_addr
*)addr
;
278 struct sctp_transport
*transport
;
280 if (!af
|| sctp_verify_addr(sk
, laddr
, af
->sockaddr_len
))
283 addr_asoc
= sctp_endpoint_lookup_assoc(sctp_sk(sk
)->ep
,
290 id_asoc
= sctp_id2assoc(sk
, id
);
291 if (id_asoc
&& (id_asoc
!= addr_asoc
))
294 sctp_get_pf_specific(sk
->sk_family
)->addr_to_user(sctp_sk(sk
),
295 (union sctp_addr
*)addr
);
300 /* API 3.1.2 bind() - UDP Style Syntax
301 * The syntax of bind() is,
303 * ret = bind(int sd, struct sockaddr *addr, int addrlen);
305 * sd - the socket descriptor returned by socket().
306 * addr - the address structure (struct sockaddr_in or struct
307 * sockaddr_in6 [RFC 2553]),
308 * addr_len - the size of the address structure.
310 static int sctp_bind(struct sock
*sk
, struct sockaddr
*addr
, int addr_len
)
316 pr_debug("%s: sk:%p, addr:%p, addr_len:%d\n", __func__
, sk
,
319 /* Disallow binding twice. */
320 if (!sctp_sk(sk
)->ep
->base
.bind_addr
.port
)
321 retval
= sctp_do_bind(sk
, (union sctp_addr
*)addr
,
331 static int sctp_get_port_local(struct sock
*, union sctp_addr
*);
333 /* Verify this is a valid sockaddr. */
334 static struct sctp_af
*sctp_sockaddr_af(struct sctp_sock
*opt
,
335 union sctp_addr
*addr
, int len
)
339 /* Check minimum size. */
340 if (len
< sizeof (struct sockaddr
))
343 if (!opt
->pf
->af_supported(addr
->sa
.sa_family
, opt
))
346 if (addr
->sa
.sa_family
== AF_INET6
) {
347 if (len
< SIN6_LEN_RFC2133
)
349 /* V4 mapped address are really of AF_INET family */
350 if (ipv6_addr_v4mapped(&addr
->v6
.sin6_addr
) &&
351 !opt
->pf
->af_supported(AF_INET
, opt
))
355 /* If we get this far, af is valid. */
356 af
= sctp_get_af_specific(addr
->sa
.sa_family
);
358 if (len
< af
->sockaddr_len
)
364 static void sctp_auto_asconf_init(struct sctp_sock
*sp
)
366 struct net
*net
= sock_net(&sp
->inet
.sk
);
368 if (net
->sctp
.default_auto_asconf
) {
369 spin_lock_bh(&net
->sctp
.addr_wq_lock
);
370 list_add_tail(&sp
->auto_asconf_list
, &net
->sctp
.auto_asconf_splist
);
371 spin_unlock_bh(&net
->sctp
.addr_wq_lock
);
372 sp
->do_auto_asconf
= 1;
376 /* Bind a local address either to an endpoint or to an association. */
377 static int sctp_do_bind(struct sock
*sk
, union sctp_addr
*addr
, int len
)
379 struct net
*net
= sock_net(sk
);
380 struct sctp_sock
*sp
= sctp_sk(sk
);
381 struct sctp_endpoint
*ep
= sp
->ep
;
382 struct sctp_bind_addr
*bp
= &ep
->base
.bind_addr
;
387 /* Common sockaddr verification. */
388 af
= sctp_sockaddr_af(sp
, addr
, len
);
390 pr_debug("%s: sk:%p, newaddr:%p, len:%d EINVAL\n",
391 __func__
, sk
, addr
, len
);
395 snum
= ntohs(addr
->v4
.sin_port
);
397 pr_debug("%s: sk:%p, new addr:%pISc, port:%d, new port:%d, len:%d\n",
398 __func__
, sk
, &addr
->sa
, bp
->port
, snum
, len
);
400 /* PF specific bind() address verification. */
401 if (!sp
->pf
->bind_verify(sp
, addr
))
402 return -EADDRNOTAVAIL
;
404 /* We must either be unbound, or bind to the same port.
405 * It's OK to allow 0 ports if we are already bound.
406 * We'll just inhert an already bound port in this case
411 else if (snum
!= bp
->port
) {
412 pr_debug("%s: new port %d doesn't match existing port "
413 "%d\n", __func__
, snum
, bp
->port
);
418 if (snum
&& inet_port_requires_bind_service(net
, snum
) &&
419 !ns_capable(net
->user_ns
, CAP_NET_BIND_SERVICE
))
422 /* See if the address matches any of the addresses we may have
423 * already bound before checking against other endpoints.
425 if (sctp_bind_addr_match(bp
, addr
, sp
))
428 /* Make sure we are allowed to bind here.
429 * The function sctp_get_port_local() does duplicate address
432 addr
->v4
.sin_port
= htons(snum
);
433 if (sctp_get_port_local(sk
, addr
))
436 /* Refresh ephemeral port. */
438 bp
->port
= inet_sk(sk
)->inet_num
;
439 sctp_auto_asconf_init(sp
);
442 /* Add the address to the bind address list.
443 * Use GFP_ATOMIC since BHs will be disabled.
445 ret
= sctp_add_bind_addr(bp
, addr
, af
->sockaddr_len
,
446 SCTP_ADDR_SRC
, GFP_ATOMIC
);
452 /* Copy back into socket for getsockname() use. */
453 inet_sk(sk
)->inet_sport
= htons(inet_sk(sk
)->inet_num
);
454 sp
->pf
->to_sk_saddr(addr
, sk
);
459 /* ADDIP Section 4.1.1 Congestion Control of ASCONF Chunks
461 * R1) One and only one ASCONF Chunk MAY be in transit and unacknowledged
462 * at any one time. If a sender, after sending an ASCONF chunk, decides
463 * it needs to transfer another ASCONF Chunk, it MUST wait until the
464 * ASCONF-ACK Chunk returns from the previous ASCONF Chunk before sending a
465 * subsequent ASCONF. Note this restriction binds each side, so at any
466 * time two ASCONF may be in-transit on any given association (one sent
467 * from each endpoint).
469 static int sctp_send_asconf(struct sctp_association
*asoc
,
470 struct sctp_chunk
*chunk
)
474 /* If there is an outstanding ASCONF chunk, queue it for later
477 if (asoc
->addip_last_asconf
) {
478 list_add_tail(&chunk
->list
, &asoc
->addip_chunk_list
);
482 /* Hold the chunk until an ASCONF_ACK is received. */
483 sctp_chunk_hold(chunk
);
484 retval
= sctp_primitive_ASCONF(asoc
->base
.net
, asoc
, chunk
);
486 sctp_chunk_free(chunk
);
488 asoc
->addip_last_asconf
= chunk
;
494 /* Add a list of addresses as bind addresses to local endpoint or
497 * Basically run through each address specified in the addrs/addrcnt
498 * array/length pair, determine if it is IPv6 or IPv4 and call
499 * sctp_do_bind() on it.
501 * If any of them fails, then the operation will be reversed and the
502 * ones that were added will be removed.
504 * Only sctp_setsockopt_bindx() is supposed to call this function.
506 static int sctp_bindx_add(struct sock
*sk
, struct sockaddr
*addrs
, int addrcnt
)
511 struct sockaddr
*sa_addr
;
514 pr_debug("%s: sk:%p, addrs:%p, addrcnt:%d\n", __func__
, sk
,
518 for (cnt
= 0; cnt
< addrcnt
; cnt
++) {
519 /* The list may contain either IPv4 or IPv6 address;
520 * determine the address length for walking thru the list.
523 af
= sctp_get_af_specific(sa_addr
->sa_family
);
529 retval
= sctp_do_bind(sk
, (union sctp_addr
*)sa_addr
,
532 addr_buf
+= af
->sockaddr_len
;
536 /* Failed. Cleanup the ones that have been added */
538 sctp_bindx_rem(sk
, addrs
, cnt
);
546 /* Send an ASCONF chunk with Add IP address parameters to all the peers of the
547 * associations that are part of the endpoint indicating that a list of local
548 * addresses are added to the endpoint.
550 * If any of the addresses is already in the bind address list of the
551 * association, we do not send the chunk for that association. But it will not
552 * affect other associations.
554 * Only sctp_setsockopt_bindx() is supposed to call this function.
556 static int sctp_send_asconf_add_ip(struct sock
*sk
,
557 struct sockaddr
*addrs
,
560 struct sctp_sock
*sp
;
561 struct sctp_endpoint
*ep
;
562 struct sctp_association
*asoc
;
563 struct sctp_bind_addr
*bp
;
564 struct sctp_chunk
*chunk
;
565 struct sctp_sockaddr_entry
*laddr
;
566 union sctp_addr
*addr
;
567 union sctp_addr saveaddr
;
577 if (!ep
->asconf_enable
)
580 pr_debug("%s: sk:%p, addrs:%p, addrcnt:%d\n",
581 __func__
, sk
, addrs
, addrcnt
);
583 list_for_each_entry(asoc
, &ep
->asocs
, asocs
) {
584 if (!asoc
->peer
.asconf_capable
)
587 if (asoc
->peer
.addip_disabled_mask
& SCTP_PARAM_ADD_IP
)
590 if (!sctp_state(asoc
, ESTABLISHED
))
593 /* Check if any address in the packed array of addresses is
594 * in the bind address list of the association. If so,
595 * do not send the asconf chunk to its peer, but continue with
596 * other associations.
599 for (i
= 0; i
< addrcnt
; i
++) {
601 af
= sctp_get_af_specific(addr
->v4
.sin_family
);
607 if (sctp_assoc_lookup_laddr(asoc
, addr
))
610 addr_buf
+= af
->sockaddr_len
;
615 /* Use the first valid address in bind addr list of
616 * association as Address Parameter of ASCONF CHUNK.
618 bp
= &asoc
->base
.bind_addr
;
619 p
= bp
->address_list
.next
;
620 laddr
= list_entry(p
, struct sctp_sockaddr_entry
, list
);
621 chunk
= sctp_make_asconf_update_ip(asoc
, &laddr
->a
, addrs
,
622 addrcnt
, SCTP_PARAM_ADD_IP
);
628 /* Add the new addresses to the bind address list with
629 * use_as_src set to 0.
632 for (i
= 0; i
< addrcnt
; i
++) {
634 af
= sctp_get_af_specific(addr
->v4
.sin_family
);
635 memcpy(&saveaddr
, addr
, af
->sockaddr_len
);
636 retval
= sctp_add_bind_addr(bp
, &saveaddr
,
638 SCTP_ADDR_NEW
, GFP_ATOMIC
);
639 addr_buf
+= af
->sockaddr_len
;
641 if (asoc
->src_out_of_asoc_ok
) {
642 struct sctp_transport
*trans
;
644 list_for_each_entry(trans
,
645 &asoc
->peer
.transport_addr_list
, transports
) {
646 trans
->cwnd
= min(4*asoc
->pathmtu
, max_t(__u32
,
647 2*asoc
->pathmtu
, 4380));
648 trans
->ssthresh
= asoc
->peer
.i
.a_rwnd
;
649 trans
->rto
= asoc
->rto_initial
;
650 sctp_max_rto(asoc
, trans
);
651 trans
->rtt
= trans
->srtt
= trans
->rttvar
= 0;
652 /* Clear the source and route cache */
653 sctp_transport_route(trans
, NULL
,
654 sctp_sk(asoc
->base
.sk
));
657 retval
= sctp_send_asconf(asoc
, chunk
);
664 /* Remove a list of addresses from bind addresses list. Do not remove the
667 * Basically run through each address specified in the addrs/addrcnt
668 * array/length pair, determine if it is IPv6 or IPv4 and call
669 * sctp_del_bind() on it.
671 * If any of them fails, then the operation will be reversed and the
672 * ones that were removed will be added back.
674 * At least one address has to be left; if only one address is
675 * available, the operation will return -EBUSY.
677 * Only sctp_setsockopt_bindx() is supposed to call this function.
679 static int sctp_bindx_rem(struct sock
*sk
, struct sockaddr
*addrs
, int addrcnt
)
681 struct sctp_sock
*sp
= sctp_sk(sk
);
682 struct sctp_endpoint
*ep
= sp
->ep
;
684 struct sctp_bind_addr
*bp
= &ep
->base
.bind_addr
;
687 union sctp_addr
*sa_addr
;
690 pr_debug("%s: sk:%p, addrs:%p, addrcnt:%d\n",
691 __func__
, sk
, addrs
, addrcnt
);
694 for (cnt
= 0; cnt
< addrcnt
; cnt
++) {
695 /* If the bind address list is empty or if there is only one
696 * bind address, there is nothing more to be removed (we need
697 * at least one address here).
699 if (list_empty(&bp
->address_list
) ||
700 (sctp_list_single_entry(&bp
->address_list
))) {
706 af
= sctp_get_af_specific(sa_addr
->sa
.sa_family
);
712 if (!af
->addr_valid(sa_addr
, sp
, NULL
)) {
713 retval
= -EADDRNOTAVAIL
;
717 if (sa_addr
->v4
.sin_port
&&
718 sa_addr
->v4
.sin_port
!= htons(bp
->port
)) {
723 if (!sa_addr
->v4
.sin_port
)
724 sa_addr
->v4
.sin_port
= htons(bp
->port
);
726 /* FIXME - There is probably a need to check if sk->sk_saddr and
727 * sk->sk_rcv_addr are currently set to one of the addresses to
728 * be removed. This is something which needs to be looked into
729 * when we are fixing the outstanding issues with multi-homing
730 * socket routing and failover schemes. Refer to comments in
731 * sctp_do_bind(). -daisy
733 retval
= sctp_del_bind_addr(bp
, sa_addr
);
735 addr_buf
+= af
->sockaddr_len
;
738 /* Failed. Add the ones that has been removed back */
740 sctp_bindx_add(sk
, addrs
, cnt
);
748 /* Send an ASCONF chunk with Delete IP address parameters to all the peers of
749 * the associations that are part of the endpoint indicating that a list of
750 * local addresses are removed from the endpoint.
752 * If any of the addresses is already in the bind address list of the
753 * association, we do not send the chunk for that association. But it will not
754 * affect other associations.
756 * Only sctp_setsockopt_bindx() is supposed to call this function.
758 static int sctp_send_asconf_del_ip(struct sock
*sk
,
759 struct sockaddr
*addrs
,
762 struct sctp_sock
*sp
;
763 struct sctp_endpoint
*ep
;
764 struct sctp_association
*asoc
;
765 struct sctp_transport
*transport
;
766 struct sctp_bind_addr
*bp
;
767 struct sctp_chunk
*chunk
;
768 union sctp_addr
*laddr
;
771 struct sctp_sockaddr_entry
*saddr
;
780 if (!ep
->asconf_enable
)
783 pr_debug("%s: sk:%p, addrs:%p, addrcnt:%d\n",
784 __func__
, sk
, addrs
, addrcnt
);
786 list_for_each_entry(asoc
, &ep
->asocs
, asocs
) {
788 if (!asoc
->peer
.asconf_capable
)
791 if (asoc
->peer
.addip_disabled_mask
& SCTP_PARAM_DEL_IP
)
794 if (!sctp_state(asoc
, ESTABLISHED
))
797 /* Check if any address in the packed array of addresses is
798 * not present in the bind address list of the association.
799 * If so, do not send the asconf chunk to its peer, but
800 * continue with other associations.
803 for (i
= 0; i
< addrcnt
; i
++) {
805 af
= sctp_get_af_specific(laddr
->v4
.sin_family
);
811 if (!sctp_assoc_lookup_laddr(asoc
, laddr
))
814 addr_buf
+= af
->sockaddr_len
;
819 /* Find one address in the association's bind address list
820 * that is not in the packed array of addresses. This is to
821 * make sure that we do not delete all the addresses in the
824 bp
= &asoc
->base
.bind_addr
;
825 laddr
= sctp_find_unmatch_addr(bp
, (union sctp_addr
*)addrs
,
827 if ((laddr
== NULL
) && (addrcnt
== 1)) {
828 if (asoc
->asconf_addr_del_pending
)
830 asoc
->asconf_addr_del_pending
=
831 kzalloc(sizeof(union sctp_addr
), GFP_ATOMIC
);
832 if (asoc
->asconf_addr_del_pending
== NULL
) {
836 asoc
->asconf_addr_del_pending
->sa
.sa_family
=
838 asoc
->asconf_addr_del_pending
->v4
.sin_port
=
840 if (addrs
->sa_family
== AF_INET
) {
841 struct sockaddr_in
*sin
;
843 sin
= (struct sockaddr_in
*)addrs
;
844 asoc
->asconf_addr_del_pending
->v4
.sin_addr
.s_addr
= sin
->sin_addr
.s_addr
;
845 } else if (addrs
->sa_family
== AF_INET6
) {
846 struct sockaddr_in6
*sin6
;
848 sin6
= (struct sockaddr_in6
*)addrs
;
849 asoc
->asconf_addr_del_pending
->v6
.sin6_addr
= sin6
->sin6_addr
;
852 pr_debug("%s: keep the last address asoc:%p %pISc at %p\n",
853 __func__
, asoc
, &asoc
->asconf_addr_del_pending
->sa
,
854 asoc
->asconf_addr_del_pending
);
856 asoc
->src_out_of_asoc_ok
= 1;
864 /* We do not need RCU protection throughout this loop
865 * because this is done under a socket lock from the
868 chunk
= sctp_make_asconf_update_ip(asoc
, laddr
, addrs
, addrcnt
,
876 /* Reset use_as_src flag for the addresses in the bind address
877 * list that are to be deleted.
880 for (i
= 0; i
< addrcnt
; i
++) {
882 af
= sctp_get_af_specific(laddr
->v4
.sin_family
);
883 list_for_each_entry(saddr
, &bp
->address_list
, list
) {
884 if (sctp_cmp_addr_exact(&saddr
->a
, laddr
))
885 saddr
->state
= SCTP_ADDR_DEL
;
887 addr_buf
+= af
->sockaddr_len
;
890 /* Update the route and saddr entries for all the transports
891 * as some of the addresses in the bind address list are
892 * about to be deleted and cannot be used as source addresses.
894 list_for_each_entry(transport
, &asoc
->peer
.transport_addr_list
,
896 sctp_transport_route(transport
, NULL
,
897 sctp_sk(asoc
->base
.sk
));
901 /* We don't need to transmit ASCONF */
903 retval
= sctp_send_asconf(asoc
, chunk
);
909 /* set addr events to assocs in the endpoint. ep and addr_wq must be locked */
910 int sctp_asconf_mgmt(struct sctp_sock
*sp
, struct sctp_sockaddr_entry
*addrw
)
912 struct sock
*sk
= sctp_opt2sk(sp
);
913 union sctp_addr
*addr
;
916 /* It is safe to write port space in caller. */
918 addr
->v4
.sin_port
= htons(sp
->ep
->base
.bind_addr
.port
);
919 af
= sctp_get_af_specific(addr
->sa
.sa_family
);
922 if (sctp_verify_addr(sk
, addr
, af
->sockaddr_len
))
925 if (addrw
->state
== SCTP_ADDR_NEW
)
926 return sctp_send_asconf_add_ip(sk
, (struct sockaddr
*)addr
, 1);
928 return sctp_send_asconf_del_ip(sk
, (struct sockaddr
*)addr
, 1);
931 /* Helper for tunneling sctp_bindx() requests through sctp_setsockopt()
934 * int sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt,
937 * If sd is an IPv4 socket, the addresses passed must be IPv4 addresses.
938 * If the sd is an IPv6 socket, the addresses passed can either be IPv4
941 * A single address may be specified as INADDR_ANY or IN6ADDR_ANY, see
942 * Section 3.1.2 for this usage.
944 * addrs is a pointer to an array of one or more socket addresses. Each
945 * address is contained in its appropriate structure (i.e. struct
946 * sockaddr_in or struct sockaddr_in6) the family of the address type
947 * must be used to distinguish the address length (note that this
948 * representation is termed a "packed array" of addresses). The caller
949 * specifies the number of addresses in the array with addrcnt.
951 * On success, sctp_bindx() returns 0. On failure, sctp_bindx() returns
952 * -1, and sets errno to the appropriate error code.
954 * For SCTP, the port given in each socket address must be the same, or
955 * sctp_bindx() will fail, setting errno to EINVAL.
957 * The flags parameter is formed from the bitwise OR of zero or more of
958 * the following currently defined flags:
960 * SCTP_BINDX_ADD_ADDR
962 * SCTP_BINDX_REM_ADDR
964 * SCTP_BINDX_ADD_ADDR directs SCTP to add the given addresses to the
965 * association, and SCTP_BINDX_REM_ADDR directs SCTP to remove the given
966 * addresses from the association. The two flags are mutually exclusive;
967 * if both are given, sctp_bindx() will fail with EINVAL. A caller may
968 * not remove all addresses from an association; sctp_bindx() will
969 * reject such an attempt with EINVAL.
971 * An application can use sctp_bindx(SCTP_BINDX_ADD_ADDR) to associate
972 * additional addresses with an endpoint after calling bind(). Or use
973 * sctp_bindx(SCTP_BINDX_REM_ADDR) to remove some addresses a listening
974 * socket is associated with so that no new association accepted will be
975 * associated with those addresses. If the endpoint supports dynamic
976 * address a SCTP_BINDX_REM_ADDR or SCTP_BINDX_ADD_ADDR may cause a
977 * endpoint to send the appropriate message to the peer to change the
978 * peers address lists.
980 * Adding and removing addresses from a connected association is
981 * optional functionality. Implementations that do not support this
982 * functionality should return EOPNOTSUPP.
984 * Basically do nothing but copying the addresses from user to kernel
985 * land and invoking either sctp_bindx_add() or sctp_bindx_rem() on the sk.
986 * This is used for tunneling the sctp_bindx() request through sctp_setsockopt()
989 * On exit there is no need to do sockfd_put(), sys_setsockopt() does
992 * sk The sk of the socket
993 * addrs The pointer to the addresses
994 * addrssize Size of the addrs buffer
995 * op Operation to perform (add or remove, see the flags of
998 * Returns 0 if ok, <0 errno code on error.
1000 static int sctp_setsockopt_bindx(struct sock
*sk
, struct sockaddr
*addrs
,
1001 int addrs_size
, int op
)
1006 struct sockaddr
*sa_addr
;
1007 void *addr_buf
= addrs
;
1010 pr_debug("%s: sk:%p addrs:%p addrs_size:%d opt:%d\n",
1011 __func__
, sk
, addr_buf
, addrs_size
, op
);
1013 if (unlikely(addrs_size
<= 0))
1016 /* Walk through the addrs buffer and count the number of addresses. */
1017 while (walk_size
< addrs_size
) {
1018 if (walk_size
+ sizeof(sa_family_t
) > addrs_size
)
1022 af
= sctp_get_af_specific(sa_addr
->sa_family
);
1024 /* If the address family is not supported or if this address
1025 * causes the address buffer to overflow return EINVAL.
1027 if (!af
|| (walk_size
+ af
->sockaddr_len
) > addrs_size
)
1030 addr_buf
+= af
->sockaddr_len
;
1031 walk_size
+= af
->sockaddr_len
;
1036 case SCTP_BINDX_ADD_ADDR
:
1037 /* Allow security module to validate bindx addresses. */
1038 err
= security_sctp_bind_connect(sk
, SCTP_SOCKOPT_BINDX_ADD
,
1042 err
= sctp_bindx_add(sk
, addrs
, addrcnt
);
1045 return sctp_send_asconf_add_ip(sk
, addrs
, addrcnt
);
1046 case SCTP_BINDX_REM_ADDR
:
1047 err
= sctp_bindx_rem(sk
, addrs
, addrcnt
);
1050 return sctp_send_asconf_del_ip(sk
, addrs
, addrcnt
);
1057 static int sctp_bind_add(struct sock
*sk
, struct sockaddr
*addrs
,
1063 err
= sctp_setsockopt_bindx(sk
, addrs
, addrlen
, SCTP_BINDX_ADD_ADDR
);
1068 static int sctp_connect_new_asoc(struct sctp_endpoint
*ep
,
1069 const union sctp_addr
*daddr
,
1070 const struct sctp_initmsg
*init
,
1071 struct sctp_transport
**tp
)
1073 struct sctp_association
*asoc
;
1074 struct sock
*sk
= ep
->base
.sk
;
1075 struct net
*net
= sock_net(sk
);
1076 enum sctp_scope scope
;
1079 if (sctp_endpoint_is_peeled_off(ep
, daddr
))
1080 return -EADDRNOTAVAIL
;
1082 if (!ep
->base
.bind_addr
.port
) {
1083 if (sctp_autobind(sk
))
1086 if (inet_port_requires_bind_service(net
, ep
->base
.bind_addr
.port
) &&
1087 !ns_capable(net
->user_ns
, CAP_NET_BIND_SERVICE
))
1091 scope
= sctp_scope(daddr
);
1092 asoc
= sctp_association_new(ep
, sk
, scope
, GFP_KERNEL
);
1096 err
= sctp_assoc_set_bind_addr_from_ep(asoc
, scope
, GFP_KERNEL
);
1100 *tp
= sctp_assoc_add_peer(asoc
, daddr
, GFP_KERNEL
, SCTP_UNKNOWN
);
1109 if (init
->sinit_num_ostreams
) {
1110 __u16 outcnt
= init
->sinit_num_ostreams
;
1112 asoc
->c
.sinit_num_ostreams
= outcnt
;
1113 /* outcnt has been changed, need to re-init stream */
1114 err
= sctp_stream_init(&asoc
->stream
, outcnt
, 0, GFP_KERNEL
);
1119 if (init
->sinit_max_instreams
)
1120 asoc
->c
.sinit_max_instreams
= init
->sinit_max_instreams
;
1122 if (init
->sinit_max_attempts
)
1123 asoc
->max_init_attempts
= init
->sinit_max_attempts
;
1125 if (init
->sinit_max_init_timeo
)
1126 asoc
->max_init_timeo
=
1127 msecs_to_jiffies(init
->sinit_max_init_timeo
);
1131 sctp_association_free(asoc
);
1135 static int sctp_connect_add_peer(struct sctp_association
*asoc
,
1136 union sctp_addr
*daddr
, int addr_len
)
1138 struct sctp_endpoint
*ep
= asoc
->ep
;
1139 struct sctp_association
*old
;
1140 struct sctp_transport
*t
;
1143 err
= sctp_verify_addr(ep
->base
.sk
, daddr
, addr_len
);
1147 old
= sctp_endpoint_lookup_assoc(ep
, daddr
, &t
);
1148 if (old
&& old
!= asoc
)
1149 return old
->state
>= SCTP_STATE_ESTABLISHED
? -EISCONN
1152 if (sctp_endpoint_is_peeled_off(ep
, daddr
))
1153 return -EADDRNOTAVAIL
;
1155 t
= sctp_assoc_add_peer(asoc
, daddr
, GFP_KERNEL
, SCTP_UNKNOWN
);
1162 /* __sctp_connect(struct sock* sk, struct sockaddr *kaddrs, int addrs_size)
1164 * Common routine for handling connect() and sctp_connectx().
1165 * Connect will come in with just a single address.
1167 static int __sctp_connect(struct sock
*sk
, struct sockaddr
*kaddrs
,
1168 int addrs_size
, int flags
, sctp_assoc_t
*assoc_id
)
1170 struct sctp_sock
*sp
= sctp_sk(sk
);
1171 struct sctp_endpoint
*ep
= sp
->ep
;
1172 struct sctp_transport
*transport
;
1173 struct sctp_association
*asoc
;
1174 void *addr_buf
= kaddrs
;
1175 union sctp_addr
*daddr
;
1180 if (sctp_sstate(sk
, ESTABLISHED
) || sctp_sstate(sk
, CLOSING
) ||
1181 (sctp_style(sk
, TCP
) && sctp_sstate(sk
, LISTENING
)))
1185 af
= sctp_get_af_specific(daddr
->sa
.sa_family
);
1186 if (!af
|| af
->sockaddr_len
> addrs_size
)
1189 err
= sctp_verify_addr(sk
, daddr
, af
->sockaddr_len
);
1193 asoc
= sctp_endpoint_lookup_assoc(ep
, daddr
, &transport
);
1195 return asoc
->state
>= SCTP_STATE_ESTABLISHED
? -EISCONN
1198 err
= sctp_connect_new_asoc(ep
, daddr
, NULL
, &transport
);
1201 asoc
= transport
->asoc
;
1203 addr_buf
+= af
->sockaddr_len
;
1204 walk_size
= af
->sockaddr_len
;
1205 while (walk_size
< addrs_size
) {
1207 if (walk_size
+ sizeof(sa_family_t
) > addrs_size
)
1211 af
= sctp_get_af_specific(daddr
->sa
.sa_family
);
1212 if (!af
|| af
->sockaddr_len
+ walk_size
> addrs_size
)
1215 if (asoc
->peer
.port
!= ntohs(daddr
->v4
.sin_port
))
1218 err
= sctp_connect_add_peer(asoc
, daddr
, af
->sockaddr_len
);
1222 addr_buf
+= af
->sockaddr_len
;
1223 walk_size
+= af
->sockaddr_len
;
1226 /* In case the user of sctp_connectx() wants an association
1227 * id back, assign one now.
1230 err
= sctp_assoc_set_id(asoc
, GFP_KERNEL
);
1235 err
= sctp_primitive_ASSOCIATE(sock_net(sk
), asoc
, NULL
);
1239 /* Initialize sk's dport and daddr for getpeername() */
1240 inet_sk(sk
)->inet_dport
= htons(asoc
->peer
.port
);
1241 sp
->pf
->to_sk_daddr(daddr
, sk
);
1245 *assoc_id
= asoc
->assoc_id
;
1247 timeo
= sock_sndtimeo(sk
, flags
& O_NONBLOCK
);
1248 return sctp_wait_for_connect(asoc
, &timeo
);
1251 pr_debug("%s: took out_free path with asoc:%p kaddrs:%p err:%d\n",
1252 __func__
, asoc
, kaddrs
, err
);
1253 sctp_association_free(asoc
);
1257 /* Helper for tunneling sctp_connectx() requests through sctp_setsockopt()
1260 * int sctp_connectx(int sd, struct sockaddr *addrs, int addrcnt,
1261 * sctp_assoc_t *asoc);
1263 * If sd is an IPv4 socket, the addresses passed must be IPv4 addresses.
1264 * If the sd is an IPv6 socket, the addresses passed can either be IPv4
1265 * or IPv6 addresses.
1267 * A single address may be specified as INADDR_ANY or IN6ADDR_ANY, see
1268 * Section 3.1.2 for this usage.
1270 * addrs is a pointer to an array of one or more socket addresses. Each
1271 * address is contained in its appropriate structure (i.e. struct
1272 * sockaddr_in or struct sockaddr_in6) the family of the address type
1273 * must be used to distengish the address length (note that this
1274 * representation is termed a "packed array" of addresses). The caller
1275 * specifies the number of addresses in the array with addrcnt.
1277 * On success, sctp_connectx() returns 0. It also sets the assoc_id to
1278 * the association id of the new association. On failure, sctp_connectx()
1279 * returns -1, and sets errno to the appropriate error code. The assoc_id
1280 * is not touched by the kernel.
1282 * For SCTP, the port given in each socket address must be the same, or
1283 * sctp_connectx() will fail, setting errno to EINVAL.
1285 * An application can use sctp_connectx to initiate an association with
1286 * an endpoint that is multi-homed. Much like sctp_bindx() this call
1287 * allows a caller to specify multiple addresses at which a peer can be
1288 * reached. The way the SCTP stack uses the list of addresses to set up
1289 * the association is implementation dependent. This function only
1290 * specifies that the stack will try to make use of all the addresses in
1291 * the list when needed.
1293 * Note that the list of addresses passed in is only used for setting up
1294 * the association. It does not necessarily equal the set of addresses
1295 * the peer uses for the resulting association. If the caller wants to
1296 * find out the set of peer addresses, it must use sctp_getpaddrs() to
1297 * retrieve them after the association has been set up.
1299 * Basically do nothing but copying the addresses from user to kernel
1300 * land and invoking either sctp_connectx(). This is used for tunneling
1301 * the sctp_connectx() request through sctp_setsockopt() from userspace.
1303 * On exit there is no need to do sockfd_put(), sys_setsockopt() does
1306 * sk The sk of the socket
1307 * addrs The pointer to the addresses
1308 * addrssize Size of the addrs buffer
1310 * Returns >=0 if ok, <0 errno code on error.
1312 static int __sctp_setsockopt_connectx(struct sock
*sk
, struct sockaddr
*kaddrs
,
1313 int addrs_size
, sctp_assoc_t
*assoc_id
)
1315 int err
= 0, flags
= 0;
1317 pr_debug("%s: sk:%p addrs:%p addrs_size:%d\n",
1318 __func__
, sk
, kaddrs
, addrs_size
);
1320 /* make sure the 1st addr's sa_family is accessible later */
1321 if (unlikely(addrs_size
< sizeof(sa_family_t
)))
1324 /* Allow security module to validate connectx addresses. */
1325 err
= security_sctp_bind_connect(sk
, SCTP_SOCKOPT_CONNECTX
,
1326 (struct sockaddr
*)kaddrs
,
1331 /* in-kernel sockets don't generally have a file allocated to them
1332 * if all they do is call sock_create_kern().
1334 if (sk
->sk_socket
->file
)
1335 flags
= sk
->sk_socket
->file
->f_flags
;
1337 return __sctp_connect(sk
, kaddrs
, addrs_size
, flags
, assoc_id
);
1341 * This is an older interface. It's kept for backward compatibility
1342 * to the option that doesn't provide association id.
1344 static int sctp_setsockopt_connectx_old(struct sock
*sk
,
1345 struct sockaddr
*kaddrs
,
1348 return __sctp_setsockopt_connectx(sk
, kaddrs
, addrs_size
, NULL
);
1352 * New interface for the API. The since the API is done with a socket
1353 * option, to make it simple we feed back the association id is as a return
1354 * indication to the call. Error is always negative and association id is
1357 static int sctp_setsockopt_connectx(struct sock
*sk
,
1358 struct sockaddr
*kaddrs
,
1361 sctp_assoc_t assoc_id
= 0;
1364 err
= __sctp_setsockopt_connectx(sk
, kaddrs
, addrs_size
, &assoc_id
);
1373 * New (hopefully final) interface for the API.
1374 * We use the sctp_getaddrs_old structure so that use-space library
1375 * can avoid any unnecessary allocations. The only different part
1376 * is that we store the actual length of the address buffer into the
1377 * addrs_num structure member. That way we can re-use the existing
1380 #ifdef CONFIG_COMPAT
1381 struct compat_sctp_getaddrs_old
{
1382 sctp_assoc_t assoc_id
;
1384 compat_uptr_t addrs
; /* struct sockaddr * */
1388 static int sctp_getsockopt_connectx3(struct sock
*sk
, int len
,
1389 char __user
*optval
,
1392 struct sctp_getaddrs_old param
;
1393 sctp_assoc_t assoc_id
= 0;
1394 struct sockaddr
*kaddrs
;
1397 #ifdef CONFIG_COMPAT
1398 if (in_compat_syscall()) {
1399 struct compat_sctp_getaddrs_old param32
;
1401 if (len
< sizeof(param32
))
1403 if (copy_from_user(¶m32
, optval
, sizeof(param32
)))
1406 param
.assoc_id
= param32
.assoc_id
;
1407 param
.addr_num
= param32
.addr_num
;
1408 param
.addrs
= compat_ptr(param32
.addrs
);
1412 if (len
< sizeof(param
))
1414 if (copy_from_user(¶m
, optval
, sizeof(param
)))
1418 kaddrs
= memdup_user(param
.addrs
, param
.addr_num
);
1420 return PTR_ERR(kaddrs
);
1422 err
= __sctp_setsockopt_connectx(sk
, kaddrs
, param
.addr_num
, &assoc_id
);
1424 if (err
== 0 || err
== -EINPROGRESS
) {
1425 if (copy_to_user(optval
, &assoc_id
, sizeof(assoc_id
)))
1427 if (put_user(sizeof(assoc_id
), optlen
))
1434 /* API 3.1.4 close() - UDP Style Syntax
1435 * Applications use close() to perform graceful shutdown (as described in
1436 * Section 10.1 of [SCTP]) on ALL the associations currently represented
1437 * by a UDP-style socket.
1441 * ret = close(int sd);
1443 * sd - the socket descriptor of the associations to be closed.
1445 * To gracefully shutdown a specific association represented by the
1446 * UDP-style socket, an application should use the sendmsg() call,
1447 * passing no user data, but including the appropriate flag in the
1448 * ancillary data (see Section xxxx).
1450 * If sd in the close() call is a branched-off socket representing only
1451 * one association, the shutdown is performed on that association only.
1453 * 4.1.6 close() - TCP Style Syntax
1455 * Applications use close() to gracefully close down an association.
1459 * int close(int sd);
1461 * sd - the socket descriptor of the association to be closed.
1463 * After an application calls close() on a socket descriptor, no further
1464 * socket operations will succeed on that descriptor.
1466 * API 7.1.4 SO_LINGER
1468 * An application using the TCP-style socket can use this option to
1469 * perform the SCTP ABORT primitive. The linger option structure is:
1472 * int l_onoff; // option on/off
1473 * int l_linger; // linger time
1476 * To enable the option, set l_onoff to 1. If the l_linger value is set
1477 * to 0, calling close() is the same as the ABORT primitive. If the
1478 * value is set to a negative value, the setsockopt() call will return
1479 * an error. If the value is set to a positive value linger_time, the
1480 * close() can be blocked for at most linger_time ms. If the graceful
1481 * shutdown phase does not finish during this period, close() will
1482 * return but the graceful shutdown phase continues in the system.
1484 static void sctp_close(struct sock
*sk
, long timeout
)
1486 struct net
*net
= sock_net(sk
);
1487 struct sctp_endpoint
*ep
;
1488 struct sctp_association
*asoc
;
1489 struct list_head
*pos
, *temp
;
1490 unsigned int data_was_unread
;
1492 pr_debug("%s: sk:%p, timeout:%ld\n", __func__
, sk
, timeout
);
1494 lock_sock_nested(sk
, SINGLE_DEPTH_NESTING
);
1495 sk
->sk_shutdown
= SHUTDOWN_MASK
;
1496 inet_sk_set_state(sk
, SCTP_SS_CLOSING
);
1498 ep
= sctp_sk(sk
)->ep
;
1500 /* Clean up any skbs sitting on the receive queue. */
1501 data_was_unread
= sctp_queue_purge_ulpevents(&sk
->sk_receive_queue
);
1502 data_was_unread
+= sctp_queue_purge_ulpevents(&sctp_sk(sk
)->pd_lobby
);
1504 /* Walk all associations on an endpoint. */
1505 list_for_each_safe(pos
, temp
, &ep
->asocs
) {
1506 asoc
= list_entry(pos
, struct sctp_association
, asocs
);
1508 if (sctp_style(sk
, TCP
)) {
1509 /* A closed association can still be in the list if
1510 * it belongs to a TCP-style listening socket that is
1511 * not yet accepted. If so, free it. If not, send an
1512 * ABORT or SHUTDOWN based on the linger options.
1514 if (sctp_state(asoc
, CLOSED
)) {
1515 sctp_association_free(asoc
);
1520 if (data_was_unread
|| !skb_queue_empty(&asoc
->ulpq
.lobby
) ||
1521 !skb_queue_empty(&asoc
->ulpq
.reasm
) ||
1522 !skb_queue_empty(&asoc
->ulpq
.reasm_uo
) ||
1523 (sock_flag(sk
, SOCK_LINGER
) && !sk
->sk_lingertime
)) {
1524 struct sctp_chunk
*chunk
;
1526 chunk
= sctp_make_abort_user(asoc
, NULL
, 0);
1527 sctp_primitive_ABORT(net
, asoc
, chunk
);
1529 sctp_primitive_SHUTDOWN(net
, asoc
, NULL
);
1532 /* On a TCP-style socket, block for at most linger_time if set. */
1533 if (sctp_style(sk
, TCP
) && timeout
)
1534 sctp_wait_for_close(sk
, timeout
);
1536 /* This will run the backlog queue. */
1539 /* Supposedly, no process has access to the socket, but
1540 * the net layers still may.
1541 * Also, sctp_destroy_sock() needs to be called with addr_wq_lock
1542 * held and that should be grabbed before socket lock.
1544 spin_lock_bh(&net
->sctp
.addr_wq_lock
);
1545 bh_lock_sock_nested(sk
);
1547 /* Hold the sock, since sk_common_release() will put sock_put()
1548 * and we have just a little more cleanup.
1551 sk_common_release(sk
);
1554 spin_unlock_bh(&net
->sctp
.addr_wq_lock
);
1558 SCTP_DBG_OBJCNT_DEC(sock
);
1561 /* Handle EPIPE error. */
1562 static int sctp_error(struct sock
*sk
, int flags
, int err
)
1565 err
= sock_error(sk
) ? : -EPIPE
;
1566 if (err
== -EPIPE
&& !(flags
& MSG_NOSIGNAL
))
1567 send_sig(SIGPIPE
, current
, 0);
1571 /* API 3.1.3 sendmsg() - UDP Style Syntax
1573 * An application uses sendmsg() and recvmsg() calls to transmit data to
1574 * and receive data from its peer.
1576 * ssize_t sendmsg(int socket, const struct msghdr *message,
1579 * socket - the socket descriptor of the endpoint.
1580 * message - pointer to the msghdr structure which contains a single
1581 * user message and possibly some ancillary data.
1583 * See Section 5 for complete description of the data
1586 * flags - flags sent or received with the user message, see Section
1587 * 5 for complete description of the flags.
1589 * Note: This function could use a rewrite especially when explicit
1590 * connect support comes in.
1592 /* BUG: We do not implement the equivalent of sk_stream_wait_memory(). */
1594 static int sctp_msghdr_parse(const struct msghdr
*msg
,
1595 struct sctp_cmsgs
*cmsgs
);
1597 static int sctp_sendmsg_parse(struct sock
*sk
, struct sctp_cmsgs
*cmsgs
,
1598 struct sctp_sndrcvinfo
*srinfo
,
1599 const struct msghdr
*msg
, size_t msg_len
)
1604 if (sctp_sstate(sk
, LISTENING
) && sctp_style(sk
, TCP
))
1607 if (msg_len
> sk
->sk_sndbuf
)
1610 memset(cmsgs
, 0, sizeof(*cmsgs
));
1611 err
= sctp_msghdr_parse(msg
, cmsgs
);
1613 pr_debug("%s: msghdr parse err:%x\n", __func__
, err
);
1617 memset(srinfo
, 0, sizeof(*srinfo
));
1618 if (cmsgs
->srinfo
) {
1619 srinfo
->sinfo_stream
= cmsgs
->srinfo
->sinfo_stream
;
1620 srinfo
->sinfo_flags
= cmsgs
->srinfo
->sinfo_flags
;
1621 srinfo
->sinfo_ppid
= cmsgs
->srinfo
->sinfo_ppid
;
1622 srinfo
->sinfo_context
= cmsgs
->srinfo
->sinfo_context
;
1623 srinfo
->sinfo_assoc_id
= cmsgs
->srinfo
->sinfo_assoc_id
;
1624 srinfo
->sinfo_timetolive
= cmsgs
->srinfo
->sinfo_timetolive
;
1628 srinfo
->sinfo_stream
= cmsgs
->sinfo
->snd_sid
;
1629 srinfo
->sinfo_flags
= cmsgs
->sinfo
->snd_flags
;
1630 srinfo
->sinfo_ppid
= cmsgs
->sinfo
->snd_ppid
;
1631 srinfo
->sinfo_context
= cmsgs
->sinfo
->snd_context
;
1632 srinfo
->sinfo_assoc_id
= cmsgs
->sinfo
->snd_assoc_id
;
1635 if (cmsgs
->prinfo
) {
1636 srinfo
->sinfo_timetolive
= cmsgs
->prinfo
->pr_value
;
1637 SCTP_PR_SET_POLICY(srinfo
->sinfo_flags
,
1638 cmsgs
->prinfo
->pr_policy
);
1641 sflags
= srinfo
->sinfo_flags
;
1642 if (!sflags
&& msg_len
)
1645 if (sctp_style(sk
, TCP
) && (sflags
& (SCTP_EOF
| SCTP_ABORT
)))
1648 if (((sflags
& SCTP_EOF
) && msg_len
> 0) ||
1649 (!(sflags
& (SCTP_EOF
| SCTP_ABORT
)) && msg_len
== 0))
1652 if ((sflags
& SCTP_ADDR_OVER
) && !msg
->msg_name
)
1658 static int sctp_sendmsg_new_asoc(struct sock
*sk
, __u16 sflags
,
1659 struct sctp_cmsgs
*cmsgs
,
1660 union sctp_addr
*daddr
,
1661 struct sctp_transport
**tp
)
1663 struct sctp_endpoint
*ep
= sctp_sk(sk
)->ep
;
1664 struct sctp_association
*asoc
;
1665 struct cmsghdr
*cmsg
;
1666 __be32 flowinfo
= 0;
1672 if (sflags
& (SCTP_EOF
| SCTP_ABORT
))
1675 if (sctp_style(sk
, TCP
) && (sctp_sstate(sk
, ESTABLISHED
) ||
1676 sctp_sstate(sk
, CLOSING
)))
1677 return -EADDRNOTAVAIL
;
1679 /* Label connection socket for first association 1-to-many
1680 * style for client sequence socket()->sendmsg(). This
1681 * needs to be done before sctp_assoc_add_peer() as that will
1682 * set up the initial packet that needs to account for any
1683 * security ip options (CIPSO/CALIPSO) added to the packet.
1685 af
= sctp_get_af_specific(daddr
->sa
.sa_family
);
1688 err
= security_sctp_bind_connect(sk
, SCTP_SENDMSG_CONNECT
,
1689 (struct sockaddr
*)daddr
,
1694 err
= sctp_connect_new_asoc(ep
, daddr
, cmsgs
->init
, tp
);
1699 if (!cmsgs
->addrs_msg
)
1702 if (daddr
->sa
.sa_family
== AF_INET6
)
1703 flowinfo
= daddr
->v6
.sin6_flowinfo
;
1705 /* sendv addr list parse */
1706 for_each_cmsghdr(cmsg
, cmsgs
->addrs_msg
) {
1707 union sctp_addr _daddr
;
1710 if (cmsg
->cmsg_level
!= IPPROTO_SCTP
||
1711 (cmsg
->cmsg_type
!= SCTP_DSTADDRV4
&&
1712 cmsg
->cmsg_type
!= SCTP_DSTADDRV6
))
1716 memset(daddr
, 0, sizeof(*daddr
));
1717 dlen
= cmsg
->cmsg_len
- sizeof(struct cmsghdr
);
1718 if (cmsg
->cmsg_type
== SCTP_DSTADDRV4
) {
1719 if (dlen
< sizeof(struct in_addr
)) {
1724 dlen
= sizeof(struct in_addr
);
1725 daddr
->v4
.sin_family
= AF_INET
;
1726 daddr
->v4
.sin_port
= htons(asoc
->peer
.port
);
1727 memcpy(&daddr
->v4
.sin_addr
, CMSG_DATA(cmsg
), dlen
);
1729 if (dlen
< sizeof(struct in6_addr
)) {
1734 dlen
= sizeof(struct in6_addr
);
1735 daddr
->v6
.sin6_flowinfo
= flowinfo
;
1736 daddr
->v6
.sin6_family
= AF_INET6
;
1737 daddr
->v6
.sin6_port
= htons(asoc
->peer
.port
);
1738 memcpy(&daddr
->v6
.sin6_addr
, CMSG_DATA(cmsg
), dlen
);
1741 err
= sctp_connect_add_peer(asoc
, daddr
, sizeof(*daddr
));
1749 sctp_association_free(asoc
);
1753 static int sctp_sendmsg_check_sflags(struct sctp_association
*asoc
,
1754 __u16 sflags
, struct msghdr
*msg
,
1757 struct sock
*sk
= asoc
->base
.sk
;
1758 struct net
*net
= sock_net(sk
);
1760 if (sctp_state(asoc
, CLOSED
) && sctp_style(sk
, TCP
))
1763 if ((sflags
& SCTP_SENDALL
) && sctp_style(sk
, UDP
) &&
1764 !sctp_state(asoc
, ESTABLISHED
))
1767 if (sflags
& SCTP_EOF
) {
1768 pr_debug("%s: shutting down association:%p\n", __func__
, asoc
);
1769 sctp_primitive_SHUTDOWN(net
, asoc
, NULL
);
1774 if (sflags
& SCTP_ABORT
) {
1775 struct sctp_chunk
*chunk
;
1777 chunk
= sctp_make_abort_user(asoc
, msg
, msg_len
);
1781 pr_debug("%s: aborting association:%p\n", __func__
, asoc
);
1782 sctp_primitive_ABORT(net
, asoc
, chunk
);
1783 iov_iter_revert(&msg
->msg_iter
, msg_len
);
1791 static int sctp_sendmsg_to_asoc(struct sctp_association
*asoc
,
1792 struct msghdr
*msg
, size_t msg_len
,
1793 struct sctp_transport
*transport
,
1794 struct sctp_sndrcvinfo
*sinfo
)
1796 struct sock
*sk
= asoc
->base
.sk
;
1797 struct sctp_sock
*sp
= sctp_sk(sk
);
1798 struct net
*net
= sock_net(sk
);
1799 struct sctp_datamsg
*datamsg
;
1800 bool wait_connect
= false;
1801 struct sctp_chunk
*chunk
;
1805 if (sinfo
->sinfo_stream
>= asoc
->stream
.outcnt
) {
1810 if (unlikely(!SCTP_SO(&asoc
->stream
, sinfo
->sinfo_stream
)->ext
)) {
1811 err
= sctp_stream_init_ext(&asoc
->stream
, sinfo
->sinfo_stream
);
1816 if (sp
->disable_fragments
&& msg_len
> asoc
->frag_point
) {
1821 if (asoc
->pmtu_pending
) {
1822 if (sp
->param_flags
& SPP_PMTUD_ENABLE
)
1823 sctp_assoc_sync_pmtu(asoc
);
1824 asoc
->pmtu_pending
= 0;
1827 if (sctp_wspace(asoc
) < (int)msg_len
)
1828 sctp_prsctp_prune(asoc
, sinfo
, msg_len
- sctp_wspace(asoc
));
1830 if (sctp_wspace(asoc
) <= 0 || !sk_wmem_schedule(sk
, msg_len
)) {
1831 timeo
= sock_sndtimeo(sk
, msg
->msg_flags
& MSG_DONTWAIT
);
1832 err
= sctp_wait_for_sndbuf(asoc
, transport
, &timeo
, msg_len
);
1835 if (unlikely(sinfo
->sinfo_stream
>= asoc
->stream
.outcnt
)) {
1841 if (sctp_state(asoc
, CLOSED
)) {
1842 err
= sctp_primitive_ASSOCIATE(net
, asoc
, NULL
);
1846 if (asoc
->ep
->intl_enable
) {
1847 timeo
= sock_sndtimeo(sk
, 0);
1848 err
= sctp_wait_for_connect(asoc
, &timeo
);
1854 wait_connect
= true;
1857 pr_debug("%s: we associated primitively\n", __func__
);
1860 datamsg
= sctp_datamsg_from_user(asoc
, sinfo
, &msg
->msg_iter
);
1861 if (IS_ERR(datamsg
)) {
1862 err
= PTR_ERR(datamsg
);
1866 asoc
->force_delay
= !!(msg
->msg_flags
& MSG_MORE
);
1868 list_for_each_entry(chunk
, &datamsg
->chunks
, frag_list
) {
1869 sctp_chunk_hold(chunk
);
1870 sctp_set_owner_w(chunk
);
1871 chunk
->transport
= transport
;
1874 err
= sctp_primitive_SEND(net
, asoc
, datamsg
);
1876 sctp_datamsg_free(datamsg
);
1880 pr_debug("%s: we sent primitively\n", __func__
);
1882 sctp_datamsg_put(datamsg
);
1884 if (unlikely(wait_connect
)) {
1885 timeo
= sock_sndtimeo(sk
, msg
->msg_flags
& MSG_DONTWAIT
);
1886 sctp_wait_for_connect(asoc
, &timeo
);
1895 static union sctp_addr
*sctp_sendmsg_get_daddr(struct sock
*sk
,
1896 const struct msghdr
*msg
,
1897 struct sctp_cmsgs
*cmsgs
)
1899 union sctp_addr
*daddr
= NULL
;
1902 if (!sctp_style(sk
, UDP_HIGH_BANDWIDTH
) && msg
->msg_name
) {
1903 int len
= msg
->msg_namelen
;
1905 if (len
> sizeof(*daddr
))
1906 len
= sizeof(*daddr
);
1908 daddr
= (union sctp_addr
*)msg
->msg_name
;
1910 err
= sctp_verify_addr(sk
, daddr
, len
);
1912 return ERR_PTR(err
);
1918 static void sctp_sendmsg_update_sinfo(struct sctp_association
*asoc
,
1919 struct sctp_sndrcvinfo
*sinfo
,
1920 struct sctp_cmsgs
*cmsgs
)
1922 if (!cmsgs
->srinfo
&& !cmsgs
->sinfo
) {
1923 sinfo
->sinfo_stream
= asoc
->default_stream
;
1924 sinfo
->sinfo_ppid
= asoc
->default_ppid
;
1925 sinfo
->sinfo_context
= asoc
->default_context
;
1926 sinfo
->sinfo_assoc_id
= sctp_assoc2id(asoc
);
1929 sinfo
->sinfo_flags
= asoc
->default_flags
;
1932 if (!cmsgs
->srinfo
&& !cmsgs
->prinfo
)
1933 sinfo
->sinfo_timetolive
= asoc
->default_timetolive
;
1935 if (cmsgs
->authinfo
) {
1936 /* Reuse sinfo_tsn to indicate that authinfo was set and
1937 * sinfo_ssn to save the keyid on tx path.
1939 sinfo
->sinfo_tsn
= 1;
1940 sinfo
->sinfo_ssn
= cmsgs
->authinfo
->auth_keynumber
;
1944 static int sctp_sendmsg(struct sock
*sk
, struct msghdr
*msg
, size_t msg_len
)
1946 struct sctp_endpoint
*ep
= sctp_sk(sk
)->ep
;
1947 struct sctp_transport
*transport
= NULL
;
1948 struct sctp_sndrcvinfo _sinfo
, *sinfo
;
1949 struct sctp_association
*asoc
, *tmp
;
1950 struct sctp_cmsgs cmsgs
;
1951 union sctp_addr
*daddr
;
1956 /* Parse and get snd_info */
1957 err
= sctp_sendmsg_parse(sk
, &cmsgs
, &_sinfo
, msg
, msg_len
);
1962 sflags
= sinfo
->sinfo_flags
;
1964 /* Get daddr from msg */
1965 daddr
= sctp_sendmsg_get_daddr(sk
, msg
, &cmsgs
);
1966 if (IS_ERR(daddr
)) {
1967 err
= PTR_ERR(daddr
);
1973 /* SCTP_SENDALL process */
1974 if ((sflags
& SCTP_SENDALL
) && sctp_style(sk
, UDP
)) {
1975 list_for_each_entry_safe(asoc
, tmp
, &ep
->asocs
, asocs
) {
1976 err
= sctp_sendmsg_check_sflags(asoc
, sflags
, msg
,
1983 sctp_sendmsg_update_sinfo(asoc
, sinfo
, &cmsgs
);
1985 err
= sctp_sendmsg_to_asoc(asoc
, msg
, msg_len
,
1990 iov_iter_revert(&msg
->msg_iter
, err
);
1996 /* Get and check or create asoc */
1998 asoc
= sctp_endpoint_lookup_assoc(ep
, daddr
, &transport
);
2000 err
= sctp_sendmsg_check_sflags(asoc
, sflags
, msg
,
2005 err
= sctp_sendmsg_new_asoc(sk
, sflags
, &cmsgs
, daddr
,
2010 asoc
= transport
->asoc
;
2014 if (!sctp_style(sk
, TCP
) && !(sflags
& SCTP_ADDR_OVER
))
2017 asoc
= sctp_id2assoc(sk
, sinfo
->sinfo_assoc_id
);
2023 err
= sctp_sendmsg_check_sflags(asoc
, sflags
, msg
, msg_len
);
2028 /* Update snd_info with the asoc */
2029 sctp_sendmsg_update_sinfo(asoc
, sinfo
, &cmsgs
);
2031 /* Send msg to the asoc */
2032 err
= sctp_sendmsg_to_asoc(asoc
, msg
, msg_len
, transport
, sinfo
);
2033 if (err
< 0 && err
!= -ESRCH
&& new)
2034 sctp_association_free(asoc
);
2039 return sctp_error(sk
, msg
->msg_flags
, err
);
2042 /* This is an extended version of skb_pull() that removes the data from the
2043 * start of a skb even when data is spread across the list of skb's in the
2044 * frag_list. len specifies the total amount of data that needs to be removed.
2045 * when 'len' bytes could be removed from the skb, it returns 0.
2046 * If 'len' exceeds the total skb length, it returns the no. of bytes that
2047 * could not be removed.
2049 static int sctp_skb_pull(struct sk_buff
*skb
, int len
)
2051 struct sk_buff
*list
;
2052 int skb_len
= skb_headlen(skb
);
2055 if (len
<= skb_len
) {
2056 __skb_pull(skb
, len
);
2060 __skb_pull(skb
, skb_len
);
2062 skb_walk_frags(skb
, list
) {
2063 rlen
= sctp_skb_pull(list
, len
);
2064 skb
->len
-= (len
-rlen
);
2065 skb
->data_len
-= (len
-rlen
);
2076 /* API 3.1.3 recvmsg() - UDP Style Syntax
2078 * ssize_t recvmsg(int socket, struct msghdr *message,
2081 * socket - the socket descriptor of the endpoint.
2082 * message - pointer to the msghdr structure which contains a single
2083 * user message and possibly some ancillary data.
2085 * See Section 5 for complete description of the data
2088 * flags - flags sent or received with the user message, see Section
2089 * 5 for complete description of the flags.
2091 static int sctp_recvmsg(struct sock
*sk
, struct msghdr
*msg
, size_t len
,
2092 int flags
, int *addr_len
)
2094 struct sctp_ulpevent
*event
= NULL
;
2095 struct sctp_sock
*sp
= sctp_sk(sk
);
2096 struct sk_buff
*skb
, *head_skb
;
2101 pr_debug("%s: sk:%p, msghdr:%p, len:%zd, flags:0x%x, addr_len:%p)\n",
2102 __func__
, sk
, msg
, len
, flags
, addr_len
);
2104 if (unlikely(flags
& MSG_ERRQUEUE
))
2105 return inet_recv_error(sk
, msg
, len
, addr_len
);
2107 if (sk_can_busy_loop(sk
) &&
2108 skb_queue_empty_lockless(&sk
->sk_receive_queue
))
2109 sk_busy_loop(sk
, flags
& MSG_DONTWAIT
);
2113 if (sctp_style(sk
, TCP
) && !sctp_sstate(sk
, ESTABLISHED
) &&
2114 !sctp_sstate(sk
, CLOSING
) && !sctp_sstate(sk
, CLOSED
)) {
2119 skb
= sctp_skb_recv_datagram(sk
, flags
, &err
);
2123 /* Get the total length of the skb including any skb's in the
2132 err
= skb_copy_datagram_msg(skb
, 0, msg
, copied
);
2134 event
= sctp_skb2event(skb
);
2139 if (event
->chunk
&& event
->chunk
->head_skb
)
2140 head_skb
= event
->chunk
->head_skb
;
2143 sock_recv_cmsgs(msg
, sk
, head_skb
);
2144 if (sctp_ulpevent_is_notification(event
)) {
2145 msg
->msg_flags
|= MSG_NOTIFICATION
;
2146 sp
->pf
->event_msgname(event
, msg
->msg_name
, addr_len
);
2148 sp
->pf
->skb_msgname(head_skb
, msg
->msg_name
, addr_len
);
2151 /* Check if we allow SCTP_NXTINFO. */
2152 if (sp
->recvnxtinfo
)
2153 sctp_ulpevent_read_nxtinfo(event
, msg
, sk
);
2154 /* Check if we allow SCTP_RCVINFO. */
2155 if (sp
->recvrcvinfo
)
2156 sctp_ulpevent_read_rcvinfo(event
, msg
);
2157 /* Check if we allow SCTP_SNDRCVINFO. */
2158 if (sctp_ulpevent_type_enabled(sp
->subscribe
, SCTP_DATA_IO_EVENT
))
2159 sctp_ulpevent_read_sndrcvinfo(event
, msg
);
2163 /* If skb's length exceeds the user's buffer, update the skb and
2164 * push it back to the receive_queue so that the next call to
2165 * recvmsg() will return the remaining data. Don't set MSG_EOR.
2167 if (skb_len
> copied
) {
2168 msg
->msg_flags
&= ~MSG_EOR
;
2169 if (flags
& MSG_PEEK
)
2171 sctp_skb_pull(skb
, copied
);
2172 skb_queue_head(&sk
->sk_receive_queue
, skb
);
2174 /* When only partial message is copied to the user, increase
2175 * rwnd by that amount. If all the data in the skb is read,
2176 * rwnd is updated when the event is freed.
2178 if (!sctp_ulpevent_is_notification(event
))
2179 sctp_assoc_rwnd_increase(event
->asoc
, copied
);
2181 } else if ((event
->msg_flags
& MSG_NOTIFICATION
) ||
2182 (event
->msg_flags
& MSG_EOR
))
2183 msg
->msg_flags
|= MSG_EOR
;
2185 msg
->msg_flags
&= ~MSG_EOR
;
2188 if (flags
& MSG_PEEK
) {
2189 /* Release the skb reference acquired after peeking the skb in
2190 * sctp_skb_recv_datagram().
2194 /* Free the event which includes releasing the reference to
2195 * the owner of the skb, freeing the skb and updating the
2198 sctp_ulpevent_free(event
);
2205 /* 7.1.12 Enable/Disable message fragmentation (SCTP_DISABLE_FRAGMENTS)
2207 * This option is a on/off flag. If enabled no SCTP message
2208 * fragmentation will be performed. Instead if a message being sent
2209 * exceeds the current PMTU size, the message will NOT be sent and
2210 * instead a error will be indicated to the user.
2212 static int sctp_setsockopt_disable_fragments(struct sock
*sk
, int *val
,
2213 unsigned int optlen
)
2215 if (optlen
< sizeof(int))
2217 sctp_sk(sk
)->disable_fragments
= (*val
== 0) ? 0 : 1;
2221 static int sctp_setsockopt_events(struct sock
*sk
, __u8
*sn_type
,
2222 unsigned int optlen
)
2224 struct sctp_sock
*sp
= sctp_sk(sk
);
2225 struct sctp_association
*asoc
;
2228 if (optlen
> sizeof(struct sctp_event_subscribe
))
2231 for (i
= 0; i
< optlen
; i
++)
2232 sctp_ulpevent_type_set(&sp
->subscribe
, SCTP_SN_TYPE_BASE
+ i
,
2235 list_for_each_entry(asoc
, &sp
->ep
->asocs
, asocs
)
2236 asoc
->subscribe
= sctp_sk(sk
)->subscribe
;
2238 /* At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
2239 * if there is no data to be sent or retransmit, the stack will
2240 * immediately send up this notification.
2242 if (sctp_ulpevent_type_enabled(sp
->subscribe
, SCTP_SENDER_DRY_EVENT
)) {
2243 struct sctp_ulpevent
*event
;
2245 asoc
= sctp_id2assoc(sk
, 0);
2246 if (asoc
&& sctp_outq_is_empty(&asoc
->outqueue
)) {
2247 event
= sctp_ulpevent_make_sender_dry_event(asoc
,
2248 GFP_USER
| __GFP_NOWARN
);
2252 asoc
->stream
.si
->enqueue_event(&asoc
->ulpq
, event
);
2259 /* 7.1.8 Automatic Close of associations (SCTP_AUTOCLOSE)
2261 * This socket option is applicable to the UDP-style socket only. When
2262 * set it will cause associations that are idle for more than the
2263 * specified number of seconds to automatically close. An association
2264 * being idle is defined an association that has NOT sent or received
2265 * user data. The special value of '0' indicates that no automatic
2266 * close of any associations should be performed. The option expects an
2267 * integer defining the number of seconds of idle time before an
2268 * association is closed.
2270 static int sctp_setsockopt_autoclose(struct sock
*sk
, u32
*optval
,
2271 unsigned int optlen
)
2273 struct sctp_sock
*sp
= sctp_sk(sk
);
2274 struct net
*net
= sock_net(sk
);
2276 /* Applicable to UDP-style socket only */
2277 if (sctp_style(sk
, TCP
))
2279 if (optlen
!= sizeof(int))
2282 sp
->autoclose
= *optval
;
2283 if (sp
->autoclose
> net
->sctp
.max_autoclose
)
2284 sp
->autoclose
= net
->sctp
.max_autoclose
;
2289 /* 7.1.13 Peer Address Parameters (SCTP_PEER_ADDR_PARAMS)
2291 * Applications can enable or disable heartbeats for any peer address of
2292 * an association, modify an address's heartbeat interval, force a
2293 * heartbeat to be sent immediately, and adjust the address's maximum
2294 * number of retransmissions sent before an address is considered
2295 * unreachable. The following structure is used to access and modify an
2296 * address's parameters:
2298 * struct sctp_paddrparams {
2299 * sctp_assoc_t spp_assoc_id;
2300 * struct sockaddr_storage spp_address;
2301 * uint32_t spp_hbinterval;
2302 * uint16_t spp_pathmaxrxt;
2303 * uint32_t spp_pathmtu;
2304 * uint32_t spp_sackdelay;
2305 * uint32_t spp_flags;
2306 * uint32_t spp_ipv6_flowlabel;
2310 * spp_assoc_id - (one-to-many style socket) This is filled in the
2311 * application, and identifies the association for
2313 * spp_address - This specifies which address is of interest.
2314 * spp_hbinterval - This contains the value of the heartbeat interval,
2315 * in milliseconds. If a value of zero
2316 * is present in this field then no changes are to
2317 * be made to this parameter.
2318 * spp_pathmaxrxt - This contains the maximum number of
2319 * retransmissions before this address shall be
2320 * considered unreachable. If a value of zero
2321 * is present in this field then no changes are to
2322 * be made to this parameter.
2323 * spp_pathmtu - When Path MTU discovery is disabled the value
2324 * specified here will be the "fixed" path mtu.
2325 * Note that if the spp_address field is empty
2326 * then all associations on this address will
2327 * have this fixed path mtu set upon them.
2329 * spp_sackdelay - When delayed sack is enabled, this value specifies
2330 * the number of milliseconds that sacks will be delayed
2331 * for. This value will apply to all addresses of an
2332 * association if the spp_address field is empty. Note
2333 * also, that if delayed sack is enabled and this
2334 * value is set to 0, no change is made to the last
2335 * recorded delayed sack timer value.
2337 * spp_flags - These flags are used to control various features
2338 * on an association. The flag field may contain
2339 * zero or more of the following options.
2341 * SPP_HB_ENABLE - Enable heartbeats on the
2342 * specified address. Note that if the address
2343 * field is empty all addresses for the association
2344 * have heartbeats enabled upon them.
2346 * SPP_HB_DISABLE - Disable heartbeats on the
2347 * speicifed address. Note that if the address
2348 * field is empty all addresses for the association
2349 * will have their heartbeats disabled. Note also
2350 * that SPP_HB_ENABLE and SPP_HB_DISABLE are
2351 * mutually exclusive, only one of these two should
2352 * be specified. Enabling both fields will have
2353 * undetermined results.
2355 * SPP_HB_DEMAND - Request a user initiated heartbeat
2356 * to be made immediately.
2358 * SPP_HB_TIME_IS_ZERO - Specify's that the time for
2359 * heartbeat delayis to be set to the value of 0
2362 * SPP_PMTUD_ENABLE - This field will enable PMTU
2363 * discovery upon the specified address. Note that
2364 * if the address feild is empty then all addresses
2365 * on the association are effected.
2367 * SPP_PMTUD_DISABLE - This field will disable PMTU
2368 * discovery upon the specified address. Note that
2369 * if the address feild is empty then all addresses
2370 * on the association are effected. Not also that
2371 * SPP_PMTUD_ENABLE and SPP_PMTUD_DISABLE are mutually
2372 * exclusive. Enabling both will have undetermined
2375 * SPP_SACKDELAY_ENABLE - Setting this flag turns
2376 * on delayed sack. The time specified in spp_sackdelay
2377 * is used to specify the sack delay for this address. Note
2378 * that if spp_address is empty then all addresses will
2379 * enable delayed sack and take on the sack delay
2380 * value specified in spp_sackdelay.
2381 * SPP_SACKDELAY_DISABLE - Setting this flag turns
2382 * off delayed sack. If the spp_address field is blank then
2383 * delayed sack is disabled for the entire association. Note
2384 * also that this field is mutually exclusive to
2385 * SPP_SACKDELAY_ENABLE, setting both will have undefined
2388 * SPP_IPV6_FLOWLABEL: Setting this flag enables the
2389 * setting of the IPV6 flow label value. The value is
2390 * contained in the spp_ipv6_flowlabel field.
2391 * Upon retrieval, this flag will be set to indicate that
2392 * the spp_ipv6_flowlabel field has a valid value returned.
2393 * If a specific destination address is set (in the
2394 * spp_address field), then the value returned is that of
2395 * the address. If just an association is specified (and
2396 * no address), then the association's default flow label
2397 * is returned. If neither an association nor a destination
2398 * is specified, then the socket's default flow label is
2399 * returned. For non-IPv6 sockets, this flag will be left
2402 * SPP_DSCP: Setting this flag enables the setting of the
2403 * Differentiated Services Code Point (DSCP) value
2404 * associated with either the association or a specific
2405 * address. The value is obtained in the spp_dscp field.
2406 * Upon retrieval, this flag will be set to indicate that
2407 * the spp_dscp field has a valid value returned. If a
2408 * specific destination address is set when called (in the
2409 * spp_address field), then that specific destination
2410 * address's DSCP value is returned. If just an association
2411 * is specified, then the association's default DSCP is
2412 * returned. If neither an association nor a destination is
2413 * specified, then the socket's default DSCP is returned.
2415 * spp_ipv6_flowlabel
2416 * - This field is used in conjunction with the
2417 * SPP_IPV6_FLOWLABEL flag and contains the IPv6 flow label.
2418 * The 20 least significant bits are used for the flow
2419 * label. This setting has precedence over any IPv6-layer
2422 * spp_dscp - This field is used in conjunction with the SPP_DSCP flag
2423 * and contains the DSCP. The 6 most significant bits are
2424 * used for the DSCP. This setting has precedence over any
2425 * IPv4- or IPv6- layer setting.
2427 static int sctp_apply_peer_addr_params(struct sctp_paddrparams
*params
,
2428 struct sctp_transport
*trans
,
2429 struct sctp_association
*asoc
,
2430 struct sctp_sock
*sp
,
2433 int sackdelay_change
)
2437 if (params
->spp_flags
& SPP_HB_DEMAND
&& trans
) {
2438 error
= sctp_primitive_REQUESTHEARTBEAT(trans
->asoc
->base
.net
,
2439 trans
->asoc
, trans
);
2444 /* Note that unless the spp_flag is set to SPP_HB_ENABLE the value of
2445 * this field is ignored. Note also that a value of zero indicates
2446 * the current setting should be left unchanged.
2448 if (params
->spp_flags
& SPP_HB_ENABLE
) {
2450 /* Re-zero the interval if the SPP_HB_TIME_IS_ZERO is
2451 * set. This lets us use 0 value when this flag
2454 if (params
->spp_flags
& SPP_HB_TIME_IS_ZERO
)
2455 params
->spp_hbinterval
= 0;
2457 if (params
->spp_hbinterval
||
2458 (params
->spp_flags
& SPP_HB_TIME_IS_ZERO
)) {
2461 msecs_to_jiffies(params
->spp_hbinterval
);
2462 sctp_transport_reset_hb_timer(trans
);
2465 msecs_to_jiffies(params
->spp_hbinterval
);
2467 sp
->hbinterval
= params
->spp_hbinterval
;
2474 trans
->param_flags
=
2475 (trans
->param_flags
& ~SPP_HB
) | hb_change
;
2478 (asoc
->param_flags
& ~SPP_HB
) | hb_change
;
2481 (sp
->param_flags
& ~SPP_HB
) | hb_change
;
2485 /* When Path MTU discovery is disabled the value specified here will
2486 * be the "fixed" path mtu (i.e. the value of the spp_flags field must
2487 * include the flag SPP_PMTUD_DISABLE for this field to have any
2490 if ((params
->spp_flags
& SPP_PMTUD_DISABLE
) && params
->spp_pathmtu
) {
2492 trans
->pathmtu
= params
->spp_pathmtu
;
2493 sctp_assoc_sync_pmtu(asoc
);
2495 sctp_assoc_set_pmtu(asoc
, params
->spp_pathmtu
);
2497 sp
->pathmtu
= params
->spp_pathmtu
;
2503 int update
= (trans
->param_flags
& SPP_PMTUD_DISABLE
) &&
2504 (params
->spp_flags
& SPP_PMTUD_ENABLE
);
2505 trans
->param_flags
=
2506 (trans
->param_flags
& ~SPP_PMTUD
) | pmtud_change
;
2508 sctp_transport_pmtu(trans
, sctp_opt2sk(sp
));
2509 sctp_assoc_sync_pmtu(asoc
);
2511 sctp_transport_pl_reset(trans
);
2514 (asoc
->param_flags
& ~SPP_PMTUD
) | pmtud_change
;
2517 (sp
->param_flags
& ~SPP_PMTUD
) | pmtud_change
;
2521 /* Note that unless the spp_flag is set to SPP_SACKDELAY_ENABLE the
2522 * value of this field is ignored. Note also that a value of zero
2523 * indicates the current setting should be left unchanged.
2525 if ((params
->spp_flags
& SPP_SACKDELAY_ENABLE
) && params
->spp_sackdelay
) {
2528 msecs_to_jiffies(params
->spp_sackdelay
);
2531 msecs_to_jiffies(params
->spp_sackdelay
);
2533 sp
->sackdelay
= params
->spp_sackdelay
;
2537 if (sackdelay_change
) {
2539 trans
->param_flags
=
2540 (trans
->param_flags
& ~SPP_SACKDELAY
) |
2544 (asoc
->param_flags
& ~SPP_SACKDELAY
) |
2548 (sp
->param_flags
& ~SPP_SACKDELAY
) |
2553 /* Note that a value of zero indicates the current setting should be
2556 if (params
->spp_pathmaxrxt
) {
2558 trans
->pathmaxrxt
= params
->spp_pathmaxrxt
;
2560 asoc
->pathmaxrxt
= params
->spp_pathmaxrxt
;
2562 sp
->pathmaxrxt
= params
->spp_pathmaxrxt
;
2566 if (params
->spp_flags
& SPP_IPV6_FLOWLABEL
) {
2568 if (trans
->ipaddr
.sa
.sa_family
== AF_INET6
) {
2569 trans
->flowlabel
= params
->spp_ipv6_flowlabel
&
2570 SCTP_FLOWLABEL_VAL_MASK
;
2571 trans
->flowlabel
|= SCTP_FLOWLABEL_SET_MASK
;
2574 struct sctp_transport
*t
;
2576 list_for_each_entry(t
, &asoc
->peer
.transport_addr_list
,
2578 if (t
->ipaddr
.sa
.sa_family
!= AF_INET6
)
2580 t
->flowlabel
= params
->spp_ipv6_flowlabel
&
2581 SCTP_FLOWLABEL_VAL_MASK
;
2582 t
->flowlabel
|= SCTP_FLOWLABEL_SET_MASK
;
2584 asoc
->flowlabel
= params
->spp_ipv6_flowlabel
&
2585 SCTP_FLOWLABEL_VAL_MASK
;
2586 asoc
->flowlabel
|= SCTP_FLOWLABEL_SET_MASK
;
2587 } else if (sctp_opt2sk(sp
)->sk_family
== AF_INET6
) {
2588 sp
->flowlabel
= params
->spp_ipv6_flowlabel
&
2589 SCTP_FLOWLABEL_VAL_MASK
;
2590 sp
->flowlabel
|= SCTP_FLOWLABEL_SET_MASK
;
2594 if (params
->spp_flags
& SPP_DSCP
) {
2596 trans
->dscp
= params
->spp_dscp
& SCTP_DSCP_VAL_MASK
;
2597 trans
->dscp
|= SCTP_DSCP_SET_MASK
;
2599 struct sctp_transport
*t
;
2601 list_for_each_entry(t
, &asoc
->peer
.transport_addr_list
,
2603 t
->dscp
= params
->spp_dscp
&
2605 t
->dscp
|= SCTP_DSCP_SET_MASK
;
2607 asoc
->dscp
= params
->spp_dscp
& SCTP_DSCP_VAL_MASK
;
2608 asoc
->dscp
|= SCTP_DSCP_SET_MASK
;
2610 sp
->dscp
= params
->spp_dscp
& SCTP_DSCP_VAL_MASK
;
2611 sp
->dscp
|= SCTP_DSCP_SET_MASK
;
2618 static int sctp_setsockopt_peer_addr_params(struct sock
*sk
,
2619 struct sctp_paddrparams
*params
,
2620 unsigned int optlen
)
2622 struct sctp_transport
*trans
= NULL
;
2623 struct sctp_association
*asoc
= NULL
;
2624 struct sctp_sock
*sp
= sctp_sk(sk
);
2626 int hb_change
, pmtud_change
, sackdelay_change
;
2628 if (optlen
== ALIGN(offsetof(struct sctp_paddrparams
,
2629 spp_ipv6_flowlabel
), 4)) {
2630 if (params
->spp_flags
& (SPP_DSCP
| SPP_IPV6_FLOWLABEL
))
2632 } else if (optlen
!= sizeof(*params
)) {
2636 /* Validate flags and value parameters. */
2637 hb_change
= params
->spp_flags
& SPP_HB
;
2638 pmtud_change
= params
->spp_flags
& SPP_PMTUD
;
2639 sackdelay_change
= params
->spp_flags
& SPP_SACKDELAY
;
2641 if (hb_change
== SPP_HB
||
2642 pmtud_change
== SPP_PMTUD
||
2643 sackdelay_change
== SPP_SACKDELAY
||
2644 params
->spp_sackdelay
> 500 ||
2645 (params
->spp_pathmtu
&&
2646 params
->spp_pathmtu
< SCTP_DEFAULT_MINSEGMENT
))
2649 /* If an address other than INADDR_ANY is specified, and
2650 * no transport is found, then the request is invalid.
2652 if (!sctp_is_any(sk
, (union sctp_addr
*)¶ms
->spp_address
)) {
2653 trans
= sctp_addr_id2transport(sk
, ¶ms
->spp_address
,
2654 params
->spp_assoc_id
);
2659 /* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the
2660 * socket is a one to many style socket, and an association
2661 * was not found, then the id was invalid.
2663 asoc
= sctp_id2assoc(sk
, params
->spp_assoc_id
);
2664 if (!asoc
&& params
->spp_assoc_id
!= SCTP_FUTURE_ASSOC
&&
2665 sctp_style(sk
, UDP
))
2668 /* Heartbeat demand can only be sent on a transport or
2669 * association, but not a socket.
2671 if (params
->spp_flags
& SPP_HB_DEMAND
&& !trans
&& !asoc
)
2674 /* Process parameters. */
2675 error
= sctp_apply_peer_addr_params(params
, trans
, asoc
, sp
,
2676 hb_change
, pmtud_change
,
2682 /* If changes are for association, also apply parameters to each
2685 if (!trans
&& asoc
) {
2686 list_for_each_entry(trans
, &asoc
->peer
.transport_addr_list
,
2688 sctp_apply_peer_addr_params(params
, trans
, asoc
, sp
,
2689 hb_change
, pmtud_change
,
2697 static inline __u32
sctp_spp_sackdelay_enable(__u32 param_flags
)
2699 return (param_flags
& ~SPP_SACKDELAY
) | SPP_SACKDELAY_ENABLE
;
2702 static inline __u32
sctp_spp_sackdelay_disable(__u32 param_flags
)
2704 return (param_flags
& ~SPP_SACKDELAY
) | SPP_SACKDELAY_DISABLE
;
2707 static void sctp_apply_asoc_delayed_ack(struct sctp_sack_info
*params
,
2708 struct sctp_association
*asoc
)
2710 struct sctp_transport
*trans
;
2712 if (params
->sack_delay
) {
2713 asoc
->sackdelay
= msecs_to_jiffies(params
->sack_delay
);
2715 sctp_spp_sackdelay_enable(asoc
->param_flags
);
2717 if (params
->sack_freq
== 1) {
2719 sctp_spp_sackdelay_disable(asoc
->param_flags
);
2720 } else if (params
->sack_freq
> 1) {
2721 asoc
->sackfreq
= params
->sack_freq
;
2723 sctp_spp_sackdelay_enable(asoc
->param_flags
);
2726 list_for_each_entry(trans
, &asoc
->peer
.transport_addr_list
,
2728 if (params
->sack_delay
) {
2729 trans
->sackdelay
= msecs_to_jiffies(params
->sack_delay
);
2730 trans
->param_flags
=
2731 sctp_spp_sackdelay_enable(trans
->param_flags
);
2733 if (params
->sack_freq
== 1) {
2734 trans
->param_flags
=
2735 sctp_spp_sackdelay_disable(trans
->param_flags
);
2736 } else if (params
->sack_freq
> 1) {
2737 trans
->sackfreq
= params
->sack_freq
;
2738 trans
->param_flags
=
2739 sctp_spp_sackdelay_enable(trans
->param_flags
);
2745 * 7.1.23. Get or set delayed ack timer (SCTP_DELAYED_SACK)
2747 * This option will effect the way delayed acks are performed. This
2748 * option allows you to get or set the delayed ack time, in
2749 * milliseconds. It also allows changing the delayed ack frequency.
2750 * Changing the frequency to 1 disables the delayed sack algorithm. If
2751 * the assoc_id is 0, then this sets or gets the endpoints default
2752 * values. If the assoc_id field is non-zero, then the set or get
2753 * effects the specified association for the one to many model (the
2754 * assoc_id field is ignored by the one to one model). Note that if
2755 * sack_delay or sack_freq are 0 when setting this option, then the
2756 * current values will remain unchanged.
2758 * struct sctp_sack_info {
2759 * sctp_assoc_t sack_assoc_id;
2760 * uint32_t sack_delay;
2761 * uint32_t sack_freq;
2764 * sack_assoc_id - This parameter, indicates which association the user
2765 * is performing an action upon. Note that if this field's value is
2766 * zero then the endpoints default value is changed (effecting future
2767 * associations only).
2769 * sack_delay - This parameter contains the number of milliseconds that
2770 * the user is requesting the delayed ACK timer be set to. Note that
2771 * this value is defined in the standard to be between 200 and 500
2774 * sack_freq - This parameter contains the number of packets that must
2775 * be received before a sack is sent without waiting for the delay
2776 * timer to expire. The default value for this is 2, setting this
2777 * value to 1 will disable the delayed sack algorithm.
2779 static int __sctp_setsockopt_delayed_ack(struct sock
*sk
,
2780 struct sctp_sack_info
*params
)
2782 struct sctp_sock
*sp
= sctp_sk(sk
);
2783 struct sctp_association
*asoc
;
2785 /* Validate value parameter. */
2786 if (params
->sack_delay
> 500)
2789 /* Get association, if sack_assoc_id != SCTP_FUTURE_ASSOC and the
2790 * socket is a one to many style socket, and an association
2791 * was not found, then the id was invalid.
2793 asoc
= sctp_id2assoc(sk
, params
->sack_assoc_id
);
2794 if (!asoc
&& params
->sack_assoc_id
> SCTP_ALL_ASSOC
&&
2795 sctp_style(sk
, UDP
))
2799 sctp_apply_asoc_delayed_ack(params
, asoc
);
2804 if (sctp_style(sk
, TCP
))
2805 params
->sack_assoc_id
= SCTP_FUTURE_ASSOC
;
2807 if (params
->sack_assoc_id
== SCTP_FUTURE_ASSOC
||
2808 params
->sack_assoc_id
== SCTP_ALL_ASSOC
) {
2809 if (params
->sack_delay
) {
2810 sp
->sackdelay
= params
->sack_delay
;
2812 sctp_spp_sackdelay_enable(sp
->param_flags
);
2814 if (params
->sack_freq
== 1) {
2816 sctp_spp_sackdelay_disable(sp
->param_flags
);
2817 } else if (params
->sack_freq
> 1) {
2818 sp
->sackfreq
= params
->sack_freq
;
2820 sctp_spp_sackdelay_enable(sp
->param_flags
);
2824 if (params
->sack_assoc_id
== SCTP_CURRENT_ASSOC
||
2825 params
->sack_assoc_id
== SCTP_ALL_ASSOC
)
2826 list_for_each_entry(asoc
, &sp
->ep
->asocs
, asocs
)
2827 sctp_apply_asoc_delayed_ack(params
, asoc
);
2832 static int sctp_setsockopt_delayed_ack(struct sock
*sk
,
2833 struct sctp_sack_info
*params
,
2834 unsigned int optlen
)
2836 if (optlen
== sizeof(struct sctp_assoc_value
)) {
2837 struct sctp_assoc_value
*v
= (struct sctp_assoc_value
*)params
;
2838 struct sctp_sack_info p
;
2840 pr_warn_ratelimited(DEPRECATED
2842 "Use of struct sctp_assoc_value in delayed_ack socket option.\n"
2843 "Use struct sctp_sack_info instead\n",
2844 current
->comm
, task_pid_nr(current
));
2846 p
.sack_assoc_id
= v
->assoc_id
;
2847 p
.sack_delay
= v
->assoc_value
;
2848 p
.sack_freq
= v
->assoc_value
? 0 : 1;
2849 return __sctp_setsockopt_delayed_ack(sk
, &p
);
2852 if (optlen
!= sizeof(struct sctp_sack_info
))
2854 if (params
->sack_delay
== 0 && params
->sack_freq
== 0)
2856 return __sctp_setsockopt_delayed_ack(sk
, params
);
2859 /* 7.1.3 Initialization Parameters (SCTP_INITMSG)
2861 * Applications can specify protocol parameters for the default association
2862 * initialization. The option name argument to setsockopt() and getsockopt()
2865 * Setting initialization parameters is effective only on an unconnected
2866 * socket (for UDP-style sockets only future associations are effected
2867 * by the change). With TCP-style sockets, this option is inherited by
2868 * sockets derived from a listener socket.
2870 static int sctp_setsockopt_initmsg(struct sock
*sk
, struct sctp_initmsg
*sinit
,
2871 unsigned int optlen
)
2873 struct sctp_sock
*sp
= sctp_sk(sk
);
2875 if (optlen
!= sizeof(struct sctp_initmsg
))
2878 if (sinit
->sinit_num_ostreams
)
2879 sp
->initmsg
.sinit_num_ostreams
= sinit
->sinit_num_ostreams
;
2880 if (sinit
->sinit_max_instreams
)
2881 sp
->initmsg
.sinit_max_instreams
= sinit
->sinit_max_instreams
;
2882 if (sinit
->sinit_max_attempts
)
2883 sp
->initmsg
.sinit_max_attempts
= sinit
->sinit_max_attempts
;
2884 if (sinit
->sinit_max_init_timeo
)
2885 sp
->initmsg
.sinit_max_init_timeo
= sinit
->sinit_max_init_timeo
;
2891 * 7.1.14 Set default send parameters (SCTP_DEFAULT_SEND_PARAM)
2893 * Applications that wish to use the sendto() system call may wish to
2894 * specify a default set of parameters that would normally be supplied
2895 * through the inclusion of ancillary data. This socket option allows
2896 * such an application to set the default sctp_sndrcvinfo structure.
2897 * The application that wishes to use this socket option simply passes
2898 * in to this call the sctp_sndrcvinfo structure defined in Section
2899 * 5.2.2) The input parameters accepted by this call include
2900 * sinfo_stream, sinfo_flags, sinfo_ppid, sinfo_context,
2901 * sinfo_timetolive. The user must provide the sinfo_assoc_id field in
2902 * to this call if the caller is using the UDP model.
2904 static int sctp_setsockopt_default_send_param(struct sock
*sk
,
2905 struct sctp_sndrcvinfo
*info
,
2906 unsigned int optlen
)
2908 struct sctp_sock
*sp
= sctp_sk(sk
);
2909 struct sctp_association
*asoc
;
2911 if (optlen
!= sizeof(*info
))
2913 if (info
->sinfo_flags
&
2914 ~(SCTP_UNORDERED
| SCTP_ADDR_OVER
|
2915 SCTP_ABORT
| SCTP_EOF
))
2918 asoc
= sctp_id2assoc(sk
, info
->sinfo_assoc_id
);
2919 if (!asoc
&& info
->sinfo_assoc_id
> SCTP_ALL_ASSOC
&&
2920 sctp_style(sk
, UDP
))
2924 asoc
->default_stream
= info
->sinfo_stream
;
2925 asoc
->default_flags
= info
->sinfo_flags
;
2926 asoc
->default_ppid
= info
->sinfo_ppid
;
2927 asoc
->default_context
= info
->sinfo_context
;
2928 asoc
->default_timetolive
= info
->sinfo_timetolive
;
2933 if (sctp_style(sk
, TCP
))
2934 info
->sinfo_assoc_id
= SCTP_FUTURE_ASSOC
;
2936 if (info
->sinfo_assoc_id
== SCTP_FUTURE_ASSOC
||
2937 info
->sinfo_assoc_id
== SCTP_ALL_ASSOC
) {
2938 sp
->default_stream
= info
->sinfo_stream
;
2939 sp
->default_flags
= info
->sinfo_flags
;
2940 sp
->default_ppid
= info
->sinfo_ppid
;
2941 sp
->default_context
= info
->sinfo_context
;
2942 sp
->default_timetolive
= info
->sinfo_timetolive
;
2945 if (info
->sinfo_assoc_id
== SCTP_CURRENT_ASSOC
||
2946 info
->sinfo_assoc_id
== SCTP_ALL_ASSOC
) {
2947 list_for_each_entry(asoc
, &sp
->ep
->asocs
, asocs
) {
2948 asoc
->default_stream
= info
->sinfo_stream
;
2949 asoc
->default_flags
= info
->sinfo_flags
;
2950 asoc
->default_ppid
= info
->sinfo_ppid
;
2951 asoc
->default_context
= info
->sinfo_context
;
2952 asoc
->default_timetolive
= info
->sinfo_timetolive
;
2959 /* RFC6458, Section 8.1.31. Set/get Default Send Parameters
2960 * (SCTP_DEFAULT_SNDINFO)
2962 static int sctp_setsockopt_default_sndinfo(struct sock
*sk
,
2963 struct sctp_sndinfo
*info
,
2964 unsigned int optlen
)
2966 struct sctp_sock
*sp
= sctp_sk(sk
);
2967 struct sctp_association
*asoc
;
2969 if (optlen
!= sizeof(*info
))
2971 if (info
->snd_flags
&
2972 ~(SCTP_UNORDERED
| SCTP_ADDR_OVER
|
2973 SCTP_ABORT
| SCTP_EOF
))
2976 asoc
= sctp_id2assoc(sk
, info
->snd_assoc_id
);
2977 if (!asoc
&& info
->snd_assoc_id
> SCTP_ALL_ASSOC
&&
2978 sctp_style(sk
, UDP
))
2982 asoc
->default_stream
= info
->snd_sid
;
2983 asoc
->default_flags
= info
->snd_flags
;
2984 asoc
->default_ppid
= info
->snd_ppid
;
2985 asoc
->default_context
= info
->snd_context
;
2990 if (sctp_style(sk
, TCP
))
2991 info
->snd_assoc_id
= SCTP_FUTURE_ASSOC
;
2993 if (info
->snd_assoc_id
== SCTP_FUTURE_ASSOC
||
2994 info
->snd_assoc_id
== SCTP_ALL_ASSOC
) {
2995 sp
->default_stream
= info
->snd_sid
;
2996 sp
->default_flags
= info
->snd_flags
;
2997 sp
->default_ppid
= info
->snd_ppid
;
2998 sp
->default_context
= info
->snd_context
;
3001 if (info
->snd_assoc_id
== SCTP_CURRENT_ASSOC
||
3002 info
->snd_assoc_id
== SCTP_ALL_ASSOC
) {
3003 list_for_each_entry(asoc
, &sp
->ep
->asocs
, asocs
) {
3004 asoc
->default_stream
= info
->snd_sid
;
3005 asoc
->default_flags
= info
->snd_flags
;
3006 asoc
->default_ppid
= info
->snd_ppid
;
3007 asoc
->default_context
= info
->snd_context
;
3014 /* 7.1.10 Set Primary Address (SCTP_PRIMARY_ADDR)
3016 * Requests that the local SCTP stack use the enclosed peer address as
3017 * the association primary. The enclosed address must be one of the
3018 * association peer's addresses.
3020 static int sctp_setsockopt_primary_addr(struct sock
*sk
, struct sctp_prim
*prim
,
3021 unsigned int optlen
)
3023 struct sctp_transport
*trans
;
3027 if (optlen
!= sizeof(struct sctp_prim
))
3030 /* Allow security module to validate address but need address len. */
3031 af
= sctp_get_af_specific(prim
->ssp_addr
.ss_family
);
3035 err
= security_sctp_bind_connect(sk
, SCTP_PRIMARY_ADDR
,
3036 (struct sockaddr
*)&prim
->ssp_addr
,
3041 trans
= sctp_addr_id2transport(sk
, &prim
->ssp_addr
, prim
->ssp_assoc_id
);
3045 sctp_assoc_set_primary(trans
->asoc
, trans
);
3051 * 7.1.5 SCTP_NODELAY
3053 * Turn on/off any Nagle-like algorithm. This means that packets are
3054 * generally sent as soon as possible and no unnecessary delays are
3055 * introduced, at the cost of more packets in the network. Expects an
3056 * integer boolean flag.
3058 static int sctp_setsockopt_nodelay(struct sock
*sk
, int *val
,
3059 unsigned int optlen
)
3061 if (optlen
< sizeof(int))
3063 sctp_sk(sk
)->nodelay
= (*val
== 0) ? 0 : 1;
3069 * 7.1.1 SCTP_RTOINFO
3071 * The protocol parameters used to initialize and bound retransmission
3072 * timeout (RTO) are tunable. sctp_rtoinfo structure is used to access
3073 * and modify these parameters.
3074 * All parameters are time values, in milliseconds. A value of 0, when
3075 * modifying the parameters, indicates that the current value should not
3079 static int sctp_setsockopt_rtoinfo(struct sock
*sk
,
3080 struct sctp_rtoinfo
*rtoinfo
,
3081 unsigned int optlen
)
3083 struct sctp_association
*asoc
;
3084 unsigned long rto_min
, rto_max
;
3085 struct sctp_sock
*sp
= sctp_sk(sk
);
3087 if (optlen
!= sizeof (struct sctp_rtoinfo
))
3090 asoc
= sctp_id2assoc(sk
, rtoinfo
->srto_assoc_id
);
3092 /* Set the values to the specific association */
3093 if (!asoc
&& rtoinfo
->srto_assoc_id
!= SCTP_FUTURE_ASSOC
&&
3094 sctp_style(sk
, UDP
))
3097 rto_max
= rtoinfo
->srto_max
;
3098 rto_min
= rtoinfo
->srto_min
;
3101 rto_max
= asoc
? msecs_to_jiffies(rto_max
) : rto_max
;
3103 rto_max
= asoc
? asoc
->rto_max
: sp
->rtoinfo
.srto_max
;
3106 rto_min
= asoc
? msecs_to_jiffies(rto_min
) : rto_min
;
3108 rto_min
= asoc
? asoc
->rto_min
: sp
->rtoinfo
.srto_min
;
3110 if (rto_min
> rto_max
)
3114 if (rtoinfo
->srto_initial
!= 0)
3116 msecs_to_jiffies(rtoinfo
->srto_initial
);
3117 asoc
->rto_max
= rto_max
;
3118 asoc
->rto_min
= rto_min
;
3120 /* If there is no association or the association-id = 0
3121 * set the values to the endpoint.
3123 if (rtoinfo
->srto_initial
!= 0)
3124 sp
->rtoinfo
.srto_initial
= rtoinfo
->srto_initial
;
3125 sp
->rtoinfo
.srto_max
= rto_max
;
3126 sp
->rtoinfo
.srto_min
= rto_min
;
3134 * 7.1.2 SCTP_ASSOCINFO
3136 * This option is used to tune the maximum retransmission attempts
3137 * of the association.
3138 * Returns an error if the new association retransmission value is
3139 * greater than the sum of the retransmission value of the peer.
3140 * See [SCTP] for more information.
3143 static int sctp_setsockopt_associnfo(struct sock
*sk
,
3144 struct sctp_assocparams
*assocparams
,
3145 unsigned int optlen
)
3148 struct sctp_association
*asoc
;
3150 if (optlen
!= sizeof(struct sctp_assocparams
))
3153 asoc
= sctp_id2assoc(sk
, assocparams
->sasoc_assoc_id
);
3155 if (!asoc
&& assocparams
->sasoc_assoc_id
!= SCTP_FUTURE_ASSOC
&&
3156 sctp_style(sk
, UDP
))
3159 /* Set the values to the specific association */
3161 if (assocparams
->sasoc_asocmaxrxt
!= 0) {
3164 struct sctp_transport
*peer_addr
;
3166 list_for_each_entry(peer_addr
, &asoc
->peer
.transport_addr_list
,
3168 path_sum
+= peer_addr
->pathmaxrxt
;
3172 /* Only validate asocmaxrxt if we have more than
3173 * one path/transport. We do this because path
3174 * retransmissions are only counted when we have more
3178 assocparams
->sasoc_asocmaxrxt
> path_sum
)
3181 asoc
->max_retrans
= assocparams
->sasoc_asocmaxrxt
;
3184 if (assocparams
->sasoc_cookie_life
!= 0)
3186 ms_to_ktime(assocparams
->sasoc_cookie_life
);
3188 /* Set the values to the endpoint */
3189 struct sctp_sock
*sp
= sctp_sk(sk
);
3191 if (assocparams
->sasoc_asocmaxrxt
!= 0)
3192 sp
->assocparams
.sasoc_asocmaxrxt
=
3193 assocparams
->sasoc_asocmaxrxt
;
3194 if (assocparams
->sasoc_cookie_life
!= 0)
3195 sp
->assocparams
.sasoc_cookie_life
=
3196 assocparams
->sasoc_cookie_life
;
3202 * 7.1.16 Set/clear IPv4 mapped addresses (SCTP_I_WANT_MAPPED_V4_ADDR)
3204 * This socket option is a boolean flag which turns on or off mapped V4
3205 * addresses. If this option is turned on and the socket is type
3206 * PF_INET6, then IPv4 addresses will be mapped to V6 representation.
3207 * If this option is turned off, then no mapping will be done of V4
3208 * addresses and a user will receive both PF_INET6 and PF_INET type
3209 * addresses on the socket.
3211 static int sctp_setsockopt_mappedv4(struct sock
*sk
, int *val
,
3212 unsigned int optlen
)
3214 struct sctp_sock
*sp
= sctp_sk(sk
);
3216 if (optlen
< sizeof(int))
3227 * 8.1.16. Get or Set the Maximum Fragmentation Size (SCTP_MAXSEG)
3228 * This option will get or set the maximum size to put in any outgoing
3229 * SCTP DATA chunk. If a message is larger than this size it will be
3230 * fragmented by SCTP into the specified size. Note that the underlying
3231 * SCTP implementation may fragment into smaller sized chunks when the
3232 * PMTU of the underlying association is smaller than the value set by
3233 * the user. The default value for this option is '0' which indicates
3234 * the user is NOT limiting fragmentation and only the PMTU will effect
3235 * SCTP's choice of DATA chunk size. Note also that values set larger
3236 * than the maximum size of an IP datagram will effectively let SCTP
3237 * control fragmentation (i.e. the same as setting this option to 0).
3239 * The following structure is used to access and modify this parameter:
3241 * struct sctp_assoc_value {
3242 * sctp_assoc_t assoc_id;
3243 * uint32_t assoc_value;
3246 * assoc_id: This parameter is ignored for one-to-one style sockets.
3247 * For one-to-many style sockets this parameter indicates which
3248 * association the user is performing an action upon. Note that if
3249 * this field's value is zero then the endpoints default value is
3250 * changed (effecting future associations only).
3251 * assoc_value: This parameter specifies the maximum size in bytes.
3253 static int sctp_setsockopt_maxseg(struct sock
*sk
,
3254 struct sctp_assoc_value
*params
,
3255 unsigned int optlen
)
3257 struct sctp_sock
*sp
= sctp_sk(sk
);
3258 struct sctp_association
*asoc
;
3259 sctp_assoc_t assoc_id
;
3262 if (optlen
== sizeof(int)) {
3263 pr_warn_ratelimited(DEPRECATED
3265 "Use of int in maxseg socket option.\n"
3266 "Use struct sctp_assoc_value instead\n",
3267 current
->comm
, task_pid_nr(current
));
3268 assoc_id
= SCTP_FUTURE_ASSOC
;
3269 val
= *(int *)params
;
3270 } else if (optlen
== sizeof(struct sctp_assoc_value
)) {
3271 assoc_id
= params
->assoc_id
;
3272 val
= params
->assoc_value
;
3277 asoc
= sctp_id2assoc(sk
, assoc_id
);
3278 if (!asoc
&& assoc_id
!= SCTP_FUTURE_ASSOC
&&
3279 sctp_style(sk
, UDP
))
3283 int min_len
, max_len
;
3284 __u16 datasize
= asoc
? sctp_datachk_len(&asoc
->stream
) :
3285 sizeof(struct sctp_data_chunk
);
3287 min_len
= sctp_min_frag_point(sp
, datasize
);
3288 max_len
= SCTP_MAX_CHUNK_LEN
- datasize
;
3290 if (val
< min_len
|| val
> max_len
)
3295 asoc
->user_frag
= val
;
3296 sctp_assoc_update_frag_point(asoc
);
3298 sp
->user_frag
= val
;
3306 * 7.1.9 Set Peer Primary Address (SCTP_SET_PEER_PRIMARY_ADDR)
3308 * Requests that the peer mark the enclosed address as the association
3309 * primary. The enclosed address must be one of the association's
3310 * locally bound addresses. The following structure is used to make a
3311 * set primary request:
3313 static int sctp_setsockopt_peer_primary_addr(struct sock
*sk
,
3314 struct sctp_setpeerprim
*prim
,
3315 unsigned int optlen
)
3317 struct sctp_sock
*sp
;
3318 struct sctp_association
*asoc
= NULL
;
3319 struct sctp_chunk
*chunk
;
3325 if (!sp
->ep
->asconf_enable
)
3328 if (optlen
!= sizeof(struct sctp_setpeerprim
))
3331 asoc
= sctp_id2assoc(sk
, prim
->sspp_assoc_id
);
3335 if (!asoc
->peer
.asconf_capable
)
3338 if (asoc
->peer
.addip_disabled_mask
& SCTP_PARAM_SET_PRIMARY
)
3341 if (!sctp_state(asoc
, ESTABLISHED
))
3344 af
= sctp_get_af_specific(prim
->sspp_addr
.ss_family
);
3348 if (!af
->addr_valid((union sctp_addr
*)&prim
->sspp_addr
, sp
, NULL
))
3349 return -EADDRNOTAVAIL
;
3351 if (!sctp_assoc_lookup_laddr(asoc
, (union sctp_addr
*)&prim
->sspp_addr
))
3352 return -EADDRNOTAVAIL
;
3354 /* Allow security module to validate address. */
3355 err
= security_sctp_bind_connect(sk
, SCTP_SET_PEER_PRIMARY_ADDR
,
3356 (struct sockaddr
*)&prim
->sspp_addr
,
3361 /* Create an ASCONF chunk with SET_PRIMARY parameter */
3362 chunk
= sctp_make_asconf_set_prim(asoc
,
3363 (union sctp_addr
*)&prim
->sspp_addr
);
3367 err
= sctp_send_asconf(asoc
, chunk
);
3369 pr_debug("%s: we set peer primary addr primitively\n", __func__
);
3374 static int sctp_setsockopt_adaptation_layer(struct sock
*sk
,
3375 struct sctp_setadaptation
*adapt
,
3376 unsigned int optlen
)
3378 if (optlen
!= sizeof(struct sctp_setadaptation
))
3381 sctp_sk(sk
)->adaptation_ind
= adapt
->ssb_adaptation_ind
;
3387 * 7.1.29. Set or Get the default context (SCTP_CONTEXT)
3389 * The context field in the sctp_sndrcvinfo structure is normally only
3390 * used when a failed message is retrieved holding the value that was
3391 * sent down on the actual send call. This option allows the setting of
3392 * a default context on an association basis that will be received on
3393 * reading messages from the peer. This is especially helpful in the
3394 * one-2-many model for an application to keep some reference to an
3395 * internal state machine that is processing messages on the
3396 * association. Note that the setting of this value only effects
3397 * received messages from the peer and does not effect the value that is
3398 * saved with outbound messages.
3400 static int sctp_setsockopt_context(struct sock
*sk
,
3401 struct sctp_assoc_value
*params
,
3402 unsigned int optlen
)
3404 struct sctp_sock
*sp
= sctp_sk(sk
);
3405 struct sctp_association
*asoc
;
3407 if (optlen
!= sizeof(struct sctp_assoc_value
))
3410 asoc
= sctp_id2assoc(sk
, params
->assoc_id
);
3411 if (!asoc
&& params
->assoc_id
> SCTP_ALL_ASSOC
&&
3412 sctp_style(sk
, UDP
))
3416 asoc
->default_rcv_context
= params
->assoc_value
;
3421 if (sctp_style(sk
, TCP
))
3422 params
->assoc_id
= SCTP_FUTURE_ASSOC
;
3424 if (params
->assoc_id
== SCTP_FUTURE_ASSOC
||
3425 params
->assoc_id
== SCTP_ALL_ASSOC
)
3426 sp
->default_rcv_context
= params
->assoc_value
;
3428 if (params
->assoc_id
== SCTP_CURRENT_ASSOC
||
3429 params
->assoc_id
== SCTP_ALL_ASSOC
)
3430 list_for_each_entry(asoc
, &sp
->ep
->asocs
, asocs
)
3431 asoc
->default_rcv_context
= params
->assoc_value
;
3437 * 7.1.24. Get or set fragmented interleave (SCTP_FRAGMENT_INTERLEAVE)
3439 * This options will at a minimum specify if the implementation is doing
3440 * fragmented interleave. Fragmented interleave, for a one to many
3441 * socket, is when subsequent calls to receive a message may return
3442 * parts of messages from different associations. Some implementations
3443 * may allow you to turn this value on or off. If so, when turned off,
3444 * no fragment interleave will occur (which will cause a head of line
3445 * blocking amongst multiple associations sharing the same one to many
3446 * socket). When this option is turned on, then each receive call may
3447 * come from a different association (thus the user must receive data
3448 * with the extended calls (e.g. sctp_recvmsg) to keep track of which
3449 * association each receive belongs to.
3451 * This option takes a boolean value. A non-zero value indicates that
3452 * fragmented interleave is on. A value of zero indicates that
3453 * fragmented interleave is off.
3455 * Note that it is important that an implementation that allows this
3456 * option to be turned on, have it off by default. Otherwise an unaware
3457 * application using the one to many model may become confused and act
3460 static int sctp_setsockopt_fragment_interleave(struct sock
*sk
, int *val
,
3461 unsigned int optlen
)
3463 if (optlen
!= sizeof(int))
3466 sctp_sk(sk
)->frag_interleave
= !!*val
;
3468 if (!sctp_sk(sk
)->frag_interleave
)
3469 sctp_sk(sk
)->ep
->intl_enable
= 0;
3475 * 8.1.21. Set or Get the SCTP Partial Delivery Point
3476 * (SCTP_PARTIAL_DELIVERY_POINT)
3478 * This option will set or get the SCTP partial delivery point. This
3479 * point is the size of a message where the partial delivery API will be
3480 * invoked to help free up rwnd space for the peer. Setting this to a
3481 * lower value will cause partial deliveries to happen more often. The
3482 * calls argument is an integer that sets or gets the partial delivery
3483 * point. Note also that the call will fail if the user attempts to set
3484 * this value larger than the socket receive buffer size.
3486 * Note that any single message having a length smaller than or equal to
3487 * the SCTP partial delivery point will be delivered in one single read
3488 * call as long as the user provided buffer is large enough to hold the
3491 static int sctp_setsockopt_partial_delivery_point(struct sock
*sk
, u32
*val
,
3492 unsigned int optlen
)
3494 if (optlen
!= sizeof(u32
))
3497 /* Note: We double the receive buffer from what the user sets
3498 * it to be, also initial rwnd is based on rcvbuf/2.
3500 if (*val
> (sk
->sk_rcvbuf
>> 1))
3503 sctp_sk(sk
)->pd_point
= *val
;
3505 return 0; /* is this the right error code? */
3509 * 7.1.28. Set or Get the maximum burst (SCTP_MAX_BURST)
3511 * This option will allow a user to change the maximum burst of packets
3512 * that can be emitted by this association. Note that the default value
3513 * is 4, and some implementations may restrict this setting so that it
3514 * can only be lowered.
3516 * NOTE: This text doesn't seem right. Do this on a socket basis with
3517 * future associations inheriting the socket value.
3519 static int sctp_setsockopt_maxburst(struct sock
*sk
,
3520 struct sctp_assoc_value
*params
,
3521 unsigned int optlen
)
3523 struct sctp_sock
*sp
= sctp_sk(sk
);
3524 struct sctp_association
*asoc
;
3525 sctp_assoc_t assoc_id
;
3528 if (optlen
== sizeof(int)) {
3529 pr_warn_ratelimited(DEPRECATED
3531 "Use of int in max_burst socket option deprecated.\n"
3532 "Use struct sctp_assoc_value instead\n",
3533 current
->comm
, task_pid_nr(current
));
3534 assoc_id
= SCTP_FUTURE_ASSOC
;
3535 assoc_value
= *((int *)params
);
3536 } else if (optlen
== sizeof(struct sctp_assoc_value
)) {
3537 assoc_id
= params
->assoc_id
;
3538 assoc_value
= params
->assoc_value
;
3542 asoc
= sctp_id2assoc(sk
, assoc_id
);
3543 if (!asoc
&& assoc_id
> SCTP_ALL_ASSOC
&& sctp_style(sk
, UDP
))
3547 asoc
->max_burst
= assoc_value
;
3552 if (sctp_style(sk
, TCP
))
3553 assoc_id
= SCTP_FUTURE_ASSOC
;
3555 if (assoc_id
== SCTP_FUTURE_ASSOC
|| assoc_id
== SCTP_ALL_ASSOC
)
3556 sp
->max_burst
= assoc_value
;
3558 if (assoc_id
== SCTP_CURRENT_ASSOC
|| assoc_id
== SCTP_ALL_ASSOC
)
3559 list_for_each_entry(asoc
, &sp
->ep
->asocs
, asocs
)
3560 asoc
->max_burst
= assoc_value
;
3566 * 7.1.18. Add a chunk that must be authenticated (SCTP_AUTH_CHUNK)
3568 * This set option adds a chunk type that the user is requesting to be
3569 * received only in an authenticated way. Changes to the list of chunks
3570 * will only effect future associations on the socket.
3572 static int sctp_setsockopt_auth_chunk(struct sock
*sk
,
3573 struct sctp_authchunk
*val
,
3574 unsigned int optlen
)
3576 struct sctp_endpoint
*ep
= sctp_sk(sk
)->ep
;
3578 if (!ep
->auth_enable
)
3581 if (optlen
!= sizeof(struct sctp_authchunk
))
3584 switch (val
->sauth_chunk
) {
3586 case SCTP_CID_INIT_ACK
:
3587 case SCTP_CID_SHUTDOWN_COMPLETE
:
3592 /* add this chunk id to the endpoint */
3593 return sctp_auth_ep_add_chunkid(ep
, val
->sauth_chunk
);
3597 * 7.1.19. Get or set the list of supported HMAC Identifiers (SCTP_HMAC_IDENT)
3599 * This option gets or sets the list of HMAC algorithms that the local
3600 * endpoint requires the peer to use.
3602 static int sctp_setsockopt_hmac_ident(struct sock
*sk
,
3603 struct sctp_hmacalgo
*hmacs
,
3604 unsigned int optlen
)
3606 struct sctp_endpoint
*ep
= sctp_sk(sk
)->ep
;
3609 if (!ep
->auth_enable
)
3612 if (optlen
< sizeof(struct sctp_hmacalgo
))
3614 optlen
= min_t(unsigned int, optlen
, sizeof(struct sctp_hmacalgo
) +
3615 SCTP_AUTH_NUM_HMACS
* sizeof(u16
));
3617 idents
= hmacs
->shmac_num_idents
;
3618 if (idents
== 0 || idents
> SCTP_AUTH_NUM_HMACS
||
3619 (idents
* sizeof(u16
)) > (optlen
- sizeof(struct sctp_hmacalgo
)))
3622 return sctp_auth_ep_set_hmacs(ep
, hmacs
);
3626 * 7.1.20. Set a shared key (SCTP_AUTH_KEY)
3628 * This option will set a shared secret key which is used to build an
3629 * association shared key.
3631 static int sctp_setsockopt_auth_key(struct sock
*sk
,
3632 struct sctp_authkey
*authkey
,
3633 unsigned int optlen
)
3635 struct sctp_endpoint
*ep
= sctp_sk(sk
)->ep
;
3636 struct sctp_association
*asoc
;
3639 if (optlen
<= sizeof(struct sctp_authkey
))
3641 /* authkey->sca_keylength is u16, so optlen can't be bigger than
3644 optlen
= min_t(unsigned int, optlen
, USHRT_MAX
+ sizeof(*authkey
));
3646 if (authkey
->sca_keylength
> optlen
- sizeof(*authkey
))
3649 asoc
= sctp_id2assoc(sk
, authkey
->sca_assoc_id
);
3650 if (!asoc
&& authkey
->sca_assoc_id
> SCTP_ALL_ASSOC
&&
3651 sctp_style(sk
, UDP
))
3655 ret
= sctp_auth_set_key(ep
, asoc
, authkey
);
3659 if (sctp_style(sk
, TCP
))
3660 authkey
->sca_assoc_id
= SCTP_FUTURE_ASSOC
;
3662 if (authkey
->sca_assoc_id
== SCTP_FUTURE_ASSOC
||
3663 authkey
->sca_assoc_id
== SCTP_ALL_ASSOC
) {
3664 ret
= sctp_auth_set_key(ep
, asoc
, authkey
);
3671 if (authkey
->sca_assoc_id
== SCTP_CURRENT_ASSOC
||
3672 authkey
->sca_assoc_id
== SCTP_ALL_ASSOC
) {
3673 list_for_each_entry(asoc
, &ep
->asocs
, asocs
) {
3674 int res
= sctp_auth_set_key(ep
, asoc
, authkey
);
3682 memzero_explicit(authkey
, optlen
);
3687 * 7.1.21. Get or set the active shared key (SCTP_AUTH_ACTIVE_KEY)
3689 * This option will get or set the active shared key to be used to build
3690 * the association shared key.
3692 static int sctp_setsockopt_active_key(struct sock
*sk
,
3693 struct sctp_authkeyid
*val
,
3694 unsigned int optlen
)
3696 struct sctp_endpoint
*ep
= sctp_sk(sk
)->ep
;
3697 struct sctp_association
*asoc
;
3700 if (optlen
!= sizeof(struct sctp_authkeyid
))
3703 asoc
= sctp_id2assoc(sk
, val
->scact_assoc_id
);
3704 if (!asoc
&& val
->scact_assoc_id
> SCTP_ALL_ASSOC
&&
3705 sctp_style(sk
, UDP
))
3709 return sctp_auth_set_active_key(ep
, asoc
, val
->scact_keynumber
);
3711 if (sctp_style(sk
, TCP
))
3712 val
->scact_assoc_id
= SCTP_FUTURE_ASSOC
;
3714 if (val
->scact_assoc_id
== SCTP_FUTURE_ASSOC
||
3715 val
->scact_assoc_id
== SCTP_ALL_ASSOC
) {
3716 ret
= sctp_auth_set_active_key(ep
, asoc
, val
->scact_keynumber
);
3721 if (val
->scact_assoc_id
== SCTP_CURRENT_ASSOC
||
3722 val
->scact_assoc_id
== SCTP_ALL_ASSOC
) {
3723 list_for_each_entry(asoc
, &ep
->asocs
, asocs
) {
3724 int res
= sctp_auth_set_active_key(ep
, asoc
,
3725 val
->scact_keynumber
);
3736 * 7.1.22. Delete a shared key (SCTP_AUTH_DELETE_KEY)
3738 * This set option will delete a shared secret key from use.
3740 static int sctp_setsockopt_del_key(struct sock
*sk
,
3741 struct sctp_authkeyid
*val
,
3742 unsigned int optlen
)
3744 struct sctp_endpoint
*ep
= sctp_sk(sk
)->ep
;
3745 struct sctp_association
*asoc
;
3748 if (optlen
!= sizeof(struct sctp_authkeyid
))
3751 asoc
= sctp_id2assoc(sk
, val
->scact_assoc_id
);
3752 if (!asoc
&& val
->scact_assoc_id
> SCTP_ALL_ASSOC
&&
3753 sctp_style(sk
, UDP
))
3757 return sctp_auth_del_key_id(ep
, asoc
, val
->scact_keynumber
);
3759 if (sctp_style(sk
, TCP
))
3760 val
->scact_assoc_id
= SCTP_FUTURE_ASSOC
;
3762 if (val
->scact_assoc_id
== SCTP_FUTURE_ASSOC
||
3763 val
->scact_assoc_id
== SCTP_ALL_ASSOC
) {
3764 ret
= sctp_auth_del_key_id(ep
, asoc
, val
->scact_keynumber
);
3769 if (val
->scact_assoc_id
== SCTP_CURRENT_ASSOC
||
3770 val
->scact_assoc_id
== SCTP_ALL_ASSOC
) {
3771 list_for_each_entry(asoc
, &ep
->asocs
, asocs
) {
3772 int res
= sctp_auth_del_key_id(ep
, asoc
,
3773 val
->scact_keynumber
);
3784 * 8.3.4 Deactivate a Shared Key (SCTP_AUTH_DEACTIVATE_KEY)
3786 * This set option will deactivate a shared secret key.
3788 static int sctp_setsockopt_deactivate_key(struct sock
*sk
,
3789 struct sctp_authkeyid
*val
,
3790 unsigned int optlen
)
3792 struct sctp_endpoint
*ep
= sctp_sk(sk
)->ep
;
3793 struct sctp_association
*asoc
;
3796 if (optlen
!= sizeof(struct sctp_authkeyid
))
3799 asoc
= sctp_id2assoc(sk
, val
->scact_assoc_id
);
3800 if (!asoc
&& val
->scact_assoc_id
> SCTP_ALL_ASSOC
&&
3801 sctp_style(sk
, UDP
))
3805 return sctp_auth_deact_key_id(ep
, asoc
, val
->scact_keynumber
);
3807 if (sctp_style(sk
, TCP
))
3808 val
->scact_assoc_id
= SCTP_FUTURE_ASSOC
;
3810 if (val
->scact_assoc_id
== SCTP_FUTURE_ASSOC
||
3811 val
->scact_assoc_id
== SCTP_ALL_ASSOC
) {
3812 ret
= sctp_auth_deact_key_id(ep
, asoc
, val
->scact_keynumber
);
3817 if (val
->scact_assoc_id
== SCTP_CURRENT_ASSOC
||
3818 val
->scact_assoc_id
== SCTP_ALL_ASSOC
) {
3819 list_for_each_entry(asoc
, &ep
->asocs
, asocs
) {
3820 int res
= sctp_auth_deact_key_id(ep
, asoc
,
3821 val
->scact_keynumber
);
3832 * 8.1.23 SCTP_AUTO_ASCONF
3834 * This option will enable or disable the use of the automatic generation of
3835 * ASCONF chunks to add and delete addresses to an existing association. Note
3836 * that this option has two caveats namely: a) it only affects sockets that
3837 * are bound to all addresses available to the SCTP stack, and b) the system
3838 * administrator may have an overriding control that turns the ASCONF feature
3839 * off no matter what setting the socket option may have.
3840 * This option expects an integer boolean flag, where a non-zero value turns on
3841 * the option, and a zero value turns off the option.
3842 * Note. In this implementation, socket operation overrides default parameter
3843 * being set by sysctl as well as FreeBSD implementation
3845 static int sctp_setsockopt_auto_asconf(struct sock
*sk
, int *val
,
3846 unsigned int optlen
)
3848 struct sctp_sock
*sp
= sctp_sk(sk
);
3850 if (optlen
< sizeof(int))
3852 if (!sctp_is_ep_boundall(sk
) && *val
)
3854 if ((*val
&& sp
->do_auto_asconf
) || (!*val
&& !sp
->do_auto_asconf
))
3857 spin_lock_bh(&sock_net(sk
)->sctp
.addr_wq_lock
);
3858 if (*val
== 0 && sp
->do_auto_asconf
) {
3859 list_del(&sp
->auto_asconf_list
);
3860 sp
->do_auto_asconf
= 0;
3861 } else if (*val
&& !sp
->do_auto_asconf
) {
3862 list_add_tail(&sp
->auto_asconf_list
,
3863 &sock_net(sk
)->sctp
.auto_asconf_splist
);
3864 sp
->do_auto_asconf
= 1;
3866 spin_unlock_bh(&sock_net(sk
)->sctp
.addr_wq_lock
);
3871 * SCTP_PEER_ADDR_THLDS
3873 * This option allows us to alter the partially failed threshold for one or all
3874 * transports in an association. See Section 6.1 of:
3875 * http://www.ietf.org/id/draft-nishida-tsvwg-sctp-failover-05.txt
3877 static int sctp_setsockopt_paddr_thresholds(struct sock
*sk
,
3878 struct sctp_paddrthlds_v2
*val
,
3879 unsigned int optlen
, bool v2
)
3881 struct sctp_transport
*trans
;
3882 struct sctp_association
*asoc
;
3885 len
= v2
? sizeof(*val
) : sizeof(struct sctp_paddrthlds
);
3889 if (v2
&& val
->spt_pathpfthld
> val
->spt_pathcpthld
)
3892 if (!sctp_is_any(sk
, (const union sctp_addr
*)&val
->spt_address
)) {
3893 trans
= sctp_addr_id2transport(sk
, &val
->spt_address
,
3898 if (val
->spt_pathmaxrxt
)
3899 trans
->pathmaxrxt
= val
->spt_pathmaxrxt
;
3901 trans
->ps_retrans
= val
->spt_pathcpthld
;
3902 trans
->pf_retrans
= val
->spt_pathpfthld
;
3907 asoc
= sctp_id2assoc(sk
, val
->spt_assoc_id
);
3908 if (!asoc
&& val
->spt_assoc_id
!= SCTP_FUTURE_ASSOC
&&
3909 sctp_style(sk
, UDP
))
3913 list_for_each_entry(trans
, &asoc
->peer
.transport_addr_list
,
3915 if (val
->spt_pathmaxrxt
)
3916 trans
->pathmaxrxt
= val
->spt_pathmaxrxt
;
3918 trans
->ps_retrans
= val
->spt_pathcpthld
;
3919 trans
->pf_retrans
= val
->spt_pathpfthld
;
3922 if (val
->spt_pathmaxrxt
)
3923 asoc
->pathmaxrxt
= val
->spt_pathmaxrxt
;
3925 asoc
->ps_retrans
= val
->spt_pathcpthld
;
3926 asoc
->pf_retrans
= val
->spt_pathpfthld
;
3928 struct sctp_sock
*sp
= sctp_sk(sk
);
3930 if (val
->spt_pathmaxrxt
)
3931 sp
->pathmaxrxt
= val
->spt_pathmaxrxt
;
3933 sp
->ps_retrans
= val
->spt_pathcpthld
;
3934 sp
->pf_retrans
= val
->spt_pathpfthld
;
3940 static int sctp_setsockopt_recvrcvinfo(struct sock
*sk
, int *val
,
3941 unsigned int optlen
)
3943 if (optlen
< sizeof(int))
3946 sctp_sk(sk
)->recvrcvinfo
= (*val
== 0) ? 0 : 1;
3951 static int sctp_setsockopt_recvnxtinfo(struct sock
*sk
, int *val
,
3952 unsigned int optlen
)
3954 if (optlen
< sizeof(int))
3957 sctp_sk(sk
)->recvnxtinfo
= (*val
== 0) ? 0 : 1;
3962 static int sctp_setsockopt_pr_supported(struct sock
*sk
,
3963 struct sctp_assoc_value
*params
,
3964 unsigned int optlen
)
3966 struct sctp_association
*asoc
;
3968 if (optlen
!= sizeof(*params
))
3971 asoc
= sctp_id2assoc(sk
, params
->assoc_id
);
3972 if (!asoc
&& params
->assoc_id
!= SCTP_FUTURE_ASSOC
&&
3973 sctp_style(sk
, UDP
))
3976 sctp_sk(sk
)->ep
->prsctp_enable
= !!params
->assoc_value
;
3981 static int sctp_setsockopt_default_prinfo(struct sock
*sk
,
3982 struct sctp_default_prinfo
*info
,
3983 unsigned int optlen
)
3985 struct sctp_sock
*sp
= sctp_sk(sk
);
3986 struct sctp_association
*asoc
;
3987 int retval
= -EINVAL
;
3989 if (optlen
!= sizeof(*info
))
3992 if (info
->pr_policy
& ~SCTP_PR_SCTP_MASK
)
3995 if (info
->pr_policy
== SCTP_PR_SCTP_NONE
)
3998 asoc
= sctp_id2assoc(sk
, info
->pr_assoc_id
);
3999 if (!asoc
&& info
->pr_assoc_id
> SCTP_ALL_ASSOC
&&
4000 sctp_style(sk
, UDP
))
4006 SCTP_PR_SET_POLICY(asoc
->default_flags
, info
->pr_policy
);
4007 asoc
->default_timetolive
= info
->pr_value
;
4011 if (sctp_style(sk
, TCP
))
4012 info
->pr_assoc_id
= SCTP_FUTURE_ASSOC
;
4014 if (info
->pr_assoc_id
== SCTP_FUTURE_ASSOC
||
4015 info
->pr_assoc_id
== SCTP_ALL_ASSOC
) {
4016 SCTP_PR_SET_POLICY(sp
->default_flags
, info
->pr_policy
);
4017 sp
->default_timetolive
= info
->pr_value
;
4020 if (info
->pr_assoc_id
== SCTP_CURRENT_ASSOC
||
4021 info
->pr_assoc_id
== SCTP_ALL_ASSOC
) {
4022 list_for_each_entry(asoc
, &sp
->ep
->asocs
, asocs
) {
4023 SCTP_PR_SET_POLICY(asoc
->default_flags
,
4025 asoc
->default_timetolive
= info
->pr_value
;
4033 static int sctp_setsockopt_reconfig_supported(struct sock
*sk
,
4034 struct sctp_assoc_value
*params
,
4035 unsigned int optlen
)
4037 struct sctp_association
*asoc
;
4038 int retval
= -EINVAL
;
4040 if (optlen
!= sizeof(*params
))
4043 asoc
= sctp_id2assoc(sk
, params
->assoc_id
);
4044 if (!asoc
&& params
->assoc_id
!= SCTP_FUTURE_ASSOC
&&
4045 sctp_style(sk
, UDP
))
4048 sctp_sk(sk
)->ep
->reconf_enable
= !!params
->assoc_value
;
4056 static int sctp_setsockopt_enable_strreset(struct sock
*sk
,
4057 struct sctp_assoc_value
*params
,
4058 unsigned int optlen
)
4060 struct sctp_endpoint
*ep
= sctp_sk(sk
)->ep
;
4061 struct sctp_association
*asoc
;
4062 int retval
= -EINVAL
;
4064 if (optlen
!= sizeof(*params
))
4067 if (params
->assoc_value
& (~SCTP_ENABLE_STRRESET_MASK
))
4070 asoc
= sctp_id2assoc(sk
, params
->assoc_id
);
4071 if (!asoc
&& params
->assoc_id
> SCTP_ALL_ASSOC
&&
4072 sctp_style(sk
, UDP
))
4078 asoc
->strreset_enable
= params
->assoc_value
;
4082 if (sctp_style(sk
, TCP
))
4083 params
->assoc_id
= SCTP_FUTURE_ASSOC
;
4085 if (params
->assoc_id
== SCTP_FUTURE_ASSOC
||
4086 params
->assoc_id
== SCTP_ALL_ASSOC
)
4087 ep
->strreset_enable
= params
->assoc_value
;
4089 if (params
->assoc_id
== SCTP_CURRENT_ASSOC
||
4090 params
->assoc_id
== SCTP_ALL_ASSOC
)
4091 list_for_each_entry(asoc
, &ep
->asocs
, asocs
)
4092 asoc
->strreset_enable
= params
->assoc_value
;
4098 static int sctp_setsockopt_reset_streams(struct sock
*sk
,
4099 struct sctp_reset_streams
*params
,
4100 unsigned int optlen
)
4102 struct sctp_association
*asoc
;
4104 if (optlen
< sizeof(*params
))
4106 /* srs_number_streams is u16, so optlen can't be bigger than this. */
4107 optlen
= min_t(unsigned int, optlen
, USHRT_MAX
+
4108 sizeof(__u16
) * sizeof(*params
));
4110 if (params
->srs_number_streams
* sizeof(__u16
) >
4111 optlen
- sizeof(*params
))
4114 asoc
= sctp_id2assoc(sk
, params
->srs_assoc_id
);
4118 return sctp_send_reset_streams(asoc
, params
);
4121 static int sctp_setsockopt_reset_assoc(struct sock
*sk
, sctp_assoc_t
*associd
,
4122 unsigned int optlen
)
4124 struct sctp_association
*asoc
;
4126 if (optlen
!= sizeof(*associd
))
4129 asoc
= sctp_id2assoc(sk
, *associd
);
4133 return sctp_send_reset_assoc(asoc
);
4136 static int sctp_setsockopt_add_streams(struct sock
*sk
,
4137 struct sctp_add_streams
*params
,
4138 unsigned int optlen
)
4140 struct sctp_association
*asoc
;
4142 if (optlen
!= sizeof(*params
))
4145 asoc
= sctp_id2assoc(sk
, params
->sas_assoc_id
);
4149 return sctp_send_add_streams(asoc
, params
);
4152 static int sctp_setsockopt_scheduler(struct sock
*sk
,
4153 struct sctp_assoc_value
*params
,
4154 unsigned int optlen
)
4156 struct sctp_sock
*sp
= sctp_sk(sk
);
4157 struct sctp_association
*asoc
;
4160 if (optlen
< sizeof(*params
))
4163 if (params
->assoc_value
> SCTP_SS_MAX
)
4166 asoc
= sctp_id2assoc(sk
, params
->assoc_id
);
4167 if (!asoc
&& params
->assoc_id
> SCTP_ALL_ASSOC
&&
4168 sctp_style(sk
, UDP
))
4172 return sctp_sched_set_sched(asoc
, params
->assoc_value
);
4174 if (sctp_style(sk
, TCP
))
4175 params
->assoc_id
= SCTP_FUTURE_ASSOC
;
4177 if (params
->assoc_id
== SCTP_FUTURE_ASSOC
||
4178 params
->assoc_id
== SCTP_ALL_ASSOC
)
4179 sp
->default_ss
= params
->assoc_value
;
4181 if (params
->assoc_id
== SCTP_CURRENT_ASSOC
||
4182 params
->assoc_id
== SCTP_ALL_ASSOC
) {
4183 list_for_each_entry(asoc
, &sp
->ep
->asocs
, asocs
) {
4184 int ret
= sctp_sched_set_sched(asoc
,
4185 params
->assoc_value
);
4195 static int sctp_setsockopt_scheduler_value(struct sock
*sk
,
4196 struct sctp_stream_value
*params
,
4197 unsigned int optlen
)
4199 struct sctp_association
*asoc
;
4200 int retval
= -EINVAL
;
4202 if (optlen
< sizeof(*params
))
4205 asoc
= sctp_id2assoc(sk
, params
->assoc_id
);
4206 if (!asoc
&& params
->assoc_id
!= SCTP_CURRENT_ASSOC
&&
4207 sctp_style(sk
, UDP
))
4211 retval
= sctp_sched_set_value(asoc
, params
->stream_id
,
4212 params
->stream_value
, GFP_KERNEL
);
4218 list_for_each_entry(asoc
, &sctp_sk(sk
)->ep
->asocs
, asocs
) {
4219 int ret
= sctp_sched_set_value(asoc
, params
->stream_id
,
4220 params
->stream_value
,
4222 if (ret
&& !retval
) /* try to return the 1st error. */
4230 static int sctp_setsockopt_interleaving_supported(struct sock
*sk
,
4231 struct sctp_assoc_value
*p
,
4232 unsigned int optlen
)
4234 struct sctp_sock
*sp
= sctp_sk(sk
);
4235 struct sctp_association
*asoc
;
4237 if (optlen
< sizeof(*p
))
4240 asoc
= sctp_id2assoc(sk
, p
->assoc_id
);
4241 if (!asoc
&& p
->assoc_id
!= SCTP_FUTURE_ASSOC
&& sctp_style(sk
, UDP
))
4244 if (!sock_net(sk
)->sctp
.intl_enable
|| !sp
->frag_interleave
) {
4248 sp
->ep
->intl_enable
= !!p
->assoc_value
;
4252 static int sctp_setsockopt_reuse_port(struct sock
*sk
, int *val
,
4253 unsigned int optlen
)
4255 if (!sctp_style(sk
, TCP
))
4258 if (sctp_sk(sk
)->ep
->base
.bind_addr
.port
)
4261 if (optlen
< sizeof(int))
4264 sctp_sk(sk
)->reuse
= !!*val
;
4269 static int sctp_assoc_ulpevent_type_set(struct sctp_event
*param
,
4270 struct sctp_association
*asoc
)
4272 struct sctp_ulpevent
*event
;
4274 sctp_ulpevent_type_set(&asoc
->subscribe
, param
->se_type
, param
->se_on
);
4276 if (param
->se_type
== SCTP_SENDER_DRY_EVENT
&& param
->se_on
) {
4277 if (sctp_outq_is_empty(&asoc
->outqueue
)) {
4278 event
= sctp_ulpevent_make_sender_dry_event(asoc
,
4279 GFP_USER
| __GFP_NOWARN
);
4283 asoc
->stream
.si
->enqueue_event(&asoc
->ulpq
, event
);
4290 static int sctp_setsockopt_event(struct sock
*sk
, struct sctp_event
*param
,
4291 unsigned int optlen
)
4293 struct sctp_sock
*sp
= sctp_sk(sk
);
4294 struct sctp_association
*asoc
;
4297 if (optlen
< sizeof(*param
))
4300 if (param
->se_type
< SCTP_SN_TYPE_BASE
||
4301 param
->se_type
> SCTP_SN_TYPE_MAX
)
4304 asoc
= sctp_id2assoc(sk
, param
->se_assoc_id
);
4305 if (!asoc
&& param
->se_assoc_id
> SCTP_ALL_ASSOC
&&
4306 sctp_style(sk
, UDP
))
4310 return sctp_assoc_ulpevent_type_set(param
, asoc
);
4312 if (sctp_style(sk
, TCP
))
4313 param
->se_assoc_id
= SCTP_FUTURE_ASSOC
;
4315 if (param
->se_assoc_id
== SCTP_FUTURE_ASSOC
||
4316 param
->se_assoc_id
== SCTP_ALL_ASSOC
)
4317 sctp_ulpevent_type_set(&sp
->subscribe
,
4318 param
->se_type
, param
->se_on
);
4320 if (param
->se_assoc_id
== SCTP_CURRENT_ASSOC
||
4321 param
->se_assoc_id
== SCTP_ALL_ASSOC
) {
4322 list_for_each_entry(asoc
, &sp
->ep
->asocs
, asocs
) {
4323 int ret
= sctp_assoc_ulpevent_type_set(param
, asoc
);
4333 static int sctp_setsockopt_asconf_supported(struct sock
*sk
,
4334 struct sctp_assoc_value
*params
,
4335 unsigned int optlen
)
4337 struct sctp_association
*asoc
;
4338 struct sctp_endpoint
*ep
;
4339 int retval
= -EINVAL
;
4341 if (optlen
!= sizeof(*params
))
4344 asoc
= sctp_id2assoc(sk
, params
->assoc_id
);
4345 if (!asoc
&& params
->assoc_id
!= SCTP_FUTURE_ASSOC
&&
4346 sctp_style(sk
, UDP
))
4349 ep
= sctp_sk(sk
)->ep
;
4350 ep
->asconf_enable
= !!params
->assoc_value
;
4352 if (ep
->asconf_enable
&& ep
->auth_enable
) {
4353 sctp_auth_ep_add_chunkid(ep
, SCTP_CID_ASCONF
);
4354 sctp_auth_ep_add_chunkid(ep
, SCTP_CID_ASCONF_ACK
);
4363 static int sctp_setsockopt_auth_supported(struct sock
*sk
,
4364 struct sctp_assoc_value
*params
,
4365 unsigned int optlen
)
4367 struct sctp_association
*asoc
;
4368 struct sctp_endpoint
*ep
;
4369 int retval
= -EINVAL
;
4371 if (optlen
!= sizeof(*params
))
4374 asoc
= sctp_id2assoc(sk
, params
->assoc_id
);
4375 if (!asoc
&& params
->assoc_id
!= SCTP_FUTURE_ASSOC
&&
4376 sctp_style(sk
, UDP
))
4379 ep
= sctp_sk(sk
)->ep
;
4380 if (params
->assoc_value
) {
4381 retval
= sctp_auth_init(ep
, GFP_KERNEL
);
4384 if (ep
->asconf_enable
) {
4385 sctp_auth_ep_add_chunkid(ep
, SCTP_CID_ASCONF
);
4386 sctp_auth_ep_add_chunkid(ep
, SCTP_CID_ASCONF_ACK
);
4390 ep
->auth_enable
= !!params
->assoc_value
;
4397 static int sctp_setsockopt_ecn_supported(struct sock
*sk
,
4398 struct sctp_assoc_value
*params
,
4399 unsigned int optlen
)
4401 struct sctp_association
*asoc
;
4402 int retval
= -EINVAL
;
4404 if (optlen
!= sizeof(*params
))
4407 asoc
= sctp_id2assoc(sk
, params
->assoc_id
);
4408 if (!asoc
&& params
->assoc_id
!= SCTP_FUTURE_ASSOC
&&
4409 sctp_style(sk
, UDP
))
4412 sctp_sk(sk
)->ep
->ecn_enable
= !!params
->assoc_value
;
4419 static int sctp_setsockopt_pf_expose(struct sock
*sk
,
4420 struct sctp_assoc_value
*params
,
4421 unsigned int optlen
)
4423 struct sctp_association
*asoc
;
4424 int retval
= -EINVAL
;
4426 if (optlen
!= sizeof(*params
))
4429 if (params
->assoc_value
> SCTP_PF_EXPOSE_MAX
)
4432 asoc
= sctp_id2assoc(sk
, params
->assoc_id
);
4433 if (!asoc
&& params
->assoc_id
!= SCTP_FUTURE_ASSOC
&&
4434 sctp_style(sk
, UDP
))
4438 asoc
->pf_expose
= params
->assoc_value
;
4440 sctp_sk(sk
)->pf_expose
= params
->assoc_value
;
4447 static int sctp_setsockopt_encap_port(struct sock
*sk
,
4448 struct sctp_udpencaps
*encap
,
4449 unsigned int optlen
)
4451 struct sctp_association
*asoc
;
4452 struct sctp_transport
*t
;
4455 if (optlen
!= sizeof(*encap
))
4458 /* If an address other than INADDR_ANY is specified, and
4459 * no transport is found, then the request is invalid.
4461 encap_port
= (__force __be16
)encap
->sue_port
;
4462 if (!sctp_is_any(sk
, (union sctp_addr
*)&encap
->sue_address
)) {
4463 t
= sctp_addr_id2transport(sk
, &encap
->sue_address
,
4464 encap
->sue_assoc_id
);
4468 t
->encap_port
= encap_port
;
4472 /* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the
4473 * socket is a one to many style socket, and an association
4474 * was not found, then the id was invalid.
4476 asoc
= sctp_id2assoc(sk
, encap
->sue_assoc_id
);
4477 if (!asoc
&& encap
->sue_assoc_id
!= SCTP_FUTURE_ASSOC
&&
4478 sctp_style(sk
, UDP
))
4481 /* If changes are for association, also apply encap_port to
4485 list_for_each_entry(t
, &asoc
->peer
.transport_addr_list
,
4487 t
->encap_port
= encap_port
;
4489 asoc
->encap_port
= encap_port
;
4493 sctp_sk(sk
)->encap_port
= encap_port
;
4497 static int sctp_setsockopt_probe_interval(struct sock
*sk
,
4498 struct sctp_probeinterval
*params
,
4499 unsigned int optlen
)
4501 struct sctp_association
*asoc
;
4502 struct sctp_transport
*t
;
4503 __u32 probe_interval
;
4505 if (optlen
!= sizeof(*params
))
4508 probe_interval
= params
->spi_interval
;
4509 if (probe_interval
&& probe_interval
< SCTP_PROBE_TIMER_MIN
)
4512 /* If an address other than INADDR_ANY is specified, and
4513 * no transport is found, then the request is invalid.
4515 if (!sctp_is_any(sk
, (union sctp_addr
*)¶ms
->spi_address
)) {
4516 t
= sctp_addr_id2transport(sk
, ¶ms
->spi_address
,
4517 params
->spi_assoc_id
);
4521 t
->probe_interval
= msecs_to_jiffies(probe_interval
);
4522 sctp_transport_pl_reset(t
);
4526 /* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the
4527 * socket is a one to many style socket, and an association
4528 * was not found, then the id was invalid.
4530 asoc
= sctp_id2assoc(sk
, params
->spi_assoc_id
);
4531 if (!asoc
&& params
->spi_assoc_id
!= SCTP_FUTURE_ASSOC
&&
4532 sctp_style(sk
, UDP
))
4535 /* If changes are for association, also apply probe_interval to
4539 list_for_each_entry(t
, &asoc
->peer
.transport_addr_list
, transports
) {
4540 t
->probe_interval
= msecs_to_jiffies(probe_interval
);
4541 sctp_transport_pl_reset(t
);
4544 asoc
->probe_interval
= msecs_to_jiffies(probe_interval
);
4548 sctp_sk(sk
)->probe_interval
= probe_interval
;
4552 /* API 6.2 setsockopt(), getsockopt()
4554 * Applications use setsockopt() and getsockopt() to set or retrieve
4555 * socket options. Socket options are used to change the default
4556 * behavior of sockets calls. They are described in Section 7.
4560 * ret = getsockopt(int sd, int level, int optname, void __user *optval,
4561 * int __user *optlen);
4562 * ret = setsockopt(int sd, int level, int optname, const void __user *optval,
4565 * sd - the socket descript.
4566 * level - set to IPPROTO_SCTP for all SCTP options.
4567 * optname - the option name.
4568 * optval - the buffer to store the value of the option.
4569 * optlen - the size of the buffer.
4571 static int sctp_setsockopt(struct sock
*sk
, int level
, int optname
,
4572 sockptr_t optval
, unsigned int optlen
)
4577 pr_debug("%s: sk:%p, optname:%d\n", __func__
, sk
, optname
);
4579 /* I can hardly begin to describe how wrong this is. This is
4580 * so broken as to be worse than useless. The API draft
4581 * REALLY is NOT helpful here... I am not convinced that the
4582 * semantics of setsockopt() with a level OTHER THAN SOL_SCTP
4583 * are at all well-founded.
4585 if (level
!= SOL_SCTP
) {
4586 struct sctp_af
*af
= sctp_sk(sk
)->pf
->af
;
4588 return af
->setsockopt(sk
, level
, optname
, optval
, optlen
);
4592 /* Trim it to the biggest size sctp sockopt may need if necessary */
4593 optlen
= min_t(unsigned int, optlen
,
4594 PAGE_ALIGN(USHRT_MAX
+
4595 sizeof(__u16
) * sizeof(struct sctp_reset_streams
)));
4596 kopt
= memdup_sockptr(optval
, optlen
);
4598 return PTR_ERR(kopt
);
4604 case SCTP_SOCKOPT_BINDX_ADD
:
4605 /* 'optlen' is the size of the addresses buffer. */
4606 retval
= sctp_setsockopt_bindx(sk
, kopt
, optlen
,
4607 SCTP_BINDX_ADD_ADDR
);
4610 case SCTP_SOCKOPT_BINDX_REM
:
4611 /* 'optlen' is the size of the addresses buffer. */
4612 retval
= sctp_setsockopt_bindx(sk
, kopt
, optlen
,
4613 SCTP_BINDX_REM_ADDR
);
4616 case SCTP_SOCKOPT_CONNECTX_OLD
:
4617 /* 'optlen' is the size of the addresses buffer. */
4618 retval
= sctp_setsockopt_connectx_old(sk
, kopt
, optlen
);
4621 case SCTP_SOCKOPT_CONNECTX
:
4622 /* 'optlen' is the size of the addresses buffer. */
4623 retval
= sctp_setsockopt_connectx(sk
, kopt
, optlen
);
4626 case SCTP_DISABLE_FRAGMENTS
:
4627 retval
= sctp_setsockopt_disable_fragments(sk
, kopt
, optlen
);
4631 retval
= sctp_setsockopt_events(sk
, kopt
, optlen
);
4634 case SCTP_AUTOCLOSE
:
4635 retval
= sctp_setsockopt_autoclose(sk
, kopt
, optlen
);
4638 case SCTP_PEER_ADDR_PARAMS
:
4639 retval
= sctp_setsockopt_peer_addr_params(sk
, kopt
, optlen
);
4642 case SCTP_DELAYED_SACK
:
4643 retval
= sctp_setsockopt_delayed_ack(sk
, kopt
, optlen
);
4645 case SCTP_PARTIAL_DELIVERY_POINT
:
4646 retval
= sctp_setsockopt_partial_delivery_point(sk
, kopt
, optlen
);
4650 retval
= sctp_setsockopt_initmsg(sk
, kopt
, optlen
);
4652 case SCTP_DEFAULT_SEND_PARAM
:
4653 retval
= sctp_setsockopt_default_send_param(sk
, kopt
, optlen
);
4655 case SCTP_DEFAULT_SNDINFO
:
4656 retval
= sctp_setsockopt_default_sndinfo(sk
, kopt
, optlen
);
4658 case SCTP_PRIMARY_ADDR
:
4659 retval
= sctp_setsockopt_primary_addr(sk
, kopt
, optlen
);
4661 case SCTP_SET_PEER_PRIMARY_ADDR
:
4662 retval
= sctp_setsockopt_peer_primary_addr(sk
, kopt
, optlen
);
4665 retval
= sctp_setsockopt_nodelay(sk
, kopt
, optlen
);
4668 retval
= sctp_setsockopt_rtoinfo(sk
, kopt
, optlen
);
4670 case SCTP_ASSOCINFO
:
4671 retval
= sctp_setsockopt_associnfo(sk
, kopt
, optlen
);
4673 case SCTP_I_WANT_MAPPED_V4_ADDR
:
4674 retval
= sctp_setsockopt_mappedv4(sk
, kopt
, optlen
);
4677 retval
= sctp_setsockopt_maxseg(sk
, kopt
, optlen
);
4679 case SCTP_ADAPTATION_LAYER
:
4680 retval
= sctp_setsockopt_adaptation_layer(sk
, kopt
, optlen
);
4683 retval
= sctp_setsockopt_context(sk
, kopt
, optlen
);
4685 case SCTP_FRAGMENT_INTERLEAVE
:
4686 retval
= sctp_setsockopt_fragment_interleave(sk
, kopt
, optlen
);
4688 case SCTP_MAX_BURST
:
4689 retval
= sctp_setsockopt_maxburst(sk
, kopt
, optlen
);
4691 case SCTP_AUTH_CHUNK
:
4692 retval
= sctp_setsockopt_auth_chunk(sk
, kopt
, optlen
);
4694 case SCTP_HMAC_IDENT
:
4695 retval
= sctp_setsockopt_hmac_ident(sk
, kopt
, optlen
);
4698 retval
= sctp_setsockopt_auth_key(sk
, kopt
, optlen
);
4700 case SCTP_AUTH_ACTIVE_KEY
:
4701 retval
= sctp_setsockopt_active_key(sk
, kopt
, optlen
);
4703 case SCTP_AUTH_DELETE_KEY
:
4704 retval
= sctp_setsockopt_del_key(sk
, kopt
, optlen
);
4706 case SCTP_AUTH_DEACTIVATE_KEY
:
4707 retval
= sctp_setsockopt_deactivate_key(sk
, kopt
, optlen
);
4709 case SCTP_AUTO_ASCONF
:
4710 retval
= sctp_setsockopt_auto_asconf(sk
, kopt
, optlen
);
4712 case SCTP_PEER_ADDR_THLDS
:
4713 retval
= sctp_setsockopt_paddr_thresholds(sk
, kopt
, optlen
,
4716 case SCTP_PEER_ADDR_THLDS_V2
:
4717 retval
= sctp_setsockopt_paddr_thresholds(sk
, kopt
, optlen
,
4720 case SCTP_RECVRCVINFO
:
4721 retval
= sctp_setsockopt_recvrcvinfo(sk
, kopt
, optlen
);
4723 case SCTP_RECVNXTINFO
:
4724 retval
= sctp_setsockopt_recvnxtinfo(sk
, kopt
, optlen
);
4726 case SCTP_PR_SUPPORTED
:
4727 retval
= sctp_setsockopt_pr_supported(sk
, kopt
, optlen
);
4729 case SCTP_DEFAULT_PRINFO
:
4730 retval
= sctp_setsockopt_default_prinfo(sk
, kopt
, optlen
);
4732 case SCTP_RECONFIG_SUPPORTED
:
4733 retval
= sctp_setsockopt_reconfig_supported(sk
, kopt
, optlen
);
4735 case SCTP_ENABLE_STREAM_RESET
:
4736 retval
= sctp_setsockopt_enable_strreset(sk
, kopt
, optlen
);
4738 case SCTP_RESET_STREAMS
:
4739 retval
= sctp_setsockopt_reset_streams(sk
, kopt
, optlen
);
4741 case SCTP_RESET_ASSOC
:
4742 retval
= sctp_setsockopt_reset_assoc(sk
, kopt
, optlen
);
4744 case SCTP_ADD_STREAMS
:
4745 retval
= sctp_setsockopt_add_streams(sk
, kopt
, optlen
);
4747 case SCTP_STREAM_SCHEDULER
:
4748 retval
= sctp_setsockopt_scheduler(sk
, kopt
, optlen
);
4750 case SCTP_STREAM_SCHEDULER_VALUE
:
4751 retval
= sctp_setsockopt_scheduler_value(sk
, kopt
, optlen
);
4753 case SCTP_INTERLEAVING_SUPPORTED
:
4754 retval
= sctp_setsockopt_interleaving_supported(sk
, kopt
,
4757 case SCTP_REUSE_PORT
:
4758 retval
= sctp_setsockopt_reuse_port(sk
, kopt
, optlen
);
4761 retval
= sctp_setsockopt_event(sk
, kopt
, optlen
);
4763 case SCTP_ASCONF_SUPPORTED
:
4764 retval
= sctp_setsockopt_asconf_supported(sk
, kopt
, optlen
);
4766 case SCTP_AUTH_SUPPORTED
:
4767 retval
= sctp_setsockopt_auth_supported(sk
, kopt
, optlen
);
4769 case SCTP_ECN_SUPPORTED
:
4770 retval
= sctp_setsockopt_ecn_supported(sk
, kopt
, optlen
);
4772 case SCTP_EXPOSE_POTENTIALLY_FAILED_STATE
:
4773 retval
= sctp_setsockopt_pf_expose(sk
, kopt
, optlen
);
4775 case SCTP_REMOTE_UDP_ENCAPS_PORT
:
4776 retval
= sctp_setsockopt_encap_port(sk
, kopt
, optlen
);
4778 case SCTP_PLPMTUD_PROBE_INTERVAL
:
4779 retval
= sctp_setsockopt_probe_interval(sk
, kopt
, optlen
);
4782 retval
= -ENOPROTOOPT
;
4791 /* API 3.1.6 connect() - UDP Style Syntax
4793 * An application may use the connect() call in the UDP model to initiate an
4794 * association without sending data.
4798 * ret = connect(int sd, const struct sockaddr *nam, socklen_t len);
4800 * sd: the socket descriptor to have a new association added to.
4802 * nam: the address structure (either struct sockaddr_in or struct
4803 * sockaddr_in6 defined in RFC2553 [7]).
4805 * len: the size of the address.
4807 static int sctp_connect(struct sock
*sk
, struct sockaddr
*addr
,
4808 int addr_len
, int flags
)
4814 pr_debug("%s: sk:%p, sockaddr:%p, addr_len:%d\n", __func__
, sk
,
4817 /* Validate addr_len before calling common connect/connectx routine. */
4818 af
= sctp_get_af_specific(addr
->sa_family
);
4819 if (af
&& addr_len
>= af
->sockaddr_len
)
4820 err
= __sctp_connect(sk
, addr
, af
->sockaddr_len
, flags
, NULL
);
4826 int sctp_inet_connect(struct socket
*sock
, struct sockaddr
*uaddr
,
4827 int addr_len
, int flags
)
4829 if (addr_len
< sizeof(uaddr
->sa_family
))
4832 if (uaddr
->sa_family
== AF_UNSPEC
)
4835 return sctp_connect(sock
->sk
, uaddr
, addr_len
, flags
);
4838 /* Only called when shutdown a listening SCTP socket. */
4839 static int sctp_disconnect(struct sock
*sk
, int flags
)
4841 if (!sctp_style(sk
, TCP
))
4844 sk
->sk_shutdown
|= RCV_SHUTDOWN
;
4848 /* 4.1.4 accept() - TCP Style Syntax
4850 * Applications use accept() call to remove an established SCTP
4851 * association from the accept queue of the endpoint. A new socket
4852 * descriptor will be returned from accept() to represent the newly
4853 * formed association.
4855 static struct sock
*sctp_accept(struct sock
*sk
, struct proto_accept_arg
*arg
)
4857 struct sctp_sock
*sp
;
4858 struct sctp_endpoint
*ep
;
4859 struct sock
*newsk
= NULL
;
4860 struct sctp_association
*asoc
;
4869 if (!sctp_style(sk
, TCP
)) {
4870 error
= -EOPNOTSUPP
;
4874 if (!sctp_sstate(sk
, LISTENING
) ||
4875 (sk
->sk_shutdown
& RCV_SHUTDOWN
)) {
4880 timeo
= sock_rcvtimeo(sk
, arg
->flags
& O_NONBLOCK
);
4882 error
= sctp_wait_for_accept(sk
, timeo
);
4886 /* We treat the list of associations on the endpoint as the accept
4887 * queue and pick the first association on the list.
4889 asoc
= list_entry(ep
->asocs
.next
, struct sctp_association
, asocs
);
4891 newsk
= sp
->pf
->create_accept_sk(sk
, asoc
, arg
->kern
);
4897 /* Populate the fields of the newsk from the oldsk and migrate the
4898 * asoc to the newsk.
4900 error
= sctp_sock_migrate(sk
, newsk
, asoc
, SCTP_SOCKET_TCP
);
4902 sk_common_release(newsk
);
4912 /* The SCTP ioctl handler. */
4913 static int sctp_ioctl(struct sock
*sk
, int cmd
, int *karg
)
4920 * SEQPACKET-style sockets in LISTENING state are valid, for
4921 * SCTP, so only discard TCP-style sockets in LISTENING state.
4923 if (sctp_style(sk
, TCP
) && sctp_sstate(sk
, LISTENING
))
4928 struct sk_buff
*skb
;
4931 skb
= skb_peek(&sk
->sk_receive_queue
);
4934 * We will only return the amount of this packet since
4935 * that is all that will be read.
4951 /* This is the function which gets called during socket creation to
4952 * initialized the SCTP-specific portion of the sock.
4953 * The sock structure should already be zero-filled memory.
4955 static int sctp_init_sock(struct sock
*sk
)
4957 struct net
*net
= sock_net(sk
);
4958 struct sctp_sock
*sp
;
4960 pr_debug("%s: sk:%p\n", __func__
, sk
);
4964 /* Initialize the SCTP per socket area. */
4965 switch (sk
->sk_type
) {
4966 case SOCK_SEQPACKET
:
4967 sp
->type
= SCTP_SOCKET_UDP
;
4970 sp
->type
= SCTP_SOCKET_TCP
;
4973 return -ESOCKTNOSUPPORT
;
4976 sk
->sk_gso_type
= SKB_GSO_SCTP
;
4978 /* Initialize default send parameters. These parameters can be
4979 * modified with the SCTP_DEFAULT_SEND_PARAM socket option.
4981 sp
->default_stream
= 0;
4982 sp
->default_ppid
= 0;
4983 sp
->default_flags
= 0;
4984 sp
->default_context
= 0;
4985 sp
->default_timetolive
= 0;
4987 sp
->default_rcv_context
= 0;
4988 sp
->max_burst
= net
->sctp
.max_burst
;
4990 sp
->sctp_hmac_alg
= net
->sctp
.sctp_hmac_alg
;
4992 /* Initialize default setup parameters. These parameters
4993 * can be modified with the SCTP_INITMSG socket option or
4994 * overridden by the SCTP_INIT CMSG.
4996 sp
->initmsg
.sinit_num_ostreams
= sctp_max_outstreams
;
4997 sp
->initmsg
.sinit_max_instreams
= sctp_max_instreams
;
4998 sp
->initmsg
.sinit_max_attempts
= net
->sctp
.max_retrans_init
;
4999 sp
->initmsg
.sinit_max_init_timeo
= net
->sctp
.rto_max
;
5001 /* Initialize default RTO related parameters. These parameters can
5002 * be modified for with the SCTP_RTOINFO socket option.
5004 sp
->rtoinfo
.srto_initial
= net
->sctp
.rto_initial
;
5005 sp
->rtoinfo
.srto_max
= net
->sctp
.rto_max
;
5006 sp
->rtoinfo
.srto_min
= net
->sctp
.rto_min
;
5008 /* Initialize default association related parameters. These parameters
5009 * can be modified with the SCTP_ASSOCINFO socket option.
5011 sp
->assocparams
.sasoc_asocmaxrxt
= net
->sctp
.max_retrans_association
;
5012 sp
->assocparams
.sasoc_number_peer_destinations
= 0;
5013 sp
->assocparams
.sasoc_peer_rwnd
= 0;
5014 sp
->assocparams
.sasoc_local_rwnd
= 0;
5015 sp
->assocparams
.sasoc_cookie_life
= net
->sctp
.valid_cookie_life
;
5017 /* Initialize default event subscriptions. By default, all the
5022 /* Default Peer Address Parameters. These defaults can
5023 * be modified via SCTP_PEER_ADDR_PARAMS
5025 sp
->hbinterval
= net
->sctp
.hb_interval
;
5026 sp
->udp_port
= htons(net
->sctp
.udp_port
);
5027 sp
->encap_port
= htons(net
->sctp
.encap_port
);
5028 sp
->pathmaxrxt
= net
->sctp
.max_retrans_path
;
5029 sp
->pf_retrans
= net
->sctp
.pf_retrans
;
5030 sp
->ps_retrans
= net
->sctp
.ps_retrans
;
5031 sp
->pf_expose
= net
->sctp
.pf_expose
;
5032 sp
->pathmtu
= 0; /* allow default discovery */
5033 sp
->sackdelay
= net
->sctp
.sack_timeout
;
5035 sp
->param_flags
= SPP_HB_ENABLE
|
5037 SPP_SACKDELAY_ENABLE
;
5038 sp
->default_ss
= SCTP_SS_DEFAULT
;
5040 /* If enabled no SCTP message fragmentation will be performed.
5041 * Configure through SCTP_DISABLE_FRAGMENTS socket option.
5043 sp
->disable_fragments
= 0;
5045 /* Enable Nagle algorithm by default. */
5048 sp
->recvrcvinfo
= 0;
5049 sp
->recvnxtinfo
= 0;
5051 /* Enable by default. */
5054 /* Auto-close idle associations after the configured
5055 * number of seconds. A value of 0 disables this
5056 * feature. Configure through the SCTP_AUTOCLOSE socket option,
5057 * for UDP-style sockets only.
5061 /* User specified fragmentation limit. */
5064 sp
->adaptation_ind
= 0;
5066 sp
->pf
= sctp_get_pf_specific(sk
->sk_family
);
5068 /* Control variables for partial data delivery. */
5069 atomic_set(&sp
->pd_mode
, 0);
5070 skb_queue_head_init(&sp
->pd_lobby
);
5071 sp
->frag_interleave
= 0;
5072 sp
->probe_interval
= net
->sctp
.probe_interval
;
5074 /* Create a per socket endpoint structure. Even if we
5075 * change the data structure relationships, this may still
5076 * be useful for storing pre-connect address information.
5078 sp
->ep
= sctp_endpoint_new(sk
, GFP_KERNEL
);
5084 sk
->sk_destruct
= sctp_destruct_sock
;
5086 SCTP_DBG_OBJCNT_INC(sock
);
5088 sk_sockets_allocated_inc(sk
);
5089 sock_prot_inuse_add(net
, sk
->sk_prot
, 1);
5094 /* Cleanup any SCTP per socket resources. Must be called with
5095 * sock_net(sk)->sctp.addr_wq_lock held if sp->do_auto_asconf is true
5097 static void sctp_destroy_sock(struct sock
*sk
)
5099 struct sctp_sock
*sp
;
5101 pr_debug("%s: sk:%p\n", __func__
, sk
);
5103 /* Release our hold on the endpoint. */
5105 /* This could happen during socket init, thus we bail out
5106 * early, since the rest of the below is not setup either.
5111 if (sp
->do_auto_asconf
) {
5112 sp
->do_auto_asconf
= 0;
5113 list_del(&sp
->auto_asconf_list
);
5115 sctp_endpoint_free(sp
->ep
);
5116 sk_sockets_allocated_dec(sk
);
5117 sock_prot_inuse_add(sock_net(sk
), sk
->sk_prot
, -1);
5120 /* Triggered when there are no references on the socket anymore */
5121 static void sctp_destruct_common(struct sock
*sk
)
5123 struct sctp_sock
*sp
= sctp_sk(sk
);
5125 /* Free up the HMAC transform. */
5126 crypto_free_shash(sp
->hmac
);
5129 static void sctp_destruct_sock(struct sock
*sk
)
5131 sctp_destruct_common(sk
);
5132 inet_sock_destruct(sk
);
5135 /* API 4.1.7 shutdown() - TCP Style Syntax
5136 * int shutdown(int socket, int how);
5138 * sd - the socket descriptor of the association to be closed.
5139 * how - Specifies the type of shutdown. The values are
5142 * Disables further receive operations. No SCTP
5143 * protocol action is taken.
5145 * Disables further send operations, and initiates
5146 * the SCTP shutdown sequence.
5148 * Disables further send and receive operations
5149 * and initiates the SCTP shutdown sequence.
5151 static void sctp_shutdown(struct sock
*sk
, int how
)
5153 struct net
*net
= sock_net(sk
);
5154 struct sctp_endpoint
*ep
;
5156 if (!sctp_style(sk
, TCP
))
5159 ep
= sctp_sk(sk
)->ep
;
5160 if (how
& SEND_SHUTDOWN
&& !list_empty(&ep
->asocs
)) {
5161 struct sctp_association
*asoc
;
5163 inet_sk_set_state(sk
, SCTP_SS_CLOSING
);
5164 asoc
= list_entry(ep
->asocs
.next
,
5165 struct sctp_association
, asocs
);
5166 sctp_primitive_SHUTDOWN(net
, asoc
, NULL
);
5170 int sctp_get_sctp_info(struct sock
*sk
, struct sctp_association
*asoc
,
5171 struct sctp_info
*info
)
5173 struct sctp_transport
*prim
;
5174 struct list_head
*pos
;
5177 memset(info
, 0, sizeof(*info
));
5179 struct sctp_sock
*sp
= sctp_sk(sk
);
5181 info
->sctpi_s_autoclose
= sp
->autoclose
;
5182 info
->sctpi_s_adaptation_ind
= sp
->adaptation_ind
;
5183 info
->sctpi_s_pd_point
= sp
->pd_point
;
5184 info
->sctpi_s_nodelay
= sp
->nodelay
;
5185 info
->sctpi_s_disable_fragments
= sp
->disable_fragments
;
5186 info
->sctpi_s_v4mapped
= sp
->v4mapped
;
5187 info
->sctpi_s_frag_interleave
= sp
->frag_interleave
;
5188 info
->sctpi_s_type
= sp
->type
;
5193 info
->sctpi_tag
= asoc
->c
.my_vtag
;
5194 info
->sctpi_state
= asoc
->state
;
5195 info
->sctpi_rwnd
= asoc
->a_rwnd
;
5196 info
->sctpi_unackdata
= asoc
->unack_data
;
5197 info
->sctpi_penddata
= sctp_tsnmap_pending(&asoc
->peer
.tsn_map
);
5198 info
->sctpi_instrms
= asoc
->stream
.incnt
;
5199 info
->sctpi_outstrms
= asoc
->stream
.outcnt
;
5200 list_for_each(pos
, &asoc
->base
.inqueue
.in_chunk_list
)
5201 info
->sctpi_inqueue
++;
5202 list_for_each(pos
, &asoc
->outqueue
.out_chunk_list
)
5203 info
->sctpi_outqueue
++;
5204 info
->sctpi_overall_error
= asoc
->overall_error_count
;
5205 info
->sctpi_max_burst
= asoc
->max_burst
;
5206 info
->sctpi_maxseg
= asoc
->frag_point
;
5207 info
->sctpi_peer_rwnd
= asoc
->peer
.rwnd
;
5208 info
->sctpi_peer_tag
= asoc
->c
.peer_vtag
;
5210 mask
= asoc
->peer
.intl_capable
<< 1;
5211 mask
= (mask
| asoc
->peer
.ecn_capable
) << 1;
5212 mask
= (mask
| asoc
->peer
.ipv4_address
) << 1;
5213 mask
= (mask
| asoc
->peer
.ipv6_address
) << 1;
5214 mask
= (mask
| asoc
->peer
.reconf_capable
) << 1;
5215 mask
= (mask
| asoc
->peer
.asconf_capable
) << 1;
5216 mask
= (mask
| asoc
->peer
.prsctp_capable
) << 1;
5217 mask
= (mask
| asoc
->peer
.auth_capable
);
5218 info
->sctpi_peer_capable
= mask
;
5219 mask
= asoc
->peer
.sack_needed
<< 1;
5220 mask
= (mask
| asoc
->peer
.sack_generation
) << 1;
5221 mask
= (mask
| asoc
->peer
.zero_window_announced
);
5222 info
->sctpi_peer_sack
= mask
;
5224 info
->sctpi_isacks
= asoc
->stats
.isacks
;
5225 info
->sctpi_osacks
= asoc
->stats
.osacks
;
5226 info
->sctpi_opackets
= asoc
->stats
.opackets
;
5227 info
->sctpi_ipackets
= asoc
->stats
.ipackets
;
5228 info
->sctpi_rtxchunks
= asoc
->stats
.rtxchunks
;
5229 info
->sctpi_outofseqtsns
= asoc
->stats
.outofseqtsns
;
5230 info
->sctpi_idupchunks
= asoc
->stats
.idupchunks
;
5231 info
->sctpi_gapcnt
= asoc
->stats
.gapcnt
;
5232 info
->sctpi_ouodchunks
= asoc
->stats
.ouodchunks
;
5233 info
->sctpi_iuodchunks
= asoc
->stats
.iuodchunks
;
5234 info
->sctpi_oodchunks
= asoc
->stats
.oodchunks
;
5235 info
->sctpi_iodchunks
= asoc
->stats
.iodchunks
;
5236 info
->sctpi_octrlchunks
= asoc
->stats
.octrlchunks
;
5237 info
->sctpi_ictrlchunks
= asoc
->stats
.ictrlchunks
;
5239 prim
= asoc
->peer
.primary_path
;
5240 memcpy(&info
->sctpi_p_address
, &prim
->ipaddr
, sizeof(prim
->ipaddr
));
5241 info
->sctpi_p_state
= prim
->state
;
5242 info
->sctpi_p_cwnd
= prim
->cwnd
;
5243 info
->sctpi_p_srtt
= prim
->srtt
;
5244 info
->sctpi_p_rto
= jiffies_to_msecs(prim
->rto
);
5245 info
->sctpi_p_hbinterval
= prim
->hbinterval
;
5246 info
->sctpi_p_pathmaxrxt
= prim
->pathmaxrxt
;
5247 info
->sctpi_p_sackdelay
= jiffies_to_msecs(prim
->sackdelay
);
5248 info
->sctpi_p_ssthresh
= prim
->ssthresh
;
5249 info
->sctpi_p_partial_bytes_acked
= prim
->partial_bytes_acked
;
5250 info
->sctpi_p_flight_size
= prim
->flight_size
;
5251 info
->sctpi_p_error
= prim
->error_count
;
5255 EXPORT_SYMBOL_GPL(sctp_get_sctp_info
);
5257 /* use callback to avoid exporting the core structure */
5258 void sctp_transport_walk_start(struct rhashtable_iter
*iter
) __acquires(RCU
)
5260 rhltable_walk_enter(&sctp_transport_hashtable
, iter
);
5262 rhashtable_walk_start(iter
);
5265 void sctp_transport_walk_stop(struct rhashtable_iter
*iter
) __releases(RCU
)
5267 rhashtable_walk_stop(iter
);
5268 rhashtable_walk_exit(iter
);
5271 struct sctp_transport
*sctp_transport_get_next(struct net
*net
,
5272 struct rhashtable_iter
*iter
)
5274 struct sctp_transport
*t
;
5276 t
= rhashtable_walk_next(iter
);
5277 for (; t
; t
= rhashtable_walk_next(iter
)) {
5279 if (PTR_ERR(t
) == -EAGAIN
)
5284 if (!sctp_transport_hold(t
))
5287 if (net_eq(t
->asoc
->base
.net
, net
) &&
5288 t
->asoc
->peer
.primary_path
== t
)
5291 sctp_transport_put(t
);
5297 struct sctp_transport
*sctp_transport_get_idx(struct net
*net
,
5298 struct rhashtable_iter
*iter
,
5301 struct sctp_transport
*t
;
5304 return SEQ_START_TOKEN
;
5306 while ((t
= sctp_transport_get_next(net
, iter
)) && !IS_ERR(t
)) {
5309 sctp_transport_put(t
);
5315 int sctp_for_each_endpoint(int (*cb
)(struct sctp_endpoint
*, void *),
5319 struct sctp_endpoint
*ep
;
5320 struct sctp_hashbucket
*head
;
5322 for (head
= sctp_ep_hashtable
; hash
< sctp_ep_hashsize
;
5324 read_lock_bh(&head
->lock
);
5325 sctp_for_each_hentry(ep
, &head
->chain
) {
5330 read_unlock_bh(&head
->lock
);
5335 EXPORT_SYMBOL_GPL(sctp_for_each_endpoint
);
5337 int sctp_transport_lookup_process(sctp_callback_t cb
, struct net
*net
,
5338 const union sctp_addr
*laddr
,
5339 const union sctp_addr
*paddr
, void *p
, int dif
)
5341 struct sctp_transport
*transport
;
5342 struct sctp_endpoint
*ep
;
5346 transport
= sctp_addrs_lookup_transport(net
, laddr
, paddr
, dif
, dif
);
5351 ep
= transport
->asoc
->ep
;
5352 if (!sctp_endpoint_hold(ep
)) { /* asoc can be peeled off */
5353 sctp_transport_put(transport
);
5359 err
= cb(ep
, transport
, p
);
5360 sctp_endpoint_put(ep
);
5361 sctp_transport_put(transport
);
5364 EXPORT_SYMBOL_GPL(sctp_transport_lookup_process
);
5366 int sctp_transport_traverse_process(sctp_callback_t cb
, sctp_callback_t cb_done
,
5367 struct net
*net
, int *pos
, void *p
)
5369 struct rhashtable_iter hti
;
5370 struct sctp_transport
*tsp
;
5371 struct sctp_endpoint
*ep
;
5376 sctp_transport_walk_start(&hti
);
5378 tsp
= sctp_transport_get_idx(net
, &hti
, *pos
+ 1);
5379 for (; !IS_ERR_OR_NULL(tsp
); tsp
= sctp_transport_get_next(net
, &hti
)) {
5381 if (sctp_endpoint_hold(ep
)) { /* asoc can be peeled off */
5382 ret
= cb(ep
, tsp
, p
);
5385 sctp_endpoint_put(ep
);
5388 sctp_transport_put(tsp
);
5390 sctp_transport_walk_stop(&hti
);
5393 if (cb_done
&& !cb_done(ep
, tsp
, p
)) {
5395 sctp_endpoint_put(ep
);
5396 sctp_transport_put(tsp
);
5399 sctp_endpoint_put(ep
);
5400 sctp_transport_put(tsp
);
5405 EXPORT_SYMBOL_GPL(sctp_transport_traverse_process
);
5407 /* 7.2.1 Association Status (SCTP_STATUS)
5409 * Applications can retrieve current status information about an
5410 * association, including association state, peer receiver window size,
5411 * number of unacked data chunks, and number of data chunks pending
5412 * receipt. This information is read-only.
5414 static int sctp_getsockopt_sctp_status(struct sock
*sk
, int len
,
5415 char __user
*optval
,
5418 struct sctp_status status
;
5419 struct sctp_association
*asoc
= NULL
;
5420 struct sctp_transport
*transport
;
5421 sctp_assoc_t associd
;
5424 if (len
< sizeof(status
)) {
5429 len
= sizeof(status
);
5430 if (copy_from_user(&status
, optval
, len
)) {
5435 associd
= status
.sstat_assoc_id
;
5436 asoc
= sctp_id2assoc(sk
, associd
);
5442 transport
= asoc
->peer
.primary_path
;
5444 status
.sstat_assoc_id
= sctp_assoc2id(asoc
);
5445 status
.sstat_state
= sctp_assoc_to_state(asoc
);
5446 status
.sstat_rwnd
= asoc
->peer
.rwnd
;
5447 status
.sstat_unackdata
= asoc
->unack_data
;
5449 status
.sstat_penddata
= sctp_tsnmap_pending(&asoc
->peer
.tsn_map
);
5450 status
.sstat_instrms
= asoc
->stream
.incnt
;
5451 status
.sstat_outstrms
= asoc
->stream
.outcnt
;
5452 status
.sstat_fragmentation_point
= asoc
->frag_point
;
5453 status
.sstat_primary
.spinfo_assoc_id
= sctp_assoc2id(transport
->asoc
);
5454 memcpy(&status
.sstat_primary
.spinfo_address
, &transport
->ipaddr
,
5455 transport
->af_specific
->sockaddr_len
);
5456 /* Map ipv4 address into v4-mapped-on-v6 address. */
5457 sctp_get_pf_specific(sk
->sk_family
)->addr_to_user(sctp_sk(sk
),
5458 (union sctp_addr
*)&status
.sstat_primary
.spinfo_address
);
5459 status
.sstat_primary
.spinfo_state
= transport
->state
;
5460 status
.sstat_primary
.spinfo_cwnd
= transport
->cwnd
;
5461 status
.sstat_primary
.spinfo_srtt
= transport
->srtt
;
5462 status
.sstat_primary
.spinfo_rto
= jiffies_to_msecs(transport
->rto
);
5463 status
.sstat_primary
.spinfo_mtu
= transport
->pathmtu
;
5465 if (status
.sstat_primary
.spinfo_state
== SCTP_UNKNOWN
)
5466 status
.sstat_primary
.spinfo_state
= SCTP_ACTIVE
;
5468 if (put_user(len
, optlen
)) {
5473 pr_debug("%s: len:%d, state:%d, rwnd:%d, assoc_id:%d\n",
5474 __func__
, len
, status
.sstat_state
, status
.sstat_rwnd
,
5475 status
.sstat_assoc_id
);
5477 if (copy_to_user(optval
, &status
, len
)) {
5487 /* 7.2.2 Peer Address Information (SCTP_GET_PEER_ADDR_INFO)
5489 * Applications can retrieve information about a specific peer address
5490 * of an association, including its reachability state, congestion
5491 * window, and retransmission timer values. This information is
5494 static int sctp_getsockopt_peer_addr_info(struct sock
*sk
, int len
,
5495 char __user
*optval
,
5498 struct sctp_paddrinfo pinfo
;
5499 struct sctp_transport
*transport
;
5502 if (len
< sizeof(pinfo
)) {
5507 len
= sizeof(pinfo
);
5508 if (copy_from_user(&pinfo
, optval
, len
)) {
5513 transport
= sctp_addr_id2transport(sk
, &pinfo
.spinfo_address
,
5514 pinfo
.spinfo_assoc_id
);
5520 if (transport
->state
== SCTP_PF
&&
5521 transport
->asoc
->pf_expose
== SCTP_PF_EXPOSE_DISABLE
) {
5526 pinfo
.spinfo_assoc_id
= sctp_assoc2id(transport
->asoc
);
5527 pinfo
.spinfo_state
= transport
->state
;
5528 pinfo
.spinfo_cwnd
= transport
->cwnd
;
5529 pinfo
.spinfo_srtt
= transport
->srtt
;
5530 pinfo
.spinfo_rto
= jiffies_to_msecs(transport
->rto
);
5531 pinfo
.spinfo_mtu
= transport
->pathmtu
;
5533 if (pinfo
.spinfo_state
== SCTP_UNKNOWN
)
5534 pinfo
.spinfo_state
= SCTP_ACTIVE
;
5536 if (put_user(len
, optlen
)) {
5541 if (copy_to_user(optval
, &pinfo
, len
)) {
5550 /* 7.1.12 Enable/Disable message fragmentation (SCTP_DISABLE_FRAGMENTS)
5552 * This option is a on/off flag. If enabled no SCTP message
5553 * fragmentation will be performed. Instead if a message being sent
5554 * exceeds the current PMTU size, the message will NOT be sent and
5555 * instead a error will be indicated to the user.
5557 static int sctp_getsockopt_disable_fragments(struct sock
*sk
, int len
,
5558 char __user
*optval
, int __user
*optlen
)
5562 if (len
< sizeof(int))
5566 val
= (sctp_sk(sk
)->disable_fragments
== 1);
5567 if (put_user(len
, optlen
))
5569 if (copy_to_user(optval
, &val
, len
))
5574 /* 7.1.15 Set notification and ancillary events (SCTP_EVENTS)
5576 * This socket option is used to specify various notifications and
5577 * ancillary data the user wishes to receive.
5579 static int sctp_getsockopt_events(struct sock
*sk
, int len
, char __user
*optval
,
5582 struct sctp_event_subscribe subscribe
;
5583 __u8
*sn_type
= (__u8
*)&subscribe
;
5588 if (len
> sizeof(struct sctp_event_subscribe
))
5589 len
= sizeof(struct sctp_event_subscribe
);
5590 if (put_user(len
, optlen
))
5593 for (i
= 0; i
< len
; i
++)
5594 sn_type
[i
] = sctp_ulpevent_type_enabled(sctp_sk(sk
)->subscribe
,
5595 SCTP_SN_TYPE_BASE
+ i
);
5597 if (copy_to_user(optval
, &subscribe
, len
))
5603 /* 7.1.8 Automatic Close of associations (SCTP_AUTOCLOSE)
5605 * This socket option is applicable to the UDP-style socket only. When
5606 * set it will cause associations that are idle for more than the
5607 * specified number of seconds to automatically close. An association
5608 * being idle is defined an association that has NOT sent or received
5609 * user data. The special value of '0' indicates that no automatic
5610 * close of any associations should be performed. The option expects an
5611 * integer defining the number of seconds of idle time before an
5612 * association is closed.
5614 static int sctp_getsockopt_autoclose(struct sock
*sk
, int len
, char __user
*optval
, int __user
*optlen
)
5616 /* Applicable to UDP-style socket only */
5617 if (sctp_style(sk
, TCP
))
5619 if (len
< sizeof(int))
5622 if (put_user(len
, optlen
))
5624 if (put_user(sctp_sk(sk
)->autoclose
, (int __user
*)optval
))
5629 /* Helper routine to branch off an association to a new socket. */
5630 static int sctp_do_peeloff(struct sock
*sk
, sctp_assoc_t id
,
5631 struct socket
**sockp
)
5633 struct sctp_association
*asoc
= sctp_id2assoc(sk
, id
);
5634 struct sctp_sock
*sp
= sctp_sk(sk
);
5635 struct socket
*sock
;
5638 /* Do not peel off from one netns to another one. */
5639 if (!net_eq(current
->nsproxy
->net_ns
, sock_net(sk
)))
5645 /* An association cannot be branched off from an already peeled-off
5646 * socket, nor is this supported for tcp style sockets.
5648 if (!sctp_style(sk
, UDP
))
5651 /* Create a new socket. */
5652 err
= sock_create(sk
->sk_family
, SOCK_SEQPACKET
, IPPROTO_SCTP
, &sock
);
5656 sctp_copy_sock(sock
->sk
, sk
, asoc
);
5658 /* Make peeled-off sockets more like 1-1 accepted sockets.
5659 * Set the daddr and initialize id to something more random and also
5660 * copy over any ip options.
5662 sp
->pf
->to_sk_daddr(&asoc
->peer
.primary_addr
, sock
->sk
);
5663 sp
->pf
->copy_ip_options(sk
, sock
->sk
);
5665 /* Populate the fields of the newsk from the oldsk and migrate the
5666 * asoc to the newsk.
5668 err
= sctp_sock_migrate(sk
, sock
->sk
, asoc
,
5669 SCTP_SOCKET_UDP_HIGH_BANDWIDTH
);
5680 static int sctp_getsockopt_peeloff_common(struct sock
*sk
, sctp_peeloff_arg_t
*peeloff
,
5681 struct file
**newfile
, unsigned flags
)
5683 struct socket
*newsock
;
5686 retval
= sctp_do_peeloff(sk
, peeloff
->associd
, &newsock
);
5690 /* Map the socket to an unused fd that can be returned to the user. */
5691 retval
= get_unused_fd_flags(flags
& SOCK_CLOEXEC
);
5693 sock_release(newsock
);
5697 *newfile
= sock_alloc_file(newsock
, 0, NULL
);
5698 if (IS_ERR(*newfile
)) {
5699 put_unused_fd(retval
);
5700 retval
= PTR_ERR(*newfile
);
5705 pr_debug("%s: sk:%p, newsk:%p, sd:%d\n", __func__
, sk
, newsock
->sk
,
5708 peeloff
->sd
= retval
;
5710 if (flags
& SOCK_NONBLOCK
)
5711 (*newfile
)->f_flags
|= O_NONBLOCK
;
5716 static int sctp_getsockopt_peeloff(struct sock
*sk
, int len
, char __user
*optval
, int __user
*optlen
)
5718 sctp_peeloff_arg_t peeloff
;
5719 struct file
*newfile
= NULL
;
5722 if (len
< sizeof(sctp_peeloff_arg_t
))
5724 len
= sizeof(sctp_peeloff_arg_t
);
5725 if (copy_from_user(&peeloff
, optval
, len
))
5728 retval
= sctp_getsockopt_peeloff_common(sk
, &peeloff
, &newfile
, 0);
5732 /* Return the fd mapped to the new socket. */
5733 if (put_user(len
, optlen
)) {
5735 put_unused_fd(retval
);
5739 if (copy_to_user(optval
, &peeloff
, len
)) {
5741 put_unused_fd(retval
);
5744 fd_install(retval
, newfile
);
5749 static int sctp_getsockopt_peeloff_flags(struct sock
*sk
, int len
,
5750 char __user
*optval
, int __user
*optlen
)
5752 sctp_peeloff_flags_arg_t peeloff
;
5753 struct file
*newfile
= NULL
;
5756 if (len
< sizeof(sctp_peeloff_flags_arg_t
))
5758 len
= sizeof(sctp_peeloff_flags_arg_t
);
5759 if (copy_from_user(&peeloff
, optval
, len
))
5762 retval
= sctp_getsockopt_peeloff_common(sk
, &peeloff
.p_arg
,
5763 &newfile
, peeloff
.flags
);
5767 /* Return the fd mapped to the new socket. */
5768 if (put_user(len
, optlen
)) {
5770 put_unused_fd(retval
);
5774 if (copy_to_user(optval
, &peeloff
, len
)) {
5776 put_unused_fd(retval
);
5779 fd_install(retval
, newfile
);
5784 /* 7.1.13 Peer Address Parameters (SCTP_PEER_ADDR_PARAMS)
5786 * Applications can enable or disable heartbeats for any peer address of
5787 * an association, modify an address's heartbeat interval, force a
5788 * heartbeat to be sent immediately, and adjust the address's maximum
5789 * number of retransmissions sent before an address is considered
5790 * unreachable. The following structure is used to access and modify an
5791 * address's parameters:
5793 * struct sctp_paddrparams {
5794 * sctp_assoc_t spp_assoc_id;
5795 * struct sockaddr_storage spp_address;
5796 * uint32_t spp_hbinterval;
5797 * uint16_t spp_pathmaxrxt;
5798 * uint32_t spp_pathmtu;
5799 * uint32_t spp_sackdelay;
5800 * uint32_t spp_flags;
5803 * spp_assoc_id - (one-to-many style socket) This is filled in the
5804 * application, and identifies the association for
5806 * spp_address - This specifies which address is of interest.
5807 * spp_hbinterval - This contains the value of the heartbeat interval,
5808 * in milliseconds. If a value of zero
5809 * is present in this field then no changes are to
5810 * be made to this parameter.
5811 * spp_pathmaxrxt - This contains the maximum number of
5812 * retransmissions before this address shall be
5813 * considered unreachable. If a value of zero
5814 * is present in this field then no changes are to
5815 * be made to this parameter.
5816 * spp_pathmtu - When Path MTU discovery is disabled the value
5817 * specified here will be the "fixed" path mtu.
5818 * Note that if the spp_address field is empty
5819 * then all associations on this address will
5820 * have this fixed path mtu set upon them.
5822 * spp_sackdelay - When delayed sack is enabled, this value specifies
5823 * the number of milliseconds that sacks will be delayed
5824 * for. This value will apply to all addresses of an
5825 * association if the spp_address field is empty. Note
5826 * also, that if delayed sack is enabled and this
5827 * value is set to 0, no change is made to the last
5828 * recorded delayed sack timer value.
5830 * spp_flags - These flags are used to control various features
5831 * on an association. The flag field may contain
5832 * zero or more of the following options.
5834 * SPP_HB_ENABLE - Enable heartbeats on the
5835 * specified address. Note that if the address
5836 * field is empty all addresses for the association
5837 * have heartbeats enabled upon them.
5839 * SPP_HB_DISABLE - Disable heartbeats on the
5840 * speicifed address. Note that if the address
5841 * field is empty all addresses for the association
5842 * will have their heartbeats disabled. Note also
5843 * that SPP_HB_ENABLE and SPP_HB_DISABLE are
5844 * mutually exclusive, only one of these two should
5845 * be specified. Enabling both fields will have
5846 * undetermined results.
5848 * SPP_HB_DEMAND - Request a user initiated heartbeat
5849 * to be made immediately.
5851 * SPP_PMTUD_ENABLE - This field will enable PMTU
5852 * discovery upon the specified address. Note that
5853 * if the address feild is empty then all addresses
5854 * on the association are effected.
5856 * SPP_PMTUD_DISABLE - This field will disable PMTU
5857 * discovery upon the specified address. Note that
5858 * if the address feild is empty then all addresses
5859 * on the association are effected. Not also that
5860 * SPP_PMTUD_ENABLE and SPP_PMTUD_DISABLE are mutually
5861 * exclusive. Enabling both will have undetermined
5864 * SPP_SACKDELAY_ENABLE - Setting this flag turns
5865 * on delayed sack. The time specified in spp_sackdelay
5866 * is used to specify the sack delay for this address. Note
5867 * that if spp_address is empty then all addresses will
5868 * enable delayed sack and take on the sack delay
5869 * value specified in spp_sackdelay.
5870 * SPP_SACKDELAY_DISABLE - Setting this flag turns
5871 * off delayed sack. If the spp_address field is blank then
5872 * delayed sack is disabled for the entire association. Note
5873 * also that this field is mutually exclusive to
5874 * SPP_SACKDELAY_ENABLE, setting both will have undefined
5877 * SPP_IPV6_FLOWLABEL: Setting this flag enables the
5878 * setting of the IPV6 flow label value. The value is
5879 * contained in the spp_ipv6_flowlabel field.
5880 * Upon retrieval, this flag will be set to indicate that
5881 * the spp_ipv6_flowlabel field has a valid value returned.
5882 * If a specific destination address is set (in the
5883 * spp_address field), then the value returned is that of
5884 * the address. If just an association is specified (and
5885 * no address), then the association's default flow label
5886 * is returned. If neither an association nor a destination
5887 * is specified, then the socket's default flow label is
5888 * returned. For non-IPv6 sockets, this flag will be left
5891 * SPP_DSCP: Setting this flag enables the setting of the
5892 * Differentiated Services Code Point (DSCP) value
5893 * associated with either the association or a specific
5894 * address. The value is obtained in the spp_dscp field.
5895 * Upon retrieval, this flag will be set to indicate that
5896 * the spp_dscp field has a valid value returned. If a
5897 * specific destination address is set when called (in the
5898 * spp_address field), then that specific destination
5899 * address's DSCP value is returned. If just an association
5900 * is specified, then the association's default DSCP is
5901 * returned. If neither an association nor a destination is
5902 * specified, then the socket's default DSCP is returned.
5904 * spp_ipv6_flowlabel
5905 * - This field is used in conjunction with the
5906 * SPP_IPV6_FLOWLABEL flag and contains the IPv6 flow label.
5907 * The 20 least significant bits are used for the flow
5908 * label. This setting has precedence over any IPv6-layer
5911 * spp_dscp - This field is used in conjunction with the SPP_DSCP flag
5912 * and contains the DSCP. The 6 most significant bits are
5913 * used for the DSCP. This setting has precedence over any
5914 * IPv4- or IPv6- layer setting.
5916 static int sctp_getsockopt_peer_addr_params(struct sock
*sk
, int len
,
5917 char __user
*optval
, int __user
*optlen
)
5919 struct sctp_paddrparams params
;
5920 struct sctp_transport
*trans
= NULL
;
5921 struct sctp_association
*asoc
= NULL
;
5922 struct sctp_sock
*sp
= sctp_sk(sk
);
5924 if (len
>= sizeof(params
))
5925 len
= sizeof(params
);
5926 else if (len
>= ALIGN(offsetof(struct sctp_paddrparams
,
5927 spp_ipv6_flowlabel
), 4))
5928 len
= ALIGN(offsetof(struct sctp_paddrparams
,
5929 spp_ipv6_flowlabel
), 4);
5933 if (copy_from_user(¶ms
, optval
, len
))
5936 /* If an address other than INADDR_ANY is specified, and
5937 * no transport is found, then the request is invalid.
5939 if (!sctp_is_any(sk
, (union sctp_addr
*)¶ms
.spp_address
)) {
5940 trans
= sctp_addr_id2transport(sk
, ¶ms
.spp_address
,
5941 params
.spp_assoc_id
);
5943 pr_debug("%s: failed no transport\n", __func__
);
5948 /* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the
5949 * socket is a one to many style socket, and an association
5950 * was not found, then the id was invalid.
5952 asoc
= sctp_id2assoc(sk
, params
.spp_assoc_id
);
5953 if (!asoc
&& params
.spp_assoc_id
!= SCTP_FUTURE_ASSOC
&&
5954 sctp_style(sk
, UDP
)) {
5955 pr_debug("%s: failed no association\n", __func__
);
5960 /* Fetch transport values. */
5961 params
.spp_hbinterval
= jiffies_to_msecs(trans
->hbinterval
);
5962 params
.spp_pathmtu
= trans
->pathmtu
;
5963 params
.spp_pathmaxrxt
= trans
->pathmaxrxt
;
5964 params
.spp_sackdelay
= jiffies_to_msecs(trans
->sackdelay
);
5966 /*draft-11 doesn't say what to return in spp_flags*/
5967 params
.spp_flags
= trans
->param_flags
;
5968 if (trans
->flowlabel
& SCTP_FLOWLABEL_SET_MASK
) {
5969 params
.spp_ipv6_flowlabel
= trans
->flowlabel
&
5970 SCTP_FLOWLABEL_VAL_MASK
;
5971 params
.spp_flags
|= SPP_IPV6_FLOWLABEL
;
5973 if (trans
->dscp
& SCTP_DSCP_SET_MASK
) {
5974 params
.spp_dscp
= trans
->dscp
& SCTP_DSCP_VAL_MASK
;
5975 params
.spp_flags
|= SPP_DSCP
;
5978 /* Fetch association values. */
5979 params
.spp_hbinterval
= jiffies_to_msecs(asoc
->hbinterval
);
5980 params
.spp_pathmtu
= asoc
->pathmtu
;
5981 params
.spp_pathmaxrxt
= asoc
->pathmaxrxt
;
5982 params
.spp_sackdelay
= jiffies_to_msecs(asoc
->sackdelay
);
5984 /*draft-11 doesn't say what to return in spp_flags*/
5985 params
.spp_flags
= asoc
->param_flags
;
5986 if (asoc
->flowlabel
& SCTP_FLOWLABEL_SET_MASK
) {
5987 params
.spp_ipv6_flowlabel
= asoc
->flowlabel
&
5988 SCTP_FLOWLABEL_VAL_MASK
;
5989 params
.spp_flags
|= SPP_IPV6_FLOWLABEL
;
5991 if (asoc
->dscp
& SCTP_DSCP_SET_MASK
) {
5992 params
.spp_dscp
= asoc
->dscp
& SCTP_DSCP_VAL_MASK
;
5993 params
.spp_flags
|= SPP_DSCP
;
5996 /* Fetch socket values. */
5997 params
.spp_hbinterval
= sp
->hbinterval
;
5998 params
.spp_pathmtu
= sp
->pathmtu
;
5999 params
.spp_sackdelay
= sp
->sackdelay
;
6000 params
.spp_pathmaxrxt
= sp
->pathmaxrxt
;
6002 /*draft-11 doesn't say what to return in spp_flags*/
6003 params
.spp_flags
= sp
->param_flags
;
6004 if (sp
->flowlabel
& SCTP_FLOWLABEL_SET_MASK
) {
6005 params
.spp_ipv6_flowlabel
= sp
->flowlabel
&
6006 SCTP_FLOWLABEL_VAL_MASK
;
6007 params
.spp_flags
|= SPP_IPV6_FLOWLABEL
;
6009 if (sp
->dscp
& SCTP_DSCP_SET_MASK
) {
6010 params
.spp_dscp
= sp
->dscp
& SCTP_DSCP_VAL_MASK
;
6011 params
.spp_flags
|= SPP_DSCP
;
6015 if (copy_to_user(optval
, ¶ms
, len
))
6018 if (put_user(len
, optlen
))
6025 * 7.1.23. Get or set delayed ack timer (SCTP_DELAYED_SACK)
6027 * This option will effect the way delayed acks are performed. This
6028 * option allows you to get or set the delayed ack time, in
6029 * milliseconds. It also allows changing the delayed ack frequency.
6030 * Changing the frequency to 1 disables the delayed sack algorithm. If
6031 * the assoc_id is 0, then this sets or gets the endpoints default
6032 * values. If the assoc_id field is non-zero, then the set or get
6033 * effects the specified association for the one to many model (the
6034 * assoc_id field is ignored by the one to one model). Note that if
6035 * sack_delay or sack_freq are 0 when setting this option, then the
6036 * current values will remain unchanged.
6038 * struct sctp_sack_info {
6039 * sctp_assoc_t sack_assoc_id;
6040 * uint32_t sack_delay;
6041 * uint32_t sack_freq;
6044 * sack_assoc_id - This parameter, indicates which association the user
6045 * is performing an action upon. Note that if this field's value is
6046 * zero then the endpoints default value is changed (effecting future
6047 * associations only).
6049 * sack_delay - This parameter contains the number of milliseconds that
6050 * the user is requesting the delayed ACK timer be set to. Note that
6051 * this value is defined in the standard to be between 200 and 500
6054 * sack_freq - This parameter contains the number of packets that must
6055 * be received before a sack is sent without waiting for the delay
6056 * timer to expire. The default value for this is 2, setting this
6057 * value to 1 will disable the delayed sack algorithm.
6059 static int sctp_getsockopt_delayed_ack(struct sock
*sk
, int len
,
6060 char __user
*optval
,
6063 struct sctp_sack_info params
;
6064 struct sctp_association
*asoc
= NULL
;
6065 struct sctp_sock
*sp
= sctp_sk(sk
);
6067 if (len
>= sizeof(struct sctp_sack_info
)) {
6068 len
= sizeof(struct sctp_sack_info
);
6070 if (copy_from_user(¶ms
, optval
, len
))
6072 } else if (len
== sizeof(struct sctp_assoc_value
)) {
6073 pr_warn_ratelimited(DEPRECATED
6075 "Use of struct sctp_assoc_value in delayed_ack socket option.\n"
6076 "Use struct sctp_sack_info instead\n",
6077 current
->comm
, task_pid_nr(current
));
6078 if (copy_from_user(¶ms
, optval
, len
))
6083 /* Get association, if sack_assoc_id != SCTP_FUTURE_ASSOC and the
6084 * socket is a one to many style socket, and an association
6085 * was not found, then the id was invalid.
6087 asoc
= sctp_id2assoc(sk
, params
.sack_assoc_id
);
6088 if (!asoc
&& params
.sack_assoc_id
!= SCTP_FUTURE_ASSOC
&&
6089 sctp_style(sk
, UDP
))
6093 /* Fetch association values. */
6094 if (asoc
->param_flags
& SPP_SACKDELAY_ENABLE
) {
6095 params
.sack_delay
= jiffies_to_msecs(asoc
->sackdelay
);
6096 params
.sack_freq
= asoc
->sackfreq
;
6099 params
.sack_delay
= 0;
6100 params
.sack_freq
= 1;
6103 /* Fetch socket values. */
6104 if (sp
->param_flags
& SPP_SACKDELAY_ENABLE
) {
6105 params
.sack_delay
= sp
->sackdelay
;
6106 params
.sack_freq
= sp
->sackfreq
;
6108 params
.sack_delay
= 0;
6109 params
.sack_freq
= 1;
6113 if (copy_to_user(optval
, ¶ms
, len
))
6116 if (put_user(len
, optlen
))
6122 /* 7.1.3 Initialization Parameters (SCTP_INITMSG)
6124 * Applications can specify protocol parameters for the default association
6125 * initialization. The option name argument to setsockopt() and getsockopt()
6128 * Setting initialization parameters is effective only on an unconnected
6129 * socket (for UDP-style sockets only future associations are effected
6130 * by the change). With TCP-style sockets, this option is inherited by
6131 * sockets derived from a listener socket.
6133 static int sctp_getsockopt_initmsg(struct sock
*sk
, int len
, char __user
*optval
, int __user
*optlen
)
6135 if (len
< sizeof(struct sctp_initmsg
))
6137 len
= sizeof(struct sctp_initmsg
);
6138 if (put_user(len
, optlen
))
6140 if (copy_to_user(optval
, &sctp_sk(sk
)->initmsg
, len
))
6146 static int sctp_getsockopt_peer_addrs(struct sock
*sk
, int len
,
6147 char __user
*optval
, int __user
*optlen
)
6149 struct sctp_association
*asoc
;
6151 struct sctp_getaddrs getaddrs
;
6152 struct sctp_transport
*from
;
6154 union sctp_addr temp
;
6155 struct sctp_sock
*sp
= sctp_sk(sk
);
6160 if (len
< sizeof(struct sctp_getaddrs
))
6163 if (copy_from_user(&getaddrs
, optval
, sizeof(struct sctp_getaddrs
)))
6166 /* For UDP-style sockets, id specifies the association to query. */
6167 asoc
= sctp_id2assoc(sk
, getaddrs
.assoc_id
);
6171 to
= optval
+ offsetof(struct sctp_getaddrs
, addrs
);
6172 space_left
= len
- offsetof(struct sctp_getaddrs
, addrs
);
6174 list_for_each_entry(from
, &asoc
->peer
.transport_addr_list
,
6176 memcpy(&temp
, &from
->ipaddr
, sizeof(temp
));
6177 addrlen
= sctp_get_pf_specific(sk
->sk_family
)
6178 ->addr_to_user(sp
, &temp
);
6179 if (space_left
< addrlen
)
6181 if (copy_to_user(to
, &temp
, addrlen
))
6185 space_left
-= addrlen
;
6188 if (put_user(cnt
, &((struct sctp_getaddrs __user
*)optval
)->addr_num
))
6190 bytes_copied
= ((char __user
*)to
) - optval
;
6191 if (put_user(bytes_copied
, optlen
))
6197 static int sctp_copy_laddrs(struct sock
*sk
, __u16 port
, void *to
,
6198 size_t space_left
, int *bytes_copied
)
6200 struct sctp_sockaddr_entry
*addr
;
6201 union sctp_addr temp
;
6204 struct net
*net
= sock_net(sk
);
6207 list_for_each_entry_rcu(addr
, &net
->sctp
.local_addr_list
, list
) {
6211 if ((PF_INET
== sk
->sk_family
) &&
6212 (AF_INET6
== addr
->a
.sa
.sa_family
))
6214 if ((PF_INET6
== sk
->sk_family
) &&
6215 inet_v6_ipv6only(sk
) &&
6216 (AF_INET
== addr
->a
.sa
.sa_family
))
6218 memcpy(&temp
, &addr
->a
, sizeof(temp
));
6219 if (!temp
.v4
.sin_port
)
6220 temp
.v4
.sin_port
= htons(port
);
6222 addrlen
= sctp_get_pf_specific(sk
->sk_family
)
6223 ->addr_to_user(sctp_sk(sk
), &temp
);
6225 if (space_left
< addrlen
) {
6229 memcpy(to
, &temp
, addrlen
);
6233 space_left
-= addrlen
;
6234 *bytes_copied
+= addrlen
;
6242 static int sctp_getsockopt_local_addrs(struct sock
*sk
, int len
,
6243 char __user
*optval
, int __user
*optlen
)
6245 struct sctp_bind_addr
*bp
;
6246 struct sctp_association
*asoc
;
6248 struct sctp_getaddrs getaddrs
;
6249 struct sctp_sockaddr_entry
*addr
;
6251 union sctp_addr temp
;
6252 struct sctp_sock
*sp
= sctp_sk(sk
);
6256 int bytes_copied
= 0;
6260 if (len
< sizeof(struct sctp_getaddrs
))
6263 if (copy_from_user(&getaddrs
, optval
, sizeof(struct sctp_getaddrs
)))
6267 * For UDP-style sockets, id specifies the association to query.
6268 * If the id field is set to the value '0' then the locally bound
6269 * addresses are returned without regard to any particular
6272 if (0 == getaddrs
.assoc_id
) {
6273 bp
= &sctp_sk(sk
)->ep
->base
.bind_addr
;
6275 asoc
= sctp_id2assoc(sk
, getaddrs
.assoc_id
);
6278 bp
= &asoc
->base
.bind_addr
;
6281 to
= optval
+ offsetof(struct sctp_getaddrs
, addrs
);
6282 space_left
= len
- offsetof(struct sctp_getaddrs
, addrs
);
6284 addrs
= kmalloc(space_left
, GFP_USER
| __GFP_NOWARN
);
6288 /* If the endpoint is bound to 0.0.0.0 or ::0, get the valid
6289 * addresses from the global local address list.
6291 if (sctp_list_single_entry(&bp
->address_list
)) {
6292 addr
= list_entry(bp
->address_list
.next
,
6293 struct sctp_sockaddr_entry
, list
);
6294 if (sctp_is_any(sk
, &addr
->a
)) {
6295 cnt
= sctp_copy_laddrs(sk
, bp
->port
, addrs
,
6296 space_left
, &bytes_copied
);
6306 /* Protection on the bound address list is not needed since
6307 * in the socket option context we hold a socket lock and
6308 * thus the bound address list can't change.
6310 list_for_each_entry(addr
, &bp
->address_list
, list
) {
6311 memcpy(&temp
, &addr
->a
, sizeof(temp
));
6312 addrlen
= sctp_get_pf_specific(sk
->sk_family
)
6313 ->addr_to_user(sp
, &temp
);
6314 if (space_left
< addrlen
) {
6315 err
= -ENOMEM
; /*fixme: right error?*/
6318 memcpy(buf
, &temp
, addrlen
);
6320 bytes_copied
+= addrlen
;
6322 space_left
-= addrlen
;
6326 if (copy_to_user(to
, addrs
, bytes_copied
)) {
6330 if (put_user(cnt
, &((struct sctp_getaddrs __user
*)optval
)->addr_num
)) {
6334 /* XXX: We should have accounted for sizeof(struct sctp_getaddrs) too,
6335 * but we can't change it anymore.
6337 if (put_user(bytes_copied
, optlen
))
6344 /* 7.1.10 Set Primary Address (SCTP_PRIMARY_ADDR)
6346 * Requests that the local SCTP stack use the enclosed peer address as
6347 * the association primary. The enclosed address must be one of the
6348 * association peer's addresses.
6350 static int sctp_getsockopt_primary_addr(struct sock
*sk
, int len
,
6351 char __user
*optval
, int __user
*optlen
)
6353 struct sctp_prim prim
;
6354 struct sctp_association
*asoc
;
6355 struct sctp_sock
*sp
= sctp_sk(sk
);
6357 if (len
< sizeof(struct sctp_prim
))
6360 len
= sizeof(struct sctp_prim
);
6362 if (copy_from_user(&prim
, optval
, len
))
6365 asoc
= sctp_id2assoc(sk
, prim
.ssp_assoc_id
);
6369 if (!asoc
->peer
.primary_path
)
6372 memcpy(&prim
.ssp_addr
, &asoc
->peer
.primary_path
->ipaddr
,
6373 asoc
->peer
.primary_path
->af_specific
->sockaddr_len
);
6375 sctp_get_pf_specific(sk
->sk_family
)->addr_to_user(sp
,
6376 (union sctp_addr
*)&prim
.ssp_addr
);
6378 if (put_user(len
, optlen
))
6380 if (copy_to_user(optval
, &prim
, len
))
6387 * 7.1.11 Set Adaptation Layer Indicator (SCTP_ADAPTATION_LAYER)
6389 * Requests that the local endpoint set the specified Adaptation Layer
6390 * Indication parameter for all future INIT and INIT-ACK exchanges.
6392 static int sctp_getsockopt_adaptation_layer(struct sock
*sk
, int len
,
6393 char __user
*optval
, int __user
*optlen
)
6395 struct sctp_setadaptation adaptation
;
6397 if (len
< sizeof(struct sctp_setadaptation
))
6400 len
= sizeof(struct sctp_setadaptation
);
6402 adaptation
.ssb_adaptation_ind
= sctp_sk(sk
)->adaptation_ind
;
6404 if (put_user(len
, optlen
))
6406 if (copy_to_user(optval
, &adaptation
, len
))
6414 * 7.1.14 Set default send parameters (SCTP_DEFAULT_SEND_PARAM)
6416 * Applications that wish to use the sendto() system call may wish to
6417 * specify a default set of parameters that would normally be supplied
6418 * through the inclusion of ancillary data. This socket option allows
6419 * such an application to set the default sctp_sndrcvinfo structure.
6422 * The application that wishes to use this socket option simply passes
6423 * in to this call the sctp_sndrcvinfo structure defined in Section
6424 * 5.2.2) The input parameters accepted by this call include
6425 * sinfo_stream, sinfo_flags, sinfo_ppid, sinfo_context,
6426 * sinfo_timetolive. The user must provide the sinfo_assoc_id field in
6427 * to this call if the caller is using the UDP model.
6429 * For getsockopt, it get the default sctp_sndrcvinfo structure.
6431 static int sctp_getsockopt_default_send_param(struct sock
*sk
,
6432 int len
, char __user
*optval
,
6435 struct sctp_sock
*sp
= sctp_sk(sk
);
6436 struct sctp_association
*asoc
;
6437 struct sctp_sndrcvinfo info
;
6439 if (len
< sizeof(info
))
6444 if (copy_from_user(&info
, optval
, len
))
6447 asoc
= sctp_id2assoc(sk
, info
.sinfo_assoc_id
);
6448 if (!asoc
&& info
.sinfo_assoc_id
!= SCTP_FUTURE_ASSOC
&&
6449 sctp_style(sk
, UDP
))
6453 info
.sinfo_stream
= asoc
->default_stream
;
6454 info
.sinfo_flags
= asoc
->default_flags
;
6455 info
.sinfo_ppid
= asoc
->default_ppid
;
6456 info
.sinfo_context
= asoc
->default_context
;
6457 info
.sinfo_timetolive
= asoc
->default_timetolive
;
6459 info
.sinfo_stream
= sp
->default_stream
;
6460 info
.sinfo_flags
= sp
->default_flags
;
6461 info
.sinfo_ppid
= sp
->default_ppid
;
6462 info
.sinfo_context
= sp
->default_context
;
6463 info
.sinfo_timetolive
= sp
->default_timetolive
;
6466 if (put_user(len
, optlen
))
6468 if (copy_to_user(optval
, &info
, len
))
6474 /* RFC6458, Section 8.1.31. Set/get Default Send Parameters
6475 * (SCTP_DEFAULT_SNDINFO)
6477 static int sctp_getsockopt_default_sndinfo(struct sock
*sk
, int len
,
6478 char __user
*optval
,
6481 struct sctp_sock
*sp
= sctp_sk(sk
);
6482 struct sctp_association
*asoc
;
6483 struct sctp_sndinfo info
;
6485 if (len
< sizeof(info
))
6490 if (copy_from_user(&info
, optval
, len
))
6493 asoc
= sctp_id2assoc(sk
, info
.snd_assoc_id
);
6494 if (!asoc
&& info
.snd_assoc_id
!= SCTP_FUTURE_ASSOC
&&
6495 sctp_style(sk
, UDP
))
6499 info
.snd_sid
= asoc
->default_stream
;
6500 info
.snd_flags
= asoc
->default_flags
;
6501 info
.snd_ppid
= asoc
->default_ppid
;
6502 info
.snd_context
= asoc
->default_context
;
6504 info
.snd_sid
= sp
->default_stream
;
6505 info
.snd_flags
= sp
->default_flags
;
6506 info
.snd_ppid
= sp
->default_ppid
;
6507 info
.snd_context
= sp
->default_context
;
6510 if (put_user(len
, optlen
))
6512 if (copy_to_user(optval
, &info
, len
))
6520 * 7.1.5 SCTP_NODELAY
6522 * Turn on/off any Nagle-like algorithm. This means that packets are
6523 * generally sent as soon as possible and no unnecessary delays are
6524 * introduced, at the cost of more packets in the network. Expects an
6525 * integer boolean flag.
6528 static int sctp_getsockopt_nodelay(struct sock
*sk
, int len
,
6529 char __user
*optval
, int __user
*optlen
)
6533 if (len
< sizeof(int))
6537 val
= (sctp_sk(sk
)->nodelay
== 1);
6538 if (put_user(len
, optlen
))
6540 if (copy_to_user(optval
, &val
, len
))
6547 * 7.1.1 SCTP_RTOINFO
6549 * The protocol parameters used to initialize and bound retransmission
6550 * timeout (RTO) are tunable. sctp_rtoinfo structure is used to access
6551 * and modify these parameters.
6552 * All parameters are time values, in milliseconds. A value of 0, when
6553 * modifying the parameters, indicates that the current value should not
6557 static int sctp_getsockopt_rtoinfo(struct sock
*sk
, int len
,
6558 char __user
*optval
,
6559 int __user
*optlen
) {
6560 struct sctp_rtoinfo rtoinfo
;
6561 struct sctp_association
*asoc
;
6563 if (len
< sizeof (struct sctp_rtoinfo
))
6566 len
= sizeof(struct sctp_rtoinfo
);
6568 if (copy_from_user(&rtoinfo
, optval
, len
))
6571 asoc
= sctp_id2assoc(sk
, rtoinfo
.srto_assoc_id
);
6573 if (!asoc
&& rtoinfo
.srto_assoc_id
!= SCTP_FUTURE_ASSOC
&&
6574 sctp_style(sk
, UDP
))
6577 /* Values corresponding to the specific association. */
6579 rtoinfo
.srto_initial
= jiffies_to_msecs(asoc
->rto_initial
);
6580 rtoinfo
.srto_max
= jiffies_to_msecs(asoc
->rto_max
);
6581 rtoinfo
.srto_min
= jiffies_to_msecs(asoc
->rto_min
);
6583 /* Values corresponding to the endpoint. */
6584 struct sctp_sock
*sp
= sctp_sk(sk
);
6586 rtoinfo
.srto_initial
= sp
->rtoinfo
.srto_initial
;
6587 rtoinfo
.srto_max
= sp
->rtoinfo
.srto_max
;
6588 rtoinfo
.srto_min
= sp
->rtoinfo
.srto_min
;
6591 if (put_user(len
, optlen
))
6594 if (copy_to_user(optval
, &rtoinfo
, len
))
6602 * 7.1.2 SCTP_ASSOCINFO
6604 * This option is used to tune the maximum retransmission attempts
6605 * of the association.
6606 * Returns an error if the new association retransmission value is
6607 * greater than the sum of the retransmission value of the peer.
6608 * See [SCTP] for more information.
6611 static int sctp_getsockopt_associnfo(struct sock
*sk
, int len
,
6612 char __user
*optval
,
6616 struct sctp_assocparams assocparams
;
6617 struct sctp_association
*asoc
;
6618 struct list_head
*pos
;
6621 if (len
< sizeof (struct sctp_assocparams
))
6624 len
= sizeof(struct sctp_assocparams
);
6626 if (copy_from_user(&assocparams
, optval
, len
))
6629 asoc
= sctp_id2assoc(sk
, assocparams
.sasoc_assoc_id
);
6631 if (!asoc
&& assocparams
.sasoc_assoc_id
!= SCTP_FUTURE_ASSOC
&&
6632 sctp_style(sk
, UDP
))
6635 /* Values correspoinding to the specific association */
6637 assocparams
.sasoc_asocmaxrxt
= asoc
->max_retrans
;
6638 assocparams
.sasoc_peer_rwnd
= asoc
->peer
.rwnd
;
6639 assocparams
.sasoc_local_rwnd
= asoc
->a_rwnd
;
6640 assocparams
.sasoc_cookie_life
= ktime_to_ms(asoc
->cookie_life
);
6642 list_for_each(pos
, &asoc
->peer
.transport_addr_list
) {
6646 assocparams
.sasoc_number_peer_destinations
= cnt
;
6648 /* Values corresponding to the endpoint */
6649 struct sctp_sock
*sp
= sctp_sk(sk
);
6651 assocparams
.sasoc_asocmaxrxt
= sp
->assocparams
.sasoc_asocmaxrxt
;
6652 assocparams
.sasoc_peer_rwnd
= sp
->assocparams
.sasoc_peer_rwnd
;
6653 assocparams
.sasoc_local_rwnd
= sp
->assocparams
.sasoc_local_rwnd
;
6654 assocparams
.sasoc_cookie_life
=
6655 sp
->assocparams
.sasoc_cookie_life
;
6656 assocparams
.sasoc_number_peer_destinations
=
6658 sasoc_number_peer_destinations
;
6661 if (put_user(len
, optlen
))
6664 if (copy_to_user(optval
, &assocparams
, len
))
6671 * 7.1.16 Set/clear IPv4 mapped addresses (SCTP_I_WANT_MAPPED_V4_ADDR)
6673 * This socket option is a boolean flag which turns on or off mapped V4
6674 * addresses. If this option is turned on and the socket is type
6675 * PF_INET6, then IPv4 addresses will be mapped to V6 representation.
6676 * If this option is turned off, then no mapping will be done of V4
6677 * addresses and a user will receive both PF_INET6 and PF_INET type
6678 * addresses on the socket.
6680 static int sctp_getsockopt_mappedv4(struct sock
*sk
, int len
,
6681 char __user
*optval
, int __user
*optlen
)
6684 struct sctp_sock
*sp
= sctp_sk(sk
);
6686 if (len
< sizeof(int))
6691 if (put_user(len
, optlen
))
6693 if (copy_to_user(optval
, &val
, len
))
6700 * 7.1.29. Set or Get the default context (SCTP_CONTEXT)
6701 * (chapter and verse is quoted at sctp_setsockopt_context())
6703 static int sctp_getsockopt_context(struct sock
*sk
, int len
,
6704 char __user
*optval
, int __user
*optlen
)
6706 struct sctp_assoc_value params
;
6707 struct sctp_association
*asoc
;
6709 if (len
< sizeof(struct sctp_assoc_value
))
6712 len
= sizeof(struct sctp_assoc_value
);
6714 if (copy_from_user(¶ms
, optval
, len
))
6717 asoc
= sctp_id2assoc(sk
, params
.assoc_id
);
6718 if (!asoc
&& params
.assoc_id
!= SCTP_FUTURE_ASSOC
&&
6719 sctp_style(sk
, UDP
))
6722 params
.assoc_value
= asoc
? asoc
->default_rcv_context
6723 : sctp_sk(sk
)->default_rcv_context
;
6725 if (put_user(len
, optlen
))
6727 if (copy_to_user(optval
, ¶ms
, len
))
6734 * 8.1.16. Get or Set the Maximum Fragmentation Size (SCTP_MAXSEG)
6735 * This option will get or set the maximum size to put in any outgoing
6736 * SCTP DATA chunk. If a message is larger than this size it will be
6737 * fragmented by SCTP into the specified size. Note that the underlying
6738 * SCTP implementation may fragment into smaller sized chunks when the
6739 * PMTU of the underlying association is smaller than the value set by
6740 * the user. The default value for this option is '0' which indicates
6741 * the user is NOT limiting fragmentation and only the PMTU will effect
6742 * SCTP's choice of DATA chunk size. Note also that values set larger
6743 * than the maximum size of an IP datagram will effectively let SCTP
6744 * control fragmentation (i.e. the same as setting this option to 0).
6746 * The following structure is used to access and modify this parameter:
6748 * struct sctp_assoc_value {
6749 * sctp_assoc_t assoc_id;
6750 * uint32_t assoc_value;
6753 * assoc_id: This parameter is ignored for one-to-one style sockets.
6754 * For one-to-many style sockets this parameter indicates which
6755 * association the user is performing an action upon. Note that if
6756 * this field's value is zero then the endpoints default value is
6757 * changed (effecting future associations only).
6758 * assoc_value: This parameter specifies the maximum size in bytes.
6760 static int sctp_getsockopt_maxseg(struct sock
*sk
, int len
,
6761 char __user
*optval
, int __user
*optlen
)
6763 struct sctp_assoc_value params
;
6764 struct sctp_association
*asoc
;
6766 if (len
== sizeof(int)) {
6767 pr_warn_ratelimited(DEPRECATED
6769 "Use of int in maxseg socket option.\n"
6770 "Use struct sctp_assoc_value instead\n",
6771 current
->comm
, task_pid_nr(current
));
6772 params
.assoc_id
= SCTP_FUTURE_ASSOC
;
6773 } else if (len
>= sizeof(struct sctp_assoc_value
)) {
6774 len
= sizeof(struct sctp_assoc_value
);
6775 if (copy_from_user(¶ms
, optval
, len
))
6780 asoc
= sctp_id2assoc(sk
, params
.assoc_id
);
6781 if (!asoc
&& params
.assoc_id
!= SCTP_FUTURE_ASSOC
&&
6782 sctp_style(sk
, UDP
))
6786 params
.assoc_value
= asoc
->frag_point
;
6788 params
.assoc_value
= sctp_sk(sk
)->user_frag
;
6790 if (put_user(len
, optlen
))
6792 if (len
== sizeof(int)) {
6793 if (copy_to_user(optval
, ¶ms
.assoc_value
, len
))
6796 if (copy_to_user(optval
, ¶ms
, len
))
6804 * 7.1.24. Get or set fragmented interleave (SCTP_FRAGMENT_INTERLEAVE)
6805 * (chapter and verse is quoted at sctp_setsockopt_fragment_interleave())
6807 static int sctp_getsockopt_fragment_interleave(struct sock
*sk
, int len
,
6808 char __user
*optval
, int __user
*optlen
)
6812 if (len
< sizeof(int))
6817 val
= sctp_sk(sk
)->frag_interleave
;
6818 if (put_user(len
, optlen
))
6820 if (copy_to_user(optval
, &val
, len
))
6827 * 7.1.25. Set or Get the sctp partial delivery point
6828 * (chapter and verse is quoted at sctp_setsockopt_partial_delivery_point())
6830 static int sctp_getsockopt_partial_delivery_point(struct sock
*sk
, int len
,
6831 char __user
*optval
,
6836 if (len
< sizeof(u32
))
6841 val
= sctp_sk(sk
)->pd_point
;
6842 if (put_user(len
, optlen
))
6844 if (copy_to_user(optval
, &val
, len
))
6851 * 7.1.28. Set or Get the maximum burst (SCTP_MAX_BURST)
6852 * (chapter and verse is quoted at sctp_setsockopt_maxburst())
6854 static int sctp_getsockopt_maxburst(struct sock
*sk
, int len
,
6855 char __user
*optval
,
6858 struct sctp_assoc_value params
;
6859 struct sctp_association
*asoc
;
6861 if (len
== sizeof(int)) {
6862 pr_warn_ratelimited(DEPRECATED
6864 "Use of int in max_burst socket option.\n"
6865 "Use struct sctp_assoc_value instead\n",
6866 current
->comm
, task_pid_nr(current
));
6867 params
.assoc_id
= SCTP_FUTURE_ASSOC
;
6868 } else if (len
>= sizeof(struct sctp_assoc_value
)) {
6869 len
= sizeof(struct sctp_assoc_value
);
6870 if (copy_from_user(¶ms
, optval
, len
))
6875 asoc
= sctp_id2assoc(sk
, params
.assoc_id
);
6876 if (!asoc
&& params
.assoc_id
!= SCTP_FUTURE_ASSOC
&&
6877 sctp_style(sk
, UDP
))
6880 params
.assoc_value
= asoc
? asoc
->max_burst
: sctp_sk(sk
)->max_burst
;
6882 if (len
== sizeof(int)) {
6883 if (copy_to_user(optval
, ¶ms
.assoc_value
, len
))
6886 if (copy_to_user(optval
, ¶ms
, len
))
6894 static int sctp_getsockopt_hmac_ident(struct sock
*sk
, int len
,
6895 char __user
*optval
, int __user
*optlen
)
6897 struct sctp_endpoint
*ep
= sctp_sk(sk
)->ep
;
6898 struct sctp_hmacalgo __user
*p
= (void __user
*)optval
;
6899 struct sctp_hmac_algo_param
*hmacs
;
6904 if (!ep
->auth_enable
)
6907 hmacs
= ep
->auth_hmacs_list
;
6908 data_len
= ntohs(hmacs
->param_hdr
.length
) -
6909 sizeof(struct sctp_paramhdr
);
6911 if (len
< sizeof(struct sctp_hmacalgo
) + data_len
)
6914 len
= sizeof(struct sctp_hmacalgo
) + data_len
;
6915 num_idents
= data_len
/ sizeof(u16
);
6917 if (put_user(len
, optlen
))
6919 if (put_user(num_idents
, &p
->shmac_num_idents
))
6921 for (i
= 0; i
< num_idents
; i
++) {
6922 __u16 hmacid
= ntohs(hmacs
->hmac_ids
[i
]);
6924 if (copy_to_user(&p
->shmac_idents
[i
], &hmacid
, sizeof(__u16
)))
6930 static int sctp_getsockopt_active_key(struct sock
*sk
, int len
,
6931 char __user
*optval
, int __user
*optlen
)
6933 struct sctp_endpoint
*ep
= sctp_sk(sk
)->ep
;
6934 struct sctp_authkeyid val
;
6935 struct sctp_association
*asoc
;
6937 if (len
< sizeof(struct sctp_authkeyid
))
6940 len
= sizeof(struct sctp_authkeyid
);
6941 if (copy_from_user(&val
, optval
, len
))
6944 asoc
= sctp_id2assoc(sk
, val
.scact_assoc_id
);
6945 if (!asoc
&& val
.scact_assoc_id
&& sctp_style(sk
, UDP
))
6949 if (!asoc
->peer
.auth_capable
)
6951 val
.scact_keynumber
= asoc
->active_key_id
;
6953 if (!ep
->auth_enable
)
6955 val
.scact_keynumber
= ep
->active_key_id
;
6958 if (put_user(len
, optlen
))
6960 if (copy_to_user(optval
, &val
, len
))
6966 static int sctp_getsockopt_peer_auth_chunks(struct sock
*sk
, int len
,
6967 char __user
*optval
, int __user
*optlen
)
6969 struct sctp_authchunks __user
*p
= (void __user
*)optval
;
6970 struct sctp_authchunks val
;
6971 struct sctp_association
*asoc
;
6972 struct sctp_chunks_param
*ch
;
6976 if (len
< sizeof(struct sctp_authchunks
))
6979 if (copy_from_user(&val
, optval
, sizeof(val
)))
6982 to
= p
->gauth_chunks
;
6983 asoc
= sctp_id2assoc(sk
, val
.gauth_assoc_id
);
6987 if (!asoc
->peer
.auth_capable
)
6990 ch
= asoc
->peer
.peer_chunks
;
6994 /* See if the user provided enough room for all the data */
6995 num_chunks
= ntohs(ch
->param_hdr
.length
) - sizeof(struct sctp_paramhdr
);
6996 if (len
< num_chunks
)
6999 if (copy_to_user(to
, ch
->chunks
, num_chunks
))
7002 len
= sizeof(struct sctp_authchunks
) + num_chunks
;
7003 if (put_user(len
, optlen
))
7005 if (put_user(num_chunks
, &p
->gauth_number_of_chunks
))
7010 static int sctp_getsockopt_local_auth_chunks(struct sock
*sk
, int len
,
7011 char __user
*optval
, int __user
*optlen
)
7013 struct sctp_endpoint
*ep
= sctp_sk(sk
)->ep
;
7014 struct sctp_authchunks __user
*p
= (void __user
*)optval
;
7015 struct sctp_authchunks val
;
7016 struct sctp_association
*asoc
;
7017 struct sctp_chunks_param
*ch
;
7021 if (len
< sizeof(struct sctp_authchunks
))
7024 if (copy_from_user(&val
, optval
, sizeof(val
)))
7027 to
= p
->gauth_chunks
;
7028 asoc
= sctp_id2assoc(sk
, val
.gauth_assoc_id
);
7029 if (!asoc
&& val
.gauth_assoc_id
!= SCTP_FUTURE_ASSOC
&&
7030 sctp_style(sk
, UDP
))
7034 if (!asoc
->peer
.auth_capable
)
7036 ch
= (struct sctp_chunks_param
*)asoc
->c
.auth_chunks
;
7038 if (!ep
->auth_enable
)
7040 ch
= ep
->auth_chunk_list
;
7045 num_chunks
= ntohs(ch
->param_hdr
.length
) - sizeof(struct sctp_paramhdr
);
7046 if (len
< sizeof(struct sctp_authchunks
) + num_chunks
)
7049 if (copy_to_user(to
, ch
->chunks
, num_chunks
))
7052 len
= sizeof(struct sctp_authchunks
) + num_chunks
;
7053 if (put_user(len
, optlen
))
7055 if (put_user(num_chunks
, &p
->gauth_number_of_chunks
))
7062 * 8.2.5. Get the Current Number of Associations (SCTP_GET_ASSOC_NUMBER)
7063 * This option gets the current number of associations that are attached
7064 * to a one-to-many style socket. The option value is an uint32_t.
7066 static int sctp_getsockopt_assoc_number(struct sock
*sk
, int len
,
7067 char __user
*optval
, int __user
*optlen
)
7069 struct sctp_sock
*sp
= sctp_sk(sk
);
7070 struct sctp_association
*asoc
;
7073 if (sctp_style(sk
, TCP
))
7076 if (len
< sizeof(u32
))
7081 list_for_each_entry(asoc
, &(sp
->ep
->asocs
), asocs
) {
7085 if (put_user(len
, optlen
))
7087 if (copy_to_user(optval
, &val
, len
))
7094 * 8.1.23 SCTP_AUTO_ASCONF
7095 * See the corresponding setsockopt entry as description
7097 static int sctp_getsockopt_auto_asconf(struct sock
*sk
, int len
,
7098 char __user
*optval
, int __user
*optlen
)
7102 if (len
< sizeof(int))
7106 if (sctp_sk(sk
)->do_auto_asconf
&& sctp_is_ep_boundall(sk
))
7108 if (put_user(len
, optlen
))
7110 if (copy_to_user(optval
, &val
, len
))
7116 * 8.2.6. Get the Current Identifiers of Associations
7117 * (SCTP_GET_ASSOC_ID_LIST)
7119 * This option gets the current list of SCTP association identifiers of
7120 * the SCTP associations handled by a one-to-many style socket.
7122 static int sctp_getsockopt_assoc_ids(struct sock
*sk
, int len
,
7123 char __user
*optval
, int __user
*optlen
)
7125 struct sctp_sock
*sp
= sctp_sk(sk
);
7126 struct sctp_association
*asoc
;
7127 struct sctp_assoc_ids
*ids
;
7131 if (sctp_style(sk
, TCP
))
7134 if (len
< sizeof(struct sctp_assoc_ids
))
7137 list_for_each_entry(asoc
, &(sp
->ep
->asocs
), asocs
) {
7141 ids_size
= struct_size(ids
, gaids_assoc_id
, num
);
7146 ids
= kmalloc(len
, GFP_USER
| __GFP_NOWARN
);
7150 ids
->gaids_number_of_ids
= num
;
7152 list_for_each_entry(asoc
, &(sp
->ep
->asocs
), asocs
) {
7153 ids
->gaids_assoc_id
[num
++] = asoc
->assoc_id
;
7156 if (put_user(len
, optlen
) || copy_to_user(optval
, ids
, len
)) {
7166 * SCTP_PEER_ADDR_THLDS
7168 * This option allows us to fetch the partially failed threshold for one or all
7169 * transports in an association. See Section 6.1 of:
7170 * http://www.ietf.org/id/draft-nishida-tsvwg-sctp-failover-05.txt
7172 static int sctp_getsockopt_paddr_thresholds(struct sock
*sk
,
7173 char __user
*optval
, int len
,
7174 int __user
*optlen
, bool v2
)
7176 struct sctp_paddrthlds_v2 val
;
7177 struct sctp_transport
*trans
;
7178 struct sctp_association
*asoc
;
7181 min
= v2
? sizeof(val
) : sizeof(struct sctp_paddrthlds
);
7185 if (copy_from_user(&val
, optval
, len
))
7188 if (!sctp_is_any(sk
, (const union sctp_addr
*)&val
.spt_address
)) {
7189 trans
= sctp_addr_id2transport(sk
, &val
.spt_address
,
7194 val
.spt_pathmaxrxt
= trans
->pathmaxrxt
;
7195 val
.spt_pathpfthld
= trans
->pf_retrans
;
7196 val
.spt_pathcpthld
= trans
->ps_retrans
;
7201 asoc
= sctp_id2assoc(sk
, val
.spt_assoc_id
);
7202 if (!asoc
&& val
.spt_assoc_id
!= SCTP_FUTURE_ASSOC
&&
7203 sctp_style(sk
, UDP
))
7207 val
.spt_pathpfthld
= asoc
->pf_retrans
;
7208 val
.spt_pathmaxrxt
= asoc
->pathmaxrxt
;
7209 val
.spt_pathcpthld
= asoc
->ps_retrans
;
7211 struct sctp_sock
*sp
= sctp_sk(sk
);
7213 val
.spt_pathpfthld
= sp
->pf_retrans
;
7214 val
.spt_pathmaxrxt
= sp
->pathmaxrxt
;
7215 val
.spt_pathcpthld
= sp
->ps_retrans
;
7219 if (put_user(len
, optlen
) || copy_to_user(optval
, &val
, len
))
7226 * SCTP_GET_ASSOC_STATS
7228 * This option retrieves local per endpoint statistics. It is modeled
7229 * after OpenSolaris' implementation
7231 static int sctp_getsockopt_assoc_stats(struct sock
*sk
, int len
,
7232 char __user
*optval
,
7235 struct sctp_assoc_stats sas
;
7236 struct sctp_association
*asoc
= NULL
;
7238 /* User must provide at least the assoc id */
7239 if (len
< sizeof(sctp_assoc_t
))
7242 /* Allow the struct to grow and fill in as much as possible */
7243 len
= min_t(size_t, len
, sizeof(sas
));
7245 if (copy_from_user(&sas
, optval
, len
))
7248 asoc
= sctp_id2assoc(sk
, sas
.sas_assoc_id
);
7252 sas
.sas_rtxchunks
= asoc
->stats
.rtxchunks
;
7253 sas
.sas_gapcnt
= asoc
->stats
.gapcnt
;
7254 sas
.sas_outofseqtsns
= asoc
->stats
.outofseqtsns
;
7255 sas
.sas_osacks
= asoc
->stats
.osacks
;
7256 sas
.sas_isacks
= asoc
->stats
.isacks
;
7257 sas
.sas_octrlchunks
= asoc
->stats
.octrlchunks
;
7258 sas
.sas_ictrlchunks
= asoc
->stats
.ictrlchunks
;
7259 sas
.sas_oodchunks
= asoc
->stats
.oodchunks
;
7260 sas
.sas_iodchunks
= asoc
->stats
.iodchunks
;
7261 sas
.sas_ouodchunks
= asoc
->stats
.ouodchunks
;
7262 sas
.sas_iuodchunks
= asoc
->stats
.iuodchunks
;
7263 sas
.sas_idupchunks
= asoc
->stats
.idupchunks
;
7264 sas
.sas_opackets
= asoc
->stats
.opackets
;
7265 sas
.sas_ipackets
= asoc
->stats
.ipackets
;
7267 /* New high max rto observed, will return 0 if not a single
7268 * RTO update took place. obs_rto_ipaddr will be bogus
7271 sas
.sas_maxrto
= asoc
->stats
.max_obs_rto
;
7272 memcpy(&sas
.sas_obs_rto_ipaddr
, &asoc
->stats
.obs_rto_ipaddr
,
7273 sizeof(struct sockaddr_storage
));
7275 /* Mark beginning of a new observation period */
7276 asoc
->stats
.max_obs_rto
= asoc
->rto_min
;
7278 if (put_user(len
, optlen
))
7281 pr_debug("%s: len:%d, assoc_id:%d\n", __func__
, len
, sas
.sas_assoc_id
);
7283 if (copy_to_user(optval
, &sas
, len
))
7289 static int sctp_getsockopt_recvrcvinfo(struct sock
*sk
, int len
,
7290 char __user
*optval
,
7295 if (len
< sizeof(int))
7299 if (sctp_sk(sk
)->recvrcvinfo
)
7301 if (put_user(len
, optlen
))
7303 if (copy_to_user(optval
, &val
, len
))
7309 static int sctp_getsockopt_recvnxtinfo(struct sock
*sk
, int len
,
7310 char __user
*optval
,
7315 if (len
< sizeof(int))
7319 if (sctp_sk(sk
)->recvnxtinfo
)
7321 if (put_user(len
, optlen
))
7323 if (copy_to_user(optval
, &val
, len
))
7329 static int sctp_getsockopt_pr_supported(struct sock
*sk
, int len
,
7330 char __user
*optval
,
7333 struct sctp_assoc_value params
;
7334 struct sctp_association
*asoc
;
7335 int retval
= -EFAULT
;
7337 if (len
< sizeof(params
)) {
7342 len
= sizeof(params
);
7343 if (copy_from_user(¶ms
, optval
, len
))
7346 asoc
= sctp_id2assoc(sk
, params
.assoc_id
);
7347 if (!asoc
&& params
.assoc_id
!= SCTP_FUTURE_ASSOC
&&
7348 sctp_style(sk
, UDP
)) {
7353 params
.assoc_value
= asoc
? asoc
->peer
.prsctp_capable
7354 : sctp_sk(sk
)->ep
->prsctp_enable
;
7356 if (put_user(len
, optlen
))
7359 if (copy_to_user(optval
, ¶ms
, len
))
7368 static int sctp_getsockopt_default_prinfo(struct sock
*sk
, int len
,
7369 char __user
*optval
,
7372 struct sctp_default_prinfo info
;
7373 struct sctp_association
*asoc
;
7374 int retval
= -EFAULT
;
7376 if (len
< sizeof(info
)) {
7382 if (copy_from_user(&info
, optval
, len
))
7385 asoc
= sctp_id2assoc(sk
, info
.pr_assoc_id
);
7386 if (!asoc
&& info
.pr_assoc_id
!= SCTP_FUTURE_ASSOC
&&
7387 sctp_style(sk
, UDP
)) {
7393 info
.pr_policy
= SCTP_PR_POLICY(asoc
->default_flags
);
7394 info
.pr_value
= asoc
->default_timetolive
;
7396 struct sctp_sock
*sp
= sctp_sk(sk
);
7398 info
.pr_policy
= SCTP_PR_POLICY(sp
->default_flags
);
7399 info
.pr_value
= sp
->default_timetolive
;
7402 if (put_user(len
, optlen
))
7405 if (copy_to_user(optval
, &info
, len
))
7414 static int sctp_getsockopt_pr_assocstatus(struct sock
*sk
, int len
,
7415 char __user
*optval
,
7418 struct sctp_prstatus params
;
7419 struct sctp_association
*asoc
;
7421 int retval
= -EINVAL
;
7423 if (len
< sizeof(params
))
7426 len
= sizeof(params
);
7427 if (copy_from_user(¶ms
, optval
, len
)) {
7432 policy
= params
.sprstat_policy
;
7433 if (!policy
|| (policy
& ~(SCTP_PR_SCTP_MASK
| SCTP_PR_SCTP_ALL
)) ||
7434 ((policy
& SCTP_PR_SCTP_ALL
) && (policy
& SCTP_PR_SCTP_MASK
)))
7437 asoc
= sctp_id2assoc(sk
, params
.sprstat_assoc_id
);
7441 if (policy
== SCTP_PR_SCTP_ALL
) {
7442 params
.sprstat_abandoned_unsent
= 0;
7443 params
.sprstat_abandoned_sent
= 0;
7444 for (policy
= 0; policy
<= SCTP_PR_INDEX(MAX
); policy
++) {
7445 params
.sprstat_abandoned_unsent
+=
7446 asoc
->abandoned_unsent
[policy
];
7447 params
.sprstat_abandoned_sent
+=
7448 asoc
->abandoned_sent
[policy
];
7451 params
.sprstat_abandoned_unsent
=
7452 asoc
->abandoned_unsent
[__SCTP_PR_INDEX(policy
)];
7453 params
.sprstat_abandoned_sent
=
7454 asoc
->abandoned_sent
[__SCTP_PR_INDEX(policy
)];
7457 if (put_user(len
, optlen
)) {
7462 if (copy_to_user(optval
, ¶ms
, len
)) {
7473 static int sctp_getsockopt_pr_streamstatus(struct sock
*sk
, int len
,
7474 char __user
*optval
,
7477 struct sctp_stream_out_ext
*streamoute
;
7478 struct sctp_association
*asoc
;
7479 struct sctp_prstatus params
;
7480 int retval
= -EINVAL
;
7483 if (len
< sizeof(params
))
7486 len
= sizeof(params
);
7487 if (copy_from_user(¶ms
, optval
, len
)) {
7492 policy
= params
.sprstat_policy
;
7493 if (!policy
|| (policy
& ~(SCTP_PR_SCTP_MASK
| SCTP_PR_SCTP_ALL
)) ||
7494 ((policy
& SCTP_PR_SCTP_ALL
) && (policy
& SCTP_PR_SCTP_MASK
)))
7497 asoc
= sctp_id2assoc(sk
, params
.sprstat_assoc_id
);
7498 if (!asoc
|| params
.sprstat_sid
>= asoc
->stream
.outcnt
)
7501 streamoute
= SCTP_SO(&asoc
->stream
, params
.sprstat_sid
)->ext
;
7503 /* Not allocated yet, means all stats are 0 */
7504 params
.sprstat_abandoned_unsent
= 0;
7505 params
.sprstat_abandoned_sent
= 0;
7510 if (policy
== SCTP_PR_SCTP_ALL
) {
7511 params
.sprstat_abandoned_unsent
= 0;
7512 params
.sprstat_abandoned_sent
= 0;
7513 for (policy
= 0; policy
<= SCTP_PR_INDEX(MAX
); policy
++) {
7514 params
.sprstat_abandoned_unsent
+=
7515 streamoute
->abandoned_unsent
[policy
];
7516 params
.sprstat_abandoned_sent
+=
7517 streamoute
->abandoned_sent
[policy
];
7520 params
.sprstat_abandoned_unsent
=
7521 streamoute
->abandoned_unsent
[__SCTP_PR_INDEX(policy
)];
7522 params
.sprstat_abandoned_sent
=
7523 streamoute
->abandoned_sent
[__SCTP_PR_INDEX(policy
)];
7526 if (put_user(len
, optlen
) || copy_to_user(optval
, ¶ms
, len
)) {
7537 static int sctp_getsockopt_reconfig_supported(struct sock
*sk
, int len
,
7538 char __user
*optval
,
7541 struct sctp_assoc_value params
;
7542 struct sctp_association
*asoc
;
7543 int retval
= -EFAULT
;
7545 if (len
< sizeof(params
)) {
7550 len
= sizeof(params
);
7551 if (copy_from_user(¶ms
, optval
, len
))
7554 asoc
= sctp_id2assoc(sk
, params
.assoc_id
);
7555 if (!asoc
&& params
.assoc_id
!= SCTP_FUTURE_ASSOC
&&
7556 sctp_style(sk
, UDP
)) {
7561 params
.assoc_value
= asoc
? asoc
->peer
.reconf_capable
7562 : sctp_sk(sk
)->ep
->reconf_enable
;
7564 if (put_user(len
, optlen
))
7567 if (copy_to_user(optval
, ¶ms
, len
))
7576 static int sctp_getsockopt_enable_strreset(struct sock
*sk
, int len
,
7577 char __user
*optval
,
7580 struct sctp_assoc_value params
;
7581 struct sctp_association
*asoc
;
7582 int retval
= -EFAULT
;
7584 if (len
< sizeof(params
)) {
7589 len
= sizeof(params
);
7590 if (copy_from_user(¶ms
, optval
, len
))
7593 asoc
= sctp_id2assoc(sk
, params
.assoc_id
);
7594 if (!asoc
&& params
.assoc_id
!= SCTP_FUTURE_ASSOC
&&
7595 sctp_style(sk
, UDP
)) {
7600 params
.assoc_value
= asoc
? asoc
->strreset_enable
7601 : sctp_sk(sk
)->ep
->strreset_enable
;
7603 if (put_user(len
, optlen
))
7606 if (copy_to_user(optval
, ¶ms
, len
))
7615 static int sctp_getsockopt_scheduler(struct sock
*sk
, int len
,
7616 char __user
*optval
,
7619 struct sctp_assoc_value params
;
7620 struct sctp_association
*asoc
;
7621 int retval
= -EFAULT
;
7623 if (len
< sizeof(params
)) {
7628 len
= sizeof(params
);
7629 if (copy_from_user(¶ms
, optval
, len
))
7632 asoc
= sctp_id2assoc(sk
, params
.assoc_id
);
7633 if (!asoc
&& params
.assoc_id
!= SCTP_FUTURE_ASSOC
&&
7634 sctp_style(sk
, UDP
)) {
7639 params
.assoc_value
= asoc
? sctp_sched_get_sched(asoc
)
7640 : sctp_sk(sk
)->default_ss
;
7642 if (put_user(len
, optlen
))
7645 if (copy_to_user(optval
, ¶ms
, len
))
7654 static int sctp_getsockopt_scheduler_value(struct sock
*sk
, int len
,
7655 char __user
*optval
,
7658 struct sctp_stream_value params
;
7659 struct sctp_association
*asoc
;
7660 int retval
= -EFAULT
;
7662 if (len
< sizeof(params
)) {
7667 len
= sizeof(params
);
7668 if (copy_from_user(¶ms
, optval
, len
))
7671 asoc
= sctp_id2assoc(sk
, params
.assoc_id
);
7677 retval
= sctp_sched_get_value(asoc
, params
.stream_id
,
7678 ¶ms
.stream_value
);
7682 if (put_user(len
, optlen
)) {
7687 if (copy_to_user(optval
, ¶ms
, len
)) {
7696 static int sctp_getsockopt_interleaving_supported(struct sock
*sk
, int len
,
7697 char __user
*optval
,
7700 struct sctp_assoc_value params
;
7701 struct sctp_association
*asoc
;
7702 int retval
= -EFAULT
;
7704 if (len
< sizeof(params
)) {
7709 len
= sizeof(params
);
7710 if (copy_from_user(¶ms
, optval
, len
))
7713 asoc
= sctp_id2assoc(sk
, params
.assoc_id
);
7714 if (!asoc
&& params
.assoc_id
!= SCTP_FUTURE_ASSOC
&&
7715 sctp_style(sk
, UDP
)) {
7720 params
.assoc_value
= asoc
? asoc
->peer
.intl_capable
7721 : sctp_sk(sk
)->ep
->intl_enable
;
7723 if (put_user(len
, optlen
))
7726 if (copy_to_user(optval
, ¶ms
, len
))
7735 static int sctp_getsockopt_reuse_port(struct sock
*sk
, int len
,
7736 char __user
*optval
,
7741 if (len
< sizeof(int))
7745 val
= sctp_sk(sk
)->reuse
;
7746 if (put_user(len
, optlen
))
7749 if (copy_to_user(optval
, &val
, len
))
7755 static int sctp_getsockopt_event(struct sock
*sk
, int len
, char __user
*optval
,
7758 struct sctp_association
*asoc
;
7759 struct sctp_event param
;
7762 if (len
< sizeof(param
))
7765 len
= sizeof(param
);
7766 if (copy_from_user(¶m
, optval
, len
))
7769 if (param
.se_type
< SCTP_SN_TYPE_BASE
||
7770 param
.se_type
> SCTP_SN_TYPE_MAX
)
7773 asoc
= sctp_id2assoc(sk
, param
.se_assoc_id
);
7774 if (!asoc
&& param
.se_assoc_id
!= SCTP_FUTURE_ASSOC
&&
7775 sctp_style(sk
, UDP
))
7778 subscribe
= asoc
? asoc
->subscribe
: sctp_sk(sk
)->subscribe
;
7779 param
.se_on
= sctp_ulpevent_type_enabled(subscribe
, param
.se_type
);
7781 if (put_user(len
, optlen
))
7784 if (copy_to_user(optval
, ¶m
, len
))
7790 static int sctp_getsockopt_asconf_supported(struct sock
*sk
, int len
,
7791 char __user
*optval
,
7794 struct sctp_assoc_value params
;
7795 struct sctp_association
*asoc
;
7796 int retval
= -EFAULT
;
7798 if (len
< sizeof(params
)) {
7803 len
= sizeof(params
);
7804 if (copy_from_user(¶ms
, optval
, len
))
7807 asoc
= sctp_id2assoc(sk
, params
.assoc_id
);
7808 if (!asoc
&& params
.assoc_id
!= SCTP_FUTURE_ASSOC
&&
7809 sctp_style(sk
, UDP
)) {
7814 params
.assoc_value
= asoc
? asoc
->peer
.asconf_capable
7815 : sctp_sk(sk
)->ep
->asconf_enable
;
7817 if (put_user(len
, optlen
))
7820 if (copy_to_user(optval
, ¶ms
, len
))
7829 static int sctp_getsockopt_auth_supported(struct sock
*sk
, int len
,
7830 char __user
*optval
,
7833 struct sctp_assoc_value params
;
7834 struct sctp_association
*asoc
;
7835 int retval
= -EFAULT
;
7837 if (len
< sizeof(params
)) {
7842 len
= sizeof(params
);
7843 if (copy_from_user(¶ms
, optval
, len
))
7846 asoc
= sctp_id2assoc(sk
, params
.assoc_id
);
7847 if (!asoc
&& params
.assoc_id
!= SCTP_FUTURE_ASSOC
&&
7848 sctp_style(sk
, UDP
)) {
7853 params
.assoc_value
= asoc
? asoc
->peer
.auth_capable
7854 : sctp_sk(sk
)->ep
->auth_enable
;
7856 if (put_user(len
, optlen
))
7859 if (copy_to_user(optval
, ¶ms
, len
))
7868 static int sctp_getsockopt_ecn_supported(struct sock
*sk
, int len
,
7869 char __user
*optval
,
7872 struct sctp_assoc_value params
;
7873 struct sctp_association
*asoc
;
7874 int retval
= -EFAULT
;
7876 if (len
< sizeof(params
)) {
7881 len
= sizeof(params
);
7882 if (copy_from_user(¶ms
, optval
, len
))
7885 asoc
= sctp_id2assoc(sk
, params
.assoc_id
);
7886 if (!asoc
&& params
.assoc_id
!= SCTP_FUTURE_ASSOC
&&
7887 sctp_style(sk
, UDP
)) {
7892 params
.assoc_value
= asoc
? asoc
->peer
.ecn_capable
7893 : sctp_sk(sk
)->ep
->ecn_enable
;
7895 if (put_user(len
, optlen
))
7898 if (copy_to_user(optval
, ¶ms
, len
))
7907 static int sctp_getsockopt_pf_expose(struct sock
*sk
, int len
,
7908 char __user
*optval
,
7911 struct sctp_assoc_value params
;
7912 struct sctp_association
*asoc
;
7913 int retval
= -EFAULT
;
7915 if (len
< sizeof(params
)) {
7920 len
= sizeof(params
);
7921 if (copy_from_user(¶ms
, optval
, len
))
7924 asoc
= sctp_id2assoc(sk
, params
.assoc_id
);
7925 if (!asoc
&& params
.assoc_id
!= SCTP_FUTURE_ASSOC
&&
7926 sctp_style(sk
, UDP
)) {
7931 params
.assoc_value
= asoc
? asoc
->pf_expose
7932 : sctp_sk(sk
)->pf_expose
;
7934 if (put_user(len
, optlen
))
7937 if (copy_to_user(optval
, ¶ms
, len
))
7946 static int sctp_getsockopt_encap_port(struct sock
*sk
, int len
,
7947 char __user
*optval
, int __user
*optlen
)
7949 struct sctp_association
*asoc
;
7950 struct sctp_udpencaps encap
;
7951 struct sctp_transport
*t
;
7954 if (len
< sizeof(encap
))
7957 len
= sizeof(encap
);
7958 if (copy_from_user(&encap
, optval
, len
))
7961 /* If an address other than INADDR_ANY is specified, and
7962 * no transport is found, then the request is invalid.
7964 if (!sctp_is_any(sk
, (union sctp_addr
*)&encap
.sue_address
)) {
7965 t
= sctp_addr_id2transport(sk
, &encap
.sue_address
,
7966 encap
.sue_assoc_id
);
7968 pr_debug("%s: failed no transport\n", __func__
);
7972 encap_port
= t
->encap_port
;
7976 /* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the
7977 * socket is a one to many style socket, and an association
7978 * was not found, then the id was invalid.
7980 asoc
= sctp_id2assoc(sk
, encap
.sue_assoc_id
);
7981 if (!asoc
&& encap
.sue_assoc_id
!= SCTP_FUTURE_ASSOC
&&
7982 sctp_style(sk
, UDP
)) {
7983 pr_debug("%s: failed no association\n", __func__
);
7988 encap_port
= asoc
->encap_port
;
7992 encap_port
= sctp_sk(sk
)->encap_port
;
7995 encap
.sue_port
= (__force
uint16_t)encap_port
;
7996 if (copy_to_user(optval
, &encap
, len
))
7999 if (put_user(len
, optlen
))
8005 static int sctp_getsockopt_probe_interval(struct sock
*sk
, int len
,
8006 char __user
*optval
,
8009 struct sctp_probeinterval params
;
8010 struct sctp_association
*asoc
;
8011 struct sctp_transport
*t
;
8012 __u32 probe_interval
;
8014 if (len
< sizeof(params
))
8017 len
= sizeof(params
);
8018 if (copy_from_user(¶ms
, optval
, len
))
8021 /* If an address other than INADDR_ANY is specified, and
8022 * no transport is found, then the request is invalid.
8024 if (!sctp_is_any(sk
, (union sctp_addr
*)¶ms
.spi_address
)) {
8025 t
= sctp_addr_id2transport(sk
, ¶ms
.spi_address
,
8026 params
.spi_assoc_id
);
8028 pr_debug("%s: failed no transport\n", __func__
);
8032 probe_interval
= jiffies_to_msecs(t
->probe_interval
);
8036 /* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the
8037 * socket is a one to many style socket, and an association
8038 * was not found, then the id was invalid.
8040 asoc
= sctp_id2assoc(sk
, params
.spi_assoc_id
);
8041 if (!asoc
&& params
.spi_assoc_id
!= SCTP_FUTURE_ASSOC
&&
8042 sctp_style(sk
, UDP
)) {
8043 pr_debug("%s: failed no association\n", __func__
);
8048 probe_interval
= jiffies_to_msecs(asoc
->probe_interval
);
8052 probe_interval
= sctp_sk(sk
)->probe_interval
;
8055 params
.spi_interval
= probe_interval
;
8056 if (copy_to_user(optval
, ¶ms
, len
))
8059 if (put_user(len
, optlen
))
8065 static int sctp_getsockopt(struct sock
*sk
, int level
, int optname
,
8066 char __user
*optval
, int __user
*optlen
)
8071 pr_debug("%s: sk:%p, optname:%d\n", __func__
, sk
, optname
);
8073 /* I can hardly begin to describe how wrong this is. This is
8074 * so broken as to be worse than useless. The API draft
8075 * REALLY is NOT helpful here... I am not convinced that the
8076 * semantics of getsockopt() with a level OTHER THAN SOL_SCTP
8077 * are at all well-founded.
8079 if (level
!= SOL_SCTP
) {
8080 struct sctp_af
*af
= sctp_sk(sk
)->pf
->af
;
8082 retval
= af
->getsockopt(sk
, level
, optname
, optval
, optlen
);
8086 if (get_user(len
, optlen
))
8096 retval
= sctp_getsockopt_sctp_status(sk
, len
, optval
, optlen
);
8098 case SCTP_DISABLE_FRAGMENTS
:
8099 retval
= sctp_getsockopt_disable_fragments(sk
, len
, optval
,
8103 retval
= sctp_getsockopt_events(sk
, len
, optval
, optlen
);
8105 case SCTP_AUTOCLOSE
:
8106 retval
= sctp_getsockopt_autoclose(sk
, len
, optval
, optlen
);
8108 case SCTP_SOCKOPT_PEELOFF
:
8109 retval
= sctp_getsockopt_peeloff(sk
, len
, optval
, optlen
);
8111 case SCTP_SOCKOPT_PEELOFF_FLAGS
:
8112 retval
= sctp_getsockopt_peeloff_flags(sk
, len
, optval
, optlen
);
8114 case SCTP_PEER_ADDR_PARAMS
:
8115 retval
= sctp_getsockopt_peer_addr_params(sk
, len
, optval
,
8118 case SCTP_DELAYED_SACK
:
8119 retval
= sctp_getsockopt_delayed_ack(sk
, len
, optval
,
8123 retval
= sctp_getsockopt_initmsg(sk
, len
, optval
, optlen
);
8125 case SCTP_GET_PEER_ADDRS
:
8126 retval
= sctp_getsockopt_peer_addrs(sk
, len
, optval
,
8129 case SCTP_GET_LOCAL_ADDRS
:
8130 retval
= sctp_getsockopt_local_addrs(sk
, len
, optval
,
8133 case SCTP_SOCKOPT_CONNECTX3
:
8134 retval
= sctp_getsockopt_connectx3(sk
, len
, optval
, optlen
);
8136 case SCTP_DEFAULT_SEND_PARAM
:
8137 retval
= sctp_getsockopt_default_send_param(sk
, len
,
8140 case SCTP_DEFAULT_SNDINFO
:
8141 retval
= sctp_getsockopt_default_sndinfo(sk
, len
,
8144 case SCTP_PRIMARY_ADDR
:
8145 retval
= sctp_getsockopt_primary_addr(sk
, len
, optval
, optlen
);
8148 retval
= sctp_getsockopt_nodelay(sk
, len
, optval
, optlen
);
8151 retval
= sctp_getsockopt_rtoinfo(sk
, len
, optval
, optlen
);
8153 case SCTP_ASSOCINFO
:
8154 retval
= sctp_getsockopt_associnfo(sk
, len
, optval
, optlen
);
8156 case SCTP_I_WANT_MAPPED_V4_ADDR
:
8157 retval
= sctp_getsockopt_mappedv4(sk
, len
, optval
, optlen
);
8160 retval
= sctp_getsockopt_maxseg(sk
, len
, optval
, optlen
);
8162 case SCTP_GET_PEER_ADDR_INFO
:
8163 retval
= sctp_getsockopt_peer_addr_info(sk
, len
, optval
,
8166 case SCTP_ADAPTATION_LAYER
:
8167 retval
= sctp_getsockopt_adaptation_layer(sk
, len
, optval
,
8171 retval
= sctp_getsockopt_context(sk
, len
, optval
, optlen
);
8173 case SCTP_FRAGMENT_INTERLEAVE
:
8174 retval
= sctp_getsockopt_fragment_interleave(sk
, len
, optval
,
8177 case SCTP_PARTIAL_DELIVERY_POINT
:
8178 retval
= sctp_getsockopt_partial_delivery_point(sk
, len
, optval
,
8181 case SCTP_MAX_BURST
:
8182 retval
= sctp_getsockopt_maxburst(sk
, len
, optval
, optlen
);
8185 case SCTP_AUTH_CHUNK
:
8186 case SCTP_AUTH_DELETE_KEY
:
8187 case SCTP_AUTH_DEACTIVATE_KEY
:
8188 retval
= -EOPNOTSUPP
;
8190 case SCTP_HMAC_IDENT
:
8191 retval
= sctp_getsockopt_hmac_ident(sk
, len
, optval
, optlen
);
8193 case SCTP_AUTH_ACTIVE_KEY
:
8194 retval
= sctp_getsockopt_active_key(sk
, len
, optval
, optlen
);
8196 case SCTP_PEER_AUTH_CHUNKS
:
8197 retval
= sctp_getsockopt_peer_auth_chunks(sk
, len
, optval
,
8200 case SCTP_LOCAL_AUTH_CHUNKS
:
8201 retval
= sctp_getsockopt_local_auth_chunks(sk
, len
, optval
,
8204 case SCTP_GET_ASSOC_NUMBER
:
8205 retval
= sctp_getsockopt_assoc_number(sk
, len
, optval
, optlen
);
8207 case SCTP_GET_ASSOC_ID_LIST
:
8208 retval
= sctp_getsockopt_assoc_ids(sk
, len
, optval
, optlen
);
8210 case SCTP_AUTO_ASCONF
:
8211 retval
= sctp_getsockopt_auto_asconf(sk
, len
, optval
, optlen
);
8213 case SCTP_PEER_ADDR_THLDS
:
8214 retval
= sctp_getsockopt_paddr_thresholds(sk
, optval
, len
,
8217 case SCTP_PEER_ADDR_THLDS_V2
:
8218 retval
= sctp_getsockopt_paddr_thresholds(sk
, optval
, len
,
8221 case SCTP_GET_ASSOC_STATS
:
8222 retval
= sctp_getsockopt_assoc_stats(sk
, len
, optval
, optlen
);
8224 case SCTP_RECVRCVINFO
:
8225 retval
= sctp_getsockopt_recvrcvinfo(sk
, len
, optval
, optlen
);
8227 case SCTP_RECVNXTINFO
:
8228 retval
= sctp_getsockopt_recvnxtinfo(sk
, len
, optval
, optlen
);
8230 case SCTP_PR_SUPPORTED
:
8231 retval
= sctp_getsockopt_pr_supported(sk
, len
, optval
, optlen
);
8233 case SCTP_DEFAULT_PRINFO
:
8234 retval
= sctp_getsockopt_default_prinfo(sk
, len
, optval
,
8237 case SCTP_PR_ASSOC_STATUS
:
8238 retval
= sctp_getsockopt_pr_assocstatus(sk
, len
, optval
,
8241 case SCTP_PR_STREAM_STATUS
:
8242 retval
= sctp_getsockopt_pr_streamstatus(sk
, len
, optval
,
8245 case SCTP_RECONFIG_SUPPORTED
:
8246 retval
= sctp_getsockopt_reconfig_supported(sk
, len
, optval
,
8249 case SCTP_ENABLE_STREAM_RESET
:
8250 retval
= sctp_getsockopt_enable_strreset(sk
, len
, optval
,
8253 case SCTP_STREAM_SCHEDULER
:
8254 retval
= sctp_getsockopt_scheduler(sk
, len
, optval
,
8257 case SCTP_STREAM_SCHEDULER_VALUE
:
8258 retval
= sctp_getsockopt_scheduler_value(sk
, len
, optval
,
8261 case SCTP_INTERLEAVING_SUPPORTED
:
8262 retval
= sctp_getsockopt_interleaving_supported(sk
, len
, optval
,
8265 case SCTP_REUSE_PORT
:
8266 retval
= sctp_getsockopt_reuse_port(sk
, len
, optval
, optlen
);
8269 retval
= sctp_getsockopt_event(sk
, len
, optval
, optlen
);
8271 case SCTP_ASCONF_SUPPORTED
:
8272 retval
= sctp_getsockopt_asconf_supported(sk
, len
, optval
,
8275 case SCTP_AUTH_SUPPORTED
:
8276 retval
= sctp_getsockopt_auth_supported(sk
, len
, optval
,
8279 case SCTP_ECN_SUPPORTED
:
8280 retval
= sctp_getsockopt_ecn_supported(sk
, len
, optval
, optlen
);
8282 case SCTP_EXPOSE_POTENTIALLY_FAILED_STATE
:
8283 retval
= sctp_getsockopt_pf_expose(sk
, len
, optval
, optlen
);
8285 case SCTP_REMOTE_UDP_ENCAPS_PORT
:
8286 retval
= sctp_getsockopt_encap_port(sk
, len
, optval
, optlen
);
8288 case SCTP_PLPMTUD_PROBE_INTERVAL
:
8289 retval
= sctp_getsockopt_probe_interval(sk
, len
, optval
, optlen
);
8292 retval
= -ENOPROTOOPT
;
8300 static bool sctp_bpf_bypass_getsockopt(int level
, int optname
)
8302 if (level
== SOL_SCTP
) {
8304 case SCTP_SOCKOPT_PEELOFF
:
8305 case SCTP_SOCKOPT_PEELOFF_FLAGS
:
8306 case SCTP_SOCKOPT_CONNECTX3
:
8316 static int sctp_hash(struct sock
*sk
)
8322 static void sctp_unhash(struct sock
*sk
)
8324 sock_rps_delete_flow(sk
);
8327 /* Check if port is acceptable. Possibly find first available port.
8329 * The port hash table (contained in the 'global' SCTP protocol storage
8330 * returned by struct sctp_protocol *sctp_get_protocol()). The hash
8331 * table is an array of 4096 lists (sctp_bind_hashbucket). Each
8332 * list (the list number is the port number hashed out, so as you
8333 * would expect from a hash function, all the ports in a given list have
8334 * such a number that hashes out to the same list number; you were
8335 * expecting that, right?); so each list has a set of ports, with a
8336 * link to the socket (struct sock) that uses it, the port number and
8337 * a fastreuse flag (FIXME: NPI ipg).
8339 static struct sctp_bind_bucket
*sctp_bucket_create(
8340 struct sctp_bind_hashbucket
*head
, struct net
*, unsigned short snum
);
8342 static int sctp_get_port_local(struct sock
*sk
, union sctp_addr
*addr
)
8344 struct sctp_sock
*sp
= sctp_sk(sk
);
8345 bool reuse
= (sk
->sk_reuse
|| sp
->reuse
);
8346 struct sctp_bind_hashbucket
*head
; /* hash list */
8347 struct net
*net
= sock_net(sk
);
8348 kuid_t uid
= sock_i_uid(sk
);
8349 struct sctp_bind_bucket
*pp
;
8350 unsigned short snum
;
8353 snum
= ntohs(addr
->v4
.sin_port
);
8355 pr_debug("%s: begins, snum:%d\n", __func__
, snum
);
8358 /* Search for an available port. */
8359 int low
, high
, remaining
, index
;
8362 inet_sk_get_local_port_range(sk
, &low
, &high
);
8363 remaining
= (high
- low
) + 1;
8364 rover
= get_random_u32_below(remaining
) + low
;
8368 if ((rover
< low
) || (rover
> high
))
8370 if (inet_is_local_reserved_port(net
, rover
))
8372 index
= sctp_phashfn(net
, rover
);
8373 head
= &sctp_port_hashtable
[index
];
8374 spin_lock_bh(&head
->lock
);
8375 sctp_for_each_hentry(pp
, &head
->chain
)
8376 if ((pp
->port
== rover
) &&
8377 net_eq(net
, pp
->net
))
8381 spin_unlock_bh(&head
->lock
);
8383 } while (--remaining
> 0);
8385 /* Exhausted local port range during search? */
8390 /* OK, here is the one we will use. HEAD (the port
8391 * hash table list entry) is non-NULL and we hold it's
8396 /* We are given an specific port number; we verify
8397 * that it is not being used. If it is used, we will
8398 * exahust the search in the hash list corresponding
8399 * to the port number (snum) - we detect that with the
8400 * port iterator, pp being NULL.
8402 head
= &sctp_port_hashtable
[sctp_phashfn(net
, snum
)];
8403 spin_lock_bh(&head
->lock
);
8404 sctp_for_each_hentry(pp
, &head
->chain
) {
8405 if ((pp
->port
== snum
) && net_eq(pp
->net
, net
))
8412 if (!hlist_empty(&pp
->owner
)) {
8413 /* We had a port hash table hit - there is an
8414 * available port (pp != NULL) and it is being
8415 * used by other socket (pp->owner not empty); that other
8416 * socket is going to be sk2.
8420 pr_debug("%s: found a possible match\n", __func__
);
8422 if ((pp
->fastreuse
&& reuse
&&
8423 sk
->sk_state
!= SCTP_SS_LISTENING
) ||
8424 (pp
->fastreuseport
&& sk
->sk_reuseport
&&
8425 uid_eq(pp
->fastuid
, uid
)))
8428 /* Run through the list of sockets bound to the port
8429 * (pp->port) [via the pointers bind_next and
8430 * bind_pprev in the struct sock *sk2 (pp->sk)]. On each one,
8431 * we get the endpoint they describe and run through
8432 * the endpoint's list of IP (v4 or v6) addresses,
8433 * comparing each of the addresses with the address of
8434 * the socket sk. If we find a match, then that means
8435 * that this port/socket (sk) combination are already
8438 sk_for_each_bound(sk2
, &pp
->owner
) {
8439 int bound_dev_if2
= READ_ONCE(sk2
->sk_bound_dev_if
);
8440 struct sctp_sock
*sp2
= sctp_sk(sk2
);
8441 struct sctp_endpoint
*ep2
= sp2
->ep
;
8444 (reuse
&& (sk2
->sk_reuse
|| sp2
->reuse
) &&
8445 sk2
->sk_state
!= SCTP_SS_LISTENING
) ||
8446 (sk
->sk_reuseport
&& sk2
->sk_reuseport
&&
8447 uid_eq(uid
, sock_i_uid(sk2
))))
8450 if ((!sk
->sk_bound_dev_if
|| !bound_dev_if2
||
8451 sk
->sk_bound_dev_if
== bound_dev_if2
) &&
8452 sctp_bind_addr_conflict(&ep2
->base
.bind_addr
,
8459 pr_debug("%s: found a match\n", __func__
);
8462 /* If there was a hash table miss, create a new port. */
8464 if (!pp
&& !(pp
= sctp_bucket_create(head
, net
, snum
)))
8467 /* In either case (hit or miss), make sure fastreuse is 1 only
8468 * if sk->sk_reuse is too (that is, if the caller requested
8469 * SO_REUSEADDR on this socket -sk-).
8471 if (hlist_empty(&pp
->owner
)) {
8472 if (reuse
&& sk
->sk_state
!= SCTP_SS_LISTENING
)
8477 if (sk
->sk_reuseport
) {
8478 pp
->fastreuseport
= 1;
8481 pp
->fastreuseport
= 0;
8484 if (pp
->fastreuse
&&
8485 (!reuse
|| sk
->sk_state
== SCTP_SS_LISTENING
))
8488 if (pp
->fastreuseport
&&
8489 (!sk
->sk_reuseport
|| !uid_eq(pp
->fastuid
, uid
)))
8490 pp
->fastreuseport
= 0;
8493 /* We are set, so fill up all the data in the hash table
8494 * entry, tie the socket list information with the rest of the
8495 * sockets FIXME: Blurry, NPI (ipg).
8498 if (!sp
->bind_hash
) {
8499 inet_sk(sk
)->inet_num
= snum
;
8500 sk_add_bind_node(sk
, &pp
->owner
);
8506 spin_unlock_bh(&head
->lock
);
8510 /* Assign a 'snum' port to the socket. If snum == 0, an ephemeral
8511 * port is requested.
8513 static int sctp_get_port(struct sock
*sk
, unsigned short snum
)
8515 union sctp_addr addr
;
8516 struct sctp_af
*af
= sctp_sk(sk
)->pf
->af
;
8518 /* Set up a dummy address struct from the sk. */
8519 af
->from_sk(&addr
, sk
);
8520 addr
.v4
.sin_port
= htons(snum
);
8522 /* Note: sk->sk_num gets filled in if ephemeral port request. */
8523 return sctp_get_port_local(sk
, &addr
);
8527 * Move a socket to LISTENING state.
8529 static int sctp_listen_start(struct sock
*sk
, int backlog
)
8531 struct sctp_sock
*sp
= sctp_sk(sk
);
8532 struct sctp_endpoint
*ep
= sp
->ep
;
8533 struct crypto_shash
*tfm
= NULL
;
8537 /* Allocate HMAC for generating cookie. */
8538 if (!sp
->hmac
&& sp
->sctp_hmac_alg
) {
8539 sprintf(alg
, "hmac(%s)", sp
->sctp_hmac_alg
);
8540 tfm
= crypto_alloc_shash(alg
, 0, 0);
8542 net_info_ratelimited("failed to load transform for %s: %ld\n",
8543 sp
->sctp_hmac_alg
, PTR_ERR(tfm
));
8546 sctp_sk(sk
)->hmac
= tfm
;
8550 * If a bind() or sctp_bindx() is not called prior to a listen()
8551 * call that allows new associations to be accepted, the system
8552 * picks an ephemeral port and will choose an address set equivalent
8553 * to binding with a wildcard address.
8555 * This is not currently spelled out in the SCTP sockets
8556 * extensions draft, but follows the practice as seen in TCP
8560 inet_sk_set_state(sk
, SCTP_SS_LISTENING
);
8561 if (!ep
->base
.bind_addr
.port
) {
8562 if (sctp_autobind(sk
)) {
8567 if (sctp_get_port(sk
, inet_sk(sk
)->inet_num
)) {
8573 WRITE_ONCE(sk
->sk_max_ack_backlog
, backlog
);
8574 err
= sctp_hash_endpoint(ep
);
8580 inet_sk_set_state(sk
, SCTP_SS_CLOSED
);
8585 * 4.1.3 / 5.1.3 listen()
8587 * By default, new associations are not accepted for UDP style sockets.
8588 * An application uses listen() to mark a socket as being able to
8589 * accept new associations.
8591 * On TCP style sockets, applications use listen() to ready the SCTP
8592 * endpoint for accepting inbound associations.
8594 * On both types of endpoints a backlog of '0' disables listening.
8596 * Move a socket to LISTENING state.
8598 int sctp_inet_listen(struct socket
*sock
, int backlog
)
8600 struct sock
*sk
= sock
->sk
;
8601 struct sctp_endpoint
*ep
= sctp_sk(sk
)->ep
;
8604 if (unlikely(backlog
< 0))
8609 /* Peeled-off sockets are not allowed to listen(). */
8610 if (sctp_style(sk
, UDP_HIGH_BANDWIDTH
))
8613 if (sock
->state
!= SS_UNCONNECTED
)
8616 if (!sctp_sstate(sk
, LISTENING
) && !sctp_sstate(sk
, CLOSED
))
8619 /* If backlog is zero, disable listening. */
8621 if (sctp_sstate(sk
, CLOSED
))
8625 sctp_unhash_endpoint(ep
);
8626 sk
->sk_state
= SCTP_SS_CLOSED
;
8627 if (sk
->sk_reuse
|| sctp_sk(sk
)->reuse
)
8628 sctp_sk(sk
)->bind_hash
->fastreuse
= 1;
8632 /* If we are already listening, just update the backlog */
8633 if (sctp_sstate(sk
, LISTENING
))
8634 WRITE_ONCE(sk
->sk_max_ack_backlog
, backlog
);
8636 err
= sctp_listen_start(sk
, backlog
);
8648 * This function is done by modeling the current datagram_poll() and the
8649 * tcp_poll(). Note that, based on these implementations, we don't
8650 * lock the socket in this function, even though it seems that,
8651 * ideally, locking or some other mechanisms can be used to ensure
8652 * the integrity of the counters (sndbuf and wmem_alloc) used
8653 * in this place. We assume that we don't need locks either until proven
8656 * Another thing to note is that we include the Async I/O support
8657 * here, again, by modeling the current TCP/UDP code. We don't have
8658 * a good way to test with it yet.
8660 __poll_t
sctp_poll(struct file
*file
, struct socket
*sock
, poll_table
*wait
)
8662 struct sock
*sk
= sock
->sk
;
8663 struct sctp_sock
*sp
= sctp_sk(sk
);
8666 poll_wait(file
, sk_sleep(sk
), wait
);
8668 sock_rps_record_flow(sk
);
8670 /* A TCP-style listening socket becomes readable when the accept queue
8673 if (sctp_style(sk
, TCP
) && sctp_sstate(sk
, LISTENING
))
8674 return (!list_empty(&sp
->ep
->asocs
)) ?
8675 (EPOLLIN
| EPOLLRDNORM
) : 0;
8679 /* Is there any exceptional events? */
8680 if (sk
->sk_err
|| !skb_queue_empty_lockless(&sk
->sk_error_queue
))
8682 (sock_flag(sk
, SOCK_SELECT_ERR_QUEUE
) ? EPOLLPRI
: 0);
8683 if (sk
->sk_shutdown
& RCV_SHUTDOWN
)
8684 mask
|= EPOLLRDHUP
| EPOLLIN
| EPOLLRDNORM
;
8685 if (sk
->sk_shutdown
== SHUTDOWN_MASK
)
8688 /* Is it readable? Reconsider this code with TCP-style support. */
8689 if (!skb_queue_empty_lockless(&sk
->sk_receive_queue
))
8690 mask
|= EPOLLIN
| EPOLLRDNORM
;
8692 /* The association is either gone or not ready. */
8693 if (!sctp_style(sk
, UDP
) && sctp_sstate(sk
, CLOSED
))
8696 /* Is it writable? */
8697 if (sctp_writeable(sk
)) {
8698 mask
|= EPOLLOUT
| EPOLLWRNORM
;
8700 sk_set_bit(SOCKWQ_ASYNC_NOSPACE
, sk
);
8702 * Since the socket is not locked, the buffer
8703 * might be made available after the writeable check and
8704 * before the bit is set. This could cause a lost I/O
8705 * signal. tcp_poll() has a race breaker for this race
8706 * condition. Based on their implementation, we put
8707 * in the following code to cover it as well.
8709 if (sctp_writeable(sk
))
8710 mask
|= EPOLLOUT
| EPOLLWRNORM
;
8715 /********************************************************************
8716 * 2nd Level Abstractions
8717 ********************************************************************/
8719 static struct sctp_bind_bucket
*sctp_bucket_create(
8720 struct sctp_bind_hashbucket
*head
, struct net
*net
, unsigned short snum
)
8722 struct sctp_bind_bucket
*pp
;
8724 pp
= kmem_cache_alloc(sctp_bucket_cachep
, GFP_ATOMIC
);
8726 SCTP_DBG_OBJCNT_INC(bind_bucket
);
8729 INIT_HLIST_HEAD(&pp
->owner
);
8731 hlist_add_head(&pp
->node
, &head
->chain
);
8736 /* Caller must hold hashbucket lock for this tb with local BH disabled */
8737 static void sctp_bucket_destroy(struct sctp_bind_bucket
*pp
)
8739 if (pp
&& hlist_empty(&pp
->owner
)) {
8740 __hlist_del(&pp
->node
);
8741 kmem_cache_free(sctp_bucket_cachep
, pp
);
8742 SCTP_DBG_OBJCNT_DEC(bind_bucket
);
8746 /* Release this socket's reference to a local port. */
8747 static inline void __sctp_put_port(struct sock
*sk
)
8749 struct sctp_bind_hashbucket
*head
=
8750 &sctp_port_hashtable
[sctp_phashfn(sock_net(sk
),
8751 inet_sk(sk
)->inet_num
)];
8752 struct sctp_bind_bucket
*pp
;
8754 spin_lock(&head
->lock
);
8755 pp
= sctp_sk(sk
)->bind_hash
;
8756 __sk_del_bind_node(sk
);
8757 sctp_sk(sk
)->bind_hash
= NULL
;
8758 inet_sk(sk
)->inet_num
= 0;
8759 sctp_bucket_destroy(pp
);
8760 spin_unlock(&head
->lock
);
8763 void sctp_put_port(struct sock
*sk
)
8766 __sctp_put_port(sk
);
8771 * The system picks an ephemeral port and choose an address set equivalent
8772 * to binding with a wildcard address.
8773 * One of those addresses will be the primary address for the association.
8774 * This automatically enables the multihoming capability of SCTP.
8776 static int sctp_autobind(struct sock
*sk
)
8778 union sctp_addr autoaddr
;
8782 /* Initialize a local sockaddr structure to INADDR_ANY. */
8783 af
= sctp_sk(sk
)->pf
->af
;
8785 port
= htons(inet_sk(sk
)->inet_num
);
8786 af
->inaddr_any(&autoaddr
, port
);
8788 return sctp_do_bind(sk
, &autoaddr
, af
->sockaddr_len
);
8791 /* Parse out IPPROTO_SCTP CMSG headers. Perform only minimal validation.
8794 * 4.2 The cmsghdr Structure *
8796 * When ancillary data is sent or received, any number of ancillary data
8797 * objects can be specified by the msg_control and msg_controllen members of
8798 * the msghdr structure, because each object is preceded by
8799 * a cmsghdr structure defining the object's length (the cmsg_len member).
8800 * Historically Berkeley-derived implementations have passed only one object
8801 * at a time, but this API allows multiple objects to be
8802 * passed in a single call to sendmsg() or recvmsg(). The following example
8803 * shows two ancillary data objects in a control buffer.
8805 * |<--------------------------- msg_controllen -------------------------->|
8808 * |<----- ancillary data object ----->|<----- ancillary data object ----->|
8810 * |<---------- CMSG_SPACE() --------->|<---------- CMSG_SPACE() --------->|
8813 * |<---------- cmsg_len ---------->| |<--------- cmsg_len ----------->| |
8815 * |<--------- CMSG_LEN() --------->| |<-------- CMSG_LEN() ---------->| |
8818 * +-----+-----+-----+--+-----------+--+-----+-----+-----+--+-----------+--+
8819 * |cmsg_|cmsg_|cmsg_|XX| |XX|cmsg_|cmsg_|cmsg_|XX| |XX|
8821 * |len |level|type |XX|cmsg_data[]|XX|len |level|type |XX|cmsg_data[]|XX|
8823 * +-----+-----+-----+--+-----------+--+-----+-----+-----+--+-----------+--+
8830 static int sctp_msghdr_parse(const struct msghdr
*msg
, struct sctp_cmsgs
*cmsgs
)
8832 struct msghdr
*my_msg
= (struct msghdr
*)msg
;
8833 struct cmsghdr
*cmsg
;
8835 for_each_cmsghdr(cmsg
, my_msg
) {
8836 if (!CMSG_OK(my_msg
, cmsg
))
8839 /* Should we parse this header or ignore? */
8840 if (cmsg
->cmsg_level
!= IPPROTO_SCTP
)
8843 /* Strictly check lengths following example in SCM code. */
8844 switch (cmsg
->cmsg_type
) {
8846 /* SCTP Socket API Extension
8847 * 5.3.1 SCTP Initiation Structure (SCTP_INIT)
8849 * This cmsghdr structure provides information for
8850 * initializing new SCTP associations with sendmsg().
8851 * The SCTP_INITMSG socket option uses this same data
8852 * structure. This structure is not used for
8855 * cmsg_level cmsg_type cmsg_data[]
8856 * ------------ ------------ ----------------------
8857 * IPPROTO_SCTP SCTP_INIT struct sctp_initmsg
8859 if (cmsg
->cmsg_len
!= CMSG_LEN(sizeof(struct sctp_initmsg
)))
8862 cmsgs
->init
= CMSG_DATA(cmsg
);
8866 /* SCTP Socket API Extension
8867 * 5.3.2 SCTP Header Information Structure(SCTP_SNDRCV)
8869 * This cmsghdr structure specifies SCTP options for
8870 * sendmsg() and describes SCTP header information
8871 * about a received message through recvmsg().
8873 * cmsg_level cmsg_type cmsg_data[]
8874 * ------------ ------------ ----------------------
8875 * IPPROTO_SCTP SCTP_SNDRCV struct sctp_sndrcvinfo
8877 if (cmsg
->cmsg_len
!= CMSG_LEN(sizeof(struct sctp_sndrcvinfo
)))
8880 cmsgs
->srinfo
= CMSG_DATA(cmsg
);
8882 if (cmsgs
->srinfo
->sinfo_flags
&
8883 ~(SCTP_UNORDERED
| SCTP_ADDR_OVER
|
8884 SCTP_SACK_IMMEDIATELY
| SCTP_SENDALL
|
8885 SCTP_PR_SCTP_MASK
| SCTP_ABORT
| SCTP_EOF
))
8890 /* SCTP Socket API Extension
8891 * 5.3.4 SCTP Send Information Structure (SCTP_SNDINFO)
8893 * This cmsghdr structure specifies SCTP options for
8894 * sendmsg(). This structure and SCTP_RCVINFO replaces
8895 * SCTP_SNDRCV which has been deprecated.
8897 * cmsg_level cmsg_type cmsg_data[]
8898 * ------------ ------------ ---------------------
8899 * IPPROTO_SCTP SCTP_SNDINFO struct sctp_sndinfo
8901 if (cmsg
->cmsg_len
!= CMSG_LEN(sizeof(struct sctp_sndinfo
)))
8904 cmsgs
->sinfo
= CMSG_DATA(cmsg
);
8906 if (cmsgs
->sinfo
->snd_flags
&
8907 ~(SCTP_UNORDERED
| SCTP_ADDR_OVER
|
8908 SCTP_SACK_IMMEDIATELY
| SCTP_SENDALL
|
8909 SCTP_PR_SCTP_MASK
| SCTP_ABORT
| SCTP_EOF
))
8913 /* SCTP Socket API Extension
8914 * 5.3.7 SCTP PR-SCTP Information Structure (SCTP_PRINFO)
8916 * This cmsghdr structure specifies SCTP options for sendmsg().
8918 * cmsg_level cmsg_type cmsg_data[]
8919 * ------------ ------------ ---------------------
8920 * IPPROTO_SCTP SCTP_PRINFO struct sctp_prinfo
8922 if (cmsg
->cmsg_len
!= CMSG_LEN(sizeof(struct sctp_prinfo
)))
8925 cmsgs
->prinfo
= CMSG_DATA(cmsg
);
8926 if (cmsgs
->prinfo
->pr_policy
& ~SCTP_PR_SCTP_MASK
)
8929 if (cmsgs
->prinfo
->pr_policy
== SCTP_PR_SCTP_NONE
)
8930 cmsgs
->prinfo
->pr_value
= 0;
8933 /* SCTP Socket API Extension
8934 * 5.3.8 SCTP AUTH Information Structure (SCTP_AUTHINFO)
8936 * This cmsghdr structure specifies SCTP options for sendmsg().
8938 * cmsg_level cmsg_type cmsg_data[]
8939 * ------------ ------------ ---------------------
8940 * IPPROTO_SCTP SCTP_AUTHINFO struct sctp_authinfo
8942 if (cmsg
->cmsg_len
!= CMSG_LEN(sizeof(struct sctp_authinfo
)))
8945 cmsgs
->authinfo
= CMSG_DATA(cmsg
);
8947 case SCTP_DSTADDRV4
:
8948 case SCTP_DSTADDRV6
:
8949 /* SCTP Socket API Extension
8950 * 5.3.9/10 SCTP Destination IPv4/6 Address Structure (SCTP_DSTADDRV4/6)
8952 * This cmsghdr structure specifies SCTP options for sendmsg().
8954 * cmsg_level cmsg_type cmsg_data[]
8955 * ------------ ------------ ---------------------
8956 * IPPROTO_SCTP SCTP_DSTADDRV4 struct in_addr
8957 * ------------ ------------ ---------------------
8958 * IPPROTO_SCTP SCTP_DSTADDRV6 struct in6_addr
8960 cmsgs
->addrs_msg
= my_msg
;
8971 * Wait for a packet..
8972 * Note: This function is the same function as in core/datagram.c
8973 * with a few modifications to make lksctp work.
8975 static int sctp_wait_for_packet(struct sock
*sk
, int *err
, long *timeo_p
)
8980 prepare_to_wait_exclusive(sk_sleep(sk
), &wait
, TASK_INTERRUPTIBLE
);
8982 /* Socket errors? */
8983 error
= sock_error(sk
);
8987 if (!skb_queue_empty(&sk
->sk_receive_queue
))
8990 /* Socket shut down? */
8991 if (sk
->sk_shutdown
& RCV_SHUTDOWN
)
8994 /* Sequenced packets can come disconnected. If so we report the
8999 /* Is there a good reason to think that we may receive some data? */
9000 if (list_empty(&sctp_sk(sk
)->ep
->asocs
) && !sctp_sstate(sk
, LISTENING
))
9003 /* Handle signals. */
9004 if (signal_pending(current
))
9007 /* Let another process have a go. Since we are going to sleep
9008 * anyway. Note: This may cause odd behaviors if the message
9009 * does not fit in the user's buffer, but this seems to be the
9010 * only way to honor MSG_DONTWAIT realistically.
9013 *timeo_p
= schedule_timeout(*timeo_p
);
9017 finish_wait(sk_sleep(sk
), &wait
);
9021 error
= sock_intr_errno(*timeo_p
);
9024 finish_wait(sk_sleep(sk
), &wait
);
9029 /* Receive a datagram.
9030 * Note: This is pretty much the same routine as in core/datagram.c
9031 * with a few changes to make lksctp work.
9033 struct sk_buff
*sctp_skb_recv_datagram(struct sock
*sk
, int flags
, int *err
)
9036 struct sk_buff
*skb
;
9039 timeo
= sock_rcvtimeo(sk
, flags
& MSG_DONTWAIT
);
9041 pr_debug("%s: timeo:%ld, max:%ld\n", __func__
, timeo
,
9042 MAX_SCHEDULE_TIMEOUT
);
9045 /* Again only user level code calls this function,
9046 * so nothing interrupt level
9047 * will suddenly eat the receive_queue.
9049 * Look at current nfs client by the way...
9050 * However, this function was correct in any case. 8)
9052 if (flags
& MSG_PEEK
) {
9053 skb
= skb_peek(&sk
->sk_receive_queue
);
9055 refcount_inc(&skb
->users
);
9057 skb
= __skb_dequeue(&sk
->sk_receive_queue
);
9063 /* Caller is allowed not to check sk->sk_err before calling. */
9064 error
= sock_error(sk
);
9068 if (sk
->sk_shutdown
& RCV_SHUTDOWN
)
9072 /* User doesn't want to wait. */
9076 } while (sctp_wait_for_packet(sk
, err
, &timeo
) == 0);
9085 /* If sndbuf has changed, wake up per association sndbuf waiters. */
9086 static void __sctp_write_space(struct sctp_association
*asoc
)
9088 struct sock
*sk
= asoc
->base
.sk
;
9090 if (sctp_wspace(asoc
) <= 0)
9093 if (waitqueue_active(&asoc
->wait
))
9094 wake_up_interruptible(&asoc
->wait
);
9096 if (sctp_writeable(sk
)) {
9097 struct socket_wq
*wq
;
9100 wq
= rcu_dereference(sk
->sk_wq
);
9102 if (waitqueue_active(&wq
->wait
))
9103 wake_up_interruptible_poll(&wq
->wait
, EPOLLOUT
|
9104 EPOLLWRNORM
| EPOLLWRBAND
);
9106 /* Note that we try to include the Async I/O support
9107 * here by modeling from the current TCP/UDP code.
9108 * We have not tested with it yet.
9110 if (!(sk
->sk_shutdown
& SEND_SHUTDOWN
))
9111 sock_wake_async(wq
, SOCK_WAKE_SPACE
, POLL_OUT
);
9117 static void sctp_wake_up_waiters(struct sock
*sk
,
9118 struct sctp_association
*asoc
)
9120 struct sctp_association
*tmp
= asoc
;
9122 /* We do accounting for the sndbuf space per association,
9123 * so we only need to wake our own association.
9125 if (asoc
->ep
->sndbuf_policy
)
9126 return __sctp_write_space(asoc
);
9128 /* If association goes down and is just flushing its
9129 * outq, then just normally notify others.
9131 if (asoc
->base
.dead
)
9132 return sctp_write_space(sk
);
9134 /* Accounting for the sndbuf space is per socket, so we
9135 * need to wake up others, try to be fair and in case of
9136 * other associations, let them have a go first instead
9137 * of just doing a sctp_write_space() call.
9139 * Note that we reach sctp_wake_up_waiters() only when
9140 * associations free up queued chunks, thus we are under
9141 * lock and the list of associations on a socket is
9142 * guaranteed not to change.
9144 for (tmp
= list_next_entry(tmp
, asocs
); 1;
9145 tmp
= list_next_entry(tmp
, asocs
)) {
9146 /* Manually skip the head element. */
9147 if (&tmp
->asocs
== &((sctp_sk(sk
))->ep
->asocs
))
9149 /* Wake up association. */
9150 __sctp_write_space(tmp
);
9151 /* We've reached the end. */
9157 /* Do accounting for the sndbuf space.
9158 * Decrement the used sndbuf space of the corresponding association by the
9159 * data size which was just transmitted(freed).
9161 static void sctp_wfree(struct sk_buff
*skb
)
9163 struct sctp_chunk
*chunk
= skb_shinfo(skb
)->destructor_arg
;
9164 struct sctp_association
*asoc
= chunk
->asoc
;
9165 struct sock
*sk
= asoc
->base
.sk
;
9167 sk_mem_uncharge(sk
, skb
->truesize
);
9168 sk_wmem_queued_add(sk
, -(skb
->truesize
+ sizeof(struct sctp_chunk
)));
9169 asoc
->sndbuf_used
-= skb
->truesize
+ sizeof(struct sctp_chunk
);
9170 WARN_ON(refcount_sub_and_test(sizeof(struct sctp_chunk
),
9171 &sk
->sk_wmem_alloc
));
9174 struct sctp_shared_key
*shkey
= chunk
->shkey
;
9176 /* refcnt == 2 and !list_empty mean after this release, it's
9177 * not being used anywhere, and it's time to notify userland
9178 * that this shkey can be freed if it's been deactivated.
9180 if (shkey
->deactivated
&& !list_empty(&shkey
->key_list
) &&
9181 refcount_read(&shkey
->refcnt
) == 2) {
9182 struct sctp_ulpevent
*ev
;
9184 ev
= sctp_ulpevent_make_authkey(asoc
, shkey
->key_id
,
9188 asoc
->stream
.si
->enqueue_event(&asoc
->ulpq
, ev
);
9190 sctp_auth_shkey_release(chunk
->shkey
);
9194 sctp_wake_up_waiters(sk
, asoc
);
9196 sctp_association_put(asoc
);
9199 /* Do accounting for the receive space on the socket.
9200 * Accounting for the association is done in ulpevent.c
9201 * We set this as a destructor for the cloned data skbs so that
9202 * accounting is done at the correct time.
9204 void sctp_sock_rfree(struct sk_buff
*skb
)
9206 struct sock
*sk
= skb
->sk
;
9207 struct sctp_ulpevent
*event
= sctp_skb2event(skb
);
9209 atomic_sub(event
->rmem_len
, &sk
->sk_rmem_alloc
);
9212 * Mimic the behavior of sock_rfree
9214 sk_mem_uncharge(sk
, event
->rmem_len
);
9218 /* Helper function to wait for space in the sndbuf. */
9219 static int sctp_wait_for_sndbuf(struct sctp_association
*asoc
,
9220 struct sctp_transport
*transport
,
9221 long *timeo_p
, size_t msg_len
)
9223 struct sock
*sk
= asoc
->base
.sk
;
9224 long current_timeo
= *timeo_p
;
9228 pr_debug("%s: asoc:%p, timeo:%ld, msg_len:%zu\n", __func__
, asoc
,
9231 /* Increment the transport and association's refcnt. */
9233 sctp_transport_hold(transport
);
9234 sctp_association_hold(asoc
);
9236 /* Wait on the association specific sndbuf space. */
9238 prepare_to_wait_exclusive(&asoc
->wait
, &wait
,
9239 TASK_INTERRUPTIBLE
);
9240 if (asoc
->base
.dead
)
9242 if ((!*timeo_p
) || (transport
&& transport
->dead
))
9244 if (sk
->sk_err
|| asoc
->state
>= SCTP_STATE_SHUTDOWN_PENDING
)
9246 if (signal_pending(current
))
9247 goto do_interrupted
;
9248 if ((int)msg_len
<= sctp_wspace(asoc
) &&
9249 sk_wmem_schedule(sk
, msg_len
))
9252 /* Let another process have a go. Since we are going
9256 current_timeo
= schedule_timeout(current_timeo
);
9258 if (sk
!= asoc
->base
.sk
)
9261 *timeo_p
= current_timeo
;
9265 finish_wait(&asoc
->wait
, &wait
);
9267 /* Release the transport and association's refcnt. */
9269 sctp_transport_put(transport
);
9270 sctp_association_put(asoc
);
9283 err
= sock_intr_errno(*timeo_p
);
9291 void sctp_data_ready(struct sock
*sk
)
9293 struct socket_wq
*wq
;
9295 trace_sk_data_ready(sk
);
9298 wq
= rcu_dereference(sk
->sk_wq
);
9299 if (skwq_has_sleeper(wq
))
9300 wake_up_interruptible_sync_poll(&wq
->wait
, EPOLLIN
|
9301 EPOLLRDNORM
| EPOLLRDBAND
);
9302 sk_wake_async_rcu(sk
, SOCK_WAKE_WAITD
, POLL_IN
);
9306 /* If socket sndbuf has changed, wake up all per association waiters. */
9307 void sctp_write_space(struct sock
*sk
)
9309 struct sctp_association
*asoc
;
9311 /* Wake up the tasks in each wait queue. */
9312 list_for_each_entry(asoc
, &((sctp_sk(sk
))->ep
->asocs
), asocs
) {
9313 __sctp_write_space(asoc
);
9317 /* Is there any sndbuf space available on the socket?
9319 * Note that sk_wmem_alloc is the sum of the send buffers on all of the
9320 * associations on the same socket. For a UDP-style socket with
9321 * multiple associations, it is possible for it to be "unwriteable"
9322 * prematurely. I assume that this is acceptable because
9323 * a premature "unwriteable" is better than an accidental "writeable" which
9324 * would cause an unwanted block under certain circumstances. For the 1-1
9325 * UDP-style sockets or TCP-style sockets, this code should work.
9328 static bool sctp_writeable(const struct sock
*sk
)
9330 return READ_ONCE(sk
->sk_sndbuf
) > READ_ONCE(sk
->sk_wmem_queued
);
9333 /* Wait for an association to go into ESTABLISHED state. If timeout is 0,
9334 * returns immediately with EINPROGRESS.
9336 static int sctp_wait_for_connect(struct sctp_association
*asoc
, long *timeo_p
)
9338 struct sock
*sk
= asoc
->base
.sk
;
9340 long current_timeo
= *timeo_p
;
9343 pr_debug("%s: asoc:%p, timeo:%ld\n", __func__
, asoc
, *timeo_p
);
9345 /* Increment the association's refcnt. */
9346 sctp_association_hold(asoc
);
9349 prepare_to_wait_exclusive(&asoc
->wait
, &wait
,
9350 TASK_INTERRUPTIBLE
);
9353 if (sk
->sk_shutdown
& RCV_SHUTDOWN
)
9355 if (sk
->sk_err
|| asoc
->state
>= SCTP_STATE_SHUTDOWN_PENDING
||
9358 if (signal_pending(current
))
9359 goto do_interrupted
;
9361 if (sctp_state(asoc
, ESTABLISHED
))
9364 /* Let another process have a go. Since we are going
9368 current_timeo
= schedule_timeout(current_timeo
);
9371 *timeo_p
= current_timeo
;
9375 finish_wait(&asoc
->wait
, &wait
);
9377 /* Release the association's refcnt. */
9378 sctp_association_put(asoc
);
9383 if (asoc
->init_err_counter
+ 1 > asoc
->max_init_attempts
)
9386 err
= -ECONNREFUSED
;
9390 err
= sock_intr_errno(*timeo_p
);
9398 static int sctp_wait_for_accept(struct sock
*sk
, long timeo
)
9400 struct sctp_endpoint
*ep
;
9404 ep
= sctp_sk(sk
)->ep
;
9408 prepare_to_wait_exclusive(sk_sleep(sk
), &wait
,
9409 TASK_INTERRUPTIBLE
);
9411 if (list_empty(&ep
->asocs
)) {
9413 timeo
= schedule_timeout(timeo
);
9418 if (!sctp_sstate(sk
, LISTENING
) ||
9419 (sk
->sk_shutdown
& RCV_SHUTDOWN
))
9423 if (!list_empty(&ep
->asocs
))
9426 err
= sock_intr_errno(timeo
);
9427 if (signal_pending(current
))
9435 finish_wait(sk_sleep(sk
), &wait
);
9440 static void sctp_wait_for_close(struct sock
*sk
, long timeout
)
9445 prepare_to_wait(sk_sleep(sk
), &wait
, TASK_INTERRUPTIBLE
);
9446 if (list_empty(&sctp_sk(sk
)->ep
->asocs
))
9449 timeout
= schedule_timeout(timeout
);
9451 } while (!signal_pending(current
) && timeout
);
9453 finish_wait(sk_sleep(sk
), &wait
);
9456 static void sctp_skb_set_owner_r_frag(struct sk_buff
*skb
, struct sock
*sk
)
9458 struct sk_buff
*frag
;
9463 /* Don't forget the fragments. */
9464 skb_walk_frags(skb
, frag
)
9465 sctp_skb_set_owner_r_frag(frag
, sk
);
9468 sctp_skb_set_owner_r(skb
, sk
);
9471 void sctp_copy_sock(struct sock
*newsk
, struct sock
*sk
,
9472 struct sctp_association
*asoc
)
9474 struct inet_sock
*inet
= inet_sk(sk
);
9475 struct inet_sock
*newinet
;
9476 struct sctp_sock
*sp
= sctp_sk(sk
);
9478 newsk
->sk_type
= sk
->sk_type
;
9479 newsk
->sk_bound_dev_if
= sk
->sk_bound_dev_if
;
9480 newsk
->sk_flags
= sk
->sk_flags
;
9481 newsk
->sk_tsflags
= sk
->sk_tsflags
;
9482 newsk
->sk_no_check_tx
= sk
->sk_no_check_tx
;
9483 newsk
->sk_no_check_rx
= sk
->sk_no_check_rx
;
9484 newsk
->sk_reuse
= sk
->sk_reuse
;
9485 sctp_sk(newsk
)->reuse
= sp
->reuse
;
9487 newsk
->sk_shutdown
= sk
->sk_shutdown
;
9488 newsk
->sk_destruct
= sk
->sk_destruct
;
9489 newsk
->sk_family
= sk
->sk_family
;
9490 newsk
->sk_protocol
= IPPROTO_SCTP
;
9491 newsk
->sk_backlog_rcv
= sk
->sk_prot
->backlog_rcv
;
9492 newsk
->sk_sndbuf
= sk
->sk_sndbuf
;
9493 newsk
->sk_rcvbuf
= sk
->sk_rcvbuf
;
9494 newsk
->sk_lingertime
= sk
->sk_lingertime
;
9495 newsk
->sk_rcvtimeo
= sk
->sk_rcvtimeo
;
9496 newsk
->sk_sndtimeo
= sk
->sk_sndtimeo
;
9497 newsk
->sk_rxhash
= sk
->sk_rxhash
;
9499 newinet
= inet_sk(newsk
);
9501 /* Initialize sk's sport, dport, rcv_saddr and daddr for
9502 * getsockname() and getpeername()
9504 newinet
->inet_sport
= inet
->inet_sport
;
9505 newinet
->inet_saddr
= inet
->inet_saddr
;
9506 newinet
->inet_rcv_saddr
= inet
->inet_rcv_saddr
;
9507 newinet
->inet_dport
= htons(asoc
->peer
.port
);
9508 newinet
->pmtudisc
= inet
->pmtudisc
;
9509 atomic_set(&newinet
->inet_id
, get_random_u16());
9511 newinet
->uc_ttl
= inet
->uc_ttl
;
9512 inet_set_bit(MC_LOOP
, newsk
);
9513 newinet
->mc_ttl
= 1;
9514 newinet
->mc_index
= 0;
9515 newinet
->mc_list
= NULL
;
9517 if (newsk
->sk_flags
& SK_FLAGS_TIMESTAMP
)
9518 net_enable_timestamp();
9520 /* Set newsk security attributes from original sk and connection
9521 * security attribute from asoc.
9523 security_sctp_sk_clone(asoc
, sk
, newsk
);
9526 static inline void sctp_copy_descendant(struct sock
*sk_to
,
9527 const struct sock
*sk_from
)
9529 size_t ancestor_size
= sizeof(struct inet_sock
);
9531 ancestor_size
+= sk_from
->sk_prot
->obj_size
;
9532 ancestor_size
-= offsetof(struct sctp_sock
, pd_lobby
);
9533 __inet_sk_copy_descendant(sk_to
, sk_from
, ancestor_size
);
9536 /* Populate the fields of the newsk from the oldsk and migrate the assoc
9537 * and its messages to the newsk.
9539 static int sctp_sock_migrate(struct sock
*oldsk
, struct sock
*newsk
,
9540 struct sctp_association
*assoc
,
9541 enum sctp_socket_type type
)
9543 struct sctp_sock
*oldsp
= sctp_sk(oldsk
);
9544 struct sctp_sock
*newsp
= sctp_sk(newsk
);
9545 struct sctp_bind_bucket
*pp
; /* hash list port iterator */
9546 struct sctp_endpoint
*newep
= newsp
->ep
;
9547 struct sk_buff
*skb
, *tmp
;
9548 struct sctp_ulpevent
*event
;
9549 struct sctp_bind_hashbucket
*head
;
9552 /* Migrate socket buffer sizes and all the socket level options to the
9555 newsk
->sk_sndbuf
= oldsk
->sk_sndbuf
;
9556 newsk
->sk_rcvbuf
= oldsk
->sk_rcvbuf
;
9557 /* Brute force copy old sctp opt. */
9558 sctp_copy_descendant(newsk
, oldsk
);
9560 /* Restore the ep value that was overwritten with the above structure
9566 /* Hook this new socket in to the bind_hash list. */
9567 head
= &sctp_port_hashtable
[sctp_phashfn(sock_net(oldsk
),
9568 inet_sk(oldsk
)->inet_num
)];
9569 spin_lock_bh(&head
->lock
);
9570 pp
= sctp_sk(oldsk
)->bind_hash
;
9571 sk_add_bind_node(newsk
, &pp
->owner
);
9572 sctp_sk(newsk
)->bind_hash
= pp
;
9573 inet_sk(newsk
)->inet_num
= inet_sk(oldsk
)->inet_num
;
9574 spin_unlock_bh(&head
->lock
);
9576 /* Copy the bind_addr list from the original endpoint to the new
9577 * endpoint so that we can handle restarts properly
9579 err
= sctp_bind_addr_dup(&newsp
->ep
->base
.bind_addr
,
9580 &oldsp
->ep
->base
.bind_addr
, GFP_KERNEL
);
9584 /* New ep's auth_hmacs should be set if old ep's is set, in case
9585 * that net->sctp.auth_enable has been changed to 0 by users and
9586 * new ep's auth_hmacs couldn't be set in sctp_endpoint_init().
9588 if (oldsp
->ep
->auth_hmacs
) {
9589 err
= sctp_auth_init_hmacs(newsp
->ep
, GFP_KERNEL
);
9594 sctp_auto_asconf_init(newsp
);
9596 /* Move any messages in the old socket's receive queue that are for the
9597 * peeled off association to the new socket's receive queue.
9599 sctp_skb_for_each(skb
, &oldsk
->sk_receive_queue
, tmp
) {
9600 event
= sctp_skb2event(skb
);
9601 if (event
->asoc
== assoc
) {
9602 __skb_unlink(skb
, &oldsk
->sk_receive_queue
);
9603 __skb_queue_tail(&newsk
->sk_receive_queue
, skb
);
9604 sctp_skb_set_owner_r_frag(skb
, newsk
);
9608 /* Clean up any messages pending delivery due to partial
9609 * delivery. Three cases:
9610 * 1) No partial deliver; no work.
9611 * 2) Peeling off partial delivery; keep pd_lobby in new pd_lobby.
9612 * 3) Peeling off non-partial delivery; move pd_lobby to receive_queue.
9614 atomic_set(&sctp_sk(newsk
)->pd_mode
, assoc
->ulpq
.pd_mode
);
9616 if (atomic_read(&sctp_sk(oldsk
)->pd_mode
)) {
9617 struct sk_buff_head
*queue
;
9619 /* Decide which queue to move pd_lobby skbs to. */
9620 if (assoc
->ulpq
.pd_mode
) {
9621 queue
= &newsp
->pd_lobby
;
9623 queue
= &newsk
->sk_receive_queue
;
9625 /* Walk through the pd_lobby, looking for skbs that
9626 * need moved to the new socket.
9628 sctp_skb_for_each(skb
, &oldsp
->pd_lobby
, tmp
) {
9629 event
= sctp_skb2event(skb
);
9630 if (event
->asoc
== assoc
) {
9631 __skb_unlink(skb
, &oldsp
->pd_lobby
);
9632 __skb_queue_tail(queue
, skb
);
9633 sctp_skb_set_owner_r_frag(skb
, newsk
);
9637 /* Clear up any skbs waiting for the partial
9638 * delivery to finish.
9640 if (assoc
->ulpq
.pd_mode
)
9641 sctp_clear_pd(oldsk
, NULL
);
9645 sctp_for_each_rx_skb(assoc
, newsk
, sctp_skb_set_owner_r_frag
);
9647 /* Set the type of socket to indicate that it is peeled off from the
9648 * original UDP-style socket or created with the accept() call on a
9649 * TCP-style socket..
9653 /* Mark the new socket "in-use" by the user so that any packets
9654 * that may arrive on the association after we've moved it are
9655 * queued to the backlog. This prevents a potential race between
9656 * backlog processing on the old socket and new-packet processing
9657 * on the new socket.
9659 * The caller has just allocated newsk so we can guarantee that other
9660 * paths won't try to lock it and then oldsk.
9662 lock_sock_nested(newsk
, SINGLE_DEPTH_NESTING
);
9663 sctp_for_each_tx_datachunk(assoc
, true, sctp_clear_owner_w
);
9664 sctp_assoc_migrate(assoc
, newsk
);
9665 sctp_for_each_tx_datachunk(assoc
, false, sctp_set_owner_w
);
9667 /* If the association on the newsk is already closed before accept()
9668 * is called, set RCV_SHUTDOWN flag.
9670 if (sctp_state(assoc
, CLOSED
) && sctp_style(newsk
, TCP
)) {
9671 inet_sk_set_state(newsk
, SCTP_SS_CLOSED
);
9672 newsk
->sk_shutdown
|= RCV_SHUTDOWN
;
9674 inet_sk_set_state(newsk
, SCTP_SS_ESTABLISHED
);
9677 release_sock(newsk
);
9683 /* This proto struct describes the ULP interface for SCTP. */
9684 struct proto sctp_prot
= {
9686 .owner
= THIS_MODULE
,
9687 .close
= sctp_close
,
9688 .disconnect
= sctp_disconnect
,
9689 .accept
= sctp_accept
,
9690 .ioctl
= sctp_ioctl
,
9691 .init
= sctp_init_sock
,
9692 .destroy
= sctp_destroy_sock
,
9693 .shutdown
= sctp_shutdown
,
9694 .setsockopt
= sctp_setsockopt
,
9695 .getsockopt
= sctp_getsockopt
,
9696 .bpf_bypass_getsockopt
= sctp_bpf_bypass_getsockopt
,
9697 .sendmsg
= sctp_sendmsg
,
9698 .recvmsg
= sctp_recvmsg
,
9700 .bind_add
= sctp_bind_add
,
9701 .backlog_rcv
= sctp_backlog_rcv
,
9703 .unhash
= sctp_unhash
,
9704 .no_autobind
= true,
9705 .obj_size
= sizeof(struct sctp_sock
),
9706 .useroffset
= offsetof(struct sctp_sock
, subscribe
),
9707 .usersize
= offsetof(struct sctp_sock
, initmsg
) -
9708 offsetof(struct sctp_sock
, subscribe
) +
9709 sizeof_field(struct sctp_sock
, initmsg
),
9710 .sysctl_mem
= sysctl_sctp_mem
,
9711 .sysctl_rmem
= sysctl_sctp_rmem
,
9712 .sysctl_wmem
= sysctl_sctp_wmem
,
9713 .memory_pressure
= &sctp_memory_pressure
,
9714 .enter_memory_pressure
= sctp_enter_memory_pressure
,
9716 .memory_allocated
= &sctp_memory_allocated
,
9717 .per_cpu_fw_alloc
= &sctp_memory_per_cpu_fw_alloc
,
9719 .sockets_allocated
= &sctp_sockets_allocated
,
9722 #if IS_ENABLED(CONFIG_IPV6)
9724 static void sctp_v6_destruct_sock(struct sock
*sk
)
9726 sctp_destruct_common(sk
);
9727 inet6_sock_destruct(sk
);
9730 static int sctp_v6_init_sock(struct sock
*sk
)
9732 int ret
= sctp_init_sock(sk
);
9735 sk
->sk_destruct
= sctp_v6_destruct_sock
;
9740 struct proto sctpv6_prot
= {
9742 .owner
= THIS_MODULE
,
9743 .close
= sctp_close
,
9744 .disconnect
= sctp_disconnect
,
9745 .accept
= sctp_accept
,
9746 .ioctl
= sctp_ioctl
,
9747 .init
= sctp_v6_init_sock
,
9748 .destroy
= sctp_destroy_sock
,
9749 .shutdown
= sctp_shutdown
,
9750 .setsockopt
= sctp_setsockopt
,
9751 .getsockopt
= sctp_getsockopt
,
9752 .bpf_bypass_getsockopt
= sctp_bpf_bypass_getsockopt
,
9753 .sendmsg
= sctp_sendmsg
,
9754 .recvmsg
= sctp_recvmsg
,
9756 .bind_add
= sctp_bind_add
,
9757 .backlog_rcv
= sctp_backlog_rcv
,
9759 .unhash
= sctp_unhash
,
9760 .no_autobind
= true,
9761 .obj_size
= sizeof(struct sctp6_sock
),
9762 .ipv6_pinfo_offset
= offsetof(struct sctp6_sock
, inet6
),
9763 .useroffset
= offsetof(struct sctp6_sock
, sctp
.subscribe
),
9764 .usersize
= offsetof(struct sctp6_sock
, sctp
.initmsg
) -
9765 offsetof(struct sctp6_sock
, sctp
.subscribe
) +
9766 sizeof_field(struct sctp6_sock
, sctp
.initmsg
),
9767 .sysctl_mem
= sysctl_sctp_mem
,
9768 .sysctl_rmem
= sysctl_sctp_rmem
,
9769 .sysctl_wmem
= sysctl_sctp_wmem
,
9770 .memory_pressure
= &sctp_memory_pressure
,
9771 .enter_memory_pressure
= sctp_enter_memory_pressure
,
9773 .memory_allocated
= &sctp_memory_allocated
,
9774 .per_cpu_fw_alloc
= &sctp_memory_per_cpu_fw_alloc
,
9776 .sockets_allocated
= &sctp_sockets_allocated
,
9778 #endif /* IS_ENABLED(CONFIG_IPV6) */