summaryrefslogtreecommitdiff
path: root/static/freebsd/man3/sctp_send.3
blob: ce34a255457668d446252ed917a4d983b251ea2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
.\" Copyright (c) 1983, 1991, 1993
.\"	The Regents of the University of California.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
.\"    may be used to endorse or promote products derived from this software
.\"    without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd February 2, 2024
.Dt SCTP_SEND 3
.Os
.Sh NAME
.Nm sctp_send ,
.Nm sctp_sendx ,
.Nm sctp_sendv
.Nd send a message from an SCTP socket
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In sys/types.h
.In sys/socket.h
.In netinet/sctp.h
.Ft ssize_t
.Fo sctp_send
.Fa "int sd" "const void *msg" "size_t len"
.Fa "const struct sctp_sndrcvinfo *sinfo" "int flags"
.Fc
.Ft ssize_t
.Fo sctp_sendx
.Fa "int sd" "const void *msg" "size_t len" "struct sockaddr *addrs"
.Fa "int addrcnt" "const struct sctp_sndrcvinfo *sinfo" "int flags"
.Fc
.Ft ssize_t
.Fo sctp_sendv
.Fa "int sd" "const struct iovec *iov" "int iocnt" "struct sockaddr *addrs"
.Fa "int addrcnt" "void *info" "socklen_t infolen" "unsigned int infotype"
.Fa "int flags"
.Fc
.Sh DESCRIPTION
The
.Fn sctp_send
system call
is used to transmit a message to another SCTP endpoint.
The
.Fn sctp_sendx
function is used to specify multiple peer addresses when creating an implicit
association, as in
.Xr sctp_connectx 3 .
The
.Fn sctp_sendv
function is used to transmit a message whose data is gathered from the
provided I/O buffers.
.Pp
.Fn sctp_send
may be used to send data to an existing association for both
one-to-many (SOCK_SEQPACKET) and one-to-one (SOCK_STREAM) socket types.
The length of the message
.Fa msg
is given by
.Fa len .
If the message is too long to pass atomically through the
underlying protocol,
.Va errno
is set to
.Er EMSGSIZE ,
-1 is returned, and
the message is not transmitted.
.Pp
No indication of failure to deliver is implicit in a
.Fn sctp_send .
Locally detected errors are indicated by a return value of -1.
.Pp
If no space is available at the socket to hold
the message to be transmitted, then
.Fn sctp_send
normally blocks, unless the socket has been placed in
non-blocking I/O mode.
The
.Xr select 2
system call may be used to determine when it is possible to
send more data on one-to-one type (SOCK_STREAM) sockets.
.Pp
The
.Fa sinfo
structure is used to control various SCTP features
and has the following format:
.Bd -literal
struct sctp_sndrcvinfo {
	uint16_t sinfo_stream;  /* Stream sending to */
	uint16_t sinfo_ssn;     /* valid for recv only */
	uint16_t sinfo_flags;   /* flags to control sending */
	uint32_t sinfo_ppid;    /* ppid field */
	uint32_t sinfo_context; /* context field */
	uint32_t sinfo_timetolive; /* timetolive for PR-SCTP */
	uint32_t sinfo_tsn;        /* valid for recv only */
	uint32_t sinfo_cumtsn;     /* valid for recv only */
	sctp_assoc_t sinfo_assoc_id; /* The association id */
};
.Ed
.Pp
The
.Fa sinfo->sinfo_ppid
argument is an opaque 32 bit value that is passed transparently
through the stack to the peer endpoint.
It will be available on reception of a message (see
.Xr sctp_recvmsg 3 ) .
Note that the stack passes this value without regard to byte
order.
.Pp
The
.Fa sinfo->sinfo_flags
argument may include one or more of the following:
.Bd -literal
#define SCTP_EOF 	  0x0100	/* Start a shutdown procedures */
#define SCTP_ABORT	  0x0200	/* Send an ABORT to peer */
#define SCTP_UNORDERED 	  0x0400	/* Message is un-ordered */
#define SCTP_ADDR_OVER	  0x0800	/* Override the primary-address */
#define SCTP_SENDALL      0x1000	/* Send this on all associations */
					/* for the endpoint */
