| 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 |
| 9 |
* |
| 10 |
* This file is part of the SCTP kernel implementation |
| 11 |
* |
| 12 |
* These functions interface with the sockets layer to implement the |
| 13 |
* SCTP Extensions for the Sockets API. |
| 14 |
* |
| 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. |
| 18 |
* |
| 19 |
* Please send any bug reports or fixes you make to the |
| 20 |
* email address(es): |
| 21 |
* lksctp developers <[email protected]> |
| 22 |
* |
| 23 |
* Written or modified by: |
| 24 |
* La Monte H.P. Yarroll <[email protected]> |
| 25 |
* Narasimha Budihal <[email protected]> |
| 26 |
* Karl Knutson <[email protected]> |
| 27 |
* Jon Grimm <[email protected]> |
| 28 |
* Xingang Guo <[email protected]> |
| 29 |
* Daisy Chang <[email protected]> |
| 30 |
* Sridhar Samudrala <[email protected]> |
| 31 |
* Inaky Perez-Gonzalez <[email protected]> |
| 32 |
* Ardelle Fan <[email protected]> |
| 33 |
* Ryan Layer <[email protected]> |
| 34 |
* Anup Pemmaiah <[email protected]> |
| 35 |
* Kevin Gao <[email protected]> |
| 36 |
*/ |
| 37 |
|
| 38 |
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 39 |
|
| 40 |
#include <linux/types.h> |
| 41 |
#include <linux/kernel.h> |
| 42 |
#include <linux/wait.h> |
| 43 |
#include <linux/time.h> |
| 44 |
#include <linux/sched/signal.h> |
| 45 |
#include <linux/ip.h> |
| 46 |
#include <linux/capability.h> |
| 47 |
#include <linux/fcntl.h> |
| 48 |
#include <linux/poll.h> |
| 49 |
#include <linux/init.h> |
| 50 |
#include <linux/slab.h> |
| 51 |
#include <linux/file.h> |
| 52 |
#include <linux/compat.h> |
| 53 |
#include <linux/rhashtable.h> |
| 54 |
|
| 55 |
#include <net/ip.h> |
| 56 |
#include <net/icmp.h> |
| 57 |
#include <net/route.h> |
| 58 |
#include <net/ipv6.h> |
| 59 |
#include <net/inet_common.h> |
| 60 |
#include <net/busy_poll.h> |
| 61 |
#include <trace/events/sock.h> |
| 62 |
|
| 63 |
#include <linux/socket.h> /* for sa_family_t */ |
| 64 |
#include <linux/export.h> |
| 65 |
#include <net/sock.h> |
| 66 |
#include <net/sctp/sctp.h> |
| 67 |
#include <net/sctp/sm.h> |
| 68 |
#include <net/sctp/stream_sched.h> |
| 69 |
#include <net/rps.h> |
| 70 |
|
| 71 |
/* Forward declarations for internal helper functions. */ |
| 72 |
static bool sctp_writeable(const struct sock *sk); |
| 73 |
static void sctp_wfree(struct sk_buff *skb); |
| 74 |
static int sctp_wait_for_sndbuf(struct sctp_association *asoc, |
| 75 |
struct sctp_transport *transport, |
| 76 |
long *timeo_p, size_t msg_len); |
| 77 |
static int sctp_wait_for_packet(struct sock *sk, int *err, long *timeo_p); |
| 78 |
static int sctp_wait_for_connect(struct sctp_association *, long *timeo_p); |
| 79 |
static int sctp_wait_for_accept(struct sock *sk, long timeo); |
| 80 |
static void sctp_wait_for_close(struct sock *sk, long timeo); |
| 81 |
static void sctp_destruct_sock(struct sock *sk); |
| 82 |
static struct sctp_af *sctp_sockaddr_af(struct sctp_sock *opt, |
| 83 |
union sctp_addr *addr, int len); |
| 84 |
static int sctp_bindx_add(struct sock *, struct sockaddr *, int); |
| 85 |
static int sctp_bindx_rem(struct sock *, struct sockaddr *, int); |
| 86 |
static int sctp_send_asconf_add_ip(struct sock *, struct sockaddr *, int); |
| 87 |
static int sctp_send_asconf_del_ip(struct sock *, struct sockaddr *, int); |
| 88 |
static int sctp_send_asconf(struct sctp_association *asoc, |
| 89 |
struct sctp_chunk *chunk); |
| 90 |
static int sctp_do_bind(struct sock *, union sctp_addr *, int); |
| 91 |
static int sctp_autobind(struct sock *sk); |
| 92 |
static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk, |
| 93 |
struct sctp_association *assoc, |
| 94 |
enum sctp_socket_type type); |
| 95 |
|
| 96 |
static unsigned long sctp_memory_pressure; |
| 97 |
static atomic_long_t sctp_memory_allocated; |
| 98 |
static DEFINE_PER_CPU(int, sctp_memory_per_cpu_fw_alloc); |
| 99 |
struct percpu_counter sctp_sockets_allocated; |
| 100 |
|
| 101 |
static void sctp_enter_memory_pressure(struct sock *sk) |
| 102 |
{ |
| 103 |
WRITE_ONCE(sctp_memory_pressure, 1); |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
/* Get the sndbuf space available at the time on the association. */ |
| 108 |
static inline int sctp_wspace(struct sctp_association *asoc) |
| 109 |
{ |
| 110 |
struct sock *sk = asoc->base.sk; |
| 111 |
|
| 112 |
return asoc->ep->sndbuf_policy ? sk->sk_sndbuf - asoc->sndbuf_used |
| 113 |
: sk_stream_wspace(sk); |
| 114 |
} |
| 115 |
|
| 116 |
/* Increment the used sndbuf space count of the corresponding association by |
| 117 |
* the size of the outgoing data chunk. |
| 118 |
* Also, set the skb destructor for sndbuf accounting later. |
| 119 |
* |
| 120 |
* Since it is always 1-1 between chunk and skb, and also a new skb is always |
| 121 |
* allocated for chunk bundling in sctp_packet_transmit(), we can use the |
| 122 |
* destructor in the data chunk skb for the purpose of the sndbuf space |
| 123 |
* tracking. |
| 124 |
*/ |
| 125 |
static inline void sctp_set_owner_w(struct sctp_chunk *chunk) |
| 126 |
{ |
| 127 |
struct sctp_association *asoc = chunk->asoc; |
| 128 |
struct sock *sk = asoc->base.sk; |
| 129 |
|
| 130 |
/* The sndbuf space is tracked per association. */ |
| 131 |
sctp_association_hold(asoc); |
| 132 |
|
| 133 |
if (chunk->shkey) |
| 134 |
sctp_auth_shkey_hold(chunk->shkey); |
| 135 |
|
| 136 |
skb_set_owner_w(chunk->skb, sk); |
| 137 |
|
| 138 |
chunk->skb->destructor = sctp_wfree; |
| 139 |
/* Save the chunk pointer in skb for sctp_wfree to use later. */ |
| 140 |
skb_shinfo(chunk->skb)->destructor_arg = chunk; |
| 141 |
|
| 142 |
refcount_add(sizeof(struct sctp_chunk), &sk->sk_wmem_alloc); |
| 143 |
asoc->sndbuf_used += chunk->skb->truesize + sizeof(struct sctp_chunk); |
| 144 |
sk_wmem_queued_add(sk, chunk->skb->truesize + sizeof(struct sctp_chunk)); |
| 145 |
sk_mem_charge(sk, chunk->skb->truesize); |
| 146 |
} |
| 147 |
|
| 148 |
static void sctp_clear_owner_w(struct sctp_chunk *chunk) |
| 149 |
{ |
| 150 |
skb_orphan(chunk->skb); |
| 151 |
} |
| 152 |
|
| 153 |
#define traverse_and_process() \ |
| 154 |
do { \ |
| 155 |
msg = chunk->msg; \ |
| 156 |
if (msg == prev_msg) \ |
| 157 |
continue; \ |
| 158 |
list_for_each_entry(c, &msg->chunks, frag_list) { \ |
| 159 |
if ((clear && asoc->base.sk == c->skb->sk) || \ |
| 160 |
(!clear && asoc->base.sk != c->skb->sk)) \ |
| 161 |
cb(c); \ |
| 162 |
} \ |
| 163 |
prev_msg = msg; \ |
| 164 |
} while (0) |
| 165 |
|
| 166 |
static void sctp_for_each_tx_datachunk(struct sctp_association *asoc, |
| 167 |
bool clear, |
| 168 |
void (*cb)(struct sctp_chunk *)) |
| 169 |
|
| 170 |
{ |
| 171 |
struct sctp_datamsg *msg, *prev_msg = NULL; |
| 172 |
struct sctp_outq *q = &asoc->outqueue; |
| 173 |
struct sctp_chunk *chunk, *c; |
| 174 |
struct sctp_transport *t; |
| 175 |
|
| 176 |
list_for_each_entry(t, &asoc->peer.transport_addr_list, transports) |
| 177 |
list_for_each_entry(chunk, &t->transmitted, transmitted_list) |
| 178 |
traverse_and_process(); |
| 179 |
|
| 180 |
list_for_each_entry(chunk, &q->retransmit, transmitted_list) |
| 181 |
traverse_and_process(); |
| 182 |
|
| 183 |
list_for_each_entry(chunk, &q->sacked, transmitted_list) |
| 184 |
traverse_and_process(); |
| 185 |
|
| 186 |
list_for_each_entry(chunk, &q->abandoned, transmitted_list) |
| 187 |
traverse_and_process(); |
| 188 |
|
| 189 |
list_for_each_entry(chunk, &q->out_chunk_list, list) |
| 190 |
traverse_and_process(); |
| 191 |
} |
| 192 |
|
| 193 |
static void sctp_for_each_rx_skb(struct sctp_association *asoc, struct sock *sk, |
| 194 |
void (*cb)(struct sk_buff *, struct sock *)) |
| 195 |
|
| 196 |
{ |
| 197 |
struct sk_buff *skb, *tmp; |
| 198 |
|
| 199 |
sctp_skb_for_each(skb, &asoc->ulpq.lobby, tmp) |
| 200 |
cb(skb, sk); |
| 201 |
|
| 202 |
sctp_skb_for_each(skb, &asoc->ulpq.reasm, tmp) |
| 203 |
cb(skb, sk); |
| 204 |
|
| 205 |
sctp_skb_for_each(skb, &asoc->ulpq.reasm_uo, tmp) |
| 206 |
cb(skb, sk); |
| 207 |
} |
| 208 |
|
| 209 |
/* Verify that this is a valid address. */ |
| 210 |
static inline int sctp_verify_addr(struct sock *sk, union sctp_addr *addr, |
| 211 |
int len) |
| 212 |
{ |
| 213 |
struct sctp_af *af; |
| 214 |
|
| 215 |
/* Verify basic sockaddr. */ |
| 216 |
af = sctp_sockaddr_af(sctp_sk(sk), addr, len); |
| 217 |
if (!af) |
| 218 |
return -EINVAL; |
| 219 |
|
| 220 |
/* Is this a valid SCTP address? */ |
| 221 |
if (!af->addr_valid(addr, sctp_sk(sk), NULL)) |
| 222 |
return -EINVAL; |
| 223 |
|
| 224 |
if (!sctp_sk(sk)->pf->send_verify(sctp_sk(sk), (addr))) |
| 225 |
return -EINVAL; |
| 226 |
|
| 227 |
return 0; |
| 228 |
} |
| 229 |
|
| 230 |
/* Look up the association by its id. If this is not a UDP-style |
| 231 |
* socket, the ID field is always ignored. |
| 232 |
*/ |
| 233 |
struct sctp_association *sctp_id2assoc(struct sock *sk, sctp_assoc_t id) |
| 234 |
{ |
| 235 |
struct sctp_association *asoc = NULL; |
| 236 |
|
| 237 |
/* If this is not a UDP-style socket, assoc id should be ignored. */ |
| 238 |
if (!sctp_style(sk, UDP)) { |
| 239 |
/* Return NULL if the socket state is not ESTABLISHED. It |
| 240 |
* could be a TCP-style listening socket or a socket which |
| 241 |
* hasn't yet called connect() to establish an association. |
| 242 |
*/ |
| 243 |
if (!sctp_sstate(sk, ESTABLISHED) && !sctp_sstate(sk, CLOSING)) |
| 244 |
return NULL; |
| 245 |
|
| 246 |
/* Get the first and the only association from the list. */ |
| 247 |
if (!list_empty(&sctp_sk(sk)->ep->asocs)) |
| 248 |
asoc = list_entry(sctp_sk(sk)->ep->asocs.next, |
| 249 |
struct sctp_association, asocs); |
| 250 |
return asoc; |
| 251 |
} |
| 252 |
|
| 253 |
/* Otherwise this is a UDP-style socket. */ |
| 254 |
if (id <= SCTP_ALL_ASSOC) |
| 255 |
return NULL; |
| 256 |
|
| 257 |
spin_lock_bh(&sctp_assocs_id_lock); |
| 258 |
asoc = (struct sctp_association *)idr_find(&sctp_assocs_id, (int)id); |
| 259 |
if (asoc && (asoc->base.sk != sk || asoc->base.dead)) |
| 260 |
asoc = NULL; |
| 261 |
spin_unlock_bh(&sctp_assocs_id_lock); |
| 262 |
|
| 263 |
return asoc; |
| 264 |
} |
| 265 |
|
| 266 |
/* Look up the transport from an address and an assoc id. If both address and |
| 267 |
* id are specified, the associations matching the address and the id should be |
| 268 |
* the same. |
| 269 |
*/ |
| 270 |
static struct sctp_transport *sctp_addr_id2transport(struct sock *sk, |
| 271 |
struct sockaddr_storage *addr, |
| 272 |
sctp_assoc_t id) |
| 273 |
{ |
| 274 |
struct sctp_association *addr_asoc = NULL, *id_asoc = NULL; |
| 275 |
struct sctp_af *af = sctp_get_af_specific(addr->ss_family); |
| 276 |
union sctp_addr *laddr = (union sctp_addr *)addr; |
| 277 |
struct sctp_transport *transport; |
| 278 |
|
| 279 |
if (!af || sctp_verify_addr(sk, laddr, af->sockaddr_len)) |
| 280 |
return NULL; |
| 281 |
|
| 282 |
addr_asoc = sctp_endpoint_lookup_assoc(sctp_sk(sk)->ep, |
| 283 |
laddr, |
| 284 |
&transport); |
| 285 |
|
| 286 |
if (!addr_asoc) |
| 287 |
return NULL; |
| 288 |
|
| 289 |
id_asoc = sctp_id2assoc(sk, id); |
| 290 |
if (id_asoc && (id_asoc != addr_asoc)) |
| 291 |
return NULL; |
| 292 |
|
| 293 |
sctp_get_pf_specific(sk->sk_family)->addr_to_user(sctp_sk(sk), |
| 294 |
(union sctp_addr *)addr); |
| 295 |
|
| 296 |
return transport; |
| 297 |
} |
| 298 |
|
| 299 |
/* API 3.1.2 bind() - UDP Style Syntax |
| 300 |
* The syntax of bind() is, |
| 301 |
* |
| 302 |
* ret = bind(int sd, struct sockaddr *addr, int addrlen); |
| 303 |
* |
| 304 |
* sd - the socket descriptor returned by socket(). |
| 305 |
* addr - the address structure (struct sockaddr_in or struct |
| 306 |
* sockaddr_in6 [RFC 2553]), |
| 307 |
* addr_len - the size of the address structure. |
| 308 |
*/ |
| 309 |
static int sctp_bind(struct sock *sk, struct sockaddr_unsized *addr, |
| 310 |
int addr_len) |
| 311 |
{ |
| 312 |
int retval = 0; |
| 313 |
|
| 314 |
lock_sock(sk); |
| 315 |
|
| 316 |
pr_debug("%s: sk:%p, addr:%p, addr_len:%d\n", __func__, sk, |
| 317 |
addr, addr_len); |
| 318 |
|
| 319 |
/* Disallow binding twice. */ |
| 320 |
if (!sctp_sk(sk)->ep->base.bind_addr.port) |
| 321 |
retval = sctp_do_bind(sk, (union sctp_addr *)addr, |
| 322 |
addr_len); |
| 323 |
else |
| 324 |
retval = -EINVAL; |
| 325 |
|
| 326 |
release_sock(sk); |
| 327 |
|
| 328 |
return retval; |
| 329 |
} |
| 330 |
|
| 331 |
static int sctp_get_port_local(struct sock *, union sctp_addr *); |
| 332 |
|
| 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) |
| 336 |
{ |
| 337 |
struct sctp_af *af; |
| 338 |
|
| 339 |
/* Check minimum size. */ |
| 340 |
if (len < sizeof (struct sockaddr)) |
| 341 |
return NULL; |
| 342 |
|
| 343 |
if (!opt->pf->af_supported(addr->sa.sa_family, opt)) |
| 344 |
return NULL; |
| 345 |
|
| 346 |
if (addr->sa.sa_family == AF_INET6) { |
| 347 |
if (len < SIN6_LEN_RFC2133) |
| 348 |
return NULL; |
| 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)) |
| 352 |
return NULL; |
| 353 |
} |
| 354 |
|
| 355 |
/* If we get this far, af is valid. */ |
| 356 |
af = sctp_get_af_specific(addr->sa.sa_family); |
| 357 |
|
| 358 |
if (len < af->sockaddr_len) |
| 359 |
return NULL; |
| 360 |
|
| 361 |
return af; |
| 362 |
} |
| 363 |
|
| 364 |
static void sctp_auto_asconf_init(struct sctp_sock *sp) |
| 365 |
{ |
| 366 |
struct net *net = sock_net(&sp->inet.sk); |
| 367 |
|
| 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; |
| 373 |
} |
| 374 |
} |
| 375 |
|
| 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) |
| 378 |
{ |
| 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; |
| 383 |
struct sctp_af *af; |
| 384 |
unsigned short snum; |
| 385 |
int ret = 0; |
| 386 |
|
| 387 |
/* Common sockaddr verification. */ |
| 388 |
af = sctp_sockaddr_af(sp, addr, len); |
| 389 |
if (!af) { |
| 390 |
pr_debug("%s: sk:%p, newaddr:%p, len:%d EINVAL\n", |
| 391 |
__func__, sk, addr, len); |
| 392 |
return -EINVAL; |
| 393 |
} |
| 394 |
|
| 395 |
snum = ntohs(addr->v4.sin_port); |
| 396 |
|
| 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); |
| 399 |
|
| 400 |
/* PF specific bind() address verification. */ |
| 401 |
if (!sp->pf->bind_verify(sp, addr)) |
| 402 |
return -EADDRNOTAVAIL; |
| 403 |
|
| 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 |
| 407 |
*/ |
| 408 |
if (bp->port) { |
| 409 |
if (!snum) |
| 410 |
snum = bp->port; |
| 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); |
| 414 |
return -EINVAL; |
| 415 |
} |
| 416 |
} |
| 417 |
|
| 418 |
if (snum && inet_port_requires_bind_service(net, snum) && |
| 419 |
!ns_capable(net->user_ns, CAP_NET_BIND_SERVICE)) |
| 420 |
return -EACCES; |
| 421 |
|
| 422 |
/* See if the address matches any of the addresses we may have |
| 423 |
* already bound before checking against other endpoints. |
| 424 |
*/ |
| 425 |
if (sctp_bind_addr_match(bp, addr, sp)) |
| 426 |
return -EINVAL; |
| 427 |
|
| 428 |
/* Make sure we are allowed to bind here. |
| 429 |
* The function sctp_get_port_local() does duplicate address |
| 430 |
* detection. |
| 431 |
*/ |
| 432 |
addr->v4.sin_port = htons(snum); |
| 433 |
if (sctp_get_port_local(sk, addr)) |
| 434 |
return -EADDRINUSE; |
| 435 |
|
| 436 |
/* Refresh ephemeral port. */ |
| 437 |
if (!bp->port) { |
| 438 |
bp->port = inet_sk(sk)->inet_num; |
| 439 |
sctp_auto_asconf_init(sp); |
| 440 |
} |
| 441 |
|
| 442 |
/* Add the address to the bind address list. |
| 443 |
* Use GFP_ATOMIC since BHs will be disabled. |
| 444 |
*/ |
| 445 |
ret = sctp_add_bind_addr(bp, addr, af->sockaddr_len, |
| 446 |
SCTP_ADDR_SRC, GFP_ATOMIC); |
| 447 |
|
| 448 |
if (ret) { |
| 449 |
sctp_put_port(sk); |
| 450 |
return ret; |
| 451 |
} |
| 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); |
| 455 |
|
| 456 |
return ret; |
| 457 |
} |
| 458 |
|
| 459 |
/* ADDIP Section 4.1.1 Congestion Control of ASCONF Chunks |
| 460 |
* |
| 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). |
| 468 |
*/ |
| 469 |
static int sctp_send_asconf(struct sctp_association *asoc, |
| 470 |
struct sctp_chunk *chunk) |
| 471 |
{ |
| 472 |
int retval = 0; |
| 473 |
|
| 474 |
/* If there is an outstanding ASCONF chunk, queue it for later |
| 475 |
* transmission. |
| 476 |
*/ |
| 477 |
if (asoc->addip_last_asconf) { |
| 478 |
list_add_tail(&chunk->list, &asoc->addip_chunk_list); |
| 479 |
goto out; |
| 480 |
} |
| 481 |
|
| 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); |
| 485 |
if (retval) |
| 486 |
sctp_chunk_free(chunk); |
| 487 |
else |
| 488 |
asoc->addip_last_asconf = chunk; |
| 489 |
|
| 490 |
out: |
| 491 |
return retval; |
| 492 |
} |
| 493 |
|
| 494 |
/* Add a list of addresses as bind addresses to local endpoint or |
| 495 |
* association. |
| 496 |
* |
| 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. |
| 500 |
* |
| 501 |
* If any of them fails, then the operation will be reversed and the |
| 502 |
* ones that were added will be removed. |
| 503 |
* |
| 504 |
* Only sctp_setsockopt_bindx() is supposed to call this function. |
| 505 |
*/ |
| 506 |
static int sctp_bindx_add(struct sock *sk, struct sockaddr *addrs, int addrcnt) |
| 507 |
{ |
| 508 |
int cnt; |
| 509 |
int retval = 0; |
| 510 |
void *addr_buf; |
| 511 |
struct sockaddr *sa_addr; |
| 512 |
struct sctp_af *af; |
| 513 |
|
| 514 |
pr_debug("%s: sk:%p, addrs:%p, addrcnt:%d\n", __func__, sk, |
| 515 |
addrs, addrcnt); |
| 516 |
|
| 517 |
addr_buf = addrs; |
| 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. |
| 521 |
*/ |
| 522 |
sa_addr = addr_buf; |
| 523 |
af = sctp_get_af_specific(sa_addr->sa_family); |
| 524 |
if (!af) { |
| 525 |
retval = -EINVAL; |
| 526 |
goto err_bindx_add; |
| 527 |
} |
| 528 |
|
| 529 |
retval = sctp_do_bind(sk, (union sctp_addr *)sa_addr, |
| 530 |
af->sockaddr_len); |
| 531 |
|
| 532 |
addr_buf += af->sockaddr_len; |
| 533 |
|
| 534 |
err_bindx_add: |
| 535 |
if (retval < 0) { |
| 536 |
/* Failed. Cleanup the ones that have been added */ |
| 537 |
if (cnt > 0) |
| 538 |
sctp_bindx_rem(sk, addrs, cnt); |
| 539 |
return retval; |
| 540 |
} |
| 541 |
} |
| 542 |
|
| 543 |
return retval; |
| 544 |
} |
| 545 |
|
| 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. |
| 549 |
* |
| 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. |
| 553 |
* |
| 554 |
* Only sctp_setsockopt_bindx() is supposed to call this function. |
| 555 |
*/ |
| 556 |
static int sctp_send_asconf_add_ip(struct sock *sk, |
| 557 |
struct sockaddr *addrs, |
| 558 |
int addrcnt) |
| 559 |
{ |
| 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; |
| 568 |
void *addr_buf; |
| 569 |
struct sctp_af *af; |
| 570 |
struct list_head *p; |
| 571 |
int i; |
| 572 |
int retval = 0; |
| 573 |
|
| 574 |
sp = sctp_sk(sk); |
| 575 |
ep = sp->ep; |
| 576 |
|
| 577 |
if (!ep->asconf_enable) |
| 578 |
return retval; |
| 579 |
|
| 580 |
pr_debug("%s: sk:%p, addrs:%p, addrcnt:%d\n", |
| 581 |
__func__, sk, addrs, addrcnt); |
| 582 |
|
| 583 |
list_for_each_entry(asoc, &ep->asocs, asocs) { |
| 584 |
if (!asoc->peer.asconf_capable) |
| 585 |
continue; |
| 586 |
|
| 587 |
if (asoc->peer.addip_disabled_mask & SCTP_PARAM_ADD_IP) |
| 588 |
continue; |
| 589 |
|
| 590 |
if (!sctp_state(asoc, ESTABLISHED)) |
| 591 |
continue; |
| 592 |
|
| 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. |
| 597 |
*/ |
| 598 |
addr_buf = addrs; |
| 599 |
for (i = 0; i < addrcnt; i++) { |
| 600 |
addr = addr_buf; |
| 601 |
af = sctp_get_af_specific(addr->v4.sin_family); |
| 602 |
if (!af) { |
| 603 |
retval = -EINVAL; |
| 604 |
goto out; |
| 605 |
} |
| 606 |
|
| 607 |
if (sctp_assoc_lookup_laddr(asoc, addr)) |
| 608 |
break; |
| 609 |
|
| 610 |
addr_buf += af->sockaddr_len; |
| 611 |
} |
| 612 |
if (i < addrcnt) |
| 613 |
continue; |
| 614 |
|
| 615 |
/* Use the first valid address in bind addr list of |
| 616 |
* association as Address Parameter of ASCONF CHUNK. |
| 617 |
*/ |
| 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); |
| 623 |
if (!chunk) { |
| 624 |
retval = -ENOMEM; |
| 625 |
goto out; |
| 626 |
} |
| 627 |
|
| 628 |
/* Add the new addresses to the bind address list with |
| 629 |
* use_as_src set to 0. |
| 630 |
*/ |
| 631 |
addr_buf = addrs; |
| 632 |
for (i = 0; i < addrcnt; i++) { |
| 633 |
addr = addr_buf; |
| 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, |
| 637 |
sizeof(saveaddr), |
| 638 |
SCTP_ADDR_NEW, GFP_ATOMIC); |
| 639 |
addr_buf += af->sockaddr_len; |
| 640 |
} |
| 641 |
if (asoc->src_out_of_asoc_ok) { |
| 642 |
struct sctp_transport *trans; |
| 643 |
|
| 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)); |
| 655 |
} |
| 656 |
} |
| 657 |
retval = sctp_send_asconf(asoc, chunk); |
| 658 |
} |
| 659 |
|
| 660 |
out: |
| 661 |
return retval; |
| 662 |
} |
| 663 |
|
| 664 |
/* Remove a list of addresses from bind addresses list. Do not remove the |
| 665 |
* last address. |
| 666 |
* |
| 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. |
| 670 |
* |
| 671 |
* If any of them fails, then the operation will be reversed and the |
| 672 |
* ones that were removed will be added back. |
| 673 |
* |
| 674 |
* At least one address has to be left; if only one address is |
| 675 |
* available, the operation will return -EBUSY. |
| 676 |
* |
| 677 |
* Only sctp_setsockopt_bindx() is supposed to call this function. |
| 678 |
*/ |
| 679 |
static int sctp_bindx_rem(struct sock *sk, struct sockaddr *addrs, int addrcnt) |
| 680 |
{ |
| 681 |
struct sctp_sock *sp = sctp_sk(sk); |
| 682 |
struct sctp_endpoint *ep = sp->ep; |
| 683 |
int cnt; |
| 684 |
struct sctp_bind_addr *bp = &ep->base.bind_addr; |
| 685 |
int retval = 0; |
| 686 |
void *addr_buf; |
| 687 |
union sctp_addr *sa_addr; |
| 688 |
struct sctp_af *af; |
| 689 |
|
| 690 |
pr_debug("%s: sk:%p, addrs:%p, addrcnt:%d\n", |
| 691 |
__func__, sk, addrs, addrcnt); |
| 692 |
|
| 693 |
addr_buf = addrs; |
| 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). |
| 698 |
*/ |
| 699 |
if (list_empty(&bp->address_list) || |
| 700 |
(sctp_list_single_entry(&bp->address_list))) { |
| 701 |
retval = -EBUSY; |
| 702 |
goto err_bindx_rem; |
| 703 |
} |
| 704 |
|
| 705 |
sa_addr = addr_buf; |
| 706 |
af = sctp_get_af_specific(sa_addr->sa.sa_family); |
| 707 |
if (!af) { |
| 708 |
retval = -EINVAL; |
| 709 |
goto err_bindx_rem; |
| 710 |
} |
| 711 |
|
| 712 |
if (!af->addr_valid(sa_addr, sp, NULL)) { |
| 713 |
retval = -EADDRNOTAVAIL; |
| 714 |
goto err_bindx_rem; |
| 715 |
} |
| 716 |
|
| 717 |
if (sa_addr->v4.sin_port && |
| 718 |
sa_addr->v4.sin_port != htons(bp->port)) { |
| 719 |
retval = -EINVAL; |
| 720 |
goto err_bindx_rem; |
| 721 |
} |
| 722 |
|
| 723 |
if (!sa_addr->v4.sin_port) |
| 724 |
sa_addr->v4.sin_port = htons(bp->port); |
| 725 |
|
| 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 |
| 732 |
*/ |
| 733 |
retval = sctp_del_bind_addr(bp, sa_addr); |
| 734 |
|
| 735 |
addr_buf += af->sockaddr_len; |
| 736 |
err_bindx_rem: |
| 737 |
if (retval < 0) { |
| 738 |
/* Failed. Add the ones that has been removed back */ |
| 739 |
if (cnt > 0) |
| 740 |
sctp_bindx_add(sk, addrs, cnt); |
| 741 |
return retval; |
| 742 |
} |
| 743 |
} |
| 744 |
|
| 745 |
return retval; |
| 746 |
} |
| 747 |
|
| 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. |
| 751 |
* |
| 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. |
| 755 |
* |
| 756 |
* Only sctp_setsockopt_bindx() is supposed to call this function. |
| 757 |
*/ |
| 758 |
static int sctp_send_asconf_del_ip(struct sock *sk, |
| 759 |
struct sockaddr *addrs, |
| 760 |
int addrcnt) |
| 761 |
{ |
| 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; |
| 769 |
void *addr_buf; |
| 770 |
struct sctp_af *af; |
| 771 |
struct sctp_sockaddr_entry *saddr; |
| 772 |
int i; |
| 773 |
int retval = 0; |
| 774 |
int stored = 0; |
| 775 |
|
| 776 |
chunk = NULL; |
| 777 |
sp = sctp_sk(sk); |
| 778 |
ep = sp->ep; |
| 779 |
|
| 780 |
if (!ep->asconf_enable) |
| 781 |
return retval; |
| 782 |
|
| 783 |
pr_debug("%s: sk:%p, addrs:%p, addrcnt:%d\n", |
| 784 |
__func__, sk, addrs, addrcnt); |
| 785 |
|
| 786 |
list_for_each_entry(asoc, &ep->asocs, asocs) { |
| 787 |
|
| 788 |
if (!asoc->peer.asconf_capable) |
| 789 |
continue; |
| 790 |
|
| 791 |
if (asoc->peer.addip_disabled_mask & SCTP_PARAM_DEL_IP) |
| 792 |
continue; |
| 793 |
|
| 794 |
if (!sctp_state(asoc, ESTABLISHED)) |
| 795 |
continue; |
| 796 |
|
| 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. |
| 801 |
*/ |
| 802 |
addr_buf = addrs; |
| 803 |
for (i = 0; i < addrcnt; i++) { |
| 804 |
laddr = addr_buf; |
| 805 |
af = sctp_get_af_specific(laddr->v4.sin_family); |
| 806 |
if (!af) { |
| 807 |
retval = -EINVAL; |
| 808 |
goto out; |
| 809 |
} |
| 810 |
|
| 811 |
if (!sctp_assoc_lookup_laddr(asoc, laddr)) |
| 812 |
break; |
| 813 |
|
| 814 |
addr_buf += af->sockaddr_len; |
| 815 |
} |
| 816 |
if (i < addrcnt) |
| 817 |
continue; |
| 818 |
|
| 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 |
| 822 |
* association. |
| 823 |
*/ |
| 824 |
bp = &asoc->base.bind_addr; |
| 825 |
laddr = sctp_find_unmatch_addr(bp, (union sctp_addr *)addrs, |
| 826 |
addrcnt, sp); |
| 827 |
if ((laddr == NULL) && (addrcnt == 1)) { |
| 828 |
if (asoc->asconf_addr_del_pending) |
| 829 |
continue; |
| 830 |
asoc->asconf_addr_del_pending = |
| 831 |
kzalloc_obj(union sctp_addr, GFP_ATOMIC); |
| 832 |
if (asoc->asconf_addr_del_pending == NULL) { |
| 833 |
retval = -ENOMEM; |
| 834 |
goto out; |
| 835 |
} |
| 836 |
asoc->asconf_addr_del_pending->sa.sa_family = |
| 837 |
addrs->sa_family; |
| 838 |
asoc->asconf_addr_del_pending->v4.sin_port = |
| 839 |
htons(bp->port); |
| 840 |
if (addrs->sa_family == AF_INET) { |
| 841 |
struct sockaddr_in *sin; |
| 842 |
|
| 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; |
| 847 |
|
| 848 |
sin6 = (struct sockaddr_in6 *)addrs; |
| 849 |
asoc->asconf_addr_del_pending->v6.sin6_addr = sin6->sin6_addr; |
| 850 |
} |
| 851 |
|
| 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); |
| 855 |
|
| 856 |
asoc->src_out_of_asoc_ok = 1; |
| 857 |
stored = 1; |
| 858 |
goto skip_mkasconf; |
| 859 |
} |
| 860 |
|
| 861 |
if (laddr == NULL) |
| 862 |
return -EINVAL; |
| 863 |
|
| 864 |
/* We do not need RCU protection throughout this loop |
| 865 |
* because this is done under a socket lock from the |
| 866 |
* setsockopt call. |
| 867 |
*/ |
| 868 |
chunk = sctp_make_asconf_update_ip(asoc, laddr, addrs, addrcnt, |
| 869 |
SCTP_PARAM_DEL_IP); |
| 870 |
if (!chunk) { |
| 871 |
retval = -ENOMEM; |
| 872 |
goto out; |
| 873 |
} |
| 874 |
|
| 875 |
skip_mkasconf: |
| 876 |
/* Reset use_as_src flag for the addresses in the bind address |
| 877 |
* list that are to be deleted. |
| 878 |
*/ |
| 879 |
addr_buf = addrs; |
| 880 |
for (i = 0; i < addrcnt; i++) { |
| 881 |
laddr = addr_buf; |
| 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; |
| 886 |
} |
| 887 |
addr_buf += af->sockaddr_len; |
| 888 |
} |
| 889 |
|
| 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. |
| 893 |
*/ |
| 894 |
list_for_each_entry(transport, &asoc->peer.transport_addr_list, |
| 895 |
transports) { |
| 896 |
sctp_transport_route(transport, NULL, |
| 897 |
sctp_sk(asoc->base.sk)); |
| 898 |
} |
| 899 |
|
| 900 |
if (stored) |
| 901 |
/* We don't need to transmit ASCONF */ |
| 902 |
continue; |
| 903 |
retval = sctp_send_asconf(asoc, chunk); |
| 904 |
} |
| 905 |
out: |
| 906 |
return retval; |
| 907 |
} |
| 908 |
|
| 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) |
| 911 |
{ |
| 912 |
struct sock *sk = sctp_opt2sk(sp); |
| 913 |
union sctp_addr *addr; |
| 914 |
struct sctp_af *af; |
| 915 |
|
| 916 |
/* It is safe to write port space in caller. */ |
| 917 |
addr = &addrw->a; |
| 918 |
addr->v4.sin_port = htons(sp->ep->base.bind_addr.port); |
| 919 |
af = sctp_get_af_specific(addr->sa.sa_family); |
| 920 |
if (!af) |
| 921 |
return -EINVAL; |
| 922 |
if (sctp_verify_addr(sk, addr, af->sockaddr_len)) |
| 923 |
return -EINVAL; |
| 924 |
|
| 925 |
if (addrw->state == SCTP_ADDR_NEW) |
| 926 |
return sctp_send_asconf_add_ip(sk, (struct sockaddr *)addr, 1); |
| 927 |
else |
| 928 |
return sctp_send_asconf_del_ip(sk, (struct sockaddr *)addr, 1); |
| 929 |
} |
| 930 |
|
| 931 |
/* Helper for tunneling sctp_bindx() requests through sctp_setsockopt() |
| 932 |
* |
| 933 |
* API 8.1 |
| 934 |
* int sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt, |
| 935 |
* int flags); |
| 936 |
* |
| 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 |
| 939 |
* or IPv6 addresses. |
| 940 |
* |
| 941 |
* A single address may be specified as INADDR_ANY or IN6ADDR_ANY, see |
| 942 |
* Section 3.1.2 for this usage. |
| 943 |
* |
| 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. |
| 950 |
* |
| 951 |
* On success, sctp_bindx() returns 0. On failure, sctp_bindx() returns |
| 952 |
* -1, and sets errno to the appropriate error code. |
| 953 |
* |
| 954 |
* For SCTP, the port given in each socket address must be the same, or |
| 955 |
* sctp_bindx() will fail, setting errno to EINVAL. |
| 956 |
* |
| 957 |
* The flags parameter is formed from the bitwise OR of zero or more of |
| 958 |
* the following currently defined flags: |
| 959 |
* |
| 960 |
* SCTP_BINDX_ADD_ADDR |
| 961 |
* |
| 962 |
* SCTP_BINDX_REM_ADDR |
| 963 |
* |
| 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. |
| 970 |
* |
| 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. |
| 979 |
* |
| 980 |
* Adding and removing addresses from a connected association is |
| 981 |
* optional functionality. Implementations that do not support this |
| 982 |
* functionality should return EOPNOTSUPP. |
| 983 |
* |
| 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() |
| 987 |
* from userspace. |
| 988 |
* |
| 989 |
* On exit there is no need to do sockfd_put(), sys_setsockopt() does |
| 990 |
* it. |
| 991 |
* |
| 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 |
| 996 |
* sctp_bindx) |
| 997 |
* |
| 998 |
* Returns 0 if ok, <0 errno code on error. |
| 999 |
*/ |
| 1000 |
static int sctp_setsockopt_bindx(struct sock *sk, struct sockaddr *addrs, |
| 1001 |
int addrs_size, int op) |
| 1002 |
{ |
| 1003 |
int err; |
| 1004 |
int addrcnt = 0; |
| 1005 |
int walk_size = 0; |
| 1006 |
struct sockaddr *sa_addr; |
| 1007 |
void *addr_buf = addrs; |
| 1008 |
struct sctp_af *af; |
| 1009 |
|
| 1010 |
pr_debug("%s: sk:%p addrs:%p addrs_size:%d opt:%d\n", |
| 1011 |
__func__, sk, addr_buf, addrs_size, op); |
| 1012 |
|
| 1013 |
if (unlikely(addrs_size <= 0)) |
| 1014 |
return -EINVAL; |
| 1015 |
|
| 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) |
| 1019 |
return -EINVAL; |
| 1020 |
|
| 1021 |
sa_addr = addr_buf; |
| 1022 |
af = sctp_get_af_specific(sa_addr->sa_family); |
| 1023 |
|
| 1024 |
/* If the address family is not supported or if this address |
| 1025 |
* causes the address buffer to overflow return EINVAL. |
| 1026 |
*/ |
| 1027 |
if (!af || (walk_size + af->sockaddr_len) > addrs_size) |
| 1028 |
return -EINVAL; |
| 1029 |
addrcnt++; |
| 1030 |
addr_buf += af->sockaddr_len; |
| 1031 |
walk_size += af->sockaddr_len; |
| 1032 |
} |
| 1033 |
|
| 1034 |
/* Do the work. */ |
| 1035 |
switch (op) { |
| 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, |
| 1039 |
addrs, addrs_size); |
| 1040 |
if (err) |
| 1041 |
return err; |
| 1042 |
err = sctp_bindx_add(sk, addrs, addrcnt); |
| 1043 |
if (err) |
| 1044 |
return err; |
| 1045 |
return sctp_send_asconf_add_ip(sk, addrs, addrcnt); |
| 1046 |
case SCTP_BINDX_REM_ADDR: |
| 1047 |
err = sctp_bindx_rem(sk, addrs, addrcnt); |
| 1048 |
if (err) |
| 1049 |
return err; |
| 1050 |
return sctp_send_asconf_del_ip(sk, addrs, addrcnt); |
| 1051 |
|
| 1052 |
default: |
| 1053 |
return -EINVAL; |
| 1054 |
} |
| 1055 |
} |
| 1056 |
|
| 1057 |
static int sctp_bind_add(struct sock *sk, struct sockaddr_unsized *addrs, |
| 1058 |
int addrlen) |
| 1059 |
{ |
| 1060 |
int err; |
| 1061 |
|
| 1062 |
lock_sock(sk); |
| 1063 |
err = sctp_setsockopt_bindx(sk, (struct sockaddr *)addrs, addrlen, SCTP_BINDX_ADD_ADDR); |
| 1064 |
release_sock(sk); |
| 1065 |
return err; |
| 1066 |
} |
| 1067 |
|
| 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) |
| 1072 |
{ |
| 1073 |
struct sctp_association *asoc; |
| 1074 |
struct sock *sk = ep->base.sk; |
| 1075 |
struct net *net = sock_net(sk); |
| 1076 |
enum sctp_scope scope; |
| 1077 |
int err; |
| 1078 |
|
| 1079 |
if (sctp_endpoint_is_peeled_off(ep, daddr)) |
| 1080 |
return -EADDRNOTAVAIL; |
| 1081 |
|
| 1082 |
if (!ep->base.bind_addr.port) { |
| 1083 |
if (sctp_autobind(sk)) |
| 1084 |
return -EAGAIN; |
| 1085 |
} else { |
| 1086 |
if (inet_port_requires_bind_service(net, ep->base.bind_addr.port) && |
| 1087 |
!ns_capable(net->user_ns, CAP_NET_BIND_SERVICE)) |
| 1088 |
return -EACCES; |
| 1089 |
} |
| 1090 |
|
| 1091 |
scope = sctp_scope(daddr); |
| 1092 |
asoc = sctp_association_new(ep, sk, scope, GFP_KERNEL); |
| 1093 |
if (!asoc) |
| 1094 |
return -ENOMEM; |
| 1095 |
|
| 1096 |
err = sctp_assoc_set_bind_addr_from_ep(asoc, scope, GFP_KERNEL); |
| 1097 |
if (err < 0) |
| 1098 |
goto free; |
| 1099 |
|
| 1100 |
*tp = sctp_assoc_add_peer(asoc, daddr, GFP_KERNEL, SCTP_UNKNOWN); |
| 1101 |
if (!*tp) { |
| 1102 |
err = -ENOMEM; |
| 1103 |
goto free; |
| 1104 |
} |
| 1105 |
|
| 1106 |
if (!init) |
| 1107 |
return 0; |
| 1108 |
|
| 1109 |
if (init->sinit_num_ostreams) { |
| 1110 |
__u16 outcnt = init->sinit_num_ostreams; |
| 1111 |
|
| 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); |
| 1115 |
if (err) |
| 1116 |
goto free; |
| 1117 |
} |
| 1118 |
|
| 1119 |
if (init->sinit_max_instreams) |
| 1120 |
asoc->c.sinit_max_instreams = init->sinit_max_instreams; |
| 1121 |
|
| 1122 |
if (init->sinit_max_attempts) |
| 1123 |
asoc->max_init_attempts = init->sinit_max_attempts; |
| 1124 |
|
| 1125 |
if (init->sinit_max_init_timeo) |
| 1126 |
asoc->max_init_timeo = |
| 1127 |
msecs_to_jiffies(init->sinit_max_init_timeo); |
| 1128 |
|
| 1129 |
return 0; |
| 1130 |
free: |
| 1131 |
sctp_association_free(asoc); |
| 1132 |
return err; |
| 1133 |
} |
| 1134 |
|
| 1135 |
static int sctp_connect_add_peer(struct sctp_association *asoc, |
| 1136 |
union sctp_addr *daddr, int addr_len) |
| 1137 |
{ |
| 1138 |
struct sctp_endpoint *ep = asoc->ep; |
| 1139 |
struct sctp_association *old; |
| 1140 |
struct sctp_transport *t; |
| 1141 |
int err; |
| 1142 |
|
| 1143 |
err = sctp_verify_addr(ep->base.sk, daddr, addr_len); |
| 1144 |
if (err) |
| 1145 |
return err; |
| 1146 |
|
| 1147 |
old = sctp_endpoint_lookup_assoc(ep, daddr, &t); |
| 1148 |
if (old && old != asoc) |
| 1149 |
return old->state >= SCTP_STATE_ESTABLISHED ? -EISCONN |
| 1150 |
: -EALREADY; |
| 1151 |
|
| 1152 |
if (sctp_endpoint_is_peeled_off(ep, daddr)) |
| 1153 |
return -EADDRNOTAVAIL; |
| 1154 |
|
| 1155 |
t = sctp_assoc_add_peer(asoc, daddr, GFP_KERNEL, SCTP_UNKNOWN); |
| 1156 |
if (!t) |
| 1157 |
return -ENOMEM; |
| 1158 |
|
| 1159 |
return 0; |
| 1160 |
} |
| 1161 |
|
| 1162 |
/* __sctp_connect(struct sock* sk, struct sockaddr *kaddrs, int addrs_size) |
| 1163 |
* |
| 1164 |
* Common routine for handling connect() and sctp_connectx(). |
| 1165 |
* Connect will come in with just a single address. |
| 1166 |
*/ |
| 1167 |
static int __sctp_connect(struct sock *sk, struct sockaddr *kaddrs, |
| 1168 |
int addrs_size, int flags, sctp_assoc_t *assoc_id) |
| 1169 |
{ |
| 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; |
| 1176 |
struct sctp_af *af; |
| 1177 |
int walk_size, err; |
| 1178 |
long timeo; |
| 1179 |
|
| 1180 |
if (sctp_sstate(sk, ESTABLISHED) || sctp_sstate(sk, CLOSING) || |
| 1181 |
(sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING))) |
| 1182 |
return -EISCONN; |
| 1183 |
|
| 1184 |
daddr = addr_buf; |
| 1185 |
af = sctp_get_af_specific(daddr->sa.sa_family); |
| 1186 |
if (!af || af->sockaddr_len > addrs_size) |
| 1187 |
return -EINVAL; |
| 1188 |
|
| 1189 |
err = sctp_verify_addr(sk, daddr, af->sockaddr_len); |
| 1190 |
if (err) |
| 1191 |
return err; |
| 1192 |
|
| 1193 |
asoc = sctp_endpoint_lookup_assoc(ep, daddr, &transport); |
| 1194 |
if (asoc) |
| 1195 |
return asoc->state >= SCTP_STATE_ESTABLISHED ? -EISCONN |
| 1196 |
: -EALREADY; |
| 1197 |
|
| 1198 |
err = sctp_connect_new_asoc(ep, daddr, NULL, &transport); |
| 1199 |
if (err) |
| 1200 |
return err; |
| 1201 |
asoc = transport->asoc; |
| 1202 |
|
| 1203 |
addr_buf += af->sockaddr_len; |
| 1204 |
walk_size = af->sockaddr_len; |
| 1205 |
while (walk_size < addrs_size) { |
| 1206 |
err = -EINVAL; |
| 1207 |
if (walk_size + sizeof(sa_family_t) > addrs_size) |
| 1208 |
goto out_free; |
| 1209 |
|
| 1210 |
daddr = addr_buf; |
| 1211 |
af = sctp_get_af_specific(daddr->sa.sa_family); |
| 1212 |
if (!af || af->sockaddr_len + walk_size > addrs_size) |
| 1213 |
goto out_free; |
| 1214 |
|
| 1215 |
if (asoc->peer.port != ntohs(daddr->v4.sin_port)) |
| 1216 |
goto out_free; |
| 1217 |
|
| 1218 |
err = sctp_connect_add_peer(asoc, daddr, af->sockaddr_len); |
| 1219 |
if (err) |
| 1220 |
goto out_free; |
| 1221 |
|
| 1222 |
addr_buf += af->sockaddr_len; |
| 1223 |
walk_size += af->sockaddr_len; |
| 1224 |
} |
| 1225 |
|
| 1226 |
/* In case the user of sctp_connectx() wants an association |
| 1227 |
* id back, assign one now. |
| 1228 |
*/ |
| 1229 |
if (assoc_id) { |
| 1230 |
err = sctp_assoc_set_id(asoc, GFP_KERNEL); |
| 1231 |
if (err < 0) |
| 1232 |
goto out_free; |
| 1233 |
} |
| 1234 |
|
| 1235 |
err = sctp_primitive_ASSOCIATE(sock_net(sk), asoc, NULL); |
| 1236 |
if (err < 0) |
| 1237 |
goto out_free; |
| 1238 |
|
| 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); |
| 1242 |
sk->sk_err = 0; |
| 1243 |
|
| 1244 |
if (assoc_id) |
| 1245 |
*assoc_id = asoc->assoc_id; |
| 1246 |
|
| 1247 |
timeo = sock_sndtimeo(sk, flags & O_NONBLOCK); |
| 1248 |
return sctp_wait_for_connect(asoc, &timeo); |
| 1249 |
|
| 1250 |
out_free: |
| 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); |
| 1254 |
return err; |
| 1255 |
} |
| 1256 |
|
| 1257 |
/* Helper for tunneling sctp_connectx() requests through sctp_setsockopt() |
| 1258 |
* |
| 1259 |
* API 8.9 |
| 1260 |
* int sctp_connectx(int sd, struct sockaddr *addrs, int addrcnt, |
| 1261 |
* sctp_assoc_t *asoc); |
| 1262 |
* |
| 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. |
| 1266 |
* |
| 1267 |
* A single address may be specified as INADDR_ANY or IN6ADDR_ANY, see |
| 1268 |
* Section 3.1.2 for this usage. |
| 1269 |
* |
| 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. |
| 1276 |
* |
| 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. |
| 1281 |
* |
| 1282 |
* For SCTP, the port given in each socket address must be the same, or |
| 1283 |
* sctp_connectx() will fail, setting errno to EINVAL. |
| 1284 |
* |
| 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. |
| 1292 |
* |
| 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. |
| 1298 |
* |
| 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. |
| 1302 |
* |
| 1303 |
* On exit there is no need to do sockfd_put(), sys_setsockopt() does |
| 1304 |
* it. |
| 1305 |
* |
| 1306 |
* sk The sk of the socket |
| 1307 |
* addrs The pointer to the addresses |
| 1308 |
* addrssize Size of the addrs buffer |
| 1309 |
* |
| 1310 |
* Returns >=0 if ok, <0 errno code on error. |
| 1311 |
*/ |
| 1312 |
static int __sctp_setsockopt_connectx(struct sock *sk, struct sockaddr *kaddrs, |
| 1313 |
int addrs_size, sctp_assoc_t *assoc_id) |
| 1314 |
{ |
| 1315 |
int err = 0, flags = 0; |
| 1316 |
|
| 1317 |
pr_debug("%s: sk:%p addrs:%p addrs_size:%d\n", |
| 1318 |
__func__, sk, kaddrs, addrs_size); |
| 1319 |
|
| 1320 |
/* make sure the 1st addr's sa_family is accessible later */ |
| 1321 |
if (unlikely(addrs_size < sizeof(sa_family_t))) |
| 1322 |
return -EINVAL; |
| 1323 |
|
| 1324 |
/* Allow security module to validate connectx addresses. */ |
| 1325 |
err = security_sctp_bind_connect(sk, SCTP_SOCKOPT_CONNECTX, |
| 1326 |
(struct sockaddr *)kaddrs, |
| 1327 |
addrs_size); |
| 1328 |
if (err) |
| 1329 |
return err; |
| 1330 |
|
| 1331 |
/* in-kernel sockets don't generally have a file allocated to them |
| 1332 |
* if all they do is call sock_create_kern(). |
| 1333 |
*/ |
| 1334 |
if (sk->sk_socket->file) |
| 1335 |
flags = sk->sk_socket->file->f_flags; |
| 1336 |
|
| 1337 |
return __sctp_connect(sk, kaddrs, addrs_size, flags, assoc_id); |
| 1338 |
} |
| 1339 |
|
| 1340 |
/* |
| 1341 |
* This is an older interface. It's kept for backward compatibility |
| 1342 |
* to the option that doesn't provide association id. |
| 1343 |
*/ |
| 1344 |
static int sctp_setsockopt_connectx_old(struct sock *sk, |
| 1345 |
struct sockaddr *kaddrs, |
| 1346 |
int addrs_size) |
| 1347 |
{ |
| 1348 |
return __sctp_setsockopt_connectx(sk, kaddrs, addrs_size, NULL); |
| 1349 |
} |
| 1350 |
|
| 1351 |
/* |
| 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 |
| 1355 |
* always positive. |
| 1356 |
*/ |
| 1357 |
static int sctp_setsockopt_connectx(struct sock *sk, |
| 1358 |
struct sockaddr *kaddrs, |
| 1359 |
int addrs_size) |
| 1360 |
{ |
| 1361 |
sctp_assoc_t assoc_id = 0; |
| 1362 |
int err = 0; |
| 1363 |
|
| 1364 |
err = __sctp_setsockopt_connectx(sk, kaddrs, addrs_size, &assoc_id); |
| 1365 |
|
| 1366 |
if (err) |
| 1367 |
return err; |
| 1368 |
else |
| 1369 |
return assoc_id; |
| 1370 |
} |
| 1371 |
|
| 1372 |
/* |
| 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 |
| 1378 |
* code. |
| 1379 |
*/ |
| 1380 |
#ifdef CONFIG_COMPAT |
| 1381 |
struct compat_sctp_getaddrs_old { |
| 1382 |
sctp_assoc_t assoc_id; |
| 1383 |
s32 addr_num; |
| 1384 |
compat_uptr_t addrs; /* struct sockaddr * */ |
| 1385 |
}; |
| 1386 |
#endif |
| 1387 |
|
| 1388 |
static int sctp_getsockopt_connectx3(struct sock *sk, int len, |
| 1389 |
char __user *optval, |
| 1390 |
int __user *optlen) |
| 1391 |
{ |
| 1392 |
struct sctp_getaddrs_old param; |
| 1393 |
sctp_assoc_t assoc_id = 0; |
| 1394 |
struct sockaddr *kaddrs; |
| 1395 |
int err = 0; |
| 1396 |
|
| 1397 |
#ifdef CONFIG_COMPAT |
| 1398 |
if (in_compat_syscall()) { |
| 1399 |
struct compat_sctp_getaddrs_old param32; |
| 1400 |
|
| 1401 |
if (len < sizeof(param32)) |
| 1402 |
return -EINVAL; |
| 1403 |
if (copy_from_user(¶m32, optval, sizeof(param32))) |
| 1404 |
return -EFAULT; |
| 1405 |
|
| 1406 |
param.assoc_id = param32.assoc_id; |
| 1407 |
param.addr_num = param32.addr_num; |
| 1408 |
param.addrs = compat_ptr(param32.addrs); |
| 1409 |
} else |
| 1410 |
#endif |
| 1411 |
{ |
| 1412 |
if (len < sizeof(param)) |
| 1413 |
return -EINVAL; |
| 1414 |
if (copy_from_user(¶m, optval, sizeof(param))) |
| 1415 |
return -EFAULT; |
| 1416 |
} |
| 1417 |
|
| 1418 |
kaddrs = memdup_user(param.addrs, param.addr_num); |
| 1419 |
if (IS_ERR(kaddrs)) |
| 1420 |
return PTR_ERR(kaddrs); |
| 1421 |
|
| 1422 |
err = __sctp_setsockopt_connectx(sk, kaddrs, param.addr_num, &assoc_id); |
| 1423 |
kfree(kaddrs); |
| 1424 |
if (err == 0 || err == -EINPROGRESS) { |
| 1425 |
if (copy_to_user(optval, &assoc_id, sizeof(assoc_id))) |
| 1426 |
return -EFAULT; |
| 1427 |
if (put_user(sizeof(assoc_id), optlen)) |
| 1428 |
return -EFAULT; |
| 1429 |
} |
| 1430 |
|
| 1431 |
return err; |
| 1432 |
} |
| 1433 |
|
| 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. |
| 1438 |
* |
| 1439 |
* The syntax is |
| 1440 |
* |
| 1441 |
* ret = close(int sd); |
| 1442 |
* |
| 1443 |
* sd - the socket descriptor of the associations to be closed. |
| 1444 |
* |
| 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). |
| 1449 |
* |
| 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. |
| 1452 |
* |
| 1453 |
* 4.1.6 close() - TCP Style Syntax |
| 1454 |
* |
| 1455 |
* Applications use close() to gracefully close down an association. |
| 1456 |
* |
| 1457 |
* The syntax is: |
| 1458 |
* |
| 1459 |
* int close(int sd); |
| 1460 |
* |
| 1461 |
* sd - the socket descriptor of the association to be closed. |
| 1462 |
* |
| 1463 |
* After an application calls close() on a socket descriptor, no further |
| 1464 |
* socket operations will succeed on that descriptor. |
| 1465 |
* |
| 1466 |
* API 7.1.4 SO_LINGER |
| 1467 |
* |
| 1468 |
* An application using the TCP-style socket can use this option to |
| 1469 |
* perform the SCTP ABORT primitive. The linger option structure is: |
| 1470 |
* |
| 1471 |
* struct linger { |
| 1472 |
* int l_onoff; // option on/off |
| 1473 |
* int l_linger; // linger time |
| 1474 |
* }; |
| 1475 |
* |
| 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. |
| 1483 |
*/ |
| 1484 |
static void sctp_close(struct sock *sk, long timeout) |
| 1485 |
{ |
| 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; |
| 1491 |
|
| 1492 |
pr_debug("%s: sk:%p, timeout:%ld\n", __func__, sk, timeout); |
| 1493 |
|
| 1494 |
lock_sock_nested(sk, SINGLE_DEPTH_NESTING); |
| 1495 |
sk->sk_shutdown = SHUTDOWN_MASK; |
| 1496 |
inet_sk_set_state(sk, SCTP_SS_CLOSING); |
| 1497 |
|
| 1498 |
ep = sctp_sk(sk)->ep; |
| 1499 |
|
| 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); |
| 1503 |
|
| 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); |
| 1507 |
|
| 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. |
| 1513 |
*/ |
| 1514 |
if (sctp_state(asoc, CLOSED)) { |
| 1515 |
sctp_association_free(asoc); |
| 1516 |
continue; |
| 1517 |
} |
| 1518 |
} |
| 1519 |
|
| 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; |
| 1525 |
|
| 1526 |
chunk = sctp_make_abort_user(asoc, NULL, 0); |
| 1527 |
sctp_primitive_ABORT(net, asoc, chunk); |
| 1528 |
} else |
| 1529 |
sctp_primitive_SHUTDOWN(net, asoc, NULL); |
| 1530 |
} |
| 1531 |
|
| 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); |
| 1535 |
|
| 1536 |
/* This will run the backlog queue. */ |
| 1537 |
release_sock(sk); |
| 1538 |
|
| 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. |
| 1543 |
*/ |
| 1544 |
spin_lock_bh(&net->sctp.addr_wq_lock); |
| 1545 |
bh_lock_sock_nested(sk); |
| 1546 |
|
| 1547 |
/* Hold the sock, since sk_common_release() will put sock_put() |
| 1548 |
* and we have just a little more cleanup. |
| 1549 |
*/ |
| 1550 |
sock_hold(sk); |
| 1551 |
sk_common_release(sk); |
| 1552 |
|
| 1553 |
bh_unlock_sock(sk); |
| 1554 |
spin_unlock_bh(&net->sctp.addr_wq_lock); |
| 1555 |
|
| 1556 |
sock_put(sk); |
| 1557 |
} |
| 1558 |
|
| 1559 |
/* Handle EPIPE error. */ |
| 1560 |
static int sctp_error(struct sock *sk, int flags, int err) |
| 1561 |
{ |
| 1562 |
if (err == -EPIPE) |
| 1563 |
err = sock_error(sk) ? : -EPIPE; |
| 1564 |
if (err == -EPIPE && !(flags & MSG_NOSIGNAL)) |
| 1565 |
send_sig(SIGPIPE, current, 0); |
| 1566 |
return err; |
| 1567 |
} |
| 1568 |
|
| 1569 |
/* API 3.1.3 sendmsg() - UDP Style Syntax |
| 1570 |
* |
| 1571 |
* An application uses sendmsg() and recvmsg() calls to transmit data to |
| 1572 |
* and receive data from its peer. |
| 1573 |
* |
| 1574 |
* ssize_t sendmsg(int socket, const struct msghdr *message, |
| 1575 |
* int flags); |
| 1576 |
* |
| 1577 |
* socket - the socket descriptor of the endpoint. |
| 1578 |
* message - pointer to the msghdr structure which contains a single |
| 1579 |
* user message and possibly some ancillary data. |
| 1580 |
* |
| 1581 |
* See Section 5 for complete description of the data |
| 1582 |
* structures. |
| 1583 |
* |
| 1584 |
* flags - flags sent or received with the user message, see Section |
| 1585 |
* 5 for complete description of the flags. |
| 1586 |
* |
| 1587 |
* Note: This function could use a rewrite especially when explicit |
| 1588 |
* connect support comes in. |
| 1589 |
*/ |
| 1590 |
/* BUG: We do not implement the equivalent of sk_stream_wait_memory(). */ |
| 1591 |
|
| 1592 |
static int sctp_msghdr_parse(const struct msghdr *msg, |
| 1593 |
struct sctp_cmsgs *cmsgs); |
| 1594 |
|
| 1595 |
static int sctp_sendmsg_parse(struct sock *sk, struct sctp_cmsgs *cmsgs, |
| 1596 |
struct sctp_sndrcvinfo *srinfo, |
| 1597 |
const struct msghdr *msg, size_t msg_len) |
| 1598 |
{ |
| 1599 |
__u16 sflags; |
| 1600 |
int err; |
| 1601 |
|
| 1602 |
if (sctp_sstate(sk, LISTENING) && sctp_style(sk, TCP)) |
| 1603 |
return -EPIPE; |
| 1604 |
|
| 1605 |
if (msg_len > sk->sk_sndbuf) |
| 1606 |
return -EMSGSIZE; |
| 1607 |
|
| 1608 |
memset(cmsgs, 0, sizeof(*cmsgs)); |
| 1609 |
err = sctp_msghdr_parse(msg, cmsgs); |
| 1610 |
if (err) { |
| 1611 |
pr_debug("%s: msghdr parse err:%x\n", __func__, err); |
| 1612 |
return err; |
| 1613 |
} |
| 1614 |
|
| 1615 |
memset(srinfo, 0, sizeof(*srinfo)); |
| 1616 |
if (cmsgs->srinfo) { |
| 1617 |
srinfo->sinfo_stream = cmsgs->srinfo->sinfo_stream; |
| 1618 |
srinfo->sinfo_flags = cmsgs->srinfo->sinfo_flags; |
| 1619 |
srinfo->sinfo_ppid = cmsgs->srinfo->sinfo_ppid; |
| 1620 |
srinfo->sinfo_context = cmsgs->srinfo->sinfo_context; |
| 1621 |
srinfo->sinfo_assoc_id = cmsgs->srinfo->sinfo_assoc_id; |
| 1622 |
srinfo->sinfo_timetolive = cmsgs->srinfo->sinfo_timetolive; |
| 1623 |
} |
| 1624 |
|
| 1625 |
if (cmsgs->sinfo) { |
| 1626 |
srinfo->sinfo_stream = cmsgs->sinfo->snd_sid; |
| 1627 |
srinfo->sinfo_flags = cmsgs->sinfo->snd_flags; |
| 1628 |
srinfo->sinfo_ppid = cmsgs->sinfo->snd_ppid; |
| 1629 |
srinfo->sinfo_context = cmsgs->sinfo->snd_context; |
| 1630 |
srinfo->sinfo_assoc_id = cmsgs->sinfo->snd_assoc_id; |
| 1631 |
} |
| 1632 |
|
| 1633 |
if (cmsgs->prinfo) { |
| 1634 |
srinfo->sinfo_timetolive = cmsgs->prinfo->pr_value; |
| 1635 |
SCTP_PR_SET_POLICY(srinfo->sinfo_flags, |
| 1636 |
cmsgs->prinfo->pr_policy); |
| 1637 |
} |
| 1638 |
|
| 1639 |
sflags = srinfo->sinfo_flags; |
| 1640 |
if (!sflags && msg_len) |
| 1641 |
return 0; |
| 1642 |
|
| 1643 |
if (sctp_style(sk, TCP) && (sflags & (SCTP_EOF | SCTP_ABORT))) |
| 1644 |
return -EINVAL; |
| 1645 |
|
| 1646 |
if (((sflags & SCTP_EOF) && msg_len > 0) || |
| 1647 |
(!(sflags & (SCTP_EOF | SCTP_ABORT)) && msg_len == 0)) |
| 1648 |
return -EINVAL; |
| 1649 |
|
| 1650 |
if ((sflags & SCTP_ADDR_OVER) && !msg->msg_name) |
| 1651 |
return -EINVAL; |
| 1652 |
|
| 1653 |
return 0; |
| 1654 |
} |
| 1655 |
|
| 1656 |
static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags, |
| 1657 |
struct sctp_cmsgs *cmsgs, |
| 1658 |
union sctp_addr *daddr, |
| 1659 |
struct sctp_transport **tp) |
| 1660 |
{ |
| 1661 |
struct sctp_endpoint *ep = sctp_sk(sk)->ep; |
| 1662 |
struct sctp_association *asoc; |
| 1663 |
struct cmsghdr *cmsg; |
| 1664 |
__be32 flowinfo = 0; |
| 1665 |
struct sctp_af *af; |
| 1666 |
int err; |
| 1667 |
|
| 1668 |
*tp = NULL; |
| 1669 |
|
| 1670 |
if (sflags & (SCTP_EOF | SCTP_ABORT)) |
| 1671 |
return -EINVAL; |
| 1672 |
|
| 1673 |
if (sctp_style(sk, TCP) && (sctp_sstate(sk, ESTABLISHED) || |
| 1674 |
sctp_sstate(sk, CLOSING))) |
| 1675 |
return -EADDRNOTAVAIL; |
| 1676 |
|
| 1677 |
/* Label connection socket for first association 1-to-many |
| 1678 |
* style for client sequence socket()->sendmsg(). This |
| 1679 |
* needs to be done before sctp_assoc_add_peer() as that will |
| 1680 |
* set up the initial packet that needs to account for any |
| 1681 |
* security ip options (CIPSO/CALIPSO) added to the packet. |
| 1682 |
*/ |
| 1683 |
af = sctp_get_af_specific(daddr->sa.sa_family); |
| 1684 |
if (!af) |
| 1685 |
return -EINVAL; |
| 1686 |
err = security_sctp_bind_connect(sk, SCTP_SENDMSG_CONNECT, |
| 1687 |
(struct sockaddr *)daddr, |
| 1688 |
af->sockaddr_len); |
| 1689 |
if (err < 0) |
| 1690 |
return err; |
| 1691 |
|
| 1692 |
err = sctp_connect_new_asoc(ep, daddr, cmsgs->init, tp); |
| 1693 |
if (err) |
| 1694 |
return err; |
| 1695 |
asoc = (*tp)->asoc; |
| 1696 |
|
| 1697 |
if (!cmsgs->addrs_msg) |
| 1698 |
return 0; |
| 1699 |
|
| 1700 |
if (daddr->sa.sa_family == AF_INET6) |
| 1701 |
flowinfo = daddr->v6.sin6_flowinfo; |
| 1702 |
|
| 1703 |
/* sendv addr list parse */ |
| 1704 |
for_each_cmsghdr(cmsg, cmsgs->addrs_msg) { |
| 1705 |
union sctp_addr _daddr; |
| 1706 |
int dlen; |
| 1707 |
|
| 1708 |
if (cmsg->cmsg_level != IPPROTO_SCTP || |
| 1709 |
(cmsg->cmsg_type != SCTP_DSTADDRV4 && |
| 1710 |
cmsg->cmsg_type != SCTP_DSTADDRV6)) |
| 1711 |
continue; |
| 1712 |
|
| 1713 |
daddr = &_daddr; |
| 1714 |
memset(daddr, 0, sizeof(*daddr)); |
| 1715 |
dlen = cmsg->cmsg_len - sizeof(struct cmsghdr); |
| 1716 |
if (cmsg->cmsg_type == SCTP_DSTADDRV4) { |
| 1717 |
if (dlen < sizeof(struct in_addr)) { |
| 1718 |
err = -EINVAL; |
| 1719 |
goto free; |
| 1720 |
} |
| 1721 |
|
| 1722 |
dlen = sizeof(struct in_addr); |
| 1723 |
daddr->v4.sin_family = AF_INET; |
| 1724 |
daddr->v4.sin_port = htons(asoc->peer.port); |
| 1725 |
memcpy(&daddr->v4.sin_addr, CMSG_DATA(cmsg), dlen); |
| 1726 |
} else { |
| 1727 |
if (dlen < sizeof(struct in6_addr)) { |
| 1728 |
err = -EINVAL; |
| 1729 |
goto free; |
| 1730 |
} |
| 1731 |
|
| 1732 |
dlen = sizeof(struct in6_addr); |
| 1733 |
daddr->v6.sin6_flowinfo = flowinfo; |
| 1734 |
daddr->v6.sin6_family = AF_INET6; |
| 1735 |
daddr->v6.sin6_port = htons(asoc->peer.port); |
| 1736 |
memcpy(&daddr->v6.sin6_addr, CMSG_DATA(cmsg), dlen); |
| 1737 |
} |
| 1738 |
|
| 1739 |
err = sctp_connect_add_peer(asoc, daddr, sizeof(*daddr)); |
| 1740 |
if (err) |
| 1741 |
goto free; |
| 1742 |
} |
| 1743 |
|
| 1744 |
return 0; |
| 1745 |
|
| 1746 |
free: |
| 1747 |
sctp_association_free(asoc); |
| 1748 |
return err; |
| 1749 |
} |
| 1750 |
|
| 1751 |
static int sctp_sendmsg_check_sflags(struct sctp_association *asoc, |
| 1752 |
__u16 sflags, struct msghdr *msg, |
| 1753 |
size_t msg_len) |
| 1754 |
{ |
| 1755 |
struct sock *sk = asoc->base.sk; |
| 1756 |
struct net *net = sock_net(sk); |
| 1757 |
|
| 1758 |
if (sctp_state(asoc, CLOSED) && sctp_style(sk, TCP)) |
| 1759 |
return -EPIPE; |
| 1760 |
|
| 1761 |
if ((sflags & SCTP_SENDALL) && sctp_style(sk, UDP) && |
| 1762 |
!sctp_state(asoc, ESTABLISHED)) |
| 1763 |
return 0; |
| 1764 |
|
| 1765 |
if (sflags & SCTP_EOF) { |
| 1766 |
pr_debug("%s: shutting down association:%p\n", __func__, asoc); |
| 1767 |
sctp_primitive_SHUTDOWN(net, asoc, NULL); |
| 1768 |
|
| 1769 |
return 0; |
| 1770 |
} |
| 1771 |
|
| 1772 |
if (sflags & SCTP_ABORT) { |
| 1773 |
struct sctp_chunk *chunk; |
| 1774 |
|
| 1775 |
chunk = sctp_make_abort_user(asoc, msg, msg_len); |
| 1776 |
if (!chunk) |
| 1777 |
return -ENOMEM; |
| 1778 |
|
| 1779 |
pr_debug("%s: aborting association:%p\n", __func__, asoc); |
| 1780 |
sctp_primitive_ABORT(net, asoc, chunk); |
| 1781 |
iov_iter_revert(&msg->msg_iter, msg_len); |
| 1782 |
|
| 1783 |
return 0; |
| 1784 |
} |
| 1785 |
|
| 1786 |
return 1; |
| 1787 |
} |
| 1788 |
|
| 1789 |
static int sctp_sendmsg_to_asoc(struct sctp_association *asoc, |
| 1790 |
struct msghdr *msg, size_t msg_len, |
| 1791 |
struct sctp_transport *transport, |
| 1792 |
struct sctp_sndrcvinfo *sinfo) |
| 1793 |
{ |
| 1794 |
struct sock *sk = asoc->base.sk; |
| 1795 |
struct sctp_sock *sp = sctp_sk(sk); |
| 1796 |
struct net *net = sock_net(sk); |
| 1797 |
struct sctp_datamsg *datamsg; |
| 1798 |
bool wait_connect = false; |
| 1799 |
struct sctp_chunk *chunk; |
| 1800 |
long timeo; |
| 1801 |
int err; |
| 1802 |
|
| 1803 |
if (sinfo->sinfo_stream >= asoc->stream.outcnt) { |
| 1804 |
err = -EINVAL; |
| 1805 |
goto err; |
| 1806 |
} |
| 1807 |
|
| 1808 |
if (unlikely(!SCTP_SO(&asoc->stream, sinfo->sinfo_stream)->ext)) { |
| 1809 |
err = sctp_stream_init_ext(&asoc->stream, sinfo->sinfo_stream); |
| 1810 |
if (err) |
| 1811 |
goto err; |
| 1812 |
} |
| 1813 |
|
| 1814 |
if (sp->disable_fragments && msg_len > asoc->frag_point) { |
| 1815 |
err = -EMSGSIZE; |
| 1816 |
goto err; |
| 1817 |
} |
| 1818 |
|
| 1819 |
if (asoc->pmtu_pending) { |
| 1820 |
if (sp->param_flags & SPP_PMTUD_ENABLE) |
| 1821 |
sctp_assoc_sync_pmtu(asoc); |
| 1822 |
asoc->pmtu_pending = 0; |
| 1823 |
} |
| 1824 |
|
| 1825 |
if (sctp_wspace(asoc) < (int)msg_len) |
| 1826 |
sctp_prsctp_prune(asoc, sinfo, msg_len - sctp_wspace(asoc)); |
| 1827 |
|
| 1828 |
if (sctp_wspace(asoc) <= 0 || !sk_wmem_schedule(sk, msg_len)) { |
| 1829 |
timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT); |
| 1830 |
err = sctp_wait_for_sndbuf(asoc, transport, &timeo, msg_len); |
| 1831 |
if (err) |
| 1832 |
goto err; |
| 1833 |
if (unlikely(sinfo->sinfo_stream >= asoc->stream.outcnt)) { |
| 1834 |
err = -EINVAL; |
| 1835 |
goto err; |
| 1836 |
} |
| 1837 |
} |
| 1838 |
|
| 1839 |
if (sctp_state(asoc, CLOSED)) { |
| 1840 |
err = sctp_primitive_ASSOCIATE(net, asoc, NULL); |
| 1841 |
if (err) |
| 1842 |
goto err; |
| 1843 |
|
| 1844 |
if (asoc->ep->intl_enable) { |
| 1845 |
timeo = sock_sndtimeo(sk, 0); |
| 1846 |
err = sctp_wait_for_connect(asoc, &timeo); |
| 1847 |
if (err) { |
| 1848 |
err = -ESRCH; |
| 1849 |
goto err; |
| 1850 |
} |
| 1851 |
} else { |
| 1852 |
wait_connect = true; |
| 1853 |
} |
| 1854 |
|
| 1855 |
pr_debug("%s: we associated primitively\n", __func__); |
| 1856 |
} |
| 1857 |
|
| 1858 |
datamsg = sctp_datamsg_from_user(asoc, sinfo, &msg->msg_iter); |
| 1859 |
if (IS_ERR(datamsg)) { |
| 1860 |
err = PTR_ERR(datamsg); |
| 1861 |
goto err; |
| 1862 |
} |
| 1863 |
|
| 1864 |
asoc->force_delay = !!(msg->msg_flags & MSG_MORE); |
| 1865 |
|
| 1866 |
list_for_each_entry(chunk, &datamsg->chunks, frag_list) { |
| 1867 |
sctp_chunk_hold(chunk); |
| 1868 |
sctp_set_owner_w(chunk); |
| 1869 |
chunk->transport = transport; |
| 1870 |
} |
| 1871 |
|
| 1872 |
err = sctp_primitive_SEND(net, asoc, datamsg); |
| 1873 |
if (err) { |
| 1874 |
sctp_datamsg_free(datamsg); |
| 1875 |
goto err; |
| 1876 |
} |
| 1877 |
|
| 1878 |
pr_debug("%s: we sent primitively\n", __func__); |
| 1879 |
|
| 1880 |
sctp_datamsg_put(datamsg); |
| 1881 |
|
| 1882 |
if (unlikely(wait_connect)) { |
| 1883 |
timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT); |
| 1884 |
sctp_wait_for_connect(asoc, &timeo); |
| 1885 |
} |
| 1886 |
|
| 1887 |
err = msg_len; |
| 1888 |
|
| 1889 |
err: |
| 1890 |
return err; |
| 1891 |
} |
| 1892 |
|
| 1893 |
static union sctp_addr *sctp_sendmsg_get_daddr(struct sock *sk, |
| 1894 |
const struct msghdr *msg, |
| 1895 |
struct sctp_cmsgs *cmsgs) |
| 1896 |
{ |
| 1897 |
union sctp_addr *daddr = NULL; |
| 1898 |
int err; |
| 1899 |
|
| 1900 |
if (!sctp_style(sk, UDP_HIGH_BANDWIDTH) && msg->msg_name) { |
| 1901 |
int len = msg->msg_namelen; |
| 1902 |
|
| 1903 |
if (len > sizeof(*daddr)) |
| 1904 |
len = sizeof(*daddr); |
| 1905 |
|
| 1906 |
daddr = (union sctp_addr *)msg->msg_name; |
| 1907 |
|
| 1908 |
err = sctp_verify_addr(sk, daddr, len); |
| 1909 |
if (err) |
| 1910 |
return ERR_PTR(err); |
| 1911 |
} |
| 1912 |
|
| 1913 |
return daddr; |
| 1914 |
} |
| 1915 |
|
| 1916 |
static void sctp_sendmsg_update_sinfo(struct sctp_association *asoc, |
| 1917 |
struct sctp_sndrcvinfo *sinfo, |
| 1918 |
struct sctp_cmsgs *cmsgs) |
| 1919 |
{ |
| 1920 |
if (!cmsgs->srinfo && !cmsgs->sinfo) { |
| 1921 |
sinfo->sinfo_stream = asoc->default_stream; |
| 1922 |
sinfo->sinfo_ppid = asoc->default_ppid; |
| 1923 |
sinfo->sinfo_context = asoc->default_context; |
| 1924 |
sinfo->sinfo_assoc_id = sctp_assoc2id(asoc); |
| 1925 |
|
| 1926 |
if (!cmsgs->prinfo) |
| 1927 |
sinfo->sinfo_flags = asoc->default_flags; |
| 1928 |
} |
| 1929 |
|
| 1930 |
if (!cmsgs->srinfo && !cmsgs->prinfo) |
| 1931 |
sinfo->sinfo_timetolive = asoc->default_timetolive; |
| 1932 |
|
| 1933 |
if (cmsgs->authinfo) { |
| 1934 |
/* Reuse sinfo_tsn to indicate that authinfo was set and |
| 1935 |
* sinfo_ssn to save the keyid on tx path. |
| 1936 |
*/ |
| 1937 |
sinfo->sinfo_tsn = 1; |
| 1938 |
sinfo->sinfo_ssn = cmsgs->authinfo->auth_keynumber; |
| 1939 |
} |
| 1940 |
} |
| 1941 |
|
| 1942 |
static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len) |
| 1943 |
{ |
| 1944 |
struct sctp_endpoint *ep = sctp_sk(sk)->ep; |
| 1945 |
struct sctp_transport *transport = NULL; |
| 1946 |
struct sctp_sndrcvinfo _sinfo, *sinfo; |
| 1947 |
struct sctp_association *asoc, *tmp; |
| 1948 |
struct sctp_cmsgs cmsgs; |
| 1949 |
union sctp_addr *daddr; |
| 1950 |
bool new = false; |
| 1951 |
__u16 sflags; |
| 1952 |
int err; |
| 1953 |
|
| 1954 |
/* Parse and get snd_info */ |
| 1955 |
err = sctp_sendmsg_parse(sk, &cmsgs, &_sinfo, msg, msg_len); |
| 1956 |
if (err) |
| 1957 |
goto out; |
| 1958 |
|
| 1959 |
sinfo = &_sinfo; |
| 1960 |
sflags = sinfo->sinfo_flags; |
| 1961 |
|
| 1962 |
/* Get daddr from msg */ |
| 1963 |
daddr = sctp_sendmsg_get_daddr(sk, msg, &cmsgs); |
| 1964 |
if (IS_ERR(daddr)) { |
| 1965 |
err = PTR_ERR(daddr); |
| 1966 |
goto out; |
| 1967 |
} |
| 1968 |
|
| 1969 |
lock_sock(sk); |
| 1970 |
|
| 1971 |
/* SCTP_SENDALL process */ |
| 1972 |
if ((sflags & SCTP_SENDALL) && sctp_style(sk, UDP)) { |
| 1973 |
list_for_each_entry_safe(asoc, tmp, &ep->asocs, asocs) { |
| 1974 |
err = sctp_sendmsg_check_sflags(asoc, sflags, msg, |
| 1975 |
msg_len); |
| 1976 |
if (err == 0) |
| 1977 |
continue; |
| 1978 |
if (err < 0) |
| 1979 |
goto out_unlock; |
| 1980 |
|
| 1981 |
sctp_sendmsg_update_sinfo(asoc, sinfo, &cmsgs); |
| 1982 |
|
| 1983 |
err = sctp_sendmsg_to_asoc(asoc, msg, msg_len, |
| 1984 |
NULL, sinfo); |
| 1985 |
if (err < 0) |
| 1986 |
goto out_unlock; |
| 1987 |
|
| 1988 |
iov_iter_revert(&msg->msg_iter, err); |
| 1989 |
|
| 1990 |
/* sctp_sendmsg_to_asoc() may have released the socket |
| 1991 |
* lock (sctp_wait_for_sndbuf), during which other |
| 1992 |
* associations on ep->asocs could have been peeled |
| 1993 |
* off or freed. @asoc itself is revalidated by the |
| 1994 |
* base.dead and base.sk checks in sctp_wait_for_sndbuf, |
| 1995 |
* so re-derive the cached cursor from it. |
| 1996 |
*/ |
| 1997 |
tmp = list_next_entry(asoc, asocs); |
| 1998 |
} |
| 1999 |
|
| 2000 |
goto out_unlock; |
| 2001 |
} |
| 2002 |
|
| 2003 |
/* Get and check or create asoc */ |
| 2004 |
if (daddr) { |
| 2005 |
asoc = sctp_endpoint_lookup_assoc(ep, daddr, &transport); |
| 2006 |
if (asoc) { |
| 2007 |
err = sctp_sendmsg_check_sflags(asoc, sflags, msg, |
| 2008 |
msg_len); |
| 2009 |
if (err <= 0) |
| 2010 |
goto out_unlock; |
| 2011 |
} else { |
| 2012 |
err = sctp_sendmsg_new_asoc(sk, sflags, &cmsgs, daddr, |
| 2013 |
&transport); |
| 2014 |
if (err) |
| 2015 |
goto out_unlock; |
| 2016 |
|
| 2017 |
asoc = transport->asoc; |
| 2018 |
new = true; |
| 2019 |
} |
| 2020 |
|
| 2021 |
if (!sctp_style(sk, TCP) && !(sflags & SCTP_ADDR_OVER)) |
| 2022 |
transport = NULL; |
| 2023 |
} else { |
| 2024 |
asoc = sctp_id2assoc(sk, sinfo->sinfo_assoc_id); |
| 2025 |
if (!asoc) { |
| 2026 |
err = -EPIPE; |
| 2027 |
goto out_unlock; |
| 2028 |
} |
| 2029 |
|
| 2030 |
err = sctp_sendmsg_check_sflags(asoc, sflags, msg, msg_len); |
| 2031 |
if (err <= 0) |
| 2032 |
goto out_unlock; |
| 2033 |
} |
| 2034 |
|
| 2035 |
/* Update snd_info with the asoc */ |
| 2036 |
sctp_sendmsg_update_sinfo(asoc, sinfo, &cmsgs); |
| 2037 |
|
| 2038 |
/* Send msg to the asoc */ |
| 2039 |
err = sctp_sendmsg_to_asoc(asoc, msg, msg_len, transport, sinfo); |
| 2040 |
if (err < 0 && err != -ESRCH && new) |
| 2041 |
sctp_association_free(asoc); |
| 2042 |
|
| 2043 |
out_unlock: |
| 2044 |
release_sock(sk); |
| 2045 |
out: |
| 2046 |
return sctp_error(sk, msg->msg_flags, err); |
| 2047 |
} |
| 2048 |
|
| 2049 |
/* This is an extended version of skb_pull() that removes the data from the |
| 2050 |
* start of a skb even when data is spread across the list of skb's in the |
| 2051 |
* frag_list. len specifies the total amount of data that needs to be removed. |
| 2052 |
* when 'len' bytes could be removed from the skb, it returns 0. |
| 2053 |
* If 'len' exceeds the total skb length, it returns the no. of bytes that |
| 2054 |
* could not be removed. |
| 2055 |
*/ |
| 2056 |
static int sctp_skb_pull(struct sk_buff *skb, int len) |
| 2057 |
{ |
| 2058 |
struct sk_buff *list; |
| 2059 |
int skb_len = skb_headlen(skb); |
| 2060 |
int rlen; |
| 2061 |
|
| 2062 |
if (len <= skb_len) { |
| 2063 |
__skb_pull(skb, len); |
| 2064 |
return 0; |
| 2065 |
} |
| 2066 |
len -= skb_len; |
| 2067 |
__skb_pull(skb, skb_len); |
| 2068 |
|
| 2069 |
skb_walk_frags(skb, list) { |
| 2070 |
rlen = sctp_skb_pull(list, len); |
| 2071 |
skb->len -= (len-rlen); |
| 2072 |
skb->data_len -= (len-rlen); |
| 2073 |
|
| 2074 |
if (!rlen) |
| 2075 |
return 0; |
| 2076 |
|
| 2077 |
len = rlen; |
| 2078 |
} |
| 2079 |
|
| 2080 |
return len; |
| 2081 |
} |
| 2082 |
|
| 2083 |
/* API 3.1.3 recvmsg() - UDP Style Syntax |
| 2084 |
* |
| 2085 |
* ssize_t recvmsg(int socket, struct msghdr *message, |
| 2086 |
* int flags); |
| 2087 |
* |
| 2088 |
* socket - the socket descriptor of the endpoint. |
| 2089 |
* message - pointer to the msghdr structure which contains a single |
| 2090 |
* user message and possibly some ancillary data. |
| 2091 |
* |
| 2092 |
* See Section 5 for complete description of the data |
| 2093 |
* structures. |
| 2094 |
* |
| 2095 |
* flags - flags sent or received with the user message, see Section |
| 2096 |
* 5 for complete description of the flags. |
| 2097 |
*/ |
| 2098 |
static int sctp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, |
| 2099 |
int flags, int *addr_len) |
| 2100 |
{ |
| 2101 |
struct sctp_ulpevent *event = NULL; |
| 2102 |
struct sctp_sock *sp = sctp_sk(sk); |
| 2103 |
struct sk_buff *skb, *head_skb; |
| 2104 |
int copied; |
| 2105 |
int err = 0; |
| 2106 |
int skb_len; |
| 2107 |
|
| 2108 |
pr_debug("%s: sk:%p, msghdr:%p, len:%zd, flags:0x%x, addr_len:%p)\n", |
| 2109 |
__func__, sk, msg, len, flags, addr_len); |
| 2110 |
|
| 2111 |
if (unlikely(flags & MSG_ERRQUEUE)) |
| 2112 |
return inet_recv_error(sk, msg, len, addr_len); |
| 2113 |
|
| 2114 |
if (sk_can_busy_loop(sk) && |
| 2115 |
skb_queue_empty_lockless(&sk->sk_receive_queue)) |
| 2116 |
sk_busy_loop(sk, flags & MSG_DONTWAIT); |
| 2117 |
|
| 2118 |
lock_sock(sk); |
| 2119 |
|
| 2120 |
if (sctp_style(sk, TCP) && !sctp_sstate(sk, ESTABLISHED) && |
| 2121 |
!sctp_sstate(sk, CLOSING) && !sctp_sstate(sk, CLOSED)) { |
| 2122 |
err = -ENOTCONN; |
| 2123 |
goto out; |
| 2124 |
} |
| 2125 |
|
| 2126 |
skb = sctp_skb_recv_datagram(sk, flags, &err); |
| 2127 |
if (!skb) |
| 2128 |
goto out; |
| 2129 |
|
| 2130 |
/* Get the total length of the skb including any skb's in the |
| 2131 |
* frag_list. |
| 2132 |
*/ |
| 2133 |
skb_len = skb->len; |
| 2134 |
|
| 2135 |
copied = skb_len; |
| 2136 |
if (copied > len) |
| 2137 |
copied = len; |
| 2138 |
|
| 2139 |
err = skb_copy_datagram_msg(skb, 0, msg, copied); |
| 2140 |
|
| 2141 |
event = sctp_skb2event(skb); |
| 2142 |
|
| 2143 |
if (err) |
| 2144 |
goto out_free; |
| 2145 |
|
| 2146 |
if (event->chunk && event->chunk->head_skb) |
| 2147 |
head_skb = event->chunk->head_skb; |
| 2148 |
else |
| 2149 |
head_skb = skb; |
| 2150 |
sock_recv_cmsgs(msg, sk, head_skb); |
| 2151 |
if (sctp_ulpevent_is_notification(event)) { |
| 2152 |
msg->msg_flags |= MSG_NOTIFICATION; |
| 2153 |
sp->pf->event_msgname(event, msg->msg_name, addr_len); |
| 2154 |
} else { |
| 2155 |
sp->pf->skb_msgname(head_skb, msg->msg_name, addr_len); |
| 2156 |
} |
| 2157 |
|
| 2158 |
/* Check if we allow SCTP_NXTINFO. */ |
| 2159 |
if (sp->recvnxtinfo) |
| 2160 |
sctp_ulpevent_read_nxtinfo(event, msg, sk); |
| 2161 |
/* Check if we allow SCTP_RCVINFO. */ |
| 2162 |
if (sp->recvrcvinfo) |
| 2163 |
sctp_ulpevent_read_rcvinfo(event, msg); |
| 2164 |
/* Check if we allow SCTP_SNDRCVINFO. */ |
| 2165 |
if (sctp_ulpevent_type_enabled(sp->subscribe, SCTP_DATA_IO_EVENT)) |
| 2166 |
sctp_ulpevent_read_sndrcvinfo(event, msg); |
| 2167 |
|
| 2168 |
err = copied; |
| 2169 |
|
| 2170 |
/* If skb's length exceeds the user's buffer, update the skb and |
| 2171 |
* push it back to the receive_queue so that the next call to |
| 2172 |
* recvmsg() will return the remaining data. Don't set MSG_EOR. |
| 2173 |
*/ |
| 2174 |
if (skb_len > copied) { |
| 2175 |
msg->msg_flags &= ~MSG_EOR; |
| 2176 |
if (flags & MSG_PEEK) |
| 2177 |
goto out_free; |
| 2178 |
sctp_skb_pull(skb, copied); |
| 2179 |
skb_queue_head(&sk->sk_receive_queue, skb); |
| 2180 |
|
| 2181 |
/* When only partial message is copied to the user, increase |
| 2182 |
* rwnd by that amount. If all the data in the skb is read, |
| 2183 |
* rwnd is updated when the event is freed. |
| 2184 |
*/ |
| 2185 |
if (!sctp_ulpevent_is_notification(event)) |
| 2186 |
sctp_assoc_rwnd_increase(event->asoc, copied); |
| 2187 |
goto out; |
| 2188 |
} else if ((event->msg_flags & MSG_NOTIFICATION) || |
| 2189 |
(event->msg_flags & MSG_EOR)) |
| 2190 |
msg->msg_flags |= MSG_EOR; |
| 2191 |
else |
| 2192 |
msg->msg_flags &= ~MSG_EOR; |
| 2193 |
|
| 2194 |
out_free: |
| 2195 |
if (flags & MSG_PEEK) { |
| 2196 |
/* Release the skb reference acquired after peeking the skb in |
| 2197 |
* sctp_skb_recv_datagram(). |
| 2198 |
*/ |
| 2199 |
kfree_skb(skb); |
| 2200 |
} else { |
| 2201 |
/* Free the event which includes releasing the reference to |
| 2202 |
* the owner of the skb, freeing the skb and updating the |
| 2203 |
* rwnd. |
| 2204 |
*/ |
| 2205 |
sctp_ulpevent_free(event); |
| 2206 |
} |
| 2207 |
out: |
| 2208 |
release_sock(sk); |
| 2209 |
return err; |
| 2210 |
} |
| 2211 |
|
| 2212 |
/* 7.1.12 Enable/Disable message fragmentation (SCTP_DISABLE_FRAGMENTS) |
| 2213 |
* |
| 2214 |
* This option is a on/off flag. If enabled no SCTP message |
| 2215 |
* fragmentation will be performed. Instead if a message being sent |
| 2216 |
* exceeds the current PMTU size, the message will NOT be sent and |
| 2217 |
* instead a error will be indicated to the user. |
| 2218 |
*/ |
| 2219 |
static int sctp_setsockopt_disable_fragments(struct sock *sk, int *val, |
| 2220 |
unsigned int optlen) |
| 2221 |
{ |
| 2222 |
if (optlen < sizeof(int)) |
| 2223 |
return -EINVAL; |
| 2224 |
sctp_sk(sk)->disable_fragments = (*val == 0) ? 0 : 1; |
| 2225 |
return 0; |
| 2226 |
} |
| 2227 |
|
| 2228 |
static int sctp_setsockopt_events(struct sock *sk, __u8 *sn_type, |
| 2229 |
unsigned int optlen) |
| 2230 |
{ |
| 2231 |
struct sctp_sock *sp = sctp_sk(sk); |
| 2232 |
struct sctp_association *asoc; |
| 2233 |
int i; |
| 2234 |
|
| 2235 |
if (optlen > sizeof(struct sctp_event_subscribe)) |
| 2236 |
return -EINVAL; |
| 2237 |
|
| 2238 |
for (i = 0; i < optlen; i++) |
| 2239 |
sctp_ulpevent_type_set(&sp->subscribe, SCTP_SN_TYPE_BASE + i, |
| 2240 |
sn_type[i]); |
| 2241 |
|
| 2242 |
list_for_each_entry(asoc, &sp->ep->asocs, asocs) |
| 2243 |
asoc->subscribe = sctp_sk(sk)->subscribe; |
| 2244 |
|
| 2245 |
/* At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT, |
| 2246 |
* if there is no data to be sent or retransmit, the stack will |
| 2247 |
* immediately send up this notification. |
| 2248 |
*/ |
| 2249 |
if (sctp_ulpevent_type_enabled(sp->subscribe, SCTP_SENDER_DRY_EVENT)) { |
| 2250 |
struct sctp_ulpevent *event; |
| 2251 |
|
| 2252 |
asoc = sctp_id2assoc(sk, 0); |
| 2253 |
if (asoc && sctp_outq_is_empty(&asoc->outqueue)) { |
| 2254 |
event = sctp_ulpevent_make_sender_dry_event(asoc, |
| 2255 |
GFP_USER | __GFP_NOWARN); |
| 2256 |
if (!event) |
| 2257 |
return -ENOMEM; |
| 2258 |
|
| 2259 |
asoc->stream.si->enqueue_event(&asoc->ulpq, event); |
| 2260 |
} |
| 2261 |
} |
| 2262 |
|
| 2263 |
return 0; |
| 2264 |
} |
| 2265 |
|
| 2266 |
/* 7.1.8 Automatic Close of associations (SCTP_AUTOCLOSE) |
| 2267 |
* |
| 2268 |
* This socket option is applicable to the UDP-style socket only. When |
| 2269 |
* set it will cause associations that are idle for more than the |
| 2270 |
* specified number of seconds to automatically close. An association |
| 2271 |
* being idle is defined an association that has NOT sent or received |
| 2272 |
* user data. The special value of '0' indicates that no automatic |
| 2273 |
* close of any associations should be performed. The option expects an |
| 2274 |
* integer defining the number of seconds of idle time before an |
| 2275 |
* association is closed. |
| 2276 |
*/ |
| 2277 |
static int sctp_setsockopt_autoclose(struct sock *sk, u32 *optval, |
| 2278 |
unsigned int optlen) |
| 2279 |
{ |
| 2280 |
struct sctp_sock *sp = sctp_sk(sk); |
| 2281 |
struct net *net = sock_net(sk); |
| 2282 |
|
| 2283 |
/* Applicable to UDP-style socket only */ |
| 2284 |
if (sctp_style(sk, TCP)) |
| 2285 |
return -EOPNOTSUPP; |
| 2286 |
if (optlen != sizeof(int)) |
| 2287 |
return -EINVAL; |
| 2288 |
|
| 2289 |
sp->autoclose = *optval; |
| 2290 |
if (sp->autoclose > net->sctp.max_autoclose) |
| 2291 |
sp->autoclose = net->sctp.max_autoclose; |
| 2292 |
|
| 2293 |
return 0; |
| 2294 |
} |
| 2295 |
|
| 2296 |
/* 7.1.13 Peer Address Parameters (SCTP_PEER_ADDR_PARAMS) |
| 2297 |
* |
| 2298 |
* Applications can enable or disable heartbeats for any peer address of |
| 2299 |
* an association, modify an address's heartbeat interval, force a |
| 2300 |
* heartbeat to be sent immediately, and adjust the address's maximum |
| 2301 |
* number of retransmissions sent before an address is considered |
| 2302 |
* unreachable. The following structure is used to access and modify an |
| 2303 |
* address's parameters: |
| 2304 |
* |
| 2305 |
* struct sctp_paddrparams { |
| 2306 |
* sctp_assoc_t spp_assoc_id; |
| 2307 |
* struct sockaddr_storage spp_address; |
| 2308 |
* uint32_t spp_hbinterval; |
| 2309 |
* uint16_t spp_pathmaxrxt; |
| 2310 |
* uint32_t spp_pathmtu; |
| 2311 |
* uint32_t spp_sackdelay; |
| 2312 |
* uint32_t spp_flags; |
| 2313 |
* uint32_t spp_ipv6_flowlabel; |
| 2314 |
* uint8_t spp_dscp; |
| 2315 |
* }; |
| 2316 |
* |
| 2317 |
* spp_assoc_id - (one-to-many style socket) This is filled in the |
| 2318 |
* application, and identifies the association for |
| 2319 |
* this query. |
| 2320 |
* spp_address - This specifies which address is of interest. |
| 2321 |
* spp_hbinterval - This contains the value of the heartbeat interval, |
| 2322 |
* in milliseconds. If a value of zero |
| 2323 |
* is present in this field then no changes are to |
| 2324 |
* be made to this parameter. |
| 2325 |
* spp_pathmaxrxt - This contains the maximum number of |
| 2326 |
* retransmissions before this address shall be |
| 2327 |
* considered unreachable. If a value of zero |
| 2328 |
* is present in this field then no changes are to |
| 2329 |
* be made to this parameter. |
| 2330 |
* spp_pathmtu - When Path MTU discovery is disabled the value |
| 2331 |
* specified here will be the "fixed" path mtu. |
| 2332 |
* Note that if the spp_address field is empty |
| 2333 |
* then all associations on this address will |
| 2334 |
* have this fixed path mtu set upon them. |
| 2335 |
* |
| 2336 |
* spp_sackdelay - When delayed sack is enabled, this value specifies |
| 2337 |
* the number of milliseconds that sacks will be delayed |
| 2338 |
* for. This value will apply to all addresses of an |
| 2339 |
* association if the spp_address field is empty. Note |
| 2340 |
* also, that if delayed sack is enabled and this |
| 2341 |
* value is set to 0, no change is made to the last |
| 2342 |
* recorded delayed sack timer value. |
| 2343 |
* |
| 2344 |
* spp_flags - These flags are used to control various features |
| 2345 |
* on an association. The flag field may contain |
| 2346 |
* zero or more of the following options. |
| 2347 |
* |
| 2348 |
* SPP_HB_ENABLE - Enable heartbeats on the |
| 2349 |
* specified address. Note that if the address |
| 2350 |
* field is empty all addresses for the association |
| 2351 |
* have heartbeats enabled upon them. |
| 2352 |
* |
| 2353 |
* SPP_HB_DISABLE - Disable heartbeats on the |
| 2354 |
* speicifed address. Note that if the address |
| 2355 |
* field is empty all addresses for the association |
| 2356 |
* will have their heartbeats disabled. Note also |
| 2357 |
* that SPP_HB_ENABLE and SPP_HB_DISABLE are |
| 2358 |
* mutually exclusive, only one of these two should |
| 2359 |
* be specified. Enabling both fields will have |
| 2360 |
* undetermined results. |
| 2361 |
* |
| 2362 |
* SPP_HB_DEMAND - Request a user initiated heartbeat |
| 2363 |
* to be made immediately. |
| 2364 |
* |
| 2365 |
* SPP_HB_TIME_IS_ZERO - Specify's that the time for |
| 2366 |
* heartbeat delayis to be set to the value of 0 |
| 2367 |
* milliseconds. |
| 2368 |
* |
| 2369 |
* SPP_PMTUD_ENABLE - This field will enable PMTU |
| 2370 |
* discovery upon the specified address. Note that |
| 2371 |
* if the address feild is empty then all addresses |
| 2372 |
* on the association are effected. |
| 2373 |
* |
| 2374 |
* SPP_PMTUD_DISABLE - This field will disable PMTU |
| 2375 |
* discovery upon the specified address. Note that |
| 2376 |
* if the address feild is empty then all addresses |
| 2377 |
* on the association are effected. Not also that |
| 2378 |
* SPP_PMTUD_ENABLE and SPP_PMTUD_DISABLE are mutually |
| 2379 |
* exclusive. Enabling both will have undetermined |
| 2380 |
* results. |
| 2381 |
* |
| 2382 |
* SPP_SACKDELAY_ENABLE - Setting this flag turns |
| 2383 |
* on delayed sack. The time specified in spp_sackdelay |
| 2384 |
* is used to specify the sack delay for this address. Note |
| 2385 |
* that if spp_address is empty then all addresses will |
| 2386 |
* enable delayed sack and take on the sack delay |
| 2387 |
* value specified in spp_sackdelay. |
| 2388 |
* SPP_SACKDELAY_DISABLE - Setting this flag turns |
| 2389 |
* off delayed sack. If the spp_address field is blank then |
| 2390 |
* delayed sack is disabled for the entire association. Note |
| 2391 |
* also that this field is mutually exclusive to |
| 2392 |
* SPP_SACKDELAY_ENABLE, setting both will have undefined |
| 2393 |
* results. |
| 2394 |
* |
| 2395 |
* SPP_IPV6_FLOWLABEL: Setting this flag enables the |
| 2396 |
* setting of the IPV6 flow label value. The value is |
| 2397 |
* contained in the spp_ipv6_flowlabel field. |
| 2398 |
* Upon retrieval, this flag will be set to indicate that |
| 2399 |
* the spp_ipv6_flowlabel field has a valid value returned. |
| 2400 |
* If a specific destination address is set (in the |
| 2401 |
* spp_address field), then the value returned is that of |
| 2402 |
* the address. If just an association is specified (and |
| 2403 |
* no address), then the association's default flow label |
| 2404 |
* is returned. If neither an association nor a destination |
| 2405 |
* is specified, then the socket's default flow label is |
| 2406 |
* returned. For non-IPv6 sockets, this flag will be left |
| 2407 |
* cleared. |
| 2408 |
* |
| 2409 |
* SPP_DSCP: Setting this flag enables the setting of the |
| 2410 |
* Differentiated Services Code Point (DSCP) value |
| 2411 |
* associated with either the association or a specific |
| 2412 |
* address. The value is obtained in the spp_dscp field. |
| 2413 |
* Upon retrieval, this flag will be set to indicate that |
| 2414 |
* the spp_dscp field has a valid value returned. If a |
| 2415 |
* specific destination address is set when called (in the |
| 2416 |
* spp_address field), then that specific destination |
| 2417 |
* address's DSCP value is returned. If just an association |
| 2418 |
* is specified, then the association's default DSCP is |
| 2419 |
* returned. If neither an association nor a destination is |
| 2420 |
* specified, then the socket's default DSCP is returned. |
| 2421 |
* |
| 2422 |
* spp_ipv6_flowlabel |
| 2423 |
* - This field is used in conjunction with the |
| 2424 |
* SPP_IPV6_FLOWLABEL flag and contains the IPv6 flow label. |
| 2425 |
* The 20 least significant bits are used for the flow |
| 2426 |
* label. This setting has precedence over any IPv6-layer |
| 2427 |
* setting. |
| 2428 |
* |
| 2429 |
* spp_dscp - This field is used in conjunction with the SPP_DSCP flag |
| 2430 |
* and contains the DSCP. The 6 most significant bits are |
| 2431 |
* used for the DSCP. This setting has precedence over any |
| 2432 |
* IPv4- or IPv6- layer setting. |
| 2433 |
*/ |
| 2434 |
static int sctp_apply_peer_addr_params(struct sctp_paddrparams *params, |
| 2435 |
struct sctp_transport *trans, |
| 2436 |
struct sctp_association *asoc, |
| 2437 |
struct sctp_sock *sp, |
| 2438 |
int hb_change, |
| 2439 |
int pmtud_change, |
| 2440 |
int sackdelay_change) |
| 2441 |
{ |
| 2442 |
int error; |
| 2443 |
|
| 2444 |
if (params->spp_flags & SPP_HB_DEMAND && trans) { |
| 2445 |
error = sctp_primitive_REQUESTHEARTBEAT(trans->asoc->base.net, |
| 2446 |
trans->asoc, trans); |
| 2447 |
if (error) |
| 2448 |
return error; |
| 2449 |
} |
| 2450 |
|
| 2451 |
/* Note that unless the spp_flag is set to SPP_HB_ENABLE the value of |
| 2452 |
* this field is ignored. Note also that a value of zero indicates |
| 2453 |
* the current setting should be left unchanged. |
| 2454 |
*/ |
| 2455 |
if (params->spp_flags & SPP_HB_ENABLE) { |
| 2456 |
|
| 2457 |
/* Re-zero the interval if the SPP_HB_TIME_IS_ZERO is |
| 2458 |
* set. This lets us use 0 value when this flag |
| 2459 |
* is set. |
| 2460 |
*/ |
| 2461 |
if (params->spp_flags & SPP_HB_TIME_IS_ZERO) |
| 2462 |
params->spp_hbinterval = 0; |
| 2463 |
|
| 2464 |
if (params->spp_hbinterval || |
| 2465 |
(params->spp_flags & SPP_HB_TIME_IS_ZERO)) { |
| 2466 |
if (trans) { |
| 2467 |
trans->hbinterval = |
| 2468 |
msecs_to_jiffies(params->spp_hbinterval); |
| 2469 |
sctp_transport_reset_hb_timer(trans); |
| 2470 |
} else if (asoc) { |
| 2471 |
asoc->hbinterval = |
| 2472 |
msecs_to_jiffies(params->spp_hbinterval); |
| 2473 |
} else { |
| 2474 |
sp->hbinterval = params->spp_hbinterval; |
| 2475 |
} |
| 2476 |
} |
| 2477 |
} |
| 2478 |
|
| 2479 |
if (hb_change) { |
| 2480 |
if (trans) { |
| 2481 |
trans->param_flags = |
| 2482 |
(trans->param_flags & ~SPP_HB) | hb_change; |
| 2483 |
} else if (asoc) { |
| 2484 |
asoc->param_flags = |
| 2485 |
(asoc->param_flags & ~SPP_HB) | hb_change; |
| 2486 |
} else { |
| 2487 |
sp->param_flags = |
| 2488 |
(sp->param_flags & ~SPP_HB) | hb_change; |
| 2489 |
} |
| 2490 |
} |
| 2491 |
|
| 2492 |
/* When Path MTU discovery is disabled the value specified here will |
| 2493 |
* be the "fixed" path mtu (i.e. the value of the spp_flags field must |
| 2494 |
* include the flag SPP_PMTUD_DISABLE for this field to have any |
| 2495 |
* effect). |
| 2496 |
*/ |
| 2497 |
if ((params->spp_flags & SPP_PMTUD_DISABLE) && params->spp_pathmtu) { |
| 2498 |
if (trans) { |
| 2499 |
trans->pathmtu = params->spp_pathmtu; |
| 2500 |
sctp_assoc_sync_pmtu(asoc); |
| 2501 |
} else if (asoc) { |
| 2502 |
sctp_assoc_set_pmtu(asoc, params->spp_pathmtu); |
| 2503 |
} else { |
| 2504 |
sp->pathmtu = params->spp_pathmtu; |
| 2505 |
} |
| 2506 |
} |
| 2507 |
|
| 2508 |
if (pmtud_change) { |
| 2509 |
if (trans) { |
| 2510 |
int update = (trans->param_flags & SPP_PMTUD_DISABLE) && |
| 2511 |
(params->spp_flags & SPP_PMTUD_ENABLE); |
| 2512 |
trans->param_flags = |
| 2513 |
(trans->param_flags & ~SPP_PMTUD) | pmtud_change; |
| 2514 |
if (update) { |
| 2515 |
sctp_transport_pmtu(trans, sctp_opt2sk(sp)); |
| 2516 |
sctp_assoc_sync_pmtu(asoc); |
| 2517 |
} |
| 2518 |
sctp_transport_pl_reset(trans); |
| 2519 |
} else if (asoc) { |
| 2520 |
asoc->param_flags = |
| 2521 |
(asoc->param_flags & ~SPP_PMTUD) | pmtud_change; |
| 2522 |
} else { |
| 2523 |
sp->param_flags = |
| 2524 |
(sp->param_flags & ~SPP_PMTUD) | pmtud_change; |
| 2525 |
} |
| 2526 |
} |
| 2527 |
|
| 2528 |
/* Note that unless the spp_flag is set to SPP_SACKDELAY_ENABLE the |
| 2529 |
* value of this field is ignored. Note also that a value of zero |
| 2530 |
* indicates the current setting should be left unchanged. |
| 2531 |
*/ |
| 2532 |
if ((params->spp_flags & SPP_SACKDELAY_ENABLE) && params->spp_sackdelay) { |
| 2533 |
if (trans) { |
| 2534 |
trans->sackdelay = |
| 2535 |
msecs_to_jiffies(params->spp_sackdelay); |
| 2536 |
} else if (asoc) { |
| 2537 |
asoc->sackdelay = |
| 2538 |
msecs_to_jiffies(params->spp_sackdelay); |
| 2539 |
} else { |
| 2540 |
sp->sackdelay = params->spp_sackdelay; |
| 2541 |
} |
| 2542 |
} |
| 2543 |
|
| 2544 |
if (sackdelay_change) { |
| 2545 |
if (trans) { |
| 2546 |
trans->param_flags = |
| 2547 |
(trans->param_flags & ~SPP_SACKDELAY) | |
| 2548 |
sackdelay_change; |
| 2549 |
} else if (asoc) { |
| 2550 |
asoc->param_flags = |
| 2551 |
(asoc->param_flags & ~SPP_SACKDELAY) | |
| 2552 |
sackdelay_change; |
| 2553 |
} else { |
| 2554 |
sp->param_flags = |
| 2555 |
(sp->param_flags & ~SPP_SACKDELAY) | |
| 2556 |
sackdelay_change; |
| 2557 |
} |
| 2558 |
} |
| 2559 |
|
| 2560 |
/* Note that a value of zero indicates the current setting should be |
| 2561 |
left unchanged. |
| 2562 |
*/ |
| 2563 |
if (params->spp_pathmaxrxt) { |
| 2564 |
if (trans) { |
| 2565 |
trans->pathmaxrxt = params->spp_pathmaxrxt; |
| 2566 |
} else if (asoc) { |
| 2567 |
asoc->pathmaxrxt = params->spp_pathmaxrxt; |
| 2568 |
} else { |
| 2569 |
sp->pathmaxrxt = params->spp_pathmaxrxt; |
| 2570 |
} |
| 2571 |
} |
| 2572 |
|
| 2573 |
if (params->spp_flags & SPP_IPV6_FLOWLABEL) { |
| 2574 |
if (trans) { |
| 2575 |
if (trans->ipaddr.sa.sa_family == AF_INET6) { |
| 2576 |
trans->flowlabel = params->spp_ipv6_flowlabel & |
| 2577 |
SCTP_FLOWLABEL_VAL_MASK; |
| 2578 |
trans->flowlabel |= SCTP_FLOWLABEL_SET_MASK; |
| 2579 |
} |
| 2580 |
} else if (asoc) { |
| 2581 |
struct sctp_transport *t; |
| 2582 |
|
| 2583 |
list_for_each_entry(t, &asoc->peer.transport_addr_list, |
| 2584 |
transports) { |
| 2585 |
if (t->ipaddr.sa.sa_family != AF_INET6) |
| 2586 |
continue; |
| 2587 |
t->flowlabel = params->spp_ipv6_flowlabel & |
| 2588 |
SCTP_FLOWLABEL_VAL_MASK; |
| 2589 |
t->flowlabel |= SCTP_FLOWLABEL_SET_MASK; |
| 2590 |
} |
| 2591 |
asoc->flowlabel = params->spp_ipv6_flowlabel & |
| 2592 |
SCTP_FLOWLABEL_VAL_MASK; |
| 2593 |
asoc->flowlabel |= SCTP_FLOWLABEL_SET_MASK; |
| 2594 |
} else if (sctp_opt2sk(sp)->sk_family == AF_INET6) { |
| 2595 |
sp->flowlabel = params->spp_ipv6_flowlabel & |
| 2596 |
SCTP_FLOWLABEL_VAL_MASK; |
| 2597 |
sp->flowlabel |= SCTP_FLOWLABEL_SET_MASK; |
| 2598 |
} |
| 2599 |
} |
| 2600 |
|
| 2601 |
if (params->spp_flags & SPP_DSCP) { |
| 2602 |
if (trans) { |
| 2603 |
trans->dscp = params->spp_dscp & SCTP_DSCP_VAL_MASK; |
| 2604 |
trans->dscp |= SCTP_DSCP_SET_MASK; |
| 2605 |
} else if (asoc) { |
| 2606 |
struct sctp_transport *t; |
| 2607 |
|
| 2608 |
list_for_each_entry(t, &asoc->peer.transport_addr_list, |
| 2609 |
transports) { |
| 2610 |
t->dscp = params->spp_dscp & |
| 2611 |
SCTP_DSCP_VAL_MASK; |
| 2612 |
t->dscp |= SCTP_DSCP_SET_MASK; |
| 2613 |
} |
| 2614 |
asoc->dscp = params->spp_dscp & SCTP_DSCP_VAL_MASK; |
| 2615 |
asoc->dscp |= SCTP_DSCP_SET_MASK; |
| 2616 |
} else { |
| 2617 |
sp->dscp = params->spp_dscp & SCTP_DSCP_VAL_MASK; |
| 2618 |
sp->dscp |= SCTP_DSCP_SET_MASK; |
| 2619 |
} |
| 2620 |
} |
| 2621 |
|
| 2622 |
return 0; |
| 2623 |
} |
| 2624 |
|
| 2625 |
static int sctp_setsockopt_peer_addr_params(struct sock *sk, |
| 2626 |
struct sctp_paddrparams *params, |
| 2627 |
unsigned int optlen) |
| 2628 |
{ |
| 2629 |
struct sctp_transport *trans = NULL; |
| 2630 |
struct sctp_association *asoc = NULL; |
| 2631 |
struct sctp_sock *sp = sctp_sk(sk); |
| 2632 |
int error; |
| 2633 |
int hb_change, pmtud_change, sackdelay_change; |
| 2634 |
|
| 2635 |
if (optlen == ALIGN(offsetof(struct sctp_paddrparams, |
| 2636 |
spp_ipv6_flowlabel), 4)) { |
| 2637 |
if (params->spp_flags & (SPP_DSCP | SPP_IPV6_FLOWLABEL)) |
| 2638 |
return -EINVAL; |
| 2639 |
} else if (optlen != sizeof(*params)) { |
| 2640 |
return -EINVAL; |
| 2641 |
} |
| 2642 |
|
| 2643 |
/* Validate flags and value parameters. */ |
| 2644 |
hb_change = params->spp_flags & SPP_HB; |
| 2645 |
pmtud_change = params->spp_flags & SPP_PMTUD; |
| 2646 |
sackdelay_change = params->spp_flags & SPP_SACKDELAY; |
| 2647 |
|
| 2648 |
if (hb_change == SPP_HB || |
| 2649 |
pmtud_change == SPP_PMTUD || |
| 2650 |
sackdelay_change == SPP_SACKDELAY || |
| 2651 |
params->spp_sackdelay > 500 || |
| 2652 |
(params->spp_pathmtu && |
| 2653 |
params->spp_pathmtu < SCTP_DEFAULT_MINSEGMENT)) |
| 2654 |
return -EINVAL; |
| 2655 |
|
| 2656 |
/* If an address other than INADDR_ANY is specified, and |
| 2657 |
* no transport is found, then the request is invalid. |
| 2658 |
*/ |
| 2659 |
if (!sctp_is_any(sk, (union sctp_addr *)¶ms->spp_address)) { |
| 2660 |
trans = sctp_addr_id2transport(sk, ¶ms->spp_address, |
| 2661 |
params->spp_assoc_id); |
| 2662 |
if (!trans) |
| 2663 |
return -EINVAL; |
| 2664 |
} |
| 2665 |
|
| 2666 |
/* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the |
| 2667 |
* socket is a one to many style socket, and an association |
| 2668 |
* was not found, then the id was invalid. |
| 2669 |
*/ |
| 2670 |
asoc = sctp_id2assoc(sk, params->spp_assoc_id); |
| 2671 |
if (!asoc && params->spp_assoc_id != SCTP_FUTURE_ASSOC && |
| 2672 |
sctp_style(sk, UDP)) |
| 2673 |
return -EINVAL; |
| 2674 |
|
| 2675 |
/* Heartbeat demand can only be sent on a transport or |
| 2676 |
* association, but not a socket. |
| 2677 |
*/ |
| 2678 |
if (params->spp_flags & SPP_HB_DEMAND && !trans && !asoc) |
| 2679 |
return -EINVAL; |
| 2680 |
|
| 2681 |
/* Process parameters. */ |
| 2682 |
error = sctp_apply_peer_addr_params(params, trans, asoc, sp, |
| 2683 |
hb_change, pmtud_change, |
| 2684 |
sackdelay_change); |
| 2685 |
|
| 2686 |
if (error) |
| 2687 |
return error; |
| 2688 |
|
| 2689 |
/* If changes are for association, also apply parameters to each |
| 2690 |
* transport. |
| 2691 |
*/ |
| 2692 |
if (!trans && asoc) { |
| 2693 |
list_for_each_entry(trans, &asoc->peer.transport_addr_list, |
| 2694 |
transports) { |
| 2695 |
sctp_apply_peer_addr_params(params, trans, asoc, sp, |
| 2696 |
hb_change, pmtud_change, |
| 2697 |
sackdelay_change); |
| 2698 |
} |
| 2699 |
} |
| 2700 |
|
| 2701 |
return 0; |
| 2702 |
} |
| 2703 |
|
| 2704 |
static inline __u32 sctp_spp_sackdelay_enable(__u32 param_flags) |
| 2705 |
{ |
| 2706 |
return (param_flags & ~SPP_SACKDELAY) | SPP_SACKDELAY_ENABLE; |
| 2707 |
} |
| 2708 |
|
| 2709 |
static inline __u32 sctp_spp_sackdelay_disable(__u32 param_flags) |
| 2710 |
{ |
| 2711 |
return (param_flags & ~SPP_SACKDELAY) | SPP_SACKDELAY_DISABLE; |
| 2712 |
} |
| 2713 |
|
| 2714 |
static void sctp_apply_asoc_delayed_ack(struct sctp_sack_info *params, |
| 2715 |
struct sctp_association *asoc) |
| 2716 |
{ |
| 2717 |
struct sctp_transport *trans; |
| 2718 |
|
| 2719 |
if (params->sack_delay) { |
| 2720 |
asoc->sackdelay = msecs_to_jiffies(params->sack_delay); |
| 2721 |
asoc->param_flags = |
| 2722 |
sctp_spp_sackdelay_enable(asoc->param_flags); |
| 2723 |
} |
| 2724 |
if (params->sack_freq == 1) { |
| 2725 |
asoc->param_flags = |
| 2726 |
sctp_spp_sackdelay_disable(asoc->param_flags); |
| 2727 |
} else if (params->sack_freq > 1) { |
| 2728 |
asoc->sackfreq = params->sack_freq; |
| 2729 |
asoc->param_flags = |
| 2730 |
sctp_spp_sackdelay_enable(asoc->param_flags); |
| 2731 |
} |
| 2732 |
|
| 2733 |
list_for_each_entry(trans, &asoc->peer.transport_addr_list, |
| 2734 |
transports) { |
| 2735 |
if (params->sack_delay) { |
| 2736 |
trans->sackdelay = msecs_to_jiffies(params->sack_delay); |
| 2737 |
trans->param_flags = |
| 2738 |
sctp_spp_sackdelay_enable(trans->param_flags); |
| 2739 |
} |
| 2740 |
if (params->sack_freq == 1) { |
| 2741 |
trans->param_flags = |
| 2742 |
sctp_spp_sackdelay_disable(trans->param_flags); |
| 2743 |
} else if (params->sack_freq > 1) { |
| 2744 |
trans->sackfreq = params->sack_freq; |
| 2745 |
trans->param_flags = |
| 2746 |
sctp_spp_sackdelay_enable(trans->param_flags); |
| 2747 |
} |
| 2748 |
} |
| 2749 |
} |
| 2750 |
|
| 2751 |
/* |
| 2752 |
* 7.1.23. Get or set delayed ack timer (SCTP_DELAYED_SACK) |
| 2753 |
* |
| 2754 |
* This option will effect the way delayed acks are performed. This |
| 2755 |
* option allows you to get or set the delayed ack time, in |
| 2756 |
* milliseconds. It also allows changing the delayed ack frequency. |
| 2757 |
* Changing the frequency to 1 disables the delayed sack algorithm. If |
| 2758 |
* the assoc_id is 0, then this sets or gets the endpoints default |
| 2759 |
* values. If the assoc_id field is non-zero, then the set or get |
| 2760 |
* effects the specified association for the one to many model (the |
| 2761 |
* assoc_id field is ignored by the one to one model). Note that if |
| 2762 |
* sack_delay or sack_freq are 0 when setting this option, then the |
| 2763 |
* current values will remain unchanged. |
| 2764 |
* |
| 2765 |
* struct sctp_sack_info { |
| 2766 |
* sctp_assoc_t sack_assoc_id; |
| 2767 |
* uint32_t sack_delay; |
| 2768 |
* uint32_t sack_freq; |
| 2769 |
* }; |
| 2770 |
* |
| 2771 |
* sack_assoc_id - This parameter, indicates which association the user |
| 2772 |
* is performing an action upon. Note that if this field's value is |
| 2773 |
* zero then the endpoints default value is changed (effecting future |
| 2774 |
* associations only). |
| 2775 |
* |
| 2776 |
* sack_delay - This parameter contains the number of milliseconds that |
| 2777 |
* the user is requesting the delayed ACK timer be set to. Note that |
| 2778 |
* this value is defined in the standard to be between 200 and 500 |
| 2779 |
* milliseconds. |
| 2780 |
* |
| 2781 |
* sack_freq - This parameter contains the number of packets that must |
| 2782 |
* be received before a sack is sent without waiting for the delay |
| 2783 |
* timer to expire. The default value for this is 2, setting this |
| 2784 |
* value to 1 will disable the delayed sack algorithm. |
| 2785 |
*/ |
| 2786 |
static int __sctp_setsockopt_delayed_ack(struct sock *sk, |
| 2787 |
struct sctp_sack_info *params) |
| 2788 |
{ |
| 2789 |
struct sctp_sock *sp = sctp_sk(sk); |
| 2790 |
struct sctp_association *asoc; |
| 2791 |
|
| 2792 |
/* Validate value parameter. */ |
| 2793 |
if (params->sack_delay > 500) |
| 2794 |
return -EINVAL; |
| 2795 |
|
| 2796 |
/* Get association, if sack_assoc_id != SCTP_FUTURE_ASSOC and the |
| 2797 |
* socket is a one to many style socket, and an association |
| 2798 |
* was not found, then the id was invalid. |
| 2799 |
*/ |
| 2800 |
asoc = sctp_id2assoc(sk, params->sack_assoc_id); |
| 2801 |
if (!asoc && params->sack_assoc_id > SCTP_ALL_ASSOC && |
| 2802 |
sctp_style(sk, UDP)) |
| 2803 |
return -EINVAL; |
| 2804 |
|
| 2805 |
if (asoc) { |
| 2806 |
sctp_apply_asoc_delayed_ack(params, asoc); |
| 2807 |
|
| 2808 |
return 0; |
| 2809 |
} |
| 2810 |
|
| 2811 |
if (sctp_style(sk, TCP)) |
| 2812 |
params->sack_assoc_id = SCTP_FUTURE_ASSOC; |
| 2813 |
|
| 2814 |
if (params->sack_assoc_id == SCTP_FUTURE_ASSOC || |
| 2815 |
params->sack_assoc_id == SCTP_ALL_ASSOC) { |
| 2816 |
if (params->sack_delay) { |
| 2817 |
sp->sackdelay = params->sack_delay; |
| 2818 |
sp->param_flags = |
| 2819 |
sctp_spp_sackdelay_enable(sp->param_flags); |
| 2820 |
} |
| 2821 |
if (params->sack_freq == 1) { |
| 2822 |
sp->param_flags = |
| 2823 |
sctp_spp_sackdelay_disable(sp->param_flags); |
| 2824 |
} else if (params->sack_freq > 1) { |
| 2825 |
sp->sackfreq = params->sack_freq; |
| 2826 |
sp->param_flags = |
| 2827 |
sctp_spp_sackdelay_enable(sp->param_flags); |
| 2828 |
} |
| 2829 |
} |
| 2830 |
|
| 2831 |
if (params->sack_assoc_id == SCTP_CURRENT_ASSOC || |
| 2832 |
params->sack_assoc_id == SCTP_ALL_ASSOC) |
| 2833 |
list_for_each_entry(asoc, &sp->ep->asocs, asocs) |
| 2834 |
sctp_apply_asoc_delayed_ack(params, asoc); |
| 2835 |
|
| 2836 |
return 0; |
| 2837 |
} |
| 2838 |
|
| 2839 |
static int sctp_setsockopt_delayed_ack(struct sock *sk, |
| 2840 |
struct sctp_sack_info *params, |
| 2841 |
unsigned int optlen) |
| 2842 |
{ |
| 2843 |
if (optlen == sizeof(struct sctp_assoc_value)) { |
| 2844 |
struct sctp_assoc_value *v = (struct sctp_assoc_value *)params; |
| 2845 |
struct sctp_sack_info p; |
| 2846 |
|
| 2847 |
pr_warn_ratelimited(DEPRECATED |
| 2848 |
"%s (pid %d) " |
| 2849 |
"Use of struct sctp_assoc_value in delayed_ack socket option.\n" |
| 2850 |
"Use struct sctp_sack_info instead\n", |
| 2851 |
current->comm, task_pid_nr(current)); |
| 2852 |
|
| 2853 |
p.sack_assoc_id = v->assoc_id; |
| 2854 |
p.sack_delay = v->assoc_value; |
| 2855 |
p.sack_freq = v->assoc_value ? 0 : 1; |
| 2856 |
return __sctp_setsockopt_delayed_ack(sk, &p); |
| 2857 |
} |
| 2858 |
|
| 2859 |
if (optlen != sizeof(struct sctp_sack_info)) |
| 2860 |
return -EINVAL; |
| 2861 |
if (params->sack_delay == 0 && params->sack_freq == 0) |
| 2862 |
return 0; |
| 2863 |
return __sctp_setsockopt_delayed_ack(sk, params); |
| 2864 |
} |
| 2865 |
|
| 2866 |
/* 7.1.3 Initialization Parameters (SCTP_INITMSG) |
| 2867 |
* |
| 2868 |
* Applications can specify protocol parameters for the default association |
| 2869 |
* initialization. The option name argument to setsockopt() and getsockopt() |
| 2870 |
* is SCTP_INITMSG. |
| 2871 |
* |
| 2872 |
* Setting initialization parameters is effective only on an unconnected |
| 2873 |
* socket (for UDP-style sockets only future associations are effected |
| 2874 |
* by the change). With TCP-style sockets, this option is inherited by |
| 2875 |
* sockets derived from a listener socket. |
| 2876 |
*/ |
| 2877 |
static int sctp_setsockopt_initmsg(struct sock *sk, struct sctp_initmsg *sinit, |
| 2878 |
unsigned int optlen) |
| 2879 |
{ |
| 2880 |
struct sctp_sock *sp = sctp_sk(sk); |
| 2881 |
|
| 2882 |
if (optlen != sizeof(struct sctp_initmsg)) |
| 2883 |
return -EINVAL; |
| 2884 |
|
| 2885 |
if (sinit->sinit_num_ostreams) |
| 2886 |
sp->initmsg.sinit_num_ostreams = sinit->sinit_num_ostreams; |
| 2887 |
if (sinit->sinit_max_instreams) |
| 2888 |
sp->initmsg.sinit_max_instreams = sinit->sinit_max_instreams; |
| 2889 |
if (sinit->sinit_max_attempts) |
| 2890 |
sp->initmsg.sinit_max_attempts = sinit->sinit_max_attempts; |
| 2891 |
if (sinit->sinit_max_init_timeo) |
| 2892 |
sp->initmsg.sinit_max_init_timeo = sinit->sinit_max_init_timeo; |
| 2893 |
|
| 2894 |
return 0; |
| 2895 |
} |
| 2896 |
|
| 2897 |
/* |
| 2898 |
* 7.1.14 Set default send parameters (SCTP_DEFAULT_SEND_PARAM) |
| 2899 |
* |
| 2900 |
* Applications that wish to use the sendto() system call may wish to |
| 2901 |
* specify a default set of parameters that would normally be supplied |
| 2902 |
* through the inclusion of ancillary data. This socket option allows |
| 2903 |
* such an application to set the default sctp_sndrcvinfo structure. |
| 2904 |
* The application that wishes to use this socket option simply passes |
| 2905 |
* in to this call the sctp_sndrcvinfo structure defined in Section |
| 2906 |
* 5.2.2) The input parameters accepted by this call include |
| 2907 |
* sinfo_stream, sinfo_flags, sinfo_ppid, sinfo_context, |
| 2908 |
* sinfo_timetolive. The user must provide the sinfo_assoc_id field in |
| 2909 |
* to this call if the caller is using the UDP model. |
| 2910 |
*/ |
| 2911 |
static int sctp_setsockopt_default_send_param(struct sock *sk, |
| 2912 |
struct sctp_sndrcvinfo *info, |
| 2913 |
unsigned int optlen) |
| 2914 |
{ |
| 2915 |
struct sctp_sock *sp = sctp_sk(sk); |
| 2916 |
struct sctp_association *asoc; |
| 2917 |
|
| 2918 |
if (optlen != sizeof(*info)) |
| 2919 |
return -EINVAL; |
| 2920 |
if (info->sinfo_flags & |
| 2921 |
~(SCTP_UNORDERED | SCTP_ADDR_OVER | |
| 2922 |
SCTP_ABORT | SCTP_EOF)) |
| 2923 |
return -EINVAL; |
| 2924 |
|
| 2925 |
asoc = sctp_id2assoc(sk, info->sinfo_assoc_id); |
| 2926 |
if (!asoc && info->sinfo_assoc_id > SCTP_ALL_ASSOC && |
| 2927 |
sctp_style(sk, UDP)) |
| 2928 |
return -EINVAL; |
| 2929 |
|
| 2930 |
if (asoc) { |
| 2931 |
asoc->default_stream = info->sinfo_stream; |
| 2932 |
asoc->default_flags = info->sinfo_flags; |
| 2933 |
asoc->default_ppid = info->sinfo_ppid; |
| 2934 |
asoc->default_context = info->sinfo_context; |
| 2935 |
asoc->default_timetolive = info->sinfo_timetolive; |
| 2936 |
|
| 2937 |
return 0; |
| 2938 |
} |
| 2939 |
|
| 2940 |
if (sctp_style(sk, TCP)) |
| 2941 |
info->sinfo_assoc_id = SCTP_FUTURE_ASSOC; |
| 2942 |
|
| 2943 |
if (info->sinfo_assoc_id == SCTP_FUTURE_ASSOC || |
| 2944 |
info->sinfo_assoc_id == SCTP_ALL_ASSOC) { |
| 2945 |
sp->default_stream = info->sinfo_stream; |
| 2946 |
sp->default_flags = info->sinfo_flags; |
| 2947 |
sp->default_ppid = info->sinfo_ppid; |
| 2948 |
sp->default_context = info->sinfo_context; |
| 2949 |
sp->default_timetolive = info->sinfo_timetolive; |
| 2950 |
} |
| 2951 |
|
| 2952 |
if (info->sinfo_assoc_id == SCTP_CURRENT_ASSOC || |
| 2953 |
info->sinfo_assoc_id == SCTP_ALL_ASSOC) { |
| 2954 |
list_for_each_entry(asoc, &sp->ep->asocs, asocs) { |
| 2955 |
asoc->default_stream = info->sinfo_stream; |
| 2956 |
asoc->default_flags = info->sinfo_flags; |
| 2957 |
asoc->default_ppid = info->sinfo_ppid; |
| 2958 |
asoc->default_context = info->sinfo_context; |
| 2959 |
asoc->default_timetolive = info->sinfo_timetolive; |
| 2960 |
} |
| 2961 |
} |
| 2962 |
|
| 2963 |
return 0; |
| 2964 |
} |
| 2965 |
|
| 2966 |
/* RFC6458, Section 8.1.31. Set/get Default Send Parameters |
| 2967 |
* (SCTP_DEFAULT_SNDINFO) |
| 2968 |
*/ |
| 2969 |
static int sctp_setsockopt_default_sndinfo(struct sock *sk, |
| 2970 |
struct sctp_sndinfo *info, |
| 2971 |
unsigned int optlen) |
| 2972 |
{ |
| 2973 |
struct sctp_sock *sp = sctp_sk(sk); |
| 2974 |
struct sctp_association *asoc; |
| 2975 |
|
| 2976 |
if (optlen != sizeof(*info)) |
| 2977 |
return -EINVAL; |
| 2978 |
if (info->snd_flags & |
| 2979 |
~(SCTP_UNORDERED | SCTP_ADDR_OVER | |
| 2980 |
SCTP_ABORT | SCTP_EOF)) |
| 2981 |
return -EINVAL; |
| 2982 |
|
| 2983 |
asoc = sctp_id2assoc(sk, info->snd_assoc_id); |
| 2984 |
if (!asoc && info->snd_assoc_id > SCTP_ALL_ASSOC && |
| 2985 |
sctp_style(sk, UDP)) |
| 2986 |
return -EINVAL; |
| 2987 |
|
| 2988 |
if (asoc) { |
| 2989 |
asoc->default_stream = info->snd_sid; |
| 2990 |
asoc->default_flags = info->snd_flags; |
| 2991 |
asoc->default_ppid = info->snd_ppid; |
| 2992 |
asoc->default_context = info->snd_context; |
| 2993 |
|
| 2994 |
return 0; |
| 2995 |
} |
| 2996 |
|
| 2997 |
if (sctp_style(sk, TCP)) |
| 2998 |
info->snd_assoc_id = SCTP_FUTURE_ASSOC; |
| 2999 |
|
| 3000 |
if (info->snd_assoc_id == SCTP_FUTURE_ASSOC || |
| 3001 |
info->snd_assoc_id == SCTP_ALL_ASSOC) { |
| 3002 |
sp->default_stream = info->snd_sid; |
| 3003 |
sp->default_flags = info->snd_flags; |
| 3004 |
sp->default_ppid = info->snd_ppid; |
| 3005 |
sp->default_context = info->snd_context; |
| 3006 |
} |
| 3007 |
|
| 3008 |
if (info->snd_assoc_id == SCTP_CURRENT_ASSOC || |
| 3009 |
info->snd_assoc_id == SCTP_ALL_ASSOC) { |
| 3010 |
list_for_each_entry(asoc, &sp->ep->asocs, asocs) { |
| 3011 |
asoc->default_stream = info->snd_sid; |
| 3012 |
asoc->default_flags = info->snd_flags; |
| 3013 |
asoc->default_ppid = info->snd_ppid; |
| 3014 |
asoc->default_context = info->snd_context; |
| 3015 |
} |
| 3016 |
} |
| 3017 |
|
| 3018 |
return 0; |
| 3019 |
} |
| 3020 |
|
| 3021 |
/* 7.1.10 Set Primary Address (SCTP_PRIMARY_ADDR) |
| 3022 |
* |
| 3023 |
* Requests that the local SCTP stack use the enclosed peer address as |
| 3024 |
* the association primary. The enclosed address must be one of the |
| 3025 |
* association peer's addresses. |
| 3026 |
*/ |
| 3027 |
static int sctp_setsockopt_primary_addr(struct sock *sk, struct sctp_prim *prim, |
| 3028 |
unsigned int optlen) |
| 3029 |
{ |
| 3030 |
struct sctp_transport *trans; |
| 3031 |
struct sctp_af *af; |
| 3032 |
int err; |
| 3033 |
|
| 3034 |
if (optlen != sizeof(struct sctp_prim)) |
| 3035 |
return -EINVAL; |
| 3036 |
|
| 3037 |
/* Allow security module to validate address but need address len. */ |
| 3038 |
af = sctp_get_af_specific(prim->ssp_addr.ss_family); |
| 3039 |
if (!af) |
| 3040 |
return -EINVAL; |
| 3041 |
|
| 3042 |
err = security_sctp_bind_connect(sk, SCTP_PRIMARY_ADDR, |
| 3043 |
(struct sockaddr *)&prim->ssp_addr, |
| 3044 |
af->sockaddr_len); |
| 3045 |
if (err) |
| 3046 |
return err; |
| 3047 |
|
| 3048 |
trans = sctp_addr_id2transport(sk, &prim->ssp_addr, prim->ssp_assoc_id); |
| 3049 |
if (!trans) |
| 3050 |
return -EINVAL; |
| 3051 |
|
| 3052 |
sctp_assoc_set_primary(trans->asoc, trans); |
| 3053 |
|
| 3054 |
return 0; |
| 3055 |
} |
| 3056 |
|
| 3057 |
/* |
| 3058 |
* 7.1.5 SCTP_NODELAY |
| 3059 |
* |
| 3060 |
* Turn on/off any Nagle-like algorithm. This means that packets are |
| 3061 |
* generally sent as soon as possible and no unnecessary delays are |
| 3062 |
* introduced, at the cost of more packets in the network. Expects an |
| 3063 |
* integer boolean flag. |
| 3064 |
*/ |
| 3065 |
static int sctp_setsockopt_nodelay(struct sock *sk, int *val, |
| 3066 |
unsigned int optlen) |
| 3067 |
{ |
| 3068 |
if (optlen < sizeof(int)) |
| 3069 |
return -EINVAL; |
| 3070 |
sctp_sk(sk)->nodelay = (*val == 0) ? 0 : 1; |
| 3071 |
return 0; |
| 3072 |
} |
| 3073 |
|
| 3074 |
/* |
| 3075 |
* |
| 3076 |
* 7.1.1 SCTP_RTOINFO |
| 3077 |
* |
| 3078 |
* The protocol parameters used to initialize and bound retransmission |
| 3079 |
* timeout (RTO) are tunable. sctp_rtoinfo structure is used to access |
| 3080 |
* and modify these parameters. |
| 3081 |
* All parameters are time values, in milliseconds. A value of 0, when |
| 3082 |
* modifying the parameters, indicates that the current value should not |
| 3083 |
* be changed. |
| 3084 |
* |
| 3085 |
*/ |
| 3086 |
static int sctp_setsockopt_rtoinfo(struct sock *sk, |
| 3087 |
struct sctp_rtoinfo *rtoinfo, |
| 3088 |
unsigned int optlen) |
| 3089 |
{ |
| 3090 |
struct sctp_association *asoc; |
| 3091 |
unsigned long rto_min, rto_max; |
| 3092 |
struct sctp_sock *sp = sctp_sk(sk); |
| 3093 |
|
| 3094 |
if (optlen != sizeof (struct sctp_rtoinfo)) |
| 3095 |
return -EINVAL; |
| 3096 |
|
| 3097 |
asoc = sctp_id2assoc(sk, rtoinfo->srto_assoc_id); |
| 3098 |
|
| 3099 |
/* Set the values to the specific association */ |
| 3100 |
if (!asoc && rtoinfo->srto_assoc_id != SCTP_FUTURE_ASSOC && |
| 3101 |
sctp_style(sk, UDP)) |
| 3102 |
return -EINVAL; |
| 3103 |
|
| 3104 |
rto_max = rtoinfo->srto_max; |
| 3105 |
rto_min = rtoinfo->srto_min; |
| 3106 |
|
| 3107 |
if (rto_max) |
| 3108 |
rto_max = asoc ? msecs_to_jiffies(rto_max) : rto_max; |
| 3109 |
else |
| 3110 |
rto_max = asoc ? asoc->rto_max : sp->rtoinfo.srto_max; |
| 3111 |
|
| 3112 |
if (rto_min) |
| 3113 |
rto_min = asoc ? msecs_to_jiffies(rto_min) : rto_min; |
| 3114 |
else |
| 3115 |
rto_min = asoc ? asoc->rto_min : sp->rtoinfo.srto_min; |
| 3116 |
|
| 3117 |
if (rto_min > rto_max) |
| 3118 |
return -EINVAL; |
| 3119 |
|
| 3120 |
if (asoc) { |
| 3121 |
if (rtoinfo->srto_initial != 0) |
| 3122 |
asoc->rto_initial = |
| 3123 |
msecs_to_jiffies(rtoinfo->srto_initial); |
| 3124 |
asoc->rto_max = rto_max; |
| 3125 |
asoc->rto_min = rto_min; |
| 3126 |
} else { |
| 3127 |
/* If there is no association or the association-id = 0 |
| 3128 |
* set the values to the endpoint. |
| 3129 |
*/ |
| 3130 |
if (rtoinfo->srto_initial != 0) |
| 3131 |
sp->rtoinfo.srto_initial = rtoinfo->srto_initial; |
| 3132 |
sp->rtoinfo.srto_max = rto_max; |
| 3133 |
sp->rtoinfo.srto_min = rto_min; |
| 3134 |
} |
| 3135 |
|
| 3136 |
return 0; |
| 3137 |
} |
| 3138 |
|
| 3139 |
/* |
| 3140 |
* |
| 3141 |
* 7.1.2 SCTP_ASSOCINFO |
| 3142 |
* |
| 3143 |
* This option is used to tune the maximum retransmission attempts |
| 3144 |
* of the association. |
| 3145 |
* Returns an error if the new association retransmission value is |
| 3146 |
* greater than the sum of the retransmission value of the peer. |
| 3147 |
* See [SCTP] for more information. |
| 3148 |
* |
| 3149 |
*/ |
| 3150 |
static int sctp_setsockopt_associnfo(struct sock *sk, |
| 3151 |
struct sctp_assocparams *assocparams, |
| 3152 |
unsigned int optlen) |
| 3153 |
{ |
| 3154 |
|
| 3155 |
struct sctp_association *asoc; |
| 3156 |
|
| 3157 |
if (optlen != sizeof(struct sctp_assocparams)) |
| 3158 |
return -EINVAL; |
| 3159 |
|
| 3160 |
asoc = sctp_id2assoc(sk, assocparams->sasoc_assoc_id); |
| 3161 |
|
| 3162 |
if (!asoc && assocparams->sasoc_assoc_id != SCTP_FUTURE_ASSOC && |
| 3163 |
sctp_style(sk, UDP)) |
| 3164 |
return -EINVAL; |
| 3165 |
|
| 3166 |
/* Set the values to the specific association */ |
| 3167 |
if (asoc) { |
| 3168 |
if (assocparams->sasoc_asocmaxrxt != 0) { |
| 3169 |
__u32 path_sum = 0; |
| 3170 |
int paths = 0; |
| 3171 |
struct sctp_transport *peer_addr; |
| 3172 |
|
| 3173 |
list_for_each_entry(peer_addr, &asoc->peer.transport_addr_list, |
| 3174 |
transports) { |
| 3175 |
path_sum += peer_addr->pathmaxrxt; |
| 3176 |
paths++; |
| 3177 |
} |
| 3178 |
|
| 3179 |
/* Only validate asocmaxrxt if we have more than |
| 3180 |
* one path/transport. We do this because path |
| 3181 |
* retransmissions are only counted when we have more |
| 3182 |
* then one path. |
| 3183 |
*/ |
| 3184 |
if (paths > 1 && |
| 3185 |
assocparams->sasoc_asocmaxrxt > path_sum) |
| 3186 |
return -EINVAL; |
| 3187 |
|
| 3188 |
asoc->max_retrans = assocparams->sasoc_asocmaxrxt; |
| 3189 |
} |
| 3190 |
|
| 3191 |
if (assocparams->sasoc_cookie_life != 0) |
| 3192 |
asoc->cookie_life = |
| 3193 |
ms_to_ktime(assocparams->sasoc_cookie_life); |
| 3194 |
} else { |
| 3195 |
/* Set the values to the endpoint */ |
| 3196 |
struct sctp_sock *sp = sctp_sk(sk); |
| 3197 |
|
| 3198 |
if (assocparams->sasoc_asocmaxrxt != 0) |
| 3199 |
sp->assocparams.sasoc_asocmaxrxt = |
| 3200 |
assocparams->sasoc_asocmaxrxt; |
| 3201 |
if (assocparams->sasoc_cookie_life != 0) |
| 3202 |
sp->assocparams.sasoc_cookie_life = |
| 3203 |
assocparams->sasoc_cookie_life; |
| 3204 |
} |
| 3205 |
return 0; |
| 3206 |
} |
| 3207 |
|
| 3208 |
/* |
| 3209 |
* 7.1.16 Set/clear IPv4 mapped addresses (SCTP_I_WANT_MAPPED_V4_ADDR) |
| 3210 |
* |
| 3211 |
* This socket option is a boolean flag which turns on or off mapped V4 |
| 3212 |
* addresses. If this option is turned on and the socket is type |
| 3213 |
* PF_INET6, then IPv4 addresses will be mapped to V6 representation. |
| 3214 |
* If this option is turned off, then no mapping will be done of V4 |
| 3215 |
* addresses and a user will receive both PF_INET6 and PF_INET type |
| 3216 |
* addresses on the socket. |
| 3217 |
*/ |
| 3218 |
static int sctp_setsockopt_mappedv4(struct sock *sk, int *val, |
| 3219 |
unsigned int optlen) |
| 3220 |
{ |
| 3221 |
struct sctp_sock *sp = sctp_sk(sk); |
| 3222 |
|
| 3223 |
if (optlen < sizeof(int)) |
| 3224 |
return -EINVAL; |
| 3225 |
if (*val) |
| 3226 |
sp->v4mapped = 1; |
| 3227 |
else |
| 3228 |
sp->v4mapped = 0; |
| 3229 |
|
| 3230 |
return 0; |
| 3231 |
} |
| 3232 |
|
| 3233 |
/* |
| 3234 |
* 8.1.16. Get or Set the Maximum Fragmentation Size (SCTP_MAXSEG) |
| 3235 |
* This option will get or set the maximum size to put in any outgoing |
| 3236 |
* SCTP DATA chunk. If a message is larger than this size it will be |
| 3237 |
* fragmented by SCTP into the specified size. Note that the underlying |
| 3238 |
* SCTP implementation may fragment into smaller sized chunks when the |
| 3239 |
* PMTU of the underlying association is smaller than the value set by |
| 3240 |
* the user. The default value for this option is '0' which indicates |
| 3241 |
* the user is NOT limiting fragmentation and only the PMTU will effect |
| 3242 |
* SCTP's choice of DATA chunk size. Note also that values set larger |
| 3243 |
* than the maximum size of an IP datagram will effectively let SCTP |
| 3244 |
* control fragmentation (i.e. the same as setting this option to 0). |
| 3245 |
* |
| 3246 |
* The following structure is used to access and modify this parameter: |
| 3247 |
* |
| 3248 |
* struct sctp_assoc_value { |
| 3249 |
* sctp_assoc_t assoc_id; |
| 3250 |
* uint32_t assoc_value; |
| 3251 |
* }; |
| 3252 |
* |
| 3253 |
* assoc_id: This parameter is ignored for one-to-one style sockets. |
| 3254 |
* For one-to-many style sockets this parameter indicates which |
| 3255 |
* association the user is performing an action upon. Note that if |
| 3256 |
* this field's value is zero then the endpoints default value is |
| 3257 |
* changed (effecting future associations only). |
| 3258 |
* assoc_value: This parameter specifies the maximum size in bytes. |
| 3259 |
*/ |
| 3260 |
static int sctp_setsockopt_maxseg(struct sock *sk, |
| 3261 |
struct sctp_assoc_value *params, |
| 3262 |
unsigned int optlen) |
| 3263 |
{ |
| 3264 |
struct sctp_sock *sp = sctp_sk(sk); |
| 3265 |
struct sctp_association *asoc; |
| 3266 |
sctp_assoc_t assoc_id; |
| 3267 |
int val; |
| 3268 |
|
| 3269 |
if (optlen == sizeof(int)) { |
| 3270 |
pr_warn_ratelimited(DEPRECATED |
| 3271 |
"%s (pid %d) " |
| 3272 |
"Use of int in maxseg socket option.\n" |
| 3273 |
"Use struct sctp_assoc_value instead\n", |
| 3274 |
current->comm, task_pid_nr(current)); |
| 3275 |
assoc_id = SCTP_FUTURE_ASSOC; |
| 3276 |
val = *(int *)params; |
| 3277 |
} else if (optlen == sizeof(struct sctp_assoc_value)) { |
| 3278 |
assoc_id = params->assoc_id; |
| 3279 |
val = params->assoc_value; |
| 3280 |
} else { |
| 3281 |
return -EINVAL; |
| 3282 |
} |
| 3283 |
|
| 3284 |
asoc = sctp_id2assoc(sk, assoc_id); |
| 3285 |
if (!asoc && assoc_id != SCTP_FUTURE_ASSOC && |
| 3286 |
sctp_style(sk, UDP)) |
| 3287 |
return -EINVAL; |
| 3288 |
|
| 3289 |
if (val) { |
| 3290 |
int min_len, max_len; |
| 3291 |
__u16 datasize = asoc ? sctp_datachk_len(&asoc->stream) : |
| 3292 |
sizeof(struct sctp_data_chunk); |
| 3293 |
|
| 3294 |
min_len = sctp_min_frag_point(sp, datasize); |
| 3295 |
max_len = SCTP_MAX_CHUNK_LEN - datasize; |
| 3296 |
|
| 3297 |
if (val < min_len || val > max_len) |
| 3298 |
return -EINVAL; |
| 3299 |
} |
| 3300 |
|
| 3301 |
if (asoc) { |
| 3302 |
asoc->user_frag = val; |
| 3303 |
sctp_assoc_update_frag_point(asoc); |
| 3304 |
} else { |
| 3305 |
sp->user_frag = val; |
| 3306 |
} |
| 3307 |
|
| 3308 |
return 0; |
| 3309 |
} |
| 3310 |
|
| 3311 |
|
| 3312 |
/* |
| 3313 |
* 7.1.9 Set Peer Primary Address (SCTP_SET_PEER_PRIMARY_ADDR) |
| 3314 |
* |
| 3315 |
* Requests that the peer mark the enclosed address as the association |
| 3316 |
* primary. The enclosed address must be one of the association's |
| 3317 |
* locally bound addresses. The following structure is used to make a |
| 3318 |
* set primary request: |
| 3319 |
*/ |
| 3320 |
static int sctp_setsockopt_peer_primary_addr(struct sock *sk, |
| 3321 |
struct sctp_setpeerprim *prim, |
| 3322 |
unsigned int optlen) |
| 3323 |
{ |
| 3324 |
struct sctp_sock *sp; |
| 3325 |
struct sctp_association *asoc = NULL; |
| 3326 |
struct sctp_chunk *chunk; |
| 3327 |
struct sctp_af *af; |
| 3328 |
int err; |
| 3329 |
|
| 3330 |
sp = sctp_sk(sk); |
| 3331 |
|
| 3332 |
if (!sp->ep->asconf_enable) |
| 3333 |
return -EPERM; |
| 3334 |
|
| 3335 |
if (optlen != sizeof(struct sctp_setpeerprim)) |
| 3336 |
return -EINVAL; |
| 3337 |
|
| 3338 |
asoc = sctp_id2assoc(sk, prim->sspp_assoc_id); |
| 3339 |
if (!asoc) |
| 3340 |
return -EINVAL; |
| 3341 |
|
| 3342 |
if (!asoc->peer.asconf_capable) |
| 3343 |
return -EPERM; |
| 3344 |
|
| 3345 |
if (asoc->peer.addip_disabled_mask & SCTP_PARAM_SET_PRIMARY) |
| 3346 |
return -EPERM; |
| 3347 |
|
| 3348 |
if (!sctp_state(asoc, ESTABLISHED)) |
| 3349 |
return -ENOTCONN; |
| 3350 |
|
| 3351 |
af = sctp_get_af_specific(prim->sspp_addr.ss_family); |
| 3352 |
if (!af) |
| 3353 |
return -EINVAL; |
| 3354 |
|
| 3355 |
if (!af->addr_valid((union sctp_addr *)&prim->sspp_addr, sp, NULL)) |
| 3356 |
return -EADDRNOTAVAIL; |
| 3357 |
|
| 3358 |
if (!sctp_assoc_lookup_laddr(asoc, (union sctp_addr *)&prim->sspp_addr)) |
| 3359 |
return -EADDRNOTAVAIL; |
| 3360 |
|
| 3361 |
/* Allow security module to validate address. */ |
| 3362 |
err = security_sctp_bind_connect(sk, SCTP_SET_PEER_PRIMARY_ADDR, |
| 3363 |
(struct sockaddr *)&prim->sspp_addr, |
| 3364 |
af->sockaddr_len); |
| 3365 |
if (err) |
| 3366 |
return err; |
| 3367 |
|
| 3368 |
/* Create an ASCONF chunk with SET_PRIMARY parameter */ |
| 3369 |
chunk = sctp_make_asconf_set_prim(asoc, |
| 3370 |
(union sctp_addr *)&prim->sspp_addr); |
| 3371 |
if (!chunk) |
| 3372 |
return -ENOMEM; |
| 3373 |
|
| 3374 |
err = sctp_send_asconf(asoc, chunk); |
| 3375 |
|
| 3376 |
pr_debug("%s: we set peer primary addr primitively\n", __func__); |
| 3377 |
|
| 3378 |
return err; |
| 3379 |
} |
| 3380 |
|
| 3381 |
static int sctp_setsockopt_adaptation_layer(struct sock *sk, |
| 3382 |
struct sctp_setadaptation *adapt, |
| 3383 |
unsigned int optlen) |
| 3384 |
{ |
| 3385 |
if (optlen != sizeof(struct sctp_setadaptation)) |
| 3386 |
return -EINVAL; |
| 3387 |
|
| 3388 |
sctp_sk(sk)->adaptation_ind = adapt->ssb_adaptation_ind; |
| 3389 |
|
| 3390 |
return 0; |
| 3391 |
} |
| 3392 |
|
| 3393 |
/* |
| 3394 |
* 7.1.29. Set or Get the default context (SCTP_CONTEXT) |
| 3395 |
* |
| 3396 |
* The context field in the sctp_sndrcvinfo structure is normally only |
| 3397 |
* used when a failed message is retrieved holding the value that was |
| 3398 |
* sent down on the actual send call. This option allows the setting of |
| 3399 |
* a default context on an association basis that will be received on |
| 3400 |
* reading messages from the peer. This is especially helpful in the |
| 3401 |
* one-2-many model for an application to keep some reference to an |
| 3402 |
* internal state machine that is processing messages on the |
| 3403 |
* association. Note that the setting of this value only effects |
| 3404 |
* received messages from the peer and does not effect the value that is |
| 3405 |
* saved with outbound messages. |
| 3406 |
*/ |
| 3407 |
static int sctp_setsockopt_context(struct sock *sk, |
| 3408 |
struct sctp_assoc_value *params, |
| 3409 |
unsigned int optlen) |
| 3410 |
{ |
| 3411 |
struct sctp_sock *sp = sctp_sk(sk); |
| 3412 |
struct sctp_association *asoc; |
| 3413 |
|
| 3414 |
if (optlen != sizeof(struct sctp_assoc_value)) |
| 3415 |
return -EINVAL; |
| 3416 |
|
| 3417 |
asoc = sctp_id2assoc(sk, params->assoc_id); |
| 3418 |
if (!asoc && params->assoc_id > SCTP_ALL_ASSOC && |
| 3419 |
sctp_style(sk, UDP)) |
| 3420 |
return -EINVAL; |
| 3421 |
|
| 3422 |
if (asoc) { |
| 3423 |
asoc->default_rcv_context = params->assoc_value; |
| 3424 |
|
| 3425 |
return 0; |
| 3426 |
} |
| 3427 |
|
| 3428 |
if (sctp_style(sk, TCP)) |
| 3429 |
params->assoc_id = SCTP_FUTURE_ASSOC; |
| 3430 |
|
| 3431 |
if (params->assoc_id == SCTP_FUTURE_ASSOC || |
| 3432 |
params->assoc_id == SCTP_ALL_ASSOC) |
| 3433 |
sp->default_rcv_context = params->assoc_value; |
| 3434 |
|
| 3435 |
if (params->assoc_id == SCTP_CURRENT_ASSOC || |
| 3436 |
params->assoc_id == SCTP_ALL_ASSOC) |
| 3437 |
list_for_each_entry(asoc, &sp->ep->asocs, asocs) |
| 3438 |
asoc->default_rcv_context = params->assoc_value; |
| 3439 |
|
| 3440 |
return 0; |
| 3441 |
} |
| 3442 |
|
| 3443 |
/* |
| 3444 |
* 7.1.24. Get or set fragmented interleave (SCTP_FRAGMENT_INTERLEAVE) |
| 3445 |
* |
| 3446 |
* This options will at a minimum specify if the implementation is doing |
| 3447 |
* fragmented interleave. Fragmented interleave, for a one to many |
| 3448 |
* socket, is when subsequent calls to receive a message may return |
| 3449 |
* parts of messages from different associations. Some implementations |
| 3450 |
* may allow you to turn this value on or off. If so, when turned off, |
| 3451 |
* no fragment interleave will occur (which will cause a head of line |
| 3452 |
* blocking amongst multiple associations sharing the same one to many |
| 3453 |
* socket). When this option is turned on, then each receive call may |
| 3454 |
* come from a different association (thus the user must receive data |
| 3455 |
* with the extended calls (e.g. sctp_recvmsg) to keep track of which |
| 3456 |
* association each receive belongs to. |
| 3457 |
* |
| 3458 |
* This option takes a boolean value. A non-zero value indicates that |
| 3459 |
* fragmented interleave is on. A value of zero indicates that |
| 3460 |
* fragmented interleave is off. |
| 3461 |
* |
| 3462 |
* Note that it is important that an implementation that allows this |
| 3463 |
* option to be turned on, have it off by default. Otherwise an unaware |
| 3464 |
* application using the one to many model may become confused and act |
| 3465 |
* incorrectly. |
| 3466 |
*/ |
| 3467 |
static int sctp_setsockopt_fragment_interleave(struct sock *sk, int *val, |
| 3468 |
unsigned int optlen) |
| 3469 |
{ |
| 3470 |
if (optlen != sizeof(int)) |
| 3471 |
return -EINVAL; |
| 3472 |
|
| 3473 |
sctp_sk(sk)->frag_interleave = !!*val; |
| 3474 |
|
| 3475 |
if (!sctp_sk(sk)->frag_interleave) |
| 3476 |
sctp_sk(sk)->ep->intl_enable = 0; |
| 3477 |
|
| 3478 |
return 0; |
| 3479 |
} |
| 3480 |
|
| 3481 |
/* |
| 3482 |
* 8.1.21. Set or Get the SCTP Partial Delivery Point |
| 3483 |
* (SCTP_PARTIAL_DELIVERY_POINT) |
| 3484 |
* |
| 3485 |
* This option will set or get the SCTP partial delivery point. This |
| 3486 |
* point is the size of a message where the partial delivery API will be |
| 3487 |
* invoked to help free up rwnd space for the peer. Setting this to a |
| 3488 |
* lower value will cause partial deliveries to happen more often. The |
| 3489 |
* calls argument is an integer that sets or gets the partial delivery |
| 3490 |
* point. Note also that the call will fail if the user attempts to set |
| 3491 |
* this value larger than the socket receive buffer size. |
| 3492 |
* |
| 3493 |
* Note that any single message having a length smaller than or equal to |
| 3494 |
* the SCTP partial delivery point will be delivered in one single read |
| 3495 |
* call as long as the user provided buffer is large enough to hold the |
| 3496 |
* message. |
| 3497 |
*/ |
| 3498 |
static int sctp_setsockopt_partial_delivery_point(struct sock *sk, u32 *val, |
| 3499 |
unsigned int optlen) |
| 3500 |
{ |
| 3501 |
if (optlen != sizeof(u32)) |
| 3502 |
return -EINVAL; |
| 3503 |
|
| 3504 |
/* Note: We double the receive buffer from what the user sets |
| 3505 |
* it to be, also initial rwnd is based on rcvbuf/2. |
| 3506 |
*/ |
| 3507 |
if (*val > (sk->sk_rcvbuf >> 1)) |
| 3508 |
return -EINVAL; |
| 3509 |
|
| 3510 |
sctp_sk(sk)->pd_point = *val; |
| 3511 |
|
| 3512 |
return 0; /* is this the right error code? */ |
| 3513 |
} |
| 3514 |
|
| 3515 |
/* |
| 3516 |
* 7.1.28. Set or Get the maximum burst (SCTP_MAX_BURST) |
| 3517 |
* |
| 3518 |
* This option will allow a user to change the maximum burst of packets |
| 3519 |
* that can be emitted by this association. Note that the default value |
| 3520 |
* is 4, and some implementations may restrict this setting so that it |
| 3521 |
* can only be lowered. |
| 3522 |
* |
| 3523 |
* NOTE: This text doesn't seem right. Do this on a socket basis with |
| 3524 |
* future associations inheriting the socket value. |
| 3525 |
*/ |
| 3526 |
static int sctp_setsockopt_maxburst(struct sock *sk, |
| 3527 |
struct sctp_assoc_value *params, |
| 3528 |
unsigned int optlen) |
| 3529 |
{ |
| 3530 |
struct sctp_sock *sp = sctp_sk(sk); |
| 3531 |
struct sctp_association *asoc; |
| 3532 |
sctp_assoc_t assoc_id; |
| 3533 |
u32 assoc_value; |
| 3534 |
|
| 3535 |
if (optlen == sizeof(int)) { |
| 3536 |
pr_warn_ratelimited(DEPRECATED |
| 3537 |
"%s (pid %d) " |
| 3538 |
"Use of int in max_burst socket option deprecated.\n" |
| 3539 |
"Use struct sctp_assoc_value instead\n", |
| 3540 |
current->comm, task_pid_nr(current)); |
| 3541 |
assoc_id = SCTP_FUTURE_ASSOC; |
| 3542 |
assoc_value = *((int *)params); |
| 3543 |
} else if (optlen == sizeof(struct sctp_assoc_value)) { |
| 3544 |
assoc_id = params->assoc_id; |
| 3545 |
assoc_value = params->assoc_value; |
| 3546 |
} else |
| 3547 |
return -EINVAL; |
| 3548 |
|
| 3549 |
asoc = sctp_id2assoc(sk, assoc_id); |
| 3550 |
if (!asoc && assoc_id > SCTP_ALL_ASSOC && sctp_style(sk, UDP)) |
| 3551 |
return -EINVAL; |
| 3552 |
|
| 3553 |
if (asoc) { |
| 3554 |
asoc->max_burst = assoc_value; |
| 3555 |
|
| 3556 |
return 0; |
| 3557 |
} |
| 3558 |
|
| 3559 |
if (sctp_style(sk, TCP)) |
| 3560 |
assoc_id = SCTP_FUTURE_ASSOC; |
| 3561 |
|
| 3562 |
if (assoc_id == SCTP_FUTURE_ASSOC || assoc_id == SCTP_ALL_ASSOC) |
| 3563 |
sp->max_burst = assoc_value; |
| 3564 |
|
| 3565 |
if (assoc_id == SCTP_CURRENT_ASSOC || assoc_id == SCTP_ALL_ASSOC) |
| 3566 |
list_for_each_entry(asoc, &sp->ep->asocs, asocs) |
| 3567 |
asoc->max_burst = assoc_value; |
| 3568 |
|
| 3569 |
return 0; |
| 3570 |
} |
| 3571 |
|
| 3572 |
/* |
| 3573 |
* 7.1.18. Add a chunk that must be authenticated (SCTP_AUTH_CHUNK) |
| 3574 |
* |
| 3575 |
* This set option adds a chunk type that the user is requesting to be |
| 3576 |
* received only in an authenticated way. Changes to the list of chunks |
| 3577 |
* will only effect future associations on the socket. |
| 3578 |
*/ |
| 3579 |
static int sctp_setsockopt_auth_chunk(struct sock *sk, |
| 3580 |
struct sctp_authchunk *val, |
| 3581 |
unsigned int optlen) |
| 3582 |
{ |
| 3583 |
struct sctp_endpoint *ep = sctp_sk(sk)->ep; |
| 3584 |
|
| 3585 |
if (!ep->auth_enable) |
| 3586 |
return -EACCES; |
| 3587 |
|
| 3588 |
if (optlen != sizeof(struct sctp_authchunk)) |
| 3589 |
return -EINVAL; |
| 3590 |
|
| 3591 |
switch (val->sauth_chunk) { |
| 3592 |
case SCTP_CID_INIT: |
| 3593 |
case SCTP_CID_INIT_ACK: |
| 3594 |
case SCTP_CID_SHUTDOWN_COMPLETE: |
| 3595 |
case SCTP_CID_AUTH: |
| 3596 |
return -EINVAL; |
| 3597 |
} |
| 3598 |
|
| 3599 |
/* add this chunk id to the endpoint */ |
| 3600 |
return sctp_auth_ep_add_chunkid(ep, val->sauth_chunk); |
| 3601 |
} |
| 3602 |
|
| 3603 |
/* |
| 3604 |
* 7.1.19. Get or set the list of supported HMAC Identifiers (SCTP_HMAC_IDENT) |
| 3605 |
* |
| 3606 |
* This option gets or sets the list of HMAC algorithms that the local |
| 3607 |
* endpoint requires the peer to use. |
| 3608 |
*/ |
| 3609 |
static int sctp_setsockopt_hmac_ident(struct sock *sk, |
| 3610 |
struct sctp_hmacalgo *hmacs, |
| 3611 |
unsigned int optlen) |
| 3612 |
{ |
| 3613 |
struct sctp_endpoint *ep = sctp_sk(sk)->ep; |
| 3614 |
u32 idents; |
| 3615 |
|
| 3616 |
if (!ep->auth_enable) |
| 3617 |
return -EACCES; |
| 3618 |
|
| 3619 |
if (optlen < sizeof(struct sctp_hmacalgo)) |
| 3620 |
return -EINVAL; |
| 3621 |
optlen = min_t(unsigned int, optlen, sizeof(struct sctp_hmacalgo) + |
| 3622 |
SCTP_AUTH_NUM_HMACS * sizeof(u16)); |
| 3623 |
|
| 3624 |
idents = hmacs->shmac_num_idents; |
| 3625 |
if (idents == 0 || idents > SCTP_AUTH_NUM_HMACS || |
| 3626 |
(idents * sizeof(u16)) > (optlen - sizeof(struct sctp_hmacalgo))) |
| 3627 |
return -EINVAL; |
| 3628 |
|
| 3629 |
return sctp_auth_ep_set_hmacs(ep, hmacs); |
| 3630 |
} |
| 3631 |
|
| 3632 |
/* |
| 3633 |
* 7.1.20. Set a shared key (SCTP_AUTH_KEY) |
| 3634 |
* |
| 3635 |
* This option will set a shared secret key which is used to build an |
| 3636 |
* association shared key. |
| 3637 |
*/ |
| 3638 |
static int sctp_setsockopt_auth_key(struct sock *sk, |
| 3639 |
struct sctp_authkey *authkey, |
| 3640 |
unsigned int optlen) |
| 3641 |
{ |
| 3642 |
struct sctp_endpoint *ep = sctp_sk(sk)->ep; |
| 3643 |
struct sctp_association *asoc; |
| 3644 |
int ret = -EINVAL; |
| 3645 |
|
| 3646 |
if (optlen <= sizeof(struct sctp_authkey)) |
| 3647 |
return -EINVAL; |
| 3648 |
/* authkey->sca_keylength is u16, so optlen can't be bigger than |
| 3649 |
* this. |
| 3650 |
*/ |
| 3651 |
optlen = min_t(unsigned int, optlen, USHRT_MAX + sizeof(*authkey)); |
| 3652 |
|
| 3653 |
if (authkey->sca_keylength > optlen - sizeof(*authkey)) |
| 3654 |
goto out; |
| 3655 |
|
| 3656 |
asoc = sctp_id2assoc(sk, authkey->sca_assoc_id); |
| 3657 |
if (!asoc && authkey->sca_assoc_id > SCTP_ALL_ASSOC && |
| 3658 |
sctp_style(sk, UDP)) |
| 3659 |
goto out; |
| 3660 |
|
| 3661 |
if (asoc) { |
| 3662 |
ret = sctp_auth_set_key(ep, asoc, authkey); |
| 3663 |
goto out; |
| 3664 |
} |
| 3665 |
|
| 3666 |
if (sctp_style(sk, TCP)) |
| 3667 |
authkey->sca_assoc_id = SCTP_FUTURE_ASSOC; |
| 3668 |
|
| 3669 |
if (authkey->sca_assoc_id == SCTP_FUTURE_ASSOC || |
| 3670 |
authkey->sca_assoc_id == SCTP_ALL_ASSOC) { |
| 3671 |
ret = sctp_auth_set_key(ep, asoc, authkey); |
| 3672 |
if (ret) |
| 3673 |
goto out; |
| 3674 |
} |
| 3675 |
|
| 3676 |
ret = 0; |
| 3677 |
|
| 3678 |
if (authkey->sca_assoc_id == SCTP_CURRENT_ASSOC || |
| 3679 |
authkey->sca_assoc_id == SCTP_ALL_ASSOC) { |
| 3680 |
list_for_each_entry(asoc, &ep->asocs, asocs) { |
| 3681 |
int res = sctp_auth_set_key(ep, asoc, authkey); |
| 3682 |
|
| 3683 |
if (res && !ret) |
| 3684 |
ret = res; |
| 3685 |
} |
| 3686 |
} |
| 3687 |
|
| 3688 |
out: |
| 3689 |
memzero_explicit(authkey, optlen); |
| 3690 |
return ret; |
| 3691 |
} |
| 3692 |
|
| 3693 |
/* |
| 3694 |
* 7.1.21. Get or set the active shared key (SCTP_AUTH_ACTIVE_KEY) |
| 3695 |
* |
| 3696 |
* This option will get or set the active shared key to be used to build |
| 3697 |
* the association shared key. |
| 3698 |
*/ |
| 3699 |
static int sctp_setsockopt_active_key(struct sock *sk, |
| 3700 |
struct sctp_authkeyid *val, |
| 3701 |
unsigned int optlen) |
| 3702 |
{ |
| 3703 |
struct sctp_endpoint *ep = sctp_sk(sk)->ep; |
| 3704 |
struct sctp_association *asoc; |
| 3705 |
int ret = 0; |
| 3706 |
|
| 3707 |
if (optlen != sizeof(struct sctp_authkeyid)) |
| 3708 |
return -EINVAL; |
| 3709 |
|
| 3710 |
asoc = sctp_id2assoc(sk, val->scact_assoc_id); |
| 3711 |
if (!asoc && val->scact_assoc_id > SCTP_ALL_ASSOC && |
| 3712 |
sctp_style(sk, UDP)) |
| 3713 |
return -EINVAL; |
| 3714 |
|
| 3715 |
if (asoc) |
| 3716 |
return sctp_auth_set_active_key(ep, asoc, val->scact_keynumber); |
| 3717 |
|
| 3718 |
if (sctp_style(sk, TCP)) |
| 3719 |
val->scact_assoc_id = SCTP_FUTURE_ASSOC; |
| 3720 |
|
| 3721 |
if (val->scact_assoc_id == SCTP_FUTURE_ASSOC || |
| 3722 |
val->scact_assoc_id == SCTP_ALL_ASSOC) { |
| 3723 |
ret = sctp_auth_set_active_key(ep, asoc, val->scact_keynumber); |
| 3724 |
if (ret) |
| 3725 |
return ret; |
| 3726 |
} |
| 3727 |
|
| 3728 |
if (val->scact_assoc_id == SCTP_CURRENT_ASSOC || |
| 3729 |
val->scact_assoc_id == SCTP_ALL_ASSOC) { |
| 3730 |
list_for_each_entry(asoc, &ep->asocs, asocs) { |
| 3731 |
int res = sctp_auth_set_active_key(ep, asoc, |
| 3732 |
val->scact_keynumber); |
| 3733 |
|
| 3734 |
if (res && !ret) |
| 3735 |
ret = res; |
| 3736 |
} |
| 3737 |
} |
| 3738 |
|
| 3739 |
return ret; |
| 3740 |
} |
| 3741 |
|
| 3742 |
/* |
| 3743 |
* 7.1.22. Delete a shared key (SCTP_AUTH_DELETE_KEY) |
| 3744 |
* |
| 3745 |
* This set option will delete a shared secret key from use. |
| 3746 |
*/ |
| 3747 |
static int sctp_setsockopt_del_key(struct sock *sk, |
| 3748 |
struct sctp_authkeyid *val, |
| 3749 |
unsigned int optlen) |
| 3750 |
{ |
| 3751 |
struct sctp_endpoint *ep = sctp_sk(sk)->ep; |
| 3752 |
struct sctp_association *asoc; |
| 3753 |
int ret = 0; |
| 3754 |
|
| 3755 |
if (optlen != sizeof(struct sctp_authkeyid)) |
| 3756 |
return -EINVAL; |
| 3757 |
|
| 3758 |
asoc = sctp_id2assoc(sk, val->scact_assoc_id); |
| 3759 |
if (!asoc && val->scact_assoc_id > SCTP_ALL_ASSOC && |
| 3760 |
sctp_style(sk, UDP)) |
| 3761 |
return -EINVAL; |
| 3762 |
|
| 3763 |
if (asoc) |
| 3764 |
return sctp_auth_del_key_id(ep, asoc, val->scact_keynumber); |
| 3765 |
|
| 3766 |
if (sctp_style(sk, TCP)) |
| 3767 |
val->scact_assoc_id = SCTP_FUTURE_ASSOC; |
| 3768 |
|
| 3769 |
if (val->scact_assoc_id == SCTP_FUTURE_ASSOC || |
| 3770 |
val->scact_assoc_id == SCTP_ALL_ASSOC) { |
| 3771 |
ret = sctp_auth_del_key_id(ep, asoc, val->scact_keynumber); |
| 3772 |
if (ret) |
| 3773 |
return ret; |
| 3774 |
} |
| 3775 |
|
| 3776 |
if (val->scact_assoc_id == SCTP_CURRENT_ASSOC || |
| 3777 |
val->scact_assoc_id == SCTP_ALL_ASSOC) { |
| 3778 |
list_for_each_entry(asoc, &ep->asocs, asocs) { |
| 3779 |
int res = sctp_auth_del_key_id(ep, asoc, |
| 3780 |
val->scact_keynumber); |
| 3781 |
|
| 3782 |
if (res && !ret) |
| 3783 |
ret = res; |
| 3784 |
} |
| 3785 |
} |
| 3786 |
|
| 3787 |
return ret; |
| 3788 |
} |
| 3789 |
|
| 3790 |
/* |
| 3791 |
* 8.3.4 Deactivate a Shared Key (SCTP_AUTH_DEACTIVATE_KEY) |
| 3792 |
* |
| 3793 |
* This set option will deactivate a shared secret key. |
| 3794 |
*/ |
| 3795 |
static int sctp_setsockopt_deactivate_key(struct sock *sk, |
| 3796 |
struct sctp_authkeyid *val, |
| 3797 |
unsigned int optlen) |
| 3798 |
{ |
| 3799 |
struct sctp_endpoint *ep = sctp_sk(sk)->ep; |
| 3800 |
struct sctp_association *asoc; |
| 3801 |
int ret = 0; |
| 3802 |
|
| 3803 |
if (optlen != sizeof(struct sctp_authkeyid)) |
| 3804 |
return -EINVAL; |
| 3805 |
|
| 3806 |
asoc = sctp_id2assoc(sk, val->scact_assoc_id); |
| 3807 |
if (!asoc && val->scact_assoc_id > SCTP_ALL_ASSOC && |
| 3808 |
sctp_style(sk, UDP)) |
| 3809 |
return -EINVAL; |
| 3810 |
|
| 3811 |
if (asoc) |
| 3812 |
return sctp_auth_deact_key_id(ep, asoc, val->scact_keynumber); |
| 3813 |
|
| 3814 |
if (sctp_style(sk, TCP)) |
| 3815 |
val->scact_assoc_id = SCTP_FUTURE_ASSOC; |
| 3816 |
|
| 3817 |
if (val->scact_assoc_id == SCTP_FUTURE_ASSOC || |
| 3818 |
val->scact_assoc_id == SCTP_ALL_ASSOC) { |
| 3819 |
ret = sctp_auth_deact_key_id(ep, asoc, val->scact_keynumber); |
| 3820 |
if (ret) |
| 3821 |
return ret; |
| 3822 |
} |
| 3823 |
|
| 3824 |
if (val->scact_assoc_id == SCTP_CURRENT_ASSOC || |
| 3825 |
val->scact_assoc_id == SCTP_ALL_ASSOC) { |
| 3826 |
list_for_each_entry(asoc, &ep->asocs, asocs) { |
| 3827 |
int res = sctp_auth_deact_key_id(ep, asoc, |
| 3828 |
val->scact_keynumber); |
| 3829 |
|
| 3830 |
if (res && !ret) |
| 3831 |
ret = res; |
| 3832 |
} |
| 3833 |
} |
| 3834 |
|
| 3835 |
return ret; |
| 3836 |
} |
| 3837 |
|
| 3838 |
/* |
| 3839 |
* 8.1.23 SCTP_AUTO_ASCONF |
| 3840 |
* |
| 3841 |
* This option will enable or disable the use of the automatic generation of |
| 3842 |
* ASCONF chunks to add and delete addresses to an existing association. Note |
| 3843 |
* that this option has two caveats namely: a) it only affects sockets that |
| 3844 |
* are bound to all addresses available to the SCTP stack, and b) the system |
| 3845 |
* administrator may have an overriding control that turns the ASCONF feature |
| 3846 |
* off no matter what setting the socket option may have. |
| 3847 |
* This option expects an integer boolean flag, where a non-zero value turns on |
| 3848 |
* the option, and a zero value turns off the option. |
| 3849 |
* Note. In this implementation, socket operation overrides default parameter |
| 3850 |
* being set by sysctl as well as FreeBSD implementation |
| 3851 |
*/ |
| 3852 |
static int sctp_setsockopt_auto_asconf(struct sock *sk, int *val, |
| 3853 |
unsigned int optlen) |
| 3854 |
{ |
| 3855 |
struct sctp_sock *sp = sctp_sk(sk); |
| 3856 |
|
| 3857 |
if (optlen < sizeof(int)) |
| 3858 |
return -EINVAL; |
| 3859 |
if (!sctp_is_ep_boundall(sk) && *val) |
| 3860 |
return -EINVAL; |
| 3861 |
if ((*val && sp->do_auto_asconf) || (!*val && !sp->do_auto_asconf)) |
| 3862 |
return 0; |
| 3863 |
|
| 3864 |
spin_lock_bh(&sock_net(sk)->sctp.addr_wq_lock); |
| 3865 |
if (*val == 0 && sp->do_auto_asconf) { |
| 3866 |
list_del(&sp->auto_asconf_list); |
| 3867 |
sp->do_auto_asconf = 0; |
| 3868 |
} else if (*val && !sp->do_auto_asconf) { |
| 3869 |
list_add_tail(&sp->auto_asconf_list, |
| 3870 |
&sock_net(sk)->sctp.auto_asconf_splist); |
| 3871 |
sp->do_auto_asconf = 1; |
| 3872 |
} |
| 3873 |
spin_unlock_bh(&sock_net(sk)->sctp.addr_wq_lock); |
| 3874 |
return 0; |
| 3875 |
} |
| 3876 |
|
| 3877 |
/* |
| 3878 |
* SCTP_PEER_ADDR_THLDS |
| 3879 |
* |
| 3880 |
* This option allows us to alter the partially failed threshold for one or all |
| 3881 |
* transports in an association. See Section 6.1 of: |
| 3882 |
* http://www.ietf.org/id/draft-nishida-tsvwg-sctp-failover-05.txt |
| 3883 |
*/ |
| 3884 |
static int sctp_setsockopt_paddr_thresholds(struct sock *sk, |
| 3885 |
struct sctp_paddrthlds_v2 *val, |
| 3886 |
unsigned int optlen, bool v2) |
| 3887 |
{ |
| 3888 |
struct sctp_transport *trans; |
| 3889 |
struct sctp_association *asoc; |
| 3890 |
int len; |
| 3891 |
|
| 3892 |
len = v2 ? sizeof(*val) : sizeof(struct sctp_paddrthlds); |
| 3893 |
if (optlen < len) |
| 3894 |
return -EINVAL; |
| 3895 |
|
| 3896 |
if (v2 && val->spt_pathpfthld > val->spt_pathcpthld) |
| 3897 |
return -EINVAL; |
| 3898 |
|
| 3899 |
if (!sctp_is_any(sk, (const union sctp_addr *)&val->spt_address)) { |
| 3900 |
trans = sctp_addr_id2transport(sk, &val->spt_address, |
| 3901 |
val->spt_assoc_id); |
| 3902 |
if (!trans) |
| 3903 |
return -ENOENT; |
| 3904 |
|
| 3905 |
if (val->spt_pathmaxrxt) |
| 3906 |
trans->pathmaxrxt = val->spt_pathmaxrxt; |
| 3907 |
if (v2) |
| 3908 |
trans->ps_retrans = val->spt_pathcpthld; |
| 3909 |
trans->pf_retrans = val->spt_pathpfthld; |
| 3910 |
|
| 3911 |
return 0; |
| 3912 |
} |
| 3913 |
|
| 3914 |
asoc = sctp_id2assoc(sk, val->spt_assoc_id); |
| 3915 |
if (!asoc && val->spt_assoc_id != SCTP_FUTURE_ASSOC && |
| 3916 |
sctp_style(sk, UDP)) |
| 3917 |
return -EINVAL; |
| 3918 |
|
| 3919 |
if (asoc) { |
| 3920 |
list_for_each_entry(trans, &asoc->peer.transport_addr_list, |
| 3921 |
transports) { |
| 3922 |
if (val->spt_pathmaxrxt) |
| 3923 |
trans->pathmaxrxt = val->spt_pathmaxrxt; |
| 3924 |
if (v2) |
| 3925 |
trans->ps_retrans = val->spt_pathcpthld; |
| 3926 |
trans->pf_retrans = val->spt_pathpfthld; |
| 3927 |
} |
| 3928 |
|
| 3929 |
if (val->spt_pathmaxrxt) |
| 3930 |
asoc->pathmaxrxt = val->spt_pathmaxrxt; |
| 3931 |
if (v2) |
| 3932 |
asoc->ps_retrans = val->spt_pathcpthld; |
| 3933 |
asoc->pf_retrans = val->spt_pathpfthld; |
| 3934 |
} else { |
| 3935 |
struct sctp_sock *sp = sctp_sk(sk); |
| 3936 |
|
| 3937 |
if (val->spt_pathmaxrxt) |
| 3938 |
sp->pathmaxrxt = val->spt_pathmaxrxt; |
| 3939 |
if (v2) |
| 3940 |
sp->ps_retrans = val->spt_pathcpthld; |
| 3941 |
sp->pf_retrans = val->spt_pathpfthld; |
| 3942 |
} |
| 3943 |
|
| 3944 |
return 0; |
| 3945 |
} |
| 3946 |
|
| 3947 |
static int sctp_setsockopt_recvrcvinfo(struct sock *sk, int *val, |
| 3948 |
unsigned int optlen) |
| 3949 |
{ |
| 3950 |
if (optlen < sizeof(int)) |
| 3951 |
return -EINVAL; |
| 3952 |
|
| 3953 |
sctp_sk(sk)->recvrcvinfo = (*val == 0) ? 0 : 1; |
| 3954 |
|
| 3955 |
return 0; |
| 3956 |
} |
| 3957 |
|
| 3958 |
static int sctp_setsockopt_recvnxtinfo(struct sock *sk, int *val, |
| 3959 |
unsigned int optlen) |
| 3960 |
{ |
| 3961 |
if (optlen < sizeof(int)) |
| 3962 |
return -EINVAL; |
| 3963 |
|
| 3964 |
sctp_sk(sk)->recvnxtinfo = (*val == 0) ? 0 : 1; |
| 3965 |
|
| 3966 |
return 0; |
| 3967 |
} |
| 3968 |
|
| 3969 |
static int sctp_setsockopt_pr_supported(struct sock *sk, |
| 3970 |
struct sctp_assoc_value *params, |
| 3971 |
unsigned int optlen) |
| 3972 |
{ |
| 3973 |
struct sctp_association *asoc; |
| 3974 |
|
| 3975 |
if (optlen != sizeof(*params)) |
| 3976 |
return -EINVAL; |
| 3977 |
|
| 3978 |
asoc = sctp_id2assoc(sk, params->assoc_id); |
| 3979 |
if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC && |
| 3980 |
sctp_style(sk, UDP)) |
| 3981 |
return -EINVAL; |
| 3982 |
|
| 3983 |
sctp_sk(sk)->ep->prsctp_enable = !!params->assoc_value; |
| 3984 |
|
| 3985 |
return 0; |
| 3986 |
} |
| 3987 |
|
| 3988 |
static int sctp_setsockopt_default_prinfo(struct sock *sk, |
| 3989 |
struct sctp_default_prinfo *info, |
| 3990 |
unsigned int optlen) |
| 3991 |
{ |
| 3992 |
struct sctp_sock *sp = sctp_sk(sk); |
| 3993 |
struct sctp_association *asoc; |
| 3994 |
int retval = -EINVAL; |
| 3995 |
|
| 3996 |
if (optlen != sizeof(*info)) |
| 3997 |
goto out; |
| 3998 |
|
| 3999 |
if (info->pr_policy & ~SCTP_PR_SCTP_MASK) |
| 4000 |
goto out; |
| 4001 |
|
| 4002 |
if (info->pr_policy == SCTP_PR_SCTP_NONE) |
| 4003 |
info->pr_value = 0; |
| 4004 |
|
| 4005 |
asoc = sctp_id2assoc(sk, info->pr_assoc_id); |
| 4006 |
if (!asoc && info->pr_assoc_id > SCTP_ALL_ASSOC && |
| 4007 |
sctp_style(sk, UDP)) |
| 4008 |
goto out; |
| 4009 |
|
| 4010 |
retval = 0; |
| 4011 |
|
| 4012 |
if (asoc) { |
| 4013 |
SCTP_PR_SET_POLICY(asoc->default_flags, info->pr_policy); |
| 4014 |
asoc->default_timetolive = info->pr_value; |
| 4015 |
goto out; |
| 4016 |
} |
| 4017 |
|
| 4018 |
if (sctp_style(sk, TCP)) |
| 4019 |
info->pr_assoc_id = SCTP_FUTURE_ASSOC; |
| 4020 |
|
| 4021 |
if (info->pr_assoc_id == SCTP_FUTURE_ASSOC || |
| 4022 |
info->pr_assoc_id == SCTP_ALL_ASSOC) { |
| 4023 |
SCTP_PR_SET_POLICY(sp->default_flags, info->pr_policy); |
| 4024 |
sp->default_timetolive = info->pr_value; |
| 4025 |
} |
| 4026 |
|
| 4027 |
if (info->pr_assoc_id == SCTP_CURRENT_ASSOC || |
| 4028 |
info->pr_assoc_id == SCTP_ALL_ASSOC) { |
| 4029 |
list_for_each_entry(asoc, &sp->ep->asocs, asocs) { |
| 4030 |
SCTP_PR_SET_POLICY(asoc->default_flags, |
| 4031 |
info->pr_policy); |
| 4032 |
asoc->default_timetolive = info->pr_value; |
| 4033 |
} |
| 4034 |
} |
| 4035 |
|
| 4036 |
out: |
| 4037 |
return retval; |
| 4038 |
} |
| 4039 |
|
| 4040 |
static int sctp_setsockopt_reconfig_supported(struct sock *sk, |
| 4041 |
struct sctp_assoc_value *params, |
| 4042 |
unsigned int optlen) |
| 4043 |
{ |
| 4044 |
struct sctp_association *asoc; |
| 4045 |
int retval = -EINVAL; |
| 4046 |
|
| 4047 |
if (optlen != sizeof(*params)) |
| 4048 |
goto out; |
| 4049 |
|
| 4050 |
asoc = sctp_id2assoc(sk, params->assoc_id); |
| 4051 |
if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC && |
| 4052 |
sctp_style(sk, UDP)) |
| 4053 |
goto out; |
| 4054 |
|
| 4055 |
sctp_sk(sk)->ep->reconf_enable = !!params->assoc_value; |
| 4056 |
|
| 4057 |
retval = 0; |
| 4058 |
|
| 4059 |
out: |
| 4060 |
return retval; |
| 4061 |
} |
| 4062 |
|
| 4063 |
static int sctp_setsockopt_enable_strreset(struct sock *sk, |
| 4064 |
struct sctp_assoc_value *params, |
| 4065 |
unsigned int optlen) |
| 4066 |
{ |
| 4067 |
struct sctp_endpoint *ep = sctp_sk(sk)->ep; |
| 4068 |
struct sctp_association *asoc; |
| 4069 |
int retval = -EINVAL; |
| 4070 |
|
| 4071 |
if (optlen != sizeof(*params)) |
| 4072 |
goto out; |
| 4073 |
|
| 4074 |
if (params->assoc_value & (~SCTP_ENABLE_STRRESET_MASK)) |
| 4075 |
goto out; |
| 4076 |
|
| 4077 |
asoc = sctp_id2assoc(sk, params->assoc_id); |
| 4078 |
if (!asoc && params->assoc_id > SCTP_ALL_ASSOC && |
| 4079 |
sctp_style(sk, UDP)) |
| 4080 |
goto out; |
| 4081 |
|
| 4082 |
retval = 0; |
| 4083 |
|
| 4084 |
if (asoc) { |
| 4085 |
asoc->strreset_enable = params->assoc_value; |
| 4086 |
goto out; |
| 4087 |
} |
| 4088 |
|
| 4089 |
if (sctp_style(sk, TCP)) |
| 4090 |
params->assoc_id = SCTP_FUTURE_ASSOC; |
| 4091 |
|
| 4092 |
if (params->assoc_id == SCTP_FUTURE_ASSOC || |
| 4093 |
params->assoc_id == SCTP_ALL_ASSOC) |
| 4094 |
ep->strreset_enable = params->assoc_value; |
| 4095 |
|
| 4096 |
if (params->assoc_id == SCTP_CURRENT_ASSOC || |
| 4097 |
params->assoc_id == SCTP_ALL_ASSOC) |
| 4098 |
list_for_each_entry(asoc, &ep->asocs, asocs) |
| 4099 |
asoc->strreset_enable = params->assoc_value; |
| 4100 |
|
| 4101 |
out: |
| 4102 |
return retval; |
| 4103 |
} |
| 4104 |
|
| 4105 |
static int sctp_setsockopt_reset_streams(struct sock *sk, |
| 4106 |
struct sctp_reset_streams *params, |
| 4107 |
unsigned int optlen) |
| 4108 |
{ |
| 4109 |
struct sctp_association *asoc; |
| 4110 |
|
| 4111 |
if (optlen < sizeof(*params)) |
| 4112 |
return -EINVAL; |
| 4113 |
/* srs_number_streams is u16, so optlen can't be bigger than this. */ |
| 4114 |
optlen = min_t(unsigned int, optlen, USHRT_MAX + |
| 4115 |
sizeof(__u16) * sizeof(*params)); |
| 4116 |
|
| 4117 |
if (params->srs_number_streams * sizeof(__u16) > |
| 4118 |
optlen - sizeof(*params)) |
| 4119 |
return -EINVAL; |
| 4120 |
|
| 4121 |
asoc = sctp_id2assoc(sk, params->srs_assoc_id); |
| 4122 |
if (!asoc) |
| 4123 |
return -EINVAL; |
| 4124 |
|
| 4125 |
return sctp_send_reset_streams(asoc, params); |
| 4126 |
} |
| 4127 |
|
| 4128 |
static int sctp_setsockopt_reset_assoc(struct sock *sk, sctp_assoc_t *associd, |
| 4129 |
unsigned int optlen) |
| 4130 |
{ |
| 4131 |
struct sctp_association *asoc; |
| 4132 |
|
| 4133 |
if (optlen != sizeof(*associd)) |
| 4134 |
return -EINVAL; |
| 4135 |
|
| 4136 |
asoc = sctp_id2assoc(sk, *associd); |
| 4137 |
if (!asoc) |
| 4138 |
return -EINVAL; |
| 4139 |
|
| 4140 |
return sctp_send_reset_assoc(asoc); |
| 4141 |
} |
| 4142 |
|
| 4143 |
static int sctp_setsockopt_add_streams(struct sock *sk, |
| 4144 |
struct sctp_add_streams *params, |
| 4145 |
unsigned int optlen) |
| 4146 |
{ |
| 4147 |
struct sctp_association *asoc; |
| 4148 |
|
| 4149 |
if (optlen != sizeof(*params)) |
| 4150 |
return -EINVAL; |
| 4151 |
|
| 4152 |
asoc = sctp_id2assoc(sk, params->sas_assoc_id); |
| 4153 |
if (!asoc) |
| 4154 |
return -EINVAL; |
| 4155 |
|
| 4156 |
return sctp_send_add_streams(asoc, params); |
| 4157 |
} |
| 4158 |
|
| 4159 |
static int sctp_setsockopt_scheduler(struct sock *sk, |
| 4160 |
struct sctp_assoc_value *params, |
| 4161 |
unsigned int optlen) |
| 4162 |
{ |
| 4163 |
struct sctp_sock *sp = sctp_sk(sk); |
| 4164 |
struct sctp_association *asoc; |
| 4165 |
int retval = 0; |
| 4166 |
|
| 4167 |
if (optlen < sizeof(*params)) |
| 4168 |
return -EINVAL; |
| 4169 |
|
| 4170 |
if (params->assoc_value > SCTP_SS_MAX) |
| 4171 |
return -EINVAL; |
| 4172 |
|
| 4173 |
asoc = sctp_id2assoc(sk, params->assoc_id); |
| 4174 |
if (!asoc && params->assoc_id > SCTP_ALL_ASSOC && |
| 4175 |
sctp_style(sk, UDP)) |
| 4176 |
return -EINVAL; |
| 4177 |
|
| 4178 |
if (asoc) |
| 4179 |
return sctp_sched_set_sched(asoc, params->assoc_value); |
| 4180 |
|
| 4181 |
if (sctp_style(sk, TCP)) |
| 4182 |
params->assoc_id = SCTP_FUTURE_ASSOC; |
| 4183 |
|
| 4184 |
if (params->assoc_id == SCTP_FUTURE_ASSOC || |
| 4185 |
params->assoc_id == SCTP_ALL_ASSOC) |
| 4186 |
sp->default_ss = params->assoc_value; |
| 4187 |
|
| 4188 |
if (params->assoc_id == SCTP_CURRENT_ASSOC || |
| 4189 |
params->assoc_id == SCTP_ALL_ASSOC) { |
| 4190 |
list_for_each_entry(asoc, &sp->ep->asocs, asocs) { |
| 4191 |
int ret = sctp_sched_set_sched(asoc, |
| 4192 |
params->assoc_value); |
| 4193 |
|
| 4194 |
if (ret && !retval) |
| 4195 |
retval = ret; |
| 4196 |
} |
| 4197 |
} |
| 4198 |
|
| 4199 |
return retval; |
| 4200 |
} |
| 4201 |
|
| 4202 |
static int sctp_setsockopt_scheduler_value(struct sock *sk, |
| 4203 |
struct sctp_stream_value *params, |
| 4204 |
unsigned int optlen) |
| 4205 |
{ |
| 4206 |
struct sctp_association *asoc; |
| 4207 |
int retval = -EINVAL; |
| 4208 |
|
| 4209 |
if (optlen < sizeof(*params)) |
| 4210 |
goto out; |
| 4211 |
|
| 4212 |
asoc = sctp_id2assoc(sk, params->assoc_id); |
| 4213 |
if (!asoc && params->assoc_id != SCTP_CURRENT_ASSOC && |
| 4214 |
sctp_style(sk, UDP)) |
| 4215 |
goto out; |
| 4216 |
|
| 4217 |
if (asoc) { |
| 4218 |
retval = sctp_sched_set_value(asoc, params->stream_id, |
| 4219 |
params->stream_value, GFP_KERNEL); |
| 4220 |
goto out; |
| 4221 |
} |
| 4222 |
|
| 4223 |
retval = 0; |
| 4224 |
|
| 4225 |
list_for_each_entry(asoc, &sctp_sk(sk)->ep->asocs, asocs) { |
| 4226 |
int ret = sctp_sched_set_value(asoc, params->stream_id, |
| 4227 |
params->stream_value, |
| 4228 |
GFP_KERNEL); |
| 4229 |
if (ret && !retval) /* try to return the 1st error. */ |
| 4230 |
retval = ret; |
| 4231 |
} |
| 4232 |
|
| 4233 |
out: |
| 4234 |
return retval; |
| 4235 |
} |
| 4236 |
|
| 4237 |
static int sctp_setsockopt_interleaving_supported(struct sock *sk, |
| 4238 |
struct sctp_assoc_value *p, |
| 4239 |
unsigned int optlen) |
| 4240 |
{ |
| 4241 |
struct sctp_sock *sp = sctp_sk(sk); |
| 4242 |
struct sctp_association *asoc; |
| 4243 |
|
| 4244 |
if (optlen < sizeof(*p)) |
| 4245 |
return -EINVAL; |
| 4246 |
|
| 4247 |
asoc = sctp_id2assoc(sk, p->assoc_id); |
| 4248 |
if (!asoc && p->assoc_id != SCTP_FUTURE_ASSOC && sctp_style(sk, UDP)) |
| 4249 |
return -EINVAL; |
| 4250 |
|
| 4251 |
if (!sock_net(sk)->sctp.intl_enable || !sp->frag_interleave) { |
| 4252 |
return -EPERM; |
| 4253 |
} |
| 4254 |
|
| 4255 |
sp->ep->intl_enable = !!p->assoc_value; |
| 4256 |
return 0; |
| 4257 |
} |
| 4258 |
|
| 4259 |
static int sctp_setsockopt_reuse_port(struct sock *sk, int *val, |
| 4260 |
unsigned int optlen) |
| 4261 |
{ |
| 4262 |
if (!sctp_style(sk, TCP)) |
| 4263 |
return -EOPNOTSUPP; |
| 4264 |
|
| 4265 |
if (sctp_sk(sk)->ep->base.bind_addr.port) |
| 4266 |
return -EFAULT; |
| 4267 |
|
| 4268 |
if (optlen < sizeof(int)) |
| 4269 |
return -EINVAL; |
| 4270 |
|
| 4271 |
sctp_sk(sk)->reuse = !!*val; |
| 4272 |
|
| 4273 |
return 0; |
| 4274 |
} |
| 4275 |
|
| 4276 |
static int sctp_assoc_ulpevent_type_set(struct sctp_event *param, |
| 4277 |
struct sctp_association *asoc) |
| 4278 |
{ |
| 4279 |
struct sctp_ulpevent *event; |
| 4280 |
|
| 4281 |
sctp_ulpevent_type_set(&asoc->subscribe, param->se_type, param->se_on); |
| 4282 |
|
| 4283 |
if (param->se_type == SCTP_SENDER_DRY_EVENT && param->se_on) { |
| 4284 |
if (sctp_outq_is_empty(&asoc->outqueue)) { |
| 4285 |
event = sctp_ulpevent_make_sender_dry_event(asoc, |
| 4286 |
GFP_USER | __GFP_NOWARN); |
| 4287 |
if (!event) |
| 4288 |
return -ENOMEM; |
| 4289 |
|
| 4290 |
asoc->stream.si->enqueue_event(&asoc->ulpq, event); |
| 4291 |
} |
| 4292 |
} |
| 4293 |
|
| 4294 |
return 0; |
| 4295 |
} |
| 4296 |
|
| 4297 |
static int sctp_setsockopt_event(struct sock *sk, struct sctp_event *param, |
| 4298 |
unsigned int optlen) |
| 4299 |
{ |
| 4300 |
struct sctp_sock *sp = sctp_sk(sk); |
| 4301 |
struct sctp_association *asoc; |
| 4302 |
int retval = 0; |
| 4303 |
|
| 4304 |
if (optlen < sizeof(*param)) |
| 4305 |
return -EINVAL; |
| 4306 |
|
| 4307 |
if (param->se_type < SCTP_SN_TYPE_BASE || |
| 4308 |
param->se_type > SCTP_SN_TYPE_MAX) |
| 4309 |
return -EINVAL; |
| 4310 |
|
| 4311 |
asoc = sctp_id2assoc(sk, param->se_assoc_id); |
| 4312 |
if (!asoc && param->se_assoc_id > SCTP_ALL_ASSOC && |
| 4313 |
sctp_style(sk, UDP)) |
| 4314 |
return -EINVAL; |
| 4315 |
|
| 4316 |
if (asoc) |
| 4317 |
return sctp_assoc_ulpevent_type_set(param, asoc); |
| 4318 |
|
| 4319 |
if (sctp_style(sk, TCP)) |
| 4320 |
param->se_assoc_id = SCTP_FUTURE_ASSOC; |
| 4321 |
|
| 4322 |
if (param->se_assoc_id == SCTP_FUTURE_ASSOC || |
| 4323 |
param->se_assoc_id == SCTP_ALL_ASSOC) |
| 4324 |
sctp_ulpevent_type_set(&sp->subscribe, |
| 4325 |
param->se_type, param->se_on); |
| 4326 |
|
| 4327 |
if (param->se_assoc_id == SCTP_CURRENT_ASSOC || |
| 4328 |
param->se_assoc_id == SCTP_ALL_ASSOC) { |
| 4329 |
list_for_each_entry(asoc, &sp->ep->asocs, asocs) { |
| 4330 |
int ret = sctp_assoc_ulpevent_type_set(param, asoc); |
| 4331 |
|
| 4332 |
if (ret && !retval) |
| 4333 |
retval = ret; |
| 4334 |
} |
| 4335 |
} |
| 4336 |
|
| 4337 |
return retval; |
| 4338 |
} |
| 4339 |
|
| 4340 |
static int sctp_setsockopt_asconf_supported(struct sock *sk, |
| 4341 |
struct sctp_assoc_value *params, |
| 4342 |
unsigned int optlen) |
| 4343 |
{ |
| 4344 |
struct sctp_association *asoc; |
| 4345 |
struct sctp_endpoint *ep; |
| 4346 |
int retval = -EINVAL; |
| 4347 |
|
| 4348 |
if (optlen != sizeof(*params)) |
| 4349 |
goto out; |
| 4350 |
|
| 4351 |
asoc = sctp_id2assoc(sk, params->assoc_id); |
| 4352 |
if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC && |
| 4353 |
sctp_style(sk, UDP)) |
| 4354 |
goto out; |
| 4355 |
|
| 4356 |
ep = sctp_sk(sk)->ep; |
| 4357 |
ep->asconf_enable = !!params->assoc_value; |
| 4358 |
|
| 4359 |
if (ep->asconf_enable && ep->auth_enable) { |
| 4360 |
sctp_auth_ep_add_chunkid(ep, SCTP_CID_ASCONF); |
| 4361 |
sctp_auth_ep_add_chunkid(ep, SCTP_CID_ASCONF_ACK); |
| 4362 |
} |
| 4363 |
|
| 4364 |
retval = 0; |
| 4365 |
|
| 4366 |
out: |
| 4367 |
return retval; |
| 4368 |
} |
| 4369 |
|
| 4370 |
static int sctp_setsockopt_auth_supported(struct sock *sk, |
| 4371 |
struct sctp_assoc_value *params, |
| 4372 |
unsigned int optlen) |
| 4373 |
{ |
| 4374 |
struct sctp_association *asoc; |
| 4375 |
struct sctp_endpoint *ep; |
| 4376 |
int retval = -EINVAL; |
| 4377 |
|
| 4378 |
if (optlen != sizeof(*params)) |
| 4379 |
goto out; |
| 4380 |
|
| 4381 |
asoc = sctp_id2assoc(sk, params->assoc_id); |
| 4382 |
if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC && |
| 4383 |
sctp_style(sk, UDP)) |
| 4384 |
goto out; |
| 4385 |
|
| 4386 |
ep = sctp_sk(sk)->ep; |
| 4387 |
if (params->assoc_value) { |
| 4388 |
retval = sctp_auth_init(ep, GFP_KERNEL); |
| 4389 |
if (retval) |
| 4390 |
goto out; |
| 4391 |
if (ep->asconf_enable) { |
| 4392 |
sctp_auth_ep_add_chunkid(ep, SCTP_CID_ASCONF); |
| 4393 |
sctp_auth_ep_add_chunkid(ep, SCTP_CID_ASCONF_ACK); |
| 4394 |
} |
| 4395 |
} |
| 4396 |
|
| 4397 |
ep->auth_enable = !!params->assoc_value; |
| 4398 |
retval = 0; |
| 4399 |
|
| 4400 |
out: |
| 4401 |
return retval; |
| 4402 |
} |
| 4403 |
|
| 4404 |
static int sctp_setsockopt_ecn_supported(struct sock *sk, |
| 4405 |
struct sctp_assoc_value *params, |
| 4406 |
unsigned int optlen) |
| 4407 |
{ |
| 4408 |
struct sctp_association *asoc; |
| 4409 |
int retval = -EINVAL; |
| 4410 |
|
| 4411 |
if (optlen != sizeof(*params)) |
| 4412 |
goto out; |
| 4413 |
|
| 4414 |
asoc = sctp_id2assoc(sk, params->assoc_id); |
| 4415 |
if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC && |
| 4416 |
sctp_style(sk, UDP)) |
| 4417 |
goto out; |
| 4418 |
|
| 4419 |
sctp_sk(sk)->ep->ecn_enable = !!params->assoc_value; |
| 4420 |
retval = 0; |
| 4421 |
|
| 4422 |
out: |
| 4423 |
return retval; |
| 4424 |
} |
| 4425 |
|
| 4426 |
static int sctp_setsockopt_pf_expose(struct sock *sk, |
| 4427 |
struct sctp_assoc_value *params, |
| 4428 |
unsigned int optlen) |
| 4429 |
{ |
| 4430 |
struct sctp_association *asoc; |
| 4431 |
int retval = -EINVAL; |
| 4432 |
|
| 4433 |
if (optlen != sizeof(*params)) |
| 4434 |
goto out; |
| 4435 |
|
| 4436 |
if (params->assoc_value > SCTP_PF_EXPOSE_MAX) |
| 4437 |
goto out; |
| 4438 |
|
| 4439 |
asoc = sctp_id2assoc(sk, params->assoc_id); |
| 4440 |
if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC && |
| 4441 |
sctp_style(sk, UDP)) |
| 4442 |
goto out; |
| 4443 |
|
| 4444 |
if (asoc) |
| 4445 |
asoc->pf_expose = params->assoc_value; |
| 4446 |
else |
| 4447 |
sctp_sk(sk)->pf_expose = params->assoc_value; |
| 4448 |
retval = 0; |
| 4449 |
|
| 4450 |
out: |
| 4451 |
return retval; |
| 4452 |
} |
| 4453 |
|
| 4454 |
static int sctp_setsockopt_encap_port(struct sock *sk, |
| 4455 |
struct sctp_udpencaps *encap, |
| 4456 |
unsigned int optlen) |
| 4457 |
{ |
| 4458 |
struct sctp_association *asoc; |
| 4459 |
struct sctp_transport *t; |
| 4460 |
__be16 encap_port; |
| 4461 |
|
| 4462 |
if (optlen != sizeof(*encap)) |
| 4463 |
return -EINVAL; |
| 4464 |
|
| 4465 |
/* If an address other than INADDR_ANY is specified, and |
| 4466 |
* no transport is found, then the request is invalid. |
| 4467 |
*/ |
| 4468 |
encap_port = (__force __be16)encap->sue_port; |
| 4469 |
if (!sctp_is_any(sk, (union sctp_addr *)&encap->sue_address)) { |
| 4470 |
t = sctp_addr_id2transport(sk, &encap->sue_address, |
| 4471 |
encap->sue_assoc_id); |
| 4472 |
if (!t) |
| 4473 |
return -EINVAL; |
| 4474 |
|
| 4475 |
t->encap_port = encap_port; |
| 4476 |
return 0; |
| 4477 |
} |
| 4478 |
|
| 4479 |
/* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the |
| 4480 |
* socket is a one to many style socket, and an association |
| 4481 |
* was not found, then the id was invalid. |
| 4482 |
*/ |
| 4483 |
asoc = sctp_id2assoc(sk, encap->sue_assoc_id); |
| 4484 |
if (!asoc && encap->sue_assoc_id != SCTP_FUTURE_ASSOC && |
| 4485 |
sctp_style(sk, UDP)) |
| 4486 |
return -EINVAL; |
| 4487 |
|
| 4488 |
/* If changes are for association, also apply encap_port to |
| 4489 |
* each transport. |
| 4490 |
*/ |
| 4491 |
if (asoc) { |
| 4492 |
list_for_each_entry(t, &asoc->peer.transport_addr_list, |
| 4493 |
transports) |
| 4494 |
t->encap_port = encap_port; |
| 4495 |
|
| 4496 |
asoc->encap_port = encap_port; |
| 4497 |
return 0; |
| 4498 |
} |
| 4499 |
|
| 4500 |
sctp_sk(sk)->encap_port = encap_port; |
| 4501 |
return 0; |
| 4502 |
} |
| 4503 |
|
| 4504 |
static int sctp_setsockopt_probe_interval(struct sock *sk, |
| 4505 |
struct sctp_probeinterval *params, |
| 4506 |
unsigned int optlen) |
| 4507 |
{ |
| 4508 |
struct sctp_association *asoc; |
| 4509 |
struct sctp_transport *t; |
| 4510 |
__u32 probe_interval; |
| 4511 |
|
| 4512 |
if (optlen != sizeof(*params)) |
| 4513 |
return -EINVAL; |
| 4514 |
|
| 4515 |
probe_interval = params->spi_interval; |
| 4516 |
if (probe_interval && probe_interval < SCTP_PROBE_TIMER_MIN) |
| 4517 |
return -EINVAL; |
| 4518 |
|
| 4519 |
/* If an address other than INADDR_ANY is specified, and |
| 4520 |
* no transport is found, then the request is invalid. |
| 4521 |
*/ |
| 4522 |
if (!sctp_is_any(sk, (union sctp_addr *)¶ms->spi_address)) { |
| 4523 |
t = sctp_addr_id2transport(sk, ¶ms->spi_address, |
| 4524 |
params->spi_assoc_id); |
| 4525 |
if (!t) |
| 4526 |
return -EINVAL; |
| 4527 |
|
| 4528 |
t->probe_interval = msecs_to_jiffies(probe_interval); |
| 4529 |
sctp_transport_pl_reset(t); |
| 4530 |
return 0; |
| 4531 |
} |
| 4532 |
|
| 4533 |
/* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the |
| 4534 |
* socket is a one to many style socket, and an association |
| 4535 |
* was not found, then the id was invalid. |
| 4536 |
*/ |
| 4537 |
asoc = sctp_id2assoc(sk, params->spi_assoc_id); |
| 4538 |
if (!asoc && params->spi_assoc_id != SCTP_FUTURE_ASSOC && |
| 4539 |
sctp_style(sk, UDP)) |
| 4540 |
return -EINVAL; |
| 4541 |
|
| 4542 |
/* If changes are for association, also apply probe_interval to |
| 4543 |
* each transport. |
| 4544 |
*/ |
| 4545 |
if (asoc) { |
| 4546 |
list_for_each_entry(t, &asoc->peer.transport_addr_list, transports) { |
| 4547 |
t->probe_interval = msecs_to_jiffies(probe_interval); |
| 4548 |
sctp_transport_pl_reset(t); |
| 4549 |
} |
| 4550 |
|
| 4551 |
asoc->probe_interval = msecs_to_jiffies(probe_interval); |
| 4552 |
return 0; |
| 4553 |
} |
| 4554 |
|
| 4555 |
sctp_sk(sk)->probe_interval = probe_interval; |
| 4556 |
return 0; |
| 4557 |
} |
| 4558 |
|
| 4559 |
/* API 6.2 setsockopt(), getsockopt() |
| 4560 |
* |
| 4561 |
* Applications use setsockopt() and getsockopt() to set or retrieve |
| 4562 |
* socket options. Socket options are used to change the default |
| 4563 |
* behavior of sockets calls. They are described in Section 7. |
| 4564 |
* |
| 4565 |
* The syntax is: |
| 4566 |
* |
| 4567 |
* ret = getsockopt(int sd, int level, int optname, void __user *optval, |
| 4568 |
* int __user *optlen); |
| 4569 |
* ret = setsockopt(int sd, int level, int optname, const void __user *optval, |
| 4570 |
* int optlen); |
| 4571 |
* |
| 4572 |
* sd - the socket descript. |
| 4573 |
* level - set to IPPROTO_SCTP for all SCTP options. |
| 4574 |
* optname - the option name. |
| 4575 |
* optval - the buffer to store the value of the option. |
| 4576 |
* optlen - the size of the buffer. |
| 4577 |
*/ |
| 4578 |
static int sctp_setsockopt(struct sock *sk, int level, int optname, |
| 4579 |
sockptr_t optval, unsigned int optlen) |
| 4580 |
{ |
| 4581 |
void *kopt = NULL; |
| 4582 |
int retval = 0; |
| 4583 |
|
| 4584 |
pr_debug("%s: sk:%p, optname:%d\n", __func__, sk, optname); |
| 4585 |
|
| 4586 |
/* I can hardly begin to describe how wrong this is. This is |
| 4587 |
* so broken as to be worse than useless. The API draft |
| 4588 |
* REALLY is NOT helpful here... I am not convinced that the |
| 4589 |
* semantics of setsockopt() with a level OTHER THAN SOL_SCTP |
| 4590 |
* are at all well-founded. |
| 4591 |
*/ |
| 4592 |
if (level != SOL_SCTP) { |
| 4593 |
struct sctp_af *af = sctp_sk(sk)->pf->af; |
| 4594 |
|
| 4595 |
return af->setsockopt(sk, level, optname, optval, optlen); |
| 4596 |
} |
| 4597 |
|
| 4598 |
if (optlen > 0) { |
| 4599 |
/* Trim it to the biggest size sctp sockopt may need if necessary */ |
| 4600 |
optlen = min_t(unsigned int, optlen, |
| 4601 |
PAGE_ALIGN(USHRT_MAX + |
| 4602 |
sizeof(__u16) * sizeof(struct sctp_reset_streams))); |
| 4603 |
kopt = memdup_sockptr(optval, optlen); |
| 4604 |
if (IS_ERR(kopt)) |
| 4605 |
return PTR_ERR(kopt); |
| 4606 |
} |
| 4607 |
|
| 4608 |
lock_sock(sk); |
| 4609 |
|
| 4610 |
switch (optname) { |
| 4611 |
case SCTP_SOCKOPT_BINDX_ADD: |
| 4612 |
/* 'optlen' is the size of the addresses buffer. */ |
| 4613 |
retval = sctp_setsockopt_bindx(sk, kopt, optlen, |
| 4614 |
SCTP_BINDX_ADD_ADDR); |
| 4615 |
break; |
| 4616 |
|
| 4617 |
case SCTP_SOCKOPT_BINDX_REM: |
| 4618 |
/* 'optlen' is the size of the addresses buffer. */ |
| 4619 |
retval = sctp_setsockopt_bindx(sk, kopt, optlen, |
| 4620 |
SCTP_BINDX_REM_ADDR); |
| 4621 |
break; |
| 4622 |
|
| 4623 |
case SCTP_SOCKOPT_CONNECTX_OLD: |
| 4624 |
/* 'optlen' is the size of the addresses buffer. */ |
| 4625 |
retval = sctp_setsockopt_connectx_old(sk, kopt, optlen); |
| 4626 |
break; |
| 4627 |
|
| 4628 |
case SCTP_SOCKOPT_CONNECTX: |
| 4629 |
/* 'optlen' is the size of the addresses buffer. */ |
| 4630 |
retval = sctp_setsockopt_connectx(sk, kopt, optlen); |
| 4631 |
break; |
| 4632 |
|
| 4633 |
case SCTP_DISABLE_FRAGMENTS: |
| 4634 |
retval = sctp_setsockopt_disable_fragments(sk, kopt, optlen); |
| 4635 |
break; |
| 4636 |
|
| 4637 |
case SCTP_EVENTS: |
| 4638 |
retval = sctp_setsockopt_events(sk, kopt, optlen); |
| 4639 |
break; |
| 4640 |
|
| 4641 |
case SCTP_AUTOCLOSE: |
| 4642 |
retval = sctp_setsockopt_autoclose(sk, kopt, optlen); |
| 4643 |
break; |
| 4644 |
|
| 4645 |
case SCTP_PEER_ADDR_PARAMS: |
| 4646 |
retval = sctp_setsockopt_peer_addr_params(sk, kopt, optlen); |
| 4647 |
break; |
| 4648 |
|
| 4649 |
case SCTP_DELAYED_SACK: |
| 4650 |
retval = sctp_setsockopt_delayed_ack(sk, kopt, optlen); |
| 4651 |
break; |
| 4652 |
case SCTP_PARTIAL_DELIVERY_POINT: |
| 4653 |
retval = sctp_setsockopt_partial_delivery_point(sk, kopt, optlen); |
| 4654 |
break; |
| 4655 |
|
| 4656 |
case SCTP_INITMSG: |
| 4657 |
retval = sctp_setsockopt_initmsg(sk, kopt, optlen); |
| 4658 |
break; |
| 4659 |
case SCTP_DEFAULT_SEND_PARAM: |
| 4660 |
retval = sctp_setsockopt_default_send_param(sk, kopt, optlen); |
| 4661 |
break; |
| 4662 |
case SCTP_DEFAULT_SNDINFO: |
| 4663 |
retval = sctp_setsockopt_default_sndinfo(sk, kopt, optlen); |
| 4664 |
break; |
| 4665 |
case SCTP_PRIMARY_ADDR: |
| 4666 |
retval = sctp_setsockopt_primary_addr(sk, kopt, optlen); |
| 4667 |
break; |
| 4668 |
case SCTP_SET_PEER_PRIMARY_ADDR: |
| 4669 |
retval = sctp_setsockopt_peer_primary_addr(sk, kopt, optlen); |
| 4670 |
break; |
| 4671 |
case SCTP_NODELAY: |
| 4672 |
retval = sctp_setsockopt_nodelay(sk, kopt, optlen); |
| 4673 |
break; |
| 4674 |
case SCTP_RTOINFO: |
| 4675 |
retval = sctp_setsockopt_rtoinfo(sk, kopt, optlen); |
| 4676 |
break; |
| 4677 |
case SCTP_ASSOCINFO: |
| 4678 |
retval = sctp_setsockopt_associnfo(sk, kopt, optlen); |
| 4679 |
break; |
| 4680 |
case SCTP_I_WANT_MAPPED_V4_ADDR: |
| 4681 |
retval = sctp_setsockopt_mappedv4(sk, kopt, optlen); |
| 4682 |
break; |
| 4683 |
case SCTP_MAXSEG: |
| 4684 |
retval = sctp_setsockopt_maxseg(sk, kopt, optlen); |
| 4685 |
break; |
| 4686 |
case SCTP_ADAPTATION_LAYER: |
| 4687 |
retval = sctp_setsockopt_adaptation_layer(sk, kopt, optlen); |
| 4688 |
break; |
| 4689 |
case SCTP_CONTEXT: |
| 4690 |
retval = sctp_setsockopt_context(sk, kopt, optlen); |
| 4691 |
break; |
| 4692 |
case SCTP_FRAGMENT_INTERLEAVE: |
| 4693 |
retval = sctp_setsockopt_fragment_interleave(sk, kopt, optlen); |
| 4694 |
break; |
| 4695 |
case SCTP_MAX_BURST: |
| 4696 |
retval = sctp_setsockopt_maxburst(sk, kopt, optlen); |
| 4697 |
break; |
| 4698 |
case SCTP_AUTH_CHUNK: |
| 4699 |
retval = sctp_setsockopt_auth_chunk(sk, kopt, optlen); |
| 4700 |
break; |
| 4701 |
case SCTP_HMAC_IDENT: |
| 4702 |
retval = sctp_setsockopt_hmac_ident(sk, kopt, optlen); |
| 4703 |
break; |
| 4704 |
case SCTP_AUTH_KEY: |
| 4705 |
retval = sctp_setsockopt_auth_key(sk, kopt, optlen); |
| 4706 |
break; |
| 4707 |
case SCTP_AUTH_ACTIVE_KEY: |
| 4708 |
retval = sctp_setsockopt_active_key(sk, kopt, optlen); |
| 4709 |
break; |
| 4710 |
case SCTP_AUTH_DELETE_KEY: |
| 4711 |
retval = sctp_setsockopt_del_key(sk, kopt, optlen); |
| 4712 |
break; |
| 4713 |
case SCTP_AUTH_DEACTIVATE_KEY: |
| 4714 |
retval = sctp_setsockopt_deactivate_key(sk, kopt, optlen); |
| 4715 |
break; |
| 4716 |
case SCTP_AUTO_ASCONF: |
| 4717 |
retval = sctp_setsockopt_auto_asconf(sk, kopt, optlen); |
| 4718 |
break; |
| 4719 |
case SCTP_PEER_ADDR_THLDS: |
| 4720 |
retval = sctp_setsockopt_paddr_thresholds(sk, kopt, optlen, |
| 4721 |
false); |
| 4722 |
break; |
| 4723 |
case SCTP_PEER_ADDR_THLDS_V2: |
| 4724 |
retval = sctp_setsockopt_paddr_thresholds(sk, kopt, optlen, |
| 4725 |
true); |
| 4726 |
break; |
| 4727 |
case SCTP_RECVRCVINFO: |
| 4728 |
retval = sctp_setsockopt_recvrcvinfo(sk, kopt, optlen); |
| 4729 |
break; |
| 4730 |
case SCTP_RECVNXTINFO: |
| 4731 |
retval = sctp_setsockopt_recvnxtinfo(sk, kopt, optlen); |
| 4732 |
break; |
| 4733 |
case SCTP_PR_SUPPORTED: |
| 4734 |
retval = sctp_setsockopt_pr_supported(sk, kopt, optlen); |
| 4735 |
break; |
| 4736 |
case SCTP_DEFAULT_PRINFO: |
| 4737 |
retval = sctp_setsockopt_default_prinfo(sk, kopt, optlen); |
| 4738 |
break; |
| 4739 |
case SCTP_RECONFIG_SUPPORTED: |
| 4740 |
retval = sctp_setsockopt_reconfig_supported(sk, kopt, optlen); |
| 4741 |
break; |
| 4742 |
case SCTP_ENABLE_STREAM_RESET: |
| 4743 |
retval = sctp_setsockopt_enable_strreset(sk, kopt, optlen); |
| 4744 |
break; |
| 4745 |
case SCTP_RESET_STREAMS: |
| 4746 |
retval = sctp_setsockopt_reset_streams(sk, kopt, optlen); |
| 4747 |
break; |
| 4748 |
case SCTP_RESET_ASSOC: |
| 4749 |
retval = sctp_setsockopt_reset_assoc(sk, kopt, optlen); |
| 4750 |
break; |
| 4751 |
case SCTP_ADD_STREAMS: |
| 4752 |
retval = sctp_setsockopt_add_streams(sk, kopt, optlen); |
| 4753 |
break; |
| 4754 |
case SCTP_STREAM_SCHEDULER: |
| 4755 |
retval = sctp_setsockopt_scheduler(sk, kopt, optlen); |
| 4756 |
break; |
| 4757 |
case SCTP_STREAM_SCHEDULER_VALUE: |
| 4758 |
retval = sctp_setsockopt_scheduler_value(sk, kopt, optlen); |
| 4759 |
break; |
| 4760 |
case SCTP_INTERLEAVING_SUPPORTED: |
| 4761 |
retval = sctp_setsockopt_interleaving_supported(sk, kopt, |
| 4762 |
optlen); |
| 4763 |
break; |
| 4764 |
case SCTP_REUSE_PORT: |
| 4765 |
retval = sctp_setsockopt_reuse_port(sk, kopt, optlen); |
| 4766 |
break; |
| 4767 |
case SCTP_EVENT: |
| 4768 |
retval = sctp_setsockopt_event(sk, kopt, optlen); |
| 4769 |
break; |
| 4770 |
case SCTP_ASCONF_SUPPORTED: |
| 4771 |
retval = sctp_setsockopt_asconf_supported(sk, kopt, optlen); |
| 4772 |
break; |
| 4773 |
case SCTP_AUTH_SUPPORTED: |
| 4774 |
retval = sctp_setsockopt_auth_supported(sk, kopt, optlen); |
| 4775 |
break; |
| 4776 |
case SCTP_ECN_SUPPORTED: |
| 4777 |
retval = sctp_setsockopt_ecn_supported(sk, kopt, optlen); |
| 4778 |
break; |
| 4779 |
case SCTP_EXPOSE_POTENTIALLY_FAILED_STATE: |
| 4780 |
retval = sctp_setsockopt_pf_expose(sk, kopt, optlen); |
| 4781 |
break; |
| 4782 |
case SCTP_REMOTE_UDP_ENCAPS_PORT: |
| 4783 |
retval = sctp_setsockopt_encap_port(sk, kopt, optlen); |
| 4784 |
break; |
| 4785 |
case SCTP_PLPMTUD_PROBE_INTERVAL: |
| 4786 |
retval = sctp_setsockopt_probe_interval(sk, kopt, optlen); |
| 4787 |
break; |
| 4788 |
default: |
| 4789 |
retval = -ENOPROTOOPT; |
| 4790 |
break; |
| 4791 |
} |
| 4792 |
|
| 4793 |
release_sock(sk); |
| 4794 |
kfree(kopt); |
| 4795 |
return retval; |
| 4796 |
} |
| 4797 |
|
| 4798 |
/* API 3.1.6 connect() - UDP Style Syntax |
| 4799 |
* |
| 4800 |
* An application may use the connect() call in the UDP model to initiate an |
| 4801 |
* association without sending data. |
| 4802 |
* |
| 4803 |
* The syntax is: |
| 4804 |
* |
| 4805 |
* ret = connect(int sd, const struct sockaddr *nam, socklen_t len); |
| 4806 |
* |
| 4807 |
* sd: the socket descriptor to have a new association added to. |
| 4808 |
* |
| 4809 |
* nam: the address structure (either struct sockaddr_in or struct |
| 4810 |
* sockaddr_in6 defined in RFC2553 [7]). |
| 4811 |
* |
| 4812 |
* len: the size of the address. |
| 4813 |
*/ |
| 4814 |
static int sctp_connect(struct sock *sk, struct sockaddr *addr, |
| 4815 |
int addr_len, int flags) |
| 4816 |
{ |
| 4817 |
struct sctp_af *af; |
| 4818 |
int err = -EINVAL; |
| 4819 |
|
| 4820 |
lock_sock(sk); |
| 4821 |
pr_debug("%s: sk:%p, sockaddr:%p, addr_len:%d\n", __func__, sk, |
| 4822 |
addr, addr_len); |
| 4823 |
|
| 4824 |
/* Validate addr_len before calling common connect/connectx routine. */ |
| 4825 |
af = sctp_get_af_specific(addr->sa_family); |
| 4826 |
if (af && addr_len >= af->sockaddr_len) |
| 4827 |
err = __sctp_connect(sk, addr, af->sockaddr_len, flags, NULL); |
| 4828 |
|
| 4829 |
release_sock(sk); |
| 4830 |
return err; |
| 4831 |
} |
| 4832 |
|
| 4833 |
int sctp_inet_connect(struct socket *sock, struct sockaddr_unsized *uaddr, |
| 4834 |
int addr_len, int flags) |
| 4835 |
{ |
| 4836 |
if (addr_len < sizeof(uaddr->sa_family)) |
| 4837 |
return -EINVAL; |
| 4838 |
|
| 4839 |
if (uaddr->sa_family == AF_UNSPEC) |
| 4840 |
return -EOPNOTSUPP; |
| 4841 |
|
| 4842 |
return sctp_connect(sock->sk, (struct sockaddr *)uaddr, addr_len, flags); |
| 4843 |
} |
| 4844 |
|
| 4845 |
/* Only called when shutdown a listening SCTP socket. */ |
| 4846 |
static int sctp_disconnect(struct sock *sk, int flags) |
| 4847 |
{ |
| 4848 |
if (!sctp_style(sk, TCP)) |
| 4849 |
return -EOPNOTSUPP; |
| 4850 |
|
| 4851 |
sk->sk_shutdown |= RCV_SHUTDOWN; |
| 4852 |
return 0; |
| 4853 |
} |
| 4854 |
|
| 4855 |
static struct sock *sctp_clone_sock(struct sock *sk, |
| 4856 |
struct sctp_association *asoc, |
| 4857 |
enum sctp_socket_type type) |
| 4858 |
{ |
| 4859 |
struct sock *newsk = sk_clone(sk, GFP_KERNEL, false); |
| 4860 |
struct inet_sock *newinet; |
| 4861 |
struct sctp_sock *newsp; |
| 4862 |
int err = -ENOMEM; |
| 4863 |
|
| 4864 |
if (!newsk) |
| 4865 |
return ERR_PTR(err); |
| 4866 |
|
| 4867 |
/* sk_clone() sets refcnt to 2 */ |
| 4868 |
sock_put(newsk); |
| 4869 |
|
| 4870 |
newinet = inet_sk(newsk); |
| 4871 |
newsp = sctp_sk(newsk); |
| 4872 |
|
| 4873 |
newsp->pf->to_sk_daddr(&asoc->peer.primary_addr, newsk); |
| 4874 |
newinet->inet_dport = htons(asoc->peer.port); |
| 4875 |
atomic_set(&newinet->inet_id, get_random_u16()); |
| 4876 |
|
| 4877 |
inet_set_bit(MC_LOOP, newsk); |
| 4878 |
newinet->mc_ttl = 1; |
| 4879 |
newinet->mc_index = 0; |
| 4880 |
newinet->mc_list = NULL; |
| 4881 |
|
| 4882 |
#if IS_ENABLED(CONFIG_IPV6) |
| 4883 |
if (sk->sk_family == AF_INET6) { |
| 4884 |
struct ipv6_pinfo *newnp; |
| 4885 |
|
| 4886 |
newinet->pinet6 = &((struct sctp6_sock *)newsk)->inet6; |
| 4887 |
newinet->ipv6_fl_list = NULL; |
| 4888 |
|
| 4889 |
newnp = inet6_sk(newsk); |
| 4890 |
memcpy(newnp, inet6_sk(sk), sizeof(struct ipv6_pinfo)); |
| 4891 |
newnp->ipv6_mc_list = NULL; |
| 4892 |
newnp->ipv6_ac_list = NULL; |
| 4893 |
} |
| 4894 |
#endif |
| 4895 |
|
| 4896 |
newsp->pf->copy_ip_options(sk, newsk); |
| 4897 |
|
| 4898 |
newsp->do_auto_asconf = 0; |
| 4899 |
skb_queue_head_init(&newsp->pd_lobby); |
| 4900 |
|
| 4901 |
newsp->ep = sctp_endpoint_new(newsk, GFP_KERNEL); |
| 4902 |
if (!newsp->ep) |
| 4903 |
goto out_release; |
| 4904 |
|
| 4905 |
SCTP_DBG_OBJCNT_INC(sock); |
| 4906 |
sk_sockets_allocated_inc(newsk); |
| 4907 |
sock_prot_inuse_add(sock_net(sk), newsk->sk_prot, 1); |
| 4908 |
|
| 4909 |
err = sctp_sock_migrate(sk, newsk, asoc, type); |
| 4910 |
if (err) |
| 4911 |
goto out_release; |
| 4912 |
|
| 4913 |
/* Set newsk security attributes from original sk and connection |
| 4914 |
* security attribute from asoc. |
| 4915 |
*/ |
| 4916 |
security_sctp_sk_clone(asoc, sk, newsk); |
| 4917 |
|
| 4918 |
return newsk; |
| 4919 |
|
| 4920 |
out_release: |
| 4921 |
sk_common_release(newsk); |
| 4922 |
return ERR_PTR(err); |
| 4923 |
} |
| 4924 |
|
| 4925 |
/* 4.1.4 accept() - TCP Style Syntax |
| 4926 |
* |
| 4927 |
* Applications use accept() call to remove an established SCTP |
| 4928 |
* association from the accept queue of the endpoint. A new socket |
| 4929 |
* descriptor will be returned from accept() to represent the newly |
| 4930 |
* formed association. |
| 4931 |
*/ |
| 4932 |
static struct sock *sctp_accept(struct sock *sk, struct proto_accept_arg *arg) |
| 4933 |
{ |
| 4934 |
struct sctp_association *asoc; |
| 4935 |
struct sock *newsk = NULL; |
| 4936 |
int error = 0; |
| 4937 |
long timeo; |
| 4938 |
|
| 4939 |
lock_sock(sk); |
| 4940 |
|
| 4941 |
if (!sctp_style(sk, TCP)) { |
| 4942 |
error = -EOPNOTSUPP; |
| 4943 |
goto out; |
| 4944 |
} |
| 4945 |
|
| 4946 |
if (!sctp_sstate(sk, LISTENING) || |
| 4947 |
(sk->sk_shutdown & RCV_SHUTDOWN)) { |
| 4948 |
error = -EINVAL; |
| 4949 |
goto out; |
| 4950 |
} |
| 4951 |
|
| 4952 |
timeo = sock_rcvtimeo(sk, arg->flags & O_NONBLOCK); |
| 4953 |
|
| 4954 |
error = sctp_wait_for_accept(sk, timeo); |
| 4955 |
if (error) |
| 4956 |
goto out; |
| 4957 |
|
| 4958 |
/* We treat the list of associations on the endpoint as the accept |
| 4959 |
* queue and pick the first association on the list. |
| 4960 |
*/ |
| 4961 |
asoc = list_entry(sctp_sk(sk)->ep->asocs.next, |
| 4962 |
struct sctp_association, asocs); |
| 4963 |
|
| 4964 |
newsk = sctp_clone_sock(sk, asoc, SCTP_SOCKET_TCP); |
| 4965 |
if (IS_ERR(newsk)) { |
| 4966 |
error = PTR_ERR(newsk); |
| 4967 |
newsk = NULL; |
| 4968 |
} |
| 4969 |
|
| 4970 |
out: |
| 4971 |
release_sock(sk); |
| 4972 |
arg->err = error; |
| 4973 |
return newsk; |
| 4974 |
} |
| 4975 |
|
| 4976 |
/* The SCTP ioctl handler. */ |
| 4977 |
static int sctp_ioctl(struct sock *sk, int cmd, int *karg) |
| 4978 |
{ |
| 4979 |
int rc = -ENOTCONN; |
| 4980 |
|
| 4981 |
lock_sock(sk); |
| 4982 |
|
| 4983 |
/* |
| 4984 |
* SEQPACKET-style sockets in LISTENING state are valid, for |
| 4985 |
* SCTP, so only discard TCP-style sockets in LISTENING state. |
| 4986 |
*/ |
| 4987 |
if (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING)) |
| 4988 |
goto out; |
| 4989 |
|
| 4990 |
switch (cmd) { |
| 4991 |
case SIOCINQ: { |
| 4992 |
struct sk_buff *skb; |
| 4993 |
*karg = 0; |
| 4994 |
|
| 4995 |
skb = skb_peek(&sk->sk_receive_queue); |
| 4996 |
if (skb != NULL) { |
| 4997 |
/* |
| 4998 |
* We will only return the amount of this packet since |
| 4999 |
* that is all that will be read. |
| 5000 |
*/ |
| 5001 |
*karg = skb->len; |
| 5002 |
} |
| 5003 |
rc = 0; |
| 5004 |
break; |
| 5005 |
} |
| 5006 |
default: |
| 5007 |
rc = -ENOIOCTLCMD; |
| 5008 |
break; |
| 5009 |
} |
| 5010 |
out: |
| 5011 |
release_sock(sk); |
| 5012 |
return rc; |
| 5013 |
} |
| 5014 |
|
| 5015 |
/* This is the function which gets called during socket creation to |
| 5016 |
* initialized the SCTP-specific portion of the sock. |
| 5017 |
* The sock structure should already be zero-filled memory. |
| 5018 |
*/ |
| 5019 |
static int sctp_init_sock(struct sock *sk) |
| 5020 |
{ |
| 5021 |
struct net *net = sock_net(sk); |
| 5022 |
struct sctp_sock *sp; |
| 5023 |
|
| 5024 |
pr_debug("%s: sk:%p\n", __func__, sk); |
| 5025 |
|
| 5026 |
sp = sctp_sk(sk); |
| 5027 |
|
| 5028 |
/* Initialize the SCTP per socket area. */ |
| 5029 |
switch (sk->sk_type) { |
| 5030 |
case SOCK_SEQPACKET: |
| 5031 |
sp->type = SCTP_SOCKET_UDP; |
| 5032 |
break; |
| 5033 |
case SOCK_STREAM: |
| 5034 |
sp->type = SCTP_SOCKET_TCP; |
| 5035 |
break; |
| 5036 |
default: |
| 5037 |
return -ESOCKTNOSUPPORT; |
| 5038 |
} |
| 5039 |
|
| 5040 |
sk->sk_gso_type = SKB_GSO_SCTP; |
| 5041 |
|
| 5042 |
/* Initialize default send parameters. These parameters can be |
| 5043 |
* modified with the SCTP_DEFAULT_SEND_PARAM socket option. |
| 5044 |
*/ |
| 5045 |
sp->default_stream = 0; |
| 5046 |
sp->default_ppid = 0; |
| 5047 |
sp->default_flags = 0; |
| 5048 |
sp->default_context = 0; |
| 5049 |
sp->default_timetolive = 0; |
| 5050 |
|
| 5051 |
sp->default_rcv_context = 0; |
| 5052 |
sp->max_burst = net->sctp.max_burst; |
| 5053 |
|
| 5054 |
sp->cookie_auth_enable = net->sctp.cookie_auth_enable; |
| 5055 |
|
| 5056 |
/* Initialize default setup parameters. These parameters |
| 5057 |
* can be modified with the SCTP_INITMSG socket option or |
| 5058 |
* overridden by the SCTP_INIT CMSG. |
| 5059 |
*/ |
| 5060 |
sp->initmsg.sinit_num_ostreams = sctp_max_outstreams; |
| 5061 |
sp->initmsg.sinit_max_instreams = sctp_max_instreams; |
| 5062 |
sp->initmsg.sinit_max_attempts = net->sctp.max_retrans_init; |
| 5063 |
sp->initmsg.sinit_max_init_timeo = net->sctp.rto_max; |
| 5064 |
|
| 5065 |
/* Initialize default RTO related parameters. These parameters can |
| 5066 |
* be modified for with the SCTP_RTOINFO socket option. |
| 5067 |
*/ |
| 5068 |
sp->rtoinfo.srto_initial = net->sctp.rto_initial; |
| 5069 |
sp->rtoinfo.srto_max = net->sctp.rto_max; |
| 5070 |
sp->rtoinfo.srto_min = net->sctp.rto_min; |
| 5071 |
|
| 5072 |
/* Initialize default association related parameters. These parameters |
| 5073 |
* can be modified with the SCTP_ASSOCINFO socket option. |
| 5074 |
*/ |
| 5075 |
sp->assocparams.sasoc_asocmaxrxt = net->sctp.max_retrans_association; |
| 5076 |
sp->assocparams.sasoc_number_peer_destinations = 0; |
| 5077 |
sp->assocparams.sasoc_peer_rwnd = 0; |
| 5078 |
sp->assocparams.sasoc_local_rwnd = 0; |
| 5079 |
sp->assocparams.sasoc_cookie_life = net->sctp.valid_cookie_life; |
| 5080 |
|
| 5081 |
/* Initialize default event subscriptions. By default, all the |
| 5082 |
* options are off. |
| 5083 |
*/ |
| 5084 |
sp->subscribe = 0; |
| 5085 |
|
| 5086 |
/* Default Peer Address Parameters. These defaults can |
| 5087 |
* be modified via SCTP_PEER_ADDR_PARAMS |
| 5088 |
*/ |
| 5089 |
sp->hbinterval = net->sctp.hb_interval; |
| 5090 |
sp->udp_port = htons(net->sctp.udp_port); |
| 5091 |
sp->encap_port = htons(net->sctp.encap_port); |
| 5092 |
sp->pathmaxrxt = net->sctp.max_retrans_path; |
| 5093 |
sp->pf_retrans = net->sctp.pf_retrans; |
| 5094 |
sp->ps_retrans = net->sctp.ps_retrans; |
| 5095 |
sp->pf_expose = net->sctp.pf_expose; |
| 5096 |
sp->pathmtu = 0; /* allow default discovery */ |
| 5097 |
sp->sackdelay = net->sctp.sack_timeout; |
| 5098 |
sp->sackfreq = 2; |
| 5099 |
sp->param_flags = SPP_HB_ENABLE | |
| 5100 |
SPP_PMTUD_ENABLE | |
| 5101 |
SPP_SACKDELAY_ENABLE; |
| 5102 |
sp->default_ss = SCTP_SS_DEFAULT; |
| 5103 |
|
| 5104 |
/* If enabled no SCTP message fragmentation will be performed. |
| 5105 |
* Configure through SCTP_DISABLE_FRAGMENTS socket option. |
| 5106 |
*/ |
| 5107 |
sp->disable_fragments = 0; |
| 5108 |
|
| 5109 |
/* Enable Nagle algorithm by default. */ |
| 5110 |
sp->nodelay = 0; |
| 5111 |
|
| 5112 |
sp->recvrcvinfo = 0; |
| 5113 |
sp->recvnxtinfo = 0; |
| 5114 |
|
| 5115 |
/* Enable by default. */ |
| 5116 |
sp->v4mapped = 1; |
| 5117 |
|
| 5118 |
/* Auto-close idle associations after the configured |
| 5119 |
* number of seconds. A value of 0 disables this |
| 5120 |
* feature. Configure through the SCTP_AUTOCLOSE socket option, |
| 5121 |
* for UDP-style sockets only. |
| 5122 |
*/ |
| 5123 |
sp->autoclose = 0; |
| 5124 |
|
| 5125 |
/* User specified fragmentation limit. */ |
| 5126 |
sp->user_frag = 0; |
| 5127 |
|
| 5128 |
sp->adaptation_ind = 0; |
| 5129 |
|
| 5130 |
sp->pf = sctp_get_pf_specific(sk->sk_family); |
| 5131 |
|
| 5132 |
/* Control variables for partial data delivery. */ |
| 5133 |
atomic_set(&sp->pd_mode, 0); |
| 5134 |
skb_queue_head_init(&sp->pd_lobby); |
| 5135 |
sp->frag_interleave = 0; |
| 5136 |
sp->probe_interval = net->sctp.probe_interval; |
| 5137 |
|
| 5138 |
/* Create a per socket endpoint structure. Even if we |
| 5139 |
* change the data structure relationships, this may still |
| 5140 |
* be useful for storing pre-connect address information. |
| 5141 |
*/ |
| 5142 |
sp->ep = sctp_endpoint_new(sk, GFP_KERNEL); |
| 5143 |
if (!sp->ep) |
| 5144 |
return -ENOMEM; |
| 5145 |
|
| 5146 |
sk->sk_destruct = sctp_destruct_sock; |
| 5147 |
|
| 5148 |
SCTP_DBG_OBJCNT_INC(sock); |
| 5149 |
|
| 5150 |
sk_sockets_allocated_inc(sk); |
| 5151 |
sock_prot_inuse_add(net, sk->sk_prot, 1); |
| 5152 |
|
| 5153 |
return 0; |
| 5154 |
} |
| 5155 |
|
| 5156 |
/* Cleanup any SCTP per socket resources. Must be called with |
| 5157 |
* sock_net(sk)->sctp.addr_wq_lock held if sp->do_auto_asconf is true |
| 5158 |
*/ |
| 5159 |
static void sctp_destroy_sock(struct sock *sk) |
| 5160 |
{ |
| 5161 |
struct sctp_sock *sp; |
| 5162 |
|
| 5163 |
pr_debug("%s: sk:%p\n", __func__, sk); |
| 5164 |
|
| 5165 |
/* Release our hold on the endpoint. */ |
| 5166 |
sp = sctp_sk(sk); |
| 5167 |
/* This could happen during socket init, thus we bail out |
| 5168 |
* early, since the rest of the below is not setup either. |
| 5169 |
*/ |
| 5170 |
if (sp->ep == NULL) |
| 5171 |
return; |
| 5172 |
|
| 5173 |
if (sp->do_auto_asconf) { |
| 5174 |
sp->do_auto_asconf = 0; |
| 5175 |
list_del(&sp->auto_asconf_list); |
| 5176 |
} |
| 5177 |
|
| 5178 |
sctp_endpoint_free(sp->ep); |
| 5179 |
|
| 5180 |
sk_sockets_allocated_dec(sk); |
| 5181 |
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); |
| 5182 |
SCTP_DBG_OBJCNT_DEC(sock); |
| 5183 |
} |
| 5184 |
|
| 5185 |
static void sctp_destruct_sock(struct sock *sk) |
| 5186 |
{ |
| 5187 |
inet_sock_destruct(sk); |
| 5188 |
} |
| 5189 |
|
| 5190 |
/* API 4.1.7 shutdown() - TCP Style Syntax |
| 5191 |
* int shutdown(int socket, int how); |
| 5192 |
* |
| 5193 |
* sd - the socket descriptor of the association to be closed. |
| 5194 |
* how - Specifies the type of shutdown. The values are |
| 5195 |
* as follows: |
| 5196 |
* SHUT_RD |
| 5197 |
* Disables further receive operations. No SCTP |
| 5198 |
* protocol action is taken. |
| 5199 |
* SHUT_WR |
| 5200 |
* Disables further send operations, and initiates |
| 5201 |
* the SCTP shutdown sequence. |
| 5202 |
* SHUT_RDWR |
| 5203 |
* Disables further send and receive operations |
| 5204 |
* and initiates the SCTP shutdown sequence. |
| 5205 |
*/ |
| 5206 |
static void sctp_shutdown(struct sock *sk, int how) |
| 5207 |
{ |
| 5208 |
struct net *net = sock_net(sk); |
| 5209 |
struct sctp_endpoint *ep; |
| 5210 |
|
| 5211 |
if (!sctp_style(sk, TCP)) |
| 5212 |
return; |
| 5213 |
|
| 5214 |
ep = sctp_sk(sk)->ep; |
| 5215 |
if (how & SEND_SHUTDOWN && !list_empty(&ep->asocs)) { |
| 5216 |
struct sctp_association *asoc; |
| 5217 |
|
| 5218 |
inet_sk_set_state(sk, SCTP_SS_CLOSING); |
| 5219 |
asoc = list_entry(ep->asocs.next, |
| 5220 |
struct sctp_association, asocs); |
| 5221 |
sctp_primitive_SHUTDOWN(net, asoc, NULL); |
| 5222 |
} |
| 5223 |
} |
| 5224 |
|
| 5225 |
int sctp_get_sctp_info(struct sock *sk, struct sctp_association *asoc, |
| 5226 |
struct sctp_info *info) |
| 5227 |
{ |
| 5228 |
struct sctp_transport *prim; |
| 5229 |
struct list_head *pos; |
| 5230 |
int mask; |
| 5231 |
|
| 5232 |
memset(info, 0, sizeof(*info)); |
| 5233 |
if (!asoc) { |
| 5234 |
struct sctp_sock *sp = sctp_sk(sk); |
| 5235 |
|
| 5236 |
info->sctpi_s_autoclose = sp->autoclose; |
| 5237 |
info->sctpi_s_adaptation_ind = sp->adaptation_ind; |
| 5238 |
info->sctpi_s_pd_point = sp->pd_point; |
| 5239 |
info->sctpi_s_nodelay = sp->nodelay; |
| 5240 |
info->sctpi_s_disable_fragments = sp->disable_fragments; |
| 5241 |
info->sctpi_s_v4mapped = sp->v4mapped; |
| 5242 |
info->sctpi_s_frag_interleave = sp->frag_interleave; |
| 5243 |
info->sctpi_s_type = sp->type; |
| 5244 |
|
| 5245 |
return 0; |
| 5246 |
} |
| 5247 |
|
| 5248 |
info->sctpi_tag = asoc->c.my_vtag; |
| 5249 |
info->sctpi_state = asoc->state; |
| 5250 |
info->sctpi_rwnd = asoc->a_rwnd; |
| 5251 |
info->sctpi_unackdata = asoc->unack_data; |
| 5252 |
info->sctpi_penddata = sctp_tsnmap_pending(&asoc->peer.tsn_map); |
| 5253 |
info->sctpi_instrms = asoc->stream.incnt; |
| 5254 |
info->sctpi_outstrms = asoc->stream.outcnt; |
| 5255 |
list_for_each(pos, &asoc->base.inqueue.in_chunk_list) |
| 5256 |
info->sctpi_inqueue++; |
| 5257 |
list_for_each(pos, &asoc->outqueue.out_chunk_list) |
| 5258 |
info->sctpi_outqueue++; |
| 5259 |
info->sctpi_overall_error = asoc->overall_error_count; |
| 5260 |
info->sctpi_max_burst = asoc->max_burst; |
| 5261 |
info->sctpi_maxseg = asoc->frag_point; |
| 5262 |
info->sctpi_peer_rwnd = asoc->peer.rwnd; |
| 5263 |
info->sctpi_peer_tag = asoc->c.peer_vtag; |
| 5264 |
|
| 5265 |
mask = asoc->peer.intl_capable << 1; |
| 5266 |
mask = (mask | asoc->peer.ecn_capable) << 1; |
| 5267 |
mask = (mask | asoc->peer.ipv4_address) << 1; |
| 5268 |
mask = (mask | asoc->peer.ipv6_address) << 1; |
| 5269 |
mask = (mask | asoc->peer.reconf_capable) << 1; |
| 5270 |
mask = (mask | asoc->peer.asconf_capable) << 1; |
| 5271 |
mask = (mask | asoc->peer.prsctp_capable) << 1; |
| 5272 |
mask = (mask | asoc->peer.auth_capable); |
| 5273 |
info->sctpi_peer_capable = mask; |
| 5274 |
mask = asoc->peer.sack_needed << 1; |
| 5275 |
mask = (mask | asoc->peer.sack_generation) << 1; |
| 5276 |
mask = (mask | asoc->peer.zero_window_announced); |
| 5277 |
info->sctpi_peer_sack = mask; |
| 5278 |
|
| 5279 |
info->sctpi_isacks = asoc->stats.isacks; |
| 5280 |
info->sctpi_osacks = asoc->stats.osacks; |
| 5281 |
info->sctpi_opackets = asoc->stats.opackets; |
| 5282 |
info->sctpi_ipackets = asoc->stats.ipackets; |
| 5283 |
info->sctpi_rtxchunks = asoc->stats.rtxchunks; |
| 5284 |
info->sctpi_outofseqtsns = asoc->stats.outofseqtsns; |
| 5285 |
info->sctpi_idupchunks = asoc->stats.idupchunks; |
| 5286 |
info->sctpi_gapcnt = asoc->stats.gapcnt; |
| 5287 |
info->sctpi_ouodchunks = asoc->stats.ouodchunks; |
| 5288 |
info->sctpi_iuodchunks = asoc->stats.iuodchunks; |
| 5289 |
info->sctpi_oodchunks = asoc->stats.oodchunks; |
| 5290 |
info->sctpi_iodchunks = asoc->stats.iodchunks; |
| 5291 |
info->sctpi_octrlchunks = asoc->stats.octrlchunks; |
| 5292 |
info->sctpi_ictrlchunks = asoc->stats.ictrlchunks; |
| 5293 |
|
| 5294 |
prim = asoc->peer.primary_path; |
| 5295 |
memcpy(&info->sctpi_p_address, &prim->ipaddr, sizeof(prim->ipaddr)); |
| 5296 |
info->sctpi_p_state = prim->state; |
| 5297 |
info->sctpi_p_cwnd = prim->cwnd; |
| 5298 |
info->sctpi_p_srtt = prim->srtt; |
| 5299 |
info->sctpi_p_rto = jiffies_to_msecs(prim->rto); |
| 5300 |
info->sctpi_p_hbinterval = prim->hbinterval; |
| 5301 |
info->sctpi_p_pathmaxrxt = prim->pathmaxrxt; |
| 5302 |
info->sctpi_p_sackdelay = jiffies_to_msecs(prim->sackdelay); |
| 5303 |
info->sctpi_p_ssthresh = prim->ssthresh; |
| 5304 |
info->sctpi_p_partial_bytes_acked = prim->partial_bytes_acked; |
| 5305 |
info->sctpi_p_flight_size = prim->flight_size; |
| 5306 |
info->sctpi_p_error = prim->error_count; |
| 5307 |
|
| 5308 |
return 0; |
| 5309 |
} |
| 5310 |
EXPORT_SYMBOL_GPL(sctp_get_sctp_info); |
| 5311 |
|
| 5312 |
/* use callback to avoid exporting the core structure */ |
| 5313 |
void sctp_transport_walk_start(struct rhashtable_iter *iter) __acquires(RCU) |
| 5314 |
{ |
| 5315 |
rhltable_walk_enter(&sctp_transport_hashtable, iter); |
| 5316 |
|
| 5317 |
rhashtable_walk_start(iter); |
| 5318 |
} |
| 5319 |
|
| 5320 |
void sctp_transport_walk_stop(struct rhashtable_iter *iter) __releases(RCU) |
| 5321 |
{ |
| 5322 |
rhashtable_walk_stop(iter); |
| 5323 |
rhashtable_walk_exit(iter); |
| 5324 |
} |
| 5325 |
|
| 5326 |
struct sctp_transport *sctp_transport_get_next(struct net *net, |
| 5327 |
struct rhashtable_iter *iter) |
| 5328 |
{ |
| 5329 |
struct sctp_transport *t; |
| 5330 |
|
| 5331 |
t = rhashtable_walk_next(iter); |
| 5332 |
for (; t; t = rhashtable_walk_next(iter)) { |
| 5333 |
if (IS_ERR(t)) { |
| 5334 |
if (PTR_ERR(t) == -EAGAIN) |
| 5335 |
continue; |
| 5336 |
break; |
| 5337 |
} |
| 5338 |
|
| 5339 |
if (!sctp_transport_hold(t)) |
| 5340 |
continue; |
| 5341 |
|
| 5342 |
if (net_eq(t->asoc->base.net, net) && |
| 5343 |
t->asoc->peer.primary_path == t) |
| 5344 |
break; |
| 5345 |
|
| 5346 |
sctp_transport_put(t); |
| 5347 |
} |
| 5348 |
|
| 5349 |
return t; |
| 5350 |
} |
| 5351 |
|
| 5352 |
struct sctp_transport *sctp_transport_get_idx(struct net *net, |
| 5353 |
struct rhashtable_iter *iter, |
| 5354 |
int pos) |
| 5355 |
{ |
| 5356 |
struct sctp_transport *t; |
| 5357 |
|
| 5358 |
if (!pos) |
| 5359 |
return SEQ_START_TOKEN; |
| 5360 |
|
| 5361 |
while ((t = sctp_transport_get_next(net, iter)) && !IS_ERR(t)) { |
| 5362 |
if (!--pos) |
| 5363 |
break; |
| 5364 |
sctp_transport_put(t); |
| 5365 |
} |
| 5366 |
|
| 5367 |
return t; |
| 5368 |
} |
| 5369 |
|
| 5370 |
int sctp_for_each_endpoint(int (*cb)(struct sctp_endpoint *, void *), |
| 5371 |
void *p) { |
| 5372 |
int err = 0; |
| 5373 |
int hash = 0; |
| 5374 |
struct sctp_endpoint *ep; |
| 5375 |
struct sctp_hashbucket *head; |
| 5376 |
|
| 5377 |
for (head = sctp_ep_hashtable; hash < sctp_ep_hashsize; |
| 5378 |
hash++, head++) { |
| 5379 |
read_lock_bh(&head->lock); |
| 5380 |
sctp_for_each_hentry(ep, &head->chain) { |
| 5381 |
err = cb(ep, p); |
| 5382 |
if (err) |
| 5383 |
break; |
| 5384 |
} |
| 5385 |
read_unlock_bh(&head->lock); |
| 5386 |
} |
| 5387 |
|
| 5388 |
return err; |
| 5389 |
} |
| 5390 |
EXPORT_SYMBOL_GPL(sctp_for_each_endpoint); |
| 5391 |
|
| 5392 |
int sctp_transport_lookup_process(sctp_callback_t cb, struct net *net, |
| 5393 |
const union sctp_addr *laddr, |
| 5394 |
const union sctp_addr *paddr, void *p, int dif) |
| 5395 |
{ |
| 5396 |
struct sctp_transport *transport; |
| 5397 |
struct sctp_endpoint *ep; |
| 5398 |
int err = -ENOENT; |
| 5399 |
|
| 5400 |
rcu_read_lock(); |
| 5401 |
transport = sctp_addrs_lookup_transport(net, laddr, paddr, dif, dif); |
| 5402 |
if (!transport) { |
| 5403 |
rcu_read_unlock(); |
| 5404 |
return err; |
| 5405 |
} |
| 5406 |
ep = transport->asoc->ep; |
| 5407 |
if (!sctp_endpoint_hold(ep)) { /* asoc can be peeled off */ |
| 5408 |
sctp_transport_put(transport); |
| 5409 |
rcu_read_unlock(); |
| 5410 |
return err; |
| 5411 |
} |
| 5412 |
rcu_read_unlock(); |
| 5413 |
|
| 5414 |
err = cb(ep, transport, p); |
| 5415 |
sctp_endpoint_put(ep); |
| 5416 |
sctp_transport_put(transport); |
| 5417 |
return err; |
| 5418 |
} |
| 5419 |
EXPORT_SYMBOL_GPL(sctp_transport_lookup_process); |
| 5420 |
|
| 5421 |
int sctp_transport_traverse_process(sctp_callback_t cb, sctp_callback_t cb_done, |
| 5422 |
struct net *net, int *pos, void *p) |
| 5423 |
{ |
| 5424 |
struct rhashtable_iter hti; |
| 5425 |
struct sctp_transport *tsp; |
| 5426 |
struct sctp_endpoint *ep; |
| 5427 |
int ret; |
| 5428 |
|
| 5429 |
again: |
| 5430 |
ret = 0; |
| 5431 |
sctp_transport_walk_start(&hti); |
| 5432 |
|
| 5433 |
tsp = sctp_transport_get_idx(net, &hti, *pos + 1); |
| 5434 |
for (; !IS_ERR_OR_NULL(tsp); tsp = sctp_transport_get_next(net, &hti)) { |
| 5435 |
ep = tsp->asoc->ep; |
| 5436 |
if (sctp_endpoint_hold(ep)) { /* asoc can be peeled off */ |
| 5437 |
ret = cb(ep, tsp, p); |
| 5438 |
if (ret) |
| 5439 |
break; |
| 5440 |
sctp_endpoint_put(ep); |
| 5441 |
} |
| 5442 |
(*pos)++; |
| 5443 |
sctp_transport_put(tsp); |
| 5444 |
} |
| 5445 |
sctp_transport_walk_stop(&hti); |
| 5446 |
|
| 5447 |
if (ret) { |
| 5448 |
if (cb_done && !cb_done(ep, tsp, p)) { |
| 5449 |
(*pos)++; |
| 5450 |
sctp_endpoint_put(ep); |
| 5451 |
sctp_transport_put(tsp); |
| 5452 |
goto again; |
| 5453 |
} |
| 5454 |
sctp_endpoint_put(ep); |
| 5455 |
sctp_transport_put(tsp); |
| 5456 |
} |
| 5457 |
|
| 5458 |
return ret; |
| 5459 |
} |
| 5460 |
EXPORT_SYMBOL_GPL(sctp_transport_traverse_process); |
| 5461 |
|
| 5462 |
/* 7.2.1 Association Status (SCTP_STATUS) |
| 5463 |
|
| 5464 |
* Applications can retrieve current status information about an |
| 5465 |
* association, including association state, peer receiver window size, |
| 5466 |
* number of unacked data chunks, and number of data chunks pending |
| 5467 |
* receipt. This information is read-only. |
| 5468 |
*/ |
| 5469 |
static int sctp_getsockopt_sctp_status(struct sock *sk, int len, |
| 5470 |
char __user *optval, |
| 5471 |
int __user *optlen) |
| 5472 |
{ |
| 5473 |
struct sctp_status status; |
| 5474 |
struct sctp_association *asoc = NULL; |
| 5475 |
struct sctp_transport *transport; |
| 5476 |
sctp_assoc_t associd; |
| 5477 |
int retval = 0; |
| 5478 |
|
| 5479 |
if (len < sizeof(status)) { |
| 5480 |
retval = -EINVAL; |
| 5481 |
goto out; |
| 5482 |
} |
| 5483 |
|
| 5484 |
len = sizeof(status); |
| 5485 |
if (copy_from_user(&status, optval, len)) { |
| 5486 |
retval = -EFAULT; |
| 5487 |
goto out; |
| 5488 |
} |
| 5489 |
|
| 5490 |
associd = status.sstat_assoc_id; |
| 5491 |
asoc = sctp_id2assoc(sk, associd); |
| 5492 |
if (!asoc) { |
| 5493 |
retval = -EINVAL; |
| 5494 |
goto out; |
| 5495 |
} |
| 5496 |
|
| 5497 |
transport = asoc->peer.primary_path; |
| 5498 |
|
| 5499 |
status.sstat_assoc_id = sctp_assoc2id(asoc); |
| 5500 |
status.sstat_state = sctp_assoc_to_state(asoc); |
| 5501 |
status.sstat_rwnd = asoc->peer.rwnd; |
| 5502 |
status.sstat_unackdata = asoc->unack_data; |
| 5503 |
|
| 5504 |
status.sstat_penddata = sctp_tsnmap_pending(&asoc->peer.tsn_map); |
| 5505 |
status.sstat_instrms = asoc->stream.incnt; |
| 5506 |
status.sstat_outstrms = asoc->stream.outcnt; |
| 5507 |
status.sstat_fragmentation_point = asoc->frag_point; |
| 5508 |
status.sstat_primary.spinfo_assoc_id = sctp_assoc2id(transport->asoc); |
| 5509 |
memcpy(&status.sstat_primary.spinfo_address, &transport->ipaddr, |
| 5510 |
transport->af_specific->sockaddr_len); |
| 5511 |
/* Map ipv4 address into v4-mapped-on-v6 address. */ |
| 5512 |
sctp_get_pf_specific(sk->sk_family)->addr_to_user(sctp_sk(sk), |
| 5513 |
(union sctp_addr *)&status.sstat_primary.spinfo_address); |
| 5514 |
status.sstat_primary.spinfo_state = transport->state; |
| 5515 |
status.sstat_primary.spinfo_cwnd = transport->cwnd; |
| 5516 |
status.sstat_primary.spinfo_srtt = transport->srtt; |
| 5517 |
status.sstat_primary.spinfo_rto = jiffies_to_msecs(transport->rto); |
| 5518 |
status.sstat_primary.spinfo_mtu = transport->pathmtu; |
| 5519 |
|
| 5520 |
if (status.sstat_primary.spinfo_state == SCTP_UNKNOWN) |
| 5521 |
status.sstat_primary.spinfo_state = SCTP_ACTIVE; |
| 5522 |
|
| 5523 |
if (put_user(len, optlen)) { |
| 5524 |
retval = -EFAULT; |
| 5525 |
goto out; |
| 5526 |
} |
| 5527 |
|
| 5528 |
pr_debug("%s: len:%d, state:%d, rwnd:%d, assoc_id:%d\n", |
| 5529 |
__func__, len, status.sstat_state, status.sstat_rwnd, |
| 5530 |
status.sstat_assoc_id); |
| 5531 |
|
| 5532 |
if (copy_to_user(optval, &status, len)) { |
| 5533 |
retval = -EFAULT; |
| 5534 |
goto out; |
| 5535 |
} |
| 5536 |
|
| 5537 |
out: |
| 5538 |
return retval; |
| 5539 |
} |
| 5540 |
|
| 5541 |
|
| 5542 |
/* 7.2.2 Peer Address Information (SCTP_GET_PEER_ADDR_INFO) |
| 5543 |
* |
| 5544 |
* Applications can retrieve information about a specific peer address |
| 5545 |
* of an association, including its reachability state, congestion |
| 5546 |
* window, and retransmission timer values. This information is |
| 5547 |
* read-only. |
| 5548 |
*/ |
| 5549 |
static int sctp_getsockopt_peer_addr_info(struct sock *sk, int len, |
| 5550 |
char __user *optval, |
| 5551 |
int __user *optlen) |
| 5552 |
{ |
| 5553 |
struct sctp_paddrinfo pinfo; |
| 5554 |
struct sctp_transport *transport; |
| 5555 |
int retval = 0; |
| 5556 |
|
| 5557 |
if (len < sizeof(pinfo)) { |
| 5558 |
retval = -EINVAL; |
| 5559 |
goto out; |
| 5560 |
} |
| 5561 |
|
| 5562 |
len = sizeof(pinfo); |
| 5563 |
if (copy_from_user(&pinfo, optval, len)) { |
| 5564 |
retval = -EFAULT; |
| 5565 |
goto out; |
| 5566 |
} |
| 5567 |
|
| 5568 |
transport = sctp_addr_id2transport(sk, &pinfo.spinfo_address, |
| 5569 |
pinfo.spinfo_assoc_id); |
| 5570 |
if (!transport) { |
| 5571 |
retval = -EINVAL; |
| 5572 |
goto out; |
| 5573 |
} |
| 5574 |
|
| 5575 |
if (transport->state == SCTP_PF && |
| 5576 |
transport->asoc->pf_expose == SCTP_PF_EXPOSE_DISABLE) { |
| 5577 |
retval = -EACCES; |
| 5578 |
goto out; |
| 5579 |
} |
| 5580 |
|
| 5581 |
pinfo.spinfo_assoc_id = sctp_assoc2id(transport->asoc); |
| 5582 |
pinfo.spinfo_state = transport->state; |
| 5583 |
pinfo.spinfo_cwnd = transport->cwnd; |
| 5584 |
pinfo.spinfo_srtt = transport->srtt; |
| 5585 |
pinfo.spinfo_rto = jiffies_to_msecs(transport->rto); |
| 5586 |
pinfo.spinfo_mtu = transport->pathmtu; |
| 5587 |
|
| 5588 |
if (pinfo.spinfo_state == SCTP_UNKNOWN) |
| 5589 |
pinfo.spinfo_state = SCTP_ACTIVE; |
| 5590 |
|
| 5591 |
if (put_user(len, optlen)) { |
| 5592 |
retval = -EFAULT; |
| 5593 |
goto out; |
| 5594 |
} |
| 5595 |
|
| 5596 |
if (copy_to_user(optval, &pinfo, len)) { |
| 5597 |
retval = -EFAULT; |
| 5598 |
goto out; |
| 5599 |
} |
| 5600 |
|
| 5601 |
out: |
| 5602 |
return retval; |
| 5603 |
} |
| 5604 |
|
| 5605 |
/* 7.1.12 Enable/Disable message fragmentation (SCTP_DISABLE_FRAGMENTS) |
| 5606 |
* |
| 5607 |
* This option is a on/off flag. If enabled no SCTP message |
| 5608 |
* fragmentation will be performed. Instead if a message being sent |
| 5609 |
* exceeds the current PMTU size, the message will NOT be sent and |
| 5610 |
* instead a error will be indicated to the user. |
| 5611 |
*/ |
| 5612 |
static int sctp_getsockopt_disable_fragments(struct sock *sk, int len, |
| 5613 |
char __user *optval, int __user *optlen) |
| 5614 |
{ |
| 5615 |
int val; |
| 5616 |
|
| 5617 |
if (len < sizeof(int)) |
| 5618 |
return -EINVAL; |
| 5619 |
|
| 5620 |
len = sizeof(int); |
| 5621 |
val = (sctp_sk(sk)->disable_fragments == 1); |
| 5622 |
if (put_user(len, optlen)) |
| 5623 |
return -EFAULT; |
| 5624 |
if (copy_to_user(optval, &val, len)) |
| 5625 |
return -EFAULT; |
| 5626 |
return 0; |
| 5627 |
} |
| 5628 |
|
| 5629 |
/* 7.1.15 Set notification and ancillary events (SCTP_EVENTS) |
| 5630 |
* |
| 5631 |
* This socket option is used to specify various notifications and |
| 5632 |
* ancillary data the user wishes to receive. |
| 5633 |
*/ |
| 5634 |
static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval, |
| 5635 |
int __user *optlen) |
| 5636 |
{ |
| 5637 |
struct sctp_event_subscribe subscribe; |
| 5638 |
__u8 *sn_type = (__u8 *)&subscribe; |
| 5639 |
int i; |
| 5640 |
|
| 5641 |
if (len == 0) |
| 5642 |
return -EINVAL; |
| 5643 |
if (len > sizeof(struct sctp_event_subscribe)) |
| 5644 |
len = sizeof(struct sctp_event_subscribe); |
| 5645 |
if (put_user(len, optlen)) |
| 5646 |
return -EFAULT; |
| 5647 |
|
| 5648 |
for (i = 0; i < len; i++) |
| 5649 |
sn_type[i] = sctp_ulpevent_type_enabled(sctp_sk(sk)->subscribe, |
| 5650 |
SCTP_SN_TYPE_BASE + i); |
| 5651 |
|
| 5652 |
if (copy_to_user(optval, &subscribe, len)) |
| 5653 |
return -EFAULT; |
| 5654 |
|
| 5655 |
return 0; |
| 5656 |
} |
| 5657 |
|
| 5658 |
/* 7.1.8 Automatic Close of associations (SCTP_AUTOCLOSE) |
| 5659 |
* |
| 5660 |
* This socket option is applicable to the UDP-style socket only. When |
| 5661 |
* set it will cause associations that are idle for more than the |
| 5662 |
* specified number of seconds to automatically close. An association |
| 5663 |
* being idle is defined an association that has NOT sent or received |
| 5664 |
* user data. The special value of '0' indicates that no automatic |
| 5665 |
* close of any associations should be performed. The option expects an |
| 5666 |
* integer defining the number of seconds of idle time before an |
| 5667 |
* association is closed. |
| 5668 |
*/ |
| 5669 |
static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen) |
| 5670 |
{ |
| 5671 |
/* Applicable to UDP-style socket only */ |
| 5672 |
if (sctp_style(sk, TCP)) |
| 5673 |
return -EOPNOTSUPP; |
| 5674 |
if (len < sizeof(int)) |
| 5675 |
return -EINVAL; |
| 5676 |
len = sizeof(int); |
| 5677 |
if (put_user(len, optlen)) |
| 5678 |
return -EFAULT; |
| 5679 |
if (put_user(sctp_sk(sk)->autoclose, (int __user *)optval)) |
| 5680 |
return -EFAULT; |
| 5681 |
return 0; |
| 5682 |
} |
| 5683 |
|
| 5684 |
/* Helper routine to branch off an association to a new socket. */ |
| 5685 |
static int sctp_do_peeloff(struct sock *sk, sctp_assoc_t id, |
| 5686 |
struct socket **sockp) |
| 5687 |
{ |
| 5688 |
struct sctp_association *asoc = sctp_id2assoc(sk, id); |
| 5689 |
struct socket *sock; |
| 5690 |
struct sock *newsk; |
| 5691 |
int err = 0; |
| 5692 |
|
| 5693 |
/* Do not peel off from one netns to another one. */ |
| 5694 |
if (!net_eq(current->nsproxy->net_ns, sock_net(sk))) |
| 5695 |
return -EINVAL; |
| 5696 |
|
| 5697 |
if (!asoc) |
| 5698 |
return -EINVAL; |
| 5699 |
|
| 5700 |
/* An association cannot be branched off from an already peeled-off |
| 5701 |
* socket, nor is this supported for tcp style sockets. |
| 5702 |
*/ |
| 5703 |
if (!sctp_style(sk, UDP)) |
| 5704 |
return -EINVAL; |
| 5705 |
|
| 5706 |
err = sock_create_lite(sk->sk_family, SOCK_SEQPACKET, IPPROTO_SCTP, &sock); |
| 5707 |
if (err) |
| 5708 |
return err; |
| 5709 |
|
| 5710 |
newsk = sctp_clone_sock(sk, asoc, SCTP_SOCKET_UDP_HIGH_BANDWIDTH); |
| 5711 |
if (IS_ERR(newsk)) { |
| 5712 |
sock_release(sock); |
| 5713 |
*sockp = NULL; |
| 5714 |
return PTR_ERR(newsk); |
| 5715 |
} |
| 5716 |
|
| 5717 |
lock_sock_nested(newsk, SINGLE_DEPTH_NESTING); |
| 5718 |
__inet_accept(sk->sk_socket, sock, newsk); |
| 5719 |
release_sock(newsk); |
| 5720 |
|
| 5721 |
sock->ops = sk->sk_socket->ops; |
| 5722 |
__module_get(sock->ops->owner); |
| 5723 |
|
| 5724 |
*sockp = sock; |
| 5725 |
|
| 5726 |
return err; |
| 5727 |
} |
| 5728 |
|
| 5729 |
static int sctp_getsockopt_peeloff_common(struct sock *sk, sctp_peeloff_arg_t *peeloff, |
| 5730 |
struct file **newfile, unsigned flags) |
| 5731 |
{ |
| 5732 |
struct socket *newsock; |
| 5733 |
int retval; |
| 5734 |
|
| 5735 |
retval = sctp_do_peeloff(sk, peeloff->associd, &newsock); |
| 5736 |
if (retval < 0) |
| 5737 |
goto out; |
| 5738 |
|
| 5739 |
/* Map the socket to an unused fd that can be returned to the user. */ |
| 5740 |
retval = get_unused_fd_flags(flags & SOCK_CLOEXEC); |
| 5741 |
if (retval < 0) { |
| 5742 |
sock_release(newsock); |
| 5743 |
goto out; |
| 5744 |
} |
| 5745 |
|
| 5746 |
*newfile = sock_alloc_file(newsock, 0, NULL); |
| 5747 |
if (IS_ERR(*newfile)) { |
| 5748 |
put_unused_fd(retval); |
| 5749 |
retval = PTR_ERR(*newfile); |
| 5750 |
*newfile = NULL; |
| 5751 |
return retval; |
| 5752 |
} |
| 5753 |
|
| 5754 |
pr_debug("%s: sk:%p, newsk:%p, sd:%d\n", __func__, sk, newsock->sk, |
| 5755 |
retval); |
| 5756 |
|
| 5757 |
peeloff->sd = retval; |
| 5758 |
|
| 5759 |
if (flags & SOCK_NONBLOCK) |
| 5760 |
(*newfile)->f_flags |= O_NONBLOCK; |
| 5761 |
out: |
| 5762 |
return retval; |
| 5763 |
} |
| 5764 |
|
| 5765 |
static int sctp_getsockopt_peeloff(struct sock *sk, int len, char __user *optval, int __user *optlen) |
| 5766 |
{ |
| 5767 |
sctp_peeloff_arg_t peeloff; |
| 5768 |
struct file *newfile = NULL; |
| 5769 |
int retval = 0; |
| 5770 |
|
| 5771 |
if (len < sizeof(sctp_peeloff_arg_t)) |
| 5772 |
return -EINVAL; |
| 5773 |
len = sizeof(sctp_peeloff_arg_t); |
| 5774 |
if (copy_from_user(&peeloff, optval, len)) |
| 5775 |
return -EFAULT; |
| 5776 |
|
| 5777 |
retval = sctp_getsockopt_peeloff_common(sk, &peeloff, &newfile, 0); |
| 5778 |
if (retval < 0) |
| 5779 |
goto out; |
| 5780 |
|
| 5781 |
/* Return the fd mapped to the new socket. */ |
| 5782 |
if (put_user(len, optlen)) { |
| 5783 |
fput(newfile); |
| 5784 |
put_unused_fd(retval); |
| 5785 |
return -EFAULT; |
| 5786 |
} |
| 5787 |
|
| 5788 |
if (copy_to_user(optval, &peeloff, len)) { |
| 5789 |
fput(newfile); |
| 5790 |
put_unused_fd(retval); |
| 5791 |
return -EFAULT; |
| 5792 |
} |
| 5793 |
fd_install(retval, newfile); |
| 5794 |
out: |
| 5795 |
return retval; |
| 5796 |
} |
| 5797 |
|
| 5798 |
static int sctp_getsockopt_peeloff_flags(struct sock *sk, int len, |
| 5799 |
char __user *optval, int __user *optlen) |
| 5800 |
{ |
| 5801 |
sctp_peeloff_flags_arg_t peeloff; |
| 5802 |
struct file *newfile = NULL; |
| 5803 |
int retval = 0; |
| 5804 |
|
| 5805 |
if (len < sizeof(sctp_peeloff_flags_arg_t)) |
| 5806 |
return -EINVAL; |
| 5807 |
len = sizeof(sctp_peeloff_flags_arg_t); |
| 5808 |
if (copy_from_user(&peeloff, optval, len)) |
| 5809 |
return -EFAULT; |
| 5810 |
|
| 5811 |
retval = sctp_getsockopt_peeloff_common(sk, &peeloff.p_arg, |
| 5812 |
&newfile, peeloff.flags); |
| 5813 |
if (retval < 0) |
| 5814 |
goto out; |
| 5815 |
|
| 5816 |
/* Return the fd mapped to the new socket. */ |
| 5817 |
if (put_user(len, optlen)) { |
| 5818 |
fput(newfile); |
| 5819 |
put_unused_fd(retval); |
| 5820 |
return -EFAULT; |
| 5821 |
} |
| 5822 |
|
| 5823 |
if (copy_to_user(optval, &peeloff, len)) { |
| 5824 |
fput(newfile); |
| 5825 |
put_unused_fd(retval); |
| 5826 |
return -EFAULT; |
| 5827 |
} |
| 5828 |
fd_install(retval, newfile); |
| 5829 |
out: |
| 5830 |
return retval; |
| 5831 |
} |
| 5832 |
|
| 5833 |
/* 7.1.13 Peer Address Parameters (SCTP_PEER_ADDR_PARAMS) |
| 5834 |
* |
| 5835 |
* Applications can enable or disable heartbeats for any peer address of |
| 5836 |
* an association, modify an address's heartbeat interval, force a |
| 5837 |
* heartbeat to be sent immediately, and adjust the address's maximum |
| 5838 |
* number of retransmissions sent before an address is considered |
| 5839 |
* unreachable. The following structure is used to access and modify an |
| 5840 |
* address's parameters: |
| 5841 |
* |
| 5842 |
* struct sctp_paddrparams { |
| 5843 |
* sctp_assoc_t spp_assoc_id; |
| 5844 |
* struct sockaddr_storage spp_address; |
| 5845 |
* uint32_t spp_hbinterval; |
| 5846 |
* uint16_t spp_pathmaxrxt; |
| 5847 |
* uint32_t spp_pathmtu; |
| 5848 |
* uint32_t spp_sackdelay; |
| 5849 |
* uint32_t spp_flags; |
| 5850 |
* }; |
| 5851 |
* |
| 5852 |
* spp_assoc_id - (one-to-many style socket) This is filled in the |
| 5853 |
* application, and identifies the association for |
| 5854 |
* this query. |
| 5855 |
* spp_address - This specifies which address is of interest. |
| 5856 |
* spp_hbinterval - This contains the value of the heartbeat interval, |
| 5857 |
* in milliseconds. If a value of zero |
| 5858 |
* is present in this field then no changes are to |
| 5859 |
* be made to this parameter. |
| 5860 |
* spp_pathmaxrxt - This contains the maximum number of |
| 5861 |
* retransmissions before this address shall be |
| 5862 |
* considered unreachable. If a value of zero |
| 5863 |
* is present in this field then no changes are to |
| 5864 |
* be made to this parameter. |
| 5865 |
* spp_pathmtu - When Path MTU discovery is disabled the value |
| 5866 |
* specified here will be the "fixed" path mtu. |
| 5867 |
* Note that if the spp_address field is empty |
| 5868 |
* then all associations on this address will |
| 5869 |
* have this fixed path mtu set upon them. |
| 5870 |
* |
| 5871 |
* spp_sackdelay - When delayed sack is enabled, this value specifies |
| 5872 |
* the number of milliseconds that sacks will be delayed |
| 5873 |
* for. This value will apply to all addresses of an |
| 5874 |
* association if the spp_address field is empty. Note |
| 5875 |
* also, that if delayed sack is enabled and this |
| 5876 |
* value is set to 0, no change is made to the last |
| 5877 |
* recorded delayed sack timer value. |
| 5878 |
* |
| 5879 |
* spp_flags - These flags are used to control various features |
| 5880 |
* on an association. The flag field may contain |
| 5881 |
* zero or more of the following options. |
| 5882 |
* |
| 5883 |
* SPP_HB_ENABLE - Enable heartbeats on the |
| 5884 |
* specified address. Note that if the address |
| 5885 |
* field is empty all addresses for the association |
| 5886 |
* have heartbeats enabled upon them. |
| 5887 |
* |
| 5888 |
* SPP_HB_DISABLE - Disable heartbeats on the |
| 5889 |
* speicifed address. Note that if the address |
| 5890 |
* field is empty all addresses for the association |
| 5891 |
* will have their heartbeats disabled. Note also |
| 5892 |
* that SPP_HB_ENABLE and SPP_HB_DISABLE are |
| 5893 |
* mutually exclusive, only one of these two should |
| 5894 |
* be specified. Enabling both fields will have |
| 5895 |
* undetermined results. |
| 5896 |
* |
| 5897 |
* SPP_HB_DEMAND - Request a user initiated heartbeat |
| 5898 |
* to be made immediately. |
| 5899 |
* |
| 5900 |
* SPP_PMTUD_ENABLE - This field will enable PMTU |
| 5901 |
* discovery upon the specified address. Note that |
| 5902 |
* if the address feild is empty then all addresses |
| 5903 |
* on the association are effected. |
| 5904 |
* |
| 5905 |
* SPP_PMTUD_DISABLE - This field will disable PMTU |
| 5906 |
* discovery upon the specified address. Note that |
| 5907 |
* if the address feild is empty then all addresses |
| 5908 |
* on the association are effected. Not also that |
| 5909 |
* SPP_PMTUD_ENABLE and SPP_PMTUD_DISABLE are mutually |
| 5910 |
* exclusive. Enabling both will have undetermined |
| 5911 |
* results. |
| 5912 |
* |
| 5913 |
* SPP_SACKDELAY_ENABLE - Setting this flag turns |
| 5914 |
* on delayed sack. The time specified in spp_sackdelay |
| 5915 |
* is used to specify the sack delay for this address. Note |
| 5916 |
* that if spp_address is empty then all addresses will |
| 5917 |
* enable delayed sack and take on the sack delay |
| 5918 |
* value specified in spp_sackdelay. |
| 5919 |
* SPP_SACKDELAY_DISABLE - Setting this flag turns |
| 5920 |
* off delayed sack. If the spp_address field is blank then |
| 5921 |
* delayed sack is disabled for the entire association. Note |
| 5922 |
* also that this field is mutually exclusive to |
| 5923 |
* SPP_SACKDELAY_ENABLE, setting both will have undefined |
| 5924 |
* results. |
| 5925 |
* |
| 5926 |
* SPP_IPV6_FLOWLABEL: Setting this flag enables the |
| 5927 |
* setting of the IPV6 flow label value. The value is |
| 5928 |
* contained in the spp_ipv6_flowlabel field. |
| 5929 |
* Upon retrieval, this flag will be set to indicate that |
| 5930 |
* the spp_ipv6_flowlabel field has a valid value returned. |
| 5931 |
* If a specific destination address is set (in the |
| 5932 |
* spp_address field), then the value returned is that of |
| 5933 |
* the address. If just an association is specified (and |
| 5934 |
* no address), then the association's default flow label |
| 5935 |
* is returned. If neither an association nor a destination |
| 5936 |
* is specified, then the socket's default flow label is |
| 5937 |
* returned. For non-IPv6 sockets, this flag will be left |
| 5938 |
* cleared. |
| 5939 |
* |
| 5940 |
* SPP_DSCP: Setting this flag enables the setting of the |
| 5941 |
* Differentiated Services Code Point (DSCP) value |
| 5942 |
* associated with either the association or a specific |
| 5943 |
* address. The value is obtained in the spp_dscp field. |
| 5944 |
* Upon retrieval, this flag will be set to indicate that |
| 5945 |
* the spp_dscp field has a valid value returned. If a |
| 5946 |
* specific destination address is set when called (in the |
| 5947 |
* spp_address field), then that specific destination |
| 5948 |
* address's DSCP value is returned. If just an association |
| 5949 |
* is specified, then the association's default DSCP is |
| 5950 |
* returned. If neither an association nor a destination is |
| 5951 |
* specified, then the socket's default DSCP is returned. |
| 5952 |
* |
| 5953 |
* spp_ipv6_flowlabel |
| 5954 |
* - This field is used in conjunction with the |
| 5955 |
* SPP_IPV6_FLOWLABEL flag and contains the IPv6 flow label. |
| 5956 |
* The 20 least significant bits are used for the flow |
| 5957 |
* label. This setting has precedence over any IPv6-layer |
| 5958 |
* setting. |
| 5959 |
* |
| 5960 |
* spp_dscp - This field is used in conjunction with the SPP_DSCP flag |
| 5961 |
* and contains the DSCP. The 6 most significant bits are |
| 5962 |
* used for the DSCP. This setting has precedence over any |
| 5963 |
* IPv4- or IPv6- layer setting. |
| 5964 |
*/ |
| 5965 |
static int sctp_getsockopt_peer_addr_params(struct sock *sk, int len, |
| 5966 |
char __user *optval, int __user *optlen) |
| 5967 |
{ |
| 5968 |
struct sctp_paddrparams params; |
| 5969 |
struct sctp_transport *trans = NULL; |
| 5970 |
struct sctp_association *asoc = NULL; |
| 5971 |
struct sctp_sock *sp = sctp_sk(sk); |
| 5972 |
|
| 5973 |
if (len >= sizeof(params)) |
| 5974 |
len = sizeof(params); |
| 5975 |
else if (len >= ALIGN(offsetof(struct sctp_paddrparams, |
| 5976 |
spp_ipv6_flowlabel), 4)) |
| 5977 |
len = ALIGN(offsetof(struct sctp_paddrparams, |
| 5978 |
spp_ipv6_flowlabel), 4); |
| 5979 |
else |
| 5980 |
return -EINVAL; |
| 5981 |
|
| 5982 |
if (copy_from_user(¶ms, optval, len)) |
| 5983 |
return -EFAULT; |
| 5984 |
|
| 5985 |
/* If an address other than INADDR_ANY is specified, and |
| 5986 |
* no transport is found, then the request is invalid. |
| 5987 |
*/ |
| 5988 |
if (!sctp_is_any(sk, (union sctp_addr *)¶ms.spp_address)) { |
| 5989 |
trans = sctp_addr_id2transport(sk, ¶ms.spp_address, |
| 5990 |
params.spp_assoc_id); |
| 5991 |
if (!trans) { |
| 5992 |
pr_debug("%s: failed no transport\n", __func__); |
| 5993 |
return -EINVAL; |
| 5994 |
} |
| 5995 |
} |
| 5996 |
|
| 5997 |
/* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the |
| 5998 |
* socket is a one to many style socket, and an association |
| 5999 |
* was not found, then the id was invalid. |
| 6000 |
*/ |
| 6001 |
asoc = sctp_id2assoc(sk, params.spp_assoc_id); |
| 6002 |
if (!asoc && params.spp_assoc_id != SCTP_FUTURE_ASSOC && |
| 6003 |
sctp_style(sk, UDP)) { |
| 6004 |
pr_debug("%s: failed no association\n", __func__); |
| 6005 |
return -EINVAL; |
| 6006 |
} |
| 6007 |
|
| 6008 |
if (trans) { |
| 6009 |
/* Fetch transport values. */ |
| 6010 |
params.spp_hbinterval = jiffies_to_msecs(trans->hbinterval); |
| 6011 |
params.spp_pathmtu = trans->pathmtu; |
| 6012 |
params.spp_pathmaxrxt = trans->pathmaxrxt; |
| 6013 |
params.spp_sackdelay = jiffies_to_msecs(trans->sackdelay); |
| 6014 |
|
| 6015 |
/*draft-11 doesn't say what to return in spp_flags*/ |
| 6016 |
params.spp_flags = trans->param_flags; |
| 6017 |
if (trans->flowlabel & SCTP_FLOWLABEL_SET_MASK) { |
| 6018 |
params.spp_ipv6_flowlabel = trans->flowlabel & |
| 6019 |
SCTP_FLOWLABEL_VAL_MASK; |
| 6020 |
params.spp_flags |= SPP_IPV6_FLOWLABEL; |
| 6021 |
} |
| 6022 |
if (trans->dscp & SCTP_DSCP_SET_MASK) { |
| 6023 |
params.spp_dscp = trans->dscp & SCTP_DSCP_VAL_MASK; |
| 6024 |
params.spp_flags |= SPP_DSCP; |
| 6025 |
} |
| 6026 |
} else if (asoc) { |
| 6027 |
/* Fetch association values. */ |
| 6028 |
params.spp_hbinterval = jiffies_to_msecs(asoc->hbinterval); |
| 6029 |
params.spp_pathmtu = asoc->pathmtu; |
| 6030 |
params.spp_pathmaxrxt = asoc->pathmaxrxt; |
| 6031 |
params.spp_sackdelay = jiffies_to_msecs(asoc->sackdelay); |
| 6032 |
|
| 6033 |
/*draft-11 doesn't say what to return in spp_flags*/ |
| 6034 |
params.spp_flags = asoc->param_flags; |
| 6035 |
if (asoc->flowlabel & SCTP_FLOWLABEL_SET_MASK) { |
| 6036 |
params.spp_ipv6_flowlabel = asoc->flowlabel & |
| 6037 |
SCTP_FLOWLABEL_VAL_MASK; |
| 6038 |
params.spp_flags |= SPP_IPV6_FLOWLABEL; |
| 6039 |
} |
| 6040 |
if (asoc->dscp & SCTP_DSCP_SET_MASK) { |
| 6041 |
params.spp_dscp = asoc->dscp & SCTP_DSCP_VAL_MASK; |
| 6042 |
params.spp_flags |= SPP_DSCP; |
| 6043 |
} |
| 6044 |
} else { |
| 6045 |
/* Fetch socket values. */ |
| 6046 |
params.spp_hbinterval = sp->hbinterval; |
| 6047 |
params.spp_pathmtu = sp->pathmtu; |
| 6048 |
params.spp_sackdelay = sp->sackdelay; |
| 6049 |
params.spp_pathmaxrxt = sp->pathmaxrxt; |
| 6050 |
|
| 6051 |
/*draft-11 doesn't say what to return in spp_flags*/ |
| 6052 |
params.spp_flags = sp->param_flags; |
| 6053 |
if (sp->flowlabel & SCTP_FLOWLABEL_SET_MASK) { |
| 6054 |
params.spp_ipv6_flowlabel = sp->flowlabel & |
| 6055 |
SCTP_FLOWLABEL_VAL_MASK; |
| 6056 |
params.spp_flags |= SPP_IPV6_FLOWLABEL; |
| 6057 |
} |
| 6058 |
if (sp->dscp & SCTP_DSCP_SET_MASK) { |
| 6059 |
params.spp_dscp = sp->dscp & SCTP_DSCP_VAL_MASK; |
| 6060 |
params.spp_flags |= SPP_DSCP; |
| 6061 |
} |
| 6062 |
} |
| 6063 |
|
| 6064 |
if (copy_to_user(optval, ¶ms, len)) |
| 6065 |
return -EFAULT; |
| 6066 |
|
| 6067 |
if (put_user(len, optlen)) |
| 6068 |
return -EFAULT; |
| 6069 |
|
| 6070 |
return 0; |
| 6071 |
} |
| 6072 |
|
| 6073 |
/* |
| 6074 |
* 7.1.23. Get or set delayed ack timer (SCTP_DELAYED_SACK) |
| 6075 |
* |
| 6076 |
* This option will effect the way delayed acks are performed. This |
| 6077 |
* option allows you to get or set the delayed ack time, in |
| 6078 |
* milliseconds. It also allows changing the delayed ack frequency. |
| 6079 |
* Changing the frequency to 1 disables the delayed sack algorithm. If |
| 6080 |
* the assoc_id is 0, then this sets or gets the endpoints default |
| 6081 |
* values. If the assoc_id field is non-zero, then the set or get |
| 6082 |
* effects the specified association for the one to many model (the |
| 6083 |
* assoc_id field is ignored by the one to one model). Note that if |
| 6084 |
* sack_delay or sack_freq are 0 when setting this option, then the |
| 6085 |
* current values will remain unchanged. |
| 6086 |
* |
| 6087 |
* struct sctp_sack_info { |
| 6088 |
* sctp_assoc_t sack_assoc_id; |
| 6089 |
* uint32_t sack_delay; |
| 6090 |
* uint32_t sack_freq; |
| 6091 |
* }; |
| 6092 |
* |
| 6093 |
* sack_assoc_id - This parameter, indicates which association the user |
| 6094 |
* is performing an action upon. Note that if this field's value is |
| 6095 |
* zero then the endpoints default value is changed (effecting future |
| 6096 |
* associations only). |
| 6097 |
* |
| 6098 |
* sack_delay - This parameter contains the number of milliseconds that |
| 6099 |
* the user is requesting the delayed ACK timer be set to. Note that |
| 6100 |
* this value is defined in the standard to be between 200 and 500 |
| 6101 |
* milliseconds. |
| 6102 |
* |
| 6103 |
* sack_freq - This parameter contains the number of packets that must |
| 6104 |
* be received before a sack is sent without waiting for the delay |
| 6105 |
* timer to expire. The default value for this is 2, setting this |
| 6106 |
* value to 1 will disable the delayed sack algorithm. |
| 6107 |
*/ |
| 6108 |
static int sctp_getsockopt_delayed_ack(struct sock *sk, int len, |
| 6109 |
char __user *optval, |
| 6110 |
int __user *optlen) |
| 6111 |
{ |
| 6112 |
struct sctp_sack_info params; |
| 6113 |
struct sctp_association *asoc = NULL; |
| 6114 |
struct sctp_sock *sp = sctp_sk(sk); |
| 6115 |
|
| 6116 |
if (len >= sizeof(struct sctp_sack_info)) { |
| 6117 |
len = sizeof(struct sctp_sack_info); |
| 6118 |
|
| 6119 |
if (copy_from_user(¶ms, optval, len)) |
| 6120 |
return -EFAULT; |
| 6121 |
} else if (len == sizeof(struct sctp_assoc_value)) { |
| 6122 |
pr_warn_ratelimited(DEPRECATED |
| 6123 |
"%s (pid %d) " |
| 6124 |
"Use of struct sctp_assoc_value in delayed_ack socket option.\n" |
| 6125 |
"Use struct sctp_sack_info instead\n", |
| 6126 |
current->comm, task_pid_nr(current)); |
| 6127 |
if (copy_from_user(¶ms, optval, len)) |
| 6128 |
return -EFAULT; |
| 6129 |
} else |
| 6130 |
return -EINVAL; |
| 6131 |
|
| 6132 |
/* Get association, if sack_assoc_id != SCTP_FUTURE_ASSOC and the |
| 6133 |
* socket is a one to many style socket, and an association |
| 6134 |
* was not found, then the id was invalid. |
| 6135 |
*/ |
| 6136 |
asoc = sctp_id2assoc(sk, params.sack_assoc_id); |
| 6137 |
if (!asoc && params.sack_assoc_id != SCTP_FUTURE_ASSOC && |
| 6138 |
sctp_style(sk, UDP)) |
| 6139 |
return -EINVAL; |
| 6140 |
|
| 6141 |
if (asoc) { |
| 6142 |
/* Fetch association values. */ |
| 6143 |
if (asoc->param_flags & SPP_SACKDELAY_ENABLE) { |
| 6144 |
params.sack_delay = jiffies_to_msecs(asoc->sackdelay); |
| 6145 |
params.sack_freq = asoc->sackfreq; |
| 6146 |
|
| 6147 |
} else { |
| 6148 |
params.sack_delay = 0; |
| 6149 |
params.sack_freq = 1; |
| 6150 |
} |
| 6151 |
} else { |
| 6152 |
/* Fetch socket values. */ |
| 6153 |
if (sp->param_flags & SPP_SACKDELAY_ENABLE) { |
| 6154 |
params.sack_delay = sp->sackdelay; |
| 6155 |
params.sack_freq = sp->sackfreq; |
| 6156 |
} else { |
| 6157 |
params.sack_delay = 0; |
| 6158 |
params.sack_freq = 1; |
| 6159 |
} |
| 6160 |
} |
| 6161 |
|
| 6162 |
if (copy_to_user(optval, ¶ms, len)) |
| 6163 |
return -EFAULT; |
| 6164 |
|
| 6165 |
if (put_user(len, optlen)) |
| 6166 |
return -EFAULT; |
| 6167 |
|
| 6168 |
return 0; |
| 6169 |
} |
| 6170 |
|
| 6171 |
/* 7.1.3 Initialization Parameters (SCTP_INITMSG) |
| 6172 |
* |
| 6173 |
* Applications can specify protocol parameters for the default association |
| 6174 |
* initialization. The option name argument to setsockopt() and getsockopt() |
| 6175 |
* is SCTP_INITMSG. |
| 6176 |
* |
| 6177 |
* Setting initialization parameters is effective only on an unconnected |
| 6178 |
* socket (for UDP-style sockets only future associations are effected |
| 6179 |
* by the change). With TCP-style sockets, this option is inherited by |
| 6180 |
* sockets derived from a listener socket. |
| 6181 |
*/ |
| 6182 |
static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen) |
| 6183 |
{ |
| 6184 |
if (len < sizeof(struct sctp_initmsg)) |
| 6185 |
return -EINVAL; |
| 6186 |
len = sizeof(struct sctp_initmsg); |
| 6187 |
if (put_user(len, optlen)) |
| 6188 |
return -EFAULT; |
| 6189 |
if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len)) |
| 6190 |
return -EFAULT; |
| 6191 |
return 0; |
| 6192 |
} |
| 6193 |
|
| 6194 |
|
| 6195 |
static int sctp_getsockopt_peer_addrs(struct sock *sk, int len, |
| 6196 |
char __user *optval, int __user *optlen) |
| 6197 |
{ |
| 6198 |
struct sctp_association *asoc; |
| 6199 |
int cnt = 0; |
| 6200 |
struct sctp_getaddrs getaddrs; |
| 6201 |
struct sctp_transport *from; |
| 6202 |
void __user *to; |
| 6203 |
union sctp_addr temp; |
| 6204 |
struct sctp_sock *sp = sctp_sk(sk); |
| 6205 |
int addrlen; |
| 6206 |
size_t space_left; |
| 6207 |
int bytes_copied; |
| 6208 |
|
| 6209 |
if (len < sizeof(struct sctp_getaddrs)) |
| 6210 |
return -EINVAL; |
| 6211 |
|
| 6212 |
if (copy_from_user(&getaddrs, optval, sizeof(struct sctp_getaddrs))) |
| 6213 |
return -EFAULT; |
| 6214 |
|
| 6215 |
/* For UDP-style sockets, id specifies the association to query. */ |
| 6216 |
asoc = sctp_id2assoc(sk, getaddrs.assoc_id); |
| 6217 |
if (!asoc) |
| 6218 |
return -EINVAL; |
| 6219 |
|
| 6220 |
to = optval + offsetof(struct sctp_getaddrs, addrs); |
| 6221 |
space_left = len - offsetof(struct sctp_getaddrs, addrs); |
| 6222 |
|
| 6223 |
list_for_each_entry(from, &asoc->peer.transport_addr_list, |
| 6224 |
transports) { |
| 6225 |
memcpy(&temp, &from->ipaddr, sizeof(temp)); |
| 6226 |
addrlen = sctp_get_pf_specific(sk->sk_family) |
| 6227 |
->addr_to_user(sp, &temp); |
| 6228 |
if (space_left < addrlen) |
| 6229 |
return -ENOMEM; |
| 6230 |
if (copy_to_user(to, &temp, addrlen)) |
| 6231 |
return -EFAULT; |
| 6232 |
to += addrlen; |
| 6233 |
cnt++; |
| 6234 |
space_left -= addrlen; |
| 6235 |
} |
| 6236 |
|
| 6237 |
if (put_user(cnt, &((struct sctp_getaddrs __user *)optval)->addr_num)) |
| 6238 |
return -EFAULT; |
| 6239 |
bytes_copied = ((char __user *)to) - optval; |
| 6240 |
if (put_user(bytes_copied, optlen)) |
| 6241 |
return -EFAULT; |
| 6242 |
|
| 6243 |
return 0; |
| 6244 |
} |
| 6245 |
|
| 6246 |
static int sctp_copy_laddrs(struct sock *sk, __u16 port, void *to, |
| 6247 |
size_t space_left, int *bytes_copied) |
| 6248 |
{ |
| 6249 |
struct sctp_sockaddr_entry *addr; |
| 6250 |
union sctp_addr temp; |
| 6251 |
int cnt = 0; |
| 6252 |
int addrlen; |
| 6253 |
struct net *net = sock_net(sk); |
| 6254 |
|
| 6255 |
rcu_read_lock(); |
| 6256 |
list_for_each_entry_rcu(addr, &net->sctp.local_addr_list, list) { |
| 6257 |
if (!addr->valid) |
| 6258 |
continue; |
| 6259 |
|
| 6260 |
if ((PF_INET == sk->sk_family) && |
| 6261 |
(AF_INET6 == addr->a.sa.sa_family)) |
| 6262 |
continue; |
| 6263 |
if ((PF_INET6 == sk->sk_family) && |
| 6264 |
inet_v6_ipv6only(sk) && |
| 6265 |
(AF_INET == addr->a.sa.sa_family)) |
| 6266 |
continue; |
| 6267 |
memcpy(&temp, &addr->a, sizeof(temp)); |
| 6268 |
if (!temp.v4.sin_port) |
| 6269 |
temp.v4.sin_port = htons(port); |
| 6270 |
|
| 6271 |
addrlen = sctp_get_pf_specific(sk->sk_family) |
| 6272 |
->addr_to_user(sctp_sk(sk), &temp); |
| 6273 |
|
| 6274 |
if (space_left < addrlen) { |
| 6275 |
cnt = -ENOMEM; |
| 6276 |
break; |
| 6277 |
} |
| 6278 |
memcpy(to, &temp, addrlen); |
| 6279 |
|
| 6280 |
to += addrlen; |
| 6281 |
cnt++; |
| 6282 |
space_left -= addrlen; |
| 6283 |
*bytes_copied += addrlen; |
| 6284 |
} |
| 6285 |
rcu_read_unlock(); |
| 6286 |
|
| 6287 |
return cnt; |
| 6288 |
} |
| 6289 |
|
| 6290 |
|
| 6291 |
static int sctp_getsockopt_local_addrs(struct sock *sk, int len, |
| 6292 |
char __user *optval, int __user *optlen) |
| 6293 |
{ |
| 6294 |
struct sctp_bind_addr *bp; |
| 6295 |
struct sctp_association *asoc; |
| 6296 |
int cnt = 0; |
| 6297 |
struct sctp_getaddrs getaddrs; |
| 6298 |
struct sctp_sockaddr_entry *addr; |
| 6299 |
void __user *to; |
| 6300 |
union sctp_addr temp; |
| 6301 |
struct sctp_sock *sp = sctp_sk(sk); |
| 6302 |
int addrlen; |
| 6303 |
int err = 0; |
| 6304 |
size_t space_left; |
| 6305 |
int bytes_copied = 0; |
| 6306 |
void *addrs; |
| 6307 |
void *buf; |
| 6308 |
|
| 6309 |
if (len < sizeof(struct sctp_getaddrs)) |
| 6310 |
return -EINVAL; |
| 6311 |
|
| 6312 |
if (copy_from_user(&getaddrs, optval, sizeof(struct sctp_getaddrs))) |
| 6313 |
return -EFAULT; |
| 6314 |
|
| 6315 |
/* |
| 6316 |
* For UDP-style sockets, id specifies the association to query. |
| 6317 |
* If the id field is set to the value '0' then the locally bound |
| 6318 |
* addresses are returned without regard to any particular |
| 6319 |
* association. |
| 6320 |
*/ |
| 6321 |
if (0 == getaddrs.assoc_id) { |
| 6322 |
bp = &sctp_sk(sk)->ep->base.bind_addr; |
| 6323 |
} else { |
| 6324 |
asoc = sctp_id2assoc(sk, getaddrs.assoc_id); |
| 6325 |
if (!asoc) |
| 6326 |
return -EINVAL; |
| 6327 |
bp = &asoc->base.bind_addr; |
| 6328 |
} |
| 6329 |
|
| 6330 |
to = optval + offsetof(struct sctp_getaddrs, addrs); |
| 6331 |
space_left = len - offsetof(struct sctp_getaddrs, addrs); |
| 6332 |
|
| 6333 |
addrs = kmalloc(space_left, GFP_USER | __GFP_NOWARN); |
| 6334 |
if (!addrs) |
| 6335 |
return -ENOMEM; |
| 6336 |
|
| 6337 |
/* If the endpoint is bound to 0.0.0.0 or ::0, get the valid |
| 6338 |
* addresses from the global local address list. |
| 6339 |
*/ |
| 6340 |
if (sctp_list_single_entry(&bp->address_list)) { |
| 6341 |
addr = list_entry(bp->address_list.next, |
| 6342 |
struct sctp_sockaddr_entry, list); |
| 6343 |
if (sctp_is_any(sk, &addr->a)) { |
| 6344 |
cnt = sctp_copy_laddrs(sk, bp->port, addrs, |
| 6345 |
space_left, &bytes_copied); |
| 6346 |
if (cnt < 0) { |
| 6347 |
err = cnt; |
| 6348 |
goto out; |
| 6349 |
} |
| 6350 |
goto copy_getaddrs; |
| 6351 |
} |
| 6352 |
} |
| 6353 |
|
| 6354 |
buf = addrs; |
| 6355 |
/* Protection on the bound address list is not needed since |
| 6356 |
* in the socket option context we hold a socket lock and |
| 6357 |
* thus the bound address list can't change. |
| 6358 |
*/ |
| 6359 |
list_for_each_entry(addr, &bp->address_list, list) { |
| 6360 |
memcpy(&temp, &addr->a, sizeof(temp)); |
| 6361 |
addrlen = sctp_get_pf_specific(sk->sk_family) |
| 6362 |
->addr_to_user(sp, &temp); |
| 6363 |
if (space_left < addrlen) { |
| 6364 |
err = -ENOMEM; /*fixme: right error?*/ |
| 6365 |
goto out; |
| 6366 |
} |
| 6367 |
memcpy(buf, &temp, addrlen); |
| 6368 |
buf += addrlen; |
| 6369 |
bytes_copied += addrlen; |
| 6370 |
cnt++; |
| 6371 |
space_left -= addrlen; |
| 6372 |
} |
| 6373 |
|
| 6374 |
copy_getaddrs: |
| 6375 |
if (copy_to_user(to, addrs, bytes_copied)) { |
| 6376 |
err = -EFAULT; |
| 6377 |
goto out; |
| 6378 |
} |
| 6379 |
if (put_user(cnt, &((struct sctp_getaddrs __user *)optval)->addr_num)) { |
| 6380 |
err = -EFAULT; |
| 6381 |
goto out; |
| 6382 |
} |
| 6383 |
/* XXX: We should have accounted for sizeof(struct sctp_getaddrs) too, |
| 6384 |
* but we can't change it anymore. |
| 6385 |
*/ |
| 6386 |
if (put_user(bytes_copied, optlen)) |
| 6387 |
err = -EFAULT; |
| 6388 |
out: |
| 6389 |
kfree(addrs); |
| 6390 |
return err; |
| 6391 |
} |
| 6392 |
|
| 6393 |
/* 7.1.10 Set Primary Address (SCTP_PRIMARY_ADDR) |
| 6394 |
* |
| 6395 |
* Requests that the local SCTP stack use the enclosed peer address as |
| 6396 |
* the association primary. The enclosed address must be one of the |
| 6397 |
* association peer's addresses. |
| 6398 |
*/ |
| 6399 |
static int sctp_getsockopt_primary_addr(struct sock *sk, int len, |
| 6400 |
char __user *optval, int __user *optlen) |
| 6401 |
{ |
| 6402 |
struct sctp_prim prim; |
| 6403 |
struct sctp_association *asoc; |
| 6404 |
struct sctp_sock *sp = sctp_sk(sk); |
| 6405 |
|
| 6406 |
if (len < sizeof(struct sctp_prim)) |
| 6407 |
return -EINVAL; |
| 6408 |
|
| 6409 |
len = sizeof(struct sctp_prim); |
| 6410 |
|
| 6411 |
if (copy_from_user(&prim, optval, len)) |
| 6412 |
return -EFAULT; |
| 6413 |
|
| 6414 |
asoc = sctp_id2assoc(sk, prim.ssp_assoc_id); |
| 6415 |
if (!asoc) |
| 6416 |
return -EINVAL; |
| 6417 |
|
| 6418 |
if (!asoc->peer.primary_path) |
| 6419 |
return -ENOTCONN; |
| 6420 |
|
| 6421 |
memcpy(&prim.ssp_addr, &asoc->peer.primary_path->ipaddr, |
| 6422 |
asoc->peer.primary_path->af_specific->sockaddr_len); |
| 6423 |
|
| 6424 |
sctp_get_pf_specific(sk->sk_family)->addr_to_user(sp, |
| 6425 |
(union sctp_addr *)&prim.ssp_addr); |
| 6426 |
|
| 6427 |
if (put_user(len, optlen)) |
| 6428 |
return -EFAULT; |
| 6429 |
if (copy_to_user(optval, &prim, len)) |
| 6430 |
return -EFAULT; |
| 6431 |
|
| 6432 |
return 0; |
| 6433 |
} |
| 6434 |
|
| 6435 |
/* |
| 6436 |
* 7.1.11 Set Adaptation Layer Indicator (SCTP_ADAPTATION_LAYER) |
| 6437 |
* |
| 6438 |
* Requests that the local endpoint set the specified Adaptation Layer |
| 6439 |
* Indication parameter for all future INIT and INIT-ACK exchanges. |
| 6440 |
*/ |
| 6441 |
static int sctp_getsockopt_adaptation_layer(struct sock *sk, int len, |
| 6442 |
char __user *optval, int __user *optlen) |
| 6443 |
{ |
| 6444 |
struct sctp_setadaptation adaptation; |
| 6445 |
|
| 6446 |
if (len < sizeof(struct sctp_setadaptation)) |
| 6447 |
return -EINVAL; |
| 6448 |
|
| 6449 |
len = sizeof(struct sctp_setadaptation); |
| 6450 |
|
| 6451 |
adaptation.ssb_adaptation_ind = sctp_sk(sk)->adaptation_ind; |
| 6452 |
|
| 6453 |
if (put_user(len, optlen)) |
| 6454 |
return -EFAULT; |
| 6455 |
if (copy_to_user(optval, &adaptation, len)) |
| 6456 |
return -EFAULT; |
| 6457 |
|
| 6458 |
return 0; |
| 6459 |
} |
| 6460 |
|
| 6461 |
/* |
| 6462 |
* |
| 6463 |
* 7.1.14 Set default send parameters (SCTP_DEFAULT_SEND_PARAM) |
| 6464 |
* |
| 6465 |
* Applications that wish to use the sendto() system call may wish to |
| 6466 |
* specify a default set of parameters that would normally be supplied |
| 6467 |
* through the inclusion of ancillary data. This socket option allows |
| 6468 |
* such an application to set the default sctp_sndrcvinfo structure. |
| 6469 |
|
| 6470 |
|
| 6471 |
* The application that wishes to use this socket option simply passes |
| 6472 |
* in to this call the sctp_sndrcvinfo structure defined in Section |
| 6473 |
* 5.2.2) The input parameters accepted by this call include |
| 6474 |
* sinfo_stream, sinfo_flags, sinfo_ppid, sinfo_context, |
| 6475 |
* sinfo_timetolive. The user must provide the sinfo_assoc_id field in |
| 6476 |
* to this call if the caller is using the UDP model. |
| 6477 |
* |
| 6478 |
* For getsockopt, it get the default sctp_sndrcvinfo structure. |
| 6479 |
*/ |
| 6480 |
static int sctp_getsockopt_default_send_param(struct sock *sk, |
| 6481 |
int len, char __user *optval, |
| 6482 |
int __user *optlen) |
| 6483 |
{ |
| 6484 |
struct sctp_sock *sp = sctp_sk(sk); |
| 6485 |
struct sctp_association *asoc; |
| 6486 |
struct sctp_sndrcvinfo info; |
| 6487 |
|
| 6488 |
if (len < sizeof(info)) |
| 6489 |
return -EINVAL; |
| 6490 |
|
| 6491 |
len = sizeof(info); |
| 6492 |
|
| 6493 |
if (copy_from_user(&info, optval, len)) |
| 6494 |
return -EFAULT; |
| 6495 |
|
| 6496 |
asoc = sctp_id2assoc(sk, info.sinfo_assoc_id); |
| 6497 |
if (!asoc && info.sinfo_assoc_id != SCTP_FUTURE_ASSOC && |
| 6498 |
sctp_style(sk, UDP)) |
| 6499 |
return -EINVAL; |
| 6500 |
|
| 6501 |
if (asoc) { |
| 6502 |
info.sinfo_stream = asoc->default_stream; |
| 6503 |
info.sinfo_flags = asoc->default_flags; |
| 6504 |
info.sinfo_ppid = asoc->default_ppid; |
| 6505 |
info.sinfo_context = asoc->default_context; |
| 6506 |
info.sinfo_timetolive = asoc->default_timetolive; |
| 6507 |
} else { |
| 6508 |
info.sinfo_stream = sp->default_stream; |
| 6509 |
info.sinfo_flags = sp->default_flags; |
| 6510 |
info.sinfo_ppid = sp->default_ppid; |
| 6511 |
info.sinfo_context = sp->default_context; |
| 6512 |
info.sinfo_timetolive = sp->default_timetolive; |
| 6513 |
} |
| 6514 |
|
| 6515 |
if (put_user(len, optlen)) |
| 6516 |
return -EFAULT; |
| 6517 |
if (copy_to_user(optval, &info, len)) |
| 6518 |
return -EFAULT; |
| 6519 |
|
| 6520 |
return 0; |
| 6521 |
} |
| 6522 |
|
| 6523 |
/* RFC6458, Section 8.1.31. Set/get Default Send Parameters |
| 6524 |
* (SCTP_DEFAULT_SNDINFO) |
| 6525 |
*/ |
| 6526 |
static int sctp_getsockopt_default_sndinfo(struct sock *sk, int len, |
| 6527 |
char __user *optval, |
| 6528 |
int __user *optlen) |
| 6529 |
{ |
| 6530 |
struct sctp_sock *sp = sctp_sk(sk); |
| 6531 |
struct sctp_association *asoc; |
| 6532 |
struct sctp_sndinfo info; |
| 6533 |
|
| 6534 |
if (len < sizeof(info)) |
| 6535 |
return -EINVAL; |
| 6536 |
|
| 6537 |
len = sizeof(info); |
| 6538 |
|
| 6539 |
if (copy_from_user(&info, optval, len)) |
| 6540 |
return -EFAULT; |
| 6541 |
|
| 6542 |
asoc = sctp_id2assoc(sk, info.snd_assoc_id); |
| 6543 |
if (!asoc && info.snd_assoc_id != SCTP_FUTURE_ASSOC && |
| 6544 |
sctp_style(sk, UDP)) |
| 6545 |
return -EINVAL; |
| 6546 |
|
| 6547 |
if (asoc) { |
| 6548 |
info.snd_sid = asoc->default_stream; |
| 6549 |
info.snd_flags = asoc->default_flags; |
| 6550 |
info.snd_ppid = asoc->default_ppid; |
| 6551 |
info.snd_context = asoc->default_context; |
| 6552 |
} else { |
| 6553 |
info.snd_sid = sp->default_stream; |
| 6554 |
info.snd_flags = sp->default_flags; |
| 6555 |
info.snd_ppid = sp->default_ppid; |
| 6556 |
info.snd_context = sp->default_context; |
| 6557 |
} |
| 6558 |
|
| 6559 |
if (put_user(len, optlen)) |
| 6560 |
return -EFAULT; |
| 6561 |
if (copy_to_user(optval, &info, len)) |
| 6562 |
return -EFAULT; |
| 6563 |
|
| 6564 |
return 0; |
| 6565 |
} |
| 6566 |
|
| 6567 |
/* |
| 6568 |
* |
| 6569 |
* 7.1.5 SCTP_NODELAY |
| 6570 |
* |
| 6571 |
* Turn on/off any Nagle-like algorithm. This means that packets are |
| 6572 |
* generally sent as soon as possible and no unnecessary delays are |
| 6573 |
* introduced, at the cost of more packets in the network. Expects an |
| 6574 |
* integer boolean flag. |
| 6575 |
*/ |
| 6576 |
|
| 6577 |
static int sctp_getsockopt_nodelay(struct sock *sk, int len, |
| 6578 |
char __user *optval, int __user *optlen) |
| 6579 |
{ |
| 6580 |
int val; |
| 6581 |
|
| 6582 |
if (len < sizeof(int)) |
| 6583 |
return -EINVAL; |
| 6584 |
|
| 6585 |
len = sizeof(int); |
| 6586 |
val = (sctp_sk(sk)->nodelay == 1); |
| 6587 |
if (put_user(len, optlen)) |
| 6588 |
return -EFAULT; |
| 6589 |
if (copy_to_user(optval, &val, len)) |
| 6590 |
return -EFAULT; |
| 6591 |
return 0; |
| 6592 |
} |
| 6593 |
|
| 6594 |
/* |
| 6595 |
* |
| 6596 |
* 7.1.1 SCTP_RTOINFO |
| 6597 |
* |
| 6598 |
* The protocol parameters used to initialize and bound retransmission |
| 6599 |
* timeout (RTO) are tunable. sctp_rtoinfo structure is used to access |
| 6600 |
* and modify these parameters. |
| 6601 |
* All parameters are time values, in milliseconds. A value of 0, when |
| 6602 |
* modifying the parameters, indicates that the current value should not |
| 6603 |
* be changed. |
| 6604 |
* |
| 6605 |
*/ |
| 6606 |
static int sctp_getsockopt_rtoinfo(struct sock *sk, int len, |
| 6607 |
char __user *optval, |
| 6608 |
int __user *optlen) { |
| 6609 |
struct sctp_rtoinfo rtoinfo; |
| 6610 |
struct sctp_association *asoc; |
| 6611 |
|
| 6612 |
if (len < sizeof (struct sctp_rtoinfo)) |
| 6613 |
return -EINVAL; |
| 6614 |
|
| 6615 |
len = sizeof(struct sctp_rtoinfo); |
| 6616 |
|
| 6617 |
if (copy_from_user(&rtoinfo, optval, len)) |
| 6618 |
return -EFAULT; |
| 6619 |
|
| 6620 |
asoc = sctp_id2assoc(sk, rtoinfo.srto_assoc_id); |
| 6621 |
|
| 6622 |
if (!asoc && rtoinfo.srto_assoc_id != SCTP_FUTURE_ASSOC && |
| 6623 |
sctp_style(sk, UDP)) |
| 6624 |
return -EINVAL; |
| 6625 |
|
| 6626 |
/* Values corresponding to the specific association. */ |
| 6627 |
if (asoc) { |
| 6628 |
rtoinfo.srto_initial = jiffies_to_msecs(asoc->rto_initial); |
| 6629 |
rtoinfo.srto_max = jiffies_to_msecs(asoc->rto_max); |
| 6630 |
rtoinfo.srto_min = jiffies_to_msecs(asoc->rto_min); |
| 6631 |
} else { |
| 6632 |
/* Values corresponding to the endpoint. */ |
| 6633 |
struct sctp_sock *sp = sctp_sk(sk); |
| 6634 |
|
| 6635 |
rtoinfo.srto_initial = sp->rtoinfo.srto_initial; |
| 6636 |
rtoinfo.srto_max = sp->rtoinfo.srto_max; |
| 6637 |
rtoinfo.srto_min = sp->rtoinfo.srto_min; |
| 6638 |
} |
| 6639 |
|
| 6640 |
if (put_user(len, optlen)) |
| 6641 |
return -EFAULT; |
| 6642 |
|
| 6643 |
if (copy_to_user(optval, &rtoinfo, len)) |
| 6644 |
return -EFAULT; |
| 6645 |
|
| 6646 |
return 0; |
| 6647 |
} |
| 6648 |
|
| 6649 |
/* |
| 6650 |
* |
| 6651 |
* 7.1.2 SCTP_ASSOCINFO |
| 6652 |
* |
| 6653 |
* This option is used to tune the maximum retransmission attempts |
| 6654 |
* of the association. |
| 6655 |
* Returns an error if the new association retransmission value is |
| 6656 |
* greater than the sum of the retransmission value of the peer. |
| 6657 |
* See [SCTP] for more information. |
| 6658 |
* |
| 6659 |
*/ |
| 6660 |
static int sctp_getsockopt_associnfo(struct sock *sk, int len, |
| 6661 |
char __user *optval, |
| 6662 |
int __user *optlen) |
| 6663 |
{ |
| 6664 |
|
| 6665 |
struct sctp_assocparams assocparams; |
| 6666 |
struct sctp_association *asoc; |
| 6667 |
struct list_head *pos; |
| 6668 |
int cnt = 0; |
| 6669 |
|
| 6670 |
if (len < sizeof (struct sctp_assocparams)) |
| 6671 |
return -EINVAL; |
| 6672 |
|
| 6673 |
len = sizeof(struct sctp_assocparams); |
| 6674 |
|
| 6675 |
if (copy_from_user(&assocparams, optval, len)) |
| 6676 |
return -EFAULT; |
| 6677 |
|
| 6678 |
asoc = sctp_id2assoc(sk, assocparams.sasoc_assoc_id); |
| 6679 |
|
| 6680 |
if (!asoc && assocparams.sasoc_assoc_id != SCTP_FUTURE_ASSOC && |
| 6681 |
sctp_style(sk, UDP)) |
| 6682 |
return -EINVAL; |
| 6683 |
|
| 6684 |
/* Values correspoinding to the specific association */ |
| 6685 |
if (asoc) { |
| 6686 |
assocparams.sasoc_asocmaxrxt = asoc->max_retrans; |
| 6687 |
assocparams.sasoc_peer_rwnd = asoc->peer.rwnd; |
| 6688 |
assocparams.sasoc_local_rwnd = asoc->a_rwnd; |
| 6689 |
assocparams.sasoc_cookie_life = ktime_to_ms(asoc->cookie_life); |
| 6690 |
|
| 6691 |
list_for_each(pos, &asoc->peer.transport_addr_list) { |
| 6692 |
cnt++; |
| 6693 |
} |
| 6694 |
|
| 6695 |
assocparams.sasoc_number_peer_destinations = cnt; |
| 6696 |
} else { |
| 6697 |
/* Values corresponding to the endpoint */ |
| 6698 |
struct sctp_sock *sp = sctp_sk(sk); |
| 6699 |
|
| 6700 |
assocparams.sasoc_asocmaxrxt = sp->assocparams.sasoc_asocmaxrxt; |
| 6701 |
assocparams.sasoc_peer_rwnd = sp->assocparams.sasoc_peer_rwnd; |
| 6702 |
assocparams.sasoc_local_rwnd = sp->assocparams.sasoc_local_rwnd; |
| 6703 |
assocparams.sasoc_cookie_life = |
| 6704 |
sp->assocparams.sasoc_cookie_life; |
| 6705 |
assocparams.sasoc_number_peer_destinations = |
| 6706 |
sp->assocparams. |
| 6707 |
sasoc_number_peer_destinations; |
| 6708 |
} |
| 6709 |
|
| 6710 |
if (put_user(len, optlen)) |
| 6711 |
return -EFAULT; |
| 6712 |
|
| 6713 |
if (copy_to_user(optval, &assocparams, len)) |
| 6714 |
return -EFAULT; |
| 6715 |
|
| 6716 |
return 0; |
| 6717 |
} |
| 6718 |
|
| 6719 |
/* |
| 6720 |
* 7.1.16 Set/clear IPv4 mapped addresses (SCTP_I_WANT_MAPPED_V4_ADDR) |
| 6721 |
* |
| 6722 |
* This socket option is a boolean flag which turns on or off mapped V4 |
| 6723 |
* addresses. If this option is turned on and the socket is type |
| 6724 |
* PF_INET6, then IPv4 addresses will be mapped to V6 representation. |
| 6725 |
* If this option is turned off, then no mapping will be done of V4 |
| 6726 |
* addresses and a user will receive both PF_INET6 and PF_INET type |
| 6727 |
* addresses on the socket. |
| 6728 |
*/ |
| 6729 |
static int sctp_getsockopt_mappedv4(struct sock *sk, int len, |
| 6730 |
char __user *optval, int __user *optlen) |
| 6731 |
{ |
| 6732 |
int val; |
| 6733 |
struct sctp_sock *sp = sctp_sk(sk); |
| 6734 |
|
| 6735 |
if (len < sizeof(int)) |
| 6736 |
return -EINVAL; |
| 6737 |
|
| 6738 |
len = sizeof(int); |
| 6739 |
val = sp->v4mapped; |
| 6740 |
if (put_user(len, optlen)) |
| 6741 |
return -EFAULT; |
| 6742 |
if (copy_to_user(optval, &val, len)) |
| 6743 |
return -EFAULT; |
| 6744 |
|
| 6745 |
return 0; |
| 6746 |
} |
| 6747 |
|
| 6748 |
/* |
| 6749 |
* 7.1.29. Set or Get the default context (SCTP_CONTEXT) |
| 6750 |
* (chapter and verse is quoted at sctp_setsockopt_context()) |
| 6751 |
*/ |
| 6752 |
static int sctp_getsockopt_context(struct sock *sk, int len, |
| 6753 |
char __user *optval, int __user *optlen) |
| 6754 |
{ |
| 6755 |
struct sctp_assoc_value params; |
| 6756 |
struct sctp_association *asoc; |
| 6757 |
|
| 6758 |
if (len < sizeof(struct sctp_assoc_value)) |
| 6759 |
return -EINVAL; |
| 6760 |
|
| 6761 |
len = sizeof(struct sctp_assoc_value); |
| 6762 |
|
| 6763 |
if (copy_from_user(¶ms, optval, len)) |
| 6764 |
return -EFAULT; |
| 6765 |
|
| 6766 |
asoc = sctp_id2assoc(sk, params.assoc_id); |
| 6767 |
if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC && |
| 6768 |
sctp_style(sk, UDP)) |
| 6769 |
return -EINVAL; |
| 6770 |
|
| 6771 |
params.assoc_value = asoc ? asoc->default_rcv_context |
| 6772 |
: sctp_sk(sk)->default_rcv_context; |
| 6773 |
|
| 6774 |
if (put_user(len, optlen)) |
| 6775 |
return -EFAULT; |
| 6776 |
if (copy_to_user(optval, ¶ms, len)) |
| 6777 |
return -EFAULT; |
| 6778 |
|
| 6779 |
return 0; |
| 6780 |
} |
| 6781 |
|
| 6782 |
/* |
| 6783 |
* 8.1.16. Get or Set the Maximum Fragmentation Size (SCTP_MAXSEG) |
| 6784 |
* This option will get or set the maximum size to put in any outgoing |
| 6785 |
* SCTP DATA chunk. If a message is larger than this size it will be |
| 6786 |
* fragmented by SCTP into the specified size. Note that the underlying |
| 6787 |
* SCTP implementation may fragment into smaller sized chunks when the |
| 6788 |
* PMTU of the underlying association is smaller than the value set by |
| 6789 |
* the user. The default value for this option is '0' which indicates |
| 6790 |
* the user is NOT limiting fragmentation and only the PMTU will effect |
| 6791 |
* SCTP's choice of DATA chunk size. Note also that values set larger |
| 6792 |
* than the maximum size of an IP datagram will effectively let SCTP |
| 6793 |
* control fragmentation (i.e. the same as setting this option to 0). |
| 6794 |
* |
| 6795 |
* The following structure is used to access and modify this parameter: |
| 6796 |
* |
| 6797 |
* struct sctp_assoc_value { |
| 6798 |
* sctp_assoc_t assoc_id; |
| 6799 |
* uint32_t assoc_value; |
| 6800 |
* }; |
| 6801 |
* |
| 6802 |
* assoc_id: This parameter is ignored for one-to-one style sockets. |
| 6803 |
* For one-to-many style sockets this parameter indicates which |
| 6804 |
* association the user is performing an action upon. Note that if |
| 6805 |
* this field's value is zero then the endpoints default value is |
| 6806 |
* changed (effecting future associations only). |
| 6807 |
* assoc_value: This parameter specifies the maximum size in bytes. |
| 6808 |
*/ |
| 6809 |
static int sctp_getsockopt_maxseg(struct sock *sk, int len, |
| 6810 |
char __user *optval, int __user *optlen) |
| 6811 |
{ |
| 6812 |
struct sctp_assoc_value params; |
| 6813 |
struct sctp_association *asoc; |
| 6814 |
|
| 6815 |
if (len == sizeof(int)) { |
| 6816 |
pr_warn_ratelimited(DEPRECATED |
| 6817 |
"%s (pid %d) " |
| 6818 |
"Use of int in maxseg socket option.\n" |
| 6819 |
"Use struct sctp_assoc_value instead\n", |
| 6820 |
current->comm, task_pid_nr(current)); |
| 6821 |
params.assoc_id = SCTP_FUTURE_ASSOC; |
| 6822 |
} else if (len >= sizeof(struct sctp_assoc_value)) { |
| 6823 |
len = sizeof(struct sctp_assoc_value); |
| 6824 |
if (copy_from_user(¶ms, optval, len)) |
| 6825 |
return -EFAULT; |
| 6826 |
} else |
| 6827 |
return -EINVAL; |
| 6828 |
|
| 6829 |
asoc = sctp_id2assoc(sk, params.assoc_id); |
| 6830 |
if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC && |
| 6831 |
sctp_style(sk, UDP)) |
| 6832 |
return -EINVAL; |
| 6833 |
|
| 6834 |
if (asoc) |
| 6835 |
params.assoc_value = asoc->frag_point; |
| 6836 |
else |
| 6837 |
params.assoc_value = sctp_sk(sk)->user_frag; |
| 6838 |
|
| 6839 |
if (put_user(len, optlen)) |
| 6840 |
return -EFAULT; |
| 6841 |
if (len == sizeof(int)) { |
| 6842 |
if (copy_to_user(optval, ¶ms.assoc_value, len)) |
| 6843 |
return -EFAULT; |
| 6844 |
} else { |
| 6845 |
if (copy_to_user(optval, ¶ms, len)) |
| 6846 |
return -EFAULT; |
| 6847 |
} |
| 6848 |
|
| 6849 |
return 0; |
| 6850 |
} |
| 6851 |
|
| 6852 |
/* |
| 6853 |
* 7.1.24. Get or set fragmented interleave (SCTP_FRAGMENT_INTERLEAVE) |
| 6854 |
* (chapter and verse is quoted at sctp_setsockopt_fragment_interleave()) |
| 6855 |
*/ |
| 6856 |
static int sctp_getsockopt_fragment_interleave(struct sock *sk, int len, |
| 6857 |
char __user *optval, int __user *optlen) |
| 6858 |
{ |
| 6859 |
int val; |
| 6860 |
|
| 6861 |
if (len < sizeof(int)) |
| 6862 |
return -EINVAL; |
| 6863 |
|
| 6864 |
len = sizeof(int); |
| 6865 |
|
| 6866 |
val = sctp_sk(sk)->frag_interleave; |
| 6867 |
if (put_user(len, optlen)) |
| 6868 |
return -EFAULT; |
| 6869 |
if (copy_to_user(optval, &val, len)) |
| 6870 |
return -EFAULT; |
| 6871 |
|
| 6872 |
return 0; |
| 6873 |
} |
| 6874 |
|
| 6875 |
/* |
| 6876 |
* 7.1.25. Set or Get the sctp partial delivery point |
| 6877 |
* (chapter and verse is quoted at sctp_setsockopt_partial_delivery_point()) |
| 6878 |
*/ |
| 6879 |
static int sctp_getsockopt_partial_delivery_point(struct sock *sk, int len, |
| 6880 |
char __user *optval, |
| 6881 |
int __user *optlen) |
| 6882 |
{ |
| 6883 |
u32 val; |
| 6884 |
|
| 6885 |
if (len < sizeof(u32)) |
| 6886 |
return -EINVAL; |
| 6887 |
|
| 6888 |
len = sizeof(u32); |
| 6889 |
|
| 6890 |
val = sctp_sk(sk)->pd_point; |
| 6891 |
if (put_user(len, optlen)) |
| 6892 |
return -EFAULT; |
| 6893 |
if (copy_to_user(optval, &val, len)) |
| 6894 |
return -EFAULT; |
| 6895 |
|
| 6896 |
return 0; |
| 6897 |
} |
| 6898 |
|
| 6899 |
/* |
| 6900 |
* 7.1.28. Set or Get the maximum burst (SCTP_MAX_BURST) |
| 6901 |
* (chapter and verse is quoted at sctp_setsockopt_maxburst()) |
| 6902 |
*/ |
| 6903 |
static int sctp_getsockopt_maxburst(struct sock *sk, int len, |
| 6904 |
char __user *optval, |
| 6905 |
int __user *optlen) |
| 6906 |
{ |
| 6907 |
struct sctp_assoc_value params; |
| 6908 |
struct sctp_association *asoc; |
| 6909 |
|
| 6910 |
if (len == sizeof(int)) { |
| 6911 |
pr_warn_ratelimited(DEPRECATED |
| 6912 |
"%s (pid %d) " |
| 6913 |
"Use of int in max_burst socket option.\n" |
| 6914 |
"Use struct sctp_assoc_value instead\n", |
| 6915 |
current->comm, task_pid_nr(current)); |
| 6916 |
params.assoc_id = SCTP_FUTURE_ASSOC; |
| 6917 |
} else if (len >= sizeof(struct sctp_assoc_value)) { |
| 6918 |
len = sizeof(struct sctp_assoc_value); |
| 6919 |
if (copy_from_user(¶ms, optval, len)) |
| 6920 |
return -EFAULT; |
| 6921 |
} else |
| 6922 |
return -EINVAL; |
| 6923 |
|
| 6924 |
asoc = sctp_id2assoc(sk, params.assoc_id); |
| 6925 |
if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC && |
| 6926 |
sctp_style(sk, UDP)) |
| 6927 |
return -EINVAL; |
| 6928 |
|
| 6929 |
params.assoc_value = asoc ? asoc->max_burst : sctp_sk(sk)->max_burst; |
| 6930 |
|
| 6931 |
if (len == sizeof(int)) { |
| 6932 |
if (copy_to_user(optval, ¶ms.assoc_value, len)) |
| 6933 |
return -EFAULT; |
| 6934 |
} else { |
| 6935 |
if (copy_to_user(optval, ¶ms, len)) |
| 6936 |
return -EFAULT; |
| 6937 |
} |
| 6938 |
|
| 6939 |
return 0; |
| 6940 |
|
| 6941 |
} |
| 6942 |
|
| 6943 |
static int sctp_getsockopt_hmac_ident(struct sock *sk, int len, |
| 6944 |
char __user *optval, int __user *optlen) |
| 6945 |
{ |
| 6946 |
struct sctp_endpoint *ep = sctp_sk(sk)->ep; |
| 6947 |
struct sctp_hmacalgo __user *p = (void __user *)optval; |
| 6948 |
struct sctp_hmac_algo_param *hmacs; |
| 6949 |
__u16 data_len = 0; |
| 6950 |
u32 num_idents; |
| 6951 |
int i; |
| 6952 |
|
| 6953 |
if (!ep->auth_enable) |
| 6954 |
return -EACCES; |
| 6955 |
|
| 6956 |
hmacs = ep->auth_hmacs_list; |
| 6957 |
data_len = ntohs(hmacs->param_hdr.length) - |
| 6958 |
sizeof(struct sctp_paramhdr); |
| 6959 |
|
| 6960 |
if (len < sizeof(struct sctp_hmacalgo) + data_len) |
| 6961 |
return -EINVAL; |
| 6962 |
|
| 6963 |
len = sizeof(struct sctp_hmacalgo) + data_len; |
| 6964 |
num_idents = data_len / sizeof(u16); |
| 6965 |
|
| 6966 |
if (put_user(len, optlen)) |
| 6967 |
return -EFAULT; |
| 6968 |
if (put_user(num_idents, &p->shmac_num_idents)) |
| 6969 |
return -EFAULT; |
| 6970 |
for (i = 0; i < num_idents; i++) { |
| 6971 |
__u16 hmacid = ntohs(hmacs->hmac_ids[i]); |
| 6972 |
|
| 6973 |
if (copy_to_user(&p->shmac_idents[i], &hmacid, sizeof(__u16))) |
| 6974 |
return -EFAULT; |
| 6975 |
} |
| 6976 |
return 0; |
| 6977 |
} |
| 6978 |
|
| 6979 |
static int sctp_getsockopt_active_key(struct sock *sk, int len, |
| 6980 |
char __user *optval, int __user *optlen) |
| 6981 |
{ |
| 6982 |
struct sctp_endpoint *ep = sctp_sk(sk)->ep; |
| 6983 |
struct sctp_authkeyid val; |
| 6984 |
struct sctp_association *asoc; |
| 6985 |
|
| 6986 |
if (len < sizeof(struct sctp_authkeyid)) |
| 6987 |
return -EINVAL; |
| 6988 |
|
| 6989 |
len = sizeof(struct sctp_authkeyid); |
| 6990 |
if (copy_from_user(&val, optval, len)) |
| 6991 |
return -EFAULT; |
| 6992 |
|
| 6993 |
asoc = sctp_id2assoc(sk, val.scact_assoc_id); |
| 6994 |
if (!asoc && val.scact_assoc_id && sctp_style(sk, UDP)) |
| 6995 |
return -EINVAL; |
| 6996 |
|
| 6997 |
if (asoc) { |
| 6998 |
if (!asoc->peer.auth_capable) |
| 6999 |
return -EACCES; |
| 7000 |
val.scact_keynumber = asoc->active_key_id; |
| 7001 |
} else { |
| 7002 |
if (!ep->auth_enable) |
| 7003 |
return -EACCES; |
| 7004 |
val.scact_keynumber = ep->active_key_id; |
| 7005 |
} |
| 7006 |
|
| 7007 |
if (put_user(len, optlen)) |
| 7008 |
return -EFAULT; |
| 7009 |
if (copy_to_user(optval, &val, len)) |
| 7010 |
return -EFAULT; |
| 7011 |
|
| 7012 |
return 0; |
| 7013 |
} |
| 7014 |
|
| 7015 |
static int sctp_getsockopt_peer_auth_chunks(struct sock *sk, int len, |
| 7016 |
char __user *optval, int __user *optlen) |
| 7017 |
{ |
| 7018 |
struct sctp_authchunks __user *p = (void __user *)optval; |
| 7019 |
struct sctp_authchunks val; |
| 7020 |
struct sctp_association *asoc; |
| 7021 |
struct sctp_chunks_param *ch; |
| 7022 |
u32 num_chunks = 0; |
| 7023 |
char __user *to; |
| 7024 |
|
| 7025 |
if (len < sizeof(struct sctp_authchunks)) |
| 7026 |
return -EINVAL; |
| 7027 |
|
| 7028 |
if (copy_from_user(&val, optval, sizeof(val))) |
| 7029 |
return -EFAULT; |
| 7030 |
|
| 7031 |
to = p->gauth_chunks; |
| 7032 |
asoc = sctp_id2assoc(sk, val.gauth_assoc_id); |
| 7033 |
if (!asoc) |
| 7034 |
return -EINVAL; |
| 7035 |
|
| 7036 |
if (!asoc->peer.auth_capable) |
| 7037 |
return -EACCES; |
| 7038 |
|
| 7039 |
ch = asoc->peer.peer_chunks; |
| 7040 |
if (!ch) |
| 7041 |
goto num; |
| 7042 |
|
| 7043 |
/* See if the user provided enough room for all the data */ |
| 7044 |
num_chunks = ntohs(ch->param_hdr.length) - sizeof(struct sctp_paramhdr); |
| 7045 |
if (len < num_chunks) |
| 7046 |
return -EINVAL; |
| 7047 |
|
| 7048 |
if (copy_to_user(to, ch->chunks, num_chunks)) |
| 7049 |
return -EFAULT; |
| 7050 |
num: |
| 7051 |
len = sizeof(struct sctp_authchunks) + num_chunks; |
| 7052 |
if (put_user(len, optlen)) |
| 7053 |
return -EFAULT; |
| 7054 |
if (put_user(num_chunks, &p->gauth_number_of_chunks)) |
| 7055 |
return -EFAULT; |
| 7056 |
return 0; |
| 7057 |
} |
| 7058 |
|
| 7059 |
static int sctp_getsockopt_local_auth_chunks(struct sock *sk, int len, |
| 7060 |
char __user *optval, int __user *optlen) |
| 7061 |
{ |
| 7062 |
struct sctp_endpoint *ep = sctp_sk(sk)->ep; |
| 7063 |
struct sctp_authchunks __user *p = (void __user *)optval; |
| 7064 |
struct sctp_authchunks val; |
| 7065 |
struct sctp_association *asoc; |
| 7066 |
struct sctp_chunks_param *ch; |
| 7067 |
u32 num_chunks = 0; |
| 7068 |
char __user *to; |
| 7069 |
|
| 7070 |
if (len < sizeof(struct sctp_authchunks)) |
| 7071 |
return -EINVAL; |
| 7072 |
|
| 7073 |
if (copy_from_user(&val, optval, sizeof(val))) |
| 7074 |
return -EFAULT; |
| 7075 |
|
| 7076 |
to = p->gauth_chunks; |
| 7077 |
asoc = sctp_id2assoc(sk, val.gauth_assoc_id); |
| 7078 |
if (!asoc && val.gauth_assoc_id != SCTP_FUTURE_ASSOC && |
| 7079 |
sctp_style(sk, UDP)) |
| 7080 |
return -EINVAL; |
| 7081 |
|
| 7082 |
if (asoc) { |
| 7083 |
if (!asoc->peer.auth_capable) |
| 7084 |
return -EACCES; |
| 7085 |
ch = (struct sctp_chunks_param *)asoc->c.auth_chunks; |
| 7086 |
} else { |
| 7087 |
if (!ep->auth_enable) |
| 7088 |
return -EACCES; |
| 7089 |
ch = ep->auth_chunk_list; |
| 7090 |
} |
| 7091 |
if (!ch) |
| 7092 |
goto num; |
| 7093 |
|
| 7094 |
num_chunks = ntohs(ch->param_hdr.length) - sizeof(struct sctp_paramhdr); |
| 7095 |
if (len < sizeof(struct sctp_authchunks) + num_chunks) |
| 7096 |
return -EINVAL; |
| 7097 |
|
| 7098 |
if (copy_to_user(to, ch->chunks, num_chunks)) |
| 7099 |
return -EFAULT; |
| 7100 |
num: |
| 7101 |
len = sizeof(struct sctp_authchunks) + num_chunks; |
| 7102 |
if (put_user(len, optlen)) |
| 7103 |
return -EFAULT; |
| 7104 |
if (put_user(num_chunks, &p->gauth_number_of_chunks)) |
| 7105 |
return -EFAULT; |
| 7106 |
|
| 7107 |
return 0; |
| 7108 |
} |
| 7109 |
|
| 7110 |
/* |
| 7111 |
* 8.2.5. Get the Current Number of Associations (SCTP_GET_ASSOC_NUMBER) |
| 7112 |
* This option gets the current number of associations that are attached |
| 7113 |
* to a one-to-many style socket. The option value is an uint32_t. |
| 7114 |
*/ |
| 7115 |
static int sctp_getsockopt_assoc_number(struct sock *sk, int len, |
| 7116 |
char __user *optval, int __user *optlen) |
| 7117 |
{ |
| 7118 |
struct sctp_sock *sp = sctp_sk(sk); |
| 7119 |
struct sctp_association *asoc; |
| 7120 |
u32 val = 0; |
| 7121 |
|
| 7122 |
if (sctp_style(sk, TCP)) |
| 7123 |
return -EOPNOTSUPP; |
| 7124 |
|
| 7125 |
if (len < sizeof(u32)) |
| 7126 |
return -EINVAL; |
| 7127 |
|
| 7128 |
len = sizeof(u32); |
| 7129 |
|
| 7130 |
list_for_each_entry(asoc, &(sp->ep->asocs), asocs) { |
| 7131 |
val++; |
| 7132 |
} |
| 7133 |
|
| 7134 |
if (put_user(len, optlen)) |
| 7135 |
return -EFAULT; |
| 7136 |
if (copy_to_user(optval, &val, len)) |
| 7137 |
return -EFAULT; |
| 7138 |
|
| 7139 |
return 0; |
| 7140 |
} |
| 7141 |
|
| 7142 |
/* |
| 7143 |
* 8.1.23 SCTP_AUTO_ASCONF |
| 7144 |
* See the corresponding setsockopt entry as description |
| 7145 |
*/ |
| 7146 |
static int sctp_getsockopt_auto_asconf(struct sock *sk, int len, |
| 7147 |
char __user *optval, int __user *optlen) |
| 7148 |
{ |
| 7149 |
int val = 0; |
| 7150 |
|
| 7151 |
if (len < sizeof(int)) |
| 7152 |
return -EINVAL; |
| 7153 |
|
| 7154 |
len = sizeof(int); |
| 7155 |
if (sctp_sk(sk)->do_auto_asconf && sctp_is_ep_boundall(sk)) |
| 7156 |
val = 1; |
| 7157 |
if (put_user(len, optlen)) |
| 7158 |
return -EFAULT; |
| 7159 |
if (copy_to_user(optval, &val, len)) |
| 7160 |
return -EFAULT; |
| 7161 |
return 0; |
| 7162 |
} |
| 7163 |
|
| 7164 |
/* |
| 7165 |
* 8.2.6. Get the Current Identifiers of Associations |
| 7166 |
* (SCTP_GET_ASSOC_ID_LIST) |
| 7167 |
* |
| 7168 |
* This option gets the current list of SCTP association identifiers of |
| 7169 |
* the SCTP associations handled by a one-to-many style socket. |
| 7170 |
*/ |
| 7171 |
static int sctp_getsockopt_assoc_ids(struct sock *sk, int len, |
| 7172 |
char __user *optval, int __user *optlen) |
| 7173 |
{ |
| 7174 |
struct sctp_sock *sp = sctp_sk(sk); |
| 7175 |
struct sctp_association *asoc; |
| 7176 |
struct sctp_assoc_ids *ids; |
| 7177 |
size_t ids_size; |
| 7178 |
u32 num = 0; |
| 7179 |
|
| 7180 |
if (sctp_style(sk, TCP)) |
| 7181 |
return -EOPNOTSUPP; |
| 7182 |
|
| 7183 |
if (len < sizeof(struct sctp_assoc_ids)) |
| 7184 |
return -EINVAL; |
| 7185 |
|
| 7186 |
list_for_each_entry(asoc, &(sp->ep->asocs), asocs) { |
| 7187 |
num++; |
| 7188 |
} |
| 7189 |
|
| 7190 |
ids_size = struct_size(ids, gaids_assoc_id, num); |
| 7191 |
if (len < ids_size) |
| 7192 |
return -EINVAL; |
| 7193 |
|
| 7194 |
len = ids_size; |
| 7195 |
ids = kmalloc(len, GFP_USER | __GFP_NOWARN); |
| 7196 |
if (unlikely(!ids)) |
| 7197 |
return -ENOMEM; |
| 7198 |
|
| 7199 |
ids->gaids_number_of_ids = num; |
| 7200 |
num = 0; |
| 7201 |
list_for_each_entry(asoc, &(sp->ep->asocs), asocs) { |
| 7202 |
ids->gaids_assoc_id[num++] = asoc->assoc_id; |
| 7203 |
} |
| 7204 |
|
| 7205 |
if (put_user(len, optlen) || copy_to_user(optval, ids, len)) { |
| 7206 |
kfree(ids); |
| 7207 |
return -EFAULT; |
| 7208 |
} |
| 7209 |
|
| 7210 |
kfree(ids); |
| 7211 |
return 0; |
| 7212 |
} |
| 7213 |
|
| 7214 |
/* |
| 7215 |
* SCTP_PEER_ADDR_THLDS |
| 7216 |
* |
| 7217 |
* This option allows us to fetch the partially failed threshold for one or all |
| 7218 |
* transports in an association. See Section 6.1 of: |
| 7219 |
* http://www.ietf.org/id/draft-nishida-tsvwg-sctp-failover-05.txt |
| 7220 |
*/ |
| 7221 |
static int sctp_getsockopt_paddr_thresholds(struct sock *sk, |
| 7222 |
char __user *optval, int len, |
| 7223 |
int __user *optlen, bool v2) |
| 7224 |
{ |
| 7225 |
struct sctp_paddrthlds_v2 val; |
| 7226 |
struct sctp_transport *trans; |
| 7227 |
struct sctp_association *asoc; |
| 7228 |
int min; |
| 7229 |
|
| 7230 |
min = v2 ? sizeof(val) : sizeof(struct sctp_paddrthlds); |
| 7231 |
if (len < min) |
| 7232 |
return -EINVAL; |
| 7233 |
len = min; |
| 7234 |
if (copy_from_user(&val, optval, len)) |
| 7235 |
return -EFAULT; |
| 7236 |
|
| 7237 |
if (!sctp_is_any(sk, (const union sctp_addr *)&val.spt_address)) { |
| 7238 |
trans = sctp_addr_id2transport(sk, &val.spt_address, |
| 7239 |
val.spt_assoc_id); |
| 7240 |
if (!trans) |
| 7241 |
return -ENOENT; |
| 7242 |
|
| 7243 |
val.spt_pathmaxrxt = trans->pathmaxrxt; |
| 7244 |
val.spt_pathpfthld = trans->pf_retrans; |
| 7245 |
val.spt_pathcpthld = trans->ps_retrans; |
| 7246 |
|
| 7247 |
goto out; |
| 7248 |
} |
| 7249 |
|
| 7250 |
asoc = sctp_id2assoc(sk, val.spt_assoc_id); |
| 7251 |
if (!asoc && val.spt_assoc_id != SCTP_FUTURE_ASSOC && |
| 7252 |
sctp_style(sk, UDP)) |
| 7253 |
return -EINVAL; |
| 7254 |
|
| 7255 |
if (asoc) { |
| 7256 |
val.spt_pathpfthld = asoc->pf_retrans; |
| 7257 |
val.spt_pathmaxrxt = asoc->pathmaxrxt; |
| 7258 |
val.spt_pathcpthld = asoc->ps_retrans; |
| 7259 |
} else { |
| 7260 |
struct sctp_sock *sp = sctp_sk(sk); |
| 7261 |
|
| 7262 |
val.spt_pathpfthld = sp->pf_retrans; |
| 7263 |
val.spt_pathmaxrxt = sp->pathmaxrxt; |
| 7264 |
val.spt_pathcpthld = sp->ps_retrans; |
| 7265 |
} |
| 7266 |
|
| 7267 |
out: |
| 7268 |
if (put_user(len, optlen) || copy_to_user(optval, &val, len)) |
| 7269 |
return -EFAULT; |
| 7270 |
|
| 7271 |
return 0; |
| 7272 |
} |
| 7273 |
|
| 7274 |
/* |
| 7275 |
* SCTP_GET_ASSOC_STATS |
| 7276 |
* |
| 7277 |
* This option retrieves local per endpoint statistics. It is modeled |
| 7278 |
* after OpenSolaris' implementation |
| 7279 |
*/ |
| 7280 |
static int sctp_getsockopt_assoc_stats(struct sock *sk, int len, |
| 7281 |
char __user *optval, |
| 7282 |
int __user *optlen) |
| 7283 |
{ |
| 7284 |
struct sctp_assoc_stats sas; |
| 7285 |
struct sctp_association *asoc = NULL; |
| 7286 |
|
| 7287 |
/* User must provide at least the assoc id */ |
| 7288 |
if (len < sizeof(sctp_assoc_t)) |
| 7289 |
return -EINVAL; |
| 7290 |
|
| 7291 |
/* Allow the struct to grow and fill in as much as possible */ |
| 7292 |
len = min_t(size_t, len, sizeof(sas)); |
| 7293 |
|
| 7294 |
if (copy_from_user(&sas, optval, len)) |
| 7295 |
return -EFAULT; |
| 7296 |
|
| 7297 |
asoc = sctp_id2assoc(sk, sas.sas_assoc_id); |
| 7298 |
if (!asoc) |
| 7299 |
return -EINVAL; |
| 7300 |
|
| 7301 |
sas.sas_rtxchunks = asoc->stats.rtxchunks; |
| 7302 |
sas.sas_gapcnt = asoc->stats.gapcnt; |
| 7303 |
sas.sas_outofseqtsns = asoc->stats.outofseqtsns; |
| 7304 |
sas.sas_osacks = asoc->stats.osacks; |
| 7305 |
sas.sas_isacks = asoc->stats.isacks; |
| 7306 |
sas.sas_octrlchunks = asoc->stats.octrlchunks; |
| 7307 |
sas.sas_ictrlchunks = asoc->stats.ictrlchunks; |
| 7308 |
sas.sas_oodchunks = asoc->stats.oodchunks; |
| 7309 |
sas.sas_iodchunks = asoc->stats.iodchunks; |
| 7310 |
sas.sas_ouodchunks = asoc->stats.ouodchunks; |
| 7311 |
sas.sas_iuodchunks = asoc->stats.iuodchunks; |
| 7312 |
sas.sas_idupchunks = asoc->stats.idupchunks; |
| 7313 |
sas.sas_opackets = asoc->stats.opackets; |
| 7314 |
sas.sas_ipackets = asoc->stats.ipackets; |
| 7315 |
|
| 7316 |
/* New high max rto observed, will return 0 if not a single |
| 7317 |
* RTO update took place. obs_rto_ipaddr will be bogus |
| 7318 |
* in such a case |
| 7319 |
*/ |
| 7320 |
sas.sas_maxrto = asoc->stats.max_obs_rto; |
| 7321 |
memcpy(&sas.sas_obs_rto_ipaddr, &asoc->stats.obs_rto_ipaddr, |
| 7322 |
sizeof(struct sockaddr_storage)); |
| 7323 |
|
| 7324 |
/* Mark beginning of a new observation period */ |
| 7325 |
asoc->stats.max_obs_rto = asoc->rto_min; |
| 7326 |
|
| 7327 |
if (put_user(len, optlen)) |
| 7328 |
return -EFAULT; |
| 7329 |
|
| 7330 |
pr_debug("%s: len:%d, assoc_id:%d\n", __func__, len, sas.sas_assoc_id); |
| 7331 |
|
| 7332 |
if (copy_to_user(optval, &sas, len)) |
| 7333 |
return -EFAULT; |
| 7334 |
|
| 7335 |
return 0; |
| 7336 |
} |
| 7337 |
|
| 7338 |
static int sctp_getsockopt_recvrcvinfo(struct sock *sk, int len, |
| 7339 |
char __user *optval, |
| 7340 |
int __user *optlen) |
| 7341 |
{ |
| 7342 |
int val = 0; |
| 7343 |
|
| 7344 |
if (len < sizeof(int)) |
| 7345 |
return -EINVAL; |
| 7346 |
|
| 7347 |
len = sizeof(int); |
| 7348 |
if (sctp_sk(sk)->recvrcvinfo) |
| 7349 |
val = 1; |
| 7350 |
if (put_user(len, optlen)) |
| 7351 |
return -EFAULT; |
| 7352 |
if (copy_to_user(optval, &val, len)) |
| 7353 |
return -EFAULT; |
| 7354 |
|
| 7355 |
return 0; |
| 7356 |
} |
| 7357 |
|
| 7358 |
static int sctp_getsockopt_recvnxtinfo(struct sock *sk, int len, |
| 7359 |
char __user *optval, |
| 7360 |
int __user *optlen) |
| 7361 |
{ |
| 7362 |
int val = 0; |
| 7363 |
|
| 7364 |
if (len < sizeof(int)) |
| 7365 |
return -EINVAL; |
| 7366 |
|
| 7367 |
len = sizeof(int); |
| 7368 |
if (sctp_sk(sk)->recvnxtinfo) |
| 7369 |
val = 1; |
| 7370 |
if (put_user(len, optlen)) |
| 7371 |
return -EFAULT; |
| 7372 |
if (copy_to_user(optval, &val, len)) |
| 7373 |
return -EFAULT; |
| 7374 |
|
| 7375 |
return 0; |
| 7376 |
} |
| 7377 |
|
| 7378 |
static int sctp_getsockopt_pr_supported(struct sock *sk, int len, |
| 7379 |
char __user *optval, |
| 7380 |
int __user *optlen) |
| 7381 |
{ |
| 7382 |
struct sctp_assoc_value params; |
| 7383 |
struct sctp_association *asoc; |
| 7384 |
int retval = -EFAULT; |
| 7385 |
|
| 7386 |
if (len < sizeof(params)) { |
| 7387 |
retval = -EINVAL; |
| 7388 |
goto out; |
| 7389 |
} |
| 7390 |
|
| 7391 |
len = sizeof(params); |
| 7392 |
if (copy_from_user(¶ms, optval, len)) |
| 7393 |
goto out; |
| 7394 |
|
| 7395 |
asoc = sctp_id2assoc(sk, params.assoc_id); |
| 7396 |
if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC && |
| 7397 |
sctp_style(sk, UDP)) { |
| 7398 |
retval = -EINVAL; |
| 7399 |
goto out; |
| 7400 |
} |
| 7401 |
|
| 7402 |
params.assoc_value = asoc ? asoc->peer.prsctp_capable |
| 7403 |
: sctp_sk(sk)->ep->prsctp_enable; |
| 7404 |
|
| 7405 |
if (put_user(len, optlen)) |
| 7406 |
goto out; |
| 7407 |
|
| 7408 |
if (copy_to_user(optval, ¶ms, len)) |
| 7409 |
goto out; |
| 7410 |
|
| 7411 |
retval = 0; |
| 7412 |
|
| 7413 |
out: |
| 7414 |
return retval; |
| 7415 |
} |
| 7416 |
|
| 7417 |
static int sctp_getsockopt_default_prinfo(struct sock *sk, int len, |
| 7418 |
char __user *optval, |
| 7419 |
int __user *optlen) |
| 7420 |
{ |
| 7421 |
struct sctp_default_prinfo info; |
| 7422 |
struct sctp_association *asoc; |
| 7423 |
int retval = -EFAULT; |
| 7424 |
|
| 7425 |
if (len < sizeof(info)) { |
| 7426 |
retval = -EINVAL; |
| 7427 |
goto out; |
| 7428 |
} |
| 7429 |
|
| 7430 |
len = sizeof(info); |
| 7431 |
if (copy_from_user(&info, optval, len)) |
| 7432 |
goto out; |
| 7433 |
|
| 7434 |
asoc = sctp_id2assoc(sk, info.pr_assoc_id); |
| 7435 |
if (!asoc && info.pr_assoc_id != SCTP_FUTURE_ASSOC && |
| 7436 |
sctp_style(sk, UDP)) { |
| 7437 |
retval = -EINVAL; |
| 7438 |
goto out; |
| 7439 |
} |
| 7440 |
|
| 7441 |
if (asoc) { |
| 7442 |
info.pr_policy = SCTP_PR_POLICY(asoc->default_flags); |
| 7443 |
info.pr_value = asoc->default_timetolive; |
| 7444 |
} else { |
| 7445 |
struct sctp_sock *sp = sctp_sk(sk); |
| 7446 |
|
| 7447 |
info.pr_policy = SCTP_PR_POLICY(sp->default_flags); |
| 7448 |
info.pr_value = sp->default_timetolive; |
| 7449 |
} |
| 7450 |
|
| 7451 |
if (put_user(len, optlen)) |
| 7452 |
goto out; |
| 7453 |
|
| 7454 |
if (copy_to_user(optval, &info, len)) |
| 7455 |
goto out; |
| 7456 |
|
| 7457 |
retval = 0; |
| 7458 |
|
| 7459 |
out: |
| 7460 |
return retval; |
| 7461 |
} |
| 7462 |
|
| 7463 |
static int sctp_getsockopt_pr_assocstatus(struct sock *sk, int len, |
| 7464 |
char __user *optval, |
| 7465 |
int __user *optlen) |
| 7466 |
{ |
| 7467 |
struct sctp_prstatus params; |
| 7468 |
struct sctp_association *asoc; |
| 7469 |
int policy; |
| 7470 |
int retval = -EINVAL; |
| 7471 |
|
| 7472 |
if (len < sizeof(params)) |
| 7473 |
goto out; |
| 7474 |
|
| 7475 |
len = sizeof(params); |
| 7476 |
if (copy_from_user(¶ms, optval, len)) { |
| 7477 |
retval = -EFAULT; |
| 7478 |
goto out; |
| 7479 |
} |
| 7480 |
|
| 7481 |
policy = params.sprstat_policy; |
| 7482 |
if (!policy || (policy & ~(SCTP_PR_SCTP_MASK | SCTP_PR_SCTP_ALL)) || |
| 7483 |
((policy & SCTP_PR_SCTP_ALL) && (policy & SCTP_PR_SCTP_MASK))) |
| 7484 |
goto out; |
| 7485 |
|
| 7486 |
asoc = sctp_id2assoc(sk, params.sprstat_assoc_id); |
| 7487 |
if (!asoc) |
| 7488 |
goto out; |
| 7489 |
|
| 7490 |
if (policy == SCTP_PR_SCTP_ALL) { |
| 7491 |
params.sprstat_abandoned_unsent = 0; |
| 7492 |
params.sprstat_abandoned_sent = 0; |
| 7493 |
for (policy = 0; policy <= SCTP_PR_INDEX(MAX); policy++) { |
| 7494 |
params.sprstat_abandoned_unsent += |
| 7495 |
asoc->abandoned_unsent[policy]; |
| 7496 |
params.sprstat_abandoned_sent += |
| 7497 |
asoc->abandoned_sent[policy]; |
| 7498 |
} |
| 7499 |
} else { |
| 7500 |
params.sprstat_abandoned_unsent = |
| 7501 |
asoc->abandoned_unsent[__SCTP_PR_INDEX(policy)]; |
| 7502 |
params.sprstat_abandoned_sent = |
| 7503 |
asoc->abandoned_sent[__SCTP_PR_INDEX(policy)]; |
| 7504 |
} |
| 7505 |
|
| 7506 |
if (put_user(len, optlen)) { |
| 7507 |
retval = -EFAULT; |
| 7508 |
goto out; |
| 7509 |
} |
| 7510 |
|
| 7511 |
if (copy_to_user(optval, ¶ms, len)) { |
| 7512 |
retval = -EFAULT; |
| 7513 |
goto out; |
| 7514 |
} |
| 7515 |
|
| 7516 |
retval = 0; |
| 7517 |
|
| 7518 |
out: |
| 7519 |
return retval; |
| 7520 |
} |
| 7521 |
|
| 7522 |
static int sctp_getsockopt_pr_streamstatus(struct sock *sk, int len, |
| 7523 |
char __user *optval, |
| 7524 |
int __user *optlen) |
| 7525 |
{ |
| 7526 |
struct sctp_stream_out_ext *streamoute; |
| 7527 |
struct sctp_association *asoc; |
| 7528 |
struct sctp_prstatus params; |
| 7529 |
int retval = -EINVAL; |
| 7530 |
int policy; |
| 7531 |
|
| 7532 |
if (len < sizeof(params)) |
| 7533 |
goto out; |
| 7534 |
|
| 7535 |
len = sizeof(params); |
| 7536 |
if (copy_from_user(¶ms, optval, len)) { |
| 7537 |
retval = -EFAULT; |
| 7538 |
goto out; |
| 7539 |
} |
| 7540 |
|
| 7541 |
policy = params.sprstat_policy; |
| 7542 |
if (!policy || (policy & ~(SCTP_PR_SCTP_MASK | SCTP_PR_SCTP_ALL)) || |
| 7543 |
((policy & SCTP_PR_SCTP_ALL) && (policy & SCTP_PR_SCTP_MASK))) |
| 7544 |
goto out; |
| 7545 |
|
| 7546 |
asoc = sctp_id2assoc(sk, params.sprstat_assoc_id); |
| 7547 |
if (!asoc || params.sprstat_sid >= asoc->stream.outcnt) |
| 7548 |
goto out; |
| 7549 |
|
| 7550 |
streamoute = SCTP_SO(&asoc->stream, params.sprstat_sid)->ext; |
| 7551 |
if (!streamoute) { |
| 7552 |
/* Not allocated yet, means all stats are 0 */ |
| 7553 |
params.sprstat_abandoned_unsent = 0; |
| 7554 |
params.sprstat_abandoned_sent = 0; |
| 7555 |
retval = 0; |
| 7556 |
goto out; |
| 7557 |
} |
| 7558 |
|
| 7559 |
if (policy == SCTP_PR_SCTP_ALL) { |
| 7560 |
params.sprstat_abandoned_unsent = 0; |
| 7561 |
params.sprstat_abandoned_sent = 0; |
| 7562 |
for (policy = 0; policy <= SCTP_PR_INDEX(MAX); policy++) { |
| 7563 |
params.sprstat_abandoned_unsent += |
| 7564 |
streamoute->abandoned_unsent[policy]; |
| 7565 |
params.sprstat_abandoned_sent += |
| 7566 |
streamoute->abandoned_sent[policy]; |
| 7567 |
} |
| 7568 |
} else { |
| 7569 |
params.sprstat_abandoned_unsent = |
| 7570 |
streamoute->abandoned_unsent[__SCTP_PR_INDEX(policy)]; |
| 7571 |
params.sprstat_abandoned_sent = |
| 7572 |
streamoute->abandoned_sent[__SCTP_PR_INDEX(policy)]; |
| 7573 |
} |
| 7574 |
|
| 7575 |
if (put_user(len, optlen) || copy_to_user(optval, ¶ms, len)) { |
| 7576 |
retval = -EFAULT; |
| 7577 |
goto out; |
| 7578 |
} |
| 7579 |
|
| 7580 |
retval = 0; |
| 7581 |
|
| 7582 |
out: |
| 7583 |
return retval; |
| 7584 |
} |
| 7585 |
|
| 7586 |
static int sctp_getsockopt_reconfig_supported(struct sock *sk, int len, |
| 7587 |
char __user *optval, |
| 7588 |
int __user *optlen) |
| 7589 |
{ |
| 7590 |
struct sctp_assoc_value params; |
| 7591 |
struct sctp_association *asoc; |
| 7592 |
int retval = -EFAULT; |
| 7593 |
|
| 7594 |
if (len < sizeof(params)) { |
| 7595 |
retval = -EINVAL; |
| 7596 |
goto out; |
| 7597 |
} |
| 7598 |
|
| 7599 |
len = sizeof(params); |
| 7600 |
if (copy_from_user(¶ms, optval, len)) |
| 7601 |
goto out; |
| 7602 |
|
| 7603 |
asoc = sctp_id2assoc(sk, params.assoc_id); |
| 7604 |
if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC && |
| 7605 |
sctp_style(sk, UDP)) { |
| 7606 |
retval = -EINVAL; |
| 7607 |
goto out; |
| 7608 |
} |
| 7609 |
|
| 7610 |
params.assoc_value = asoc ? asoc->peer.reconf_capable |
| 7611 |
: sctp_sk(sk)->ep->reconf_enable; |
| 7612 |
|
| 7613 |
if (put_user(len, optlen)) |
| 7614 |
goto out; |
| 7615 |
|
| 7616 |
if (copy_to_user(optval, ¶ms, len)) |
| 7617 |
goto out; |
| 7618 |
|
| 7619 |
retval = 0; |
| 7620 |
|
| 7621 |
out: |
| 7622 |
return retval; |
| 7623 |
} |
| 7624 |
|
| 7625 |
static int sctp_getsockopt_enable_strreset(struct sock *sk, int len, |
| 7626 |
char __user *optval, |
| 7627 |
int __user *optlen) |
| 7628 |
{ |
| 7629 |
struct sctp_assoc_value params; |
| 7630 |
struct sctp_association *asoc; |
| 7631 |
int retval = -EFAULT; |
| 7632 |
|
| 7633 |
if (len < sizeof(params)) { |
| 7634 |
retval = -EINVAL; |
| 7635 |
goto out; |
| 7636 |
} |
| 7637 |
|
| 7638 |
len = sizeof(params); |
| 7639 |
if (copy_from_user(¶ms, optval, len)) |
| 7640 |
goto out; |
| 7641 |
|
| 7642 |
asoc = sctp_id2assoc(sk, params.assoc_id); |
| 7643 |
if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC && |
| 7644 |
sctp_style(sk, UDP)) { |
| 7645 |
retval = -EINVAL; |
| 7646 |
goto out; |
| 7647 |
} |
| 7648 |
|
| 7649 |
params.assoc_value = asoc ? asoc->strreset_enable |
| 7650 |
: sctp_sk(sk)->ep->strreset_enable; |
| 7651 |
|
| 7652 |
if (put_user(len, optlen)) |
| 7653 |
goto out; |
| 7654 |
|
| 7655 |
if (copy_to_user(optval, ¶ms, len)) |
| 7656 |
goto out; |
| 7657 |
|
| 7658 |
retval = 0; |
| 7659 |
|
| 7660 |
out: |
| 7661 |
return retval; |
| 7662 |
} |
| 7663 |
|
| 7664 |
static int sctp_getsockopt_scheduler(struct sock *sk, int len, |
| 7665 |
char __user *optval, |
| 7666 |
int __user *optlen) |
| 7667 |
{ |
| 7668 |
struct sctp_assoc_value params; |
| 7669 |
struct sctp_association *asoc; |
| 7670 |
int retval = -EFAULT; |
| 7671 |
|
| 7672 |
if (len < sizeof(params)) { |
| 7673 |
retval = -EINVAL; |
| 7674 |
goto out; |
| 7675 |
} |
| 7676 |
|
| 7677 |
len = sizeof(params); |
| 7678 |
if (copy_from_user(¶ms, optval, len)) |
| 7679 |
goto out; |
| 7680 |
|
| 7681 |
asoc = sctp_id2assoc(sk, params.assoc_id); |
| 7682 |
if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC && |
| 7683 |
sctp_style(sk, UDP)) { |
| 7684 |
retval = -EINVAL; |
| 7685 |
goto out; |
| 7686 |
} |
| 7687 |
|
| 7688 |
params.assoc_value = asoc ? sctp_sched_get_sched(asoc) |
| 7689 |
: sctp_sk(sk)->default_ss; |
| 7690 |
|
| 7691 |
if (put_user(len, optlen)) |
| 7692 |
goto out; |
| 7693 |
|
| 7694 |
if (copy_to_user(optval, ¶ms, len)) |
| 7695 |
goto out; |
| 7696 |
|
| 7697 |
retval = 0; |
| 7698 |
|
| 7699 |
out: |
| 7700 |
return retval; |
| 7701 |
} |
| 7702 |
|
| 7703 |
static int sctp_getsockopt_scheduler_value(struct sock *sk, int len, |
| 7704 |
char __user *optval, |
| 7705 |
int __user *optlen) |
| 7706 |
{ |
| 7707 |
struct sctp_stream_value params; |
| 7708 |
struct sctp_association *asoc; |
| 7709 |
int retval = -EFAULT; |
| 7710 |
|
| 7711 |
if (len < sizeof(params)) { |
| 7712 |
retval = -EINVAL; |
| 7713 |
goto out; |
| 7714 |
} |
| 7715 |
|
| 7716 |
len = sizeof(params); |
| 7717 |
if (copy_from_user(¶ms, optval, len)) |
| 7718 |
goto out; |
| 7719 |
|
| 7720 |
asoc = sctp_id2assoc(sk, params.assoc_id); |
| 7721 |
if (!asoc) { |
| 7722 |
retval = -EINVAL; |
| 7723 |
goto out; |
| 7724 |
} |
| 7725 |
|
| 7726 |
retval = sctp_sched_get_value(asoc, params.stream_id, |
| 7727 |
¶ms.stream_value); |
| 7728 |
if (retval) |
| 7729 |
goto out; |
| 7730 |
|
| 7731 |
if (put_user(len, optlen)) { |
| 7732 |
retval = -EFAULT; |
| 7733 |
goto out; |
| 7734 |
} |
| 7735 |
|
| 7736 |
if (copy_to_user(optval, ¶ms, len)) { |
| 7737 |
retval = -EFAULT; |
| 7738 |
goto out; |
| 7739 |
} |
| 7740 |
|
| 7741 |
out: |
| 7742 |
return retval; |
| 7743 |
} |
| 7744 |
|
| 7745 |
static int sctp_getsockopt_interleaving_supported(struct sock *sk, int len, |
| 7746 |
char __user *optval, |
| 7747 |
int __user *optlen) |
| 7748 |
{ |
| 7749 |
struct sctp_assoc_value params; |
| 7750 |
struct sctp_association *asoc; |
| 7751 |
int retval = -EFAULT; |
| 7752 |
|
| 7753 |
if (len < sizeof(params)) { |
| 7754 |
retval = -EINVAL; |
| 7755 |
goto out; |
| 7756 |
} |
| 7757 |
|
| 7758 |
len = sizeof(params); |
| 7759 |
if (copy_from_user(¶ms, optval, len)) |
| 7760 |
goto out; |
| 7761 |
|
| 7762 |
asoc = sctp_id2assoc(sk, params.assoc_id); |
| 7763 |
if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC && |
| 7764 |
sctp_style(sk, UDP)) { |
| 7765 |
retval = -EINVAL; |
| 7766 |
goto out; |
| 7767 |
} |
| 7768 |
|
| 7769 |
params.assoc_value = asoc ? asoc->peer.intl_capable |
| 7770 |
: sctp_sk(sk)->ep->intl_enable; |
| 7771 |
|
| 7772 |
if (put_user(len, optlen)) |
| 7773 |
goto out; |
| 7774 |
|
| 7775 |
if (copy_to_user(optval, ¶ms, len)) |
| 7776 |
goto out; |
| 7777 |
|
| 7778 |
retval = 0; |
| 7779 |
|
| 7780 |
out: |
| 7781 |
return retval; |
| 7782 |
} |
| 7783 |
|
| 7784 |
static int sctp_getsockopt_reuse_port(struct sock *sk, int len, |
| 7785 |
char __user *optval, |
| 7786 |
int __user *optlen) |
| 7787 |
{ |
| 7788 |
int val; |
| 7789 |
|
| 7790 |
if (len < sizeof(int)) |
| 7791 |
return -EINVAL; |
| 7792 |
|
| 7793 |
len = sizeof(int); |
| 7794 |
val = sctp_sk(sk)->reuse; |
| 7795 |
if (put_user(len, optlen)) |
| 7796 |
return -EFAULT; |
| 7797 |
|
| 7798 |
if (copy_to_user(optval, &val, len)) |
| 7799 |
return -EFAULT; |
| 7800 |
|
| 7801 |
return 0; |
| 7802 |
} |
| 7803 |
|
| 7804 |
static int sctp_getsockopt_event(struct sock *sk, int len, char __user *optval, |
| 7805 |
int __user *optlen) |
| 7806 |
{ |
| 7807 |
struct sctp_association *asoc; |
| 7808 |
struct sctp_event param; |
| 7809 |
__u16 subscribe; |
| 7810 |
|
| 7811 |
if (len < sizeof(param)) |
| 7812 |
return -EINVAL; |
| 7813 |
|
| 7814 |
len = sizeof(param); |
| 7815 |
if (copy_from_user(¶m, optval, len)) |
| 7816 |
return -EFAULT; |
| 7817 |
|
| 7818 |
if (param.se_type < SCTP_SN_TYPE_BASE || |
| 7819 |
param.se_type > SCTP_SN_TYPE_MAX) |
| 7820 |
return -EINVAL; |
| 7821 |
|
| 7822 |
asoc = sctp_id2assoc(sk, param.se_assoc_id); |
| 7823 |
if (!asoc && param.se_assoc_id != SCTP_FUTURE_ASSOC && |
| 7824 |
sctp_style(sk, UDP)) |
| 7825 |
return -EINVAL; |
| 7826 |
|
| 7827 |
subscribe = asoc ? asoc->subscribe : sctp_sk(sk)->subscribe; |
| 7828 |
param.se_on = sctp_ulpevent_type_enabled(subscribe, param.se_type); |
| 7829 |
|
| 7830 |
if (put_user(len, optlen)) |
| 7831 |
return -EFAULT; |
| 7832 |
|
| 7833 |
if (copy_to_user(optval, ¶m, len)) |
| 7834 |
return -EFAULT; |
| 7835 |
|
| 7836 |
return 0; |
| 7837 |
} |
| 7838 |
|
| 7839 |
static int sctp_getsockopt_asconf_supported(struct sock *sk, int len, |
| 7840 |
char __user *optval, |
| 7841 |
int __user *optlen) |
| 7842 |
{ |
| 7843 |
struct sctp_assoc_value params; |
| 7844 |
struct sctp_association *asoc; |
| 7845 |
int retval = -EFAULT; |
| 7846 |
|
| 7847 |
if (len < sizeof(params)) { |
| 7848 |
retval = -EINVAL; |
| 7849 |
goto out; |
| 7850 |
} |
| 7851 |
|
| 7852 |
len = sizeof(params); |
| 7853 |
if (copy_from_user(¶ms, optval, len)) |
| 7854 |
goto out; |
| 7855 |
|
| 7856 |
asoc = sctp_id2assoc(sk, params.assoc_id); |
| 7857 |
if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC && |
| 7858 |
sctp_style(sk, UDP)) { |
| 7859 |
retval = -EINVAL; |
| 7860 |
goto out; |
| 7861 |
} |
| 7862 |
|
| 7863 |
params.assoc_value = asoc ? asoc->peer.asconf_capable |
| 7864 |
: sctp_sk(sk)->ep->asconf_enable; |
| 7865 |
|
| 7866 |
if (put_user(len, optlen)) |
| 7867 |
goto out; |
| 7868 |
|
| 7869 |
if (copy_to_user(optval, ¶ms, len)) |
| 7870 |
goto out; |
| 7871 |
|
| 7872 |
retval = 0; |
| 7873 |
|
| 7874 |
out: |
| 7875 |
return retval; |
| 7876 |
} |
| 7877 |
|
| 7878 |
static int sctp_getsockopt_auth_supported(struct sock *sk, int len, |
| 7879 |
char __user *optval, |
| 7880 |
int __user *optlen) |
| 7881 |
{ |
| 7882 |
struct sctp_assoc_value params; |
| 7883 |
struct sctp_association *asoc; |
| 7884 |
int retval = -EFAULT; |
| 7885 |
|
| 7886 |
if (len < sizeof(params)) { |
| 7887 |
retval = -EINVAL; |
| 7888 |
goto out; |
| 7889 |
} |
| 7890 |
|
| 7891 |
len = sizeof(params); |
| 7892 |
if (copy_from_user(¶ms, optval, len)) |
| 7893 |
goto out; |
| 7894 |
|
| 7895 |
asoc = sctp_id2assoc(sk, params.assoc_id); |
| 7896 |
if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC && |
| 7897 |
sctp_style(sk, UDP)) { |
| 7898 |
retval = -EINVAL; |
| 7899 |
goto out; |
| 7900 |
} |
| 7901 |
|
| 7902 |
params.assoc_value = asoc ? asoc->peer.auth_capable |
| 7903 |
: sctp_sk(sk)->ep->auth_enable; |
| 7904 |
|
| 7905 |
if (put_user(len, optlen)) |
| 7906 |
goto out; |
| 7907 |
|
| 7908 |
if (copy_to_user(optval, ¶ms, len)) |
| 7909 |
goto out; |
| 7910 |
|
| 7911 |
retval = 0; |
| 7912 |
|
| 7913 |
out: |
| 7914 |
return retval; |
| 7915 |
} |
| 7916 |
|
| 7917 |
static int sctp_getsockopt_ecn_supported(struct sock *sk, int len, |
| 7918 |
char __user *optval, |
| 7919 |
int __user *optlen) |
| 7920 |
{ |
| 7921 |
struct sctp_assoc_value params; |
| 7922 |
struct sctp_association *asoc; |
| 7923 |
int retval = -EFAULT; |
| 7924 |
|
| 7925 |
if (len < sizeof(params)) { |
| 7926 |
retval = -EINVAL; |
| 7927 |
goto out; |
| 7928 |
} |
| 7929 |
|
| 7930 |
len = sizeof(params); |
| 7931 |
if (copy_from_user(¶ms, optval, len)) |
| 7932 |
goto out; |
| 7933 |
|
| 7934 |
asoc = sctp_id2assoc(sk, params.assoc_id); |
| 7935 |
if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC && |
| 7936 |
sctp_style(sk, UDP)) { |
| 7937 |
retval = -EINVAL; |
| 7938 |
goto out; |
| 7939 |
} |
| 7940 |
|
| 7941 |
params.assoc_value = asoc ? asoc->peer.ecn_capable |
| 7942 |
: sctp_sk(sk)->ep->ecn_enable; |
| 7943 |
|
| 7944 |
if (put_user(len, optlen)) |
| 7945 |
goto out; |
| 7946 |
|
| 7947 |
if (copy_to_user(optval, ¶ms, len)) |
| 7948 |
goto out; |
| 7949 |
|
| 7950 |
retval = 0; |
| 7951 |
|
| 7952 |
out: |
| 7953 |
return retval; |
| 7954 |
} |
| 7955 |
|
| 7956 |
static int sctp_getsockopt_pf_expose(struct sock *sk, int len, |
| 7957 |
char __user *optval, |
| 7958 |
int __user *optlen) |
| 7959 |
{ |
| 7960 |
struct sctp_assoc_value params; |
| 7961 |
struct sctp_association *asoc; |
| 7962 |
int retval = -EFAULT; |
| 7963 |
|
| 7964 |
if (len < sizeof(params)) { |
| 7965 |
retval = -EINVAL; |
| 7966 |
goto out; |
| 7967 |
} |
| 7968 |
|
| 7969 |
len = sizeof(params); |
| 7970 |
if (copy_from_user(¶ms, optval, len)) |
| 7971 |
goto out; |
| 7972 |
|
| 7973 |
asoc = sctp_id2assoc(sk, params.assoc_id); |
| 7974 |
if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC && |
| 7975 |
sctp_style(sk, UDP)) { |
| 7976 |
retval = -EINVAL; |
| 7977 |
goto out; |
| 7978 |
} |
| 7979 |
|
| 7980 |
params.assoc_value = asoc ? asoc->pf_expose |
| 7981 |
: sctp_sk(sk)->pf_expose; |
| 7982 |
|
| 7983 |
if (put_user(len, optlen)) |
| 7984 |
goto out; |
| 7985 |
|
| 7986 |
if (copy_to_user(optval, ¶ms, len)) |
| 7987 |
goto out; |
| 7988 |
|
| 7989 |
retval = 0; |
| 7990 |
|
| 7991 |
out: |
| 7992 |
return retval; |
| 7993 |
} |
| 7994 |
|
| 7995 |
static int sctp_getsockopt_encap_port(struct sock *sk, int len, |
| 7996 |
char __user *optval, int __user *optlen) |
| 7997 |
{ |
| 7998 |
struct sctp_association *asoc; |
| 7999 |
struct sctp_udpencaps encap; |
| 8000 |
struct sctp_transport *t; |
| 8001 |
__be16 encap_port; |
| 8002 |
|
| 8003 |
if (len < sizeof(encap)) |
| 8004 |
return -EINVAL; |
| 8005 |
|
| 8006 |
len = sizeof(encap); |
| 8007 |
if (copy_from_user(&encap, optval, len)) |
| 8008 |
return -EFAULT; |
| 8009 |
|
| 8010 |
/* If an address other than INADDR_ANY is specified, and |
| 8011 |
* no transport is found, then the request is invalid. |
| 8012 |
*/ |
| 8013 |
if (!sctp_is_any(sk, (union sctp_addr *)&encap.sue_address)) { |
| 8014 |
t = sctp_addr_id2transport(sk, &encap.sue_address, |
| 8015 |
encap.sue_assoc_id); |
| 8016 |
if (!t) { |
| 8017 |
pr_debug("%s: failed no transport\n", __func__); |
| 8018 |
return -EINVAL; |
| 8019 |
} |
| 8020 |
|
| 8021 |
encap_port = t->encap_port; |
| 8022 |
goto out; |
| 8023 |
} |
| 8024 |
|
| 8025 |
/* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the |
| 8026 |
* socket is a one to many style socket, and an association |
| 8027 |
* was not found, then the id was invalid. |
| 8028 |
*/ |
| 8029 |
asoc = sctp_id2assoc(sk, encap.sue_assoc_id); |
| 8030 |
if (!asoc && encap.sue_assoc_id != SCTP_FUTURE_ASSOC && |
| 8031 |
sctp_style(sk, UDP)) { |
| 8032 |
pr_debug("%s: failed no association\n", __func__); |
| 8033 |
return -EINVAL; |
| 8034 |
} |
| 8035 |
|
| 8036 |
if (asoc) { |
| 8037 |
encap_port = asoc->encap_port; |
| 8038 |
goto out; |
| 8039 |
} |
| 8040 |
|
| 8041 |
encap_port = sctp_sk(sk)->encap_port; |
| 8042 |
|
| 8043 |
out: |
| 8044 |
encap.sue_port = (__force uint16_t)encap_port; |
| 8045 |
if (copy_to_user(optval, &encap, len)) |
| 8046 |
return -EFAULT; |
| 8047 |
|
| 8048 |
if (put_user(len, optlen)) |
| 8049 |
return -EFAULT; |
| 8050 |
|
| 8051 |
return 0; |
| 8052 |
} |
| 8053 |
|
| 8054 |
static int sctp_getsockopt_probe_interval(struct sock *sk, int len, |
| 8055 |
char __user *optval, |
| 8056 |
int __user *optlen) |
| 8057 |
{ |
| 8058 |
struct sctp_probeinterval params; |
| 8059 |
struct sctp_association *asoc; |
| 8060 |
struct sctp_transport *t; |
| 8061 |
__u32 probe_interval; |
| 8062 |
|
| 8063 |
if (len < sizeof(params)) |
| 8064 |
return -EINVAL; |
| 8065 |
|
| 8066 |
len = sizeof(params); |
| 8067 |
if (copy_from_user(¶ms, optval, len)) |
| 8068 |
return -EFAULT; |
| 8069 |
|
| 8070 |
/* If an address other than INADDR_ANY is specified, and |
| 8071 |
* no transport is found, then the request is invalid. |
| 8072 |
*/ |
| 8073 |
if (!sctp_is_any(sk, (union sctp_addr *)¶ms.spi_address)) { |
| 8074 |
t = sctp_addr_id2transport(sk, ¶ms.spi_address, |
| 8075 |
params.spi_assoc_id); |
| 8076 |
if (!t) { |
| 8077 |
pr_debug("%s: failed no transport\n", __func__); |
| 8078 |
return -EINVAL; |
| 8079 |
} |
| 8080 |
|
| 8081 |
probe_interval = jiffies_to_msecs(t->probe_interval); |
| 8082 |
goto out; |
| 8083 |
} |
| 8084 |
|
| 8085 |
/* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the |
| 8086 |
* socket is a one to many style socket, and an association |
| 8087 |
* was not found, then the id was invalid. |
| 8088 |
*/ |
| 8089 |
asoc = sctp_id2assoc(sk, params.spi_assoc_id); |
| 8090 |
if (!asoc && params.spi_assoc_id != SCTP_FUTURE_ASSOC && |
| 8091 |
sctp_style(sk, UDP)) { |
| 8092 |
pr_debug("%s: failed no association\n", __func__); |
| 8093 |
return -EINVAL; |
| 8094 |
} |
| 8095 |
|
| 8096 |
if (asoc) { |
| 8097 |
probe_interval = jiffies_to_msecs(asoc->probe_interval); |
| 8098 |
goto out; |
| 8099 |
} |
| 8100 |
|
| 8101 |
probe_interval = sctp_sk(sk)->probe_interval; |
| 8102 |
|
| 8103 |
out: |
| 8104 |
params.spi_interval = probe_interval; |
| 8105 |
if (copy_to_user(optval, ¶ms, len)) |
| 8106 |
return -EFAULT; |
| 8107 |
|
| 8108 |
if (put_user(len, optlen)) |
| 8109 |
return -EFAULT; |
| 8110 |
|
| 8111 |
return 0; |
| 8112 |
} |
| 8113 |
|
| 8114 |
static int sctp_getsockopt(struct sock *sk, int level, int optname, |
| 8115 |
char __user *optval, int __user *optlen) |
| 8116 |
{ |
| 8117 |
int retval = 0; |
| 8118 |
int len; |
| 8119 |
|
| 8120 |
pr_debug("%s: sk:%p, optname:%d\n", __func__, sk, optname); |
| 8121 |
|
| 8122 |
/* I can hardly begin to describe how wrong this is. This is |
| 8123 |
* so broken as to be worse than useless. The API draft |
| 8124 |
* REALLY is NOT helpful here... I am not convinced that the |
| 8125 |
* semantics of getsockopt() with a level OTHER THAN SOL_SCTP |
| 8126 |
* are at all well-founded. |
| 8127 |
*/ |
| 8128 |
if (level != SOL_SCTP) { |
| 8129 |
struct sctp_af *af = sctp_sk(sk)->pf->af; |
| 8130 |
|
| 8131 |
retval = af->getsockopt(sk, level, optname, optval, optlen); |
| 8132 |
return retval; |
| 8133 |
} |
| 8134 |
|
| 8135 |
if (get_user(len, optlen)) |
| 8136 |
return -EFAULT; |
| 8137 |
|
| 8138 |
if (len < 0) |
| 8139 |
return -EINVAL; |
| 8140 |
|
| 8141 |
lock_sock(sk); |
| 8142 |
|
| 8143 |
switch (optname) { |
| 8144 |
case SCTP_STATUS: |
| 8145 |
retval = sctp_getsockopt_sctp_status(sk, len, optval, optlen); |
| 8146 |
break; |
| 8147 |
case SCTP_DISABLE_FRAGMENTS: |
| 8148 |
retval = sctp_getsockopt_disable_fragments(sk, len, optval, |
| 8149 |
optlen); |
| 8150 |
break; |
| 8151 |
case SCTP_EVENTS: |
| 8152 |
retval = sctp_getsockopt_events(sk, len, optval, optlen); |
| 8153 |
break; |
| 8154 |
case SCTP_AUTOCLOSE: |
| 8155 |
retval = sctp_getsockopt_autoclose(sk, len, optval, optlen); |
| 8156 |
break; |
| 8157 |
case SCTP_SOCKOPT_PEELOFF: |
| 8158 |
retval = sctp_getsockopt_peeloff(sk, len, optval, optlen); |
| 8159 |
break; |
| 8160 |
case SCTP_SOCKOPT_PEELOFF_FLAGS: |
| 8161 |
retval = sctp_getsockopt_peeloff_flags(sk, len, optval, optlen); |
| 8162 |
break; |
| 8163 |
case SCTP_PEER_ADDR_PARAMS: |
| 8164 |
retval = sctp_getsockopt_peer_addr_params(sk, len, optval, |
| 8165 |
optlen); |
| 8166 |
break; |
| 8167 |
case SCTP_DELAYED_SACK: |
| 8168 |
retval = sctp_getsockopt_delayed_ack(sk, len, optval, |
| 8169 |
optlen); |
| 8170 |
break; |
| 8171 |
case SCTP_INITMSG: |
| 8172 |
retval = sctp_getsockopt_initmsg(sk, len, optval, optlen); |
| 8173 |
break; |
| 8174 |
case SCTP_GET_PEER_ADDRS: |
| 8175 |
retval = sctp_getsockopt_peer_addrs(sk, len, optval, |
| 8176 |
optlen); |
| 8177 |
break; |
| 8178 |
case SCTP_GET_LOCAL_ADDRS: |
| 8179 |
retval = sctp_getsockopt_local_addrs(sk, len, optval, |
| 8180 |
optlen); |
| 8181 |
break; |
| 8182 |
case SCTP_SOCKOPT_CONNECTX3: |
| 8183 |
retval = sctp_getsockopt_connectx3(sk, len, optval, optlen); |
| 8184 |
break; |
| 8185 |
case SCTP_DEFAULT_SEND_PARAM: |
| 8186 |
retval = sctp_getsockopt_default_send_param(sk, len, |
| 8187 |
optval, optlen); |
| 8188 |
break; |
| 8189 |
case SCTP_DEFAULT_SNDINFO: |
| 8190 |
retval = sctp_getsockopt_default_sndinfo(sk, len, |
| 8191 |
optval, optlen); |
| 8192 |
break; |
| 8193 |
case SCTP_PRIMARY_ADDR: |
| 8194 |
retval = sctp_getsockopt_primary_addr(sk, len, optval, optlen); |
| 8195 |
break; |
| 8196 |
case SCTP_NODELAY: |
| 8197 |
retval = sctp_getsockopt_nodelay(sk, len, optval, optlen); |
| 8198 |
break; |
| 8199 |
case SCTP_RTOINFO: |
| 8200 |
retval = sctp_getsockopt_rtoinfo(sk, len, optval, optlen); |
| 8201 |
break; |
| 8202 |
case SCTP_ASSOCINFO: |
| 8203 |
retval = sctp_getsockopt_associnfo(sk, len, optval, optlen); |
| 8204 |
break; |
| 8205 |
case SCTP_I_WANT_MAPPED_V4_ADDR: |
| 8206 |
retval = sctp_getsockopt_mappedv4(sk, len, optval, optlen); |
| 8207 |
break; |
| 8208 |
case SCTP_MAXSEG: |
| 8209 |
retval = sctp_getsockopt_maxseg(sk, len, optval, optlen); |
| 8210 |
break; |
| 8211 |
case SCTP_GET_PEER_ADDR_INFO: |
| 8212 |
retval = sctp_getsockopt_peer_addr_info(sk, len, optval, |
| 8213 |
optlen); |
| 8214 |
break; |
| 8215 |
case SCTP_ADAPTATION_LAYER: |
| 8216 |
retval = sctp_getsockopt_adaptation_layer(sk, len, optval, |
| 8217 |
optlen); |
| 8218 |
break; |
| 8219 |
case SCTP_CONTEXT: |
| 8220 |
retval = sctp_getsockopt_context(sk, len, optval, optlen); |
| 8221 |
break; |
| 8222 |
case SCTP_FRAGMENT_INTERLEAVE: |
| 8223 |
retval = sctp_getsockopt_fragment_interleave(sk, len, optval, |
| 8224 |
optlen); |
| 8225 |
break; |
| 8226 |
case SCTP_PARTIAL_DELIVERY_POINT: |
| 8227 |
retval = sctp_getsockopt_partial_delivery_point(sk, len, optval, |
| 8228 |
optlen); |
| 8229 |
break; |
| 8230 |
case SCTP_MAX_BURST: |
| 8231 |
retval = sctp_getsockopt_maxburst(sk, len, optval, optlen); |
| 8232 |
break; |
| 8233 |
case SCTP_AUTH_KEY: |
| 8234 |
case SCTP_AUTH_CHUNK: |
| 8235 |
case SCTP_AUTH_DELETE_KEY: |
| 8236 |
case SCTP_AUTH_DEACTIVATE_KEY: |
| 8237 |
retval = -EOPNOTSUPP; |
| 8238 |
break; |
| 8239 |
case SCTP_HMAC_IDENT: |
| 8240 |
retval = sctp_getsockopt_hmac_ident(sk, len, optval, optlen); |
| 8241 |
break; |
| 8242 |
case SCTP_AUTH_ACTIVE_KEY: |
| 8243 |
retval = sctp_getsockopt_active_key(sk, len, optval, optlen); |
| 8244 |
break; |
| 8245 |
case SCTP_PEER_AUTH_CHUNKS: |
| 8246 |
retval = sctp_getsockopt_peer_auth_chunks(sk, len, optval, |
| 8247 |
optlen); |
| 8248 |
break; |
| 8249 |
case SCTP_LOCAL_AUTH_CHUNKS: |
| 8250 |
retval = sctp_getsockopt_local_auth_chunks(sk, len, optval, |
| 8251 |
optlen); |
| 8252 |
break; |
| 8253 |
case SCTP_GET_ASSOC_NUMBER: |
| 8254 |
retval = sctp_getsockopt_assoc_number(sk, len, optval, optlen); |
| 8255 |
break; |
| 8256 |
case SCTP_GET_ASSOC_ID_LIST: |
| 8257 |
retval = sctp_getsockopt_assoc_ids(sk, len, optval, optlen); |
| 8258 |
break; |
| 8259 |
case SCTP_AUTO_ASCONF: |
| 8260 |
retval = sctp_getsockopt_auto_asconf(sk, len, optval, optlen); |
| 8261 |
break; |
| 8262 |
case SCTP_PEER_ADDR_THLDS: |
| 8263 |
retval = sctp_getsockopt_paddr_thresholds(sk, optval, len, |
| 8264 |
optlen, false); |
| 8265 |
break; |
| 8266 |
case SCTP_PEER_ADDR_THLDS_V2: |
| 8267 |
retval = sctp_getsockopt_paddr_thresholds(sk, optval, len, |
| 8268 |
optlen, true); |
| 8269 |
break; |
| 8270 |
case SCTP_GET_ASSOC_STATS: |
| 8271 |
retval = sctp_getsockopt_assoc_stats(sk, len, optval, optlen); |
| 8272 |
break; |
| 8273 |
case SCTP_RECVRCVINFO: |
| 8274 |
retval = sctp_getsockopt_recvrcvinfo(sk, len, optval, optlen); |
| 8275 |
break; |
| 8276 |
case SCTP_RECVNXTINFO: |
| 8277 |
retval = sctp_getsockopt_recvnxtinfo(sk, len, optval, optlen); |
| 8278 |
break; |
| 8279 |
case SCTP_PR_SUPPORTED: |
| 8280 |
retval = sctp_getsockopt_pr_supported(sk, len, optval, optlen); |
| 8281 |
break; |
| 8282 |
case SCTP_DEFAULT_PRINFO: |
| 8283 |
retval = sctp_getsockopt_default_prinfo(sk, len, optval, |
| 8284 |
optlen); |
| 8285 |
break; |
| 8286 |
case SCTP_PR_ASSOC_STATUS: |
| 8287 |
retval = sctp_getsockopt_pr_assocstatus(sk, len, optval, |
| 8288 |
optlen); |
| 8289 |
break; |
| 8290 |
case SCTP_PR_STREAM_STATUS: |
| 8291 |
retval = sctp_getsockopt_pr_streamstatus(sk, len, optval, |
| 8292 |
optlen); |
| 8293 |
break; |
| 8294 |
case SCTP_RECONFIG_SUPPORTED: |
| 8295 |
retval = sctp_getsockopt_reconfig_supported(sk, len, optval, |
| 8296 |
optlen); |
| 8297 |
break; |
| 8298 |
case SCTP_ENABLE_STREAM_RESET: |
| 8299 |
retval = sctp_getsockopt_enable_strreset(sk, len, optval, |
| 8300 |
optlen); |
| 8301 |
break; |
| 8302 |
case SCTP_STREAM_SCHEDULER: |
| 8303 |
retval = sctp_getsockopt_scheduler(sk, len, optval, |
| 8304 |
optlen); |
| 8305 |
break; |
| 8306 |
case SCTP_STREAM_SCHEDULER_VALUE: |
| 8307 |
retval = sctp_getsockopt_scheduler_value(sk, len, optval, |
| 8308 |
optlen); |
| 8309 |
break; |
| 8310 |
case SCTP_INTERLEAVING_SUPPORTED: |
| 8311 |
retval = sctp_getsockopt_interleaving_supported(sk, len, optval, |
| 8312 |
optlen); |
| 8313 |
break; |
| 8314 |
case SCTP_REUSE_PORT: |
| 8315 |
retval = sctp_getsockopt_reuse_port(sk, len, optval, optlen); |
| 8316 |
break; |
| 8317 |
case SCTP_EVENT: |
| 8318 |
retval = sctp_getsockopt_event(sk, len, optval, optlen); |
| 8319 |
break; |
| 8320 |
case SCTP_ASCONF_SUPPORTED: |
| 8321 |
retval = sctp_getsockopt_asconf_supported(sk, len, optval, |
| 8322 |
optlen); |
| 8323 |
break; |
| 8324 |
case SCTP_AUTH_SUPPORTED: |
| 8325 |
retval = sctp_getsockopt_auth_supported(sk, len, optval, |
| 8326 |
optlen); |
| 8327 |
break; |
| 8328 |
case SCTP_ECN_SUPPORTED: |
| 8329 |
retval = sctp_getsockopt_ecn_supported(sk, len, optval, optlen); |
| 8330 |
break; |
| 8331 |
case SCTP_EXPOSE_POTENTIALLY_FAILED_STATE: |
| 8332 |
retval = sctp_getsockopt_pf_expose(sk, len, optval, optlen); |
| 8333 |
break; |
| 8334 |
case SCTP_REMOTE_UDP_ENCAPS_PORT: |
| 8335 |
retval = sctp_getsockopt_encap_port(sk, len, optval, optlen); |
| 8336 |
break; |
| 8337 |
case SCTP_PLPMTUD_PROBE_INTERVAL: |
| 8338 |
retval = sctp_getsockopt_probe_interval(sk, len, optval, optlen); |
| 8339 |
break; |
| 8340 |
default: |
| 8341 |
retval = -ENOPROTOOPT; |
| 8342 |
break; |
| 8343 |
} |
| 8344 |
|
| 8345 |
release_sock(sk); |
| 8346 |
return retval; |
| 8347 |
} |
| 8348 |
|
| 8349 |
static bool sctp_bpf_bypass_getsockopt(int level, int optname) |
| 8350 |
{ |
| 8351 |
if (level == SOL_SCTP) { |
| 8352 |
switch (optname) { |
| 8353 |
case SCTP_SOCKOPT_PEELOFF: |
| 8354 |
case SCTP_SOCKOPT_PEELOFF_FLAGS: |
| 8355 |
case SCTP_SOCKOPT_CONNECTX3: |
| 8356 |
return true; |
| 8357 |
default: |
| 8358 |
return false; |
| 8359 |
} |
| 8360 |
} |
| 8361 |
|
| 8362 |
return false; |
| 8363 |
} |
| 8364 |
|
| 8365 |
static int sctp_hash(struct sock *sk) |
| 8366 |
{ |
| 8367 |
/* STUB */ |
| 8368 |
return 0; |
| 8369 |
} |
| 8370 |
|
| 8371 |
static void sctp_unhash(struct sock *sk) |
| 8372 |
{ |
| 8373 |
sock_rps_delete_flow(sk); |
| 8374 |
} |
| 8375 |
|
| 8376 |
/* Check if port is acceptable. Possibly find first available port. |
| 8377 |
* |
| 8378 |
* The port hash table (contained in the 'global' SCTP protocol storage |
| 8379 |
* returned by struct sctp_protocol *sctp_get_protocol()). The hash |
| 8380 |
* table is an array of 4096 lists (sctp_bind_hashbucket). Each |
| 8381 |
* list (the list number is the port number hashed out, so as you |
| 8382 |
* would expect from a hash function, all the ports in a given list have |
| 8383 |
* such a number that hashes out to the same list number; you were |
| 8384 |
* expecting that, right?); so each list has a set of ports, with a |
| 8385 |
* link to the socket (struct sock) that uses it, the port number and |
| 8386 |
* a fastreuse flag (FIXME: NPI ipg). |
| 8387 |
*/ |
| 8388 |
static struct sctp_bind_bucket *sctp_bucket_create( |
| 8389 |
struct sctp_bind_hashbucket *head, struct net *, unsigned short snum); |
| 8390 |
|
| 8391 |
static int sctp_get_port_local(struct sock *sk, union sctp_addr *addr) |
| 8392 |
{ |
| 8393 |
struct sctp_sock *sp = sctp_sk(sk); |
| 8394 |
bool reuse = (sk->sk_reuse || sp->reuse); |
| 8395 |
struct sctp_bind_hashbucket *head; /* hash list */ |
| 8396 |
struct net *net = sock_net(sk); |
| 8397 |
struct sctp_bind_bucket *pp; |
| 8398 |
kuid_t uid = sk_uid(sk); |
| 8399 |
unsigned short snum; |
| 8400 |
int ret; |
| 8401 |
|
| 8402 |
snum = ntohs(addr->v4.sin_port); |
| 8403 |
|
| 8404 |
pr_debug("%s: begins, snum:%d\n", __func__, snum); |
| 8405 |
|
| 8406 |
if (snum == 0) { |
| 8407 |
/* Search for an available port. */ |
| 8408 |
int low, high, remaining, index; |
| 8409 |
unsigned int rover; |
| 8410 |
|
| 8411 |
inet_sk_get_local_port_range(sk, &low, &high); |
| 8412 |
remaining = (high - low) + 1; |
| 8413 |
rover = get_random_u32_below(remaining) + low; |
| 8414 |
|
| 8415 |
do { |
| 8416 |
rover++; |
| 8417 |
if ((rover < low) || (rover > high)) |
| 8418 |
rover = low; |
| 8419 |
if (inet_is_local_reserved_port(net, rover)) |
| 8420 |
continue; |
| 8421 |
index = sctp_phashfn(net, rover); |
| 8422 |
head = &sctp_port_hashtable[index]; |
| 8423 |
spin_lock_bh(&head->lock); |
| 8424 |
sctp_for_each_hentry(pp, &head->chain) |
| 8425 |
if ((pp->port == rover) && |
| 8426 |
net_eq(net, pp->net)) |
| 8427 |
goto next; |
| 8428 |
break; |
| 8429 |
next: |
| 8430 |
spin_unlock_bh(&head->lock); |
| 8431 |
cond_resched(); |
| 8432 |
} while (--remaining > 0); |
| 8433 |
|
| 8434 |
/* Exhausted local port range during search? */ |
| 8435 |
ret = 1; |
| 8436 |
if (remaining <= 0) |
| 8437 |
return ret; |
| 8438 |
|
| 8439 |
/* OK, here is the one we will use. HEAD (the port |
| 8440 |
* hash table list entry) is non-NULL and we hold it's |
| 8441 |
* mutex. |
| 8442 |
*/ |
| 8443 |
snum = rover; |
| 8444 |
} else { |
| 8445 |
/* We are given an specific port number; we verify |
| 8446 |
* that it is not being used. If it is used, we will |
| 8447 |
* exahust the search in the hash list corresponding |
| 8448 |
* to the port number (snum) - we detect that with the |
| 8449 |
* port iterator, pp being NULL. |
| 8450 |
*/ |
| 8451 |
head = &sctp_port_hashtable[sctp_phashfn(net, snum)]; |
| 8452 |
spin_lock_bh(&head->lock); |
| 8453 |
sctp_for_each_hentry(pp, &head->chain) { |
| 8454 |
if ((pp->port == snum) && net_eq(pp->net, net)) |
| 8455 |
goto pp_found; |
| 8456 |
} |
| 8457 |
} |
| 8458 |
pp = NULL; |
| 8459 |
goto pp_not_found; |
| 8460 |
pp_found: |
| 8461 |
if (!hlist_empty(&pp->owner)) { |
| 8462 |
/* We had a port hash table hit - there is an |
| 8463 |
* available port (pp != NULL) and it is being |
| 8464 |
* used by other socket (pp->owner not empty); that other |
| 8465 |
* socket is going to be sk2. |
| 8466 |
*/ |
| 8467 |
struct sock *sk2; |
| 8468 |
|
| 8469 |
pr_debug("%s: found a possible match\n", __func__); |
| 8470 |
|
| 8471 |
if ((pp->fastreuse && reuse && |
| 8472 |
sk->sk_state != SCTP_SS_LISTENING) || |
| 8473 |
(pp->fastreuseport && sk->sk_reuseport && |
| 8474 |
uid_eq(pp->fastuid, uid))) |
| 8475 |
goto success; |
| 8476 |
|
| 8477 |
/* Run through the list of sockets bound to the port |
| 8478 |
* (pp->port) [via the pointers bind_next and |
| 8479 |
* bind_pprev in the struct sock *sk2 (pp->sk)]. On each one, |
| 8480 |
* we get the endpoint they describe and run through |
| 8481 |
* the endpoint's list of IP (v4 or v6) addresses, |
| 8482 |
* comparing each of the addresses with the address of |
| 8483 |
* the socket sk. If we find a match, then that means |
| 8484 |
* that this port/socket (sk) combination are already |
| 8485 |
* in an endpoint. |
| 8486 |
*/ |
| 8487 |
sk_for_each_bound(sk2, &pp->owner) { |
| 8488 |
int bound_dev_if2 = READ_ONCE(sk2->sk_bound_dev_if); |
| 8489 |
struct sctp_sock *sp2 = sctp_sk(sk2); |
| 8490 |
struct sctp_endpoint *ep2 = sp2->ep; |
| 8491 |
|
| 8492 |
if (sk == sk2 || |
| 8493 |
(reuse && (sk2->sk_reuse || sp2->reuse) && |
| 8494 |
sk2->sk_state != SCTP_SS_LISTENING) || |
| 8495 |
(sk->sk_reuseport && sk2->sk_reuseport && |
| 8496 |
uid_eq(uid, sk_uid(sk2)))) |
| 8497 |
continue; |
| 8498 |
|
| 8499 |
if ((!sk->sk_bound_dev_if || !bound_dev_if2 || |
| 8500 |
sk->sk_bound_dev_if == bound_dev_if2) && |
| 8501 |
sctp_bind_addr_conflict(&ep2->base.bind_addr, |
| 8502 |
addr, sp2, sp)) { |
| 8503 |
ret = 1; |
| 8504 |
goto fail_unlock; |
| 8505 |
} |
| 8506 |
} |
| 8507 |
|
| 8508 |
pr_debug("%s: found a match\n", __func__); |
| 8509 |
} |
| 8510 |
pp_not_found: |
| 8511 |
/* If there was a hash table miss, create a new port. */ |
| 8512 |
ret = 1; |
| 8513 |
if (!pp && !(pp = sctp_bucket_create(head, net, snum))) |
| 8514 |
goto fail_unlock; |
| 8515 |
|
| 8516 |
/* In either case (hit or miss), make sure fastreuse is 1 only |
| 8517 |
* if sk->sk_reuse is too (that is, if the caller requested |
| 8518 |
* SO_REUSEADDR on this socket -sk-). |
| 8519 |
*/ |
| 8520 |
if (hlist_empty(&pp->owner)) { |
| 8521 |
if (reuse && sk->sk_state != SCTP_SS_LISTENING) |
| 8522 |
pp->fastreuse = 1; |
| 8523 |
else |
| 8524 |
pp->fastreuse = 0; |
| 8525 |
|
| 8526 |
if (sk->sk_reuseport) { |
| 8527 |
pp->fastreuseport = 1; |
| 8528 |
pp->fastuid = uid; |
| 8529 |
} else { |
| 8530 |
pp->fastreuseport = 0; |
| 8531 |
} |
| 8532 |
} else { |
| 8533 |
if (pp->fastreuse && |
| 8534 |
(!reuse || sk->sk_state == SCTP_SS_LISTENING)) |
| 8535 |
pp->fastreuse = 0; |
| 8536 |
|
| 8537 |
if (pp->fastreuseport && |
| 8538 |
(!sk->sk_reuseport || !uid_eq(pp->fastuid, uid))) |
| 8539 |
pp->fastreuseport = 0; |
| 8540 |
} |
| 8541 |
|
| 8542 |
/* We are set, so fill up all the data in the hash table |
| 8543 |
* entry, tie the socket list information with the rest of the |
| 8544 |
* sockets FIXME: Blurry, NPI (ipg). |
| 8545 |
*/ |
| 8546 |
success: |
| 8547 |
if (!sp->bind_hash) { |
| 8548 |
inet_sk(sk)->inet_num = snum; |
| 8549 |
sk_add_bind_node(sk, &pp->owner); |
| 8550 |
sp->bind_hash = pp; |
| 8551 |
} |
| 8552 |
ret = 0; |
| 8553 |
|
| 8554 |
fail_unlock: |
| 8555 |
spin_unlock_bh(&head->lock); |
| 8556 |
return ret; |
| 8557 |
} |
| 8558 |
|
| 8559 |
/* Assign a 'snum' port to the socket. If snum == 0, an ephemeral |
| 8560 |
* port is requested. |
| 8561 |
*/ |
| 8562 |
static int sctp_get_port(struct sock *sk, unsigned short snum) |
| 8563 |
{ |
| 8564 |
union sctp_addr addr; |
| 8565 |
struct sctp_af *af = sctp_sk(sk)->pf->af; |
| 8566 |
|
| 8567 |
/* Set up a dummy address struct from the sk. */ |
| 8568 |
af->from_sk(&addr, sk); |
| 8569 |
addr.v4.sin_port = htons(snum); |
| 8570 |
|
| 8571 |
/* Note: sk->sk_num gets filled in if ephemeral port request. */ |
| 8572 |
return sctp_get_port_local(sk, &addr); |
| 8573 |
} |
| 8574 |
|
| 8575 |
/* |
| 8576 |
* Move a socket to LISTENING state. |
| 8577 |
*/ |
| 8578 |
static int sctp_listen_start(struct sock *sk, int backlog) |
| 8579 |
{ |
| 8580 |
struct sctp_sock *sp = sctp_sk(sk); |
| 8581 |
struct sctp_endpoint *ep = sp->ep; |
| 8582 |
int err; |
| 8583 |
|
| 8584 |
/* |
| 8585 |
* If a bind() or sctp_bindx() is not called prior to a listen() |
| 8586 |
* call that allows new associations to be accepted, the system |
| 8587 |
* picks an ephemeral port and will choose an address set equivalent |
| 8588 |
* to binding with a wildcard address. |
| 8589 |
* |
| 8590 |
* This is not currently spelled out in the SCTP sockets |
| 8591 |
* extensions draft, but follows the practice as seen in TCP |
| 8592 |
* sockets. |
| 8593 |
* |
| 8594 |
*/ |
| 8595 |
inet_sk_set_state(sk, SCTP_SS_LISTENING); |
| 8596 |
if (!ep->base.bind_addr.port) { |
| 8597 |
if (sctp_autobind(sk)) { |
| 8598 |
err = -EAGAIN; |
| 8599 |
goto err; |
| 8600 |
} |
| 8601 |
} else { |
| 8602 |
if (sctp_get_port(sk, inet_sk(sk)->inet_num)) { |
| 8603 |
err = -EADDRINUSE; |
| 8604 |
goto err; |
| 8605 |
} |
| 8606 |
} |
| 8607 |
|
| 8608 |
WRITE_ONCE(sk->sk_max_ack_backlog, backlog); |
| 8609 |
err = sctp_hash_endpoint(ep); |
| 8610 |
if (err) |
| 8611 |
goto err; |
| 8612 |
|
| 8613 |
return 0; |
| 8614 |
err: |
| 8615 |
inet_sk_set_state(sk, SCTP_SS_CLOSED); |
| 8616 |
return err; |
| 8617 |
} |
| 8618 |
|
| 8619 |
/* |
| 8620 |
* 4.1.3 / 5.1.3 listen() |
| 8621 |
* |
| 8622 |
* By default, new associations are not accepted for UDP style sockets. |
| 8623 |
* An application uses listen() to mark a socket as being able to |
| 8624 |
* accept new associations. |
| 8625 |
* |
| 8626 |
* On TCP style sockets, applications use listen() to ready the SCTP |
| 8627 |
* endpoint for accepting inbound associations. |
| 8628 |
* |
| 8629 |
* On both types of endpoints a backlog of '0' disables listening. |
| 8630 |
* |
| 8631 |
* Move a socket to LISTENING state. |
| 8632 |
*/ |
| 8633 |
int sctp_inet_listen(struct socket *sock, int backlog) |
| 8634 |
{ |
| 8635 |
struct sock *sk = sock->sk; |
| 8636 |
struct sctp_endpoint *ep = sctp_sk(sk)->ep; |
| 8637 |
int err = -EINVAL; |
| 8638 |
|
| 8639 |
if (unlikely(backlog < 0)) |
| 8640 |
return err; |
| 8641 |
|
| 8642 |
lock_sock(sk); |
| 8643 |
|
| 8644 |
/* Peeled-off sockets are not allowed to listen(). */ |
| 8645 |
if (sctp_style(sk, UDP_HIGH_BANDWIDTH)) |
| 8646 |
goto out; |
| 8647 |
|
| 8648 |
if (sock->state != SS_UNCONNECTED) |
| 8649 |
goto out; |
| 8650 |
|
| 8651 |
if (!sctp_sstate(sk, LISTENING) && !sctp_sstate(sk, CLOSED)) |
| 8652 |
goto out; |
| 8653 |
|
| 8654 |
/* If backlog is zero, disable listening. */ |
| 8655 |
if (!backlog) { |
| 8656 |
if (sctp_sstate(sk, CLOSED)) |
| 8657 |
goto out; |
| 8658 |
|
| 8659 |
err = 0; |
| 8660 |
sctp_unhash_endpoint(ep); |
| 8661 |
sk->sk_state = SCTP_SS_CLOSED; |
| 8662 |
if (sk->sk_reuse || sctp_sk(sk)->reuse) |
| 8663 |
sctp_sk(sk)->bind_hash->fastreuse = 1; |
| 8664 |
goto out; |
| 8665 |
} |
| 8666 |
|
| 8667 |
/* If we are already listening, just update the backlog */ |
| 8668 |
if (sctp_sstate(sk, LISTENING)) |
| 8669 |
WRITE_ONCE(sk->sk_max_ack_backlog, backlog); |
| 8670 |
else { |
| 8671 |
err = sctp_listen_start(sk, backlog); |
| 8672 |
if (err) |
| 8673 |
goto out; |
| 8674 |
} |
| 8675 |
|
| 8676 |
err = 0; |
| 8677 |
out: |
| 8678 |
release_sock(sk); |
| 8679 |
return err; |
| 8680 |
} |
| 8681 |
|
| 8682 |
/* |
| 8683 |
* This function is done by modeling the current datagram_poll() and the |
| 8684 |
* tcp_poll(). Note that, based on these implementations, we don't |
| 8685 |
* lock the socket in this function, even though it seems that, |
| 8686 |
* ideally, locking or some other mechanisms can be used to ensure |
| 8687 |
* the integrity of the counters (sndbuf and wmem_alloc) used |
| 8688 |
* in this place. We assume that we don't need locks either until proven |
| 8689 |
* otherwise. |
| 8690 |
* |
| 8691 |
* Another thing to note is that we include the Async I/O support |
| 8692 |
* here, again, by modeling the current TCP/UDP code. We don't have |
| 8693 |
* a good way to test with it yet. |
| 8694 |
*/ |
| 8695 |
__poll_t sctp_poll(struct file *file, struct socket *sock, poll_table *wait) |
| 8696 |
{ |
| 8697 |
struct sock *sk = sock->sk; |
| 8698 |
struct sctp_sock *sp = sctp_sk(sk); |
| 8699 |
__poll_t mask; |
| 8700 |
|
| 8701 |
poll_wait(file, sk_sleep(sk), wait); |
| 8702 |
|
| 8703 |
sock_rps_record_flow(sk); |
| 8704 |
|
| 8705 |
/* A TCP-style listening socket becomes readable when the accept queue |
| 8706 |
* is not empty. |
| 8707 |
*/ |
| 8708 |
if (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING)) |
| 8709 |
return (!list_empty(&sp->ep->asocs)) ? |
| 8710 |
(EPOLLIN | EPOLLRDNORM) : 0; |
| 8711 |
|
| 8712 |
mask = 0; |
| 8713 |
|
| 8714 |
/* Is there any exceptional events? */ |
| 8715 |
if (sk->sk_err || !skb_queue_empty_lockless(&sk->sk_error_queue)) |
| 8716 |
mask |= EPOLLERR | |
| 8717 |
(sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? EPOLLPRI : 0); |
| 8718 |
if (sk->sk_shutdown & RCV_SHUTDOWN) |
| 8719 |
mask |= EPOLLRDHUP | EPOLLIN | EPOLLRDNORM; |
| 8720 |
if (sk->sk_shutdown == SHUTDOWN_MASK) |
| 8721 |
mask |= EPOLLHUP; |
| 8722 |
|
| 8723 |
/* Is it readable? Reconsider this code with TCP-style support. */ |
| 8724 |
if (!skb_queue_empty_lockless(&sk->sk_receive_queue)) |
| 8725 |
mask |= EPOLLIN | EPOLLRDNORM; |
| 8726 |
|
| 8727 |
/* The association is either gone or not ready. */ |
| 8728 |
if (!sctp_style(sk, UDP) && sctp_sstate(sk, CLOSED)) |
| 8729 |
return mask; |
| 8730 |
|
| 8731 |
/* Is it writable? */ |
| 8732 |
if (sctp_writeable(sk)) { |
| 8733 |
mask |= EPOLLOUT | EPOLLWRNORM; |
| 8734 |
} else { |
| 8735 |
sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk); |
| 8736 |
/* |
| 8737 |
* Since the socket is not locked, the buffer |
| 8738 |
* might be made available after the writeable check and |
| 8739 |
* before the bit is set. This could cause a lost I/O |
| 8740 |
* signal. tcp_poll() has a race breaker for this race |
| 8741 |
* condition. Based on their implementation, we put |
| 8742 |
* in the following code to cover it as well. |
| 8743 |
*/ |
| 8744 |
if (sctp_writeable(sk)) |
| 8745 |
mask |= EPOLLOUT | EPOLLWRNORM; |
| 8746 |
} |
| 8747 |
return mask; |
| 8748 |
} |
| 8749 |
|
| 8750 |
/******************************************************************** |
| 8751 |
* 2nd Level Abstractions |
| 8752 |
********************************************************************/ |
| 8753 |
|
| 8754 |
static struct sctp_bind_bucket *sctp_bucket_create( |
| 8755 |
struct sctp_bind_hashbucket *head, struct net *net, unsigned short snum) |
| 8756 |
{ |
| 8757 |
struct sctp_bind_bucket *pp; |
| 8758 |
|
| 8759 |
pp = kmem_cache_alloc(sctp_bucket_cachep, GFP_ATOMIC); |
| 8760 |
if (pp) { |
| 8761 |
SCTP_DBG_OBJCNT_INC(bind_bucket); |
| 8762 |
pp->port = snum; |
| 8763 |
pp->fastreuse = 0; |
| 8764 |
INIT_HLIST_HEAD(&pp->owner); |
| 8765 |
pp->net = net; |
| 8766 |
hlist_add_head(&pp->node, &head->chain); |
| 8767 |
} |
| 8768 |
return pp; |
| 8769 |
} |
| 8770 |
|
| 8771 |
/* Caller must hold hashbucket lock for this tb with local BH disabled */ |
| 8772 |
static void sctp_bucket_destroy(struct sctp_bind_bucket *pp) |
| 8773 |
{ |
| 8774 |
if (pp && hlist_empty(&pp->owner)) { |
| 8775 |
__hlist_del(&pp->node); |
| 8776 |
kmem_cache_free(sctp_bucket_cachep, pp); |
| 8777 |
SCTP_DBG_OBJCNT_DEC(bind_bucket); |
| 8778 |
} |
| 8779 |
} |
| 8780 |
|
| 8781 |
/* Release this socket's reference to a local port. */ |
| 8782 |
static inline void __sctp_put_port(struct sock *sk) |
| 8783 |
{ |
| 8784 |
struct sctp_bind_hashbucket *head = |
| 8785 |
&sctp_port_hashtable[sctp_phashfn(sock_net(sk), |
| 8786 |
inet_sk(sk)->inet_num)]; |
| 8787 |
struct sctp_bind_bucket *pp; |
| 8788 |
|
| 8789 |
spin_lock(&head->lock); |
| 8790 |
pp = sctp_sk(sk)->bind_hash; |
| 8791 |
__sk_del_bind_node(sk); |
| 8792 |
sctp_sk(sk)->bind_hash = NULL; |
| 8793 |
inet_sk(sk)->inet_num = 0; |
| 8794 |
sctp_bucket_destroy(pp); |
| 8795 |
spin_unlock(&head->lock); |
| 8796 |
} |
| 8797 |
|
| 8798 |
void sctp_put_port(struct sock *sk) |
| 8799 |
{ |
| 8800 |
local_bh_disable(); |
| 8801 |
__sctp_put_port(sk); |
| 8802 |
local_bh_enable(); |
| 8803 |
} |
| 8804 |
|
| 8805 |
/* |
| 8806 |
* The system picks an ephemeral port and choose an address set equivalent |
| 8807 |
* to binding with a wildcard address. |
| 8808 |
* One of those addresses will be the primary address for the association. |
| 8809 |
* This automatically enables the multihoming capability of SCTP. |
| 8810 |
*/ |
| 8811 |
static int sctp_autobind(struct sock *sk) |
| 8812 |
{ |
| 8813 |
union sctp_addr autoaddr; |
| 8814 |
struct sctp_af *af; |
| 8815 |
__be16 port; |
| 8816 |
|
| 8817 |
/* Initialize a local sockaddr structure to INADDR_ANY. */ |
| 8818 |
af = sctp_sk(sk)->pf->af; |
| 8819 |
|
| 8820 |
port = htons(inet_sk(sk)->inet_num); |
| 8821 |
af->inaddr_any(&autoaddr, port); |
| 8822 |
|
| 8823 |
return sctp_do_bind(sk, &autoaddr, af->sockaddr_len); |
| 8824 |
} |
| 8825 |
|
| 8826 |
/* Parse out IPPROTO_SCTP CMSG headers. Perform only minimal validation. |
| 8827 |
* |
| 8828 |
* From RFC 2292 |
| 8829 |
* 4.2 The cmsghdr Structure * |
| 8830 |
* |
| 8831 |
* When ancillary data is sent or received, any number of ancillary data |
| 8832 |
* objects can be specified by the msg_control and msg_controllen members of |
| 8833 |
* the msghdr structure, because each object is preceded by |
| 8834 |
* a cmsghdr structure defining the object's length (the cmsg_len member). |
| 8835 |
* Historically Berkeley-derived implementations have passed only one object |
| 8836 |
* at a time, but this API allows multiple objects to be |
| 8837 |
* passed in a single call to sendmsg() or recvmsg(). The following example |
| 8838 |
* shows two ancillary data objects in a control buffer. |
| 8839 |
* |
| 8840 |
* |<--------------------------- msg_controllen -------------------------->| |
| 8841 |
* | | |
| 8842 |
* |
| 8843 |
* |<----- ancillary data object ----->|<----- ancillary data object ----->| |
| 8844 |
* |
| 8845 |
* |<---------- CMSG_SPACE() --------->|<---------- CMSG_SPACE() --------->| |
| 8846 |
* | | | |
| 8847 |
* |
| 8848 |
* |<---------- cmsg_len ---------->| |<--------- cmsg_len ----------->| | |
| 8849 |
* |
| 8850 |
* |<--------- CMSG_LEN() --------->| |<-------- CMSG_LEN() ---------->| | |
| 8851 |
* | | | | | |
| 8852 |
* |
| 8853 |
* +-----+-----+-----+--+-----------+--+-----+-----+-----+--+-----------+--+ |
| 8854 |
* |cmsg_|cmsg_|cmsg_|XX| |XX|cmsg_|cmsg_|cmsg_|XX| |XX| |
| 8855 |
* |
| 8856 |
* |len |level|type |XX|cmsg_data[]|XX|len |level|type |XX|cmsg_data[]|XX| |
| 8857 |
* |
| 8858 |
* +-----+-----+-----+--+-----------+--+-----+-----+-----+--+-----------+--+ |
| 8859 |
* ^ |
| 8860 |
* | |
| 8861 |
* |
| 8862 |
* msg_control |
| 8863 |
* points here |
| 8864 |
*/ |
| 8865 |
static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs) |
| 8866 |
{ |
| 8867 |
struct msghdr *my_msg = (struct msghdr *)msg; |
| 8868 |
struct cmsghdr *cmsg; |
| 8869 |
|
| 8870 |
for_each_cmsghdr(cmsg, my_msg) { |
| 8871 |
if (!CMSG_OK(my_msg, cmsg)) |
| 8872 |
return -EINVAL; |
| 8873 |
|
| 8874 |
/* Should we parse this header or ignore? */ |
| 8875 |
if (cmsg->cmsg_level != IPPROTO_SCTP) |
| 8876 |
continue; |
| 8877 |
|
| 8878 |
/* Strictly check lengths following example in SCM code. */ |
| 8879 |
switch (cmsg->cmsg_type) { |
| 8880 |
case SCTP_INIT: |
| 8881 |
/* SCTP Socket API Extension |
| 8882 |
* 5.3.1 SCTP Initiation Structure (SCTP_INIT) |
| 8883 |
* |
| 8884 |
* This cmsghdr structure provides information for |
| 8885 |
* initializing new SCTP associations with sendmsg(). |
| 8886 |
* The SCTP_INITMSG socket option uses this same data |
| 8887 |
* structure. This structure is not used for |
| 8888 |
* recvmsg(). |
| 8889 |
* |
| 8890 |
* cmsg_level cmsg_type cmsg_data[] |
| 8891 |
* ------------ ------------ ---------------------- |
| 8892 |
* IPPROTO_SCTP SCTP_INIT struct sctp_initmsg |
| 8893 |
*/ |
| 8894 |
if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct sctp_initmsg))) |
| 8895 |
return -EINVAL; |
| 8896 |
|
| 8897 |
cmsgs->init = CMSG_DATA(cmsg); |
| 8898 |
break; |
| 8899 |
|
| 8900 |
case SCTP_SNDRCV: |
| 8901 |
/* SCTP Socket API Extension |
| 8902 |
* 5.3.2 SCTP Header Information Structure(SCTP_SNDRCV) |
| 8903 |
* |
| 8904 |
* This cmsghdr structure specifies SCTP options for |
| 8905 |
* sendmsg() and describes SCTP header information |
| 8906 |
* about a received message through recvmsg(). |
| 8907 |
* |
| 8908 |
* cmsg_level cmsg_type cmsg_data[] |
| 8909 |
* ------------ ------------ ---------------------- |
| 8910 |
* IPPROTO_SCTP SCTP_SNDRCV struct sctp_sndrcvinfo |
| 8911 |
*/ |
| 8912 |
if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct sctp_sndrcvinfo))) |
| 8913 |
return -EINVAL; |
| 8914 |
|
| 8915 |
cmsgs->srinfo = CMSG_DATA(cmsg); |
| 8916 |
|
| 8917 |
if (cmsgs->srinfo->sinfo_flags & |
| 8918 |
~(SCTP_UNORDERED | SCTP_ADDR_OVER | |
| 8919 |
SCTP_SACK_IMMEDIATELY | SCTP_SENDALL | |
| 8920 |
SCTP_PR_SCTP_MASK | SCTP_ABORT | SCTP_EOF)) |
| 8921 |
return -EINVAL; |
| 8922 |
break; |
| 8923 |
|
| 8924 |
case SCTP_SNDINFO: |
| 8925 |
/* SCTP Socket API Extension |
| 8926 |
* 5.3.4 SCTP Send Information Structure (SCTP_SNDINFO) |
| 8927 |
* |
| 8928 |
* This cmsghdr structure specifies SCTP options for |
| 8929 |
* sendmsg(). This structure and SCTP_RCVINFO replaces |
| 8930 |
* SCTP_SNDRCV which has been deprecated. |
| 8931 |
* |
| 8932 |
* cmsg_level cmsg_type cmsg_data[] |
| 8933 |
* ------------ ------------ --------------------- |
| 8934 |
* IPPROTO_SCTP SCTP_SNDINFO struct sctp_sndinfo |
| 8935 |
*/ |
| 8936 |
if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct sctp_sndinfo))) |
| 8937 |
return -EINVAL; |
| 8938 |
|
| 8939 |
cmsgs->sinfo = CMSG_DATA(cmsg); |
| 8940 |
|
| 8941 |
if (cmsgs->sinfo->snd_flags & |
| 8942 |
~(SCTP_UNORDERED | SCTP_ADDR_OVER | |
| 8943 |
SCTP_SACK_IMMEDIATELY | SCTP_SENDALL | |
| 8944 |
SCTP_PR_SCTP_MASK | SCTP_ABORT | SCTP_EOF)) |
| 8945 |
return -EINVAL; |
| 8946 |
break; |
| 8947 |
case SCTP_PRINFO: |
| 8948 |
/* SCTP Socket API Extension |
| 8949 |
* 5.3.7 SCTP PR-SCTP Information Structure (SCTP_PRINFO) |
| 8950 |
* |
| 8951 |
* This cmsghdr structure specifies SCTP options for sendmsg(). |
| 8952 |
* |
| 8953 |
* cmsg_level cmsg_type cmsg_data[] |
| 8954 |
* ------------ ------------ --------------------- |
| 8955 |
* IPPROTO_SCTP SCTP_PRINFO struct sctp_prinfo |
| 8956 |
*/ |
| 8957 |
if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct sctp_prinfo))) |
| 8958 |
return -EINVAL; |
| 8959 |
|
| 8960 |
cmsgs->prinfo = CMSG_DATA(cmsg); |
| 8961 |
if (cmsgs->prinfo->pr_policy & ~SCTP_PR_SCTP_MASK) |
| 8962 |
return -EINVAL; |
| 8963 |
|
| 8964 |
if (cmsgs->prinfo->pr_policy == SCTP_PR_SCTP_NONE) |
| 8965 |
cmsgs->prinfo->pr_value = 0; |
| 8966 |
break; |
| 8967 |
case SCTP_AUTHINFO: |
| 8968 |
/* SCTP Socket API Extension |
| 8969 |
* 5.3.8 SCTP AUTH Information Structure (SCTP_AUTHINFO) |
| 8970 |
* |
| 8971 |
* This cmsghdr structure specifies SCTP options for sendmsg(). |
| 8972 |
* |
| 8973 |
* cmsg_level cmsg_type cmsg_data[] |
| 8974 |
* ------------ ------------ --------------------- |
| 8975 |
* IPPROTO_SCTP SCTP_AUTHINFO struct sctp_authinfo |
| 8976 |
*/ |
| 8977 |
if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct sctp_authinfo))) |
| 8978 |
return -EINVAL; |
| 8979 |
|
| 8980 |
cmsgs->authinfo = CMSG_DATA(cmsg); |
| 8981 |
break; |
| 8982 |
case SCTP_DSTADDRV4: |
| 8983 |
case SCTP_DSTADDRV6: |
| 8984 |
/* SCTP Socket API Extension |
| 8985 |
* 5.3.9/10 SCTP Destination IPv4/6 Address Structure (SCTP_DSTADDRV4/6) |
| 8986 |
* |
| 8987 |
* This cmsghdr structure specifies SCTP options for sendmsg(). |
| 8988 |
* |
| 8989 |
* cmsg_level cmsg_type cmsg_data[] |
| 8990 |
* ------------ ------------ --------------------- |
| 8991 |
* IPPROTO_SCTP SCTP_DSTADDRV4 struct in_addr |
| 8992 |
* ------------ ------------ --------------------- |
| 8993 |
* IPPROTO_SCTP SCTP_DSTADDRV6 struct in6_addr |
| 8994 |
*/ |
| 8995 |
cmsgs->addrs_msg = my_msg; |
| 8996 |
break; |
| 8997 |
default: |
| 8998 |
return -EINVAL; |
| 8999 |
} |
| 9000 |
} |
| 9001 |
|
| 9002 |
return 0; |
| 9003 |
} |
| 9004 |
|
| 9005 |
/* |
| 9006 |
* Wait for a packet.. |
| 9007 |
* Note: This function is the same function as in core/datagram.c |
| 9008 |
* with a few modifications to make lksctp work. |
| 9009 |
*/ |
| 9010 |
static int sctp_wait_for_packet(struct sock *sk, int *err, long *timeo_p) |
| 9011 |
{ |
| 9012 |
int error; |
| 9013 |
DEFINE_WAIT(wait); |
| 9014 |
|
| 9015 |
prepare_to_wait_exclusive(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); |
| 9016 |
|
| 9017 |
/* Socket errors? */ |
| 9018 |
error = sock_error(sk); |
| 9019 |
if (error) |
| 9020 |
goto out; |
| 9021 |
|
| 9022 |
if (!skb_queue_empty(&sk->sk_receive_queue)) |
| 9023 |
goto ready; |
| 9024 |
|
| 9025 |
/* Socket shut down? */ |
| 9026 |
if (sk->sk_shutdown & RCV_SHUTDOWN) |
| 9027 |
goto out; |
| 9028 |
|
| 9029 |
/* Sequenced packets can come disconnected. If so we report the |
| 9030 |
* problem. |
| 9031 |
*/ |
| 9032 |
error = -ENOTCONN; |
| 9033 |
|
| 9034 |
/* Is there a good reason to think that we may receive some data? */ |
| 9035 |
if (list_empty(&sctp_sk(sk)->ep->asocs) && !sctp_sstate(sk, LISTENING)) |
| 9036 |
goto out; |
| 9037 |
|
| 9038 |
/* Handle signals. */ |
| 9039 |
if (signal_pending(current)) |
| 9040 |
goto interrupted; |
| 9041 |
|
| 9042 |
/* Let another process have a go. Since we are going to sleep |
| 9043 |
* anyway. Note: This may cause odd behaviors if the message |
| 9044 |
* does not fit in the user's buffer, but this seems to be the |
| 9045 |
* only way to honor MSG_DONTWAIT realistically. |
| 9046 |
*/ |
| 9047 |
release_sock(sk); |
| 9048 |
*timeo_p = schedule_timeout(*timeo_p); |
| 9049 |
lock_sock(sk); |
| 9050 |
|
| 9051 |
ready: |
| 9052 |
finish_wait(sk_sleep(sk), &wait); |
| 9053 |
return 0; |
| 9054 |
|
| 9055 |
interrupted: |
| 9056 |
error = sock_intr_errno(*timeo_p); |
| 9057 |
|
| 9058 |
out: |
| 9059 |
finish_wait(sk_sleep(sk), &wait); |
| 9060 |
*err = error; |
| 9061 |
return error; |
| 9062 |
} |
| 9063 |
|
| 9064 |
/* Receive a datagram. |
| 9065 |
* Note: This is pretty much the same routine as in core/datagram.c |
| 9066 |
* with a few changes to make lksctp work. |
| 9067 |
*/ |
| 9068 |
struct sk_buff *sctp_skb_recv_datagram(struct sock *sk, int flags, int *err) |
| 9069 |
{ |
| 9070 |
int error; |
| 9071 |
struct sk_buff *skb; |
| 9072 |
long timeo; |
| 9073 |
|
| 9074 |
timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT); |
| 9075 |
|
| 9076 |
pr_debug("%s: timeo:%ld, max:%ld\n", __func__, timeo, |
| 9077 |
MAX_SCHEDULE_TIMEOUT); |
| 9078 |
|
| 9079 |
do { |
| 9080 |
/* Again only user level code calls this function, |
| 9081 |
* so nothing interrupt level |
| 9082 |
* will suddenly eat the receive_queue. |
| 9083 |
* |
| 9084 |
* Look at current nfs client by the way... |
| 9085 |
* However, this function was correct in any case. 8) |
| 9086 |
*/ |
| 9087 |
if (flags & MSG_PEEK) { |
| 9088 |
skb = skb_peek(&sk->sk_receive_queue); |
| 9089 |
if (skb) |
| 9090 |
refcount_inc(&skb->users); |
| 9091 |
} else { |
| 9092 |
skb = __skb_dequeue(&sk->sk_receive_queue); |
| 9093 |
} |
| 9094 |
|
| 9095 |
if (skb) |
| 9096 |
return skb; |
| 9097 |
|
| 9098 |
/* Caller is allowed not to check sk->sk_err before calling. */ |
| 9099 |
error = sock_error(sk); |
| 9100 |
if (error) |
| 9101 |
goto no_packet; |
| 9102 |
|
| 9103 |
if (sk->sk_shutdown & RCV_SHUTDOWN) |
| 9104 |
break; |
| 9105 |
|
| 9106 |
|
| 9107 |
/* User doesn't want to wait. */ |
| 9108 |
error = -EAGAIN; |
| 9109 |
if (!timeo) |
| 9110 |
goto no_packet; |
| 9111 |
} while (sctp_wait_for_packet(sk, err, &timeo) == 0); |
| 9112 |
|
| 9113 |
return NULL; |
| 9114 |
|
| 9115 |
no_packet: |
| 9116 |
*err = error; |
| 9117 |
return NULL; |
| 9118 |
} |
| 9119 |
|
| 9120 |
/* If sndbuf has changed, wake up per association sndbuf waiters. */ |
| 9121 |
static void __sctp_write_space(struct sctp_association *asoc) |
| 9122 |
{ |
| 9123 |
struct sock *sk = asoc->base.sk; |
| 9124 |
|
| 9125 |
if (sctp_wspace(asoc) <= 0) |
| 9126 |
return; |
| 9127 |
|
| 9128 |
if (waitqueue_active(&asoc->wait)) |
| 9129 |
wake_up_interruptible(&asoc->wait); |
| 9130 |
|
| 9131 |
if (sctp_writeable(sk)) { |
| 9132 |
struct socket_wq *wq; |
| 9133 |
|
| 9134 |
rcu_read_lock(); |
| 9135 |
wq = rcu_dereference(sk->sk_wq); |
| 9136 |
if (wq) { |
| 9137 |
if (waitqueue_active(&wq->wait)) |
| 9138 |
wake_up_interruptible_poll(&wq->wait, EPOLLOUT | |
| 9139 |
EPOLLWRNORM | EPOLLWRBAND); |
| 9140 |
|
| 9141 |
/* Note that we try to include the Async I/O support |
| 9142 |
* here by modeling from the current TCP/UDP code. |
| 9143 |
* We have not tested with it yet. |
| 9144 |
*/ |
| 9145 |
if (!(sk->sk_shutdown & SEND_SHUTDOWN)) |
| 9146 |
sock_wake_async(wq, SOCK_WAKE_SPACE, POLL_OUT); |
| 9147 |
} |
| 9148 |
rcu_read_unlock(); |
| 9149 |
} |
| 9150 |
} |
| 9151 |
|
| 9152 |
static void sctp_wake_up_waiters(struct sock *sk, |
| 9153 |
struct sctp_association *asoc) |
| 9154 |
{ |
| 9155 |
struct sctp_association *tmp = asoc; |
| 9156 |
|
| 9157 |
/* We do accounting for the sndbuf space per association, |
| 9158 |
* so we only need to wake our own association. |
| 9159 |
*/ |
| 9160 |
if (asoc->ep->sndbuf_policy) |
| 9161 |
return __sctp_write_space(asoc); |
| 9162 |
|
| 9163 |
/* If association goes down and is just flushing its |
| 9164 |
* outq, then just normally notify others. |
| 9165 |
*/ |
| 9166 |
if (asoc->base.dead) |
| 9167 |
return sctp_write_space(sk); |
| 9168 |
|
| 9169 |
/* Accounting for the sndbuf space is per socket, so we |
| 9170 |
* need to wake up others, try to be fair and in case of |
| 9171 |
* other associations, let them have a go first instead |
| 9172 |
* of just doing a sctp_write_space() call. |
| 9173 |
* |
| 9174 |
* Note that we reach sctp_wake_up_waiters() only when |
| 9175 |
* associations free up queued chunks, thus we are under |
| 9176 |
* lock and the list of associations on a socket is |
| 9177 |
* guaranteed not to change. |
| 9178 |
*/ |
| 9179 |
for (tmp = list_next_entry(tmp, asocs); 1; |
| 9180 |
tmp = list_next_entry(tmp, asocs)) { |
| 9181 |
/* Manually skip the head element. */ |
| 9182 |
if (&tmp->asocs == &((sctp_sk(sk))->ep->asocs)) |
| 9183 |
continue; |
| 9184 |
/* Wake up association. */ |
| 9185 |
__sctp_write_space(tmp); |
| 9186 |
/* We've reached the end. */ |
| 9187 |
if (tmp == asoc) |
| 9188 |
break; |
| 9189 |
} |
| 9190 |
} |
| 9191 |
|
| 9192 |
/* Do accounting for the sndbuf space. |
| 9193 |
* Decrement the used sndbuf space of the corresponding association by the |
| 9194 |
* data size which was just transmitted(freed). |
| 9195 |
*/ |
| 9196 |
static void sctp_wfree(struct sk_buff *skb) |
| 9197 |
{ |
| 9198 |
struct sctp_chunk *chunk = skb_shinfo(skb)->destructor_arg; |
| 9199 |
struct sctp_association *asoc = chunk->asoc; |
| 9200 |
struct sock *sk = asoc->base.sk; |
| 9201 |
|
| 9202 |
sk_mem_uncharge(sk, skb->truesize); |
| 9203 |
sk_wmem_queued_add(sk, -(skb->truesize + sizeof(struct sctp_chunk))); |
| 9204 |
asoc->sndbuf_used -= skb->truesize + sizeof(struct sctp_chunk); |
| 9205 |
WARN_ON(refcount_sub_and_test(sizeof(struct sctp_chunk), |
| 9206 |
&sk->sk_wmem_alloc)); |
| 9207 |
|
| 9208 |
if (chunk->shkey) { |
| 9209 |
struct sctp_shared_key *shkey = chunk->shkey; |
| 9210 |
|
| 9211 |
/* refcnt == 2 and !list_empty mean after this release, it's |
| 9212 |
* not being used anywhere, and it's time to notify userland |
| 9213 |
* that this shkey can be freed if it's been deactivated. |
| 9214 |
*/ |
| 9215 |
if (shkey->deactivated && !list_empty(&shkey->key_list) && |
| 9216 |
refcount_read(&shkey->refcnt) == 2) { |
| 9217 |
struct sctp_ulpevent *ev; |
| 9218 |
|
| 9219 |
ev = sctp_ulpevent_make_authkey(asoc, shkey->key_id, |
| 9220 |
SCTP_AUTH_FREE_KEY, |
| 9221 |
GFP_KERNEL); |
| 9222 |
if (ev) |
| 9223 |
asoc->stream.si->enqueue_event(&asoc->ulpq, ev); |
| 9224 |
} |
| 9225 |
sctp_auth_shkey_release(chunk->shkey); |
| 9226 |
} |
| 9227 |
|
| 9228 |
sock_wfree(skb); |
| 9229 |
sctp_wake_up_waiters(sk, asoc); |
| 9230 |
|
| 9231 |
sctp_association_put(asoc); |
| 9232 |
} |
| 9233 |
|
| 9234 |
/* Do accounting for the receive space on the socket. |
| 9235 |
* Accounting for the association is done in ulpevent.c |
| 9236 |
* We set this as a destructor for the cloned data skbs so that |
| 9237 |
* accounting is done at the correct time. |
| 9238 |
*/ |
| 9239 |
void sctp_sock_rfree(struct sk_buff *skb) |
| 9240 |
{ |
| 9241 |
struct sock *sk = skb->sk; |
| 9242 |
struct sctp_ulpevent *event = sctp_skb2event(skb); |
| 9243 |
|
| 9244 |
atomic_sub(event->rmem_len, &sk->sk_rmem_alloc); |
| 9245 |
|
| 9246 |
/* |
| 9247 |
* Mimic the behavior of sock_rfree |
| 9248 |
*/ |
| 9249 |
sk_mem_uncharge(sk, event->rmem_len); |
| 9250 |
} |
| 9251 |
|
| 9252 |
|
| 9253 |
/* Helper function to wait for space in the sndbuf. */ |
| 9254 |
static int sctp_wait_for_sndbuf(struct sctp_association *asoc, |
| 9255 |
struct sctp_transport *transport, |
| 9256 |
long *timeo_p, size_t msg_len) |
| 9257 |
{ |
| 9258 |
struct sock *sk = asoc->base.sk; |
| 9259 |
long current_timeo = *timeo_p; |
| 9260 |
DEFINE_WAIT(wait); |
| 9261 |
int err = 0; |
| 9262 |
|
| 9263 |
pr_debug("%s: asoc:%p, timeo:%ld, msg_len:%zu\n", __func__, asoc, |
| 9264 |
*timeo_p, msg_len); |
| 9265 |
|
| 9266 |
/* Increment the transport and association's refcnt. */ |
| 9267 |
if (transport) |
| 9268 |
sctp_transport_hold(transport); |
| 9269 |
sctp_association_hold(asoc); |
| 9270 |
|
| 9271 |
/* Wait on the association specific sndbuf space. */ |
| 9272 |
for (;;) { |
| 9273 |
prepare_to_wait_exclusive(&asoc->wait, &wait, |
| 9274 |
TASK_INTERRUPTIBLE); |
| 9275 |
if (asoc->base.dead) |
| 9276 |
goto do_dead; |
| 9277 |
if ((!*timeo_p) || (transport && transport->dead)) |
| 9278 |
goto do_nonblock; |
| 9279 |
if (sk->sk_err || asoc->state >= SCTP_STATE_SHUTDOWN_PENDING) |
| 9280 |
goto do_error; |
| 9281 |
if (signal_pending(current)) |
| 9282 |
goto do_interrupted; |
| 9283 |
if ((int)msg_len <= sctp_wspace(asoc) && |
| 9284 |
sk_wmem_schedule(sk, msg_len)) |
| 9285 |
break; |
| 9286 |
|
| 9287 |
/* Let another process have a go. Since we are going |
| 9288 |
* to sleep anyway. |
| 9289 |
*/ |
| 9290 |
release_sock(sk); |
| 9291 |
current_timeo = schedule_timeout(current_timeo); |
| 9292 |
lock_sock(sk); |
| 9293 |
if (sk != asoc->base.sk) |
| 9294 |
goto do_error; |
| 9295 |
|
| 9296 |
*timeo_p = current_timeo; |
| 9297 |
} |
| 9298 |
|
| 9299 |
out: |
| 9300 |
finish_wait(&asoc->wait, &wait); |
| 9301 |
|
| 9302 |
/* Release the transport and association's refcnt. */ |
| 9303 |
if (transport) |
| 9304 |
sctp_transport_put(transport); |
| 9305 |
sctp_association_put(asoc); |
| 9306 |
|
| 9307 |
return err; |
| 9308 |
|
| 9309 |
do_dead: |
| 9310 |
err = -ESRCH; |
| 9311 |
goto out; |
| 9312 |
|
| 9313 |
do_error: |
| 9314 |
err = -EPIPE; |
| 9315 |
goto out; |
| 9316 |
|
| 9317 |
do_interrupted: |
| 9318 |
err = sock_intr_errno(*timeo_p); |
| 9319 |
goto out; |
| 9320 |
|
| 9321 |
do_nonblock: |
| 9322 |
err = -EAGAIN; |
| 9323 |
goto out; |
| 9324 |
} |
| 9325 |
|
| 9326 |
void sctp_data_ready(struct sock *sk) |
| 9327 |
{ |
| 9328 |
struct socket_wq *wq; |
| 9329 |
|
| 9330 |
trace_sk_data_ready(sk); |
| 9331 |
|
| 9332 |
rcu_read_lock(); |
| 9333 |
wq = rcu_dereference(sk->sk_wq); |
| 9334 |
if (skwq_has_sleeper(wq)) |
| 9335 |
wake_up_interruptible_sync_poll(&wq->wait, EPOLLIN | |
| 9336 |
EPOLLRDNORM | EPOLLRDBAND); |
| 9337 |
sk_wake_async_rcu(sk, SOCK_WAKE_WAITD, POLL_IN); |
| 9338 |
rcu_read_unlock(); |
| 9339 |
} |
| 9340 |
|
| 9341 |
/* If socket sndbuf has changed, wake up all per association waiters. */ |
| 9342 |
void sctp_write_space(struct sock *sk) |
| 9343 |
{ |
| 9344 |
struct sctp_association *asoc; |
| 9345 |
|
| 9346 |
/* Wake up the tasks in each wait queue. */ |
| 9347 |
list_for_each_entry(asoc, &((sctp_sk(sk))->ep->asocs), asocs) { |
| 9348 |
__sctp_write_space(asoc); |
| 9349 |
} |
| 9350 |
} |
| 9351 |
|
| 9352 |
/* Is there any sndbuf space available on the socket? |
| 9353 |
* |
| 9354 |
* Note that sk_wmem_alloc is the sum of the send buffers on all of the |
| 9355 |
* associations on the same socket. For a UDP-style socket with |
| 9356 |
* multiple associations, it is possible for it to be "unwriteable" |
| 9357 |
* prematurely. I assume that this is acceptable because |
| 9358 |
* a premature "unwriteable" is better than an accidental "writeable" which |
| 9359 |
* would cause an unwanted block under certain circumstances. For the 1-1 |
| 9360 |
* UDP-style sockets or TCP-style sockets, this code should work. |
| 9361 |
* - Daisy |
| 9362 |
*/ |
| 9363 |
static bool sctp_writeable(const struct sock *sk) |
| 9364 |
{ |
| 9365 |
return READ_ONCE(sk->sk_sndbuf) > READ_ONCE(sk->sk_wmem_queued); |
| 9366 |
} |
| 9367 |
|
| 9368 |
/* Wait for an association to go into ESTABLISHED state. If timeout is 0, |
| 9369 |
* returns immediately with EINPROGRESS. |
| 9370 |
*/ |
| 9371 |
static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p) |
| 9372 |
{ |
| 9373 |
struct sock *sk = asoc->base.sk; |
| 9374 |
int err = 0; |
| 9375 |
long current_timeo = *timeo_p; |
| 9376 |
DEFINE_WAIT(wait); |
| 9377 |
|
| 9378 |
pr_debug("%s: asoc:%p, timeo:%ld\n", __func__, asoc, *timeo_p); |
| 9379 |
|
| 9380 |
/* Increment the association's refcnt. */ |
| 9381 |
sctp_association_hold(asoc); |
| 9382 |
|
| 9383 |
for (;;) { |
| 9384 |
prepare_to_wait_exclusive(&asoc->wait, &wait, |
| 9385 |
TASK_INTERRUPTIBLE); |
| 9386 |
if (!*timeo_p) |
| 9387 |
goto do_nonblock; |
| 9388 |
if (sk->sk_shutdown & RCV_SHUTDOWN) |
| 9389 |
break; |
| 9390 |
if (sk->sk_err || asoc->state >= SCTP_STATE_SHUTDOWN_PENDING || |
| 9391 |
asoc->base.dead) |
| 9392 |
goto do_error; |
| 9393 |
if (signal_pending(current)) |
| 9394 |
goto do_interrupted; |
| 9395 |
|
| 9396 |
if (sctp_state(asoc, ESTABLISHED)) |
| 9397 |
break; |
| 9398 |
|
| 9399 |
/* Let another process have a go. Since we are going |
| 9400 |
* to sleep anyway. |
| 9401 |
*/ |
| 9402 |
release_sock(sk); |
| 9403 |
current_timeo = schedule_timeout(current_timeo); |
| 9404 |
lock_sock(sk); |
| 9405 |
|
| 9406 |
*timeo_p = current_timeo; |
| 9407 |
} |
| 9408 |
|
| 9409 |
out: |
| 9410 |
finish_wait(&asoc->wait, &wait); |
| 9411 |
|
| 9412 |
/* Release the association's refcnt. */ |
| 9413 |
sctp_association_put(asoc); |
| 9414 |
|
| 9415 |
return err; |
| 9416 |
|
| 9417 |
do_error: |
| 9418 |
if (asoc->init_err_counter + 1 > asoc->max_init_attempts) |
| 9419 |
err = -ETIMEDOUT; |
| 9420 |
else |
| 9421 |
err = -ECONNREFUSED; |
| 9422 |
goto out; |
| 9423 |
|
| 9424 |
do_interrupted: |
| 9425 |
err = sock_intr_errno(*timeo_p); |
| 9426 |
goto out; |
| 9427 |
|
| 9428 |
do_nonblock: |
| 9429 |
err = -EINPROGRESS; |
| 9430 |
goto out; |
| 9431 |
} |
| 9432 |
|
| 9433 |
static int sctp_wait_for_accept(struct sock *sk, long timeo) |
| 9434 |
{ |
| 9435 |
struct sctp_endpoint *ep; |
| 9436 |
int err = 0; |
| 9437 |
DEFINE_WAIT(wait); |
| 9438 |
|
| 9439 |
ep = sctp_sk(sk)->ep; |
| 9440 |
|
| 9441 |
|
| 9442 |
for (;;) { |
| 9443 |
prepare_to_wait_exclusive(sk_sleep(sk), &wait, |
| 9444 |
TASK_INTERRUPTIBLE); |
| 9445 |
|
| 9446 |
if (list_empty(&ep->asocs)) { |
| 9447 |
release_sock(sk); |
| 9448 |
timeo = schedule_timeout(timeo); |
| 9449 |
lock_sock(sk); |
| 9450 |
} |
| 9451 |
|
| 9452 |
err = -EINVAL; |
| 9453 |
if (!sctp_sstate(sk, LISTENING) || |
| 9454 |
(sk->sk_shutdown & RCV_SHUTDOWN)) |
| 9455 |
break; |
| 9456 |
|
| 9457 |
err = 0; |
| 9458 |
if (!list_empty(&ep->asocs)) |
| 9459 |
break; |
| 9460 |
|
| 9461 |
err = sock_intr_errno(timeo); |
| 9462 |
if (signal_pending(current)) |
| 9463 |
break; |
| 9464 |
|
| 9465 |
err = -EAGAIN; |
| 9466 |
if (!timeo) |
| 9467 |
break; |
| 9468 |
} |
| 9469 |
|
| 9470 |
finish_wait(sk_sleep(sk), &wait); |
| 9471 |
|
| 9472 |
return err; |
| 9473 |
} |
| 9474 |
|
| 9475 |
static void sctp_wait_for_close(struct sock *sk, long timeout) |
| 9476 |
{ |
| 9477 |
DEFINE_WAIT(wait); |
| 9478 |
|
| 9479 |
do { |
| 9480 |
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); |
| 9481 |
if (list_empty(&sctp_sk(sk)->ep->asocs)) |
| 9482 |
break; |
| 9483 |
release_sock(sk); |
| 9484 |
timeout = schedule_timeout(timeout); |
| 9485 |
lock_sock(sk); |
| 9486 |
} while (!signal_pending(current) && timeout); |
| 9487 |
|
| 9488 |
finish_wait(sk_sleep(sk), &wait); |
| 9489 |
} |
| 9490 |
|
| 9491 |
static void sctp_skb_set_owner_r_frag(struct sk_buff *skb, struct sock *sk) |
| 9492 |
{ |
| 9493 |
struct sk_buff *frag; |
| 9494 |
|
| 9495 |
if (!skb->data_len) |
| 9496 |
goto done; |
| 9497 |
|
| 9498 |
/* Don't forget the fragments. */ |
| 9499 |
skb_walk_frags(skb, frag) |
| 9500 |
sctp_skb_set_owner_r_frag(frag, sk); |
| 9501 |
|
| 9502 |
done: |
| 9503 |
sctp_skb_set_owner_r(skb, sk); |
| 9504 |
} |
| 9505 |
|
| 9506 |
/* Populate the fields of the newsk from the oldsk and migrate the assoc |
| 9507 |
* and its messages to the newsk. |
| 9508 |
*/ |
| 9509 |
static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk, |
| 9510 |
struct sctp_association *assoc, |
| 9511 |
enum sctp_socket_type type) |
| 9512 |
{ |
| 9513 |
struct sctp_sock *oldsp = sctp_sk(oldsk); |
| 9514 |
struct sctp_sock *newsp = sctp_sk(newsk); |
| 9515 |
struct sctp_bind_bucket *pp; /* hash list port iterator */ |
| 9516 |
struct sctp_endpoint *newep = newsp->ep; |
| 9517 |
struct sk_buff *skb, *tmp; |
| 9518 |
struct sctp_ulpevent *event; |
| 9519 |
struct sctp_bind_hashbucket *head; |
| 9520 |
int err; |
| 9521 |
|
| 9522 |
/* Restore the ep value that was overwritten with the above structure |
| 9523 |
* copy. |
| 9524 |
*/ |
| 9525 |
newsp->ep = newep; |
| 9526 |
|
| 9527 |
/* Hook this new socket in to the bind_hash list. */ |
| 9528 |
head = &sctp_port_hashtable[sctp_phashfn(sock_net(oldsk), |
| 9529 |
inet_sk(oldsk)->inet_num)]; |
| 9530 |
spin_lock_bh(&head->lock); |
| 9531 |
pp = sctp_sk(oldsk)->bind_hash; |
| 9532 |
sk_add_bind_node(newsk, &pp->owner); |
| 9533 |
sctp_sk(newsk)->bind_hash = pp; |
| 9534 |
inet_sk(newsk)->inet_num = inet_sk(oldsk)->inet_num; |
| 9535 |
spin_unlock_bh(&head->lock); |
| 9536 |
|
| 9537 |
/* Copy the bind_addr list from the original endpoint to the new |
| 9538 |
* endpoint so that we can handle restarts properly |
| 9539 |
*/ |
| 9540 |
err = sctp_bind_addr_dup(&newsp->ep->base.bind_addr, |
| 9541 |
&oldsp->ep->base.bind_addr, GFP_KERNEL); |
| 9542 |
if (err) |
| 9543 |
return err; |
| 9544 |
|
| 9545 |
sctp_auto_asconf_init(newsp); |
| 9546 |
|
| 9547 |
/* Move any messages in the old socket's receive queue that are for the |
| 9548 |
* peeled off association to the new socket's receive queue. |
| 9549 |
*/ |
| 9550 |
sctp_skb_for_each(skb, &oldsk->sk_receive_queue, tmp) { |
| 9551 |
event = sctp_skb2event(skb); |
| 9552 |
if (event->asoc == assoc) { |
| 9553 |
__skb_unlink(skb, &oldsk->sk_receive_queue); |
| 9554 |
__skb_queue_tail(&newsk->sk_receive_queue, skb); |
| 9555 |
sctp_skb_set_owner_r_frag(skb, newsk); |
| 9556 |
} |
| 9557 |
} |
| 9558 |
|
| 9559 |
/* Clean up any messages pending delivery due to partial |
| 9560 |
* delivery. Three cases: |
| 9561 |
* 1) No partial deliver; no work. |
| 9562 |
* 2) Peeling off partial delivery; keep pd_lobby in new pd_lobby. |
| 9563 |
* 3) Peeling off non-partial delivery; move pd_lobby to receive_queue. |
| 9564 |
*/ |
| 9565 |
atomic_set(&sctp_sk(newsk)->pd_mode, assoc->ulpq.pd_mode); |
| 9566 |
|
| 9567 |
if (atomic_read(&sctp_sk(oldsk)->pd_mode)) { |
| 9568 |
struct sk_buff_head *queue; |
| 9569 |
|
| 9570 |
/* Decide which queue to move pd_lobby skbs to. */ |
| 9571 |
if (assoc->ulpq.pd_mode) { |
| 9572 |
queue = &newsp->pd_lobby; |
| 9573 |
} else |
| 9574 |
queue = &newsk->sk_receive_queue; |
| 9575 |
|
| 9576 |
/* Walk through the pd_lobby, looking for skbs that |
| 9577 |
* need moved to the new socket. |
| 9578 |
*/ |
| 9579 |
sctp_skb_for_each(skb, &oldsp->pd_lobby, tmp) { |
| 9580 |
event = sctp_skb2event(skb); |
| 9581 |
if (event->asoc == assoc) { |
| 9582 |
__skb_unlink(skb, &oldsp->pd_lobby); |
| 9583 |
__skb_queue_tail(queue, skb); |
| 9584 |
sctp_skb_set_owner_r_frag(skb, newsk); |
| 9585 |
} |
| 9586 |
} |
| 9587 |
|
| 9588 |
/* Clear up any skbs waiting for the partial |
| 9589 |
* delivery to finish. |
| 9590 |
*/ |
| 9591 |
if (assoc->ulpq.pd_mode) |
| 9592 |
sctp_clear_pd(oldsk, NULL); |
| 9593 |
|
| 9594 |
} |
| 9595 |
|
| 9596 |
sctp_for_each_rx_skb(assoc, newsk, sctp_skb_set_owner_r_frag); |
| 9597 |
|
| 9598 |
/* Set the type of socket to indicate that it is peeled off from the |
| 9599 |
* original UDP-style socket or created with the accept() call on a |
| 9600 |
* TCP-style socket.. |
| 9601 |
*/ |
| 9602 |
newsp->type = type; |
| 9603 |
|
| 9604 |
/* Mark the new socket "in-use" by the user so that any packets |
| 9605 |
* that may arrive on the association after we've moved it are |
| 9606 |
* queued to the backlog. This prevents a potential race between |
| 9607 |
* backlog processing on the old socket and new-packet processing |
| 9608 |
* on the new socket. |
| 9609 |
* |
| 9610 |
* The caller has just allocated newsk so we can guarantee that other |
| 9611 |
* paths won't try to lock it and then oldsk. |
| 9612 |
*/ |
| 9613 |
lock_sock_nested(newsk, SINGLE_DEPTH_NESTING); |
| 9614 |
sctp_for_each_tx_datachunk(assoc, true, sctp_clear_owner_w); |
| 9615 |
sctp_assoc_migrate(assoc, newsk); |
| 9616 |
sctp_for_each_tx_datachunk(assoc, false, sctp_set_owner_w); |
| 9617 |
|
| 9618 |
/* If the association on the newsk is already closed before accept() |
| 9619 |
* is called, set RCV_SHUTDOWN flag. |
| 9620 |
*/ |
| 9621 |
if (sctp_state(assoc, CLOSED) && sctp_style(newsk, TCP)) { |
| 9622 |
inet_sk_set_state(newsk, SCTP_SS_CLOSED); |
| 9623 |
newsk->sk_shutdown |= RCV_SHUTDOWN; |
| 9624 |
} else { |
| 9625 |
inet_sk_set_state(newsk, SCTP_SS_ESTABLISHED); |
| 9626 |
} |
| 9627 |
|
| 9628 |
release_sock(newsk); |
| 9629 |
|
| 9630 |
return 0; |
| 9631 |
} |
| 9632 |
|
| 9633 |
|
| 9634 |
/* This proto struct describes the ULP interface for SCTP. */ |
| 9635 |
struct proto sctp_prot = { |
| 9636 |
.name = "SCTP", |
| 9637 |
.owner = THIS_MODULE, |
| 9638 |
.close = sctp_close, |
| 9639 |
.disconnect = sctp_disconnect, |
| 9640 |
.accept = sctp_accept, |
| 9641 |
.ioctl = sctp_ioctl, |
| 9642 |
.init = sctp_init_sock, |
| 9643 |
.destroy = sctp_destroy_sock, |
| 9644 |
.shutdown = sctp_shutdown, |
| 9645 |
.setsockopt = sctp_setsockopt, |
| 9646 |
.getsockopt = sctp_getsockopt, |
| 9647 |
.bpf_bypass_getsockopt = sctp_bpf_bypass_getsockopt, |
| 9648 |
.sendmsg = sctp_sendmsg, |
| 9649 |
.recvmsg = sctp_recvmsg, |
| 9650 |
.bind = sctp_bind, |
| 9651 |
.bind_add = sctp_bind_add, |
| 9652 |
.backlog_rcv = sctp_backlog_rcv, |
| 9653 |
.hash = sctp_hash, |
| 9654 |
.unhash = sctp_unhash, |
| 9655 |
.no_autobind = true, |
| 9656 |
.obj_size = sizeof(struct sctp_sock), |
| 9657 |
.useroffset = offsetof(struct sctp_sock, subscribe), |
| 9658 |
.usersize = offsetof(struct sctp_sock, initmsg) - |
| 9659 |
offsetof(struct sctp_sock, subscribe) + |
| 9660 |
sizeof_field(struct sctp_sock, initmsg), |
| 9661 |
.sysctl_mem = sysctl_sctp_mem, |
| 9662 |
.sysctl_rmem = sysctl_sctp_rmem, |
| 9663 |
.sysctl_wmem = sysctl_sctp_wmem, |
| 9664 |
.memory_pressure = &sctp_memory_pressure, |
| 9665 |
.enter_memory_pressure = sctp_enter_memory_pressure, |
| 9666 |
|
| 9667 |
.memory_allocated = &sctp_memory_allocated, |
| 9668 |
.per_cpu_fw_alloc = &sctp_memory_per_cpu_fw_alloc, |
| 9669 |
|
| 9670 |
.sockets_allocated = &sctp_sockets_allocated, |
| 9671 |
}; |
| 9672 |
|
| 9673 |
#if IS_ENABLED(CONFIG_IPV6) |
| 9674 |
|
| 9675 |
static void sctp_v6_destruct_sock(struct sock *sk) |
| 9676 |
{ |
| 9677 |
inet6_sock_destruct(sk); |
| 9678 |
} |
| 9679 |
|
| 9680 |
static int sctp_v6_init_sock(struct sock *sk) |
| 9681 |
{ |
| 9682 |
int ret = sctp_init_sock(sk); |
| 9683 |
|
| 9684 |
if (!ret) |
| 9685 |
sk->sk_destruct = sctp_v6_destruct_sock; |
| 9686 |
|
| 9687 |
return ret; |
| 9688 |
} |
| 9689 |
|
| 9690 |
struct proto sctpv6_prot = { |
| 9691 |
.name = "SCTPv6", |
| 9692 |
.owner = THIS_MODULE, |
| 9693 |
.close = sctp_close, |
| 9694 |
.disconnect = sctp_disconnect, |
| 9695 |
.accept = sctp_accept, |
| 9696 |
.ioctl = sctp_ioctl, |
| 9697 |
.init = sctp_v6_init_sock, |
| 9698 |
.destroy = sctp_destroy_sock, |
| 9699 |
.shutdown = sctp_shutdown, |
| 9700 |
.setsockopt = sctp_setsockopt, |
| 9701 |
.getsockopt = sctp_getsockopt, |
| 9702 |
.bpf_bypass_getsockopt = sctp_bpf_bypass_getsockopt, |
| 9703 |
.sendmsg = sctp_sendmsg, |
| 9704 |
.recvmsg = sctp_recvmsg, |
| 9705 |
.bind = sctp_bind, |
| 9706 |
.bind_add = sctp_bind_add, |
| 9707 |
.backlog_rcv = sctp_backlog_rcv, |
| 9708 |
.hash = sctp_hash, |
| 9709 |
.unhash = sctp_unhash, |
| 9710 |
.no_autobind = true, |
| 9711 |
.obj_size = sizeof(struct sctp6_sock), |
| 9712 |
.ipv6_pinfo_offset = offsetof(struct sctp6_sock, inet6), |
| 9713 |
.useroffset = offsetof(struct sctp6_sock, sctp.subscribe), |
| 9714 |
.usersize = offsetof(struct sctp6_sock, sctp.initmsg) - |
| 9715 |
offsetof(struct sctp6_sock, sctp.subscribe) + |
| 9716 |
sizeof_field(struct sctp6_sock, sctp.initmsg), |
| 9717 |
.sysctl_mem = sysctl_sctp_mem, |
| 9718 |
.sysctl_rmem = sysctl_sctp_rmem, |
| 9719 |
.sysctl_wmem = sysctl_sctp_wmem, |
| 9720 |
.memory_pressure = &sctp_memory_pressure, |
| 9721 |
.enter_memory_pressure = sctp_enter_memory_pressure, |
| 9722 |
|
| 9723 |
.memory_allocated = &sctp_memory_allocated, |
| 9724 |
.per_cpu_fw_alloc = &sctp_memory_per_cpu_fw_alloc, |
| 9725 |
|
| 9726 |
.sockets_allocated = &sctp_sockets_allocated, |
| 9727 |
}; |
| 9728 |
#endif /* IS_ENABLED(CONFIG_IPV6) */ |