diff options
author | Hugo Landau <hlandau@openssl.org> | 2022-11-17 15:17:39 +0000 |
---|---|---|
committer | Hugo Landau <hlandau@openssl.org> | 2023-01-13 13:20:14 +0000 |
commit | 68801bcb766806a04e95e8ef714a0b836b1d7069 (patch) | |
tree | 1ea4c0098636cc8241114e25f2761fccac618790 | |
parent | 4ed9e0a1e36eaa8f07a4a5371f9d13912a3f9da8 (diff) |
Add BIO poll descriptors
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19703)
-rw-r--r-- | crypto/bio/bio_lib.c | 10 | ||||
-rw-r--r-- | crypto/bio/bss_dgram.c | 10 | ||||
-rw-r--r-- | include/openssl/bio.h.in | 21 | ||||
-rw-r--r-- | include/openssl/ssl.h.in | 4 | ||||
-rw-r--r-- | ssl/bio_ssl.c | 8 | ||||
-rw-r--r-- | ssl/ssl_lib.c | 28 |
6 files changed, 81 insertions, 0 deletions
diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c index cceef45095..4708b984fa 100644 --- a/crypto/bio/bio_lib.c +++ b/crypto/bio/bio_lib.c @@ -490,6 +490,16 @@ int BIO_recvmmsg(BIO *b, BIO_MSG *msg, return ret; } +int BIO_get_rpoll_descriptor(BIO *b, BIO_POLL_DESCRIPTOR *desc) +{ + return BIO_ctrl(b, BIO_CTRL_GET_RPOLL_DESCRIPTOR, 0, desc); +} + +int BIO_get_wpoll_descriptor(BIO *b, BIO_POLL_DESCRIPTOR *desc) +{ + return BIO_ctrl(b, BIO_CTRL_GET_WPOLL_DESCRIPTOR, 0, desc); +} + int BIO_puts(BIO *b, const char *buf) { int ret; diff --git a/crypto/bio/bss_dgram.c b/crypto/bio/bss_dgram.c index 1d31ab811c..a2e90f6bd5 100644 --- a/crypto/bio/bss_dgram.c +++ b/crypto/bio/bss_dgram.c @@ -945,6 +945,16 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) *(int *)ptr = data->local_addr_enabled; break; + case BIO_CTRL_GET_RPOLL_DESCRIPTOR: + case BIO_CTRL_GET_WPOLL_DESCRIPTOR: + { + BIO_POLL_DESCRIPTOR *pd = ptr; + + pd->type = BIO_POLL_DESCRIPTOR_TYPE_SOCK_FD; + pd->value.fd = b->num; + } + break; + default: ret = 0; break; diff --git a/include/openssl/bio.h.in b/include/openssl/bio.h.in index 89c88c67e7..dbb65f50e4 100644 --- a/include/openssl/bio.h.in +++ b/include/openssl/bio.h.in @@ -187,6 +187,9 @@ extern "C" { * # define BIO_CTRL_SET_KTLS_TX_ZEROCOPY_SENDFILE 90 */ +# define BIO_CTRL_GET_RPOLL_DESCRIPTOR 90 +# define BIO_CTRL_GET_WPOLL_DESCRIPTOR 91 + # define BIO_DGRAM_CAP_NONE 0U # define BIO_DGRAM_CAP_HANDLES_SRC_ADDR (1U << 0) # define BIO_DGRAM_CAP_HANDLES_DST_ADDR (1U << 1) @@ -377,6 +380,22 @@ typedef struct bio_mmsg_cb_args_st { size_t *msgs_processed; } BIO_MMSG_CB_ARGS; +#define BIO_POLL_DESCRIPTOR_TYPE_NONE 0 +#define BIO_POLL_DESCRIPTOR_TYPE_SOCK_FD 1 +#define BIO_POLL_DESCRIPTOR_CUSTOM_START 8192 +#define BIO_POLL_DESCRIPTOR_NUM_CUSTOM 4 + +typedef struct bio_poll_descriptor_st { + int type; + union { + int fd; + union { + void *ptr; + uint64_t u64; + } custom[BIO_POLL_DESCRIPTOR_NUM_CUSTOM]; + } value; +} BIO_POLL_DESCRIPTOR; + /* * #define BIO_CONN_get_param_hostname BIO_ctrl */ @@ -690,6 +709,8 @@ int BIO_write_ex(BIO *b, const void *data, size_t dlen, size_t *written); __owur int BIO_sendmmsg(BIO *b, BIO_MSG *msg, size_t stride, size_t num_msg, uint64_t flags, size_t *msgs_processed); +__owur int BIO_get_rpoll_descriptor(BIO *b, BIO_POLL_DESCRIPTOR *desc); +__owur int BIO_get_wpoll_descriptor(BIO *b, BIO_POLL_DESCRIPTOR *desc); int BIO_puts(BIO *bp, const char *buf); int BIO_indent(BIO *b, int indent, int max); long BIO_ctrl(BIO *bp, int cmd, long larg, void *parg); diff --git a/include/openssl/ssl.h.in b/include/openssl/ssl.h.in index 871ad265c5..b01147785c 100644 --- a/include/openssl/ssl.h.in +++ b/include/openssl/ssl.h.in @@ -2247,6 +2247,10 @@ size_t SSL_get_num_tickets(const SSL *s); int SSL_CTX_set_num_tickets(SSL_CTX *ctx, size_t num_tickets); size_t SSL_CTX_get_num_tickets(const SSL_CTX *ctx); +/* QUIC support */ +__owur int SSL_get_rpoll_descriptor(SSL *s, BIO_POLL_DESCRIPTOR *desc); +__owur int SSL_get_wpoll_descriptor(SSL *s, BIO_POLL_DESCRIPTOR *desc); + # ifndef OPENSSL_NO_DEPRECATED_1_1_0 # define SSL_cache_hit(s) SSL_session_reused(s) # endif diff --git a/ssl/bio_ssl.c b/ssl/bio_ssl.c index c9bb20b2da..64d1849c7e 100644 --- a/ssl/bio_ssl.c +++ b/ssl/bio_ssl.c @@ -385,6 +385,14 @@ static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr) case BIO_CTRL_SET_CALLBACK: ret = 0; /* use callback ctrl */ break; + case BIO_CTRL_GET_RPOLL_DESCRIPTOR: + if (!SSL_get_rpoll_descriptor(ssl, (BIO_POLL_DESCRIPTOR *)ptr)) + ret = 0; + break; + case BIO_CTRL_GET_WPOLL_DESCRIPTOR: + if (!SSL_get_wpoll_descriptor(ssl, (BIO_POLL_DESCRIPTOR *)ptr)) + ret = 0; + break; default: ret = BIO_ctrl(sc->rbio, cmd, num, ptr); break; diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index 77abe3dc27..9a24893601 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -6942,3 +6942,31 @@ int SSL_CTX_set0_tmp_dh_pkey(SSL_CTX *ctx, EVP_PKEY *dhpkey) ctx->cert->dh_tmp = dhpkey; return 1; } + +int SSL_get_rpoll_descriptor(SSL *s, BIO_POLL_DESCRIPTOR *desc) +{ +#ifndef OPENSSL_NO_QUIC + QUIC_CONNECTION *qc = QUIC_CONNECTION_FROM_SSL(s); + + if (qc == NULL) + return -1; + + return -1; /* TODO(QUIC) */ +#else + return -1; +#endif +} + +int SSL_get_wpoll_descriptor(SSL *s, BIO_POLL_DESCRIPTOR *desc) +{ +#ifndef OPENSSL_NO_QUIC + QUIC_CONNECTION *qc = QUIC_CONNECTION_FROM_SSL(s); + + if (qc == NULL) + return -1; + + return -1; /* TODO(QUIC) */ +#else + return -1; +#endif +} |