primitive.c 7.4 KB

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