summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorschwarze <>2022-12-23 15:59:34 +0000
committerschwarze <>2022-12-23 15:59:34 +0000
commit17d89e9441347d9dbad8083dcd4fea3874aee1f4 (patch)
tree640eae8c5ca218f1d27773bdf934b0546ab22991 /src/lib
parentbaf6f3e2cd652bf21f854e7aaad1e05f88077c25 (diff)
downloadopenbsd-17d89e9441347d9dbad8083dcd4fea3874aee1f4.tar.gz
openbsd-17d89e9441347d9dbad8083dcd4fea3874aee1f4.tar.bz2
openbsd-17d89e9441347d9dbad8083dcd4fea3874aee1f4.zip
new manual page BIO_s_datagram(3);
feedback and OK tb@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/man/BIO_new.35
-rw-r--r--src/lib/libcrypto/man/BIO_s_datagram.3572
-rw-r--r--src/lib/libcrypto/man/Makefile3
3 files changed, 577 insertions, 3 deletions
diff --git a/src/lib/libcrypto/man/BIO_new.3 b/src/lib/libcrypto/man/BIO_new.3
index 6c357054b9..f958149973 100644
--- a/src/lib/libcrypto/man/BIO_new.3
+++ b/src/lib/libcrypto/man/BIO_new.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: BIO_new.3,v 1.25 2022/12/22 21:05:48 schwarze Exp $ 1.\" $OpenBSD: BIO_new.3,v 1.26 2022/12/23 15:59:34 schwarze Exp $
2.\" full merge up to: 2.\" full merge up to:
3.\" OpenSSL man3/BIO_new.pod fb46be03 Feb 26 11:51:31 2016 +0000 3.\" OpenSSL man3/BIO_new.pod fb46be03 Feb 26 11:51:31 2016 +0000
4.\" OpenSSL man7/bio.pod 631c37be Dec 12 16:56:50 2017 +0100 4.\" OpenSSL man7/bio.pod 631c37be Dec 12 16:56:50 2017 +0100
@@ -52,7 +52,7 @@
52.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 52.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53.\" OF THE POSSIBILITY OF SUCH DAMAGE. 53.\" OF THE POSSIBILITY OF SUCH DAMAGE.
54.\" 54.\"
55.Dd $Mdocdate: December 22 2022 $ 55.Dd $Mdocdate: December 23 2022 $
56.Dt BIO_NEW 3 56.Dt BIO_NEW 3
57.Os 57.Os
58.Sh NAME 58.Sh NAME
@@ -250,6 +250,7 @@ Create a memory BIO:
250.Xr BIO_s_accept 3 , 250.Xr BIO_s_accept 3 ,
251.Xr BIO_s_bio 3 , 251.Xr BIO_s_bio 3 ,
252.Xr BIO_s_connect 3 , 252.Xr BIO_s_connect 3 ,
253.Xr BIO_s_datagram 3 ,
253.Xr BIO_s_fd 3 , 254.Xr BIO_s_fd 3 ,
254.Xr BIO_s_file 3 , 255.Xr BIO_s_file 3 ,
255.Xr BIO_s_mem 3 , 256.Xr BIO_s_mem 3 ,
diff --git a/src/lib/libcrypto/man/BIO_s_datagram.3 b/src/lib/libcrypto/man/BIO_s_datagram.3
new file mode 100644
index 0000000000..bef3c564fc
--- /dev/null
+++ b/src/lib/libcrypto/man/BIO_s_datagram.3
@@ -0,0 +1,572 @@
1.\" $OpenBSD: BIO_s_datagram.3,v 1.1 2022/12/23 15:59:34 schwarze Exp $
2.\"
3.\" Copyright (c) 2022 Ingo Schwarze <schwarze@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: December 23 2022 $
18.Dt BIO_S_DATAGRAM 3
19.Os
20.Sh NAME
21.Nm BIO_s_datagram ,
22.Nm BIO_new_dgram ,
23.Nm BIO_dgram_set_peer ,
24.Nm BIO_ctrl_dgram_connect ,
25.Nm BIO_dgram_get_peer ,
26.Nm BIO_ctrl_set_connected ,
27.Nm BIO_dgram_recv_timedout ,
28.Nm BIO_dgram_send_timedout ,
29.Nm BIO_dgram_non_fatal_error
30.Nd datagram socket BIO
31.Sh SYNOPSIS
32.In openssl/bio.h
33.Ft const BIO_METHOD *
34.Fn BIO_s_datagram void
35.Ft BIO *
36.Fo BIO_new_dgram
37.Fa "int fd"
38.Fa "int close_flag"
39.Fc
40.Ft int
41.Fo BIO_dgram_set_peer
42.Fa "BIO *b"
43.Fa "struct sockaddr *sa"
44.Fc
45.Ft int
46.Fo BIO_ctrl_dgram_connect
47.Fa "BIO *b"
48.Fa "struct sockaddr *sa"
49.Fc
50.Ft int
51.Fo BIO_dgram_get_peer
52.Fa "BIO *b"
53.Fa "struct sockaddr *sa"
54.Fc
55.Ft int
56.Fo BIO_ctrl_set_connected
57.Fa "BIO *b"
58.Fa "long argl"
59.Fa "struct sockaddr *sa"
60.Fc
61.Ft int
62.Fn BIO_dgram_recv_timedout "BIO *b"
63.Ft int
64.Fn BIO_dgram_send_timedout "BIO *b"
65.Ft int
66.Fn BIO_dgram_non_fatal_error "int errnum"
67.Sh DESCRIPTION
68.Fn BIO_s_datagram
69returns the datagram socket BIO method.
70The usual application is to transmit data using the IPv4 or IPv6
71.Xr udp 4
72protocol.
73.Pp
74When called on a datagram socket BIO object,
75.Xr BIO_method_type 3
76returns the constant
77.Dv BIO_TYPE_DGRAM
78and
79.Xr BIO_method_name 3
80returns a pointer to the static string
81.Qq datagram socket .
82.Ss Constructors and destructors
83.Xr BIO_new 3
84allocates a new datagram socket BIO object and initializes all its data
85to zero, including the datagram socket file descriptor, the peer address,
86the init flag that can be retrieved with
87.Xr BIO_get_init 3 ,
88the connected flag, the MTU, and all timeout and error information.
89The reference count and the close flag are set to 1.
90.Pp
91.Fn BIO_new_dgram
92allocates and initializes a new datagram socket BIO object with
93.Xr BIO_new 3 ,
94sets the datagram socket file descriptor and the close flag
95according to its arguments, and sets the init flag to 1.
96.Pp
97If the reference count reaches 0 in
98.Xr BIO_free 3
99and the close and init flags are set,
100.Xr shutdown 2
101and
102.Xr close 2
103are called on the datagram socket file descriptor before freeing the
104storage used by the BIO object.
105.Pp
106When a chain containing a datagram socket BIO is copied with
107.Xr BIO_dup_chain 3 ,
108the datagram socket file descriptor, the init flag, the close flag,
109the flags accessible with
110.Xr BIO_test_flags 3 ,
111and any data that was set with
112.Xr BIO_set_ex_data 3
113are automatically copied from the original BIO object to the new one,
114but the peer address, the connected flag, the MTU and all timeout and
115error information are not copied but instead initialized to zero.
116.Ss Initialization and configuration
117If the close flag is set in
118.Fa b ,
119.Xr BIO_set_fd 3
120clears all flags that are set in
121.Fa b
122and if the init flag was set, it calls
123.Xr shutdown 2
124and
125.Xr close 2
126on the previously assigned file descriptor.
127In any case,
128.Xr BIO_set_fd 3
129then sets the new file descriptor and the new close flag according to
130its arguments and sets the init flag to 1.
131.Pp
132If the init flag is set in
133.Fa b ,
134.Xr BIO_get_fd 3
135returns its datagram socket file descriptor, and unless the
136.Fa c
137argument is a
138.Dv NULL
139pointer, it also stores the file descriptor in
140.Pf * Fa c .
141If the init flag is not set,
142.Xr BIO_get_fd 3
143fails and returns \-1.
144.Pp
145.Xr BIO_set_close 3
146sets the close flag in
147.Fa b
148to the
149.Fa flag
150argument.
151.Xr BIO_get_close 3
152returns the value of the close flag from
153.Fa b .
154.Pp
155For datagram socket BIO objects,
156the shutdown flag is the same flag as the close flag.
157Consequently,
158.Xr BIO_set_shutdown 3
159has the same effect as
160.Xr BIO_set_close 3
161and
162.Xr BIO_get_shutdown 3
163has the same effect as
164.Xr BIO_get_close 3 .
165.Pp
166.Fn BIO_dgram_set_peer
167copies
168.Fa sa
169as the peer address into
170.Fa b .
171.Pp
172.Fn BIO_ctrl_dgram_connect
173does exactly the same as
174.Fn BIO_dgram_set_peer .
175Its name is even more misleading than the name of
176.Fn BIO_ctrl_set_connected .
177In addition to what is said there,
178.Fn BIO_ctrl_dgram_connect
179does not even set the connected flag in
180.Fa b .
181.Pp
182.Fn BIO_dgram_get_peer
183copies the peer address from
184.Fa b
185to
186.Pf * Fa sa .
187Before calling this function, the caller has to make sure
188that the peer address is indeed set in
189.Fa b
190and that sufficient memory is available starting at
191.Fa sa
192to copy a complete
193.Vt struct sockaddr ,
194.Vt struct sockaddr_in ,
195or
196.Vt struct sockaddr_in6
197to that place, depending on which address family
198.Fa b
199is currently used for.
200.Pp
201Unless
202.Fa sa
203is
204.Dv NULL ,
205.Fn BIO_ctrl_set_connected
206sets the connected flag in
207.Fa b
208and copies
209.Fa sa
210as the peer address into
211.Fa b .
212If
213.Fa sa
214is
215.Dv NULL ,
216.Fn BIO_ctrl_set_connected
217clears the connected flag and the peer address in
218.Fa b .
219Considering that communication using a datagram protocol is connectionless,
220the name of this function is misleading.
221It is neither establishing or terminating a connection nor changing
222anything with respect to the state of the datagram socket, but merely
223modifying some purely informational data in the wrapping BIO object.
224The additional
225.Fa argl
226argument is passed through to the callbacks documented in
227.Xr BIO_set_callback 3
228if any such callbacks are installed, but it is otherwise ignored.
229.Pp
230.Xr BIO_ctrl 3
231with a
232.Fa cmd
233of
234.Dv BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT
235interprets the
236.Fa parg
237argument as a pointer to a
238.Vt struct timeval
239and sets the read timeout to the specified absolute UTC time.
240.Pp
241.Xr BIO_ctrl 3
242with a
243.Fa cmd
244of
245.Dv BIO_CTRL_DGRAM_SET_RECV_TIMEOUT ,
246.Dv BIO_CTRL_DGRAM_GET_RECV_TIMEOUT ,
247.Dv BIO_CTRL_DGRAM_SET_SEND_TIMEOUT ,
248or
249.Dv BIO_CTRL_DGRAM_GET_SEND_TIMEOUT
250interprets the
251.Fa parg
252argument as a pointer to a
253.Vt struct timeval
254and calls
255.Xr setsockopt 2
256or
257.Xr getsockopt 2
258on the datagram socket file descriptor of
259.Fa b
260with an argument of
261.Dv SO_RCVTIMEO
262or
263.Dv SO_SNDTIMEO ,
264respectively.
265.Dv BIO_CTRL_DGRAM_SET_RECV_TIMEOUT
266and
267.Dv BIO_CTRL_DGRAM_SET_SEND_TIMEOUT
268return 1 on succcess,
269.Dv BIO_CTRL_DGRAM_GET_RECV_TIMEOUT
270and
271.Dv BIO_CTRL_DGRAM_GET_SEND_TIMEOUT
272the number of bytes written to
273.Pf * Fa parg .
274All four return \-1 on failure.
275Remember that
276.Xr BIO_read 3
277may actually use a shorter timeout when
278.Dv BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT
279is in effect.
280.Pp
281.Xr BIO_ctrl 3
282with a
283.Fa cmd
284of
285.Dv BIO_CTRL_DGRAM_GET_FALLBACK_MTU
286returns 1232 if the peer address is an IPv6 address that is not IPv4 mapped
287or 548 otherwise.
288Making sure that a peer address is set before issuing this command
289is the responsibility of the caller.
290.Pp
291.Xr BIO_ctrl 3
292with a
293.Fa cmd
294of
295.Dv BIO_CTRL_DGRAM_SET_MTU
296sets the MTU attribute of
297.Fa b
298to the value of the
299.Fa larg
300argument and also returns that argument.
301.Xr BIO_ctrl 3
302with a
303.Fa cmd
304of
305.Dv BIO_CTRL_DGRAM_GET_MTU
306returns the MTU attribute of
307.Fa b
308or 0 if it was not set.
309.Pp
310.Xr BIO_ctrl 3
311with a
312.Fa cmd
313of
314.Dv BIO_CTRL_DGRAM_MTU_EXCEEDED
315returns 1 if the most recent non-fatal failure of
316.Xr BIO_read 3
317or
318.Xr BIO_write 3
319was caused by
320.Er EMSGSIZE
321or 0 otherwise.
322This command also clears the
323.Xr errno 2
324value that was saved internally for this particular purpose, so that
325issuing the same command again will return 0 until the next
326.Er EMSGSIZE
327failure occurs.
328.Pp
329.Fn BIO_dgram_recv_timedout
330and
331.Fn BIO_dgram_send_timedout
332check whether the most recent non-fatal failure of
333.Xr BIO_read 3
334or
335.Xr BIO_write 3
336was caused by
337.Er EAGAIN .
338Despite having different names, both functions do exactly the same,
339and both inspect the most recent non-fatal I/O failure, no matter
340whether it occurred during a receive or send operation.
341Both functions also clear the
342.Xr errno 2
343value that was saved internally for this particular purpose,
344so that calling these functions again will return 0 until the next
345.Er EAGAIN
346failure occurs.
347.Pp
348Datagram socket BIOs do not support
349.Xr BIO_eof 3 ,
350.Xr BIO_get_mem_data 3 ,
351.Xr BIO_pending 3 ,
352.Xr BIO_reset 3 ,
353.Xr BIO_seek 3 ,
354.Xr BIO_tell 3 ,
355and
356.Xr BIO_wpending 3 ,
357and attempting any such operation results in failure
358and returns a value of 0.
359.Pp
360Control commands correspond to accessor functions as follows:
361.Pp
362.Bl -tag -width BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP -compact
363.It Dv BIO_C_GET_FD
364.Xr BIO_get_fd 3
365.It Dv BIO_C_SET_FD
366.Xr BIO_set_fd 3
367.It Dv BIO_CTRL_DGRAM_CONNECT
368.Fn BIO_ctrl_dgram_connect Pq deprecated
369.It Dv BIO_CTRL_DGRAM_GET_PEER
370.Fn BIO_dgram_get_peer
371.It BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP
372.Fn BIO_dgram_recv_timedout
373.It BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP
374.Fn BIO_dgram_send_timedout
375.It Dv BIO_CTRL_DGRAM_SET_CONNECTED
376.Fn BIO_ctrl_set_connected
377.It Dv BIO_CTRL_DGRAM_SET_PEER
378.Fn BIO_dgram_set_peer
379.It Dv BIO_CTRL_GET_CLOSE
380.Xr BIO_get_close 3
381.It Dv BIO_CTRL_SET_CLOSE
382.Xr BIO_set_close 3
383.El
384.\" OpenBSD does not appear to support
385.\" BIO_CTRL_DGRAM_MTU_DISCOVER and BIO_CTRL_DGRAM_QUERY_MTU.
386.Ss Input and output operations
387.Xr BIO_read 3
388attempts to read up to
389.Fa len
390bytes into
391.Fa buf
392from the datagram socket file descriptor using
393.Xr recvfrom 2 .
394If a read timeout is set,
395.Xr setsockopt 2
396is used with an argument of
397.Dv SO_RCVTIMEO
398to temporarily shorten the timeout on the datagram socket during the
399.Xr recvfrom 2
400call such that it returns before the read timeout expires.
401.Pp
402If
403.Xr recvfrom 2
404succeeds and the connected flag is not yet set,
405.Xr BIO_read 3
406also copies the peer address received from
407.Xr recvfrom 2
408into
409.Fa b .
410.Pp
411If
412.Xr recvfrom 2
413is attempted,
414.Xr BIO_read 3
415clears the flags
416.Dv BIO_FLAGS_WRITE
417and
418.Dv BIO_FLAGS_IO_SPECIAL
419in
420.Fa b
421and clears or sets the flags
422.Dv BIO_FLAGS_READ
423and
424.Dv BIO_FLAGS_SHOULD_RETRY
425as appropriate.
426.Pp
427If the connected flag is set in
428.Fa b ,
429.Xr BIO_write 3
430attempts to
431.Xr write 2
432.Fa len
433bytes from
434.Fa buf
435to the datagram socket file descriptor.
436If the connected flag is not set, it attempts to transmit
437.Fa len
438bytes from
439.Fa buf
440to the peer using
441.Xr sendto 2 .
442.Pp
443If
444.Xr write 2
445or
446.Xr sendto 2
447is attempted,
448.Xr BIO_write 3
449clears the flags
450.Dv BIO_FLAGS_READ
451and
452.Dv BIO_FLAGS_IO_SPECIAL
453in
454.Fa b
455and clears or sets the flags
456.Dv BIO_FLAGS_WRITE
457and
458.Dv BIO_FLAGS_SHOULD_RETRY
459as appropriate.
460.Pp
461The effect of
462.Xr BIO_puts 3
463is similar to the effect of
464.Xr BIO_write 3
465with a
466.Fa len
467argument of
468.Fn strlen string .
469.Pp
470Datagram socket BIOs do not support
471.Xr BIO_gets 3 .
472Calling this function fails and returns \-2.
473.Pp
474.Xr BIO_flush 3
475has no effect on a datagram socket BIO.
476It always succeeds and returns 1.
477.Sh RETURN VALUES
478.Fn BIO_s_datagram
479returns the datagram socket BIO method.
480.Pp
481.Fn BIO_new_dgram
482returns a newly allocated datagram socket BIO object or
483.Dv NULL
484on failure.
485.Pp
486.Fn BIO_dgram_set_peer ,
487.Fn BIO_ctrl_dgram_connect ,
488and
489.Fn BIO_ctrl_set_connected
490return 1 on success or a value less than or equal to zero on failure.
491They can only fail if
492.Fa b
493is not a datagram socket BIO object.
494.Pp
495.Fn BIO_dgram_get_peer
496returns the number of bytes copied to
497.Fa sa
498or a value less than or equal to zero on failure.
499It can only fail if
500.Fa b
501is not a datagram socket BIO object.
502.Pp
503.Fn BIO_dgram_recv_timedout
504and
505.Fn BIO_dgram_send_timedout
506return 1 if the most recent non-fatal I/O error was caused by
507.Er EAGAIN
508or 0 otherwise.
509.Pp
510.Fn BIO_dgram_non_fatal_error
511returns 1 if
512.Fa errnum
513is
514.Er EAGAIN ,
515.Er EALREADY ,
516.Er EINPROGRESS ,
517or
518.Er EINTR
519or 0 otherwise, even if
520.Fa errnum
521is 0.
522.Sh SEE ALSO
523.Xr close 2 ,
524.Xr getsockopt 2 ,
525.Xr recvfrom 2 ,
526.Xr sendto 2 ,
527.Xr shutdown 2 ,
528.Xr BIO_ctrl 3 ,
529.Xr BIO_get_init 3 ,
530.Xr BIO_new 3 ,
531.Xr BIO_read 3 ,
532.Xr BIO_s_connect 3 ,
533.Xr BIO_set_fd 3 ,
534.Xr BIO_should_retry 3 ,
535.Xr udp 4
536.Sh HISTORY
537.Fn BIO_s_datagram ,
538.Fn BIO_new_dgram ,
539.Fn BIO_dgram_set_peer ,
540.Fn BIO_ctrl_dgram_connect ,
541.Fn BIO_ctrl_set_connected ,
542.Fn BIO_dgram_recv_timedout ,
543.Fn BIO_dgram_send_timedout ,
544and
545.Fn BIO_dgram_non_fatal_error
546first appeared in OpenSSL 0.9.8 and have been available since
547.Ox 4.5 .
548.Pp
549.Fn BIO_dgram_get_peer
550first appeared in OpenSSL 0.9.8m and has been available since
551.Ox 4.9 .
552.Sh BUGS
553If
554.Xr getsockopt 2
555or
556.Xr setsockopt 2
557fails during
558.Xr BIO_read 3 ,
559the library prints an error message to standard error output
560but otherwise ignores the problem, thus possibly using unintended
561timeout values.
562.Pp
563.Xr BIO_read 3
564and
565.Xr BIO_write 3
566may clear the global variable
567.Xr errno 2
568before attempting the
569.Xr recvfrom 2
570or
571.Xr sendto 2
572system call but may not clear it if they fail before reaching this point.
diff --git a/src/lib/libcrypto/man/Makefile b/src/lib/libcrypto/man/Makefile
index b67ae786de..f18336625d 100644
--- a/src/lib/libcrypto/man/Makefile
+++ b/src/lib/libcrypto/man/Makefile
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile,v 1.241 2022/12/22 21:05:48 schwarze Exp $ 1# $OpenBSD: Makefile,v 1.242 2022/12/23 15:59:34 schwarze Exp $
2 2
3.include <bsd.own.mk> 3.include <bsd.own.mk>
4 4
@@ -58,6 +58,7 @@ MAN= \
58 BIO_s_accept.3 \ 58 BIO_s_accept.3 \
59 BIO_s_bio.3 \ 59 BIO_s_bio.3 \
60 BIO_s_connect.3 \ 60 BIO_s_connect.3 \
61 BIO_s_datagram.3 \
61 BIO_s_fd.3 \ 62 BIO_s_fd.3 \
62 BIO_s_file.3 \ 63 BIO_s_file.3 \
63 BIO_s_mem.3 \ 64 BIO_s_mem.3 \