primitive.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. #include <linux/types.h>
  48. #include <linux/list.h> /* For struct list_head */
  49. #include <linux/socket.h>
  50. #include <linux/ip.h>
  51. #include <linux/time.h> /* For struct timeval */
  52. #include <linux/gfp.h>
  53. #include <net/sock.h>
  54. #include <net/sctp/sctp.h>
  55. #include <net/sctp/sm.h>
  56. #define DECLARE_PRIMITIVE(name) \
  57. /* This is called in the code as sctp_primitive_ ## name. */ \
  58. int sctp_primitive_ ## name(struct sctp_association *asoc, \
  59. void *arg) { \
  60. int error = 0; \
  61. sctp_event_t event_type; sctp_subtype_t subtype; \
  62. sctp_state_t state; \
  63. struct sctp_endpoint *ep; \
  64. \
  65. event_type = SCTP_EVENT_T_PRIMITIVE; \
  66. subtype = SCTP_ST_PRIMITIVE(SCTP_PRIMITIVE_ ## name); \
  67. state = asoc ? asoc->state : SCTP_STATE_CLOSED; \
  68. ep = asoc ? asoc->ep : NULL; \
  69. \
  70. error = sctp_do_sm(event_type, subtype, state, ep, asoc, \
  71. arg, GFP_KERNEL); \
  72. return error; \
  73. }
  74. /* 10.1 ULP-to-SCTP
  75. * B) Associate
  76. *
  77. * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
  78. * outbound stream count)
  79. * -> association id [,destination transport addr list] [,outbound stream
  80. * count]
  81. *
  82. * This primitive allows the upper layer to initiate an association to a
  83. * specific peer endpoint.
  84. *
  85. * This version assumes that asoc is fully populated with the initial
  86. * parameters. We then return a traditional kernel indicator of
  87. * success or failure.
  88. */
  89. /* This is called in the code as sctp_primitive_ASSOCIATE. */
  90. DECLARE_PRIMITIVE(ASSOCIATE)
  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. DECLARE_PRIMITIVE(SHUTDOWN);
  105. /* 10.1 ULP-to-SCTP
  106. * C) Abort
  107. *
  108. * Format: Abort(association id [, cause code])
  109. * -> result
  110. *
  111. * Ungracefully closes an association. Any locally queued user data
  112. * will be discarded and an ABORT chunk is sent to the peer. A success
  113. * code will be returned on successful abortion of the association. If
  114. * attempting to abort the association results in a failure, an error
  115. * code shall be returned.
  116. */
  117. DECLARE_PRIMITIVE(ABORT);
  118. /* 10.1 ULP-to-SCTP
  119. * E) Send
  120. *
  121. * Format: SEND(association id, buffer address, byte count [,context]
  122. * [,stream id] [,life time] [,destination transport address]
  123. * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
  124. * -> result
  125. *
  126. * This is the main method to send user data via SCTP.
  127. *
  128. * Mandatory attributes:
  129. *
  130. * o association id - local handle to the SCTP association
  131. *
  132. * o buffer address - the location where the user message to be
  133. * transmitted is stored;
  134. *
  135. * o byte count - The size of the user data in number of bytes;
  136. *
  137. * Optional attributes:
  138. *
  139. * o context - an optional 32 bit integer that will be carried in the
  140. * sending failure notification to the ULP if the transportation of
  141. * this User Message fails.
  142. *
  143. * o stream id - to indicate which stream to send the data on. If not
  144. * specified, stream 0 will be used.
  145. *
  146. * o life time - specifies the life time of the user data. The user data
  147. * will not be sent by SCTP after the life time expires. This
  148. * parameter can be used to avoid efforts to transmit stale
  149. * user messages. SCTP notifies the ULP if the data cannot be
  150. * initiated to transport (i.e. sent to the destination via SCTP's
  151. * send primitive) within the life time variable. However, the
  152. * user data will be transmitted if SCTP has attempted to transmit a
  153. * chunk before the life time expired.
  154. *
  155. * o destination transport address - specified as one of the destination
  156. * transport addresses of the peer endpoint to which this packet
  157. * should be sent. Whenever possible, SCTP should use this destination
  158. * transport address for sending the packets, instead of the current
  159. * primary path.
  160. *
  161. * o unorder flag - this flag, if present, indicates that the user
  162. * would like the data delivered in an unordered fashion to the peer
  163. * (i.e., the U flag is set to 1 on all DATA chunks carrying this
  164. * message).
  165. *
  166. * o no-bundle flag - instructs SCTP not to bundle this user data with
  167. * other outbound DATA chunks. SCTP MAY still bundle even when
  168. * this flag is present, when faced with network congestion.
  169. *
  170. * o payload protocol-id - A 32 bit unsigned integer that is to be
  171. * passed to the peer indicating the type of payload protocol data
  172. * being transmitted. This value is passed as opaque data by SCTP.
  173. */
  174. DECLARE_PRIMITIVE(SEND);
  175. /* 10.1 ULP-to-SCTP
  176. * J) Request Heartbeat
  177. *
  178. * Format: REQUESTHEARTBEAT(association id, destination transport address)
  179. *
  180. * -> result
  181. *
  182. * Instructs the local endpoint to perform a HeartBeat on the specified
  183. * destination transport address of the given association. The returned
  184. * result should indicate whether the transmission of the HEARTBEAT
  185. * chunk to the destination address is successful.
  186. *
  187. * Mandatory attributes:
  188. *
  189. * o association id - local handle to the SCTP association
  190. *
  191. * o destination transport address - the transport address of the
  192. * association on which a heartbeat should be issued.
  193. */
  194. DECLARE_PRIMITIVE(REQUESTHEARTBEAT);
  195. /* ADDIP
  196. * 3.1.1 Address Configuration Change Chunk (ASCONF)
  197. *
  198. * This chunk is used to communicate to the remote endpoint one of the
  199. * configuration change requests that MUST be acknowledged. The
  200. * information carried in the ASCONF Chunk uses the form of a
  201. * Type-Length-Value (TLV), as described in "3.2.1 Optional/
  202. * Variable-length Parameter Format" in RFC2960 [5], forall variable
  203. * parameters.
  204. */
  205. DECLARE_PRIMITIVE(ASCONF);