Commit 7c3a7561 authored by Boris Pismenny's avatar Boris Pismenny Committed by Matt Caswell
Browse files

ssl: Add SSL_sendfile



This commit adds the SSL_sendfile call, which allows KTLS sockets to
transmit file using zero-copy semantics.

Signed-off-by: default avatarBoris Pismenny <borisp@mellanox.com>

Reviewed-by: default avatarPaul Dale <paul.dale@oracle.com>
Reviewed-by: default avatarMatt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/8727)
parent 72fb59c7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1437,6 +1437,7 @@ SSL_F_SSL_RENEGOTIATE:516:SSL_renegotiate
SSL_F_SSL_RENEGOTIATE_ABBREVIATED:546:SSL_renegotiate_abbreviated
SSL_F_SSL_SCAN_CLIENTHELLO_TLSEXT:320:*
SSL_F_SSL_SCAN_SERVERHELLO_TLSEXT:321:*
SSL_F_SSL_SENDFILE:639:SSL_sendfile
SSL_F_SSL_SESSION_DUP:348:ssl_session_dup
SSL_F_SSL_SESSION_NEW:189:SSL_SESSION_new
SSL_F_SSL_SESSION_PRINT_FP:190:SSL_SESSION_print_fp
+29 −2
Original line number Diff line number Diff line
@@ -2,12 +2,13 @@

=head1 NAME

SSL_write_ex, SSL_write - write bytes to a TLS/SSL connection
SSL_write_ex, SSL_write, SSL_sendfile - write bytes to a TLS/SSL connection

=head1 SYNOPSIS

 #include <openssl/ssl.h>

 ossl_ssize_t SSL_sendfile(SSL *s, int fd, off_t offset, size_t size, int flags);
 int SSL_write_ex(SSL *s, const void *buf, size_t num, size_t *written);
 int SSL_write(SSL *ssl, const void *buf, int num);

@@ -17,6 +18,14 @@ SSL_write_ex() and SSL_write() write B<num> bytes from the buffer B<buf> into
the specified B<ssl> connection. On success SSL_write_ex() will store the number
of bytes written in B<*written>.

SSL_sendfile() writes B<size> bytes from offset B<offset> in the file
descriptor B<fd> to the specified SSL connection B<s>. This function provides
efficient zero-copy semantics. SSL_sendfile() is available only when
Kernel TLS is enabled, which can be checked by calling BIO_get_ktls_send().
It is provided here to allow users to maintain the same interface.
The meaning of B<flags> is platform dependent.
Currently, under Linux it is ignored.

=head1 NOTES

In the paragraphs below a "write function" is defined as one of either
@@ -104,17 +113,35 @@ You should instead call SSL_get_error() to find out if it's retryable.

=back

For SSL_sendfile(), the following return values can occur:

=over 4

=item Z<>>= 0

The write operation was successful, the return value is the number
of bytes of the file written to the TLS/SSL connection.

=item E<lt> 0

The write operation was not successful, because either the connection was
closed, an error occured or action must be taken by the calling process.
Call SSL_get_error() with the return value to find out the reason.

=back

=head1 SEE ALSO

L<SSL_get_error(3)>, L<SSL_read_ex(3)>, L<SSL_read(3)>
L<SSL_CTX_set_mode(3)>, L<SSL_CTX_new(3)>,
L<SSL_connect(3)>, L<SSL_accept(3)>
L<SSL_set_connect_state(3)>,
L<SSL_set_connect_state(3)>, L<BIO_ctrl(3)>,
L<ssl(7)>, L<bio(7)>

=head1 HISTORY

The SSL_write_ex() function was added in OpenSSL 1.1.1.
The SSL_sendfile() function was added in OpenSSL 3.0.0.

=head1 COPYRIGHT

+1 −0
Original line number Diff line number Diff line
@@ -177,6 +177,7 @@ typedef struct err_state_st {
# define SYS_F_STAT              22
# define SYS_F_FCNTL             23
# define SYS_F_FSTAT             24
# define SYS_F_SENDFILE          25

/* reasons */
# define ERR_R_SYS_LIB   ERR_LIB_SYS/* 2 */
+2 −0
Original line number Diff line number Diff line
@@ -1848,6 +1848,8 @@ __owur int SSL_read_early_data(SSL *s, void *buf, size_t num,
                               size_t *readbytes);
__owur int SSL_peek(SSL *ssl, void *buf, int num);
__owur int SSL_peek_ex(SSL *ssl, void *buf, size_t num, size_t *readbytes);
__owur ossl_ssize_t SSL_sendfile(SSL *s, int fd, off_t offset, size_t size,
                                 int flags);
__owur int SSL_write(SSL *ssl, const void *buf, int num);
__owur int SSL_write_ex(SSL *s, const void *buf, size_t num, size_t *written);
__owur int SSL_write_early_data(SSL *s, const void *buf, size_t num,
+1 −0
Original line number Diff line number Diff line
@@ -217,6 +217,7 @@ int ERR_load_SSL_strings(void);
# define SSL_F_SSL_RENEGOTIATE_ABBREVIATED                546
# define SSL_F_SSL_SCAN_CLIENTHELLO_TLSEXT                320
# define SSL_F_SSL_SCAN_SERVERHELLO_TLSEXT                321
# define SSL_F_SSL_SENDFILE                               639
# define SSL_F_SSL_SESSION_DUP                            348
# define SSL_F_SSL_SESSION_NEW                            189
# define SSL_F_SSL_SESSION_PRINT_FP                       190
Loading