fix a kmap leak in virtio_console
[linux/fpc-iii.git] / net / sctp / primitive.c
blobab8d9f96a177da9d900e01568cafc56b6b4cf1cb
1 /* SCTP kernel implementation
2 * Copyright (c) 1999-2000 Cisco, Inc.
3 * Copyright (c) 1999-2001 Motorola, Inc.
5 * This file is part of the SCTP kernel implementation
7 * These functions implement the SCTP primitive functions from Section 10.
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.
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.
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.
25 * You should have received a copy of the GNU General Public License
26 * along with GNU CC; see the file COPYING. If not, see
27 * <http://www.gnu.org/licenses/>.
29 * Please send any bug reports or fixes you make to the
30 * email address(es):
31 * lksctp developers <linux-sctp@vger.kernel.org>
33 * 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>
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 */
46 #include <linux/gfp.h>
47 #include <net/sock.h>
48 #include <net/sctp/sctp.h>
49 #include <net/sctp/sm.h>
51 #define DECLARE_PRIMITIVE(name) \
52 /* This is called in the code as sctp_primitive_ ## name. */ \
53 int sctp_primitive_ ## name(struct net *net, struct sctp_association *asoc, \
54 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; \
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; \
65 error = sctp_do_sm(net, event_type, subtype, state, ep, asoc, \
66 arg, GFP_KERNEL); \
67 return error; \
70 /* 10.1 ULP-to-SCTP
71 * B) Associate
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]
78 * This primitive allows the upper layer to initiate an association to a
79 * specific peer endpoint.
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.
86 /* This is called in the code as sctp_primitive_ASSOCIATE. */
88 DECLARE_PRIMITIVE(ASSOCIATE)
90 /* 10.1 ULP-to-SCTP
91 * C) Shutdown
93 * Format: SHUTDOWN(association id)
94 * -> result
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.
104 DECLARE_PRIMITIVE(SHUTDOWN);
106 /* 10.1 ULP-to-SCTP
107 * C) Abort
109 * Format: Abort(association id [, cause code])
110 * -> result
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.
119 DECLARE_PRIMITIVE(ABORT);
121 /* 10.1 ULP-to-SCTP
122 * E) Send
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
129 * This is the main method to send user data via SCTP.
131 * Mandatory attributes:
133 * o association id - local handle to the SCTP association
135 * o buffer address - the location where the user message to be
136 * transmitted is stored;
138 * o byte count - The size of the user data in number of bytes;
140 * Optional attributes:
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.
146 * o stream id - to indicate which stream to send the data on. If not
147 * specified, stream 0 will be used.
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.
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.
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).
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.
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.
178 DECLARE_PRIMITIVE(SEND);
180 /* 10.1 ULP-to-SCTP
181 * J) Request Heartbeat
183 * Format: REQUESTHEARTBEAT(association id, destination transport address)
185 * -> result
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.
192 * Mandatory attributes:
194 * o association id - local handle to the SCTP association
196 * o destination transport address - the transport address of the
197 * association on which a heartbeat should be issued.
200 DECLARE_PRIMITIVE(REQUESTHEARTBEAT);
202 /* ADDIP
203 * 3.1.1 Address Configuration Change Chunk (ASCONF)
205 * 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.
213 DECLARE_PRIMITIVE(ASCONF);