Add BIO_CTRL_DGRAM_SET_PEEK_MODE

Add the ability to peek at a message from the DTLS read BIO. This is needed
for the DTLSv1_listen rewrite.

Reviewed-by: Andy Polyakov <appro@openssl.org>
This commit is contained in:
Matt Caswell 2015-09-14 22:36:04 +01:00
parent 1556d21850
commit 01b7851aa2
2 changed files with 10 additions and 1 deletions

View File

@ -169,6 +169,7 @@ typedef struct bio_dgram_data_st {
unsigned int mtu; unsigned int mtu;
struct timeval next_timeout; struct timeval next_timeout;
struct timeval socket_timeout; struct timeval socket_timeout;
unsigned int peekmode;
} bio_dgram_data; } bio_dgram_data;
# ifndef OPENSSL_NO_SCTP # ifndef OPENSSL_NO_SCTP
@ -367,6 +368,7 @@ static int dgram_read(BIO *b, char *out, int outl)
{ {
int ret = 0; int ret = 0;
bio_dgram_data *data = (bio_dgram_data *)b->ptr; bio_dgram_data *data = (bio_dgram_data *)b->ptr;
int flags = 0;
struct { struct {
/* /*
@ -392,7 +394,9 @@ static int dgram_read(BIO *b, char *out, int outl)
clear_socket_error(); clear_socket_error();
memset(&sa.peer, 0, sizeof(sa.peer)); memset(&sa.peer, 0, sizeof(sa.peer));
dgram_adjust_rcv_timeout(b); dgram_adjust_rcv_timeout(b);
ret = recvfrom(b->num, out, outl, 0, &sa.peer.sa, (void *)&sa.len); if (data->peekmode)
flags = MSG_PEEK;
ret = recvfrom(b->num, out, outl, flags, &sa.peer.sa, (void *)&sa.len);
if (sizeof(sa.len.i) != sizeof(sa.len.s) && sa.len.i == 0) { if (sizeof(sa.len.i) != sizeof(sa.len.s) && sa.len.i == 0) {
OPENSSL_assert(sa.len.s <= sizeof(sa.peer)); OPENSSL_assert(sa.len.s <= sizeof(sa.peer));
sa.len.i = (int)sa.len.s; sa.len.i = (int)sa.len.s;
@ -923,6 +927,9 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
case BIO_CTRL_DGRAM_GET_MTU_OVERHEAD: case BIO_CTRL_DGRAM_GET_MTU_OVERHEAD:
ret = dgram_get_mtu_overhead(data); ret = dgram_get_mtu_overhead(data);
break; break;
case BIO_CTRL_DGRAM_SET_PEEK_MODE:
data->peekmode = (unsigned int)num;
break;
default: default:
ret = 0; ret = 0;
break; break;

View File

@ -178,6 +178,8 @@ extern "C" {
# define BIO_CTRL_DGRAM_GET_MTU_OVERHEAD 49 # define BIO_CTRL_DGRAM_GET_MTU_OVERHEAD 49
# define BIO_CTRL_DGRAM_SET_PEEK_MODE 50
# ifndef OPENSSL_NO_SCTP # ifndef OPENSSL_NO_SCTP
/* SCTP stuff */ /* SCTP stuff */
# define BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE 50 # define BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE 50