BIO_sendmmsg.3ossl 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. .\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
  2. .\"
  3. .\" Standard preamble:
  4. .\" ========================================================================
  5. .de Sp \" Vertical space (when we can't use .PP)
  6. .if t .sp .5v
  7. .if n .sp
  8. ..
  9. .de Vb \" Begin verbatim text
  10. .ft CW
  11. .nf
  12. .ne \\$1
  13. ..
  14. .de Ve \" End verbatim text
  15. .ft R
  16. .fi
  17. ..
  18. .\" Set up some character translations and predefined strings. \*(-- will
  19. .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
  20. .\" double quote, and \*(R" will give a right double quote. \*(C+ will
  21. .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
  22. .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
  23. .\" nothing in troff, for use with C<>.
  24. .tr \(*W-
  25. .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
  26. .ie n \{\
  27. . ds -- \(*W-
  28. . ds PI pi
  29. . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
  30. . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
  31. . ds L" ""
  32. . ds R" ""
  33. . ds C` ""
  34. . ds C' ""
  35. 'br\}
  36. .el\{\
  37. . ds -- \|\(em\|
  38. . ds PI \(*p
  39. . ds L" ``
  40. . ds R" ''
  41. . ds C`
  42. . ds C'
  43. 'br\}
  44. .\"
  45. .\" Escape single quotes in literal strings from groff's Unicode transform.
  46. .ie \n(.g .ds Aq \(aq
  47. .el .ds Aq '
  48. .\"
  49. .\" If the F register is >0, we'll generate index entries on stderr for
  50. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  51. .\" entries marked with X<> in POD. Of course, you'll have to process the
  52. .\" output yourself in some meaningful fashion.
  53. .\"
  54. .\" Avoid warning from groff about undefined register 'F'.
  55. .de IX
  56. ..
  57. .nr rF 0
  58. .if \n(.g .if rF .nr rF 1
  59. .if (\n(rF:(\n(.g==0)) \{\
  60. . if \nF \{\
  61. . de IX
  62. . tm Index:\\$1\t\\n%\t"\\$2"
  63. ..
  64. . if !\nF==2 \{\
  65. . nr % 0
  66. . nr F 2
  67. . \}
  68. . \}
  69. .\}
  70. .rr rF
  71. .\"
  72. .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
  73. .\" Fear. Run. Save yourself. No user-serviceable parts.
  74. . \" fudge factors for nroff and troff
  75. .if n \{\
  76. . ds #H 0
  77. . ds #V .8m
  78. . ds #F .3m
  79. . ds #[ \f1
  80. . ds #] \fP
  81. .\}
  82. .if t \{\
  83. . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
  84. . ds #V .6m
  85. . ds #F 0
  86. . ds #[ \&
  87. . ds #] \&
  88. .\}
  89. . \" simple accents for nroff and troff
  90. .if n \{\
  91. . ds ' \&
  92. . ds ` \&
  93. . ds ^ \&
  94. . ds , \&
  95. . ds ~ ~
  96. . ds /
  97. .\}
  98. .if t \{\
  99. . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
  100. . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
  101. . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
  102. . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
  103. . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
  104. . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
  105. .\}
  106. . \" troff and (daisy-wheel) nroff accents
  107. .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
  108. .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
  109. .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
  110. .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
  111. .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
  112. .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
  113. .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
  114. .ds ae a\h'-(\w'a'u*4/10)'e
  115. .ds Ae A\h'-(\w'A'u*4/10)'E
  116. . \" corrections for vroff
  117. .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
  118. .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
  119. . \" for low resolution devices (crt and lpr)
  120. .if \n(.H>23 .if \n(.V>19 \
  121. \{\
  122. . ds : e
  123. . ds 8 ss
  124. . ds o a
  125. . ds d- d\h'-1'\(ga
  126. . ds D- D\h'-1'\(hy
  127. . ds th \o'bp'
  128. . ds Th \o'LP'
  129. . ds ae ae
  130. . ds Ae AE
  131. .\}
  132. .rm #[ #] #H #V #F C
  133. .\" ========================================================================
  134. .\"
  135. .IX Title "BIO_SENDMMSG 3ossl"
  136. .TH BIO_SENDMMSG 3ossl "2024-09-03" "3.3.2" "OpenSSL"
  137. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  138. .\" way too many mistakes in technical documents.
  139. .if n .ad l
  140. .nh
  141. .SH "NAME"
  142. BIO_sendmmsg, BIO_recvmmsg, BIO_dgram_set_local_addr_enable,
  143. BIO_dgram_get_local_addr_enable, BIO_dgram_get_local_addr_cap,
  144. BIO_err_is_non_fatal \- send and receive multiple datagrams in a single call
  145. .SH "SYNOPSIS"
  146. .IX Header "SYNOPSIS"
  147. .Vb 1
  148. \& #include <openssl/bio.h>
  149. \&
  150. \& typedef struct bio_msg_st {
  151. \& void *data;
  152. \& size_t data_len;
  153. \& BIO_ADDR *peer, *local;
  154. \& uint64_t flags;
  155. \& } BIO_MSG;
  156. \&
  157. \& int BIO_sendmmsg(BIO *b, BIO_MSG *msg,
  158. \& size_t stride, size_t num_msg, uint64_t flags,
  159. \& size_t *msgs_processed);
  160. \& int BIO_recvmmsg(BIO *b, BIO_MSG *msg,
  161. \& size_t stride, size_t num_msg, uint64_t flags,
  162. \& size_t *msgs_processed);
  163. \&
  164. \& int BIO_dgram_set_local_addr_enable(BIO *b, int enable);
  165. \& int BIO_dgram_get_local_addr_enable(BIO *b, int *enable);
  166. \& int BIO_dgram_get_local_addr_cap(BIO *b);
  167. \& int BIO_err_is_non_fatal(unsigned int errcode);
  168. .Ve
  169. .SH "DESCRIPTION"
  170. .IX Header "DESCRIPTION"
  171. \&\fBBIO_sendmmsg()\fR and \fBBIO_recvmmsg()\fR functions can be used to send and receive
  172. multiple messages in a single call to a \s-1BIO.\s0 They are analogous to \fBsendmmsg\fR\|(2)
  173. and \fBrecvmmsg\fR\|(2) on operating systems which provide those functions.
  174. .PP
  175. The \fB\s-1BIO_MSG\s0\fR structure provides a subset of the functionality of the \fBstruct
  176. msghdr\fR structure defined by \s-1POSIX.\s0 These functions accept an array of
  177. \&\fB\s-1BIO_MSG\s0\fR structures. On any particular invocation, these functions may process
  178. all of the passed structures, some of them, or none of them. This is indicated
  179. by the value stored in \fI*msgs_processed\fR, which expresses the number of
  180. messages processed.
  181. .PP
  182. The caller should set the \fIdata\fR member of a \fB\s-1BIO_MSG\s0\fR to a buffer containing
  183. the data to send, or to be filled with a received message. \fIdata_len\fR should be
  184. set to the size of the buffer in bytes. If the given \fB\s-1BIO_MSG\s0\fR is processed (in
  185. other words, if the integer returned by the function is greater than or equal to
  186. that \fB\s-1BIO_MSG\s0\fR's array index), \fIdata_len\fR will be modified to specify the
  187. actual amount of data sent or received.
  188. .PP
  189. The \fIflags\fR field of a \fB\s-1BIO_MSG\s0\fR provides input per-message flags to the
  190. invocation. If the invocation processes that \fB\s-1BIO_MSG\s0\fR, the \fIflags\fR field is
  191. written with output per-message flags, or zero if no such flags are applicable.
  192. .PP
  193. Currently, no input or output per-message flags are defined and this field
  194. should be set to zero before calling \fBBIO_sendmmsg()\fR or \fBBIO_recvmmsg()\fR.
  195. .PP
  196. The \fIflags\fR argument to \fBBIO_sendmmsg()\fR and \fBBIO_recvmmsg()\fR provides global
  197. flags which affect the entire invocation. No global flags are currently
  198. defined and this argument should be set to zero.
  199. .PP
  200. When these functions are used to send and receive datagrams, the \fIpeer\fR field
  201. of a \fB\s-1BIO_MSG\s0\fR allows the destination address of sent datagrams to be specified
  202. on a per-datagram basis, and the source address of received datagrams to be
  203. determined. The \fIpeer\fR field should be set to point to a \fB\s-1BIO_ADDR\s0\fR, which
  204. will be read by \fBBIO_sendmmsg()\fR and used as the destination address for sent
  205. datagrams, and written by \fBBIO_recvmmsg()\fR with the source address of received
  206. datagrams.
  207. .PP
  208. Similarly, the \fIlocal\fR field of a \fB\s-1BIO_MSG\s0\fR allows the source address of sent
  209. datagrams to be specified on a per-datagram basis, and the destination address
  210. of received datagrams to be determined. Unlike \fIpeer\fR, support for \fIlocal\fR
  211. must be explicitly enabled on a \fB\s-1BIO\s0\fR before it can be used; see
  212. \&\fBBIO_dgram_set_local_addr_enable()\fR. If \fIlocal\fR is non-NULL in a \fB\s-1BIO_MSG\s0\fR and
  213. support for \fIlocal\fR has not been enabled, processing of that \fB\s-1BIO_MSG\s0\fR fails.
  214. .PP
  215. \&\fIpeer\fR and \fIlocal\fR should be set to \s-1NULL\s0 if they are not required. Support for
  216. \&\fIlocal\fR may not be available on all platforms; on these platforms, these
  217. functions always fail if \fIlocal\fR is non-NULL.
  218. .PP
  219. If \fIlocal\fR is specified and local address support is enabled, but the operating
  220. system does not report a local address for a specific received message, the
  221. \&\fB\s-1BIO_ADDR\s0\fR it points to will be cleared (address family set to \f(CW\*(C`AF_UNSPEC\*(C'\fR).
  222. This is known to happen on Windows when a packet is received which was sent by
  223. the local system, regardless of whether the packet's destination address was the
  224. loopback address or the \s-1IP\s0 address of a local non-loopback interface. This is
  225. also known to happen on macOS in some circumstances, such as for packets sent
  226. before local address support was enabled for a receiving socket. These are
  227. OS-specific limitations. As such, users of this \s-1API\s0 using local address support
  228. should expect to sometimes receive a cleared local \fB\s-1BIO_ADDR\s0\fR instead of the
  229. correct value.
  230. .PP
  231. The \fIstride\fR argument must be set to \f(CW\*(C`sizeof(BIO_MSG)\*(C'\fR. This argument
  232. facilitates backwards compatibility if fields are added to \fB\s-1BIO_MSG\s0\fR. Callers
  233. must zero-initialize \fB\s-1BIO_MSG\s0\fR.
  234. .PP
  235. \&\fInum_msg\fR should be sent to the maximum number of messages to send or receive,
  236. which is also the length of the array pointed to by \fImsg\fR.
  237. .PP
  238. \&\fImsgs_processed\fR must be non-NULL and points to an integer written with the
  239. number of messages successfully processed; see the \s-1RETURN VALUES\s0 section for
  240. further discussion.
  241. .PP
  242. Unlike most \s-1BIO\s0 functions, these functions explicitly support multi-threaded
  243. use. Multiple concurrent writers and multiple concurrent readers of the same \s-1BIO\s0
  244. are permitted in any combination. As such, these functions do not clear, set, or
  245. otherwise modify \s-1BIO\s0 retry flags. The return value must be used to determine
  246. whether an operation should be retried; see below.
  247. .PP
  248. The support for concurrent use extends to \fBBIO_sendmmsg()\fR and \fBBIO_recvmmsg()\fR
  249. only, and no other function may be called on a given \s-1BIO\s0 while any call to
  250. \&\fBBIO_sendmmsg()\fR or \fBBIO_recvmmsg()\fR is in progress, or vice versa.
  251. .PP
  252. \&\fBBIO_dgram_set_local_addr_enable()\fR and \fBBIO_dgram_get_local_addr_enable()\fR control
  253. whether local address support is enabled. To enable local address support, call
  254. \&\fBBIO_dgram_set_local_addr_enable()\fR with an argument of 1. The call will fail if
  255. local address support is not available for the platform.
  256. \&\fBBIO_dgram_get_local_addr_enable()\fR retrieves the value set by
  257. \&\fBBIO_dgram_set_local_addr_enable()\fR.
  258. .PP
  259. \&\fBBIO_dgram_get_local_addr_cap()\fR determines if the \fB\s-1BIO\s0\fR is capable of supporting
  260. local addresses.
  261. .PP
  262. \&\fBBIO_err_is_non_fatal()\fR determines if a packed error code represents an error
  263. which is transient in nature.
  264. .SH "NOTES"
  265. .IX Header "NOTES"
  266. Some implementations of the \fBBIO_sendmmsg()\fR and \fBBIO_recvmmsg()\fR \s-1BIO\s0 methods might
  267. always process at most one message at a time, for example when OS-level
  268. functionality to transmit or receive multiple messages at a time is not
  269. available.
  270. .SH "RETURN VALUES"
  271. .IX Header "RETURN VALUES"
  272. On success, the functions \fBBIO_sendmmsg()\fR and \fBBIO_recvmmsg()\fR return 1 and write
  273. the number of messages successfully processed (which need not be nonzero) to
  274. \&\fImsgs_processed\fR. Where a positive value n is written to \fImsgs_processed\fR, all
  275. entries in the \fB\s-1BIO_MSG\s0\fR array from 0 through n\-1 inclusive have their
  276. \&\fIdata_len\fR and \fIflags\fR fields updated with the results of the operation on
  277. that message. If the call was to \fBBIO_recvmmsg()\fR and the \fIpeer\fR or \fIlocal\fR
  278. fields of that message are non-NULL, the \fB\s-1BIO_ADDR\s0\fR structures they point to
  279. are written with the relevant address.
  280. .PP
  281. On failure, the functions \fBBIO_sendmmsg()\fR and \fBBIO_recvmmsg()\fR return 0 and write
  282. zero to \fImsgs_processed\fR. Thus \fImsgs_processed\fR is always written regardless
  283. of the outcome of the function call.
  284. .PP
  285. If \fBBIO_sendmmsg()\fR and \fBBIO_recvmmsg()\fR fail, they always raise an \fB\s-1ERR_LIB_BIO\s0\fR
  286. error using \fBERR_raise\fR\|(3). Any error may be raised, but the following in
  287. particular may be noted:
  288. .IP "\fB\s-1BIO_R_LOCAL_ADDR_NOT_AVAILABLE\s0\fR" 2
  289. .IX Item "BIO_R_LOCAL_ADDR_NOT_AVAILABLE"
  290. The \fIlocal\fR field was set to a non-NULL value, but local address support is not
  291. available or not enabled on the \s-1BIO.\s0
  292. .IP "\fB\s-1BIO_R_PEER_ADDR_NOT_AVAILABLE\s0\fR" 2
  293. .IX Item "BIO_R_PEER_ADDR_NOT_AVAILABLE"
  294. The \fIpeer\fR field was set to a non-NULL value, but peer address support is not
  295. available on the \s-1BIO.\s0
  296. .IP "\fB\s-1BIO_R_UNSUPPORTED_METHOD\s0\fR" 2
  297. .IX Item "BIO_R_UNSUPPORTED_METHOD"
  298. The \fBBIO_sendmmsg()\fR or \fBBIO_recvmmsg()\fR method is not supported on the \s-1BIO.\s0
  299. .IP "\fB\s-1BIO_R_NON_FATAL\s0\fR" 2
  300. .IX Item "BIO_R_NON_FATAL"
  301. The call failed due to a transient, non-fatal error (for example, because the
  302. \&\s-1BIO\s0 is in nonblocking mode and the call would otherwise have blocked).
  303. .Sp
  304. Implementations of this interface which do not make system calls and thereby
  305. pass through system error codes using \fB\s-1ERR_LIB_SYS\s0\fR (for example, memory-based
  306. implementations) should issue this reason code to indicate a transient failure.
  307. However, users of this interface should not test for this reason code directly,
  308. as there are multiple possible packed error codes representing a transient
  309. failure; use \fBBIO_err_is_non_fatal()\fR instead (discussed below).
  310. .IP "Socket errors" 2
  311. .IX Item "Socket errors"
  312. OS-level socket errors are reported using an error with library code
  313. \&\fB\s-1ERR_LIB_SYS\s0\fR; for a packed error code \fBerrcode\fR where
  314. \&\f(CW\*(C`ERR_SYSTEM_ERROR(errcode) == 1\*(C'\fR, the OS-level socket error code can be
  315. retrieved using \f(CW\*(C`ERR_GET_REASON(errcode)\*(C'\fR. The packed error code can be
  316. retrieved by calling \fBERR_peek_last_error\fR\|(3) after the call to \fBBIO_sendmmsg()\fR
  317. or \fBBIO_recvmmsg()\fR returns 0.
  318. .IP "Non-fatal errors" 2
  319. .IX Item "Non-fatal errors"
  320. Whether an error is transient can be determined by passing the packed error code
  321. to \fBBIO_err_is_non_fatal()\fR. Callers should do this instead of testing the reason
  322. code directly, as there are many possible error codes which can indicate a
  323. transient error, many of which are system specific.
  324. .PP
  325. Third parties implementing custom BIOs supporting the \fBBIO_sendmmsg()\fR or
  326. \&\fBBIO_recvmmsg()\fR methods should note that it is a required part of the \s-1API\s0
  327. contract that an error is always raised when either of these functions return 0.
  328. .PP
  329. \&\fBBIO_dgram_set_local_addr_enable()\fR returns 1 if local address support was
  330. successfully enabled or disabled and 0 otherwise.
  331. .PP
  332. \&\fBBIO_dgram_get_local_addr_enable()\fR returns 1 if the local address support enable
  333. flag was successfully retrieved.
  334. .PP
  335. \&\fBBIO_dgram_get_local_addr_cap()\fR returns 1 if the \fB\s-1BIO\s0\fR can support local
  336. addresses.
  337. .PP
  338. \&\fBBIO_err_is_non_fatal()\fR returns 1 if the passed packed error code represents an
  339. error which is transient in nature.
  340. .SH "HISTORY"
  341. .IX Header "HISTORY"
  342. These functions were added in OpenSSL 3.2.
  343. .SH "COPYRIGHT"
  344. .IX Header "COPYRIGHT"
  345. Copyright 2000\-2023 The OpenSSL Project Authors. All Rights Reserved.
  346. .PP
  347. Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use
  348. this file except in compliance with the License. You can obtain a copy
  349. in the file \s-1LICENSE\s0 in the source distribution or at
  350. <https://www.openssl.org/source/license.html>.