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