/* SCTP kernel implementation1* Copyright (c) 1999-2000 Cisco, Inc.2* Copyright (c) 1999-2001 Motorola, Inc.3*4* This file is part of the SCTP kernel implementation5*6* These functions implement the SCTP primitive functions from Section 10.7*8* Note that the descriptions from the specification are USER level9* functions--this file is the functions which populate the struct proto10* for SCTP which is the BOTTOM of the sockets interface.11*12* This SCTP implementation is free software;13* you can redistribute it and/or modify it under the terms of14* the GNU General Public License as published by15* the Free Software Foundation; either version 2, or (at your option)16* any later version.17*18* This SCTP implementation is distributed in the hope that it19* will be useful, but WITHOUT ANY WARRANTY; without even the implied20* ************************21* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.22* See the GNU General Public License for more details.23*24* You should have received a copy of the GNU General Public License25* along with GNU CC; see the file COPYING. If not, write to26* the Free Software Foundation, 59 Temple Place - Suite 330,27* Boston, MA 02111-1307, USA.28*29* Please send any bug reports or fixes you make to the30* email address(es):31* lksctp developers <[email protected]>32*33* Or submit a bug report through the following website:34* http://www.sf.net/projects/lksctp35*36* Written or modified by:37* La Monte H.P. Yarroll <[email protected]>38* Narasimha Budihal <[email protected]>39* Karl Knutson <[email protected]>40* Ardelle Fan <[email protected]>41* Kevin Gao <[email protected]>42*43* Any bugs reported given to us we will try to fix... any fixes shared will44* be incorporated into the next SCTP release.45*/4647#include <linux/types.h>48#include <linux/list.h> /* For struct list_head */49#include <linux/socket.h>50#include <linux/ip.h>51#include <linux/time.h> /* For struct timeval */52#include <linux/gfp.h>53#include <net/sock.h>54#include <net/sctp/sctp.h>55#include <net/sctp/sm.h>5657#define DECLARE_PRIMITIVE(name) \58/* This is called in the code as sctp_primitive_ ## name. */ \59int sctp_primitive_ ## name(struct sctp_association *asoc, \60void *arg) { \61int error = 0; \62sctp_event_t event_type; sctp_subtype_t subtype; \63sctp_state_t state; \64struct sctp_endpoint *ep; \65\66event_type = SCTP_EVENT_T_PRIMITIVE; \67subtype = SCTP_ST_PRIMITIVE(SCTP_PRIMITIVE_ ## name); \68state = asoc ? asoc->state : SCTP_STATE_CLOSED; \69ep = asoc ? asoc->ep : NULL; \70\71error = sctp_do_sm(event_type, subtype, state, ep, asoc, \72arg, GFP_KERNEL); \73return error; \74}7576/* 10.1 ULP-to-SCTP77* B) Associate78*79* Format: ASSOCIATE(local SCTP instance name, destination transport addr,80* outbound stream count)81* -> association id [,destination transport addr list] [,outbound stream82* count]83*84* This primitive allows the upper layer to initiate an association to a85* specific peer endpoint.86*87* This version assumes that asoc is fully populated with the initial88* parameters. We then return a traditional kernel indicator of89* success or failure.90*/9192/* This is called in the code as sctp_primitive_ASSOCIATE. */9394DECLARE_PRIMITIVE(ASSOCIATE)9596/* 10.1 ULP-to-SCTP97* C) Shutdown98*99* Format: SHUTDOWN(association id)100* -> result101*102* Gracefully closes an association. Any locally queued user data103* will be delivered to the peer. The association will be terminated only104* after the peer acknowledges all the SCTP packets sent. A success code105* will be returned on successful termination of the association. If106* attempting to terminate the association results in a failure, an error107* code shall be returned.108*/109110DECLARE_PRIMITIVE(SHUTDOWN);111112/* 10.1 ULP-to-SCTP113* C) Abort114*115* Format: Abort(association id [, cause code])116* -> result117*118* Ungracefully closes an association. Any locally queued user data119* will be discarded and an ABORT chunk is sent to the peer. A success120* code will be returned on successful abortion of the association. If121* attempting to abort the association results in a failure, an error122* code shall be returned.123*/124125DECLARE_PRIMITIVE(ABORT);126127/* 10.1 ULP-to-SCTP128* E) Send129*130* Format: SEND(association id, buffer address, byte count [,context]131* [,stream id] [,life time] [,destination transport address]132* [,unorder flag] [,no-bundle flag] [,payload protocol-id] )133* -> result134*135* This is the main method to send user data via SCTP.136*137* Mandatory attributes:138*139* o association id - local handle to the SCTP association140*141* o buffer address - the location where the user message to be142* transmitted is stored;143*144* o byte count - The size of the user data in number of bytes;145*146* Optional attributes:147*148* o context - an optional 32 bit integer that will be carried in the149* sending failure notification to the ULP if the transportation of150* this User Message fails.151*152* o stream id - to indicate which stream to send the data on. If not153* specified, stream 0 will be used.154*155* o life time - specifies the life time of the user data. The user data156* will not be sent by SCTP after the life time expires. This157* parameter can be used to avoid efforts to transmit stale158* user messages. SCTP notifies the ULP if the data cannot be159* initiated to transport (i.e. sent to the destination via SCTP's160* send primitive) within the life time variable. However, the161* user data will be transmitted if SCTP has attempted to transmit a162* chunk before the life time expired.163*164* o destination transport address - specified as one of the destination165* transport addresses of the peer endpoint to which this packet166* should be sent. Whenever possible, SCTP should use this destination167* transport address for sending the packets, instead of the current168* primary path.169*170* o unorder flag - this flag, if present, indicates that the user171* would like the data delivered in an unordered fashion to the peer172* (i.e., the U flag is set to 1 on all DATA chunks carrying this173* message).174*175* o no-bundle flag - instructs SCTP not to bundle this user data with176* other outbound DATA chunks. SCTP MAY still bundle even when177* this flag is present, when faced with network congestion.178*179* o payload protocol-id - A 32 bit unsigned integer that is to be180* passed to the peer indicating the type of payload protocol data181* being transmitted. This value is passed as opaque data by SCTP.182*/183184DECLARE_PRIMITIVE(SEND);185186/* 10.1 ULP-to-SCTP187* J) Request Heartbeat188*189* Format: REQUESTHEARTBEAT(association id, destination transport address)190*191* -> result192*193* Instructs the local endpoint to perform a HeartBeat on the specified194* destination transport address of the given association. The returned195* result should indicate whether the transmission of the HEARTBEAT196* chunk to the destination address is successful.197*198* Mandatory attributes:199*200* o association id - local handle to the SCTP association201*202* o destination transport address - the transport address of the203* association on which a heartbeat should be issued.204*/205206DECLARE_PRIMITIVE(REQUESTHEARTBEAT);207208/* ADDIP209* 3.1.1 Address Configuration Change Chunk (ASCONF)210*211* This chunk is used to communicate to the remote endpoint one of the212* configuration change requests that MUST be acknowledged. The213* information carried in the ASCONF Chunk uses the form of a214* Type-Length-Value (TLV), as described in "3.2.1 Optional/215* Variable-length Parameter Format" in RFC2960 [5], forall variable216* parameters.217*/218219DECLARE_PRIMITIVE(ASCONF);220221222