BIO_s_dgram_pair.3ossl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "BIO_S_DGRAM_PAIR 3ossl"
  58. .TH BIO_S_DGRAM_PAIR 3ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. BIO_s_dgram_pair, BIO_new_bio_dgram_pair, BIO_dgram_set_no_trunc,
  65. BIO_dgram_get_no_trunc, BIO_dgram_get_effective_caps, BIO_dgram_get_caps,
  66. BIO_dgram_set_caps, BIO_dgram_set_mtu, BIO_dgram_get_mtu \- datagram pair BIO
  67. .SH SYNOPSIS
  68. .IX Header "SYNOPSIS"
  69. .Vb 1
  70. \& #include <openssl/bio.h>
  71. \&
  72. \& const BIO_METHOD *BIO_s_dgram_pair(void);
  73. \&
  74. \& int BIO_new_bio_dgram_pair(BIO **bio1, size_t writebuf1,
  75. \& BIO **bio2, size_t writebuf2);
  76. \& int BIO_dgram_set_no_trunc(BIO *bio, int enable);
  77. \& int BIO_dgram_get_no_trunc(BIO *bio);
  78. \& uint32_t BIO_dgram_get_effective_caps(BIO *bio);
  79. \& uint32_t BIO_dgram_get_caps(BIO *bio);
  80. \& int BIO_dgram_set_caps(BIO *bio, uint32_t caps);
  81. \& int BIO_dgram_set_mtu(BIO *bio, unsigned int mtu);
  82. \& unsigned int BIO_dgram_get_mtu(BIO *bio);
  83. .Ve
  84. .SH DESCRIPTION
  85. .IX Header "DESCRIPTION"
  86. \&\fBBIO_s_dgram_pair()\fR returns the method for a BIO datagram pair. A BIO datagram
  87. pair is similar to a BIO pair (see \fBBIO_s_bio\fR\|(3)) but has datagram semantics.
  88. Broadly, this means that the length of the buffer passed to a write call will
  89. match that retrieved by a read call. If the buffer passed to a read call is too
  90. short, the datagram is truncated or the read fails, depending on how the BIO is
  91. configured.
  92. .PP
  93. The BIO datagram pair attaches certain metadata to each write, such as source
  94. and destination addresses. This information may be retrieved on read.
  95. .PP
  96. A typical application of a BIO datagram pair is to allow an application to keep
  97. all datagram network I/O requested by libssl under application control.
  98. .PP
  99. The BIO datagram pair is designed to support multithreaded use where certain
  100. restrictions are observed; see THREADING.
  101. .PP
  102. The BIO datagram pair allows each half of a pair to signal to the other half
  103. whether they support certain capabilities; see CAPABILITY INDICATION.
  104. .PP
  105. \&\fBBIO_new_bio_dgram_pair()\fR combines the calls to \fBBIO_new\fR\|(3),
  106. \&\fBBIO_make_bio_pair\fR\|(3) and \fBBIO_set_write_buf_size\fR\|(3) to create a connected
  107. pair of BIOs \fBbio1\fR, \fBbio2\fR with write buffer sizes \fBwritebuf1\fR and
  108. \&\fBwritebuf2\fR. If either size is zero then the default size is used.
  109. .PP
  110. \&\fBBIO_make_bio_pair\fR\|(3) may be used to join two datagram pair BIOs into a pair.
  111. The two BIOs must both use the method returned by \fBBIO_s_dgram_pair()\fR and neither
  112. of the BIOs may currently be associated in a pair.
  113. .PP
  114. \&\fBBIO_destroy_bio_pair\fR\|(3) destroys the association between two connected BIOs.
  115. Freeing either half of the pair will automatically destroy the association.
  116. .PP
  117. \&\fBBIO_reset\fR\|(3) clears any data in the write buffer of the given BIO. This means
  118. that the opposite BIO in the pair will no longer have any data waiting to be
  119. read.
  120. .PP
  121. The BIO maintains a fixed size internal write buffer. When the buffer is full,
  122. further writes will fail until the buffer is drained via calls to
  123. \&\fBBIO_read\fR\|(3). The size of the buffer can be changed using
  124. \&\fBBIO_set_write_buf_size\fR\|(3) and queried using \fBBIO_get_write_buf_size\fR\|(3).
  125. .PP
  126. Note that the write buffer is partially consumed by metadata stored internally
  127. which is attached to each datagram, such as source and destination addresses.
  128. The size of this overhead is undefined and may change between releases.
  129. .PP
  130. The standard \fBBIO_ctrl_pending\fR\|(3) call has modified behaviour and returns the
  131. size of the next datagram waiting to be read in bytes. An application can use
  132. this function to ensure it provides an adequate buffer to a subsequent read
  133. call. If no datagram is waiting to be read, zero is returned.
  134. .PP
  135. This BIO does not support sending or receiving zero-length datagrams. Passing a
  136. zero-length buffer to BIO_write is treated as a no-op.
  137. .PP
  138. \&\fBBIO_eof\fR\|(3) returns 1 only if the given BIO datagram pair BIO is not currently
  139. connected to a peer BIO.
  140. .PP
  141. \&\fBBIO_get_write_guarantee\fR\|(3) and \fBBIO_ctrl_get_write_guarantee\fR\|(3) return how
  142. large a datagram the next call to \fBBIO_write\fR\|(3) can accept. If there is not
  143. enough space in the write buffer to accept another datagram equal in size to the
  144. configured MTU, zero is returned (see below). This is intended to avoid a
  145. situation where an application attempts to read a datagram from a network
  146. intending to write it to a BIO datagram pair, but where the received datagram
  147. ends up being too large to write to the BIO datagram pair.
  148. .PP
  149. \&\fBBIO_dgram_set_no_trunc()\fR and \fBBIO_ctrl_get_no_trunc()\fR set and retrieve the
  150. truncation mode for the given half of a BIO datagram pair. When no-truncate mode
  151. is enabled, \fBBIO_read()\fR will fail if the buffer provided is inadequate to hold
  152. the next datagram to be read. If no-truncate mode is disabled (the default), the
  153. datagram will be silently truncated. This default behaviour maintains
  154. compatibility with the semantics of the Berkeley sockets API.
  155. .PP
  156. \&\fBBIO_dgram_set_mtu()\fR and \fBBIO_dgram_get_mtu()\fR may be used to set an informational
  157. MTU value on the BIO datagram pair. If \fBBIO_dgram_set_mtu()\fR is used on a BIO
  158. which is currently part of a BIO datagram pair, the MTU value is set on both
  159. halves of the pair. The value does not affect the operation of the BIO datagram
  160. pair (except for \fBBIO_get_write_guarantee()\fR; see above) but may be used by other
  161. code to determine a requested MTU. When a BIO datagram pair BIO is created, the
  162. MTU is set to an unspecified but valid value.
  163. .PP
  164. \&\fBBIO_flush\fR\|(3) is a no-op.
  165. .SH NOTES
  166. .IX Header "NOTES"
  167. The halves of a BIO datagram pair have independent lifetimes and must be
  168. separately freed.
  169. .SH THREADING
  170. .IX Header "THREADING"
  171. \&\fBBIO_recvmmsg\fR\|(3), \fBBIO_sendmmsg\fR\|(3), \fBBIO_read\fR\|(3), \fBBIO_write\fR\|(3),
  172. \&\fBBIO_pending\fR\|(3), \fBBIO_get_write_guarantee\fR\|(3) and \fBBIO_flush\fR\|(3) may be used
  173. by multiple threads simultaneously on the same BIO datagram pair. Specific
  174. \&\fBBIO_ctrl\fR\|(3) operations (namely BIO_CTRL_PENDING, BIO_CTRL_FLUSH and
  175. BIO_C_GET_WRITE_GUARANTEE) may also be used. Invoking any other BIO call, or any
  176. other \fBBIO_ctrl\fR\|(3) operation, on either half of a BIO datagram pair while any
  177. other BIO call is also in progress to either half of the same BIO datagram pair
  178. results in undefined behaviour.
  179. .SH "CAPABILITY INDICATION"
  180. .IX Header "CAPABILITY INDICATION"
  181. The BIO datagram pair can be used to enqueue datagrams which have source and
  182. destination addresses attached. It is important that the component consuming one
  183. side of a BIO datagram pair understand whether the other side of the pair will
  184. honour any source and destination addresses it attaches to each datagram. For
  185. example, if datagrams are queued with destination addresses set but simply read
  186. by simple calls to \fBBIO_read\fR\|(3), the destination addresses will be discarded.
  187. .PP
  188. Each half of a BIO datagram pair can have capability flags set on it which
  189. indicate whether source and destination addresses will be honoured by the reader
  190. and whether they will be provided by the writer. These capability flags should
  191. be set via a call to \fBBIO_dgram_set_caps()\fR, and these capabilities will be
  192. reflected in the value returned by \fBBIO_dgram_get_effective_caps()\fR on the
  193. opposite BIO. If necessary, the capability value previously set can be retrieved
  194. using \fBBIO_dgram_get_caps()\fR. Note that \fBBIO_dgram_set_caps()\fR on a given BIO
  195. controls the capabilities advertised to the peer, and
  196. \&\fBBIO_dgram_get_effective_caps()\fR on a given BIO determines the capabilities
  197. advertised by the peer of that BIO.
  198. .PP
  199. The following capabilities are available:
  200. .IP \fBBIO_DGRAM_CAP_HANDLES_SRC_ADDR\fR 4
  201. .IX Item "BIO_DGRAM_CAP_HANDLES_SRC_ADDR"
  202. The user of the datagram pair BIO promises to honour source addresses provided
  203. with datagrams written to the BIO pair.
  204. .IP \fBBIO_DGRAM_CAP_HANDLES_DST_ADDR\fR 4
  205. .IX Item "BIO_DGRAM_CAP_HANDLES_DST_ADDR"
  206. The user of the datagram pair BIO promises to honour destination addresses provided
  207. with datagrams written to the BIO pair.
  208. .IP \fBBIO_DGRAM_CAP_PROVIDES_SRC_ADDR\fR 4
  209. .IX Item "BIO_DGRAM_CAP_PROVIDES_SRC_ADDR"
  210. The user of the datagram pair BIO advertises the fact that it will provide source
  211. addressing information with future writes to the BIO pair, where available.
  212. .IP \fBBIO_DGRAM_CAP_PROVIDES_DST_ADDR\fR 4
  213. .IX Item "BIO_DGRAM_CAP_PROVIDES_DST_ADDR"
  214. The user of the datagram pair BIO advertises the fact that it will provide
  215. destination addressing information with future writes to the BIO pair, where
  216. available.
  217. .PP
  218. If a caller attempts to specify a destination address (for example, using
  219. \&\fBBIO_sendmmsg\fR\|(3)) and the peer has not advertised the
  220. \&\fBBIO_DGRAM_CAP_HANDLES_DST_ADDR\fR capability, the operation fails. Thus,
  221. capability negotiation is mandatory.
  222. .PP
  223. If a caller attempts to specify a source address when writing, or requests a
  224. destination address when receiving, and local address support has not been
  225. enabled, the operation fails; see \fBBIO_dgram_set_local_addr_enable\fR\|(3).
  226. .PP
  227. If a caller attempts to enable local address support using
  228. \&\fBBIO_dgram_set_local_addr_enable\fR\|(3) and \fBBIO_dgram_get_local_addr_cap\fR\|(3)
  229. does not return 1 (meaning that the peer has not advertised both the
  230. \&\fBBIO_DGRAM_CAP_HANDLES_SRC_ADDR\fR and the \fBBIO_DGRAM_CAP_PROVIDES_DST_ADDR\fR
  231. capability), the operation fails.
  232. .PP
  233. \&\fBBIO_DGRAM_CAP_PROVIDES_SRC_ADDR\fR and \fBBIO_DGRAM_CAP_PROVIDES_DST_ADDR\fR
  234. indicate that the application using that half of a BIO datagram pair promises to
  235. provide source and destination addresses respectively when writing datagrams to
  236. that half of the BIO datagram pair. However, these capability flags do not
  237. affect the behaviour of the BIO datagram pair.
  238. .SH "RETURN VALUES"
  239. .IX Header "RETURN VALUES"
  240. \&\fBBIO_new_bio_dgram_pair()\fR returns 1 on success, with the new BIOs available in
  241. \&\fBbio1\fR and \fBbio2\fR, or 0 on failure, with NULL pointers stored into the
  242. locations for \fBbio1\fR and \fBbio2\fR. Check the error stack for more information.
  243. .PP
  244. \&\fBBIO_dgram_set_no_trunc()\fR, \fBBIO_dgram_set_caps()\fR and \fBBIO_dgram_set_mtu()\fR return 1
  245. on success and 0 on failure.
  246. .PP
  247. \&\fBBIO_dgram_get_no_trunc()\fR returns 1 if no-truncate mode is enabled on a BIO, or 0
  248. if no-truncate mode is not enabled or not supported on a given BIO.
  249. .PP
  250. \&\fBBIO_dgram_get_effective_caps()\fR and \fBBIO_dgram_get_caps()\fR return zero if no
  251. capabilities are supported.
  252. .PP
  253. \&\fBBIO_dgram_get_mtu()\fR returns the MTU value configured on the BIO, or zero if the
  254. operation is not supported.
  255. .SH "SEE ALSO"
  256. .IX Header "SEE ALSO"
  257. \&\fBBIO_s_bio\fR\|(3), \fBbio\fR\|(7)
  258. .SH COPYRIGHT
  259. .IX Header "COPYRIGHT"
  260. Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
  261. .PP
  262. Licensed under the Apache License 2.0 (the "License"). You may not use
  263. this file except in compliance with the License. You can obtain a copy
  264. in the file LICENSE in the source distribution or at
  265. <https://www.openssl.org/source/license.html>.