xref: /freebsd/crypto/openssl/doc/man3/BIO_ctrl.pod (revision b077aed3)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5e71b7053SJung-uk KimBIO_ctrl, BIO_callback_ctrl, BIO_ptr_ctrl, BIO_int_ctrl, BIO_reset,
6e71b7053SJung-uk KimBIO_seek, BIO_tell, BIO_flush, BIO_eof, BIO_set_close, BIO_get_close,
7e71b7053SJung-uk KimBIO_pending, BIO_wpending, BIO_ctrl_pending, BIO_ctrl_wpending,
8aa906e2aSJohn BaldwinBIO_get_info_callback, BIO_set_info_callback, BIO_info_cb, BIO_get_ktls_send,
9aa906e2aSJohn BaldwinBIO_get_ktls_recv
10e71b7053SJung-uk Kim- BIO control operations
11e71b7053SJung-uk Kim
12e71b7053SJung-uk Kim=head1 SYNOPSIS
13e71b7053SJung-uk Kim
14e71b7053SJung-uk Kim #include <openssl/bio.h>
15e71b7053SJung-uk Kim
16e71b7053SJung-uk Kim typedef int BIO_info_cb(BIO *b, int state, int res);
17e71b7053SJung-uk Kim
18e71b7053SJung-uk Kim long BIO_ctrl(BIO *bp, int cmd, long larg, void *parg);
19e71b7053SJung-uk Kim long BIO_callback_ctrl(BIO *b, int cmd, BIO_info_cb *cb);
205ac766abSJung-uk Kim void *BIO_ptr_ctrl(BIO *bp, int cmd, long larg);
21e71b7053SJung-uk Kim long BIO_int_ctrl(BIO *bp, int cmd, long larg, int iarg);
22e71b7053SJung-uk Kim
23e71b7053SJung-uk Kim int BIO_reset(BIO *b);
24e71b7053SJung-uk Kim int BIO_seek(BIO *b, int ofs);
25e71b7053SJung-uk Kim int BIO_tell(BIO *b);
26e71b7053SJung-uk Kim int BIO_flush(BIO *b);
27e71b7053SJung-uk Kim int BIO_eof(BIO *b);
28e71b7053SJung-uk Kim int BIO_set_close(BIO *b, long flag);
29e71b7053SJung-uk Kim int BIO_get_close(BIO *b);
30e71b7053SJung-uk Kim int BIO_pending(BIO *b);
31e71b7053SJung-uk Kim int BIO_wpending(BIO *b);
32e71b7053SJung-uk Kim size_t BIO_ctrl_pending(BIO *b);
33e71b7053SJung-uk Kim size_t BIO_ctrl_wpending(BIO *b);
34e71b7053SJung-uk Kim
35e71b7053SJung-uk Kim int BIO_get_info_callback(BIO *b, BIO_info_cb **cbp);
36e71b7053SJung-uk Kim int BIO_set_info_callback(BIO *b, BIO_info_cb *cb);
37e71b7053SJung-uk Kim
38aa906e2aSJohn Baldwin int BIO_get_ktls_send(BIO *b);
39aa906e2aSJohn Baldwin int BIO_get_ktls_recv(BIO *b);
40aa906e2aSJohn Baldwin
41e71b7053SJung-uk Kim=head1 DESCRIPTION
42e71b7053SJung-uk Kim
43e71b7053SJung-uk KimBIO_ctrl(), BIO_callback_ctrl(), BIO_ptr_ctrl() and BIO_int_ctrl()
44e71b7053SJung-uk Kimare BIO "control" operations taking arguments of various types.
45e71b7053SJung-uk KimThese functions are not normally called directly, various macros
46e71b7053SJung-uk Kimare used instead. The standard macros are described below, macros
47e71b7053SJung-uk Kimspecific to a particular type of BIO are described in the specific
48e71b7053SJung-uk KimBIOs manual page as well as any special features of the standard
49e71b7053SJung-uk Kimcalls.
50e71b7053SJung-uk Kim
51e71b7053SJung-uk KimBIO_reset() typically resets a BIO to some initial state, in the case
52e71b7053SJung-uk Kimof file related BIOs for example it rewinds the file pointer to the
53e71b7053SJung-uk Kimstart of the file.
54e71b7053SJung-uk Kim
55e71b7053SJung-uk KimBIO_seek() resets a file related BIO's (that is file descriptor and
56e71b7053SJung-uk KimFILE BIOs) file position pointer to B<ofs> bytes from start of file.
57e71b7053SJung-uk Kim
58e71b7053SJung-uk KimBIO_tell() returns the current file position of a file related BIO.
59e71b7053SJung-uk Kim
60e71b7053SJung-uk KimBIO_flush() normally writes out any internally buffered data, in some
61e71b7053SJung-uk Kimcases it is used to signal EOF and that no more data will be written.
62e71b7053SJung-uk Kim
63e71b7053SJung-uk KimBIO_eof() returns 1 if the BIO has read EOF, the precise meaning of
64e71b7053SJung-uk Kim"EOF" varies according to the BIO type.
65e71b7053SJung-uk Kim
66e71b7053SJung-uk KimBIO_set_close() sets the BIO B<b> close flag to B<flag>. B<flag> can
67e71b7053SJung-uk Kimtake the value BIO_CLOSE or BIO_NOCLOSE. Typically BIO_CLOSE is used
68e71b7053SJung-uk Kimin a source/sink BIO to indicate that the underlying I/O stream should
69e71b7053SJung-uk Kimbe closed when the BIO is freed.
70e71b7053SJung-uk Kim
71e71b7053SJung-uk KimBIO_get_close() returns the BIOs close flag.
72e71b7053SJung-uk Kim
73e71b7053SJung-uk KimBIO_pending(), BIO_ctrl_pending(), BIO_wpending() and BIO_ctrl_wpending()
74e71b7053SJung-uk Kimreturn the number of pending characters in the BIOs read and write buffers.
75e71b7053SJung-uk KimNot all BIOs support these calls. BIO_ctrl_pending() and BIO_ctrl_wpending()
76e71b7053SJung-uk Kimreturn a size_t type and are functions, BIO_pending() and BIO_wpending() are
77e71b7053SJung-uk Kimmacros which call BIO_ctrl().
78e71b7053SJung-uk Kim
79aa906e2aSJohn BaldwinBIO_get_ktls_send() returns 1 if the BIO is using the Kernel TLS data-path for
80aa906e2aSJohn Baldwinsending. Otherwise, it returns zero.
81aa906e2aSJohn BaldwinBIO_get_ktls_recv() returns 1 if the BIO is using the Kernel TLS data-path for
82aa906e2aSJohn Baldwinreceiving. Otherwise, it returns zero.
83aa906e2aSJohn Baldwin
84e71b7053SJung-uk Kim=head1 RETURN VALUES
85e71b7053SJung-uk Kim
86b077aed3SPierre ProncheryBIO_reset() normally returns 1 for success and <=0 for failure. File
87e71b7053SJung-uk KimBIOs are an exception, they return 0 for success and -1 for failure.
88e71b7053SJung-uk Kim
89e71b7053SJung-uk KimBIO_seek() and BIO_tell() both return the current file position on success
90e71b7053SJung-uk Kimand -1 for failure, except file BIOs which for BIO_seek() always return 0
91e71b7053SJung-uk Kimfor success and -1 for failure.
92e71b7053SJung-uk Kim
93b077aed3SPierre ProncheryBIO_flush() returns 1 for success and <=0 for failure.
94e71b7053SJung-uk Kim
95b077aed3SPierre ProncheryBIO_eof() returns 1 if EOF has been reached, 0 if not, or negative values for failure.
96e71b7053SJung-uk Kim
97b077aed3SPierre ProncheryBIO_set_close() returns 1 on success or <=0 for failure.
98e71b7053SJung-uk Kim
99b077aed3SPierre ProncheryBIO_get_close() returns the close flag value: BIO_CLOSE or BIO_NOCLOSE. It also
100b077aed3SPierre Proncheryreturns other negative values if an error occurs.
101e71b7053SJung-uk Kim
102e71b7053SJung-uk KimBIO_pending(), BIO_ctrl_pending(), BIO_wpending() and BIO_ctrl_wpending()
103b077aed3SPierre Proncheryreturn the amount of pending data. BIO_pending() and BIO_wpending() return
104b077aed3SPierre Proncherynegative value or 0 on error. BIO_ctrl_pending() and BIO_ctrl_wpending() return
105b077aed3SPierre Pronchery0 on error.
106e71b7053SJung-uk Kim
107aa906e2aSJohn BaldwinBIO_get_ktls_send() returns 1 if the BIO is using the Kernel TLS data-path for
108aa906e2aSJohn Baldwinsending. Otherwise, it returns zero.
109aa906e2aSJohn BaldwinBIO_get_ktls_recv() returns 1 if the BIO is using the Kernel TLS data-path for
110aa906e2aSJohn Baldwinreceiving. Otherwise, it returns zero.
111aa906e2aSJohn Baldwin
112e71b7053SJung-uk Kim=head1 NOTES
113e71b7053SJung-uk Kim
114e71b7053SJung-uk KimBIO_flush(), because it can write data may return 0 or -1 indicating
115e71b7053SJung-uk Kimthat the call should be retried later in a similar manner to BIO_write_ex().
116e71b7053SJung-uk KimThe BIO_should_retry() call should be used and appropriate action taken
117e71b7053SJung-uk Kimis the call fails.
118e71b7053SJung-uk Kim
119e71b7053SJung-uk KimThe return values of BIO_pending() and BIO_wpending() may not reliably
120e71b7053SJung-uk Kimdetermine the amount of pending data in all cases. For example in the
121e71b7053SJung-uk Kimcase of a file BIO some data may be available in the FILE structures
122e71b7053SJung-uk Kiminternal buffers but it is not possible to determine this in a
123e71b7053SJung-uk Kimportably way. For other types of BIO they may not be supported.
124e71b7053SJung-uk Kim
125e71b7053SJung-uk KimFilter BIOs if they do not internally handle a particular BIO_ctrl()
126e71b7053SJung-uk Kimoperation usually pass the operation to the next BIO in the chain.
127e71b7053SJung-uk KimThis often means there is no need to locate the required BIO for
128e71b7053SJung-uk Kima particular operation, it can be called on a chain and it will
12958f35182SJung-uk Kimbe automatically passed to the relevant BIO. However, this can cause
130e71b7053SJung-uk Kimunexpected results: for example no current filter BIOs implement
131e71b7053SJung-uk KimBIO_seek(), but this may still succeed if the chain ends in a FILE
132e71b7053SJung-uk Kimor file descriptor BIO.
133e71b7053SJung-uk Kim
134e71b7053SJung-uk KimSource/sink BIOs return an 0 if they do not recognize the BIO_ctrl()
135e71b7053SJung-uk Kimoperation.
136e71b7053SJung-uk Kim
137e71b7053SJung-uk Kim=head1 BUGS
138e71b7053SJung-uk Kim
139e71b7053SJung-uk KimSome of the return values are ambiguous and care should be taken. In
140e71b7053SJung-uk Kimparticular a return value of 0 can be returned if an operation is not
141e71b7053SJung-uk Kimsupported, if an error occurred, if EOF has not been reached and in
142e71b7053SJung-uk Kimthe case of BIO_seek() on a file BIO for a successful operation.
143e71b7053SJung-uk Kim
144b077aed3SPierre ProncheryIn older versions of OpenSSL the BIO_ctrl_pending() and
145b077aed3SPierre ProncheryBIO_ctrl_wpending() could return values greater than INT_MAX on error.
146b077aed3SPierre Pronchery
147aa906e2aSJohn Baldwin=head1 HISTORY
148aa906e2aSJohn Baldwin
149b077aed3SPierre ProncheryThe BIO_get_ktls_send() and BIO_get_ktls_recv() macros were added in
150b077aed3SPierre ProncheryOpenSSL 3.0. They were modified to never return -1 in OpenSSL 3.0.4.
151aa906e2aSJohn Baldwin
152e71b7053SJung-uk Kim=head1 COPYRIGHT
153e71b7053SJung-uk Kim
1545ac766abSJung-uk KimCopyright 2000-2022 The OpenSSL Project Authors. All Rights Reserved.
155e71b7053SJung-uk Kim
156b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
157e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
158e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
159e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
160e71b7053SJung-uk Kim
161e71b7053SJung-uk Kim=cut
162