allow separate set fds for read/write, helpful for DTLS multicast

This commit is contained in:
toddouska
2016-11-30 11:15:57 -08:00
parent 235060eff2
commit 8f89d4922f
5 changed files with 49 additions and 10 deletions

View File

@@ -3387,7 +3387,8 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx)
ssl->dtls_timeout_init = DTLS_TIMEOUT_INIT;
ssl->dtls_timeout_max = DTLS_TIMEOUT_MAX;
ssl->dtls_timeout = ssl->dtls_timeout_init;
ssl->buffers.dtlsCtx.fd = -1;
ssl->buffers.dtlsCtx.rfd = -1;
ssl->buffers.dtlsCtx.wfd = -1;
#endif
#ifndef NO_OLD_TLS

View File

@@ -398,7 +398,7 @@ int EmbedReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *ctx)
WOLFSSL_DTLS_CTX* dtlsCtx = (WOLFSSL_DTLS_CTX*)ctx;
int recvd;
int err;
int sd = dtlsCtx->fd;
int sd = dtlsCtx->rfd;
int dtls_timeout = wolfSSL_dtls_get_current_timeout(ssl);
struct sockaddr_storage peer;
XSOCKLENT peerSz = sizeof(peer);
@@ -477,7 +477,7 @@ int EmbedReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *ctx)
int EmbedSendTo(WOLFSSL* ssl, char *buf, int sz, void *ctx)
{
WOLFSSL_DTLS_CTX* dtlsCtx = (WOLFSSL_DTLS_CTX*)ctx;
int sd = dtlsCtx->fd;
int sd = dtlsCtx->wfd;
int sent;
int len = sz;
int err;

View File

@@ -431,29 +431,64 @@ int wolfSSL_use_old_poly(WOLFSSL* ssl, int value)
}
#endif
int wolfSSL_set_fd(WOLFSSL* ssl, int fd)
{
int ret;
WOLFSSL_ENTER("SSL_set_fd");
ret = wolfSSL_set_read_fd(ssl, fd);
if (ret == SSL_SUCCESS) {
ret = wolfSSL_set_write_fd(ssl, fd);
}
return ret;
}
int wolfSSL_set_read_fd(WOLFSSL* ssl, int fd)
{
WOLFSSL_ENTER("SSL_set_read_fd");
if (ssl == NULL) {
return BAD_FUNC_ARG;
}
ssl->rfd = fd; /* not used directly to allow IO callbacks */
ssl->wfd = fd;
ssl->IOCB_ReadCtx = &ssl->rfd;
ssl->IOCB_WriteCtx = &ssl->wfd;
#ifdef WOLFSSL_DTLS
if (ssl->options.dtls) {
ssl->IOCB_ReadCtx = &ssl->buffers.dtlsCtx;
ssl->IOCB_WriteCtx = &ssl->buffers.dtlsCtx;
ssl->buffers.dtlsCtx.fd = fd;
ssl->buffers.dtlsCtx.rfd = fd;
}
#endif
WOLFSSL_LEAVE("SSL_set_fd", SSL_SUCCESS);
WOLFSSL_LEAVE("SSL_set_read_fd", SSL_SUCCESS);
return SSL_SUCCESS;
}
int wolfSSL_set_write_fd(WOLFSSL* ssl, int fd)
{
WOLFSSL_ENTER("SSL_set_write_fd");
if (ssl == NULL) {
return BAD_FUNC_ARG;
}
ssl->wfd = fd; /* not used directly to allow IO callbacks */
ssl->IOCB_WriteCtx = &ssl->wfd;
#ifdef WOLFSSL_DTLS
if (ssl->options.dtls) {
ssl->IOCB_WriteCtx = &ssl->buffers.dtlsCtx;
ssl->buffers.dtlsCtx.wfd = fd;
}
#endif
WOLFSSL_LEAVE("SSL_set_write_fd", SSL_SUCCESS);
return SSL_SUCCESS;
}

View File

@@ -1585,7 +1585,8 @@ struct WOLFSSL_SOCKADDR {
typedef struct WOLFSSL_DTLS_CTX {
WOLFSSL_SOCKADDR peer;
int fd;
int rfd;
int wfd;
} WOLFSSL_DTLS_CTX;

View File

@@ -328,6 +328,8 @@ WOLFSSL_API int wolfSSL_use_RSAPrivateKey_file(WOLFSSL*, const char*, int);
WOLFSSL_API WOLFSSL_CTX* wolfSSL_CTX_new(WOLFSSL_METHOD*);
WOLFSSL_API WOLFSSL* wolfSSL_new(WOLFSSL_CTX*);
WOLFSSL_API int wolfSSL_set_fd (WOLFSSL*, int);
WOLFSSL_API int wolfSSL_set_write_fd (WOLFSSL*, int);
WOLFSSL_API int wolfSSL_set_read_fd (WOLFSSL*, int);
WOLFSSL_API char* wolfSSL_get_cipher_list(int priority);
WOLFSSL_API int wolfSSL_get_ciphers(char*, int);
WOLFSSL_API const char* wolfSSL_get_cipher_name(WOLFSSL* ssl);