Reapply MXS-504 changes subsequent to optimisation changes. Merge SSL processing into non-SSL processing so far as possible, correct usage of OpenSSL, simplify where possible.

This commit is contained in:
counterpoint
2016-01-13 10:08:37 +00:00
parent d13bec0647
commit 5515c71988
6 changed files with 622 additions and 932 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1567,7 +1567,44 @@ static void poll_add_event_to_dcb(DCB* dcb,
void void
poll_fake_write_event(DCB *dcb) poll_fake_write_event(DCB *dcb)
{ {
uint32_t ev = EPOLLOUT; poll_fake_event(dcb, EPOLLOUT);
}
/*
* Insert a fake read completion event for a DCB into the polling
* queue.
*
* This is used to trigger transmission activity on another DCB from
* within the event processing routine of a DCB. or to allow a DCB
* to defer some further input processing, to allow for other DCBs
* to receive a slice of the processing time. Fake events are added
* to the tail of the event queue, in the same way that real events
* are, so maintain the "fairness" of processing.
*
* @param dcb DCB to emulate an EPOLLIN event for
*/
void
poll_fake_read_event(DCB *dcb)
{
poll_fake_event(dcb, EPOLLIN);
}
/*
* Insert a fake completion event for a DCB into the polling queue.
*
* This is used to trigger transmission activity on another DCB from
* within the event processing routine of a DCB. or to allow a DCB
* to defer some further output processing, to allow for other DCBs
* to receive a slice of the processing time. Fake events are added
* to the tail of the event queue, in the same way that real events
* are, so maintain the "fairness" of processing.
*
* @param dcb DCB to emulate an event for
* @param ev Event to emulate
*/
void
poll_fake_event(DCB *dcb, uint32_t ev)
{
spinlock_acquire(&pollqlock); spinlock_acquire(&pollqlock);
/* /*

View File

@ -278,7 +278,11 @@ typedef struct dcb
unsigned int high_water; /**< High water mark */ unsigned int high_water; /**< High water mark */
unsigned int low_water; /**< Low water mark */ unsigned int low_water; /**< Low water mark */
struct server *server; /**< The associated backend server */ struct server *server; /**< The associated backend server */
SSL* ssl; /*< SSL struct for connection */ SSL* ssl; /*< SSL struct for connection */
bool ssl_read_want_read; /*< Flag */
bool ssl_read_want_write; /*< Flag */
bool ssl_write_want_read; /*< Flag */
bool ssl_write_want_write; /*< Flag */
int dcb_port; /**< port of target server */ int dcb_port; /**< port of target server */
skygw_chk_t dcb_chk_tail; skygw_chk_t dcb_chk_tail;
} DCB; } DCB;
@ -318,7 +322,6 @@ int fail_accept_errno;
#define DCB_POLL_BUSY(x) ((x)->evq.next != NULL) #define DCB_POLL_BUSY(x) ((x)->evq.next != NULL)
DCB *dcb_get_zombies(void); DCB *dcb_get_zombies(void);
int gw_write(DCB *, const void *, size_t);
int dcb_write(DCB *, GWBUF *); int dcb_write(DCB *, GWBUF *);
DCB *dcb_alloc(dcb_role_t); DCB *dcb_alloc(dcb_role_t);
void dcb_free(DCB *); void dcb_free(DCB *);
@ -353,10 +356,7 @@ char *dcb_role_name(DCB *); /* Return the name of a role */
int dcb_create_SSL(DCB* dcb); int dcb_create_SSL(DCB* dcb);
int dcb_accept_SSL(DCB* dcb); int dcb_accept_SSL(DCB* dcb);
int dcb_connect_SSL(DCB* dcb); int dcb_connect_SSL(DCB* dcb);
int gw_write_SSL(SSL* ssl, const void *buf, size_t nbytes);
int dcb_write_SSL(DCB *dcb,GWBUF *queue);
int dcb_read_SSL(DCB *dcb,GWBUF **head); int dcb_read_SSL(DCB *dcb,GWBUF **head);
int dcb_drain_writeq_SSL(DCB *dcb);
/** /**

View File

@ -83,7 +83,6 @@ int do_read_dcb(DCB *dcb);
int do_read_10(DCB *dcb, uint8_t *buffer); int do_read_10(DCB *dcb, uint8_t *buffer);
int MySQLWrite(DCB *dcb, GWBUF *queue); int MySQLWrite(DCB *dcb, GWBUF *queue);
int setnonblocking(int fd); int setnonblocking(int fd);
int gw_write(DCB *dcb, const void *buf, size_t nbytes);
int gw_getsockerrno(int fd); int gw_getsockerrno(int fd);
int parse_bindconfig(char *, unsigned short, struct sockaddr_in *); int parse_bindconfig(char *, unsigned short, struct sockaddr_in *);
int setipaddress(struct in_addr *, char *); int setipaddress(struct in_addr *, char *);

View File

@ -22,14 +22,14 @@
#include <resultset.h> #include <resultset.h>
/** /**
* @file poll.h The poll related functionality * @file poll.h The poll related functionality
* *
* @verbatim * @verbatim
* Revision History * Revision History
* *
* Date Who Description * Date Who Description
* 19/06/13 Mark Riddoch Initial implementation * 19/06/13 Mark Riddoch Initial implementation
* 17/10/15 Martin Brampton Declare fake event functions * 17/10/15 Martin Brampton Declare fake event functions
* *
* @endverbatim * @endverbatim
*/ */
@ -52,22 +52,23 @@ typedef enum
POLL_STAT_MAX_EXECTIME POLL_STAT_MAX_EXECTIME
} POLL_STAT; } POLL_STAT;
extern void poll_init(); extern void poll_init();
extern int poll_add_dcb(DCB *); extern int poll_add_dcb(DCB *);
extern int poll_remove_dcb(DCB *); extern int poll_remove_dcb(DCB *);
extern void poll_waitevents(void *); extern void poll_waitevents(void *);
extern void poll_shutdown(); extern void poll_shutdown();
extern GWBITMASK* poll_bitmask(); extern GWBITMASK *poll_bitmask();
extern void poll_set_maxwait(unsigned int); extern void poll_set_maxwait(unsigned int);
extern void poll_set_nonblocking_polls(unsigned int); extern void poll_set_nonblocking_polls(unsigned int);
extern void dprintPollStats(DCB *); extern void dprintPollStats(DCB *);
extern void dShowThreads(DCB *dcb); extern void dShowThreads(DCB *dcb);
void poll_add_epollin_event_to_dcb(DCB* dcb, GWBUF* buf); extern void poll_add_epollin_event_to_dcb(DCB* dcb, GWBUF* buf);
extern void dShowEventQ(DCB *dcb); extern void dShowEventQ(DCB *dcb);
extern void dShowEventStats(DCB *dcb); extern void dShowEventStats(DCB *dcb);
extern int poll_get_stat(POLL_STAT stat); extern int poll_get_stat(POLL_STAT stat);
extern RESULTSET* eventTimesGetList(); extern RESULTSET *eventTimesGetList();
extern void poll_fake_hangup_event(DCB *dcb); extern void poll_fake_event(DCB *dcb, uint32_t ev);
extern void poll_fake_write_event(DCB *dcb); extern void poll_fake_hangup_event(DCB *dcb);
extern void poll_fake_write_event(DCB *dcb);
extern void poll_fake_read_event(DCB *dcb);
#endif #endif

