^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) * Copyright (c) 1999-2000 Cisco, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 1999-2001 Motorola, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * This file is part of the SCTP kernel implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * These functions implement the SCTP primitive functions from Section 10.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Note that the descriptions from the specification are USER level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * functions--this file is the functions which populate the struct proto
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * for SCTP which is the BOTTOM of the sockets interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Please send any bug reports or fixes you make to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * email address(es):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * lksctp developers <linux-sctp@vger.kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Written or modified by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * La Monte H.P. Yarroll <piggy@acm.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Narasimha Budihal <narasimha@refcode.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * Karl Knutson <karl@athena.chicago.il.us>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * Ardelle Fan <ardelle.fan@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * Kevin Gao <kevin.gao@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/list.h> /* For struct list_head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/time.h> /* For struct timeval */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <net/sctp/sctp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <net/sctp/sm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define DECLARE_PRIMITIVE(name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /* This is called in the code as sctp_primitive_ ## name. */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) int sctp_primitive_ ## name(struct net *net, struct sctp_association *asoc, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) void *arg) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) int error = 0; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) enum sctp_event_type event_type; union sctp_subtype subtype; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) enum sctp_state state; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct sctp_endpoint *ep; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) event_type = SCTP_EVENT_T_PRIMITIVE; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) subtype = SCTP_ST_PRIMITIVE(SCTP_PRIMITIVE_ ## name); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) state = asoc ? asoc->state : SCTP_STATE_CLOSED; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) ep = asoc ? asoc->ep : NULL; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) error = sctp_do_sm(net, event_type, subtype, state, ep, asoc, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) arg, GFP_KERNEL); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return error; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /* 10.1 ULP-to-SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * B) Associate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * outbound stream count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * -> association id [,destination transport addr list] [,outbound stream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * count]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * This primitive allows the upper layer to initiate an association to a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * specific peer endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * This version assumes that asoc is fully populated with the initial
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * parameters. We then return a traditional kernel indicator of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * success or failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /* This is called in the code as sctp_primitive_ASSOCIATE. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) DECLARE_PRIMITIVE(ASSOCIATE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) /* 10.1 ULP-to-SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * C) Shutdown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * Format: SHUTDOWN(association id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * -> result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * Gracefully closes an association. Any locally queued user data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * will be delivered to the peer. The association will be terminated only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * after the peer acknowledges all the SCTP packets sent. A success code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * will be returned on successful termination of the association. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * attempting to terminate the association results in a failure, an error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * code shall be returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) DECLARE_PRIMITIVE(SHUTDOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /* 10.1 ULP-to-SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * C) Abort
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * Format: Abort(association id [, cause code])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * -> result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * Ungracefully closes an association. Any locally queued user data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * will be discarded and an ABORT chunk is sent to the peer. A success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * code will be returned on successful abortion of the association. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * attempting to abort the association results in a failure, an error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * code shall be returned.
^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) DECLARE_PRIMITIVE(ABORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /* 10.1 ULP-to-SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * E) Send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * Format: SEND(association id, buffer address, byte count [,context]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * [,stream id] [,life time] [,destination transport address]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * -> result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * This is the main method to send user data via SCTP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * Mandatory attributes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * o association id - local handle to the SCTP association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * o buffer address - the location where the user message to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * transmitted is stored;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * o byte count - The size of the user data in number of bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * Optional attributes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * o context - an optional 32 bit integer that will be carried in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * sending failure notification to the ULP if the transportation of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * this User Message fails.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * o stream id - to indicate which stream to send the data on. If not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * specified, stream 0 will be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * o life time - specifies the life time of the user data. The user data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * will not be sent by SCTP after the life time expires. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * parameter can be used to avoid efforts to transmit stale
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * user messages. SCTP notifies the ULP if the data cannot be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * initiated to transport (i.e. sent to the destination via SCTP's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * send primitive) within the life time variable. However, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * user data will be transmitted if SCTP has attempted to transmit a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * chunk before the life time expired.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * o destination transport address - specified as one of the destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * transport addresses of the peer endpoint to which this packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * should be sent. Whenever possible, SCTP should use this destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * transport address for sending the packets, instead of the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * primary path.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * o unorder flag - this flag, if present, indicates that the user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * would like the data delivered in an unordered fashion to the peer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * (i.e., the U flag is set to 1 on all DATA chunks carrying this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * message).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * o no-bundle flag - instructs SCTP not to bundle this user data with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * other outbound DATA chunks. SCTP MAY still bundle even when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * this flag is present, when faced with network congestion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * o payload protocol-id - A 32 bit unsigned integer that is to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * passed to the peer indicating the type of payload protocol data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * being transmitted. This value is passed as opaque data by SCTP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) DECLARE_PRIMITIVE(SEND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /* 10.1 ULP-to-SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * J) Request Heartbeat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * Format: REQUESTHEARTBEAT(association id, destination transport address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * -> result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * Instructs the local endpoint to perform a HeartBeat on the specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * destination transport address of the given association. The returned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * result should indicate whether the transmission of the HEARTBEAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * chunk to the destination address is successful.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * Mandatory attributes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * o association id - local handle to the SCTP association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * o destination transport address - the transport address of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * association on which a heartbeat should be issued.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) DECLARE_PRIMITIVE(REQUESTHEARTBEAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /* ADDIP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * 3.1.1 Address Configuration Change Chunk (ASCONF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * This chunk is used to communicate to the remote endpoint one of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * configuration change requests that MUST be acknowledged. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * information carried in the ASCONF Chunk uses the form of a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * Type-Length-Value (TLV), as described in "3.2.1 Optional/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * Variable-length Parameter Format" in RFC2960 [5], forall variable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) DECLARE_PRIMITIVE(ASCONF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) /* RE-CONFIG 5.1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) DECLARE_PRIMITIVE(RECONF);