Skip to content

Commit

Permalink
Rename 'redis_tls_ctx' and 'redis_tls_client_ctx' global variables (#268
Browse files Browse the repository at this point in the history
)

Signed-off-by: Daniel House <daniel.house@huawei.com>
Signed-off-by: daniel-house <danny@cs.toronto.edu>
Co-authored-by: Daniel House <daniel.house@huawei.com>
  • Loading branch information
daniel-house and daniel-house-at-huawei authored Apr 10, 2024
1 parent 2e46046 commit b669af0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
8 changes: 4 additions & 4 deletions src/sentinel.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
extern char **environ;

#if USE_OPENSSL == 1 /* BUILD_YES */
extern SSL_CTX *redis_tls_ctx;
extern SSL_CTX *redis_tls_client_ctx;
extern SSL_CTX *valkey_tls_ctx;
extern SSL_CTX *valkey_tls_client_ctx;
#endif

#define REDIS_SENTINEL_PORT 26379
Expand Down Expand Up @@ -2377,8 +2377,8 @@ void sentinelSetClientName(sentinelRedisInstance *ri, redisAsyncContext *c, char

static int instanceLinkNegotiateTLS(redisAsyncContext *context) {
#if USE_OPENSSL == 1 /* BUILD_YES */
if (!redis_tls_ctx) return C_ERR;
SSL *ssl = SSL_new(redis_tls_client_ctx ? redis_tls_client_ctx : redis_tls_ctx);
if (!valkey_tls_ctx) return C_ERR;
SSL *ssl = SSL_new(valkey_tls_client_ctx ? valkey_tls_client_ctx : valkey_tls_ctx);
if (!ssl) return C_ERR;

if (redisInitiateSSL(&context->c, ssl) == REDIS_ERR) {
Expand Down
34 changes: 17 additions & 17 deletions src/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
#define REDIS_TLS_PROTO_DEFAULT (REDIS_TLS_PROTO_TLSv1_2)
#endif

SSL_CTX *redis_tls_ctx = NULL;
SSL_CTX *redis_tls_client_ctx = NULL;
SSL_CTX *valkey_tls_ctx = NULL;
SSL_CTX *valkey_tls_client_ctx = NULL;

static int parseProtocolsConfig(const char *str) {
int i, count = 0;
Expand Down Expand Up @@ -170,13 +170,13 @@ static void tlsInit(void) {
}

static void tlsCleanup(void) {
if (redis_tls_ctx) {
SSL_CTX_free(redis_tls_ctx);
redis_tls_ctx = NULL;
if (valkey_tls_ctx) {
SSL_CTX_free(valkey_tls_ctx);
valkey_tls_ctx = NULL;
}
if (redis_tls_client_ctx) {
SSL_CTX_free(redis_tls_client_ctx);
redis_tls_client_ctx = NULL;
if (valkey_tls_client_ctx) {
SSL_CTX_free(valkey_tls_client_ctx);
valkey_tls_client_ctx = NULL;
}

#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
Expand Down Expand Up @@ -284,15 +284,15 @@ static SSL_CTX *createSSLContext(serverTLSContextConfig *ctx_config, int protoco
* leave the SSL_CTX unchanged if fails.
* @priv: config of serverTLSContextConfig.
* @reconfigure: if true, ignore the previous configure; if false, only
* configure from @ctx_config if redis_tls_ctx is NULL.
* configure from @ctx_config if valkey_tls_ctx is NULL.
*/
static int tlsConfigure(void *priv, int reconfigure) {
serverTLSContextConfig *ctx_config = (serverTLSContextConfig *)priv;
char errbuf[256];
SSL_CTX *ctx = NULL;
SSL_CTX *client_ctx = NULL;

if (!reconfigure && redis_tls_ctx) {
if (!reconfigure && valkey_tls_ctx) {
return C_OK;
}

Expand Down Expand Up @@ -402,10 +402,10 @@ static int tlsConfigure(void *priv, int reconfigure) {
if (!client_ctx) goto error;
}

SSL_CTX_free(redis_tls_ctx);
SSL_CTX_free(redis_tls_client_ctx);
redis_tls_ctx = ctx;
redis_tls_client_ctx = client_ctx;
SSL_CTX_free(valkey_tls_ctx);
SSL_CTX_free(valkey_tls_client_ctx);
valkey_tls_ctx = ctx;
valkey_tls_client_ctx = client_ctx;

return C_OK;

Expand Down Expand Up @@ -457,9 +457,9 @@ typedef struct tls_connection {
} tls_connection;

static connection *createTLSConnection(int client_side) {
SSL_CTX *ctx = redis_tls_ctx;
if (client_side && redis_tls_client_ctx)
ctx = redis_tls_client_ctx;
SSL_CTX *ctx = valkey_tls_ctx;
if (client_side && valkey_tls_client_ctx)
ctx = valkey_tls_client_ctx;
tls_connection *conn = zcalloc(sizeof(tls_connection));
conn->c.type = &CT_TLS;
conn->c.fd = -1;
Expand Down

0 comments on commit b669af0

Please sign in to comment.