1 /* SCTP kernel reference Implementation 2 * (C) Copyright IBM Corp. 2001, 2004 3 * Copyright (c) 1999-2000 Cisco, Inc. 4 * Copyright (c) 1999-2001 Motorola, Inc. 5 * Copyright (c) 2002 Intel Corp. 6 * 7 * This file is part of the SCTP kernel reference Implementation 8 * 9 * This header represents the structures and constants needed to support 10 * the SCTP Extension to the Sockets API. 11 * 12 * The SCTP reference implementation is free software; 13 * you can redistribute it and/or modify it under the terms of 14 * the GNU General Public License as published by 15 * the Free Software Foundation; either version 2, or (at your option) 16 * any later version. 17 * 18 * The SCTP reference implementation is distributed in the hope that it 19 * will be useful, but WITHOUT ANY WARRANTY; without even the implied 20 * ************************ 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 License 25 * along with GNU CC; see the file COPYING. If not, write to 26 * 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 the 30 * email address(es): 31 * lksctp developers <lksctp-developers@lists.sourceforge.net> 32 * 33 * Or submit a bug report through the following website: 34 * http://www.sf.net/projects/lksctp 35 * 36 * Written or modified by: 37 * La Monte H.P. Yarroll <piggy@acm.org> 38 * R. Stewart <randall@sctp.chicago.il.us> 39 * K. Morneau <kmorneau@cisco.com> 40 * Q. Xie <qxie1@email.mot.com> 41 * Karl Knutson <karl@athena.chicago.il.us> 42 * Jon Grimm <jgrimm@us.ibm.com> 43 * Daisy Chang <daisyc@us.ibm.com> 44 * Ryan Layer <rmlayer@us.ibm.com> 45 * Ardelle Fan <ardelle.fan@intel.com> 46 * Sridhar Samudrala <sri@us.ibm.com> 47 * 48 * Any bugs reported given to us we will try to fix... any fixes shared will 49 * be incorporated into the next SCTP release. 50 */ 51 52 #ifndef __net_sctp_user_h__ 53 #define __net_sctp_user_h__ 54 55 #include <linux/types.h> 56 #include <linux/socket.h> 57 58 typedef void * sctp_assoc_t; 59 60 /* The following symbols come from the Sockets API Extensions for 61 * SCTP <draft-ietf-tsvwg-sctpsocket-07.txt>. 62 */ 63 enum sctp_optname { 64 SCTP_RTOINFO, 65 #define SCTP_RTOINFO SCTP_RTOINFO 66 SCTP_ASSOCINFO, 67 #define SCTP_ASSOCINFO SCTP_ASSOCINFO 68 SCTP_INITMSG, 69 #define SCTP_INITMSG SCTP_INITMSG 70 SCTP_NODELAY, /* Get/set nodelay option. */ 71 #define SCTP_NODELAY SCTP_NODELAY 72 SCTP_AUTOCLOSE, 73 #define SCTP_AUTOCLOSE SCTP_AUTOCLOSE 74 SCTP_SET_PEER_PRIMARY_ADDR, 75 #define SCTP_SET_PEER_PRIMARY_ADDR SCTP_SET_PEER_PRIMARY_ADDR 76 SCTP_PRIMARY_ADDR, 77 #define SCTP_PRIMARY_ADDR SCTP_PRIMARY_ADDR 78 SCTP_ADAPTION_LAYER, 79 #define SCTP_ADAPTION_LAYER SCTP_ADAPTION_LAYER 80 SCTP_DISABLE_FRAGMENTS, 81 #define SCTP_DISABLE_FRAGMENTS SCTP_DISABLE_FRAGMENTS 82 SCTP_PEER_ADDR_PARAMS, 83 #define SCTP_PEER_ADDR_PARAMS SCTP_PEER_ADDR_PARAMS 84 SCTP_DEFAULT_SEND_PARAM, 85 #define SCTP_DEFAULT_SEND_PARAM SCTP_DEFAULT_SEND_PARAM 86 SCTP_EVENTS, 87 #define SCTP_EVENTS SCTP_EVENTS 88 SCTP_I_WANT_MAPPED_V4_ADDR, /* Turn on/off mapped v4 addresses */ 89 #define SCTP_I_WANT_MAPPED_V4_ADDR SCTP_I_WANT_MAPPED_V4_ADDR 90 SCTP_MAXSEG, /* Get/set maximum fragment. */ 91 #define SCTP_MAXSEG SCTP_MAXSEG 92 SCTP_STATUS, 93 #define SCTP_STATUS SCTP_STATUS 94 SCTP_GET_PEER_ADDR_INFO, 95 #define SCTP_GET_PEER_ADDR_INFO SCTP_GET_PEER_ADDR_INFO 96 97 /* Internal Socket Options. Some of the sctp library functions are 98 * implemented using these socket options. 99 */ 100 SCTP_SOCKOPT_BINDX_ADD = 100,/* BINDX requests for adding addresses. */ 101 #define SCTP_SOCKOPT_BINDX_ADD SCTP_SOCKOPT_BINDX_ADD 102 SCTP_SOCKOPT_BINDX_REM, /* BINDX requests for removing addresses. */ 103 #define SCTP_SOCKOPT_BINDX_REM SCTP_SOCKOPT_BINDX_REM 104 SCTP_SOCKOPT_PEELOFF, /* peel off association. */ 105 #define SCTP_SOCKOPT_PEELOFF SCTP_SOCKOPT_PEELOFF 106 SCTP_GET_PEER_ADDRS_NUM, /* Get number of peer addresss. */ 107 #define SCTP_GET_PEER_ADDRS_NUM SCTP_GET_PEER_ADDRS_NUM 108 SCTP_GET_PEER_ADDRS, /* Get all peer addresss. */ 109 #define SCTP_GET_PEER_ADDRS SCTP_GET_PEER_ADDRS 110 SCTP_GET_LOCAL_ADDRS_NUM, /* Get number of local addresss. */ 111 #define SCTP_GET_LOCAL_ADDRS_NUM SCTP_GET_LOCAL_ADDRS_NUM 112 SCTP_GET_LOCAL_ADDRS, /* Get all local addresss. */ 113 #define SCTP_GET_LOCAL_ADDRS SCTP_GET_LOCAL_ADDRS 114 }; 115 116 /* 117 * 5.2.1 SCTP Initiation Structure (SCTP_INIT) 118 * 119 * This cmsghdr structure provides information for initializing new 120 * SCTP associations with sendmsg(). The SCTP_INITMSG socket option 121 * uses this same data structure. This structure is not used for 122 * recvmsg(). 123 * 124 * cmsg_level cmsg_type cmsg_data[] 125 * ------------ ------------ ---------------------- 126 * IPPROTO_SCTP SCTP_INIT struct sctp_initmsg 127 * 128 */ 129 struct sctp_initmsg { 130 __u16 sinit_num_ostreams; 131 __u16 sinit_max_instreams; 132 __u16 sinit_max_attempts; 133 __u16 sinit_max_init_timeo; 134 }; 135 136 /* 137 * 5.2.2 SCTP Header Information Structure (SCTP_SNDRCV) 138 * 139 * This cmsghdr structure specifies SCTP options for sendmsg() and 140 * describes SCTP header information about a received message through 141 * recvmsg(). 142 * 143 * cmsg_level cmsg_type cmsg_data[] 144 * ------------ ------------ ---------------------- 145 * IPPROTO_SCTP SCTP_SNDRCV struct sctp_sndrcvinfo 146 * 147 */ 148 struct sctp_sndrcvinfo { 149 __u16 sinfo_stream; 150 __u16 sinfo_ssn; 151 __u16 sinfo_flags; 152 __u32 sinfo_ppid; 153 __u32 sinfo_context; 154 __u32 sinfo_timetolive; 155 __u32 sinfo_tsn; 156 __u32 sinfo_cumtsn; 157 sctp_assoc_t sinfo_assoc_id; 158 }; 159 160 /* 161 * sinfo_flags: 16 bits (unsigned integer) 162 * 163 * This field may contain any of the following flags and is composed of 164 * a bitwise OR of these values. 165 */ 166 167 enum sctp_sinfo_flags { 168 MSG_UNORDERED = 1, /* Send/receive message unordered. */ 169 MSG_ADDR_OVER = 2, /* Override the primary destination. */ 170 MSG_ABORT=4, /* Send an ABORT message to the peer. */ 171 /* MSG_EOF is already defined per socket.h */ 172 }; 173 174 175 typedef union { 176 __u8 raw; 177 struct sctp_initmsg init; 178 struct sctp_sndrcvinfo sndrcv; 179 } sctp_cmsg_data_t; 180 181 /* These are cmsg_types. */ 182 typedef enum sctp_cmsg_type { 183 SCTP_INIT, /* 5.2.1 SCTP Initiation Structure */ 184 SCTP_SNDRCV, /* 5.2.2 SCTP Header Information Structure */ 185 } sctp_cmsg_t; 186 187 188 /* 189 * 5.3.1.1 SCTP_ASSOC_CHANGE 190 * 191 * Communication notifications inform the ULP that an SCTP association 192 * has either begun or ended. The identifier for a new association is 193 * provided by this notificaion. The notification information has the 194 * following format: 195 * 196 */ 197 struct sctp_assoc_change { 198 __u16 sac_type; 199 __u16 sac_flags; 200 __u32 sac_length; 201 __u16 sac_state; 202 __u16 sac_error; 203 __u16 sac_outbound_streams; 204 __u16 sac_inbound_streams; 205 sctp_assoc_t sac_assoc_id; 206 }; 207 208 /* 209 * sac_state: 32 bits (signed integer) 210 * 211 * This field holds one of a number of values that communicate the 212 * event that happened to the association. They include: 213 * 214 * Note: The following state names deviate from the API draft as 215 * the names clash too easily with other kernel symbols. 216 */ 217 enum sctp_sac_state { 218 SCTP_COMM_UP, 219 SCTP_COMM_LOST, 220 SCTP_RESTART, 221 SCTP_SHUTDOWN_COMP, 222 SCTP_CANT_STR_ASSOC, 223 }; 224 225 /* 226 * 5.3.1.2 SCTP_PEER_ADDR_CHANGE 227 * 228 * When a destination address on a multi-homed peer encounters a change 229 * an interface details event is sent. The information has the 230 * following structure: 231 */ 232 struct sctp_paddr_change { 233 __u16 spc_type; 234 __u16 spc_flags; 235 __u32 spc_length; 236 struct sockaddr_storage spc_aaddr; 237 int spc_state; 238 int spc_error; 239 sctp_assoc_t spc_assoc_id; 240 }; 241 242 /* 243 * spc_state: 32 bits (signed integer) 244 * 245 * This field holds one of a number of values that communicate the 246 * event that happened to the address. They include: 247 */ 248 enum sctp_spc_state { 249 SCTP_ADDR_AVAILABLE, 250 SCTP_ADDR_UNREACHABLE, 251 SCTP_ADDR_REMOVED, 252 SCTP_ADDR_ADDED, 253 SCTP_ADDR_MADE_PRIM, 254 }; 255 256 257 /* 258 * 5.3.1.3 SCTP_REMOTE_ERROR 259 * 260 * A remote peer may send an Operational Error message to its peer. 261 * This message indicates a variety of error conditions on an 262 * association. The entire error TLV as it appears on the wire is 263 * included in a SCTP_REMOTE_ERROR event. Please refer to the SCTP 264 * specification [SCTP] and any extensions for a list of possible 265 * error formats. SCTP error TLVs have the format: 266 */ 267 struct sctp_remote_error { 268 __u16 sre_type; 269 __u16 sre_flags; 270 __u32 sre_length; 271 __u16 sre_error; 272 sctp_assoc_t sre_assoc_id; 273 __u8 sre_data[0]; 274 }; 275 276 277 /* 278 * 5.3.1.4 SCTP_SEND_FAILED 279 * 280 * If SCTP cannot deliver a message it may return the message as a 281 * notification. 282 */ 283 struct sctp_send_failed { 284 __u16 ssf_type; 285 __u16 ssf_flags; 286 __u32 ssf_length; 287 __u32 ssf_error; 288 struct sctp_sndrcvinfo ssf_info; 289 sctp_assoc_t ssf_assoc_id; 290 __u8 ssf_data[0]; 291 }; 292 293 /* 294 * ssf_flags: 16 bits (unsigned integer) 295 * 296 * The flag value will take one of the following values 297 * 298 * SCTP_DATA_UNSENT - Indicates that the data was never put on 299 * the wire. 300 * 301 * SCTP_DATA_SENT - Indicates that the data was put on the wire. 302 * Note that this does not necessarily mean that the 303 * data was (or was not) successfully delivered. 304 */ 305 enum sctp_ssf_flags { 306 SCTP_DATA_UNSENT, 307 SCTP_DATA_SENT, 308 }; 309 310 /* 311 * 5.3.1.5 SCTP_SHUTDOWN_EVENT 312 * 313 * When a peer sends a SHUTDOWN, SCTP delivers this notification to 314 * inform the application that it should cease sending data. 315 */ 316 struct sctp_shutdown_event { 317 __u16 sse_type; 318 __u16 sse_flags; 319 __u32 sse_length; 320 sctp_assoc_t sse_assoc_id; 321 }; 322 323 /* 324 * 5.3.1.6 SCTP_ADAPTION_INDICATION 325 * 326 * When a peer sends a Adaption Layer Indication parameter , SCTP 327 * delivers this notification to inform the application 328 * that of the peers requested adaption layer. 329 */ 330 struct sctp_adaption_event { 331 __u16 sai_type; 332 __u16 sai_flags; 333 __u32 sai_length; 334 __u32 sai_adaption_ind; 335 sctp_assoc_t sai_assoc_id; 336 }; 337 338 /* 339 * 5.3.1.7 SCTP_PARTIAL_DELIVERY_EVENT 340 * 341 * When a reciever is engaged in a partial delivery of a 342 * message this notification will be used to inidicate 343 * various events. 344 */ 345 struct sctp_pdapi_event { 346 __u16 pdapi_type; 347 __u16 pdapi_flags; 348 __u32 pdapi_length; 349 __u32 pdapi_indication; 350 sctp_assoc_t pdapi_assoc_id; 351 }; 352 353 enum { SCTP_PARTIAL_DELIVERY_ABORTED=0, }; 354 355 /* 356 * Described in Section 7.3 357 * Ancillary Data and Notification Interest Options 358 */ 359 struct sctp_event_subscribe { 360 __u8 sctp_data_io_event; 361 __u8 sctp_association_event; 362 __u8 sctp_address_event; 363 __u8 sctp_send_failure_event; 364 __u8 sctp_peer_error_event; 365 __u8 sctp_shutdown_event; 366 __u8 sctp_partial_delivery_event; 367 __u8 sctp_adaption_layer_event; 368 }; 369 370 /* 371 * 5.3.1 SCTP Notification Structure 372 * 373 * The notification structure is defined as the union of all 374 * notification types. 375 * 376 */ 377 union sctp_notification { 378 struct { 379 __u16 sn_type; /* Notification type. */ 380 __u16 sn_flags; 381 __u32 sn_length; 382 } sn_header; 383 struct sctp_assoc_change sn_assoc_change; 384 struct sctp_paddr_change sn_paddr_change; 385 struct sctp_remote_error sn_remote_error; 386 struct sctp_send_failed sn_send_failed; 387 struct sctp_shutdown_event sn_shutdown_event; 388 struct sctp_adaption_event sn_adaption_event; 389 struct sctp_pdapi_event sn_pdapi_event; 390 }; 391 392 /* Section 5.3.1 393 * All standard values for sn_type flags are greater than 2^15. 394 * Values from 2^15 and down are reserved. 395 */ 396 397 enum sctp_sn_type { 398 SCTP_SN_TYPE_BASE = (1<<15), 399 SCTP_ASSOC_CHANGE, 400 SCTP_PEER_ADDR_CHANGE, 401 SCTP_SEND_FAILED, 402 SCTP_REMOTE_ERROR, 403 SCTP_SHUTDOWN_EVENT, 404 SCTP_PARTIAL_DELIVERY_EVENT, 405 SCTP_ADAPTION_INDICATION, 406 }; 407 408 /* Notification error codes used to fill up the error fields in some 409 * notifications. 410 * SCTP_PEER_ADDRESS_CHAGE : spc_error 411 * SCTP_ASSOC_CHANGE : sac_error 412 * These names should be potentially included in the draft 04 of the SCTP 413 * sockets API specification. 414 */ 415 typedef enum sctp_sn_error { 416 SCTP_FAILED_THRESHOLD, 417 SCTP_RECEIVED_SACK, 418 SCTP_HEARTBEAT_SUCCESS, 419 SCTP_RESPONSE_TO_USER_REQ, 420 SCTP_INTERNAL_ERROR, 421 SCTP_SHUTDOWN_GUARD_EXPIRES, 422 SCTP_PEER_FAULTY, 423 } sctp_sn_error_t; 424 425 /* 426 * 7.1.1 Retransmission Timeout Parameters (SCTP_RTOINFO) 427 * 428 * The protocol parameters used to initialize and bound retransmission 429 * timeout (RTO) are tunable. See [SCTP] for more information on how 430 * these parameters are used in RTO calculation. 431 */ 432 struct sctp_rtoinfo { 433 sctp_assoc_t srto_assoc_id; 434 __u32 srto_initial; 435 __u32 srto_max; 436 __u32 srto_min; 437 }; 438 439 /* 440 * 7.1.2 Association Parameters (SCTP_ASSOCINFO) 441 * 442 * This option is used to both examine and set various association and 443 * endpoint parameters. 444 */ 445 struct sctp_assocparams { 446 sctp_assoc_t sasoc_assoc_id; 447 __u16 sasoc_asocmaxrxt; 448 __u16 sasoc_number_peer_destinations; 449 __u32 sasoc_peer_rwnd; 450 __u32 sasoc_local_rwnd; 451 __u32 sasoc_cookie_life; 452 }; 453 454 /* 455 * 7.1.9 Set Peer Primary Address (SCTP_SET_PEER_PRIMARY_ADDR) 456 * 457 * Requests that the peer mark the enclosed address as the association 458 * primary. The enclosed address must be one of the association's 459 * locally bound addresses. The following structure is used to make a 460 * set primary request: 461 */ 462 struct sctp_setpeerprim { 463 sctp_assoc_t sspp_assoc_id; 464 struct sockaddr_storage sspp_addr; 465 }; 466 467 /* 468 * 7.1.10 Set Primary Address (SCTP_PRIMARY_ADDR) 469 * 470 * Requests that the local SCTP stack use the enclosed peer address as 471 * the association primary. The enclosed address must be one of the 472 * association peer's addresses. The following structure is used to 473 * make a set peer primary request: 474 */ 475 struct sctp_prim { 476 sctp_assoc_t ssp_assoc_id; 477 struct sockaddr_storage ssp_addr; 478 }; 479 480 /* 481 * 7.1.11 Set Adaption Layer Indicator (SCTP_ADAPTION_LAYER) 482 * 483 * Requests that the local endpoint set the specified Adaption Layer 484 * Indication parameter for all future INIT and INIT-ACK exchanges. 485 */ 486 struct sctp_setadaption { 487 __u32 ssb_adaption_ind; 488 }; 489 490 /* 491 * 7.1.13 Peer Address Parameters (SCTP_PEER_ADDR_PARAMS) 492 * 493 * Applications can enable or disable heartbeats for any peer address 494 * of an association, modify an address's heartbeat interval, force a 495 * heartbeat to be sent immediately, and adjust the address's maximum 496 * number of retransmissions sent before an address is considered 497 * unreachable. The following structure is used to access and modify an 498 * address's parameters: 499 */ 500 struct sctp_paddrparams { 501 sctp_assoc_t spp_assoc_id; 502 struct sockaddr_storage spp_address; 503 __u32 spp_hbinterval; 504 __u16 spp_pathmaxrxt; 505 }; 506 507 /* 508 * 7.2.2 Peer Address Information 509 * 510 * Applications can retrieve information about a specific peer address 511 * of an association, including its reachability state, congestion 512 * window, and retransmission timer values. This information is 513 * read-only. The following structure is used to access this 514 * information: 515 */ 516 struct sctp_paddrinfo { 517 sctp_assoc_t spinfo_assoc_id; 518 struct sockaddr_storage spinfo_address; 519 __s32 spinfo_state; 520 __u32 spinfo_cwnd; 521 __u32 spinfo_srtt; 522 __u32 spinfo_rto; 523 __u32 spinfo_mtu; 524 }; 525 526 /* Peer addresses's state. */ 527 enum sctp_spinfo_state { 528 SCTP_INACTIVE, 529 SCTP_ACTIVE, 530 }; 531 532 /* 533 * 7.2.1 Association Status (SCTP_STATUS) 534 * 535 * Applications can retrieve current status information about an 536 * association, including association state, peer receiver window size, 537 * number of unacked data chunks, and number of data chunks pending 538 * receipt. This information is read-only. The following structure is 539 * used to access this information: 540 */ 541 struct sctp_status { 542 sctp_assoc_t sstat_assoc_id; 543 __s32 sstat_state; 544 __u32 sstat_rwnd; 545 __u16 sstat_unackdata; 546 __u16 sstat_penddata; 547 __u16 sstat_instrms; 548 __u16 sstat_outstrms; 549 __u32 sstat_fragmentation_point; 550 struct sctp_paddrinfo sstat_primary; 551 }; 552 553 /* 554 * 8.3, 8.5 get all peer/local addresses in an association. 555 * This parameter struct is used by SCTP_GET_PEER_ADDRS and 556 * SCTP_GET_LOCAL_ADDRS socket options used internally to implement 557 * sctp_getpaddrs() and sctp_getladdrs() API. 558 */ 559 struct sctp_getaddrs { 560 sctp_assoc_t assoc_id; 561 int addr_num; 562 struct sockaddr *addrs; 563 }; 564 565 /* These are bit fields for msghdr->msg_flags. See section 5.1. */ 566 /* On user space Linux, these live in <bits/socket.h> as an enum. */ 567 enum sctp_msg_flags { 568 MSG_NOTIFICATION = 0x8000, 569 #define MSG_NOTIFICATION MSG_NOTIFICATION 570 }; 571 572 /* 573 * 8.1 sctp_bindx() 574 * 575 * The flags parameter is formed from the bitwise OR of zero or more of the 576 * following currently defined flags: 577 */ 578 #define SCTP_BINDX_ADD_ADDR 0x01 579 #define SCTP_BINDX_REM_ADDR 0x02 580 581 /* This is the structure that is passed as an argument(optval) to 582 * getsockopt(SCTP_SOCKOPT_PEELOFF). 583 */ 584 typedef struct { 585 sctp_assoc_t associd; 586 int sd; 587 } sctp_peeloff_arg_t; 588 589 #endif /* __net_sctp_user_h__ */ 590