diff --git a/src/internal.c b/src/internal.c index 531b49fae..638814f6f 100644 --- a/src/internal.c +++ b/src/internal.c @@ -7182,13 +7182,7 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup) #endif #if defined(WOLFSSL_SCTP) || defined(WOLFSSL_DTLS_MTU) ssl->dtlsMtuSz = ctx->dtlsMtuSz; - ssl->dtls_expected_rx = ssl->dtlsMtuSz; - #else - ssl->dtls_expected_rx = MAX_MTU; #endif - /* Add some bytes so that we can operate with slight difference - * in set MTU size on each peer */ - ssl->dtls_expected_rx += DTLS_MTU_ADDITIONAL_READ_BUFFER; ssl->dtls_timeout_init = DTLS_TIMEOUT_INIT; ssl->dtls_timeout_max = DTLS_TIMEOUT_MAX; ssl->dtls_timeout = ssl->dtls_timeout_init; @@ -10599,13 +10593,12 @@ int CheckAvailableSize(WOLFSSL *ssl, int size) #ifdef WOLFSSL_DTLS if (ssl->options.dtls) { - if (size + ssl->buffers.outputBuffer.length > #if defined(WOLFSSL_SCTP) || defined(WOLFSSL_DTLS_MTU) - ssl->dtlsMtuSz + word32 mtu = (word32)ssl->dtlsMtuSz; #else - ssl->dtls_expected_rx + word32 mtu = MAX_MTU; #endif - ) { + if ((word32)size + ssl->buffers.outputBuffer.length > mtu) { int ret; WOLFSSL_MSG("CheckAvailableSize() flushing buffer " "to make room for new message"); @@ -10613,12 +10606,7 @@ int CheckAvailableSize(WOLFSSL *ssl, int size) return ret; } } - if (size > (int) -#if defined(WOLFSSL_SCTP) || defined(WOLFSSL_DTLS_MTU) - ssl->dtlsMtuSz -#else - ssl->dtls_expected_rx -#endif + if ((word32)size > mtu #ifdef WOLFSSL_DTLS13 /* DTLS1.3 uses the output buffer to store the full message and deal with fragmentation later in dtls13HandshakeSend() */ @@ -19854,10 +19842,16 @@ static int GetInputData(WOLFSSL *ssl, word32 size) inSz = (int)(size - usedLength); /* from last partial read */ #ifdef WOLFSSL_DTLS - if (ssl->options.dtls) { - if (size < ssl->dtls_expected_rx) - dtlsExtra = (int)(ssl->dtls_expected_rx - size); - inSz = ssl->dtls_expected_rx; + if (ssl->options.dtls && IsDtlsNotSctpMode(ssl)) { + /* Add DTLS_MTU_ADDITIONAL_READ_BUFFER bytes so that we can operate with + * slight difference in set MTU size on each peer */ +#ifdef WOLFSSL_DTLS_MTU + inSz = (word32)ssl->dtlsMtuSz + DTLS_MTU_ADDITIONAL_READ_BUFFER; +#else + inSz = MAX_MTU + DTLS_MTU_ADDITIONAL_READ_BUFFER; +#endif + if (size < (word32)inSz) + dtlsExtra = (int)(inSz - size); } #endif diff --git a/src/ssl.c b/src/ssl.c index 1d33daa2a..a6188f68b 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -3338,22 +3338,6 @@ static int wolfSSL_read_internal(WOLFSSL* ssl, void* data, int sz, int peek) errno = 0; #endif -#ifdef WOLFSSL_DTLS - if (ssl->options.dtls) { - ssl->dtls_expected_rx = max(sz + DTLS_MTU_ADDITIONAL_READ_BUFFER, - MAX_MTU); -#ifdef WOLFSSL_SCTP - if (ssl->options.dtlsSctp) -#endif -#if defined(WOLFSSL_SCTP) || defined(WOLFSSL_DTLS_MTU) - /* Add some bytes so that we can operate with slight difference - * in set MTU size on each peer */ - ssl->dtls_expected_rx = max(ssl->dtls_expected_rx, - ssl->dtlsMtuSz + (word32)DTLS_MTU_ADDITIONAL_READ_BUFFER); -#endif - } -#endif - ret = ReceiveData(ssl, (byte*)data, sz, peek); #ifdef HAVE_WRITE_DUP diff --git a/wolfssl/internal.h b/wolfssl/internal.h index c983a39e1..aaee17948 100644 --- a/wolfssl/internal.h +++ b/wolfssl/internal.h @@ -5567,7 +5567,6 @@ struct WOLFSSL { DtlsMsg* dtls_tx_msg; DtlsMsg* dtls_rx_msg_list; void* IOCB_CookieCtx; /* gen cookie ctx */ - word32 dtls_expected_rx; #ifdef WOLFSSL_SESSION_EXPORT wc_dtls_export dtls_export; /* export function for session */ #endif