View File

@ -44,6 +44,8 @@
* 11/06/2015 Martin Brampton COM_QUIT suppressed for persistent connections * 11/06/2015 Martin Brampton COM_QUIT suppressed for persistent connections
* 04/09/2015 Martin Brampton Introduce DUMMY session to fulfill guarantee DCB always has session * 04/09/2015 Martin Brampton Introduce DUMMY session to fulfill guarantee DCB always has session
* 09/09/2015 Martin Brampton Modify error handler calls * 09/09/2015 Martin Brampton Modify error handler calls
* 11/01/2016 Martin Brampton Remove SSL write code, now handled at lower level;
* replace gwbuf_consume by gwbuf_free (multiple).
*/ */
#include <skygw_utils.h> #include <skygw_utils.h>
#include <log_manager.h> #include <log_manager.h>
@ -73,8 +75,6 @@ static int gw_error_client_event(DCB *dcb);
static int gw_client_close(DCB *dcb); static int gw_client_close(DCB *dcb);
static int gw_client_hangup_event(DCB *dcb); static int gw_client_hangup_event(DCB *dcb);
int gw_read_client_event_SSL(DCB* dcb); int gw_read_client_event_SSL(DCB* dcb);
int gw_MySQLWrite_client_SSL(DCB *dcb, GWBUF *queue);
int gw_write_client_event_SSL(DCB *dcb);
int mysql_send_ok(DCB *dcb, int packet_number, int in_affected_rows, const char* mysql_message); int mysql_send_ok(DCB *dcb, int packet_number, int in_affected_rows, const char* mysql_message);
int MySQLSendHandshake(DCB* dcb); int MySQLSendHandshake(DCB* dcb);
static int gw_mysql_do_authentication(DCB *dcb, GWBUF **queue); static int gw_mysql_do_authentication(DCB *dcb, GWBUF **queue);
@ -646,25 +646,6 @@ int gw_MySQLWrite_client(DCB *dcb, GWBUF *queue)
return dcb_write(dcb, queue); return dcb_write(dcb, queue);
} }
/**
* Write function for client DCB: writes data from MaxScale to Client using SSL
* encryption. The SSH handshake must have already been done.
*
* @param dcb The DCB of the client
* @param queue Queue of buffers to write
*/
int gw_MySQLWrite_client_SSL(DCB *dcb, GWBUF *queue)
{
CHK_DCB(dcb);
#ifdef SS_DEBUG
MySQLProtocol *protocol = NULL;
protocol = DCB_PROTOCOL(dcb, MySQLProtocol);
CHK_PROTOCOL(protocol);
#endif
return dcb_write_SSL(dcb, queue);
}
/** /**
* Client read event triggered by EPOLLIN * Client read event triggered by EPOLLIN
* *
@ -774,10 +755,8 @@ int gw_read_client_event(DCB* dcb)
2, 2,
0, 0,
"failed to create new session"); "failed to create new session");
while (read_buffer) gwbuf_free(read_buffer);
{ read_buffer = NULL;
read_buffer = gwbuf_consume(read_buffer, GWBUF_LENGTH(read_buffer));
}
return 0; return 0;
} }
@ -865,10 +844,8 @@ int gw_read_client_event(DCB* dcb)
/** SSL was requested and the handshake is either done or /** SSL was requested and the handshake is either done or
* still ongoing. After the handshake is done, the client * still ongoing. After the handshake is done, the client
* will send another auth packet. */ * will send another auth packet. */
while ((read_buffer = gwbuf_consume(read_buffer,GWBUF_LENGTH(read_buffer)))) gwbuf_free(read_buffer);
{ read_buffer = NULL;
;
}
break; break;
} }
@ -962,7 +939,8 @@ int gw_read_client_event(DCB* dcb)
dcb_close(dcb); dcb_close(dcb);
} }
read_buffer = gwbuf_consume(read_buffer, nbytes_read); gwbuf_free(read_buffer);
read_buffer = NULL;
} }
break; break;
@ -1062,7 +1040,8 @@ int gw_read_client_event(DCB* dcb)
dcb_close(dcb); dcb_close(dcb);
} }
read_buffer = gwbuf_consume(read_buffer, nbytes_read); gwbuf_free(read_buffer);
read_buffer = NULL;
} }
break; break;
@ -1172,10 +1151,8 @@ int gw_read_client_event(DCB* dcb)
"Session will be closed."); "Session will be closed.");
} }
while (read_buffer) gwbuf_free(read_buffer);
{ read_buffer = NULL;
read_buffer = gwbuf_consume(read_buffer, GWBUF_LENGTH(read_buffer));
}
} }
} }
} }
@ -1271,56 +1248,6 @@ return_1:
return 1; return 1;
} }
/**
* EPOLLOUT event arrived and as a consequence, client input buffer (writeq) is
* flushed. The data is encrypted and SSL is used. The SSL handshake must have
* been successfully completed prior to this function being called.
* @param client dcb
* @return constantly 1
*/
int gw_write_client_event_SSL(DCB *dcb)
{
MySQLProtocol *protocol = NULL;
CHK_DCB(dcb);
ss_dassert(dcb->state != DCB_STATE_DISCONNECTED);
if (dcb == NULL)
{
goto return_1;
}
if (dcb->state == DCB_STATE_DISCONNECTED)
{
goto return_1;
}
if (dcb->protocol == NULL)
{
goto return_1;
}
protocol = (MySQLProtocol *)dcb->protocol;
CHK_PROTOCOL(protocol);
if (protocol->protocol_auth_state == MYSQL_IDLE)
{
dcb_drain_writeq_SSL(dcb);
goto return_1;
}
return_1:
#if defined(SS_DEBUG)
if (dcb->state == DCB_STATE_POLLING ||
dcb->state == DCB_STATE_NOPOLLING ||
dcb->state == DCB_STATE_ZOMBIE)
{
CHK_PROTOCOL(protocol);
}
#endif
return 1;
}
/** /**
* Bind the DCB to a network port or a UNIX Domain Socket. * Bind the DCB to a network port or a UNIX Domain Socket.
* @param listen_dcb Listener DCB * @param listen_dcb Listener DCB
@ -1983,11 +1910,6 @@ int do_ssl_accept(MySQLProtocol* protocol)
protocol->use_ssl = true; protocol->use_ssl = true;
spinlock_release(&protocol->protocol_lock); spinlock_release(&protocol->protocol_lock);
spinlock_acquire(&dcb->authlock);
dcb->func.write = gw_MySQLWrite_client_SSL;
dcb->func.write_ready = gw_write_client_event_SSL;
spinlock_release(&dcb->authlock);
rval = 1; rval = 1;
MXS_INFO("SSL_accept done for %s@%s", MXS_INFO("SSL_accept done for %s@%s",