Formatted tee filter
Tee filter formatted according to the style guide.
This commit is contained in:
@ -45,6 +45,7 @@
|
|||||||
*
|
*
|
||||||
* @endverbatim
|
* @endverbatim
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <filter.h>
|
#include <filter.h>
|
||||||
@ -83,7 +84,8 @@
|
|||||||
static int debug_seq = 0;
|
static int debug_seq = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static unsigned char required_packets[] = {
|
static unsigned char required_packets[] =
|
||||||
|
{
|
||||||
MYSQL_COM_QUIT,
|
MYSQL_COM_QUIT,
|
||||||
MYSQL_COM_INITDB,
|
MYSQL_COM_INITDB,
|
||||||
MYSQL_COM_FIELD_LIST,
|
MYSQL_COM_FIELD_LIST,
|
||||||
@ -94,9 +96,11 @@ static unsigned char required_packets[] = {
|
|||||||
MYSQL_COM_STMT_CLOSE,
|
MYSQL_COM_STMT_CLOSE,
|
||||||
MYSQL_COM_STMT_RESET,
|
MYSQL_COM_STMT_RESET,
|
||||||
MYSQL_COM_CONNECT,
|
MYSQL_COM_CONNECT,
|
||||||
0 };
|
0
|
||||||
|
};
|
||||||
|
|
||||||
MODULE_INFO info = {
|
MODULE_INFO info =
|
||||||
|
{
|
||||||
MODULE_API_FILTER,
|
MODULE_API_FILTER,
|
||||||
MODULE_GA,
|
MODULE_GA,
|
||||||
FILTER_VERSION,
|
FILTER_VERSION,
|
||||||
@ -118,7 +122,8 @@ static int routeQuery(FILTER *instance, void *fsession, GWBUF *queue);
|
|||||||
static int clientReply(FILTER *instance, void *fsession, GWBUF *queue);
|
static int clientReply(FILTER *instance, void *fsession, GWBUF *queue);
|
||||||
static void diagnostic(FILTER *instance, void *fsession, DCB *dcb);
|
static void diagnostic(FILTER *instance, void *fsession, DCB *dcb);
|
||||||
|
|
||||||
static FILTER_OBJECT MyObject = {
|
static FILTER_OBJECT MyObject =
|
||||||
|
{
|
||||||
createInstance,
|
createInstance,
|
||||||
newSession,
|
newSession,
|
||||||
closeSession,
|
closeSession,
|
||||||
@ -134,7 +139,8 @@ static FILTER_OBJECT MyObject = {
|
|||||||
* The instance structure for the TEE filter - this holds the configuration
|
* The instance structure for the TEE filter - this holds the configuration
|
||||||
* information for the filter.
|
* information for the filter.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
SERVICE *service; /* The service to duplicate requests to */
|
SERVICE *service; /* The service to duplicate requests to */
|
||||||
char *source; /* The source of the client connection */
|
char *source; /* The source of the client connection */
|
||||||
char *userName; /* The user name to filter on */
|
char *userName; /* The user name to filter on */
|
||||||
@ -152,10 +158,10 @@ typedef struct {
|
|||||||
*
|
*
|
||||||
* It also holds the file descriptor to which queries are written.
|
* It also holds the file descriptor to which queries are written.
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
DOWNSTREAM down; /* The downstream filter */
|
DOWNSTREAM down; /* The downstream filter */
|
||||||
UPSTREAM up; /* The upstream filter */
|
UPSTREAM up; /* The upstream filter */
|
||||||
|
|
||||||
FILTER_DEF* dummy_filterdef;
|
FILTER_DEF* dummy_filterdef;
|
||||||
int active; /* filter is active? */
|
int active; /* filter is active? */
|
||||||
bool use_ok;
|
bool use_ok;
|
||||||
@ -221,8 +227,6 @@ orphan_free(void* data)
|
|||||||
{
|
{
|
||||||
if (ptr->session->state == SESSION_STATE_TO_BE_FREED)
|
if (ptr->session->state == SESSION_STATE_TO_BE_FREED)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
if (ptr == allOrphans)
|
if (ptr == allOrphans)
|
||||||
{
|
{
|
||||||
tmp = ptr;
|
tmp = ptr;
|
||||||
@ -232,14 +236,15 @@ orphan_free(void* data)
|
|||||||
{
|
{
|
||||||
tmp = allOrphans;
|
tmp = allOrphans;
|
||||||
while (tmp && tmp->next != ptr)
|
while (tmp && tmp->next != ptr)
|
||||||
|
{
|
||||||
tmp = tmp->next;
|
tmp = tmp->next;
|
||||||
|
}
|
||||||
if (tmp)
|
if (tmp)
|
||||||
{
|
{
|
||||||
tmp->next = ptr->next;
|
tmp->next = ptr->next;
|
||||||
tmp = ptr;
|
tmp = ptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -274,9 +279,11 @@ orphan_free(void* data)
|
|||||||
|
|
||||||
#ifdef SS_DEBUG
|
#ifdef SS_DEBUG
|
||||||
if (o_stopping + o_ready > 0)
|
if (o_stopping + o_ready > 0)
|
||||||
|
{
|
||||||
MXS_DEBUG("tee.c: %d orphans in "
|
MXS_DEBUG("tee.c: %d orphans in "
|
||||||
"SESSION_STATE_STOPPING, %d orphans in "
|
"SESSION_STATE_STOPPING, %d orphans in "
|
||||||
"SESSION_STATE_ROUTER_READY. ", o_stopping, o_ready);
|
"SESSION_STATE_ROUTER_READY. ", o_stopping, o_ready);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (finished)
|
while (finished)
|
||||||
@ -387,9 +394,13 @@ int i;
|
|||||||
my_instance->nomatch = strdup(params[i]->value);
|
my_instance->nomatch = strdup(params[i]->value);
|
||||||
}
|
}
|
||||||
else if (!strcmp(params[i]->name, "source"))
|
else if (!strcmp(params[i]->name, "source"))
|
||||||
|
{
|
||||||
my_instance->source = strdup(params[i]->value);
|
my_instance->source = strdup(params[i]->value);
|
||||||
|
}
|
||||||
else if (!strcmp(params[i]->name, "user"))
|
else if (!strcmp(params[i]->name, "user"))
|
||||||
|
{
|
||||||
my_instance->userName = strdup(params[i]->value);
|
my_instance->userName = strdup(params[i]->value);
|
||||||
|
}
|
||||||
else if (!filter_standard_parameter(params[i]->name))
|
else if (!filter_standard_parameter(params[i]->name))
|
||||||
{
|
{
|
||||||
MXS_ERROR("tee: Unexpected parameter '%s'.",
|
MXS_ERROR("tee: Unexpected parameter '%s'.",
|
||||||
@ -683,13 +694,16 @@ MXS_INFO("Tee free: %d", atomic_add(&debug_seq,1));
|
|||||||
filter_free(my_session->dummy_filterdef);
|
filter_free(my_session->dummy_filterdef);
|
||||||
}
|
}
|
||||||
if (my_session->tee_replybuf)
|
if (my_session->tee_replybuf)
|
||||||
|
{
|
||||||
gwbuf_free(my_session->tee_replybuf);
|
gwbuf_free(my_session->tee_replybuf);
|
||||||
|
}
|
||||||
free(session);
|
free(session);
|
||||||
|
|
||||||
orphan_free(NULL);
|
orphan_free(NULL);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the downstream filter or router to which queries will be
|
* Set the downstream filter or router to which queries will be
|
||||||
* passed from this filter.
|
* passed from this filter.
|
||||||
@ -789,7 +803,9 @@ routeQuery(FILTER *instance, void *session, GWBUF *queue)
|
|||||||
|
|
||||||
/* Reset session state */
|
/* Reset session state */
|
||||||
if (!reset_session_state(my_session, buffer))
|
if (!reset_session_state(my_session, buffer))
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/** Route query downstream */
|
/** Route query downstream */
|
||||||
spinlock_acquire(&my_session->tee_lock);
|
spinlock_acquire(&my_session->tee_lock);
|
||||||
@ -821,7 +837,10 @@ int count_replies(GWBUF* buffer)
|
|||||||
if (PTR_IS_EOF(ptr) || PTR_IS_ERR(ptr)) eof++;
|
if (PTR_IS_EOF(ptr) || PTR_IS_ERR(ptr)) eof++;
|
||||||
ptr += pktlen;
|
ptr += pktlen;
|
||||||
}
|
}
|
||||||
if(eof == 2) replies++;
|
if (eof == 2)
|
||||||
|
{
|
||||||
|
replies++;
|
||||||
|
}
|
||||||
eof = 0;
|
eof = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -833,14 +852,22 @@ int lenenc_length(uint8_t* ptr)
|
|||||||
{
|
{
|
||||||
char val = *ptr;
|
char val = *ptr;
|
||||||
if (val < 251)
|
if (val < 251)
|
||||||
|
{
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
else if (val == 0xfc)
|
else if (val == 0xfc)
|
||||||
|
{
|
||||||
return 3;
|
return 3;
|
||||||
|
}
|
||||||
else if (val == 0xfd)
|
else if (val == 0xfd)
|
||||||
|
{
|
||||||
return 4;
|
return 4;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return 9;
|
return 9;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t get_response_flags(uint8_t* datastart, bool ok_packet)
|
uint16_t get_response_flags(uint8_t* datastart, bool ok_packet)
|
||||||
{
|
{
|
||||||
@ -1102,19 +1129,27 @@ TEE_INSTANCE *my_instance = (TEE_INSTANCE *)instance;
|
|||||||
TEE_SESSION *my_session = (TEE_SESSION *) fsession;
|
TEE_SESSION *my_session = (TEE_SESSION *) fsession;
|
||||||
|
|
||||||
if (my_instance->source)
|
if (my_instance->source)
|
||||||
|
{
|
||||||
dcb_printf(dcb, "\t\tLimit to connections from %s\n",
|
dcb_printf(dcb, "\t\tLimit to connections from %s\n",
|
||||||
my_instance->source);
|
my_instance->source);
|
||||||
|
}
|
||||||
dcb_printf(dcb, "\t\tDuplicate statements to service %s\n",
|
dcb_printf(dcb, "\t\tDuplicate statements to service %s\n",
|
||||||
my_instance->service->name);
|
my_instance->service->name);
|
||||||
if (my_instance->userName)
|
if (my_instance->userName)
|
||||||
|
{
|
||||||
dcb_printf(dcb, "\t\tLimit to user %s\n",
|
dcb_printf(dcb, "\t\tLimit to user %s\n",
|
||||||
my_instance->userName);
|
my_instance->userName);
|
||||||
|
}
|
||||||
if (my_instance->match)
|
if (my_instance->match)
|
||||||
|
{
|
||||||
dcb_printf(dcb, "\t\tInclude queries that match %s\n",
|
dcb_printf(dcb, "\t\tInclude queries that match %s\n",
|
||||||
my_instance->match);
|
my_instance->match);
|
||||||
|
}
|
||||||
if (my_instance->nomatch)
|
if (my_instance->nomatch)
|
||||||
|
{
|
||||||
dcb_printf(dcb, "\t\tExclude queries that match %s\n",
|
dcb_printf(dcb, "\t\tExclude queries that match %s\n",
|
||||||
my_instance->nomatch);
|
my_instance->nomatch);
|
||||||
|
}
|
||||||
if (my_session)
|
if (my_session)
|
||||||
{
|
{
|
||||||
dcb_printf(dcb, "\t\tNo. of statements duplicated: %d.\n",
|
dcb_printf(dcb, "\t\tNo. of statements duplicated: %d.\n",
|
||||||
@ -1140,9 +1175,15 @@ int i;
|
|||||||
|
|
||||||
ptr = GWBUF_DATA(queue);
|
ptr = GWBUF_DATA(queue);
|
||||||
if (GWBUF_LENGTH(queue) > 4)
|
if (GWBUF_LENGTH(queue) > 4)
|
||||||
|
{
|
||||||
for (i = 0; required_packets[i]; i++)
|
for (i = 0; required_packets[i]; i++)
|
||||||
|
{
|
||||||
if (ptr[4] == required_packets[i])
|
if (ptr[4] == required_packets[i])
|
||||||
|
{
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1319,7 +1360,9 @@ int route_single_query(TEE_INSTANCE* my_instance, TEE_SESSION* my_session, GWBUF
|
|||||||
int reset_session_state(TEE_SESSION* my_session, GWBUF* buffer)
|
int reset_session_state(TEE_SESSION* my_session, GWBUF* buffer)
|
||||||
{
|
{
|
||||||
if (gwbuf_length(buffer) < 5)
|
if (gwbuf_length(buffer) < 5)
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned char command = *((unsigned char*) buffer->start + 4);
|
unsigned char command = *((unsigned char*) buffer->start + 4);
|
||||||
|
|
||||||
@ -1358,7 +1401,9 @@ void create_orphan(SESSION* ses)
|
|||||||
MXS_ERROR("Failed to "
|
MXS_ERROR("Failed to "
|
||||||
"allocate memory for orphan session struct, "
|
"allocate memory for orphan session struct, "
|
||||||
"child session might leak memory.");
|
"child session might leak memory.");
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
orphan->session = ses;
|
orphan->session = ses;
|
||||||
spinlock_acquire(&orphanLock);
|
spinlock_acquire(&orphanLock);
|
||||||
orphan->next = allOrphans;
|
orphan->next = allOrphans;
|
||||||
|
Reference in New Issue
Block a user