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