/* The lower byte is an enumeration of PR-SCTP policies */
#define SCTP_PR_SCTP_TTL  0x0001	/* Time based PR-SCTP */
#define SCTP_PR_SCTP_BUF  0x0002	/* Buffer based PR-SCTP */
#define SCTP_PR_SCTP_RTX  0x0003	/* Number of retransmissions based PR-SCTP */
.Ed
.Pp
The flag
.Dv SCTP_EOF
is used to instruct the SCTP stack to queue this message
and then start a graceful shutdown of the association.
All
remaining data in queue will be sent after which the association
will be shut down.
.Pp
.Dv SCTP_ABORT
is used to immediately terminate an association.
An abort
is sent to the peer and the local TCB is destroyed.
.Pp
.Dv SCTP_UNORDERED
is used to specify that the message being sent has no
specific order and should be delivered to the peer application
as soon as possible.
When this flag is absent messages
are delivered in order within the stream they are sent, but without
respect to order to peer streams.
.Pp
The flag
.Dv SCTP_ADDR_OVER
is used to specify that a specific address should be used.
Normally
SCTP will use only one of a multi-homed peers addresses as the primary
address to send to.
By default, no matter what the
.Fa to
argument is, this primary address is used to send data.
By specifying
this flag, the user is asking the stack to ignore the primary address
and instead use the specified address not only as a lookup mechanism
to find the association but also as the actual address to send to.
.Pp
For a one-to-many type (SOCK_SEQPACKET) socket the flag
.Dv SCTP_SENDALL
can be used as a convenient way to make one send call and have
all associations that are under the socket get a copy of the message.
Note that this mechanism is quite efficient and makes only one actual
copy of the data which is shared by all the associations for sending.
.Pp
The remaining flags are used for the partial reliability extension (RFC3758)
and will only be effective if the peer endpoint supports this extension.
This option specifies what local policy the local endpoint should use
in skipping data.
If none of these options are set, then data is
never skipped over.
.Pp
.Dv SCTP_PR_SCTP_TTL
is used to indicate that a time based lifetime is being applied
to the data.
The
.Fa sinfo->sinfo_timetolive
argument is then a number of milliseconds for which the data is
attempted to be transmitted.
If that many milliseconds elapse
and the peer has not acknowledged the data, the data will be
skipped and no longer transmitted.
Note that this policy does
not even assure that the data will ever be sent.
In times of a congestion
with large amounts of data being queued, the
.Fa sinfo->sinfo_timetolive
may expire before the first transmission is ever made.
.Pp
The
.Dv SCTP_PR_SCTP_BUF
based policy transforms the
.Fa sinfo->sinfo_timetolive
field into a total number of bytes allowed on the outbound
send queue.
If that number or more bytes are in queue, then
other buffer-based sends are looked to be removed and
skipped.
Note that this policy may also result in the data
never being sent if no buffer based sends are in queue and
the maximum specified by
.Fa timetolive
bytes is in queue.
.Pp
The
.Dv SCTP_PR_SCTP_RTX
policy transforms the
.Fa sinfo->sinfo_timetolive
into a number of retransmissions to allow.
This policy
always assures that at a minimum one send attempt is
made of the data.
After which no more than
.Fa sinfo->sinfo_timetolive
retransmissions will be made before the data is skipped.
.Pp
.Fa sinfo->sinfo_stream
is the SCTP stream that you wish to send the
message on.
Streams in SCTP are reliable (or partially reliable) flows of ordered
messages.
.Pp
The
.Fa sinfo->sinfo_assoc_id
field is used to
select the association to send to on a one-to-many socket.
For a one-to-one socket, this field is ignored.
.Pp
The
.Fa sinfo->sinfo_context
field is used only in the event the message cannot be sent.
This is an opaque
value that the stack retains and will give to the user when a failed send
is given if that notification is enabled (see
.Xr sctp 4 ) .
Normally a user process can use this value to index some application
specific data structure when a send cannot be fulfilled.
.Pp
The
.Fa flags
argument holds the same meaning and values as those found in
.Xr sendmsg 2
but is generally ignored by SCTP.
.Pp
The fields
.Fa sinfo->sinfo_ssn ,
.Fa sinfo->sinfo_tsn ,
and
.Fa sinfo->sinfo_cumtsn
are used only when receiving messages and are thus ignored by
.Fn sctp_send .
.Pp
The function
.Fn sctp_sendx
has the same properties as
.Fn sctp_send
with the additional arguments of an array of sockaddr structures
passed in.
With the
.Fa addrs
argument being given as an array of addresses to be sent to and
the
.Fa addrcnt
argument indicating how many socket addresses are in the passed
in array.
Note that all of the addresses will only be used
when an implicit association is being set up.
This allows the
user the equivalent behavior as doing a
.Fn sctp_connectx
followed by a
.Fn sctp_send
to the association.
Note that if the
.Fa sinfo->sinfo_assoc_id
field is 0, then the first address will be used to look up
the association in place of the association id.
If both
an address and an association id are specified, the association
id has priority.
.Pp
The function
.Fn sctp_sendv
works as
.Fn sctp_sendx ,
with two differences.
Firstly, the data to be written is passed as an array containing
.Vt iocnt
objects of type
.Vt struct iovec ,
which will be gathered for sending in the same manner as
.Xr writev 2 .
Secondly, the
.Fa info
argument is replaced by the tuple
.Fa sinfo ,
.Fa infolen ,
.Fa infotype ,
where
.Fa sinfo
is a pointer to a struct of size
.Fa infolen
whose type is indicated by the
.Fa infotype
argument.
.Pp
If no information is passed, set
.Fa infotype
to
.Va SCTP_SENDV_NOINFO .
.Fa sinfo
may be a null pointer.
.Pp
If
.Fa sinfo
points to a
.Vt struct sctp_sndinfo ,
set
.Fa infotype
to
.Va SCTP_SENDV_SNDINFO .
The
.Vt sctp_sndinfo
structure has the following format:
.Bd -literal
struct sctp_sndinfo {
	uint16_t snd_sid;		/* stream identifier */
	uint16_t snd_flags;		/* Flags */
	uint32_t snd_ppid;		/* ppid field */
	uint32_t snd_context;		/* context field */
	sctp_assoc_t snd_assoc_id;	/* association id */
};
.Ed
.Pp
The meaning of these fields is the same as in
.Vt struct sctp_sndrcvinfo ,
described above.
.Pp
If
.Fa sinfo
points to a
.Vt struct sctp_authinfo ,
set
.Fa infotype
to
.Va SCTP_SENDV_AUTHINFO .
The
.Vt sctp_authinfo
struct has the following format:
.Bd -literal
struct sctp_authinfo {
	uint16_t auth_keynumber;	/* Shared key identifier */
};
.Ed
.Pp
The
.Va auth_keynumber
field specifies the shared key identifier that will be used for sending the
message.
.Pp
If
.Fa sinfo
points to a
.Vt struct sctp_prinfo ,
set
.Fa infotype
to
.Va SCTP_SENDV_PRINFO .
The
.Vt sctp_prinfo
structure has the following format:
.Bd -literal
struct sctp_prinfo {
	uint16_t pr_policy;	/* PR-SCTP policy */
	uint32_t pr_value;	/* PR-SCTP Policy option */
};
.Ed
.Pp
The
.Va pr_policy
field should be set to either
.Va SCTP_PR_SCTP_NONE
to use reliable transmission (in which case the field
.Va pr_value
is ignored), or
.Va SCTP_PR_SCTP_TTL
to use RFC 3758 timed reliability, in which case the field
.Va pr_value
contains the lifetime in milliseconds.
.Pp
To pass two or more types in
.Fa sinfo ,
set
.Fa infotype
to
.Va SCTP_SENDV_SPA
and pass a pointer to a
.Vt struct sctp_sendv_spa
in
.Fa sinfo .
The
.Ft sctp_sendv_spa
structure has the following format:
.Bd -literal
struct sctp_sendv_spa {
	uint32_t sendv_flags;
	struct sctp_sndinfo sendv_sndinfo;
	struct sctp_prinfo sendv_prinfo;
	struct sctp_authinfo sendv_authinfo;
};
.Ed
.Pp
The
.Va sendv_flags
member should be set to the bitwise OR of the flags
.Va SCTP_SEND_SNDINFO_VALID ,
.Va SCTP_SEND_PRINFO_VALID ,
and
.Va SCTP_SEND_AUTHINFO_VALID
to indicate which fields of the struct contain valid data.
.Pp
If
.Fa infotype
is set to SCTP_SENDV_NOINFO, the
.Fa infolen
argument should be set to zero.
Otherwise,
.Fa infolen
should be set to the length of the data structure pointed to by
.Fa info .
.Sh RETURN VALUES
The call returns the number of characters sent, or -1
if an error occurred.
.Sh ERRORS
The
.Fn sctp_send
system call
fails if:
.Bl -tag -width Er
.It Bq Er EBADF
An invalid descriptor was specified.
.It Bq Er ENOTSOCK
The argument
.Fa s
is not a socket.
.It Bq Er EFAULT
An invalid user space address was specified for an argument.
.It Bq Er EMSGSIZE
The socket requires that message be sent atomically,
and the size of the message to be sent made this impossible.
.It Bq Er EAGAIN
The socket is marked non-blocking and the requested operation
would block.
.It Bq Er ENOBUFS
The system was unable to allocate an internal buffer.
The operation may succeed when buffers become available.
.It Bq Er ENOBUFS
The output queue for a network interface was full.
This generally indicates that the interface has stopped sending,
but may be caused by transient congestion.
.It Bq Er EHOSTUNREACH
The remote host was unreachable.
.It Bq Er ENOTCONN
On a one-to-one style socket no association exists.
.It Bq Er ECONNRESET
An abort was received by the stack while the user was
attempting to send data to the peer.
.It Bq Er ENOENT
On a one-to-many style socket no address is specified
so that the association cannot be located or the
SCTP_ABORT flag was specified on a non-existing association.
.It Bq Er EPIPE
The socket is unable to send anymore data
.Dv ( SBS_CANTSENDMORE
has been set on the socket).
This typically means that the socket
is not connected and is a one-to-one style socket.
.El
.Sh NOTES
The functions
.Fn sctp_send
and
.Fn sctp_sendx
are deprecated.
New applications should use
.Fn sctp_sendv .
.Sh SEE ALSO
.Xr getsockopt 2 ,
.Xr recv 2 ,
.Xr select 2 ,
.Xr sendmsg 2 ,
.Xr socket 2 ,
.Xr write 2 ,
.Xr sctp_connectx 3 ,
.Xr sctp_recvmsg 3 ,
.Xr sctp_sendmsg 3 ,
.Xr sctp 4
.Rs
.%A R. Stewart
.%A M. Tuexen
.%A K. Poon
.%A P. Lei
.%A V. Yasevich
.%T Sockets API Extensions for the Stream Control Transmission Protocol (SCTP)
.%R RFC 6458
.%D December 2011
.Re
.Sh STANDARDS
The functions described in this document conform to RFC 6458.
.Sh BUGS
Because
.Fn sctp_send
may have multiple associations under one endpoint, a
select on write will only work for a one-to-one style
socket.