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