mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-31 19:24:42 +02:00
DTLS Multicast
1. Restore original EmbedRecvFrom callback. 2. Add new EmbedRecvFromMcast callback. (EmbedSendTo still the same.) 3. Set new receive from callback when setting the member ID. 4. Fixed bad rebase change.
This commit is contained in:
67
src/io.c
67
src/io.c
@@ -293,12 +293,12 @@ int EmbedReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *ctx)
|
||||
}
|
||||
}
|
||||
else {
|
||||
// if (dtlsCtx->peer.sz > 0
|
||||
// && peerSz != (XSOCKLENT)dtlsCtx->peer.sz
|
||||
// && XMEMCMP(&peer, dtlsCtx->peer.sa, peerSz) != 0) {
|
||||
// WOLFSSL_MSG(" Ignored packet from invalid peer");
|
||||
// return WOLFSSL_CBIO_ERR_WANT_READ;
|
||||
// }
|
||||
if (dtlsCtx->peer.sz > 0
|
||||
&& peerSz != (XSOCKLENT)dtlsCtx->peer.sz
|
||||
&& XMEMCMP(&peer, dtlsCtx->peer.sa, peerSz) != 0) {
|
||||
WOLFSSL_MSG(" Ignored packet from invalid peer");
|
||||
return WOLFSSL_CBIO_ERR_WANT_READ;
|
||||
}
|
||||
}
|
||||
|
||||
return recvd;
|
||||
@@ -354,6 +354,61 @@ int EmbedSendTo(WOLFSSL* ssl, char *buf, int sz, void *ctx)
|
||||
}
|
||||
|
||||
|
||||
#ifdef WOLFSSL_MULTICAST
|
||||
|
||||
/* The alternate receive embedded callback for Multicast
|
||||
* return : nb bytes read, or error
|
||||
*/
|
||||
int EmbedReceiveFromMcast(WOLFSSL *ssl, char *buf, int sz, void *ctx)
|
||||
{
|
||||
WOLFSSL_DTLS_CTX* dtlsCtx = (WOLFSSL_DTLS_CTX*)ctx;
|
||||
int recvd;
|
||||
int err;
|
||||
int sd = dtlsCtx->rfd;
|
||||
|
||||
WOLFSSL_ENTER("EmbedReceiveFromMcast()");
|
||||
|
||||
recvd = (int)RECVFROM_FUNCTION(sd, buf, sz, ssl->rflags, NULL, NULL);
|
||||
|
||||
recvd = TranslateReturnCode(recvd, sd);
|
||||
|
||||
if (recvd < 0) {
|
||||
err = LastError();
|
||||
WOLFSSL_MSG("Embed Receive From error");
|
||||
|
||||
if (err == SOCKET_EWOULDBLOCK || err == SOCKET_EAGAIN) {
|
||||
if (wolfSSL_get_using_nonblock(ssl)) {
|
||||
WOLFSSL_MSG("\tWould block");
|
||||
return WOLFSSL_CBIO_ERR_WANT_READ;
|
||||
}
|
||||
else {
|
||||
WOLFSSL_MSG("\tSocket timeout");
|
||||
return WOLFSSL_CBIO_ERR_TIMEOUT;
|
||||
}
|
||||
}
|
||||
else if (err == SOCKET_ECONNRESET) {
|
||||
WOLFSSL_MSG("\tConnection reset");
|
||||
return WOLFSSL_CBIO_ERR_CONN_RST;
|
||||
}
|
||||
else if (err == SOCKET_EINTR) {
|
||||
WOLFSSL_MSG("\tSocket interrupted");
|
||||
return WOLFSSL_CBIO_ERR_ISR;
|
||||
}
|
||||
else if (err == SOCKET_ECONNREFUSED) {
|
||||
WOLFSSL_MSG("\tConnection refused");
|
||||
return WOLFSSL_CBIO_ERR_WANT_READ;
|
||||
}
|
||||
else {
|
||||
WOLFSSL_MSG("\tGeneral error");
|
||||
return WOLFSSL_CBIO_ERR_GENERAL;
|
||||
}
|
||||
}
|
||||
|
||||
return recvd;
|
||||
}
|
||||
#endif /* WOLFSSL_MULTICAST */
|
||||
|
||||
|
||||
/* The DTLS Generate Cookie callback
|
||||
* return : number of bytes copied into buf, or error
|
||||
*/
|
||||
|
@@ -859,6 +859,9 @@ int wolfSSL_CTX_mcast_set_member_id(WOLFSSL_CTX* ctx, word16 id)
|
||||
ctx->haveEMS = 0;
|
||||
ctx->haveMcast = 1;
|
||||
ctx->mcastID = id;
|
||||
#ifndef WOLFSSL_USER_IO
|
||||
ctx->CBIORecv = EmbedReceiveFromMcast;
|
||||
#endif /* WOLFSSL_USER_IO */
|
||||
}
|
||||
|
||||
if (ret == 0)
|
||||
|
@@ -2872,13 +2872,11 @@ typedef struct Options {
|
||||
#endif
|
||||
#ifdef WOLFSSL_DTLS
|
||||
word16 dtlsHsRetain:1; /* DTLS retaining HS data */
|
||||
word16 haveMcast:1; /* using multicast ? */
|
||||
#ifdef WOLFSSL_SCTP
|
||||
word16 dtlsSctp:1; /* DTLS-over-SCTP mode */
|
||||
#endif
|
||||
#endif
|
||||
word16 haveMcast:1; /* using multicast ? */
|
||||
#endif
|
||||
word16 haveEMS:1; /* using extended master secret */
|
||||
#if defined(HAVE_TLS_EXTENSIONS) && defined(HAVE_SUPPORTED_CURVES)
|
||||
word16 userCurves:1; /* indicates user called wolfSSL_UseSupportedCurve */
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user