Linux Audio

Check our new training course

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