Sniffer Statistics

1. Added a structure for all the statistics to be kept.
2. Added a global to track the statistics.
3. Added a copy function to get a copy of the statistics.
4. Added a reset function for the statistics.
5. Handle the alert messages in statistics.
This commit is contained in:
John Safranek 2019-05-20 16:26:46 -07:00
parent f4548945f7
commit 2ee7d05dcc
2 changed files with 71 additions and 0 deletions

View File

@ -410,6 +410,10 @@ static word32 MissedDataSessions = 0; /* # of sessions with missed data */
static SSLConnCb ConnectionCb;
static void* ConnectionCbCtx = NULL;
/* Sessions Statistics */
static SSLStats SnifferStats;
static wolfSSL_Mutex StatsMutex;
static void UpdateMissedDataSessions(void)
{
@ -419,13 +423,21 @@ static void UpdateMissedDataSessions(void)
}
#define ADD_TO_STAT(x,y) do { wc_LockMutex(&StatsMutex); \
x += y; \
wc_UnLockMutex(&StatsMutex); } while (0)
#define INC_STAT(x) ADD_TO_STAT(x,1)
/* Initialize overall Sniffer */
void ssl_InitSniffer(void)
{
wolfSSL_Init();
XMEMSET(&SnifferStats, 0, sizeof(SSLStats));
wc_InitMutex(&ServerListMutex);
wc_InitMutex(&SessionMutex);
wc_InitMutex(&RecoveryMutex);
wc_InitMutex(&StatsMutex);
}
@ -3577,6 +3589,7 @@ doPart:
break;
case alert:
Trace(GOT_ALERT_STR);
INC_STAT(SnifferStats.sslAlerts);
sslFrame += rhSize;
sslBytes -= rhSize;
break;
@ -3845,6 +3858,30 @@ int ssl_SetConnectionCtx(void* ctx)
}
/* Resets the statistics tracking global structure.
* returns 0 on success, -1 on error */
int ssl_ResetStatistics(void)
{
wc_LockMutex(&StatsMutex);
XMEMSET(&SnifferStats, 0, sizeof(SSLStats));
wc_UnLockMutex(&StatsMutex);
return 0;
}
/* Copies the SSL statistics into the provided stats record.
* returns 0 on success, -1 on error */
int ssl_ReadStatistics(SSLStats* stats)
{
if (stats == NULL)
return -1;
wc_LockMutex(&StatsMutex);
XMEMCPY(stats, &SnifferStats, sizeof(SSLStats));
wc_UnLockMutex(&StatsMutex);
return 0;
}
#endif /* WOLFSSL_SNIFFER */
#endif /* WOLFCRYPT_ONLY */

View File

@ -134,6 +134,40 @@ WOLFSSL_API
SSL_SNIFFER_API int ssl_SetConnectionCtx(void* ctx);
typedef struct SSLStats
{
unsigned int sslStandardConns;
unsigned int sslRehandshakeConns;
unsigned int sslClientAuthConns;
unsigned int sslResumedConns;
unsigned int sslResumedRehandshakeConns;
unsigned int sslClientAuthRehandshakeConns;
unsigned int sslEphemeralMisses;
unsigned int sslResumeMisses;
unsigned int sslCiphersUnsupported;
unsigned int sslKeysUnmatched;
unsigned int sslKeyFails;
unsigned int sslDecodeFails;
unsigned int sslAlerts;
unsigned int sslDecryptedBytes;
unsigned int sslEncryptedBytes;
unsigned int sslEncryptedPackets;
unsigned int sslDecryptedPackets;
unsigned int sslEncryptedConns;
unsigned int sslKeyMatches;
unsigned int sslEncryptedConnsPerSecond;
unsigned int sslActiveFlowsPerSecond;
} SSLStats;
WOLFSSL_API
SSL_SNIFFER_API int ssl_ResetStatistics(void);
WOLFSSL_API
SSL_SNIFFER_API int ssl_ReadStatistics(SSLStats* stats);
#ifdef __cplusplus
} /* extern "C" */
#endif