diff options
author | Matt Caswell <matt@openssl.org> | 2015-02-03 10:48:28 +0000 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2015-03-26 15:02:00 +0000 |
commit | 295c3f41113f4ff537fb95e29f7f709ba03c6a21 (patch) | |
tree | cb292176111dcc5a461969c3e807e233c7e6d3e5 | |
parent | 7a7048aff053929feaadee4895749fe0a661d353 (diff) | |
download | openssl-295c3f41113f4ff537fb95e29f7f709ba03c6a21.tar.gz |
Move s->rstate to s->rlayer.rstate
Reviewed-by: Richard Levitte <levitte@openssl.org>
-rw-r--r-- | ssl/record/d1_pkt.c | 6 | ||||
-rw-r--r-- | ssl/record/rec_layer.h | 5 | ||||
-rw-r--r-- | ssl/record/s3_pkt.c | 60 | ||||
-rw-r--r-- | ssl/record/ssl3_record.c | 22 | ||||
-rw-r--r-- | ssl/ssl.h | 4 | ||||
-rw-r--r-- | ssl/ssl_lib.c | 3 | ||||
-rw-r--r-- | ssl/ssl_locl.h | 2 | ||||
-rw-r--r-- | ssl/ssl_stat.c | 41 |
8 files changed, 79 insertions, 64 deletions
diff --git a/ssl/record/d1_pkt.c b/ssl/record/d1_pkt.c index 5ad4632454..5df1d3043a 100644 --- a/ssl/record/d1_pkt.c +++ b/ssl/record/d1_pkt.c @@ -450,7 +450,7 @@ int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek) 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); @@ -522,7 +522,7 @@ int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek) 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; } } @@ -629,7 +629,7 @@ int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek) */ FIX ME #endif - s->rstate = SSL_ST_READ_HEADER; + s->rlayer.rstate = SSL_ST_READ_HEADER; rr->length = 0; goto start; } diff --git a/ssl/record/rec_layer.h b/ssl/record/rec_layer.h index 2997419193..9111741f05 100644 --- a/ssl/record/rec_layer.h +++ b/ssl/record/rec_layer.h @@ -140,6 +140,8 @@ typedef struct record_layer_st { * 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 */ @@ -176,6 +178,7 @@ void RECORD_LAYER_release(RECORD_LAYER *rl); 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); @@ -203,6 +206,8 @@ void dtls1_reset_seq_numbers(SSL *s, int rw); #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, diff --git a/ssl/record/s3_pkt.c b/ssl/record/s3_pkt.c index 646fd334c1..f024ff58e6 100644 --- a/ssl/record/s3_pkt.c +++ b/ssl/record/s3_pkt.c @@ -163,6 +163,7 @@ void RECORD_LAYER_clear(RECORD_LAYER *rl) * that right? */ rl->read_ahead = read_ahead; + rl->rstate = SSL_ST_READ_HEADER; rl->s = s; } @@ -189,7 +190,7 @@ int RECORD_LAYER_set_data(RECORD_LAYER *rl, const unsigned char *buf, int len) { 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; @@ -201,15 +202,66 @@ int RECORD_LAYER_set_data(RECORD_LAYER *rl, const unsigned char *buf, int len) 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) { /* @@ -965,7 +1017,7 @@ int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek) 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); @@ -1017,7 +1069,7 @@ int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek) 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) diff --git a/ssl/record/ssl3_record.c b/ssl/record/ssl3_record.c index 74343229cc..16d181415f 100644 --- a/ssl/record/ssl3_record.c +++ b/ssl/record/ssl3_record.c @@ -207,13 +207,13 @@ int ssl3_get_record(SSL *s) 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) @@ -255,10 +255,10 @@ int ssl3_get_record(SSL *s) 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) { @@ -273,7 +273,8 @@ int ssl3_get_record(SSL *s) */ } - 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, @@ -1399,7 +1400,7 @@ int dtls1_get_record(SSL *s) /* 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); @@ -1413,7 +1414,7 @@ int dtls1_get_record(SSL *s) 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); @@ -1459,10 +1460,10 @@ int dtls1_get_record(SSL *s) 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) { @@ -1481,7 +1482,8 @@ int dtls1_get_record(SSL *s) * 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); @@ -999,8 +999,8 @@ extern "C" { # 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 diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index 892f2e3383..abb3fd301f 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -215,7 +215,6 @@ int SSL_clear(SSL *s) 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); @@ -2830,7 +2829,7 @@ SSL *SSL_dup(SSL *s) 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 */ diff --git a/ssl/ssl_locl.h b/ssl/ssl_locl.h index 27fba36748..056051a2e1 100644 --- a/ssl/ssl_locl.h +++ b/ssl/ssl_locl.h @@ -1022,8 +1022,6 @@ struct ssl_st { 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() */ diff --git a/ssl/ssl_stat.c b/ssl/ssl_stat.c index 4e39a9b8aa..258c4eb2b4 100644 --- a/ssl/ssl_stat.c +++ b/ssl/ssl_stat.c @@ -342,26 +342,6 @@ const char *SSL_state_string_long(const SSL *s) 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) { @@ -817,24 +797,3 @@ const char *SSL_alert_desc_string_long(int value) } 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); -} |