Move s->rstate to s->rlayer.rstate
authorMatt Caswell <matt@openssl.org>
Tue, 3 Feb 2015 10:48:28 +0000 (10:48 +0000)
committerMatt Caswell <matt@openssl.org>
Thu, 26 Mar 2015 15:02:00 +0000 (15:02 +0000)
Reviewed-by: Richard Levitte <levitte@openssl.org>
ssl/record/d1_pkt.c
ssl/record/rec_layer.h
ssl/record/s3_pkt.c
ssl/record/ssl3_record.c
ssl/ssl.h
ssl/ssl_lib.c
ssl/ssl_locl.h
ssl/ssl_stat.c

index 5ad4632..5df1d30 100644 (file)
@@ -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;
             }
index 2997419..9111741 100644 (file)
@@ -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,
index 646fd33..f024ff5 100644 (file)
@@ -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)
index 7434322..16d1814 100644 (file)
@@ -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);
index 55aa6a6..50a79a8 100644 (file)
--- a/ssl/ssl.h
+++ b/ssl/ssl.h
@@ -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
index 892f2e3..abb3fd3 100644 (file)
@@ -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 */
index 27fba36..056051a 100644 (file)
@@ -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() */
index 4e39a9b..258c4eb 100644 (file)
@@ -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);
-}