primitive.c 7.6 KB

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