goto start;
/* get new packet if necessary */
- if ((rr->length == 0) || (s->rstate == SSL_ST_READ_BODY)) {
+ if ((rr->length == 0) || (s->rlayer.rstate == SSL_ST_READ_BODY)) {
ret = dtls1_get_record(s);
if (ret <= 0) {
ret = dtls1_read_failed(s, ret);
rr->length -= n;
rr->off += n;
if (rr->length == 0) {
- s->rstate = SSL_ST_READ_HEADER;
+ s->rlayer.rstate = SSL_ST_READ_HEADER;
rr->off = 0;
}
}
*/
FIX ME
#endif
- s->rstate = SSL_ST_READ_HEADER;
+ s->rlayer.rstate = SSL_ST_READ_HEADER;
rr->length = 0;
goto start;
}
* non-blocking reads)
*/
int read_ahead;
+ /* where we are when reading */
+ int rstate;
/* read IO goes into here */
SSL3_BUFFER rbuf;
/* write IO goes into here */
int RECORD_LAYER_read_pending(RECORD_LAYER *rl);
int RECORD_LAYER_write_pending(RECORD_LAYER *rl);
int RECORD_LAYER_set_data(RECORD_LAYER *rl, const unsigned char *buf, int len);
+void RECORD_LAYER_dup(RECORD_LAYER *dst, RECORD_LAYER *src);
__owur int ssl3_pending(const SSL *s);
__owur int ssl23_read_bytes(SSL *s, int n);
__owur int ssl23_write_bytes(SSL *s);
#define RECORD_LAYER_get_wrec(rl) (&(rl)->wrec)
#define RECORD_LAYER_set_packet(rl, p) ((rl)->packet = (p))
#define RECORD_LAYER_reset_packet_length(rl) ((rl)->packet_length = 0)
+#define RECORD_LAYER_get_rstate(rl) ((rl)->rstate)
+#define RECORD_LAYER_set_rstate(rl, st) ((rl)->rstate = (st))
__owur int ssl3_read_n(SSL *s, int n, int max, int extend);
__owur int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
* that right?
*/
rl->read_ahead = read_ahead;
+ rl->rstate = SSL_ST_READ_HEADER;
rl->s = s;
}
{
rl->packet_length = len;
if(len != 0) {
- rl->s->rstate = SSL_ST_READ_HEADER;
+ rl->rstate = SSL_ST_READ_HEADER;
if (!SSL3_BUFFER_is_initialised(&rl->rbuf))
if (!ssl3_setup_read_buffer(rl->s))
return 0;
return 1;
}
+void RECORD_LAYER_dup(RECORD_LAYER *dst, RECORD_LAYER *src)
+{
+ /*
+ * Currently only called from SSL_dup...which only seems to expect the
+ * rstate to be duplicated and nothing else from the RECORD_LAYER???
+ */
+ dst->rstate = src->rstate;
+}
+
int ssl3_pending(const SSL *s)
{
- if (s->rstate == SSL_ST_READ_BODY)
+ if (s->rlayer.rstate == SSL_ST_READ_BODY)
return 0;
return (SSL3_RECORD_get_type(&s->rlayer.rrec) == SSL3_RT_APPLICATION_DATA)
? SSL3_RECORD_get_length(&s->rlayer.rrec) : 0;
}
+const char *SSL_rstate_string_long(const SSL *s)
+{
+ const char *str;
+
+ switch (s->rlayer.rstate) {
+ case SSL_ST_READ_HEADER:
+ str = "read header";
+ break;
+ case SSL_ST_READ_BODY:
+ str = "read body";
+ break;
+ case SSL_ST_READ_DONE:
+ str = "read done";
+ break;
+ default:
+ str = "unknown";
+ break;
+ }
+ return (str);
+}
+
+const char *SSL_rstate_string(const SSL *s)
+{
+ const char *str;
+
+ switch (s->rlayer.rstate) {
+ case SSL_ST_READ_HEADER:
+ str = "RH";
+ break;
+ case SSL_ST_READ_BODY:
+ str = "RB";
+ break;
+ case SSL_ST_READ_DONE:
+ str = "RD";
+ break;
+ default:
+ str = "unknown";
+ break;
+ }
+ return (str);
+}
+
int ssl3_read_n(SSL *s, int n, int max, int extend)
{
/*
rr = &s->rlayer.rrec;
/* get new packet if necessary */
- if ((rr->length == 0) || (s->rstate == SSL_ST_READ_BODY)) {
+ if ((rr->length == 0) || (s->rlayer.rstate == SSL_ST_READ_BODY)) {
ret = ssl3_get_record(s);
if (ret <= 0)
return (ret);
rr->length -= n;
rr->off += n;
if (rr->length == 0) {
- s->rstate = SSL_ST_READ_HEADER;
+ s->rlayer.rstate = SSL_ST_READ_HEADER;
rr->off = 0;
if (s->mode & SSL_MODE_RELEASE_BUFFERS
&& SSL3_BUFFER_get_left(&s->rlayer.rbuf) == 0)
again:
/* check if we have the header */
- if ((s->rstate != SSL_ST_READ_BODY) ||
+ if ((RECORD_LAYER_get_rstate(&s->rlayer) != SSL_ST_READ_BODY) ||
(RECORD_LAYER_get_packet_length(&s->rlayer) < SSL3_RT_HEADER_LENGTH)) {
n = ssl3_read_n(s, SSL3_RT_HEADER_LENGTH,
SSL3_BUFFER_get_len(&s->rlayer.rbuf), 0);
if (n <= 0)
return (n); /* error or non-blocking */
- s->rstate = SSL_ST_READ_BODY;
+ RECORD_LAYER_set_rstate(&s->rlayer, SSL_ST_READ_BODY);
p = RECORD_LAYER_get_packet(&s->rlayer);
if (s->msg_callback)
goto f_err;
}
- /* now s->rstate == SSL_ST_READ_BODY */
+ /* now s->rlayer.rstate == SSL_ST_READ_BODY */
}
- /* s->rstate == SSL_ST_READ_BODY, get and decode the data */
+ /* s->rlayer.rstate == SSL_ST_READ_BODY, get and decode the data */
if (rr->length >
RECORD_LAYER_get_packet_length(&s->rlayer) - SSL3_RT_HEADER_LENGTH) {
*/
}
- s->rstate = SSL_ST_READ_HEADER; /* set state for later operations */
+ /* set state for later operations */
+ RECORD_LAYER_set_rstate(&s->rlayer, SSL_ST_READ_HEADER);
/*
* At this point, s->packet_length == SSL3_RT_HEADER_LNGTH + rr->length,
/* get something from the wire */
again:
/* check if we have the header */
- if ((s->rstate != SSL_ST_READ_BODY) ||
+ if ((RECORD_LAYER_get_rstate(&s->rlayer) != SSL_ST_READ_BODY) ||
(RECORD_LAYER_get_packet_length(&s->rlayer) < DTLS1_RT_HEADER_LENGTH)) {
n = ssl3_read_n(s, DTLS1_RT_HEADER_LENGTH,
SSL3_BUFFER_get_len(&s->rlayer.rbuf), 0);
goto again;
}
- s->rstate = SSL_ST_READ_BODY;
+ RECORD_LAYER_set_rstate(&s->rlayer, SSL_ST_READ_BODY);
p = RECORD_LAYER_get_packet(&s->rlayer);
goto again;
}
- /* now s->rstate == SSL_ST_READ_BODY */
+ /* now s->rlayer.rstate == SSL_ST_READ_BODY */
}
- /* s->rstate == SSL_ST_READ_BODY, get and decode the data */
+ /* s->rlayer.rstate == SSL_ST_READ_BODY, get and decode the data */
if (rr->length >
RECORD_LAYER_get_packet_length(&s->rlayer) - DTLS1_RT_HEADER_LENGTH) {
* DTLS1_RT_HEADER_LENGTH + rr->length
*/
}
- s->rstate = SSL_ST_READ_HEADER; /* set state for later operations */
+ /* set state for later operations */
+ RECORD_LAYER_set_rstate(&s->rlayer, SSL_ST_READ_HEADER);
/* match epochs. NULL means the packet is dropped on the floor */
bitmap = dtls1_get_bitmap(s, rr, &is_next_epoch);
# define SSL_in_accept_init(a) (SSL_state(a)&SSL_ST_ACCEPT)
/*
- * The following 2 states are kept in ssl->rstate when reads fail, you should
- * not need these
+ * The following 3 states are kept in ssl->rlayer.rstate when reads fail, you
+ * should not need these
*/
# define SSL_ST_READ_HEADER 0xF0
# define SSL_ST_READ_BODY 0xF1
s->version = s->method->version;
s->client_version = s->version;
s->rwstate = SSL_NOTHING;
- s->rstate = SSL_ST_READ_HEADER;
if (s->init_buf != NULL) {
BUF_MEM_free(s->init_buf);
ret->shutdown = s->shutdown;
ret->state = s->state; /* SSL_dup does not really work at any state,
* though */
- ret->rstate = s->rstate;
+ RECORD_LAYER_dup(&ret->rlayer, &s->rlayer);
ret->init_num = 0; /* would have to copy ret->init_buf,
* ret->init_msg, ret->init_num,
* ret->init_off */
int shutdown;
/* where we are */
int state;
- /* where we are when reading */
- int rstate;
BUF_MEM *init_buf; /* buffer used during init */
void *init_msg; /* pointer to handshake message body, set by
* ssl3_get_message() */
return (str);
}
-const char *SSL_rstate_string_long(const SSL *s)
-{
- const char *str;
-
- switch (s->rstate) {
- case SSL_ST_READ_HEADER:
- str = "read header";
- break;
- case SSL_ST_READ_BODY:
- str = "read body";
- break;
- case SSL_ST_READ_DONE:
- str = "read done";
- break;
- default:
- str = "unknown";
- break;
- }
- return (str);
-}
const char *SSL_state_string(const SSL *s)
{
}
return (str);
}
-
-const char *SSL_rstate_string(const SSL *s)
-{
- const char *str;
-
- switch (s->rstate) {
- case SSL_ST_READ_HEADER:
- str = "RH";
- break;
- case SSL_ST_READ_BODY:
- str = "RB";
- break;
- case SSL_ST_READ_DONE:
- str = "RD";
- break;
- default:
- str = "unknown";
- break;
- }
- return (str);
-}