Skip to content

Commit

Permalink
Enable BIO_ctrl() call by reordering it before transferring to SSL ob…
Browse files Browse the repository at this point in the history
…ejct
  • Loading branch information
cgzones committed Oct 30, 2024
1 parent 44bb86f commit 2664158
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/netlog/netlog-dtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,22 @@ int dtls_connect(DTLSManager *m, SocketAddress *address) {

log_debug("DTLS: Connected to remote server: '%s'", pretty);

ssl = SSL_new(m->ctx);
if (!ssl)
return log_error_errno(SYNTHETIC_ERRNO(ENOMEM),
"DTLS: Failed to allocate memory for ssl: %s",
ERR_error_string(ERR_get_error(), NULL));

/* Create BIO from socket array! */
bio = BIO_new_dgram(fd, BIO_NOCLOSE);
if (!bio)
return log_error_errno(SYNTHETIC_ERRNO(ENOMEM),
"DTLS: Failed to allocate memory for bio: %m");

BIO_ctrl(bio, BIO_CTRL_DGRAM_SET_CONNECTED, 0, &address);
/* Set and activate timeouts */
BIO_ctrl(bio, BIO_CTRL_DGRAM_SET_RECV_TIMEOUT, 0, &timeout);

ssl = SSL_new(m->ctx);
if (!ssl)
return log_error_errno(SYNTHETIC_ERRNO(ENOMEM),
"DTLS: Failed to allocate memory for ssl: %s",
ERR_error_string(ERR_get_error(), NULL));

SSL_set_bio(ssl, bio, bio);
bio = NULL;

Expand Down Expand Up @@ -154,9 +157,6 @@ int dtls_connect(DTLSManager *m, SocketAddress *address) {
log_debug("DTLS: No certificates.");
}

/* Set and activate timeouts */
BIO_ctrl(bio, BIO_CTRL_DGRAM_SET_RECV_TIMEOUT, 0, &timeout);

m->ssl = TAKE_PTR(ssl);
m->fd = TAKE_FD(fd);
m->pretty_address = TAKE_PTR(pretty);
Expand Down

0 comments on commit 2664158

Please sign in to comment.