^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* SCTP kernel implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * (C) Copyright IBM Corp. 2001, 2004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 1999-2000 Cisco, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 1999-2001 Motorola, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 2001-2003 Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (c) 2001-2002 Nokia, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (c) 2001 La Monte H.P. Yarroll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * This file is part of the SCTP kernel implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * These functions interface with the sockets layer to implement the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * SCTP Extensions for the Sockets API.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Note that the descriptions from the specification are USER level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * functions--this file is the functions which populate the struct proto
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * for SCTP which is the BOTTOM of the sockets interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Please send any bug reports or fixes you make to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * email address(es):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * lksctp developers <linux-sctp@vger.kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * Written or modified by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * La Monte H.P. Yarroll <piggy@acm.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * Narasimha Budihal <narsi@refcode.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * Karl Knutson <karl@athena.chicago.il.us>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * Jon Grimm <jgrimm@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * Xingang Guo <xingang.guo@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * Daisy Chang <daisyc@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Sridhar Samudrala <samudrala@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * Inaky Perez-Gonzalez <inaky.gonzalez@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * Ardelle Fan <ardelle.fan@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * Ryan Layer <rmlayer@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * Anup Pemmaiah <pemmaiah@cc.usu.edu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * Kevin Gao <kevin.gao@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <crypto/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <linux/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #include <linux/rhashtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #include <net/icmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #include <net/route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #include <net/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #include <net/inet_common.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #include <net/busy_poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #include <linux/socket.h> /* for sa_family_t */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #include <net/sctp/sctp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #include <net/sctp/sm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #include <net/sctp/stream_sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /* Forward declarations for internal helper functions. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static bool sctp_writeable(struct sock *sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static void sctp_wfree(struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static int sctp_wait_for_sndbuf(struct sctp_association *asoc, long *timeo_p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) size_t msg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static int sctp_wait_for_packet(struct sock *sk, int *err, long *timeo_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static int sctp_wait_for_connect(struct sctp_association *, long *timeo_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static int sctp_wait_for_accept(struct sock *sk, long timeo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static void sctp_wait_for_close(struct sock *sk, long timeo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static void sctp_destruct_sock(struct sock *sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static struct sctp_af *sctp_sockaddr_af(struct sctp_sock *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) union sctp_addr *addr, int len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static int sctp_bindx_add(struct sock *, struct sockaddr *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static int sctp_bindx_rem(struct sock *, struct sockaddr *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static int sctp_send_asconf_add_ip(struct sock *, struct sockaddr *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static int sctp_send_asconf_del_ip(struct sock *, struct sockaddr *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static int sctp_send_asconf(struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct sctp_chunk *chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static int sctp_do_bind(struct sock *, union sctp_addr *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) static int sctp_autobind(struct sock *sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct sctp_association *assoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) enum sctp_socket_type type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static unsigned long sctp_memory_pressure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) static atomic_long_t sctp_memory_allocated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct percpu_counter sctp_sockets_allocated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static void sctp_enter_memory_pressure(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) sctp_memory_pressure = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /* Get the sndbuf space available at the time on the association. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static inline int sctp_wspace(struct sctp_association *asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct sock *sk = asoc->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return asoc->ep->sndbuf_policy ? sk->sk_sndbuf - asoc->sndbuf_used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) : sk_stream_wspace(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /* Increment the used sndbuf space count of the corresponding association by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * the size of the outgoing data chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * Also, set the skb destructor for sndbuf accounting later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * Since it is always 1-1 between chunk and skb, and also a new skb is always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * allocated for chunk bundling in sctp_packet_transmit(), we can use the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * destructor in the data chunk skb for the purpose of the sndbuf space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * tracking.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static inline void sctp_set_owner_w(struct sctp_chunk *chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct sctp_association *asoc = chunk->asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct sock *sk = asoc->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* The sndbuf space is tracked per association. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) sctp_association_hold(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (chunk->shkey)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) sctp_auth_shkey_hold(chunk->shkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) skb_set_owner_w(chunk->skb, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) chunk->skb->destructor = sctp_wfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /* Save the chunk pointer in skb for sctp_wfree to use later. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) skb_shinfo(chunk->skb)->destructor_arg = chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) refcount_add(sizeof(struct sctp_chunk), &sk->sk_wmem_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) asoc->sndbuf_used += chunk->skb->truesize + sizeof(struct sctp_chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) sk->sk_wmem_queued += chunk->skb->truesize + sizeof(struct sctp_chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) sk_mem_charge(sk, chunk->skb->truesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static void sctp_clear_owner_w(struct sctp_chunk *chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) skb_orphan(chunk->skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) #define traverse_and_process() \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) msg = chunk->msg; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (msg == prev_msg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) continue; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) list_for_each_entry(c, &msg->chunks, frag_list) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if ((clear && asoc->base.sk == c->skb->sk) || \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) (!clear && asoc->base.sk != c->skb->sk)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) cb(c); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) prev_msg = msg; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static void sctp_for_each_tx_datachunk(struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) bool clear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) void (*cb)(struct sctp_chunk *))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct sctp_datamsg *msg, *prev_msg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct sctp_outq *q = &asoc->outqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct sctp_chunk *chunk, *c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct sctp_transport *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) list_for_each_entry(t, &asoc->peer.transport_addr_list, transports)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) list_for_each_entry(chunk, &t->transmitted, transmitted_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) traverse_and_process();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) list_for_each_entry(chunk, &q->retransmit, transmitted_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) traverse_and_process();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) list_for_each_entry(chunk, &q->sacked, transmitted_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) traverse_and_process();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) list_for_each_entry(chunk, &q->abandoned, transmitted_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) traverse_and_process();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) list_for_each_entry(chunk, &q->out_chunk_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) traverse_and_process();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static void sctp_for_each_rx_skb(struct sctp_association *asoc, struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) void (*cb)(struct sk_buff *, struct sock *))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) struct sk_buff *skb, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) sctp_skb_for_each(skb, &asoc->ulpq.lobby, tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) cb(skb, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) sctp_skb_for_each(skb, &asoc->ulpq.reasm, tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) cb(skb, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) sctp_skb_for_each(skb, &asoc->ulpq.reasm_uo, tmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) cb(skb, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* Verify that this is a valid address. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static inline int sctp_verify_addr(struct sock *sk, union sctp_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct sctp_af *af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /* Verify basic sockaddr. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) af = sctp_sockaddr_af(sctp_sk(sk), addr, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (!af)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /* Is this a valid SCTP address? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (!af->addr_valid(addr, sctp_sk(sk), NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (!sctp_sk(sk)->pf->send_verify(sctp_sk(sk), (addr)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /* Look up the association by its id. If this is not a UDP-style
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * socket, the ID field is always ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct sctp_association *sctp_id2assoc(struct sock *sk, sctp_assoc_t id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) struct sctp_association *asoc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /* If this is not a UDP-style socket, assoc id should be ignored. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (!sctp_style(sk, UDP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /* Return NULL if the socket state is not ESTABLISHED. It
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * could be a TCP-style listening socket or a socket which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * hasn't yet called connect() to establish an association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (!sctp_sstate(sk, ESTABLISHED) && !sctp_sstate(sk, CLOSING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /* Get the first and the only association from the list. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (!list_empty(&sctp_sk(sk)->ep->asocs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) asoc = list_entry(sctp_sk(sk)->ep->asocs.next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) struct sctp_association, asocs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /* Otherwise this is a UDP-style socket. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (id <= SCTP_ALL_ASSOC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) spin_lock_bh(&sctp_assocs_id_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) asoc = (struct sctp_association *)idr_find(&sctp_assocs_id, (int)id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (asoc && (asoc->base.sk != sk || asoc->base.dead))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) asoc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) spin_unlock_bh(&sctp_assocs_id_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /* Look up the transport from an address and an assoc id. If both address and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * id are specified, the associations matching the address and the id should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * the same.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static struct sctp_transport *sctp_addr_id2transport(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) struct sockaddr_storage *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) sctp_assoc_t id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct sctp_association *addr_asoc = NULL, *id_asoc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct sctp_af *af = sctp_get_af_specific(addr->ss_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) union sctp_addr *laddr = (union sctp_addr *)addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) struct sctp_transport *transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (!af || sctp_verify_addr(sk, laddr, af->sockaddr_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) addr_asoc = sctp_endpoint_lookup_assoc(sctp_sk(sk)->ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) &transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (!addr_asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) id_asoc = sctp_id2assoc(sk, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (id_asoc && (id_asoc != addr_asoc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) sctp_get_pf_specific(sk->sk_family)->addr_to_user(sctp_sk(sk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) (union sctp_addr *)addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) return transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) /* API 3.1.2 bind() - UDP Style Syntax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * The syntax of bind() is,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * ret = bind(int sd, struct sockaddr *addr, int addrlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * sd - the socket descriptor returned by socket().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * addr - the address structure (struct sockaddr_in or struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * sockaddr_in6 [RFC 2553]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * addr_len - the size of the address structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static int sctp_bind(struct sock *sk, struct sockaddr *addr, int addr_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) pr_debug("%s: sk:%p, addr:%p, addr_len:%d\n", __func__, sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) addr, addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) /* Disallow binding twice. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (!sctp_sk(sk)->ep->base.bind_addr.port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) retval = sctp_do_bind(sk, (union sctp_addr *)addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) static int sctp_get_port_local(struct sock *, union sctp_addr *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) /* Verify this is a valid sockaddr. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) static struct sctp_af *sctp_sockaddr_af(struct sctp_sock *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) union sctp_addr *addr, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) struct sctp_af *af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) /* Check minimum size. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (len < sizeof (struct sockaddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if (!opt->pf->af_supported(addr->sa.sa_family, opt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (addr->sa.sa_family == AF_INET6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (len < SIN6_LEN_RFC2133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) /* V4 mapped address are really of AF_INET family */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) if (ipv6_addr_v4mapped(&addr->v6.sin6_addr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) !opt->pf->af_supported(AF_INET, opt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) /* If we get this far, af is valid. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) af = sctp_get_af_specific(addr->sa.sa_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) if (len < af->sockaddr_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) return af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) static void sctp_auto_asconf_init(struct sctp_sock *sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) struct net *net = sock_net(&sp->inet.sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) if (net->sctp.default_auto_asconf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) spin_lock(&net->sctp.addr_wq_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) list_add_tail(&sp->auto_asconf_list, &net->sctp.auto_asconf_splist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) spin_unlock(&net->sctp.addr_wq_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) sp->do_auto_asconf = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) /* Bind a local address either to an endpoint or to an association. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) static int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) struct sctp_endpoint *ep = sp->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) struct sctp_bind_addr *bp = &ep->base.bind_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) struct sctp_af *af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) unsigned short snum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) /* Common sockaddr verification. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) af = sctp_sockaddr_af(sp, addr, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) if (!af) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) pr_debug("%s: sk:%p, newaddr:%p, len:%d EINVAL\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) __func__, sk, addr, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) snum = ntohs(addr->v4.sin_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) pr_debug("%s: sk:%p, new addr:%pISc, port:%d, new port:%d, len:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) __func__, sk, &addr->sa, bp->port, snum, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) /* PF specific bind() address verification. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) if (!sp->pf->bind_verify(sp, addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) /* We must either be unbound, or bind to the same port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) * It's OK to allow 0 ports if we are already bound.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) * We'll just inhert an already bound port in this case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) if (bp->port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (!snum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) snum = bp->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) else if (snum != bp->port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) pr_debug("%s: new port %d doesn't match existing port "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) "%d\n", __func__, snum, bp->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) if (snum && inet_is_local_unbindable_port(net, snum))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) if (snum && inet_port_requires_bind_service(net, snum) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) !ns_capable(net->user_ns, CAP_NET_BIND_SERVICE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) /* See if the address matches any of the addresses we may have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) * already bound before checking against other endpoints.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) if (sctp_bind_addr_match(bp, addr, sp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) /* Make sure we are allowed to bind here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) * The function sctp_get_port_local() does duplicate address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) * detection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) addr->v4.sin_port = htons(snum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if (sctp_get_port_local(sk, addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) return -EADDRINUSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) /* Refresh ephemeral port. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) if (!bp->port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) bp->port = inet_sk(sk)->inet_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) sctp_auto_asconf_init(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) /* Add the address to the bind address list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) * Use GFP_ATOMIC since BHs will be disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) ret = sctp_add_bind_addr(bp, addr, af->sockaddr_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) SCTP_ADDR_SRC, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) sctp_put_port(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) /* Copy back into socket for getsockname() use. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) inet_sk(sk)->inet_sport = htons(inet_sk(sk)->inet_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) sp->pf->to_sk_saddr(addr, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) /* ADDIP Section 4.1.1 Congestion Control of ASCONF Chunks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) * R1) One and only one ASCONF Chunk MAY be in transit and unacknowledged
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) * at any one time. If a sender, after sending an ASCONF chunk, decides
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) * it needs to transfer another ASCONF Chunk, it MUST wait until the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) * ASCONF-ACK Chunk returns from the previous ASCONF Chunk before sending a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) * subsequent ASCONF. Note this restriction binds each side, so at any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) * time two ASCONF may be in-transit on any given association (one sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) * from each endpoint).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) static int sctp_send_asconf(struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) struct sctp_chunk *chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) /* If there is an outstanding ASCONF chunk, queue it for later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * transmission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) if (asoc->addip_last_asconf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) list_add_tail(&chunk->list, &asoc->addip_chunk_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) /* Hold the chunk until an ASCONF_ACK is received. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) sctp_chunk_hold(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) retval = sctp_primitive_ASCONF(asoc->base.net, asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) sctp_chunk_free(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) asoc->addip_last_asconf = chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) /* Add a list of addresses as bind addresses to local endpoint or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) * association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) * Basically run through each address specified in the addrs/addrcnt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) * array/length pair, determine if it is IPv6 or IPv4 and call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) * sctp_do_bind() on it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) * If any of them fails, then the operation will be reversed and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) * ones that were added will be removed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) * Only sctp_setsockopt_bindx() is supposed to call this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) static int sctp_bindx_add(struct sock *sk, struct sockaddr *addrs, int addrcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) int cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) void *addr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) struct sockaddr *sa_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) struct sctp_af *af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) pr_debug("%s: sk:%p, addrs:%p, addrcnt:%d\n", __func__, sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) addrs, addrcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) addr_buf = addrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) for (cnt = 0; cnt < addrcnt; cnt++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) /* The list may contain either IPv4 or IPv6 address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) * determine the address length for walking thru the list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) sa_addr = addr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) af = sctp_get_af_specific(sa_addr->sa_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) if (!af) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) goto err_bindx_add;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) retval = sctp_do_bind(sk, (union sctp_addr *)sa_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) af->sockaddr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) addr_buf += af->sockaddr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) err_bindx_add:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) if (retval < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) /* Failed. Cleanup the ones that have been added */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) if (cnt > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) sctp_bindx_rem(sk, addrs, cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) /* Send an ASCONF chunk with Add IP address parameters to all the peers of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) * associations that are part of the endpoint indicating that a list of local
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) * addresses are added to the endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) * If any of the addresses is already in the bind address list of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) * association, we do not send the chunk for that association. But it will not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) * affect other associations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) * Only sctp_setsockopt_bindx() is supposed to call this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) static int sctp_send_asconf_add_ip(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) struct sockaddr *addrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) int addrcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) struct sctp_sock *sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) struct sctp_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) struct sctp_bind_addr *bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) struct sctp_chunk *chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) struct sctp_sockaddr_entry *laddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) union sctp_addr *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) union sctp_addr saveaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) void *addr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) struct sctp_af *af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) struct list_head *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) ep = sp->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) if (!ep->asconf_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) pr_debug("%s: sk:%p, addrs:%p, addrcnt:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) __func__, sk, addrs, addrcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) list_for_each_entry(asoc, &ep->asocs, asocs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) if (!asoc->peer.asconf_capable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) if (asoc->peer.addip_disabled_mask & SCTP_PARAM_ADD_IP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) if (!sctp_state(asoc, ESTABLISHED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) /* Check if any address in the packed array of addresses is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) * in the bind address list of the association. If so,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) * do not send the asconf chunk to its peer, but continue with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) * other associations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) addr_buf = addrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) for (i = 0; i < addrcnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) addr = addr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) af = sctp_get_af_specific(addr->v4.sin_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) if (!af) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) if (sctp_assoc_lookup_laddr(asoc, addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) addr_buf += af->sockaddr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) if (i < addrcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) /* Use the first valid address in bind addr list of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) * association as Address Parameter of ASCONF CHUNK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) bp = &asoc->base.bind_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) p = bp->address_list.next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) laddr = list_entry(p, struct sctp_sockaddr_entry, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) chunk = sctp_make_asconf_update_ip(asoc, &laddr->a, addrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) addrcnt, SCTP_PARAM_ADD_IP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) if (!chunk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) /* Add the new addresses to the bind address list with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) * use_as_src set to 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) addr_buf = addrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) for (i = 0; i < addrcnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) addr = addr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) af = sctp_get_af_specific(addr->v4.sin_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) memcpy(&saveaddr, addr, af->sockaddr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) retval = sctp_add_bind_addr(bp, &saveaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) sizeof(saveaddr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) SCTP_ADDR_NEW, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) addr_buf += af->sockaddr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) if (asoc->src_out_of_asoc_ok) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) struct sctp_transport *trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) list_for_each_entry(trans,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) &asoc->peer.transport_addr_list, transports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) trans->cwnd = min(4*asoc->pathmtu, max_t(__u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 2*asoc->pathmtu, 4380));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) trans->ssthresh = asoc->peer.i.a_rwnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) trans->rto = asoc->rto_initial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) sctp_max_rto(asoc, trans);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) trans->rtt = trans->srtt = trans->rttvar = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) /* Clear the source and route cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) sctp_transport_route(trans, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) sctp_sk(asoc->base.sk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) retval = sctp_send_asconf(asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) /* Remove a list of addresses from bind addresses list. Do not remove the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) * last address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) * Basically run through each address specified in the addrs/addrcnt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) * array/length pair, determine if it is IPv6 or IPv4 and call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) * sctp_del_bind() on it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) * If any of them fails, then the operation will be reversed and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) * ones that were removed will be added back.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) * At least one address has to be left; if only one address is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) * available, the operation will return -EBUSY.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) * Only sctp_setsockopt_bindx() is supposed to call this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) static int sctp_bindx_rem(struct sock *sk, struct sockaddr *addrs, int addrcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) struct sctp_endpoint *ep = sp->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) int cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) struct sctp_bind_addr *bp = &ep->base.bind_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) void *addr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) union sctp_addr *sa_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) struct sctp_af *af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) pr_debug("%s: sk:%p, addrs:%p, addrcnt:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) __func__, sk, addrs, addrcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) addr_buf = addrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) for (cnt = 0; cnt < addrcnt; cnt++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) /* If the bind address list is empty or if there is only one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) * bind address, there is nothing more to be removed (we need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) * at least one address here).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) if (list_empty(&bp->address_list) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) (sctp_list_single_entry(&bp->address_list))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) retval = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) goto err_bindx_rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) sa_addr = addr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) af = sctp_get_af_specific(sa_addr->sa.sa_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) if (!af) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) goto err_bindx_rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) if (!af->addr_valid(sa_addr, sp, NULL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) retval = -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) goto err_bindx_rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) if (sa_addr->v4.sin_port &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) sa_addr->v4.sin_port != htons(bp->port)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) goto err_bindx_rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) if (!sa_addr->v4.sin_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) sa_addr->v4.sin_port = htons(bp->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) /* FIXME - There is probably a need to check if sk->sk_saddr and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) * sk->sk_rcv_addr are currently set to one of the addresses to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) * be removed. This is something which needs to be looked into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) * when we are fixing the outstanding issues with multi-homing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) * socket routing and failover schemes. Refer to comments in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) * sctp_do_bind(). -daisy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) retval = sctp_del_bind_addr(bp, sa_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) addr_buf += af->sockaddr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) err_bindx_rem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) if (retval < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) /* Failed. Add the ones that has been removed back */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) if (cnt > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) sctp_bindx_add(sk, addrs, cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) /* Send an ASCONF chunk with Delete IP address parameters to all the peers of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) * the associations that are part of the endpoint indicating that a list of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) * local addresses are removed from the endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) * If any of the addresses is already in the bind address list of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) * association, we do not send the chunk for that association. But it will not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) * affect other associations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) * Only sctp_setsockopt_bindx() is supposed to call this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) static int sctp_send_asconf_del_ip(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) struct sockaddr *addrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) int addrcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) struct sctp_sock *sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) struct sctp_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) struct sctp_transport *transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) struct sctp_bind_addr *bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) struct sctp_chunk *chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) union sctp_addr *laddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) void *addr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) struct sctp_af *af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) struct sctp_sockaddr_entry *saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) int stored = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) chunk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) ep = sp->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) if (!ep->asconf_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) pr_debug("%s: sk:%p, addrs:%p, addrcnt:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) __func__, sk, addrs, addrcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) list_for_each_entry(asoc, &ep->asocs, asocs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) if (!asoc->peer.asconf_capable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) if (asoc->peer.addip_disabled_mask & SCTP_PARAM_DEL_IP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) if (!sctp_state(asoc, ESTABLISHED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) /* Check if any address in the packed array of addresses is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) * not present in the bind address list of the association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) * If so, do not send the asconf chunk to its peer, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) * continue with other associations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) addr_buf = addrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) for (i = 0; i < addrcnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) laddr = addr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) af = sctp_get_af_specific(laddr->v4.sin_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) if (!af) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) if (!sctp_assoc_lookup_laddr(asoc, laddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) addr_buf += af->sockaddr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) if (i < addrcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) /* Find one address in the association's bind address list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) * that is not in the packed array of addresses. This is to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) * make sure that we do not delete all the addresses in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) * association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) bp = &asoc->base.bind_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) laddr = sctp_find_unmatch_addr(bp, (union sctp_addr *)addrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) addrcnt, sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) if ((laddr == NULL) && (addrcnt == 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) if (asoc->asconf_addr_del_pending)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) asoc->asconf_addr_del_pending =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) kzalloc(sizeof(union sctp_addr), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) if (asoc->asconf_addr_del_pending == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) asoc->asconf_addr_del_pending->sa.sa_family =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) addrs->sa_family;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) asoc->asconf_addr_del_pending->v4.sin_port =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) htons(bp->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) if (addrs->sa_family == AF_INET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) struct sockaddr_in *sin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) sin = (struct sockaddr_in *)addrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) asoc->asconf_addr_del_pending->v4.sin_addr.s_addr = sin->sin_addr.s_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) } else if (addrs->sa_family == AF_INET6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) struct sockaddr_in6 *sin6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) sin6 = (struct sockaddr_in6 *)addrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) asoc->asconf_addr_del_pending->v6.sin6_addr = sin6->sin6_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) pr_debug("%s: keep the last address asoc:%p %pISc at %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) __func__, asoc, &asoc->asconf_addr_del_pending->sa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) asoc->asconf_addr_del_pending);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) asoc->src_out_of_asoc_ok = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) stored = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) goto skip_mkasconf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) if (laddr == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) /* We do not need RCU protection throughout this loop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) * because this is done under a socket lock from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) * setsockopt call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) chunk = sctp_make_asconf_update_ip(asoc, laddr, addrs, addrcnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) SCTP_PARAM_DEL_IP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) if (!chunk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) retval = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) skip_mkasconf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) /* Reset use_as_src flag for the addresses in the bind address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) * list that are to be deleted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) addr_buf = addrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) for (i = 0; i < addrcnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) laddr = addr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) af = sctp_get_af_specific(laddr->v4.sin_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) list_for_each_entry(saddr, &bp->address_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) if (sctp_cmp_addr_exact(&saddr->a, laddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) saddr->state = SCTP_ADDR_DEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) addr_buf += af->sockaddr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) /* Update the route and saddr entries for all the transports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) * as some of the addresses in the bind address list are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) * about to be deleted and cannot be used as source addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) list_for_each_entry(transport, &asoc->peer.transport_addr_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) transports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) sctp_transport_route(transport, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) sctp_sk(asoc->base.sk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) if (stored)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) /* We don't need to transmit ASCONF */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) retval = sctp_send_asconf(asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) /* set addr events to assocs in the endpoint. ep and addr_wq must be locked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) int sctp_asconf_mgmt(struct sctp_sock *sp, struct sctp_sockaddr_entry *addrw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) struct sock *sk = sctp_opt2sk(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) union sctp_addr *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) struct sctp_af *af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) /* It is safe to write port space in caller. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) addr = &addrw->a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) addr->v4.sin_port = htons(sp->ep->base.bind_addr.port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) af = sctp_get_af_specific(addr->sa.sa_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) if (!af)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) if (sctp_verify_addr(sk, addr, af->sockaddr_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) if (addrw->state == SCTP_ADDR_NEW)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) return sctp_send_asconf_add_ip(sk, (struct sockaddr *)addr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) return sctp_send_asconf_del_ip(sk, (struct sockaddr *)addr, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) /* Helper for tunneling sctp_bindx() requests through sctp_setsockopt()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) * API 8.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) * int sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) * int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) * If sd is an IPv4 socket, the addresses passed must be IPv4 addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) * If the sd is an IPv6 socket, the addresses passed can either be IPv4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) * or IPv6 addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) * A single address may be specified as INADDR_ANY or IN6ADDR_ANY, see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) * Section 3.1.2 for this usage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) * addrs is a pointer to an array of one or more socket addresses. Each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) * address is contained in its appropriate structure (i.e. struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) * sockaddr_in or struct sockaddr_in6) the family of the address type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) * must be used to distinguish the address length (note that this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) * representation is termed a "packed array" of addresses). The caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) * specifies the number of addresses in the array with addrcnt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) * On success, sctp_bindx() returns 0. On failure, sctp_bindx() returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) * -1, and sets errno to the appropriate error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) * For SCTP, the port given in each socket address must be the same, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) * sctp_bindx() will fail, setting errno to EINVAL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) * The flags parameter is formed from the bitwise OR of zero or more of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) * the following currently defined flags:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) * SCTP_BINDX_ADD_ADDR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) * SCTP_BINDX_REM_ADDR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) * SCTP_BINDX_ADD_ADDR directs SCTP to add the given addresses to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) * association, and SCTP_BINDX_REM_ADDR directs SCTP to remove the given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) * addresses from the association. The two flags are mutually exclusive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) * if both are given, sctp_bindx() will fail with EINVAL. A caller may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) * not remove all addresses from an association; sctp_bindx() will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) * reject such an attempt with EINVAL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) * An application can use sctp_bindx(SCTP_BINDX_ADD_ADDR) to associate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) * additional addresses with an endpoint after calling bind(). Or use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) * sctp_bindx(SCTP_BINDX_REM_ADDR) to remove some addresses a listening
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) * socket is associated with so that no new association accepted will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) * associated with those addresses. If the endpoint supports dynamic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) * address a SCTP_BINDX_REM_ADDR or SCTP_BINDX_ADD_ADDR may cause a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) * endpoint to send the appropriate message to the peer to change the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) * peers address lists.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) * Adding and removing addresses from a connected association is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) * optional functionality. Implementations that do not support this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) * functionality should return EOPNOTSUPP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) * Basically do nothing but copying the addresses from user to kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) * land and invoking either sctp_bindx_add() or sctp_bindx_rem() on the sk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) * This is used for tunneling the sctp_bindx() request through sctp_setsockopt()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) * from userspace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) * On exit there is no need to do sockfd_put(), sys_setsockopt() does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) * it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) * sk The sk of the socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) * addrs The pointer to the addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) * addrssize Size of the addrs buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) * op Operation to perform (add or remove, see the flags of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) * sctp_bindx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) * Returns 0 if ok, <0 errno code on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) static int sctp_setsockopt_bindx(struct sock *sk, struct sockaddr *addrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) int addrs_size, int op)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) int addrcnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) int walk_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) struct sockaddr *sa_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) void *addr_buf = addrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) struct sctp_af *af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) pr_debug("%s: sk:%p addrs:%p addrs_size:%d opt:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) __func__, sk, addr_buf, addrs_size, op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) if (unlikely(addrs_size <= 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) /* Walk through the addrs buffer and count the number of addresses. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) while (walk_size < addrs_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) if (walk_size + sizeof(sa_family_t) > addrs_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) sa_addr = addr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) af = sctp_get_af_specific(sa_addr->sa_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) /* If the address family is not supported or if this address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) * causes the address buffer to overflow return EINVAL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) if (!af || (walk_size + af->sockaddr_len) > addrs_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) addrcnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) addr_buf += af->sockaddr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) walk_size += af->sockaddr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) /* Do the work. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) switch (op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) case SCTP_BINDX_ADD_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) /* Allow security module to validate bindx addresses. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) err = security_sctp_bind_connect(sk, SCTP_SOCKOPT_BINDX_ADD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) addrs, addrs_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) err = sctp_bindx_add(sk, addrs, addrcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) return sctp_send_asconf_add_ip(sk, addrs, addrcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) case SCTP_BINDX_REM_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) err = sctp_bindx_rem(sk, addrs, addrcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) return sctp_send_asconf_del_ip(sk, addrs, addrcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) static int sctp_bind_add(struct sock *sk, struct sockaddr *addrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) int addrlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) err = sctp_setsockopt_bindx(sk, addrs, addrlen, SCTP_BINDX_ADD_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) static int sctp_connect_new_asoc(struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) const union sctp_addr *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) const struct sctp_initmsg *init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) struct sctp_transport **tp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) struct sock *sk = ep->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) enum sctp_scope scope;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) if (sctp_endpoint_is_peeled_off(ep, daddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) if (!ep->base.bind_addr.port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) if (sctp_autobind(sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) if (inet_is_local_unbindable_port(net, ep->base.bind_addr.port))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) if (inet_port_requires_bind_service(net, ep->base.bind_addr.port) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) !ns_capable(net->user_ns, CAP_NET_BIND_SERVICE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) scope = sctp_scope(daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) asoc = sctp_association_new(ep, sk, scope, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) if (!asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) err = sctp_assoc_set_bind_addr_from_ep(asoc, scope, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) *tp = sctp_assoc_add_peer(asoc, daddr, GFP_KERNEL, SCTP_UNKNOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) if (!*tp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) if (!init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) if (init->sinit_num_ostreams) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) __u16 outcnt = init->sinit_num_ostreams;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) asoc->c.sinit_num_ostreams = outcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) /* outcnt has been changed, need to re-init stream */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) err = sctp_stream_init(&asoc->stream, outcnt, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) if (init->sinit_max_instreams)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) asoc->c.sinit_max_instreams = init->sinit_max_instreams;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) if (init->sinit_max_attempts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) asoc->max_init_attempts = init->sinit_max_attempts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) if (init->sinit_max_init_timeo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) asoc->max_init_timeo =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) msecs_to_jiffies(init->sinit_max_init_timeo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) sctp_association_free(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) static int sctp_connect_add_peer(struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) union sctp_addr *daddr, int addr_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) struct sctp_endpoint *ep = asoc->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) struct sctp_association *old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) struct sctp_transport *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) err = sctp_verify_addr(ep->base.sk, daddr, addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) old = sctp_endpoint_lookup_assoc(ep, daddr, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) if (old && old != asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) return old->state >= SCTP_STATE_ESTABLISHED ? -EISCONN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) : -EALREADY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) if (sctp_endpoint_is_peeled_off(ep, daddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) t = sctp_assoc_add_peer(asoc, daddr, GFP_KERNEL, SCTP_UNKNOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) if (!t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) /* __sctp_connect(struct sock* sk, struct sockaddr *kaddrs, int addrs_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) * Common routine for handling connect() and sctp_connectx().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) * Connect will come in with just a single address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) static int __sctp_connect(struct sock *sk, struct sockaddr *kaddrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) int addrs_size, int flags, sctp_assoc_t *assoc_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) struct sctp_endpoint *ep = sp->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) struct sctp_transport *transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) void *addr_buf = kaddrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) union sctp_addr *daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) struct sctp_af *af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) int walk_size, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) long timeo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) if (sctp_sstate(sk, ESTABLISHED) || sctp_sstate(sk, CLOSING) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) return -EISCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) daddr = addr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) af = sctp_get_af_specific(daddr->sa.sa_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) if (!af || af->sockaddr_len > addrs_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) err = sctp_verify_addr(sk, daddr, af->sockaddr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) asoc = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) if (asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) return asoc->state >= SCTP_STATE_ESTABLISHED ? -EISCONN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) : -EALREADY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) err = sctp_connect_new_asoc(ep, daddr, NULL, &transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) asoc = transport->asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) addr_buf += af->sockaddr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) walk_size = af->sockaddr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) while (walk_size < addrs_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) if (walk_size + sizeof(sa_family_t) > addrs_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) daddr = addr_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) af = sctp_get_af_specific(daddr->sa.sa_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) if (!af || af->sockaddr_len + walk_size > addrs_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) if (asoc->peer.port != ntohs(daddr->v4.sin_port))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) err = sctp_connect_add_peer(asoc, daddr, af->sockaddr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) addr_buf += af->sockaddr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) walk_size += af->sockaddr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) /* In case the user of sctp_connectx() wants an association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) * id back, assign one now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) if (assoc_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) err = sctp_assoc_set_id(asoc, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) err = sctp_primitive_ASSOCIATE(sock_net(sk), asoc, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) /* Initialize sk's dport and daddr for getpeername() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) inet_sk(sk)->inet_dport = htons(asoc->peer.port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) sp->pf->to_sk_daddr(daddr, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) sk->sk_err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) if (assoc_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) *assoc_id = asoc->assoc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) return sctp_wait_for_connect(asoc, &timeo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) pr_debug("%s: took out_free path with asoc:%p kaddrs:%p err:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) __func__, asoc, kaddrs, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) sctp_association_free(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) /* Helper for tunneling sctp_connectx() requests through sctp_setsockopt()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) * API 8.9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) * int sctp_connectx(int sd, struct sockaddr *addrs, int addrcnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) * sctp_assoc_t *asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) * If sd is an IPv4 socket, the addresses passed must be IPv4 addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) * If the sd is an IPv6 socket, the addresses passed can either be IPv4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) * or IPv6 addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) * A single address may be specified as INADDR_ANY or IN6ADDR_ANY, see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) * Section 3.1.2 for this usage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) * addrs is a pointer to an array of one or more socket addresses. Each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) * address is contained in its appropriate structure (i.e. struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) * sockaddr_in or struct sockaddr_in6) the family of the address type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) * must be used to distengish the address length (note that this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) * representation is termed a "packed array" of addresses). The caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) * specifies the number of addresses in the array with addrcnt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) * On success, sctp_connectx() returns 0. It also sets the assoc_id to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) * the association id of the new association. On failure, sctp_connectx()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) * returns -1, and sets errno to the appropriate error code. The assoc_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) * is not touched by the kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) * For SCTP, the port given in each socket address must be the same, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) * sctp_connectx() will fail, setting errno to EINVAL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) * An application can use sctp_connectx to initiate an association with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) * an endpoint that is multi-homed. Much like sctp_bindx() this call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) * allows a caller to specify multiple addresses at which a peer can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) * reached. The way the SCTP stack uses the list of addresses to set up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) * the association is implementation dependent. This function only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) * specifies that the stack will try to make use of all the addresses in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) * the list when needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) * Note that the list of addresses passed in is only used for setting up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) * the association. It does not necessarily equal the set of addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) * the peer uses for the resulting association. If the caller wants to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) * find out the set of peer addresses, it must use sctp_getpaddrs() to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) * retrieve them after the association has been set up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) * Basically do nothing but copying the addresses from user to kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) * land and invoking either sctp_connectx(). This is used for tunneling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) * the sctp_connectx() request through sctp_setsockopt() from userspace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) * On exit there is no need to do sockfd_put(), sys_setsockopt() does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) * it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) * sk The sk of the socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) * addrs The pointer to the addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) * addrssize Size of the addrs buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) * Returns >=0 if ok, <0 errno code on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) static int __sctp_setsockopt_connectx(struct sock *sk, struct sockaddr *kaddrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) int addrs_size, sctp_assoc_t *assoc_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) int err = 0, flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) pr_debug("%s: sk:%p addrs:%p addrs_size:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) __func__, sk, kaddrs, addrs_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) /* make sure the 1st addr's sa_family is accessible later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) if (unlikely(addrs_size < sizeof(sa_family_t)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) /* Allow security module to validate connectx addresses. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) err = security_sctp_bind_connect(sk, SCTP_SOCKOPT_CONNECTX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) (struct sockaddr *)kaddrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) addrs_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) /* in-kernel sockets don't generally have a file allocated to them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) * if all they do is call sock_create_kern().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) if (sk->sk_socket->file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) flags = sk->sk_socket->file->f_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) return __sctp_connect(sk, kaddrs, addrs_size, flags, assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) * This is an older interface. It's kept for backward compatibility
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) * to the option that doesn't provide association id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) static int sctp_setsockopt_connectx_old(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) struct sockaddr *kaddrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) int addrs_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) return __sctp_setsockopt_connectx(sk, kaddrs, addrs_size, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) * New interface for the API. The since the API is done with a socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) * option, to make it simple we feed back the association id is as a return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) * indication to the call. Error is always negative and association id is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) * always positive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) static int sctp_setsockopt_connectx(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) struct sockaddr *kaddrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) int addrs_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) sctp_assoc_t assoc_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) err = __sctp_setsockopt_connectx(sk, kaddrs, addrs_size, &assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) return assoc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) * New (hopefully final) interface for the API.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) * We use the sctp_getaddrs_old structure so that use-space library
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) * can avoid any unnecessary allocations. The only different part
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) * is that we store the actual length of the address buffer into the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) * addrs_num structure member. That way we can re-use the existing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) * code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) struct compat_sctp_getaddrs_old {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) sctp_assoc_t assoc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) s32 addr_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) compat_uptr_t addrs; /* struct sockaddr * */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) static int sctp_getsockopt_connectx3(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) struct sctp_getaddrs_old param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) sctp_assoc_t assoc_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) struct sockaddr *kaddrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) if (in_compat_syscall()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) struct compat_sctp_getaddrs_old param32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) if (len < sizeof(param32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) if (copy_from_user(¶m32, optval, sizeof(param32)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) param.assoc_id = param32.assoc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) param.addr_num = param32.addr_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) param.addrs = compat_ptr(param32.addrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) if (len < sizeof(param))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) if (copy_from_user(¶m, optval, sizeof(param)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) kaddrs = memdup_user(param.addrs, param.addr_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) if (IS_ERR(kaddrs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) return PTR_ERR(kaddrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) err = __sctp_setsockopt_connectx(sk, kaddrs, param.addr_num, &assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) kfree(kaddrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) if (err == 0 || err == -EINPROGRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) if (copy_to_user(optval, &assoc_id, sizeof(assoc_id)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) if (put_user(sizeof(assoc_id), optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) /* API 3.1.4 close() - UDP Style Syntax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) * Applications use close() to perform graceful shutdown (as described in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) * Section 10.1 of [SCTP]) on ALL the associations currently represented
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) * by a UDP-style socket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) * The syntax is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) * ret = close(int sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) * sd - the socket descriptor of the associations to be closed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) * To gracefully shutdown a specific association represented by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) * UDP-style socket, an application should use the sendmsg() call,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) * passing no user data, but including the appropriate flag in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) * ancillary data (see Section xxxx).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) * If sd in the close() call is a branched-off socket representing only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) * one association, the shutdown is performed on that association only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) * 4.1.6 close() - TCP Style Syntax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) * Applications use close() to gracefully close down an association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) * The syntax is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) * int close(int sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) * sd - the socket descriptor of the association to be closed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) * After an application calls close() on a socket descriptor, no further
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) * socket operations will succeed on that descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) * API 7.1.4 SO_LINGER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) * An application using the TCP-style socket can use this option to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) * perform the SCTP ABORT primitive. The linger option structure is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) * struct linger {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) * int l_onoff; // option on/off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) * int l_linger; // linger time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) * };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) * To enable the option, set l_onoff to 1. If the l_linger value is set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) * to 0, calling close() is the same as the ABORT primitive. If the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) * value is set to a negative value, the setsockopt() call will return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) * an error. If the value is set to a positive value linger_time, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) * close() can be blocked for at most linger_time ms. If the graceful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) * shutdown phase does not finish during this period, close() will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) * return but the graceful shutdown phase continues in the system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) static void sctp_close(struct sock *sk, long timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) struct sctp_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) struct list_head *pos, *temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) unsigned int data_was_unread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) pr_debug("%s: sk:%p, timeout:%ld\n", __func__, sk, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) sk->sk_shutdown = SHUTDOWN_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) inet_sk_set_state(sk, SCTP_SS_CLOSING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) ep = sctp_sk(sk)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) /* Clean up any skbs sitting on the receive queue. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) data_was_unread = sctp_queue_purge_ulpevents(&sk->sk_receive_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) data_was_unread += sctp_queue_purge_ulpevents(&sctp_sk(sk)->pd_lobby);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) /* Walk all associations on an endpoint. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) list_for_each_safe(pos, temp, &ep->asocs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) asoc = list_entry(pos, struct sctp_association, asocs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) if (sctp_style(sk, TCP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) /* A closed association can still be in the list if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) * it belongs to a TCP-style listening socket that is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) * not yet accepted. If so, free it. If not, send an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) * ABORT or SHUTDOWN based on the linger options.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) if (sctp_state(asoc, CLOSED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) sctp_association_free(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) if (data_was_unread || !skb_queue_empty(&asoc->ulpq.lobby) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) !skb_queue_empty(&asoc->ulpq.reasm) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) !skb_queue_empty(&asoc->ulpq.reasm_uo) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) struct sctp_chunk *chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) chunk = sctp_make_abort_user(asoc, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) sctp_primitive_ABORT(net, asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) sctp_primitive_SHUTDOWN(net, asoc, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) /* On a TCP-style socket, block for at most linger_time if set. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) if (sctp_style(sk, TCP) && timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) sctp_wait_for_close(sk, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) /* This will run the backlog queue. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) /* Supposedly, no process has access to the socket, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) * the net layers still may.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) * Also, sctp_destroy_sock() needs to be called with addr_wq_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) * held and that should be grabbed before socket lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) spin_lock_bh(&net->sctp.addr_wq_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) bh_lock_sock_nested(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) /* Hold the sock, since sk_common_release() will put sock_put()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) * and we have just a little more cleanup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) sock_hold(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) sk_common_release(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) bh_unlock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) spin_unlock_bh(&net->sctp.addr_wq_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) sock_put(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) SCTP_DBG_OBJCNT_DEC(sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) /* Handle EPIPE error. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) static int sctp_error(struct sock *sk, int flags, int err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) if (err == -EPIPE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) err = sock_error(sk) ? : -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) if (err == -EPIPE && !(flags & MSG_NOSIGNAL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) send_sig(SIGPIPE, current, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) /* API 3.1.3 sendmsg() - UDP Style Syntax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) * An application uses sendmsg() and recvmsg() calls to transmit data to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) * and receive data from its peer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) * ssize_t sendmsg(int socket, const struct msghdr *message,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) * int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) * socket - the socket descriptor of the endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) * message - pointer to the msghdr structure which contains a single
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) * user message and possibly some ancillary data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) * See Section 5 for complete description of the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) * structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) * flags - flags sent or received with the user message, see Section
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) * 5 for complete description of the flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) * Note: This function could use a rewrite especially when explicit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) * connect support comes in.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) /* BUG: We do not implement the equivalent of sk_stream_wait_memory(). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) static int sctp_msghdr_parse(const struct msghdr *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) struct sctp_cmsgs *cmsgs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) static int sctp_sendmsg_parse(struct sock *sk, struct sctp_cmsgs *cmsgs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) struct sctp_sndrcvinfo *srinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) const struct msghdr *msg, size_t msg_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) __u16 sflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) if (sctp_sstate(sk, LISTENING) && sctp_style(sk, TCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) return -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) if (msg_len > sk->sk_sndbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) memset(cmsgs, 0, sizeof(*cmsgs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) err = sctp_msghdr_parse(msg, cmsgs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) pr_debug("%s: msghdr parse err:%x\n", __func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) memset(srinfo, 0, sizeof(*srinfo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) if (cmsgs->srinfo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) srinfo->sinfo_stream = cmsgs->srinfo->sinfo_stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) srinfo->sinfo_flags = cmsgs->srinfo->sinfo_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) srinfo->sinfo_ppid = cmsgs->srinfo->sinfo_ppid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) srinfo->sinfo_context = cmsgs->srinfo->sinfo_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) srinfo->sinfo_assoc_id = cmsgs->srinfo->sinfo_assoc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) srinfo->sinfo_timetolive = cmsgs->srinfo->sinfo_timetolive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) if (cmsgs->sinfo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) srinfo->sinfo_stream = cmsgs->sinfo->snd_sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) srinfo->sinfo_flags = cmsgs->sinfo->snd_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) srinfo->sinfo_ppid = cmsgs->sinfo->snd_ppid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) srinfo->sinfo_context = cmsgs->sinfo->snd_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) srinfo->sinfo_assoc_id = cmsgs->sinfo->snd_assoc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) if (cmsgs->prinfo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) srinfo->sinfo_timetolive = cmsgs->prinfo->pr_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) SCTP_PR_SET_POLICY(srinfo->sinfo_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) cmsgs->prinfo->pr_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) sflags = srinfo->sinfo_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) if (!sflags && msg_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) if (sctp_style(sk, TCP) && (sflags & (SCTP_EOF | SCTP_ABORT)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) if (((sflags & SCTP_EOF) && msg_len > 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) (!(sflags & (SCTP_EOF | SCTP_ABORT)) && msg_len == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) if ((sflags & SCTP_ADDR_OVER) && !msg->msg_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) static int sctp_sendmsg_new_asoc(struct sock *sk, __u16 sflags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) struct sctp_cmsgs *cmsgs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) union sctp_addr *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) struct sctp_transport **tp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) struct sctp_endpoint *ep = sctp_sk(sk)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) struct cmsghdr *cmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) __be32 flowinfo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) struct sctp_af *af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) *tp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) if (sflags & (SCTP_EOF | SCTP_ABORT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) if (sctp_style(sk, TCP) && (sctp_sstate(sk, ESTABLISHED) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) sctp_sstate(sk, CLOSING)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) /* Label connection socket for first association 1-to-many
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) * style for client sequence socket()->sendmsg(). This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) * needs to be done before sctp_assoc_add_peer() as that will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) * set up the initial packet that needs to account for any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) * security ip options (CIPSO/CALIPSO) added to the packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) af = sctp_get_af_specific(daddr->sa.sa_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) if (!af)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) err = security_sctp_bind_connect(sk, SCTP_SENDMSG_CONNECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) (struct sockaddr *)daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) af->sockaddr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) err = sctp_connect_new_asoc(ep, daddr, cmsgs->init, tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) asoc = (*tp)->asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) if (!cmsgs->addrs_msg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) if (daddr->sa.sa_family == AF_INET6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) flowinfo = daddr->v6.sin6_flowinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) /* sendv addr list parse */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) for_each_cmsghdr(cmsg, cmsgs->addrs_msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) union sctp_addr _daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) int dlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) if (cmsg->cmsg_level != IPPROTO_SCTP ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) (cmsg->cmsg_type != SCTP_DSTADDRV4 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) cmsg->cmsg_type != SCTP_DSTADDRV6))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) daddr = &_daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) memset(daddr, 0, sizeof(*daddr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) dlen = cmsg->cmsg_len - sizeof(struct cmsghdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) if (cmsg->cmsg_type == SCTP_DSTADDRV4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) if (dlen < sizeof(struct in_addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) dlen = sizeof(struct in_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) daddr->v4.sin_family = AF_INET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) daddr->v4.sin_port = htons(asoc->peer.port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) memcpy(&daddr->v4.sin_addr, CMSG_DATA(cmsg), dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) if (dlen < sizeof(struct in6_addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) dlen = sizeof(struct in6_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) daddr->v6.sin6_flowinfo = flowinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) daddr->v6.sin6_family = AF_INET6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) daddr->v6.sin6_port = htons(asoc->peer.port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) memcpy(&daddr->v6.sin6_addr, CMSG_DATA(cmsg), dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) err = sctp_connect_add_peer(asoc, daddr, sizeof(*daddr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) goto free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) sctp_association_free(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) static int sctp_sendmsg_check_sflags(struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) __u16 sflags, struct msghdr *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) size_t msg_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) struct sock *sk = asoc->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) if (sctp_state(asoc, CLOSED) && sctp_style(sk, TCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) return -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) if ((sflags & SCTP_SENDALL) && sctp_style(sk, UDP) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) !sctp_state(asoc, ESTABLISHED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) if (sflags & SCTP_EOF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) pr_debug("%s: shutting down association:%p\n", __func__, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) sctp_primitive_SHUTDOWN(net, asoc, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) if (sflags & SCTP_ABORT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) struct sctp_chunk *chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) chunk = sctp_make_abort_user(asoc, msg, msg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) if (!chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) pr_debug("%s: aborting association:%p\n", __func__, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) sctp_primitive_ABORT(net, asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) iov_iter_revert(&msg->msg_iter, msg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) static int sctp_sendmsg_to_asoc(struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) struct msghdr *msg, size_t msg_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) struct sctp_transport *transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) struct sctp_sndrcvinfo *sinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) struct sock *sk = asoc->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) struct sctp_datamsg *datamsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) bool wait_connect = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) struct sctp_chunk *chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) long timeo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) if (sinfo->sinfo_stream >= asoc->stream.outcnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) if (unlikely(!SCTP_SO(&asoc->stream, sinfo->sinfo_stream)->ext)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) err = sctp_stream_init_ext(&asoc->stream, sinfo->sinfo_stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) if (sp->disable_fragments && msg_len > asoc->frag_point) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) err = -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) if (asoc->pmtu_pending) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) if (sp->param_flags & SPP_PMTUD_ENABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) sctp_assoc_sync_pmtu(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) asoc->pmtu_pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) if (sctp_wspace(asoc) < (int)msg_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) sctp_prsctp_prune(asoc, sinfo, msg_len - sctp_wspace(asoc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) if (sk_under_memory_pressure(sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) sk_mem_reclaim(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) if (sctp_wspace(asoc) <= 0 || !sk_wmem_schedule(sk, msg_len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) err = sctp_wait_for_sndbuf(asoc, &timeo, msg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) if (sctp_state(asoc, CLOSED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) err = sctp_primitive_ASSOCIATE(net, asoc, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) if (asoc->ep->intl_enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) timeo = sock_sndtimeo(sk, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) err = sctp_wait_for_connect(asoc, &timeo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) err = -ESRCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) wait_connect = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) pr_debug("%s: we associated primitively\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) datamsg = sctp_datamsg_from_user(asoc, sinfo, &msg->msg_iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) if (IS_ERR(datamsg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) err = PTR_ERR(datamsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) asoc->force_delay = !!(msg->msg_flags & MSG_MORE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) list_for_each_entry(chunk, &datamsg->chunks, frag_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) sctp_chunk_hold(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) sctp_set_owner_w(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) chunk->transport = transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) err = sctp_primitive_SEND(net, asoc, datamsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) sctp_datamsg_free(datamsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) pr_debug("%s: we sent primitively\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) sctp_datamsg_put(datamsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) if (unlikely(wait_connect)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) sctp_wait_for_connect(asoc, &timeo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) err = msg_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) static union sctp_addr *sctp_sendmsg_get_daddr(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) const struct msghdr *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) struct sctp_cmsgs *cmsgs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) union sctp_addr *daddr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) if (!sctp_style(sk, UDP_HIGH_BANDWIDTH) && msg->msg_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) int len = msg->msg_namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) if (len > sizeof(*daddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) len = sizeof(*daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) daddr = (union sctp_addr *)msg->msg_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) err = sctp_verify_addr(sk, daddr, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) return daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) static void sctp_sendmsg_update_sinfo(struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) struct sctp_sndrcvinfo *sinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) struct sctp_cmsgs *cmsgs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) if (!cmsgs->srinfo && !cmsgs->sinfo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) sinfo->sinfo_stream = asoc->default_stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) sinfo->sinfo_ppid = asoc->default_ppid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) sinfo->sinfo_context = asoc->default_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) sinfo->sinfo_assoc_id = sctp_assoc2id(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) if (!cmsgs->prinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) sinfo->sinfo_flags = asoc->default_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) if (!cmsgs->srinfo && !cmsgs->prinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) sinfo->sinfo_timetolive = asoc->default_timetolive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) if (cmsgs->authinfo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) /* Reuse sinfo_tsn to indicate that authinfo was set and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) * sinfo_ssn to save the keyid on tx path.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) sinfo->sinfo_tsn = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) sinfo->sinfo_ssn = cmsgs->authinfo->auth_keynumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) static int sctp_sendmsg(struct sock *sk, struct msghdr *msg, size_t msg_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) struct sctp_endpoint *ep = sctp_sk(sk)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) struct sctp_transport *transport = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) struct sctp_sndrcvinfo _sinfo, *sinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) struct sctp_association *asoc, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) struct sctp_cmsgs cmsgs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) union sctp_addr *daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) bool new = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) __u16 sflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) /* Parse and get snd_info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) err = sctp_sendmsg_parse(sk, &cmsgs, &_sinfo, msg, msg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) sinfo = &_sinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) sflags = sinfo->sinfo_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) /* Get daddr from msg */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) daddr = sctp_sendmsg_get_daddr(sk, msg, &cmsgs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) if (IS_ERR(daddr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) err = PTR_ERR(daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) /* SCTP_SENDALL process */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) if ((sflags & SCTP_SENDALL) && sctp_style(sk, UDP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) list_for_each_entry_safe(asoc, tmp, &ep->asocs, asocs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) err = sctp_sendmsg_check_sflags(asoc, sflags, msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) msg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) if (err == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) sctp_sendmsg_update_sinfo(asoc, sinfo, &cmsgs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) err = sctp_sendmsg_to_asoc(asoc, msg, msg_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) NULL, sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) iov_iter_revert(&msg->msg_iter, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) /* Get and check or create asoc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) if (daddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) asoc = sctp_endpoint_lookup_assoc(ep, daddr, &transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) err = sctp_sendmsg_check_sflags(asoc, sflags, msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) msg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) if (err <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) err = sctp_sendmsg_new_asoc(sk, sflags, &cmsgs, daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) &transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) asoc = transport->asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) new = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) if (!sctp_style(sk, TCP) && !(sflags & SCTP_ADDR_OVER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) transport = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) asoc = sctp_id2assoc(sk, sinfo->sinfo_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) if (!asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) err = -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) err = sctp_sendmsg_check_sflags(asoc, sflags, msg, msg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) if (err <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) /* Update snd_info with the asoc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) sctp_sendmsg_update_sinfo(asoc, sinfo, &cmsgs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) /* Send msg to the asoc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) err = sctp_sendmsg_to_asoc(asoc, msg, msg_len, transport, sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) if (err < 0 && err != -ESRCH && new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) sctp_association_free(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) return sctp_error(sk, msg->msg_flags, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) /* This is an extended version of skb_pull() that removes the data from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) * start of a skb even when data is spread across the list of skb's in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) * frag_list. len specifies the total amount of data that needs to be removed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) * when 'len' bytes could be removed from the skb, it returns 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) * If 'len' exceeds the total skb length, it returns the no. of bytes that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) * could not be removed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) static int sctp_skb_pull(struct sk_buff *skb, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) struct sk_buff *list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) int skb_len = skb_headlen(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) int rlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) if (len <= skb_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) __skb_pull(skb, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) len -= skb_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) __skb_pull(skb, skb_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) skb_walk_frags(skb, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) rlen = sctp_skb_pull(list, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) skb->len -= (len-rlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) skb->data_len -= (len-rlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) if (!rlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) len = rlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) /* API 3.1.3 recvmsg() - UDP Style Syntax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) * ssize_t recvmsg(int socket, struct msghdr *message,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) * int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) * socket - the socket descriptor of the endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) * message - pointer to the msghdr structure which contains a single
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) * user message and possibly some ancillary data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) * See Section 5 for complete description of the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) * structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) * flags - flags sent or received with the user message, see Section
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) * 5 for complete description of the flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) static int sctp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) int noblock, int flags, int *addr_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) struct sctp_ulpevent *event = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) struct sk_buff *skb, *head_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) int copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) int skb_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) pr_debug("%s: sk:%p, msghdr:%p, len:%zd, noblock:%d, flags:0x%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) "addr_len:%p)\n", __func__, sk, msg, len, noblock, flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) if (sctp_style(sk, TCP) && !sctp_sstate(sk, ESTABLISHED) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) !sctp_sstate(sk, CLOSING) && !sctp_sstate(sk, CLOSED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) err = -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) skb = sctp_skb_recv_datagram(sk, flags, noblock, &err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) /* Get the total length of the skb including any skb's in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) * frag_list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) skb_len = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) copied = skb_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) if (copied > len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) copied = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) err = skb_copy_datagram_msg(skb, 0, msg, copied);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) event = sctp_skb2event(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) if (event->chunk && event->chunk->head_skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) head_skb = event->chunk->head_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) head_skb = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) sock_recv_ts_and_drops(msg, sk, head_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) if (sctp_ulpevent_is_notification(event)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) msg->msg_flags |= MSG_NOTIFICATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) sp->pf->event_msgname(event, msg->msg_name, addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) sp->pf->skb_msgname(head_skb, msg->msg_name, addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) /* Check if we allow SCTP_NXTINFO. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) if (sp->recvnxtinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) sctp_ulpevent_read_nxtinfo(event, msg, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) /* Check if we allow SCTP_RCVINFO. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) if (sp->recvrcvinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) sctp_ulpevent_read_rcvinfo(event, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) /* Check if we allow SCTP_SNDRCVINFO. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) if (sctp_ulpevent_type_enabled(sp->subscribe, SCTP_DATA_IO_EVENT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) sctp_ulpevent_read_sndrcvinfo(event, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) err = copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) /* If skb's length exceeds the user's buffer, update the skb and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) * push it back to the receive_queue so that the next call to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) * recvmsg() will return the remaining data. Don't set MSG_EOR.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) if (skb_len > copied) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) msg->msg_flags &= ~MSG_EOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) if (flags & MSG_PEEK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) sctp_skb_pull(skb, copied);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) skb_queue_head(&sk->sk_receive_queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) /* When only partial message is copied to the user, increase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) * rwnd by that amount. If all the data in the skb is read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) * rwnd is updated when the event is freed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) if (!sctp_ulpevent_is_notification(event))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) sctp_assoc_rwnd_increase(event->asoc, copied);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) } else if ((event->msg_flags & MSG_NOTIFICATION) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) (event->msg_flags & MSG_EOR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) msg->msg_flags |= MSG_EOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) msg->msg_flags &= ~MSG_EOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) if (flags & MSG_PEEK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) /* Release the skb reference acquired after peeking the skb in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) * sctp_skb_recv_datagram().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) /* Free the event which includes releasing the reference to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) * the owner of the skb, freeing the skb and updating the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) * rwnd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) sctp_ulpevent_free(event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) /* 7.1.12 Enable/Disable message fragmentation (SCTP_DISABLE_FRAGMENTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) * This option is a on/off flag. If enabled no SCTP message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) * fragmentation will be performed. Instead if a message being sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) * exceeds the current PMTU size, the message will NOT be sent and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) * instead a error will be indicated to the user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) static int sctp_setsockopt_disable_fragments(struct sock *sk, int *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) if (optlen < sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) sctp_sk(sk)->disable_fragments = (*val == 0) ? 0 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) static int sctp_setsockopt_events(struct sock *sk, __u8 *sn_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) if (optlen > sizeof(struct sctp_event_subscribe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) for (i = 0; i < optlen; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) sctp_ulpevent_type_set(&sp->subscribe, SCTP_SN_TYPE_BASE + i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) sn_type[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) list_for_each_entry(asoc, &sp->ep->asocs, asocs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) asoc->subscribe = sctp_sk(sk)->subscribe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) /* At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) * if there is no data to be sent or retransmit, the stack will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) * immediately send up this notification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) if (sctp_ulpevent_type_enabled(sp->subscribe, SCTP_SENDER_DRY_EVENT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) struct sctp_ulpevent *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) asoc = sctp_id2assoc(sk, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) if (asoc && sctp_outq_is_empty(&asoc->outqueue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) event = sctp_ulpevent_make_sender_dry_event(asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) GFP_USER | __GFP_NOWARN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) if (!event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) asoc->stream.si->enqueue_event(&asoc->ulpq, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) /* 7.1.8 Automatic Close of associations (SCTP_AUTOCLOSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) * This socket option is applicable to the UDP-style socket only. When
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) * set it will cause associations that are idle for more than the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) * specified number of seconds to automatically close. An association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) * being idle is defined an association that has NOT sent or received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) * user data. The special value of '0' indicates that no automatic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) * close of any associations should be performed. The option expects an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) * integer defining the number of seconds of idle time before an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) * association is closed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) static int sctp_setsockopt_autoclose(struct sock *sk, u32 *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) /* Applicable to UDP-style socket only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) if (sctp_style(sk, TCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) if (optlen != sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) sp->autoclose = *optval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) if (sp->autoclose > net->sctp.max_autoclose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) sp->autoclose = net->sctp.max_autoclose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) /* 7.1.13 Peer Address Parameters (SCTP_PEER_ADDR_PARAMS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) * Applications can enable or disable heartbeats for any peer address of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) * an association, modify an address's heartbeat interval, force a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) * heartbeat to be sent immediately, and adjust the address's maximum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) * number of retransmissions sent before an address is considered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) * unreachable. The following structure is used to access and modify an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) * address's parameters:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) * struct sctp_paddrparams {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) * sctp_assoc_t spp_assoc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) * struct sockaddr_storage spp_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) * uint32_t spp_hbinterval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) * uint16_t spp_pathmaxrxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) * uint32_t spp_pathmtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) * uint32_t spp_sackdelay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) * uint32_t spp_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) * uint32_t spp_ipv6_flowlabel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) * uint8_t spp_dscp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) * };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) * spp_assoc_id - (one-to-many style socket) This is filled in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) * application, and identifies the association for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) * this query.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) * spp_address - This specifies which address is of interest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) * spp_hbinterval - This contains the value of the heartbeat interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) * in milliseconds. If a value of zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) * is present in this field then no changes are to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) * be made to this parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) * spp_pathmaxrxt - This contains the maximum number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) * retransmissions before this address shall be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) * considered unreachable. If a value of zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) * is present in this field then no changes are to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) * be made to this parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317) * spp_pathmtu - When Path MTU discovery is disabled the value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) * specified here will be the "fixed" path mtu.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) * Note that if the spp_address field is empty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) * then all associations on this address will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) * have this fixed path mtu set upon them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) * spp_sackdelay - When delayed sack is enabled, this value specifies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) * the number of milliseconds that sacks will be delayed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) * for. This value will apply to all addresses of an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) * association if the spp_address field is empty. Note
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) * also, that if delayed sack is enabled and this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) * value is set to 0, no change is made to the last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) * recorded delayed sack timer value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) * spp_flags - These flags are used to control various features
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) * on an association. The flag field may contain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) * zero or more of the following options.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) * SPP_HB_ENABLE - Enable heartbeats on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) * specified address. Note that if the address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) * field is empty all addresses for the association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) * have heartbeats enabled upon them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) * SPP_HB_DISABLE - Disable heartbeats on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) * speicifed address. Note that if the address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) * field is empty all addresses for the association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) * will have their heartbeats disabled. Note also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) * that SPP_HB_ENABLE and SPP_HB_DISABLE are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) * mutually exclusive, only one of these two should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) * be specified. Enabling both fields will have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) * undetermined results.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) * SPP_HB_DEMAND - Request a user initiated heartbeat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) * to be made immediately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) * SPP_HB_TIME_IS_ZERO - Specify's that the time for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) * heartbeat delayis to be set to the value of 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) * milliseconds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) * SPP_PMTUD_ENABLE - This field will enable PMTU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) * discovery upon the specified address. Note that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) * if the address feild is empty then all addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) * on the association are effected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) * SPP_PMTUD_DISABLE - This field will disable PMTU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) * discovery upon the specified address. Note that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) * if the address feild is empty then all addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) * on the association are effected. Not also that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) * SPP_PMTUD_ENABLE and SPP_PMTUD_DISABLE are mutually
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) * exclusive. Enabling both will have undetermined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) * results.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) * SPP_SACKDELAY_ENABLE - Setting this flag turns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) * on delayed sack. The time specified in spp_sackdelay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) * is used to specify the sack delay for this address. Note
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) * that if spp_address is empty then all addresses will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) * enable delayed sack and take on the sack delay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) * value specified in spp_sackdelay.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) * SPP_SACKDELAY_DISABLE - Setting this flag turns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) * off delayed sack. If the spp_address field is blank then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) * delayed sack is disabled for the entire association. Note
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) * also that this field is mutually exclusive to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) * SPP_SACKDELAY_ENABLE, setting both will have undefined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) * results.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) * SPP_IPV6_FLOWLABEL: Setting this flag enables the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) * setting of the IPV6 flow label value. The value is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) * contained in the spp_ipv6_flowlabel field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) * Upon retrieval, this flag will be set to indicate that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) * the spp_ipv6_flowlabel field has a valid value returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) * If a specific destination address is set (in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) * spp_address field), then the value returned is that of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) * the address. If just an association is specified (and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) * no address), then the association's default flow label
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) * is returned. If neither an association nor a destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) * is specified, then the socket's default flow label is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) * returned. For non-IPv6 sockets, this flag will be left
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) * cleared.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) * SPP_DSCP: Setting this flag enables the setting of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) * Differentiated Services Code Point (DSCP) value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) * associated with either the association or a specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) * address. The value is obtained in the spp_dscp field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) * Upon retrieval, this flag will be set to indicate that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) * the spp_dscp field has a valid value returned. If a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) * specific destination address is set when called (in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) * spp_address field), then that specific destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) * address's DSCP value is returned. If just an association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) * is specified, then the association's default DSCP is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) * returned. If neither an association nor a destination is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) * specified, then the socket's default DSCP is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) * spp_ipv6_flowlabel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) * - This field is used in conjunction with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) * SPP_IPV6_FLOWLABEL flag and contains the IPv6 flow label.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) * The 20 least significant bits are used for the flow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) * label. This setting has precedence over any IPv6-layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) * setting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) * spp_dscp - This field is used in conjunction with the SPP_DSCP flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) * and contains the DSCP. The 6 most significant bits are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) * used for the DSCP. This setting has precedence over any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) * IPv4- or IPv6- layer setting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) static int sctp_apply_peer_addr_params(struct sctp_paddrparams *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) struct sctp_transport *trans,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) struct sctp_sock *sp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) int hb_change,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) int pmtud_change,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) int sackdelay_change)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) if (params->spp_flags & SPP_HB_DEMAND && trans) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) error = sctp_primitive_REQUESTHEARTBEAT(trans->asoc->base.net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) trans->asoc, trans);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) /* Note that unless the spp_flag is set to SPP_HB_ENABLE the value of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) * this field is ignored. Note also that a value of zero indicates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) * the current setting should be left unchanged.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) if (params->spp_flags & SPP_HB_ENABLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) /* Re-zero the interval if the SPP_HB_TIME_IS_ZERO is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) * set. This lets us use 0 value when this flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) * is set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) if (params->spp_flags & SPP_HB_TIME_IS_ZERO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) params->spp_hbinterval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) if (params->spp_hbinterval ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) (params->spp_flags & SPP_HB_TIME_IS_ZERO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) if (trans) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) trans->hbinterval =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) msecs_to_jiffies(params->spp_hbinterval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) } else if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) asoc->hbinterval =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) msecs_to_jiffies(params->spp_hbinterval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) sp->hbinterval = params->spp_hbinterval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) if (hb_change) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) if (trans) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) trans->param_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) (trans->param_flags & ~SPP_HB) | hb_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) } else if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) asoc->param_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) (asoc->param_flags & ~SPP_HB) | hb_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) sp->param_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) (sp->param_flags & ~SPP_HB) | hb_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) /* When Path MTU discovery is disabled the value specified here will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) * be the "fixed" path mtu (i.e. the value of the spp_flags field must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) * include the flag SPP_PMTUD_DISABLE for this field to have any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) * effect).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) if ((params->spp_flags & SPP_PMTUD_DISABLE) && params->spp_pathmtu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) if (trans) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) trans->pathmtu = params->spp_pathmtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) sctp_assoc_sync_pmtu(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) } else if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) sctp_assoc_set_pmtu(asoc, params->spp_pathmtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) sp->pathmtu = params->spp_pathmtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) if (pmtud_change) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) if (trans) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) int update = (trans->param_flags & SPP_PMTUD_DISABLE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) (params->spp_flags & SPP_PMTUD_ENABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) trans->param_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) (trans->param_flags & ~SPP_PMTUD) | pmtud_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) if (update) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) sctp_transport_pmtu(trans, sctp_opt2sk(sp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) sctp_assoc_sync_pmtu(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) } else if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) asoc->param_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) (asoc->param_flags & ~SPP_PMTUD) | pmtud_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) sp->param_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) (sp->param_flags & ~SPP_PMTUD) | pmtud_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) /* Note that unless the spp_flag is set to SPP_SACKDELAY_ENABLE the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) * value of this field is ignored. Note also that a value of zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) * indicates the current setting should be left unchanged.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) if ((params->spp_flags & SPP_SACKDELAY_ENABLE) && params->spp_sackdelay) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) if (trans) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) trans->sackdelay =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) msecs_to_jiffies(params->spp_sackdelay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) } else if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) asoc->sackdelay =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) msecs_to_jiffies(params->spp_sackdelay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) sp->sackdelay = params->spp_sackdelay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) if (sackdelay_change) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) if (trans) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) trans->param_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) (trans->param_flags & ~SPP_SACKDELAY) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) sackdelay_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) } else if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) asoc->param_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) (asoc->param_flags & ~SPP_SACKDELAY) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) sackdelay_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) sp->param_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) (sp->param_flags & ~SPP_SACKDELAY) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) sackdelay_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) /* Note that a value of zero indicates the current setting should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) left unchanged.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) if (params->spp_pathmaxrxt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) if (trans) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) trans->pathmaxrxt = params->spp_pathmaxrxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) } else if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) asoc->pathmaxrxt = params->spp_pathmaxrxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) sp->pathmaxrxt = params->spp_pathmaxrxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) if (params->spp_flags & SPP_IPV6_FLOWLABEL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) if (trans) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) if (trans->ipaddr.sa.sa_family == AF_INET6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) trans->flowlabel = params->spp_ipv6_flowlabel &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) SCTP_FLOWLABEL_VAL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) trans->flowlabel |= SCTP_FLOWLABEL_SET_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) } else if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) struct sctp_transport *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) list_for_each_entry(t, &asoc->peer.transport_addr_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) transports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) if (t->ipaddr.sa.sa_family != AF_INET6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) t->flowlabel = params->spp_ipv6_flowlabel &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) SCTP_FLOWLABEL_VAL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) t->flowlabel |= SCTP_FLOWLABEL_SET_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) asoc->flowlabel = params->spp_ipv6_flowlabel &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) SCTP_FLOWLABEL_VAL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) asoc->flowlabel |= SCTP_FLOWLABEL_SET_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) } else if (sctp_opt2sk(sp)->sk_family == AF_INET6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) sp->flowlabel = params->spp_ipv6_flowlabel &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) SCTP_FLOWLABEL_VAL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) sp->flowlabel |= SCTP_FLOWLABEL_SET_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) if (params->spp_flags & SPP_DSCP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) if (trans) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) trans->dscp = params->spp_dscp & SCTP_DSCP_VAL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) trans->dscp |= SCTP_DSCP_SET_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) } else if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) struct sctp_transport *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) list_for_each_entry(t, &asoc->peer.transport_addr_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) transports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) t->dscp = params->spp_dscp &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) SCTP_DSCP_VAL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) t->dscp |= SCTP_DSCP_SET_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) asoc->dscp = params->spp_dscp & SCTP_DSCP_VAL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) asoc->dscp |= SCTP_DSCP_SET_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) sp->dscp = params->spp_dscp & SCTP_DSCP_VAL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) sp->dscp |= SCTP_DSCP_SET_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) static int sctp_setsockopt_peer_addr_params(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) struct sctp_paddrparams *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) struct sctp_transport *trans = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) struct sctp_association *asoc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) int hb_change, pmtud_change, sackdelay_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) if (optlen == ALIGN(offsetof(struct sctp_paddrparams,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) spp_ipv6_flowlabel), 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) if (params->spp_flags & (SPP_DSCP | SPP_IPV6_FLOWLABEL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) } else if (optlen != sizeof(*params)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) /* Validate flags and value parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) hb_change = params->spp_flags & SPP_HB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) pmtud_change = params->spp_flags & SPP_PMTUD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) sackdelay_change = params->spp_flags & SPP_SACKDELAY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) if (hb_change == SPP_HB ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) pmtud_change == SPP_PMTUD ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) sackdelay_change == SPP_SACKDELAY ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) params->spp_sackdelay > 500 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) (params->spp_pathmtu &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) params->spp_pathmtu < SCTP_DEFAULT_MINSEGMENT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) /* If an address other than INADDR_ANY is specified, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) * no transport is found, then the request is invalid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) if (!sctp_is_any(sk, (union sctp_addr *)¶ms->spp_address)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) trans = sctp_addr_id2transport(sk, ¶ms->spp_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) params->spp_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) if (!trans)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) /* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) * socket is a one to many style socket, and an association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) * was not found, then the id was invalid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) asoc = sctp_id2assoc(sk, params->spp_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) if (!asoc && params->spp_assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) /* Heartbeat demand can only be sent on a transport or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) * association, but not a socket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) if (params->spp_flags & SPP_HB_DEMAND && !trans && !asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) /* Process parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) error = sctp_apply_peer_addr_params(params, trans, asoc, sp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) hb_change, pmtud_change,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) sackdelay_change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) /* If changes are for association, also apply parameters to each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) * transport.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) if (!trans && asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) list_for_each_entry(trans, &asoc->peer.transport_addr_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) transports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) sctp_apply_peer_addr_params(params, trans, asoc, sp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) hb_change, pmtud_change,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) sackdelay_change);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) static inline __u32 sctp_spp_sackdelay_enable(__u32 param_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) return (param_flags & ~SPP_SACKDELAY) | SPP_SACKDELAY_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) static inline __u32 sctp_spp_sackdelay_disable(__u32 param_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) return (param_flags & ~SPP_SACKDELAY) | SPP_SACKDELAY_DISABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) static void sctp_apply_asoc_delayed_ack(struct sctp_sack_info *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) struct sctp_association *asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) struct sctp_transport *trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) if (params->sack_delay) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) asoc->sackdelay = msecs_to_jiffies(params->sack_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) asoc->param_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) sctp_spp_sackdelay_enable(asoc->param_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) if (params->sack_freq == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) asoc->param_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) sctp_spp_sackdelay_disable(asoc->param_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) } else if (params->sack_freq > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) asoc->sackfreq = params->sack_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) asoc->param_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) sctp_spp_sackdelay_enable(asoc->param_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) list_for_each_entry(trans, &asoc->peer.transport_addr_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) transports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) if (params->sack_delay) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) trans->sackdelay = msecs_to_jiffies(params->sack_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) trans->param_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) sctp_spp_sackdelay_enable(trans->param_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) if (params->sack_freq == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) trans->param_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) sctp_spp_sackdelay_disable(trans->param_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) } else if (params->sack_freq > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) trans->sackfreq = params->sack_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) trans->param_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) sctp_spp_sackdelay_enable(trans->param_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) * 7.1.23. Get or set delayed ack timer (SCTP_DELAYED_SACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) * This option will effect the way delayed acks are performed. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) * option allows you to get or set the delayed ack time, in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) * milliseconds. It also allows changing the delayed ack frequency.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) * Changing the frequency to 1 disables the delayed sack algorithm. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) * the assoc_id is 0, then this sets or gets the endpoints default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) * values. If the assoc_id field is non-zero, then the set or get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) * effects the specified association for the one to many model (the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) * assoc_id field is ignored by the one to one model). Note that if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) * sack_delay or sack_freq are 0 when setting this option, then the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) * current values will remain unchanged.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) * struct sctp_sack_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) * sctp_assoc_t sack_assoc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) * uint32_t sack_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) * uint32_t sack_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) * };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) * sack_assoc_id - This parameter, indicates which association the user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) * is performing an action upon. Note that if this field's value is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) * zero then the endpoints default value is changed (effecting future
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) * associations only).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) * sack_delay - This parameter contains the number of milliseconds that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) * the user is requesting the delayed ACK timer be set to. Note that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) * this value is defined in the standard to be between 200 and 500
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) * milliseconds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) * sack_freq - This parameter contains the number of packets that must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) * be received before a sack is sent without waiting for the delay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) * timer to expire. The default value for this is 2, setting this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) * value to 1 will disable the delayed sack algorithm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) static int __sctp_setsockopt_delayed_ack(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) struct sctp_sack_info *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) /* Validate value parameter. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) if (params->sack_delay > 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) /* Get association, if sack_assoc_id != SCTP_FUTURE_ASSOC and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) * socket is a one to many style socket, and an association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) * was not found, then the id was invalid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) asoc = sctp_id2assoc(sk, params->sack_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) if (!asoc && params->sack_assoc_id > SCTP_ALL_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) sctp_apply_asoc_delayed_ack(params, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) if (sctp_style(sk, TCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) params->sack_assoc_id = SCTP_FUTURE_ASSOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) if (params->sack_assoc_id == SCTP_FUTURE_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) params->sack_assoc_id == SCTP_ALL_ASSOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) if (params->sack_delay) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) sp->sackdelay = params->sack_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) sp->param_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) sctp_spp_sackdelay_enable(sp->param_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) if (params->sack_freq == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) sp->param_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) sctp_spp_sackdelay_disable(sp->param_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) } else if (params->sack_freq > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) sp->sackfreq = params->sack_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) sp->param_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) sctp_spp_sackdelay_enable(sp->param_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) if (params->sack_assoc_id == SCTP_CURRENT_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) params->sack_assoc_id == SCTP_ALL_ASSOC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) list_for_each_entry(asoc, &sp->ep->asocs, asocs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) sctp_apply_asoc_delayed_ack(params, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) static int sctp_setsockopt_delayed_ack(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) struct sctp_sack_info *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) if (optlen == sizeof(struct sctp_assoc_value)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) struct sctp_assoc_value *v = (struct sctp_assoc_value *)params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) struct sctp_sack_info p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) pr_warn_ratelimited(DEPRECATED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) "%s (pid %d) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) "Use of struct sctp_assoc_value in delayed_ack socket option.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) "Use struct sctp_sack_info instead\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) current->comm, task_pid_nr(current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) p.sack_assoc_id = v->assoc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) p.sack_delay = v->assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) p.sack_freq = v->assoc_value ? 0 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) return __sctp_setsockopt_delayed_ack(sk, &p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) if (optlen != sizeof(struct sctp_sack_info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) if (params->sack_delay == 0 && params->sack_freq == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) return __sctp_setsockopt_delayed_ack(sk, params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) /* 7.1.3 Initialization Parameters (SCTP_INITMSG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) * Applications can specify protocol parameters for the default association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) * initialization. The option name argument to setsockopt() and getsockopt()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) * is SCTP_INITMSG.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) * Setting initialization parameters is effective only on an unconnected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) * socket (for UDP-style sockets only future associations are effected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) * by the change). With TCP-style sockets, this option is inherited by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) * sockets derived from a listener socket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) static int sctp_setsockopt_initmsg(struct sock *sk, struct sctp_initmsg *sinit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) if (optlen != sizeof(struct sctp_initmsg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) if (sinit->sinit_num_ostreams)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) sp->initmsg.sinit_num_ostreams = sinit->sinit_num_ostreams;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) if (sinit->sinit_max_instreams)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) sp->initmsg.sinit_max_instreams = sinit->sinit_max_instreams;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) if (sinit->sinit_max_attempts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) sp->initmsg.sinit_max_attempts = sinit->sinit_max_attempts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) if (sinit->sinit_max_init_timeo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) sp->initmsg.sinit_max_init_timeo = sinit->sinit_max_init_timeo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) * 7.1.14 Set default send parameters (SCTP_DEFAULT_SEND_PARAM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) * Applications that wish to use the sendto() system call may wish to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) * specify a default set of parameters that would normally be supplied
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) * through the inclusion of ancillary data. This socket option allows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) * such an application to set the default sctp_sndrcvinfo structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) * The application that wishes to use this socket option simply passes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) * in to this call the sctp_sndrcvinfo structure defined in Section
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) * 5.2.2) The input parameters accepted by this call include
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) * sinfo_stream, sinfo_flags, sinfo_ppid, sinfo_context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) * sinfo_timetolive. The user must provide the sinfo_assoc_id field in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) * to this call if the caller is using the UDP model.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) static int sctp_setsockopt_default_send_param(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) struct sctp_sndrcvinfo *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) if (optlen != sizeof(*info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) if (info->sinfo_flags &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) ~(SCTP_UNORDERED | SCTP_ADDR_OVER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) SCTP_ABORT | SCTP_EOF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) asoc = sctp_id2assoc(sk, info->sinfo_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) if (!asoc && info->sinfo_assoc_id > SCTP_ALL_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) asoc->default_stream = info->sinfo_stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) asoc->default_flags = info->sinfo_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) asoc->default_ppid = info->sinfo_ppid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) asoc->default_context = info->sinfo_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) asoc->default_timetolive = info->sinfo_timetolive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) if (sctp_style(sk, TCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) info->sinfo_assoc_id = SCTP_FUTURE_ASSOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) if (info->sinfo_assoc_id == SCTP_FUTURE_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) info->sinfo_assoc_id == SCTP_ALL_ASSOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) sp->default_stream = info->sinfo_stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) sp->default_flags = info->sinfo_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) sp->default_ppid = info->sinfo_ppid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) sp->default_context = info->sinfo_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) sp->default_timetolive = info->sinfo_timetolive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) if (info->sinfo_assoc_id == SCTP_CURRENT_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) info->sinfo_assoc_id == SCTP_ALL_ASSOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) list_for_each_entry(asoc, &sp->ep->asocs, asocs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) asoc->default_stream = info->sinfo_stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) asoc->default_flags = info->sinfo_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) asoc->default_ppid = info->sinfo_ppid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) asoc->default_context = info->sinfo_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) asoc->default_timetolive = info->sinfo_timetolive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) /* RFC6458, Section 8.1.31. Set/get Default Send Parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) * (SCTP_DEFAULT_SNDINFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) static int sctp_setsockopt_default_sndinfo(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) struct sctp_sndinfo *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) if (optlen != sizeof(*info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) if (info->snd_flags &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) ~(SCTP_UNORDERED | SCTP_ADDR_OVER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) SCTP_ABORT | SCTP_EOF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) asoc = sctp_id2assoc(sk, info->snd_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) if (!asoc && info->snd_assoc_id > SCTP_ALL_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) asoc->default_stream = info->snd_sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) asoc->default_flags = info->snd_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) asoc->default_ppid = info->snd_ppid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) asoc->default_context = info->snd_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982) if (sctp_style(sk, TCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) info->snd_assoc_id = SCTP_FUTURE_ASSOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) if (info->snd_assoc_id == SCTP_FUTURE_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) info->snd_assoc_id == SCTP_ALL_ASSOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) sp->default_stream = info->snd_sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) sp->default_flags = info->snd_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) sp->default_ppid = info->snd_ppid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) sp->default_context = info->snd_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) if (info->snd_assoc_id == SCTP_CURRENT_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) info->snd_assoc_id == SCTP_ALL_ASSOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) list_for_each_entry(asoc, &sp->ep->asocs, asocs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996) asoc->default_stream = info->snd_sid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) asoc->default_flags = info->snd_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998) asoc->default_ppid = info->snd_ppid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) asoc->default_context = info->snd_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) /* 7.1.10 Set Primary Address (SCTP_PRIMARY_ADDR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) * Requests that the local SCTP stack use the enclosed peer address as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) * the association primary. The enclosed address must be one of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) * association peer's addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) static int sctp_setsockopt_primary_addr(struct sock *sk, struct sctp_prim *prim,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) struct sctp_transport *trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) struct sctp_af *af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) if (optlen != sizeof(struct sctp_prim))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) /* Allow security module to validate address but need address len. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) af = sctp_get_af_specific(prim->ssp_addr.ss_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) if (!af)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027) err = security_sctp_bind_connect(sk, SCTP_PRIMARY_ADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) (struct sockaddr *)&prim->ssp_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) af->sockaddr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) trans = sctp_addr_id2transport(sk, &prim->ssp_addr, prim->ssp_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) if (!trans)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) sctp_assoc_set_primary(trans->asoc, trans);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) * 7.1.5 SCTP_NODELAY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) * Turn on/off any Nagle-like algorithm. This means that packets are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) * generally sent as soon as possible and no unnecessary delays are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) * introduced, at the cost of more packets in the network. Expects an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) * integer boolean flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) static int sctp_setsockopt_nodelay(struct sock *sk, int *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053) if (optlen < sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) sctp_sk(sk)->nodelay = (*val == 0) ? 0 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) * 7.1.1 SCTP_RTOINFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) * The protocol parameters used to initialize and bound retransmission
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) * timeout (RTO) are tunable. sctp_rtoinfo structure is used to access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) * and modify these parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) * All parameters are time values, in milliseconds. A value of 0, when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) * modifying the parameters, indicates that the current value should not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) * be changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) static int sctp_setsockopt_rtoinfo(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) struct sctp_rtoinfo *rtoinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) unsigned long rto_min, rto_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) if (optlen != sizeof (struct sctp_rtoinfo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) asoc = sctp_id2assoc(sk, rtoinfo->srto_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) /* Set the values to the specific association */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) if (!asoc && rtoinfo->srto_assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) rto_max = rtoinfo->srto_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) rto_min = rtoinfo->srto_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) if (rto_max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) rto_max = asoc ? msecs_to_jiffies(rto_max) : rto_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095) rto_max = asoc ? asoc->rto_max : sp->rtoinfo.srto_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) if (rto_min)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) rto_min = asoc ? msecs_to_jiffies(rto_min) : rto_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) rto_min = asoc ? asoc->rto_min : sp->rtoinfo.srto_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) if (rto_min > rto_max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) if (rtoinfo->srto_initial != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) asoc->rto_initial =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) msecs_to_jiffies(rtoinfo->srto_initial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) asoc->rto_max = rto_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110) asoc->rto_min = rto_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) /* If there is no association or the association-id = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) * set the values to the endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) if (rtoinfo->srto_initial != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) sp->rtoinfo.srto_initial = rtoinfo->srto_initial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117) sp->rtoinfo.srto_max = rto_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) sp->rtoinfo.srto_min = rto_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) * 7.1.2 SCTP_ASSOCINFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) * This option is used to tune the maximum retransmission attempts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) * of the association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) * Returns an error if the new association retransmission value is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) * greater than the sum of the retransmission value of the peer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) * See [SCTP] for more information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) static int sctp_setsockopt_associnfo(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136) struct sctp_assocparams *assocparams,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) if (optlen != sizeof(struct sctp_assocparams))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) asoc = sctp_id2assoc(sk, assocparams->sasoc_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) if (!asoc && assocparams->sasoc_assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) /* Set the values to the specific association */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153) if (assocparams->sasoc_asocmaxrxt != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) __u32 path_sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) int paths = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) struct sctp_transport *peer_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) list_for_each_entry(peer_addr, &asoc->peer.transport_addr_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) transports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) path_sum += peer_addr->pathmaxrxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) paths++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164) /* Only validate asocmaxrxt if we have more than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) * one path/transport. We do this because path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) * retransmissions are only counted when we have more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) * then one path.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169) if (paths > 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) assocparams->sasoc_asocmaxrxt > path_sum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) asoc->max_retrans = assocparams->sasoc_asocmaxrxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176) if (assocparams->sasoc_cookie_life != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) asoc->cookie_life =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) ms_to_ktime(assocparams->sasoc_cookie_life);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) /* Set the values to the endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) if (assocparams->sasoc_asocmaxrxt != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) sp->assocparams.sasoc_asocmaxrxt =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) assocparams->sasoc_asocmaxrxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) if (assocparams->sasoc_cookie_life != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) sp->assocparams.sasoc_cookie_life =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) assocparams->sasoc_cookie_life;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) * 7.1.16 Set/clear IPv4 mapped addresses (SCTP_I_WANT_MAPPED_V4_ADDR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196) * This socket option is a boolean flag which turns on or off mapped V4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) * addresses. If this option is turned on and the socket is type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) * PF_INET6, then IPv4 addresses will be mapped to V6 representation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) * If this option is turned off, then no mapping will be done of V4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200) * addresses and a user will receive both PF_INET6 and PF_INET type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) * addresses on the socket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) static int sctp_setsockopt_mappedv4(struct sock *sk, int *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) if (optlen < sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) if (*val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) sp->v4mapped = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) sp->v4mapped = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) * 8.1.16. Get or Set the Maximum Fragmentation Size (SCTP_MAXSEG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) * This option will get or set the maximum size to put in any outgoing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) * SCTP DATA chunk. If a message is larger than this size it will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) * fragmented by SCTP into the specified size. Note that the underlying
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) * SCTP implementation may fragment into smaller sized chunks when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) * PMTU of the underlying association is smaller than the value set by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) * the user. The default value for this option is '0' which indicates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) * the user is NOT limiting fragmentation and only the PMTU will effect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227) * SCTP's choice of DATA chunk size. Note also that values set larger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) * than the maximum size of an IP datagram will effectively let SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) * control fragmentation (i.e. the same as setting this option to 0).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) * The following structure is used to access and modify this parameter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) * struct sctp_assoc_value {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) * sctp_assoc_t assoc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) * uint32_t assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) * };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) * assoc_id: This parameter is ignored for one-to-one style sockets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) * For one-to-many style sockets this parameter indicates which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240) * association the user is performing an action upon. Note that if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) * this field's value is zero then the endpoints default value is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) * changed (effecting future associations only).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243) * assoc_value: This parameter specifies the maximum size in bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) static int sctp_setsockopt_maxseg(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) struct sctp_assoc_value *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) sctp_assoc_t assoc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) if (optlen == sizeof(int)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) pr_warn_ratelimited(DEPRECATED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256) "%s (pid %d) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) "Use of int in maxseg socket option.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) "Use struct sctp_assoc_value instead\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) current->comm, task_pid_nr(current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) assoc_id = SCTP_FUTURE_ASSOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261) val = *(int *)params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) } else if (optlen == sizeof(struct sctp_assoc_value)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) assoc_id = params->assoc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) val = params->assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) asoc = sctp_id2assoc(sk, assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) if (!asoc && assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) if (val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) int min_len, max_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) __u16 datasize = asoc ? sctp_datachk_len(&asoc->stream) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277) sizeof(struct sctp_data_chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) min_len = sctp_min_frag_point(sp, datasize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) max_len = SCTP_MAX_CHUNK_LEN - datasize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) if (val < min_len || val > max_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) asoc->user_frag = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) sctp_assoc_update_frag_point(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) sp->user_frag = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) * 7.1.9 Set Peer Primary Address (SCTP_SET_PEER_PRIMARY_ADDR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) * Requests that the peer mark the enclosed address as the association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) * primary. The enclosed address must be one of the association's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) * locally bound addresses. The following structure is used to make a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) * set primary request:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305) static int sctp_setsockopt_peer_primary_addr(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) struct sctp_setpeerprim *prim,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) struct sctp_sock *sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) struct sctp_association *asoc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311) struct sctp_chunk *chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) struct sctp_af *af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) if (!sp->ep->asconf_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) if (optlen != sizeof(struct sctp_setpeerprim))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) asoc = sctp_id2assoc(sk, prim->sspp_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) if (!asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) if (!asoc->peer.asconf_capable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) if (asoc->peer.addip_disabled_mask & SCTP_PARAM_SET_PRIMARY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) if (!sctp_state(asoc, ESTABLISHED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334) return -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336) af = sctp_get_af_specific(prim->sspp_addr.ss_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) if (!af)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) if (!af->addr_valid((union sctp_addr *)&prim->sspp_addr, sp, NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341) return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343) if (!sctp_assoc_lookup_laddr(asoc, (union sctp_addr *)&prim->sspp_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346) /* Allow security module to validate address. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) err = security_sctp_bind_connect(sk, SCTP_SET_PEER_PRIMARY_ADDR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348) (struct sockaddr *)&prim->sspp_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) af->sockaddr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353) /* Create an ASCONF chunk with SET_PRIMARY parameter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) chunk = sctp_make_asconf_set_prim(asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355) (union sctp_addr *)&prim->sspp_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) if (!chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359) err = sctp_send_asconf(asoc, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) pr_debug("%s: we set peer primary addr primitively\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366) static int sctp_setsockopt_adaptation_layer(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) struct sctp_setadaptation *adapt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370) if (optlen != sizeof(struct sctp_setadaptation))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) sctp_sk(sk)->adaptation_ind = adapt->ssb_adaptation_ind;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) * 7.1.29. Set or Get the default context (SCTP_CONTEXT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) * The context field in the sctp_sndrcvinfo structure is normally only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382) * used when a failed message is retrieved holding the value that was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) * sent down on the actual send call. This option allows the setting of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) * a default context on an association basis that will be received on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) * reading messages from the peer. This is especially helpful in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) * one-2-many model for an application to keep some reference to an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387) * internal state machine that is processing messages on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388) * association. Note that the setting of this value only effects
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) * received messages from the peer and does not effect the value that is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) * saved with outbound messages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) static int sctp_setsockopt_context(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393) struct sctp_assoc_value *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) if (optlen != sizeof(struct sctp_assoc_value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) asoc = sctp_id2assoc(sk, params->assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403) if (!asoc && params->assoc_id > SCTP_ALL_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) asoc->default_rcv_context = params->assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413) if (sctp_style(sk, TCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) params->assoc_id = SCTP_FUTURE_ASSOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) if (params->assoc_id == SCTP_FUTURE_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) params->assoc_id == SCTP_ALL_ASSOC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) sp->default_rcv_context = params->assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) if (params->assoc_id == SCTP_CURRENT_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) params->assoc_id == SCTP_ALL_ASSOC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) list_for_each_entry(asoc, &sp->ep->asocs, asocs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) asoc->default_rcv_context = params->assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429) * 7.1.24. Get or set fragmented interleave (SCTP_FRAGMENT_INTERLEAVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) * This options will at a minimum specify if the implementation is doing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432) * fragmented interleave. Fragmented interleave, for a one to many
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433) * socket, is when subsequent calls to receive a message may return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) * parts of messages from different associations. Some implementations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) * may allow you to turn this value on or off. If so, when turned off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) * no fragment interleave will occur (which will cause a head of line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) * blocking amongst multiple associations sharing the same one to many
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) * socket). When this option is turned on, then each receive call may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439) * come from a different association (thus the user must receive data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) * with the extended calls (e.g. sctp_recvmsg) to keep track of which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) * association each receive belongs to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) * This option takes a boolean value. A non-zero value indicates that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) * fragmented interleave is on. A value of zero indicates that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) * fragmented interleave is off.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) * Note that it is important that an implementation that allows this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448) * option to be turned on, have it off by default. Otherwise an unaware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) * application using the one to many model may become confused and act
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) * incorrectly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452) static int sctp_setsockopt_fragment_interleave(struct sock *sk, int *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) if (optlen != sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) sctp_sk(sk)->frag_interleave = !!*val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) if (!sctp_sk(sk)->frag_interleave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) sctp_sk(sk)->ep->intl_enable = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467) * 8.1.21. Set or Get the SCTP Partial Delivery Point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) * (SCTP_PARTIAL_DELIVERY_POINT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) * This option will set or get the SCTP partial delivery point. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) * point is the size of a message where the partial delivery API will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) * invoked to help free up rwnd space for the peer. Setting this to a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) * lower value will cause partial deliveries to happen more often. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) * calls argument is an integer that sets or gets the partial delivery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) * point. Note also that the call will fail if the user attempts to set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) * this value larger than the socket receive buffer size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478) * Note that any single message having a length smaller than or equal to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479) * the SCTP partial delivery point will be delivered in one single read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) * call as long as the user provided buffer is large enough to hold the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) * message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) static int sctp_setsockopt_partial_delivery_point(struct sock *sk, u32 *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) if (optlen != sizeof(u32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) /* Note: We double the receive buffer from what the user sets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490) * it to be, also initial rwnd is based on rcvbuf/2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) if (*val > (sk->sk_rcvbuf >> 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) sctp_sk(sk)->pd_point = *val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) return 0; /* is this the right error code? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) * 7.1.28. Set or Get the maximum burst (SCTP_MAX_BURST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503) * This option will allow a user to change the maximum burst of packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) * that can be emitted by this association. Note that the default value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) * is 4, and some implementations may restrict this setting so that it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) * can only be lowered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) * NOTE: This text doesn't seem right. Do this on a socket basis with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) * future associations inheriting the socket value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) static int sctp_setsockopt_maxburst(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512) struct sctp_assoc_value *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) sctp_assoc_t assoc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) u32 assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) if (optlen == sizeof(int)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) pr_warn_ratelimited(DEPRECATED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522) "%s (pid %d) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) "Use of int in max_burst socket option deprecated.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) "Use struct sctp_assoc_value instead\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525) current->comm, task_pid_nr(current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) assoc_id = SCTP_FUTURE_ASSOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527) assoc_value = *((int *)params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) } else if (optlen == sizeof(struct sctp_assoc_value)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) assoc_id = params->assoc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) assoc_value = params->assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) asoc = sctp_id2assoc(sk, assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) if (!asoc && assoc_id > SCTP_ALL_ASSOC && sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) asoc->max_burst = assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) if (sctp_style(sk, TCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) assoc_id = SCTP_FUTURE_ASSOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) if (assoc_id == SCTP_FUTURE_ASSOC || assoc_id == SCTP_ALL_ASSOC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) sp->max_burst = assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) if (assoc_id == SCTP_CURRENT_ASSOC || assoc_id == SCTP_ALL_ASSOC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) list_for_each_entry(asoc, &sp->ep->asocs, asocs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) asoc->max_burst = assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558) * 7.1.18. Add a chunk that must be authenticated (SCTP_AUTH_CHUNK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) * This set option adds a chunk type that the user is requesting to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561) * received only in an authenticated way. Changes to the list of chunks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) * will only effect future associations on the socket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564) static int sctp_setsockopt_auth_chunk(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) struct sctp_authchunk *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) struct sctp_endpoint *ep = sctp_sk(sk)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) if (!ep->auth_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) if (optlen != sizeof(struct sctp_authchunk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) switch (val->sauth_chunk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) case SCTP_CID_INIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) case SCTP_CID_INIT_ACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579) case SCTP_CID_SHUTDOWN_COMPLETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) case SCTP_CID_AUTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) /* add this chunk id to the endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) return sctp_auth_ep_add_chunkid(ep, val->sauth_chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) * 7.1.19. Get or set the list of supported HMAC Identifiers (SCTP_HMAC_IDENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) * This option gets or sets the list of HMAC algorithms that the local
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592) * endpoint requires the peer to use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) static int sctp_setsockopt_hmac_ident(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) struct sctp_hmacalgo *hmacs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598) struct sctp_endpoint *ep = sctp_sk(sk)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) u32 idents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) if (!ep->auth_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) if (optlen < sizeof(struct sctp_hmacalgo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) optlen = min_t(unsigned int, optlen, sizeof(struct sctp_hmacalgo) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) SCTP_AUTH_NUM_HMACS * sizeof(u16));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) idents = hmacs->shmac_num_idents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) if (idents == 0 || idents > SCTP_AUTH_NUM_HMACS ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) (idents * sizeof(u16)) > (optlen - sizeof(struct sctp_hmacalgo)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) return sctp_auth_ep_set_hmacs(ep, hmacs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) * 7.1.20. Set a shared key (SCTP_AUTH_KEY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620) * This option will set a shared secret key which is used to build an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) * association shared key.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623) static int sctp_setsockopt_auth_key(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) struct sctp_authkey *authkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) struct sctp_endpoint *ep = sctp_sk(sk)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) if (optlen <= sizeof(struct sctp_authkey))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) /* authkey->sca_keylength is u16, so optlen can't be bigger than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634) * this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636) optlen = min_t(unsigned int, optlen, USHRT_MAX + sizeof(*authkey));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) if (authkey->sca_keylength > optlen - sizeof(*authkey))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) asoc = sctp_id2assoc(sk, authkey->sca_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642) if (!asoc && authkey->sca_assoc_id > SCTP_ALL_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) ret = sctp_auth_set_key(ep, asoc, authkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651) if (sctp_style(sk, TCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652) authkey->sca_assoc_id = SCTP_FUTURE_ASSOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654) if (authkey->sca_assoc_id == SCTP_FUTURE_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655) authkey->sca_assoc_id == SCTP_ALL_ASSOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) ret = sctp_auth_set_key(ep, asoc, authkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) if (authkey->sca_assoc_id == SCTP_CURRENT_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664) authkey->sca_assoc_id == SCTP_ALL_ASSOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665) list_for_each_entry(asoc, &ep->asocs, asocs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666) int res = sctp_auth_set_key(ep, asoc, authkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668) if (res && !ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669) ret = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) memzero_explicit(authkey, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679) * 7.1.21. Get or set the active shared key (SCTP_AUTH_ACTIVE_KEY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681) * This option will get or set the active shared key to be used to build
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) * the association shared key.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) static int sctp_setsockopt_active_key(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685) struct sctp_authkeyid *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) struct sctp_endpoint *ep = sctp_sk(sk)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) if (optlen != sizeof(struct sctp_authkeyid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) asoc = sctp_id2assoc(sk, val->scact_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) if (!asoc && val->scact_assoc_id > SCTP_ALL_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) if (asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) return sctp_auth_set_active_key(ep, asoc, val->scact_keynumber);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703) if (sctp_style(sk, TCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) val->scact_assoc_id = SCTP_FUTURE_ASSOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706) if (val->scact_assoc_id == SCTP_FUTURE_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) val->scact_assoc_id == SCTP_ALL_ASSOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708) ret = sctp_auth_set_active_key(ep, asoc, val->scact_keynumber);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) if (val->scact_assoc_id == SCTP_CURRENT_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) val->scact_assoc_id == SCTP_ALL_ASSOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) list_for_each_entry(asoc, &ep->asocs, asocs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) int res = sctp_auth_set_active_key(ep, asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) val->scact_keynumber);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719) if (res && !ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720) ret = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728) * 7.1.22. Delete a shared key (SCTP_AUTH_DELETE_KEY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) * This set option will delete a shared secret key from use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) static int sctp_setsockopt_del_key(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) struct sctp_authkeyid *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736) struct sctp_endpoint *ep = sctp_sk(sk)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740) if (optlen != sizeof(struct sctp_authkeyid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) asoc = sctp_id2assoc(sk, val->scact_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) if (!asoc && val->scact_assoc_id > SCTP_ALL_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) if (asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749) return sctp_auth_del_key_id(ep, asoc, val->scact_keynumber);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) if (sctp_style(sk, TCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) val->scact_assoc_id = SCTP_FUTURE_ASSOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754) if (val->scact_assoc_id == SCTP_FUTURE_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) val->scact_assoc_id == SCTP_ALL_ASSOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) ret = sctp_auth_del_key_id(ep, asoc, val->scact_keynumber);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761) if (val->scact_assoc_id == SCTP_CURRENT_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762) val->scact_assoc_id == SCTP_ALL_ASSOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) list_for_each_entry(asoc, &ep->asocs, asocs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) int res = sctp_auth_del_key_id(ep, asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765) val->scact_keynumber);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767) if (res && !ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768) ret = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776) * 8.3.4 Deactivate a Shared Key (SCTP_AUTH_DEACTIVATE_KEY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3777) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3778) * This set option will deactivate a shared secret key.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3779) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3780) static int sctp_setsockopt_deactivate_key(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3781) struct sctp_authkeyid *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3782) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3783) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3784) struct sctp_endpoint *ep = sctp_sk(sk)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3785) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3786) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3788) if (optlen != sizeof(struct sctp_authkeyid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3789) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3791) asoc = sctp_id2assoc(sk, val->scact_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3792) if (!asoc && val->scact_assoc_id > SCTP_ALL_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3793) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3794) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3796) if (asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3797) return sctp_auth_deact_key_id(ep, asoc, val->scact_keynumber);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3799) if (sctp_style(sk, TCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3800) val->scact_assoc_id = SCTP_FUTURE_ASSOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3802) if (val->scact_assoc_id == SCTP_FUTURE_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3803) val->scact_assoc_id == SCTP_ALL_ASSOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3804) ret = sctp_auth_deact_key_id(ep, asoc, val->scact_keynumber);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3805) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3806) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3807) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3809) if (val->scact_assoc_id == SCTP_CURRENT_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3810) val->scact_assoc_id == SCTP_ALL_ASSOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3811) list_for_each_entry(asoc, &ep->asocs, asocs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3812) int res = sctp_auth_deact_key_id(ep, asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3813) val->scact_keynumber);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3815) if (res && !ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3816) ret = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3820) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3823) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3824) * 8.1.23 SCTP_AUTO_ASCONF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3825) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3826) * This option will enable or disable the use of the automatic generation of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3827) * ASCONF chunks to add and delete addresses to an existing association. Note
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3828) * that this option has two caveats namely: a) it only affects sockets that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3829) * are bound to all addresses available to the SCTP stack, and b) the system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3830) * administrator may have an overriding control that turns the ASCONF feature
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3831) * off no matter what setting the socket option may have.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3832) * This option expects an integer boolean flag, where a non-zero value turns on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3833) * the option, and a zero value turns off the option.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3834) * Note. In this implementation, socket operation overrides default parameter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3835) * being set by sysctl as well as FreeBSD implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3836) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3837) static int sctp_setsockopt_auto_asconf(struct sock *sk, int *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3838) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3839) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3840) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3842) if (optlen < sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3843) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3844) if (!sctp_is_ep_boundall(sk) && *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3845) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3846) if ((*val && sp->do_auto_asconf) || (!*val && !sp->do_auto_asconf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3847) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3849) spin_lock_bh(&sock_net(sk)->sctp.addr_wq_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3850) if (*val == 0 && sp->do_auto_asconf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3851) list_del(&sp->auto_asconf_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3852) sp->do_auto_asconf = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3853) } else if (*val && !sp->do_auto_asconf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3854) list_add_tail(&sp->auto_asconf_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3855) &sock_net(sk)->sctp.auto_asconf_splist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3856) sp->do_auto_asconf = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3857) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3858) spin_unlock_bh(&sock_net(sk)->sctp.addr_wq_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3859) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3860) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3862) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3863) * SCTP_PEER_ADDR_THLDS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3864) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3865) * This option allows us to alter the partially failed threshold for one or all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3866) * transports in an association. See Section 6.1 of:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3867) * http://www.ietf.org/id/draft-nishida-tsvwg-sctp-failover-05.txt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3868) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3869) static int sctp_setsockopt_paddr_thresholds(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3870) struct sctp_paddrthlds_v2 *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3871) unsigned int optlen, bool v2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3872) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3873) struct sctp_transport *trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3874) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3875) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3877) len = v2 ? sizeof(*val) : sizeof(struct sctp_paddrthlds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3878) if (optlen < len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3879) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3881) if (v2 && val->spt_pathpfthld > val->spt_pathcpthld)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3882) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3884) if (!sctp_is_any(sk, (const union sctp_addr *)&val->spt_address)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3885) trans = sctp_addr_id2transport(sk, &val->spt_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3886) val->spt_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3887) if (!trans)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3888) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3890) if (val->spt_pathmaxrxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3891) trans->pathmaxrxt = val->spt_pathmaxrxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3892) if (v2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3893) trans->ps_retrans = val->spt_pathcpthld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3894) trans->pf_retrans = val->spt_pathpfthld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3896) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3897) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3899) asoc = sctp_id2assoc(sk, val->spt_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3900) if (!asoc && val->spt_assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3901) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3902) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3904) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3905) list_for_each_entry(trans, &asoc->peer.transport_addr_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3906) transports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3907) if (val->spt_pathmaxrxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3908) trans->pathmaxrxt = val->spt_pathmaxrxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3909) if (v2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3910) trans->ps_retrans = val->spt_pathcpthld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3911) trans->pf_retrans = val->spt_pathpfthld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3914) if (val->spt_pathmaxrxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3915) asoc->pathmaxrxt = val->spt_pathmaxrxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3916) if (v2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3917) asoc->ps_retrans = val->spt_pathcpthld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3918) asoc->pf_retrans = val->spt_pathpfthld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3919) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3920) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3922) if (val->spt_pathmaxrxt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3923) sp->pathmaxrxt = val->spt_pathmaxrxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3924) if (v2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3925) sp->ps_retrans = val->spt_pathcpthld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3926) sp->pf_retrans = val->spt_pathpfthld;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3927) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3929) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3932) static int sctp_setsockopt_recvrcvinfo(struct sock *sk, int *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3933) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3934) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3935) if (optlen < sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3936) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3938) sctp_sk(sk)->recvrcvinfo = (*val == 0) ? 0 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3940) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3941) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3943) static int sctp_setsockopt_recvnxtinfo(struct sock *sk, int *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3944) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3945) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3946) if (optlen < sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3947) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3949) sctp_sk(sk)->recvnxtinfo = (*val == 0) ? 0 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3950)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3951) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3952) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3954) static int sctp_setsockopt_pr_supported(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3955) struct sctp_assoc_value *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3956) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3957) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3958) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3960) if (optlen != sizeof(*params))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3961) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3963) asoc = sctp_id2assoc(sk, params->assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3964) if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3965) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3966) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3968) sctp_sk(sk)->ep->prsctp_enable = !!params->assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3970) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3973) static int sctp_setsockopt_default_prinfo(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3974) struct sctp_default_prinfo *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3975) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3976) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3977) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3978) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3979) int retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3981) if (optlen != sizeof(*info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3982) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3984) if (info->pr_policy & ~SCTP_PR_SCTP_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3985) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3987) if (info->pr_policy == SCTP_PR_SCTP_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3988) info->pr_value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3989)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3990) asoc = sctp_id2assoc(sk, info->pr_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3991) if (!asoc && info->pr_assoc_id > SCTP_ALL_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3992) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3993) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3995) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3997) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3998) SCTP_PR_SET_POLICY(asoc->default_flags, info->pr_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3999) asoc->default_timetolive = info->pr_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4000) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4001) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4003) if (sctp_style(sk, TCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4004) info->pr_assoc_id = SCTP_FUTURE_ASSOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4006) if (info->pr_assoc_id == SCTP_FUTURE_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4007) info->pr_assoc_id == SCTP_ALL_ASSOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4008) SCTP_PR_SET_POLICY(sp->default_flags, info->pr_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4009) sp->default_timetolive = info->pr_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4010) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4012) if (info->pr_assoc_id == SCTP_CURRENT_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4013) info->pr_assoc_id == SCTP_ALL_ASSOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4014) list_for_each_entry(asoc, &sp->ep->asocs, asocs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4015) SCTP_PR_SET_POLICY(asoc->default_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4016) info->pr_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4017) asoc->default_timetolive = info->pr_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4018) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4019) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4021) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4022) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4023) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4025) static int sctp_setsockopt_reconfig_supported(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4026) struct sctp_assoc_value *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4027) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4028) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4029) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4030) int retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4032) if (optlen != sizeof(*params))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4033) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4034)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4035) asoc = sctp_id2assoc(sk, params->assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4036) if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4037) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4038) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4040) sctp_sk(sk)->ep->reconf_enable = !!params->assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4041)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4042) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4044) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4045) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4046) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4048) static int sctp_setsockopt_enable_strreset(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4049) struct sctp_assoc_value *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4050) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4051) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4052) struct sctp_endpoint *ep = sctp_sk(sk)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4053) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4054) int retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4056) if (optlen != sizeof(*params))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4057) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4059) if (params->assoc_value & (~SCTP_ENABLE_STRRESET_MASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4060) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4061)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4062) asoc = sctp_id2assoc(sk, params->assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4063) if (!asoc && params->assoc_id > SCTP_ALL_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4064) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4065) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4067) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4069) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4070) asoc->strreset_enable = params->assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4071) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4072) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4073)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4074) if (sctp_style(sk, TCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4075) params->assoc_id = SCTP_FUTURE_ASSOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4076)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4077) if (params->assoc_id == SCTP_FUTURE_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4078) params->assoc_id == SCTP_ALL_ASSOC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4079) ep->strreset_enable = params->assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4081) if (params->assoc_id == SCTP_CURRENT_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4082) params->assoc_id == SCTP_ALL_ASSOC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4083) list_for_each_entry(asoc, &ep->asocs, asocs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4084) asoc->strreset_enable = params->assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4086) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4087) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4088) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4090) static int sctp_setsockopt_reset_streams(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4091) struct sctp_reset_streams *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4092) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4093) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4094) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4095)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4096) if (optlen < sizeof(*params))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4097) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4098) /* srs_number_streams is u16, so optlen can't be bigger than this. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4099) optlen = min_t(unsigned int, optlen, USHRT_MAX +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4100) sizeof(__u16) * sizeof(*params));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4102) if (params->srs_number_streams * sizeof(__u16) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4103) optlen - sizeof(*params))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4104) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4106) asoc = sctp_id2assoc(sk, params->srs_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4107) if (!asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4108) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4110) return sctp_send_reset_streams(asoc, params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4113) static int sctp_setsockopt_reset_assoc(struct sock *sk, sctp_assoc_t *associd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4114) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4116) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4118) if (optlen != sizeof(*associd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4119) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4121) asoc = sctp_id2assoc(sk, *associd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4122) if (!asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4123) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4125) return sctp_send_reset_assoc(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4128) static int sctp_setsockopt_add_streams(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4129) struct sctp_add_streams *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4130) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4132) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4134) if (optlen != sizeof(*params))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4135) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4137) asoc = sctp_id2assoc(sk, params->sas_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4138) if (!asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4139) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4141) return sctp_send_add_streams(asoc, params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4144) static int sctp_setsockopt_scheduler(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4145) struct sctp_assoc_value *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4146) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4148) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4149) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4150) int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4152) if (optlen < sizeof(*params))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4153) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4155) if (params->assoc_value > SCTP_SS_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4156) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4158) asoc = sctp_id2assoc(sk, params->assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4159) if (!asoc && params->assoc_id > SCTP_ALL_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4160) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4161) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4163) if (asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4164) return sctp_sched_set_sched(asoc, params->assoc_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4166) if (sctp_style(sk, TCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4167) params->assoc_id = SCTP_FUTURE_ASSOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4169) if (params->assoc_id == SCTP_FUTURE_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4170) params->assoc_id == SCTP_ALL_ASSOC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4171) sp->default_ss = params->assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4173) if (params->assoc_id == SCTP_CURRENT_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4174) params->assoc_id == SCTP_ALL_ASSOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4175) list_for_each_entry(asoc, &sp->ep->asocs, asocs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4176) int ret = sctp_sched_set_sched(asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4177) params->assoc_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4179) if (ret && !retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4180) retval = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4184) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4187) static int sctp_setsockopt_scheduler_value(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4188) struct sctp_stream_value *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4189) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4191) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4192) int retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4194) if (optlen < sizeof(*params))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4195) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4197) asoc = sctp_id2assoc(sk, params->assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4198) if (!asoc && params->assoc_id != SCTP_CURRENT_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4199) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4200) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4202) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4203) retval = sctp_sched_set_value(asoc, params->stream_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4204) params->stream_value, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4205) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4208) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4210) list_for_each_entry(asoc, &sctp_sk(sk)->ep->asocs, asocs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4211) int ret = sctp_sched_set_value(asoc, params->stream_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4212) params->stream_value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4213) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4214) if (ret && !retval) /* try to return the 1st error. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4215) retval = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4218) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4219) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4222) static int sctp_setsockopt_interleaving_supported(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4223) struct sctp_assoc_value *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4224) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4226) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4227) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4229) if (optlen < sizeof(*p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4230) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4232) asoc = sctp_id2assoc(sk, p->assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4233) if (!asoc && p->assoc_id != SCTP_FUTURE_ASSOC && sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4234) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4236) if (!sock_net(sk)->sctp.intl_enable || !sp->frag_interleave) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4237) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4240) sp->ep->intl_enable = !!p->assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4241) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4244) static int sctp_setsockopt_reuse_port(struct sock *sk, int *val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4245) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4247) if (!sctp_style(sk, TCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4248) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4250) if (sctp_sk(sk)->ep->base.bind_addr.port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4251) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4253) if (optlen < sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4254) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4256) sctp_sk(sk)->reuse = !!*val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4258) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4261) static int sctp_assoc_ulpevent_type_set(struct sctp_event *param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4262) struct sctp_association *asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4264) struct sctp_ulpevent *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4266) sctp_ulpevent_type_set(&asoc->subscribe, param->se_type, param->se_on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4268) if (param->se_type == SCTP_SENDER_DRY_EVENT && param->se_on) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4269) if (sctp_outq_is_empty(&asoc->outqueue)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4270) event = sctp_ulpevent_make_sender_dry_event(asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4271) GFP_USER | __GFP_NOWARN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4272) if (!event)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4273) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4275) asoc->stream.si->enqueue_event(&asoc->ulpq, event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4279) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4282) static int sctp_setsockopt_event(struct sock *sk, struct sctp_event *param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4283) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4285) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4286) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4287) int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4289) if (optlen < sizeof(*param))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4290) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4292) if (param->se_type < SCTP_SN_TYPE_BASE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4293) param->se_type > SCTP_SN_TYPE_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4294) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4296) asoc = sctp_id2assoc(sk, param->se_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4297) if (!asoc && param->se_assoc_id > SCTP_ALL_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4298) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4299) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4301) if (asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4302) return sctp_assoc_ulpevent_type_set(param, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4304) if (sctp_style(sk, TCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4305) param->se_assoc_id = SCTP_FUTURE_ASSOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4307) if (param->se_assoc_id == SCTP_FUTURE_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4308) param->se_assoc_id == SCTP_ALL_ASSOC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4309) sctp_ulpevent_type_set(&sp->subscribe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4310) param->se_type, param->se_on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4312) if (param->se_assoc_id == SCTP_CURRENT_ASSOC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4313) param->se_assoc_id == SCTP_ALL_ASSOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4314) list_for_each_entry(asoc, &sp->ep->asocs, asocs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4315) int ret = sctp_assoc_ulpevent_type_set(param, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4317) if (ret && !retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4318) retval = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4322) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4325) static int sctp_setsockopt_asconf_supported(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4326) struct sctp_assoc_value *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4327) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4329) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4330) struct sctp_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4331) int retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4333) if (optlen != sizeof(*params))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4334) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4336) asoc = sctp_id2assoc(sk, params->assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4337) if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4338) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4339) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4341) ep = sctp_sk(sk)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4342) ep->asconf_enable = !!params->assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4344) if (ep->asconf_enable && ep->auth_enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4345) sctp_auth_ep_add_chunkid(ep, SCTP_CID_ASCONF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4346) sctp_auth_ep_add_chunkid(ep, SCTP_CID_ASCONF_ACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4349) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4351) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4352) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4355) static int sctp_setsockopt_auth_supported(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4356) struct sctp_assoc_value *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4357) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4359) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4360) struct sctp_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4361) int retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4363) if (optlen != sizeof(*params))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4364) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4366) asoc = sctp_id2assoc(sk, params->assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4367) if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4368) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4369) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4371) ep = sctp_sk(sk)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4372) if (params->assoc_value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4373) retval = sctp_auth_init(ep, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4374) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4375) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4376) if (ep->asconf_enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4377) sctp_auth_ep_add_chunkid(ep, SCTP_CID_ASCONF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4378) sctp_auth_ep_add_chunkid(ep, SCTP_CID_ASCONF_ACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4382) ep->auth_enable = !!params->assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4383) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4385) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4386) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4389) static int sctp_setsockopt_ecn_supported(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4390) struct sctp_assoc_value *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4391) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4393) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4394) int retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4396) if (optlen != sizeof(*params))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4397) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4399) asoc = sctp_id2assoc(sk, params->assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4400) if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4401) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4402) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4404) sctp_sk(sk)->ep->ecn_enable = !!params->assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4405) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4407) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4408) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4411) static int sctp_setsockopt_pf_expose(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4412) struct sctp_assoc_value *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4413) unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4415) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4416) int retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4418) if (optlen != sizeof(*params))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4419) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4421) if (params->assoc_value > SCTP_PF_EXPOSE_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4422) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4424) asoc = sctp_id2assoc(sk, params->assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4425) if (!asoc && params->assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4426) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4427) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4429) if (asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4430) asoc->pf_expose = params->assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4431) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4432) sctp_sk(sk)->pf_expose = params->assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4433) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4435) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4436) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4439) /* API 6.2 setsockopt(), getsockopt()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4440) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4441) * Applications use setsockopt() and getsockopt() to set or retrieve
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4442) * socket options. Socket options are used to change the default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4443) * behavior of sockets calls. They are described in Section 7.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4444) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4445) * The syntax is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4446) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4447) * ret = getsockopt(int sd, int level, int optname, void __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4448) * int __user *optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4449) * ret = setsockopt(int sd, int level, int optname, const void __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4450) * int optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4451) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4452) * sd - the socket descript.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4453) * level - set to IPPROTO_SCTP for all SCTP options.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4454) * optname - the option name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4455) * optval - the buffer to store the value of the option.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4456) * optlen - the size of the buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4457) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4458) static int sctp_setsockopt(struct sock *sk, int level, int optname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4459) sockptr_t optval, unsigned int optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4460) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4461) void *kopt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4462) int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4464) pr_debug("%s: sk:%p, optname:%d\n", __func__, sk, optname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4466) /* I can hardly begin to describe how wrong this is. This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4467) * so broken as to be worse than useless. The API draft
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4468) * REALLY is NOT helpful here... I am not convinced that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4469) * semantics of setsockopt() with a level OTHER THAN SOL_SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4470) * are at all well-founded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4471) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4472) if (level != SOL_SCTP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4473) struct sctp_af *af = sctp_sk(sk)->pf->af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4475) return af->setsockopt(sk, level, optname, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4478) if (optlen > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4479) /* Trim it to the biggest size sctp sockopt may need if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4480) optlen = min_t(unsigned int, optlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4481) PAGE_ALIGN(USHRT_MAX +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4482) sizeof(__u16) * sizeof(struct sctp_reset_streams)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4483) kopt = memdup_sockptr(optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4484) if (IS_ERR(kopt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4485) return PTR_ERR(kopt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4488) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4490) switch (optname) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4491) case SCTP_SOCKOPT_BINDX_ADD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4492) /* 'optlen' is the size of the addresses buffer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4493) retval = sctp_setsockopt_bindx(sk, kopt, optlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4494) SCTP_BINDX_ADD_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4495) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4497) case SCTP_SOCKOPT_BINDX_REM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4498) /* 'optlen' is the size of the addresses buffer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4499) retval = sctp_setsockopt_bindx(sk, kopt, optlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4500) SCTP_BINDX_REM_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4501) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4503) case SCTP_SOCKOPT_CONNECTX_OLD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4504) /* 'optlen' is the size of the addresses buffer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4505) retval = sctp_setsockopt_connectx_old(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4506) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4508) case SCTP_SOCKOPT_CONNECTX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4509) /* 'optlen' is the size of the addresses buffer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4510) retval = sctp_setsockopt_connectx(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4511) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4513) case SCTP_DISABLE_FRAGMENTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4514) retval = sctp_setsockopt_disable_fragments(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4515) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4517) case SCTP_EVENTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4518) retval = sctp_setsockopt_events(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4519) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4521) case SCTP_AUTOCLOSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4522) retval = sctp_setsockopt_autoclose(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4523) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4525) case SCTP_PEER_ADDR_PARAMS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4526) retval = sctp_setsockopt_peer_addr_params(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4527) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4529) case SCTP_DELAYED_SACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4530) retval = sctp_setsockopt_delayed_ack(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4531) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4532) case SCTP_PARTIAL_DELIVERY_POINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4533) retval = sctp_setsockopt_partial_delivery_point(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4534) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4536) case SCTP_INITMSG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4537) retval = sctp_setsockopt_initmsg(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4538) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4539) case SCTP_DEFAULT_SEND_PARAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4540) retval = sctp_setsockopt_default_send_param(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4541) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4542) case SCTP_DEFAULT_SNDINFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4543) retval = sctp_setsockopt_default_sndinfo(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4544) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4545) case SCTP_PRIMARY_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4546) retval = sctp_setsockopt_primary_addr(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4547) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4548) case SCTP_SET_PEER_PRIMARY_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4549) retval = sctp_setsockopt_peer_primary_addr(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4550) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4551) case SCTP_NODELAY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4552) retval = sctp_setsockopt_nodelay(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4553) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4554) case SCTP_RTOINFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4555) retval = sctp_setsockopt_rtoinfo(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4556) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4557) case SCTP_ASSOCINFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4558) retval = sctp_setsockopt_associnfo(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4559) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4560) case SCTP_I_WANT_MAPPED_V4_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4561) retval = sctp_setsockopt_mappedv4(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4562) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4563) case SCTP_MAXSEG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4564) retval = sctp_setsockopt_maxseg(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4565) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4566) case SCTP_ADAPTATION_LAYER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4567) retval = sctp_setsockopt_adaptation_layer(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4568) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4569) case SCTP_CONTEXT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4570) retval = sctp_setsockopt_context(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4571) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4572) case SCTP_FRAGMENT_INTERLEAVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4573) retval = sctp_setsockopt_fragment_interleave(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4574) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4575) case SCTP_MAX_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4576) retval = sctp_setsockopt_maxburst(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4577) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4578) case SCTP_AUTH_CHUNK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4579) retval = sctp_setsockopt_auth_chunk(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4580) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4581) case SCTP_HMAC_IDENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4582) retval = sctp_setsockopt_hmac_ident(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4583) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4584) case SCTP_AUTH_KEY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4585) retval = sctp_setsockopt_auth_key(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4586) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4587) case SCTP_AUTH_ACTIVE_KEY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4588) retval = sctp_setsockopt_active_key(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4589) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4590) case SCTP_AUTH_DELETE_KEY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4591) retval = sctp_setsockopt_del_key(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4592) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4593) case SCTP_AUTH_DEACTIVATE_KEY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4594) retval = sctp_setsockopt_deactivate_key(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4595) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4596) case SCTP_AUTO_ASCONF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4597) retval = sctp_setsockopt_auto_asconf(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4598) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4599) case SCTP_PEER_ADDR_THLDS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4600) retval = sctp_setsockopt_paddr_thresholds(sk, kopt, optlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4601) false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4602) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4603) case SCTP_PEER_ADDR_THLDS_V2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4604) retval = sctp_setsockopt_paddr_thresholds(sk, kopt, optlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4605) true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4606) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4607) case SCTP_RECVRCVINFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4608) retval = sctp_setsockopt_recvrcvinfo(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4609) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4610) case SCTP_RECVNXTINFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4611) retval = sctp_setsockopt_recvnxtinfo(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4612) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4613) case SCTP_PR_SUPPORTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4614) retval = sctp_setsockopt_pr_supported(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4615) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4616) case SCTP_DEFAULT_PRINFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4617) retval = sctp_setsockopt_default_prinfo(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4618) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4619) case SCTP_RECONFIG_SUPPORTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4620) retval = sctp_setsockopt_reconfig_supported(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4621) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4622) case SCTP_ENABLE_STREAM_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4623) retval = sctp_setsockopt_enable_strreset(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4624) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4625) case SCTP_RESET_STREAMS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4626) retval = sctp_setsockopt_reset_streams(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4627) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4628) case SCTP_RESET_ASSOC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4629) retval = sctp_setsockopt_reset_assoc(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4630) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4631) case SCTP_ADD_STREAMS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4632) retval = sctp_setsockopt_add_streams(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4633) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4634) case SCTP_STREAM_SCHEDULER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4635) retval = sctp_setsockopt_scheduler(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4636) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4637) case SCTP_STREAM_SCHEDULER_VALUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4638) retval = sctp_setsockopt_scheduler_value(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4639) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4640) case SCTP_INTERLEAVING_SUPPORTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4641) retval = sctp_setsockopt_interleaving_supported(sk, kopt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4642) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4643) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4644) case SCTP_REUSE_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4645) retval = sctp_setsockopt_reuse_port(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4646) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4647) case SCTP_EVENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4648) retval = sctp_setsockopt_event(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4649) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4650) case SCTP_ASCONF_SUPPORTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4651) retval = sctp_setsockopt_asconf_supported(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4652) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4653) case SCTP_AUTH_SUPPORTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4654) retval = sctp_setsockopt_auth_supported(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4655) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4656) case SCTP_ECN_SUPPORTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4657) retval = sctp_setsockopt_ecn_supported(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4658) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4659) case SCTP_EXPOSE_POTENTIALLY_FAILED_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4660) retval = sctp_setsockopt_pf_expose(sk, kopt, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4661) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4662) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4663) retval = -ENOPROTOOPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4664) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4667) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4668) kfree(kopt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4669) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4672) /* API 3.1.6 connect() - UDP Style Syntax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4673) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4674) * An application may use the connect() call in the UDP model to initiate an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4675) * association without sending data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4676) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4677) * The syntax is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4678) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4679) * ret = connect(int sd, const struct sockaddr *nam, socklen_t len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4680) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4681) * sd: the socket descriptor to have a new association added to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4682) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4683) * nam: the address structure (either struct sockaddr_in or struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4684) * sockaddr_in6 defined in RFC2553 [7]).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4685) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4686) * len: the size of the address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4687) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4688) static int sctp_connect(struct sock *sk, struct sockaddr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4689) int addr_len, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4690) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4691) struct sctp_af *af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4692) int err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4694) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4695) pr_debug("%s: sk:%p, sockaddr:%p, addr_len:%d\n", __func__, sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4696) addr, addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4698) /* Validate addr_len before calling common connect/connectx routine. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4699) af = sctp_get_af_specific(addr->sa_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4700) if (af && addr_len >= af->sockaddr_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4701) err = __sctp_connect(sk, addr, af->sockaddr_len, flags, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4703) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4704) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4707) int sctp_inet_connect(struct socket *sock, struct sockaddr *uaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4708) int addr_len, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4709) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4710) if (addr_len < sizeof(uaddr->sa_family))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4711) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4713) if (uaddr->sa_family == AF_UNSPEC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4714) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4716) return sctp_connect(sock->sk, uaddr, addr_len, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4717) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4719) /* FIXME: Write comments. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4720) static int sctp_disconnect(struct sock *sk, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4721) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4722) return -EOPNOTSUPP; /* STUB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4725) /* 4.1.4 accept() - TCP Style Syntax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4726) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4727) * Applications use accept() call to remove an established SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4728) * association from the accept queue of the endpoint. A new socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4729) * descriptor will be returned from accept() to represent the newly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4730) * formed association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4731) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4732) static struct sock *sctp_accept(struct sock *sk, int flags, int *err, bool kern)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4733) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4734) struct sctp_sock *sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4735) struct sctp_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4736) struct sock *newsk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4737) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4738) long timeo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4739) int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4741) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4743) sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4744) ep = sp->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4746) if (!sctp_style(sk, TCP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4747) error = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4748) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4749) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4751) if (!sctp_sstate(sk, LISTENING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4752) error = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4753) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4754) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4756) timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4758) error = sctp_wait_for_accept(sk, timeo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4759) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4760) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4762) /* We treat the list of associations on the endpoint as the accept
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4763) * queue and pick the first association on the list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4764) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4765) asoc = list_entry(ep->asocs.next, struct sctp_association, asocs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4767) newsk = sp->pf->create_accept_sk(sk, asoc, kern);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4768) if (!newsk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4769) error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4770) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4773) /* Populate the fields of the newsk from the oldsk and migrate the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4774) * asoc to the newsk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4775) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4776) error = sctp_sock_migrate(sk, newsk, asoc, SCTP_SOCKET_TCP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4777) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4778) sk_common_release(newsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4779) newsk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4782) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4783) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4784) *err = error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4785) return newsk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4786) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4788) /* The SCTP ioctl handler. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4789) static int sctp_ioctl(struct sock *sk, int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4790) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4791) int rc = -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4793) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4795) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4796) * SEQPACKET-style sockets in LISTENING state are valid, for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4797) * SCTP, so only discard TCP-style sockets in LISTENING state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4798) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4799) if (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4800) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4802) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4803) case SIOCINQ: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4804) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4805) unsigned int amount = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4807) skb = skb_peek(&sk->sk_receive_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4808) if (skb != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4809) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4810) * We will only return the amount of this packet since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4811) * that is all that will be read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4812) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4813) amount = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4814) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4815) rc = put_user(amount, (int __user *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4816) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4818) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4819) rc = -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4820) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4822) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4823) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4824) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4827) /* This is the function which gets called during socket creation to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4828) * initialized the SCTP-specific portion of the sock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4829) * The sock structure should already be zero-filled memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4830) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4831) static int sctp_init_sock(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4832) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4833) struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4834) struct sctp_sock *sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4836) pr_debug("%s: sk:%p\n", __func__, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4838) sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4840) /* Initialize the SCTP per socket area. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4841) switch (sk->sk_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4842) case SOCK_SEQPACKET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4843) sp->type = SCTP_SOCKET_UDP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4844) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4845) case SOCK_STREAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4846) sp->type = SCTP_SOCKET_TCP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4847) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4848) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4849) return -ESOCKTNOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4852) sk->sk_gso_type = SKB_GSO_SCTP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4854) /* Initialize default send parameters. These parameters can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4855) * modified with the SCTP_DEFAULT_SEND_PARAM socket option.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4856) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4857) sp->default_stream = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4858) sp->default_ppid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4859) sp->default_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4860) sp->default_context = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4861) sp->default_timetolive = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4863) sp->default_rcv_context = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4864) sp->max_burst = net->sctp.max_burst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4866) sp->sctp_hmac_alg = net->sctp.sctp_hmac_alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4868) /* Initialize default setup parameters. These parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4869) * can be modified with the SCTP_INITMSG socket option or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4870) * overridden by the SCTP_INIT CMSG.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4871) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4872) sp->initmsg.sinit_num_ostreams = sctp_max_outstreams;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4873) sp->initmsg.sinit_max_instreams = sctp_max_instreams;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4874) sp->initmsg.sinit_max_attempts = net->sctp.max_retrans_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4875) sp->initmsg.sinit_max_init_timeo = net->sctp.rto_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4877) /* Initialize default RTO related parameters. These parameters can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4878) * be modified for with the SCTP_RTOINFO socket option.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4879) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4880) sp->rtoinfo.srto_initial = net->sctp.rto_initial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4881) sp->rtoinfo.srto_max = net->sctp.rto_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4882) sp->rtoinfo.srto_min = net->sctp.rto_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4884) /* Initialize default association related parameters. These parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4885) * can be modified with the SCTP_ASSOCINFO socket option.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4886) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4887) sp->assocparams.sasoc_asocmaxrxt = net->sctp.max_retrans_association;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4888) sp->assocparams.sasoc_number_peer_destinations = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4889) sp->assocparams.sasoc_peer_rwnd = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4890) sp->assocparams.sasoc_local_rwnd = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4891) sp->assocparams.sasoc_cookie_life = net->sctp.valid_cookie_life;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4893) /* Initialize default event subscriptions. By default, all the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4894) * options are off.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4895) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4896) sp->subscribe = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4898) /* Default Peer Address Parameters. These defaults can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4899) * be modified via SCTP_PEER_ADDR_PARAMS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4900) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4901) sp->hbinterval = net->sctp.hb_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4902) sp->pathmaxrxt = net->sctp.max_retrans_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4903) sp->pf_retrans = net->sctp.pf_retrans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4904) sp->ps_retrans = net->sctp.ps_retrans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4905) sp->pf_expose = net->sctp.pf_expose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4906) sp->pathmtu = 0; /* allow default discovery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4907) sp->sackdelay = net->sctp.sack_timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4908) sp->sackfreq = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4909) sp->param_flags = SPP_HB_ENABLE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4910) SPP_PMTUD_ENABLE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4911) SPP_SACKDELAY_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4912) sp->default_ss = SCTP_SS_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4914) /* If enabled no SCTP message fragmentation will be performed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4915) * Configure through SCTP_DISABLE_FRAGMENTS socket option.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4916) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4917) sp->disable_fragments = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4919) /* Enable Nagle algorithm by default. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4920) sp->nodelay = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4922) sp->recvrcvinfo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4923) sp->recvnxtinfo = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4925) /* Enable by default. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4926) sp->v4mapped = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4928) /* Auto-close idle associations after the configured
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4929) * number of seconds. A value of 0 disables this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4930) * feature. Configure through the SCTP_AUTOCLOSE socket option,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4931) * for UDP-style sockets only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4932) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4933) sp->autoclose = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4935) /* User specified fragmentation limit. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4936) sp->user_frag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4938) sp->adaptation_ind = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4940) sp->pf = sctp_get_pf_specific(sk->sk_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4942) /* Control variables for partial data delivery. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4943) atomic_set(&sp->pd_mode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4944) skb_queue_head_init(&sp->pd_lobby);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4945) sp->frag_interleave = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4947) /* Create a per socket endpoint structure. Even if we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4948) * change the data structure relationships, this may still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4949) * be useful for storing pre-connect address information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4950) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4951) sp->ep = sctp_endpoint_new(sk, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4952) if (!sp->ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4953) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4955) sp->hmac = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4957) sk->sk_destruct = sctp_destruct_sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4959) SCTP_DBG_OBJCNT_INC(sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4961) local_bh_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4962) sk_sockets_allocated_inc(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4963) sock_prot_inuse_add(net, sk->sk_prot, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4965) local_bh_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4966)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4967) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4968) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4970) /* Cleanup any SCTP per socket resources. Must be called with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4971) * sock_net(sk)->sctp.addr_wq_lock held if sp->do_auto_asconf is true
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4972) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4973) static void sctp_destroy_sock(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4974) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4975) struct sctp_sock *sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4977) pr_debug("%s: sk:%p\n", __func__, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4978)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4979) /* Release our hold on the endpoint. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4980) sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4981) /* This could happen during socket init, thus we bail out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4982) * early, since the rest of the below is not setup either.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4983) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4984) if (sp->ep == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4985) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4987) if (sp->do_auto_asconf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4988) sp->do_auto_asconf = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4989) list_del(&sp->auto_asconf_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4990) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4991) sctp_endpoint_free(sp->ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4992) local_bh_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4993) sk_sockets_allocated_dec(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4994) sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4995) local_bh_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4996) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4998) /* Triggered when there are no references on the socket anymore */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4999) static void sctp_destruct_sock(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5001) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5003) /* Free up the HMAC transform. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5004) crypto_free_shash(sp->hmac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5006) inet_sock_destruct(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5007) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5009) /* API 4.1.7 shutdown() - TCP Style Syntax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5010) * int shutdown(int socket, int how);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5011) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5012) * sd - the socket descriptor of the association to be closed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5013) * how - Specifies the type of shutdown. The values are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5014) * as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5015) * SHUT_RD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5016) * Disables further receive operations. No SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5017) * protocol action is taken.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5018) * SHUT_WR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5019) * Disables further send operations, and initiates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5020) * the SCTP shutdown sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5021) * SHUT_RDWR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5022) * Disables further send and receive operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5023) * and initiates the SCTP shutdown sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5024) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5025) static void sctp_shutdown(struct sock *sk, int how)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5026) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5027) struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5028) struct sctp_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5030) if (!sctp_style(sk, TCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5031) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5033) ep = sctp_sk(sk)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5034) if (how & SEND_SHUTDOWN && !list_empty(&ep->asocs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5035) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5037) inet_sk_set_state(sk, SCTP_SS_CLOSING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5038) asoc = list_entry(ep->asocs.next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5039) struct sctp_association, asocs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5040) sctp_primitive_SHUTDOWN(net, asoc, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5041) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5042) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5044) int sctp_get_sctp_info(struct sock *sk, struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5045) struct sctp_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5046) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5047) struct sctp_transport *prim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5048) struct list_head *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5049) int mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5051) memset(info, 0, sizeof(*info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5052) if (!asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5053) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5055) info->sctpi_s_autoclose = sp->autoclose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5056) info->sctpi_s_adaptation_ind = sp->adaptation_ind;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5057) info->sctpi_s_pd_point = sp->pd_point;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5058) info->sctpi_s_nodelay = sp->nodelay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5059) info->sctpi_s_disable_fragments = sp->disable_fragments;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5060) info->sctpi_s_v4mapped = sp->v4mapped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5061) info->sctpi_s_frag_interleave = sp->frag_interleave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5062) info->sctpi_s_type = sp->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5064) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5065) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5067) info->sctpi_tag = asoc->c.my_vtag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5068) info->sctpi_state = asoc->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5069) info->sctpi_rwnd = asoc->a_rwnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5070) info->sctpi_unackdata = asoc->unack_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5071) info->sctpi_penddata = sctp_tsnmap_pending(&asoc->peer.tsn_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5072) info->sctpi_instrms = asoc->stream.incnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5073) info->sctpi_outstrms = asoc->stream.outcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5074) list_for_each(pos, &asoc->base.inqueue.in_chunk_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5075) info->sctpi_inqueue++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5076) list_for_each(pos, &asoc->outqueue.out_chunk_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5077) info->sctpi_outqueue++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5078) info->sctpi_overall_error = asoc->overall_error_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5079) info->sctpi_max_burst = asoc->max_burst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5080) info->sctpi_maxseg = asoc->frag_point;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5081) info->sctpi_peer_rwnd = asoc->peer.rwnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5082) info->sctpi_peer_tag = asoc->c.peer_vtag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5084) mask = asoc->peer.ecn_capable << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5085) mask = (mask | asoc->peer.ipv4_address) << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5086) mask = (mask | asoc->peer.ipv6_address) << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5087) mask = (mask | asoc->peer.hostname_address) << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5088) mask = (mask | asoc->peer.asconf_capable) << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5089) mask = (mask | asoc->peer.prsctp_capable) << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5090) mask = (mask | asoc->peer.auth_capable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5091) info->sctpi_peer_capable = mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5092) mask = asoc->peer.sack_needed << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5093) mask = (mask | asoc->peer.sack_generation) << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5094) mask = (mask | asoc->peer.zero_window_announced);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5095) info->sctpi_peer_sack = mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5097) info->sctpi_isacks = asoc->stats.isacks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5098) info->sctpi_osacks = asoc->stats.osacks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5099) info->sctpi_opackets = asoc->stats.opackets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5100) info->sctpi_ipackets = asoc->stats.ipackets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5101) info->sctpi_rtxchunks = asoc->stats.rtxchunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5102) info->sctpi_outofseqtsns = asoc->stats.outofseqtsns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5103) info->sctpi_idupchunks = asoc->stats.idupchunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5104) info->sctpi_gapcnt = asoc->stats.gapcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5105) info->sctpi_ouodchunks = asoc->stats.ouodchunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5106) info->sctpi_iuodchunks = asoc->stats.iuodchunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5107) info->sctpi_oodchunks = asoc->stats.oodchunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5108) info->sctpi_iodchunks = asoc->stats.iodchunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5109) info->sctpi_octrlchunks = asoc->stats.octrlchunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5110) info->sctpi_ictrlchunks = asoc->stats.ictrlchunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5112) prim = asoc->peer.primary_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5113) memcpy(&info->sctpi_p_address, &prim->ipaddr, sizeof(prim->ipaddr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5114) info->sctpi_p_state = prim->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5115) info->sctpi_p_cwnd = prim->cwnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5116) info->sctpi_p_srtt = prim->srtt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5117) info->sctpi_p_rto = jiffies_to_msecs(prim->rto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5118) info->sctpi_p_hbinterval = prim->hbinterval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5119) info->sctpi_p_pathmaxrxt = prim->pathmaxrxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5120) info->sctpi_p_sackdelay = jiffies_to_msecs(prim->sackdelay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5121) info->sctpi_p_ssthresh = prim->ssthresh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5122) info->sctpi_p_partial_bytes_acked = prim->partial_bytes_acked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5123) info->sctpi_p_flight_size = prim->flight_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5124) info->sctpi_p_error = prim->error_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5126) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5128) EXPORT_SYMBOL_GPL(sctp_get_sctp_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5130) /* use callback to avoid exporting the core structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5131) void sctp_transport_walk_start(struct rhashtable_iter *iter) __acquires(RCU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5133) rhltable_walk_enter(&sctp_transport_hashtable, iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5135) rhashtable_walk_start(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5138) void sctp_transport_walk_stop(struct rhashtable_iter *iter) __releases(RCU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5140) rhashtable_walk_stop(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5141) rhashtable_walk_exit(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5144) struct sctp_transport *sctp_transport_get_next(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5145) struct rhashtable_iter *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5147) struct sctp_transport *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5149) t = rhashtable_walk_next(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5150) for (; t; t = rhashtable_walk_next(iter)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5151) if (IS_ERR(t)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5152) if (PTR_ERR(t) == -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5153) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5154) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5157) if (!sctp_transport_hold(t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5158) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5160) if (net_eq(t->asoc->base.net, net) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5161) t->asoc->peer.primary_path == t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5162) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5164) sctp_transport_put(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5167) return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5170) struct sctp_transport *sctp_transport_get_idx(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5171) struct rhashtable_iter *iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5172) int pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5174) struct sctp_transport *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5176) if (!pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5177) return SEQ_START_TOKEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5179) while ((t = sctp_transport_get_next(net, iter)) && !IS_ERR(t)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5180) if (!--pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5181) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5182) sctp_transport_put(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5185) return t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5188) int sctp_for_each_endpoint(int (*cb)(struct sctp_endpoint *, void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5189) void *p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5190) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5191) int hash = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5192) struct sctp_ep_common *epb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5193) struct sctp_hashbucket *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5195) for (head = sctp_ep_hashtable; hash < sctp_ep_hashsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5196) hash++, head++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5197) read_lock_bh(&head->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5198) sctp_for_each_hentry(epb, &head->chain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5199) err = cb(sctp_ep(epb), p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5200) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5201) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5203) read_unlock_bh(&head->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5206) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5208) EXPORT_SYMBOL_GPL(sctp_for_each_endpoint);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5210) int sctp_transport_lookup_process(int (*cb)(struct sctp_transport *, void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5211) struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5212) const union sctp_addr *laddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5213) const union sctp_addr *paddr, void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5215) struct sctp_transport *transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5216) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5218) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5219) transport = sctp_addrs_lookup_transport(net, laddr, paddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5220) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5221) if (!transport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5222) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5224) err = cb(transport, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5225) sctp_transport_put(transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5227) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5229) EXPORT_SYMBOL_GPL(sctp_transport_lookup_process);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5231) int sctp_transport_traverse_process(sctp_callback_t cb, sctp_callback_t cb_done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5232) struct net *net, int *pos, void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5234) struct rhashtable_iter hti;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5235) struct sctp_transport *tsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5236) struct sctp_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5237) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5239) again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5240) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5241) sctp_transport_walk_start(&hti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5243) tsp = sctp_transport_get_idx(net, &hti, *pos + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5244) for (; !IS_ERR_OR_NULL(tsp); tsp = sctp_transport_get_next(net, &hti)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5245) ep = tsp->asoc->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5246) if (sctp_endpoint_hold(ep)) { /* asoc can be peeled off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5247) ret = cb(ep, tsp, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5248) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5249) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5250) sctp_endpoint_put(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5252) (*pos)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5253) sctp_transport_put(tsp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5255) sctp_transport_walk_stop(&hti);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5257) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5258) if (cb_done && !cb_done(ep, tsp, p)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5259) (*pos)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5260) sctp_endpoint_put(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5261) sctp_transport_put(tsp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5262) goto again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5264) sctp_endpoint_put(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5265) sctp_transport_put(tsp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5268) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5270) EXPORT_SYMBOL_GPL(sctp_transport_traverse_process);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5272) /* 7.2.1 Association Status (SCTP_STATUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5274) * Applications can retrieve current status information about an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5275) * association, including association state, peer receiver window size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5276) * number of unacked data chunks, and number of data chunks pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5277) * receipt. This information is read-only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5278) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5279) static int sctp_getsockopt_sctp_status(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5280) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5281) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5283) struct sctp_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5284) struct sctp_association *asoc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5285) struct sctp_transport *transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5286) sctp_assoc_t associd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5287) int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5289) if (len < sizeof(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5290) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5291) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5294) len = sizeof(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5295) if (copy_from_user(&status, optval, len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5296) retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5297) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5300) associd = status.sstat_assoc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5301) asoc = sctp_id2assoc(sk, associd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5302) if (!asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5303) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5304) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5307) transport = asoc->peer.primary_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5309) status.sstat_assoc_id = sctp_assoc2id(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5310) status.sstat_state = sctp_assoc_to_state(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5311) status.sstat_rwnd = asoc->peer.rwnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5312) status.sstat_unackdata = asoc->unack_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5314) status.sstat_penddata = sctp_tsnmap_pending(&asoc->peer.tsn_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5315) status.sstat_instrms = asoc->stream.incnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5316) status.sstat_outstrms = asoc->stream.outcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5317) status.sstat_fragmentation_point = asoc->frag_point;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5318) status.sstat_primary.spinfo_assoc_id = sctp_assoc2id(transport->asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5319) memcpy(&status.sstat_primary.spinfo_address, &transport->ipaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5320) transport->af_specific->sockaddr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5321) /* Map ipv4 address into v4-mapped-on-v6 address. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5322) sctp_get_pf_specific(sk->sk_family)->addr_to_user(sctp_sk(sk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5323) (union sctp_addr *)&status.sstat_primary.spinfo_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5324) status.sstat_primary.spinfo_state = transport->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5325) status.sstat_primary.spinfo_cwnd = transport->cwnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5326) status.sstat_primary.spinfo_srtt = transport->srtt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5327) status.sstat_primary.spinfo_rto = jiffies_to_msecs(transport->rto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5328) status.sstat_primary.spinfo_mtu = transport->pathmtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5330) if (status.sstat_primary.spinfo_state == SCTP_UNKNOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5331) status.sstat_primary.spinfo_state = SCTP_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5333) if (put_user(len, optlen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5334) retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5335) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5338) pr_debug("%s: len:%d, state:%d, rwnd:%d, assoc_id:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5339) __func__, len, status.sstat_state, status.sstat_rwnd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5340) status.sstat_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5342) if (copy_to_user(optval, &status, len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5343) retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5344) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5347) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5348) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5352) /* 7.2.2 Peer Address Information (SCTP_GET_PEER_ADDR_INFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5353) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5354) * Applications can retrieve information about a specific peer address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5355) * of an association, including its reachability state, congestion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5356) * window, and retransmission timer values. This information is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5357) * read-only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5358) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5359) static int sctp_getsockopt_peer_addr_info(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5360) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5361) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5363) struct sctp_paddrinfo pinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5364) struct sctp_transport *transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5365) int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5367) if (len < sizeof(pinfo)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5368) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5369) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5372) len = sizeof(pinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5373) if (copy_from_user(&pinfo, optval, len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5374) retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5375) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5378) transport = sctp_addr_id2transport(sk, &pinfo.spinfo_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5379) pinfo.spinfo_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5380) if (!transport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5381) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5382) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5385) if (transport->state == SCTP_PF &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5386) transport->asoc->pf_expose == SCTP_PF_EXPOSE_DISABLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5387) retval = -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5388) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5391) pinfo.spinfo_assoc_id = sctp_assoc2id(transport->asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5392) pinfo.spinfo_state = transport->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5393) pinfo.spinfo_cwnd = transport->cwnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5394) pinfo.spinfo_srtt = transport->srtt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5395) pinfo.spinfo_rto = jiffies_to_msecs(transport->rto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5396) pinfo.spinfo_mtu = transport->pathmtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5398) if (pinfo.spinfo_state == SCTP_UNKNOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5399) pinfo.spinfo_state = SCTP_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5401) if (put_user(len, optlen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5402) retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5403) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5406) if (copy_to_user(optval, &pinfo, len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5407) retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5408) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5411) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5412) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5415) /* 7.1.12 Enable/Disable message fragmentation (SCTP_DISABLE_FRAGMENTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5416) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5417) * This option is a on/off flag. If enabled no SCTP message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5418) * fragmentation will be performed. Instead if a message being sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5419) * exceeds the current PMTU size, the message will NOT be sent and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5420) * instead a error will be indicated to the user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5421) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5422) static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5423) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5425) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5427) if (len < sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5428) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5430) len = sizeof(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5431) val = (sctp_sk(sk)->disable_fragments == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5432) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5433) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5434) if (copy_to_user(optval, &val, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5435) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5436) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5439) /* 7.1.15 Set notification and ancillary events (SCTP_EVENTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5440) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5441) * This socket option is used to specify various notifications and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5442) * ancillary data the user wishes to receive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5443) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5444) static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5445) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5447) struct sctp_event_subscribe subscribe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5448) __u8 *sn_type = (__u8 *)&subscribe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5449) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5451) if (len == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5452) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5453) if (len > sizeof(struct sctp_event_subscribe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5454) len = sizeof(struct sctp_event_subscribe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5455) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5456) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5458) for (i = 0; i < len; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5459) sn_type[i] = sctp_ulpevent_type_enabled(sctp_sk(sk)->subscribe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5460) SCTP_SN_TYPE_BASE + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5462) if (copy_to_user(optval, &subscribe, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5463) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5465) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5468) /* 7.1.8 Automatic Close of associations (SCTP_AUTOCLOSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5469) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5470) * This socket option is applicable to the UDP-style socket only. When
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5471) * set it will cause associations that are idle for more than the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5472) * specified number of seconds to automatically close. An association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5473) * being idle is defined an association that has NOT sent or received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5474) * user data. The special value of '0' indicates that no automatic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5475) * close of any associations should be performed. The option expects an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5476) * integer defining the number of seconds of idle time before an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5477) * association is closed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5478) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5479) static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5481) /* Applicable to UDP-style socket only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5482) if (sctp_style(sk, TCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5483) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5484) if (len < sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5485) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5486) len = sizeof(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5487) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5488) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5489) if (put_user(sctp_sk(sk)->autoclose, (int __user *)optval))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5490) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5491) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5494) /* Helper routine to branch off an association to a new socket. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5495) int sctp_do_peeloff(struct sock *sk, sctp_assoc_t id, struct socket **sockp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5496) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5497) struct sctp_association *asoc = sctp_id2assoc(sk, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5498) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5499) struct socket *sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5500) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5502) /* Do not peel off from one netns to another one. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5503) if (!net_eq(current->nsproxy->net_ns, sock_net(sk)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5504) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5506) if (!asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5507) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5509) /* An association cannot be branched off from an already peeled-off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5510) * socket, nor is this supported for tcp style sockets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5511) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5512) if (!sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5513) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5515) /* Create a new socket. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5516) err = sock_create(sk->sk_family, SOCK_SEQPACKET, IPPROTO_SCTP, &sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5517) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5518) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5520) sctp_copy_sock(sock->sk, sk, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5522) /* Make peeled-off sockets more like 1-1 accepted sockets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5523) * Set the daddr and initialize id to something more random and also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5524) * copy over any ip options.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5525) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5526) sp->pf->to_sk_daddr(&asoc->peer.primary_addr, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5527) sp->pf->copy_ip_options(sk, sock->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5529) /* Populate the fields of the newsk from the oldsk and migrate the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5530) * asoc to the newsk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5531) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5532) err = sctp_sock_migrate(sk, sock->sk, asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5533) SCTP_SOCKET_UDP_HIGH_BANDWIDTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5534) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5535) sock_release(sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5536) sock = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5539) *sockp = sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5541) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5543) EXPORT_SYMBOL(sctp_do_peeloff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5545) static int sctp_getsockopt_peeloff_common(struct sock *sk, sctp_peeloff_arg_t *peeloff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5546) struct file **newfile, unsigned flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5548) struct socket *newsock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5549) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5551) retval = sctp_do_peeloff(sk, peeloff->associd, &newsock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5552) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5553) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5555) /* Map the socket to an unused fd that can be returned to the user. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5556) retval = get_unused_fd_flags(flags & SOCK_CLOEXEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5557) if (retval < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5558) sock_release(newsock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5559) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5562) *newfile = sock_alloc_file(newsock, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5563) if (IS_ERR(*newfile)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5564) put_unused_fd(retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5565) retval = PTR_ERR(*newfile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5566) *newfile = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5567) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5570) pr_debug("%s: sk:%p, newsk:%p, sd:%d\n", __func__, sk, newsock->sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5571) retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5573) peeloff->sd = retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5575) if (flags & SOCK_NONBLOCK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5576) (*newfile)->f_flags |= O_NONBLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5577) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5578) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5581) static int sctp_getsockopt_peeloff(struct sock *sk, int len, char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5582) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5583) sctp_peeloff_arg_t peeloff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5584) struct file *newfile = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5585) int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5587) if (len < sizeof(sctp_peeloff_arg_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5588) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5589) len = sizeof(sctp_peeloff_arg_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5590) if (copy_from_user(&peeloff, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5591) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5593) retval = sctp_getsockopt_peeloff_common(sk, &peeloff, &newfile, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5594) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5595) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5597) /* Return the fd mapped to the new socket. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5598) if (put_user(len, optlen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5599) fput(newfile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5600) put_unused_fd(retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5601) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5604) if (copy_to_user(optval, &peeloff, len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5605) fput(newfile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5606) put_unused_fd(retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5607) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5609) fd_install(retval, newfile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5610) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5611) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5614) static int sctp_getsockopt_peeloff_flags(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5615) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5616) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5617) sctp_peeloff_flags_arg_t peeloff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5618) struct file *newfile = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5619) int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5621) if (len < sizeof(sctp_peeloff_flags_arg_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5622) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5623) len = sizeof(sctp_peeloff_flags_arg_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5624) if (copy_from_user(&peeloff, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5625) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5627) retval = sctp_getsockopt_peeloff_common(sk, &peeloff.p_arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5628) &newfile, peeloff.flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5629) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5630) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5632) /* Return the fd mapped to the new socket. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5633) if (put_user(len, optlen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5634) fput(newfile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5635) put_unused_fd(retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5636) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5639) if (copy_to_user(optval, &peeloff, len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5640) fput(newfile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5641) put_unused_fd(retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5642) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5644) fd_install(retval, newfile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5645) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5646) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5649) /* 7.1.13 Peer Address Parameters (SCTP_PEER_ADDR_PARAMS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5650) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5651) * Applications can enable or disable heartbeats for any peer address of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5652) * an association, modify an address's heartbeat interval, force a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5653) * heartbeat to be sent immediately, and adjust the address's maximum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5654) * number of retransmissions sent before an address is considered
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5655) * unreachable. The following structure is used to access and modify an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5656) * address's parameters:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5657) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5658) * struct sctp_paddrparams {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5659) * sctp_assoc_t spp_assoc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5660) * struct sockaddr_storage spp_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5661) * uint32_t spp_hbinterval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5662) * uint16_t spp_pathmaxrxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5663) * uint32_t spp_pathmtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5664) * uint32_t spp_sackdelay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5665) * uint32_t spp_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5666) * };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5667) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5668) * spp_assoc_id - (one-to-many style socket) This is filled in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5669) * application, and identifies the association for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5670) * this query.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5671) * spp_address - This specifies which address is of interest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5672) * spp_hbinterval - This contains the value of the heartbeat interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5673) * in milliseconds. If a value of zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5674) * is present in this field then no changes are to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5675) * be made to this parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5676) * spp_pathmaxrxt - This contains the maximum number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5677) * retransmissions before this address shall be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5678) * considered unreachable. If a value of zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5679) * is present in this field then no changes are to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5680) * be made to this parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5681) * spp_pathmtu - When Path MTU discovery is disabled the value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5682) * specified here will be the "fixed" path mtu.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5683) * Note that if the spp_address field is empty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5684) * then all associations on this address will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5685) * have this fixed path mtu set upon them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5686) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5687) * spp_sackdelay - When delayed sack is enabled, this value specifies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5688) * the number of milliseconds that sacks will be delayed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5689) * for. This value will apply to all addresses of an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5690) * association if the spp_address field is empty. Note
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5691) * also, that if delayed sack is enabled and this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5692) * value is set to 0, no change is made to the last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5693) * recorded delayed sack timer value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5694) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5695) * spp_flags - These flags are used to control various features
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5696) * on an association. The flag field may contain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5697) * zero or more of the following options.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5698) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5699) * SPP_HB_ENABLE - Enable heartbeats on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5700) * specified address. Note that if the address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5701) * field is empty all addresses for the association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5702) * have heartbeats enabled upon them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5703) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5704) * SPP_HB_DISABLE - Disable heartbeats on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5705) * speicifed address. Note that if the address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5706) * field is empty all addresses for the association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5707) * will have their heartbeats disabled. Note also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5708) * that SPP_HB_ENABLE and SPP_HB_DISABLE are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5709) * mutually exclusive, only one of these two should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5710) * be specified. Enabling both fields will have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5711) * undetermined results.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5712) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5713) * SPP_HB_DEMAND - Request a user initiated heartbeat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5714) * to be made immediately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5715) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5716) * SPP_PMTUD_ENABLE - This field will enable PMTU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5717) * discovery upon the specified address. Note that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5718) * if the address feild is empty then all addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5719) * on the association are effected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5720) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5721) * SPP_PMTUD_DISABLE - This field will disable PMTU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5722) * discovery upon the specified address. Note that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5723) * if the address feild is empty then all addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5724) * on the association are effected. Not also that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5725) * SPP_PMTUD_ENABLE and SPP_PMTUD_DISABLE are mutually
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5726) * exclusive. Enabling both will have undetermined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5727) * results.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5728) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5729) * SPP_SACKDELAY_ENABLE - Setting this flag turns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5730) * on delayed sack. The time specified in spp_sackdelay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5731) * is used to specify the sack delay for this address. Note
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5732) * that if spp_address is empty then all addresses will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5733) * enable delayed sack and take on the sack delay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5734) * value specified in spp_sackdelay.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5735) * SPP_SACKDELAY_DISABLE - Setting this flag turns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5736) * off delayed sack. If the spp_address field is blank then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5737) * delayed sack is disabled for the entire association. Note
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5738) * also that this field is mutually exclusive to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5739) * SPP_SACKDELAY_ENABLE, setting both will have undefined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5740) * results.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5741) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5742) * SPP_IPV6_FLOWLABEL: Setting this flag enables the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5743) * setting of the IPV6 flow label value. The value is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5744) * contained in the spp_ipv6_flowlabel field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5745) * Upon retrieval, this flag will be set to indicate that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5746) * the spp_ipv6_flowlabel field has a valid value returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5747) * If a specific destination address is set (in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5748) * spp_address field), then the value returned is that of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5749) * the address. If just an association is specified (and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5750) * no address), then the association's default flow label
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5751) * is returned. If neither an association nor a destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5752) * is specified, then the socket's default flow label is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5753) * returned. For non-IPv6 sockets, this flag will be left
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5754) * cleared.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5755) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5756) * SPP_DSCP: Setting this flag enables the setting of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5757) * Differentiated Services Code Point (DSCP) value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5758) * associated with either the association or a specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5759) * address. The value is obtained in the spp_dscp field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5760) * Upon retrieval, this flag will be set to indicate that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5761) * the spp_dscp field has a valid value returned. If a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5762) * specific destination address is set when called (in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5763) * spp_address field), then that specific destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5764) * address's DSCP value is returned. If just an association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5765) * is specified, then the association's default DSCP is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5766) * returned. If neither an association nor a destination is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5767) * specified, then the socket's default DSCP is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5768) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5769) * spp_ipv6_flowlabel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5770) * - This field is used in conjunction with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5771) * SPP_IPV6_FLOWLABEL flag and contains the IPv6 flow label.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5772) * The 20 least significant bits are used for the flow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5773) * label. This setting has precedence over any IPv6-layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5774) * setting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5775) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5776) * spp_dscp - This field is used in conjunction with the SPP_DSCP flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5777) * and contains the DSCP. The 6 most significant bits are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5778) * used for the DSCP. This setting has precedence over any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5779) * IPv4- or IPv6- layer setting.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5780) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5781) static int sctp_getsockopt_peer_addr_params(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5782) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5783) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5784) struct sctp_paddrparams params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5785) struct sctp_transport *trans = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5786) struct sctp_association *asoc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5787) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5789) if (len >= sizeof(params))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5790) len = sizeof(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5791) else if (len >= ALIGN(offsetof(struct sctp_paddrparams,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5792) spp_ipv6_flowlabel), 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5793) len = ALIGN(offsetof(struct sctp_paddrparams,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5794) spp_ipv6_flowlabel), 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5795) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5796) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5798) if (copy_from_user(¶ms, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5799) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5801) /* If an address other than INADDR_ANY is specified, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5802) * no transport is found, then the request is invalid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5803) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5804) if (!sctp_is_any(sk, (union sctp_addr *)¶ms.spp_address)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5805) trans = sctp_addr_id2transport(sk, ¶ms.spp_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5806) params.spp_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5807) if (!trans) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5808) pr_debug("%s: failed no transport\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5809) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5813) /* Get association, if assoc_id != SCTP_FUTURE_ASSOC and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5814) * socket is a one to many style socket, and an association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5815) * was not found, then the id was invalid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5816) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5817) asoc = sctp_id2assoc(sk, params.spp_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5818) if (!asoc && params.spp_assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5819) sctp_style(sk, UDP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5820) pr_debug("%s: failed no association\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5821) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5824) if (trans) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5825) /* Fetch transport values. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5826) params.spp_hbinterval = jiffies_to_msecs(trans->hbinterval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5827) params.spp_pathmtu = trans->pathmtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5828) params.spp_pathmaxrxt = trans->pathmaxrxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5829) params.spp_sackdelay = jiffies_to_msecs(trans->sackdelay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5831) /*draft-11 doesn't say what to return in spp_flags*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5832) params.spp_flags = trans->param_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5833) if (trans->flowlabel & SCTP_FLOWLABEL_SET_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5834) params.spp_ipv6_flowlabel = trans->flowlabel &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5835) SCTP_FLOWLABEL_VAL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5836) params.spp_flags |= SPP_IPV6_FLOWLABEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5838) if (trans->dscp & SCTP_DSCP_SET_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5839) params.spp_dscp = trans->dscp & SCTP_DSCP_VAL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5840) params.spp_flags |= SPP_DSCP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5841) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5842) } else if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5843) /* Fetch association values. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5844) params.spp_hbinterval = jiffies_to_msecs(asoc->hbinterval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5845) params.spp_pathmtu = asoc->pathmtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5846) params.spp_pathmaxrxt = asoc->pathmaxrxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5847) params.spp_sackdelay = jiffies_to_msecs(asoc->sackdelay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5849) /*draft-11 doesn't say what to return in spp_flags*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5850) params.spp_flags = asoc->param_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5851) if (asoc->flowlabel & SCTP_FLOWLABEL_SET_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5852) params.spp_ipv6_flowlabel = asoc->flowlabel &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5853) SCTP_FLOWLABEL_VAL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5854) params.spp_flags |= SPP_IPV6_FLOWLABEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5856) if (asoc->dscp & SCTP_DSCP_SET_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5857) params.spp_dscp = asoc->dscp & SCTP_DSCP_VAL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5858) params.spp_flags |= SPP_DSCP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5860) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5861) /* Fetch socket values. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5862) params.spp_hbinterval = sp->hbinterval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5863) params.spp_pathmtu = sp->pathmtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5864) params.spp_sackdelay = sp->sackdelay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5865) params.spp_pathmaxrxt = sp->pathmaxrxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5867) /*draft-11 doesn't say what to return in spp_flags*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5868) params.spp_flags = sp->param_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5869) if (sp->flowlabel & SCTP_FLOWLABEL_SET_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5870) params.spp_ipv6_flowlabel = sp->flowlabel &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5871) SCTP_FLOWLABEL_VAL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5872) params.spp_flags |= SPP_IPV6_FLOWLABEL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5873) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5874) if (sp->dscp & SCTP_DSCP_SET_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5875) params.spp_dscp = sp->dscp & SCTP_DSCP_VAL_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5876) params.spp_flags |= SPP_DSCP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5880) if (copy_to_user(optval, ¶ms, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5881) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5883) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5884) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5886) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5887) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5889) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5890) * 7.1.23. Get or set delayed ack timer (SCTP_DELAYED_SACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5891) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5892) * This option will effect the way delayed acks are performed. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5893) * option allows you to get or set the delayed ack time, in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5894) * milliseconds. It also allows changing the delayed ack frequency.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5895) * Changing the frequency to 1 disables the delayed sack algorithm. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5896) * the assoc_id is 0, then this sets or gets the endpoints default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5897) * values. If the assoc_id field is non-zero, then the set or get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5898) * effects the specified association for the one to many model (the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5899) * assoc_id field is ignored by the one to one model). Note that if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5900) * sack_delay or sack_freq are 0 when setting this option, then the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5901) * current values will remain unchanged.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5902) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5903) * struct sctp_sack_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5904) * sctp_assoc_t sack_assoc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5905) * uint32_t sack_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5906) * uint32_t sack_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5907) * };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5908) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5909) * sack_assoc_id - This parameter, indicates which association the user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5910) * is performing an action upon. Note that if this field's value is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5911) * zero then the endpoints default value is changed (effecting future
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5912) * associations only).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5913) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5914) * sack_delay - This parameter contains the number of milliseconds that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5915) * the user is requesting the delayed ACK timer be set to. Note that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5916) * this value is defined in the standard to be between 200 and 500
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5917) * milliseconds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5918) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5919) * sack_freq - This parameter contains the number of packets that must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5920) * be received before a sack is sent without waiting for the delay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5921) * timer to expire. The default value for this is 2, setting this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5922) * value to 1 will disable the delayed sack algorithm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5923) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5924) static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5925) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5926) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5927) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5928) struct sctp_sack_info params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5929) struct sctp_association *asoc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5930) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5932) if (len >= sizeof(struct sctp_sack_info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5933) len = sizeof(struct sctp_sack_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5935) if (copy_from_user(¶ms, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5936) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5937) } else if (len == sizeof(struct sctp_assoc_value)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5938) pr_warn_ratelimited(DEPRECATED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5939) "%s (pid %d) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5940) "Use of struct sctp_assoc_value in delayed_ack socket option.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5941) "Use struct sctp_sack_info instead\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5942) current->comm, task_pid_nr(current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5943) if (copy_from_user(¶ms, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5944) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5945) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5946) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5948) /* Get association, if sack_assoc_id != SCTP_FUTURE_ASSOC and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5949) * socket is a one to many style socket, and an association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5950) * was not found, then the id was invalid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5951) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5952) asoc = sctp_id2assoc(sk, params.sack_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5953) if (!asoc && params.sack_assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5954) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5955) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5956)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5957) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5958) /* Fetch association values. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5959) if (asoc->param_flags & SPP_SACKDELAY_ENABLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5960) params.sack_delay = jiffies_to_msecs(asoc->sackdelay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5961) params.sack_freq = asoc->sackfreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5963) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5964) params.sack_delay = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5965) params.sack_freq = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5966) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5967) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5968) /* Fetch socket values. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5969) if (sp->param_flags & SPP_SACKDELAY_ENABLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5970) params.sack_delay = sp->sackdelay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5971) params.sack_freq = sp->sackfreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5972) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5973) params.sack_delay = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5974) params.sack_freq = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5976) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5978) if (copy_to_user(optval, ¶ms, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5979) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5981) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5982) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5984) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5985) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5987) /* 7.1.3 Initialization Parameters (SCTP_INITMSG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5988) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5989) * Applications can specify protocol parameters for the default association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5990) * initialization. The option name argument to setsockopt() and getsockopt()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5991) * is SCTP_INITMSG.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5992) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5993) * Setting initialization parameters is effective only on an unconnected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5994) * socket (for UDP-style sockets only future associations are effected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5995) * by the change). With TCP-style sockets, this option is inherited by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5996) * sockets derived from a listener socket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5997) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5998) static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5999) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6000) if (len < sizeof(struct sctp_initmsg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6001) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6002) len = sizeof(struct sctp_initmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6003) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6004) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6005) if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6006) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6007) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6008) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6011) static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6012) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6013) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6014) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6015) int cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6016) struct sctp_getaddrs getaddrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6017) struct sctp_transport *from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6018) void __user *to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6019) union sctp_addr temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6020) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6021) int addrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6022) size_t space_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6023) int bytes_copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6025) if (len < sizeof(struct sctp_getaddrs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6026) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6028) if (copy_from_user(&getaddrs, optval, sizeof(struct sctp_getaddrs)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6029) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6031) /* For UDP-style sockets, id specifies the association to query. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6032) asoc = sctp_id2assoc(sk, getaddrs.assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6033) if (!asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6034) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6036) to = optval + offsetof(struct sctp_getaddrs, addrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6037) space_left = len - offsetof(struct sctp_getaddrs, addrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6039) list_for_each_entry(from, &asoc->peer.transport_addr_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6040) transports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6041) memcpy(&temp, &from->ipaddr, sizeof(temp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6042) addrlen = sctp_get_pf_specific(sk->sk_family)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6043) ->addr_to_user(sp, &temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6044) if (space_left < addrlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6045) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6046) if (copy_to_user(to, &temp, addrlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6047) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6048) to += addrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6049) cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6050) space_left -= addrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6051) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6053) if (put_user(cnt, &((struct sctp_getaddrs __user *)optval)->addr_num))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6054) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6055) bytes_copied = ((char __user *)to) - optval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6056) if (put_user(bytes_copied, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6057) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6059) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6060) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6061)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6062) static int sctp_copy_laddrs(struct sock *sk, __u16 port, void *to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6063) size_t space_left, int *bytes_copied)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6064) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6065) struct sctp_sockaddr_entry *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6066) union sctp_addr temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6067) int cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6068) int addrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6069) struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6071) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6072) list_for_each_entry_rcu(addr, &net->sctp.local_addr_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6073) if (!addr->valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6074) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6076) if ((PF_INET == sk->sk_family) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6077) (AF_INET6 == addr->a.sa.sa_family))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6078) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6079) if ((PF_INET6 == sk->sk_family) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6080) inet_v6_ipv6only(sk) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6081) (AF_INET == addr->a.sa.sa_family))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6082) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6083) memcpy(&temp, &addr->a, sizeof(temp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6084) if (!temp.v4.sin_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6085) temp.v4.sin_port = htons(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6086)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6087) addrlen = sctp_get_pf_specific(sk->sk_family)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6088) ->addr_to_user(sctp_sk(sk), &temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6090) if (space_left < addrlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6091) cnt = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6092) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6093) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6094) memcpy(to, &temp, addrlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6095)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6096) to += addrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6097) cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6098) space_left -= addrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6099) *bytes_copied += addrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6101) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6103) return cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6107) static int sctp_getsockopt_local_addrs(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6108) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6110) struct sctp_bind_addr *bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6111) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6112) int cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6113) struct sctp_getaddrs getaddrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6114) struct sctp_sockaddr_entry *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6115) void __user *to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6116) union sctp_addr temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6117) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6118) int addrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6119) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6120) size_t space_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6121) int bytes_copied = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6122) void *addrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6123) void *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6125) if (len < sizeof(struct sctp_getaddrs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6126) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6128) if (copy_from_user(&getaddrs, optval, sizeof(struct sctp_getaddrs)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6129) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6131) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6132) * For UDP-style sockets, id specifies the association to query.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6133) * If the id field is set to the value '0' then the locally bound
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6134) * addresses are returned without regard to any particular
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6135) * association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6136) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6137) if (0 == getaddrs.assoc_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6138) bp = &sctp_sk(sk)->ep->base.bind_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6139) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6140) asoc = sctp_id2assoc(sk, getaddrs.assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6141) if (!asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6142) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6143) bp = &asoc->base.bind_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6146) to = optval + offsetof(struct sctp_getaddrs, addrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6147) space_left = len - offsetof(struct sctp_getaddrs, addrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6149) addrs = kmalloc(space_left, GFP_USER | __GFP_NOWARN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6150) if (!addrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6151) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6153) /* If the endpoint is bound to 0.0.0.0 or ::0, get the valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6154) * addresses from the global local address list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6155) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6156) if (sctp_list_single_entry(&bp->address_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6157) addr = list_entry(bp->address_list.next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6158) struct sctp_sockaddr_entry, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6159) if (sctp_is_any(sk, &addr->a)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6160) cnt = sctp_copy_laddrs(sk, bp->port, addrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6161) space_left, &bytes_copied);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6162) if (cnt < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6163) err = cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6164) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6166) goto copy_getaddrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6170) buf = addrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6171) /* Protection on the bound address list is not needed since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6172) * in the socket option context we hold a socket lock and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6173) * thus the bound address list can't change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6174) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6175) list_for_each_entry(addr, &bp->address_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6176) memcpy(&temp, &addr->a, sizeof(temp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6177) addrlen = sctp_get_pf_specific(sk->sk_family)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6178) ->addr_to_user(sp, &temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6179) if (space_left < addrlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6180) err = -ENOMEM; /*fixme: right error?*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6181) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6183) memcpy(buf, &temp, addrlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6184) buf += addrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6185) bytes_copied += addrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6186) cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6187) space_left -= addrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6190) copy_getaddrs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6191) if (copy_to_user(to, addrs, bytes_copied)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6192) err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6193) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6195) if (put_user(cnt, &((struct sctp_getaddrs __user *)optval)->addr_num)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6196) err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6197) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6199) /* XXX: We should have accounted for sizeof(struct sctp_getaddrs) too,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6200) * but we can't change it anymore.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6201) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6202) if (put_user(bytes_copied, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6203) err = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6204) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6205) kfree(addrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6206) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6209) /* 7.1.10 Set Primary Address (SCTP_PRIMARY_ADDR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6210) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6211) * Requests that the local SCTP stack use the enclosed peer address as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6212) * the association primary. The enclosed address must be one of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6213) * association peer's addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6214) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6215) static int sctp_getsockopt_primary_addr(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6216) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6218) struct sctp_prim prim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6219) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6220) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6222) if (len < sizeof(struct sctp_prim))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6223) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6225) len = sizeof(struct sctp_prim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6227) if (copy_from_user(&prim, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6228) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6230) asoc = sctp_id2assoc(sk, prim.ssp_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6231) if (!asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6232) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6234) if (!asoc->peer.primary_path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6235) return -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6237) memcpy(&prim.ssp_addr, &asoc->peer.primary_path->ipaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6238) asoc->peer.primary_path->af_specific->sockaddr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6240) sctp_get_pf_specific(sk->sk_family)->addr_to_user(sp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6241) (union sctp_addr *)&prim.ssp_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6243) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6244) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6245) if (copy_to_user(optval, &prim, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6246) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6248) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6251) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6252) * 7.1.11 Set Adaptation Layer Indicator (SCTP_ADAPTATION_LAYER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6253) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6254) * Requests that the local endpoint set the specified Adaptation Layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6255) * Indication parameter for all future INIT and INIT-ACK exchanges.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6256) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6257) static int sctp_getsockopt_adaptation_layer(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6258) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6260) struct sctp_setadaptation adaptation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6262) if (len < sizeof(struct sctp_setadaptation))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6263) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6265) len = sizeof(struct sctp_setadaptation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6267) adaptation.ssb_adaptation_ind = sctp_sk(sk)->adaptation_ind;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6269) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6270) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6271) if (copy_to_user(optval, &adaptation, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6272) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6274) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6277) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6278) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6279) * 7.1.14 Set default send parameters (SCTP_DEFAULT_SEND_PARAM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6280) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6281) * Applications that wish to use the sendto() system call may wish to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6282) * specify a default set of parameters that would normally be supplied
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6283) * through the inclusion of ancillary data. This socket option allows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6284) * such an application to set the default sctp_sndrcvinfo structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6287) * The application that wishes to use this socket option simply passes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6288) * in to this call the sctp_sndrcvinfo structure defined in Section
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6289) * 5.2.2) The input parameters accepted by this call include
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6290) * sinfo_stream, sinfo_flags, sinfo_ppid, sinfo_context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6291) * sinfo_timetolive. The user must provide the sinfo_assoc_id field in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6292) * to this call if the caller is using the UDP model.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6293) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6294) * For getsockopt, it get the default sctp_sndrcvinfo structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6295) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6296) static int sctp_getsockopt_default_send_param(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6297) int len, char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6298) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6300) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6301) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6302) struct sctp_sndrcvinfo info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6304) if (len < sizeof(info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6305) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6307) len = sizeof(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6309) if (copy_from_user(&info, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6310) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6312) asoc = sctp_id2assoc(sk, info.sinfo_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6313) if (!asoc && info.sinfo_assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6314) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6315) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6317) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6318) info.sinfo_stream = asoc->default_stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6319) info.sinfo_flags = asoc->default_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6320) info.sinfo_ppid = asoc->default_ppid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6321) info.sinfo_context = asoc->default_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6322) info.sinfo_timetolive = asoc->default_timetolive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6323) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6324) info.sinfo_stream = sp->default_stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6325) info.sinfo_flags = sp->default_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6326) info.sinfo_ppid = sp->default_ppid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6327) info.sinfo_context = sp->default_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6328) info.sinfo_timetolive = sp->default_timetolive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6331) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6332) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6333) if (copy_to_user(optval, &info, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6334) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6336) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6339) /* RFC6458, Section 8.1.31. Set/get Default Send Parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6340) * (SCTP_DEFAULT_SNDINFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6341) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6342) static int sctp_getsockopt_default_sndinfo(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6343) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6344) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6346) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6347) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6348) struct sctp_sndinfo info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6350) if (len < sizeof(info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6351) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6353) len = sizeof(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6355) if (copy_from_user(&info, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6356) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6358) asoc = sctp_id2assoc(sk, info.snd_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6359) if (!asoc && info.snd_assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6360) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6361) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6363) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6364) info.snd_sid = asoc->default_stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6365) info.snd_flags = asoc->default_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6366) info.snd_ppid = asoc->default_ppid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6367) info.snd_context = asoc->default_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6368) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6369) info.snd_sid = sp->default_stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6370) info.snd_flags = sp->default_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6371) info.snd_ppid = sp->default_ppid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6372) info.snd_context = sp->default_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6375) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6376) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6377) if (copy_to_user(optval, &info, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6378) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6380) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6383) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6384) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6385) * 7.1.5 SCTP_NODELAY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6386) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6387) * Turn on/off any Nagle-like algorithm. This means that packets are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6388) * generally sent as soon as possible and no unnecessary delays are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6389) * introduced, at the cost of more packets in the network. Expects an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6390) * integer boolean flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6391) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6393) static int sctp_getsockopt_nodelay(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6394) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6396) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6398) if (len < sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6399) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6401) len = sizeof(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6402) val = (sctp_sk(sk)->nodelay == 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6403) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6404) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6405) if (copy_to_user(optval, &val, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6406) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6407) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6410) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6411) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6412) * 7.1.1 SCTP_RTOINFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6413) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6414) * The protocol parameters used to initialize and bound retransmission
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6415) * timeout (RTO) are tunable. sctp_rtoinfo structure is used to access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6416) * and modify these parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6417) * All parameters are time values, in milliseconds. A value of 0, when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6418) * modifying the parameters, indicates that the current value should not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6419) * be changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6420) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6421) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6422) static int sctp_getsockopt_rtoinfo(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6423) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6424) int __user *optlen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6425) struct sctp_rtoinfo rtoinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6426) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6428) if (len < sizeof (struct sctp_rtoinfo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6429) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6431) len = sizeof(struct sctp_rtoinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6433) if (copy_from_user(&rtoinfo, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6434) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6436) asoc = sctp_id2assoc(sk, rtoinfo.srto_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6438) if (!asoc && rtoinfo.srto_assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6439) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6440) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6442) /* Values corresponding to the specific association. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6443) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6444) rtoinfo.srto_initial = jiffies_to_msecs(asoc->rto_initial);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6445) rtoinfo.srto_max = jiffies_to_msecs(asoc->rto_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6446) rtoinfo.srto_min = jiffies_to_msecs(asoc->rto_min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6447) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6448) /* Values corresponding to the endpoint. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6449) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6451) rtoinfo.srto_initial = sp->rtoinfo.srto_initial;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6452) rtoinfo.srto_max = sp->rtoinfo.srto_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6453) rtoinfo.srto_min = sp->rtoinfo.srto_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6456) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6457) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6459) if (copy_to_user(optval, &rtoinfo, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6460) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6462) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6465) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6466) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6467) * 7.1.2 SCTP_ASSOCINFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6468) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6469) * This option is used to tune the maximum retransmission attempts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6470) * of the association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6471) * Returns an error if the new association retransmission value is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6472) * greater than the sum of the retransmission value of the peer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6473) * See [SCTP] for more information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6474) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6475) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6476) static int sctp_getsockopt_associnfo(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6477) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6478) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6479) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6481) struct sctp_assocparams assocparams;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6482) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6483) struct list_head *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6484) int cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6486) if (len < sizeof (struct sctp_assocparams))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6487) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6489) len = sizeof(struct sctp_assocparams);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6491) if (copy_from_user(&assocparams, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6492) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6494) asoc = sctp_id2assoc(sk, assocparams.sasoc_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6496) if (!asoc && assocparams.sasoc_assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6497) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6498) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6500) /* Values correspoinding to the specific association */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6501) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6502) assocparams.sasoc_asocmaxrxt = asoc->max_retrans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6503) assocparams.sasoc_peer_rwnd = asoc->peer.rwnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6504) assocparams.sasoc_local_rwnd = asoc->a_rwnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6505) assocparams.sasoc_cookie_life = ktime_to_ms(asoc->cookie_life);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6507) list_for_each(pos, &asoc->peer.transport_addr_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6508) cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6511) assocparams.sasoc_number_peer_destinations = cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6512) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6513) /* Values corresponding to the endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6514) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6516) assocparams.sasoc_asocmaxrxt = sp->assocparams.sasoc_asocmaxrxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6517) assocparams.sasoc_peer_rwnd = sp->assocparams.sasoc_peer_rwnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6518) assocparams.sasoc_local_rwnd = sp->assocparams.sasoc_local_rwnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6519) assocparams.sasoc_cookie_life =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6520) sp->assocparams.sasoc_cookie_life;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6521) assocparams.sasoc_number_peer_destinations =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6522) sp->assocparams.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6523) sasoc_number_peer_destinations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6526) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6527) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6529) if (copy_to_user(optval, &assocparams, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6530) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6532) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6535) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6536) * 7.1.16 Set/clear IPv4 mapped addresses (SCTP_I_WANT_MAPPED_V4_ADDR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6537) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6538) * This socket option is a boolean flag which turns on or off mapped V4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6539) * addresses. If this option is turned on and the socket is type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6540) * PF_INET6, then IPv4 addresses will be mapped to V6 representation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6541) * If this option is turned off, then no mapping will be done of V4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6542) * addresses and a user will receive both PF_INET6 and PF_INET type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6543) * addresses on the socket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6544) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6545) static int sctp_getsockopt_mappedv4(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6546) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6548) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6549) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6551) if (len < sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6552) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6554) len = sizeof(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6555) val = sp->v4mapped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6556) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6557) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6558) if (copy_to_user(optval, &val, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6559) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6561) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6564) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6565) * 7.1.29. Set or Get the default context (SCTP_CONTEXT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6566) * (chapter and verse is quoted at sctp_setsockopt_context())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6567) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6568) static int sctp_getsockopt_context(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6569) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6570) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6571) struct sctp_assoc_value params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6572) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6574) if (len < sizeof(struct sctp_assoc_value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6575) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6577) len = sizeof(struct sctp_assoc_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6579) if (copy_from_user(¶ms, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6580) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6582) asoc = sctp_id2assoc(sk, params.assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6583) if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6584) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6585) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6587) params.assoc_value = asoc ? asoc->default_rcv_context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6588) : sctp_sk(sk)->default_rcv_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6590) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6591) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6592) if (copy_to_user(optval, ¶ms, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6593) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6595) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6598) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6599) * 8.1.16. Get or Set the Maximum Fragmentation Size (SCTP_MAXSEG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6600) * This option will get or set the maximum size to put in any outgoing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6601) * SCTP DATA chunk. If a message is larger than this size it will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6602) * fragmented by SCTP into the specified size. Note that the underlying
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6603) * SCTP implementation may fragment into smaller sized chunks when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6604) * PMTU of the underlying association is smaller than the value set by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6605) * the user. The default value for this option is '0' which indicates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6606) * the user is NOT limiting fragmentation and only the PMTU will effect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6607) * SCTP's choice of DATA chunk size. Note also that values set larger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6608) * than the maximum size of an IP datagram will effectively let SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6609) * control fragmentation (i.e. the same as setting this option to 0).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6610) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6611) * The following structure is used to access and modify this parameter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6612) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6613) * struct sctp_assoc_value {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6614) * sctp_assoc_t assoc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6615) * uint32_t assoc_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6616) * };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6617) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6618) * assoc_id: This parameter is ignored for one-to-one style sockets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6619) * For one-to-many style sockets this parameter indicates which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6620) * association the user is performing an action upon. Note that if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6621) * this field's value is zero then the endpoints default value is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6622) * changed (effecting future associations only).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6623) * assoc_value: This parameter specifies the maximum size in bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6624) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6625) static int sctp_getsockopt_maxseg(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6626) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6627) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6628) struct sctp_assoc_value params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6629) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6631) if (len == sizeof(int)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6632) pr_warn_ratelimited(DEPRECATED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6633) "%s (pid %d) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6634) "Use of int in maxseg socket option.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6635) "Use struct sctp_assoc_value instead\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6636) current->comm, task_pid_nr(current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6637) params.assoc_id = SCTP_FUTURE_ASSOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6638) } else if (len >= sizeof(struct sctp_assoc_value)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6639) len = sizeof(struct sctp_assoc_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6640) if (copy_from_user(¶ms, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6641) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6642) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6643) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6645) asoc = sctp_id2assoc(sk, params.assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6646) if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6647) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6648) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6650) if (asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6651) params.assoc_value = asoc->frag_point;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6652) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6653) params.assoc_value = sctp_sk(sk)->user_frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6655) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6656) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6657) if (len == sizeof(int)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6658) if (copy_to_user(optval, ¶ms.assoc_value, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6659) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6660) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6661) if (copy_to_user(optval, ¶ms, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6662) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6665) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6668) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6669) * 7.1.24. Get or set fragmented interleave (SCTP_FRAGMENT_INTERLEAVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6670) * (chapter and verse is quoted at sctp_setsockopt_fragment_interleave())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6671) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6672) static int sctp_getsockopt_fragment_interleave(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6673) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6674) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6675) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6677) if (len < sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6678) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6680) len = sizeof(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6682) val = sctp_sk(sk)->frag_interleave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6683) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6684) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6685) if (copy_to_user(optval, &val, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6686) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6688) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6689) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6691) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6692) * 7.1.25. Set or Get the sctp partial delivery point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6693) * (chapter and verse is quoted at sctp_setsockopt_partial_delivery_point())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6694) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6695) static int sctp_getsockopt_partial_delivery_point(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6696) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6697) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6698) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6699) u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6701) if (len < sizeof(u32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6702) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6704) len = sizeof(u32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6706) val = sctp_sk(sk)->pd_point;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6707) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6708) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6709) if (copy_to_user(optval, &val, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6710) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6712) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6715) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6716) * 7.1.28. Set or Get the maximum burst (SCTP_MAX_BURST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6717) * (chapter and verse is quoted at sctp_setsockopt_maxburst())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6718) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6719) static int sctp_getsockopt_maxburst(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6720) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6721) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6723) struct sctp_assoc_value params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6724) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6726) if (len == sizeof(int)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6727) pr_warn_ratelimited(DEPRECATED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6728) "%s (pid %d) "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6729) "Use of int in max_burst socket option.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6730) "Use struct sctp_assoc_value instead\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6731) current->comm, task_pid_nr(current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6732) params.assoc_id = SCTP_FUTURE_ASSOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6733) } else if (len >= sizeof(struct sctp_assoc_value)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6734) len = sizeof(struct sctp_assoc_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6735) if (copy_from_user(¶ms, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6736) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6737) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6738) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6740) asoc = sctp_id2assoc(sk, params.assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6741) if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6742) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6743) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6745) params.assoc_value = asoc ? asoc->max_burst : sctp_sk(sk)->max_burst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6747) if (len == sizeof(int)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6748) if (copy_to_user(optval, ¶ms.assoc_value, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6749) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6750) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6751) if (copy_to_user(optval, ¶ms, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6752) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6755) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6759) static int sctp_getsockopt_hmac_ident(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6760) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6761) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6762) struct sctp_endpoint *ep = sctp_sk(sk)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6763) struct sctp_hmacalgo __user *p = (void __user *)optval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6764) struct sctp_hmac_algo_param *hmacs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6765) __u16 data_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6766) u32 num_idents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6767) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6769) if (!ep->auth_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6770) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6772) hmacs = ep->auth_hmacs_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6773) data_len = ntohs(hmacs->param_hdr.length) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6774) sizeof(struct sctp_paramhdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6776) if (len < sizeof(struct sctp_hmacalgo) + data_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6777) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6779) len = sizeof(struct sctp_hmacalgo) + data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6780) num_idents = data_len / sizeof(u16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6782) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6783) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6784) if (put_user(num_idents, &p->shmac_num_idents))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6785) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6786) for (i = 0; i < num_idents; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6787) __u16 hmacid = ntohs(hmacs->hmac_ids[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6789) if (copy_to_user(&p->shmac_idents[i], &hmacid, sizeof(__u16)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6790) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6792) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6795) static int sctp_getsockopt_active_key(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6796) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6797) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6798) struct sctp_endpoint *ep = sctp_sk(sk)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6799) struct sctp_authkeyid val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6800) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6802) if (len < sizeof(struct sctp_authkeyid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6803) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6805) len = sizeof(struct sctp_authkeyid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6806) if (copy_from_user(&val, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6807) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6809) asoc = sctp_id2assoc(sk, val.scact_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6810) if (!asoc && val.scact_assoc_id && sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6811) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6813) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6814) if (!asoc->peer.auth_capable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6815) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6816) val.scact_keynumber = asoc->active_key_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6817) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6818) if (!ep->auth_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6819) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6820) val.scact_keynumber = ep->active_key_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6823) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6824) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6825) if (copy_to_user(optval, &val, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6826) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6828) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6831) static int sctp_getsockopt_peer_auth_chunks(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6832) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6833) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6834) struct sctp_authchunks __user *p = (void __user *)optval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6835) struct sctp_authchunks val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6836) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6837) struct sctp_chunks_param *ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6838) u32 num_chunks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6839) char __user *to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6841) if (len < sizeof(struct sctp_authchunks))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6842) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6844) if (copy_from_user(&val, optval, sizeof(val)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6845) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6847) to = p->gauth_chunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6848) asoc = sctp_id2assoc(sk, val.gauth_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6849) if (!asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6850) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6852) if (!asoc->peer.auth_capable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6853) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6855) ch = asoc->peer.peer_chunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6856) if (!ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6857) goto num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6859) /* See if the user provided enough room for all the data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6860) num_chunks = ntohs(ch->param_hdr.length) - sizeof(struct sctp_paramhdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6861) if (len < num_chunks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6862) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6864) if (copy_to_user(to, ch->chunks, num_chunks))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6865) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6866) num:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6867) len = sizeof(struct sctp_authchunks) + num_chunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6868) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6869) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6870) if (put_user(num_chunks, &p->gauth_number_of_chunks))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6871) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6872) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6873) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6875) static int sctp_getsockopt_local_auth_chunks(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6876) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6877) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6878) struct sctp_endpoint *ep = sctp_sk(sk)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6879) struct sctp_authchunks __user *p = (void __user *)optval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6880) struct sctp_authchunks val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6881) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6882) struct sctp_chunks_param *ch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6883) u32 num_chunks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6884) char __user *to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6886) if (len < sizeof(struct sctp_authchunks))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6887) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6889) if (copy_from_user(&val, optval, sizeof(val)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6890) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6892) to = p->gauth_chunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6893) asoc = sctp_id2assoc(sk, val.gauth_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6894) if (!asoc && val.gauth_assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6895) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6896) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6898) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6899) if (!asoc->peer.auth_capable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6900) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6901) ch = (struct sctp_chunks_param *)asoc->c.auth_chunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6902) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6903) if (!ep->auth_enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6904) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6905) ch = ep->auth_chunk_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6907) if (!ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6908) goto num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6910) num_chunks = ntohs(ch->param_hdr.length) - sizeof(struct sctp_paramhdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6911) if (len < sizeof(struct sctp_authchunks) + num_chunks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6912) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6914) if (copy_to_user(to, ch->chunks, num_chunks))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6915) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6916) num:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6917) len = sizeof(struct sctp_authchunks) + num_chunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6918) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6919) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6920) if (put_user(num_chunks, &p->gauth_number_of_chunks))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6921) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6923) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6924) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6926) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6927) * 8.2.5. Get the Current Number of Associations (SCTP_GET_ASSOC_NUMBER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6928) * This option gets the current number of associations that are attached
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6929) * to a one-to-many style socket. The option value is an uint32_t.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6930) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6931) static int sctp_getsockopt_assoc_number(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6932) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6933) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6934) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6935) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6936) u32 val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6938) if (sctp_style(sk, TCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6939) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6941) if (len < sizeof(u32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6942) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6944) len = sizeof(u32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6946) list_for_each_entry(asoc, &(sp->ep->asocs), asocs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6947) val++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6948) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6950) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6951) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6952) if (copy_to_user(optval, &val, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6953) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6955) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6958) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6959) * 8.1.23 SCTP_AUTO_ASCONF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6960) * See the corresponding setsockopt entry as description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6961) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6962) static int sctp_getsockopt_auto_asconf(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6963) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6964) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6965) int val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6966)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6967) if (len < sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6968) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6970) len = sizeof(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6971) if (sctp_sk(sk)->do_auto_asconf && sctp_is_ep_boundall(sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6972) val = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6973) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6974) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6975) if (copy_to_user(optval, &val, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6976) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6977) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6978) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6980) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6981) * 8.2.6. Get the Current Identifiers of Associations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6982) * (SCTP_GET_ASSOC_ID_LIST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6983) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6984) * This option gets the current list of SCTP association identifiers of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6985) * the SCTP associations handled by a one-to-many style socket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6986) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6987) static int sctp_getsockopt_assoc_ids(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6988) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6989) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6990) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6991) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6992) struct sctp_assoc_ids *ids;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6993) u32 num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6995) if (sctp_style(sk, TCP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6996) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6998) if (len < sizeof(struct sctp_assoc_ids))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6999) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7001) list_for_each_entry(asoc, &(sp->ep->asocs), asocs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7002) num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7003) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7005) if (len < sizeof(struct sctp_assoc_ids) + sizeof(sctp_assoc_t) * num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7006) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7008) len = sizeof(struct sctp_assoc_ids) + sizeof(sctp_assoc_t) * num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7010) ids = kmalloc(len, GFP_USER | __GFP_NOWARN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7011) if (unlikely(!ids))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7012) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7014) ids->gaids_number_of_ids = num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7015) num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7016) list_for_each_entry(asoc, &(sp->ep->asocs), asocs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7017) ids->gaids_assoc_id[num++] = asoc->assoc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7018) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7020) if (put_user(len, optlen) || copy_to_user(optval, ids, len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7021) kfree(ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7022) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7023) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7025) kfree(ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7026) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7027) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7029) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7030) * SCTP_PEER_ADDR_THLDS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7031) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7032) * This option allows us to fetch the partially failed threshold for one or all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7033) * transports in an association. See Section 6.1 of:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7034) * http://www.ietf.org/id/draft-nishida-tsvwg-sctp-failover-05.txt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7035) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7036) static int sctp_getsockopt_paddr_thresholds(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7037) char __user *optval, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7038) int __user *optlen, bool v2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7039) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7040) struct sctp_paddrthlds_v2 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7041) struct sctp_transport *trans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7042) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7043) int min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7045) min = v2 ? sizeof(val) : sizeof(struct sctp_paddrthlds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7046) if (len < min)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7047) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7048) len = min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7049) if (copy_from_user(&val, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7050) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7052) if (!sctp_is_any(sk, (const union sctp_addr *)&val.spt_address)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7053) trans = sctp_addr_id2transport(sk, &val.spt_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7054) val.spt_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7055) if (!trans)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7056) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7058) val.spt_pathmaxrxt = trans->pathmaxrxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7059) val.spt_pathpfthld = trans->pf_retrans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7060) val.spt_pathcpthld = trans->ps_retrans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7061)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7062) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7063) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7064)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7065) asoc = sctp_id2assoc(sk, val.spt_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7066) if (!asoc && val.spt_assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7067) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7068) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7069)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7070) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7071) val.spt_pathpfthld = asoc->pf_retrans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7072) val.spt_pathmaxrxt = asoc->pathmaxrxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7073) val.spt_pathcpthld = asoc->ps_retrans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7074) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7075) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7076)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7077) val.spt_pathpfthld = sp->pf_retrans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7078) val.spt_pathmaxrxt = sp->pathmaxrxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7079) val.spt_pathcpthld = sp->ps_retrans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7080) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7082) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7083) if (put_user(len, optlen) || copy_to_user(optval, &val, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7084) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7086) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7089) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7090) * SCTP_GET_ASSOC_STATS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7091) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7092) * This option retrieves local per endpoint statistics. It is modeled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7093) * after OpenSolaris' implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7094) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7095) static int sctp_getsockopt_assoc_stats(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7096) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7097) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7098) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7099) struct sctp_assoc_stats sas;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7100) struct sctp_association *asoc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7102) /* User must provide at least the assoc id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7103) if (len < sizeof(sctp_assoc_t))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7104) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7106) /* Allow the struct to grow and fill in as much as possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7107) len = min_t(size_t, len, sizeof(sas));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7109) if (copy_from_user(&sas, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7110) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7112) asoc = sctp_id2assoc(sk, sas.sas_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7113) if (!asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7114) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7116) sas.sas_rtxchunks = asoc->stats.rtxchunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7117) sas.sas_gapcnt = asoc->stats.gapcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7118) sas.sas_outofseqtsns = asoc->stats.outofseqtsns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7119) sas.sas_osacks = asoc->stats.osacks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7120) sas.sas_isacks = asoc->stats.isacks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7121) sas.sas_octrlchunks = asoc->stats.octrlchunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7122) sas.sas_ictrlchunks = asoc->stats.ictrlchunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7123) sas.sas_oodchunks = asoc->stats.oodchunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7124) sas.sas_iodchunks = asoc->stats.iodchunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7125) sas.sas_ouodchunks = asoc->stats.ouodchunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7126) sas.sas_iuodchunks = asoc->stats.iuodchunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7127) sas.sas_idupchunks = asoc->stats.idupchunks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7128) sas.sas_opackets = asoc->stats.opackets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7129) sas.sas_ipackets = asoc->stats.ipackets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7131) /* New high max rto observed, will return 0 if not a single
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7132) * RTO update took place. obs_rto_ipaddr will be bogus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7133) * in such a case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7134) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7135) sas.sas_maxrto = asoc->stats.max_obs_rto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7136) memcpy(&sas.sas_obs_rto_ipaddr, &asoc->stats.obs_rto_ipaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7137) sizeof(struct sockaddr_storage));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7139) /* Mark beginning of a new observation period */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7140) asoc->stats.max_obs_rto = asoc->rto_min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7142) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7143) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7145) pr_debug("%s: len:%d, assoc_id:%d\n", __func__, len, sas.sas_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7147) if (copy_to_user(optval, &sas, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7148) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7150) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7153) static int sctp_getsockopt_recvrcvinfo(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7154) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7155) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7157) int val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7159) if (len < sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7160) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7162) len = sizeof(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7163) if (sctp_sk(sk)->recvrcvinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7164) val = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7165) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7166) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7167) if (copy_to_user(optval, &val, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7168) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7170) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7173) static int sctp_getsockopt_recvnxtinfo(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7174) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7175) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7177) int val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7179) if (len < sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7180) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7182) len = sizeof(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7183) if (sctp_sk(sk)->recvnxtinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7184) val = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7185) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7186) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7187) if (copy_to_user(optval, &val, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7188) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7190) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7193) static int sctp_getsockopt_pr_supported(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7194) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7195) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7197) struct sctp_assoc_value params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7198) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7199) int retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7201) if (len < sizeof(params)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7202) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7203) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7206) len = sizeof(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7207) if (copy_from_user(¶ms, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7208) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7210) asoc = sctp_id2assoc(sk, params.assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7211) if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7212) sctp_style(sk, UDP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7213) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7214) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7217) params.assoc_value = asoc ? asoc->peer.prsctp_capable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7218) : sctp_sk(sk)->ep->prsctp_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7220) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7221) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7223) if (copy_to_user(optval, ¶ms, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7224) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7226) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7228) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7229) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7232) static int sctp_getsockopt_default_prinfo(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7233) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7234) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7236) struct sctp_default_prinfo info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7237) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7238) int retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7240) if (len < sizeof(info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7241) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7242) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7245) len = sizeof(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7246) if (copy_from_user(&info, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7247) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7249) asoc = sctp_id2assoc(sk, info.pr_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7250) if (!asoc && info.pr_assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7251) sctp_style(sk, UDP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7252) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7253) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7256) if (asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7257) info.pr_policy = SCTP_PR_POLICY(asoc->default_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7258) info.pr_value = asoc->default_timetolive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7259) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7260) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7262) info.pr_policy = SCTP_PR_POLICY(sp->default_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7263) info.pr_value = sp->default_timetolive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7266) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7267) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7269) if (copy_to_user(optval, &info, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7270) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7272) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7274) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7275) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7278) static int sctp_getsockopt_pr_assocstatus(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7279) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7280) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7282) struct sctp_prstatus params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7283) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7284) int policy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7285) int retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7287) if (len < sizeof(params))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7288) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7290) len = sizeof(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7291) if (copy_from_user(¶ms, optval, len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7292) retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7293) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7296) policy = params.sprstat_policy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7297) if (!policy || (policy & ~(SCTP_PR_SCTP_MASK | SCTP_PR_SCTP_ALL)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7298) ((policy & SCTP_PR_SCTP_ALL) && (policy & SCTP_PR_SCTP_MASK)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7299) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7301) asoc = sctp_id2assoc(sk, params.sprstat_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7302) if (!asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7303) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7305) if (policy == SCTP_PR_SCTP_ALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7306) params.sprstat_abandoned_unsent = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7307) params.sprstat_abandoned_sent = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7308) for (policy = 0; policy <= SCTP_PR_INDEX(MAX); policy++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7309) params.sprstat_abandoned_unsent +=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7310) asoc->abandoned_unsent[policy];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7311) params.sprstat_abandoned_sent +=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7312) asoc->abandoned_sent[policy];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7314) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7315) params.sprstat_abandoned_unsent =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7316) asoc->abandoned_unsent[__SCTP_PR_INDEX(policy)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7317) params.sprstat_abandoned_sent =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7318) asoc->abandoned_sent[__SCTP_PR_INDEX(policy)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7321) if (put_user(len, optlen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7322) retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7323) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7326) if (copy_to_user(optval, ¶ms, len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7327) retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7328) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7331) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7333) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7334) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7337) static int sctp_getsockopt_pr_streamstatus(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7338) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7339) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7341) struct sctp_stream_out_ext *streamoute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7342) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7343) struct sctp_prstatus params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7344) int retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7345) int policy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7347) if (len < sizeof(params))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7348) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7350) len = sizeof(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7351) if (copy_from_user(¶ms, optval, len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7352) retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7353) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7356) policy = params.sprstat_policy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7357) if (!policy || (policy & ~(SCTP_PR_SCTP_MASK | SCTP_PR_SCTP_ALL)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7358) ((policy & SCTP_PR_SCTP_ALL) && (policy & SCTP_PR_SCTP_MASK)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7359) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7361) asoc = sctp_id2assoc(sk, params.sprstat_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7362) if (!asoc || params.sprstat_sid >= asoc->stream.outcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7363) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7365) streamoute = SCTP_SO(&asoc->stream, params.sprstat_sid)->ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7366) if (!streamoute) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7367) /* Not allocated yet, means all stats are 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7368) params.sprstat_abandoned_unsent = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7369) params.sprstat_abandoned_sent = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7370) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7371) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7374) if (policy == SCTP_PR_SCTP_ALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7375) params.sprstat_abandoned_unsent = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7376) params.sprstat_abandoned_sent = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7377) for (policy = 0; policy <= SCTP_PR_INDEX(MAX); policy++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7378) params.sprstat_abandoned_unsent +=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7379) streamoute->abandoned_unsent[policy];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7380) params.sprstat_abandoned_sent +=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7381) streamoute->abandoned_sent[policy];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7383) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7384) params.sprstat_abandoned_unsent =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7385) streamoute->abandoned_unsent[__SCTP_PR_INDEX(policy)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7386) params.sprstat_abandoned_sent =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7387) streamoute->abandoned_sent[__SCTP_PR_INDEX(policy)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7390) if (put_user(len, optlen) || copy_to_user(optval, ¶ms, len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7391) retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7392) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7395) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7397) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7398) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7401) static int sctp_getsockopt_reconfig_supported(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7402) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7403) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7405) struct sctp_assoc_value params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7406) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7407) int retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7409) if (len < sizeof(params)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7410) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7411) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7414) len = sizeof(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7415) if (copy_from_user(¶ms, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7416) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7418) asoc = sctp_id2assoc(sk, params.assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7419) if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7420) sctp_style(sk, UDP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7421) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7422) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7425) params.assoc_value = asoc ? asoc->peer.reconf_capable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7426) : sctp_sk(sk)->ep->reconf_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7428) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7429) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7431) if (copy_to_user(optval, ¶ms, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7432) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7434) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7436) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7437) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7440) static int sctp_getsockopt_enable_strreset(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7441) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7442) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7444) struct sctp_assoc_value params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7445) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7446) int retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7448) if (len < sizeof(params)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7449) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7450) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7453) len = sizeof(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7454) if (copy_from_user(¶ms, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7455) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7457) asoc = sctp_id2assoc(sk, params.assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7458) if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7459) sctp_style(sk, UDP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7460) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7461) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7464) params.assoc_value = asoc ? asoc->strreset_enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7465) : sctp_sk(sk)->ep->strreset_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7467) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7468) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7470) if (copy_to_user(optval, ¶ms, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7471) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7473) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7475) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7476) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7479) static int sctp_getsockopt_scheduler(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7480) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7481) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7482) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7483) struct sctp_assoc_value params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7484) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7485) int retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7487) if (len < sizeof(params)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7488) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7489) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7492) len = sizeof(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7493) if (copy_from_user(¶ms, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7494) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7496) asoc = sctp_id2assoc(sk, params.assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7497) if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7498) sctp_style(sk, UDP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7499) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7500) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7503) params.assoc_value = asoc ? sctp_sched_get_sched(asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7504) : sctp_sk(sk)->default_ss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7506) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7507) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7509) if (copy_to_user(optval, ¶ms, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7510) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7512) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7514) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7515) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7518) static int sctp_getsockopt_scheduler_value(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7519) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7520) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7521) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7522) struct sctp_stream_value params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7523) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7524) int retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7526) if (len < sizeof(params)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7527) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7528) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7531) len = sizeof(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7532) if (copy_from_user(¶ms, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7533) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7535) asoc = sctp_id2assoc(sk, params.assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7536) if (!asoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7537) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7538) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7541) retval = sctp_sched_get_value(asoc, params.stream_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7542) ¶ms.stream_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7543) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7544) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7546) if (put_user(len, optlen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7547) retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7548) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7551) if (copy_to_user(optval, ¶ms, len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7552) retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7553) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7556) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7557) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7560) static int sctp_getsockopt_interleaving_supported(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7561) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7562) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7563) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7564) struct sctp_assoc_value params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7565) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7566) int retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7568) if (len < sizeof(params)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7569) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7570) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7573) len = sizeof(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7574) if (copy_from_user(¶ms, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7575) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7577) asoc = sctp_id2assoc(sk, params.assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7578) if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7579) sctp_style(sk, UDP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7580) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7581) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7584) params.assoc_value = asoc ? asoc->peer.intl_capable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7585) : sctp_sk(sk)->ep->intl_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7587) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7588) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7590) if (copy_to_user(optval, ¶ms, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7591) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7593) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7595) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7596) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7599) static int sctp_getsockopt_reuse_port(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7600) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7601) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7603) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7605) if (len < sizeof(int))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7606) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7608) len = sizeof(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7609) val = sctp_sk(sk)->reuse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7610) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7611) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7613) if (copy_to_user(optval, &val, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7614) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7616) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7619) static int sctp_getsockopt_event(struct sock *sk, int len, char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7620) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7621) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7622) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7623) struct sctp_event param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7624) __u16 subscribe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7626) if (len < sizeof(param))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7627) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7629) len = sizeof(param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7630) if (copy_from_user(¶m, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7631) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7633) if (param.se_type < SCTP_SN_TYPE_BASE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7634) param.se_type > SCTP_SN_TYPE_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7635) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7637) asoc = sctp_id2assoc(sk, param.se_assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7638) if (!asoc && param.se_assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7639) sctp_style(sk, UDP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7640) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7642) subscribe = asoc ? asoc->subscribe : sctp_sk(sk)->subscribe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7643) param.se_on = sctp_ulpevent_type_enabled(subscribe, param.se_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7645) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7646) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7648) if (copy_to_user(optval, ¶m, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7649) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7651) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7654) static int sctp_getsockopt_asconf_supported(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7655) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7656) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7657) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7658) struct sctp_assoc_value params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7659) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7660) int retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7662) if (len < sizeof(params)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7663) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7664) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7667) len = sizeof(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7668) if (copy_from_user(¶ms, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7669) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7671) asoc = sctp_id2assoc(sk, params.assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7672) if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7673) sctp_style(sk, UDP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7674) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7675) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7676) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7678) params.assoc_value = asoc ? asoc->peer.asconf_capable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7679) : sctp_sk(sk)->ep->asconf_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7681) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7682) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7684) if (copy_to_user(optval, ¶ms, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7685) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7687) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7689) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7690) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7693) static int sctp_getsockopt_auth_supported(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7694) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7695) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7696) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7697) struct sctp_assoc_value params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7698) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7699) int retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7701) if (len < sizeof(params)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7702) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7703) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7706) len = sizeof(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7707) if (copy_from_user(¶ms, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7708) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7710) asoc = sctp_id2assoc(sk, params.assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7711) if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7712) sctp_style(sk, UDP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7713) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7714) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7717) params.assoc_value = asoc ? asoc->peer.auth_capable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7718) : sctp_sk(sk)->ep->auth_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7720) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7721) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7723) if (copy_to_user(optval, ¶ms, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7724) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7726) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7728) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7729) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7732) static int sctp_getsockopt_ecn_supported(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7733) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7734) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7735) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7736) struct sctp_assoc_value params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7737) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7738) int retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7740) if (len < sizeof(params)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7741) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7742) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7743) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7745) len = sizeof(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7746) if (copy_from_user(¶ms, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7747) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7749) asoc = sctp_id2assoc(sk, params.assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7750) if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7751) sctp_style(sk, UDP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7752) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7753) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7754) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7756) params.assoc_value = asoc ? asoc->peer.ecn_capable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7757) : sctp_sk(sk)->ep->ecn_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7759) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7760) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7762) if (copy_to_user(optval, ¶ms, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7763) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7765) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7767) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7768) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7771) static int sctp_getsockopt_pf_expose(struct sock *sk, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7772) char __user *optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7773) int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7774) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7775) struct sctp_assoc_value params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7776) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7777) int retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7779) if (len < sizeof(params)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7780) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7781) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7784) len = sizeof(params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7785) if (copy_from_user(¶ms, optval, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7786) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7788) asoc = sctp_id2assoc(sk, params.assoc_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7789) if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7790) sctp_style(sk, UDP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7791) retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7792) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7795) params.assoc_value = asoc ? asoc->pf_expose
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7796) : sctp_sk(sk)->pf_expose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7798) if (put_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7799) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7801) if (copy_to_user(optval, ¶ms, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7802) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7804) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7806) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7807) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7808) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7810) static int sctp_getsockopt(struct sock *sk, int level, int optname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7811) char __user *optval, int __user *optlen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7812) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7813) int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7814) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7816) pr_debug("%s: sk:%p, optname:%d\n", __func__, sk, optname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7818) /* I can hardly begin to describe how wrong this is. This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7819) * so broken as to be worse than useless. The API draft
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7820) * REALLY is NOT helpful here... I am not convinced that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7821) * semantics of getsockopt() with a level OTHER THAN SOL_SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7822) * are at all well-founded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7823) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7824) if (level != SOL_SCTP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7825) struct sctp_af *af = sctp_sk(sk)->pf->af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7827) retval = af->getsockopt(sk, level, optname, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7828) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7831) if (get_user(len, optlen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7832) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7834) if (len < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7835) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7837) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7839) switch (optname) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7840) case SCTP_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7841) retval = sctp_getsockopt_sctp_status(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7842) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7843) case SCTP_DISABLE_FRAGMENTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7844) retval = sctp_getsockopt_disable_fragments(sk, len, optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7845) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7846) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7847) case SCTP_EVENTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7848) retval = sctp_getsockopt_events(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7849) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7850) case SCTP_AUTOCLOSE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7851) retval = sctp_getsockopt_autoclose(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7852) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7853) case SCTP_SOCKOPT_PEELOFF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7854) retval = sctp_getsockopt_peeloff(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7855) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7856) case SCTP_SOCKOPT_PEELOFF_FLAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7857) retval = sctp_getsockopt_peeloff_flags(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7858) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7859) case SCTP_PEER_ADDR_PARAMS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7860) retval = sctp_getsockopt_peer_addr_params(sk, len, optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7861) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7862) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7863) case SCTP_DELAYED_SACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7864) retval = sctp_getsockopt_delayed_ack(sk, len, optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7865) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7866) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7867) case SCTP_INITMSG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7868) retval = sctp_getsockopt_initmsg(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7869) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7870) case SCTP_GET_PEER_ADDRS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7871) retval = sctp_getsockopt_peer_addrs(sk, len, optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7872) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7873) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7874) case SCTP_GET_LOCAL_ADDRS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7875) retval = sctp_getsockopt_local_addrs(sk, len, optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7876) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7877) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7878) case SCTP_SOCKOPT_CONNECTX3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7879) retval = sctp_getsockopt_connectx3(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7880) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7881) case SCTP_DEFAULT_SEND_PARAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7882) retval = sctp_getsockopt_default_send_param(sk, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7883) optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7884) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7885) case SCTP_DEFAULT_SNDINFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7886) retval = sctp_getsockopt_default_sndinfo(sk, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7887) optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7888) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7889) case SCTP_PRIMARY_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7890) retval = sctp_getsockopt_primary_addr(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7891) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7892) case SCTP_NODELAY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7893) retval = sctp_getsockopt_nodelay(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7894) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7895) case SCTP_RTOINFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7896) retval = sctp_getsockopt_rtoinfo(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7897) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7898) case SCTP_ASSOCINFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7899) retval = sctp_getsockopt_associnfo(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7900) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7901) case SCTP_I_WANT_MAPPED_V4_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7902) retval = sctp_getsockopt_mappedv4(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7903) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7904) case SCTP_MAXSEG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7905) retval = sctp_getsockopt_maxseg(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7906) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7907) case SCTP_GET_PEER_ADDR_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7908) retval = sctp_getsockopt_peer_addr_info(sk, len, optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7909) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7910) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7911) case SCTP_ADAPTATION_LAYER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7912) retval = sctp_getsockopt_adaptation_layer(sk, len, optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7913) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7914) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7915) case SCTP_CONTEXT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7916) retval = sctp_getsockopt_context(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7917) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7918) case SCTP_FRAGMENT_INTERLEAVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7919) retval = sctp_getsockopt_fragment_interleave(sk, len, optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7920) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7921) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7922) case SCTP_PARTIAL_DELIVERY_POINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7923) retval = sctp_getsockopt_partial_delivery_point(sk, len, optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7924) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7925) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7926) case SCTP_MAX_BURST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7927) retval = sctp_getsockopt_maxburst(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7928) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7929) case SCTP_AUTH_KEY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7930) case SCTP_AUTH_CHUNK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7931) case SCTP_AUTH_DELETE_KEY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7932) case SCTP_AUTH_DEACTIVATE_KEY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7933) retval = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7934) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7935) case SCTP_HMAC_IDENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7936) retval = sctp_getsockopt_hmac_ident(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7937) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7938) case SCTP_AUTH_ACTIVE_KEY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7939) retval = sctp_getsockopt_active_key(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7940) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7941) case SCTP_PEER_AUTH_CHUNKS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7942) retval = sctp_getsockopt_peer_auth_chunks(sk, len, optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7943) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7944) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7945) case SCTP_LOCAL_AUTH_CHUNKS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7946) retval = sctp_getsockopt_local_auth_chunks(sk, len, optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7947) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7948) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7949) case SCTP_GET_ASSOC_NUMBER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7950) retval = sctp_getsockopt_assoc_number(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7951) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7952) case SCTP_GET_ASSOC_ID_LIST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7953) retval = sctp_getsockopt_assoc_ids(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7954) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7955) case SCTP_AUTO_ASCONF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7956) retval = sctp_getsockopt_auto_asconf(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7957) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7958) case SCTP_PEER_ADDR_THLDS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7959) retval = sctp_getsockopt_paddr_thresholds(sk, optval, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7960) optlen, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7961) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7962) case SCTP_PEER_ADDR_THLDS_V2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7963) retval = sctp_getsockopt_paddr_thresholds(sk, optval, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7964) optlen, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7965) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7966) case SCTP_GET_ASSOC_STATS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7967) retval = sctp_getsockopt_assoc_stats(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7968) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7969) case SCTP_RECVRCVINFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7970) retval = sctp_getsockopt_recvrcvinfo(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7971) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7972) case SCTP_RECVNXTINFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7973) retval = sctp_getsockopt_recvnxtinfo(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7974) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7975) case SCTP_PR_SUPPORTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7976) retval = sctp_getsockopt_pr_supported(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7977) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7978) case SCTP_DEFAULT_PRINFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7979) retval = sctp_getsockopt_default_prinfo(sk, len, optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7980) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7981) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7982) case SCTP_PR_ASSOC_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7983) retval = sctp_getsockopt_pr_assocstatus(sk, len, optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7984) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7985) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7986) case SCTP_PR_STREAM_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7987) retval = sctp_getsockopt_pr_streamstatus(sk, len, optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7988) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7989) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7990) case SCTP_RECONFIG_SUPPORTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7991) retval = sctp_getsockopt_reconfig_supported(sk, len, optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7992) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7993) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7994) case SCTP_ENABLE_STREAM_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7995) retval = sctp_getsockopt_enable_strreset(sk, len, optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7996) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7997) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7998) case SCTP_STREAM_SCHEDULER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7999) retval = sctp_getsockopt_scheduler(sk, len, optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8000) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8001) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8002) case SCTP_STREAM_SCHEDULER_VALUE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8003) retval = sctp_getsockopt_scheduler_value(sk, len, optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8004) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8005) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8006) case SCTP_INTERLEAVING_SUPPORTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8007) retval = sctp_getsockopt_interleaving_supported(sk, len, optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8008) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8009) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8010) case SCTP_REUSE_PORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8011) retval = sctp_getsockopt_reuse_port(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8012) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8013) case SCTP_EVENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8014) retval = sctp_getsockopt_event(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8015) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8016) case SCTP_ASCONF_SUPPORTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8017) retval = sctp_getsockopt_asconf_supported(sk, len, optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8018) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8019) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8020) case SCTP_AUTH_SUPPORTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8021) retval = sctp_getsockopt_auth_supported(sk, len, optval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8022) optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8023) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8024) case SCTP_ECN_SUPPORTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8025) retval = sctp_getsockopt_ecn_supported(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8026) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8027) case SCTP_EXPOSE_POTENTIALLY_FAILED_STATE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8028) retval = sctp_getsockopt_pf_expose(sk, len, optval, optlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8029) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8030) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8031) retval = -ENOPROTOOPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8032) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8033) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8034)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8035) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8036) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8037) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8039) static int sctp_hash(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8040) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8041) /* STUB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8042) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8043) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8045) static void sctp_unhash(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8046) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8047) /* STUB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8048) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8050) /* Check if port is acceptable. Possibly find first available port.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8051) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8052) * The port hash table (contained in the 'global' SCTP protocol storage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8053) * returned by struct sctp_protocol *sctp_get_protocol()). The hash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8054) * table is an array of 4096 lists (sctp_bind_hashbucket). Each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8055) * list (the list number is the port number hashed out, so as you
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8056) * would expect from a hash function, all the ports in a given list have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8057) * such a number that hashes out to the same list number; you were
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8058) * expecting that, right?); so each list has a set of ports, with a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8059) * link to the socket (struct sock) that uses it, the port number and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8060) * a fastreuse flag (FIXME: NPI ipg).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8061) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8062) static struct sctp_bind_bucket *sctp_bucket_create(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8063) struct sctp_bind_hashbucket *head, struct net *, unsigned short snum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8064)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8065) static int sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8066) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8067) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8068) bool reuse = (sk->sk_reuse || sp->reuse);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8069) struct sctp_bind_hashbucket *head; /* hash list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8070) struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8071) kuid_t uid = sock_i_uid(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8072) struct sctp_bind_bucket *pp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8073) unsigned short snum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8074) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8076) snum = ntohs(addr->v4.sin_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8078) pr_debug("%s: begins, snum:%d\n", __func__, snum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8080) if (snum == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8081) /* Search for an available port. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8082) int low, high, remaining, index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8083) unsigned int rover;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8085) inet_get_local_port_range(net, &low, &high);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8086) remaining = (high - low) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8087) rover = prandom_u32() % remaining + low;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8089) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8090) rover++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8091) if ((rover < low) || (rover > high))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8092) rover = low;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8093) if (inet_is_local_reserved_port(net, rover))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8094) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8095) index = sctp_phashfn(net, rover);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8096) head = &sctp_port_hashtable[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8097) spin_lock_bh(&head->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8098) sctp_for_each_hentry(pp, &head->chain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8099) if ((pp->port == rover) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8100) net_eq(net, pp->net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8101) goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8102) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8103) next:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8104) spin_unlock_bh(&head->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8105) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8106) } while (--remaining > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8108) /* Exhausted local port range during search? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8109) ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8110) if (remaining <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8111) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8113) /* OK, here is the one we will use. HEAD (the port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8114) * hash table list entry) is non-NULL and we hold it's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8115) * mutex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8116) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8117) snum = rover;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8118) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8119) /* We are given an specific port number; we verify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8120) * that it is not being used. If it is used, we will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8121) * exahust the search in the hash list corresponding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8122) * to the port number (snum) - we detect that with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8123) * port iterator, pp being NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8124) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8125) head = &sctp_port_hashtable[sctp_phashfn(net, snum)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8126) spin_lock_bh(&head->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8127) sctp_for_each_hentry(pp, &head->chain) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8128) if ((pp->port == snum) && net_eq(pp->net, net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8129) goto pp_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8132) pp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8133) goto pp_not_found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8134) pp_found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8135) if (!hlist_empty(&pp->owner)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8136) /* We had a port hash table hit - there is an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8137) * available port (pp != NULL) and it is being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8138) * used by other socket (pp->owner not empty); that other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8139) * socket is going to be sk2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8140) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8141) struct sock *sk2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8143) pr_debug("%s: found a possible match\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8145) if ((pp->fastreuse && reuse &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8146) sk->sk_state != SCTP_SS_LISTENING) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8147) (pp->fastreuseport && sk->sk_reuseport &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8148) uid_eq(pp->fastuid, uid)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8149) goto success;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8151) /* Run through the list of sockets bound to the port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8152) * (pp->port) [via the pointers bind_next and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8153) * bind_pprev in the struct sock *sk2 (pp->sk)]. On each one,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8154) * we get the endpoint they describe and run through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8155) * the endpoint's list of IP (v4 or v6) addresses,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8156) * comparing each of the addresses with the address of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8157) * the socket sk. If we find a match, then that means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8158) * that this port/socket (sk) combination are already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8159) * in an endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8160) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8161) sk_for_each_bound(sk2, &pp->owner) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8162) struct sctp_sock *sp2 = sctp_sk(sk2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8163) struct sctp_endpoint *ep2 = sp2->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8165) if (sk == sk2 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8166) (reuse && (sk2->sk_reuse || sp2->reuse) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8167) sk2->sk_state != SCTP_SS_LISTENING) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8168) (sk->sk_reuseport && sk2->sk_reuseport &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8169) uid_eq(uid, sock_i_uid(sk2))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8170) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8172) if (sctp_bind_addr_conflict(&ep2->base.bind_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8173) addr, sp2, sp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8174) ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8175) goto fail_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8179) pr_debug("%s: found a match\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8181) pp_not_found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8182) /* If there was a hash table miss, create a new port. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8183) ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8184) if (!pp && !(pp = sctp_bucket_create(head, net, snum)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8185) goto fail_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8187) /* In either case (hit or miss), make sure fastreuse is 1 only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8188) * if sk->sk_reuse is too (that is, if the caller requested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8189) * SO_REUSEADDR on this socket -sk-).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8190) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8191) if (hlist_empty(&pp->owner)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8192) if (reuse && sk->sk_state != SCTP_SS_LISTENING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8193) pp->fastreuse = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8194) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8195) pp->fastreuse = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8197) if (sk->sk_reuseport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8198) pp->fastreuseport = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8199) pp->fastuid = uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8200) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8201) pp->fastreuseport = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8203) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8204) if (pp->fastreuse &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8205) (!reuse || sk->sk_state == SCTP_SS_LISTENING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8206) pp->fastreuse = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8208) if (pp->fastreuseport &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8209) (!sk->sk_reuseport || !uid_eq(pp->fastuid, uid)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8210) pp->fastreuseport = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8213) /* We are set, so fill up all the data in the hash table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8214) * entry, tie the socket list information with the rest of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8215) * sockets FIXME: Blurry, NPI (ipg).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8216) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8217) success:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8218) if (!sp->bind_hash) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8219) inet_sk(sk)->inet_num = snum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8220) sk_add_bind_node(sk, &pp->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8221) sp->bind_hash = pp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8223) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8225) fail_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8226) spin_unlock_bh(&head->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8227) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8230) /* Assign a 'snum' port to the socket. If snum == 0, an ephemeral
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8231) * port is requested.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8232) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8233) static int sctp_get_port(struct sock *sk, unsigned short snum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8235) union sctp_addr addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8236) struct sctp_af *af = sctp_sk(sk)->pf->af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8238) /* Set up a dummy address struct from the sk. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8239) af->from_sk(&addr, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8240) addr.v4.sin_port = htons(snum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8242) /* Note: sk->sk_num gets filled in if ephemeral port request. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8243) return sctp_get_port_local(sk, &addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8246) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8247) * Move a socket to LISTENING state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8248) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8249) static int sctp_listen_start(struct sock *sk, int backlog)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8251) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8252) struct sctp_endpoint *ep = sp->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8253) struct crypto_shash *tfm = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8254) char alg[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8256) /* Allocate HMAC for generating cookie. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8257) if (!sp->hmac && sp->sctp_hmac_alg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8258) sprintf(alg, "hmac(%s)", sp->sctp_hmac_alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8259) tfm = crypto_alloc_shash(alg, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8260) if (IS_ERR(tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8261) net_info_ratelimited("failed to load transform for %s: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8262) sp->sctp_hmac_alg, PTR_ERR(tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8263) return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8265) sctp_sk(sk)->hmac = tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8268) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8269) * If a bind() or sctp_bindx() is not called prior to a listen()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8270) * call that allows new associations to be accepted, the system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8271) * picks an ephemeral port and will choose an address set equivalent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8272) * to binding with a wildcard address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8273) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8274) * This is not currently spelled out in the SCTP sockets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8275) * extensions draft, but follows the practice as seen in TCP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8276) * sockets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8277) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8278) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8279) inet_sk_set_state(sk, SCTP_SS_LISTENING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8280) if (!ep->base.bind_addr.port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8281) if (sctp_autobind(sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8282) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8283) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8284) if (sctp_get_port(sk, inet_sk(sk)->inet_num)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8285) inet_sk_set_state(sk, SCTP_SS_CLOSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8286) return -EADDRINUSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8290) WRITE_ONCE(sk->sk_max_ack_backlog, backlog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8291) return sctp_hash_endpoint(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8294) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8295) * 4.1.3 / 5.1.3 listen()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8296) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8297) * By default, new associations are not accepted for UDP style sockets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8298) * An application uses listen() to mark a socket as being able to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8299) * accept new associations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8300) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8301) * On TCP style sockets, applications use listen() to ready the SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8302) * endpoint for accepting inbound associations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8303) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8304) * On both types of endpoints a backlog of '0' disables listening.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8305) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8306) * Move a socket to LISTENING state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8307) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8308) int sctp_inet_listen(struct socket *sock, int backlog)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8310) struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8311) struct sctp_endpoint *ep = sctp_sk(sk)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8312) int err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8314) if (unlikely(backlog < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8315) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8317) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8319) /* Peeled-off sockets are not allowed to listen(). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8320) if (sctp_style(sk, UDP_HIGH_BANDWIDTH))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8321) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8323) if (sock->state != SS_UNCONNECTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8324) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8326) if (!sctp_sstate(sk, LISTENING) && !sctp_sstate(sk, CLOSED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8327) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8329) /* If backlog is zero, disable listening. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8330) if (!backlog) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8331) if (sctp_sstate(sk, CLOSED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8332) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8334) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8335) sctp_unhash_endpoint(ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8336) sk->sk_state = SCTP_SS_CLOSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8337) if (sk->sk_reuse || sctp_sk(sk)->reuse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8338) sctp_sk(sk)->bind_hash->fastreuse = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8339) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8342) /* If we are already listening, just update the backlog */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8343) if (sctp_sstate(sk, LISTENING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8344) WRITE_ONCE(sk->sk_max_ack_backlog, backlog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8345) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8346) err = sctp_listen_start(sk, backlog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8347) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8348) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8351) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8352) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8353) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8354) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8357) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8358) * This function is done by modeling the current datagram_poll() and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8359) * tcp_poll(). Note that, based on these implementations, we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8360) * lock the socket in this function, even though it seems that,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8361) * ideally, locking or some other mechanisms can be used to ensure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8362) * the integrity of the counters (sndbuf and wmem_alloc) used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8363) * in this place. We assume that we don't need locks either until proven
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8364) * otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8365) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8366) * Another thing to note is that we include the Async I/O support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8367) * here, again, by modeling the current TCP/UDP code. We don't have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8368) * a good way to test with it yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8369) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8370) __poll_t sctp_poll(struct file *file, struct socket *sock, poll_table *wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8372) struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8373) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8374) __poll_t mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8376) poll_wait(file, sk_sleep(sk), wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8378) sock_rps_record_flow(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8380) /* A TCP-style listening socket becomes readable when the accept queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8381) * is not empty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8382) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8383) if (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8384) return (!list_empty(&sp->ep->asocs)) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8385) (EPOLLIN | EPOLLRDNORM) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8387) mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8389) /* Is there any exceptional events? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8390) if (sk->sk_err || !skb_queue_empty_lockless(&sk->sk_error_queue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8391) mask |= EPOLLERR |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8392) (sock_flag(sk, SOCK_SELECT_ERR_QUEUE) ? EPOLLPRI : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8393) if (sk->sk_shutdown & RCV_SHUTDOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8394) mask |= EPOLLRDHUP | EPOLLIN | EPOLLRDNORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8395) if (sk->sk_shutdown == SHUTDOWN_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8396) mask |= EPOLLHUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8398) /* Is it readable? Reconsider this code with TCP-style support. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8399) if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8400) mask |= EPOLLIN | EPOLLRDNORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8402) /* The association is either gone or not ready. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8403) if (!sctp_style(sk, UDP) && sctp_sstate(sk, CLOSED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8404) return mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8406) /* Is it writable? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8407) if (sctp_writeable(sk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8408) mask |= EPOLLOUT | EPOLLWRNORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8409) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8410) sk_set_bit(SOCKWQ_ASYNC_NOSPACE, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8411) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8412) * Since the socket is not locked, the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8413) * might be made available after the writeable check and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8414) * before the bit is set. This could cause a lost I/O
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8415) * signal. tcp_poll() has a race breaker for this race
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8416) * condition. Based on their implementation, we put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8417) * in the following code to cover it as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8418) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8419) if (sctp_writeable(sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8420) mask |= EPOLLOUT | EPOLLWRNORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8422) return mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8425) /********************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8426) * 2nd Level Abstractions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8427) ********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8429) static struct sctp_bind_bucket *sctp_bucket_create(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8430) struct sctp_bind_hashbucket *head, struct net *net, unsigned short snum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8432) struct sctp_bind_bucket *pp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8434) pp = kmem_cache_alloc(sctp_bucket_cachep, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8435) if (pp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8436) SCTP_DBG_OBJCNT_INC(bind_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8437) pp->port = snum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8438) pp->fastreuse = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8439) INIT_HLIST_HEAD(&pp->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8440) pp->net = net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8441) hlist_add_head(&pp->node, &head->chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8443) return pp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8446) /* Caller must hold hashbucket lock for this tb with local BH disabled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8447) static void sctp_bucket_destroy(struct sctp_bind_bucket *pp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8448) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8449) if (pp && hlist_empty(&pp->owner)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8450) __hlist_del(&pp->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8451) kmem_cache_free(sctp_bucket_cachep, pp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8452) SCTP_DBG_OBJCNT_DEC(bind_bucket);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8456) /* Release this socket's reference to a local port. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8457) static inline void __sctp_put_port(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8459) struct sctp_bind_hashbucket *head =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8460) &sctp_port_hashtable[sctp_phashfn(sock_net(sk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8461) inet_sk(sk)->inet_num)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8462) struct sctp_bind_bucket *pp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8464) spin_lock(&head->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8465) pp = sctp_sk(sk)->bind_hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8466) __sk_del_bind_node(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8467) sctp_sk(sk)->bind_hash = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8468) inet_sk(sk)->inet_num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8469) sctp_bucket_destroy(pp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8470) spin_unlock(&head->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8473) void sctp_put_port(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8475) local_bh_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8476) __sctp_put_port(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8477) local_bh_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8480) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8481) * The system picks an ephemeral port and choose an address set equivalent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8482) * to binding with a wildcard address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8483) * One of those addresses will be the primary address for the association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8484) * This automatically enables the multihoming capability of SCTP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8485) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8486) static int sctp_autobind(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8488) union sctp_addr autoaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8489) struct sctp_af *af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8490) __be16 port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8492) /* Initialize a local sockaddr structure to INADDR_ANY. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8493) af = sctp_sk(sk)->pf->af;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8495) port = htons(inet_sk(sk)->inet_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8496) af->inaddr_any(&autoaddr, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8498) return sctp_do_bind(sk, &autoaddr, af->sockaddr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8501) /* Parse out IPPROTO_SCTP CMSG headers. Perform only minimal validation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8502) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8503) * From RFC 2292
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8504) * 4.2 The cmsghdr Structure *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8505) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8506) * When ancillary data is sent or received, any number of ancillary data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8507) * objects can be specified by the msg_control and msg_controllen members of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8508) * the msghdr structure, because each object is preceded by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8509) * a cmsghdr structure defining the object's length (the cmsg_len member).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8510) * Historically Berkeley-derived implementations have passed only one object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8511) * at a time, but this API allows multiple objects to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8512) * passed in a single call to sendmsg() or recvmsg(). The following example
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8513) * shows two ancillary data objects in a control buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8514) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8515) * |<--------------------------- msg_controllen -------------------------->|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8516) * | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8517) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8518) * |<----- ancillary data object ----->|<----- ancillary data object ----->|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8519) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8520) * |<---------- CMSG_SPACE() --------->|<---------- CMSG_SPACE() --------->|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8521) * | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8522) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8523) * |<---------- cmsg_len ---------->| |<--------- cmsg_len ----------->| |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8524) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8525) * |<--------- CMSG_LEN() --------->| |<-------- CMSG_LEN() ---------->| |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8526) * | | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8527) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8528) * +-----+-----+-----+--+-----------+--+-----+-----+-----+--+-----------+--+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8529) * |cmsg_|cmsg_|cmsg_|XX| |XX|cmsg_|cmsg_|cmsg_|XX| |XX|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8530) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8531) * |len |level|type |XX|cmsg_data[]|XX|len |level|type |XX|cmsg_data[]|XX|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8532) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8533) * +-----+-----+-----+--+-----------+--+-----+-----+-----+--+-----------+--+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8534) * ^
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8535) * |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8536) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8537) * msg_control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8538) * points here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8539) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8540) static int sctp_msghdr_parse(const struct msghdr *msg, struct sctp_cmsgs *cmsgs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8541) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8542) struct msghdr *my_msg = (struct msghdr *)msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8543) struct cmsghdr *cmsg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8545) for_each_cmsghdr(cmsg, my_msg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8546) if (!CMSG_OK(my_msg, cmsg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8547) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8549) /* Should we parse this header or ignore? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8550) if (cmsg->cmsg_level != IPPROTO_SCTP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8551) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8553) /* Strictly check lengths following example in SCM code. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8554) switch (cmsg->cmsg_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8555) case SCTP_INIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8556) /* SCTP Socket API Extension
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8557) * 5.3.1 SCTP Initiation Structure (SCTP_INIT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8558) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8559) * This cmsghdr structure provides information for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8560) * initializing new SCTP associations with sendmsg().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8561) * The SCTP_INITMSG socket option uses this same data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8562) * structure. This structure is not used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8563) * recvmsg().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8564) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8565) * cmsg_level cmsg_type cmsg_data[]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8566) * ------------ ------------ ----------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8567) * IPPROTO_SCTP SCTP_INIT struct sctp_initmsg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8568) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8569) if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct sctp_initmsg)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8570) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8572) cmsgs->init = CMSG_DATA(cmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8573) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8575) case SCTP_SNDRCV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8576) /* SCTP Socket API Extension
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8577) * 5.3.2 SCTP Header Information Structure(SCTP_SNDRCV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8578) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8579) * This cmsghdr structure specifies SCTP options for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8580) * sendmsg() and describes SCTP header information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8581) * about a received message through recvmsg().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8582) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8583) * cmsg_level cmsg_type cmsg_data[]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8584) * ------------ ------------ ----------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8585) * IPPROTO_SCTP SCTP_SNDRCV struct sctp_sndrcvinfo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8586) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8587) if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct sctp_sndrcvinfo)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8588) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8590) cmsgs->srinfo = CMSG_DATA(cmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8592) if (cmsgs->srinfo->sinfo_flags &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8593) ~(SCTP_UNORDERED | SCTP_ADDR_OVER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8594) SCTP_SACK_IMMEDIATELY | SCTP_SENDALL |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8595) SCTP_PR_SCTP_MASK | SCTP_ABORT | SCTP_EOF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8596) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8597) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8599) case SCTP_SNDINFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8600) /* SCTP Socket API Extension
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8601) * 5.3.4 SCTP Send Information Structure (SCTP_SNDINFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8602) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8603) * This cmsghdr structure specifies SCTP options for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8604) * sendmsg(). This structure and SCTP_RCVINFO replaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8605) * SCTP_SNDRCV which has been deprecated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8606) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8607) * cmsg_level cmsg_type cmsg_data[]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8608) * ------------ ------------ ---------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8609) * IPPROTO_SCTP SCTP_SNDINFO struct sctp_sndinfo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8610) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8611) if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct sctp_sndinfo)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8612) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8614) cmsgs->sinfo = CMSG_DATA(cmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8616) if (cmsgs->sinfo->snd_flags &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8617) ~(SCTP_UNORDERED | SCTP_ADDR_OVER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8618) SCTP_SACK_IMMEDIATELY | SCTP_SENDALL |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8619) SCTP_PR_SCTP_MASK | SCTP_ABORT | SCTP_EOF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8620) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8621) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8622) case SCTP_PRINFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8623) /* SCTP Socket API Extension
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8624) * 5.3.7 SCTP PR-SCTP Information Structure (SCTP_PRINFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8625) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8626) * This cmsghdr structure specifies SCTP options for sendmsg().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8627) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8628) * cmsg_level cmsg_type cmsg_data[]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8629) * ------------ ------------ ---------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8630) * IPPROTO_SCTP SCTP_PRINFO struct sctp_prinfo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8631) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8632) if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct sctp_prinfo)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8633) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8635) cmsgs->prinfo = CMSG_DATA(cmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8636) if (cmsgs->prinfo->pr_policy & ~SCTP_PR_SCTP_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8637) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8639) if (cmsgs->prinfo->pr_policy == SCTP_PR_SCTP_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8640) cmsgs->prinfo->pr_value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8641) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8642) case SCTP_AUTHINFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8643) /* SCTP Socket API Extension
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8644) * 5.3.8 SCTP AUTH Information Structure (SCTP_AUTHINFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8645) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8646) * This cmsghdr structure specifies SCTP options for sendmsg().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8647) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8648) * cmsg_level cmsg_type cmsg_data[]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8649) * ------------ ------------ ---------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8650) * IPPROTO_SCTP SCTP_AUTHINFO struct sctp_authinfo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8651) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8652) if (cmsg->cmsg_len != CMSG_LEN(sizeof(struct sctp_authinfo)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8653) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8655) cmsgs->authinfo = CMSG_DATA(cmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8656) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8657) case SCTP_DSTADDRV4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8658) case SCTP_DSTADDRV6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8659) /* SCTP Socket API Extension
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8660) * 5.3.9/10 SCTP Destination IPv4/6 Address Structure (SCTP_DSTADDRV4/6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8661) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8662) * This cmsghdr structure specifies SCTP options for sendmsg().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8663) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8664) * cmsg_level cmsg_type cmsg_data[]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8665) * ------------ ------------ ---------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8666) * IPPROTO_SCTP SCTP_DSTADDRV4 struct in_addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8667) * ------------ ------------ ---------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8668) * IPPROTO_SCTP SCTP_DSTADDRV6 struct in6_addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8669) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8670) cmsgs->addrs_msg = my_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8671) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8672) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8673) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8677) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8680) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8681) * Wait for a packet..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8682) * Note: This function is the same function as in core/datagram.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8683) * with a few modifications to make lksctp work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8684) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8685) static int sctp_wait_for_packet(struct sock *sk, int *err, long *timeo_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8686) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8687) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8688) DEFINE_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8690) prepare_to_wait_exclusive(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8692) /* Socket errors? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8693) error = sock_error(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8694) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8695) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8697) if (!skb_queue_empty(&sk->sk_receive_queue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8698) goto ready;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8700) /* Socket shut down? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8701) if (sk->sk_shutdown & RCV_SHUTDOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8702) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8704) /* Sequenced packets can come disconnected. If so we report the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8705) * problem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8706) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8707) error = -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8709) /* Is there a good reason to think that we may receive some data? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8710) if (list_empty(&sctp_sk(sk)->ep->asocs) && !sctp_sstate(sk, LISTENING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8711) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8713) /* Handle signals. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8714) if (signal_pending(current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8715) goto interrupted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8717) /* Let another process have a go. Since we are going to sleep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8718) * anyway. Note: This may cause odd behaviors if the message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8719) * does not fit in the user's buffer, but this seems to be the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8720) * only way to honor MSG_DONTWAIT realistically.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8721) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8722) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8723) *timeo_p = schedule_timeout(*timeo_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8724) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8726) ready:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8727) finish_wait(sk_sleep(sk), &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8728) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8730) interrupted:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8731) error = sock_intr_errno(*timeo_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8733) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8734) finish_wait(sk_sleep(sk), &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8735) *err = error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8736) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8737) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8739) /* Receive a datagram.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8740) * Note: This is pretty much the same routine as in core/datagram.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8741) * with a few changes to make lksctp work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8742) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8743) struct sk_buff *sctp_skb_recv_datagram(struct sock *sk, int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8744) int noblock, int *err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8745) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8746) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8747) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8748) long timeo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8750) timeo = sock_rcvtimeo(sk, noblock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8752) pr_debug("%s: timeo:%ld, max:%ld\n", __func__, timeo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8753) MAX_SCHEDULE_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8755) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8756) /* Again only user level code calls this function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8757) * so nothing interrupt level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8758) * will suddenly eat the receive_queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8759) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8760) * Look at current nfs client by the way...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8761) * However, this function was correct in any case. 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8762) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8763) if (flags & MSG_PEEK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8764) skb = skb_peek(&sk->sk_receive_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8765) if (skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8766) refcount_inc(&skb->users);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8767) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8768) skb = __skb_dequeue(&sk->sk_receive_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8771) if (skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8772) return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8774) /* Caller is allowed not to check sk->sk_err before calling. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8775) error = sock_error(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8776) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8777) goto no_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8779) if (sk->sk_shutdown & RCV_SHUTDOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8780) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8782) if (sk_can_busy_loop(sk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8783) sk_busy_loop(sk, noblock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8785) if (!skb_queue_empty_lockless(&sk->sk_receive_queue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8786) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8789) /* User doesn't want to wait. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8790) error = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8791) if (!timeo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8792) goto no_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8793) } while (sctp_wait_for_packet(sk, err, &timeo) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8795) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8797) no_packet:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8798) *err = error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8799) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8800) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8802) /* If sndbuf has changed, wake up per association sndbuf waiters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8803) static void __sctp_write_space(struct sctp_association *asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8804) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8805) struct sock *sk = asoc->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8807) if (sctp_wspace(asoc) <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8808) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8810) if (waitqueue_active(&asoc->wait))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8811) wake_up_interruptible(&asoc->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8813) if (sctp_writeable(sk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8814) struct socket_wq *wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8816) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8817) wq = rcu_dereference(sk->sk_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8818) if (wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8819) if (waitqueue_active(&wq->wait))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8820) wake_up_interruptible(&wq->wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8822) /* Note that we try to include the Async I/O support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8823) * here by modeling from the current TCP/UDP code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8824) * We have not tested with it yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8825) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8826) if (!(sk->sk_shutdown & SEND_SHUTDOWN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8827) sock_wake_async(wq, SOCK_WAKE_SPACE, POLL_OUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8829) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8830) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8833) static void sctp_wake_up_waiters(struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8834) struct sctp_association *asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8835) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8836) struct sctp_association *tmp = asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8838) /* We do accounting for the sndbuf space per association,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8839) * so we only need to wake our own association.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8840) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8841) if (asoc->ep->sndbuf_policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8842) return __sctp_write_space(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8844) /* If association goes down and is just flushing its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8845) * outq, then just normally notify others.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8846) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8847) if (asoc->base.dead)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8848) return sctp_write_space(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8850) /* Accounting for the sndbuf space is per socket, so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8851) * need to wake up others, try to be fair and in case of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8852) * other associations, let them have a go first instead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8853) * of just doing a sctp_write_space() call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8854) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8855) * Note that we reach sctp_wake_up_waiters() only when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8856) * associations free up queued chunks, thus we are under
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8857) * lock and the list of associations on a socket is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8858) * guaranteed not to change.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8859) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8860) for (tmp = list_next_entry(tmp, asocs); 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8861) tmp = list_next_entry(tmp, asocs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8862) /* Manually skip the head element. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8863) if (&tmp->asocs == &((sctp_sk(sk))->ep->asocs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8864) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8865) /* Wake up association. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8866) __sctp_write_space(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8867) /* We've reached the end. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8868) if (tmp == asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8869) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8870) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8871) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8873) /* Do accounting for the sndbuf space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8874) * Decrement the used sndbuf space of the corresponding association by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8875) * data size which was just transmitted(freed).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8876) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8877) static void sctp_wfree(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8878) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8879) struct sctp_chunk *chunk = skb_shinfo(skb)->destructor_arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8880) struct sctp_association *asoc = chunk->asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8881) struct sock *sk = asoc->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8883) sk_mem_uncharge(sk, skb->truesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8884) sk->sk_wmem_queued -= skb->truesize + sizeof(struct sctp_chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8885) asoc->sndbuf_used -= skb->truesize + sizeof(struct sctp_chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8886) WARN_ON(refcount_sub_and_test(sizeof(struct sctp_chunk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8887) &sk->sk_wmem_alloc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8889) if (chunk->shkey) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8890) struct sctp_shared_key *shkey = chunk->shkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8892) /* refcnt == 2 and !list_empty mean after this release, it's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8893) * not being used anywhere, and it's time to notify userland
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8894) * that this shkey can be freed if it's been deactivated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8895) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8896) if (shkey->deactivated && !list_empty(&shkey->key_list) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8897) refcount_read(&shkey->refcnt) == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8898) struct sctp_ulpevent *ev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8900) ev = sctp_ulpevent_make_authkey(asoc, shkey->key_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8901) SCTP_AUTH_FREE_KEY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8902) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8903) if (ev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8904) asoc->stream.si->enqueue_event(&asoc->ulpq, ev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8905) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8906) sctp_auth_shkey_release(chunk->shkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8907) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8909) sock_wfree(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8910) sctp_wake_up_waiters(sk, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8912) sctp_association_put(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8913) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8915) /* Do accounting for the receive space on the socket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8916) * Accounting for the association is done in ulpevent.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8917) * We set this as a destructor for the cloned data skbs so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8918) * accounting is done at the correct time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8919) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8920) void sctp_sock_rfree(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8921) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8922) struct sock *sk = skb->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8923) struct sctp_ulpevent *event = sctp_skb2event(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8925) atomic_sub(event->rmem_len, &sk->sk_rmem_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8927) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8928) * Mimic the behavior of sock_rfree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8929) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8930) sk_mem_uncharge(sk, event->rmem_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8931) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8934) /* Helper function to wait for space in the sndbuf. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8935) static int sctp_wait_for_sndbuf(struct sctp_association *asoc, long *timeo_p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8936) size_t msg_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8937) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8938) struct sock *sk = asoc->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8939) long current_timeo = *timeo_p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8940) DEFINE_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8941) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8943) pr_debug("%s: asoc:%p, timeo:%ld, msg_len:%zu\n", __func__, asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8944) *timeo_p, msg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8946) /* Increment the association's refcnt. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8947) sctp_association_hold(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8949) /* Wait on the association specific sndbuf space. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8950) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8951) prepare_to_wait_exclusive(&asoc->wait, &wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8952) TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8953) if (asoc->base.dead)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8954) goto do_dead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8955) if (!*timeo_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8956) goto do_nonblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8957) if (sk->sk_err || asoc->state >= SCTP_STATE_SHUTDOWN_PENDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8958) goto do_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8959) if (signal_pending(current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8960) goto do_interrupted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8961) if (sk_under_memory_pressure(sk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8962) sk_mem_reclaim(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8963) if ((int)msg_len <= sctp_wspace(asoc) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8964) sk_wmem_schedule(sk, msg_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8965) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8966)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8967) /* Let another process have a go. Since we are going
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8968) * to sleep anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8969) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8970) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8971) current_timeo = schedule_timeout(current_timeo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8972) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8973) if (sk != asoc->base.sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8974) goto do_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8976) *timeo_p = current_timeo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8977) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8978)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8979) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8980) finish_wait(&asoc->wait, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8981)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8982) /* Release the association's refcnt. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8983) sctp_association_put(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8984)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8985) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8987) do_dead:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8988) err = -ESRCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8989) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8991) do_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8992) err = -EPIPE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8993) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8995) do_interrupted:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8996) err = sock_intr_errno(*timeo_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8997) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8999) do_nonblock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9000) err = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9001) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9002) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9004) void sctp_data_ready(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9005) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9006) struct socket_wq *wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9008) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9009) wq = rcu_dereference(sk->sk_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9010) if (skwq_has_sleeper(wq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9011) wake_up_interruptible_sync_poll(&wq->wait, EPOLLIN |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9012) EPOLLRDNORM | EPOLLRDBAND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9013) sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9014) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9015) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9017) /* If socket sndbuf has changed, wake up all per association waiters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9018) void sctp_write_space(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9019) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9020) struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9022) /* Wake up the tasks in each wait queue. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9023) list_for_each_entry(asoc, &((sctp_sk(sk))->ep->asocs), asocs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9024) __sctp_write_space(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9025) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9028) /* Is there any sndbuf space available on the socket?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9029) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9030) * Note that sk_wmem_alloc is the sum of the send buffers on all of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9031) * associations on the same socket. For a UDP-style socket with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9032) * multiple associations, it is possible for it to be "unwriteable"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9033) * prematurely. I assume that this is acceptable because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9034) * a premature "unwriteable" is better than an accidental "writeable" which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9035) * would cause an unwanted block under certain circumstances. For the 1-1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9036) * UDP-style sockets or TCP-style sockets, this code should work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9037) * - Daisy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9038) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9039) static bool sctp_writeable(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9040) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9041) return sk->sk_sndbuf > sk->sk_wmem_queued;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9042) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9044) /* Wait for an association to go into ESTABLISHED state. If timeout is 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9045) * returns immediately with EINPROGRESS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9046) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9047) static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9048) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9049) struct sock *sk = asoc->base.sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9050) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9051) long current_timeo = *timeo_p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9052) DEFINE_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9054) pr_debug("%s: asoc:%p, timeo:%ld\n", __func__, asoc, *timeo_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9056) /* Increment the association's refcnt. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9057) sctp_association_hold(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9059) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9060) prepare_to_wait_exclusive(&asoc->wait, &wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9061) TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9062) if (!*timeo_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9063) goto do_nonblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9064) if (sk->sk_shutdown & RCV_SHUTDOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9065) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9066) if (sk->sk_err || asoc->state >= SCTP_STATE_SHUTDOWN_PENDING ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9067) asoc->base.dead)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9068) goto do_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9069) if (signal_pending(current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9070) goto do_interrupted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9072) if (sctp_state(asoc, ESTABLISHED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9073) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9075) /* Let another process have a go. Since we are going
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9076) * to sleep anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9077) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9078) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9079) current_timeo = schedule_timeout(current_timeo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9080) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9082) *timeo_p = current_timeo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9083) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9085) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9086) finish_wait(&asoc->wait, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9088) /* Release the association's refcnt. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9089) sctp_association_put(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9091) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9093) do_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9094) if (asoc->init_err_counter + 1 > asoc->max_init_attempts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9095) err = -ETIMEDOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9096) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9097) err = -ECONNREFUSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9098) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9099)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9100) do_interrupted:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9101) err = sock_intr_errno(*timeo_p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9102) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9104) do_nonblock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9105) err = -EINPROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9106) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9109) static int sctp_wait_for_accept(struct sock *sk, long timeo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9111) struct sctp_endpoint *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9112) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9113) DEFINE_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9115) ep = sctp_sk(sk)->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9118) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9119) prepare_to_wait_exclusive(sk_sleep(sk), &wait,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9120) TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9122) if (list_empty(&ep->asocs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9123) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9124) timeo = schedule_timeout(timeo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9125) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9128) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9129) if (!sctp_sstate(sk, LISTENING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9130) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9132) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9133) if (!list_empty(&ep->asocs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9134) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9136) err = sock_intr_errno(timeo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9137) if (signal_pending(current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9138) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9140) err = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9141) if (!timeo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9142) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9145) finish_wait(sk_sleep(sk), &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9147) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9150) static void sctp_wait_for_close(struct sock *sk, long timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9152) DEFINE_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9154) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9155) prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9156) if (list_empty(&sctp_sk(sk)->ep->asocs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9157) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9158) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9159) timeout = schedule_timeout(timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9160) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9161) } while (!signal_pending(current) && timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9163) finish_wait(sk_sleep(sk), &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9166) static void sctp_skb_set_owner_r_frag(struct sk_buff *skb, struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9168) struct sk_buff *frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9170) if (!skb->data_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9171) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9173) /* Don't forget the fragments. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9174) skb_walk_frags(skb, frag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9175) sctp_skb_set_owner_r_frag(frag, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9177) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9178) sctp_skb_set_owner_r(skb, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9181) void sctp_copy_sock(struct sock *newsk, struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9182) struct sctp_association *asoc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9184) struct inet_sock *inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9185) struct inet_sock *newinet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9186) struct sctp_sock *sp = sctp_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9187) struct sctp_endpoint *ep = sp->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9189) newsk->sk_type = sk->sk_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9190) newsk->sk_bound_dev_if = sk->sk_bound_dev_if;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9191) newsk->sk_flags = sk->sk_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9192) newsk->sk_tsflags = sk->sk_tsflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9193) newsk->sk_no_check_tx = sk->sk_no_check_tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9194) newsk->sk_no_check_rx = sk->sk_no_check_rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9195) newsk->sk_reuse = sk->sk_reuse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9196) sctp_sk(newsk)->reuse = sp->reuse;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9198) newsk->sk_shutdown = sk->sk_shutdown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9199) newsk->sk_destruct = sctp_destruct_sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9200) newsk->sk_family = sk->sk_family;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9201) newsk->sk_protocol = IPPROTO_SCTP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9202) newsk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9203) newsk->sk_sndbuf = sk->sk_sndbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9204) newsk->sk_rcvbuf = sk->sk_rcvbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9205) newsk->sk_lingertime = sk->sk_lingertime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9206) newsk->sk_rcvtimeo = sk->sk_rcvtimeo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9207) newsk->sk_sndtimeo = sk->sk_sndtimeo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9208) newsk->sk_rxhash = sk->sk_rxhash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9210) newinet = inet_sk(newsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9212) /* Initialize sk's sport, dport, rcv_saddr and daddr for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9213) * getsockname() and getpeername()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9214) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9215) newinet->inet_sport = inet->inet_sport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9216) newinet->inet_saddr = inet->inet_saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9217) newinet->inet_rcv_saddr = inet->inet_rcv_saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9218) newinet->inet_dport = htons(asoc->peer.port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9219) newinet->pmtudisc = inet->pmtudisc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9220) newinet->inet_id = prandom_u32();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9222) newinet->uc_ttl = inet->uc_ttl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9223) newinet->mc_loop = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9224) newinet->mc_ttl = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9225) newinet->mc_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9226) newinet->mc_list = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9228) if (newsk->sk_flags & SK_FLAGS_TIMESTAMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9229) net_enable_timestamp();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9231) /* Set newsk security attributes from orginal sk and connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9232) * security attribute from ep.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9233) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9234) security_sctp_sk_clone(ep, sk, newsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9237) static inline void sctp_copy_descendant(struct sock *sk_to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9238) const struct sock *sk_from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9240) size_t ancestor_size = sizeof(struct inet_sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9242) ancestor_size += sk_from->sk_prot->obj_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9243) ancestor_size -= offsetof(struct sctp_sock, pd_lobby);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9244) __inet_sk_copy_descendant(sk_to, sk_from, ancestor_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9247) /* Populate the fields of the newsk from the oldsk and migrate the assoc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9248) * and its messages to the newsk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9249) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9250) static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9251) struct sctp_association *assoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9252) enum sctp_socket_type type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9254) struct sctp_sock *oldsp = sctp_sk(oldsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9255) struct sctp_sock *newsp = sctp_sk(newsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9256) struct sctp_bind_bucket *pp; /* hash list port iterator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9257) struct sctp_endpoint *newep = newsp->ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9258) struct sk_buff *skb, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9259) struct sctp_ulpevent *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9260) struct sctp_bind_hashbucket *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9261) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9263) /* Migrate socket buffer sizes and all the socket level options to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9264) * new socket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9265) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9266) newsk->sk_sndbuf = oldsk->sk_sndbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9267) newsk->sk_rcvbuf = oldsk->sk_rcvbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9268) /* Brute force copy old sctp opt. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9269) sctp_copy_descendant(newsk, oldsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9271) /* Restore the ep value that was overwritten with the above structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9272) * copy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9273) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9274) newsp->ep = newep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9275) newsp->hmac = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9277) /* Hook this new socket in to the bind_hash list. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9278) head = &sctp_port_hashtable[sctp_phashfn(sock_net(oldsk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9279) inet_sk(oldsk)->inet_num)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9280) spin_lock_bh(&head->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9281) pp = sctp_sk(oldsk)->bind_hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9282) sk_add_bind_node(newsk, &pp->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9283) sctp_sk(newsk)->bind_hash = pp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9284) inet_sk(newsk)->inet_num = inet_sk(oldsk)->inet_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9285) spin_unlock_bh(&head->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9287) /* Copy the bind_addr list from the original endpoint to the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9288) * endpoint so that we can handle restarts properly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9289) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9290) err = sctp_bind_addr_dup(&newsp->ep->base.bind_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9291) &oldsp->ep->base.bind_addr, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9292) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9293) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9295) /* New ep's auth_hmacs should be set if old ep's is set, in case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9296) * that net->sctp.auth_enable has been changed to 0 by users and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9297) * new ep's auth_hmacs couldn't be set in sctp_endpoint_init().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9298) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9299) if (oldsp->ep->auth_hmacs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9300) err = sctp_auth_init_hmacs(newsp->ep, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9301) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9302) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9305) sctp_auto_asconf_init(newsp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9307) /* Move any messages in the old socket's receive queue that are for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9308) * peeled off association to the new socket's receive queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9309) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9310) sctp_skb_for_each(skb, &oldsk->sk_receive_queue, tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9311) event = sctp_skb2event(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9312) if (event->asoc == assoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9313) __skb_unlink(skb, &oldsk->sk_receive_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9314) __skb_queue_tail(&newsk->sk_receive_queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9315) sctp_skb_set_owner_r_frag(skb, newsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9319) /* Clean up any messages pending delivery due to partial
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9320) * delivery. Three cases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9321) * 1) No partial deliver; no work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9322) * 2) Peeling off partial delivery; keep pd_lobby in new pd_lobby.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9323) * 3) Peeling off non-partial delivery; move pd_lobby to receive_queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9324) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9325) atomic_set(&sctp_sk(newsk)->pd_mode, assoc->ulpq.pd_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9327) if (atomic_read(&sctp_sk(oldsk)->pd_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9328) struct sk_buff_head *queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9330) /* Decide which queue to move pd_lobby skbs to. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9331) if (assoc->ulpq.pd_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9332) queue = &newsp->pd_lobby;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9333) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9334) queue = &newsk->sk_receive_queue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9336) /* Walk through the pd_lobby, looking for skbs that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9337) * need moved to the new socket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9338) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9339) sctp_skb_for_each(skb, &oldsp->pd_lobby, tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9340) event = sctp_skb2event(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9341) if (event->asoc == assoc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9342) __skb_unlink(skb, &oldsp->pd_lobby);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9343) __skb_queue_tail(queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9344) sctp_skb_set_owner_r_frag(skb, newsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9348) /* Clear up any skbs waiting for the partial
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9349) * delivery to finish.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9350) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9351) if (assoc->ulpq.pd_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9352) sctp_clear_pd(oldsk, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9356) sctp_for_each_rx_skb(assoc, newsk, sctp_skb_set_owner_r_frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9358) /* Set the type of socket to indicate that it is peeled off from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9359) * original UDP-style socket or created with the accept() call on a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9360) * TCP-style socket..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9361) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9362) newsp->type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9364) /* Mark the new socket "in-use" by the user so that any packets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9365) * that may arrive on the association after we've moved it are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9366) * queued to the backlog. This prevents a potential race between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9367) * backlog processing on the old socket and new-packet processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9368) * on the new socket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9369) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9370) * The caller has just allocated newsk so we can guarantee that other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9371) * paths won't try to lock it and then oldsk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9372) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9373) lock_sock_nested(newsk, SINGLE_DEPTH_NESTING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9374) sctp_for_each_tx_datachunk(assoc, true, sctp_clear_owner_w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9375) sctp_assoc_migrate(assoc, newsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9376) sctp_for_each_tx_datachunk(assoc, false, sctp_set_owner_w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9378) /* If the association on the newsk is already closed before accept()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9379) * is called, set RCV_SHUTDOWN flag.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9380) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9381) if (sctp_state(assoc, CLOSED) && sctp_style(newsk, TCP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9382) inet_sk_set_state(newsk, SCTP_SS_CLOSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9383) newsk->sk_shutdown |= RCV_SHUTDOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9384) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9385) inet_sk_set_state(newsk, SCTP_SS_ESTABLISHED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9388) release_sock(newsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9390) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9394) /* This proto struct describes the ULP interface for SCTP. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9395) struct proto sctp_prot = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9396) .name = "SCTP",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9397) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9398) .close = sctp_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9399) .disconnect = sctp_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9400) .accept = sctp_accept,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9401) .ioctl = sctp_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9402) .init = sctp_init_sock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9403) .destroy = sctp_destroy_sock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9404) .shutdown = sctp_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9405) .setsockopt = sctp_setsockopt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9406) .getsockopt = sctp_getsockopt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9407) .sendmsg = sctp_sendmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9408) .recvmsg = sctp_recvmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9409) .bind = sctp_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9410) .bind_add = sctp_bind_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9411) .backlog_rcv = sctp_backlog_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9412) .hash = sctp_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9413) .unhash = sctp_unhash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9414) .no_autobind = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9415) .obj_size = sizeof(struct sctp_sock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9416) .useroffset = offsetof(struct sctp_sock, subscribe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9417) .usersize = offsetof(struct sctp_sock, initmsg) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9418) offsetof(struct sctp_sock, subscribe) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9419) sizeof_field(struct sctp_sock, initmsg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9420) .sysctl_mem = sysctl_sctp_mem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9421) .sysctl_rmem = sysctl_sctp_rmem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9422) .sysctl_wmem = sysctl_sctp_wmem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9423) .memory_pressure = &sctp_memory_pressure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9424) .enter_memory_pressure = sctp_enter_memory_pressure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9425) .memory_allocated = &sctp_memory_allocated,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9426) .sockets_allocated = &sctp_sockets_allocated,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9427) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9429) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9431) #include <net/transp_v6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9432) static void sctp_v6_destroy_sock(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9434) sctp_destroy_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9435) inet6_destroy_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9438) struct proto sctpv6_prot = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9439) .name = "SCTPv6",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9440) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9441) .close = sctp_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9442) .disconnect = sctp_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9443) .accept = sctp_accept,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9444) .ioctl = sctp_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9445) .init = sctp_init_sock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9446) .destroy = sctp_v6_destroy_sock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9447) .shutdown = sctp_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9448) .setsockopt = sctp_setsockopt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9449) .getsockopt = sctp_getsockopt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9450) .sendmsg = sctp_sendmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9451) .recvmsg = sctp_recvmsg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9452) .bind = sctp_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9453) .bind_add = sctp_bind_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9454) .backlog_rcv = sctp_backlog_rcv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9455) .hash = sctp_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9456) .unhash = sctp_unhash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9457) .no_autobind = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9458) .obj_size = sizeof(struct sctp6_sock),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9459) .useroffset = offsetof(struct sctp6_sock, sctp.subscribe),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9460) .usersize = offsetof(struct sctp6_sock, sctp.initmsg) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9461) offsetof(struct sctp6_sock, sctp.subscribe) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9462) sizeof_field(struct sctp6_sock, sctp.initmsg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9463) .sysctl_mem = sysctl_sctp_mem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9464) .sysctl_rmem = sysctl_sctp_rmem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9465) .sysctl_wmem = sysctl_sctp_wmem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9466) .memory_pressure = &sctp_memory_pressure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9467) .enter_memory_pressure = sctp_enter_memory_pressure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9468) .memory_allocated = &sctp_memory_allocated,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9469) .sockets_allocated = &sctp_sockets_allocated,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9470) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9471) #endif /* IS_ENABLED(CONFIG_IPV6) */