primitive.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* SCTP kernel implementation
  3. * Copyright (c) 1999-2000 Cisco, Inc.
  4. * Copyright (c) 1999-2001 Motorola, Inc.
  5. *
  6. * This file is part of the SCTP kernel implementation
  7. *
  8. * These functions implement the SCTP primitive functions from Section 10.
  9. *
  10. * Note that the descriptions from the specification are USER level
  11. * functions--this file is the functions which populate the struct proto
  12. * for SCTP which is the BOTTOM of the sockets interface.
  13. *
  14. * Please send any bug reports or fixes you make to the
  15. * email address(es):
  16. * lksctp developers <linux-sctp@vger.kernel.org>
  17. *
  18. * Written or modified by:
  19. * La Monte H.P. Yarroll <piggy@acm.org>
  20. * Narasimha Budihal <narasimha@refcode.org>
  21. * Karl Knutson <karl@athena.chicago.il.us>
  22. * Ardelle Fan <ardelle.fan@intel.com>
  23. * Kevin Gao <kevin.gao@intel.com>
  24. */
  25. #include <linux/types.h>
  26. #include <linux/list.h> /* For struct list_head */
  27. #include <linux/socket.h>
  28. #include <linux/ip.h>
  29. #include <linux/time.h> /* For struct timeval */
  30. #include <linux/gfp.h>
  31. #include <net/sock.h>
  32. #include <net/sctp/sctp.h>
  33. #include <net/sctp/sm.h>
  34. #define DECLARE_PRIMITIVE(name) \
  35. /* This is called in the code as sctp_primitive_ ## name. */ \
  36. int sctp_primitive_ ## name(struct net *net, struct sctp_association *asoc, \
  37. void *arg) { \
  38. int error = 0; \
  39. enum sctp_event_type event_type; union sctp_subtype subtype; \
  40. enum sctp_state state; \
  41. struct sctp_endpoint *ep; \
  42. \
  43. event_type = SCTP_EVENT_T_PRIMITIVE; \
  44. subtype = SCTP_ST_PRIMITIVE(SCTP_PRIMITIVE_ ## name); \
  45. state = asoc ? asoc->state : SCTP_STATE_CLOSED; \
  46. ep = asoc ? asoc->ep : NULL; \
  47. \
  48. error = sctp_do_sm(net, event_type, subtype, state, ep, asoc, \
  49. arg, GFP_KERNEL); \
  50. return error; \
  51. }
  52. /* 10.1 ULP-to-SCTP
  53. * B) Associate
  54. *
  55. * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
  56. * outbound stream count)
  57. * -> association id [,destination transport addr list] [,outbound stream
  58. * count]
  59. *
  60. * This primitive allows the upper layer to initiate an association to a
  61. * specific peer endpoint.
  62. *
  63. * This version assumes that asoc is fully populated with the initial
  64. * parameters. We then return a traditional kernel indicator of
  65. * success or failure.
  66. */
  67. /* This is called in the code as sctp_primitive_ASSOCIATE. */
  68. DECLARE_PRIMITIVE(ASSOCIATE)
  69. /* 10.1 ULP-to-SCTP
  70. * C) Shutdown
  71. *
  72. * Format: SHUTDOWN(association id)
  73. * -> result
  74. *
  75. * Gracefully closes an association. Any locally queued user data
  76. * will be delivered to the peer. The association will be terminated only
  77. * after the peer acknowledges all the SCTP packets sent. A success code
  78. * will be returned on successful termination of the association. If
  79. * attempting to terminate the association results in a failure, an error
  80. * code shall be returned.
  81. */
  82. DECLARE_PRIMITIVE(SHUTDOWN);
  83. /* 10.1 ULP-to-SCTP
  84. * C) Abort
  85. *
  86. * Format: Abort(association id [, cause code])
  87. * -> result
  88. *
  89. * Ungracefully closes an association. Any locally queued user data
  90. * will be discarded and an ABORT chunk is sent to the peer. A success
  91. * code will be returned on successful abortion of the association. If
  92. * attempting to abort the association results in a failure, an error
  93. * code shall be returned.
  94. */
  95. DECLARE_PRIMITIVE(ABORT);
  96. /* 10.1 ULP-to-SCTP
  97. * E) Send
  98. *
  99. * Format: SEND(association id, buffer address, byte count [,context]
  100. * [,stream id] [,life time] [,destination transport address]
  101. * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
  102. * -> result
  103. *
  104. * This is the main method to send user data via SCTP.
  105. *
  106. * Mandatory attributes:
  107. *
  108. * o association id - local handle to the SCTP association
  109. *
  110. * o buffer address - the location where the user message to be
  111. * transmitted is stored;
  112. *
  113. * o byte count - The size of the user data in number of bytes;
  114. *
  115. * Optional attributes:
  116. *
  117. * o context - an optional 32 bit integer that will be carried in the
  118. * sending failure notification to the ULP if the transportation of
  119. * this User Message fails.
  120. *
  121. * o stream id - to indicate which stream to send the data on. If not
  122. * specified, stream 0 will be used.
  123. *
  124. * o life time - specifies the life time of the user data. The user data
  125. * will not be sent by SCTP after the life time expires. This
  126. * parameter can be used to avoid efforts to transmit stale
  127. * user messages. SCTP notifies the ULP if the data cannot be
  128. * initiated to transport (i.e. sent to the destination via SCTP's
  129. * send primitive) within the life time variable. However, the
  130. * user data will be transmitted if SCTP has attempted to transmit a
  131. * chunk before the life time expired.
  132. *
  133. * o destination transport address - specified as one of the destination
  134. * transport addresses of the peer endpoint to which this packet
  135. * should be sent. Whenever possible, SCTP should use this destination
  136. * transport address for sending the packets, instead of the current
  137. * primary path.
  138. *
  139. * o unorder flag - this flag, if present, indicates that the user
  140. * would like the data delivered in an unordered fashion to the peer
  141. * (i.e., the U flag is set to 1 on all DATA chunks carrying this
  142. * message).
  143. *
  144. * o no-bundle flag - instructs SCTP not to bundle this user data with
  145. * other outbound DATA chunks. SCTP MAY still bundle even when
  146. * this flag is present, when faced with network congestion.
  147. *
  148. * o payload protocol-id - A 32 bit unsigned integer that is to be
  149. * passed to the peer indicating the type of payload protocol data
  150. * being transmitted. This value is passed as opaque data by SCTP.
  151. */
  152. DECLARE_PRIMITIVE(SEND);
  153. /* 10.1 ULP-to-SCTP
  154. * J) Request Heartbeat
  155. *
  156. * Format: REQUESTHEARTBEAT(association id, destination transport address)
  157. *
  158. * -> result
  159. *
  160. * Instructs the local endpoint to perform a HeartBeat on the specified
  161. * destination transport address of the given association. The returned
  162. * result should indicate whether the transmission of the HEARTBEAT
  163. * chunk to the destination address is successful.
  164. *
  165. * Mandatory attributes:
  166. *
  167. * o association id - local handle to the SCTP association
  168. *
  169. * o destination transport address - the transport address of the
  170. * association on which a heartbeat should be issued.
  171. */
  172. DECLARE_PRIMITIVE(REQUESTHEARTBEAT);
  173. /* ADDIP
  174. * 3.1.1 Address Configuration Change Chunk (ASCONF)
  175. *
  176. * This chunk is used to communicate to the remote endpoint one of the
  177. * configuration change requests that MUST be acknowledged. The
  178. * information carried in the ASCONF Chunk uses the form of a
  179. * Type-Length-Value (TLV), as described in "3.2.1 Optional/
  180. * Variable-length Parameter Format" in RFC2960 [5], forall variable
  181. * parameters.
  182. */
  183. DECLARE_PRIMITIVE(ASCONF);
  184. /* RE-CONFIG 5.1 */
  185. DECLARE_PRIMITIVE(RECONF);