[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openssl-dev
Subject:    [openssl-dev] [openssl.org #3873] [PATCH] Add traffic counters
From:       "Short, Todd via RT" <rt () openssl ! org>
Date:       2015-05-27 20:32:32
Message-ID: rt-4.0.4-1870-1432758752-749.3873-21-0 () openssl ! org
[Download RAW message or body]

Hello OpenSSL Org:

This is a change that Akamai has made to its implementation of OpenSSL.

Version: master branch
Description: Add traffic counters

Add data counters to SSL structure bytes_written and bytes_read
Includes SSL_get_byte_counters() API.

Github link:
https://github.com/akamai/openssl/commit/517559c8637cda3750b39017685742590f1b692e

And attachment.

Thank you.
--
-Todd Short
// tshort@akamai.com
// "One if by land, two if by sea, three if by the Internet."


["0016-Add-traffic-counters.patch" (application/octet-stream)]

From 517559c8637cda3750b39017685742590f1b692e Mon Sep 17 00:00:00 2001
From: Dancer Vesperman <dvesperm@akamai.com>
Date: Tue, 31 Mar 2015 14:51:59 -0400
Subject: [PATCH 16/26] Add traffic counters

Add data counters to SSL structure bytes_written and bytes_read

(cherry picked from commit 7709c18909a07c4c325d51132045bf19e4970458)

Conflicts:
	include/openssl/ssl.h
	ssl/record/rec_layer_s3.c
---
 include/openssl/ssl.h     |  2 +-
 ssl/record/rec_layer_s3.c |  1 +
 ssl/record/ssl3_record.c  |  4 ++++
 ssl/ssl_lib.c             | 10 ++++++++++
 ssl/ssl_locl.h            |  4 ++++
 5 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/include/openssl/ssl.h b/include/openssl/ssl.h
index 2cc92d2..d14460c 100644
--- a/include/openssl/ssl.h
+++ b/include/openssl/ssl.h
@@ -956,7 +956,6 @@ typedef struct {
     unsigned char *msg_end;
 } SSL_key_exch_prep_ctx;
 
-
 # define SSL_MAC_FLAG_READ_MAC_STREAM 1
 # define SSL_MAC_FLAG_WRITE_MAC_STREAM 2
 
@@ -1890,6 +1889,7 @@ void SSL_set_not_resumable_session_callback(SSL *ssl,
 void SSL_set_debug(SSL *s, int debug);
 __owur int SSL_cache_hit(SSL *s);
 __owur int SSL_is_server(SSL *s);
+void SSL_get_byte_counters(SSL *s, size_t *w, size_t *r);
 
 __owur __owur SSL_CONF_CTX *SSL_CONF_CTX_new(void);
 int SSL_CONF_CTX_finish(SSL_CONF_CTX *cctx);
diff --git a/ssl/record/rec_layer_s3.c b/ssl/record/rec_layer_s3.c
index ec245fc..c9b6b2d 100644
--- a/ssl/record/rec_layer_s3.c
+++ b/ssl/record/rec_layer_s3.c
@@ -673,6 +673,7 @@ int ssl3_writev_bytes(SSL *s, int type, const ssl_bucket *buckets,
             s->rlayer.wnum = tot;
             return i;
         }
+        s->bytes_written += i;
 
         if ((i == (int)n) ||
             (type == SSL3_RT_APPLICATION_DATA &&
diff --git a/ssl/record/ssl3_record.c b/ssl/record/ssl3_record.c
index 941ef8c..e58ef06 100644
--- a/ssl/record/ssl3_record.c
+++ b/ssl/record/ssl3_record.c
@@ -220,6 +220,7 @@ int ssl3_get_record(SSL *s)
             SSL3_BUFFER_get_len(&s->rlayer.rbuf), 0);
         if (n <= 0)
             return (n);         /* error or non-blocking */
+        s->bytes_read += n;
         RECORD_LAYER_set_rstate(&s->rlayer, SSL_ST_READ_BODY);
 
         p = RECORD_LAYER_get_packet(&s->rlayer);
@@ -309,6 +310,7 @@ int ssl3_get_record(SSL *s)
         n = ssl3_read_n(s, i, i, 1);
         if (n <= 0)
             return (n);         /* error or non-blocking io */
+        s->bytes_read += n;
     }
 
     /* set state for later operations */
@@ -1424,6 +1426,7 @@ int dtls1_get_record(SSL *s)
         /* read timeout is handled by dtls1_read_bytes */
         if (n <= 0)
             return (n);         /* error or non-blocking */
+        s->bytes_read += n;
 
         /* this packet contained a partial record, dump it */
         if (RECORD_LAYER_get_packet_length(&s->rlayer) != DTLS1_RT_HEADER_LENGTH) {
@@ -1493,6 +1496,7 @@ int dtls1_get_record(SSL *s)
             RECORD_LAYER_reset_packet_length(&s->rlayer);
             goto again;
         }
+        s->bytes_read += n;
 
         /*
          * now n == rr->length, and s->packet_length ==
diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c
index a556f08..b834c00 100644
--- a/ssl/ssl_lib.c
+++ b/ssl/ssl_lib.c
@@ -198,6 +198,8 @@ int SSL_clear(SSL *s)
         s->session = NULL;
     }
 
+    s->bytes_read = 0;
+    s->bytes_written = 0;
     s->error = 0;
     s->hit = 0;
     s->shutdown = 0;
@@ -3518,4 +3520,12 @@ void SSL_CTX_share_session_cache(SSL_CTX *a, SSL_CTX *b)
     CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
 }
 
+void SSL_get_byte_counters(SSL *s, size_t *w, size_t *r)
+{
+    if (w)
+        *w = s->bytes_written;
+    if (r)
+        *r = s->bytes_read;
+}
+
 IMPLEMENT_OBJ_BSEARCH_GLOBAL_CMP_FN(SSL_CIPHER, SSL_CIPHER, ssl_cipher_id);
diff --git a/ssl/ssl_locl.h b/ssl/ssl_locl.h
index ad8218c..2e83fa5 100644
--- a/ssl/ssl_locl.h
+++ b/ssl/ssl_locl.h
@@ -1239,6 +1239,10 @@ struct ssl_st {
             SSL_key_exch_prep_ctx kx_sign;
         } ctx;                 /* context/closure handed out to task */
     } task;
+
+    /* Keep track of bytes passed through SSL */
+    size_t bytes_written;
+    size_t bytes_read;
 };
 
 
-- 
2.3.2 (Apple Git-55)



_______________________________________________
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic