Blame view

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