xref: /openbmc/linux/net/sctp/primitive.c (revision 58e16d792a6a8c6b750f637a4649967fcac853dc)
1*47505b8bSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
260c778b2SVlad Yasevich /* SCTP kernel implementation
31da177e4SLinus Torvalds  * Copyright (c) 1999-2000 Cisco, Inc.
41da177e4SLinus Torvalds  * Copyright (c) 1999-2001 Motorola, Inc.
51da177e4SLinus Torvalds  *
660c778b2SVlad Yasevich  * This file is part of the SCTP kernel implementation
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  * These functions implement the SCTP primitive functions from Section 10.
91da177e4SLinus Torvalds  *
101da177e4SLinus Torvalds  * Note that the descriptions from the specification are USER level
111da177e4SLinus Torvalds  * functions--this file is the functions which populate the struct proto
121da177e4SLinus Torvalds  * for SCTP which is the BOTTOM of the sockets interface.
131da177e4SLinus Torvalds  *
141da177e4SLinus Torvalds  * Please send any bug reports or fixes you make to the
151da177e4SLinus Torvalds  * email address(es):
1691705c61SDaniel Borkmann  *    lksctp developers <linux-sctp@vger.kernel.org>
171da177e4SLinus Torvalds  *
181da177e4SLinus Torvalds  * Written or modified by:
191da177e4SLinus Torvalds  *    La Monte H.P. Yarroll <piggy@acm.org>
201da177e4SLinus Torvalds  *    Narasimha Budihal     <narasimha@refcode.org>
211da177e4SLinus Torvalds  *    Karl Knutson          <karl@athena.chicago.il.us>
221da177e4SLinus Torvalds  *    Ardelle Fan	    <ardelle.fan@intel.com>
231da177e4SLinus Torvalds  *    Kevin Gao             <kevin.gao@intel.com>
241da177e4SLinus Torvalds  */
251da177e4SLinus Torvalds 
261da177e4SLinus Torvalds #include <linux/types.h>
271da177e4SLinus Torvalds #include <linux/list.h> /* For struct list_head */
281da177e4SLinus Torvalds #include <linux/socket.h>
291da177e4SLinus Torvalds #include <linux/ip.h>
301da177e4SLinus Torvalds #include <linux/time.h> /* For struct timeval */
315a0e3ad6STejun Heo #include <linux/gfp.h>
321da177e4SLinus Torvalds #include <net/sock.h>
331da177e4SLinus Torvalds #include <net/sctp/sctp.h>
341da177e4SLinus Torvalds #include <net/sctp/sm.h>
351da177e4SLinus Torvalds 
361da177e4SLinus Torvalds #define DECLARE_PRIMITIVE(name) \
371da177e4SLinus Torvalds /* This is called in the code as sctp_primitive_ ## name.  */ \
3855e26eb9SEric W. Biederman int sctp_primitive_ ## name(struct net *net, struct sctp_association *asoc, \
391da177e4SLinus Torvalds 			    void *arg) { \
401da177e4SLinus Torvalds 	int error = 0; \
4188ee48c1SXin Long 	enum sctp_event_type event_type; union sctp_subtype subtype; \
4252106019SXin Long 	enum sctp_state state; \
431da177e4SLinus Torvalds 	struct sctp_endpoint *ep; \
441da177e4SLinus Torvalds 	\
451da177e4SLinus Torvalds 	event_type = SCTP_EVENT_T_PRIMITIVE; \
461da177e4SLinus Torvalds 	subtype = SCTP_ST_PRIMITIVE(SCTP_PRIMITIVE_ ## name); \
471da177e4SLinus Torvalds 	state = asoc ? asoc->state : SCTP_STATE_CLOSED; \
481da177e4SLinus Torvalds 	ep = asoc ? asoc->ep : NULL; \
491da177e4SLinus Torvalds 	\
5055e26eb9SEric W. Biederman 	error = sctp_do_sm(net, event_type, subtype, state, ep, asoc,	\
511da177e4SLinus Torvalds 			   arg, GFP_KERNEL); \
521da177e4SLinus Torvalds 	return error; \
531da177e4SLinus Torvalds }
541da177e4SLinus Torvalds 
551da177e4SLinus Torvalds /* 10.1 ULP-to-SCTP
561da177e4SLinus Torvalds  * B) Associate
571da177e4SLinus Torvalds  *
581da177e4SLinus Torvalds  * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
591da177e4SLinus Torvalds  *         outbound stream count)
601da177e4SLinus Torvalds  * -> association id [,destination transport addr list] [,outbound stream
611da177e4SLinus Torvalds  *    count]
621da177e4SLinus Torvalds  *
631da177e4SLinus Torvalds  * This primitive allows the upper layer to initiate an association to a
641da177e4SLinus Torvalds  * specific peer endpoint.
651da177e4SLinus Torvalds  *
661da177e4SLinus Torvalds  * This version assumes that asoc is fully populated with the initial
671da177e4SLinus Torvalds  * parameters.  We then return a traditional kernel indicator of
681da177e4SLinus Torvalds  * success or failure.
691da177e4SLinus Torvalds  */
701da177e4SLinus Torvalds 
711da177e4SLinus Torvalds /* This is called in the code as sctp_primitive_ASSOCIATE.  */
721da177e4SLinus Torvalds 
731da177e4SLinus Torvalds DECLARE_PRIMITIVE(ASSOCIATE)
741da177e4SLinus Torvalds 
751da177e4SLinus Torvalds /* 10.1 ULP-to-SCTP
761da177e4SLinus Torvalds  * C) Shutdown
771da177e4SLinus Torvalds  *
781da177e4SLinus Torvalds  * Format: SHUTDOWN(association id)
791da177e4SLinus Torvalds  * -> result
801da177e4SLinus Torvalds  *
811da177e4SLinus Torvalds  * Gracefully closes an association. Any locally queued user data
821da177e4SLinus Torvalds  * will be delivered to the peer. The association will be terminated only
831da177e4SLinus Torvalds  * after the peer acknowledges all the SCTP packets sent.  A success code
841da177e4SLinus Torvalds  * will be returned on successful termination of the association. If
851da177e4SLinus Torvalds  * attempting to terminate the association results in a failure, an error
861da177e4SLinus Torvalds  * code shall be returned.
871da177e4SLinus Torvalds  */
881da177e4SLinus Torvalds 
891da177e4SLinus Torvalds DECLARE_PRIMITIVE(SHUTDOWN);
901da177e4SLinus Torvalds 
911da177e4SLinus Torvalds /* 10.1 ULP-to-SCTP
921da177e4SLinus Torvalds  * C) Abort
931da177e4SLinus Torvalds  *
941da177e4SLinus Torvalds  * Format: Abort(association id [, cause code])
951da177e4SLinus Torvalds  * -> result
961da177e4SLinus Torvalds  *
971da177e4SLinus Torvalds  * Ungracefully closes an association. Any locally queued user data
981da177e4SLinus Torvalds  * will be discarded and an ABORT chunk is sent to the peer. A success
991da177e4SLinus Torvalds  * code will be returned on successful abortion of the association. If
1001da177e4SLinus Torvalds  * attempting to abort the association results in a failure, an error
1011da177e4SLinus Torvalds  * code shall be returned.
1021da177e4SLinus Torvalds  */
1031da177e4SLinus Torvalds 
1041da177e4SLinus Torvalds DECLARE_PRIMITIVE(ABORT);
1051da177e4SLinus Torvalds 
1061da177e4SLinus Torvalds /* 10.1 ULP-to-SCTP
1071da177e4SLinus Torvalds  * E) Send
1081da177e4SLinus Torvalds  *
1091da177e4SLinus Torvalds  * Format: SEND(association id, buffer address, byte count [,context]
1101da177e4SLinus Torvalds  *         [,stream id] [,life time] [,destination transport address]
1111da177e4SLinus Torvalds  *         [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
1121da177e4SLinus Torvalds  * -> result
1131da177e4SLinus Torvalds  *
1141da177e4SLinus Torvalds  * This is the main method to send user data via SCTP.
1151da177e4SLinus Torvalds  *
1161da177e4SLinus Torvalds  * Mandatory attributes:
1171da177e4SLinus Torvalds  *
1181da177e4SLinus Torvalds  *  o association id - local handle to the SCTP association
1191da177e4SLinus Torvalds  *
1201da177e4SLinus Torvalds  *  o buffer address - the location where the user message to be
1211da177e4SLinus Torvalds  *    transmitted is stored;
1221da177e4SLinus Torvalds  *
1231da177e4SLinus Torvalds  *  o byte count - The size of the user data in number of bytes;
1241da177e4SLinus Torvalds  *
1251da177e4SLinus Torvalds  * Optional attributes:
1261da177e4SLinus Torvalds  *
1271da177e4SLinus Torvalds  *  o context - an optional 32 bit integer that will be carried in the
1281da177e4SLinus Torvalds  *    sending failure notification to the ULP if the transportation of
1291da177e4SLinus Torvalds  *    this User Message fails.
1301da177e4SLinus Torvalds  *
1311da177e4SLinus Torvalds  *  o stream id - to indicate which stream to send the data on. If not
1321da177e4SLinus Torvalds  *    specified, stream 0 will be used.
1331da177e4SLinus Torvalds  *
1341da177e4SLinus Torvalds  *  o life time - specifies the life time of the user data. The user data
1351da177e4SLinus Torvalds  *    will not be sent by SCTP after the life time expires. This
1361da177e4SLinus Torvalds  *    parameter can be used to avoid efforts to transmit stale
1371da177e4SLinus Torvalds  *    user messages. SCTP notifies the ULP if the data cannot be
1381da177e4SLinus Torvalds  *    initiated to transport (i.e. sent to the destination via SCTP's
1391da177e4SLinus Torvalds  *    send primitive) within the life time variable. However, the
1401da177e4SLinus Torvalds  *    user data will be transmitted if SCTP has attempted to transmit a
1411da177e4SLinus Torvalds  *    chunk before the life time expired.
1421da177e4SLinus Torvalds  *
1431da177e4SLinus Torvalds  *  o destination transport address - specified as one of the destination
1441da177e4SLinus Torvalds  *    transport addresses of the peer endpoint to which this packet
1451da177e4SLinus Torvalds  *    should be sent. Whenever possible, SCTP should use this destination
1461da177e4SLinus Torvalds  *    transport address for sending the packets, instead of the current
1471da177e4SLinus Torvalds  *    primary path.
1481da177e4SLinus Torvalds  *
1491da177e4SLinus Torvalds  *  o unorder flag - this flag, if present, indicates that the user
1501da177e4SLinus Torvalds  *    would like the data delivered in an unordered fashion to the peer
1511da177e4SLinus Torvalds  *    (i.e., the U flag is set to 1 on all DATA chunks carrying this
1521da177e4SLinus Torvalds  *    message).
1531da177e4SLinus Torvalds  *
1541da177e4SLinus Torvalds  *  o no-bundle flag - instructs SCTP not to bundle this user data with
1551da177e4SLinus Torvalds  *    other outbound DATA chunks. SCTP MAY still bundle even when
1561da177e4SLinus Torvalds  *    this flag is present, when faced with network congestion.
1571da177e4SLinus Torvalds  *
1581da177e4SLinus Torvalds  *  o payload protocol-id - A 32 bit unsigned integer that is to be
1591da177e4SLinus Torvalds  *    passed to the peer indicating the type of payload protocol data
1601da177e4SLinus Torvalds  *    being transmitted. This value is passed as opaque data by SCTP.
1611da177e4SLinus Torvalds  */
1621da177e4SLinus Torvalds 
1631da177e4SLinus Torvalds DECLARE_PRIMITIVE(SEND);
1641da177e4SLinus Torvalds 
1651da177e4SLinus Torvalds /* 10.1 ULP-to-SCTP
1661da177e4SLinus Torvalds  * J) Request Heartbeat
1671da177e4SLinus Torvalds  *
1681da177e4SLinus Torvalds  * Format: REQUESTHEARTBEAT(association id, destination transport address)
1691da177e4SLinus Torvalds  *
1701da177e4SLinus Torvalds  * -> result
1711da177e4SLinus Torvalds  *
1721da177e4SLinus Torvalds  * Instructs the local endpoint to perform a HeartBeat on the specified
1731da177e4SLinus Torvalds  * destination transport address of the given association. The returned
1741da177e4SLinus Torvalds  * result should indicate whether the transmission of the HEARTBEAT
1751da177e4SLinus Torvalds  * chunk to the destination address is successful.
1761da177e4SLinus Torvalds  *
1771da177e4SLinus Torvalds  * Mandatory attributes:
1781da177e4SLinus Torvalds  *
1791da177e4SLinus Torvalds  * o association id - local handle to the SCTP association
1801da177e4SLinus Torvalds  *
1811da177e4SLinus Torvalds  * o destination transport address - the transport address of the
1821da177e4SLinus Torvalds  *   association on which a heartbeat should be issued.
1831da177e4SLinus Torvalds  */
1841da177e4SLinus Torvalds 
1851da177e4SLinus Torvalds DECLARE_PRIMITIVE(REQUESTHEARTBEAT);
1861da177e4SLinus Torvalds 
1871da177e4SLinus Torvalds /* ADDIP
1881da177e4SLinus Torvalds * 3.1.1 Address Configuration Change Chunk (ASCONF)
1891da177e4SLinus Torvalds *
1901da177e4SLinus Torvalds * This chunk is used to communicate to the remote endpoint one of the
1911da177e4SLinus Torvalds * configuration change requests that MUST be acknowledged.  The
1921da177e4SLinus Torvalds * information carried in the ASCONF Chunk uses the form of a
1931da177e4SLinus Torvalds * Type-Length-Value (TLV), as described in "3.2.1 Optional/
1941da177e4SLinus Torvalds * Variable-length Parameter Format" in RFC2960 [5], forall variable
1951da177e4SLinus Torvalds * parameters.
1961da177e4SLinus Torvalds */
1971da177e4SLinus Torvalds 
1981da177e4SLinus Torvalds DECLARE_PRIMITIVE(ASCONF);
1997a090b04SXin Long 
2007a090b04SXin Long /* RE-CONFIG 5.1 */
2017a090b04SXin Long DECLARE_PRIMITIVE(RECONF);
202