blob: ab8d9f96a177da9d900e01568cafc56b6b4cf1cb [file] [log] [blame]
Vlad Yasevich60c778b2008-01-11 09:57:09 -05001/* SCTP kernel implementation
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Copyright (c) 1999-2000 Cisco, Inc.
3 * Copyright (c) 1999-2001 Motorola, Inc.
4 *
Vlad Yasevich60c778b2008-01-11 09:57:09 -05005 * This file is part of the SCTP kernel implementation
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * These functions implement the SCTP primitive functions from Section 10.
8 *
9 * Note that the descriptions from the specification are USER level
10 * functions--this file is the functions which populate the struct proto
11 * for SCTP which is the BOTTOM of the sockets interface.
12 *
Vlad Yasevich60c778b2008-01-11 09:57:09 -050013 * This SCTP implementation is free software;
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 * you can redistribute it and/or modify it under the terms of
15 * the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
17 * any later version.
18 *
Vlad Yasevich60c778b2008-01-11 09:57:09 -050019 * This SCTP implementation is distributed in the hope that it
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
21 * ************************
22 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 * See the GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
Jeff Kirsher4b2f13a2013-12-06 06:28:48 -080026 * along with GNU CC; see the file COPYING. If not, see
27 * <http://www.gnu.org/licenses/>.
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 *
29 * Please send any bug reports or fixes you make to the
30 * email address(es):
Daniel Borkmann91705c62013-07-23 14:51:47 +020031 * lksctp developers <linux-sctp@vger.kernel.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 * Written or modified by:
34 * La Monte H.P. Yarroll <piggy@acm.org>
35 * Narasimha Budihal <narasimha@refcode.org>
36 * Karl Knutson <karl@athena.chicago.il.us>
37 * Ardelle Fan <ardelle.fan@intel.com>
38 * Kevin Gao <kevin.gao@intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 */
40
41#include <linux/types.h>
42#include <linux/list.h> /* For struct list_head */
43#include <linux/socket.h>
44#include <linux/ip.h>
45#include <linux/time.h> /* For struct timeval */
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090046#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <net/sock.h>
48#include <net/sctp/sctp.h>
49#include <net/sctp/sm.h>
50
51#define DECLARE_PRIMITIVE(name) \
52/* This is called in the code as sctp_primitive_ ## name. */ \
Eric W. Biederman55e26eb2012-08-07 07:25:24 +000053int sctp_primitive_ ## name(struct net *net, struct sctp_association *asoc, \
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 void *arg) { \
55 int error = 0; \
56 sctp_event_t event_type; sctp_subtype_t subtype; \
57 sctp_state_t state; \
58 struct sctp_endpoint *ep; \
59 \
60 event_type = SCTP_EVENT_T_PRIMITIVE; \
61 subtype = SCTP_ST_PRIMITIVE(SCTP_PRIMITIVE_ ## name); \
62 state = asoc ? asoc->state : SCTP_STATE_CLOSED; \
63 ep = asoc ? asoc->ep : NULL; \
64 \
Eric W. Biederman55e26eb2012-08-07 07:25:24 +000065 error = sctp_do_sm(net, event_type, subtype, state, ep, asoc, \
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 arg, GFP_KERNEL); \
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +090067 return error; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070068}
69
70/* 10.1 ULP-to-SCTP
71 * B) Associate
72 *
73 * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
74 * outbound stream count)
75 * -> association id [,destination transport addr list] [,outbound stream
76 * count]
77 *
78 * This primitive allows the upper layer to initiate an association to a
79 * specific peer endpoint.
80 *
81 * This version assumes that asoc is fully populated with the initial
82 * parameters. We then return a traditional kernel indicator of
83 * success or failure.
84 */
85
86/* This is called in the code as sctp_primitive_ASSOCIATE. */
87
88DECLARE_PRIMITIVE(ASSOCIATE)
89
90/* 10.1 ULP-to-SCTP
91 * C) Shutdown
92 *
93 * Format: SHUTDOWN(association id)
94 * -> result
95 *
96 * Gracefully closes an association. Any locally queued user data
97 * will be delivered to the peer. The association will be terminated only
98 * after the peer acknowledges all the SCTP packets sent. A success code
99 * will be returned on successful termination of the association. If
100 * attempting to terminate the association results in a failure, an error
101 * code shall be returned.
102 */
103
104DECLARE_PRIMITIVE(SHUTDOWN);
105
106/* 10.1 ULP-to-SCTP
107 * C) Abort
108 *
109 * Format: Abort(association id [, cause code])
110 * -> result
111 *
112 * Ungracefully closes an association. Any locally queued user data
113 * will be discarded and an ABORT chunk is sent to the peer. A success
114 * code will be returned on successful abortion of the association. If
115 * attempting to abort the association results in a failure, an error
116 * code shall be returned.
117 */
118
119DECLARE_PRIMITIVE(ABORT);
120
121/* 10.1 ULP-to-SCTP
122 * E) Send
123 *
124 * Format: SEND(association id, buffer address, byte count [,context]
125 * [,stream id] [,life time] [,destination transport address]
126 * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
127 * -> result
128 *
129 * This is the main method to send user data via SCTP.
130 *
131 * Mandatory attributes:
132 *
133 * o association id - local handle to the SCTP association
134 *
135 * o buffer address - the location where the user message to be
136 * transmitted is stored;
137 *
138 * o byte count - The size of the user data in number of bytes;
139 *
140 * Optional attributes:
141 *
142 * o context - an optional 32 bit integer that will be carried in the
143 * sending failure notification to the ULP if the transportation of
144 * this User Message fails.
145 *
146 * o stream id - to indicate which stream to send the data on. If not
147 * specified, stream 0 will be used.
148 *
149 * o life time - specifies the life time of the user data. The user data
150 * will not be sent by SCTP after the life time expires. This
151 * parameter can be used to avoid efforts to transmit stale
152 * user messages. SCTP notifies the ULP if the data cannot be
153 * initiated to transport (i.e. sent to the destination via SCTP's
154 * send primitive) within the life time variable. However, the
155 * user data will be transmitted if SCTP has attempted to transmit a
156 * chunk before the life time expired.
157 *
158 * o destination transport address - specified as one of the destination
159 * transport addresses of the peer endpoint to which this packet
160 * should be sent. Whenever possible, SCTP should use this destination
161 * transport address for sending the packets, instead of the current
162 * primary path.
163 *
164 * o unorder flag - this flag, if present, indicates that the user
165 * would like the data delivered in an unordered fashion to the peer
166 * (i.e., the U flag is set to 1 on all DATA chunks carrying this
167 * message).
168 *
169 * o no-bundle flag - instructs SCTP not to bundle this user data with
170 * other outbound DATA chunks. SCTP MAY still bundle even when
171 * this flag is present, when faced with network congestion.
172 *
173 * o payload protocol-id - A 32 bit unsigned integer that is to be
174 * passed to the peer indicating the type of payload protocol data
175 * being transmitted. This value is passed as opaque data by SCTP.
176 */
177
178DECLARE_PRIMITIVE(SEND);
179
180/* 10.1 ULP-to-SCTP
181 * J) Request Heartbeat
182 *
183 * Format: REQUESTHEARTBEAT(association id, destination transport address)
184 *
185 * -> result
186 *
187 * Instructs the local endpoint to perform a HeartBeat on the specified
188 * destination transport address of the given association. The returned
189 * result should indicate whether the transmission of the HEARTBEAT
190 * chunk to the destination address is successful.
191 *
192 * Mandatory attributes:
193 *
194 * o association id - local handle to the SCTP association
195 *
196 * o destination transport address - the transport address of the
197 * association on which a heartbeat should be issued.
198 */
199
200DECLARE_PRIMITIVE(REQUESTHEARTBEAT);
201
202/* ADDIP
203* 3.1.1 Address Configuration Change Chunk (ASCONF)
YOSHIFUJI Hideakid808ad92007-02-09 23:25:18 +0900204*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205* This chunk is used to communicate to the remote endpoint one of the
206* configuration change requests that MUST be acknowledged. The
207* information carried in the ASCONF Chunk uses the form of a
208* Type-Length-Value (TLV), as described in "3.2.1 Optional/
209* Variable-length Parameter Format" in RFC2960 [5], forall variable
210* parameters.
211*/
212
213DECLARE_PRIMITIVE(ASCONF);