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