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