BIO_s_dgram_pair.pod 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. =pod
  2. =head1 NAME
  3. BIO_s_dgram_pair, BIO_new_bio_dgram_pair, BIO_dgram_set_no_trunc,
  4. BIO_dgram_get_no_trunc, BIO_dgram_get_effective_caps, BIO_dgram_get_caps,
  5. BIO_dgram_set_caps, BIO_dgram_set_mtu, BIO_dgram_get_mtu - datagram pair BIO
  6. =head1 SYNOPSIS
  7. #include <openssl/bio.h>
  8. const BIO_METHOD *BIO_s_dgram_pair(void);
  9. int BIO_new_bio_dgram_pair(BIO **bio1, size_t writebuf1,
  10. BIO **bio2, size_t writebuf2);
  11. int BIO_dgram_set_no_trunc(BIO *bio, int enable);
  12. int BIO_dgram_get_no_trunc(BIO *bio);
  13. uint32_t BIO_dgram_get_effective_caps(BIO *bio);
  14. uint32_t BIO_dgram_get_caps(BIO *bio);
  15. int BIO_dgram_set_caps(BIO *bio, uint32_t caps);
  16. int BIO_dgram_set_mtu(BIO *bio, unsigned int mtu);
  17. unsigned int BIO_dgram_get_mtu(BIO *bio);
  18. =head1 DESCRIPTION
  19. BIO_s_dgram_pair() returns the method for a BIO datagram pair. A BIO datagram
  20. pair is similar to a BIO pair (see L<BIO_s_bio(3)>) but has datagram semantics.
  21. Broadly, this means that the length of the buffer passed to a write call will
  22. match that retrieved by a read call. If the buffer passed to a read call is too
  23. short, the datagram is truncated or the read fails, depending on how the BIO is
  24. configured.
  25. The BIO datagram pair attaches certain metadata to each write, such as source
  26. and destination addresses. This information may be retrieved on read.
  27. A typical application of a BIO datagram pair is to allow an application to keep
  28. all datagram network I/O requested by libssl under application control.
  29. The BIO datagram pair is designed to support multithreaded use where certain
  30. restrictions are observed; see THREADING.
  31. The BIO datagram pair allows each half of a pair to signal to the other half
  32. whether they support certain capabilities; see CAPABILITY INDICATION.
  33. BIO_new_bio_dgram_pair() combines the calls to L<BIO_new(3)>,
  34. L<BIO_make_bio_pair(3)> and L<BIO_set_write_buf_size(3)> to create a connected
  35. pair of BIOs B<bio1>, B<bio2> with write buffer sizes B<writebuf1> and
  36. B<writebuf2>. If either size is zero then the default size is used.
  37. L<BIO_make_bio_pair(3)> may be used to join two datagram pair BIOs into a pair.
  38. The two BIOs must both use the method returned by BIO_s_dgram_pair() and neither
  39. of the BIOs may currently be associated in a pair.
  40. L<BIO_destroy_bio_pair(3)> destroys the association between two connected BIOs.
  41. Freeing either half of the pair will automatically destroy the association.
  42. L<BIO_reset(3)> clears any data in the write buffer of the given BIO. This means
  43. that the opposite BIO in the pair will no longer have any data waiting to be
  44. read.
  45. The BIO maintains a fixed size internal write buffer. When the buffer is full,
  46. further writes will fail until the buffer is drained via calls to
  47. L<BIO_read(3)>. The size of the buffer can be changed using
  48. L<BIO_set_write_buf_size(3)> and queried using L<BIO_get_write_buf_size(3)>.
  49. Note that the write buffer is partially consumed by metadata stored internally
  50. which is attached to each datagram, such as source and destination addresses.
  51. The size of this overhead is undefined and may change between releases.
  52. The standard L<BIO_ctrl_pending(3)> call has modified behaviour and returns the
  53. size of the next datagram waiting to be read in bytes. An application can use
  54. this function to ensure it provides an adequate buffer to a subsequent read
  55. call. If no datagram is waiting to be read, zero is returned.
  56. This BIO does not support sending or receiving zero-length datagrams. Passing a
  57. zero-length buffer to BIO_write is treated as a no-op.
  58. L<BIO_eof(3)> returns 1 only if the given BIO datagram pair BIO is not currently
  59. connected to a peer BIO.
  60. L<BIO_get_write_guarantee(3)> and L<BIO_ctrl_get_write_guarantee(3)> return how
  61. large a datagram the next call to L<BIO_write(3)> can accept. If there is not
  62. enough space in the write buffer to accept another datagram equal in size to the
  63. configured MTU, zero is returned (see below). This is intended to avoid a
  64. situation where an application attempts to read a datagram from a network
  65. intending to write it to a BIO datagram pair, but where the received datagram
  66. ends up being too large to write to the BIO datagram pair.
  67. BIO_dgram_set_no_trunc() and BIO_ctrl_get_no_trunc() set and retrieve the
  68. truncation mode for the given half of a BIO datagram pair. When no-truncate mode
  69. is enabled, BIO_read() will fail if the buffer provided is inadequate to hold
  70. the next datagram to be read. If no-truncate mode is disabled (the default), the
  71. datagram will be silently truncated. This default behaviour maintains
  72. compatibility with the semantics of the Berkeley sockets API.
  73. BIO_dgram_set_mtu() and BIO_dgram_get_mtu() may be used to set an informational
  74. MTU value on the BIO datagram pair. If BIO_dgram_set_mtu() is used on a BIO
  75. which is currently part of a BIO datagram pair, the MTU value is set on both
  76. halves of the pair. The value does not affect the operation of the BIO datagram
  77. pair (except for BIO_get_write_guarantee(); see above) but may be used by other
  78. code to determine a requested MTU. When a BIO datagram pair BIO is created, the
  79. MTU is set to an unspecified but valid value.
  80. L<BIO_flush(3)> is a no-op.
  81. =head1 NOTES
  82. The halves of a BIO datagram pair have independent lifetimes and must be
  83. separately freed.
  84. =head1 THREADING
  85. L<BIO_recvmmsg(3)>, L<BIO_sendmmsg(3)>, L<BIO_read(3)>, L<BIO_write(3)>,
  86. L<BIO_pending(3)>, L<BIO_get_write_guarantee(3)> and L<BIO_flush(3)> may be used
  87. by multiple threads simultaneously on the same BIO datagram pair. Specific
  88. L<BIO_ctrl(3)> operations (namely BIO_CTRL_PENDING, BIO_CTRL_FLUSH and
  89. BIO_C_GET_WRITE_GUARANTEE) may also be used. Invoking any other BIO call, or any
  90. other L<BIO_ctrl(3)> operation, on either half of a BIO datagram pair while any
  91. other BIO call is also in progress to either half of the same BIO datagram pair
  92. results in undefined behaviour.
  93. =head1 CAPABILITY INDICATION
  94. The BIO datagram pair can be used to enqueue datagrams which have source and
  95. destination addresses attached. It is important that the component consuming one
  96. side of a BIO datagram pair understand whether the other side of the pair will
  97. honour any source and destination addresses it attaches to each datagram. For
  98. example, if datagrams are queued with destination addresses set but simply read
  99. by simple calls to L<BIO_read(3)>, the destination addresses will be discarded.
  100. Each half of a BIO datagram pair can have capability flags set on it which
  101. indicate whether source and destination addresses will be honoured by the reader
  102. and whether they will be provided by the writer. These capability flags should
  103. be set via a call to BIO_dgram_set_caps(), and these capabilities will be
  104. reflected in the value returned by BIO_dgram_get_effective_caps() on the
  105. opposite BIO. If necessary, the capability value previously set can be retrieved
  106. using BIO_dgram_get_caps(). Note that BIO_dgram_set_caps() on a given BIO
  107. controls the capabilities advertised to the peer, and
  108. BIO_dgram_get_effective_caps() on a given BIO determines the capabilities
  109. advertised by the peer of that BIO.
  110. The following capabilities are available:
  111. =over 4
  112. =item B<BIO_DGRAM_CAP_HANDLES_SRC_ADDR>
  113. The user of the datagram pair BIO promises to honour source addresses provided
  114. with datagrams written to the BIO pair.
  115. =item B<BIO_DGRAM_CAP_HANDLES_DST_ADDR>
  116. The user of the datagram pair BIO promises to honour destination addresses provided
  117. with datagrams written to the BIO pair.
  118. =item B<BIO_DGRAM_CAP_PROVIDES_SRC_ADDR>
  119. The user of the datagram pair BIO advertises the fact that it will provide source
  120. addressing information with future writes to the BIO pair, where available.
  121. =item B<BIO_DGRAM_CAP_PROVIDES_DST_ADDR>
  122. The user of the datagram pair BIO advertises the fact that it will provide
  123. destination addressing information with future writes to the BIO pair, where
  124. available.
  125. =back
  126. If a caller attempts to specify a destination address (for example, using
  127. L<BIO_sendmmsg(3)>) and the peer has not advertised the
  128. B<BIO_DGRAM_CAP_HANDLES_DST_ADDR> capability, the operation fails. Thus,
  129. capability negotiation is mandatory.
  130. If a caller attempts to specify a source address when writing, or requests a
  131. destination address when receiving, and local address support has not been
  132. enabled, the operation fails; see L<BIO_dgram_set_local_addr_enable(3)>.
  133. If a caller attempts to enable local address support using
  134. L<BIO_dgram_set_local_addr_enable(3)> and L<BIO_dgram_get_local_addr_cap(3)>
  135. does not return 1 (meaning that the peer has not advertised both the
  136. B<BIO_DGRAM_CAP_HANDLES_SRC_ADDR> and the B<BIO_DGRAM_CAP_PROVIDES_DST_ADDR>
  137. capability), the operation fails.
  138. B<BIO_DGRAM_CAP_PROVIDES_SRC_ADDR> and B<BIO_DGRAM_CAP_PROVIDES_DST_ADDR>
  139. indicate that the application using that half of a BIO datagram pair promises to
  140. provide source and destination addresses respectively when writing datagrams to
  141. that half of the BIO datagram pair. However, these capability flags do not
  142. affect the behaviour of the BIO datagram pair.
  143. =head1 RETURN VALUES
  144. BIO_new_bio_dgram_pair() returns 1 on success, with the new BIOs available in
  145. B<bio1> and B<bio2>, or 0 on failure, with NULL pointers stored into the
  146. locations for B<bio1> and B<bio2>. Check the error stack for more information.
  147. BIO_dgram_set_no_trunc(), BIO_dgram_set_caps() and BIO_dgram_set_mtu() return 1
  148. on success and 0 on failure.
  149. BIO_dgram_get_no_trunc() returns 1 if no-truncate mode is enabled on a BIO, or 0
  150. if no-truncate mode is not enabled or not supported on a given BIO.
  151. BIO_dgram_get_effective_caps() and BIO_dgram_get_caps() return zero if no
  152. capabilities are supported.
  153. BIO_dgram_get_mtu() returns the MTU value configured on the BIO, or zero if the
  154. operation is not supported.
  155. =head1 SEE ALSO
  156. L<BIO_s_bio(3)>, L<bio(7)>
  157. =head1 COPYRIGHT
  158. Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
  159. Licensed under the Apache License 2.0 (the "License"). You may not use
  160. this file except in compliance with the License. You can obtain a copy
  161. in the file LICENSE in the source distribution or at
  162. L<https://www.openssl.org/source/license.html>.
  163. =cut