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:
John Safranek
2017-01-23 10:16:04 -08:00
parent af1a9ca908
commit 6097d29045
3 changed files with 65 additions and 9 deletions

View File

@@ -293,12 +293,12 @@ int EmbedReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *ctx)
} }
} }
else { else {
// if (dtlsCtx->peer.sz > 0 if (dtlsCtx->peer.sz > 0
// && peerSz != (XSOCKLENT)dtlsCtx->peer.sz && peerSz != (XSOCKLENT)dtlsCtx->peer.sz
// && XMEMCMP(&peer, dtlsCtx->peer.sa, peerSz) != 0) { && XMEMCMP(&peer, dtlsCtx->peer.sa, peerSz) != 0) {
// WOLFSSL_MSG(" Ignored packet from invalid peer"); WOLFSSL_MSG(" Ignored packet from invalid peer");
// return WOLFSSL_CBIO_ERR_WANT_READ; return WOLFSSL_CBIO_ERR_WANT_READ;
// } }
} }
return recvd; 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 /* The DTLS Generate Cookie callback
* return : number of bytes copied into buf, or error * return : number of bytes copied into buf, or error
*/ */

View File

@@ -859,6 +859,9 @@ int wolfSSL_CTX_mcast_set_member_id(WOLFSSL_CTX* ctx, word16 id)
ctx->haveEMS = 0; ctx->haveEMS = 0;
ctx->haveMcast = 1; ctx->haveMcast = 1;
ctx->mcastID = id; ctx->mcastID = id;
#ifndef WOLFSSL_USER_IO
ctx->CBIORecv = EmbedReceiveFromMcast;
#endif /* WOLFSSL_USER_IO */
} }
if (ret == 0) if (ret == 0)

View File

@@ -2872,13 +2872,11 @@ typedef struct Options {
#endif #endif
#ifdef WOLFSSL_DTLS #ifdef WOLFSSL_DTLS
word16 dtlsHsRetain:1; /* DTLS retaining HS data */ word16 dtlsHsRetain:1; /* DTLS retaining HS data */
word16 haveMcast:1; /* using multicast ? */
#ifdef WOLFSSL_SCTP #ifdef WOLFSSL_SCTP
word16 dtlsSctp:1; /* DTLS-over-SCTP mode */ word16 dtlsSctp:1; /* DTLS-over-SCTP mode */
#endif #endif
#endif #endif
word16 haveMcast:1; /* using multicast ? */
#endif
word16 haveEMS:1; /* using extended master secret */
#if defined(HAVE_TLS_EXTENSIONS) && defined(HAVE_SUPPORTED_CURVES) #if defined(HAVE_TLS_EXTENSIONS) && defined(HAVE_SUPPORTED_CURVES)
word16 userCurves:1; /* indicates user called wolfSSL_UseSupportedCurve */ word16 userCurves:1; /* indicates user called wolfSSL_UseSupportedCurve */
#endif #endif