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